restructure directive parsing into independent function
This commit is contained in:
parent
8bea0d6a6d
commit
e5b3f19bec
23
src/parser.c
23
src/parser.c
@ -16,6 +16,7 @@ void parseBranch(a64inst_instruction *instr, char* opcode, char *operandList[]);
|
|||||||
void calculateAddressFormat(a64inst_instruction *instr, char *operandList[], int numOperands);
|
void calculateAddressFormat(a64inst_instruction *instr, char *operandList[], int numOperands);
|
||||||
void parseDPImmediate(a64inst_instruction *inst, char *tokens[], int tokensCount);
|
void parseDPImmediate(a64inst_instruction *inst, char *tokens[], int tokensCount);
|
||||||
void parseDPRegister(a64inst_instruction *inst, char *tokens[], int tokensCount);
|
void parseDPRegister(a64inst_instruction *inst, char *tokens[], int tokensCount);
|
||||||
|
void parseDirective(a64inst_instruction *inst, char *tokens[]);
|
||||||
|
|
||||||
/** Constants */
|
/** Constants */
|
||||||
static const char *BRANCH_OPCODES[] = {"b", "br", "b.eq", "b.ne", "b.ge", "b.lt", "b.gt", "b.le", "b.al"};
|
static const char *BRANCH_OPCODES[] = {"b", "br", "b.eq", "b.ne", "b.ge", "b.lt", "b.gt", "b.le", "b.al"};
|
||||||
@ -212,14 +213,8 @@ 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;
|
||||||
char *intValue = tokens[1];
|
parseDirective(instr, tokens);
|
||||||
char *endptr;
|
|
||||||
if(strncmp(intValue, "0x", 2) == 0) {
|
|
||||||
intValue += 2;
|
|
||||||
instr->data.DirectiveData.value = strtol(intValue, &endptr, 16);
|
|
||||||
} else {
|
|
||||||
instr->data.DirectiveData.value = strtol(tokens[1], &endptr, 10);
|
|
||||||
}
|
|
||||||
|
|
||||||
} else if(opcode[strlen(opcode)-1]== ':') {
|
} else if(opcode[strlen(opcode)-1]== ':') {
|
||||||
// Label
|
// Label
|
||||||
@ -305,6 +300,18 @@ static int parseRegisterType(char *operand) {
|
|||||||
return operand[0] == 'x';
|
return operand[0] == 'x';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void parseDirective(a64inst_instruction *instr, char *tokens[]) {
|
||||||
|
char *intValue = tokens[1];
|
||||||
|
char *endptr;
|
||||||
|
if(strncmp(intValue, "0x", 2) == 0) {
|
||||||
|
intValue += 2;
|
||||||
|
instr->data.DirectiveData.value = strtol(intValue, &endptr, 16);
|
||||||
|
} else {
|
||||||
|
instr->data.DirectiveData.value = strtol(tokens[1], &endptr, 10);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void parseSingleTransfer(a64inst_instruction *instr, char *opcode, char *tokens[], int tokensCount) {
|
void parseSingleTransfer(a64inst_instruction *instr, char *opcode, char *tokens[], int tokensCount) {
|
||||||
|
|
||||||
switch(instr->type){
|
switch(instr->type){
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user