diff options
author | Bad Diode <bd@badd10de.dev> | 2022-04-25 11:59:22 -0300 |
---|---|---|
committer | Bad Diode <bd@badd10de.dev> | 2022-04-25 11:59:22 -0300 |
commit | ada3f3a2eac5b3828c3a55970d5640fef922d3d0 (patch) | |
tree | 6e1ce0a6cb41b21f3fd58eade27d3f219cb05c46 /src/viz.c | |
parent | 38fd557a61e7366140b6fbdacfebc3ad28f55369 (diff) | |
download | bdl-ada3f3a2eac5b3828c3a55970d5640fef922d3d0.tar.gz bdl-ada3f3a2eac5b3828c3a55970d5640fef922d3d0.zip |
Add BASM generation for `if` expressions
Diffstat (limited to 'src/viz.c')
-rw-r--r-- | src/viz.c | 75 |
1 files changed, 42 insertions, 33 deletions
@@ -237,39 +237,41 @@ viz_symtables(Scope **scopes) { | |||
237 | } | 237 | } |
238 | 238 | ||
239 | static const char* basm_op_str[] = { | 239 | static const char* basm_op_str[] = { |
240 | [OP_ADD] = "add ", | 240 | [OP_ADD] = "add ", |
241 | [OP_SUB] = "sub ", | 241 | [OP_SUB] = "sub ", |
242 | [OP_MUL] = "mul ", | 242 | [OP_MUL] = "mul ", |
243 | [OP_DIV] = "div ", | 243 | [OP_DIV] = "div ", |
244 | [OP_MOD] = "mod ", | 244 | [OP_MOD] = "mod ", |
245 | [OP_LD8] = "ld8 ", | 245 | [OP_LD8] = "ld8 ", |
246 | [OP_LD16] = "ld16 ", | 246 | [OP_LD16] = "ld16 ", |
247 | [OP_LD32] = "ld32 ", | 247 | [OP_LD32] = "ld32 ", |
248 | [OP_LD64] = "ld64 ", | 248 | [OP_LD64] = "ld64 ", |
249 | [OP_ST8] = "st8 ", | 249 | [OP_ST8] = "st8 ", |
250 | [OP_ST16] = "st16 ", | 250 | [OP_ST16] = "st16 ", |
251 | [OP_ST32] = "st32 ", | 251 | [OP_ST32] = "st32 ", |
252 | [OP_ST64] = "st64 ", | 252 | [OP_ST64] = "st64 ", |
253 | [OP_CP8] = "cp8 ", | 253 | [OP_CP8] = "cp8 ", |
254 | [OP_CP16] = "cp16 ", | 254 | [OP_CP16] = "cp16 ", |
255 | [OP_CP32] = "cp32 ", | 255 | [OP_CP32] = "cp32 ", |
256 | [OP_CP64] = "cp64 ", | 256 | [OP_CP64] = "cp64 ", |
257 | [OP_NOT] = "not ", | 257 | [OP_NOT] = "not ", |
258 | [OP_AND] = "and ", | 258 | [OP_AND] = "and ", |
259 | [OP_OR] = "or ", | 259 | [OP_OR] = "or ", |
260 | [OP_XOR] = "xor ", | 260 | [OP_XOR] = "xor ", |
261 | [OP_LSHIFT] = "lshift", | 261 | [OP_LSHIFT] = "lshift", |
262 | [OP_RSHIFT] = "rshift", | 262 | [OP_RSHIFT] = "rshift", |
263 | [OP_LROT] = "lrot ", | 263 | [OP_LROT] = "lrot ", |
264 | [OP_RROT] = "rrot ", | 264 | [OP_RROT] = "rrot ", |
265 | [OP_LABEL] = "lab ", | 265 | [OP_LABEL] = "lab ", |
266 | [OP_JMP] = "jmp ", | 266 | [OP_JMP] = "jmp ", |
267 | [OP_JMP_EQ] = "jeq ", | 267 | [OP_JMP_TRUE] = "jt ", |
268 | [OP_JMP_NEQ] = "jne ", | 268 | [OP_JMP_FALSE] = "jf ", |
269 | [OP_JMP_GT] = "jgt ", | 269 | [OP_JMP_EQ] = "jeq ", |
270 | [OP_JMP_LT] = "jlt ", | 270 | [OP_JMP_NEQ] = "jne ", |
271 | [OP_JMP_GE] = "jge ", | 271 | [OP_JMP_GT] = "jgt ", |
272 | [OP_JMP_LE] = "jle ", | 272 | [OP_JMP_LT] = "jlt ", |
273 | [OP_JMP_GE] = "jge ", | ||
274 | [OP_JMP_LE] = "jle ", | ||
273 | }; | 275 | }; |
274 | 276 | ||
275 | void | 277 | void |
@@ -314,6 +316,13 @@ viz_instruction(Instruction *inst, LineInfo *line) { | |||
314 | printf(" "); | 316 | printf(" "); |
315 | viz_operand(inst->dst); | 317 | viz_operand(inst->dst); |
316 | } break; | 318 | } break; |
319 | case OP_JMP_TRUE: | ||
320 | case OP_JMP_FALSE: { | ||
321 | printf(" "); | ||
322 | viz_operand(inst->dst); | ||
323 | printf(", "); | ||
324 | viz_operand(inst->src_a); | ||
325 | } break; | ||
317 | default: { | 326 | default: { |
318 | printf(" "); | 327 | printf(" "); |
319 | viz_operand(inst->dst); | 328 | viz_operand(inst->dst); |