instructions rename and uninitialized memory error fix
This commit is contained in:
@@ -68,7 +68,7 @@ static bool compileSection(Compiler* cmp, Section* sec){
|
||||
CompiledSection* cs = List_CompiledSection_expand(&cmp->binary.section_list, 1);
|
||||
CompiledSection_construct(cs, sec->name);
|
||||
if(!HashMap_CompiledSectionPtr_tryPush(&cmp->binary.section_map, cs->name, cs)){
|
||||
returnError("duplicate section '%s'", str_copy(sec->name));
|
||||
returnError("duplicate section '%s'", str_copy(sec->name).data);
|
||||
}
|
||||
|
||||
// compile code
|
||||
@@ -308,6 +308,10 @@ bool Compiler_compile(Compiler* cmp, cstr source_file_name, cstr out_file_name,
|
||||
for(u32 j = 0; j < sec->code.len; j++){
|
||||
Operation* op = &sec->code.data[j];
|
||||
const Instruction* instr = Instruction_getByOpcode(op->opcode);
|
||||
if(instr == NULL){
|
||||
returnError("unknown opcode: %i", op->opcode)
|
||||
}
|
||||
|
||||
printf(" %s", instr->name.data);
|
||||
for(u32 k = 0; k < op->args.len; k++){
|
||||
Argument* arg = &op->args.data[k];
|
||||
|
||||
@@ -259,10 +259,12 @@ bool Compiler_parse(Compiler* cmp){
|
||||
// data definition starts with const
|
||||
if(str_startsWith(instr_name, STR("const"))){
|
||||
DataDefinition* dataDefPtr = List_DataDefinition_expand(&sec->data, 1);
|
||||
memset(dataDefPtr, 0, sizeof(DataDefinition));
|
||||
parseDataDefinition(cmp, instr_name, dataDefPtr);
|
||||
}
|
||||
else {
|
||||
Operation* operPtr = List_Operation_expand(&sec->code, 1);
|
||||
memset(operPtr, 0, sizeof(Operation));
|
||||
parseOperation(cmp, instr_name, operPtr);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "impl_macros.h"
|
||||
|
||||
/// MOV [dst_register] [src_register]
|
||||
i32 MOV_impl(VM* vm){
|
||||
/// MOVR [dst_register] [src_register]
|
||||
i32 MOVR_impl(VM* vm){
|
||||
u8 dst_register_i = 0;
|
||||
readRegisterVar(dst_register_i);
|
||||
u8 src_register_i = 0;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "impl_macros.h"
|
||||
|
||||
/// PUSH [dst_register] [value_size] [value]
|
||||
i32 PUSH_impl(VM* vm){
|
||||
/// MOVC [dst_register] [value_size] [value]
|
||||
i32 MOVC_impl(VM* vm){
|
||||
u8 dst_register_i = 0;
|
||||
readRegisterVar(dst_register_i);
|
||||
/*u8 value_size = 0;
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
#include "../collections/HashMap.h"
|
||||
|
||||
i32 NOP_impl(VM* vm);
|
||||
i32 PUSH_impl(VM* vm);
|
||||
i32 MOV_impl(VM* vm);
|
||||
i32 MOVC_impl(VM* vm);
|
||||
i32 MOVR_impl(VM* vm);
|
||||
i32 ADD_impl(VM* vm);
|
||||
i32 SUB_impl(VM* vm);
|
||||
i32 MUL_impl(VM* vm);
|
||||
@@ -17,8 +17,8 @@ i32 CALL_impl(VM* vm);
|
||||
Array_declare(Instruction);
|
||||
static const Array_Instruction instructions_array = ARRAY(Instruction, {
|
||||
Instruction_construct(NOP),
|
||||
Instruction_construct(PUSH),
|
||||
Instruction_construct(MOV),
|
||||
Instruction_construct(MOVC),
|
||||
Instruction_construct(MOVR),
|
||||
Instruction_construct(ADD),
|
||||
Instruction_construct(SUB),
|
||||
Instruction_construct(MUL),
|
||||
|
||||
@@ -7,8 +7,8 @@ typedef i32 (*InstructionImplFunc_t)(VM* vm);
|
||||
|
||||
typedef enum __attribute__((__packed__)) Opcode {
|
||||
Opcode_NOP,
|
||||
Opcode_PUSH,
|
||||
Opcode_MOV,
|
||||
Opcode_MOVC,
|
||||
Opcode_MOVR,
|
||||
Opcode_ADD,
|
||||
Opcode_SUB,
|
||||
Opcode_MUL,
|
||||
|
||||
Reference in New Issue
Block a user