Browse Source

print garbage instructions nicer

master
Martin Dørum 3 years ago
parent
commit
d48ca19bca
1 changed files with 13 additions and 0 deletions
  1. 13
    0
      lib/vm/print.c

+ 13
- 0
lib/vm/print.c View File

#include "vm/print.h" #include "vm/print.h"


#include <stdio.h> #include <stdio.h>
#include <string.h>


void l2_vm_print_val(struct l2_vm_value *val) { void l2_vm_print_val(struct l2_vm_value *val) {
switch (val->flags & 0x0f) { switch (val->flags & 0x0f) {
case L2_OP_HALT: case L2_OP_HALT:
printf("HALT\n"); printf("HALT\n");
break; break;

default:
{
l2_word word = (l2_word)opcode;
char bytes[sizeof(word)];
memcpy(&bytes, &word, sizeof(word));
printf("?");
for (size_t i = 0; i < sizeof(bytes); ++i) {
printf(" %02x", bytes[i]);
}
printf("\n");
}
} }
} }



Loading…
Cancel
Save