Class: AsmJIT::CodeHolder
- Inherits:
-
Object
- Object
- AsmJIT::CodeHolder
- Defined in:
- lib/asmjit.rb,
ext/asmjit/asmjit.cc
Instance Method Summary collapse
- #assembler ⇒ Object
- #binary ⇒ Object
- #def_class(arity, method_name: :call) ⇒ Object
- #def_method(mod, name, arity_val) ⇒ Object
- #def_module(arity, method_name: :call) ⇒ Object
- #initialize ⇒ Object constructor
- #to_fiddle(inputs: nil, output: nil) ⇒ Object
- #to_ptr ⇒ Object
Constructor Details
#initialize ⇒ Object
55 56 57 58 59 60 61 62 63 |
# File 'ext/asmjit/asmjit.cc', line 55
VALUE code_holder_initialize(VALUE self) {
CodeHolderWrapper *wrapper;
TypedData_Get_Struct(self, CodeHolderWrapper, &code_holder_type, wrapper);
CodeHolder *code = wrapper->code;
code->init(jit_runtime.environment());
return self;
}
|
Instance Method Details
#assembler ⇒ Object
15 16 17 |
# File 'lib/asmjit.rb', line 15 def assembler X86::Assembler.new(self) end |
#binary ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'ext/asmjit/asmjit.cc', line 98
VALUE code_holder_binary(VALUE self) {
CodeHolderWrapper *wrapper;
TypedData_Get_Struct(self, CodeHolderWrapper, &code_holder_type, wrapper);
CodeHolder *code = wrapper->code;
CodeBuffer buffer = code->sectionById(0)->buffer();
return rb_str_new(
reinterpret_cast<const char *>(buffer.data()),
buffer.size()
);
}
|
#def_class(arity, method_name: :call) ⇒ Object
35 36 37 38 39 |
# File 'lib/asmjit.rb', line 35 def def_class(arity, method_name: :call) mod = Class.new self.def_method(mod, method_name, arity) mod end |
#def_method(mod, name, arity_val) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'ext/asmjit/asmjit.cc', line 79
VALUE code_holder_define_method(VALUE self, VALUE mod, VALUE name, VALUE arity_val) {
CodeHolderWrapper *wrapper;
TypedData_Get_Struct(self, CodeHolderWrapper, &code_holder_type, wrapper);
CodeHolder *code = wrapper->code;
int arity = FIX2INT(arity_val);
ID id = rb_sym2id(name);
VALUE (*fn)(ANYARGS);
jit_runtime.add(&fn, code);
// avoid cxxanyargs
#undef rb_define_method_id
rb_define_method_id(mod, id, fn, arity);
return name;
}
|
#def_module(arity, method_name: :call) ⇒ Object
29 30 31 32 33 |
# File 'lib/asmjit.rb', line 29 def def_module(arity, method_name: :call) mod = Module.new self.def_method(mod, method_name, arity) mod end |
#to_fiddle(inputs: nil, output: nil) ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/asmjit.rb', line 19 def to_fiddle(inputs: nil, output: nil) ptr = to_ptr Fiddle::Function.new( ptr, inputs || [], output || Fiddle::TYPE_INT ) end |
#to_ptr ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 |
# File 'ext/asmjit/asmjit.cc', line 65
VALUE code_holder_to_ptr(VALUE self) {
CodeHolderWrapper *wrapper;
TypedData_Get_Struct(self, CodeHolderWrapper, &code_holder_type, wrapper);
CodeHolder *code = wrapper->code;
int (*fn)(void);
jit_runtime.add(&fn, code);
return ULL2NUM(uintptr_t(fn));
}
|