flat assembler
Message board for the users of flat assembler.

Index > Compiler Internals > Using source line numbers

Author
Thread Post new topic Reply to topic
Posetf



Joined: 01 Mar 2004
Posts: 35
Location: London
Posetf 01 Mar 2004, 20:28
Is there any way to use the source line number in the code emitted?

I'm writing an exception handler/debugger type thing & especially for testing I'd like to be able to write something like:

mov [currline],$line
<test case 1>
mov [currline],$line
<test case 2>

If not, roughly where might be a good place to add this in the sources of fasm?

Regards
Post 01 Mar 2004, 20:28
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8357
Location: Kraków, Poland
Tomasz Grysztar 01 Mar 2004, 22:43
OK, here's quick guide how you can quickly add support for the %L symbol that gives you the number of currently processed source line.

First, you need to modify the PARSER.INC file, so the parser will be able to recognize the %L symbol. Find the "get_predefined_id" label (somewhere around line 826), somewhere below it you can find those two lines:
Code:
        cmp     al,'t'
        je      get_timestamp_id    

just after them you can add check for any additional "%+letter" symbols you want to use, in this case:
Code:
        cmp     al,'l'
        je      get_linenumber_id    

The "get_timestamp_id" routine is defined somewhere above, you can add the "get_linenumber_id" just after it, and it should look like:
Code:
      get_linenumber_id:
        mov     eax,3
        ret    

where 3 is the identifier of %L symbol which will appear in the parsed source.

Now you have to modify also EXPRESSI.INC file to allow the assembler to recognize this new type of symbol and get the right value for it during the calculations. Find the "predefined_label" routine (around line 999), it looks like:
Code:
      predefined_label:
        or      eax,eax
        jz      current_offset_label
        cmp     eax,1
        je      counter_label
        cmp     eax,2
        je      timestamp_label    

of course you have to add there something like:
Code:
        cmp     eax,3
        je      linenumber_label    

The "timestamp_label" routine is just above, after it you can add the routine that gets the number of current line:
Code:
      linenumber_label:
        mov     eax,[current_line]
        mov     eax,[eax+4]
        jmp     make_dword_label_value    


And that's all - now you can use %L symbol to get the line number. Please note that in case of line inside the macro, it has the bit 31 set, and the lower bits contain the number of line in the macro, not in the file. To get number of source line that invoked the macro or number of line in macro definition, you would have to make some more modifications.
Post 01 Mar 2004, 22:43
View user's profile Send private message Visit poster's website Reply with quote
Posetf



Joined: 01 Mar 2004
Posts: 35
Location: London
Posetf 02 Mar 2004, 00:20
WOW!

Coded, working, thanks!
Post 02 Mar 2004, 00:20
View user's profile Send private message Visit poster's website Reply with quote
Posetf



Joined: 01 Mar 2004
Posts: 35
Location: London
Posetf 02 Mar 2004, 00:36
Forgot to ask:
Yeah/nay on this being in 1.52?
(nay is ok, just would like to know)
Post 02 Mar 2004, 00:36
View user's profile Send private message Visit poster's website Reply with quote
comrade



Joined: 16 Jun 2003
Posts: 1150
Location: Russian Federation
comrade 02 Mar 2004, 01:14
Certainly "yay" on my part Twisted Evil

_________________
comrade (comrade64@live.com; http://comrade.ownz.com/)
Post 02 Mar 2004, 01:14
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
Posetf



Joined: 01 Mar 2004
Posts: 35
Location: London
Posetf 02 Mar 2004, 01:49
comrade wrote:
Certainly "yay" on my part Twisted Evil

Although it wouldn't be any practical use to me at the moment, I'm compelled to suggest %s for the current source file as a possible addition as well.
Post 02 Mar 2004, 01:49
View user's profile Send private message Visit poster's website 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.