flat assembler
Message board for the users of flat assembler.

Index > Compiler Internals > [BUG]question about 'match' and 'file'

Author
Thread Post new topic Reply to topic
zhak



Joined: 12 Apr 2005
Posts: 501
Location: Belarus
zhak 27 Mar 2010, 15:00
Hi
I use the following macro to include files based on language settings:

match lang,SYS_LANGUAGE { include '..\DOCS\HELP\'#lang#'\COMMAND.HLP' }

it works fine with include, but when i try to use 'file' directive instead of 'include', i get error "file not found".
why?

[Edit by Loco]Bug details are in some post below
Post 27 Mar 2010, 15:00
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20363
Location: In your JS exploiting you and your system
revolution 27 Mar 2010, 15:15
file does not enumerate the include environment variable.
Post 27 Mar 2010, 15:15
View user's profile Send private message Visit poster's website Reply with quote
zhak



Joined: 12 Apr 2005
Posts: 501
Location: Belarus
zhak 27 Mar 2010, 15:18
how is it possible to implement the macro above so that 'file' directive could be used to add files to source code?
thanks in advance
Post 27 Mar 2010, 15:18
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20363
Location: In your JS exploiting you and your system
revolution 27 Mar 2010, 15:20
Change the path so that fasm can find it without needing the include environment variable
Post 27 Mar 2010, 15:20
View user's profile Send private message Visit poster's website Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 27 Mar 2010, 15:20
I don't have that problem here. I've tried with this:
Code:
SYS_LANGUAGE equ "Test"

match lang, SYS_LANGUAGE { file '.\'#lang#'\test.inc' }    


Do you have the same problem if you use "file '..\DOCS\HELP\some_lang\COMMAND.HLP"? (some_lang has to be replaced by an existing directory)
Post 27 Mar 2010, 15:20
View user's profile Send private message Reply with quote
zhak



Joined: 12 Apr 2005
Posts: 501
Location: Belarus
zhak 27 Mar 2010, 15:52
i have the following:
Code:
LANGUAGE_ENGLISH equ 'ENG'
SYS_LANGUAGE equ LANGUAGE_ENGLISH

match lang,SYS_LANGUAGE { include '.\LANG\'#lang#'\CMDLINE.SZ' }
    

this works fine. But if I try
Code:
match lang,SYS_LANGUAGE { file '.\LANG\'#lang#'\CMDLINE.SZ' }
    

then error 'file not found' occurs.
If I use simply
Code:
file '.\LANG\ENG\CMDLINE.SZ'
    

then it compiles OK.
Post 27 Mar 2010, 15:52
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 27 Mar 2010, 16:19
I'm uploading what I exactly tested under FASMW, please try it.

PS: I'm using FASMW 1.69.12


Description:
Download
Filename: zhak.zip
Filesize: 779 Bytes
Downloaded: 423 Time(s)

Post 27 Mar 2010, 16:19
View user's profile Send private message Reply with quote
zhak



Joined: 12 Apr 2005
Posts: 501
Location: Belarus
zhak 27 Mar 2010, 17:35
the problem is that match macro doesn't correctly recognize ..\ (go to parent dir) in path to file

the following example doesn't work:


Description:
Download
Filename: zhak.zip
Filesize: 969 Bytes
Downloaded: 454 Time(s)

Post 27 Mar 2010, 17:35
View user's profile Send private message Reply with quote
zhak



Joined: 12 Apr 2005
Posts: 501
Location: Belarus
zhak 27 Mar 2010, 17:51
finally I got it!!!! I don't need to use ..\ in macro.
Code:
match lang,SYS_LANGUAGE { file 'DOCS\HELP\'#lang#'\RLDR\COMMANDS\CLR.HLP' }
sz_help_mem:
    file '..\DOCS\HELP\ENG\RLDR\COMMANDS\MEM.HLP'
    


both lines compile OK
Post 27 Mar 2010, 17:51
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr 27 Mar 2010, 20:59
zhak,

I was surprised that your source (attachment from 2010-03-27 19:35) compiled without a hitch. Then I remembered some modifications regarding file and include directives I made to FASM sources not a long time ago…

Partly you're right, the problem is related to match directive usage: when file directive is a result of macro expansion (irp / irps / match / rept are instant macros), FASM don't search for the file in the directory that contains included source which originates that file directive (INCL in our case, because it contains test.inc), only the directory of the main source.

Here is the mod:
Code:
      open_binary_file:
        push    esi
 push    edi
;;;; ASSEMBLE.INC [1734]
;    mov     esi,[current_line]
; mov     esi,[esi]
;+++
   mov     eax,[current_line]
      find_current_source_path:
   mov     esi,[eax]
   test    byte [eax+7],80h
    jz      get_current_path
    mov     eax,[eax+12]
        jmp     find_current_source_path
;=== ASSEMBLE.INC [1736]
      get_current_path:    
I don't guarantee anything, though, because I had to guess about structure pointed by current_line.

The last source compiles (you didn't provide entire tree, so I should guess) because 'DOCS\HELP\lang\RLDR\COMMANDS\CLR.HLP' is valid file path relative to your main source. What if your include file was found via %INCLUDE%?

P.S. Now I remember: there was the topic A suggestion! ("FILE" and "INCLUDE") about this.
Post 27 Mar 2010, 20:59
View user's profile Send private message Reply with quote
zhak



Joined: 12 Apr 2005
Posts: 501
Location: Belarus
zhak 27 Mar 2010, 21:25
Thanks baldr,

To compile, i use .BAT script in the source root directory. I don't use %INCLUDE% variable. And yes, you're right, DOCS folder is relative to main source.
Post 27 Mar 2010, 21:25
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 27 Mar 2010, 21:53
baldr, sorry I don't have my brain turned on today, should I move this to compiler internals and flag it as a bug?

I found really odd the behavior, for me, "file" should have the same path searching method no matter where it came from, after all, the assembler stage should be completely ignorant about the existence of a preprocessor and that fasm has a built-in one should be considered just a coincidence. If fasm wants to make "file" search relative to the source containing it, then it should do so for the same line not included inside any block enclosed by curly braces.

In case someone else is lost like I was for a moment, fasm is not realizing that "match" is forming a path, the fail also happens when using a literal string in INCL/test.inc (zhak attachment)
Code:
match lang,SYS_LANGUAGE { file '..\LANG\ENG\CMDLINE.SZ' } ; Also  triggers file not found, but it is OK if you keep match's body only.    
Post 27 Mar 2010, 21:53
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8356
Location: Kraków, Poland
Tomasz Grysztar 27 Mar 2010, 22:18
LocoDelAssembly wrote:
baldr, sorry I don't have my brain turned on today, should I move this to compiler internals and flag it as a bug?
Yes, it is a bug.
Post 27 Mar 2010, 22:18
View user's profile Send private message Visit poster's website Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr 27 Mar 2010, 22:43
LocoDelAssembly,

If assembler don't know from where the source line came, how do it guess the exact error location so luckily? Wink

You can get the same error with any macro facility: macro / struc / irp / irps / match / rept. That error is not related to them directly: it's open_binary_file bug.

By the way, this mod applies the same behavior change to format PE … on 'filename', section … resource from 'filename' and data resource from 'filename' directives.

__________
Tomasz Grysztar,

Was I lucky with my guess about [eax+12]?
Post 27 Mar 2010, 22:43
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8356
Location: Kraków, Poland
Tomasz Grysztar 27 Mar 2010, 23:05
baldr wrote:
Tomasz Grysztar,

Was I lucky with my guess about [eax+12]?

Yes, that was a very good guess. BTW, you can find some information about this structure in FASM.ASH file in fasm DLL package.
Post 27 Mar 2010, 23:05
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.