rename fileaccess
This commit is contained in:
parent
cadac4e1bb
commit
0f04ac9e22
@ -37,6 +37,7 @@ int writeBinaryFile(word instrs[], char outputFile[]){
|
||||
|
||||
//reads assembly file of "inputFile" name, and passes
|
||||
//each line into a parser
|
||||
//TODO: allocate whole file in memory, line-by-line
|
||||
int readAssemblyFile(char inputFile[]) {
|
||||
if (!isValidFileFormat(filename, "s")){
|
||||
exit(EXIT_FAILURE);
|
||||
10
src/parser.c
10
src/parser.c
@ -14,7 +14,10 @@
|
||||
// - count operands and match type/values
|
||||
// - generate final a64inst and return
|
||||
|
||||
char *tokeniseOperands(char* str, int operandCount, char *operands[]){
|
||||
//takes string of operands, and reference to operandcounter
|
||||
//takes input of result array
|
||||
//outputs array of operands
|
||||
void tokeniseOperands(char* str, int operandCount, char *operands[]){
|
||||
char *operandsDupe = strdup(str);
|
||||
int operandCount = 0;
|
||||
char *operand = strtok(operandsDupe, OPERAND_DELIMITER);
|
||||
@ -25,10 +28,10 @@ char *tokeniseOperands(char* str, int operandCount, char *operands[]){
|
||||
operand = strtok(NULL, OPERAND_DELIMITER);
|
||||
operands[operandCount] = operand;
|
||||
}
|
||||
return(operands);
|
||||
|
||||
}
|
||||
|
||||
//takes inputted assembly line and returns a
|
||||
//pointer to an abstract representation of the instruction
|
||||
a64inst_instruction *parser(char asmLine[]){
|
||||
a64inst_instruction *instr = malloc(sizeof(a64inst_instruction));
|
||||
if (instr == NULL){
|
||||
@ -36,6 +39,7 @@ a64inst_instruction *parser(char asmLine[]){
|
||||
}
|
||||
|
||||
//"opcode operand1, {operand2}, ..."
|
||||
//duplicated as strtok modifies the input string
|
||||
char *stringptr = strdup(asmLine);
|
||||
|
||||
char *opcode = strtok(stringptr, " ");
|
||||
|
||||
Loading…
Reference in New Issue
Block a user