diff --git a/src/parser.c b/src/parser.c index 98fa61a..b736d29 100644 --- a/src/parser.c +++ b/src/parser.c @@ -27,9 +27,21 @@ void classifyOpcode(char* opcode, a64inst_instruction *instr, char *operandList[ 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){ + } else if((int isLoad = strcmp(opcode, "ldr")) == 0 || (int isStore = strcmp(opcode, "str")) == 0){ //loading/storing instruction; classify operands - char *address = opcode[1]; + char *address = operandList[1]; + if( *address == '['){ + //type is register + instr->type = a64inst_SINGLETRANSFER; + if(isLoad == 0){ + instr->data.processOpData.singleDataTransferData.transferType = a64inst_LOAD; + } else { + instr->data.processOpData.singleDataTransferData.transferType = a64inst_STORE; + } + } else { + instr->type = a64inst_LOADLITERAL; + //instr->data.processOpData.offset = {} to be defined by symbol table + } } else { //data processing @@ -39,7 +51,6 @@ void classifyOpcode(char* opcode, a64inst_instruction *instr, char *operandList[ char *tokeniseOperands(char* str, int operandCount, char *operands[]){ char *operandsDupe = strdup(str); - int operandCount = 0; char *operand = strtok(operandsDupe, OPERAND_DELIMITER); operands[0] = operand; @@ -71,7 +82,7 @@ a64inst_instruction *parser(char asmLine[]){ if(strcmp(opcode, ".int") == 0){ //type is directive - //define new type in a64instr struct + } else if(strcmp(opcode[strlen(opcode)-1], ":") == 0) { //type is label //add to symbol table