Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>C compilers are capable of doing math. No regular expressions or file modifications needed.</p> <p>file.h:</p> <pre><code>/* Definitions for peripherals */ #define XPAR_NF10_ROUTER_OUTPUT_PORT_LOOKUP_0_BAR0_BASEADDR 0x76800000 #define XPAR_NF10_ROUTER_OUTPUT_PORT_LOOKUP_0_BAR0_HIGHADDR 0x7680FFFF //Shorten name to make it easier for asker to read #define BASEADDR XPAR_NF10_ROUTER_OUTPUT_PORT_LOOKUP_0_BAR0_BASEADDR #define XPAR_NF10_ROUTER_OUTPUT_PORT_LOOKUP_0_BAR0_RESET_CNTRS_OFFSET (BASEADDR + 0x0) #define XPAR_NF10_ROUTER_OUTPUT_PORT_LOOKUP_0_BAR0_MAC_1_LOW_OFFSET (BASEADDR + 0xc) #define XPAR_NF10_ROUTER_OUTPUT_PORT_LOOKUP_0_BAR0_MAC_1_HIGH_OFFSET (BASEADDR + 0x10) #define XPAR_NF10_ROUTER_OUTPUT_PORT_LOOKUP_0_BAR0_MAC_3_LOW_OFFSET (BASEADDR + 0x1c) #define XPAR_NF10_ROUTER_OUTPUT_PORT_LOOKUP_0_BAR0_MAC_3_HIGH_OFFSET (BASEADDR + 0x20) #undef BASEADDR </code></pre> <p>And a pseudocode script (with real regexes) to do the transformation you want, if you don't like this solution:</p> <pre><code>#This script assumes that OFFSET #defines come after # their associated BASEADDR #defines input_file = open("path/to/input/file.c", read) output_file = open("path/to/output/file.c", write) baseaddr = 0 #In iteration of the loop, "line" will be a string # containing a single line of the file foreach line in input_file: #Get base address from the _BASEADDR #defines if regex_match("#define .*_BASEADDR (0x[0-9]{8})", line): baseaddr = hex_string_to_number(regex_groups[0]) write_line(output_file, line) #Create new offset #define by adding offset from source # file to base address from source file else if regex_match("#define (.*)_OFFSET (0x[0-9]+)", line): new_val = hex_string_to_number(regex_groups[1]) + baseaddr #Format here is similar to C's sprintf. # Whichever language you choose will likely have # something that behaves differently new_line = format("#define %s_OFFSET %s", regex_groups[0], number_to_hex_string(new_val)) write_line(output_file, new_line) #Pass through all other lines (blanks, HIGHADDRs, comments, etc) else: write_line(output_file, line) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload