1 /* macro.c - expand macros for assembler */
13 Enter macro: stack macro and get its parameters.
14 Parameters form a linked list of null-terminated strings of form
15 next:string. The first string is the macro number in 4 bytes.
18 PUBLIC
void entermac(symptr
)
21 if (maclevel
>= MAXMAC
)
23 else if (macpar
+ 2 > macptop
)
24 error(PAROV
); /* no room for 0th param */
25 /* (2 structs to fit it!) */
29 struct schain_s
*param1
;
30 register char *reglineptr
;
31 register char *stringptr
;
34 (--macstak
)->text
= (char *) symptr
->value_reg_or_op
.value
;
35 macstak
->parameters
= param1
= macpar
;
36 param1
->next
= NUL_PTR
;
37 *(stringptr
= build_number(++macnum
, 3, param1
->string
)) = 0;
38 macpar
= (struct schain_s
*) (stringptr
+ 1);
42 return; /* no other params */
47 stringptr
= macpar
->string
;
50 if (stringptr
>= (char *) macptop
)
58 /* escaped means no special meaning for slash, comma, paren */
60 else if (ch
== ',' || ch
== ')' || ch
== '!' || ch
== ';'
61 || ch
== '\n' || ch
== 0)
63 if (stringptr
>= (char *) macptop
)
66 error(PAROV
); /* no room for null */
70 param1
->next
= macpar
; /* ptr from previous */
71 (param1
= macpar
)->next
= NUL_PTR
;
72 /* this goes nowhere */
73 macpar
= (struct schain_s
*) (stringptr
+ 1);
74 /* but is finished OK - TODO align */
75 stringptr
= macpar
->string
;
80 if ((*stringptr
++ = ch
) == 0)
96 struct sym_s
*symptr
=0;
99 char * macbuf
= asalloc(8);
101 saving
= /* prepare for bad macro */
102 savingc
= FALSE
; /* normally don't save comments */
103 macload
= TRUE
; /* show loading */
104 if (label
!= NUL_PTR
)
106 else if (sym
!= IDENT
)
111 if (symptr
->type
& MNREGBIT
)
113 else if (symptr
->type
& LABIT
|| symptr
->data
& FORBIT
)
115 else if (pass
!= last_pass
|| symptr
->type
& REDBIT
)
116 /* copy on pass 0, also pass 1 if redefined */
119 if (symptr
->type
& MACBIT
)
120 symptr
->type
|= REDBIT
;
122 symptr
->type
|= MACBIT
;
123 symptr
->data
= UNDBIT
; /* undefined till end */
124 symptr
->value_reg_or_op
.value
= (offset_t
) macbuf
;
125 getsym_nolookup(); /* test for "C" */
126 if (sym
== IDENT
&& lineptr
== symname
+ 1 && *symname
== 'C')
136 break; /* macload cleared to show eof */
140 if (lineptr
== symname
+ 4 &&
141 ( strncmp(symname
, "MEND", 4) == 0 || strncmp(symname
, "mend", 4) == 0) )
147 else if (sym
!= MACROARG
)
150 continue; /* don't save comment */
155 char * p
= strchr(linebuf
, EOLCHAR
);
156 int len
= (p
-linebuf
+1);
158 if ( macoff
+ len
> maclen
-4 )
160 maclen
= maclen
* 2 + len
;
161 macbuf
= asrealloc(macbuf
, maclen
);
163 memcpy(macbuf
+macoff
, linebuf
, len
);
171 macbuf
[macoff
] = ETB
;
172 symptr
->value_reg_or_op
.value
= (offset_t
) macbuf
;