flat assembler
Message board for the users of flat assembler.

Index > Compiler Internals > Preprocess and don't assemble- is it possible?

Author
Thread Post new topic Reply to topic
THEWizardGenius



Joined: 14 Jan 2005
Posts: 382
Location: California, USA
THEWizardGenius 03 Feb 2005, 18:27
I had an idea and I was wondering how difficult would this be to do?

It would in many cases be helpful for me to know the code that the preprocessor generates. Would it be possible to, using a commandline option (or if you prefer, a directive) so that FASM would only spit out partially chewed-up source code to speak- in other words, it preprocesses the file and then spits it out, without actually assembling it. For example, consider the code

macro dblax {add ax,ax}
dblax ;Add AX to itself
dblax
dblax

with my idea in effect, a commandline option or directive would spit out

add ax,ax ;Add AX to itself
add ax,ax
add ax,ax

into a certain .ASM file (or maybe some other extension, such as .PRC?).
This is not a very useful example, but that gives you the basic idea. Has anyone ever though of this, or tried to do it? I read the FASM internals guide, and I remember it converts certain mnemonics to a special code which will later be converted to machine language, am I correct? But does it do this at preprocessing, or later?

In other words, is it possible to have something like this BUILT IN TO FASM ITSELF (not a separate program) that could spit out readable code (not obscured code that is half-digested, but readable code that has only been chewed up by the preprocessor) and then quit (at the preprocessor stage). It would spit out a source file with no preprocessor directives of any kind. I imagine there would be just pure assembly and nothing else. Is this possible, and if so, is it easy to do, or not (due to the way FASM works)?

I don't know much about that sort of thing, and I can't understand the source code of FASM itself, so I was just wondering if it's possible.

_________________
FASM Rules!
OS Dev is fun!
Pepsi tastes nasty!
Some ants toot!
It's over!
Post 03 Feb 2005, 18:27
View user's profile Send private message AIM Address Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 03 Feb 2005, 20:29
search the forum, there was an easy way to rewrite source this way (altough i will like it more as comandl ine paramter)
Post 03 Feb 2005, 20:29
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
THEWizardGenius



Joined: 14 Jan 2005
Posts: 382
Location: California, USA
THEWizardGenius 04 Feb 2005, 03:34
I think I found it, but all it had was a broken link:

http://board.win32asmcommunity.net/showthread.php?s=&threadid=10289

This isn't much help... I was hoping Privavlov would know what to do, and maybe put into the next FASM (yeah I know, 1.57 JUST came out... I guess it'll be a bit of a wait until the next one comes out...) maybe if enough people think this is a good idea, he will. I doubt he'll put it in as a commandline option though, because (as he always says) commandline options should not be able to determine the output of the file- it's all packed into one file. I really don't care where he puts it, I just want that feature... maybe a directive such as:

preprocess_only

or something... I think it would be a cool idea. If he won't put it in, it would be nice if he'd tell us how... like I say, I don't understand this much, so he would have to give some sort of guide "replace this line with this" sort of thing like that...
Post 04 Feb 2005, 03:34
View user's profile Send private message AIM Address Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 05 Feb 2005, 10:21
not directive but command line switch due to FASM philosophy. What you have found wasn't what i meant, it was on this forum.
Post 05 Feb 2005, 10:21
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8351
Location: Kraków, Poland
Tomasz Grysztar 05 Feb 2005, 12:15
If you want to see the preprocessed source, you can insert the following lines after the "call preprocessor" and before the "call parser" instruction in the fasm.asm file:
Code:
        mov     edx,_preprocessed
        call    create
        mov     edx,[memory_start]
        mov     ecx,[source_start]
        sub     ecx,edx
        call    write
        call    close
        jmp     parse
        _preprocessed db 'preproce.dat',0
    parse:    

(you can jump directly to "exit_program" instead of "parse" if you want it to do preprocessing only). Then every preprocessed source will be written into preproce.dat file, but it will be in the fasm's source format (already described in guide to fasm's internals), you'll probably need to convert it into human-readable form.
Post 05 Feb 2005, 12:15
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 06 Feb 2005, 00:25
privalov: (once more this question) WHY don't you make it as command line parameter ?!?
Post 06 Feb 2005, 00:25
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8351
Location: Kraków, Poland
Tomasz Grysztar 06 Feb 2005, 02:51
1) The format of preprocessed source is not guaranteed to be the same in all versions.
2) It contains some address fields, which would have to be relocated to be usable after writing to file, converting it to other form would help, but:
3) Some of the original information is lost when converting to preprocessing format, for example the first four characters of macro definition directive are replaced by some address field.

All of the above make any implementation of this feature "dirty" and I'd like to avoid implementing "dirty" features in official releases.
Post 06 Feb 2005, 02:51
View user's profile Send private message Visit poster's website Reply with quote
THEWizardGenius



Joined: 14 Jan 2005
Posts: 382
Location: California, USA
THEWizardGenius 22 Feb 2005, 23:00
Well can't we have like something that doesn't spit out the weird FASM code-format but normal assembly? Perhaps in a normal executable... For example, given the code

macro mymac someth
{
mov ax,someth
}
mymac 3
mymac 4
mymac 5

It would spit out this:

mov ax,3
mov ax,4
mov ax,5
Post 22 Feb 2005, 23:00
View user's profile Send private message AIM Address Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3499
Location: Bulgaria
JohnFound 23 Feb 2005, 00:27
Fresh IDE have some similar functionality, related to the source level debuger. For now you can't get the whole listing at once, but when you debug the program step by step in the source, there is additional window that show the code generated by macroses.
Unfortunately, the debuger is not finished and have a big lack of features, i.e. it is not very usefull for now. In the future, there will be implemented more features and I though about some "list" function.
Again unfortunately, the debuger have low priority in my task list, so... stay tuned. Smile

