Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
11/21/06 14:42
Modified:
  11/21/06 14:48

Read: times


 
#128364 - Build-time scripts
Responding to: ???'s previous message
Erik said:
This works GREAT with Keil where you can use C style .h files in assembler allowing you to have

#define RALPH_SIZE
in a .h module
and, in your assembler XDATA you can include the .h and have
RALPH: ds RALPH_SIZE

I do not know to which extent other toolsets support this.

Unfortunately, some of them don't. One way to get a similar effect is to define the symbols you need in both C and ASM within a new file (make up your own syntax) that might look something like this:
RALPH_SIZE      is      100
DEBUG_OUTPUT    is      0
STX             is      2
ETX             is      3
DLE             is      16
Next write two little scripts (AWK would be a good language choice). One of them converts your new file into a .h file that looks like this:
#define RALPH_SIZE      100
#define DEBUG_OUTPUT    0
#define STX             2
#define ETX             3
#define DLE             16
and the other converts the new file into a file acceptable to your assembler that might (depending on the assembler) look something like this:
RALPH_SIZE      EQU     100
DEBUG_OUTPUT    EQU     0
STX             EQU     2
ETX             EQU     3
DLE             EQU     16
Finally, set up your build environment (makefile, batch files, IDE, or whatever) to automatically run these scripts before each compile, and live happily ever after.

-- Russ

PS: This general technique can also be used in many other situations to reduce coding effort and minimize stupid errors. Take something as simple as a table of error messages that might look like this in C:
typdef struct {
    int	error_code;
    char *error_text;
    } error_table_entry;

error_table_entry error_table[] = {
    { 308, "X axis failure" },
    { 309, "Y axis failure" },
    { 422, "No power to vacuum pump" },
    };
If there are a lot of different messages, you're going to get tired of typing all those commas and quotes and braces, and chances are good that you'll make a few typographical mistakes in the process. Instead, type the error messages and codes into their own file, as simply as this:
308 X axis failure
309 Y axis failure
422 No power to vacuum pump
Then write a little one-line AWK script to add all the punctuation, and #include its output in your original source file like this:
error_table_entry error_table[] = {
#include "awk_generated_messages.c"
    };
This technique really starts to shine when various, possibly dispersed parts of your code all depend on some common information such that when that common information changes, you need to make multiple, synchronized changes to various parts of your code. Instead of trying to perform that synchronization manually, put the common information in a single file and let some simple build-time scripts do the dirty work of generating the various bits of code that depend on it.

Another application of the technique is when something you need to code doesn't quite fit with the syntax of the language you're using. Invent a syntax that does make sense for what you're doing, then translate it into C (or whatever) using a build-time script.

Etc.


List of 37 messages in thread
TopicAuthorDate
(SDCC): How to point to end of used memory?            01/01/70 00:00      
   Make a dummy variable ???            01/01/70 00:00      
      A Better Idea            01/01/70 00:00      
         Good Point            01/01/70 00:00      
            A good point indeed...            01/01/70 00:00      
   SDCC options            01/01/70 00:00      
      this is still my fixation to asm....            01/01/70 00:00      
         Try this snippet?            01/01/70 00:00      
            Thanks!            01/01/70 00:00      
            Another bad idea?            01/01/70 00:00      
               it seems that this is hardwired in SDCC...            01/01/70 00:00      
                  More guessing            01/01/70 00:00      
               like that snippet?            01/01/70 00:00      
                  Yes!            01/01/70 00:00      
                  nice...            01/01/70 00:00      
   you do not want a 'heap' in '51 C, however            01/01/70 00:00      
      passing a #define to assembler within SDCC            01/01/70 00:00      
         NO, no, no            01/01/70 00:00      
            inline assembly versus separate assembly file            01/01/70 00:00      
               separate file is nicer            01/01/70 00:00      
                  good place to start, bad place to stay            01/01/70 00:00      
               that's the crux            01/01/70 00:00      
      Build-time scripts            01/01/70 00:00      
   the question of matter            01/01/70 00:00      
      have as much memory as possible            01/01/70 00:00      
         be sure or not to be?            01/01/70 00:00      
            easy            01/01/70 00:00      
               I'd disagree on this one...            01/01/70 00:00      
         well, you have to mix to get that            01/01/70 00:00      
            Did I miss something?            01/01/70 00:00      
               I thought I posted this            01/01/70 00:00      
                  Thanks            01/01/70 00:00      
            Do you think I would ask answerable questions? :-)            01/01/70 00:00      
               The Right Group?            01/01/70 00:00      
         Know no nice solution            01/01/70 00:00      
            thanks            01/01/70 00:00      
   Maybe compiler/linker settins help?            01/01/70 00:00      

Back to Subject List