Mercurial > hg-old > index.cgi
annotate lwasm/pragma.c @ 259:c3a34f820893 2.x
Added asprintf redux
author | lost |
---|---|
date | Tue, 22 Dec 2009 05:53:25 +0000 |
parents | a58f49a77441 |
children |
rev | line source |
---|---|
0 | 1 /* |
4
34568fab6058
Fixed package to include all required files; also added copyright preamble to all source files
lost
parents:
0
diff
changeset
|
2 pragma.c |
34568fab6058
Fixed package to include all required files; also added copyright preamble to all source files
lost
parents:
0
diff
changeset
|
3 Copyright © 2008 William Astle |
34568fab6058
Fixed package to include all required files; also added copyright preamble to all source files
lost
parents:
0
diff
changeset
|
4 |
34568fab6058
Fixed package to include all required files; also added copyright preamble to all source files
lost
parents:
0
diff
changeset
|
5 This file is part of LWASM. |
34568fab6058
Fixed package to include all required files; also added copyright preamble to all source files
lost
parents:
0
diff
changeset
|
6 |
34568fab6058
Fixed package to include all required files; also added copyright preamble to all source files
lost
parents:
0
diff
changeset
|
7 LWASM is free software: you can redistribute it and/or modify it under the |
34568fab6058
Fixed package to include all required files; also added copyright preamble to all source files
lost
parents:
0
diff
changeset
|
8 terms of the GNU General Public License as published by the Free Software |
34568fab6058
Fixed package to include all required files; also added copyright preamble to all source files
lost
parents:
0
diff
changeset
|
9 Foundation, either version 3 of the License, or (at your option) any later |
34568fab6058
Fixed package to include all required files; also added copyright preamble to all source files
lost
parents:
0
diff
changeset
|
10 version. |
34568fab6058
Fixed package to include all required files; also added copyright preamble to all source files
lost
parents:
0
diff
changeset
|
11 |
34568fab6058
Fixed package to include all required files; also added copyright preamble to all source files
lost
parents:
0
diff
changeset
|
12 This program is distributed in the hope that it will be useful, but WITHOUT |
34568fab6058
Fixed package to include all required files; also added copyright preamble to all source files
lost
parents:
0
diff
changeset
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
34568fab6058
Fixed package to include all required files; also added copyright preamble to all source files
lost
parents:
0
diff
changeset
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
34568fab6058
Fixed package to include all required files; also added copyright preamble to all source files
lost
parents:
0
diff
changeset
|
15 more details. |
34568fab6058
Fixed package to include all required files; also added copyright preamble to all source files
lost
parents:
0
diff
changeset
|
16 |
34568fab6058
Fixed package to include all required files; also added copyright preamble to all source files
lost
parents:
0
diff
changeset
|
17 You should have received a copy of the GNU General Public License along with |
34568fab6058
Fixed package to include all required files; also added copyright preamble to all source files
lost
parents:
0
diff
changeset
|
18 this program. If not, see <http://www.gnu.org/licenses/>. |
34568fab6058
Fixed package to include all required files; also added copyright preamble to all source files
lost
parents:
0
diff
changeset
|
19 |
34568fab6058
Fixed package to include all required files; also added copyright preamble to all source files
lost
parents:
0
diff
changeset
|
20 |
34568fab6058
Fixed package to include all required files; also added copyright preamble to all source files
lost
parents:
0
diff
changeset
|
21 This file contains stuff associated with lwasm specific strangeness |
34568fab6058
Fixed package to include all required files; also added copyright preamble to all source files
lost
parents:
0
diff
changeset
|
22 */ |
212 | 23 #include <config.h> |
0 | 24 #include <ctype.h> |
25 #include <stdlib.h> | |
26 #include <string.h> | |
27 #include "lwasm.h" | |
73 | 28 #include "instab.h" |
0 | 29 |
30 /* | |
31 A pragma is a means of controlling code generation. | |
32 | |
33 The pseudo op "*pragma" which will be treated as a comment by an assembler | |
34 that doesn't recognize it and thus will not cause assembly errors. This is | |
35 the preferred way of flagging a pragma if it will not cause incorrect | |
36 execution of the program. | |
37 | |
38 The pseudo op "pragma" which will cause an error on an assembler that does | |
39 not understand it. | |
40 | |
41 In the case of "*pragma", unrecognized pragmas MUST be silently ignored. In | |
42 the case of "pragma", unrecognized pragmas should raise an error. | |
43 | |
44 LWASM understands the following pragmas: | |
45 | |
46 index0tonone | |
47 noindex0tonone | |
48 | |
49 When set (index0tonone), an expression that evaluates to 0, other than a | |
50 bare constant, in a <offset>,r operand will cause the code for ",r" to be | |
51 emitted rather than "0,r". If not set (noindex0tonone), the "0,r" output | |
52 will be emitted. The default is to perform the optimization. | |
53 | |
54 This particular optimization will save a cycle for a direct operation. For | |
55 an indirect operation, however, it will save several cycles and a program byte | |
56 which may be very useful. | |
57 */ | |
58 | |
73 | 59 void pseudo_pragma_real(asmstate_t *as, lwasm_line_t *cl, char **optr, int error) |
0 | 60 { |
61 char pragma[128]; | |
62 int c = 0; | |
63 | |
200 | 64 while (**optr && isspace(**optr)) |
0 | 65 (*optr)++; |
165
566943f98f8d
Made pragma actually take multiple pragmas on one line
lost
parents:
160
diff
changeset
|
66 |
566943f98f8d
Made pragma actually take multiple pragmas on one line
lost
parents:
160
diff
changeset
|
67 pragmaagain: |
566943f98f8d
Made pragma actually take multiple pragmas on one line
lost
parents:
160
diff
changeset
|
68 c = 0; |
566943f98f8d
Made pragma actually take multiple pragmas on one line
lost
parents:
160
diff
changeset
|
69 while (c < 127 && **optr && **optr != ',' && !isspace(**optr)) |
0 | 70 { |
71 pragma[c++] = **optr; | |
72 (*optr)++; | |
73 } | |
74 | |
165
566943f98f8d
Made pragma actually take multiple pragmas on one line
lost
parents:
160
diff
changeset
|
75 if (c == 0 || (**optr && **optr != ',' && !isspace(**optr))) |
0 | 76 { |
77 if (error) | |
73 | 78 { |
79 register_error(as, cl, 1, "Unrecognized pragma"); | |
80 } | |
143
0ee5f65bccf9
Added pragma to allow all undefined symbols to be considered external and also added a --pragma command line option
lost
parents:
73
diff
changeset
|
81 if (error == 2) |
0ee5f65bccf9
Added pragma to allow all undefined symbols to be considered external and also added a --pragma command line option
lost
parents:
73
diff
changeset
|
82 { |
0ee5f65bccf9
Added pragma to allow all undefined symbols to be considered external and also added a --pragma command line option
lost
parents:
73
diff
changeset
|
83 *optr = NULL; |
0ee5f65bccf9
Added pragma to allow all undefined symbols to be considered external and also added a --pragma command line option
lost
parents:
73
diff
changeset
|
84 } |
0 | 85 return; |
86 } | |
87 pragma[c] = 0; | |
144 | 88 if (!strcasecmp(pragma, "noindex0tonone")) |
0 | 89 { |
90 as -> pragmas |= PRAGMA_NOINDEX0TONONE; | |
91 } | |
144 | 92 else if (!strcasecmp(pragma, "index0tonone")) |
0 | 93 { |
94 as -> pragmas &= ~PRAGMA_NOINDEX0TONONE; | |
95 } | |
144 | 96 else if (!strcasecmp(pragma, "undefextern")) |
143
0ee5f65bccf9
Added pragma to allow all undefined symbols to be considered external and also added a --pragma command line option
lost
parents:
73
diff
changeset
|
97 { |
0ee5f65bccf9
Added pragma to allow all undefined symbols to be considered external and also added a --pragma command line option
lost
parents:
73
diff
changeset
|
98 as -> pragmas |= PRAGMA_UNDEFEXTERN; |
0ee5f65bccf9
Added pragma to allow all undefined symbols to be considered external and also added a --pragma command line option
lost
parents:
73
diff
changeset
|
99 } |
144 | 100 else if (!strcasecmp(pragma, "noundefextern")) |
143
0ee5f65bccf9
Added pragma to allow all undefined symbols to be considered external and also added a --pragma command line option
lost
parents:
73
diff
changeset
|
101 { |
0ee5f65bccf9
Added pragma to allow all undefined symbols to be considered external and also added a --pragma command line option
lost
parents:
73
diff
changeset
|
102 as -> pragmas &= ~PRAGMA_UNDEFEXTERN; |
0ee5f65bccf9
Added pragma to allow all undefined symbols to be considered external and also added a --pragma command line option
lost
parents:
73
diff
changeset
|
103 } |
160
b061350c17e4
Added cescapes pragma and a few other compatibility pseudo ops
lost
parents:
151
diff
changeset
|
104 else if (!strcasecmp(pragma, "cescapes")) |
b061350c17e4
Added cescapes pragma and a few other compatibility pseudo ops
lost
parents:
151
diff
changeset
|
105 { |
b061350c17e4
Added cescapes pragma and a few other compatibility pseudo ops
lost
parents:
151
diff
changeset
|
106 as -> pragmas |= PRAGMA_CESCAPES; |
b061350c17e4
Added cescapes pragma and a few other compatibility pseudo ops
lost
parents:
151
diff
changeset
|
107 } |
b061350c17e4
Added cescapes pragma and a few other compatibility pseudo ops
lost
parents:
151
diff
changeset
|
108 else if (!strcasecmp(pragma, "nocescapes")) |
b061350c17e4
Added cescapes pragma and a few other compatibility pseudo ops
lost
parents:
151
diff
changeset
|
109 { |
b061350c17e4
Added cescapes pragma and a few other compatibility pseudo ops
lost
parents:
151
diff
changeset
|
110 as -> pragmas &= ~PRAGMA_CESCAPES; |
b061350c17e4
Added cescapes pragma and a few other compatibility pseudo ops
lost
parents:
151
diff
changeset
|
111 } |
198 | 112 else if (!strcasecmp(pragma, "importundefexport")) |
113 { | |
114 as -> pragmas |= PRAGMA_IMPORTUNDEFEXPORT; | |
115 } | |
116 else if (!strcasecmp(pragma, "noimportundefexport")) | |
117 { | |
118 as -> pragmas &= ~PRAGMA_IMPORTUNDEFEXPORT; | |
119 } | |
236
a58f49a77441
Added os9 target, pragma to control whether $ localizes a symbol, and fixed some condition nesting bugs
lost
parents:
212
diff
changeset
|
120 else if (!strcasecmp(pragma, "dollarnotlocal") || !strcasecmp(pragma, "nodollarlocal")) |
a58f49a77441
Added os9 target, pragma to control whether $ localizes a symbol, and fixed some condition nesting bugs
lost
parents:
212
diff
changeset
|
121 { |
a58f49a77441
Added os9 target, pragma to control whether $ localizes a symbol, and fixed some condition nesting bugs
lost
parents:
212
diff
changeset
|
122 as -> pragmas |= PRAGMA_DOLLARNOTLOCAL; |
a58f49a77441
Added os9 target, pragma to control whether $ localizes a symbol, and fixed some condition nesting bugs
lost
parents:
212
diff
changeset
|
123 } |
a58f49a77441
Added os9 target, pragma to control whether $ localizes a symbol, and fixed some condition nesting bugs
lost
parents:
212
diff
changeset
|
124 else if (!strcasecmp(pragma, "dollarlocal") || !strcasecmp(pragma, "nodollarnotlocal")) |
a58f49a77441
Added os9 target, pragma to control whether $ localizes a symbol, and fixed some condition nesting bugs
lost
parents:
212
diff
changeset
|
125 { |
a58f49a77441
Added os9 target, pragma to control whether $ localizes a symbol, and fixed some condition nesting bugs
lost
parents:
212
diff
changeset
|
126 as -> pragmas &= ~PRAGMA_DOLLARNOTLOCAL; |
a58f49a77441
Added os9 target, pragma to control whether $ localizes a symbol, and fixed some condition nesting bugs
lost
parents:
212
diff
changeset
|
127 } |
0 | 128 else |
129 { | |
130 if (error) | |
73 | 131 { |
132 register_error(as, cl, 1, "Unrecognized pragma"); | |
143
0ee5f65bccf9
Added pragma to allow all undefined symbols to be considered external and also added a --pragma command line option
lost
parents:
73
diff
changeset
|
133 if (error == 2) |
0ee5f65bccf9
Added pragma to allow all undefined symbols to be considered external and also added a --pragma command line option
lost
parents:
73
diff
changeset
|
134 { |
0ee5f65bccf9
Added pragma to allow all undefined symbols to be considered external and also added a --pragma command line option
lost
parents:
73
diff
changeset
|
135 *optr = NULL; |
0ee5f65bccf9
Added pragma to allow all undefined symbols to be considered external and also added a --pragma command line option
lost
parents:
73
diff
changeset
|
136 } |
73 | 137 } |
0 | 138 } |
200 | 139 if (*optr && **optr == ',') |
165
566943f98f8d
Made pragma actually take multiple pragmas on one line
lost
parents:
160
diff
changeset
|
140 { |
566943f98f8d
Made pragma actually take multiple pragmas on one line
lost
parents:
160
diff
changeset
|
141 (*optr)++; |
566943f98f8d
Made pragma actually take multiple pragmas on one line
lost
parents:
160
diff
changeset
|
142 goto pragmaagain; |
566943f98f8d
Made pragma actually take multiple pragmas on one line
lost
parents:
160
diff
changeset
|
143 } |
0 | 144 } |
145 | |
73 | 146 OPFUNC(pseudo_pragma) |
0 | 147 { |
73 | 148 pseudo_pragma_real(as, l, p, 1); |
0 | 149 } |
150 | |
73 | 151 OPFUNC(pseudo_starpragma) |
0 | 152 { |
73 | 153 pseudo_pragma_real(as, l, p, 0); |
0 | 154 } |