Update parser to correctly handle the zero register

This commit is contained in:
sBubshait 2024-06-14 20:46:35 +01:00
parent 3838227a09
commit 58371a4fa4

View File

@ -25,6 +25,7 @@ static const char *ARITHMETIC_OPCODES[] = {"add", "adds", "sub", "subs"};
static const char *MULTIPLY_OPCODES[] = {"mul", "madd", "msub", "mneg"}; static const char *MULTIPLY_OPCODES[] = {"mul", "madd", "msub", "mneg"};
static const char *SHIFT_TYPE_OPCODES[] = {"lsl", "lsr", "asr", "ror"}; static const char *SHIFT_TYPE_OPCODES[] = {"lsl", "lsr", "asr", "ror"};
static const char *LOGIC_OPCODES[] = {"and", "ands", "bic", "bics", "eor", "eon", "orr", "orn"}; static const char *LOGIC_OPCODES[] = {"and", "ands", "bic", "bics", "eor", "eon", "orr", "orn"};
static const char *ZERO_REGISTER_ALIAS[] = {"xzr", "wzr"};
static const char *ALIAS_OPCODES[] = {"cmp", "cmn", "neg", "negs", "tst", "mvn", "mov"}; static const char *ALIAS_OPCODES[] = {"cmp", "cmn", "neg", "negs", "tst", "mvn", "mov"};
static char *ALIAS_TARGET_OPCODES[] = {"subs", "adds", "sub", "subs", "ands", "orn", "orr"}; static char *ALIAS_TARGET_OPCODES[] = {"subs", "adds", "sub", "subs", "ands", "orn", "orr"};
@ -172,6 +173,10 @@ void classifyOpcode(char* opcode, a64inst_instruction *instr, char *tokens[], in
//takes inputted char array and returns the integer of the operand, skipping the first character //takes inputted char array and returns the integer of the operand, skipping the first character
//e.g. for a passed "R32", it skips the 'R' and returns 32 //e.g. for a passed "R32", it skips the 'R' and returns 32
int getOperandNumber(char *operand){ int getOperandNumber(char *operand){
if (isStringIn(operand, ZERO_REGISTER_ALIAS, 2)) {
return ZERO_REGISTER;
}
char operandCpy[strlen(operand)]; char operandCpy[strlen(operand)];
strcpy(operandCpy, operand+1); strcpy(operandCpy, operand+1);
char **endptr = NULL; char **endptr = NULL;