summaryrefslogtreecommitdiffhomepage
path: root/mrbgems
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2018-07-11 15:09:57 +0900
committerGitHub <[email protected]>2018-07-11 15:09:57 +0900
commite3bc680d9864ca5bb454f80c728210484647998f (patch)
treeac1bdf921c231f401678c6b8550e1aa23975f50d /mrbgems
parentea435f99da3aa5ba1dc6bf5cb7f48d9565bed1a6 (diff)
parenta921b936d6370794d4d66c23a4863507e013becb (diff)
downloadmruby-e3bc680d9864ca5bb454f80c728210484647998f.tar.gz
mruby-e3bc680d9864ca5bb454f80c728210484647998f.zip
Merge pull request #4068 from yurie/mrbc
add mrbc option `--remove-lv`
Diffstat (limited to 'mrbgems')
-rw-r--r--mrbgems/mruby-bin-mrbc/tools/mrbc/mrbc.c9
-rw-r--r--mrbgems/mruby-bin-strip/tools/mruby-strip/mruby-strip.c18
-rw-r--r--mrbgems/mruby-compiler/core/codegen.c15
3 files changed, 25 insertions, 17 deletions
diff --git a/mrbgems/mruby-bin-mrbc/tools/mrbc/mrbc.c b/mrbgems/mruby-bin-mrbc/tools/mrbc/mrbc.c
index 580c2e25b..2fd9da77d 100644
--- a/mrbgems/mruby-bin-mrbc/tools/mrbc/mrbc.c
+++ b/mrbgems/mruby-bin-mrbc/tools/mrbc/mrbc.c
@@ -18,6 +18,7 @@ struct mrbc_args {
const char *initname;
mrb_bool check_syntax : 1;
mrb_bool verbose : 1;
+ mrb_bool remove_lv : 1;
unsigned int flags : 4;
};
@@ -33,6 +34,7 @@ usage(const char *name)
"-B<symbol> binary <symbol> output in C language format",
"-e generate little endian iseq data",
"-E generate big endian iseq data",
+ "--remove-lv remove local variables",
"--verbose run at verbose mode",
"--version print the version",
"--copyright print the copyright",
@@ -142,6 +144,10 @@ parse_args(mrb_state *mrb, int argc, char **argv, struct mrbc_args *args)
mrb_show_copyright(mrb);
exit(EXIT_SUCCESS);
}
+ else if (strcmp(argv[i] + 2, "remove-lv") == 0) {
+ args->remove_lv = TRUE;
+ break;
+ }
return -1;
default:
return i;
@@ -232,6 +238,9 @@ dump_file(mrb_state *mrb, FILE *wfp, const char *outfile, struct RProc *proc, st
int n = MRB_DUMP_OK;
mrb_irep *irep = proc->body.irep;
+ if (args->remove_lv) {
+ mrb_irep_remove_lv(mrb, irep);
+ }
if (args->initname) {
n = mrb_dump_irep_cfunc(mrb, irep, args->flags, wfp, args->initname);
if (n == MRB_DUMP_INVALID_ARGUMENT) {
diff --git a/mrbgems/mruby-bin-strip/tools/mruby-strip/mruby-strip.c b/mrbgems/mruby-bin-strip/tools/mruby-strip/mruby-strip.c
index deb66d54c..fb78b0c3b 100644
--- a/mrbgems/mruby-bin-strip/tools/mruby-strip/mruby-strip.c
+++ b/mrbgems/mruby-bin-strip/tools/mruby-strip/mruby-strip.c
@@ -12,22 +12,6 @@ struct strip_args {
mrb_bool lvar;
};
-
-static void
-irep_remove_lv(mrb_state *mrb, mrb_irep *irep)
-{
- int i;
-
- if (irep->lv) {
- mrb_free(mrb, irep->lv);
- irep->lv = NULL;
- }
-
- for (i = 0; i < irep->rlen; ++i) {
- irep_remove_lv(mrb, irep->reps[i]);
- }
-}
-
static void
print_usage(const char *f)
{
@@ -99,7 +83,7 @@ strip(mrb_state *mrb, struct strip_args *args)
/* clear lv if --lvar is enabled */
if (args->lvar) {
- irep_remove_lv(mrb, irep);
+ mrb_irep_remove_lv(mrb, irep);
}
wfile = fopen(filename, "wb");
diff --git a/mrbgems/mruby-compiler/core/codegen.c b/mrbgems/mruby-compiler/core/codegen.c
index f71de9b4b..fec747f0c 100644
--- a/mrbgems/mruby-compiler/core/codegen.c
+++ b/mrbgems/mruby-compiler/core/codegen.c
@@ -3092,3 +3092,18 @@ mrb_generate_code(mrb_state *mrb, parser_state *p)
{
return generate_code(mrb, p, VAL);
}
+
+void
+mrb_irep_remove_lv(mrb_state *mrb, mrb_irep *irep)
+{
+ int i;
+
+ if (irep->lv) {
+ mrb_free(mrb, irep->lv);
+ irep->lv = NULL;
+ }
+
+ for (i = 0; i < irep->rlen; ++i) {
+ mrb_irep_remove_lv(mrb, irep->reps[i]);
+ }
+}