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.



68
69
70
# File 'lib/llvm/core/bitcode.rb', line 68

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:



80
81
82
83
84
85
86
87
88
# File 'lib/llvm/core/bitcode.rb', line 80

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:



92
93
94
95
96
97
98
99
100
# File 'lib/llvm/core/bitcode.rb', line 92

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



102
103
104
105
106
# File 'lib/llvm/core/bitcode.rb', line 102

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

#to_ptrObject



73
74
75
# File 'lib/llvm/core/bitcode.rb', line 73

def to_ptr
  @ptr
end