annotate old-trunk/lwasm/old/pragma.c @ 348:11a95c6414b4

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