public
Description:
Homepage:
Clone URL: git://github.com/miura1729/yarv2llvm.git
yarv2llvm / yarv2llvm.rb
100644 117 lines (93 sloc) 3.107 kb
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/bin/env ruby
#
# yarv2llvm convert yarv to LLVM and define LLVM executable as Ruby method.
#
#
require 'lib/yarv2llvm'
 
if __FILE__ == $0 then
  require 'optparse'
  
  preload = []
  opt = OptionParser.new
  y2lopt = {}
 
  opt.on('-O', '--[no-]optimize',
         'Execute optimize (use "opt" in llvm)') do |f|
    y2lopt[:optimize] = f
  end
 
  opt.on('--[no-]post-optimize',
         'Execute post optimize (llvm level peephole optimize)') do |f|
    y2lopt[:post_optimize] = f
  end
 
  opt.on('-r FILE',
         'Execute FILE by Ruby1.9 before compile main program') do |f|
    rf = File.read(f)
    prog = eval(rf)
    is = RubyVM::InstructionSequence.compile( prog, f, 1,
            { :peephole_optimization => true,
               :inline_const_cache => false,
               :specialized_instruction => true,}).to_a
    preload.push VMLib::InstSeqTree.new(nil, is)
  end
 
  opt.on('--[no-]strict-type-inference',
         'When occur type conflict, compile stop.') do |f|
    y2lopt[:strict_type_inderence] = f
  end
 
  opt.on('--[no-]implicit-numeric-type-conversion',
         'Implicit type conversion. For example Fixnum to Float') do |f|
    y2lopt[:implicit_numeric_type_conversion] = f
  end
 
  opt.on('--[no-]inline-block',
         'Inline block when compile "each" method.') do |f|
    y2lopt[:inline_block] = f
  end
 
  opt.on('--[no-]array-range-check',
         'Raise exception when refer out of range of array or hash') do |f|
    y2lopt[:array_range_check] = f
  end
 
  opt.on('--[no-]cache-instance-variable',
         'Cache instance varibale table (It is dangerous)') do |f|
    y2lopt[:cache_instance_variable] = f
  end
 
  opt.on('--[no-]disasm',
         'Disassemble generated llvm code') do |f|
    y2lopt[:disasm] = f
  end
 
  opt.on('--[no-]dump-yarv',
         'Dump generated yarv code') do |f|
    y2lopt[:dump_yarv] = f
  end
 
  opt.on('--write-bc[=File]',
         'Dump generated llvm bitcode to file(default is yarv.bc)') do |f|
    y2lopt[:write_bc] = f
  end
 
  opt.on('--[no-]func-signature',
         'Display type inferenced inforamtion about function and local variable') do |f|
    y2lopt[:func_signature] = f
  end
 
  opt.on('--[no-]var-signature',
         'Display type inferenced inforamtion about global variable') do |f|
    y2lopt[:var_signature] = f
  end
 
  opt.on('--[no-]type-message',
         'Display type message for example Type Conflict Error') do |f|
    y2lopt[:type_message] = f
  end
 
  opt.on('--compile-only',
         'Do compile but execute it') do |f|
    y2lopt[:compile_only] = f
  end
 
  opt.on('--gc-profile',
         'GC profiler invoke (for tuning yarv2llvm itself)') do |f|
    y2lopt[:gc_profile] = f
  end
  
  opt.parse!(ARGV)
 
  if y2lopt[:gc_profile] then
    GC::Profiler.enable
  end
 
  progn = ARGV[0]
  $0 = progn
  ARGV.shift
 
  YARV2LLVM::compile_file(progn, y2lopt, preload)
  if y2lopt[:gc_profile] then
    GC::Profiler.report(STDERR)
  end
end # __FILE__ == $0