2001-09-18 21:10:45 +08:00
|
|
|
//===-- llc.cpp - Implement the LLVM Compiler ----------------------------===//
|
2001-09-08 06:20:50 +08:00
|
|
|
//
|
|
|
|
// This is the llc compiler driver.
|
|
|
|
//
|
2001-09-18 21:10:45 +08:00
|
|
|
//===---------------------------------------------------------------------===//
|
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-09-14 13:34:53 +08:00
|
|
|
#include "llvm/Target/Sparc.h"
|
2001-09-18 21:10:45 +08:00
|
|
|
#include "llvm/Target/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-09-19 01:04:18 +08:00
|
|
|
#include <memory>
|
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-18 21:10:45 +08:00
|
|
|
|
|
|
|
//-------------------------- Internal Functions -----------------------------//
|
|
|
|
|
2001-09-19 01:04:18 +08:00
|
|
|
static void NormalizeMethod(Method* method) {
|
2001-08-29 07:23:14 +08:00
|
|
|
NormalizePhiConstantArgs(method);
|
|
|
|
}
|
|
|
|
|
2001-09-18 21:10:45 +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-09-18 21:10:45 +08:00
|
|
|
//===---------------------------------------------------------------------===//
|
|
|
|
|
2001-09-19 01:04:18 +08:00
|
|
|
int main(int argc, char **argv) {
|
|
|
|
// Parse command line options...
|
2001-07-23 10:35:57 +08:00
|
|
|
cl::ParseCommandLineOptions(argc, argv, " llvm system compiler\n");
|
2001-08-29 07:23:14 +08:00
|
|
|
|
2001-09-19 01:04:18 +08:00
|
|
|
// Allocate a target... in the future this will be controllable on the
|
|
|
|
// command line.
|
|
|
|
auto_ptr<TargetMachine> Target(allocateSparcTargetMachine());
|
|
|
|
|
|
|
|
// Load the module to be compiled...
|
|
|
|
auto_ptr<Module> M(ParseBytecodeFile(InputFilename));
|
|
|
|
if (M.get() == 0) {
|
|
|
|
cerr << "bytecode didn't read correctly.\n";
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Loop over all of the methods in the module, compiling them.
|
|
|
|
for (Module::const_iterator MI = M->begin(), ME = M->end(); MI != ME; ++MI) {
|
|
|
|
Method *Meth = *MI;
|
2001-09-14 13:34:53 +08:00
|
|
|
|
2001-09-19 01:04:18 +08:00
|
|
|
NormalizeMethod(Meth);
|
2001-09-14 13:34:53 +08:00
|
|
|
|
2001-09-19 01:04:18 +08:00
|
|
|
if (Target.get()->compileMethod(Meth)) {
|
|
|
|
cerr << "Error compiling " << InputFilename << "!\n";
|
|
|
|
return 1;
|
2001-09-14 13:34:53 +08:00
|
|
|
}
|
2001-09-19 01:04:18 +08:00
|
|
|
}
|
2001-07-21 20:42:29 +08:00
|
|
|
|
2001-09-19 21:56:47 +08:00
|
|
|
Target->emitAssembly(M.get(), cout);
|
2001-09-19 01:04:18 +08:00
|
|
|
return 0;
|
2001-07-21 20:42:29 +08:00
|
|
|
}
|
2001-09-14 11:37:52 +08:00
|
|
|
|
2001-09-18 21:10:45 +08:00
|
|
|
|