std::string CodeGeneratorTest::CheckResult(const std::string &ExpectedResult, bool printResults, const std::string &ExpectedResultFile) { std::string CodeGenResult = GenerateCode(); if (printResults) { errs() << "### Expected Result:\n" << ExpectedResult << "\n"; errs() << "### Generated Result:\n" << CodeGenResult << "\n"; } if (ExpectedResult != CodeGenResult) { if (ExpectedResultFile.empty()) { remove("expected"); writeFile("expected", ExpectedResult); } else link(ExpectedResultFile, "expected"); writeFile("actual", CodeGenResult); if (!assembly.empty()) writeFile("assembly-failed.ll", assembly); } // compare results EXPECT_EQ(ExpectedResult, CodeGenResult); return CodeGenResult; }
int main(){ printf("******* INTIATING COMPILER ***********\n"); //printf("Choose Relevant stage of compiler:\n"); //printf("1. Lexical Analysis\n"); //printf("2. Parsing\n"); //printf("3. Semantic Analysis\n"); //printf("4. Code Generation\n"); int choice,i; char c; if(1){ hashTable* T = build_hash(); // build the hash table to maintain state of tokens printStoreHash(T); // store hashTable in a file Dnode* DFA = buildDFA(); memset(LexicalUnits,'\0',sizeof(LexicalUnits)); lexerCode(DFA,T,LexicalUnits,tokenValue,line); printf("\nLexer tokens have been generated in Lexer Tokens.txt\n"); pnode* root=NULL; root=parse(LexicalUnits,tokenValue,line); printf("\nParse tree generated in parseTree.txt\n"); pnode* ast=getAST(root); printf("\nAbstarct Syntax Tree Generated in AbstractSyntaxTree.txt\n"); Master *sym = (Master*)malloc(sizeof (Master)); getSymbolTable(sym,ast); printf("\nSymbol Table Generated in symbolTable.txt\n"); GenerateCode(sym,ast); printf("\nCode Generation Successfull\n\n"); } return 0; }
static void GenerateStubs (Interface parse) { char filename[1000]; FILE *file; if (! makedir (OutputDirectory)) { fprintf (stderr, "Couldn't create output directory %s.\n", OutputDirectory); exit (1); } if (GenerateClasses) { GenerateHeaders (parse); GenerateCode (parse); } if (GenerateImakefile) { sprintf (filename, "%s/Imakefile", OutputDirectory); possibleUnlink (filename); if ((file = fopen (filename, "w")) == NULL) { fprintf (stderr, "Couldn't open output file %s.\n", filename); exit (1); } printf ("ILU-style Imakefile to %s...\n", filename); generate_imakefile (parse, file); fclose (file); } }
ERRORCODE NodeSimCodeGenerator::CompileCode(ICluster* pCluster, bool bRegenerate, bool /*bReCompile*/, INsCodeGenHelper* codeGenHelper) { if (nullptr == codeGenHelper) { return EC_FAILURE; } ERRORCODE ecRetVal = EC_FAILURE; std::string strFileName; pCluster->GetDBFilePath(strFileName); if ( bRegenerate == false ) { bRegenerate = bIsDependentFileModified(pCluster); } if ( bRegenerate == true ) //Not else { if ( "" != strFileName ) { std::string strCheckSum; pCluster->GetDBFileChecksum(strCheckSum); char chTempFolder[MAX_PATH]; char chTempPath[MAX_PATH]; GetTempPath( MAX_PATH, chTempFolder ); GetTempFileName(chTempFolder, // directory for tmp files TEXT("BM"), // temp file name prefix 0, // create unique name chTempPath); // buffer for name std::string strCppFilePath = chTempPath; //+ ".cpp"; std::string strDbAppPath; GetBusMasterDBCachePath(strDbAppPath); std::string strHeaderFilePath = strDbAppPath + "\\"; strHeaderFilePath += strCheckSum + ".h"; GenerateCode(strHeaderFilePath, strCppFilePath, pCluster, codeGenHelper); ecRetVal = GenerateObjectFile(strCppFilePath, pCluster); //DeleteFile(chTempPath); } else { ecRetVal = EC_FAILURE; } } return ecRetVal; }
int ShaderGenUI::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QDialog::qt_metacall(_c, _id, _a); if (_id < 0) return _id; if (_c == QMetaObject::InvokeMetaMethod) { switch (_id) { case 0: SelectInputFiles(); break; case 1: SelectOutputFolderHLSL(); break; case 2: SelectOutputFolderCPP(); break; case 3: GenerateCode(); break; default: ; } _id -= 4; } return _id; }
MaterialCompiler::eCompileResult MaterialCompiler::Compile(MaterialGraph * _materialGraph, PolygonGroup * _polygonGroup, uint32 maxLights, NMaterial ** resultMaterial) { materialGraph = _materialGraph; polygonGroup = _polygonGroup; MaterialGraphNode * rootResultNode = materialGraph->GetNodeByName("material"); if (!rootResultNode) { return COMPILATION_FAILED; } currentMaterial = new NMaterial(maxLights); RecursiveSetDepthMarker(rootResultNode, 0); materialGraph->SortByDepthMarkerAndRemoveUnused(); MaterialGraphNode::RecursiveSetRealUsageBack(rootResultNode); MaterialGraphNode::RecursiveSetRealUsageForward(rootResultNode); materialCompiledVshName = FilePath::CreateWithNewExtension(materialGraph->GetMaterialPathname(), ".vsh"); materialCompiledFshName = FilePath::CreateWithNewExtension(materialGraph->GetMaterialPathname(), ".fsh"); #if 1 materialCompiledVshName = "~doc:/temp.vsh"; materialCompiledFshName = "~doc:/temp.fsh"; #endif GenerateCode(materialGraph); Shader * shader = new Shader(); shader->Load(materialCompiledVshName, materialCompiledFshName); shader->RecompileAsync(); currentMaterial->SetShader(0, shader); *resultMaterial = currentMaterial; return COMPILATION_SUCCESS; };
cEqObsBlockCam::cEqObsBlockCam ( cRotationFormelle & aRotRT0, cRotationFormelle & aRotLT0, cRotationFormelle & aRotRT1, cRotationFormelle & aRotLT1, bool doGenerateCode ) : mSet (aRotRT0.Set()), mRotRT0 (&aRotRT0), mRotLT0 (&aRotLT0), mRotRT1 (&aRotRT1), mRotLT1 (&aRotLT1), mNameType ("cCodeBlockCam"), mFoncEqResidu (0), #if (HandleGL) mMatR0("GL_MK0",3,3), mMatL0("GL_MK1",3,3), mMatR1("GL_MK2",3,3), mMatL1("GL_MK3",3,3) #endif { AllowUnsortedVarIn_SetMappingCur = true; ELISE_ASSERT(mSet==mRotRT0->Set(),"Different sets incEqObsBlockCam"); ELISE_ASSERT(mSet==mRotLT0->Set(),"Different sets incEqObsBlockCam"); ELISE_ASSERT(mSet==mRotRT1->Set(),"Different sets incEqObsBlockCam"); ELISE_ASSERT(mSet==mRotLT1->Set(),"Different sets incEqObsBlockCam"); mRotRT0->IncInterv().SetName("OriR0"); mRotLT0->IncInterv().SetName("OriL0"); mRotRT1->IncInterv().SetName("OriR1"); mRotLT1->IncInterv().SetName("OriL1"); mLInterv.AddInterv(mRotRT0->IncInterv()); mLInterv.AddInterv(mRotLT0->IncInterv()); mLInterv.AddInterv(mRotRT1->IncInterv()); mLInterv.AddInterv(mRotLT1->IncInterv()); if (doGenerateCode) { GenerateCode(); return; } mFoncEqResidu = cElCompiledFonc::AllocFromName(mNameType); ELISE_ASSERT(mFoncEqResidu!=0,"Cannot allocate cEqObsBlockCam"); mFoncEqResidu->SetMappingCur(mLInterv,mSet); #if (HandleGL) mMatR0.InitAdr(*mFoncEqResidu); mMatL0.InitAdr(*mFoncEqResidu); mMatR1.InitAdr(*mFoncEqResidu); mMatL1.InitAdr(*mFoncEqResidu); #endif mSet->AddFonct(mFoncEqResidu); }
void GenerateForm ( istream& input, const JString& formName, const JString& tagName, const JString& enclName, const JString& codePath, const JString& stringPath, const JString& codeSuffix, const JString& headerSuffix, JPtrArray<JString>* backupList ) { const JString codeFileName = codePath + formName + codeSuffix; const JString codeFileBakName = codeFileName + kBackupSuffix; const JString headerFileName = codePath + formName + headerSuffix; const JString headerFileBakName = headerFileName + kBackupSuffix; if (!JFileExists(codeFileName)) { cerr << codeFileName << " not found" << endl; return; } if (!JFileExists(headerFileName)) { cerr << headerFileName << " not found" << endl; return; } cout << "Generating: " << formName << ", " << tagName << endl; const JBoolean shouldBackup = ShouldBackupForm(formName, backupList); // copy code file contents before start delimiter JString tempCodeFileName; JError err = JCreateTempFile(codePath, NULL, &tempCodeFileName); if (!err.OK()) { cerr << "Unable to create temporary file in " << codePath << endl; cerr << " (" << err.GetMessage() << ')' << endl; return; } ifstream origCode(codeFileName); ofstream outputCode(tempCodeFileName); if (!outputCode.good()) { cerr << "Unable to open temporary file in " << codePath << endl; remove(tempCodeFileName); return; } if (!CopyBeforeCodeDelimiter(tagName, origCode, outputCode)) { cerr << "No starting delimiter in " << codeFileName << endl; outputCode.close(); remove(tempCodeFileName); return; } // generate code for each object in the form JPtrArray<JString> objTypes(JPtrArrayT::kDeleteAll), objNames(JPtrArrayT::kDeleteAll); GenerateCode(input, outputCode, stringPath, formName, tagName, enclName, &objTypes, &objNames); // copy code file contents after end delimiter JBoolean done = CopyAfterCodeDelimiter(tagName, origCode, outputCode); origCode.close(); outputCode.close(); if (!done) { cerr << "No ending delimiter in " << codeFileName << endl; remove(tempCodeFileName); return; } else if (shouldBackup && rename(codeFileName, codeFileBakName) != 0) { cerr << "Unable to rename original " << codeFileName << endl; remove(tempCodeFileName); return; } JEditVCS(codeFileName); rename(tempCodeFileName, codeFileName); // copy header file contents before start delimiter JString tempHeaderFileName; err = JCreateTempFile(codePath, NULL, &tempHeaderFileName); if (!err.OK()) { cerr << "Unable to create temporary file in " << codePath << endl; cerr << " (" << err.GetMessage() << ')' << endl; return; } ifstream origHeader(headerFileName); ofstream outputHeader(tempHeaderFileName); if (!outputHeader.good()) { cerr << "Unable to open temporary file in " << codePath << endl; remove(tempHeaderFileName); return; } if (!CopyBeforeCodeDelimiter(tagName, origHeader, outputHeader)) { cerr << "No starting delimiter in " << headerFileName << endl; outputHeader.close(); remove(tempHeaderFileName); return; } // generate instance variable for each object in the form GenerateHeader(outputHeader, objTypes, objNames); // copy header file contents after end delimiter done = CopyAfterCodeDelimiter(tagName, origHeader, outputHeader); origHeader.close(); outputHeader.close(); if (!done) { cerr << "No ending delimiter in " << headerFileName << endl; remove(tempHeaderFileName); return; } // check if header file actually changed JString origHeaderText, newHeaderText; JReadFile(headerFileName, &origHeaderText); JReadFile(tempHeaderFileName, &newHeaderText); if (newHeaderText != origHeaderText) { if (shouldBackup && rename(headerFileName, headerFileBakName) != 0) { cerr << "Unable to rename original " << headerFileName << endl; remove(tempHeaderFileName); return; } JEditVCS(headerFileName); rename(tempHeaderFileName, headerFileName); } else { remove(tempHeaderFileName); } }
//-------------------------------------------------------------------------------------------------- void MakeSystem ( int argc, ///< Count of the number of command line parameters. const char** argv ///< Pointer to an array of pointers to command line argument strings. ) //-------------------------------------------------------------------------------------------------- { GetCommandLineArgs(argc, argv); // Set the target-specific environment variables (e.g., LEGATO_TARGET). envVars::SetTargetSpecific(BuildParams.target); // Compute the staging directory path. auto stagingDir = path::Combine(BuildParams.workingDir, "staging"); // If we have been asked not to run Ninja, then delete the staging area because it probably // will contain some of the wrong files now that .Xdef file have changed. if (DontRunNinja) { file::DeleteDir(stagingDir); } // If we have not been asked to ignore any already existing build.ninja, and the command-line // arguments and environment variables we were given are the same as last time, just run ninja. else if (args::MatchesSaved(BuildParams, argc, argv) && envVars::MatchesSaved(BuildParams)) { RunNinja(BuildParams); // NOTE: If build.ninja exists, RunNinja() will not return. If it doesn't it will. } // Construct a model of the system. model::System_t* systemPtr = modeller::GetSystem(SdefFilePath, BuildParams); // If verbose mode is on, print a summary of the system model. if (BuildParams.beVerbose) { // modeller::PrintSummary(systemPtr); } // Create the working directory and the staging directory, if they don't already exist. file::MakeDir(stagingDir); // Generate code for all the components in the system. GenerateCode(model::Component_t::GetComponentMap(), BuildParams); // Generate code and configuration files for all the apps in the system. for (auto appMapEntry : systemPtr->apps) { GenerateCode(appMapEntry.second, BuildParams); } // Generate the configuration files for the system. config::Generate(systemPtr, BuildParams); // Generate the build script for the system. ninja::Generate(systemPtr, BuildParams, OutputDir, argc, argv); // If we haven't been asked not to run ninja, if (!DontRunNinja) { // Save the command-line arguments and environment variables for future comparison. // Note: we don't need to do this if we have been asked not to run ninja, because // that only happens when ninja is already running and asking us to regenerate its // script for us, and that only happens if we just saved the args and env vars and // ran ninja. args::Save(BuildParams, argc, argv); envVars::Save(BuildParams); RunNinja(BuildParams); } }
// arg & 1: decompile to C code (1) or normally (0) // arg & 2: print instruction list before splitting into nodes // arg & 4: dump current instruction // arg & 8: process all functions void idaapi run(int arg) { msg("Running The Desquirr decompiler plugin\n"); IdaPro* idapro; if (PLFM_386 == ph.id) idapro = new IdaX86(); else if (PLFM_ARM == ph.id) idapro = new IdaArm(); else { msg("Unexpected processor module\n"); return; } Frontend_ptr frontend(idapro); Frontend::Set(frontend); if (arg & 4) { idapro->DumpInsn(get_screen_ea()); return; } CodeStyle style = (arg & 1) ? C_STYLE : LISTING_STYLE; for (func_t *function= (arg&8)?get_next_func(0) : get_func(get_screen_ea()) ; function ; function= (arg&8)?get_next_func(function->startEA):0) { if (function->flags & FUNC_LIB) msg("Warning: Library function\n"); Instruction_list instructions; msg("-> Creating instruction list\n"); idapro->FillList(function, instructions); if (arg & 2) { msg("Instruction list:\n"); GenerateCode(instructions, style); break; } Node_list nodes; msg("-> Creating node list\n"); Node::CreateList(instructions, nodes); //if (g_bDumpNodeContents) DumpList(nodes); msg("-> Update uses and definitions\n"); UpdateUsesAndDefinitions(nodes); //if (g_bDumpNodeContents) DumpList(nodes); msg("-> Live register analysis\n"); Node::LiveRegisterAnalysis(nodes); //if (g_bDumpNodeContents) DumpList(nodes); msg("-> Finding DU chains\n"); Node::FindDefintionUseChains(nodes); if (g_bDumpNodeContents) DumpList(nodes); msg("-> Data flow analysis\n"); { DataFlowAnalysis analysis(nodes); analysis.AnalyzeNodeList(); // want destructor to run here :-) } if (g_bDumpNodeContents) DumpList(nodes); msg("Basic block list:\n"); GenerateCode(nodes, style); } }
//-------------------------------------------------------------------------------------------------- void MakeApp ( int argc, ///< Count of the number of command line parameters. const char** argv ///< Pointer to an array of pointers to command line argument strings. ) //-------------------------------------------------------------------------------------------------- { GetCommandLineArgs(argc, argv); // Set the target-specific environment variables (e.g., LEGATO_TARGET). envVars::SetTargetSpecific(BuildParams.target); // If we have been asked not to run Ninja, then delete the staging area because it probably // will contain some of the wrong files now that .Xdef file have changed. if (DontRunNinja) { file::DeleteDir(path::Combine(BuildParams.workingDir, "staging")); } // If we have not been asked to ignore any already existing build.ninja, and the command-line // arguments and environment variables we were given are the same as last time, just run ninja. else if (args::MatchesSaved(BuildParams, argc, argv) && envVars::MatchesSaved(BuildParams)) { RunNinja(BuildParams); // NOTE: If build.ninja exists, RunNinja() will not return. If it doesn't it will. } // If we have not been asked to ignore any already existing build.ninja and there has // been a change in either the argument list or the environment variables, // save the command-line arguments and environment variables for future comparison. // Note: we don't need to do this if we have been asked not to run ninja, because // that only happens when ninja is already running and asking us to regenerate its // script for us, and that only happens if the args and env vars have already been saved. else { // Save the command line arguments. args::Save(BuildParams, argc, argv); // Save the environment variables. // Note: we must do this before we parse the definition file, because parsing the file // will result in the CURDIR environment variable being set. envVars::Save(BuildParams); } // Construct a model of the application. model::App_t* appPtr = modeller::GetApp(AdefFilePath, BuildParams); // Append a "." and the VersionSuffix if the user provides a // "--append or -a" argument in the command line. if (appPtr->version.empty()) { appPtr->version = VersionSuffix; } else if (VersionSuffix.empty() == false) { appPtr->version += '.' + VersionSuffix; } // Ensure that all client-side interfaces have either been bound to something or declared // external. modeller::EnsureClientInterfacesSatisfied(appPtr); // If verbose mode is on, print a summary of the application model. if (BuildParams.beVerbose) { modeller::PrintSummary(appPtr); } // Generate app-specific code and configuration files. GenerateCode(appPtr, BuildParams); // Generate code for all the components in the app. GenerateCode(appPtr->components, BuildParams); // Generate the build script for the application. ninja::Generate(appPtr, BuildParams, OutputDir, argc, argv); // If we haven't been asked not to, run ninja. if (!DontRunNinja) { RunNinja(BuildParams); } }