ruby-llvm 2.9.3 → 3.0.0.beta

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.rdoc CHANGED
@@ -20,7 +20,7 @@ ruby-llvm has been tested on Mac OS X 10.6 using the following Ruby interpreters
20
20
  If using MRI, ffi >= 1.0.7 is recommended (only ffi >= 1.0.0 is required).
21
21
 
22
22
  == Requirements
23
- * LLVM 2.9, including libLLVM-2.9 (compile LLVM with --enable-shared).
23
+ * LLVM 3.0, including libLLVM-3.0 (compile LLVM with --enable-shared).
24
24
  * In order to ensure the usability of JIT features (i.e. create_jit_compiler), compile LLVM with --enable-jit as well.
25
25
 
26
26
  == About version numbers
@@ -3,7 +3,7 @@ require 'ffi'
3
3
 
4
4
  CC = "g++"
5
5
  LLVM_CONFIG = `llvm-config --cxxflags --ldflags --libs all`.gsub("\n"," ")
6
- OUTPUT = FFI.map_library_name "RubyLLVMSupport-2.9.2"
6
+ OUTPUT = FFI.map_library_name "RubyLLVMSupport-3.0.0"
7
7
  OUTPUT_DIR = "../../lib"
8
8
  SRC = "support.cpp"
9
9
  CLOBBER.include(OUTPUT)
@@ -2,6 +2,7 @@
2
2
  * Extended bindings for LLVM.
3
3
  */
4
4
 
5
+ #include <llvm/ADT/StringRef.h>
5
6
  #include <llvm/Support/DynamicLibrary.h>
6
7
 
7
8
  extern "C" {
data/lib/llvm.rb CHANGED
@@ -7,6 +7,6 @@ module LLVM
7
7
  # @private
8
8
  module C
9
9
  extend ::FFI::Library
10
- ffi_lib ['LLVM-2.9']
10
+ ffi_lib ['LLVM-3.0']
11
11
  end
12
12
  end
data/lib/llvm/core.rb CHANGED
@@ -20,10 +20,16 @@ module LLVM
20
20
  :optimize_for_size, 1 << 13,
21
21
  :stack_protect, 1 << 14,
22
22
  :stack_protect_req, 1 << 15,
23
+ :alignment, 31 << 16,
23
24
  :no_capture, 1 << 21,
24
25
  :no_red_zone, 1 << 22,
25
26
  :no_implicit_float, 1 << 23,
26
- :naked, 1 << 24
27
+ :naked, 1 << 24,
28
+ :inline_hint, 1 << 25,
29
+ :stack_alignment, 7 << 26,
30
+ :returns_twice, 1 << 29,
31
+ :uw_table, 1 << 30,
32
+ :non_lazy_bind, 1 << 31
27
33
  ]
28
34
 
29
35
  enum :opcode, [
@@ -33,7 +39,7 @@ module LLVM
33
39
  :switch, 3,
34
40
  :indirectbr, 4,
35
41
  :invoke, 5,
36
- :unwind, 6,
42
+ # removed 6 due to API changes
37
43
  :unreachable, 7,
38
44
 
39
45
  # Standard Binary Operators
@@ -84,15 +90,24 @@ module LLVM
84
90
  :phi, 44,
85
91
  :call, 45,
86
92
  :select, 46,
87
-
88
- # UserOp1
89
- # UserOp2
93
+ :user_op_1, 47,
94
+ :user_op_2, 48,
90
95
  :vaarg, 49,
91
96
  :extractelement, 50,
92
97
  :insertelement, 51,
93
98
  :shufflevector, 52,
94
99
  :extractvalue, 53,
95
100
  :insertvalue, 54,
101
+
102
+ # Atomic Operators
103
+ :fence, 55,
104
+ :atomic_cmp_xchg, 56,
105
+ :atomic_rmw, 57,
106
+
107
+ # Exception Handling Operators
108
+ :resume, 58,
109
+ :landing_pad, 59,
110
+ :unwind, 60
96
111
  ]
97
112
 
98
113
  enum :type_kind, [
@@ -108,9 +123,9 @@ module LLVM
108
123
  :struct,
109
124
  :array,
110
125
  :pointer,
111
- :opaque,
112
126
  :vector,
113
- :metadata
127
+ :metadata,
128
+ :x86_mmx
114
129
  ]
115
130
 
116
131
  enum :linkage, [
@@ -177,6 +192,11 @@ module LLVM
177
192
  :true
178
193
  ]
