comparison old-trunk/lwasm/old/pragma.c @ 339:eb230fa7d28e

Prepare for migration to hg
author lost
date Fri, 19 Mar 2010 02:54:14 +0000
parents
children
comparison
equal deleted inserted replaced
338:e7885b3ee266 339:eb230fa7d28e
1 /*
2 pragma.c
3 Copyright © 2008 William Astle
4
5 This file is part of LWASM.
6
7 LWASM is free software: you can redistribute it and/or modify it under the
8 terms of the GNU General Public License as published by the Free Software
9 Foundation, either version 3 of the License, or (at your option) any later
10 version.
11
12 This program is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 more details.
16
17 You should have received a copy of the GNU General Public License along with
18 this program. If not, see <http://www.gnu.org/licenses/>.
19
20
21 This file contains stuff associated with lwasm specific strangeness
22 */
23 #include <config.h>
24 #include <ctype.h>
25 #include <stdlib.h>
26 #include <string.h>
27 #include "lwasm.h"
28 #include "instab.h"
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
59 void pseudo_pragma_real(asmstate_t *as, lwasm_line_t *cl, char **optr, int error)
60 {
61 char pragma[128];
62 int c = 0;
63
64 while (**optr && isspace(**optr))
65 (*optr)++;
66
67 pragmaagain:
68 c = 0;
69 while (c < 127 && **optr && **optr != ',' && !isspace(**optr))
70 {
71 pragma[c++] = **optr;
72 (*optr)++;
73 }
74
75 if (c == 0 || (**optr && **optr != ',' && !isspace(**optr)))
76 {
77 if (error)
78 {
79 register_error(as, cl, 1, "Unrecognized pragma");
80 }
81 if (error == 2)
82 {
83 *optr = NULL;
84 }
85 return;
86 }
87 pragma[c] = 0;
88 if (!strcasecmp(pragma, "noindex0tonone"))
89 {
90 as -> pragmas |= PRAGMA_NOINDEX0TONONE;
91 }
92 else if (!strcasecmp(pragma, "index0tonone"))
93 {
94 as -> pragmas &= ~PRAGMA_NOINDEX0TONONE;
95 }
96 else if (!strcasecmp(pragma, "undefextern"))
97 {
98 as -> pragmas |= PRAGMA_UNDEFEXTERN;
99 }
100 else if (!strcasecmp(pragma, "noundefextern"))
101 {
102 as -> pragmas &= ~PRAGMA_UNDEFEXTERN;
103 }
104 else if (!strcasecmp(pragma, "cescapes"))
105 {
106 as -> pragmas |= PRAGMA_CESCAPES;
107 }
108 else if (!strcasecmp(pragma, "nocescapes"))
109 {
110 as -> pragmas &= ~PRAGMA_CESCAPES;
111 }
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 }
120 else if (!strcasecmp(pragma, "dollarnotlocal") || !strcasecmp(pragma, "nodollarlocal"))
121 {
122 as -> pragmas |= PRAGMA_DOLLARNOTLOCAL;
123 }
124 else if (!strcasecmp(pragma, "dollarlocal") || !strcasecmp(pragma, "nodollarnotlocal"))
125 {
126 as -> pragmas &= ~PRAGMA_DOLLARNOTLOCAL;
127 }
128 else
129 {
130 if (error)
131 {
132 register_error(as, cl, 1, "Unrecognized pragma");
133 if (error == 2)
134 {
135 *optr = NULL;
136 }
137 }
138 }
139 if (*optr && **optr == ',')
140 {
141 (*optr)++;
142 goto pragmaagain;
143 }
144 }
145
146 OPFUNC(pseudo_pragma)
147 {
148 pseudo_pragma_real(as, l, p, 1);
149 }
150
151 OPFUNC(pseudo_starpragma)
152 {
153 pseudo_pragma_real(as, l, p, 0);
154 }