rewrite DP classification logic
This commit is contained in:
parent
f57e0a786f
commit
1fa33798bf
49
src/parser.c
49
src/parser.c
@ -1,5 +1,6 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
#include "parser.h"
|
||||
|
||||
#include "a64instruction.h"
|
||||
@ -25,23 +26,23 @@ void calcluateAddressFormat(a64inst_instruction *instr, char *operandList[]){
|
||||
} else if( (strcmp(operandList[2][strlen(operandList[1])-1], "x") == 0)
|
||||
|| (strcmp(operandList[2][strlen(operandList[1])-1], "w") == 0)){
|
||||
//register
|
||||
instr->data.processOpData.addressingMode = a64inst_REGISTER_OFFSET;
|
||||
instr->data.SingleTransferData.singleDataTransferData.processOpData.addressingMode = a64inst_REGISTER_OFFSET;
|
||||
} else {
|
||||
instr->data.processOpData.addressingMode = a64inst_UNSIGNED_OFFSET;
|
||||
}
|
||||
}
|
||||
|
||||
void generateLoadStoreOperands(a64inst_instruction *instr, char *opcode, char *operandList[]){
|
||||
switch(instr->data.type){
|
||||
switch(instr->type){
|
||||
case a64inst_SINGLETRANSFER:
|
||||
if(strcmp(operandList[0][0], "x")==0){
|
||||
//x-register
|
||||
instr->data.regType = 1;
|
||||
instr->data.SingleTransferData.regType = 1;
|
||||
} else {
|
||||
instr->data.regType = 0;
|
||||
instr->data.SingleTransferData.regType = 0;
|
||||
}
|
||||
char *endptr;
|
||||
instr->data.target = strtol(operandList[0][0]+1, endptr, 2);
|
||||
instr->data.SingleTransferData.target = strtol(operandList[0][0]+1, endptr, 2);
|
||||
calcluateAddressFormat(instr, operandList);
|
||||
break;
|
||||
case a64inst_LOADLITERAL:
|
||||
@ -51,38 +52,48 @@ void generateLoadStoreOperands(a64inst_instruction *instr, char *opcode, char *o
|
||||
}
|
||||
|
||||
void generateBranchOperands(a64inst_instruction *instr, char* opcode, char *operandList[]){
|
||||
switch(instr->data.BranchType){
|
||||
switch(instr->data.BranchData.BranchType){
|
||||
case a64inst_UNCONDITIONAL:
|
||||
//define and sign extend immediate offset
|
||||
//use symbol table
|
||||
break;
|
||||
case a64inst_REGISTER:
|
||||
char *endptr;
|
||||
instr->data.processOpData.src = strtol(operandList[0] + 1, endptr, 2)
|
||||
instr->data.BranchData.processOpData.src = strtol(operandList[0] + 1, endptr, 2)
|
||||
break;
|
||||
case a64inst_CONDITIONAL:
|
||||
char* condition = strtok(strdup(opcode), "b.");
|
||||
condition = strtok(NULL, "");
|
||||
if(strcmp(condition, "eq")==0){
|
||||
instr->data.processOpData.cond = EQ;
|
||||
instr->data.branchData.processOpData.cond = EQ;
|
||||
} else if (strcmp(condition, "ne")==0){
|
||||
instr->data.processOpData.cond = NE;
|
||||
instr->data.branchData.processOpData.cond = NE;
|
||||
} else if (strcmp(condition, "ge")==0){
|
||||
instr->data.processOpData.cond = GE;
|
||||
instr->data.branchData.processOpData.cond = GE;
|
||||
} else if (strcmp(condition, "lt")==0){
|
||||
instr->data.processOpData.cond = LT;
|
||||
instr->data.branchData.processOpData.cond = LT;
|
||||
} else if (strcmp(condition, "gt")==0){
|
||||
instr->data.processOpData.cond = GT;
|
||||
instr->data.branchData.processOpData.cond = GT;
|
||||
} else if (strcmp(condition, "le")==0){
|
||||
instr->data.processOpData.cond = LE;
|
||||
instr->data.branchData.processOpData.cond = LE;
|
||||
} else if (srtcmp(condition, "al")==0){
|
||||
instr->data.processOpData.cond = AL;
|
||||
instr->data.branchData.processOpData.cond = AL;
|
||||
}
|
||||
break;
|
||||
//calculate offset from symbol table.
|
||||
}
|
||||
}
|
||||
|
||||
int isOperandRegister(char *operand){
|
||||
return((strcmp(operand[0], "x")==0) || (strcmp(operand[0], "w")==0));
|
||||
}
|
||||
|
||||
int classifyDPInst(char *operandList[]){
|
||||
return(isOperandRegister(operandList[0]) &&
|
||||
isOperandRegister(operandList[1]) &&
|
||||
isOperandRegister(operandList[2]));
|
||||
}
|
||||
|
||||
void classifyOpcode(char* opcode, a64inst_instruction *instr, char *operandList[]){
|
||||
int isUnconditional = strcmp(opcode, "b");
|
||||
int isRegister = strcmp(opcode, "br");
|
||||
@ -108,11 +119,11 @@ void classifyOpcode(char* opcode, a64inst_instruction *instr, char *operandList[
|
||||
if( *address == '['){
|
||||
//type is register
|
||||
instr->type = a64inst_SINGLETRANSFER;
|
||||
instr->data.SingleTransferOpType = a64inst_SINGLE_TRANSFER_SINGLE_DATA_TRANSFER;
|
||||
instr->data.singleTransferData.SingleTransferOpType = a64inst_SINGLE_TRANSFER_SINGLE_DATA_TRANSFER;
|
||||
if(isLoad == 0){
|
||||
instr->data.processOpData.transferType = a64inst_LOAD;
|
||||
instr->data.SingleTransferData.transferType = a64inst_LOAD;
|
||||
} else {
|
||||
instr->data.processOpData.transferType = a64inst_STORE;
|
||||
instr->data.SingleTransferData.processOpData.transferType = a64inst_STORE;
|
||||
}
|
||||
} else {
|
||||
instr->type = a64inst_LOADLITERAL;
|
||||
@ -121,7 +132,7 @@ void classifyOpcode(char* opcode, a64inst_instruction *instr, char *operandList[
|
||||
|
||||
} else {
|
||||
int numOperands = sizeof(operandList) / sizeof(operandList[0])
|
||||
if(numOperands==3){
|
||||
if(classifyDPInst(operandList)){
|
||||
instr->type = a64inst_DPREGISTER;
|
||||
} else {
|
||||
instr->type = a64inst_DPIMMEDIATE;
|
||||
@ -172,7 +183,7 @@ a64inst_instruction *parser(char asmLine[]){
|
||||
instr->type = a64inst_LABEL;
|
||||
char *opcodeCpy = strdup(opcode);
|
||||
char *labelData = strtok(opcodeCpy, ":");
|
||||
instr->data.label = labelData;
|
||||
instr->data.labelData.label = labelData;
|
||||
} else {
|
||||
//type is instruction
|
||||
int operandCount = 0;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user