summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common.mk5
-rw-r--r--template/builtin_binary.inc.tmpl30
-rw-r--r--tool/mk_builtin_binary.rb44
3 files changed, 33 insertions, 46 deletions
diff --git a/common.mk b/common.mk
index 053b9b4f69..b428a4deff 100644
--- a/common.mk
+++ b/common.mk
@@ -1121,8 +1121,9 @@ preludes: {$(srcdir)}golf_prelude.c
$(ECHO) making $@
$(Q) $(BASERUBY) $(tooldir)/mk_builtin_loader.rb $<
-builtin_binary.inc: $(PREP) $(BUILTIN_RB_SRCS) $(tooldir)/mk_builtin_binary.rb
- $(Q) $(MINIRUBY) $(tooldir)/mk_builtin_binary.rb --cross=$(CROSS_COMPILING)
+builtin_binary.inc: $(PREP) $(BUILTIN_RB_SRCS) $(srcdir)/template/builtin_binary.inc.tmpl
+ $(Q) $(MINIRUBY) $(tooldir)/generic_erb.rb -c -o $@ \
+ $(srcdir)/template/builtin_binary.inc.tmpl -- --cross=$(CROSS_COMPILING)
$(BUILTIN_RB_INCS): $(top_srcdir)/tool/mk_builtin_loader.rb
diff --git a/template/builtin_binary.inc.tmpl b/template/builtin_binary.inc.tmpl
new file mode 100644
index 0000000000..eb0bded3d9
--- /dev/null
+++ b/template/builtin_binary.inc.tmpl
@@ -0,0 +1,30 @@
+// -*- c -*-
+% ary = RubyVM.enum_for(:each_builtin).to_a
+// DO NOT MODIFY THIS FILE DIRECTLY.
+// auto-generated file by tool/generic_erb.rb
+// with template/builtin_binary.inc.tmpl
+% unless ARGV.include?('--corss=yes')
+% ary.each{|feature, iseq|
+
+static const unsigned char <%= feature %>_bin[] = {
+% iseq \
+% . to_binary \
+% . each_byte \
+% . map(&:ord) \
+% . map{ '0x%02x' % _1 } \
+% . each_slice(12) {|a|
+ <%= a.join(', ') %>,
+% }
+};
+% }
+
+static const struct builtin_binary builtin_binary[] = {
+% ary.each{|feature, |
+ { <%= feature.dump %>, <%= feature %>_bin, sizeof(<%= feature %>_bin), },
+% }
+ { NULL, },<%# dummy entry %>
+};
+
+#define BUILTIN_BINARY_SIZE <%= ary.size %>
+STATIC_ASSERT(n_builtin, numberof(builtin_binary) == BUILTIN_BINARY_SIZE + 1);
+% end
diff --git a/tool/mk_builtin_binary.rb b/tool/mk_builtin_binary.rb
deleted file mode 100644
index 1b3fe50ac9..0000000000
--- a/tool/mk_builtin_binary.rb
+++ /dev/null
@@ -1,44 +0,0 @@
-#
-# make builtin_binary.inc file.
-#
-
-def dump_bin iseq
- bin = iseq.to_binary
- bin.each_byte.with_index{|b, index|
- print "\n " if (index%20) == 0
- print " 0x#{'%02x' % b.ord},"
- }
- print "\n"
-end
-
-$stdout = open('builtin_binary.inc', 'wb')
-
-puts <<H
-// -*- c -*-
-// DO NOT MODIFY THIS FILE DIRECTLY.
-// auto-generated file by #{File.basename(__FILE__)}
-
-H
-
-if ARGV.include?('--cross=yes')
- # do nothing
-else
- ary = []
- RubyVM::each_builtin{|feature, iseq|
- ary << [feature, iseq]
- }
-
- ary.each{|feature, iseq|
- print "\n""static const unsigned char #{feature}_bin[] = {"
- dump_bin(iseq)
- puts "};"
- }
-
- print "\n""static const struct builtin_binary builtin_binary[] = {\n"
- ary.each{|feature, iseq|
- puts " {#{feature.dump}, #{feature}_bin, sizeof(#{feature}_bin)},"
- }
- puts " {NULL}," # dummy sentry
- puts "};"
- puts "#define BUILTIN_BINARY_SIZE #{ary.size}"
-end