flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > Include only once problem.

Author
Thread Post new topic Reply to topic
halyavin



Joined: 21 Aug 2004
Posts: 42
halyavin 06 Jan 2006, 08:20
I have complex nesting include directives. Sometimes the same file included twice. But this leads to errors. What is the best solution for this problem when file contains macroses and when it doesn't?
Currently I use
Code:
if ~defined file_inc
file_inc_fix:
file_inc fix file_inc_fix ;fix requires less memory than equ
;actual code...
end if
    

when file doesn't contains macroses.
Post 06 Jan 2006, 08:20
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8367
Location: Kraków, Poland
Tomasz Grysztar 06 Jan 2006, 08:54
Read the answer to fourth question in the FAQ and the section 2.3.7 of the manual (I feel like deja vu).

As for your particular problem, this macro will include each file only once, but only if the path given for such file is exactly the same each time (it's case sensitive):
Code:
macro includeonce path
{
 file@include equ path
 match head path tail,files@included
 \{ file@include equ \}
 match head path,files@included
 \{ file@include equ \}
 match file, file@include
 \{ include file \}
 files@included equ files@included path
}    


PS. Do not overuse FIX directive - it is no longer to widely used, the section 2.3.7 might explain to you, why.
Post 06 Jan 2006, 08:54
View user's profile Send private message Visit poster's website Reply with quote
halyavin



Joined: 21 Aug 2004
Posts: 42
halyavin 06 Jan 2006, 09:53
Thanks for this macro idea. It can be improved (if necessary) a little:
Code:
macro includeonce [path]
{
reverse
 file@include equ path 
forward
 match head path tail,files@included 
 \{ file@include equ \} 
 match head path,files@included 
 \{ file@include equ \} 
 match path tail, files@included
 \{ file@include equ \}
 match path,files@included
 \{ file@include equ \}
common
 match file, file@include 
 \{ include file \} 
forward
 files@included equ files@included path 
}    

for using as includeone "real path","mirror1","mirror2"
PS When fix disappear from fasm syntax I manually execute "fix fix equ" command for my source files Wink .
Post 06 Jan 2006, 09:53
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20526
Location: In your JS exploiting you and your system
revolution 20 Jun 2024, 23:45
Matching by file name is fraught with many problems. Having different roots to the same file can't be identified by string matching. For a simple example the following can all be the same file.
Code:
include 'myfile.inc'
include './myfile.inc'
include '../mydir/myfile.inc'    
Many C headers solve this by wrapping the code in #ifndef/#define/#endif
Code:
#ifndef _C_SOURCE_H
#define _C_SOURCE_H 1

// C code goes here

#endif /* c_source.h */    
The same can be done in fasm.
Code:
irpv any, unique_identifier { rept 0 {} rept 1 { unique_identifier equ

; assembly code goes here

}    
Choose a suitable naming convention for "unique_identifier" in each file.

Using this allows each file to handle its own multiple inclusion guard.

The downside being that if the code contains any closing braces then they must be escaped. Both x86 and ARM have syntax that uses braces, and fasm native macros use them also.
Code:
irpv any, unique_identifier { rept 0 {} rept 1 { unique_identifier equ

        macro foo \{
                vprolvd xmm1{k1\\}{z\\},xmm2,xmm3 ; escape the closing braces
        \}
        foo

}    
Post 20 Jun 2024, 23:45
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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.