8000 Binding generation tool; progress towards compiling simple method (#156) · kddnewton/ruby@f78a5d6 · GitHub
[go: up one dir, main page]

Skip to content

Commit f78a5d6

Browse files
authored
Binding generation tool; progress towards compiling simple method (ruby#156)
* Add YJIT bindgen Mainly for ergonomics. See module level docs for the cruby module for design considerations. * new make target `yjit-bindgen` * use autogenerated bindings for two hash related functions We may choose to depend on the clang crate directly rather than bindgen as a more programatic approach might be better for this particular tool. * Export enough so YARV calls YJIT * Bind enough to get into the per block compile loop * We can finish generating putnil;leave, but can't do prologue Made CodeBlock vec a bit bigger so gen_entry_prologue() doesn't bail due to capacity, but then it trips a todo! when it hits cb.align_pos. Time to stop and cut a PR. A couple of new bindings; see bindgen/src/main.rs. * Some comments * Use newly learned Relase-Acquire concurrency model * Add comments and revert `pub` additions * Fix merge build break and copypasta in C code
1 parent 0396cc7 commit f78a5d6

File tree

16 files changed

+638
-123
lines changed

16 files changed

+638
-123
lines changed

defs/gmake.mk

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,8 +371,16 @@ $(YJIT_LIBS): yjit-static-lib
371371
$(empty)
372372

373373
# Put this here instead of in common.mk to avoid breaking nmake builds
374+
# TODO: might need to move for BSD Make support
374375
miniruby$(EXEEXT): $(YJIT_LIBS)
375376

377+
# generate rust bindings. see source for details
378+
.PHONY: yjit-bindgen
379+
yjit-bindgen:
380+
cd '$(top_srcdir)'
381+
# See make recipe for `.c.i`
382+
$(CARGO) run --manifest-path '$(top_srcdir)/yjit/bindgen/Cargo.toml' -- $(CFLAGS) $(XCFLAGS) $(CPPFLAGS)
383+
376384
# Query on the generated rdoc
377385
#
378386
# $ make rdoc:Integer#+

vm_core.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,11 @@ struct rb_iseq_constant_body {
492492
struct rb_mjit_unit *jit_unit;
493493
#endif
494494

495+
// YJIT stores some data per iseq
496+
// TODO(alan) #if YJIT_BUILD here. can't include yjit.h has circular dependency at the moment.
497+
void *yjit_payload;
498+
499+
// TODO(alan) remove this
495500
rb_yjit_block_array_array_t yjit_blocks; // empty, or has a size equal to iseq_size
496501
};
497502

yjit.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// YJIT combined compilation unit. This setup allows spreading functions
22
// across different files without having to worry about putting things
33
// in headers and prefixing function names.
4+
45
#include "internal.h"
56
#include "vm_core.h"
67
#include "vm_callinfo.h"
@@ -74,6 +75,43 @@ rb_iseq_encoded_size(const rb_iseq_t *iseq)
7475
return iseq->body->iseq_size;
7576
}
7677

78+
// TODO(alan): consider using an opaque pointer for the payload rather than a void pointer
79+
void *
80+
rb_iseq_get_yjit_payload(const rb_iseq_t *iseq)
81+
{
82+
RUBY_ASSERT_ALWAYS(IMEMO_TYPE_P(iseq, imemo_iseq));
83+
return iseq->body->yjit_payload;
84+
}
85+
86+
void
87+
rb_iseq_set_yjit_payload(const rb_iseq_t *iseq, void *payload)
88+
{
89+
RUBY_ASSERT_ALWAYS(IMEMO_TYPE_P(iseq, imemo_iseq));
90+
RUBY_ASSERT_ALWAYS(NULL == iseq->body->yjit_payload);
91+
iseq->body->yjit_payload = payload;
92+
}
93+
94+
// Get the PC for a given index in an iseq
95+
VALUE *
96+
rb_iseq_pc_at_idx(const rb_iseq_t *iseq, uint32_t insn_idx)
97+
{
98+
RUBY_ASSERT_ALWAYS(IMEMO_TYPE_P(iseq, imemo_iseq));
99+
RUBY_ASSERT_ALWAYS(insn_idx < iseq->body->iseq_size);
100+
VALUE *encoded = iseq->body->iseq_encoded;
101+
VALUE *pc = &encoded[insn_idx];
102+
return pc;
103+
}
104+
105+
int
106+
rb_iseq_opcode_at_pc(const rb_iseq_t *iseq, const VALUE *pc)
107+
{
108+
// YJIT should only use iseqs after AST to bytecode compilation
109+
RUBY_ASSERT_ALWAYS(FL_TEST_RAW((VALUE)iseq, ISEQ_TRANSLATED));
110+
111+
const VALUE at_pc = *pc;
112+
return rb_vm_insn_addr2opcode((const void *)at_pc);
113+
}
114+
77115
#if YJIT_STATS
78116
// Comments for generated code
79117
struct yjit_comment {

yjit/.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# Build output
2-
/target/
2+
target/
33

4-
Cargo.lock
4+
/Cargo.lock

0 commit comments

Comments
 (0)
0