rltk 3.0.0 → 3.0.1
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.
- checksums.yaml +4 -4
- data/Rakefile +21 -22
- data/lib/rltk/ast.rb +185 -118
- data/lib/rltk/cfg.rb +157 -103
- data/lib/rltk/cg/basic_block.rb +19 -19
- data/lib/rltk/cg/bindings.rb +16 -16
- data/lib/rltk/cg/builder.rb +129 -129
- data/lib/rltk/cg/context.rb +7 -7
- data/lib/rltk/cg/contractor.rb +7 -7
- data/lib/rltk/cg/execution_engine.rb +30 -30
- data/lib/rltk/cg/function.rb +37 -37
- data/lib/rltk/cg/generated_bindings.rb +3932 -3932
- data/lib/rltk/cg/generic_value.rb +17 -17
- data/lib/rltk/cg/instruction.rb +116 -116
- data/lib/rltk/cg/llvm.rb +22 -22
- data/lib/rltk/cg/memory_buffer.rb +7 -7
- data/lib/rltk/cg/module.rb +73 -73
- data/lib/rltk/cg/pass_manager.rb +35 -35
- data/lib/rltk/cg/target.rb +41 -41
- data/lib/rltk/cg/triple.rb +7 -7
- data/lib/rltk/cg/type.rb +75 -75
- data/lib/rltk/cg/value.rb +161 -161
- data/lib/rltk/lexer.rb +57 -57
- data/lib/rltk/lexers/calculator.rb +7 -7
- data/lib/rltk/lexers/ebnf.rb +5 -5
- data/lib/rltk/parser.rb +338 -295
- data/lib/rltk/parsers/infix_calc.rb +7 -7
- data/lib/rltk/parsers/postfix_calc.rb +3 -3
- data/lib/rltk/parsers/prefix_calc.rb +3 -3
- data/lib/rltk/token.rb +13 -13
- data/lib/rltk/version.rb +6 -6
- data/test/cg/tc_basic_block.rb +17 -17
- data/test/cg/tc_control_flow.rb +41 -41
- data/test/cg/tc_function.rb +4 -4
- data/test/cg/tc_generic_value.rb +3 -3
- data/test/cg/tc_instruction.rb +53 -53
- data/test/cg/tc_math.rb +12 -12
- data/test/cg/tc_module.rb +14 -14
- data/test/cg/tc_transforms.rb +11 -11
- data/test/cg/tc_type.rb +12 -12
- data/test/cg/tc_value.rb +35 -35
- data/test/cg/ts_cg.rb +5 -5
- data/test/tc_ast.rb +137 -60
- data/test/tc_cfg.rb +34 -34
- data/test/tc_lexer.rb +42 -42
- data/test/tc_parser.rb +250 -173
- data/test/tc_token.rb +2 -2
- data/test/ts_rltk.rb +8 -8
- metadata +84 -85
- data/lib/rltk/cg/old_generated_bindings.rb +0 -6152
data/lib/rltk/cg/value.rb
CHANGED
@@ -19,12 +19,12 @@ require 'rltk/cg/type'
|
|
19
19
|
#######################
|
20
20
|
|
21
21
|
module RLTK::CG
|
22
|
-
|
22
|
+
|
23
23
|
# This class represents LLVM IR "data", including integer and float
|
24
24
|
# literals, functions, and constant arrays, structs, and vectors.
|
25
25
|
class Value
|
26
26
|
include BindingClass
|
27
|
-
|
27
|
+
|
28
28
|
# Instantiate a Value object from a pointer. This should never be
|
29
29
|
# done by library users, and is only used internally.
|
30
30
|
#
|
@@ -32,7 +32,7 @@ module RLTK::CG
|
|
32
32
|
def initialize(ptr)
|
33
33
|
@ptr = check_type(ptr, FFI::Pointer, 'ptr')
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
36
|
# Compare one Value to another.
|
37
37
|
#
|
38
38
|
# @param [Value] other Another value object.
|
@@ -41,13 +41,13 @@ module RLTK::CG
|
|
41
41
|
def ==(other)
|
42
42
|
other.is_a?(Value) and @ptr == other.ptr
|
43
43
|
end
|
44
|
-
|
44
|
+
|
45
45
|
# @return [AttrCollection] Proxy object for inspecing a value's attributes.
|
46
46
|
def attributes
|
47
47
|
@attributes ||= AttrCollection.new(@ptr)
|
48
48
|
end
|
49
49
|
alias :attrs :attributes
|
50
|
-
|
50
|
+
|
51
51
|
# Bitcast a value to a given type.
|
52
52
|
#
|
53
53
|
# @param [Type] type Type to cast to.
|
@@ -56,12 +56,12 @@ module RLTK::CG
|
|
56
56
|
def bitcast(type)
|
57
57
|
ConstantExpr.new(Bindings.const_bit_cast(@ptr, check_cg_type(type)))
|
58
58
|
end
|
59
|
-
|
59
|
+
|
60
60
|
# @return [Boolean] If this value is a constant.
|
61
61
|
def constant?
|
62
62
|
Bindings.is_constant(@ptr).to_bool
|
63
63
|
end
|
64
|
-
|
64
|
+
|
65
65
|
# Print the LLVM IR representation of this value to standard error.
|
66
66
|
# This function is the debugging version of the more general purpose
|
67
67
|
# {#print} method.
|
@@ -72,17 +72,17 @@ module RLTK::CG
|
|
72
72
|
def dump
|
73
73
|
Bindings.dump_value(@ptr)
|
74
74
|
end
|
75
|
-
|
75
|
+
|
76
76
|
# @return [Fixnum] Hashed value of the pointer representing this value.
|
77
77
|
def hash
|
78
78
|
@ptr.address.hash
|
79
79
|
end
|
80
|
-
|
80
|
+
|
81
81
|
# @return [String] Name of this value in LLVM IR.
|
82
82
|
def name
|
83
83
|
Bindings.get_value_name(@ptr)
|
84
84
|
end
|
85
|
-
|
85
|
+
|
86
86
|
# Set the name of this value in LLVM IR.
|
87
87
|
#
|
88
88
|
# @param [String] str Name of the value in LLVM IR.
|
@@ -91,17 +91,17 @@ module RLTK::CG
|
|
91
91
|
def name=(str)
|
92
92
|
str.tap { Bindings.set_value_name(@ptr, check_type(str, String)) }
|
93
93
|
end
|
94
|
-
|
94
|
+
|
95
95
|
# @return [Boolean] If the value is null or not.
|
96
96
|
def null?
|
97
97
|
Bindings.is_null(@ptr).to_bool
|
98
98
|
end
|
99
|
-
|
99
|
+
|
100
100
|
# @return [String] LLVM IR representation of this value
|
101
101
|
def print
|
102
102
|
Bindings.print_value_to_string(@ptr)
|
103
103
|
end
|
104
|
-
|
104
|
+
|
105
105
|
# Truncate a value to a given type.
|
106
106
|
#
|
107
107
|
# @param [Type] type Type to truncate to.
|
@@ -110,7 +110,7 @@ module RLTK::CG
|
|
110
110
|
def trunc(type)
|
111
111
|
ConstantExpr.new(Bindings.const_trunc(check_cg_type(type)))
|
112
112
|
end
|
113
|
-
|
113
|
+
|
114
114
|
# Truncate or bitcast a value to the given type as is appropriate.
|
115
115
|
#
|
116
116
|
# @param [Type] type Type to cast or truncate to.
|
@@ -119,17 +119,17 @@ module RLTK::CG
|
|
119
119
|
def trunc_or_bitcast(type)
|
120
120
|
ConstantExpr.new(Bindings.const_trunc_or_bit_cast(check_cg_type(type)))
|
121
121
|
end
|
122
|
-
|
122
|
+
|
123
123
|
# @return [Type] Type of this value.
|
124
124
|
def type
|
125
125
|
@type ||= Type.from_ptr(Bindings.type_of(@ptr))
|
126
126
|
end
|
127
|
-
|
127
|
+
|
128
128
|
# @return [Boolean] If the value is undefined or not.
|
129
129
|
def undefined?
|
130
130
|
Bindings.is_undef(@ptr).to_bool
|
131
131
|
end
|
132
|
-
|
132
|
+
|
133
133
|
# Zero extend the value to the length of *type*.
|
134
134
|
#
|
135
135
|
# @param [Type] type Type to extend the value to.
|
@@ -138,7 +138,7 @@ module RLTK::CG
|
|
138
138
|
def zextend(type)
|
139
139
|
ConstantExpr.new(Bindings.const_z_ext(check_cg_type(type)))
|
140
140
|
end
|
141
|
-
|
141
|
+
|
142
142
|
# Zero extend or bitcast the value to the given type as is appropriate.
|
143
143
|
#
|
144
144
|
# @param [Type] type Type to cast or extend to.
|
@@ -147,18 +147,18 @@ module RLTK::CG
|
|
147
147
|
def zextend_or_bitcast(type)
|
148
148
|
ConstantExpr.new(Bindings.const_z_ext_or_bit_cast(check_cg_type(type)))
|
149
149
|
end
|
150
|
-
|
150
|
+
|
151
151
|
# This class is used to access a {Value Value's} attributes.
|
152
152
|
class AttrCollection
|
153
153
|
@@add_method = :add_attribute
|
154
154
|
@@del_method = :remove_attribute
|
155
|
-
|
155
|
+
|
156
156
|
# @param [Value] value Value for which this is a proxy.
|
157
157
|
def initialize(value)
|
158
158
|
@attributes = Array.new
|
159
159
|
@value = value
|
160
160
|
end
|
161
|
-
|
161
|
+
|
162
162
|
# Add the given attribute to a value.
|
163
163
|
#
|
164
164
|
# @see Bindings._enum_attribute_
|
@@ -173,7 +173,7 @@ module RLTK::CG
|
|
173
173
|
end
|
174
174
|
end
|
175
175
|
alias :'<<' :add
|
176
|
-
|
176
|
+
|
177
177
|
# Test to see if an attribute has been set on a value.
|
178
178
|
#
|
179
179
|
# @see Bindings._enum_attribute_
|
@@ -184,7 +184,7 @@ module RLTK::CG
|
|
184
184
|
def include?(attribute)
|
185
185
|
@attributes.include?(attribute)
|
186
186
|
end
|
187
|
-
|
187
|
+
|
188
188
|
# Remove the given attribute from a value.
|
189
189
|
#
|
190
190
|
# @see Bindings._enum_attribute_
|
@@ -199,37 +199,37 @@ module RLTK::CG
|
|
199
199
|
end
|
200
200
|
end
|
201
201
|
alias :'>>' :remove
|
202
|
-
|
202
|
+
|
203
203
|
# @return [String] Textual representation of the enabled attributes.
|
204
204
|
def to_s
|
205
205
|
@attributes.to_s
|
206
206
|
end
|
207
207
|
end
|
208
208
|
end
|
209
|
-
|
209
|
+
|
210
210
|
# An empty class definition for completeness and future use.
|
211
211
|
class Argument < Value; end
|
212
|
-
|
212
|
+
|
213
213
|
# A base class for a wide variety of classes.
|
214
214
|
#
|
215
215
|
# @abstract
|
216
216
|
class User < Value
|
217
217
|
include Filigree::AbstractClass
|
218
|
-
|
218
|
+
|
219
219
|
# @return [OperandCollection] Proxy object for accessing a value's operands.
|
220
220
|
def operands
|
221
221
|
@operands ||= OperandCollection.new(self)
|
222
222
|
end
|
223
|
-
|
223
|
+
|
224
224
|
# This class is used to access a {User User's} operands.
|
225
225
|
class OperandCollection
|
226
226
|
include Enumerable
|
227
|
-
|
227
|
+
|
228
228
|
# @param [User] user User object for which this is a proxy.
|
229
229
|
def initialize(user)
|
230
230
|
@user = user
|
231
231
|
end
|
232
|
-
|
232
|
+
|
233
233
|
# Access the operand at the given index.
|
234
234
|
#
|
235
235
|
# @param [Integer] index
|
@@ -238,7 +238,7 @@ module RLTK::CG
|
|
238
238
|
def [](index)
|
239
239
|
if (ptr = Bindings.get_operand(@user, index)).null? then nil else Value.new(ptr) end
|
240
240
|
end
|
241
|
-
|
241
|
+
|
242
242
|
# Set the operand at the given index.
|
243
243
|
#
|
244
244
|
# @param [Integer] index Index of operand to set.
|
@@ -248,7 +248,7 @@ module RLTK::CG
|
|
248
248
|
def []=(index, value)
|
249
249
|
Bindings.set_operand(@user, index, check_type(value, Value, 'value'))
|
250
250
|
end
|
251
|
-
|
251
|
+
|
252
252
|
# An iterator for each operand inside this collection.
|
253
253
|
#
|
254
254
|
# @yieldparam val [Value]
|
@@ -256,25 +256,25 @@ module RLTK::CG
|
|
256
256
|
# @return [Enumerator] Returns an Enumerator if no block is given.
|
257
257
|
def each
|
258
258
|
return to_enum(:each) unless block_given?
|
259
|
-
|
259
|
+
|
260
260
|
self.size.times { |i| yield self[i] }
|
261
|
-
|
261
|
+
|
262
262
|
self
|
263
263
|
end
|
264
|
-
|
264
|
+
|
265
265
|
# @return [Integer] Number of operands.
|
266
266
|
def size
|
267
267
|
Bindings.get_num_operands(@user)
|
268
268
|
end
|
269
269
|
end
|
270
270
|
end
|
271
|
-
|
271
|
+
|
272
272
|
# All classes representing constant values inherit from this class.
|
273
273
|
#
|
274
274
|
# @abstract
|
275
275
|
class Constant < User
|
276
276
|
include Filigree::AbstractClass
|
277
|
-
|
277
|
+
|
278
278
|
# Create a new constant from a pointer or a type. As a library user
|
279
279
|
# you should never pass a pointer in here as that is only used
|
280
280
|
# internally.
|
@@ -285,14 +285,14 @@ module RLTK::CG
|
|
285
285
|
case overloaded
|
286
286
|
when FFI::Pointer
|
287
287
|
overloaded
|
288
|
-
|
288
|
+
|
289
289
|
when Type
|
290
290
|
Bindings.send(@@initializer, @type = overloaded)
|
291
291
|
else
|
292
292
|
raise 'New must be passed either a Type or a FFI::Pointer.'
|
293
293
|
end
|
294
294
|
end
|
295
|
-
|
295
|
+
|
296
296
|
# Cast a constant to a given address space
|
297
297
|
#
|
298
298
|
# @param [Type] type Type to cast to
|
@@ -301,7 +301,7 @@ module RLTK::CG
|
|
301
301
|
def addr_space_cast(type)
|
302
302
|
ConstantExpr.new(Bindings.const_addr_space_cast(@ptr, check_cg_type(type)))
|
303
303
|
end
|
304
|
-
|
304
|
+
|
305
305
|
# Bitcast a constant to a given type.
|
306
306
|
#
|
307
307
|
# @param [Type] type Type to cast to
|
@@ -310,7 +310,7 @@ module RLTK::CG
|
|
310
310
|
def bitcast_to(type)
|
311
311
|
ConstantExpr.new(Bindings.const_bit_cast(@ptr, check_cg_type(type)))
|
312
312
|
end
|
313
|
-
|
313
|
+
|
314
314
|
# Get a pointer to an element of a constant value.
|
315
315
|
#
|
316
316
|
# @param [Array<Value>] indices A Ruby array of Value objects representing indicies into the constant value.
|
@@ -319,11 +319,11 @@ module RLTK::CG
|
|
319
319
|
def get_element_ptr(*indices)
|
320
320
|
indicies_ptr = FFI::MemoryPointer.new(:pointer, indices.length)
|
321
321
|
indices_ptr.write_array_of_pointer(indices)
|
322
|
-
|
322
|
+
|
323
323
|
ConstantExpr.new(Bindings.const_gep(@ptr, indices_ptr, indices.length))
|
324
324
|
end
|
325
325
|
alias :gep :get_element_ptr
|
326
|
-
|
326
|
+
|
327
327
|
# Get a pointer to an element of a constant value, ensuring that the
|
328
328
|
# pointer is within the bounds of the value.
|
329
329
|
#
|
@@ -333,12 +333,12 @@ module RLTK::CG
|
|
333
333
|
def get_element_ptr_in_bounds(*indices)
|
334
334
|
indices_ptr = FFI::MemoryPointer.new(:pointer, indices.length)
|
335
335
|
indices_ptr.write_array_of_pointer(indices)
|
336
|
-
|
336
|
+
|
337
337
|
ConstantExpr.new(Bindings.const_in_bounds_gep(@ptr, indices_ptr, indices.length))
|
338
338
|
end
|
339
339
|
alias :inbounds_gep :get_element_ptr_in_bounds
|
340
340
|
end
|
341
|
-
|
341
|
+
|
342
342
|
# This class represents a wide range of values returned by various
|
343
343
|
# operations.
|
344
344
|
class ConstantExpr < Constant
|
@@ -350,28 +350,28 @@ module RLTK::CG
|
|
350
350
|
@ptr = check_type(ptr, FFI::Pointer, 'ptr')
|
351
351
|
end
|
352
352
|
end
|
353
|
-
|
353
|
+
|
354
354
|
# A constant null value.
|
355
355
|
class ConstantNull < Constant
|
356
356
|
@@initializer = :const_null
|
357
357
|
end
|
358
|
-
|
358
|
+
|
359
359
|
# A constant null pointer value.
|
360
360
|
class ConstantNullPtr < Constant
|
361
361
|
@@initializer = :const_pointer_null
|
362
362
|
end
|
363
|
-
|
363
|
+
|
364
364
|
# A constant undefined value.
|
365
365
|
class ConstantUndef < Constant
|
366
366
|
@@initializer = :get_undef
|
367
367
|
end
|
368
|
-
|
368
|
+
|
369
369
|
# All constant aggregate values inherit from this class.
|
370
370
|
#
|
371
371
|
# @abstract
|
372
372
|
class ConstantAggregate < Constant
|
373
373
|
include Filigree::AbstractClass
|
374
|
-
|
374
|
+
|
375
375
|
# Extract values from a constant aggregate value.
|
376
376
|
#
|
377
377
|
# @param [Array<Value>] indices Array of values representing indices into the aggregate.
|
@@ -380,10 +380,10 @@ module RLTK::CG
|
|
380
380
|
def extract(*indices)
|
381
381
|
indices_ptr = FFI::MemoryPointer.new(:uint, indices.length)
|
382
382
|
indices_ptr.write_array_of_uint(indices)
|
383
|
-
|
383
|
+
|
384
384
|
ConstantExpr.new(Bindings.const_extract_value(@ptr, indices_ptr, indices.length))
|
385
385
|
end
|
386
|
-
|
386
|
+
|
387
387
|
# Insert values into a constant aggregate value.
|
388
388
|
#
|
389
389
|
# @param [Value] value Value to insert.
|
@@ -393,11 +393,11 @@ module RLTK::CG
|
|
393
393
|
def insert(value, indices)
|
394
394
|
indices_ptr = FFI::MemoryPointer.new(:uint, indices.length)
|
395
395
|
indices_ptr.write_array_of_uint(indices)
|
396
|
-
|
396
|
+
|
397
397
|
ConstantExpr.new(Bindings.const_insert_value(@ptr, value, indices_ptr, inicies.length))
|
398
398
|
end
|
399
399
|
end
|
400
|
-
|
400
|
+
|
401
401
|
# A constant array value.
|
402
402
|
class ConstantArray < ConstantAggregate
|
403
403
|
# Create a new constant array value.
|
@@ -418,13 +418,13 @@ module RLTK::CG
|
|
418
418
|
element_type = check_cg_type(element_type, Type, 'element_type')
|
419
419
|
@ptr = Bindings.const_array(element_type, vals_ptr, vals_ptr.size / vals_ptr.type_size)
|
420
420
|
end
|
421
|
-
|
421
|
+
|
422
422
|
def size
|
423
423
|
self.type.size
|
424
424
|
end
|
425
425
|
alias :length :size
|
426
426
|
end
|
427
|
-
|
427
|
+
|
428
428
|
# A sub-class of {ConstantArray} specifically for holding strings.
|
429
429
|
class ConstantString < ConstantArray
|
430
430
|
# Create a new constant string value.
|
@@ -434,7 +434,7 @@ module RLTK::CG
|
|
434
434
|
# @param [Context, nil] context Context in which to create the value.
|
435
435
|
def initialize(string, null_terminate = true, context = nil)
|
436
436
|
@type = ArrayType.new(Int8Type)
|
437
|
-
|
437
|
+
|
438
438
|
@ptr =
|
439
439
|
if context
|
440
440
|
Bindings.const_string_in_context(check_type(context, Context, 'context'), string, string.length, null_terminate.to_i)
|
@@ -443,7 +443,7 @@ module RLTK::CG
|
|
443
443
|
end
|
444
444
|
end
|
445
445
|
end
|
446
|
-
|
446
|
+
|
447
447
|
# A constant struct value.
|
448
448
|
class ConstantStruct < ConstantAggregate
|
449
449
|
# Create a new constant struct value.
|
@@ -462,7 +462,7 @@ module RLTK::CG
|
|
462
462
|
# @param [Proc] block Block evaluated if size is specified.
|
463
463
|
def initialize(size_or_values, packed = false, context = nil, &block)
|
464
464
|
vals_ptr = make_ptr_to_elements(size_or_values, &block)
|
465
|
-
|
465
|
+
|
466
466
|
@ptr =
|
467
467
|
if context
|
468
468
|
Bindings.const_struct_in_context(check_type(context, Context, 'context'),
|
@@ -472,7 +472,7 @@ module RLTK::CG
|
|
472
472
|
end
|
473
473
|
end
|
474
474
|
end
|
475
|
-
|
475
|
+
|
476
476
|
# A constant vector value used for SIMD instructions.
|
477
477
|
class ConstantVector < Constant
|
478
478
|
# Create a new constant vector value.
|
@@ -493,18 +493,18 @@ module RLTK::CG
|
|
493
493
|
size_or_values
|
494
494
|
else
|
495
495
|
vals_ptr = make_ptr_to_elements(size_or_values, &block)
|
496
|
-
|
496
|
+
|
497
497
|
Bindings.const_vector(vals_ptr, vals_ptr.size / vals_ptr.type_size)
|
498
498
|
end
|
499
499
|
end
|
500
|
-
|
500
|
+
|
501
501
|
# @param [Integer] index Index of desired element.
|
502
502
|
#
|
503
503
|
# @return [ConstantExpr] Extracted element.
|
504
504
|
def extract_element(index)
|
505
505
|
ConstantExpr.new(Bindings.const_extract_element(@ptr, index))
|
506
506
|
end
|
507
|
-
|
507
|
+
|
508
508
|
# @param [Value] element Value to insert into the vector.
|
509
509
|
# @param [Integer] index Index to insert the value at.
|
510
510
|
#
|
@@ -512,7 +512,7 @@ module RLTK::CG
|
|
512
512
|
def insert_element(element, index)
|
513
513
|
ConstantExpr.new(Bindings.const_insert_element(@ptr, element, index))
|
514
514
|
end
|
515
|
-
|
515
|
+
|
516
516
|
# @param [ConstantVector] other Other vector to shuffle with this one.
|
517
517
|
# @param [ConstantVector] mask Mask to use when shuffling.
|
518
518
|
#
|
@@ -520,39 +520,39 @@ module RLTK::CG
|
|
520
520
|
def shuffle(other, mask)
|
521
521
|
ConstantVector.new(Bindings.const_shuffle_vector(@ptr, other, mask))
|
522
522
|
end
|
523
|
-
|
523
|
+
|
524
524
|
def size
|
525
525
|
self.type.size
|
526
526
|
end
|
527
527
|
alias :length :size
|
528
528
|
end
|
529
|
-
|
529
|
+
|
530
530
|
# All number constants inherit from this class.
|
531
531
|
#
|
532
532
|
# @abstract
|
533
533
|
class ConstantNumber < Constant
|
534
534
|
include Filigree::AbstractClass
|
535
|
-
|
535
|
+
|
536
536
|
# @return [Type] The corresponding Type sub-class that is used to represent the type of this value.
|
537
537
|
def self.type
|
538
538
|
@type ||= RLTK::CG.const_get(self.short_name + 'Type').instance
|
539
539
|
end
|
540
|
-
|
540
|
+
|
541
541
|
# @return [Type] The corresponding Type sub-class that is used to represent the type of this value.
|
542
542
|
def type
|
543
543
|
self.class.type
|
544
544
|
end
|
545
545
|
end
|
546
|
-
|
546
|
+
|
547
547
|
# All integer constants inherit from this class.
|
548
548
|
#
|
549
549
|
# @abstract
|
550
550
|
class ConstantInteger < ConstantNumber
|
551
551
|
include Filigree::AbstractClass
|
552
|
-
|
552
|
+
|
553
553
|
# @return [Boolean] If the integer is signed or not.
|
554
554
|
attr_reader :signed
|
555
|
-
|
555
|
+
|
556
556
|
# The constructor for ConstantInteger's various sub-classes. This
|
557
557
|
# constructor is a bit complicated due to having two overloaded
|
558
558
|
# parameters, but once you see the valid combinations it is a bit
|
@@ -576,15 +576,15 @@ module RLTK::CG
|
|
576
576
|
case overloaded0
|
577
577
|
when FFI::Pointer
|
578
578
|
overloaded0
|
579
|
-
|
579
|
+
|
580
580
|
when Integer
|
581
581
|
@signed = overloaded1 or true
|
582
|
-
|
582
|
+
|
583
583
|
Bindings.const_int(self.type, overloaded0, @signed.to_i)
|
584
|
-
|
584
|
+
|
585
585
|
when String
|
586
586
|
base = overloaded1 or 10
|
587
|
-
|
587
|
+
|
588
588
|
if size
|
589
589
|
Bindings.const_int_of_string_and_size(self.type, overloaded0, size, base)
|
590
590
|
else
|
@@ -592,17 +592,17 @@ module RLTK::CG
|
|
592
592
|
end
|
593
593
|
else
|
594
594
|
@signed = true
|
595
|
-
|
595
|
+
|
596
596
|
Bindings.const_all_ones(self.type)
|
597
597
|
end
|
598
598
|
end
|
599
|
-
|
599
|
+
|
600
600
|
########
|
601
601
|
# Math #
|
602
602
|
########
|
603
|
-
|
603
|
+
|
604
604
|
# Addition
|
605
|
-
|
605
|
+
|
606
606
|
# Add this value with another value.
|
607
607
|
#
|
608
608
|
# @param [ConstantInteger] rhs
|
@@ -611,7 +611,7 @@ module RLTK::CG
|
|
611
611
|
def +(rhs)
|
612
612
|
self.class.new(Bindings.const_add(@ptr, rhs))
|
613
613
|
end
|
614
|
-
|
614
|
+
|
615
615
|
# Add this value with another value. Performs no signed wrap
|
616
616
|
# addition.
|
617
617
|
#
|
@@ -621,7 +621,7 @@ module RLTK::CG
|
|
621
621
|
def nsw_add(rhs)
|
622
622
|
self.class.new(Bindings.const_nsw_add(@ptr, rhs))
|
623
623
|
end
|
624
|
-
|
624
|
+
|
625
625
|
# Add this value with another value. Performs no unsigned wrap
|
626
626
|
# addition.
|
627
627
|
#
|
@@ -631,9 +631,9 @@ module RLTK::CG
|
|
631
631
|
def nuw_add(rhs)
|
632
632
|
self.class.new(Bindings.const_nuw_add(@ptr, rhs))
|
633
633
|
end
|
634
|
-
|
634
|
+
|
635
635
|
# Subtraction
|
636
|
-
|
636
|
+
|
637
637
|
# Subtract a value from this value.
|
638
638
|
#
|
639
639
|
# @param [ConstantInteger] rhs
|
@@ -642,7 +642,7 @@ module RLTK::CG
|
|
642
642
|
def -(rhs)
|
643
643
|
self.class.new(Bindings.const_sub(@ptr, rhs))
|
644
644
|
end
|
645
|
-
|
645
|
+
|
646
646
|
# Subtract a value from this value. Performs no signed wrap
|
647
647
|
# subtraction.
|
648
648
|
#
|
@@ -652,7 +652,7 @@ module RLTK::CG
|
|
652
652
|
def nsw_sub(rhs)
|
653
653
|
self.class.new(Bindings.const_nsw_sub(@ptr, rhs))
|
654
654
|
end
|
655
|
-
|
655
|
+
|
656
656
|
# Subtract a value from this value. Performs no unsigned wrap
|
657
657
|
# subtraction.
|
658
658
|
#
|
@@ -662,9 +662,9 @@ module RLTK::CG
|
|
662
662
|
def nuw_sub(rhs)
|
663
663
|
self.class.new(Bindings.const_nuw_sub(@ptr, rhs))
|
664
664
|
end
|
665
|
-
|
665
|
+
|
666
666
|
# Multiplication
|
667
|
-
|
667
|
+
|
668
668
|
# Multiply this value with another value.
|
669
669
|
#
|
670
670
|
# @param [ConstantInteger] rhs
|
@@ -673,7 +673,7 @@ module RLTK::CG
|
|
673
673
|
def *(rhs)
|
674
674
|
self.class.new(Bindings.const_mul(@ptr, rhs))
|
675
675
|
end
|
676
|
-
|
676
|
+
|
677
677
|
# Multiply this value with another value. Perform no signed wrap
|
678
678
|
# multiplication.
|
679
679
|
#
|
@@ -683,7 +683,7 @@ module RLTK::CG
|
|
683
683
|
def nsw_mul(rhs)
|
684
684
|
self.class.new(Bindings.const_nsw_mul(@ptr, rhs))
|
685
685
|
end
|
686
|
-
|
686
|
+
|
687
687
|
# Multiply this value with another value. Perform no unsigned wrap
|
688
688
|
# multiplication.
|
689
689
|
#
|
@@ -693,9 +693,9 @@ module RLTK::CG
|
|
693
693
|
def nuw_mul(rhs)
|
694
694
|
self.class.new(Bindings.const_nuw_mul(@ptr, rhs))
|
695
695
|
end
|
696
|
-
|
696
|
+
|
697
697
|
# Division
|
698
|
-
|
698
|
+
|
699
699
|
# Divide this value by another value. Uses signed division.
|
700
700
|
#
|
701
701
|
# @param [ConstantInteger] rhs
|
@@ -704,7 +704,7 @@ module RLTK::CG
|
|
704
704
|
def /(rhs)
|
705
705
|
self.class.new(Bindings.const_s_div(@ptr, rhs))
|
706
706
|
end
|
707
|
-
|
707
|
+
|
708
708
|
# Divide this value by another value. Uses exact signed division.
|
709
709
|
#
|
710
710
|
# @param [ConstantInteger] rhs
|
@@ -713,7 +713,7 @@ module RLTK::CG
|
|
713
713
|
def extact_sdiv(rhs)
|
714
714
|
self.class.new(Bindings.const_extact_s_div(@ptr, rhs))
|
715
715
|
end
|
716
|
-
|
716
|
+
|
717
717
|
# Divide this value by another value. Uses unsigned division.
|
718
718
|
#
|
719
719
|
# @param [ConstantInteger] rhs
|
@@ -722,9 +722,9 @@ module RLTK::CG
|
|
722
722
|
def udiv(rhs)
|
723
723
|
self.class.new(Bindings.const_u_div(@ptr, rhs))
|
724
724
|
end
|
725
|
-
|
725
|
+
|
726
726
|
# Remainder
|
727
|
-
|
727
|
+
|
728
728
|
# Modulo this value by another value. Uses signed modulo.
|
729
729
|
#
|
730
730
|
# @param [ConstantInteger] rhs
|
@@ -733,7 +733,7 @@ module RLTK::CG
|
|
733
733
|
def %(rhs)
|
734
734
|
self.class.new(Bindings.const_s_rem(@ptr, rhs))
|
735
735
|
end
|
736
|
-
|
736
|
+
|
737
737
|
# Modulo this value by another value. Uses unsigned modulo.
|
738
738
|
#
|
739
739
|
# @param [ConstantInteger] rhs
|
@@ -742,34 +742,34 @@ module RLTK::CG
|
|
742
742
|
def urem(rhs)
|
743
743
|
self.class.new(Bindings.const_u_rem(@ptr, rhs))
|
744
744
|
end
|
745
|
-
|
745
|
+
|
746
746
|
# Negation
|
747
|
-
|
747
|
+
|
748
748
|
# Negate this value.
|
749
749
|
#
|
750
|
-
# @return [ConstantInteger] Instance of the same class
|
750
|
+
# @return [ConstantInteger] Instance of the same class
|
751
751
|
def -@
|
752
752
|
self.class.new(Bindings.const_neg(@ptr))
|
753
753
|
end
|
754
|
-
|
754
|
+
|
755
755
|
# Negate this value. Uses no signed wrap negation.
|
756
756
|
#
|
757
757
|
# @return [ConstantInteger] Instance of the same class
|
758
758
|
def nsw_neg
|
759
759
|
self.class.new(Bindings.const_nsw_neg(@ptr))
|
760
760
|
end
|
761
|
-
|
761
|
+
|
762
762
|
# Negate this value. Uses no unsigned wrap negation.
|
763
763
|
#
|
764
764
|
# @return [ConstantInteger] Instance of the same class
|
765
765
|
def nuw_neg
|
766
766
|
self.class.new(Bindings.const_nuw_neg(@ptr))
|
767
767
|
end
|
768
|
-
|
768
|
+
|
769
769
|
######################
|
770
770
|
# Bitwise Operations #
|
771
771
|
######################
|
772
|
-
|
772
|
+
|
773
773
|
# A wrapper method around the {#shift_left} and {#shift_right}
|
774
774
|
# methods.
|
775
775
|
#
|
@@ -784,7 +784,7 @@ module RLTK::CG
|
|
784
784
|
when :right then shift_right(bits, mode)
|
785
785
|
end
|
786
786
|
end
|
787
|
-
|
787
|
+
|
788
788
|
# Shift the value left a specific number of bits.
|
789
789
|
#
|
790
790
|
# @param [Integer] bits Number of bits to shift.
|
@@ -795,7 +795,7 @@ module RLTK::CG
|
|
795
795
|
end
|
796
796
|
alias :shl :shift_left
|
797
797
|
alias :<< :shift_left
|
798
|
-
|
798
|
+
|
799
799
|
# Shift the value right a specific number of bits.
|
800
800
|
#
|
801
801
|
# @param [Integer] bits Number of bits to shift.
|
@@ -808,7 +808,7 @@ module RLTK::CG
|
|
808
808
|
when :logical then lshr(bits)
|
809
809
|
end
|
810
810
|
end
|
811
|
-
|
811
|
+
|
812
812
|
# Arithmetic right shift.
|
813
813
|
#
|
814
814
|
# @param [Integer] bits Number of bits to shift.
|
@@ -818,7 +818,7 @@ module RLTK::CG
|
|
818
818
|
self.class.new(Bindings.const_a_shr(@ptr, bits))
|
819
819
|
end
|
820
820
|
alias :>> :ashr
|
821
|
-
|
821
|
+
|
822
822
|
# Logical right shift.
|
823
823
|
#
|
824
824
|
# @param [Integer] bits Number of bits to shift.
|
@@ -827,7 +827,7 @@ module RLTK::CG
|
|
827
827
|
def lshr(bits)
|
828
828
|
self.class.new(Bindings.const_l_shr(@ptr, bits))
|
829
829
|
end
|
830
|
-
|
830
|
+
|
831
831
|
# Bitwise AND this value with another.
|
832
832
|
#
|
833
833
|
# @param [ConstantInteger] rhs
|
@@ -836,7 +836,7 @@ module RLTK::CG
|
|
836
836
|
def and(rhs)
|
837
837
|
self.class.new(Bindings.const_and(@ptr, rhs))
|
838
838
|
end
|
839
|
-
|
839
|
+
|
840
840
|
# Bitwise OR this value with another.
|
841
841
|
#
|
842
842
|
# @param [ConstantInteger] rhs
|
@@ -845,7 +845,7 @@ module RLTK::CG
|
|
845
845
|
def or(rhs)
|
846
846
|
self.class.new(Bindings.const_or(@ptr, rhs))
|
847
847
|
end
|
848
|
-
|
848
|
+
|
849
849
|
# Bitwise XOR this value with another.
|
850
850
|
#
|
851
851
|
# @param [ConstantInteger] rhs
|
@@ -854,18 +854,18 @@ module RLTK::CG
|
|
854
854
|
def xor(rhs)
|
855
855
|
self.class.new(Bindings.const_xor(@ptr, rhs))
|
856
856
|
end
|
857
|
-
|
857
|
+
|
858
858
|
# Bitwise NOT this value.
|
859
859
|
#
|
860
860
|
# @return [ConstantInteger] Instance of the same class.
|
861
861
|
def not
|
862
862
|
self.class.new(Bindings.const_not(@ptr))
|
863
863
|
end
|
864
|
-
|
864
|
+
|
865
865
|
#################
|
866
866
|
# Miscellaneous #
|
867
867
|
#################
|
868
|
-
|
868
|
+
|
869
869
|
# Cast this constant integer to another number type.
|
870
870
|
#
|
871
871
|
# @param [NumberType] type Desired type to cast to.
|
@@ -875,7 +875,7 @@ module RLTK::CG
|
|
875
875
|
def cast(type, signed = true)
|
876
876
|
type.value_class.new(Bindings.const_int_cast(@ptr, check_cg_type(type, NumberType), signed.to_i))
|
877
877
|
end
|
878
|
-
|
878
|
+
|
879
879
|
# Compare this value to another value.
|
880
880
|
#
|
881
881
|
# @see Bindings._enum_int_predicate_
|
@@ -887,7 +887,7 @@ module RLTK::CG
|
|
887
887
|
def cmp(pred, rhs)
|
888
888
|
Int1.new(Bindings.const_i_cmp(pred, @ptr, rhs))
|
889
889
|
end
|
890
|
-
|
890
|
+
|
891
891
|
# Convert this integer to a float.
|
892
892
|
#
|
893
893
|
# @param [RealType] type Type of float to convert to.
|
@@ -896,7 +896,7 @@ module RLTK::CG
|
|
896
896
|
def to_f(type)
|
897
897
|
type.value_class.new(Bindings.send(@signed ? :const_si_to_fp : :const_ui_to_fp, @ptr, check_cg_type(type, FloatingPointType)))
|
898
898
|
end
|
899
|
-
|
899
|
+
|
900
900
|
# Get the value of this constant as a signed or unsigned long long.
|
901
901
|
#
|
902
902
|
# @param [:sign, :zero] extension Extension method.
|
@@ -909,7 +909,7 @@ module RLTK::CG
|
|
909
909
|
end
|
910
910
|
end
|
911
911
|
end
|
912
|
-
|
912
|
+
|
913
913
|
# 1 bit integer value. Often used to represent Boolean values.
|
914
914
|
class Int1 < ConstantInteger; end
|
915
915
|
# 8 bit (1 byte) integer value.
|
@@ -920,21 +920,21 @@ module RLTK::CG
|
|
920
920
|
class Int32 < ConstantInteger; end
|
921
921
|
# 64 bit (8 byte) integer value.
|
922
922
|
class Int64 < ConstantInteger; end
|
923
|
-
|
923
|
+
|
924
924
|
# The native integer value class on the current (not the target) platform.
|
925
925
|
NativeInt = RLTK::CG.const_get("Int#{FFI.type_size(:int) * 8}")
|
926
|
-
|
926
|
+
|
927
927
|
# A constant Int 1 representing the Boolean value TRUE.
|
928
928
|
TRUE = Int1.new(-1)
|
929
929
|
# A constant Int 1 representing the Boolean value FALSE.
|
930
930
|
FALSE = Int1.new( 0)
|
931
|
-
|
931
|
+
|
932
932
|
# All real constants inherit from this class.
|
933
933
|
#
|
934
934
|
# @abstract
|
935
935
|
class ConstantReal < ConstantNumber
|
936
936
|
include Filigree::AbstractClass
|
937
|
-
|
937
|
+
|
938
938
|
# Create a constant real number using a Ruby value or a string.
|
939
939
|
#
|
940
940
|
# @param [::Float, String] num_or_string Ruby value or string representation of a float.
|
@@ -943,22 +943,22 @@ module RLTK::CG
|
|
943
943
|
@ptr =
|
944
944
|
if num_or_string.is_a?(::Float)
|
945
945
|
Bindings.const_real(self.type, num_or_string)
|
946
|
-
|
946
|
+
|
947
947
|
elsif size
|
948
948
|
Bindings.const_real_of_string_and_size(self.type, num_or_string, size)
|
949
|
-
|
949
|
+
|
950
950
|
else
|
951
951
|
Bindings.const_real_of_string(self.type, num_or_string)
|
952
952
|
end
|
953
953
|
end
|
954
|
-
|
954
|
+
|
955
955
|
# Negate this value.
|
956
956
|
#
|
957
957
|
# @return [ConstantReal] Instance of the same class
|
958
958
|
def -@
|
959
959
|
self.class.new(Bindings.const_f_neg(@ptr))
|
960
960
|
end
|
961
|
-
|
961
|
+
|
962
962
|
# Add this value with another value.
|
963
963
|
#
|
964
964
|
# @param [ConstantReal] rhs
|
@@ -967,7 +967,7 @@ module RLTK::CG
|
|
967
967
|
def +(rhs)
|
968
968
|
self.class.new(Bindings.const_f_add(@ptr, rhs))
|
969
969
|
end
|
970
|
-
|
970
|
+
|
971
971
|
# Subtract a value from this value.
|
972
972
|
#
|
973
973
|
# @param [ConstantReal] rhs
|
@@ -976,7 +976,7 @@ module RLTK::CG
|
|
976
976
|
def -(rhs)
|
977
977
|
self.class.new(Bindings.const_f_sub(@ptr, rhs))
|
978
978
|
end
|
979
|
-
|
979
|
+
|
980
980
|
# Multiply this value with another value.
|
981
981
|
#
|
982
982
|
# @param [ConstantReal] rhs
|
@@ -985,7 +985,7 @@ module RLTK::CG
|
|
985
985
|
def *(rhs)
|
986
986
|
self.class.new(Bindings.const_f_mul(@ptr, rhs))
|
987
987
|
end
|
988
|
-
|
988
|
+
|
989
989
|
# Divide this value by another value.
|
990
990
|
#
|
991
991
|
# @param [ConstantReal] rhs
|
@@ -994,7 +994,7 @@ module RLTK::CG
|
|
994
994
|
def /(rhs)
|
995
995
|
self.class.new(Bindings.const_f_div(@ptr, rhs))
|
996
996
|
end
|
997
|
-
|
997
|
+
|
998
998
|
# Modulo this value by another value.
|
999
999
|
#
|
1000
1000
|
# @param [ConstantReal] rhs
|
@@ -1003,7 +1003,7 @@ module RLTK::CG
|
|
1003
1003
|
def %(rhs)
|
1004
1004
|
self.class.new(Bindings.const_f_remm(@ptr, rhs))
|
1005
1005
|
end
|
1006
|
-
|
1006
|
+
|
1007
1007
|
# Compare this value to another value.
|
1008
1008
|
#
|
1009
1009
|
# @see Bindings._enum_real_predicate_
|
@@ -1015,7 +1015,7 @@ module RLTK::CG
|
|
1015
1015
|
def cmp(pred, rhs)
|
1016
1016
|
Int1.new(Bindings.const_f_cmp(pred, @ptr, rhs))
|
1017
1017
|
end
|
1018
|
-
|
1018
|
+
|
1019
1019
|
# Cast this constant real to another number type.
|
1020
1020
|
#
|
1021
1021
|
# @param [NumberType] type Desired type to cast to.
|
@@ -1024,7 +1024,7 @@ module RLTK::CG
|
|
1024
1024
|
def cast(type)
|
1025
1025
|
type.value_class.new(Bindings.const_fp_cast(@ptr, check_cg_type(type, NumberType)))
|
1026
1026
|
end
|
1027
|
-
|
1027
|
+
|
1028
1028
|
# Convert this real number into an integer.
|
1029
1029
|
#
|
1030
1030
|
# @param [BasicIntType] type Type to convert to.
|
@@ -1034,7 +1034,7 @@ module RLTK::CG
|
|
1034
1034
|
def to_i(type = NativeIntType, signed = true)
|
1035
1035
|
type.value_class.new(Bindings.send(signed ? :const_fp_to_si : :const_fp_to_ui, @ptr, check_cg_type(type, BasicIntType)))
|
1036
1036
|
end
|
1037
|
-
|
1037
|
+
|
1038
1038
|
# Extend a constant real number to a larger size.
|
1039
1039
|
#
|
1040
1040
|
# @param [RealType] type Type to extend to.
|
@@ -1043,7 +1043,7 @@ module RLTK::CG
|
|
1043
1043
|
def extend(type)
|
1044
1044
|
type.value_class.new(Bindings.const_fp_ext(@ptr, check_cg_type(type, RealType)))
|
1045
1045
|
end
|
1046
|
-
|
1046
|
+
|
1047
1047
|
# Truncate a constant real number to a smaller size.
|
1048
1048
|
#
|
1049
1049
|
# @param [RealType] type Type to truncate to.
|
@@ -1053,7 +1053,7 @@ module RLTK::CG
|
|
1053
1053
|
type.value_class.new(Bindings.const_fp_trunc(@ptr, check_cg_type(type, RealType)))
|
1054
1054
|
end
|
1055
1055
|
end
|
1056
|
-
|
1056
|
+
|
1057
1057
|
# A 16-bit floating point number value.
|
1058
1058
|
class Half < ConstantReal; end
|
1059
1059
|
# A double precision floating point number value.
|
@@ -1066,7 +1066,7 @@ module RLTK::CG
|
|
1066
1066
|
class PPCFP128 < ConstantReal; end
|
1067
1067
|
# A 80 bit (10 byte) floating point number value for the x86 architecture.
|
1068
1068
|
class X86FP80 < ConstantReal; end
|
1069
|
-
|
1069
|
+
|
1070
1070
|
# This class represents global constants, variables, and functions.
|
1071
1071
|
class GlobalValue < Constant
|
1072
1072
|
# Global values can only be instantiated using a pointer, and as such
|
@@ -1076,14 +1076,14 @@ module RLTK::CG
|
|
1076
1076
|
def initialize(ptr)
|
1077
1077
|
@ptr = check_type(ptr, FFI::Pointer, 'ptr')
|
1078
1078
|
end
|
1079
|
-
|
1079
|
+
|
1080
1080
|
# Get the byte alignment of this value.
|
1081
1081
|
#
|
1082
1082
|
# @return [Integer]
|
1083
1083
|
def alignment
|
1084
1084
|
Bindings.get_alignment(@ptr)
|
1085
1085
|
end
|
1086
|
-
|
1086
|
+
|
1087
1087
|
# Set the byte alignment of this value.
|
1088
1088
|
#
|
1089
1089
|
# @param [Integer] bytes
|
@@ -1092,14 +1092,14 @@ module RLTK::CG
|
|
1092
1092
|
def alignment=(bytes)
|
1093
1093
|
Bindings.set_alignment(@ptr, bytes)
|
1094
1094
|
end
|
1095
|
-
|
1095
|
+
|
1096
1096
|
# Check if this value is a declaration.
|
1097
1097
|
#
|
1098
1098
|
# @return [Boolean]
|
1099
1099
|
def declaration?
|
1100
1100
|
Bindings.is_declaration(@ptr).to_bool
|
1101
1101
|
end
|
1102
|
-
|
1102
|
+
|
1103
1103
|
# Sets the externally initialized property of a global value.
|
1104
1104
|
#
|
1105
1105
|
# @param [Boolean] bool If the value is externally initialized
|
@@ -1108,21 +1108,21 @@ module RLTK::CG
|
|
1108
1108
|
def externally_initialized=(bool)
|
1109
1109
|
Bindings.set_externally_initialized(@ptr, bool.to_i)
|
1110
1110
|
end
|
1111
|
-
|
1111
|
+
|
1112
1112
|
# Check if this global is initialized externally.
|
1113
1113
|
#
|
1114
1114
|
# @return [Boolean]
|
1115
1115
|
def externally_initialized?
|
1116
1116
|
Bindings.externally_initialized(@ptr).to_bool
|
1117
1117
|
end
|
1118
|
-
|
1118
|
+
|
1119
1119
|
# Check if this value is a global constant.
|
1120
1120
|
#
|
1121
1121
|
# @return [Boolean]
|
1122
1122
|
def global_constant?
|
1123
1123
|
Bindings.is_global_constant(@ptr).to_bool
|
1124
1124
|
end
|
1125
|
-
|
1125
|
+
|
1126
1126
|
# Set this value as a global constant or not.
|
1127
1127
|
#
|
1128
1128
|
# @param [Boolean] flag
|
@@ -1131,14 +1131,14 @@ module RLTK::CG
|
|
1131
1131
|
def global_constant=(flag)
|
1132
1132
|
Bindings.set_global_constant(@ptr, flag.to_i)
|
1133
1133
|
end
|
1134
|
-
|
1134
|
+
|
1135
1135
|
# Get this value's initializer.
|
1136
1136
|
#
|
1137
1137
|
# @return [Value]
|
1138
1138
|
def initializer
|
1139
1139
|
Value.new(Bindings.get_initializer(@ptr))
|
1140
1140
|
end
|
1141
|
-
|
1141
|
+
|
1142
1142
|
# Set this value's initializer.
|
1143
1143
|
#
|
1144
1144
|
# @param [Value] val
|
@@ -1147,7 +1147,7 @@ module RLTK::CG
|
|
1147
1147
|
def initializer=(val)
|
1148
1148
|
Bindings.set_initializer(@ptr, check_type(val, Value, 'val'))
|
1149
1149
|
end
|
1150
|
-
|
1150
|
+
|
1151
1151
|
# Get this value's linkage type.
|
1152
1152
|
#
|
1153
1153
|
# @see Bindings._enum_linkage_
|
@@ -1156,7 +1156,7 @@ module RLTK::CG
|
|
1156
1156
|
def linkage
|
1157
1157
|
Bindings.get_linkage(@ptr)
|
1158
1158
|
end
|
1159
|
-
|
1159
|
+
|
1160
1160
|
# Set this value's linkage type.
|
1161
1161
|
#
|
1162
1162
|
# @see Bindings._enum_linkage_
|
@@ -1167,14 +1167,14 @@ module RLTK::CG
|
|
1167
1167
|
def linkage=(linkage)
|
1168
1168
|
Bindings.set_linkage(@ptr, linkage)
|
1169
1169
|
end
|
1170
|
-
|
1170
|
+
|
1171
1171
|
# Get this value's section string.
|
1172
1172
|
#
|
1173
1173
|
# @return [String]
|
1174
1174
|
def section
|
1175
1175
|
Bindings.get_section(@ptr)
|
1176
1176
|
end
|
1177
|
-
|
1177
|
+
|
1178
1178
|
# Set this value's section string.
|
1179
1179
|
#
|
1180
1180
|
# @param [String] section
|
@@ -1183,15 +1183,15 @@ module RLTK::CG
|
|
1183
1183
|
def section=(section)
|
1184
1184
|
Bindings.set_section(@ptr, section)
|
1185
1185
|
end
|
1186
|
-
|
1187
|
-
# Returns the thread local model used by a global value.
|
1186
|
+
|
1187
|
+
# Returns the thread local model used by a global value.
|
1188
1188
|
#
|
1189
1189
|
# @return [Symbol from _enum_thread_local_mode_]
|
1190
1190
|
def thread_local_mode
|
1191
1191
|
Bindings.get_thread_local_mode(@ptr)
|
1192
|
-
end
|
1193
|
-
|
1194
|
-
|
1192
|
+
end
|
1193
|
+
|
1194
|
+
|
1195
1195
|
# Set the global value's thread local mode.
|
1196
1196
|
#
|
1197
1197
|
# @param [Symbol from _enum_thread_local_mode_] mode
|
@@ -1200,7 +1200,7 @@ module RLTK::CG
|
|
1200
1200
|
def thread_local_mode=(mode)
|
1201
1201
|
Bindings.set_thread_local_mode(@ptr, mode)
|
1202
1202
|
end
|
1203
|
-
|
1203
|
+
|
1204
1204
|
# Get this value's visibility.
|
1205
1205
|
#
|
1206
1206
|
# @see Bindings._enum_visibility_
|
@@ -1209,7 +1209,7 @@ module RLTK::CG
|
|
1209
1209
|
def visibility
|
1210
1210
|
Bindings.get_visibility(@ptr)
|
1211
1211
|
end
|
1212
|
-
|
1212
|
+
|
1213
1213
|
# Set this value's visibility.
|
1214
1214
|
#
|
1215
1215
|
# @see Bindings._enum_visibility_
|
@@ -1221,11 +1221,11 @@ module RLTK::CG
|
|
1221
1221
|
Bindings.set_visibility(@ptr, vis)
|
1222
1222
|
end
|
1223
1223
|
end
|
1224
|
-
|
1224
|
+
|
1225
1225
|
# This class represents global aliases.
|
1226
1226
|
class GlobalAlias < GlobalValue
|
1227
1227
|
end
|
1228
|
-
|
1228
|
+
|
1229
1229
|
# This class represents global variables.
|
1230
1230
|
class GlobalVariable < GlobalValue
|
1231
1231
|
# Check to see if this global variable is thread local.
|
@@ -1234,7 +1234,7 @@ module RLTK::CG
|
|
1234
1234
|
def thread_local?
|
1235
1235
|
Bindings.is_thread_local(@ptr).to_bool
|
1236
1236
|
end
|
1237
|
-
|
1237
|
+
|
1238
1238
|
# Set this global variable as thread local or not.
|
1239
1239
|
#
|
1240
1240
|
# @param [Boolean] local
|
@@ -1262,11 +1262,11 @@ def make_ptr_to_elements(size_or_values, &block)
|
|
1262
1262
|
case size_or_values
|
1263
1263
|
when Integer
|
1264
1264
|
raise ArgumentError, 'Block not given.' if not block_given?
|
1265
|
-
|
1265
|
+
|
1266
1266
|
::Array.new(size_or_values, &block)
|
1267
1267
|
else
|
1268
1268
|
size_or_values
|
1269
1269
|
end
|
1270
|
-
|
1270
|
+
|
1271
1271
|
FFI::MemoryPointer.new(:pointer, values.size).write_array_of_pointer(values)
|
1272
1272
|
end
|