eliminate FileModel::Model, just use CodeGenFileType. The client

of the code generator shouldn't care what object format a target
uses.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@95124 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2010-02-02 21:06:45 +00:00
parent 1de46a4ab5
commit 211edae484
7 changed files with 42 additions and 50 deletions

View File

@ -60,16 +60,6 @@ namespace CodeModel {
};
}
namespace FileModel {
enum Model {
Error,
None,
AsmFile,
MachOFile,
ElfFile
};
}
// Code generation optimization level.
namespace CodeGenOpt {
enum Level {
@ -206,9 +196,13 @@ public:
}
/// CodeGenFileType - These enums are meant to be passed into
/// addPassesToEmitFile to indicate what type of file to emit.
/// addPassesToEmitFile to indicate what type of file to emit, and returned by
/// it to indicate what type of file could actually be made.
enum CodeGenFileType {
AssemblyFile, ObjectFile, DynamicLibrary
CGFT_AssemblyFile,
CGFT_ObjectFile,
CGFT_DynamicLibrary,
CGFT_ErrorOccurred
};
/// getEnableTailMergeDefault - the default setting for -enable-tail-merge
@ -218,14 +212,14 @@ public:
/// addPassesToEmitFile - Add passes to the specified pass manager to get the
/// specified file emitted. Typically this will involve several steps of code
/// generation.
/// This method should return FileModel::Error if emission of this file type
/// This method should return InvalidFile if emission of this file type
/// is not supported.
///
virtual FileModel::Model addPassesToEmitFile(PassManagerBase &,
formatted_raw_ostream &,
CodeGenFileType,
CodeGenOpt::Level) {
return FileModel::None;
virtual CodeGenFileType addPassesToEmitFile(PassManagerBase &,
formatted_raw_ostream &,
CodeGenFileType Filetype,
CodeGenOpt::Level) {
return CGFT_ErrorOccurred;
}
/// addPassesToEmitMachineCode - Add passes to the specified pass manager to
@ -271,19 +265,19 @@ public:
/// addPassesToEmitFile - Add passes to the specified pass manager to get the
/// specified file emitted. Typically this will involve several steps of code
/// generation. If OptLevel is None, the code generator should emit code as fast
/// as possible, though the generated code may be less efficient. This method
/// should return FileModel::Error if emission of this file type is not
/// supported.
/// generation. If OptLevel is None, the code generator should emit code as
/// fast as possible, though the generated code may be less efficient. This
/// method should return CGFT_ErrorOccurred if emission of this file type is
/// not supported.
///
/// The default implementation of this method adds components from the
/// LLVM retargetable code generator, invoking the methods below to get
/// target-specific passes in standard locations.
///
virtual FileModel::Model addPassesToEmitFile(PassManagerBase &PM,
formatted_raw_ostream &Out,
CodeGenFileType FileType,
CodeGenOpt::Level);
virtual CodeGenFileType addPassesToEmitFile(PassManagerBase &PM,
formatted_raw_ostream &Out,
CodeGenFileType FileType,
CodeGenOpt::Level);
/// addPassesToEmitMachineCode - Add passes to the specified pass manager to
/// get machine code emitted. This uses a MachineCodeEmitter object to handle

View File

@ -96,28 +96,25 @@ LLVMTargetMachine::setCodeModelForStatic() {
setCodeModel(CodeModel::Small);
}
FileModel::Model
TargetMachine::CodeGenFileType
LLVMTargetMachine::addPassesToEmitFile(PassManagerBase &PM,
formatted_raw_ostream &Out,
CodeGenFileType FileType,
CodeGenOpt::Level OptLevel) {
// Add common CodeGen passes.
if (addCommonCodeGenPasses(PM, OptLevel))
return FileModel::Error;
return CGFT_ErrorOccurred;
FileModel::Model ResultTy;
switch (FileType) {
default:
return FileModel::Error;
case TargetMachine::ObjectFile:
return FileModel::Error;
case TargetMachine::AssemblyFile: {
case CGFT_ObjectFile:
return CGFT_ErrorOccurred;
case CGFT_AssemblyFile: {
FunctionPass *Printer =
getTarget().createAsmPrinter(Out, *this, getMCAsmInfo(),
getAsmVerbosityDefault());
if (Printer == 0) return FileModel::Error;
if (Printer == 0) return CGFT_ErrorOccurred;
PM.add(Printer);
ResultTy = FileModel::AsmFile;
break;
}
}
@ -125,7 +122,7 @@ LLVMTargetMachine::addPassesToEmitFile(PassManagerBase &PM,
// Make sure the code model is set.
setCodeModelForStatic();
PM.add(createGCInfoDeleter());
return ResultTy;
return FileType;
}
/// addPassesToEmitMachineCode - Add passes to the specified pass manager to

View File

@ -3706,7 +3706,7 @@ bool CTargetMachine::addPassesToEmitWholeFile(PassManager &PM,
formatted_raw_ostream &o,
CodeGenFileType FileType,
CodeGenOpt::Level OptLevel) {
if (FileType != TargetMachine::AssemblyFile) return true;
if (FileType != TargetMachine::CGFT_AssemblyFile) return true;
PM.add(createGCLoweringPass());
PM.add(createLowerInvokePass());

View File

@ -2009,7 +2009,7 @@ bool CPPTargetMachine::addPassesToEmitWholeFile(PassManager &PM,
formatted_raw_ostream &o,
CodeGenFileType FileType,
CodeGenOpt::Level OptLevel) {
if (FileType != TargetMachine::AssemblyFile) return true;
if (FileType != TargetMachine::CGFT_AssemblyFile) return true;
PM.add(new CppWriter(o));
return false;
}

View File

@ -1690,7 +1690,7 @@ bool MSILTarget::addPassesToEmitWholeFile(PassManager &PM,
CodeGenFileType FileType,
CodeGenOpt::Level OptLevel)
{
if (FileType != TargetMachine::AssemblyFile) return true;
if (FileType != TargetMachine::CGFT_AssemblyFile) return true;
MSILWriter* Writer = new MSILWriter(o);
PM.add(createGCLoweringPass());
// FIXME: Handle switch through native IL instruction "switch"

View File

@ -85,14 +85,14 @@ MAttrs("mattr",
cl::value_desc("a1,+a2,-a3,..."));
cl::opt<TargetMachine::CodeGenFileType>
FileType("filetype", cl::init(TargetMachine::AssemblyFile),
FileType("filetype", cl::init(TargetMachine::CGFT_AssemblyFile),
cl::desc("Choose a file type (not all types are supported by all targets):"),
cl::values(
clEnumValN(TargetMachine::AssemblyFile, "asm",
clEnumValN(TargetMachine::CGFT_AssemblyFile, "asm",
"Emit an assembly ('.s') file"),
clEnumValN(TargetMachine::ObjectFile, "obj",
clEnumValN(TargetMachine::CGFT_ObjectFile, "obj",
"Emit a native object ('.o') file [experimental]"),
clEnumValN(TargetMachine::DynamicLibrary, "dynlib",
clEnumValN(TargetMachine::CGFT_DynamicLibrary, "dynlib",
"Emit a native dynamic library ('.so') file"
" [experimental]"),
clEnumValEnd));
@ -162,7 +162,8 @@ static formatted_raw_ostream *GetOutputStream(const char *TargetName,
bool Binary = false;
switch (FileType) {
case TargetMachine::AssemblyFile:
default: assert(0 && "Unknown file type");
case TargetMachine::CGFT_AssemblyFile:
if (TargetName[0] == 'c') {
if (TargetName[1] == 0)
OutputFilename += ".cbe.c";
@ -173,11 +174,11 @@ static formatted_raw_ostream *GetOutputStream(const char *TargetName,
} else
OutputFilename += ".s";
break;
case TargetMachine::ObjectFile:
case TargetMachine::CGFT_ObjectFile:
OutputFilename += ".o";
Binary = true;
break;
case TargetMachine::DynamicLibrary:
case TargetMachine::CGFT_DynamicLibrary:
OutputFilename += LTDL_SHLIB_EXT;
Binary = true;
break;
@ -352,14 +353,14 @@ int main(int argc, char **argv) {
default:
assert(0 && "Invalid file model!");
return 1;
case FileModel::Error:
case TargetMachine::CGFT_ErrorOccurred:
errs() << argv[0] << ": target does not support generation of this"
<< " file type!\n";
if (Out != &fouts()) delete Out;
// And the Out file is empty and useless, so remove it now.
sys::Path(OutputFilename).eraseFromDisk();
return 1;
case FileModel::AsmFile:
case TargetMachine::CGFT_AssemblyFile:
break;
}

View File

@ -396,9 +396,9 @@ bool LTOCodeGenerator::generateAssemblyCode(formatted_raw_ostream& out,
codeGenPasses->add(new TargetData(*_target->getTargetData()));
switch (_target->addPassesToEmitFile(*codeGenPasses, out,
TargetMachine::AssemblyFile,
TargetMachine::CGFT_AssemblyFile,
CodeGenOpt::Aggressive)) {
case FileModel::AsmFile:
case TargetMachine::CGFT_AssemblyFile:
break;
default:
errMsg = "target file type not supported";