* as/z80/z80mch.c: fixed bug #1704376: missing as-z80 errors
[fw/sdcc] / doc / macro-sys-design.txt
1 Macro system design
2 $Id$
3
4 The purposes of the macro system are:
5 1.  Provide a way to target other assemblers than asxxxx, such as the
6 GB IAR or rgbds assemblers.
7 2.  Provide a way to target multiple similar processors at a relatively
8 simple level from one backend, such as the gbz80 and z80.
9 3.  Provide a way to dynamically build a command line for any spawned
10 processes.
11 4.  Provide a way for the backend to conveniently access volatile global data
12 such as the source file name or current function name.  This is mainly
13 to get around assembler limitations.
14
15 Examples are:
16 1.  Different assemblers use different forms for immediate values.
17  Compare:
18             ld a,#0x00
19             ld a,$00
20             ld a,#$00
21     Different assemblers use different forms for certain constructs.
22  Compare:
23             .ds 2
24             DS  2
25             DEFS 2
26
27 2.  Some concepts, such as prolog and epilogue can be combined.  
28  Compare:
29             push        ix
30             ld          ix,#0
31             add         ix,sp
32
33             ld          hl,0(sp)
34
35 3.  Various paths such as include or library paths may change at run
36 time.
37
38 4.  Need to use the function name in a temporary variable name as the
39 assembler doesn't support temporary local labels
40  Compare:
41             1$:
42             _func_0001:
43
44 Types of data:
45 1.  Static for a given starting set of parameters, such as target
46 assembler or path
47
48           {zero}        -> #0, $0, 0x00
49           {sdccinclude} -> c:/sdcc/include, /usr/share/sdcc/include
50
51 2.  Static for a given starting set of parameters, but include
52 arguments inside them
53
54           {immeda}       -> #0x%02X, $%02X
55           {areaa}        -> .area %s, SECTION "%s"
56
57 3.  Volatile throughout the run time with no parameters
58
59           {currfuncv}    -> _func
60
61 4.  Volatile with arguments
62           {templabeldef} -> {currfuncv}_%d:
63
64 Rules:
65 1.  Macros are surrounded by curly braces {}.  
66 2.  Curly braces cannot appear in any data.
67 3.  Macros will be recursively expanded.  The expansion cannot be
68 cyclic.
69 4.  Macros used as values to arguments will be recursively expanded.
70 Any macros used as argument values cannot require arguments.  If they
71 do the arguments will not be evaluated.
72
73 Problems:
74 1.  There is no type checking or usage checking due to things being
75 evaluated at run time.  This could be verified by using a separate
76 perl script to statically evaluate the strings.
77
78 -- Michael
79