flat assembler
Message board for the users of flat assembler.

Index > Compiler Internals > detailed "eqtype" evaluation

Author
Thread Post new topic Reply to topic
MCD



Joined: 21 Aug 2004
Posts: 602
Location: Germany
MCD 11 Feb 2007, 15:58
I did an extensive evaluation of the eqtype operator in a recent Fasm (1.67.15).

the Fasm docs says something about the eqtype operator, but this is to inexact for my purpos, cause I intend to write some sophisticate macro that checks the passed paramter agains many different types, so I did a little eqtype-test program:
Code:
macro   type_test       A{
  if A eqtype
    display "empty argument",0Ah
  else if A eqtype 4
    display "numeric constant",0Ah
  else if A eqtype "a"
    display "string",0Ah
  else if A eqtype 1.1
    display "floating point value",0Ah
  else if A eqtype ax
    display "register",0Ah
  else if A eqtype [bx]
    display "memory",0Ah
  else if A eqtype byte
    display "size prefix",0Ah
  else if A eqtype byte [bx]
    display "memory with size prefix",0Ah
  else if A eqtype mov;this includes special assembler instructions
    display "instruction",0Ah
  else if A eqtype align
    display "align",0Ah
  else if A eqtype defined
    display "defined",0Ah
  else if A eqtype dup
    display "dup",0Ah 
  else if A eqtype end if
    display "end if/else if/repeat/while",0Ah
  else if A eqtype eq
    display "eq",0Ah
  else if A eqtype times
    display "times",0Ah
  else if A eqtype used
    display "used",0Ah
  end if
}

toll    dd      100

type_test
type_test       10 + 70*(1-777/88) + toll
type_test       "This is a string"
type_test       -90.7e-107
type_test       sp
type_test       [toll+bx]
type_test       tbyte
type_test       qword [toll+ecx*8+100h]
;no way to distinguish between regular 80x86 instructions and special
;assembler instructions
type_test       xor
type_test       while
;But it's funny that the special assembler instructions dup, align and defined
;can be distinguished. Is it a bug or is there a special need for that?
type_test       align
type_test       defined
type_test       dup
  ;end repeat, end while, end if and else can't be distinguished each other,
  ;but they can be distinguished from other assembler instruction
type_test       end if
type_test       else if
type_test       end repeat
type_test       end while
;the following special assembler instructions can't be distinguished at all:
type_test       eq
;the following special assembler instruction can't be distinguished at all
;and generates an assembly-error (I guess syntax error):
;type_test      times
;type_test      used
    

mostly, the eqtype operator worked as expected, but there are a number of issues with the special assembler instructions (stuff like align, defined, used, end if/repeat/while, eq and used operators). Most special assembler symbols can't be distinguished (label, repeat, while, if, else), but some can, and this confuses me, especially for the "dup", "align" and "defined".

I guess there is a need in the parser/assembler for that, but I'm not sure, since it's been a while since I last examinated Fasm source code. If there's no need, then this behaviour should be changed to a more uniform one, which would mean that no special assembler instructions can be distinguished with eqtype or something else.

But hopefully it may be that checks against special assemler instructions with eqtype are not needed in my final program, so this thread is just another hint for others.

_________________
MCD - the inevitable return of the Mad Computer Doggy

-||__/
.|+-~
.|| ||
Post 11 Feb 2007, 15:58
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 11 Feb 2007, 16:53
there was list of eqtype types in some thread, try to find it.
Post 11 Feb 2007, 16:53
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8360
Location: Kraków, Poland
Tomasz Grysztar 11 Feb 2007, 20:41
The list is here: http://board.flatassembler.net/topic.php?t=573
It's not complete, however, even though I stated it - it lacks some of the special formatter types and directive operators.

Also note that it's the sequence of entities that is compared, not necessarily the single one. That's why "end if" is not only the same type as "end while", but even the same as "mov add", as all of them are the sequence of two instruction/directive mnemonics.

