Class: LLVM::MemoryBuffer

Inherits:
Object
  • Object
show all
Defined in:
lib/llvm/core/bitcode.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ptr) ⇒ MemoryBuffer

Returns a new instance of MemoryBuffer.


44
45
46
# File 'lib/llvm/core/bitcode.rb', line 44

def initialize(ptr)
  @ptr = ptr
end

Class Method Details

.from_file(path) ⇒ LLVM::MemoryBuffer

Read the contents of a file into a memory buffer

Parameters:

  • path (String)

Returns:


56
57
58
59
60
61
62
63
64
# File 'lib/llvm/core/bitcode.rb', line 56

def self.from_file(path)
  FFI::MemoryPointer.new(:pointer) do |buf_ref|
    FFI::MemoryPointer.new(:pointer) do |msg_ref|
      status = C.create_memory_buffer_with_contents_of_file(path.to_str, buf_ref, msg_ref)
      raise msg_ref.get_pointer(0).get_string(0) if status != 0
      return new(buf_ref.get_pointer(0))
    end
  end
end

.from_stdinLLVM::MemoryBuffer

Read STDIN into a memory buffer

Returns:


68
69
70
71
72
73
74
75
76
# File 'lib/llvm/core/bitcode.rb', line 68

def self.from_stdin
  FFI::Buffer.new(:pointer) do |buf_ref|
    FFI::Buffer.new(:pointer) do |msg_ref|
      status = C.create_memory_buffer_with_stdin(buf_ref, msg_ref)
      raise msg_ref.get_pointer(0).get_string(0) if status != 0
      return new(buf_ref.get_pointer(0))
    end
  end
end

Instance Method Details

#disposeObject


78
79
80
81
82
# File 'lib/llvm/core/bitcode.rb', line 78

def dispose
  return if @ptr.nil?
  C.dispose_memory_buffer(@ptr)
  @ptr = nil
end

#to_ptrObject


49
50
51
# File 'lib/llvm/core/bitcode.rb', line 49

def to_ptr
  @ptr
end