ruby-llvm 2.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +28 -0
- data/lib/llvm.rb +15 -0
- data/lib/llvm/analysis.rb +46 -0
- data/lib/llvm/core.rb +520 -0
- data/lib/llvm/core/builder.rb +377 -0
- data/lib/llvm/core/context.rb +29 -0
- data/lib/llvm/core/module.rb +199 -0
- data/lib/llvm/core/pass_manager.rb +30 -0
- data/lib/llvm/core/type.rb +113 -0
- data/lib/llvm/core/value.rb +469 -0
- data/lib/llvm/execution_engine.rb +139 -0
- data/lib/llvm/target.rb +8 -0
- data/lib/llvm/transforms/scalar.rb +119 -0
- metadata +74 -0
@@ -0,0 +1,139 @@
|
|
1
|
+
require 'llvm'
|
2
|
+
require 'llvm/core'
|
3
|
+
require 'llvm/target'
|
4
|
+
require 'llvm/analysis'
|
5
|
+
|
6
|
+
module LLVM
|
7
|
+
module C
|
8
|
+
# Generic values
|
9
|
+
attach_function :LLVMCreateGenericValueOfInt, [:pointer, :long_long, :int], :pointer
|
10
|
+
attach_function :LLVMCreateGenericValueOfPointer, [:pointer], :pointer
|
11
|
+
attach_function :LLVMCreateGenericValueOfFloat, [:pointer, :double], :pointer
|
12
|
+
|
13
|
+
attach_function :LLVMGenericValueIntWidth, [:pointer], :uint
|
14
|
+
|
15
|
+
attach_function :LLVMGenericValueToInt, [:pointer, :int], :long_long
|
16
|
+
attach_function :LLVMGenericValueToPointer, [:pointer], :pointer
|
17
|
+
attach_function :LLVMGenericValueToFloat, [:pointer, :pointer], :double
|
18
|
+
attach_function :LLVMDisposeGenericValue, [:pointer], :void
|
19
|
+
|
20
|
+
# Execution engines
|
21
|
+
attach_function :LLVMCreateExecutionEngineForModule, [:pointer, :pointer, :pointer], :int
|
22
|
+
attach_function :LLVMCreateInterpreterForModule, [:pointer, :pointer, :pointer], :int
|
23
|
+
attach_function :LLVMCreateJITCompilerForModule, [:pointer, :pointer, :uint, :pointer], :int
|
24
|
+
attach_function :LLVMDisposeExecutionEngine, [:pointer], :void
|
25
|
+
|
26
|
+
attach_function :LLVMRunStaticConstructors, [:pointer], :void
|
27
|
+
attach_function :LLVMRunStaticDestructors, [:pointer], :void
|
28
|
+
|
29
|
+
attach_function :LLVMRunFunctionAsMain, [:pointer, :pointer, :uint, :pointer, :pointer], :int
|
30
|
+
attach_function :LLVMRunFunction, [:pointer, :pointer, :uint, :pointer], :pointer
|
31
|
+
|
32
|
+
attach_function :LLVMFreeMachineCodeForFunction, [:pointer, :pointer], :void
|
33
|
+
attach_function :LLVMAddModuleProvider, [:pointer, :pointer], :void
|
34
|
+
attach_function :LLVMRemoveModuleProvider, [:pointer, :pointer, :pointer, :pointer], :int
|
35
|
+
|
36
|
+
attach_function :LLVMFindFunction, [:pointer, :pointer, :pointer, :pointer], :int
|
37
|
+
|
38
|
+
attach_function :LLVMGetExecutionEngineTargetData, [:pointer], :pointer
|
39
|
+
|
40
|
+
attach_function :LLVMAddGlobalMapping, [:pointer, :pointer, :pointer], :void
|
41
|
+
|
42
|
+
attach_function :LLVMGetPointerToGlobal, [:pointer, :pointer], :pointer
|
43
|
+
|
44
|
+
attach_function :LLVMInitializeX86TargetInfo, [], :void
|
45
|
+
|
46
|
+
attach_function :LLVMInitializeX86Target, [], :void
|
47
|
+
end
|
48
|
+
|
49
|
+
def LLVM.init_x86
|
50
|
+
LLVM::C.LLVMInitializeX86Target
|
51
|
+
LLVM::C.LLVMInitializeX86TargetInfo
|
52
|
+
end
|
53
|
+
|
54
|
+
class ExecutionEngine
|
55
|
+
class << self
|
56
|
+
private :new
|
57
|
+
end
|
58
|
+
|
59
|
+
def initialize(ptr) # :nodoc:
|
60
|
+
@ptr = ptr
|
61
|
+
end
|
62
|
+
|
63
|
+
def to_ptr # :nodoc:
|
64
|
+
@ptr
|
65
|
+
end
|
66
|
+
|
67
|
+
def self.create_jit_compiler(mod, opt_level = 3)
|
68
|
+
FFI::MemoryPointer.new(FFI.type_size(:pointer)) do |ptr|
|
69
|
+
error = FFI::MemoryPointer.new(FFI.type_size(:pointer))
|
70
|
+
status = C.LLVMCreateJITCompilerForModule(ptr, mod, opt_level, error)
|
71
|
+
errorp = error.read_pointer
|
72
|
+
message = errorp.read_string unless errorp.null?
|
73
|
+
|
74
|
+
if status.zero?
|
75
|
+
return new(ptr.read_pointer)
|
76
|
+
else
|
77
|
+
C.LLVMDisposeMessage(error)
|
78
|
+
raise RuntimeError, "Error creating JIT compiler: #{message}"
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def run_function(fun, *args)
|
84
|
+
FFI::MemoryPointer.new(FFI.type_size(:pointer) * args.size) do |args_ptr|
|
85
|
+
args_ptr.write_array_of_pointer(args.map { |arg| LLVM.GenericValue(arg).to_ptr })
|
86
|
+
return LLVM::GenericValue.from_ptr(
|
87
|
+
C.LLVMRunFunction(self, fun, args.size, args_ptr))
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def pointer_to_global(global)
|
92
|
+
C.LLVMGetPointerToGlobal(self, global)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
class GenericValue
|
97
|
+
class << self
|
98
|
+
private :new
|
99
|
+
end
|
100
|
+
|
101
|
+
def initialize(ptr) # :nodoc:
|
102
|
+
@ptr = ptr
|
103
|
+
end
|
104
|
+
|
105
|
+
def to_ptr # :nodoc:
|
106
|
+
@ptr
|
107
|
+
end
|
108
|
+
|
109
|
+
def self.from_i(i, type = LLVM::Int, signed = true)
|
110
|
+
new(C.LLVMCreateGenericValueOfInt(type, i, signed ? 1 : 0))
|
111
|
+
end
|
112
|
+
|
113
|
+
def self.from_f(f)
|
114
|
+
type = LLVM::Float.type
|
115
|
+
new(C.LLVMCreateGenericValueOfFloat(type, f))
|
116
|
+
end
|
117
|
+
|
118
|
+
def self.from_ptr(ptr)
|
119
|
+
new(ptr)
|
120
|
+
end
|
121
|
+
|
122
|
+
def to_i(signed = true)
|
123
|
+
C.LLVMGenericValueToInt(self, signed ? 1 : 0)
|
124
|
+
end
|
125
|
+
|
126
|
+
def to_f
|
127
|
+
C.LLVMGenericValueToFloat(LLVM::Float.type, self)
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
def GenericValue(val)
|
132
|
+
case val
|
133
|
+
when GenericValue then val
|
134
|
+
when Integer then GenericValue.from_i(val)
|
135
|
+
when Float then GenericValue.from_f(val)
|
136
|
+
end
|
137
|
+
end
|
138
|
+
module_function :GenericValue
|
139
|
+
end
|
data/lib/llvm/target.rb
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
require 'llvm'
|
2
|
+
require 'llvm/core'
|
3
|
+
|
4
|
+
module LLVM
|
5
|
+
module C
|
6
|
+
attach_function :LLVMAddAggressiveDCEPass, [:pointer], :void
|
7
|
+
attach_function :LLVMAddCFGSimplificationPass, [:pointer], :void
|
8
|
+
attach_function :LLVMAddDeadStoreEliminationPass, [:pointer], :void
|
9
|
+
attach_function :LLVMAddGVNPass, [:pointer], :void
|
10
|
+
attach_function :LLVMAddIndVarSimplifyPass, [:pointer], :void
|
11
|
+
attach_function :LLVMAddInstructionCombiningPass, [:pointer], :void
|
12
|
+
attach_function :LLVMAddJumpThreadingPass, [:pointer], :void
|
13
|
+
attach_function :LLVMAddLICMPass, [:pointer], :void
|
14
|
+
attach_function :LLVMAddLoopDeletionPass, [:pointer], :void
|
15
|
+
attach_function :LLVMAddLoopIndexSplitPass, [:pointer], :void
|
16
|
+
attach_function :LLVMAddLoopRotatePass, [:pointer], :void
|
17
|
+
attach_function :LLVMAddLoopUnrollPass, [:pointer], :void
|
18
|
+
attach_function :LLVMAddLoopUnswitchPass, [:pointer], :void
|
19
|
+
attach_function :LLVMAddMemCpyOptPass, [:pointer], :void
|
20
|
+
attach_function :LLVMAddPromoteMemoryToRegisterPass, [:pointer], :void
|
21
|
+
attach_function :LLVMAddReassociatePass, [:pointer], :void
|
22
|
+
attach_function :LLVMAddSCCPPass, [:pointer], :void
|
23
|
+
attach_function :LLVMAddScalarReplAggregatesPass, [:pointer], :void
|
24
|
+
attach_function :LLVMAddSimplifyLibCallsPass, [:pointer], :void
|
25
|
+
attach_function :LLVMAddTailCallEliminationPass, [:pointer], :void
|
26
|
+
attach_function :LLVMAddConstantPropagationPass, [:pointer], :void
|
27
|
+
attach_function :LLVMAddDemoteMemoryToRegisterPass, [:pointer], :void
|
28
|
+
end
|
29
|
+
|
30
|
+
class PassManager
|
31
|
+
def adce!
|
32
|
+
C.LLVMAddAggressiveDCEPass(self)
|
33
|
+
end
|
34
|
+
|
35
|
+
def simplifycfg!
|
36
|
+
C.LLVMAddCFGSimplificationPass(self)
|
37
|
+
end
|
38
|
+
|
39
|
+
def dse!
|
40
|
+
C.LLVMAddDeadStoreEliminationPass(self)
|
41
|
+
end
|
42
|
+
|
43
|
+
def gvn!
|
44
|
+
C.LLVMAddGVNPass(self)
|
45
|
+
end
|
46
|
+
|
47
|
+
def indvars!
|
48
|
+
C.LLVMAddIndVarSimplifyPass(self)
|
49
|
+
end
|
50
|
+
|
51
|
+
def instcombine!
|
52
|
+
C.LLVMAddInstructionCombiningPass(self)
|
53
|
+
end
|
54
|
+
|
55
|
+
def jump_threading!
|
56
|
+
C.LLVMAddJumpThreadingPass(self)
|
57
|
+
end
|
58
|
+
|
59
|
+
def licm!
|
60
|
+
C.LLVMAddLICMPass(self)
|
61
|
+
end
|
62
|
+
|
63
|
+
def loop_deletion!
|
64
|
+
C.LLVMAddLoopDeletionPass(self)
|
65
|
+
end
|
66
|
+
|
67
|
+
def loop_index_split!
|
68
|
+
C.LLVMAddLoopIndexSplitPass(self)
|
69
|
+
end
|
70
|
+
|
71
|
+
def loop_rotate!
|
72
|
+
C.LLVMAddLoopRotatePass(self)
|
73
|
+
end
|
74
|
+
|
75
|
+
def loop_unroll!
|
76
|
+
C.LLVMAddLoopUnrollPass(self)
|
77
|
+
end
|
78
|
+
|
79
|
+
def loop_unswitch!
|
80
|
+
C.LLVMAddLoopUnswitchPass(self)
|
81
|
+
end
|
82
|
+
|
83
|
+
def memcpyopt!
|
84
|
+
C.LLVMAddMemCpyOptPass(self)
|
85
|
+
end
|
86
|
+
|
87
|
+
def mem2reg!
|
88
|
+
C.LLVMAddPromoteMemoryToRegisterPass(self)
|
89
|
+
end
|
90
|
+
|
91
|
+
def reassociate!
|
92
|
+
C.LLVMAddReassociatePass(self)
|
93
|
+
end
|
94
|
+
|
95
|
+
def sccp!
|
96
|
+
C.LLVMAddSCCPPass(self)
|
97
|
+
end
|
98
|
+
|
99
|
+
def scalarrepl!
|
100
|
+
C.LLVMAddScalarReplAggregatesPass(self)
|
101
|
+
end
|
102
|
+
|
103
|
+
def simplify_libcalls!
|
104
|
+
C.LLVMAddSimplifyLibCallsPass(self)
|
105
|
+
end
|
106
|
+
|
107
|
+
def tailcallelim!
|
108
|
+
C.LLVMAddTailCallEliminationPass(self)
|
109
|
+
end
|
110
|
+
|
111
|
+
def constprop!
|
112
|
+
C.LLVMAddConstantPropagationPass(self)
|
113
|
+
end
|
114
|
+
|
115
|
+
def reg2mem!
|
116
|
+
C.LLVMAddDemoteMemoryToRegisterPass(self)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
metadata
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ruby-llvm
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.7.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jeremy Voorhis
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2010-06-10 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: ffi
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.5.4
|
24
|
+
version:
|
25
|
+
description:
|
26
|
+
email: jvoorhis@gmail.com
|
27
|
+
executables: []
|
28
|
+
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files:
|
32
|
+
- README.rdoc
|
33
|
+
files:
|
34
|
+
- lib/llvm/analysis.rb
|
35
|
+
- lib/llvm/core/builder.rb
|
36
|
+
- lib/llvm/core/context.rb
|
37
|
+
- lib/llvm/core/module.rb
|
38
|
+
- lib/llvm/core/pass_manager.rb
|
39
|
+
- lib/llvm/core/type.rb
|
40
|
+
- lib/llvm/core/value.rb
|
41
|
+
- lib/llvm/core.rb
|
42
|
+
- lib/llvm/execution_engine.rb
|
43
|
+
- lib/llvm/target.rb
|
44
|
+
- lib/llvm/transforms/scalar.rb
|
45
|
+
- lib/llvm.rb
|
46
|
+
- README.rdoc
|
47
|
+
has_rdoc: true
|
48
|
+
homepage: http://github.com/jvoorhis/ruby-llvm
|
49
|
+
post_install_message:
|
50
|
+
rdoc_options: []
|
51
|
+
|
52
|
+
require_paths:
|
53
|
+
- lib
|
54
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: "0"
|
59
|
+
version:
|
60
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: "0"
|
65
|
+
version:
|
66
|
+
requirements: []
|
67
|
+
|
68
|
+
rubyforge_project:
|
69
|
+
rubygems_version: 1.3.1
|
70
|
+
signing_key:
|
71
|
+
specification_version: 2
|
72
|
+
summary: LLVM bindings for Ruby
|
73
|
+
test_files: []
|
74
|
+
|