void fillCode (FILE *file) { char line[8] ={0}; int i = 0; char *terms[3]={0}; while (fgets(line, sizeof(line), file) ) { // printLine(line); IR inst; //split input line using space a delim splitLine(line, terms); //generate instruction object using values in terms[] generateInst(&inst, terms, i); //set current code index to new inst obj code[i] = inst; //clear line in memory memset(&line[0], 0, sizeof(line)); i++; } CURRENT_CODE_LENGTH = i; stack[0] = (int) &code; }
// Blah blah blah... miniTramp *instPoint::instrument(AstNode *ast, callWhen when, callOrder order, bool trampRecursive, bool noCost) { miniTramp *mini = addInst(ast, when, order, trampRecursive, noCost); if (!mini) { cerr << "instPoint::instrument: failed addInst, ret NULL" << endl; return NULL; } if (!generateInst()) { cerr << "instPoint::instrument: failed generateInst, ret NULL" << endl; return NULL; } if (!installInst()) { cerr << "instPoint::instrument: failed installInst, ret NULL" << endl; return NULL; } if (!linkInst()) { cerr << "instPoint::instrument: failed linkInst, ret NULL" << endl; return NULL; } return mini; }
void fillCode (char* fileName) { int i = 0; char *terms[3] = {0}; int c = 0; int j = 0; int k = 0; char *line = malloc ( 8 * sizeof(char)); char* inputStream = fillInputStream(fileName); size_t size = strlen(inputStream); for (k = 0; k < size; k++) { c = inputStream[k]; if ( c == '\n' ) { IR inst; line[j] = '\0'; char* tmp = strdup(line); terms[0] = strsep(&tmp, " "); terms[1] = strsep(&tmp, " "); terms[2] = strsep(&tmp, " "); //generate instruction object using values in terms[] generateInst(&inst, terms, i); //set current code index to new inst obj code[i] = inst; i++; // printf("%s\n", line); //clear line in memory memset(line, 0, sizeof(*line)); j = 0; } else if ( (k == size - 1) && isdigit(c) ) { line[j] = c; line[j + 1] = '\0'; char* tmp = strdup(line); terms[0] = strsep(&tmp, " "); terms[1] = strsep(&tmp, " "); terms[2] = strsep(&tmp, " "); IR inst; //generate instruction object using values in terms[] generateInst(&inst, terms, i); //set current code index to new inst obj code[i] = inst; i++; // printf("%s\n", line); //clear line in memory memset(line, 0, sizeof(*line)); j = 0; } else { line[j] = c; j++; } } CURRENT_CODE_LENGTH = i; // puts("end of code fill\n"); }