From 13e2cc8c9d556cdb92d2f02de01980c36fbe8b8d Mon Sep 17 00:00:00 2001 From: EDiasAlberto Date: Tue, 4 Jun 2024 03:35:06 +0100 Subject: [PATCH] classify branch type from opcode --- src/parser.c | 16 +++++++++++++--- src/twopassassembly.c | 2 +- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/parser.c b/src/parser.c index e944ebc..0103a3d 100644 --- a/src/parser.c +++ b/src/parser.c @@ -10,13 +10,23 @@ //TODO: // - use string matching to get opcode, and operands (DONE) // - check operand count (DONE) -// - match opcode to a64 struct types +// - match opcode to a64 struct types (PARTIALLY DONE) // - count operands and match type/values // - generate final a64inst and return void classifyOpcode(char* opcode, a64inst_instruction *instr){ - if(strcmp(opcode, "b") == 0 || strcmp(opcode, "br") == 0 || strncmp(opcode, "b.", strlen("b.")) == 2){ - instr->type = a64inst_BRANCH; + if((int isUnconditional = strcmp(opcode, "b")) == 0 || + (int isRegister = strcmp(opcode, "br")) == 0 || + strncmp(opcode, "b.", 2) == 0){ + instr->type = a64inst_BRANCH; + if(isUnconditional){ + instr->data.BranchData.BranchType = a64inst_UNCONDITIONAL; + } else if (isRegister){ + instr->data.BranchData.BranchType = a64inst_REGISTER; + } else { + instr->data.BranchData.BranchType = a64inst_CONDITIONAL; + //instr->data.branchData.processOpData.cond = {remove first two chars of opcode} + } } else if(strcmp(opcode, "ldr") == 0 || strcmp(opcode, "str") == 0){ //loading/storing instruction; classify operands instr->type = a64inst_SINGLETRANSFER; diff --git a/src/twopassassembly.c b/src/twopassassembly.c index d2536dd..f7b75f8 100644 --- a/src/twopassassembly.c +++ b/src/twopassassembly.c @@ -11,7 +11,7 @@ void generateSymbolTable(a64inst_instruction instrs[], int numInstrs){ } } -word assembleBranch(a64inst_instruction *instr){ +word assembleBranch(a64inst_instruction *instr, int ){ word binInstr = 0; switch (instr->data.BranchData.BranchType) {