Logging
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -71,6 +71,7 @@ if True:
|
||||
result += f"""
|
||||
case BC_{op_name}_{T}:{{
|
||||
{T} left = ({T})b->registers[instr->left].{t};
|
||||
bc_log("{symbol} v{sign}", left);
|
||||
{T} *dst = b->registers[instr->dst].pointer_{t};
|
||||
*dst = {symbol}left;
|
||||
}}break;
|
||||
@@ -84,7 +85,7 @@ if True:
|
||||
case BC_{op_name}_{T}:{{
|
||||
{T} left = b->registers[instr->left].{t};
|
||||
{T} right = b->registers[instr->right].{t};
|
||||
bc_log("{sign} {symbol} {sign}", left, right);
|
||||
bc_log("v{sign} {symbol} v{sign}", left, right);
|
||||
b->registers[instr->dst].{t} = left {symbol} right; break;
|
||||
}}break;
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user