Mercurial > hg-old > index.cgi
comparison src/pseudo.c @ 52:b9856da2674a
Added file inclusion
author | lost |
---|---|
date | Sun, 04 Jan 2009 20:16:38 +0000 |
parents | e672232caffe |
children | 493cb8ea50a0 |
comparison
equal
deleted
inserted
replaced
51:04868fa52a15 | 52:b9856da2674a |
---|---|
24 #include <stdlib.h> | 24 #include <stdlib.h> |
25 #include <string.h> | 25 #include <string.h> |
26 #include "lwasm.h" | 26 #include "lwasm.h" |
27 #include "instab.h" | 27 #include "instab.h" |
28 #include "expr.h" | 28 #include "expr.h" |
29 | 29 #include "util.h" |
30 | |
31 extern int lwasm_read_file(asmstate_t *as, const char *filename); | |
30 | 32 |
31 OPFUNC(pseudo_org) | 33 OPFUNC(pseudo_org) |
32 { | 34 { |
33 int rval; | 35 int rval; |
34 lwasm_expr_stack_t *s; | 36 lwasm_expr_stack_t *s; |
37 | |
38 if (as -> passnum != 1) | |
39 { | |
40 // org is not needed to be processed on pass 2 | |
41 // this will prevent phasing errors for forward references that | |
42 // resolve on the second pass | |
43 // we saved the org address in l -> codeaddr on pass 1 | |
44 as -> addr = l -> codeaddr; | |
45 return; | |
46 } | |
35 | 47 |
36 if (l -> sym) | 48 if (l -> sym) |
37 { | 49 { |
38 register_error(as, l, 1, "No symbol allowed with ORG"); | 50 register_error(as, l, 1, "No symbol allowed with ORG"); |
39 } | 51 } |
55 l -> addrset = 1; | 67 l -> addrset = 1; |
56 as -> addr = rval; | 68 as -> addr = rval; |
57 } | 69 } |
58 | 70 |
59 /* | 71 /* |
60 void pseudo_include(asmstate_t *as, sourceline_t *cl, char **optr) | 72 The operand for include is a string optionally enclosed in " |
73 */ | |
74 OPFUNC(pseudo_include) | |
61 { | 75 { |
62 int v1; | 76 int v1; |
63 | 77 char *fn; |
78 | |
79 // only include files on pass 1 | |
80 // but make sure local include context is right | |
81 // for the next line... | |
64 if (as -> passnum != 1) | 82 if (as -> passnum != 1) |
65 return; | 83 { |
66 while (**optr && isspace(**optr)) | 84 as -> context += 1; |
67 (*optr)++; | 85 return; |
68 if (!**optr) | 86 } |
69 { | 87 |
70 register_error(as, cl, ERR_BADFN); | 88 while (**p && isspace(**p)) |
71 return; | 89 (*p)++; |
72 } | 90 |
73 for (v1 = 0; *((*optr)+v1) && !isspace(*((*optr)+v1)); v1++) | 91 if (!**p) |
74 ; | 92 { |
75 { | 93 register_error(as, l, 1, "Bad file name"); |
76 char *fn = malloc(v1 + 1); | 94 return; |
77 strncpy(fn, *optr, v1); | 95 } |
78 fn[v1] = '\0'; | 96 |
79 lwasm_read_file(as, fn); | 97 if (**p == '"') |
80 } | 98 { |
81 } | 99 // search for ending " |
82 | 100 (*p)++; |
83 */ | 101 for (v1 = 0; *((*p)+v1) && *((*p)+v1) != '"'; v1++) |
102 /* do nothing */ ; | |
103 if (*((*p)+v1) != '"') | |
104 { | |
105 register_error(as, l, 1, "Bad file name"); | |
106 return; | |
107 } | |
108 } | |
109 else | |
110 { | |
111 // search for a space type character | |
112 for (v1 = 0; *((*p)+v1) && !isspace(*((*p)+v1)); v1++) | |
113 ; | |
114 } | |
115 | |
116 fn = lwasm_alloc(v1 + 1); | |
117 memcpy(fn, *p, v1); | |
118 fn[v1] = '\0'; | |
119 | |
120 // end local label context on include | |
121 as -> context += 1; | |
122 if (lwasm_read_file(as, fn) < 0) | |
123 { | |
124 register_error(as, l, 1, "File include error (%s)", fn); | |
125 } | |
126 lwasm_free(fn); | |
127 } | |
128 | |
84 OPFUNC(pseudo_rmb) | 129 OPFUNC(pseudo_rmb) |
85 { | 130 { |
86 int rval; | 131 int rval; |
87 lwasm_expr_stack_t *s; | 132 lwasm_expr_stack_t *s; |
88 | 133 |
254 */ | 299 */ |
255 OPFUNC(pseudo_equ) | 300 OPFUNC(pseudo_equ) |
256 { | 301 { |
257 lwasm_expr_stack_t *s; | 302 lwasm_expr_stack_t *s; |
258 int rval; | 303 int rval; |
259 | 304 |
305 // equ is not needed to be processed on pass 2 | |
306 if (as -> passnum != 1) | |
307 return; | |
308 | |
260 if (l -> sym == NULL) | 309 if (l -> sym == NULL) |
261 { | 310 { |
262 register_error(as, l, 1, "No symbol specified"); | 311 register_error(as, l, 1, "No symbol specified"); |
263 return; | 312 return; |
264 } | 313 } |