179
194
 
195
+ enum :landing_pad_clause_type, [
196
+ :catch,
197
+ :filter
198
+ ]
199
+
180
200
  # Error handling
181
201
  attach_function :LLVMDisposeMessage, [:pointer], :void
182
202
 
@@ -193,13 +213,12 @@ module LLVM
193
213
  attach_function :LLVMSetDataLayout, [:pointer, :string], :void
194
214
  attach_function :LLVMGetTarget, [:pointer], :string
195
215
  attach_function :LLVMSetTarget, [:pointer, :string], :void
196
- attach_function :LLVMAddTypeName, [:pointer, :string, :pointer], :int
197
- attach_function :LLVMDeleteTypeName, [:pointer, :string], :void
198
216
  attach_function :LLVMGetTypeByName, [:pointer, :string], :pointer
199
217
  attach_function :LLVMDumpModule, [:pointer], :void
200
218
 
201
219
  # Types
202
220
  attach_function :LLVMGetTypeKind, [:pointer], :type_kind
221
+ attach_function :LLVMTypeIsSized, [:pointer], :int
203
222
  attach_function :LLVMGetTypeContext, [:pointer], :pointer
204
223
 
205
224
  # Integer types
@@ -241,9 +260,14 @@ module LLVM
241
260
  # Struct types
242
261
  attach_function :LLVMStructTypeInContext, [:pointer, :pointer, :uint, :int], :pointer
243
262
  attach_function :LLVMStructType, [:pointer, :uint, :int], :pointer
263
+ attach_function :LLVMStructCreateNamed, [:pointer, :string], :pointer
264
+ attach_function :LLVMGetStructName, [:pointer], :string
265
+ attach_function :LLVMStructSetBody, [:pointer, :pointer, :uint, :int], :void
244
266
  attach_function :LLVMCountStructElementTypes, [:pointer], :uint
245
267
  attach_function :LLVMGetStructElementTypes, [:pointer, :pointer], :void
246
268
  attach_function :LLVMIsPackedStruct, [:pointer], :int
269
+ attach_function :LLVMIsOpaqueStruct, [:pointer], :int
270
+ attach_function :LLVMGetTypeByName, [:pointer, :string], :pointer
247
271
 
248
272
  # Array, pointer and vector types (sequence types)
249
273
  attach_function :LLVMArrayType, [:pointer, :uint], :pointer
@@ -258,17 +282,9 @@ module LLVM
258
282
  # All other types
259
283
  attach_function :LLVMVoidTypeInContext, [:pointer], :pointer
260
284
  attach_function :LLVMLabelTypeInContext, [:pointer], :pointer
261
- attach_function :LLVMOpaqueTypeInContext, [:pointer], :pointer
262
285
 
263
286
  attach_function :LLVMVoidType, [], :pointer
264
287
  attach_function :LLVMLabelType, [], :pointer
265
- attach_function :LLVMOpaqueType, [], :pointer
266
-
267
- # Type handles
268
- attach_function :LLVMCreateTypeHandle, [:pointer], :pointer
269
- attach_function :LLVMRefineType, [:pointer, :pointer], :void
270
- attach_function :LLVMResolveTypeHandle, [:pointer], :pointer
271
- attach_function :LLVMDisposeTypeHandle, [:pointer], :void
272
288
 
273
289
  # All values
274
290
  attach_function :LLVMTypeOf, [:pointer], :pointer
@@ -485,7 +501,6 @@ module LLVM
485
501
  attach_function :LLVMBuildCondBr, [:pointer, :pointer, :pointer, :pointer], :pointer
486
502
  attach_function :LLVMBuildSwitch, [:pointer, :pointer, :pointer, :uint], :pointer
487
503
  attach_function :LLVMBuildInvoke, [:pointer, :pointer, :pointer, :uint, :pointer, :pointer, :string], :pointer
488
- attach_function :LLVMBuildUnwind, [:pointer], :pointer
489
504
  attach_function :LLVMBuildUnreachable, [:pointer], :pointer
490
505
 
491
506
  # Switch instruction
@@ -117,13 +117,6 @@ module LLVM
117
117
  fun, args, args.size, normal, exception, name))
118
118
  end
119
119
 
