llvm-project/llvm/tools/llc/llc.cpp

65 lines
1.8 KiB
C++
Raw Normal View History

2001-09-18 21:10:45 +08:00
//===-- llc.cpp - Implement the LLVM Compiler ----------------------------===//
//
// This is the llc compiler driver.
//
2001-09-18 21:10:45 +08:00
//===---------------------------------------------------------------------===//
#include "llvm/Bytecode/Reader.h"
#include "llvm/Optimizations/Normalize.h"
#include "llvm/Target/Sparc.h"
2001-09-18 21:10:45 +08:00
#include "llvm/Target/TargetMachine.h"
#include "llvm/Support/CommandLine.h"
2001-09-08 05:26:31 +08:00
#include "llvm/Module.h"
#include "llvm/Method.h"
#include <memory>
cl::String InputFilename ("", "Input filename", cl::NoFlags, "-");
cl::String OutputFilename("o", "Output filename", cl::NoFlags, "");
2001-09-18 21:10:45 +08:00
//-------------------------- Internal Functions -----------------------------//
static void NormalizeMethod(Method* method) {
NormalizePhiConstantArgs(method);
}
2001-09-18 21:10:45 +08:00
//===---------------------------------------------------------------------===//
// Function main()
//
// Entry point for the llc compiler.
2001-09-18 21:10:45 +08:00
//===---------------------------------------------------------------------===//
int main(int argc, char **argv) {
// Parse command line options...
cl::ParseCommandLineOptions(argc, argv, " llvm system compiler\n");
// 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;
NormalizeMethod(Meth);
if (Target.get()->compileMethod(Meth)) {
cerr << "Error compiling " << InputFilename << "!\n";
return 1;
}
}
Target->emitAssembly(M.get(), cout);
return 0;
}
2001-09-18 21:10:45 +08:00