blob: 4bf26d5a16f7ddb934d1d12c13ee96a5df37387a [file] [log] [blame]
Vikram S. Adve2d94a342001-07-21 12:42:29 +00001// $Id$
2//***************************************************************************
3// File:
4// llc.cpp
5//
6// Purpose:
7// Driver for llc compiler.
8//
9// History:
10// 7/15/01 - Vikram Adve - Created
11//
12//**************************************************************************/
13
Vikram S. Adve2d94a342001-07-21 12:42:29 +000014#include "llvm/Module.h"
15#include "llvm/Method.h"
16#include "llvm/Bytecode/Reader.h"
17#include "llvm/Bytecode/Writer.h"
Chris Lattnerdd511762001-07-21 20:58:30 +000018#include "llvm/CodeGen/InstrSelection.h"
Vikram S. Adve2d94a342001-07-21 12:42:29 +000019#include "llvm/LLC/CompileContext.h"
Chris Lattner9c0f8f22001-07-22 04:40:02 +000020#include "llvm/CodeGen/Sparc.h"
21#include "LLCOptions.h"
Vikram S. Adve2d94a342001-07-21 12:42:29 +000022
Chris Lattner9c0f8f22001-07-22 04:40:02 +000023CompileContext::~CompileContext() { delete targetMachine; }
Vikram S. Adve2d94a342001-07-21 12:42:29 +000024
Chris Lattner9c0f8f22001-07-22 04:40:02 +000025static bool CompileModule(Module *module, CompileContext& ccontext,
26 LLCOptions &Options) {
27 bool failed = false;
28
29 for (Module::MethodListType::const_iterator
30 methodIter = module->getMethodList().begin();
31 methodIter != module->getMethodList().end();
32 ++methodIter)
33 {
34 Method* method = *methodIter;
35
36 if (SelectInstructionsForMethod(method, ccontext,
37 Options.IntOptionValue(DEBUG_INSTR_SELECT_OPT)))
38 {
39 failed = true;
40 cerr << "Instruction selection failed for method "
41 << method->getName() << "\n\n";
42 }
43 }
44
45 return failed;
46}
Vikram S. Adve2d94a342001-07-21 12:42:29 +000047
48
49//---------------------------------------------------------------------------
50// Function main()
51//
52// Entry point for the driver.
53//---------------------------------------------------------------------------
54
Chris Lattner9c0f8f22001-07-22 04:40:02 +000055int main(int argc, const char** argv, const char** envp) {
56 LLCOptions Options(argc, argv, envp);
57 CompileContext compileContext(new UltraSparc());
Vikram S. Adve2d94a342001-07-21 12:42:29 +000058
Chris Lattner9c0f8f22001-07-22 04:40:02 +000059 Module *module = ParseBytecodeFile(Options.getInputFileName());
Vikram S. Adve2d94a342001-07-21 12:42:29 +000060 if (module == 0) {
61 cerr << "bytecode didn't read correctly.\n";
62 return 1;
63 }
64
Chris Lattner9c0f8f22001-07-22 04:40:02 +000065 bool failure = CompileModule(module, compileContext, Options);
Vikram S. Adve2d94a342001-07-21 12:42:29 +000066
Chris Lattner9c0f8f22001-07-22 04:40:02 +000067 if (failure) {
Vikram S. Adve2d94a342001-07-21 12:42:29 +000068 cerr << "Error compiling "
Chris Lattner9c0f8f22001-07-22 04:40:02 +000069 << Options.getInputFileName() << "!\n";
Vikram S. Adve2d94a342001-07-21 12:42:29 +000070 delete module;
71 return 1;
72 }
73
74 // Okay, we're done now... write out result...
75 // WriteBytecodeToFile(module,
76 // compileContext.getOptions().getOutputFileName);
77
78 // Clean up and exit
79 delete module;
80 return 0;
81}