mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
e427fdff0a
This lets us use libcapstone directly from miniruby so we don't need a Ruby Gem to to dev work. Example usage: ```ruby def foo(x) if x < 1 "wow" else "neat" end end iseq = RubyVM::InstructionSequence.of(method(:foo)) puts UJIT.disasm(iseq) 100.times { foo 1 } puts UJIT.disasm(iseq) ``` Then in the terminal ``` $ ./miniruby test.rb == disasm: #<ISeq:foo@test.rb:1 (1,0)-(7,3)> (catch: FALSE) local table (size: 1, argc: 1 [opts: 0, rest: -1, post: 0, block: -1, kw: -1@-1, kwrest: -1]) [ 1] x@0<Arg> 0000 getlocal_WC_0 x@0 ( 2)[LiCa] 0002 putobject_INT2FIX_1_ 0003 opt_lt <calldata!mid:<, argc:1, ARGS_SIMPLE> 0005 branchunless 10 0007 putstring "wow" ( 3)[Li] 0009 leave ( 7)[Re] 0010 putstring "neat" ( 5)[Li] 0012 leave ( 7)[Re] == ISEQ RANGE: 10 -> 10 ======================================================== 0x0: movabs rax, 0x7fe816e2d1a0 0xa: mov qword ptr [rdi], rax 0xd: mov r8, rax 0x10: mov r9, rax 0x13: mov r11, r12 0x16: jmp qword ptr [rax] == ISEQ RANGE: 0 -> 7 ========================================================== 0x0: mov rax, qword ptr [rdi + 0x20] 0x4: mov rax, qword ptr [rax - 0x18] 0x8: mov qword ptr [rdx], rax 0xb: mov qword ptr [rdx + 8], 3 0x13: movabs rax, 0x7fe817808200 0x1d: test byte ptr [rax + 0x3e6], 1 0x24: jne 0x3ffff7b 0x2a: test byte ptr [rdx], 1 0x2d: je 0x3ffff7b 0x33: test byte ptr [rdx + 8], 1 0x37: je 0x3ffff7b 0x3d: mov rax, qword ptr [rdx] 0x40: cmp rax, qword ptr [rdx + 8] 0x44: movabs rax, 0 0x4e: movabs rcx, 0x14 0x58: cmovl rax, rcx 0x5c: mov qword ptr [rdx], rax 0x5f: test qword ptr [rdx], -9 0x66: jne 0x3ffffd5 ``` Make sure to `brew install pkg-config capstone`
105 lines
2 KiB
C
105 lines
2 KiB
C
/**********************************************************************
|
|
|
|
inits.c -
|
|
|
|
$Author$
|
|
created at: Tue Dec 28 16:01:58 JST 1993
|
|
|
|
Copyright (C) 1993-2007 Yukihiro Matsumoto
|
|
|
|
**********************************************************************/
|
|
|
|
#include "internal/inits.h"
|
|
#include "ruby.h"
|
|
#include "builtin.h"
|
|
static void Init_builtin_prelude(void);
|
|
#include "prelude.rbinc"
|
|
|
|
#define CALL(n) {void Init_##n(void); Init_##n();}
|
|
|
|
void
|
|
rb_call_inits(void)
|
|
{
|
|
CALL(Thread_Mutex);
|
|
#if USE_TRANSIENT_HEAP
|
|
CALL(TransientHeap);
|
|
#endif
|
|
CALL(vm_postponed_job);
|
|
CALL(Method);
|
|
CALL(RandomSeedCore);
|
|
CALL(encodings);
|
|
CALL(sym);
|
|
CALL(var_tables);
|
|
CALL(Object);
|
|
CALL(top_self);
|
|
CALL(Encoding);
|
|
CALL(Comparable);
|
|
CALL(Enumerable);
|
|
CALL(String);
|
|
CALL(Exception);
|
|
CALL(eval);
|
|
CALL(jump);
|
|
CALL(Numeric);
|
|
CALL(Bignum);
|
|
CALL(syserr);
|
|
CALL(Array);
|
|
CALL(Hash);
|
|
CALL(Struct);
|
|
CALL(Regexp);
|
|
CALL(pack);
|
|
CALL(transcode);
|
|
CALL(marshal);
|
|
CALL(Range);
|
|
CALL(IO);
|
|
CALL(Dir);
|
|
CALL(Time);
|
|
CALL(Random);
|
|
CALL(signal);
|
|
CALL(load);
|
|
CALL(Proc);
|
|
CALL(Binding);
|
|
CALL(Math);
|
|
CALL(GC);
|
|
CALL(Enumerator);
|
|
CALL(Ractor);
|
|
CALL(VM);
|
|
CALL(ISeq);
|
|
CALL(Thread);
|
|
CALL(Fiber_Scheduler);
|
|
CALL(process);
|
|
CALL(Cont);
|
|
CALL(Rational);
|
|
CALL(Complex);
|
|
CALL(MemoryView);
|
|
CALL(version);
|
|
CALL(vm_trace);
|
|
CALL(vm_stack_canary);
|
|
CALL(ast);
|
|
CALL(gc_stress);
|
|
|
|
// enable builtin loading
|
|
CALL(builtin);
|
|
}
|
|
|
|
void
|
|
rb_call_builtin_inits(void)
|
|
{
|
|
#define BUILTIN(n) CALL(builtin_##n)
|
|
BUILTIN(gc);
|
|
BUILTIN(ractor);
|
|
BUILTIN(numeric);
|
|
BUILTIN(io);
|
|
BUILTIN(dir);
|
|
BUILTIN(ast);
|
|
BUILTIN(trace_point);
|
|
BUILTIN(pack);
|
|
BUILTIN(warning);
|
|
BUILTIN(array);
|
|
BUILTIN(kernel);
|
|
BUILTIN(timev);
|
|
BUILTIN(nilclass);
|
|
BUILTIN(marshal);
|
|
BUILTIN(ujit);
|
|
Init_builtin_prelude();
|
|
}
|
|
#undef CALL
|