Class: Inliner::Builder
- Inherits:
-
Object
- Object
- Inliner::Builder
- Defined in:
- lib/ffi-inliner/inliner.rb
Instance Attribute Summary collapse
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#compiler ⇒ Object
readonly
Returns the value of attribute compiler.
Instance Method Summary collapse
- #build ⇒ Object
- #c(code) ⇒ Object
- #c_raw(code) ⇒ Object
- #include(fn, options = {}) ⇒ Object
-
#initialize(mod, code = "", options = {}) ⇒ Builder
constructor
A new instance of Builder.
- #library(*libraries) ⇒ Object
- #map(type_map) ⇒ Object
- #struct(ffi_struct) ⇒ Object
- #use_compiler(compiler) ⇒ Object
Constructor Details
#initialize(mod, code = "", options = {}) ⇒ Builder
Returns a new instance of Builder.
126 127 128 129 130 131 132 133 134 |
# File 'lib/ffi-inliner/inliner.rb', line 126 def initialize(mod, code = "", = {}) make_pointer_types @mod = mod @code = code @sig = [parse_signature(@code)] unless @code.empty? = { :use_compiler => Compilers::GCC }.merge() @compiler = [:use_compiler] @libraries = [] end |
Instance Attribute Details
#code ⇒ Object (readonly)
Returns the value of attribute code.
125 126 127 |
# File 'lib/ffi-inliner/inliner.rb', line 125 def code @code end |
#compiler ⇒ Object (readonly)
Returns the value of attribute compiler.
125 126 127 |
# File 'lib/ffi-inliner/inliner.rb', line 125 def compiler @compiler end |
Instance Method Details
#build ⇒ Object
169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/ffi-inliner/inliner.rb', line 169 def build @fm = FilenameManager.new(@mod, @code) @compiler = @compiler.check_and_create(@fm, @libraries) unless @fm.cached? write_files(@code, @sig) @compiler.compile @mod.instance_eval generate_ffi(@sig) else @mod.instance_eval(File.read(@fm.rb_fn)) end end |
#c(code) ⇒ Object
148 149 150 151 |
# File 'lib/ffi-inliner/inliner.rb', line 148 def c(code) (@sig ||= []) << parse_signature(code) @code << (@compiler == Compilers::GPlusPlus ? "extern \"C\" {\n#{code}\n}" : code ) end |
#c_raw(code) ⇒ Object
153 154 155 |
# File 'lib/ffi-inliner/inliner.rb', line 153 def c_raw(code) @code << code end |
#include(fn, options = {}) ⇒ Object
140 141 142 |
# File 'lib/ffi-inliner/inliner.rb', line 140 def include(fn, = {}) [:quoted] ? @code << "#include \"#{fn}\"\n" : @code << "#include <#{fn}>\n" end |
#library(*libraries) ⇒ Object
144 145 146 |
# File 'lib/ffi-inliner/inliner.rb', line 144 def library(*libraries) (@libraries ||= []).concat(libraries) end |
#map(type_map) ⇒ Object
136 137 138 |
# File 'lib/ffi-inliner/inliner.rb', line 136 def map(type_map) @types.merge!(type_map) end |
#struct(ffi_struct) ⇒ Object
161 162 163 164 165 166 167 |
# File 'lib/ffi-inliner/inliner.rb', line 161 def struct(ffi_struct) @code << "typedef struct {" ffi_struct.layout.fields.each do |field| @code << "#{field} #{field.name};\n" end @code << "} #{ffi_struct.class.name}" end |
#use_compiler(compiler) ⇒ Object
157 158 159 |
# File 'lib/ffi-inliner/inliner.rb', line 157 def use_compiler(compiler) @compiler = compiler end |