120
- # Builds an unwind Instruction.
121
- # @return [LLVM::Instruction]
122
- # @LLVMinst unwind
123
- def unwind
124
- Instruction.from_ptr(C.LLVMBuildUnwind(self))
125
- end
126
-
127
120
  # Generates an instruction with no defined semantics. Can be used to
128
121
  # provide hints to the optimizer.
129
122
  # @return [LLVM::Instruction]
@@ -1,7 +1,7 @@
1
1
  module LLVM
2
2
  class Context
3
- def initialize
4
- @ptr = C.LLVMContextCreate()
3
+ def initialize(ptr = nil)
4
+ @ptr = ptr || C.LLVMContextCreate()
5
5
  end
6
6
 
7
7
  # @private
@@ -42,11 +42,6 @@ module LLVM
42
42
  @module = mod
43
43
  end
44
44
 
45
- # Adds the given Type to the collection with the given name (symbol or string).
46
- def add(name, type)
47
- C.LLVMAddTypeName(@module, name.to_s, type)
48
- end
49
-
50
45
  # Returns the Type with the given name (symbol or string).
51
46
  def named(name)
52
47
  Type.from_ptr(C.LLVMGetTypeByName(@module, name.to_s))
@@ -149,7 +144,7 @@ module LLVM
149
144
 
150
145
  # Adds a Function with the given name (symbol or string) and args (Types).
151
146
  def add(name, *args)
152
- if args.first.kind_of? Type
147
+ if args.first.kind_of? FunctionType
153
148
  type = args.first
154
149
  else
155
150
  type = Type.function(*args)
@@ -57,6 +57,11 @@ module LLVM
57
57
  Type.pointer(self, address_space)
58
58
  end
59
59
 
60
+ # Returns the name of the struct type.
61
+ def name
62
+ C.LLVMGetStructName(self)
63
+ end
64
+
60
65
  # @private
61
66
  def self.from_ptr(ptr)
62
67
  return if ptr.null?
@@ -90,11 +95,17 @@ module LLVM
90
95
  end
91
96
 
92
97
  # Creates a struct type with the given array of element types.
93
- def self.struct(elt_types, is_packed)
98
+ def self.struct(elt_types, is_packed, name = nil)
94
99
  elt_types.map! { |ty| LLVM::Type(ty) }
95
100
  elt_types_ptr = FFI::MemoryPointer.new(FFI.type_size(:pointer) * elt_types.size)
96
101
  elt_types_ptr.write_array_of_pointer(elt_types)
97
- from_ptr(C.LLVMStructType(elt_types_ptr, elt_types.size, is_packed ? 1 : 0))
102
+ if name
103
+ struct = from_ptr(C.LLVMStructCreateNamed(Context.global, name))
104
+ C.LLVMStructSetBody(struct, elt_types_ptr, elt_types.size, is_packed ? 1 : 0)
105
+ struct
106
+ else
107
+ from_ptr(C.LLVMStructType(elt_types_ptr, elt_types.size, is_packed ? 1 : 0))
108
+ end
98
109
  end
99
110
 
100
111
  # Creates a void type.
@@ -102,21 +113,12 @@ module LLVM
102
113
  from_ptr(C.LLVMVoidType)
103
114
  end
104
115
 
105
- # Creates an opaque type.
106
- def self.opaque
107
- from_ptr(C.LLVMOpaqueType)
108
- end
109
-
110
116
  def self.rec
111
117
  h = opaque
112
118
  ty = yield h
113
119
  h.refine(ty)
114
120
  ty
115
121
  end
116
-
117
- def refine(ty)
118
- C.LLVMRefineType(self, ty)
119
- end
120
122
  end
121
123
 
122
124
  class IntType < Type
@@ -163,7 +165,12 @@ module LLVM
163
165
 
164
166
  # Shortcut to Type.struct.
165
167
  def Struct(*elt_types)
166
- LLVM::Type.struct(elt_types, false)
168
+ name = if elt_types.last.is_a? String
169
+ elt_types.pop
170
+ else
171
+ nil
172
+ end
173
+ LLVM::Type.struct(elt_types, false, name)
167
174
  end
168
175
 
169
176
  # Shortcut to Type.void.
@@ -45,11 +45,14 @@ module LLVM
45
45
  attach_function :LLVMInitializeX86TargetInfo, [], :void
46
46
 
47
47
  attach_function :LLVMInitializeX86Target, [], :void
48
+
49
+ attach_function :LLVMInitializeX86TargetMC, [], :void
48
50
  end
49
51
 
50
52
  def LLVM.init_x86
