classify asm line type, tokenise operands
This commit is contained in:
parent
ba1b614fc1
commit
036e163fe8
@ -1,8 +1,6 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#define MAX_ASM_LINE_LENGTH 100
|
|
||||||
|
|
||||||
//validates inputted charlist as valid filename against expected extension
|
//validates inputted charlist as valid filename against expected extension
|
||||||
int isValidFileFormat(char filename[], char expectedExtension[]){
|
int isValidFileFormat(char filename[], char expectedExtension[]){
|
||||||
int *pointLoc = strrchr(filename, '.');
|
int *pointLoc = strrchr(filename, '.');
|
||||||
@ -45,7 +43,7 @@ int readAssemblyFile(char inputFile[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
char savedLine[MAX_ASM_LINE_LENGTH];
|
char savedLine[sizeof(a64inst_instruction)];
|
||||||
|
|
||||||
fp = fopen(inputFile, "r");
|
fp = fopen(inputFile, "r");
|
||||||
|
|
||||||
|
|||||||
39
src/parser.c
39
src/parser.c
@ -14,6 +14,43 @@
|
|||||||
// - count operands and match type/values
|
// - count operands and match type/values
|
||||||
// - generate final a64inst and return
|
// - generate final a64inst and return
|
||||||
|
|
||||||
a64inst_instruction parser(char asmLine[]){
|
char *splitOperands(char* str, int operandCount, char *operands[]){
|
||||||
|
char *operandsDupe = strdup(str);
|
||||||
|
int operandCount = 0;
|
||||||
|
char *operand = strtok(operandsDupe, OPERAND_DELIMITER);
|
||||||
|
operands[0] = operand;
|
||||||
|
|
||||||
|
while (operand != NULL){
|
||||||
|
operandCount++;
|
||||||
|
operand = strtok(NULL, OPERAND_DELIMITER);
|
||||||
|
operands[operandCount] = operand;
|
||||||
|
}
|
||||||
|
return(operands);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
a64inst_instruction *tokeniser(char asmLine[]){
|
||||||
|
a64inst_instruction *instr = malloc(sizeof(a64inst_instruction));
|
||||||
|
if (instr == NULL){
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
//"opcode operand1, {operand2}, ..."
|
||||||
|
char *stringptr = strdup(asmLine);
|
||||||
|
|
||||||
|
char *opcode = strtok(stringptr, " ");
|
||||||
|
char *operands = strtok(NULL, "");
|
||||||
|
|
||||||
|
if(opcode[0]=="."){
|
||||||
|
//type is directive
|
||||||
|
} else if(opcode[strlen(opcode)-1]==":") {
|
||||||
|
//type is label
|
||||||
|
} else {
|
||||||
|
//type is instruction
|
||||||
|
int operandCount = 0;
|
||||||
|
const char *operandList[4];
|
||||||
|
splitOperands(operands, &operandCount, operandList);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -0,0 +1 @@
|
|||||||
|
#define OPERAND_DELIMITER ", "
|
||||||
Loading…
Reference in New Issue
Block a user