flat assembler
Message board for the users of flat assembler.

Index > Compiler Internals > Patch to allow command line arguments

Author
Thread Post new topic Reply to topic
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 27 Sep 2007, 02:02
Hi, in case someone has use for this, here is diff script that allows defining equates from command line. It only allows to set name of equate, value is always "1". Option to set value will be added later.

It also allows -q switch to turn off all output, except error information. "display" output is turned off too.

patch "SOURCE\WIN32\FASM.ASM" with this
Code:
11,12c11,17
<        mov     esi,_logo
<       call    display_string
---
> 
>  call    init_memory
> 
>    ;initialize buffer for fake file in beginning of memory block
>   mov     edi, [memory_start]
>     mov     [fake_file_start], edi
>  mov     [fake_file_end], edi
17c22,43
<        call    init_memory
---
>      ;finish fake source file
>        ;add line to include actual main file
>   mov     edi, [fake_file_end]
>    mov     esi, _include
>   mov     ecx, _include.len
>       cld
>     rep     movsb
>   mov     esi, [input_file]
> @@:
>       lodsb
>   or      al, al
>  jz      @f
>      stosb
>   jmp     @b
> @@:      mov     al, '"'
>  stosb
> 
>  ;set up things after source file is finished
>    mov     [memory_start], edi             ;new start of buffer is behind fake file
>        mov     eax, [input_file]
>       mov     [original_input_file], eax      ;save name of original input file
>       mov     [input_file], _fake_name        ;set fake file as new input file
18a45,48
>    cmp     [quiet_mode], 1
>         je      skip_initial_display
>    mov     esi,_logo
>       call    display_string
28a59
> skip_initial_display:
37a69,70
>   cmp     [quiet_mode], 1
>         je      skip_ending_display
66a100,101
> skip_ending_display:
> 
70a106,107
>       mov     esi,_logo
>       call    display_string
148a186,193
>   cmp     al,'d'
>        je      define_option
>   cmp     al,'D'
>        je      define_option
>   cmp     al,'q'
>        je      quiet_option
>    cmp     al,'Q'
>        je      quiet_option
178a224,278
>     quiet_option:
>       mov     [quiet_mode], 1
>         jmp     find_param
>     define_option:
>       lodsb
>   cmp     al,20h
>  je      define_option
>   cmp     al,0Dh
>  je      bad_params
>      or      al,al
>   jz      bad_params
>      dec     esi
>     push    edi
>     mov     edi, [fake_file_end]
>     define_option_char:
>        lodsb
>   or      al,al
>   je      define_option_end
>       cmp     al, 0Dh
>         je      define_option_end
>       cmp     al, 20h
>         je      define_option_end
>       cmp     al, '@'
>       je      define_option_okay
>      cmp     al, '_'
>       je      define_option_okay
>      cmp     al, '.'
>       je      define_option_okay
>      cmp     al, 'A'
>       jb      define_option_bad
>       cmp     al, 'Z'
>       jae     define_option_okay
>      cmp     al, 'a'
>       jb      define_option_bad
>       cmp     al, 'z'
>       jae     define_option_okay
>      cmp     al, '0'
>       jb      define_option_bad
>       cmp     al, '9'
>       jae     define_option_okay
>     define_option_okay:
>  stosb
>   jmp     define_option_char
>     define_option_bad:
>   pop     esi
>     jmp     bad_params
>     define_option_end:
>   mov     dword [edi], ' equ'
>   mov     word [edi+4], ' 1'
>    mov     word [edi+6], 0A0Dh
>     add     edi, 8
>  mov     [fake_file_end], edi
>    pop     edi
>     dec     esi
>     jmp     find_param
253c353,355
<        db ' -p <limit>  set the maximum allowed number of passes',0D,0Ah
---
>        db ' -p <limit>  set the maximum allowed number of passes',0Dh,0Ah
>        db ' -q          quiet mode: logo, compilation information, and "display" texts not diplayed',0Dh,0Ah
>        db ' -f <name>   defines equate with given name and value 1 at beginning of source',0Dh,0Ah
265a368,378
> ;data for fake file
> _fake_name db "<<< fake file >>>",0
> _include   db 'include "'
>   .len = $ - _include
> quiet_mode db 0                   ; quiet mode: no output, not even "display"
> align 4
> fake_file_start     dd ?              ; pointer to beginning of fake file buffer
> fake_file_pos            dd ?                ; current position in fake file
> original_input_file dd ?                ; pointer to name of original input file
> label fake_file_end at memory_start    ; end of fake file is also start of memory block
> 
    


patch "SOURCE\WIN32\SYSTEM.INC" with this:
Code:
105a106,114
>   ;check if we are opening fake file
>      cmp     edx, _fake_name
>         jne     .normal
>         mov     [in_fake], 1
>    mov     ebx, _fake_name
>         mov     [fake_file_pos], 0
>      clc
>     ret
> .normal:
121a131,132
> 
> 
122a134,136
>        ;fail if we try to create fake file
>     cmp     edx, _fake_name
>         je      write_failed
135a150
> 
136a152,154
>         ;fail if we try to write fake file
>      cmp     ebx, _fake_name
>         je      write_failed
146a165
> 
147a167,180
>         ;handle reading from fake file
>  cmp     ebx, _fake_name
>         jne     .normal
>         push    esi edi
>         mov     esi, [fake_file_start]
>  add     esi, [fake_file_pos]
>    add     [fake_file_pos], ecx
>    mov     edi, edx
>        cld
>     rep     movsb
>   pop     edi esi
>         clc
>     ret
> .normal:
160a194,195
> 
> 
161a197,204
>        ;handle closing fake file
>       cmp     [in_fake], 0
>    je      .normal
>         mov     [in_fake], 0
>    push    [original_input_file]   ;restore name of original input file
>    pop     [input_file]            ;needed for proper default output file name
>     ret
> .normal:
164a208
> 
165a210,224
>     ;handle seeking in fake file
>    cmp     ebx, _fake_name
>         jne     .normal
>         cmp     al, 0
>   jne     @f
>      mov     [fake_file_pos], edx
>    ret
> @@:     cmp     al, 1
>   jne     @f
>      add     [fake_file_pos], edx
>    ret
> @@:     mov     eax, [fake_file_end]
>    sub     eax, [fake_file_start]
>  ret
> .normal:
311a371
> 
    


This is just early version, if you need something else, let me know.


Description: version with -d and -q switches
Download
Filename: FASM-tweaked.ZIP
Filesize: 45.98 KB
Downloaded: 441 Time(s)

Post 27 Sep 2007, 02:02
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number 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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.