Commit dabb20dd authored by yuri's avatar yuri

add mrbc option `--remove-lv`

* refactor: move `irep_remove_lv` from `mruby-bin-strip` gem to src/dump and rename to `mrb_irep_remove_lv`
* add: mrbc option `--remove-lv` to remove LVAR section
parent 17c9e656
...@@ -31,6 +31,7 @@ MRB_API mrb_value mrb_load_irep_file(mrb_state*,FILE*); ...@@ -31,6 +31,7 @@ MRB_API mrb_value mrb_load_irep_file(mrb_state*,FILE*);
MRB_API mrb_value mrb_load_irep_file_cxt(mrb_state*, FILE*, mrbc_context*); MRB_API mrb_value mrb_load_irep_file_cxt(mrb_state*, FILE*, mrbc_context*);
#endif #endif
MRB_API mrb_irep *mrb_read_irep(mrb_state*, const uint8_t*); MRB_API mrb_irep *mrb_read_irep(mrb_state*, const uint8_t*);
void mrb_irep_remove_lv(mrb_state *mrb, mrb_irep *irep);
/* dump/load error code /* dump/load error code
* *
......
...@@ -18,6 +18,7 @@ struct mrbc_args { ...@@ -18,6 +18,7 @@ struct mrbc_args {
const char *initname; const char *initname;
mrb_bool check_syntax : 1; mrb_bool check_syntax : 1;
mrb_bool verbose : 1; mrb_bool verbose : 1;
mrb_bool remove_lv : 1;
unsigned int flags : 4; unsigned int flags : 4;
}; };
...@@ -33,6 +34,7 @@ usage(const char *name) ...@@ -33,6 +34,7 @@ usage(const char *name)
"-B<symbol> binary <symbol> output in C language format", "-B<symbol> binary <symbol> output in C language format",
"-e generate little endian iseq data", "-e generate little endian iseq data",
"-E generate big endian iseq data", "-E generate big endian iseq data",
"--remove-lv remove local variables",
"--verbose run at verbose mode", "--verbose run at verbose mode",
"--version print the version", "--version print the version",
"--copyright print the copyright", "--copyright print the copyright",
...@@ -142,6 +144,10 @@ parse_args(mrb_state *mrb, int argc, char **argv, struct mrbc_args *args) ...@@ -142,6 +144,10 @@ parse_args(mrb_state *mrb, int argc, char **argv, struct mrbc_args *args)
mrb_show_copyright(mrb); mrb_show_copyright(mrb);
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} }
else if (strcmp(argv[i] + 2, "remove-lv") == 0) {
args->remove_lv = TRUE;
break;
}
return -1; return -1;
default: default:
return i; return i;
...@@ -232,6 +238,9 @@ dump_file(mrb_state *mrb, FILE *wfp, const char *outfile, struct RProc *proc, st ...@@ -232,6 +238,9 @@ dump_file(mrb_state *mrb, FILE *wfp, const char *outfile, struct RProc *proc, st
int n = MRB_DUMP_OK; int n = MRB_DUMP_OK;
mrb_irep *irep = proc->body.irep; mrb_irep *irep = proc->body.irep;
if (args->remove_lv) {
mrb_irep_remove_lv(mrb, irep);
}
if (args->initname) { if (args->initname) {
n = mrb_dump_irep_cfunc(mrb, irep, args->flags, wfp, args->initname); n = mrb_dump_irep_cfunc(mrb, irep, args->flags, wfp, args->initname);
if (n == MRB_DUMP_INVALID_ARGUMENT) { if (n == MRB_DUMP_INVALID_ARGUMENT) {
......
...@@ -12,22 +12,6 @@ struct strip_args { ...@@ -12,22 +12,6 @@ struct strip_args {
mrb_bool lvar; 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 static void
print_usage(const char *f) print_usage(const char *f)
{ {
...@@ -99,7 +83,7 @@ strip(mrb_state *mrb, struct strip_args *args) ...@@ -99,7 +83,7 @@ strip(mrb_state *mrb, struct strip_args *args)
/* clear lv if --lvar is enabled */ /* clear lv if --lvar is enabled */
if (args->lvar) { if (args->lvar) {
irep_remove_lv(mrb, irep); mrb_irep_remove_lv(mrb, irep);
} }
wfile = fopen(filename, "wb"); wfile = fopen(filename, "wb");
......
...@@ -1103,4 +1103,19 @@ mrb_dump_irep_cfunc(mrb_state *mrb, mrb_irep *irep, uint8_t flags, FILE *fp, con ...@@ -1103,4 +1103,19 @@ mrb_dump_irep_cfunc(mrb_state *mrb, mrb_irep *irep, uint8_t flags, FILE *fp, con
return result; return result;
} }
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]);
}
}
#endif /* MRB_DISABLE_STDIO */ #endif /* MRB_DISABLE_STDIO */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment