Mercurial > hg-old > index.cgi
annotate src/pragma.c @ 17:df0c4a46af8f
Started adding expression handling infrastructure
author | lost |
---|---|
date | Thu, 01 Jan 2009 02:26:26 +0000 |
parents | 34568fab6058 |
children | 4b37f17624a7 |
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 */ |
0 | 23 |
24 #include <ctype.h> | |
25 #include <stdlib.h> | |
26 #include <string.h> | |
27 #include "lwasm.h" | |
28 | |
29 /* | |
30 A pragma is a means of controlling code generation. | |
31 | |
32 The pseudo op "*pragma" which will be treated as a comment by an assembler | |
33 that doesn't recognize it and thus will not cause assembly errors. This is | |
34 the preferred way of flagging a pragma if it will not cause incorrect | |
35 execution of the program. | |
36 | |
37 The pseudo op "pragma" which will cause an error on an assembler that does | |
38 not understand it. | |
39 | |
40 In the case of "*pragma", unrecognized pragmas MUST be silently ignored. In | |
41 the case of "pragma", unrecognized pragmas should raise an error. | |
42 | |
43 LWASM understands the following pragmas: | |
44 | |
45 index0tonone | |
46 noindex0tonone | |
47 | |
48 When set (index0tonone), an expression that evaluates to 0, other than a | |
49 bare constant, in a <offset>,r operand will cause the code for ",r" to be | |
50 emitted rather than "0,r". If not set (noindex0tonone), the "0,r" output | |
51 will be emitted. The default is to perform the optimization. | |
52 | |
53 This particular optimization will save a cycle for a direct operation. For | |
54 an indirect operation, however, it will save several cycles and a program byte | |
55 which may be very useful. | |
56 */ | |
57 | |
58 void pseudo_pragma_real(asmstate_t *as, sourceline_t *cl, char **optr, int error) | |
59 { | |
60 char pragma[128]; | |
61 int c = 0; | |
62 | |
63 while (isspace(**optr)) | |
64 (*optr)++; | |
65 | |
66 while (c < 127 && **optr && !isspace(**optr)) | |
67 { | |
68 pragma[c++] = **optr; | |
69 (*optr)++; | |
70 } | |
71 | |
72 if (c == 0 || (**optr && !isspace(**optr))) | |
73 { | |
74 if (error) | |
75 errorp1(ERR_PRAGMA); | |
76 return; | |
77 } | |
78 pragma[c] = 0; | |
79 if (!strcmp(pragma, "noindex0tonone")) | |
80 { | |
81 as -> pragmas |= PRAGMA_NOINDEX0TONONE; | |
82 } | |
83 else if (!strcmp(pragma, "index0tonone")) | |
84 { | |
85 as -> pragmas &= ~PRAGMA_NOINDEX0TONONE; | |
86 } | |
87 else | |
88 { | |
89 if (error) | |
90 errorp1(ERR_PRAGMA); | |
91 } | |
92 } | |
93 | |
94 void pseudo_pragma(asmstate_t *as, sourceline_t *cl, char **optr) | |
95 { | |
96 pseudo_pragma_real(as, cl, optr, 1); | |
97 } | |
98 | |
99 void pseudo_starpragma(asmstate_t *as, sourceline_t *cl, char **optr) | |
100 { | |
101 pseudo_pragma_real(as, cl, optr, 0); | |
102 } |