51
53
  LLVM::C.LLVMInitializeX86Target
52
54
  LLVM::C.LLVMInitializeX86TargetInfo
55
+ LLVM::C.LLVMInitializeX86TargetMC
53
56
  end
54
57
 
55
58
  class JITCompiler
data/lib/llvm/support.rb CHANGED
@@ -7,7 +7,7 @@ module LLVM
7
7
  File.join(
8
8
  File.dirname(__FILE__),
9
9
  '../',
10
- FFI.map_library_name('RubyLLVMSupport-2.9.2')))
10
+ FFI.map_library_name('RubyLLVMSupport-3.0.0')))
11
11
  ffi_lib [support_lib]
12
12
  attach_function :LLVMLoadLibraryPermanently, [:string], :int
13
13
  end
data/lib/llvm/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module LLVM
2
- LLVM_VERSION = "2.9"
3
- RUBY_LLVM_VERSION = "2.9.3"
2
+ LLVM_VERSION = "3.0"
3
+ RUBY_LLVM_VERSION = "3.0.0.beta"
4
4
  end
@@ -74,9 +74,9 @@ class EqualityTestCase < Test::Unit::TestCase
74
74
  def test_function
75
75
  mod = LLVM::Module.new('test')
76
76
 
77
- fn1 = mod.functions.add('test1', LLVM.Void)
77
+ fn1 = mod.functions.add('test1', [], LLVM.Void)
78
78
  fn2 = LLVM::Function.from_ptr(fn1.to_ptr)
79
- fn3 = mod.functions.add('test2', LLVM.Void)
79
+ fn3 = mod.functions.add('test2', [], LLVM.Void)
80
80
  fn4 = MyFunction.from_ptr(fn1.to_ptr)
81
81
 
82
82
  assert_equalities :equal => [fn1, fn2, fn4],
data/test/struct_test.rb CHANGED
@@ -13,6 +13,12 @@ class StructTestCase < Test::Unit::TestCase
13
13
  struct = LLVM::Struct(LLVM::Int, LLVM::Float)
14
14
  assert_instance_of LLVM::Type, struct
15
15
  end
16
+
17
+ def test_named_struct
18
+ struct = LLVM::Struct(LLVM::Int, LLVM::Float, "struct100")
19
+ assert_instance_of LLVM::Type, struct
20
+ assert_equal "struct100", struct.name
21
+ end
16
22
 
17
23
  def test_unpacked_constant_struct_from_size
18
24
  struct = LLVM::ConstantStruct.const(2, LLVM_UNPACKED) { |i| LLVM::Int(i) }
metadata CHANGED
@@ -1,19 +1,19 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-llvm
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.9.3
5
- prerelease:
4
+ version: 3.0.0.beta
5
+ prerelease: 6
6
6
  platform: ruby
7
7
  authors:
8
8
  - Jeremy Voorhis
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-12-21 00:00:00.000000000 Z
12
+ date: 2012-02-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ffi
16
- requirement: &70109058811900 !ruby/object:Gem::Requirement
16
+ requirement: &70123470125560 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 1.0.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70109058811900
24
+ version_requirements: *70123470125560
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rake
27
- requirement: &70109058811480 !ruby/object:Gem::Requirement
27
+ requirement: &70123470125140 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70109058811480
35
+ version_requirements: *70123470125140
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rcov
38
- requirement: &70109058811000 !ruby/object:Gem::Requirement
38
+ requirement: &70123470124680 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70109058811000
46
+ version_requirements: *70123470124680
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: yard
49
- requirement: &70109058810580 !ruby/object:Gem::Requirement
49
+ requirement: &70123470124260 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70109058810580
57
+ version_requirements: *70123470124260
58
58
  description: LLVM bindings for Ruby
59
59
  email: jvoorhis@gmail.com
60
60
  executables: []
@@ -120,12 +120,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
120
120
  required_rubygems_version: !ruby/object:Gem::Requirement
121
121
  none: false
122
122
  requirements:
123
- - - ! '>='
123
+ - - ! '>'
124
124
  - !ruby/object:Gem::Version
125
- version: '0'
125
+ version: 1.3.1
126
126
  requirements: []
127
127
  rubyforge_project:
128
- rubygems_version: 1.8.10
128
+ rubygems_version: 1.8.11
129
129
  signing_key:
130
130
  specification_version: 3
131
131
  summary: LLVM bindings for Ruby