Mercurial > hg-old > index.cgi
annotate lwasm/pragma.c @ 442:a9521955554f 3.0
Added pragma pcaspcr to treat PC as PCR; additional fixes for PCR addressing modes
author | lost@l-w.ca |
---|---|
date | Sat, 30 Oct 2010 12:15:00 -0600 |
parents | f5b77989f675 |
children |
rev | line source |
---|---|
325 | 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 <config.h> | |
23 | |
24 #include <lw_string.h> | |
25 | |
26 #include "lwasm.h" | |
352 | 27 #include "instab.h" |
325 | 28 |
29 struct pragma_list | |
30 { | |
31 const char *str; | |
32 int flag; | |
33 }; | |
34 | |
35 static const struct pragma_list set_pragmas[] = | |
36 { | |
37 { "dollarnotlocal", PRAGMA_DOLLARNOTLOCAL }, | |
38 { "noindex0tonone", PRAGMA_NOINDEX0TONONE }, | |
39 { "undefextern", PRAGMA_UNDEFEXTERN }, | |
40 { "cescapes", PRAGMA_CESCAPES }, | |
41 { "importundefexport", PRAGMA_IMPORTUNDEFEXPORT }, | |
442
a9521955554f
Added pragma pcaspcr to treat PC as PCR; additional fixes for PCR addressing modes
lost@l-w.ca
parents:
352
diff
changeset
|
42 { "pcaspcr", PRAGMA_PCASPCR }, |
325 | 43 { 0, 0 } |
44 }; | |
45 | |
46 static const struct pragma_list reset_pragmas[] = | |
47 { | |
48 { "nodollarnotlocal", PRAGMA_DOLLARNOTLOCAL }, | |
49 { "index0tonone", PRAGMA_NOINDEX0TONONE }, | |
50 { "noundefextern", PRAGMA_UNDEFEXTERN }, | |
51 { "nocescapes", PRAGMA_CESCAPES }, | |
52 { "noimportundefexport", PRAGMA_IMPORTUNDEFEXPORT }, | |
442
a9521955554f
Added pragma pcaspcr to treat PC as PCR; additional fixes for PCR addressing modes
lost@l-w.ca
parents:
352
diff
changeset
|
53 { "nopcaspcr", PRAGMA_PCASPCR }, |
325 | 54 { 0, 0 } |
55 }; | |
56 | |
352 | 57 int parse_pragma_string(asmstate_t *as, char *str, int ignoreerr) |
325 | 58 { |
59 char *p; | |
60 int i; | |
61 const char *np = str; | |
62 int pragmas = as -> pragmas; | |
63 | |
64 while (np) | |
65 { | |
66 p = lw_token(np, ',', &np); | |
67 for (i = 0; set_pragmas[i].str; i++) | |
68 { | |
69 if (!strcasecmp(p, set_pragmas[i].str)) | |
70 { | |
71 pragmas |= set_pragmas[i].flag; | |
72 goto out; | |
73 } | |
74 } | |
75 for (i = 0; reset_pragmas[i].str; i++) | |
76 { | |
77 if (!strcasecmp(p, reset_pragmas[i].str)) | |
78 { | |
79 pragmas &= ~(reset_pragmas[i].flag); | |
80 goto out; | |
81 } | |
82 } | |
83 /* unrecognized pragma here */ | |
352 | 84 if (!ignoreerr) |
85 { | |
86 lw_free(p); | |
87 return 0; | |
88 } | |
325 | 89 out: |
90 lw_free(p); | |
91 } | |
92 as -> pragmas = pragmas; | |
93 return 1; | |
94 } | |
352 | 95 |
96 PARSEFUNC(pseudo_parse_pragma) | |
97 { | |
98 char *ps, *t; | |
99 | |
100 for (t = *p; *t && !isspace(*t); t++) | |
101 /* do nothing */ ; | |
102 | |
103 ps = lw_strndup(*p, t - *p); | |
104 *p = t; | |
105 | |
106 if (parse_pragma_string(as, ps, 0) == 0) | |
107 { | |
108 lwasm_register_error(as, l, "Unrecognized pragma string"); | |
109 } | |
110 lw_free(ps); | |
111 } | |
112 | |
113 PARSEFUNC(pseudo_parse_starpragma) | |
114 { | |
115 char *ps, *t; | |
116 | |
117 for (t = *p; *t && !isspace(*t); t++) | |
118 /* do nothing */ ; | |
119 | |
120 ps = lw_strndup(*p, t - *p); | |
121 *p = t; | |
122 | |
123 // *pragma must NEVER throw an error | |
124 parse_pragma_string(as, ps, 1); | |
125 lw_free(ps); | |
126 } |