Register stuff cleanup
This commit is contained in:
@@ -1,10 +1,14 @@
|
||||
#define BC_LOG 1
|
||||
#if BC_LOG
|
||||
#define bc_log(...) log_info(__VA_ARGS__)
|
||||
#else
|
||||
#define bc_log(...)
|
||||
#endif
|
||||
|
||||
//
|
||||
// Generated using code_generating_script.py
|
||||
//
|
||||
|
||||
|
||||
|
||||
enum Operation: S32{
|
||||
BC_END_OF_INSTRUCTIONS,
|
||||
BC_POP_STACK,
|
||||
@@ -142,12 +146,6 @@ union Register{
|
||||
U8 *pointer;
|
||||
};
|
||||
|
||||
enum{
|
||||
REG_STACK_POINTER,
|
||||
REG_INSTRUCTION_POINTER,
|
||||
REG_SPECIAL_COUNT,
|
||||
};
|
||||
|
||||
struct Instruction{
|
||||
Operation operation;
|
||||
S32 index_c;
|
||||
@@ -168,8 +166,10 @@ struct Instruction{
|
||||
//
|
||||
struct Bc{
|
||||
U32 dis; // @debug_id
|
||||
U8 *stack_bottom;
|
||||
|
||||
U64 *stack_bottom;
|
||||
U64 *stack_pointer;
|
||||
Instruction *instruction_pointer;
|
||||
Array<Register> registers;
|
||||
Array<Register_Index> used_registers;
|
||||
Array<Register_Index> free_registers;
|
||||
@@ -218,10 +218,6 @@ create_bytecode_interp(){
|
||||
b.free_registers = array_make<Register_Index>(pctx->heap, 1024);
|
||||
b.used_registers = array_make<Register_Index>(pctx->heap, 1024);
|
||||
|
||||
for(S32 i = 0; i < REG_SPECIAL_COUNT; i++){
|
||||
allocate_register(&b);
|
||||
}
|
||||
|
||||
{
|
||||
arena_init(&b.instructions, "Bytecode instructions"_s);
|
||||
arena_push_size(&b.instructions, 16); // Commit
|
||||
@@ -326,47 +322,40 @@ emit_end(Bc *b){
|
||||
i->operation = BC_END_OF_INSTRUCTIONS;
|
||||
}
|
||||
|
||||
#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){
|
||||
// Setup registers
|
||||
b->registers[REG_INSTRUCTION_POINTER].pointer = b->instructions.memory.data;
|
||||
b->registers[REG_STACK_POINTER].pointer = b->stack_bottom = b->stack.memory.data;
|
||||
b->instruction_pointer = (Instruction *)b->instructions.memory.data;
|
||||
b->stack_pointer = b->stack_bottom = (U64 *)b->stack.memory.data;
|
||||
|
||||
for(;;){
|
||||
auto instr = (Instruction *)b->registers[REG_INSTRUCTION_POINTER].pointer64;
|
||||
bc_log("%llu.[0x%llx] - %s ", instr->di, b->registers[REG_INSTRUCTION_POINTER].pointer64, op_name[instr->operation]);
|
||||
b->registers[REG_INSTRUCTION_POINTER].pointer += sizeof(Instruction);
|
||||
Instruction *instr = b->instruction_pointer++;
|
||||
bc_log("i%u[0x%llx] %s ", instr->di, instr, op_name[instr->operation]);
|
||||
|
||||
switch(instr->operation){
|
||||
default:{}
|
||||
case BC_LOAD_FROM_MEMORY64:{
|
||||
U64 *load_address = b->registers[instr->index_a].pointer64;
|
||||
b->registers[instr->index_c].u64 = *load_address;
|
||||
bc_log("r%u(dst) [0x%llx|%lld|%f]", instr->index_c, b->registers[instr->index_c].u64, b->registers[instr->index_c].u64, b->registers[instr->index_c].u64);
|
||||
bc_log("load_address[r%u, %llx] dst[r%u] [0x%llx|%lld|%f]", instr->index_a, load_address, instr->index_c, b->registers[instr->index_c].u64, b->registers[instr->index_c].u64, b->registers[instr->index_c].u64);
|
||||
}break;
|
||||
|
||||
case BC_STORE_TO_MEMORY64:{
|
||||
U64 *store_address = b->registers[instr->index_c].pointer64;
|
||||
*store_address = b->registers[instr->index_a].u64;
|
||||
bc_log("r%u(src) [0x%llx|%lld|%f]", instr->index_a, *store_address, *store_address, *store_address);
|
||||
bc_log("src[r%u] store_address[r%u, %llx] value_written[0x%llx|%lld|%f]", instr->index_a, instr->index_c, store_address, *store_address, *store_address, *store_address);
|
||||
}break;
|
||||
|
||||
case BC_PUSH_STACK:{
|
||||
U64 *stack = b->registers[REG_STACK_POINTER].pointer64++;
|
||||
U64 *stack = b->stack_pointer++;
|
||||
|
||||
U64 src = b->registers[instr->index_a].u64;
|
||||
bc_log("r%u(src) [0x%llx|%lld|%f]", instr->index_a, src, src, src);
|
||||
*stack = src;
|
||||
}break;
|
||||
|
||||
case BC_POP_STACK:{
|
||||
U64 *stack = --b->registers[REG_STACK_POINTER].pointer64;
|
||||
U64 *stack = --b->stack_pointer;
|
||||
bc_log("r%u(dst) [0x%llx|%lld|%f]", instr->index_c, *stack, *stack, *stack);
|
||||
b->registers[instr->index_c].u64 = *stack;
|
||||
}break;
|
||||
@@ -379,10 +368,10 @@ run_bytecode_interp(Bc *b){
|
||||
b->registers[instr->index_c] = instr->constant;
|
||||
#if BC_LOG
|
||||
switch(instr->debug_type_flag){
|
||||
case TYPE_S64: bc_log("r%u(dst) [%lld]", instr->index_c, instr->constant.s64); break;
|
||||
case TYPE_U64: bc_log("r%u(dst) [%llu]", instr->index_c, instr->constant.u64); break;
|
||||
case TYPE_F64: bc_log("r%u(dst) [%f]" , instr->index_c, instr->constant.f64); break;
|
||||
case TYPE_POINTER: bc_log("r%u(dst) [0x%llx]" , instr->index_c, instr->constant.pointer64); break;
|
||||
case TYPE_S64: bc_log("dst[r%u] S64[%lld]", instr->index_c, instr->constant.s64); break;
|
||||
case TYPE_U64: bc_log("dst[r%u] U64[%llu]", instr->index_c, instr->constant.u64); break;
|
||||
case TYPE_F64: bc_log("dst[r%u] F64[%f]" , instr->index_c, instr->constant.f64); break;
|
||||
case TYPE_POINTER: bc_log("dst[r%u] Pointer[0x%llx]" , instr->index_c, instr->constant.pointer64); break;
|
||||
invalid_default_case;
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user