Exemplo n.º 1
0
int readFeatures(aggInstFeature af[INST_TYPE_NUM], const char* fname)
{
	featureValues* head = retriveFeatures(fname);
	featureValues* p = head;

	while(p)
	{
		int type = getInstType(p->token);
		af[type].type = type;
		af[type].count++;
		p = p->next;
	}

	return 0;
}
Exemplo n.º 2
0
void parseInstruction(FILE * fp, const char * instruction, int insIndex, Label ** lArr) {
	char code[INST_SIZE+1];
	char *inst, *p;
	int i, iType;

	if(instruction) {
		inst = malloc((strlen(instruction) +1) * sizeof(char));
	} else {
		fprintf(stderr, "instruction is NULL") ;
		exit(1);
	}
	strcpy(inst, instruction);
 
	for(i=0;i< INST_SIZE; i++) {
		code[i] = '0';
	}
	code[INST_SIZE] = '\0';

	i=0;

	while(!isspace(inst[i])) {
		i++;
	}
	inst[i] = '\0';
	/* we need inst to free it
	 * therefore use p to traverse the rest
	 */
	p =	 &inst[i+1];


	/* determine instruction type */
	iType = getInstType(inst, code);

	parseArgs(p, iType, code, insIndex);

	if(iType == TYPE_R ) {
		for(i=0;i < 6;i++) {
			fprintf(fp, "%c",code[i]);
		}
		fprintf(fp, " ");
		for(;i < 11; i++) {
			fprintf(fp, "%c", code[i]);
		}
		fprintf(fp, " ");
		for(;i < 16; i++) {
			fprintf(fp, "%c", code[i]);
		}
		fprintf(fp, " ");
		for(;i < 21; i++) {
			fprintf(fp, "%c", code[i]);
		}
		fprintf(fp, " ");
		for(;i < 26; i++) {
			fprintf(fp, "%c", code[i]);
		}
		fprintf(fp, " ");
		for(;i < INST_SIZE; i++) {
			fprintf(fp, "%c", code[i]);
		}
		fprintf(fp,"\n");
	} else if (iType == TYPE_I || iType == TYPE_LS) {
		for(i=0;i < 6;i++) {
			fprintf(fp, "%c",code[i]);
		}
		fprintf(fp, " ");
		for(;i < 11; i++) {
			fprintf(fp, "%c", code[i]);
		}
		fprintf(fp, " ");
		for(;i < 16; i++) {
			fprintf(fp, "%c", code[i]);
		}
		fprintf(fp, " ");
		for(;i < INST_SIZE; i++) {
			fprintf(fp, "%c", code[i]);
		}
		fprintf(fp,"\n");
	} else if (iType == TYPE_JR) {
		for(i=0;i < 6;i++) {
			fprintf(fp, "%c",code[i]);
		}
		fprintf(fp, " ");
		for(;i < 11; i++) {
			fprintf(fp, "%c", code[i]);
		}
		fprintf(fp, " ");
		for(;i < 26; i++) {
			fprintf(fp, "%c", code[i]);
		}
		fprintf(fp, " ");
		for(;i < INST_SIZE; i++) {
			fprintf(fp, "%c", code[i]);
		}
		fprintf(fp,"\n");
	} else if (iType == TYPE_J) {
		for(i=0;i < 6;i++) {
			fprintf(fp, "%c",code[i]);
		}
		fprintf(fp, " ");
		for(;i < INST_SIZE; i++) {
			fprintf(fp, "%c", code[i]);
		}
		fprintf(fp, " ");

		fprintf(fp,"\n");
	} else {
		fprintf(fp,"\n");
	}
	free(inst);
}