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.



46
47
48
# File 'lib/llvm/core/bitcode.rb', line 46

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:



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

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:



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

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



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

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

#to_ptrObject



51
52
53
# File 'lib/llvm/core/bitcode.rb', line 51

def to_ptr
  @ptr
end