blob: 789087f9a5f8d6a9ddf7528d1371ff7feac90353 [file] [log] [blame]
Chris Lattnerb26bcc52001-09-14 05:34:53 +00001//===-- llc.cpp - Implement the LLVM Compiler -----------------------------===//
Chris Lattnere737c7a2001-09-07 22:20:50 +00002//
3// This is the llc compiler driver.
4//
Chris Lattnerb26bcc52001-09-14 05:34:53 +00005//===----------------------------------------------------------------------===//
Vikram S. Advecb465fc2001-07-21 12:42:29 +00006
Vikram S. Advecb465fc2001-07-21 12:42:29 +00007#include "llvm/Bytecode/Reader.h"
Vikram S. Adve14335832001-08-28 23:23:14 +00008#include "llvm/Optimizations/Normalize.h"
Chris Lattnerb26bcc52001-09-14 05:34:53 +00009#include "llvm/Target/Sparc.h"
10#include "llvm/Target/Machine.h"
Chris Lattner57dbb3a2001-07-23 17:46:59 +000011#include "llvm/Support/CommandLine.h"
Chris Lattner46ac43c2001-09-07 21:26:31 +000012#include "llvm/Module.h"
13#include "llvm/Method.h"
Chris Lattner8f367bd2001-07-23 02:35:57 +000014
Chris Lattner1e78f362001-07-23 19:27:24 +000015cl::String InputFilename ("", "Input filename", cl::NoFlags, "-");
Chris Lattner8f367bd2001-07-23 02:35:57 +000016cl::String OutputFilename("o", "Output filename", cl::NoFlags, "");
17
Chris Lattner46ac43c2001-09-07 21:26:31 +000018static void NormalizeMethod(Method* method) {
Vikram S. Adve14335832001-08-28 23:23:14 +000019 NormalizePhiConstantArgs(method);
20}
21
Chris Lattnerb26bcc52001-09-14 05:34:53 +000022//===----------------------------------------------------------------------===//
Vikram S. Advecb465fc2001-07-21 12:42:29 +000023// Function main()
Chris Lattnerb26bcc52001-09-14 05:34:53 +000024//===----------------------------------------------------------------------===//
Vikram S. Advecb465fc2001-07-21 12:42:29 +000025//
Vikram S. Adve14335832001-08-28 23:23:14 +000026// Entry point for the llc compiler.
Chris Lattnerb26bcc52001-09-14 05:34:53 +000027//
Chris Lattner46ac43c2001-09-07 21:26:31 +000028int main(int argc, char** argv) {
Chris Lattner8f367bd2001-07-23 02:35:57 +000029 cl::ParseCommandLineOptions(argc, argv, " llvm system compiler\n");
Chris Lattnerf6e0e282001-09-14 04:32:55 +000030 TargetMachine *Target = allocateSparcTargetMachine();
Vikram S. Adve14335832001-08-28 23:23:14 +000031
Chris Lattnerb26bcc52001-09-14 05:34:53 +000032 Module *M = ParseBytecodeFile(InputFilename);
33 if (M == 0) {
Vikram S. Advecb465fc2001-07-21 12:42:29 +000034 cerr << "bytecode didn't read correctly.\n";
Chris Lattnerb26bcc52001-09-14 05:34:53 +000035 delete Target;
Vikram S. Advecb465fc2001-07-21 12:42:29 +000036 return 1;
37 }
Vikram S. Adve14335832001-08-28 23:23:14 +000038
Chris Lattnerb26bcc52001-09-14 05:34:53 +000039 bool Failed = false;
40 for (Module::const_iterator MI = M->begin(), ME = M->end(); MI != ME; ++MI) {
41 Method *Meth = *MI;
42
43 NormalizeMethod(Meth);
44
45 if (Target->compileMethod(Meth)) {
46 cerr << "Error compiling " << InputFilename << "!\n";
47 Failed = true;
48 break;
49 }
Chris Lattner1e78f362001-07-23 19:27:24 +000050 }
Vikram S. Advecb465fc2001-07-21 12:42:29 +000051
52 // Clean up and exit
Chris Lattnerb26bcc52001-09-14 05:34:53 +000053 delete M;
Chris Lattnerf6e0e282001-09-14 04:32:55 +000054 delete Target;
Chris Lattnerb26bcc52001-09-14 05:34:53 +000055 return Failed;
Vikram S. Advecb465fc2001-07-21 12:42:29 +000056}
Chris Lattner0e6530e2001-09-14 03:37:52 +000057