aboutsummaryrefslogtreecommitdiffstats
path: root/tools/llc/llc.cpp
blob: 6ac3175f2b253fde5272ae88d888fb3b9549c986 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// $Id$
//***************************************************************************
// File:
//	llc.cpp
// 
// Purpose:
//	Driver for llc compiler.
// 
// History:
//	7/15/01	 -  Vikram Adve  -  Created
// 
//**************************************************************************/

//************************** System Include Files **************************/

//*************************** User Include Files ***************************/

#include "llvm/Module.h"
#include "llvm/Method.h"
#include "llvm/Bytecode/Reader.h"
#include "llvm/Bytecode/Writer.h"
#include "llvm/CodeGen/InstrForest.h"
#include "llvm/CodeGen/InstrSelection.h"
#include "llvm/LLC/LLCOptions.h"
#include "llvm/LLC/CompileContext.h"

//************************** Forward Declarations **************************/

class Module;
class CompileContext;


static bool	CompileModule	(Module *module,
				 CompileContext& compileContext);

int DebugInstrSelectLevel = DEBUG_INSTR_TREES;


//---------------------------------------------------------------------------
// Function main()
// 
// Entry point for the driver.
//---------------------------------------------------------------------------


int
main(int argc, const char** argv, const char** envp)
{
  CompileContext compileContext(argc, argv, envp);
  
  Module *module =
    ParseBytecodeFile(compileContext.getOptions().getInputFileName());
  
  if (module == 0) {
    cerr << "bytecode didn't read correctly.\n";
    return 1;
  }
  
  bool failure = CompileModule(module, compileContext);
  
  if (failure)
    {
      cerr << "Error compiling "
	   << compileContext.getOptions().getInputFileName() << "!\n";
      delete module;
      return 1;
    }
  
  // Okay, we're done now... write out result...
  // WriteBytecodeToFile(module, 
  // 		      compileContext.getOptions().getOutputFileName);
  
  // Clean up and exit
  delete module;
  return 0;
}


static bool
CompileModule(Module *module,
	      CompileContext& ccontext)
{
  bool failed = false;
  
  for (Module::MethodListType::const_iterator
	 methodIter = module->getMethodList().begin();
       methodIter != module->getMethodList().end();
       ++methodIter)
    {
      Method* method = *methodIter;
      
      if (SelectInstructionsForMethod(method, ccontext))
	{
	  failed = true;
	  cerr << "Instruction selection failed for method "
	       << (method->hasName()? method->getName() : "")
	       << endl << endl;
	}
    }
  
  return failed;
}