adjust branch struct to hold label data
This commit is contained in:
parent
59871d7a0e
commit
5bb68d95e1
@ -10,6 +10,7 @@ typedef enum {
|
|||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
word unconditionalOffset;
|
word unconditionalOffset;
|
||||||
|
char* label;
|
||||||
} a64inst_Branch_UnconditionalData;
|
} a64inst_Branch_UnconditionalData;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@ -29,6 +30,7 @@ typedef enum {
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
a64inst_ConditionType cond;
|
a64inst_ConditionType cond;
|
||||||
word offset;
|
word offset;
|
||||||
|
char* label;
|
||||||
} a64inst_Branch_ConditionalData;
|
} a64inst_Branch_ConditionalData;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
|||||||
38
src/parser.c
38
src/parser.c
@ -88,26 +88,6 @@ int isOperandRegister(char regStartChar) {
|
|||||||
return((regStartChar == 'x') || (regStartChar == 'w'));
|
return((regStartChar == 'x') || (regStartChar == 'w'));
|
||||||
}
|
}
|
||||||
|
|
||||||
//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[strlen(operand)];
|
|
||||||
strcpy(operandCpy, operand+1);
|
|
||||||
char **endptr = NULL;
|
|
||||||
int number;
|
|
||||||
if((strncmp(operandCpy, "0x", 2)==0)) {
|
|
||||||
//hex value
|
|
||||||
strcpy(operandCpy, operand+3);
|
|
||||||
number = strtol(operandCpy, endptr, 16);
|
|
||||||
} else if(operandCpy[0]=='x'){
|
|
||||||
strcpy(operandCpy, operand+2);
|
|
||||||
number = strtol(operandCpy, endptr, 16);
|
|
||||||
} else {
|
|
||||||
number = strtol(operandCpy, endptr, 10);
|
|
||||||
}
|
|
||||||
return number;
|
|
||||||
}
|
|
||||||
|
|
||||||
int classifyDPInst(char *operandList[]){
|
int classifyDPInst(char *operandList[]){
|
||||||
return(isOperandRegister(operandList[1][0]) &&
|
return(isOperandRegister(operandList[1][0]) &&
|
||||||
isOperandRegister(operandList[2][0]) &&
|
isOperandRegister(operandList[2][0]) &&
|
||||||
@ -208,7 +188,6 @@ void parse_instruction(char asmLine[], a64inst_instruction *instr) {
|
|||||||
if(strcmp(opcode, ".int") == 0){
|
if(strcmp(opcode, ".int") == 0){
|
||||||
// Directive
|
// Directive
|
||||||
instr->type = a64inst_DIRECTIVE;
|
instr->type = a64inst_DIRECTIVE;
|
||||||
instr->data.DirectiveData.value = getOperandNumber(tokens[1]);
|
|
||||||
|
|
||||||
} else if(opcode[strlen(opcode)-1]== ':') {
|
} else if(opcode[strlen(opcode)-1]== ':') {
|
||||||
// Label
|
// Label
|
||||||
@ -251,7 +230,22 @@ void parse_instruction(char asmLine[], a64inst_instruction *instr) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//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[strlen(operand)];
|
||||||
|
strcpy(operandCpy, operand+1);
|
||||||
|
char **endptr = NULL;
|
||||||
|
int number;
|
||||||
|
if(strncmp(operandCpy, "0x", 2)==0){
|
||||||
|
//hex value
|
||||||
|
strcpy(operandCpy, operand+3);
|
||||||
|
number = strtol(operandCpy, endptr, 16);
|
||||||
|
} else {
|
||||||
|
number = strtol(operandCpy, endptr, 10);
|
||||||
|
}
|
||||||
|
return number;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void calculateAddressFormat(a64inst_instruction *instr, char *tokens[], int tokenCount) {
|
void calculateAddressFormat(a64inst_instruction *instr, char *tokens[], int tokenCount) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user