Mercurial > hg-old > index.cgi
comparison src/parse.c @ 44:2330b88f9600
Added simple output listing
author | lost |
---|---|
date | Sun, 04 Jan 2009 06:52:18 +0000 |
parents | 9bd584bb6296 |
children | b9856da2674a |
comparison
equal
deleted
inserted
replaced
43:b33eca135258 | 44:2330b88f9600 |
---|---|
35 int lwasm_parse_line(asmstate_t *as, lwasm_line_t *l) | 35 int lwasm_parse_line(asmstate_t *as, lwasm_line_t *l) |
36 { | 36 { |
37 char *p, *p2; | 37 char *p, *p2; |
38 char *opc; | 38 char *opc; |
39 int opnum; | 39 int opnum; |
40 char *sym; | 40 char *sym = NULL; |
41 | 41 |
42 p = l -> text; | 42 p = l -> text; |
43 | 43 |
44 if (!*p) | 44 if (!*p) |
45 { | 45 { |
46 as -> context += 1; | 46 as -> context += 1; |
47 return 0; | 47 return 0; |
48 } | 48 } |
49 | |
50 // for output generation later | |
51 l -> codeaddr = as -> addr; | |
49 | 52 |
50 if (!isspace(*p) && *p != '*' && *p != ';') | 53 if (!isspace(*p) && *p != '*' && *p != ';') |
51 { | 54 { |
52 // we have a symbol specified here | 55 // we have a symbol specified here |
53 // parse it and define | 56 // parse it and define |
57 | 60 |
58 sym = lwasm_alloc((p2 - p) + 1); | 61 sym = lwasm_alloc((p2 - p) + 1); |
59 sym[p2 - p] = '\0'; | 62 sym[p2 - p] = '\0'; |
60 memcpy(sym, p, p2 - p); | 63 memcpy(sym, p, p2 - p); |
61 | 64 |
62 l -> sym = sym; | 65 p = p2; |
63 // have a symbol; now determine if it is valid and register it | 66 |
64 // at the current address of the line | 67 if (as -> passnum == 1) |
65 debug_message(1, "Registering symbol '%s' at %04X", sym, as -> addr); | 68 { |
66 if (lwasm_register_symbol(as, l, sym, as -> addr) < 0) | 69 l -> sym = sym; |
67 l -> sym = NULL; | 70 // have a symbol; now determine if it is valid and register it |
71 // at the current address of the line | |
72 debug_message(1, "Registering symbol '%s' at %04X", sym, as -> addr); | |
73 if (lwasm_register_symbol(as, l, sym, as -> addr) < 0) | |
74 l -> sym = NULL; | |
75 } | |
68 } | 76 } |
69 else | 77 else |
70 { | 78 { |
71 while (*p && isspace(*p)) | 79 while (*p && isspace(*p)) |
72 p++; | 80 p++; |
82 p++; | 90 p++; |
83 | 91 |
84 // if comment or end of line, return | 92 // if comment or end of line, return |
85 if (!*p || *p == '*' || *p == ';') | 93 if (!*p || *p == '*' || *p == ';') |
86 { | 94 { |
87 lwasm_free(l -> sym); | 95 if (sym) |
96 lwasm_free(l -> sym); | |
88 return 0; | 97 return 0; |
89 } | 98 } |
90 | 99 |
91 // parse the opcode | 100 // parse the opcode |
92 for (p2 = p; *p2 && !isspace(*p2); p2++) | 101 for (p2 = p; *p2 && !isspace(*p2); p2++) |
113 | 122 |
114 if (!(instab[opnum].opcode) || !(instab[opnum].fn)) | 123 if (!(instab[opnum].opcode) || !(instab[opnum].fn)) |
115 { | 124 { |
116 // invalid operation code, throw error | 125 // invalid operation code, throw error |
117 register_error(as, l, 1, "Invalid operation code '%s'", opc); | 126 register_error(as, l, 1, "Invalid operation code '%s'", opc); |
118 lwasm_free(l -> sym); | 127 if (sym) |
128 lwasm_free(l -> sym); | |
119 lwasm_free(opc); | 129 lwasm_free(opc); |
120 return -1; | 130 return -1; |
121 } | 131 } |
122 | 132 |
123 // dispatch handler | 133 // dispatch handler |
124 (instab[opnum].fn)(as, l, &p2, opnum); | 134 (instab[opnum].fn)(as, l, &p2, opnum); |
125 | 135 |
126 lwasm_free(opc); | 136 lwasm_free(opc); |
127 lwasm_free(sym); | 137 if (sym) |
138 lwasm_free(sym); | |
128 } | 139 } |