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"
|
|
27
|
|
28 struct pragma_list
|
|
29 {
|
|
30 const char *str;
|
|
31 int flag;
|
|
32 };
|
|
33
|
|
34 static const struct pragma_list set_pragmas[] =
|
|
35 {
|
|
36 { "dollarnotlocal", PRAGMA_DOLLARNOTLOCAL },
|
|
37 { "noindex0tonone", PRAGMA_NOINDEX0TONONE },
|
|
38 { "undefextern", PRAGMA_UNDEFEXTERN },
|
|
39 { "cescapes", PRAGMA_CESCAPES },
|
|
40 { "importundefexport", PRAGMA_IMPORTUNDEFEXPORT },
|
|
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 { 0, 0 }
|
|
52 };
|
|
53
|
|
54 int parse_pragma_string(asmstate_t *as, char *str)
|
|
55 {
|
|
56 char *p;
|
|
57 int i;
|
|
58 const char *np = str;
|
|
59 int pragmas = as -> pragmas;
|
|
60
|
|
61 while (np)
|
|
62 {
|
|
63 p = lw_token(np, ',', &np);
|
|
64 for (i = 0; set_pragmas[i].str; i++)
|
|
65 {
|
|
66 if (!strcasecmp(p, set_pragmas[i].str))
|
|
67 {
|
|
68 pragmas |= set_pragmas[i].flag;
|
|
69 goto out;
|
|
70 }
|
|
71 }
|
|
72 for (i = 0; reset_pragmas[i].str; i++)
|
|
73 {
|
|
74 if (!strcasecmp(p, reset_pragmas[i].str))
|
|
75 {
|
|
76 pragmas &= ~(reset_pragmas[i].flag);
|
|
77 goto out;
|
|
78 }
|
|
79 }
|
|
80 /* unrecognized pragma here */
|
|
81 lw_free(p);
|
|
82 return 0;
|
|
83
|
|
84 out:
|
|
85 lw_free(p);
|
|
86 }
|
|
87 as -> pragmas = pragmas;
|
|
88 return 1;
|
|
89 }
|