summaryrefslogtreecommitdiff
path: root/tool
diff options
context:
space:
mode:
authorTakashi Kokubun <takashikkbn@gmail.com>2022-11-27 15:15:52 -0800
committerTakashi Kokubun <takashikkbn@gmail.com>2022-11-27 21:11:33 -0800
commit6844bcc6b4cdc50def1c0d30d4e8b5045fb43443 (patch)
treee76f3b03120395c52007d1fcaec6e42ace508561 /tool
parent6d26f78f684607a39249882ea686a231f8768bd5 (diff)
MJIT: Use a String buffer in builtin compilers
instead of FILE*. Using C.fprintf is slower than String manipulation on memory. I'm going to change the way MJIT writes files, and this is a prerequisite for it.
Diffstat (limited to 'tool')
-rw-r--r--tool/mk_builtin_loader.rb18
1 files changed, 9 insertions, 9 deletions
diff --git a/tool/mk_builtin_loader.rb b/tool/mk_builtin_loader.rb
index 6b4ae121d9..c4f36889d6 100644
--- a/tool/mk_builtin_loader.rb
+++ b/tool/mk_builtin_loader.rb
@@ -325,10 +325,10 @@ def mk_builtin_header file
. map {|i|", argv[#{i}]"} \
. join('')
f.puts %'static void'
- f.puts %'mjit_compile_invokebuiltin_for_#{func}(FILE *f, long index, unsigned stack_size, bool inlinable_p)'
+ f.puts %'mjit_compile_invokebuiltin_for_#{func}(VALUE buf, long index, unsigned stack_size, bool inlinable_p)'
f.puts %'{'
- f.puts %' fprintf(f, " VALUE self = GET_SELF();\\n");'
- f.puts %' fprintf(f, " typedef VALUE (*func)(rb_execution_context_t *, VALUE#{decl});\\n");'
+ f.puts %' rb_str_catf(buf, " VALUE self = GET_SELF();\\n");'
+ f.puts %' rb_str_catf(buf, " typedef VALUE (*func)(rb_execution_context_t *, VALUE#{decl});\\n");'
if inlines.has_key? cfunc_name
body_lineno, text, locals, func_name = inlines[cfunc_name]
lineno, str = generate_cexpr(ofile, lineno, line_file, body_lineno, text, locals, func_name)
@@ -336,22 +336,22 @@ def mk_builtin_header file
str.gsub(/^(?!#)/, ' ').each_line {|i|
j = RubyVM::CEscape.rstring2cstr(i).dup
j.sub!(/^ return\b/ , ' val =')
- f.printf(%' fprintf(f, "%%s", %s);\n', j)
+ f.printf(%' rb_str_catf(buf, "%%s", %s);\n', j)
}
f.puts(%' return;')
f.puts(%' }')
end
if argc > 0
f.puts %' if (index == -1) {'
- f.puts %' fprintf(f, " const VALUE *argv = &stack[%d];\\n", stack_size - #{argc});'
+ f.puts %' rb_str_catf(buf, " const VALUE *argv = &stack[%d];\\n", stack_size - #{argc});'
f.puts %' }'
f.puts %' else {'
- f.puts %' fprintf(f, " const unsigned int lnum = ISEQ_BODY(GET_ISEQ())->local_table_size;\\n");'
- f.puts %' fprintf(f, " const VALUE *argv = GET_EP() - lnum - VM_ENV_DATA_SIZE + 1 + %ld;\\n", index);'
+ f.puts %' rb_str_catf(buf, " const unsigned int lnum = ISEQ_BODY(GET_ISEQ())->local_table_size;\\n");'
+ f.puts %' rb_str_catf(buf, " const VALUE *argv = GET_EP() - lnum - VM_ENV_DATA_SIZE + 1 + %ld;\\n", index);'
f.puts %' }'
end
- f.puts %' fprintf(f, " func f = (func)%"PRIuVALUE"; /* == #{cfunc_name} */\\n", (VALUE)#{cfunc_name});'
- f.puts %' fprintf(f, " val = f(ec, self#{argv});\\n");'
+ f.puts %' rb_str_catf(buf, " func f = (func)%"PRIuVALUE"; /* == #{cfunc_name} */\\n", (VALUE)#{cfunc_name});'
+ f.puts %' rb_str_catf(buf, " val = f(ec, self#{argv});\\n");'
f.puts %'}'
f.puts
}