calculate offsets for different store instructions
This commit is contained in:
parent
04dda33987
commit
4098ea5a5f
39
src/parser.c
39
src/parser.c
@ -17,8 +17,8 @@
|
||||
// - CREATE FUNC TO TIDY UP OPERANDS IN DP
|
||||
|
||||
//calculate offsets from string
|
||||
void calcluateAddressFormat(a64inst_instruction *instr, char *operandList[]){
|
||||
char *baseRegister = operandList[1];
|
||||
void calcluateAddressFormat(a64inst_instruction *instr, char *operandList[], int numOperands){
|
||||
char *baseRegister = strdup(operandList[1]);
|
||||
baseRegister++;
|
||||
baseRegister++;
|
||||
char *endptr;
|
||||
@ -27,20 +27,39 @@ void calcluateAddressFormat(a64inst_instruction *instr, char *operandList[]){
|
||||
|
||||
if(strcmp(operandList[2][strlen(operandList[1])-1], "!")==0){
|
||||
instr->data.SingleTransferData.processOpData.singleDataTransferData.addressingMode = a64inst_PRE_INDEXED;
|
||||
|
||||
char *offsetParam = strdup(operandList[2]);
|
||||
offsetParam++;
|
||||
instr->data.SingleTransferData.processOpData.singleDataTransferData.a64inst_addressingModeData.indexedOffset = strtol(operandList[2], endptr, 10);
|
||||
} else if(strcmp(operandList[1][strlen(operandList[0])-1], "]") == 0) {
|
||||
//post-indexed
|
||||
instr->data.SingleTransferData.processOpData.singleDataTransferData.addressingMode = a64inst_POST_INDEXED;
|
||||
char *offsetParam = strdup(operandList[2]);
|
||||
offsetParam++;
|
||||
instr->data.SingleTransferData.processOpData.singleDataTransferData.a64inst_addressingModeData.indexedOffset = strtol(operandList[2], endptr, 10);
|
||||
} else if( (strcmp(operandList[2][0], "x") == 0)
|
||||
|| (strcmp(operandList[2][0], "w") == 0)){
|
||||
//register
|
||||
instr->data.SingleTransferData.processOpData.singleDataTransferData.processOpData.addressingMode = a64inst_REGISTER_OFFSET;
|
||||
instr->data.SingleTransferData.processOpData.singleDataTransferData.addressingMode = a64inst_REGISTER_OFFSET;
|
||||
char *offsetRegister = strdup(operandList[2]);
|
||||
offsetRegister++;
|
||||
instr->data.SingleTransferData.processOpData.singleDataTransferData.addressingModeData.offsetReg = strtol(offsetRegister, endptr, 10);
|
||||
} else {
|
||||
instr->data.SingleTransferData.processOpData.singleDataTransferData.addressingMode = a64inst_UNSIGNED_OFFSET;
|
||||
if(numOperands==3){
|
||||
char *offsetParam = strdup(operandList[2]);
|
||||
offsetParam++;
|
||||
int offset = strtol(operandList[2], endptr, 10);
|
||||
if(instr->data.SingleTransferData.regType == 1){
|
||||
instr->data.SingleTransferData.processOpData.singleDataTransferData.a64inst_addressingModeData.unsignedOffset = offset/8;
|
||||
} else {
|
||||
instr->data.SingleTransferData.processOpData.singleDataTransferData.a64inst_addressingModeData.unsignedOffset = offset/4;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void generateLoadStoreOperands(a64inst_instruction *instr, char *opcode, char *operandList[]){
|
||||
void generateLoadStoreOperands(a64inst_instruction *instr, char *opcode, char *operandList[], int numOperands){
|
||||
switch(instr->type){
|
||||
case a64inst_SINGLETRANSFER:
|
||||
if(strcmp(operandList[0][0], "x")==0){
|
||||
@ -51,7 +70,7 @@ void generateLoadStoreOperands(a64inst_instruction *instr, char *opcode, char *o
|
||||
}
|
||||
char *endptr;
|
||||
instr->data.SingleTransferData.target = strtol(operandList[0][0]+1, endptr, 10);
|
||||
calcluateAddressFormat(instr, operandList);
|
||||
calcluateAddressFormat(instr, operandList, numOperands);
|
||||
break;
|
||||
case a64inst_LOADLITERAL:
|
||||
break;
|
||||
@ -102,7 +121,7 @@ int classifyDPInst(char *operandList[]){
|
||||
isOperandRegister(operandList[2]));
|
||||
}
|
||||
|
||||
void classifyOpcode(char* opcode, a64inst_instruction *instr, char *operandList[]){
|
||||
void classifyOpcode(char* opcode, a64inst_instruction *instr, char *operandList[], int numOperands){
|
||||
int isUnconditional = strcmp(opcode, "b");
|
||||
int isRegister = strcmp(opcode, "br");
|
||||
int isLoad = strcmp(opcode, "ldr");
|
||||
@ -149,7 +168,7 @@ void classifyOpcode(char* opcode, a64inst_instruction *instr, char *operandList[
|
||||
}
|
||||
}
|
||||
|
||||
char *tokeniseOperands(char* str, int operandCount, char *operands[]){
|
||||
char *tokeniseOperands(char* str, int operandCount, char *operands[], int numOperands){
|
||||
char *operandsDupe = strdup(str);
|
||||
char *operand = strtok(operandsDupe, OPERAND_DELIMITER);
|
||||
operands[0] = operand;
|
||||
@ -159,11 +178,13 @@ char *tokeniseOperands(char* str, int operandCount, char *operands[]){
|
||||
operand = strtok(NULL, OPERAND_DELIMITER);
|
||||
operands[operandCount] = operand;
|
||||
}
|
||||
numOperands = operandCount+1;
|
||||
}
|
||||
|
||||
//takes inputted assembly line and returns a
|
||||
//pointer to an abstract representation of the instruction
|
||||
a64inst_instruction *parser(char asmLine[]){
|
||||
int numOperands = 0;
|
||||
a64inst_instruction *instr = malloc(sizeof(a64inst_instruction));
|
||||
if (instr == NULL){
|
||||
exit(EXIT_FAILURE);
|
||||
@ -196,7 +217,7 @@ a64inst_instruction *parser(char asmLine[]){
|
||||
//type is instruction
|
||||
int operandCount = 0;
|
||||
const char *operandList[4];
|
||||
tokeniseOperands(operands, &operandCount, operandList);
|
||||
tokeniseOperands(operands, &operandCount, operandList, &numOperands);
|
||||
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user