From: Reid Spencer Date: Mon, 16 Aug 2004 07:06:38 +0000 (+0000) Subject: Back out dependencies on lib/System/Path.h X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=2a069fa0034e974481307916ccfea6c0e625b956;p=oota-llvm.git Back out dependencies on lib/System/Path.h git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@15815 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/tools/llvmc/CompilerDriver.cpp b/tools/llvmc/CompilerDriver.cpp index 038274b72aa..f0ae129cea8 100644 --- a/tools/llvmc/CompilerDriver.cpp +++ b/tools/llvmc/CompilerDriver.cpp @@ -70,8 +70,19 @@ namespace { std::cerr << "Linker: "; DumpAction(&cd->Linker); } -} + void CleanupTempFile(const char* fname) { + if (0 == access(fname, F_OK | R_OK)) + unlink(fname); + } + + /// This specifies the passes to run for OPT_FAST_COMPILE (-O1) + /// which should reduce the volume of code and make compilation + /// faster. This is also safe on any llvm module. + static const char* DefaultOptimizations[] = { + "-simplifycfg", "-mem2reg", "-mergereturn", "-instcombine", + }; +} CompilerDriver::CompilerDriver(ConfigDataProvider& confDatProv ) : cdp(&confDatProv) @@ -215,7 +226,7 @@ void CompilerDriver::DoAction(Action*a) } int CompilerDriver::execute(const InputList& InpList, - const sys::Path& Output ) { + const std::string& Output ) { // Echo the configuration of options if we're running verbose if (isDebug) { @@ -248,12 +259,15 @@ int CompilerDriver::execute(const InputList& InpList, std::vector actions; // Create a temporary directory for our temporary files - sys::Path TempDir(sys::Path::CONSTRUCT_TEMP_DIR); - sys::Path TempPreprocessorOut; - sys::Path TempTranslatorOut; - sys::Path TempOptimizerOut; - sys::Path TempAssemblerOut; - sys::Path TempLinkerOut; + char temp_name[64]; + strcpy(temp_name,"/tmp/llvm_XXXXXX"); + if (0 == mkdtemp(temp_name)) + error("Can't create temporary directory"); + std::string TempDir(temp_name); + std::string TempPreprocessorOut(TempDir + "/preproc.tmp"); + std::string TempTranslatorOut(TempDir + "/trans.tmp"); + std::string TempOptimizerOut(TempDir + "/opt.tmp"); + std::string TempAssemblerOut(TempDir + "/asm.tmp"); /// PRE-PROCESSING / TRANSLATION / OPTIMIZATION / ASSEMBLY phases // for each input item @@ -304,8 +318,6 @@ int CompilerDriver::execute(const InputList& InpList, // Get the preprocessing action, if needed, or error if appropriate if (!a.program.empty()) { if (a.isSet(REQUIRED_FLAG) || finalPhase == PREPROCESSING) { - TempPreprocessorOut = TempDir; - TempPreprocessorOut.append_file("preproc.out"); actions.push_back(GetAction(cd,I->first, TempPreprocessorOut,PREPROCESSING)); } @@ -324,8 +336,6 @@ int CompilerDriver::execute(const InputList& InpList, // Get the translation action, if needed, or error if appropriate if (!a.program.empty()) { if (a.isSet(REQUIRED_FLAG) || finalPhase == TRANSLATION) { - TempTranslatorOut = TempDir; - TempTranslatorOut.append_file("trans.out"); actions.push_back(GetAction(cd,I->first,TempTranslatorOut,TRANSLATION)); } } else if (finalPhase == TRANSLATION) { @@ -342,8 +352,6 @@ int CompilerDriver::execute(const InputList& InpList, // Get the optimization action, if needed, or error if appropriate if (!a.program.empty()) { - TempOptimizerOut = TempDir; - TempOptimizerOut.append_file("trans.out"); actions.push_back(GetAction(cd,I->first,TempOptimizerOut,OPTIMIZATION)); } else if (finalPhase == OPTIMIZATION) { error(cd->langName + " does not support optimization"); @@ -367,14 +375,13 @@ int CompilerDriver::execute(const InputList& InpList, } // Cleanup files - if (TempPreprocessorOut.exists()) - TempPreprocessorOut.remove_file(); - if (TempTranslatorOut.exists()) - TempTranslatorOut.remove_file(); - if (TempOptimizerOut.exists()) - TempOptimizerOut.remove_file(); - if (TempDir.exists()) - TempDir.remove_directory(); + CleanupTempFile(TempPreprocessorOut.c_str()); + CleanupTempFile(TempTranslatorOut.c_str()); + CleanupTempFile(TempOptimizerOut.c_str()); + + // Cleanup temporary directory we created + if (0 == access(TempDir.c_str(), F_OK | W_OK)) + rmdir(TempDir.c_str()); return 0; } diff --git a/tools/llvmc/CompilerDriver.h b/tools/llvmc/CompilerDriver.h index da2a8f1a317..0914feca4c5 100644 --- a/tools/llvmc/CompilerDriver.h +++ b/tools/llvmc/CompilerDriver.h @@ -14,7 +14,6 @@ #ifndef LLVM_TOOLS_LLVMC_COMPILERDRIVER_H #define LLVM_TOOLS_LLVMC_COMPILERDRIVER_H -#include "llvm/System/Path.h" #include #include @@ -66,7 +65,7 @@ namespace llvm { /// a vector of filename/filetype pairs. The filetype is used to look up /// the configuration of the actions to be taken by the driver. /// @brief The Input Data to the execute method - typedef std::vector > InputList; + typedef std::vector > InputList; /// This type is read from configuration files or otherwise provided to /// the CompilerDriver through a "ConfigDataProvider". It serves as both @@ -75,7 +74,7 @@ namespace llvm { /// language. struct Action { Action() : inputAt(0) , outputAt(0), flags(0) {} - sys::Path program; ///< The program to execve + std::string program; ///< The program to execve StringVector args; ///< Arguments to the program size_t inputAt; ///< Argument index to insert input file size_t outputAt; ///< Argument index to insert output file @@ -122,7 +121,7 @@ namespace llvm { virtual void error(const std::string& errmsg); /// @brief Execute the actions requested for the given input list. - virtual int execute(const InputList& list, const sys::Path& output); + virtual int execute(const InputList& list, const std::string& output); /// @} /// @name Mutators