2001-09-08 06:20:50 +08:00
|
|
|
//===------------------------------------------------------------------------===
|
|
|
|
// LLVM 'LLC' UTILITY
|
|
|
|
//
|
|
|
|
// This is the llc compiler driver.
|
|
|
|
//
|
|
|
|
//===------------------------------------------------------------------------===
|
2001-07-21 20:42:29 +08:00
|
|
|
|
|
|
|
#include "llvm/Bytecode/Reader.h"
|
2001-08-29 07:23:14 +08:00
|
|
|
#include "llvm/Optimizations/Normalize.h"
|
2001-07-22 12:40:02 +08:00
|
|
|
#include "llvm/CodeGen/Sparc.h"
|
2001-09-14 12:32:55 +08:00
|
|
|
#include "llvm/CodeGen/TargetMachine.h"
|
2001-07-24 01:46:59 +08:00
|
|
|
#include "llvm/Support/CommandLine.h"
|
2001-09-08 05:26:31 +08:00
|
|
|
#include "llvm/Module.h"
|
|
|
|
#include "llvm/Method.h"
|
2001-07-23 10:35:57 +08:00
|
|
|
|
2001-07-24 03:27:24 +08:00
|
|
|
cl::String InputFilename ("", "Input filename", cl::NoFlags, "-");
|
2001-07-23 10:35:57 +08:00
|
|
|
cl::String OutputFilename("o", "Output filename", cl::NoFlags, "");
|
|
|
|
|
2001-09-08 05:26:31 +08:00
|
|
|
static void NormalizeMethod(Method* method) {
|
2001-08-29 07:23:14 +08:00
|
|
|
NormalizePhiConstantArgs(method);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-09-08 05:26:31 +08:00
|
|
|
static bool CompileModule(Module *M, TargetMachine &Target) {
|
|
|
|
for (Module::const_iterator MI = M->begin(), ME = M->end(); MI != ME; ++MI) {
|
|
|
|
Method *Meth = *MI;
|
2001-08-29 07:23:14 +08:00
|
|
|
|
2001-09-08 05:26:31 +08:00
|
|
|
NormalizeMethod(Meth);
|
2001-07-22 12:40:02 +08:00
|
|
|
|
2001-09-14 11:37:52 +08:00
|
|
|
if (Target.compileMethod(Meth)) return true;
|
2001-09-08 05:26:31 +08:00
|
|
|
}
|
2001-07-22 12:40:02 +08:00
|
|
|
|
2001-09-08 05:26:31 +08:00
|
|
|
return false;
|
2001-07-22 12:40:02 +08:00
|
|
|
}
|
2001-07-21 20:42:29 +08:00
|
|
|
|
|
|
|
|
2001-08-29 07:23:14 +08:00
|
|
|
|
2001-07-21 20:42:29 +08:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
// Function main()
|
|
|
|
//
|
2001-08-29 07:23:14 +08:00
|
|
|
// Entry point for the llc compiler.
|
2001-07-21 20:42:29 +08:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
2001-09-08 05:26:31 +08:00
|
|
|
int main(int argc, char** argv) {
|
2001-07-23 10:35:57 +08:00
|
|
|
cl::ParseCommandLineOptions(argc, argv, " llvm system compiler\n");
|
2001-09-14 12:32:55 +08:00
|
|
|
TargetMachine *Target = allocateSparcTargetMachine();
|
2001-08-29 07:23:14 +08:00
|
|
|
|
2001-07-24 03:27:24 +08:00
|
|
|
Module *module = ParseBytecodeFile(InputFilename);
|
2001-07-21 20:42:29 +08:00
|
|
|
if (module == 0) {
|
|
|
|
cerr << "bytecode didn't read correctly.\n";
|
|
|
|
return 1;
|
|
|
|
}
|
2001-08-29 07:23:14 +08:00
|
|
|
|
2001-09-14 12:32:55 +08:00
|
|
|
if (CompileModule(module, *Target)) {
|
2001-07-24 03:27:24 +08:00
|
|
|
cerr << "Error compiling " << InputFilename << "!\n";
|
|
|
|
delete module;
|
|
|
|
return 1;
|
|
|
|
}
|
2001-07-21 20:42:29 +08:00
|
|
|
|
|
|
|
// Clean up and exit
|
|
|
|
delete module;
|
2001-09-14 12:32:55 +08:00
|
|
|
delete Target;
|
2001-07-21 20:42:29 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2001-09-14 11:37:52 +08:00
|
|
|
|