Mercurial > hg > index.cgi
comparison lwasm/pragma.c @ 108:9960e05cbe3a
Added *pragmapush and *pragmapop; still seems to be nonfunctional
author | lost@l-w.ca |
---|---|
date | Sun, 07 Aug 2011 00:58:00 -0600 |
parents | 8fa52c3f2970 |
children | 38c1537857ce |
comparison
equal
deleted
inserted
replaced
107:b3557f8325f7 | 108:9960e05cbe3a |
---|---|
25 #include <lw_string.h> | 25 #include <lw_string.h> |
26 #include <lw_alloc.h> | 26 #include <lw_alloc.h> |
27 | 27 |
28 #include "lwasm.h" | 28 #include "lwasm.h" |
29 #include "instab.h" | 29 #include "instab.h" |
30 #include "input.h" | |
30 | 31 |
31 struct pragma_list | 32 struct pragma_list |
32 { | 33 { |
33 const char *str; | 34 const char *setstr; |
35 const char *resetstr; | |
34 int flag; | 36 int flag; |
35 }; | 37 }; |
36 | 38 |
39 struct pragma_stack_entry | |
40 { | |
41 int magic; // must always be at the start of any input stack entry | |
42 int flag; // the pragma flag bit | |
43 char str[1]; // magic number - this will be allocated bigger | |
44 // string will be what's needed to re-instate a pragma | |
45 }; | |
46 | |
37 static const struct pragma_list set_pragmas[] = | 47 static const struct pragma_list set_pragmas[] = |
38 { | 48 { |
39 { "dollarnotlocal", PRAGMA_DOLLARNOTLOCAL }, | 49 { "dollarnotlocal", "nodollarnotlocal", PRAGMA_DOLLARNOTLOCAL }, |
40 { "noindex0tonone", PRAGMA_NOINDEX0TONONE }, | 50 { "noindex0tonone", "index0tonone", PRAGMA_NOINDEX0TONONE }, |
41 { "undefextern", PRAGMA_UNDEFEXTERN }, | 51 { "undefextern", "noundefextern", PRAGMA_UNDEFEXTERN }, |
42 { "cescapes", PRAGMA_CESCAPES }, | 52 { "cescapes", "nocescapes", PRAGMA_CESCAPES }, |
43 { "importundefexport", PRAGMA_IMPORTUNDEFEXPORT }, | 53 { "importundefexport", "noimportundefexport", PRAGMA_IMPORTUNDEFEXPORT }, |
44 { "pcaspcr", PRAGMA_PCASPCR }, | 54 { "pcaspcr", "nopcaspcr", PRAGMA_PCASPCR }, |
45 { "shadow", PRAGMA_SHADOW }, | 55 { "shadow", "noshadow", PRAGMA_SHADOW }, |
46 { "nolist", PRAGMA_NOLIST }, | 56 { "nolist", "list", PRAGMA_NOLIST }, |
47 { 0, 0 } | 57 { 0, 0, 0} |
48 }; | |
49 | |
50 static const struct pragma_list reset_pragmas[] = | |
51 { | |
52 { "nodollarnotlocal", PRAGMA_DOLLARNOTLOCAL }, | |
53 { "index0tonone", PRAGMA_NOINDEX0TONONE }, | |
54 { "noundefextern", PRAGMA_UNDEFEXTERN }, | |
55 { "nocescapes", PRAGMA_CESCAPES }, | |
56 { "noimportundefexport", PRAGMA_IMPORTUNDEFEXPORT }, | |
57 { "nopcaspcr", PRAGMA_PCASPCR }, | |
58 { "noshadow", PRAGMA_SHADOW }, | |
59 { "list", PRAGMA_NOLIST }, | |
60 { 0, 0 } | |
61 }; | 58 }; |
62 | 59 |
63 int parse_pragma_string(asmstate_t *as, char *str, int ignoreerr) | 60 int parse_pragma_string(asmstate_t *as, char *str, int ignoreerr) |
64 { | 61 { |
65 char *p; | 62 char *p; |
68 int pragmas = as -> pragmas; | 65 int pragmas = as -> pragmas; |
69 | 66 |
70 while (np) | 67 while (np) |
71 { | 68 { |
72 p = lw_token(np, ',', &np); | 69 p = lw_token(np, ',', &np); |
73 for (i = 0; set_pragmas[i].str; i++) | 70 for (i = 0; set_pragmas[i].setstr; i++) |
74 { | 71 { |
75 if (!strcasecmp(p, set_pragmas[i].str)) | 72 if (!strcasecmp(p, set_pragmas[i].setstr)) |
76 { | 73 { |
77 pragmas |= set_pragmas[i].flag; | 74 pragmas |= set_pragmas[i].flag; |
78 goto out; | 75 goto out; |
79 } | 76 } |
80 } | 77 if (!strcasecmp(p, set_pragmas[i].resetstr)) |
81 for (i = 0; reset_pragmas[i].str; i++) | 78 { |
82 { | 79 pragmas &= ~(set_pragmas[i].flag); |
83 if (!strcasecmp(p, reset_pragmas[i].str)) | |
84 { | |
85 pragmas &= ~(reset_pragmas[i].flag); | |
86 goto out; | 80 goto out; |
87 } | 81 } |
88 } | 82 } |
89 /* unrecognized pragma here */ | 83 /* unrecognized pragma here */ |
90 if (!ignoreerr) | 84 if (!ignoreerr) |
136 parse_pragma_string(as, ps, 1); | 130 parse_pragma_string(as, ps, 1); |
137 if (as -> pragmas & PRAGMA_NOLIST) | 131 if (as -> pragmas & PRAGMA_NOLIST) |
138 l -> pragmas |= PRAGMA_NOLIST; | 132 l -> pragmas |= PRAGMA_NOLIST; |
139 lw_free(ps); | 133 lw_free(ps); |
140 } | 134 } |
135 | |
136 static int pragma_stack_compare(input_stack_entry *e, void *d) | |
137 { | |
138 int flag = *((int *)d); | |
139 struct pragma_stack_entry *pse = (struct pragma_stack_entry *)e; | |
140 | |
141 if (pse -> flag == flag) | |
142 return 1; | |
143 return 0; | |
144 } | |
145 | |
146 PARSEFUNC(pseudo_parse_starpragmapop) | |
147 { | |
148 char *ps, *t; | |
149 char *pp; | |
150 int i; | |
151 const char *np; | |
152 struct pragma_stack_entry *pse; | |
153 | |
154 for (t = *p; *t && !isspace(*t); t++) | |
155 /* do nothing */ ; | |
156 | |
157 ps = lw_strndup(*p, t - *p); | |
158 *p = t; | |
159 | |
160 l -> len = 0; | |
161 | |
162 // *pragma stuff must never throw an error | |
163 np = ps; | |
164 | |
165 while (np) | |
166 { | |
167 pp = lw_token(np, ',', &np); | |
168 for (i = 0; set_pragmas[i].setstr; i++) | |
169 { | |
170 if (!strcasecmp(pp, set_pragmas[i].setstr) || !strcasecmp(pp, set_pragmas[i].resetstr)) | |
171 { | |
172 pse = (struct pragma_stack_entry *)input_stack_pop(as, 0x42424242, pragma_stack_compare, (void *)&(set_pragmas[i].flag)); | |
173 if (pse) | |
174 { | |
175 parse_pragma_string(as, (char *)&(pse->str), 1); | |
176 lw_free(pse); | |
177 } | |
178 if (set_pragmas[i].flag == PRAGMA_NOLIST) | |
179 l -> pragmas |= PRAGMA_NOLIST; | |
180 } | |
181 } | |
182 lw_free(pp); | |
183 } | |
184 | |
185 lw_free(ps); | |
186 } | |
187 | |
188 PARSEFUNC(pseudo_parse_starpragmapush) | |
189 { | |
190 char *ps, *t; | |
191 char *pp; | |
192 int i; | |
193 const char *np; | |
194 struct pragma_stack_entry *pse; | |
195 | |
196 for (t = *p; *t && !isspace(*t); t++) | |
197 /* do nothing */ ; | |
198 | |
199 ps = lw_strndup(*p, t - *p); | |
200 *p = t; | |
201 | |
202 l -> len = 0; | |
203 | |
204 // *pragma stuff must never throw an error | |
205 np = ps; | |
206 | |
207 while (np) | |
208 { | |
209 pp = lw_token(np, ',', &np); | |
210 for (i = 0; set_pragmas[i].setstr; i++) | |
211 { | |
212 if (!strcasecmp(pp, set_pragmas[i].setstr) || !strcasecmp(pp, set_pragmas[i].resetstr)) | |
213 { | |
214 /* found set or reset pragma */ | |
215 /* push pragma state */ | |
216 if (as -> pragmas & (set_pragmas[i].flag)) | |
217 { | |
218 /* use set string */ | |
219 t = (char *)set_pragmas[i].setstr; | |
220 } | |
221 else | |
222 { | |
223 /* use reset string */ | |
224 t = (char *)set_pragmas[i].resetstr; | |
225 } | |
226 pse = lw_alloc(sizeof(struct pragma_stack_entry) + strlen(t)); | |
227 pse -> flag = set_pragmas[i].flag; | |
228 pse -> magic = 0x42424242; | |
229 strcpy((char *)&(pse -> str), t); | |
230 input_stack_push(as, (input_stack_entry *)pse); | |
231 | |
232 if (set_pragmas[i].flag == PRAGMA_NOLIST) | |
233 l -> pragmas |= PRAGMA_NOLIST; | |
234 } | |
235 } | |
236 lw_free(pp); | |
237 } | |
238 | |
239 lw_free(ps); | |
240 } | |
241 |