The directive operators, like "dup" (for the full list see the "directive_operators" table in SOURCE/TABLES.INC) are a separate types that must be matched exactly, a bit analogously to how the special character symbols are handled by "match". (When you match something against "a:b" pattern, the "a" and "b" can be anything, while ":" must be matched exactly. In a similar manner when you do "eqtype" comparison of "something at 4" with some other sequence, the "at" must be matched exactly.)
Post 11 Feb 2007, 20:41
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 11 Feb 2007, 21:32
tomasz: so how about some complete description of eqtype in one chunk? some article or something
Post 11 Feb 2007, 21:32
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
MCD



Joined: 21 Aug 2004
Posts: 602
Location: Germany
MCD 11 Feb 2007, 23:59
thanks!

yes, I've also noted that eqtype also distinguishes between different number of arguments, like
Code:
A eqtype "s";1 string
A eqtype "s" "t";2 strings
    

are not the same thing
Post 11 Feb 2007, 23:59
View user's profile Send private message Reply with quote
IceStudent



Joined: 19 Dec 2003
Posts: 60
Location: Ukraine
IceStudent 17 Feb 2007, 09:49
Can 'eqtype' to distinguish numbers from a labels? Or another way exist to do it?
Code:
if arg eqtype 0
  ; number
else if arg eqtype ???
 ; label
end if    


It would be better to detect difference between data labels" (declared as "t1 dd" or 'label' directive) and "code labels" (t2: ).
Post 17 Feb 2007, 09:49
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 17 Feb 2007, 10:25
IceStudent: and what is difference between them? you mean to detect labels with assigned size and without assigned size?
Post 17 Feb 2007, 10:25
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
IceStudent



Joined: 19 Dec 2003
Posts: 60
Location: Ukraine
IceStudent 21 Feb 2007, 18:42
Quote:
you mean to detect labels with assigned size and without assigned size?

Yes
Post 21 Feb 2007, 18:42
View user's profile Send private message Reply with quote
wht36



Joined: 18 Sep 2005
Posts: 106
wht36 24 Dec 2008, 06:39
After some testing, below is a list I came up with:
Code:
;eqtype    each element in the sets below are of the same type
;         name (e.g. a.b, _, @, !, name?, name%), number (includes $, $$), numeric expression, +, -, /, *, continue, exit, preprocessor words (e.g. include, macro, define, equ, match, irps)
;        %
;        ?
;        ,
;      space, tab
;         "" "string" 'string' ''
;    name:
;  [, ], [], [abcd]
;   (a)
;        (a, a)
;     {, }
;     0.0
;        registers e.g. ax, eax, fs
;         opcodes, data definition (e.g. db, rd), if, else, while, repeat, end, break, virtual, load, store, section, format, entry, stack, heap, segment, extrn
;     near, far
;  use16, use32
;       byte, word, dword, fword, pword, qword, tbyte, tword, dqword
;       code, data, readable, writeable, executable, shareable, discardable, notpageable, linkinfo, linkremove
;     fixups, resource, export, import
;   console, GUI
;       binary, MZ, PE, PE64, COFF, ELF, ELF64
;     MS, MS64
;   align
;      file
;       dup
;        display
;    label
;      as
;         a used b
;   a defined b
;        a public b
;         a times b
;  a at b
;     a from b
;   a rva b
;   note
;        logical expressions (e.g. a eq b, ~ a eq b, c & b, a|b) cannot eqtyped because they are
;        executed before the eqtype  ('if logical expression eqtype...')    

And for comparison: the preprocessor directive match
Code:
;match expands equates immediately
;        matches quoted strings, ~ & | + - / * : () {} [] <> exactly
;        space and tab are delimeters
;       @ ^ $ % . _ ? ! etc are alphanumeric and are not matched specifically    
Post 24 Dec 2008, 06:39
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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.