예제 #1
0
bool CompileScope(CompileInstance &inst, const mtlChars &input, bool branch)
{
    bool result = true;
    Scope &scope = PushScope(inst, branch);
    scope.parser.SetBuffer(input);
    mtlList<mtlChars> m;
    while (result && !scope.parser.IsEnd()) {
        switch (scope.parser.MatchPart("{%s}%|%w%w(%s){%s}%|if(%s){%s}else{%s}%|if(%s){%s}%|%s;", m, NULL)) {
        case 0: // SCOPE
            result = CompileScope(inst, m.GetFirst()->GetItem(), false);
            break;
        case 1: // FUNCTION
            result = CompileFunction(inst, m.GetFirst()->GetItem(), m.GetFirst()->GetNext()->GetItem(), m.GetFirst()->GetNext()->GetNext()->GetItem(), m.GetFirst()->GetNext()->GetNext()->GetNext()->GetItem());
            break;
        case 2: // CONDITION
            result = CompileCondition(inst, m.GetFirst()->GetNext()->GetItem(), m.GetFirst()->GetNext()->GetNext()->GetItem(), "");
            break;
        case 3: // CONDITION
            result = CompileCondition(inst, m.GetFirst()->GetNext()->GetItem(), m.GetFirst()->GetNext()->GetNext()->GetItem(), m.GetFirst()->GetNext()->GetNext()->GetNext()->GetItem());
            break;
        case 4: // STATEMENT
            result = CompileStatement(inst, m.GetFirst()->GetItem());
            break;
        default:
            AddError(inst, "Malformed sequence", input);
            return false;
            break;
        }
    }
    PopScope(inst);
    return result;
}
예제 #2
0
// Read data
void AppWindow::OnOpen(BMessage *msg) {
entry_ref ref;
BMessage archive;
	msg->FindRef("refs", &ref);
	BFile file(&ref, B_READ_ONLY);
	archive.Unflatten(&file);
	Graph *g = (Graph*)Graph::Instantiate(&archive);
	if (g != NULL) {
		delete view->graph; view->graph = g;
		BMenu *menu = data->functions->Menu();
		while (menu->RemoveItem((int32)0) != NULL);
		Function1 *f;
		int i;

		if (program->Lock()) {
			program->view->SetText(g->GetDefinitions()->GetText());
			program->Unlock();
		}
		
		MarkColorMenuItem(bg_color, view->graph->bg_color);
		MarkColorMenuItem(axes_color, view->graph->axes_color);
		
		ExprList *el = g->GetGraphExprs();
		for (i = 0; i < 6; i++) 
			data->gCtrls[i]->SetText(el->GetText(i));
		
		for (i = 0; i < 5; i++)
			data->fCtrls[i]->SetText("");

		UpdateGraph();
		for (i = 0; NULL != (f = g->GetFunction(i)); i++) {
			CompileFunction(f, false);
		}
		
		for (i = 0; NULL != (f = g->GetFunction(i)); i++)
			AddFunction(f);
		OnSelect();
		
		OnUpdate();	
	} else {
		BAlert *a = new BAlert("Open Error", "Could not read file.", "OK");
		a->Go();
	}
}
예제 #3
0
// Read all data, parse und evaluate it
bool AppWindow::CheckFunction() {
int i;
	UpdateGraph(); 
	for (i = 0; i < 5; i++) {
		view->f1->Exprs()->SetText(i, data->fCtrls[i]->Text());
	}
	view->f1->SetVisible(data->visible->Value());

	ColorMenuItem *c = (ColorMenuItem*)data->color->Menu()->FindMarked();
	if (c != NULL) view->f1->SetColor(c->GetColor());

	BMenuItem *item = data->style->Menu()->FindMarked();
	if (item != NULL) view->f1->SetStyle(data->style->Menu()->IndexOf(item));

	if (CompileFunction(view->f1, true)) {
		statusLine->SetText("ok");
		return true;
	} else
		return false;
}
예제 #4
0
파일: Main_Aot.cpp 프로젝트: cmexp/Play-
void Compile(const char* databasePathName, const char* cpuArchName, const char* imageFormatName, const char* outputPath)
{
	CPsfVm virtualMachine;
	auto subSystem = std::make_shared<Iop::CPsfSubSystem>(false);
	virtualMachine.SetSubSystem(subSystem);

	Jitter::CCodeGen* codeGen = nullptr;
	Jitter::CObjectFile::CPU_ARCH cpuArch = Jitter::CObjectFile::CPU_ARCH_X86;
	if(!strcmp(cpuArchName, "x86"))
	{
		codeGen = new Jitter::CCodeGen_x86_32();
		cpuArch = Jitter::CObjectFile::CPU_ARCH_X86;
	}
	else if(!strcmp(cpuArchName, "arm"))
	{
		codeGen = new Jitter::CCodeGen_Arm();
		cpuArch = Jitter::CObjectFile::CPU_ARCH_ARM;
	}
	else
	{
		throw std::runtime_error("Invalid cpu target.");
	}

	std::unique_ptr<Jitter::CObjectFile> objectFile;
	if(!strcmp(imageFormatName, "coff"))
	{
		objectFile = std::make_unique<Jitter::CCoffObjectFile>(cpuArch);
	}
	else if(!strcmp(imageFormatName, "macho"))
	{
		objectFile = std::make_unique<Jitter::CMachoObjectFile>(cpuArch);
	}
	else
	{
		throw std::runtime_error("Invalid executable image type (must be coff or macho).");
	}

	codeGen->RegisterExternalSymbols(objectFile.get());
	objectFile->AddExternalSymbol("_MemoryUtils_GetByteProxy", &MemoryUtils_GetByteProxy);
	objectFile->AddExternalSymbol("_MemoryUtils_GetHalfProxy", &MemoryUtils_GetHalfProxy);
	objectFile->AddExternalSymbol("_MemoryUtils_GetWordProxy", &MemoryUtils_GetWordProxy);
	objectFile->AddExternalSymbol("_MemoryUtils_SetByteProxy", &MemoryUtils_SetByteProxy);
	objectFile->AddExternalSymbol("_MemoryUtils_SetHalfProxy", &MemoryUtils_SetHalfProxy);
	objectFile->AddExternalSymbol("_MemoryUtils_SetWordProxy", &MemoryUtils_SetWordProxy);
	objectFile->AddExternalSymbol("_LWL_Proxy", &LWL_Proxy);
	objectFile->AddExternalSymbol("_LWR_Proxy", &LWR_Proxy);
	objectFile->AddExternalSymbol("_SWL_Proxy", &SWL_Proxy);
	objectFile->AddExternalSymbol("_SWR_Proxy", &SWR_Proxy);

	filesystem::path databasePath(databasePathName);
	auto blocks = GetBlocksFromCache(databasePath);

	//Initialize Jitter Service
	auto jitter = new CMipsJitter(codeGen);
	for(unsigned int i = 0; i < 4; i++)
	{
		jitter->SetVariableAsConstant(
			offsetof(CMIPS, m_State.nGPR[CMIPS::R0].nV[i]),
			0
			);
	}

	printf("Got %d blocks to compile.\r\n", blocks.size());

	FunctionTable functionTable;
	functionTable.reserve(blocks.size());

	for(const auto& blockCachePair : blocks)
	{
		const auto& blockKey = blockCachePair.first;

		auto functionName = "aotblock_" + std::to_string(blockKey.crc) + "_" + std::to_string(blockKey.begin) + "_" + std::to_string(blockKey.end);

		unsigned int functionSymbolIndex = CompileFunction(virtualMachine, jitter, blockCachePair.second, *objectFile, functionName, blockKey.begin, blockKey.end);

		FUNCTION_TABLE_ITEM tableItem = { blockKey, functionSymbolIndex };
		functionTable.push_back(tableItem);
	}

	std::sort(functionTable.begin(), functionTable.end(), 
		[] (const FUNCTION_TABLE_ITEM& item1, const FUNCTION_TABLE_ITEM& item2)
		{
			return item1.key < item2.key;
		}
	);

	{
		Framework::CMemStream blockTableStream;
		Jitter::CObjectFile::INTERNAL_SYMBOL blockTableSymbol;
		blockTableSymbol.name		= "__aot_firstBlock";
		blockTableSymbol.location	= Jitter::CObjectFile::INTERNAL_SYMBOL_LOCATION_DATA;

		for(const auto& functionTableItem : functionTable)
		{
			blockTableStream.Write32(functionTableItem.key.crc);
			blockTableStream.Write32(functionTableItem.key.begin);
			blockTableStream.Write32(functionTableItem.key.end);
			
			{
				Jitter::CObjectFile::SYMBOL_REFERENCE ref;
				ref.offset		= static_cast<uint32>(blockTableStream.Tell());
				ref.type		= Jitter::CObjectFile::SYMBOL_TYPE_INTERNAL;
				ref.symbolIndex	= functionTableItem.symbolIndex;
				blockTableSymbol.symbolReferences.push_back(ref);
			}

			blockTableStream.Write32(0);
		}

		blockTableSymbol.data = std::vector<uint8>(blockTableStream.GetBuffer(), blockTableStream.GetBuffer() + blockTableStream.GetLength());
		objectFile->AddInternalSymbol(blockTableSymbol);
	}

	{
		Jitter::CObjectFile::INTERNAL_SYMBOL blockCountSymbol;
		blockCountSymbol.name		= "__aot_blockCount";
		blockCountSymbol.location	= Jitter::CObjectFile::INTERNAL_SYMBOL_LOCATION_DATA;
		blockCountSymbol.data		= std::vector<uint8>(4);
		*reinterpret_cast<uint32*>(blockCountSymbol.data.data()) = functionTable.size();
		objectFile->AddInternalSymbol(blockCountSymbol);
	}

	objectFile->Write(Framework::CStdStream(outputPath, "wb"));
}