blob: 6ac3175f2b253fde5272ae88d888fb3b9549c986 [file] [log] [blame]
Vikram S. Advecb465fc2001-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
14//************************** System Include Files **************************/
15
16//*************************** User Include Files ***************************/
17
18#include "llvm/Module.h"
19#include "llvm/Method.h"
20#include "llvm/Bytecode/Reader.h"
21#include "llvm/Bytecode/Writer.h"
Chris Lattner7e583cf2001-07-21 20:58:30 +000022#include "llvm/CodeGen/InstrForest.h"
23#include "llvm/CodeGen/InstrSelection.h"
Vikram S. Advecb465fc2001-07-21 12:42:29 +000024#include "llvm/LLC/LLCOptions.h"
25#include "llvm/LLC/CompileContext.h"
26
27//************************** Forward Declarations **************************/
28
29class Module;
30class CompileContext;
31
32
33static bool CompileModule (Module *module,
34 CompileContext& compileContext);
35
36int DebugInstrSelectLevel = DEBUG_INSTR_TREES;
37
38
39//---------------------------------------------------------------------------
40// Function main()
41//
42// Entry point for the driver.
43//---------------------------------------------------------------------------
44
45
46int
47main(int argc, const char** argv, const char** envp)
48{
49 CompileContext compileContext(argc, argv, envp);
50
51 Module *module =
52 ParseBytecodeFile(compileContext.getOptions().getInputFileName());
53
54 if (module == 0) {
55 cerr << "bytecode didn't read correctly.\n";
56 return 1;
57 }
58
59 bool failure = CompileModule(module, compileContext);
60
61 if (failure)
62 {
63 cerr << "Error compiling "
64 << compileContext.getOptions().getInputFileName() << "!\n";
65 delete module;
66 return 1;
67 }
68
69 // Okay, we're done now... write out result...
70 // WriteBytecodeToFile(module,
71 // compileContext.getOptions().getOutputFileName);
72
73 // Clean up and exit
74 delete module;
75 return 0;
76}
77
78
79static bool
80CompileModule(Module *module,
81 CompileContext& ccontext)
82{
83 bool failed = false;
84
85 for (Module::MethodListType::const_iterator
86 methodIter = module->getMethodList().begin();
87 methodIter != module->getMethodList().end();
88 ++methodIter)
89 {
90 Method* method = *methodIter;
91
92 if (SelectInstructionsForMethod(method, ccontext))
93 {
94 failed = true;
95 cerr << "Instruction selection failed for method "
96 << (method->hasName()? method->getName() : "")
97 << endl << endl;
98 }
99 }
100
101 return failed;
102}
103