aboutsummaryrefslogtreecommitdiff
path: root/tools/llc/llc.cpp
blob: fb5c1fc9456845ae25ed49d11e371a7048c714f3 (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
//===------------------------------------------------------------------------===
// LLVM 'LLC' UTILITY 
//
// This is the llc compiler driver.
//
//===------------------------------------------------------------------------===

#include "llvm/Bytecode/Reader.h"
#include "llvm/Optimizations/Normalize.h"
#include "llvm/CodeGen/Sparc.h"
#include "llvm/CodeGen/TargetMachine.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Module.h"
#include "llvm/Method.h"

cl::String InputFilename ("", "Input filename", cl::NoFlags, "-");
cl::String OutputFilename("o", "Output filename", cl::NoFlags, "");

static void NormalizeMethod(Method* method) {
  NormalizePhiConstantArgs(method);
}


static bool CompileModule(Module *M, TargetMachine &Target) {
  for (Module::const_iterator MI = M->begin(), ME = M->end(); MI != ME; ++MI) {
    Method *Meth = *MI;
      
    NormalizeMethod(Meth);
      
    if (Target.compileMethod(Meth)) return true;
  }
  
  return false;
}



//---------------------------------------------------------------------------
// Function main()
// 
// Entry point for the llc compiler.
//---------------------------------------------------------------------------

int main(int argc, char** argv) {
  cl::ParseCommandLineOptions(argc, argv, " llvm system compiler\n");
  TargetMachine *Target = allocateSparcTargetMachine();
  
  Module *module = ParseBytecodeFile(InputFilename);
  if (module == 0) {
    cerr << "bytecode didn't read correctly.\n";
    return 1;
  }

  if (CompileModule(module, *Target)) {
    cerr << "Error compiling " << InputFilename << "!\n";
    delete module;
    return 1;
  }
  
  // Clean up and exit
  delete module;
  delete Target;
  return 0;
}