flat assembler
Message board for the users of flat assembler.
Index
> Macroinstructions > Including a C header file using macros ? |
Author |
|
baldr 11 Nov 2008, 10:04
wht36,
Is your goal is a fasm source that compiles to some other fasm source with constants, structures and some kind of prototypes for functions from given C source? For it's impossible to write self-modifying source in fasm AFAIK. Pretty challenging, interpret C source with fasm script… Your problem with // comments may be solved as follows: Code: format binary as "c.fasm" file "test.c" in_comment = 0; are we in // comment? Not yet. repeat $ - $$ load c byte from $$+%-1 if in_comment if c = 10; LF in_comment = 0; single-line comment ends here end if else if (c = '/') & ($$+% < $); got slash and it's not last character in file load c byte from $$+%; or else we'll got error here if c = '/'; got two slashes store byte ';' at $$+%-1; replace first slash with semicolon in_comment = 1; and set flag to ignore everything up to LF end if end if end if end repeat |
|||
11 Nov 2008, 10:04 |
|
wht36 11 Nov 2008, 15:59
baldr wrote: wht36, Yes, that is my goal. Initially I considered writing a specific EXE program to convert C prototypes into fasm macros (possibly with type checking), but I should try to do it with macros, since I'm trying to learn macros. Thanks very much for your code! I was struggling with range errors and couldn't quite figure out how to avoid them! I guess the only way to change "//" into ";/" is to load the file as a binary file and to replace with assembler directives. Oh well, I could always use a batch file to run fasm twice to parse the output again. Many thanks! |
|||
11 Nov 2008, 15:59 |
|
baldr 11 Nov 2008, 17:08
wht36,
My example didn't use macros. Just assembler directives. It's possible to write such a script to replace "//" with ";" (not just ";/"), but it will be complex and hard to understand. Now imagine that you're trying to handle /* */ comments as well… Hell of a scripting, almost implementing C syntax parser (with regards to C preprocessor also)… Doesn't it undermine the goal? Standalone program will fit the bill much more accurately. There was attempts to use C preprocessor for preprocessing fasm sources with #includes of C header files. Unluckily, it will replace RT_CURSOR with something like (LPSTR)((ULONG_PTR)((WORD)(1))), tasty bit for fasm's error handler… |
|||
11 Nov 2008, 17:08 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.