示例#1
0
/*
 * Wrapper to dynamically load LIB_LLVM and call LLVMCreateDisasm().
 */
__private_extern__
LLVMDisasmContextRef
llvm_create_disasm(
const char *TripleName,
const char *CPU,
void *DisInfo,
int TagType,
LLVMOpInfoCallback GetOpInfo,
LLVMSymbolLookupCallback SymbolLookUp)
{
   LLVMDisasmContextRef DC;

	if(tried_to_load_llvm == 0){
	    load_llvm();
	}
	if(llvm_handle == NULL)
	    return(NULL);

	/*
	 * Note this was added after the interface was defined, so it may
	 * be undefined.  But if not we must call it first.
	 */
	initialize = dlsym(llvm_handle, "lto_initialize_disassembler");
	if(initialize != NULL)
	    initialize();

	if(*CPU != '\0' && createCPU != NULL)
	    DC = createCPU(TripleName, CPU, DisInfo, TagType, GetOpInfo,
			   SymbolLookUp);
	else
	    DC = create(TripleName, DisInfo, TagType, GetOpInfo, SymbolLookUp);
	return(DC);
}
示例#2
0
文件: Driver.c 项目: inochi108/OS_HW2
void main(void) {

	srand(time(NULL));
	char processNameSetUp[10] = "Process";
	int i = 0;
	FIFO_queue_p PCBContainer = createLinkedList();
	PCB_p tempPCB;
	int PCBCounter = 0;
	int loopCounter = 0;
	int numberOfPCB = 0;

	FILE* outFile = fopen("scheduleTrace.txt", "w+");
	fprintf(outFile, "Group 5: Nok Him Nam, Jowy Tran, Mark Johnson, David Humphreys\nDate (DD/MM/YY) : 28/ 01/ 2015\nAssignment : Problem 2 - Scheduling\n");

	//Create CPU
	CPU_instance_p testingCPU = createCPU();

	//Master CPU Loop
	while (loopCounter <= MAX_NUMBER_OF_RUNTIME) {

		if (loopCounter % PRINT_EVERY_xTIMES == 0) {
			fprintf(outFile, "\n__________NEXT TIME QUANTUM  : %d___________\n", loopCounter);
		}

		numberOfPCB = rand() % 6;

		//While the number of PCBs created is less than 30, create more PCBs
		if (PCBCounter < MAX_NUMBER_OF_PCB && PCBCounter + numberOfPCB <= MAX_NUMBER_OF_PCB) {

			if (loopCounter % PRINT_EVERY_xTIMES == 0) {
				//fprintf(outFile, "\n__________NEXT TIME QUANTUM  : %d___________\n", loopCounter);
				fprintf(outFile, "//----------------------------------\n");
				fprintf(outFile, "We are creating %d PCBs \n\n", numberOfPCB);
			}

			for (i = 0; i < numberOfPCB; i++) {

				sprintf(processNameSetUp, "Process%d", PCBCounter);

				enqueue(PCBContainer, tempPCB = createPCB(processNameSetUp, PCBCounter, rand() % 15,
					0, 1000 * PCBCounter, ready));
				if (loopCounter % PRINT_EVERY_xTIMES == 0) {
					toStringFileVersion(tempPCB, outFile);
				}

				strcpy(processNameSetUp, "Process");
				PCBCounter++;
			}
		} else if(PCBCounter == MAX_NUMBER_OF_PCB && loopCounter % 4 == 0) {
			fprintf(outFile, "We are done creating PCBs\n");
		}

		if (loopCounter % PRINT_EVERY_xTIMES == 0) {
			fprintf(outFile, "//----------------------------------\n");
		}

		//If we have started a running processes, increment the PC value to simulate running
		if (testingCPU->runningProcess != NULL) {
			testingCPU->runningProcess->pc += rand() % 1000 + 3000;

			//strcpy(testingCPU->systemStack->name, testingCPU->runningProcess->name);
			testingCPU->systemStack->pc = testingCPU->runningProcess->pc;
		}
		//else, create a temp "fake" processs PCB till a "real" one is created
		else {
			testingCPU->runningProcess = createPCB("Default", 0, 0, 0, 0, running);
			testingCPU->systemStack = createPCB("Default", 0, 0, 0, 0, running);
		}

		//Simulate Timer Interrupt
		timerISR(testingCPU, PCBContainer);

		if (loopCounter % PRINT_EVERY_xTIMES == 0) {
			//PRINT RESULTS AFTER TIMER ISR
			fprintf(outFile, "\nRunning process: \n");
			//printf("//--------------------------------------\n");
			toStringFileVersion(testingCPU->runningProcess, outFile);
			fprintf(outFile, "//---------------------------------------\n\n");
			fprintf(outFile, "State of the Ready Queue: \n\n");
			printListFileVersion(testingCPU->readQueue_p, outFile);
			fprintf(outFile, "\n\n");
		}

		//pseudo halt for debug screen
		//getchar();

		//one run has passed
		loopCounter++;
		
	}

	//free used memory
	freeLinkedList(PCBContainer);
	freeCPU(testingCPU);
}