Class: RLTK::CG::Module
- Includes:
- BindingClass
- Defined in:
- lib/rltk/cg/module.rb
Overview
This class represents a collection of functions, constants, and global variables.
Defined Under Namespace
Classes: FunctionCollection, GlobalCollection
Instance Attribute Summary collapse
-
#engine ⇒ ExecutionEngine?
Execution engine associated with this module.
Attributes included from BindingClass
Class Method Summary collapse
-
.read_bitcode(overloaded) ⇒ Module
Load a module from LLVM bitcode.
-
.read_ir_file(file_name, context = Context.global) ⇒ Module
Load a Module form an LLVM IR file.
Instance Method Summary collapse
-
#compile(file_name, mode = :object, machine = TargetMachine.host, opt_level = 2, verify = true) ⇒ void
Compile this module to an assembly or object file.
-
#context ⇒ Context
Context in which this module exists.
-
#dispose ⇒ void
Frees the resources used by LLVM for this module.
-
#dump ⇒ void
Print the LLVM IR representation of this value to standard error.
-
#function_pass_manager ⇒ FunctionPassManager
(also: #fpm)
Function pass manager for this module.
-
#functions ⇒ FunctionCollection
(also: #funs)
Proxy object for inspecting this module’s functions.
-
#globals ⇒ GlobalCollection
Proxy object for inspecting this module’s global values and variables.
-
#initialize(overloaded, context = nil, &block) ⇒ Module
constructor
Create a new LLVM module.
-
#pass_manager ⇒ PassManager
(also: #pm)
Pass manager for this module.
-
#print(io = $stdout) ⇒ void
Print the LLVM IR representation of this module to a file.
-
#target ⇒ String
Get the module’s target triple.
-
#target=(triple) ⇒ void
Set the module’s target triple.
-
#verify ⇒ nil, String
Verify that the module is valid LLVM IR.
-
#verify! ⇒ nil
Verify that a module is valid LLVM IR and abort the process if it isn’t.
-
#write_bitcode(overloaded) ⇒ Boolean
Write the module as LLVM bitcode to a file.
Methods included from BindingClass
Constructor Details
#initialize(overloaded, context = nil, &block) ⇒ Module
Create a new LLVM module.
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/rltk/cg/module.rb', line 65 def initialize(overloaded, context = nil, &block) @ptr = case overloaded when FFI::Pointer overloaded when String if context Bindings.module_create_with_name_in_context(overloaded, check_type(context, Context, 'context')) else Bindings.module_create_with_name(overloaded) end end self.instance_exec(&block) if block end |
Instance Attribute Details
#engine ⇒ ExecutionEngine?
Returns Execution engine associated with this module.
27 28 29 |
# File 'lib/rltk/cg/module.rb', line 27 def engine @engine end |
Class Method Details
.read_bitcode(overloaded) ⇒ Module
Load a module from LLVM bitcode.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/rltk/cg/module.rb', line 36 def self.read_bitcode(overloaded) buffer = if overloaded.is_a?(MemoryBuffer) then overloaded else MemoryBuffer.new(overloaded) end mod_ptr = FFI::MemoryPointer.new(:pointer) msg_ptr = FFI::MemoryPointer.new(:pointer) status = Bindings.parse_bitcode(buffer, mod_ptr, msg_ptr) if status != 0 raise msg_ptr.get_pointer(0).get_string(0) else Module.new(mod_ptr.get_pointer(0)) end end |
.read_ir_file(file_name, context = Context.global) ⇒ Module
Load a Module form an LLVM IR file.
56 57 58 |
# File 'lib/rltk/cg/module.rb', line 56 def self.read_ir_file(file_name, context = Context.global) self.new(Bindings.load_module_from_ir_file(file_name, context)) end |
Instance Method Details
#compile(file_name, mode = :object, machine = TargetMachine.host, opt_level = 2, verify = true) ⇒ void
This method returns an undefined value.
Compile this module to an assembly or object file.
91 92 93 |
# File 'lib/rltk/cg/module.rb', line 91 def compile(file_name, mode = :object, machine = TargetMachine.host, opt_level = 2, verify = true) Bindings.compile_module_to_file(@ptr, machine, self.pm, file_name, mode, opt_level, (!verify).to_i) end |
#context ⇒ Context
Returns Context in which this module exists.
96 97 98 |
# File 'lib/rltk/cg/module.rb', line 96 def context Context.new(Bindings.get_module_context(@ptr)) end |
#dispose ⇒ void
This method returns an undefined value.
Frees the resources used by LLVM for this module.
103 104 105 106 107 108 109 |
# File 'lib/rltk/cg/module.rb', line 103 def dispose if @ptr Bindings.dispose_module(@ptr) @ptr = nil end end |
#dump ⇒ void
This method returns an undefined value.
Print the LLVM IR representation of this value to standard error. This function is the debugging version of the more general purpose #print method.
118 119 120 |
# File 'lib/rltk/cg/module.rb', line 118 def dump Bindings.dump_module(@ptr) end |
#function_pass_manager ⇒ FunctionPassManager Also known as: fpm
Returns Function pass manager for this module.
123 124 125 |
# File 'lib/rltk/cg/module.rb', line 123 def function_pass_manager @function_pass_manager ||= FunctionPassManager.new(self) end |
#functions ⇒ FunctionCollection Also known as: funs
Returns Proxy object for inspecting this module’s functions.
155 156 157 |
# File 'lib/rltk/cg/module.rb', line 155 def functions @functions ||= FunctionCollection.new(self) end |
#globals ⇒ GlobalCollection
Returns Proxy object for inspecting this module’s global values and variables.
161 162 163 |
# File 'lib/rltk/cg/module.rb', line 161 def globals @globals ||= GlobalCollection.new(self) end |
#pass_manager ⇒ PassManager Also known as: pm
Returns Pass manager for this module.
129 130 131 |
# File 'lib/rltk/cg/module.rb', line 129 def pass_manager @pass_manager ||= PassManager.new(self) end |
#print(io = $stdout) ⇒ void
This method returns an undefined value.
Print the LLVM IR representation of this module to a file. The file may be specified via a file name (which will be created or truncated) or an object that responds to #fileno.
143 144 145 146 147 148 149 150 151 152 |
# File 'lib/rltk/cg/module.rb', line 143 def print(io = $stdout) case io when String File.open(io, 'w') do |f| Bindings.print_module(@ptr, f.fileno) end else Bindings.print_module(@ptr, io.fileno) end end |
#target ⇒ String
Get the module’s target triple.
177 178 179 |
# File 'lib/rltk/cg/module.rb', line 177 def target Bindings.get_target(@ptr) end |
#target=(triple) ⇒ void
This method returns an undefined value.
Set the module’s target triple.
170 171 172 |
# File 'lib/rltk/cg/module.rb', line 170 def target=(triple) Bindings.set_target(@ptr, triple) end |
#verify ⇒ nil, String
Verify that the module is valid LLVM IR.
205 206 207 |
# File 'lib/rltk/cg/module.rb', line 205 def verify do_verification(:return_status) end |
#verify! ⇒ nil
Verify that a module is valid LLVM IR and abort the process if it isn’t.
212 213 214 |
# File 'lib/rltk/cg/module.rb', line 212 def verify! do_verification(:abort_process) end |
#write_bitcode(overloaded) ⇒ Boolean
Write the module as LLVM bitcode to a file.
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/rltk/cg/module.rb', line 186 def write_bitcode(overloaded) 0 == if overloaded.respond_to?(:path) Bindings.write_bitcode_to_file(@ptr, overloaded.path) elsif overloaded.respond_to?(:fileno) Bindings.write_bitcode_to_fd(@ptr, overloaded.fileno, 0, 1) elsif overloaded.is_a?(Integer) Bindings.write_bitcode_to_fd(@ptr, overloaded, 0, 1) elsif overloaded.is_a?(String) Bindings.write_bitcode_to_file(@ptr, overloaded) end end |