Regards.
Post 23 Feb 2005, 00:27
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
iklin



Joined: 20 Mar 2004
Posts: 120
Location: Russia, Siberia
iklin 23 Feb 2005, 20:07
2 THEWizardGenius:
Get the attach, replace files in the fasm source dir and compile.
You'll get the fasm 1.58l with listing feature by Privalov not by me!

2 Privalov:
If I place
Code:
        mov     edx,_processed 
        call    create 
        mov     edx,[source_start]
        mov     ecx,[code_start] 
        sub     ecx,edx 
        call    write 
        call    close 
        jmp     assemble
        _processed db 'proce.dat',0 
    assemble:
    

after "call parser" and before "call assembler"... hmm... will I get in 'proce.dat' parsed but not assembled fasm source which format isn't described in guide to fasm's internals? If I'm right after "call parse" all macros will be expanded and so on?


Description: fasm 1.58l (with listing feature)
Download
Filename: fasm158l.rar
Filesize: 11.44 KB
Downloaded: 644 Time(s)

Post 23 Feb 2005, 20:07
View user's profile Send private message ICQ Number Reply with quote
THEWizardGenius



Joined: 14 Jan 2005
Posts: 382
Location: California, USA
THEWizardGenius 24 Feb 2005, 21:39
No, it assembles into special codes on the first pass, codes that only FASM understands, and on the SECOND pass it assembles to machine code. Unless of course the file is really big.
Post 24 Feb 2005, 21:39
View user's profile Send private message AIM Address Reply with quote
iklin



Joined: 20 Mar 2004
Posts: 120
Location: Russia, Siberia
iklin 25 Feb 2005, 15:37
I said "before "call assembler"..." What I'll get after parse calling parser and before calling assembler? After preprocessing there will be full source with includes in fasm internal format and there will be after parsing?
It seems like pure asm code without macros in fasm internal format. Maybe we can convert this code to human-readable form?
Post 25 Feb 2005, 15:37
View user's profile Send private message ICQ Number Reply with quote
decard



Joined: 11 Sep 2003
Posts: 1092
Location: Poland
decard 25 Feb 2005, 19:11
proably it wouldn't be so difficult to modify fasm code, strip everything after preprocessor, and make it emit human-readable code...
Post 25 Feb 2005, 19:11
View user's profile Send private message Visit poster's website Reply with quote
iklin



Joined: 20 Mar 2004
Posts: 120
Location: Russia, Siberia
iklin 26 Feb 2005, 05:41
After preprocessor macros isn't expanded and we get just listing with expanded "include" statements. And this work already done by Privalov for version 1.56 (e.g.) and I'm applied this to version 1.58. But as I said after parser it seems that all macros, equs and another things are expanded but fasm internal format after parser stage(s) isn't described in unfinished fasm internals docs.
Post 26 Feb 2005, 05:41
View user's profile Send private message ICQ Number Reply with quote
THEWizardGenius



Joined: 14 Jan 2005
Posts: 382
Location: California, USA
THEWizardGenius 01 Mar 2005, 18:47
I just want macros and include and struc and other preprocessor directives expanded, giving us a file with little or no preprocessor directives in it at all. I don't want the undocumented internal format of cryptic binary codes, or anything like that; just a normal assembly file. If this isn't possible, I guess it doesn't matter, but all this other "gibberish" I don't understand.
Post 01 Mar 2005, 18:47
View user's profile Send private message AIM Address Reply with quote
d0dka



Joined: 05 Dec 2004
Posts: 2
d0dka 11 Mar 2005, 20:36
i have question 'bout macroses and structs in fasm inner representation. as 3Bh symbol marks the lcode as preprocessed, so i put line to output, but the starnge symbols appear replacing macro or structure reserved word. i'll try to find some explanations in fasm guide, but find nothing.

i have such symbols
for macro:
6D byte byte 42h 00h
for structs:
73h byte byte 42h 00h

at first i think that is value of [ macro_state ], but second byte confusing me. can anyone tell what meaning of this bytes?
Post 11 Mar 2005, 20:36
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8351
Location: Kraków, Poland
Tomasz Grysztar 11 Mar 2005, 21:52
The earlier fasm versions were storing there the 32-bit pointer to the header of first macro line. However it is no more true with fasm 1.59 - with the latest versions this is stored inside the macro entry in preprocessor's symbols table and the "macro"/"struc" symbol in source is kept unchanged.

But there is one more case when the original source symbol is corrupted by preprocessor - when you use the "struc" macro, the preprocessor puts the colon character after the structure label, cutting out the first character of structure name (as it's no longer needed after recognizing the macro).
Post 11 Mar 2005, 21:52
View user's profile Send private message Visit poster's website Reply with quote
mrpink



Joined: 03 Jun 2005
Posts: 27
Location: Germany
mrpink 22 Aug 2005, 09:58
I've written a postprocessor for the preprocessor of fasm 1.60.
It can easily be integrated into fasm or used as standalone
commandline tool(9 kB).

It simply recodes the preprocesed data to a "compilable" and readable file.
The output is a little bit formatted for better readability.
If you can live with fasm version 1.60 and want to try it, please send me
an email and I will send you the code.
Post 22 Aug 2005, 09:58
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.