annotate src/pragma.c @ 143:0ee5f65bccf9

Added pragma to allow all undefined symbols to be considered external and also added a --pragma command line option
author lost
date Thu, 29 Jan 2009 01:32:11 +0000
parents 4b37f17624a7
children 006d737756fd
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
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
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
23
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
24 #include <ctype.h>
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
25 #include <stdlib.h>
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
26 #include <string.h>
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
27 #include "lwasm.h"
73
4b37f17624a7 Added pragma directives
lost
parents: 4
diff changeset
28 #include "instab.h"
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
29
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
30 /*
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
31 A pragma is a means of controlling code generation.
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
32
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
33 The pseudo op "*pragma" which will be treated as a comment by an assembler
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
34 that doesn't recognize it and thus will not cause assembly errors. This is
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
35 the preferred way of flagging a pragma if it will not cause incorrect
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
36 execution of the program.
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
37
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
38 The pseudo op "pragma" which will cause an error on an assembler that does
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
39 not understand it.
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
40
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
41 In the case of "*pragma", unrecognized pragmas MUST be silently ignored. In
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
42 the case of "pragma", unrecognized pragmas should raise an error.
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
43
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
44 LWASM understands the following pragmas:
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
45
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
46 index0tonone
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
47 noindex0tonone
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
48
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
49 When set (index0tonone), an expression that evaluates to 0, other than a
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
50 bare constant, in a <offset>,r operand will cause the code for ",r" to be
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
51 emitted rather than "0,r". If not set (noindex0tonone), the "0,r" output
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
52 will be emitted. The default is to perform the optimization.
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
53
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
54 This particular optimization will save a cycle for a direct operation. For
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
55 an indirect operation, however, it will save several cycles and a program byte
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
56 which may be very useful.
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
57 */
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
58
73
4b37f17624a7 Added pragma directives
lost
parents: 4
diff changeset
59 void pseudo_pragma_real(asmstate_t *as, lwasm_line_t *cl, char **optr, int error)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
60 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
61 char pragma[128];
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
62 int c = 0;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
63
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
64 while (isspace(**optr))
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
65 (*optr)++;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
66
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
67 while (c < 127 && **optr && !isspace(**optr))
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
68 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
69 pragma[c++] = **optr;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
70 (*optr)++;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
71 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
72
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
73 if (c == 0 || (**optr && !isspace(**optr)))
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
74 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
75 if (error)
73
4b37f17624a7 Added pragma directives
lost
parents: 4
diff changeset
76 {
4b37f17624a7 Added pragma directives
lost
parents: 4
diff changeset
77 register_error(as, cl, 1, "Unrecognized pragma");
4b37f17624a7 Added pragma directives
lost
parents: 4
diff changeset
78 }
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
79 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
80 {
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 *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
82 }
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
83 return;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
84 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
85 pragma[c] = 0;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
86 if (!strcmp(pragma, "noindex0tonone"))
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
87 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
88 as -> pragmas |= PRAGMA_NOINDEX0TONONE;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
89 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
90 else if (!strcmp(pragma, "index0tonone"))
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
91 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
92 as -> pragmas &= ~PRAGMA_NOINDEX0TONONE;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
93 }
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
94 else if (!strcmp(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
95 {
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
96 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
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 else if (!strcmp(pragma, "noundefextern"))
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 {
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
100 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
101 }
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
102 else
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
103 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
104 if (error)
73
4b37f17624a7 Added pragma directives
lost
parents: 4
diff changeset
105 {
4b37f17624a7 Added pragma directives
lost
parents: 4
diff changeset
106 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
107 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
108 {
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
109 *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
110 }
73
4b37f17624a7 Added pragma directives
lost
parents: 4
diff changeset
111 }
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
112 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
113 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
114
73
4b37f17624a7 Added pragma directives
lost
parents: 4
diff changeset
115 OPFUNC(pseudo_pragma)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
116 {
73
4b37f17624a7 Added pragma directives
lost
parents: 4
diff changeset
117 pseudo_pragma_real(as, l, p, 1);
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
118 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
119
73
4b37f17624a7 Added pragma directives
lost
parents: 4
diff changeset
120 OPFUNC(pseudo_starpragma)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
121 {
73
4b37f17624a7 Added pragma directives
lost
parents: 4
diff changeset
122 pseudo_pragma_real(as, l, p, 0);
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
123 }