Mercurial > hg > index.cgi
comparison lwasm/pragma.c @ 0:2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
author | lost@l-w.ca |
---|---|
date | Wed, 19 Jan 2011 22:27:17 -0700 |
parents | |
children | 7317fbe024af |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:2c24602be78f |
---|---|
1 /* | |
2 pragma.c | |
3 | |
4 Copyright © 2010 William Astle | |
5 | |
6 This file is part of LWTOOLS. | |
7 | |
8 LWTOOLS is free software: you can redistribute it and/or modify it under the | |
9 terms of the GNU General Public License as published by the Free Software | |
10 Foundation, either version 3 of the License, or (at your option) any later | |
11 version. | |
12 | |
13 This program is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
16 more details. | |
17 | |
18 You should have received a copy of the GNU General Public License along with | |
19 this program. If not, see <http://www.gnu.org/licenses/>. | |
20 */ | |
21 | |
22 #include <lw_string.h> | |
23 | |
24 #include "lwasm.h" | |
25 #include "instab.h" | |
26 | |
27 struct pragma_list | |
28 { | |
29 const char *str; | |
30 int flag; | |
31 }; | |
32 | |
33 static const struct pragma_list set_pragmas[] = | |
34 { | |
35 { "dollarnotlocal", PRAGMA_DOLLARNOTLOCAL }, | |
36 { "noindex0tonone", PRAGMA_NOINDEX0TONONE }, | |
37 { "undefextern", PRAGMA_UNDEFEXTERN }, | |
38 { "cescapes", PRAGMA_CESCAPES }, | |
39 { "importundefexport", PRAGMA_IMPORTUNDEFEXPORT }, | |
40 { "pcaspcr", PRAGMA_PCASPCR }, | |
41 { 0, 0 } | |
42 }; | |
43 | |
44 static const struct pragma_list reset_pragmas[] = | |
45 { | |
46 { "nodollarnotlocal", PRAGMA_DOLLARNOTLOCAL }, | |
47 { "index0tonone", PRAGMA_NOINDEX0TONONE }, | |
48 { "noundefextern", PRAGMA_UNDEFEXTERN }, | |
49 { "nocescapes", PRAGMA_CESCAPES }, | |
50 { "noimportundefexport", PRAGMA_IMPORTUNDEFEXPORT }, | |
51 { "nopcaspcr", PRAGMA_PCASPCR }, | |
52 { 0, 0 } | |
53 }; | |
54 | |
55 int parse_pragma_string(asmstate_t *as, char *str, int ignoreerr) | |
56 { | |
57 char *p; | |
58 int i; | |
59 const char *np = str; | |
60 int pragmas = as -> pragmas; | |
61 | |
62 while (np) | |
63 { | |
64 p = lw_token(np, ',', &np); | |
65 for (i = 0; set_pragmas[i].str; i++) | |
66 { | |
67 if (!strcasecmp(p, set_pragmas[i].str)) | |
68 { | |
69 pragmas |= set_pragmas[i].flag; | |
70 goto out; | |
71 } | |
72 } | |
73 for (i = 0; reset_pragmas[i].str; i++) | |
74 { | |
75 if (!strcasecmp(p, reset_pragmas[i].str)) | |
76 { | |
77 pragmas &= ~(reset_pragmas[i].flag); | |
78 goto out; | |
79 } | |
80 } | |
81 /* unrecognized pragma here */ | |
82 if (!ignoreerr) | |
83 { | |
84 lw_free(p); | |
85 return 0; | |
86 } | |
87 out: | |
88 lw_free(p); | |
89 } | |
90 as -> pragmas = pragmas; | |
91 return 1; | |
92 } | |
93 | |
94 PARSEFUNC(pseudo_parse_pragma) | |
95 { | |
96 char *ps, *t; | |
97 | |
98 for (t = *p; *t && !isspace(*t); t++) | |
99 /* do nothing */ ; | |
100 | |
101 ps = lw_strndup(*p, t - *p); | |
102 *p = t; | |
103 | |
104 if (parse_pragma_string(as, ps, 0) == 0) | |
105 { | |
106 lwasm_register_error(as, l, "Unrecognized pragma string"); | |
107 } | |
108 lw_free(ps); | |
109 } | |
110 | |
111 PARSEFUNC(pseudo_parse_starpragma) | |
112 { | |
113 char *ps, *t; | |
114 | |
115 for (t = *p; *t && !isspace(*t); t++) | |
116 /* do nothing */ ; | |
117 | |
118 ps = lw_strndup(*p, t - *p); | |
119 *p = t; | |
120 | |
121 // *pragma must NEVER throw an error | |
122 parse_pragma_string(as, ps, 1); | |
123 lw_free(ps); | |
124 } |