Vikram S. Adve | cb465fc | 2001-07-21 12:42:29 +0000 | [diff] [blame] | 1 | // $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 Lattner | 7e583cf | 2001-07-21 20:58:30 +0000 | [diff] [blame^] | 22 | #include "llvm/CodeGen/InstrForest.h" |
| 23 | #include "llvm/CodeGen/InstrSelection.h" |
Vikram S. Adve | cb465fc | 2001-07-21 12:42:29 +0000 | [diff] [blame] | 24 | #include "llvm/LLC/LLCOptions.h" |
| 25 | #include "llvm/LLC/CompileContext.h" |
| 26 | |
| 27 | //************************** Forward Declarations **************************/ |
| 28 | |
| 29 | class Module; |
| 30 | class CompileContext; |
| 31 | |
| 32 | |
| 33 | static bool CompileModule (Module *module, |
| 34 | CompileContext& compileContext); |
| 35 | |
| 36 | int DebugInstrSelectLevel = DEBUG_INSTR_TREES; |
| 37 | |
| 38 | |
| 39 | //--------------------------------------------------------------------------- |
| 40 | // Function main() |
| 41 | // |
| 42 | // Entry point for the driver. |
| 43 | //--------------------------------------------------------------------------- |
| 44 | |
| 45 | |
| 46 | int |
| 47 | main(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 | |
| 79 | static bool |
| 80 | CompileModule(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 | |