comparison lwasm/os9.c @ 370:8764142b3192

Convert internal error/warning handling framework to a new unified system Replace the ad hoc error and warning handling with a new system that codifies the errors with specific codes. This makes it possible in the future for error numbers to be used for testing and other purposes. It also makes sure the error strings themselves are consistent. Thanks to Erik G <erik@6809.org> for the patch.
author William Astle <lost@l-w.ca>
date Mon, 22 Jun 2015 18:49:38 -0600
parents 244f1227f2b5
children 928c033c0cd0
comparison
equal deleted inserted replaced
369:682524a1f32f 370:8764142b3192
36 { 36 {
37 lw_expr_t e; 37 lw_expr_t e;
38 38
39 if (as -> output_format != OUTPUT_OS9 && as -> output_format != OUTPUT_OBJ) 39 if (as -> output_format != OUTPUT_OS9 && as -> output_format != OUTPUT_OBJ)
40 { 40 {
41 lwasm_register_error(as, l, "os9 directive only valid for OS9 target"); 41 lwasm_register_error2(as, l, E_DIRECTIVE_OS9_ONLY, "%s", "os9");
42 return; 42 return;
43 } 43 }
44 44
45 // fetch immediate value 45 // fetch immediate value
46 e = lwasm_parse_expr(as, p); 46 e = lwasm_parse_expr(as, p);
47 if (!e) 47 if (!e)
48 { 48 {
49 lwasm_register_error(as, l, "Bad operand"); 49 lwasm_register_error(as, l, E_OPERAND_BAD);
50 return; 50 return;
51 } 51 }
52 lwasm_save_expr(l, 0, e); 52 lwasm_save_expr(l, 0, e);
53 l -> len = 3; 53 l -> len = 3;
54 } 54 }
68 lw_expr_t e; 68 lw_expr_t e;
69 int i; 69 int i;
70 70
71 if (as -> output_format != OUTPUT_OS9) 71 if (as -> output_format != OUTPUT_OS9)
72 { 72 {
73 lwasm_register_error(as, l, "mod directive only valid for OS9 target"); 73 lwasm_register_error2(as, l, E_DIRECTIVE_OS9_ONLY, "%s", "mod");
74 skip_operand(p); 74 skip_operand(p);
75 return; 75 return;
76 } 76 }
77 77
78 if (as -> inmod) 78 if (as -> inmod)
79 { 79 {
80 lwasm_register_error(as, l, "Already in a module!"); 80 lwasm_register_error(as, l, E_MODULE_IN);
81 skip_operand(p); 81 skip_operand(p);
82 return; 82 return;
83 } 83 }
84 84
85 // parse 6 expressions... 85 // parse 6 expressions...
86 for (i = 0; i < 5; i++) 86 for (i = 0; i < 5; i++)
87 { 87 {
88 e = lwasm_parse_expr(as, p); 88 e = lwasm_parse_expr(as, p);
89 if (!e) 89 if (!e)
90 { 90 {
91 lwasm_register_error(as, l, "Bad operand"); 91 lwasm_register_error(as, l, E_OPERAND_BAD);
92 return; 92 return;
93 } 93 }
94 94
95 lwasm_save_expr(l, i, e); 95 lwasm_save_expr(l, i, e);
96 96
97 if (**p != ',') 97 if (**p != ',')
98 { 98 {
99 lwasm_register_error(as, l, "Bad operand"); 99 lwasm_register_error(as, l, E_OPERAND_BAD);
100 return; 100 return;
101 } 101 }
102 (*p)++; 102 (*p)++;
103 } 103 }
104 104
105 e = lwasm_parse_expr(as, p); 105 e = lwasm_parse_expr(as, p);
106 if (!e) 106 if (!e)
107 { 107 {
108 lwasm_register_error(as, l, "Bad operand"); 108 lwasm_register_error(as, l, E_OPERAND_BAD);
109 return; 109 return;
110 } 110 }
111 lwasm_save_expr(l, 5, e); 111 lwasm_save_expr(l, 5, e);
112 112
113 l -> inmod = 1; 113 l -> inmod = 1;
171 PARSEFUNC(pseudo_parse_emod) 171 PARSEFUNC(pseudo_parse_emod)
172 { 172 {
173 skip_operand(p); 173 skip_operand(p);
174 if (as -> output_format != OUTPUT_OS9) 174 if (as -> output_format != OUTPUT_OS9)
175 { 175 {
176 lwasm_register_error(as, l, "emod directive only valid for OS9 target"); 176 lwasm_register_error2(as, l, E_DIRECTIVE_OS9_ONLY, "%s", "emod");
177 return; 177 return;
178 } 178 }
179 179
180 if (!(as -> inmod)) 180 if (!(as -> inmod))
181 { 181 {
182 lwasm_register_error(as, l, "not in a module!"); 182 lwasm_register_error(as, l, E_MODULE_NOTIN);
183 return; 183 return;
184 } 184 }
185 185
186 as -> inmod = 0; 186 as -> inmod = 0;
187 l -> len = 3; 187 l -> len = 3;