??? 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 16Next 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 16and 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 16Finally, 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 pumpThen 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. |