rltk 2.2.1 → 3.0.0
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 +7 -0
- data/LICENSE +12 -12
- data/README.md +458 -285
- data/Rakefile +99 -92
- data/lib/rltk/ast.rb +221 -126
- data/lib/rltk/cfg.rb +218 -239
- data/lib/rltk/cg/basic_block.rb +1 -1
- data/lib/rltk/cg/bindings.rb +9 -26
- data/lib/rltk/cg/builder.rb +40 -8
- data/lib/rltk/cg/context.rb +1 -1
- data/lib/rltk/cg/contractor.rb +51 -0
- data/lib/rltk/cg/execution_engine.rb +45 -8
- data/lib/rltk/cg/function.rb +12 -2
- data/lib/rltk/cg/generated_bindings.rb +2541 -575
- data/lib/rltk/cg/generic_value.rb +2 -2
- data/lib/rltk/cg/instruction.rb +104 -83
- data/lib/rltk/cg/llvm.rb +44 -3
- data/lib/rltk/cg/memory_buffer.rb +22 -5
- data/lib/rltk/cg/module.rb +85 -36
- data/lib/rltk/cg/old_generated_bindings.rb +6152 -0
- data/lib/rltk/cg/pass_manager.rb +87 -43
- data/lib/rltk/cg/support.rb +2 -4
- data/lib/rltk/cg/target.rb +158 -28
- data/lib/rltk/cg/triple.rb +8 -8
- data/lib/rltk/cg/type.rb +69 -25
- data/lib/rltk/cg/value.rb +107 -66
- data/lib/rltk/cg.rb +16 -17
- data/lib/rltk/lexer.rb +21 -11
- data/lib/rltk/lexers/calculator.rb +1 -1
- data/lib/rltk/lexers/ebnf.rb +8 -7
- data/lib/rltk/parser.rb +300 -247
- data/lib/rltk/parsers/infix_calc.rb +1 -1
- data/lib/rltk/parsers/postfix_calc.rb +2 -2
- data/lib/rltk/parsers/prefix_calc.rb +2 -2
- data/lib/rltk/token.rb +1 -2
- data/lib/rltk/version.rb +3 -3
- data/lib/rltk.rb +6 -6
- data/test/cg/tc_basic_block.rb +83 -0
- data/test/cg/tc_control_flow.rb +191 -0
- data/test/cg/tc_function.rb +54 -0
- data/test/cg/tc_generic_value.rb +33 -0
- data/test/cg/tc_instruction.rb +256 -0
- data/test/cg/tc_llvm.rb +25 -0
- data/test/cg/tc_math.rb +88 -0
- data/test/cg/tc_module.rb +89 -0
- data/test/cg/tc_transforms.rb +68 -0
- data/test/cg/tc_type.rb +69 -0
- data/test/cg/tc_value.rb +151 -0
- data/test/cg/ts_cg.rb +23 -0
- data/test/tc_ast.rb +105 -8
- data/test/tc_cfg.rb +63 -48
- data/test/tc_lexer.rb +84 -96
- data/test/tc_parser.rb +224 -52
- data/test/tc_token.rb +6 -6
- data/test/ts_rltk.rb +12 -15
- metadata +149 -75
- data/lib/rltk/cg/generated_extended_bindings.rb +0 -287
- data/lib/rltk/util/abstract_class.rb +0 -25
- data/lib/rltk/util/monkeys.rb +0 -129
@@ -15,7 +15,7 @@ require 'rltk/cg/type'
|
|
15
15
|
# Classes and Modules #
|
16
16
|
#######################
|
17
17
|
|
18
|
-
module RLTK::CG
|
18
|
+
module RLTK::CG
|
19
19
|
|
20
20
|
# GenericValue objects are used to pass parameters into
|
21
21
|
# {ExecutionEngine ExecutionEngines} as well as retreive an evaluated
|
@@ -83,7 +83,7 @@ module RLTK::CG # :nodoc:
|
|
83
83
|
end
|
84
84
|
|
85
85
|
# @return [Boolean]
|
86
|
-
def
|
86
|
+
def to_bool
|
87
87
|
self.to_i(false).to_bool
|
88
88
|
end
|
89
89
|
|
data/lib/rltk/cg/instruction.rb
CHANGED
@@ -15,7 +15,7 @@ require 'rltk/cg/value'
|
|
15
15
|
# Classes and Modules #
|
16
16
|
#######################
|
17
17
|
|
18
|
-
module RLTK::CG
|
18
|
+
module RLTK::CG
|
19
19
|
|
20
20
|
# This class represents LLVM IR instructions.
|
21
21
|
class Instruction < User
|
@@ -25,6 +25,7 @@ module RLTK::CG # :nodoc:
|
|
25
25
|
# sub-types can be tested for. This is a list of those sub-types and
|
26
26
|
# the names of their tests.
|
27
27
|
TESTABLE = [
|
28
|
+
:AddrSpaceCast,
|
28
29
|
:Alloca,
|
29
30
|
:BitCast,
|
30
31
|
:Call,
|
@@ -141,7 +142,21 @@ module RLTK::CG # :nodoc:
|
|
141
142
|
Bindings.set_instruction_call_conv(@ptr, Bindings.enum_type(:call_conv)[conv])
|
142
143
|
|
143
144
|
conv
|
144
|
-
end
|
145
|
+
end
|
146
|
+
|
147
|
+
# @return [Boolean]
|
148
|
+
def tail_call?
|
149
|
+
Bindings.is_tail_call(@ptr).to_bool
|
150
|
+
end
|
151
|
+
|
152
|
+
# Sets the *tail call* property for this call instruction.
|
153
|
+
#
|
154
|
+
# @param [Boolean] bool If this is a tail call or not
|
155
|
+
#
|
156
|
+
# @return [void]
|
157
|
+
def tail_call=(bool)
|
158
|
+
Bindings.set_tail_call(@ptr, bool.to_i)
|
159
|
+
end
|
145
160
|
end
|
146
161
|
|
147
162
|
# An Instruction representing a Phi node.
|
@@ -179,10 +194,10 @@ module RLTK::CG # :nodoc:
|
|
179
194
|
# Add incoming {BasicBlock}/{Value} pairs to a Phi node.
|
180
195
|
#
|
181
196
|
# @example Adding a single block/value pair:
|
182
|
-
#
|
197
|
+
# phi.incoming.add(bb, val)
|
183
198
|
#
|
184
199
|
# @example Adding several block/value pairs:
|
185
|
-
#
|
200
|
+
# phi.incoming.add({bb0 => val0, bb1 => val1})
|
186
201
|
#
|
187
202
|
# @param [BasicBlock, Hash{BasicBlock => Value}] overloaded
|
188
203
|
# @param [Value, nil] value
|
@@ -206,7 +221,7 @@ module RLTK::CG # :nodoc:
|
|
206
221
|
blks_ptr = FFI::MemoryPointer.new(:pointer, blks.size)
|
207
222
|
blks_ptr.write_array_of_pointer(blks)
|
208
223
|
|
209
|
-
|
224
|
+
nil.tap { Bindings.add_incoming(@phi, vals_ptr, blks_ptr, vals.length) }
|
210
225
|
end
|
211
226
|
alias :<< :add
|
212
227
|
|
@@ -272,227 +287,233 @@ module RLTK::CG # :nodoc:
|
|
272
287
|
#############################
|
273
288
|
|
274
289
|
# @LLVMInst add
|
275
|
-
class AddInst
|
290
|
+
class AddInst < Instruction; end
|
291
|
+
|
292
|
+
# @LLVMInst addr_space_cast
|
293
|
+
class AddrSpaceCastInst < Instruction; end
|
276
294
|
|
277
295
|
# @LLVMInst alloca
|
278
|
-
class AllocaInst
|
296
|
+
class AllocaInst < Instruction; end
|
279
297
|
|
280
298
|
# @LLVMInst and
|
281
|
-
class AndInst
|
299
|
+
class AndInst < Instruction; end
|
282
300
|
|
283
301
|
# @LLVMInst ashr
|
284
|
-
class ARightShiftInst
|
302
|
+
class ARightShiftInst < Instruction; end
|
285
303
|
|
286
304
|
# @LLVMInst alloca
|
287
|
-
class ArrayAllocaInst
|
305
|
+
class ArrayAllocaInst < Instruction; end
|
306
|
+
|
307
|
+
class ArrayMallocInst < Instruction; end
|
288
308
|
|
289
|
-
|
309
|
+
# @LLVMInst atomicrmw
|
310
|
+
class AtomicRMWInst < Instruction; end
|
290
311
|
|
291
312
|
# @LLVMInst bitcast
|
292
|
-
class BitCastInst
|
313
|
+
class BitCastInst < Instruction; end
|
293
314
|
|
294
315
|
# @LLVMInst br
|
295
|
-
class BranchInst
|
316
|
+
class BranchInst < Instruction; end
|
296
317
|
|
297
318
|
# @LLVMInst br
|
298
|
-
class CondBranchInst
|
319
|
+
class CondBranchInst < Instruction; end
|
299
320
|
|
300
321
|
# @LLVMInst sdiv
|
301
|
-
class ExactSDivInst
|
322
|
+
class ExactSDivInst < Instruction; end
|
302
323
|
|
303
324
|
# @LLVMInst extractelement
|
304
|
-
class ExtractElementInst
|
325
|
+
class ExtractElementInst < Instruction; end
|
305
326
|
|
306
327
|
# @LLVMInst extractvalue
|
307
|
-
class ExtractValueInst
|
328
|
+
class ExtractValueInst < Instruction; end
|
308
329
|
|
309
330
|
# @LLVMInst fadd
|
310
|
-
class FAddInst
|
331
|
+
class FAddInst < Instruction; end
|
311
332
|
|
312
333
|
# @LLVMInst fcmp
|
313
|
-
class FCmpInst
|
334
|
+
class FCmpInst < Instruction; end
|
314
335
|
|
315
336
|
# @LLVMInst fdiv
|
316
|
-
class FDivInst
|
337
|
+
class FDivInst < Instruction; end
|
317
338
|
|
318
339
|
# @LLVMInst fmul
|
319
|
-
class FMulInst
|
340
|
+
class FMulInst < Instruction; end
|
320
341
|
|
321
342
|
# @LLVMInst fsub
|
322
|
-
class FNegInst
|
343
|
+
class FNegInst < Instruction; end
|
323
344
|
|
324
345
|
# @LLVMInst fptosi
|
325
|
-
class FPToSIInst
|
346
|
+
class FPToSIInst < Instruction; end
|
326
347
|
|
327
348
|
# @LLVMInst fptoui
|
328
|
-
class FPToUIInst
|
349
|
+
class FPToUIInst < Instruction; end
|
329
350
|
|
330
|
-
class FPCastInst
|
351
|
+
class FPCastInst < Instruction; end
|
331
352
|
|
332
353
|
# @LLVMInst fpext
|
333
|
-
class FPExtendInst
|
354
|
+
class FPExtendInst < Instruction; end
|
334
355
|
|
335
356
|
# @LLVMInst fptrunc
|
336
|
-
class FPTruncInst
|
357
|
+
class FPTruncInst < Instruction; end
|
337
358
|
|
338
|
-
class FreeInst
|
359
|
+
class FreeInst < Instruction; end
|
339
360
|
|
340
361
|
# @LLVMInst frem
|
341
|
-
class FRemInst
|
362
|
+
class FRemInst < Instruction; end
|
342
363
|
|
343
364
|
# @LLVMInst fsub
|
344
|
-
class FSubInst
|
365
|
+
class FSubInst < Instruction; end
|
345
366
|
|
346
367
|
# @LLVMInst gep
|
347
368
|
# @see http://llvm.org/docs/GetElementPtr.html
|
348
|
-
class GetElementPtrInst
|
369
|
+
class GetElementPtrInst < Instruction; end
|
349
370
|
|
350
|
-
class GlobalStringInst
|
351
|
-
class GlobalStringPtrInst
|
371
|
+
class GlobalStringInst < Instruction; end
|
372
|
+
class GlobalStringPtrInst < Instruction; end
|
352
373
|
|
353
374
|
# @LLVMInst gep
|
354
375
|
# @see http://llvm.org/docs/GetElementPtr.html
|
355
|
-
class InBoundsGEPInst
|
376
|
+
class InBoundsGEPInst < Instruction; end
|
356
377
|
|
357
378
|
# @LLVMInst insertelement
|
358
|
-
class InsertElementInst
|
379
|
+
class InsertElementInst < Instruction; end
|
359
380
|
|
360
381
|
# @LLVMInst insertvalue
|
361
|
-
class InsertValueInst
|
382
|
+
class InsertValueInst < Instruction; end
|
362
383
|
|
363
384
|
# @LLVMInst inttoptr
|
364
|
-
class IntToPtrInst
|
385
|
+
class IntToPtrInst < Instruction; end
|
365
386
|
|
366
|
-
class IntCastInst
|
387
|
+
class IntCastInst < Instruction; end
|
367
388
|
|
368
389
|
# @LLVMInst icmp
|
369
|
-
class IntCmpInst
|
390
|
+
class IntCmpInst < Instruction; end
|
370
391
|
|
371
392
|
# @LLVMInst invoke
|
372
|
-
class InvokeInst
|
393
|
+
class InvokeInst < Instruction; end
|
373
394
|
|
374
|
-
class IsNotNullInst
|
375
|
-
class IsNullInstInst
|
395
|
+
class IsNotNullInst < Instruction; end
|
396
|
+
class IsNullInstInst < Instruction; end
|
376
397
|
|
377
398
|
# @LLVMInst shl
|
378
|
-
class LeftShiftInst
|
399
|
+
class LeftShiftInst < Instruction; end
|
379
400
|
|
380
401
|
# @LLVMInst load
|
381
|
-
class LoadInst
|
402
|
+
class LoadInst < Instruction; end
|
382
403
|
|
383
404
|
# @LLVMInst lshr
|
384
|
-
class LRightShiftInst
|
405
|
+
class LRightShiftInst < Instruction; end
|
385
406
|
|
386
|
-
class MallocInst
|
407
|
+
class MallocInst < Instruction; end
|
387
408
|
|
388
409
|
# @LLVMInst mul
|
389
|
-
class MulInst
|
410
|
+
class MulInst < Instruction; end
|
390
411
|
|
391
412
|
# @LLVMInst sub
|
392
|
-
class NegInst
|
413
|
+
class NegInst < Instruction; end
|
393
414
|
|
394
|
-
class NotInst
|
415
|
+
class NotInst < Instruction; end
|
395
416
|
|
396
417
|
# @LLVMInst add
|
397
|
-
class NSWAddInst
|
418
|
+
class NSWAddInst < Instruction; end
|
398
419
|
|
399
420
|
# @LLVMInst mul
|
400
|
-
class NSWMulInst
|
421
|
+
class NSWMulInst < Instruction; end
|
401
422
|
|
402
423
|
# @LLVMInst sub
|
403
|
-
class NSWNegInst
|
424
|
+
class NSWNegInst < Instruction; end
|
404
425
|
|
405
426
|
# @LLVMInst sub
|
406
|
-
class NSWSubInst
|
427
|
+
class NSWSubInst < Instruction; end
|
407
428
|
|
408
429
|
# @LLVMInst add
|
409
|
-
class NUWAddInst
|
430
|
+
class NUWAddInst < Instruction; end
|
410
431
|
|
411
432
|
# @LLVMInst mul
|
412
|
-
class NUWMulInst
|
433
|
+
class NUWMulInst < Instruction; end
|
413
434
|
|
414
435
|
# @LLVMInst sub
|
415
|
-
class NUWNegInst
|
436
|
+
class NUWNegInst < Instruction; end
|
416
437
|
|
417
438
|
# @LLVMInst sub
|
418
|
-
class NUWSubInst
|
439
|
+
class NUWSubInst < Instruction; end
|
419
440
|
|
420
441
|
# @LLVMInst or
|
421
|
-
class OrInst
|
442
|
+
class OrInst < Instruction; end
|
422
443
|
|
423
444
|
# @LLVMInst ptrtoint
|
424
|
-
class PtrToIntInst
|
445
|
+
class PtrToIntInst < Instruction; end
|
425
446
|
|
426
|
-
class PtrCastInst
|
427
|
-
class PtrDiffInst
|
447
|
+
class PtrCastInst < Instruction; end
|
448
|
+
class PtrDiffInst < Instruction; end
|
428
449
|
|
429
450
|
# @LLVMInst ret
|
430
|
-
class ReturnInst
|
451
|
+
class ReturnInst < Instruction; end
|
431
452
|
|
432
453
|
# @LLVMInst ret
|
433
|
-
class ReturnAggregateInst
|
454
|
+
class ReturnAggregateInst < Instruction; end
|
434
455
|
|
435
456
|
# @LLVMInst ret
|
436
|
-
class ReturnVoidInst
|
457
|
+
class ReturnVoidInst < Instruction; end
|
437
458
|
|
438
459
|
# @LLVMInst sdiv
|
439
|
-
class SDivInst
|
460
|
+
class SDivInst < Instruction; end
|
440
461
|
|
441
462
|
# @LLVMInst select
|
442
|
-
class SelectInst
|
463
|
+
class SelectInst < Instruction; end
|
443
464
|
|
444
465
|
# @LLVMInst shufflevector
|
445
|
-
class ShuffleVectorInst
|
466
|
+
class ShuffleVectorInst < Instruction; end
|
446
467
|
|
447
468
|
# @LLVMInst sext
|
448
|
-
class SignExtendInst
|
469
|
+
class SignExtendInst < Instruction; end
|
449
470
|
|
450
471
|
# @LLVMInst sext
|
451
472
|
# @LLVMInst bitcast
|
452
|
-
class SignExtendOrBitCastInst
|
473
|
+
class SignExtendOrBitCastInst < Instruction; end
|
453
474
|
|
454
475
|
# @LLVMInst sitofp
|
455
|
-
class SIToFPInst
|
476
|
+
class SIToFPInst < Instruction; end
|
456
477
|
|
457
478
|
# @LLVMInst srem
|
458
|
-
class SRemInst
|
479
|
+
class SRemInst < Instruction; end
|
459
480
|
|
460
481
|
# @LLVMInst store
|
461
|
-
class StoreInst
|
482
|
+
class StoreInst < Instruction; end
|
462
483
|
|
463
484
|
# @LLVMInst gep
|
464
485
|
# @see http://llvm.org/docs/GetElementPtr.html
|
465
|
-
class StructGEPInst
|
486
|
+
class StructGEPInst < Instruction; end
|
466
487
|
|
467
488
|
# @LLVMInst sub
|
468
|
-
class SubInst
|
489
|
+
class SubInst < Instruction; end
|
469
490
|
|
470
491
|
# @LLVMInst trunc
|
471
|
-
class TruncateInst
|
492
|
+
class TruncateInst < Instruction; end
|
472
493
|
|
473
494
|
# @LLVMInst trunc
|
474
495
|
# @LLVMInst bitcast
|
475
|
-
class TruncateOrBitCastInst
|
496
|
+
class TruncateOrBitCastInst < Instruction; end
|
476
497
|
|
477
498
|
# @LLVMInst udiv
|
478
|
-
class UDivInst
|
499
|
+
class UDivInst < Instruction; end
|
479
500
|
|
480
501
|
# @LLVMInst uitofp
|
481
|
-
class UIToFPInst
|
502
|
+
class UIToFPInst < Instruction; end
|
482
503
|
|
483
504
|
# @LLVMInst unreachable
|
484
|
-
class UnreachableInst
|
505
|
+
class UnreachableInst < Instruction; end
|
485
506
|
|
486
507
|
# @LLVMInst urem
|
487
|
-
class URemInst
|
508
|
+
class URemInst < Instruction; end
|
488
509
|
|
489
510
|
# @LLVMInst xor
|
490
|
-
class XOrInst
|
511
|
+
class XOrInst < Instruction; end
|
491
512
|
|
492
513
|
# @LLVMInst zext
|
493
|
-
class ZeroExtendInst
|
514
|
+
class ZeroExtendInst < Instruction; end
|
494
515
|
|
495
516
|
# @LLVMInst zext
|
496
517
|
# @LLVMInst bitcast
|
497
|
-
class ZeroExtendOrBitCastInst
|
518
|
+
class ZeroExtendOrBitCastInst < Instruction; end
|
498
519
|
end
|
data/lib/rltk/cg/llvm.rb
CHANGED
@@ -15,10 +15,20 @@ require 'rltk/cg/bindings'
|
|
15
15
|
# Classes and Modules #
|
16
16
|
#######################
|
17
17
|
|
18
|
-
module RLTK::CG
|
18
|
+
module RLTK::CG
|
19
19
|
|
20
20
|
# This module contains global operations on the LLVM compiler infrastructure.
|
21
21
|
module LLVM
|
22
|
+
|
23
|
+
# Enable LLVM's built-in stack trace code. This intercepts the OS's
|
24
|
+
# crash signals and prints which component of LLVM you were in at the
|
25
|
+
# time if the crash.
|
26
|
+
#
|
27
|
+
# @return [void]
|
28
|
+
def self.enable_pretty_stack_trace
|
29
|
+
Bindings.enable_pretty_stack_trace
|
30
|
+
end
|
31
|
+
|
22
32
|
# Initialize LLVM to generate code for a given architecture. You may
|
23
33
|
# also specify :all to initialize all targets or :native to
|
24
34
|
# initialize the host target.
|
@@ -32,10 +42,10 @@ module RLTK::CG # :nodoc:
|
|
32
42
|
# @return [void]
|
33
43
|
def self.init(arch)
|
34
44
|
if arch == :all
|
35
|
-
Bindings.
|
45
|
+
Bindings.initialize_all_targets
|
36
46
|
|
37
47
|
elsif arch == :native
|
38
|
-
Bindings.
|
48
|
+
Bindings.initialize_native_target
|
39
49
|
|
40
50
|
elsif Bindings::ARCHS.include?(arch) or Bindings::ARCHS.map { |sym| sym.to_s.downcase.to_sym }.include?(arch)
|
41
51
|
arch = Bindings.get_bname(arch)
|
@@ -49,6 +59,14 @@ module RLTK::CG # :nodoc:
|
|
49
59
|
end
|
50
60
|
end
|
51
61
|
|
62
|
+
# Initialize access to all available target MC that LLVM is
|
63
|
+
# configured to support.
|
64
|
+
#
|
65
|
+
# @return [void]
|
66
|
+
def self.initialize_all_target_mcs
|
67
|
+
Bindings.initialize_all_target_mcs
|
68
|
+
end
|
69
|
+
|
52
70
|
# Initialize a given ASM parser inside LLVM. You may also specify
|
53
71
|
# :all to initialize all ASM parsers.
|
54
72
|
#
|
@@ -101,6 +119,29 @@ module RLTK::CG # :nodoc:
|
|
101
119
|
end
|
102
120
|
end
|
103
121
|
|
122
|
+
def self.multithreaded?
|
123
|
+
Bindings.is_multithreaded.to_bool
|
124
|
+
end
|
125
|
+
|
126
|
+
# Deallocate and destroy all ManagedStatic variables.
|
127
|
+
#
|
128
|
+
# @return [void]
|
129
|
+
def self.shutdown
|
130
|
+
Bindings.shutdown
|
131
|
+
end
|
132
|
+
|
133
|
+
# Initialize LLVM's multithreaded infrestructure.
|
134
|
+
#
|
135
|
+
# @return [void]
|
136
|
+
def self.start_multithreaded
|
137
|
+
Bindings.start_multithreaded
|
138
|
+
end
|
139
|
+
|
140
|
+
# Shutdown and cleanup LLVM's multithreaded infrastructure.
|
141
|
+
def self.stop_multithreaded
|
142
|
+
Bindings.stop_multithreaded
|
143
|
+
end
|
144
|
+
|
104
145
|
# @return [String] String representing the version of LLVM targeted by these bindings.
|
105
146
|
def self.version
|
106
147
|
RLTK::LLVM_TARGET_VERSION
|
@@ -14,7 +14,7 @@ require 'rltk/cg/bindings'
|
|
14
14
|
# Classes and Modules #
|
15
15
|
#######################
|
16
16
|
|
17
|
-
module RLTK::CG
|
17
|
+
module RLTK::CG
|
18
18
|
|
19
19
|
# This class is used by the {Module} class to dump and load LLVM bitcode.
|
20
20
|
class MemoryBuffer
|
@@ -26,7 +26,7 @@ module RLTK::CG # :nodoc:
|
|
26
26
|
# Create a new memory buffer.
|
27
27
|
#
|
28
28
|
# @param [FFI::Pointer, String, nil] overloaded This parameter may be either a pointer to an existing memory
|
29
|
-
# buffer, the name of a file containing LLVM bitcode, or nil. If it is nil the memory buffer will read
|
29
|
+
# buffer, the name of a file containing LLVM bitcode or IR, or nil. If it is nil the memory buffer will read
|
30
30
|
# from standard in.
|
31
31
|
def initialize(overloaded = nil)
|
32
32
|
@ptr =
|
@@ -45,14 +45,31 @@ module RLTK::CG # :nodoc:
|
|
45
45
|
Bindings.create_memory_buffer_with_stdin(buf_ptr, msg_ptr)
|
46
46
|
end
|
47
47
|
|
48
|
-
|
49
|
-
|
50
|
-
|
48
|
+
if status.zero?
|
49
|
+
buf_ptr.get_pointer(0)
|
50
|
+
else
|
51
|
+
raise msg_ptr.get_pointer(0).get_string(0)
|
52
|
+
end
|
51
53
|
end
|
52
54
|
|
53
55
|
# Define a finalizer to free the memory used by LLVM for this
|
54
56
|
# memory buffer.
|
55
57
|
ObjectSpace.define_finalizer(self, CLASS_FINALIZER)
|
56
58
|
end
|
59
|
+
|
60
|
+
# Get the size of the memory buffer.
|
61
|
+
#
|
62
|
+
# @return [Integer] Size of memory buffer
|
63
|
+
def size
|
64
|
+
Bindings.get_buffer_size(@ptr)
|
65
|
+
end
|
66
|
+
|
67
|
+
# Get a copy of the memory buffer, from the beginning, as a sequence
|
68
|
+
# of characters.
|
69
|
+
#
|
70
|
+
# @return [String]
|
71
|
+
def start
|
72
|
+
Bindings.get_buffer_start(@ptr)
|
73
|
+
end
|
57
74
|
end
|
58
75
|
end
|