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 },
|
|
42 { 0, 0 }
|
|
43 };
|
|
44
|
|
45 static const struct pragma_list reset_pragmas[] =
|
|
46 {
|
|
47 { "nodollarnotlocal", PRAGMA_DOLLARNOTLOCAL },
|
|
48 { "index0tonone", PRAGMA_NOINDEX0TONONE },
|
|
49 { "noundefextern", PRAGMA_UNDEFEXTERN },
|
|
50 { "nocescapes", PRAGMA_CESCAPES },
|
|
51 { "noimportundefexport", PRAGMA_IMPORTUNDEFEXPORT },
|
|
52 { 0, 0 }
|
|
53 };
|
|
54
|
352
|
55 int parse_pragma_string(asmstate_t *as, char *str, int ignoreerr)
|
325
|
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 */
|
352
|
82 if (!ignoreerr)
|
|
83 {
|
|
84 lw_free(p);
|
|
85 return 0;
|
|
86 }
|
325
|
87 out:
|
|
88 lw_free(p);
|
|
89 }
|
|
90 as -> pragmas = pragmas;
|
|
91 return 1;
|
|
92 }
|
352
|
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 }
|