diff options
| author | dearblue <[email protected]> | 2021-12-17 23:02:04 +0900 |
|---|---|---|
| committer | dearblue <[email protected]> | 2021-12-17 23:02:04 +0900 |
| commit | 6b8582c95d64b75837e6778c712d705e07edad17 (patch) | |
| tree | 8db635b5dd92ebc46218ebcb383239b4f96ec838 /mrbgems/mruby-compiler/core/codegen.c | |
| parent | 9b65d0dc861f4a5d1605fa7fccb56f1758a2bd6f (diff) | |
| download | mruby-6b8582c95d64b75837e6778c712d705e07edad17.tar.gz mruby-6b8582c95d64b75837e6778c712d705e07edad17.zip | |
Add `bin/mrbc --no-ext-ops` switch
Print an error if `OP_EXT[123]` is needed when generating mruby binary.
This may be useful for mruby/c.
Inspired by #5590.
Diffstat (limited to 'mrbgems/mruby-compiler/core/codegen.c')
| -rw-r--r-- | mrbgems/mruby-compiler/core/codegen.c | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/mrbgems/mruby-compiler/core/codegen.c b/mrbgems/mruby-compiler/core/codegen.c index 54eb611ca..ce513feee 100644 --- a/mrbgems/mruby-compiler/core/codegen.c +++ b/mrbgems/mruby-compiler/core/codegen.c @@ -167,6 +167,14 @@ codegen_realloc(codegen_scope *s, void *p, size_t len) return p; } +static void +check_no_ext_ops(codegen_scope *s, uint16_t a, uint16_t b) +{ + if (s->parser->no_ext_ops && (a | b) > 0xff) { + codegen_error(s, "need OP_EXTs instruction (currently OP_EXTs are prohibited)"); + } +} + static int new_label(codegen_scope *s) { @@ -235,6 +243,7 @@ static void genop_1(codegen_scope *s, mrb_code i, uint16_t a) { s->lastpc = s->pc; + check_no_ext_ops(s, a, 0); if (a > 0xff) { gen_B(s, OP_EXT1); gen_B(s, i); @@ -250,6 +259,7 @@ static void genop_2(codegen_scope *s, mrb_code i, uint16_t a, uint16_t b) { s->lastpc = s->pc; + check_no_ext_ops(s, a, b); if (a > 0xff && b > 0xff) { gen_B(s, OP_EXT3); gen_B(s, i); @@ -555,6 +565,7 @@ genjmp2(codegen_scope *s, mrb_code i, uint16_t a, uint32_t pc, int val) } if (a > 0xff) { + check_no_ext_ops(s, a, 0); gen_B(s, OP_EXT1); genop_0(s, i); gen_S(s, a); |
