|
|
1.1 root 1: / Coherent 'as' macro for simplifying some aspects of structure and data type
2: / declaration. This facility uses the rich macro facilities of the Coherent
3: / 'as' assembler to ease interfacing of assembly language and C or C++, with
4: / some limitations. Do not expect this to work with any other assembler.
5:
6: / It would have been nice to actually have a notion of scope, but the macro
7: / facility in Coherent 'as', while better than most, is still an ad hoc kludge.
8: / Now, something more along Scheme lines...
9:
10: / Limitations:
11: / Only one structure may be declared at a time. Nested structures must
12: / be defined separately (and thus, must be given names).
13: / C as
14: / struct foo { .struct _internal
15: / struct { .ends _internal
16: / } a; .struct foo
17: / }; .member a,_internal
18: / .ends foo
19:
20: / Every C/C++ data item that we might want to declare an instance of has some
21: / special attributes; a type name, a size in bytes, and an alignment. An
22: / instance of a given type will also typically have an address.
23:
24: .extern .macro name,type
25: .globl name
26: SIZE.\name .equ SIZE..\type
27: ALIGN.\name .equ ALIGN..\type
28: .endm
29:
30: .declare .macro name,type
31: .comm name,SIZE..\type
32: SIZE.\name .equ SIZE..\type
33: ALIGN.\name .equ ALIGN..\type
34: .endm
35:
36: .deftype .macro name,size
37: SIZE..\name .equ size
38: ALIGN..\name .equ size
39: .endm
40:
41: .typedef .macro name,type
42: SIZE..\name .equ SIZE..\type
43: ALIGN..\name .equ ALIGN..\type
44: .endm
45:
46:
47: .deftype char,1
48: .deftype uchar,1
49: .deftype short,2
50: .deftype ushort,2
51: .deftype int,4
52: .deftype uint,4
53: .deftype long,4
54: .deftype ulong,4
55: .deftype ptr,4
56:
57: DEPTH .equ 0
58:
59: .struct .macro name
60: .if DEPTH
61: .fail Structure declarations cannot be nested
62: .endi
63: NAME .define ..\name
64: SIZE\NAME .equ 0
65: ALIGN\NAME .equ 0
66: DEPTH\NAME .equ 1
67: DEPTH .equ DEPTH + 1
68: .endm
69:
70: .member .macro name,type
71: .if DEPTH != 1
72: .fail .member needs to be inside .struct
73: .endi
74: .if .defined name
75: .fail member tag already in use
76: .endi
77: name .equ [SIZE\NAME + ALIGN..\type - 1] & - ALIGN..\type
78: SIZE\NAME .equ name + SIZE..\type
79: .if ALIGN\NAME < ALIGN..\type
80: ALIGN\NAME .equ ALIGN..\type
81: .endi
82: .endm
83:
84: / Implementation note; under Coherent 'as', .define symbols built within macros
85: / can never be removed, because lines beginning with the .define-suppression
86: / indicator '#' are actually never processed despite what the documentation
87: / says. Maybe this is how Charles "fixed" as for GCC.
88: / [ This has been reported, so maybe this will be changed. ]
89:
90: .ends .macro name
91: .if DEPTH != 1 | DEPTH != DEPTH..\name
92: .fail .ends needs to match .struct
93: .endi
94: DEPTH..\name .equ 0
95: DEPTH .equ DEPTH - 1
96: .endm
97:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.