classify branch type from opcode

This commit is contained in:
EDiasAlberto 2024-06-04 03:35:06 +01:00
parent bb3218b535
commit 13e2cc8c9d
2 changed files with 14 additions and 4 deletions

View File

@ -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;

View File

@ -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)
{