int main(int argc, char *argv[]) { // Declare a pointer to the input file FILE *inFile; // Declare a pointer to the root file name char *rootName; // Declare pointers to the head and tail of the symbol table DEF_NODE *head, *tail; // Set head and tail to NULL head = tail = NULL; // Initialize the errorIndex to 0 errorIndex = 0; // Find the root file name and set it rootName = (char *)findRootFileName(argv[IN_FILE]); // Try to open the input file for reading if((inFile = fopen(argv[IN_FILE], "r")) == NULL) { // Print error message if file could not be opened fprintf(stderr, "Could not open file: %s\n", argv[IN_FILE]); // Fatal error, exit program exit(1); } // Initialize all the opcodes initOpcodes(); // Do the first pass and build the symbol table passOne(inFile, &head, &tail); // Rewind the input file so it is ready for the second pass rewind(inFile); // Do the second pass and check for errors passTwo(inFile, &head, &tail); // If there were errors in the input file... if(errorIndex > 0) { // Make an error file writeErrFile(inFile, rootName); } // There were no errors in the input file else { // Write the symbol table file printST(head, rootName); // Write the object code file writeObjFile(rootName); } // Try to close the input file if(fclose(inFile) == EOF) { // If file could not be closed, print error fprintf(stderr, "Could not close file: %s\n", argv[IN_FILE]); // Fatal error, exit program exit(1); } // Program finished without errors, return 0 return 0; }
int main (int argc, char *argv[]) { if((argc > 2) || (argc <= 1)) { printf("Syntax: ssasm <inputFileName>\n"); return 0; } writeOpcodeSheet(); printf("\n**********************************************************************************\n"); printf("\t\tSIC machine assembler by Suhas H and Sumukha TV\n\n"); passOne(argv[1]); checkError(argv[1]); // check if there are any errors in the source code length = LOCCTR - startAddr; if(flag == 0) // perform pass two only if no errors are found passTwo(argv[1]); else printf("\nAssembler Terminated!\n"); printf("\n**********************************************************************************\n\n"); return 0; }