annotate lwasm/pragma.c @ 325:619fd6ad4ab9

Completed command line parsing
author lost
date Sat, 13 Feb 2010 05:20:55 +0000
parents
children f5b77989f675
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
325
619fd6ad4ab9 Completed command line parsing
lost
parents:
diff changeset
1 /*
619fd6ad4ab9 Completed command line parsing
lost
parents:
diff changeset
2 pragma.c
619fd6ad4ab9 Completed command line parsing
lost
parents:
diff changeset
3
619fd6ad4ab9 Completed command line parsing
lost
parents:
diff changeset
4 Copyright © 2010 William Astle
619fd6ad4ab9 Completed command line parsing
lost
parents:
diff changeset
5
619fd6ad4ab9 Completed command line parsing
lost
parents:
diff changeset
6 This file is part of LWTOOLS.
619fd6ad4ab9 Completed command line parsing
lost
parents:
diff changeset
7
619fd6ad4ab9 Completed command line parsing
lost
parents:
diff changeset
8 LWTOOLS is free software: you can redistribute it and/or modify it under the
619fd6ad4ab9 Completed command line parsing
lost
parents:
diff changeset
9 terms of the GNU General Public License as published by the Free Software
619fd6ad4ab9 Completed command line parsing
lost
parents:
diff changeset
10 Foundation, either version 3 of the License, or (at your option) any later
619fd6ad4ab9 Completed command line parsing
lost
parents:
diff changeset
11 version.
619fd6ad4ab9 Completed command line parsing
lost
parents:
diff changeset
12
619fd6ad4ab9 Completed command line parsing
lost
parents:
diff changeset
13 This program is distributed in the hope that it will be useful, but WITHOUT
619fd6ad4ab9 Completed command line parsing
lost
parents:
diff changeset
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
619fd6ad4ab9 Completed command line parsing
lost
parents:
diff changeset
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
619fd6ad4ab9 Completed command line parsing
lost
parents:
diff changeset
16 more details.
619fd6ad4ab9 Completed command line parsing
lost
parents:
diff changeset
17
619fd6ad4ab9 Completed command line parsing
lost
parents:
diff changeset
18 You should have received a copy of the GNU General Public License along with
619fd6ad4ab9 Completed command line parsing
lost
parents:
diff changeset
19 this program. If not, see <http://www.gnu.org/licenses/>.
619fd6ad4ab9 Completed command line parsing
lost
parents:
diff changeset
20 */
619fd6ad4ab9 Completed command line parsing
lost
parents:
diff changeset
21
619fd6ad4ab9 Completed command line parsing
lost
parents:
diff changeset
22 #include <config.h>
619fd6ad4ab9 Completed command line parsing
lost
parents:
diff changeset
23
619fd6ad4ab9 Completed command line parsing
lost
parents:
diff changeset
24 #include <lw_string.h>
619fd6ad4ab9 Completed command line parsing
lost
parents:
diff changeset
25
619fd6ad4ab9 Completed command line parsing
lost
parents:
diff changeset
26 #include "lwasm.h"
619fd6ad4ab9 Completed command line parsing
lost
parents:
diff changeset
27
619fd6ad4ab9 Completed command line parsing
lost
parents:
diff changeset
28 struct pragma_list
619fd6ad4ab9 Completed command line parsing
lost
parents:
diff changeset
29 {
619fd6ad4ab9 Completed command line parsing
lost
parents:
diff changeset
30 const char *str;
619fd6ad4ab9 Completed command line parsing
lost
parents:
diff changeset
31 int flag;
619fd6ad4ab9 Completed command line parsing
lost
parents:
diff changeset
32 };
619fd6ad4ab9 Completed command line parsing
lost
parents:
diff changeset
33
619fd6ad4ab9 Completed command line parsing
lost
parents:
diff changeset
34 static const struct pragma_list set_pragmas[] =
619fd6ad4ab9 Completed command line parsing
lost
parents:
diff changeset
35 {
619fd6ad4ab9 Completed command line parsing
lost
parents:
diff changeset
36 { "dollarnotlocal", PRAGMA_DOLLARNOTLOCAL },
619fd6ad4ab9 Completed command line parsing
lost
parents:
diff changeset
37 { "noindex0tonone", PRAGMA_NOINDEX0TONONE },
619fd6ad4ab9 Completed command line parsing
lost
parents:
diff changeset
38 { "undefextern", PRAGMA_UNDEFEXTERN },
619fd6ad4ab9 Completed command line parsing
lost
parents:
diff changeset
39 { "cescapes", PRAGMA_CESCAPES },
619fd6ad4ab9 Completed command line parsing
lost
parents:
diff changeset
40 { "importundefexport", PRAGMA_IMPORTUNDEFEXPORT },
619fd6ad4ab9 Completed command line parsing
lost
parents:
diff changeset
41 { 0, 0 }
619fd6ad4ab9 Completed command line parsing
lost
parents:
diff changeset
42 };
619fd6ad4ab9 Completed command line parsing
lost
parents:
diff changeset
43
619fd6ad4ab9 Completed command line parsing
lost
parents:
diff changeset
44 static const struct pragma_list reset_pragmas[] =
619fd6ad4ab9 Completed command line parsing
lost
parents:
diff changeset
45 {
619fd6ad4ab9 Completed command line parsing
lost
parents:
diff changeset
46 { "nodollarnotlocal", PRAGMA_DOLLARNOTLOCAL },
619fd6ad4ab9 Completed command line parsing
lost
parents:
diff changeset
47 { "index0tonone", PRAGMA_NOINDEX0TONONE },
619fd6ad4ab9 Completed command line parsing
lost
parents:
diff changeset
48 { "noundefextern", PRAGMA_UNDEFEXTERN },
619fd6ad4ab9 Completed command line parsing
lost
parents:
diff changeset
49 { "nocescapes", PRAGMA_CESCAPES },
619fd6ad4ab9 Completed command line parsing
lost
parents:
diff changeset
50 { "noimportundefexport", PRAGMA_IMPORTUNDEFEXPORT },
619fd6ad4ab9 Completed command line parsing
lost
parents:
diff changeset
51 { 0, 0 }
619fd6ad4ab9 Completed command line parsing
lost
parents:
diff changeset
52 };
619fd6ad4ab9 Completed command line parsing
lost
parents:
diff changeset
53
619fd6ad4ab9 Completed command line parsing
lost
parents:
diff changeset
54 int parse_pragma_string(asmstate_t *as, char *str)
619fd6ad4ab9 Completed command line parsing
lost
parents:
diff changeset
55 {
619fd6ad4ab9 Completed command line parsing
lost
parents:
diff changeset
56 char *p;
619fd6ad4ab9 Completed command line parsing
lost
parents:
diff changeset
57 int i;
619fd6ad4ab9 Completed command line parsing
lost
parents:
diff changeset
58 const char *np = str;
619fd6ad4ab9 Completed command line parsing
lost
parents:
diff changeset
59 int pragmas = as -> pragmas;
619fd6ad4ab9 Completed command line parsing
lost
parents:
diff changeset
60
619fd6ad4ab9 Completed command line parsing
lost
parents:
diff changeset
61 while (np)
619fd6ad4ab9 Completed command line parsing
lost
parents:
diff changeset
62 {
619fd6ad4ab9 Completed command line parsing
lost
parents:
diff changeset
63 p = lw_token(np, ',', &np);
619fd6ad4ab9 Completed command line parsing
lost
parents:
diff changeset
64 for (i = 0; set_pragmas[i].str; i++)
619fd6ad4ab9 Completed command line parsing
lost
parents:
diff changeset
65 {
619fd6ad4ab9 Completed command line parsing
lost
parents:
diff changeset
66 if (!strcasecmp(p, set_pragmas[i].str))
619fd6ad4ab9 Completed command line parsing
lost
parents:
diff changeset
67 {
619fd6ad4ab9 Completed command line parsing
lost
parents:
diff changeset
68 pragmas |= set_pragmas[i].flag;
619fd6ad4ab9 Completed command line parsing
lost
parents:
diff changeset
69 goto out;
619fd6ad4ab9 Completed command line parsing
lost
parents:
diff changeset
70 }
619fd6ad4ab9 Completed command line parsing
lost
parents:
diff changeset
71 }
619fd6ad4ab9 Completed command line parsing
lost
parents:
diff changeset
72 for (i = 0; reset_pragmas[i].str; i++)
619fd6ad4ab9 Completed command line parsing
lost
parents:
diff changeset
73 {
619fd6ad4ab9 Completed command line parsing
lost
parents:
diff changeset
74 if (!strcasecmp(p, reset_pragmas[i].str))
619fd6ad4ab9 Completed command line parsing
lost
parents:
diff changeset
75 {
619fd6ad4ab9 Completed command line parsing
lost
parents:
diff changeset
76 pragmas &= ~(reset_pragmas[i].flag);
619fd6ad4ab9 Completed command line parsing
lost
parents:
diff changeset
77 goto out;
619fd6ad4ab9 Completed command line parsing
lost
parents:
diff changeset
78 }
619fd6ad4ab9 Completed command line parsing
lost
parents:
diff changeset
79 }
619fd6ad4ab9 Completed command line parsing
lost
parents:
diff changeset
80 /* unrecognized pragma here */
619fd6ad4ab9 Completed command line parsing
lost
parents:
diff changeset
81 lw_free(p);
619fd6ad4ab9 Completed command line parsing
lost
parents:
diff changeset
82 return 0;
619fd6ad4ab9 Completed command line parsing
lost
parents:
diff changeset
83
619fd6ad4ab9 Completed command line parsing
lost
parents:
diff changeset
84 out:
619fd6ad4ab9 Completed command line parsing
lost
parents:
diff changeset
85 lw_free(p);
619fd6ad4ab9 Completed command line parsing
lost
parents:
diff changeset
86 }
619fd6ad4ab9 Completed command line parsing
lost
parents:
diff changeset
87 as -> pragmas = pragmas;
619fd6ad4ab9 Completed command line parsing
lost
parents:
diff changeset
88 return 1;
619fd6ad4ab9 Completed command line parsing
lost
parents:
diff changeset
89 }