annotate src/pragma.c @ 0:57495da01900

Initial checking of LWASM
author lost
date Fri, 03 Oct 2008 02:44:20 +0000
parents
children 34568fab6058
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
1 /*
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
2 * pragma.c
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
3 *
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
4 * stuff associated with lwasm specific strangeness
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
5 */
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
6
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
7 #include <ctype.h>
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
8 #include <stdlib.h>
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
9 #include <string.h>
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
10 #include "lwasm.h"
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
11
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
12 /*
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
13 A pragma is a means of controlling code generation.
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
14
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
15 The pseudo op "*pragma" which will be treated as a comment by an assembler
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
16 that doesn't recognize it and thus will not cause assembly errors. This is
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
17 the preferred way of flagging a pragma if it will not cause incorrect
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
18 execution of the program.
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
19
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
20 The pseudo op "pragma" which will cause an error on an assembler that does
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
21 not understand it.
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
22
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
23 In the case of "*pragma", unrecognized pragmas MUST be silently ignored. In
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
24 the case of "pragma", unrecognized pragmas should raise an error.
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
25
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
26 LWASM understands the following pragmas:
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
27
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
28 index0tonone
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
29 noindex0tonone
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
30
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
31 When set (index0tonone), an expression that evaluates to 0, other than a
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
32 bare constant, in a <offset>,r operand will cause the code for ",r" to be
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
33 emitted rather than "0,r". If not set (noindex0tonone), the "0,r" output
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
34 will be emitted. The default is to perform the optimization.
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
35
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
36 This particular optimization will save a cycle for a direct operation. For
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
37 an indirect operation, however, it will save several cycles and a program byte
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
38 which may be very useful.
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
39 */
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
40
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
41 void pseudo_pragma_real(asmstate_t *as, sourceline_t *cl, char **optr, int error)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
42 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
43 char pragma[128];
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
44 int c = 0;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
45
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
46 while (isspace(**optr))
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
47 (*optr)++;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
48
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
49 while (c < 127 && **optr && !isspace(**optr))
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
50 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
51 pragma[c++] = **optr;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
52 (*optr)++;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
53 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
54
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
55 if (c == 0 || (**optr && !isspace(**optr)))
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
56 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
57 if (error)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
58 errorp1(ERR_PRAGMA);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
59 return;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
60 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
61 pragma[c] = 0;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
62 if (!strcmp(pragma, "noindex0tonone"))
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
63 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
64 as -> pragmas |= PRAGMA_NOINDEX0TONONE;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
65 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
66 else if (!strcmp(pragma, "index0tonone"))
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
67 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
68 as -> pragmas &= ~PRAGMA_NOINDEX0TONONE;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
69 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
70 else
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
71 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
72 if (error)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
73 errorp1(ERR_PRAGMA);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
74 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
75 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
76
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
77 void pseudo_pragma(asmstate_t *as, sourceline_t *cl, char **optr)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
78 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
79 pseudo_pragma_real(as, cl, optr, 1);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
80 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
81
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
82 void pseudo_starpragma(asmstate_t *as, sourceline_t *cl, char **optr)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
83 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
84 pseudo_pragma_real(as, cl, optr, 0);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
85 }