Merge branch 'assembler-e' into 'assembler-s'

# Conflicts:
#   src/parser.c
This commit is contained in:
Dias Alberto, Ethan 2024-06-12 16:49:17 +00:00
commit 6c1be8e1ef

View File

@ -21,9 +21,8 @@
//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
int getOperandNumber(char *operand){
char *operandCpy = NULL;
strcpy(operandCpy, operand);
operandCpy++;
char operandCpy[strlen(operand)];
strcpy(operandCpy, operand+1);
char **endptr = NULL;
int number = strtol(operandCpy, endptr, 10);
return number;
@ -97,9 +96,8 @@ void generateBranchOperands(a64inst_instruction *instr, char* opcode, char *oper
break;
case a64inst_CONDITIONAL:
{
char *condition = NULL;
condition = strcpy(condition, opcode);
condition += 2;
char condition[strlen(opcode)+1];
strcpy(condition, opcode+2);
if(strcmp(condition, "eq")==0){
instr->data.BranchData.processOpData.conditionalData.cond = EQ;
} else if (strcmp(condition, "ne")==0){
@ -144,7 +142,6 @@ void classifyOpcode(char* opcode, a64inst_instruction *instr, char *operandList[
} else {
instr->data.BranchData.BranchType = a64inst_CONDITIONAL;
}
generateBranchOperands(instr, opcode, operandList);
} else if(isLoad == 0 || isStore == 0){
//loading/storing instruction; classify operands
char *address = operandList[1];
@ -167,7 +164,6 @@ void classifyOpcode(char* opcode, a64inst_instruction *instr, char *operandList[
//offset is literal, use symbol table and calculate difference
}
}
generateLoadStoreOperands(instr, opcode, operandList, numOperands);
} else {
if(classifyDPInst(operandList)){
@ -211,10 +207,13 @@ void parser_instruction(char asmLine[], a64inst_instruction *instr) {
//duplicated as strtok modifies the input string
char stringptr[strlen(asmLine) + 1];
strcpy(stringptr, asmLine);
char *opcode = strtok(stringptr, " ");
char *operands = strtok(stringptr, "");
char *token;
token = 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){
//type is directive
@ -224,14 +223,14 @@ void parser_instruction(char asmLine[], a64inst_instruction *instr) {
//type is label
//add to symbol table
instr->type = a64inst_LABEL;
char opcodeCpy[strlen(opcode)];
char opcodeCpy[strlen(opcode)+1];
strcpy(opcodeCpy, opcode);
char *labelData = strtok(opcodeCpy, ":");
instr->data.LabelData.label = labelData;
} else {
//type is instruction
int operandCount = 0;
char *operandList[4];
char *operandList[5];
//generate list of operands
tokeniseOperands(operands, &operandCount, operandList, &numOperands);
//categorise instruction type from opcode and operands