Implement Assembly support.

Consolidate platform-specific code into "sys" namespace.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@15947 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Reid Spencer
2004-08-20 09:14:05 +00:00
parent ff22c42e0e
commit 9a8fedd6f9

View File

@ -70,11 +70,6 @@ namespace {
DumpAction(&cd->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) /// This specifies the passes to run for OPT_FAST_COMPILE (-O1)
/// which should reduce the volume of code and make compilation /// which should reduce the volume of code and make compilation
/// faster. This is also safe on any llvm module. /// faster. This is also safe on any llvm module.
@ -86,6 +81,16 @@ namespace {
// Stuff in this namespace properly belongs in lib/System and needs // Stuff in this namespace properly belongs in lib/System and needs
// to be portable but we're avoiding that for now. // to be portable but we're avoiding that for now.
namespace sys { namespace sys {
bool FileReadable(const std::string& fname) {
return 0 == access(fname.c_str(), F_OK | R_OK);
}
void CleanupTempFile(const std::string& fname) {
if (FileReadable(fname))
unlink(fname.c_str());
}
std::string MakeTemporaryDirectory() { std::string MakeTemporaryDirectory() {
char temp_name[64]; char temp_name[64];
strcpy(temp_name,"/tmp/llvm_XXXXXX"); strcpy(temp_name,"/tmp/llvm_XXXXXX");
@ -453,6 +458,7 @@ int CompilerDriver::execute(const InputList& InpList,
Action* action = new Action(); Action* action = new Action();
action->program = "llvm-as"; action->program = "llvm-as";
action->args.push_back(InFile); action->args.push_back(InFile);
action->args.push_back("-f");
action->args.push_back("-o"); action->args.push_back("-o");
InFile += ".bc"; InFile += ".bc";
action->args.push_back(InFile); action->args.push_back(InFile);
@ -470,9 +476,26 @@ int CompilerDriver::execute(const InputList& InpList,
if (finalPhase == OPTIMIZATION) { ++I; continue; } if (finalPhase == OPTIMIZATION) { ++I; continue; }
/// ASSEMBLY PHASE /// ASSEMBLY PHASE
action = cd->Assembler;
if (finalPhase == ASSEMBLY) {
if (emitNativeCode) { if (emitNativeCode) {
// We must cause native code to be generated if (action.program.empty()) {
error(std::string("Native Assembler not specified for ") +
cd->langName + " files");
} else { } else {
actions.push_back(GetAction(cd,InFile,OutFile,ASSEMBLY));
}
} else {
// Just convert back to llvm assembly with llvm-dis
Action* action = new Action();
action->program = "llvm-dis";
action->args.push_back(InFile);
action->args.push_back("-f");
action->args.push_back("-o");
action->args.push_back(OutFile);
actions.push_back(action);
}
} }
// Go to next file to be processed // Go to next file to be processed
@ -480,9 +503,11 @@ int CompilerDriver::execute(const InputList& InpList,
} }
/// LINKING PHASE /// LINKING PHASE
if (finalPhase == LINKING) {
if (emitNativeCode) { if (emitNativeCode) {
} else { } else {
} }
}
/// RUN THE ACTIONS /// RUN THE ACTIONS
std::vector<Action*>::iterator aIter = actions.begin(); std::vector<Action*>::iterator aIter = actions.begin();
@ -494,12 +519,12 @@ int CompilerDriver::execute(const InputList& InpList,
if (!keepTemps) { if (!keepTemps) {
// Cleanup files // Cleanup files
CleanupTempFile(TempPreprocessorOut.c_str()); ::sys::CleanupTempFile(TempPreprocessorOut);
CleanupTempFile(TempTranslatorOut.c_str()); ::sys::CleanupTempFile(TempTranslatorOut);
CleanupTempFile(TempOptimizerOut.c_str()); ::sys::CleanupTempFile(TempOptimizerOut);
// Cleanup temporary directory we created // Cleanup temporary directory we created
if (0 == access(TempDir.c_str(), F_OK | W_OK)) if (::sys::FileReadable(TempDir))
rmdir(TempDir.c_str()); rmdir(TempDir.c_str());
} }