Class: RLTK::CG::MemoryBuffer
- Inherits:
-
Object
- Object
- RLTK::CG::MemoryBuffer
- Includes:
- BindingClass
- Defined in:
- lib/rltk/cg/memory_buffer.rb
Overview
This class is used by the Module class to dump and load LLVM bitcode.
Constant Summary collapse
- CLASS_FINALIZER =
The Proc object called by the garbage collector to free resources used by LLVM.
Proc.new { |id| Bindings.dispose_memory_buffer(ptr) if ptr = ObjectSpace._id2ref(id).ptr }
Instance Attribute Summary
Attributes included from BindingClass
Instance Method Summary collapse
-
#initialize(overloaded = nil) ⇒ MemoryBuffer
constructor
Create a new memory buffer.
-
#size ⇒ Integer
Get the size of the memory buffer.
-
#start ⇒ String
Get a copy of the memory buffer, from the beginning, as a sequence of characters.
Methods included from BindingClass
Constructor Details
#initialize(overloaded = nil) ⇒ MemoryBuffer
Create a new memory buffer.
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 |
# File 'lib/rltk/cg/memory_buffer.rb', line 31 def initialize(overloaded = nil) @ptr = case overloaded when FFI::Pointer overloaded else buf_ptr = FFI::MemoryPointer.new(:pointer) msg_ptr = FFI::MemoryPointer.new(:pointer) status = case overloaded when String Bindings.create_memory_buffer_with_contents_of_file(overloaded, buf_ptr, msg_ptr) else Bindings.create_memory_buffer_with_stdin(buf_ptr, msg_ptr) end if status.zero? buf_ptr.get_pointer(0) else raise msg_ptr.get_pointer(0).get_string(0) end end # Define a finalizer to free the memory used by LLVM for this # memory buffer. ObjectSpace.define_finalizer(self, CLASS_FINALIZER) end |
Instance Method Details
#size ⇒ Integer
Get the size of the memory buffer.
63 64 65 |
# File 'lib/rltk/cg/memory_buffer.rb', line 63 def size Bindings.get_buffer_size(@ptr) end |
#start ⇒ String
Get a copy of the memory buffer, from the beginning, as a sequence of characters.
71 72 73 |
# File 'lib/rltk/cg/memory_buffer.rb', line 71 def start Bindings.get_buffer_start(@ptr) end |