From bc9c47d5180ab28e1a3db4dca80da7512aa6839a Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Mon, 2 Feb 2015 09:34:24 +0900 Subject: allow endian specification of mrb files by `mrbc -e/-E` `mruby -b` now accepts both big/little endian mrb (compiled binary) files. `mrbc` generates mrb files in big endian for .mrb files and in native endian for C files (with -B option specified) by default. If you are cross compiling, you need to specify target endian by -e/-E options if it is different from host endian. --- tools/mrbc/mrbc.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'tools/mrbc') diff --git a/tools/mrbc/mrbc.c b/tools/mrbc/mrbc.c index b51cc4da7..f27f87a5d 100644 --- a/tools/mrbc/mrbc.c +++ b/tools/mrbc/mrbc.c @@ -18,7 +18,7 @@ struct mrbc_args { const char *initname; mrb_bool check_syntax : 1; mrb_bool verbose : 1; - mrb_bool debug_info : 1; + unsigned int flags : 4; }; static void @@ -31,6 +31,8 @@ usage(const char *name) "-v print version number, then turn on verbose mode", "-g produce debugging information", "-B binary output in C language format", + "-e generate little endian iseq data", + "-E generate big endian iseq data", "--verbose run at verbose mode", "--version print the version", "--copyright print the copyright", @@ -114,7 +116,13 @@ parse_args(mrb_state *mrb, int argc, char **argv, struct mrbc_args *args) args->verbose = TRUE; break; case 'g': - args->debug_info = TRUE; + args->flags |= DUMP_DEBUG_INFO; + break; + case 'E': + args->flags = DUMP_ENDIAN_BIG | (args->flags & DUMP_DEBUG_INFO); + break; + case 'e': + args->flags = DUMP_ENDIAN_LIL | (args->flags & DUMP_DEBUG_INFO); break; case 'h': return -1; @@ -143,6 +151,10 @@ parse_args(mrb_state *mrb, int argc, char **argv, struct mrbc_args *args) break; } } + if (args->verbose && args->initname && (args->flags & DUMP_ENDIAN_MASK) == 0) { + fprintf(stderr, "%s: generating %s endian C file. specify -e/-E for cross compiling.\n", + args->prog, bigendian_p() ? "big" : "little"); + } return i; } @@ -222,13 +234,13 @@ dump_file(mrb_state *mrb, FILE *wfp, const char *outfile, struct RProc *proc, st mrb_irep *irep = proc->body.irep; if (args->initname) { - n = mrb_dump_irep_cfunc(mrb, irep, args->debug_info, wfp, args->initname); + n = mrb_dump_irep_cfunc(mrb, irep, args->flags, wfp, args->initname); if (n == MRB_DUMP_INVALID_ARGUMENT) { fprintf(stderr, "%s: invalid C language symbol name\n", args->initname); } } else { - n = mrb_dump_irep_binary(mrb, irep, args->debug_info, wfp); + n = mrb_dump_irep_binary(mrb, irep, args->flags, wfp); } if (n != MRB_DUMP_OK) { fprintf(stderr, "%s: error in mrb dump (%s) %d\n", args->prog, outfile, n); -- cgit v1.2.3