Merge branch 'assembler-e' into 'assembler-s'
# Conflicts: # src/parser.c
This commit is contained in:
commit
6c1be8e1ef
27
src/parser.c
27
src/parser.c
@ -21,9 +21,8 @@
|
|||||||
//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){
|
||||||
char *operandCpy = NULL;
|
char operandCpy[strlen(operand)];
|
||||||
strcpy(operandCpy, operand);
|
strcpy(operandCpy, operand+1);
|
||||||
operandCpy++;
|
|
||||||
char **endptr = NULL;
|
char **endptr = NULL;
|
||||||
int number = strtol(operandCpy, endptr, 10);
|
int number = strtol(operandCpy, endptr, 10);
|
||||||
return number;
|
return number;
|
||||||
@ -97,9 +96,8 @@ void generateBranchOperands(a64inst_instruction *instr, char* opcode, char *oper
|
|||||||
break;
|
break;
|
||||||
case a64inst_CONDITIONAL:
|
case a64inst_CONDITIONAL:
|
||||||
{
|
{
|
||||||
char *condition = NULL;
|
char condition[strlen(opcode)+1];
|
||||||
condition = strcpy(condition, opcode);
|
strcpy(condition, opcode+2);
|
||||||
condition += 2;
|
|
||||||
if(strcmp(condition, "eq")==0){
|
if(strcmp(condition, "eq")==0){
|
||||||
instr->data.BranchData.processOpData.conditionalData.cond = EQ;
|
instr->data.BranchData.processOpData.conditionalData.cond = EQ;
|
||||||
} else if (strcmp(condition, "ne")==0){
|
} else if (strcmp(condition, "ne")==0){
|
||||||
@ -144,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];
|
||||||
@ -167,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)){
|
||||||
@ -211,10 +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
|
||||||
@ -224,14 +223,14 @@ void parser_instruction(char asmLine[], a64inst_instruction *instr) {
|
|||||||
//type is label
|
//type is label
|
||||||
//add to symbol table
|
//add to symbol table
|
||||||
instr->type = a64inst_LABEL;
|
instr->type = a64inst_LABEL;
|
||||||
char opcodeCpy[strlen(opcode)];
|
char opcodeCpy[strlen(opcode)+1];
|
||||||
strcpy(opcodeCpy, opcode);
|
strcpy(opcodeCpy, opcode);
|
||||||
char *labelData = strtok(opcodeCpy, ":");
|
char *labelData = strtok(opcodeCpy, ":");
|
||||||
instr->data.LabelData.label = labelData;
|
instr->data.LabelData.label = labelData;
|
||||||
} 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
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user