Class: LLVM::Module
- Inherits:
-
Object
- Object
- LLVM::Module
- Defined in:
- lib/llvm/analysis.rb,
lib/llvm/core/module.rb,
lib/llvm/core/bitcode.rb
Defined Under Namespace
Classes: FunctionCollection, GlobalCollection, TypeCollection
Class Method Summary collapse
- .from_ptr(ptr) ⇒ Object
-
.parse_bitcode(path_or_memory_buffer) ⇒ LLVM::Module
Parse a module from a memory buffer.
Instance Method Summary collapse
-
#==(other) ⇒ Object
Checks if the module is equal to other.
-
#dispose ⇒ Object
Dispose the module.
-
#dump ⇒ Object
Print the module’s IR to stdout.
-
#eql?(other) ⇒ Boolean
Checks if the module is equal to other.
-
#functions ⇒ Object
Returns a FunctionCollection of all the Functions in the module.
-
#globals ⇒ Object
Returns an Enumerable of all the GlobalVariables in the module.
-
#initialize(name) ⇒ Module
constructor
A new instance of Module.
- #to_ptr ⇒ Object
-
#types ⇒ Object
Returns a TypeCollection of all the Types in the module.
-
#verify ⇒ nil, String
Verify that the module is valid.
-
#verify! ⇒ nil
Verify that a module is valid, and abort the process if not.
-
#write_bitcode(path_or_io) ⇒ true, false
Write bitcode to the given path, IO object or file descriptor.
Constructor Details
Class Method Details
.from_ptr(ptr) ⇒ Object
4 5 6 7 8 9 |
# File 'lib/llvm/core/module.rb', line 4 def self.from_ptr(ptr) return if ptr.null? mod = allocate mod.instance_variable_set(:@ptr, ptr) mod end |
.parse_bitcode(path_or_memory_buffer) ⇒ LLVM::Module
Parse a module from a memory buffer
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/llvm/core/bitcode.rb', line 14 def self.parse_bitcode(path_or_memory_buffer) memory_buffer = case path_or_memory_buffer when MemoryBuffer then path_or_memory_buffer else MemoryBuffer.from_file(path_or_memory_buffer) end FFI::MemoryPointer.new(:pointer) do |mod_ref| FFI::MemoryPointer.new(:pointer) do |msg_ref| status = C.LLVMParseBitcode(memory_buffer, mod_ref, msg_ref) raise msg_ref.get_pointer(0).get_string(0) if status != 0 return from_ptr(mod_ref.get_pointer(0)) end end end |
Instance Method Details
#==(other) ⇒ Object
Checks if the module is equal to other.
21 22 23 24 25 26 27 28 |
# File 'lib/llvm/core/module.rb', line 21 def ==(other) case other when LLVM::Module @ptr == other.to_ptr else false end end |
#dispose ⇒ Object
Dispose the module.
228 229 230 |
# File 'lib/llvm/core/module.rb', line 228 def dispose C.LLVMDisposeModule(@ptr) end |
#dump ⇒ Object
Print the module’s IR to stdout.
223 224 225 |
# File 'lib/llvm/core/module.rb', line 223 def dump C.LLVMDumpModule(self) end |
#eql?(other) ⇒ Boolean
Checks if the module is equal to other.
31 32 33 |
# File 'lib/llvm/core/module.rb', line 31 def eql?(other) other.instance_of?(self.class) && self == other end |
#functions ⇒ Object
Returns a FunctionCollection of all the Functions in the module.
139 140 141 |
# File 'lib/llvm/core/module.rb', line 139 def functions @functions ||= FunctionCollection.new(self) end |
#globals ⇒ Object
Returns an Enumerable of all the GlobalVariables in the module.
67 68 69 |
# File 'lib/llvm/core/module.rb', line 67 def globals @globals ||= GlobalCollection.new(self) end |
#to_ptr ⇒ Object
16 17 18 |
# File 'lib/llvm/core/module.rb', line 16 def to_ptr @ptr end |
#types ⇒ Object
Returns a TypeCollection of all the Types in the module.
36 37 38 |
# File 'lib/llvm/core/module.rb', line 36 def types @types ||= TypeCollection.new(self) end |
#verify ⇒ nil, String
Verify that the module is valid.
22 23 24 |
# File 'lib/llvm/analysis.rb', line 22 def verify do_verification(:return_status) end |
#verify! ⇒ nil
Verify that a module is valid, and abort the process if not.
28 29 30 |
# File 'lib/llvm/analysis.rb', line 28 def verify! do_verification(:abort_process) end |
#write_bitcode(path_or_io) ⇒ true, false
Write bitcode to the given path, IO object or file descriptor
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/llvm/core/bitcode.rb', line 31 def write_bitcode(path_or_io) status = if path_or_io.respond_to?(:path) C.LLVMWriteBitcodeToFile(self, path_or_io.path) elsif path_or_io.respond_to?(:fileno) C.LLVMWriteBitcodeToFD(self, path_or_io.fileno, 0, 1) elsif path_or_io.kind_of?(Integer) C.LLVMWriteBitcodeToFD(self, path_or_io, 0, 1) else C.LLVMWriteBitcodeToFile(self, path_or_io.to_str) end return status == 0 end |