rewrite opcode/operand splitting logic

This commit is contained in:
EDiasAlberto 2024-06-12 17:34:14 +01:00
parent 53f5b05210
commit 06b18706ed

View File

@ -142,7 +142,6 @@ void classifyOpcode(char* opcode, a64inst_instruction *instr, char *operandList[
} else { } else {
instr->data.BranchData.BranchType = a64inst_CONDITIONAL; instr->data.BranchData.BranchType = a64inst_CONDITIONAL;
} }
generateBranchOperands(instr, opcode, operandList);
} else if(isLoad == 0 || isStore == 0){ } else if(isLoad == 0 || isStore == 0){
//loading/storing instruction; classify operands //loading/storing instruction; classify operands
char *address = operandList[1]; char *address = operandList[1];
@ -165,7 +164,6 @@ void classifyOpcode(char* opcode, a64inst_instruction *instr, char *operandList[
//offset is literal, use symbol table and calculate difference //offset is literal, use symbol table and calculate difference
} }
} }
generateLoadStoreOperands(instr, opcode, operandList, numOperands);
} else { } else {
if(classifyDPInst(operandList)){ if(classifyDPInst(operandList)){
@ -209,9 +207,13 @@ void parser_instruction(char asmLine[], a64inst_instruction *instr) {
//duplicated as strtok modifies the input string //duplicated as strtok modifies the input string
char stringptr[strlen(asmLine) + 1]; char stringptr[strlen(asmLine) + 1];
strcpy(stringptr, asmLine); strcpy(stringptr, asmLine);
char *token;
char *opcode = strtok(stringptr, " "); token = strtok(stringptr, " ");
char *operands = strtok(stringptr, ""); char opcode[strlen(token)+1];
strcpy(opcode, token);
token = strtok(NULL, "");
char operands[strlen(token)+1];
strcpy(operands, token);
if(strcmp(opcode, ".int") == 0){ if(strcmp(opcode, ".int") == 0){
//type is directive //type is directive
@ -228,7 +230,7 @@ void parser_instruction(char asmLine[], a64inst_instruction *instr) {
} else { } else {
//type is instruction //type is instruction
int operandCount = 0; int operandCount = 0;
char *operandList[4]; char *operandList[5];
//generate list of operands //generate list of operands
tokeniseOperands(operands, &operandCount, operandList, &numOperands); tokeniseOperands(operands, &operandCount, operandList, &numOperands);
//categorise instruction type from opcode and operands //categorise instruction type from opcode and operands