comparison lwasm/insn_bitbit.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 7317fbe024af
children b20f14edda5a
comparison
equal deleted inserted replaced
369:682524a1f32f 370:8764142b3192
44 r = 0; 44 r = 0;
45 (*p)++; 45 (*p)++;
46 } 46 }
47 else 47 else
48 { 48 {
49 lwasm_register_error(as, l, "Bad register"); 49 lwasm_register_error(as, l, E_REGISTER_BAD);
50 return; 50 return;
51 } 51 }
52 52
53 if (*(*p)++ != ',') 53 if (*(*p)++ != ',')
54 { 54 {
55 lwasm_register_error(as, l, "Bad operand"); 55 lwasm_register_error(as, l, E_OPERAND_BAD);
56 return; 56 return;
57 } 57 }
58 e = lwasm_parse_expr(as, p); 58 e = lwasm_parse_expr(as, p);
59 if (!e) 59 if (!e)
60 { 60 {
61 lwasm_register_error(as, l, "Bad operand"); 61 lwasm_register_error(as, l, E_OPERAND_BAD);
62 return; 62 return;
63 } 63 }
64 lwasm_save_expr(l, 0, e); 64 lwasm_save_expr(l, 0, e);
65 if (*(*p)++ != ',') 65 if (*(*p)++ != ',')
66 { 66 {
67 lwasm_register_error(as, l, "Bad operand"); 67 lwasm_register_error(as, l, E_OPERAND_BAD);
68 return; 68 return;
69 } 69 }
70 70
71 e = lwasm_parse_expr(as, p); 71 e = lwasm_parse_expr(as, p);
72 if (!e) 72 if (!e)
73 { 73 {
74 lwasm_register_error(as, l, "Bad operand"); 74 lwasm_register_error(as, l, E_OPERAND_BAD);
75 return; 75 return;
76 } 76 }
77 lwasm_save_expr(l, 1, e); 77 lwasm_save_expr(l, 1, e);
78 78
79 if (*(*p)++ != ',') 79 if (*(*p)++ != ',')
80 { 80 {
81 lwasm_register_error(as, l, "Bad operand"); 81 lwasm_register_error(as, l, E_OPERAND_BAD);
82 return; 82 return;
83 } 83 }
84 84
85 // ignore base page address modifier 85 // ignore base page address modifier
86 if (**p == '<') 86 if (**p == '<')
87 (*p)++; 87 (*p)++;
88 88
89 e = lwasm_parse_expr(as, p); 89 e = lwasm_parse_expr(as, p);
90 if (!e) 90 if (!e)
91 { 91 {
92 lwasm_register_error(as, l, "Bad operand"); 92 lwasm_register_error(as, l, E_OPERAND_BAD);
93 return; 93 return;
94 } 94 }
95 lwasm_save_expr(l, 2, e); 95 lwasm_save_expr(l, 2, e);
96 96
97 l -> lint = r; 97 l -> lint = r;
104 lw_expr_t e; 104 lw_expr_t e;
105 105
106 e = lwasm_fetch_expr(l, 0); 106 e = lwasm_fetch_expr(l, 0);
107 if (!lw_expr_istype(e, lw_expr_type_int)) 107 if (!lw_expr_istype(e, lw_expr_type_int))
108 { 108 {
109 lwasm_register_error(as, l, "Bit number must be fully resolved"); 109 lwasm_register_error(as, l, E_BITNUMBER_UNRESOLVED);
110 return; 110 return;
111 } 111 }
112 v1 = lw_expr_intval(e); 112 v1 = lw_expr_intval(e);
113 if (v1 < 0 || v1 > 7) 113 if (v1 < 0 || v1 > 7)
114 { 114 {
115 lwasm_register_error(as, l, "Invalid bit number"); 115 lwasm_register_error(as, l, E_BITNUMBER_INVALID);
116 v1 = 0; 116 v1 = 0;
117 } 117 }
118 118
119 e = lwasm_fetch_expr(l, 1); 119 e = lwasm_fetch_expr(l, 1);
120 if (!lw_expr_istype(e, lw_expr_type_int)) 120 if (!lw_expr_istype(e, lw_expr_type_int))
121 { 121 {
122 lwasm_register_error(as, l, "Bit number must be fully resolved"); 122 lwasm_register_error(as, l, E_BITNUMBER_UNRESOLVED);
123 return; 123 return;
124 } 124 }
125 v2 = lw_expr_intval(e); 125 v2 = lw_expr_intval(e);
126 if (v2 < 0 || v2 > 7) 126 if (v2 < 0 || v2 > 7)
127 { 127 {
128 lwasm_register_error(as, l, "Invalid bit number"); 128 lwasm_register_error(as, l, E_BITNUMBER_INVALID);
129 v2 = 0; 129 v2 = 0;
130 } 130 }
131 l -> pb = (l -> lint << 6) | (v1 << 3) | v2; 131 l -> pb = (l -> lint << 6) | (v1 << 3) | v2;
132 132
133 e = lwasm_fetch_expr(l, 2); 133 e = lwasm_fetch_expr(l, 2);
135 { 135 {
136 v1 = lw_expr_intval(e) & 0xFFFF; 136 v1 = lw_expr_intval(e) & 0xFFFF;
137 v2 = v1 - ((l -> dpval) << 8); 137 v2 = v1 - ((l -> dpval) << 8);
138 if (v2 > 0xFF || v2 < 0) 138 if (v2 > 0xFF || v2 < 0)
139 { 139 {
140 lwasm_register_error(as, l, "Byte overflow"); 140 lwasm_register_error(as, l, E_BYTE_OVERFLOW);
141 return; 141 return;
142 } 142 }
143 } 143 }
144 lwasm_emitop(l, instab[l -> insn].ops[0]); 144 lwasm_emitop(l, instab[l -> insn].ops[0]);
145 lwasm_emit(l, l -> pb); 145 lwasm_emit(l, l -> pb);