This commit is contained in:
Krzosa Karol
2022-06-21 14:02:54 +02:00
parent 3f384a60ec
commit 80fb582854
2 changed files with 13 additions and 7 deletions

View File

@@ -278,17 +278,21 @@ emit_end(Bc *b){
i->operation = BC_END_OF_INSTRUCTIONS;
}
#define bc_log(...) log_info(__VA_ARGS__)
#define BC_LOG 1
#if BC_LOG
#define bc_log(...) log_info(__VA_ARGS__)
#else
#define bc_log(...)
#endif
function void
run_bytecode_interp(Bc *b){
for(;;){
auto instr = (Instruction *)b->registers[REG_INS_POINTER].pointer64;
bc_log("[%llx] - %s ", b->registers[REG_INS_POINTER].pointer64, op_name[instr->operation]);
b->registers[REG_INS_POINTER].pointer += sizeof(Instruction);
switch(instr->operation){
switch(instr->operation){
case BC_LOAD_FROM_MEMORY64:{
U64 *load_address = b->registers[instr->src].pointer64;
b->registers[instr->dst].u64 = *load_address;
@@ -302,6 +306,7 @@ run_bytecode_interp(Bc *b){
case BC_PUSH_STACK:{
U64 *stack = b->registers[REG_STACK_POINTER].pointer64++;
U64 src = b->registers[instr->src].u64;
bc_log("r%u ", instr->src);
*stack = src;
}break;
@@ -320,9 +325,9 @@ run_bytecode_interp(Bc *b){
b->registers[i->dst] = i->constant;
#if BC_LOG
switch(i->debug_type_flag){
case TYPE_S64: bc_log("%u %lld", i->dst, i->constant.s64); break;
case TYPE_U64: bc_log("%u %llu", i->dst, i->constant.u64); break;
case TYPE_F64: bc_log("%u %f" , i->dst, i->constant.f64); break;
case TYPE_S64: bc_log("r%u v%lld", i->dst, i->constant.s64); break;
case TYPE_U64: bc_log("r%u v%llu", i->dst, i->constant.u64); break;
case TYPE_F64: bc_log("r%u v%f" , i->dst, i->constant.f64); break;
invalid_default_case;
}
#endif