flat assembler
Message board for the users of flat assembler.

Index > Compiler Internals > Patching match to match numbers

Author
Thread Post new topic Reply to topic
wht36



Joined: 18 Sep 2005
Posts: 106
wht36
While eqtype can detect numbers and floats, it is nice to be able to match for numbers/floats at the preprocessor stage.
The patch below will allow ! to match a number and !.! to match a float such that one can do things like:
Code:
match !,0 {db !} ;this will code db 0
match !,x {db !} ;this will not match    

The patch applies to PREPROCE.INC.
Code:
      skip_match_element:
        cmp     esi,[parameters_end]
        je      cannot_match
;vvvvvvvvvvvvvvvvv Insert lines below vvvvvvvvvvvvvvvvvvvvvv
;Lines below will allow ! to match for symbols beginning with a numeric expression
;and !.! to match for a float expression
        mov     ebp,esi                 ;save esi
        cmp     byte [ebx],1Ah          ;before we skip the symbol, check if need to match a number
        jne     skip_match_rest
        mov     eax,[ebx+1]
        cmp     eax,'!.!' shl 8 + 3
        je      match_float
        cmp     ax,'!' shl 8 + 1
        jne     skip_match_rest
      match_number:                     ;first match for single operands +/-/not
        push    ebx edx edi
        mov     edi,single_operand_operators
        call    get_operator
        pop     edi edx ebx
        or      al,al
        jnz     match_number
        lodsb
        cmp     al,'('
        je      match_number
        dec     esi
        cmp     al,1Ah
        jne     number_mismatch
        pushd   ebp ebx edx [edi] [edi+4]
        call    get_number
        popd    [edi+4] [edi] edx ebx ebp
        jc      number_mismatch
      number_matched:
        push    ebx edx edi
        mov     edi,operators
        call    get_operator
        pop     edi edx ebx
        or      al,al
        jnz     match_number
        mov     al,[esi]
        cmp     al,')'
        je      number_matched
        cmp     al,'('
        je      match_number
        clc
        ret
      number_mismatch:
        mov     esi,ebp                 ;error = return with CF set, symbol not skipped
        stc
        ret
      match_float:
        push    ebx edx ebp
        call    get_fp_value
        pop     ebp edx ebx
        jc      number_mismatch
        ret
      skip_match_rest:
        mov     esi,ebp
;^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^    
Post 13 Jan 2013, 21:06
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-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.