comparison src/pragma.c @ 0:57495da01900

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