| 1 |
/* |
| 2 |
** cdump.c - mruby binary dumper (in C) |
| 3 |
** |
| 4 |
** See Copyright Notice in mruby.h |
| 5 |
*/ |
| 6 |
|
| 7 |
#include <mruby.h> |
| 8 |
#include <mruby/string.h> |
| 9 |
#include <mruby/dump.h> |
| 10 |
#include <mruby/irep.h> |
| 11 |
#include <mruby/debug.h> |
| 12 |
#include <mruby/internal.h> |
| 13 |
|
| 14 |
#include <string.h> |
| 15 |
|
| 16 |
#ifndef MRB_NO_STDIO |
| 17 |
|
| 18 |
#ifndef MRB_NO_FLOAT |
| 19 |
#include <mruby/endian.h> |
| 20 |
#define MRB_FLOAT_FMT "%.17g" |
| 21 |
#endif |
| 22 |
|
| 23 |
static int |
| 24 |
cdump_pool(mrb_state *mrb, const mrb_pool_value *p, FILE *fp) |
| 25 |
{ |
| 26 |
if (p->tt & IREP_TT_NFLAG) { /* number */ |
| 27 |
switch (p->tt) { |
| 28 |
#ifdef MRB_64BIT |
| 29 |
case IREP_TT_INT64: |
| 30 |
if (p->u.i64 < INT32_MIN || INT32_MAX < p->u.i64) { |
| 31 |
fprintf(fp, "{IREP_TT_INT64, {.i64=%" PRId64 "}},\n", p->u.i64); |
| 32 |
} |
| 33 |
else { |
| 34 |
fprintf(fp, "{IREP_TT_INT32, {.i32=%" PRId32 "}},\n", (int32_t)p->u.i64); |
| 35 |
} |
| 36 |
break; |
| 37 |
#endif |
| 38 |
case IREP_TT_INT32: |
| 39 |
fprintf(fp, "{IREP_TT_INT32, {.i32=%" PRId32 "}},\n", p->u.i32); |
| 40 |
break; |
| 41 |
case IREP_TT_FLOAT: |
| 42 |
#ifndef MRB_NO_FLOAT |
| 43 |
fprintf(fp, "{IREP_TT_FLOAT, {.f=" MRB_FLOAT_FMT "}},\n", p->u.f); |
| 44 |
#endif |
| 45 |
break; |
| 46 |
case IREP_TT_BIGINT: |
| 47 |
{ |
| 48 |
const char *s = p->u.str; |
| 49 |
int len = s[0]+2; |
| 50 |
fputs("{IREP_TT_BIGINT, {\"", fp); |
| 51 |
for (int i=0; i<len; i++) { |
| 52 |
fprintf(fp, "\\x%02x", (int)s[i]&0xff); |
| 53 |
} |
| 54 |
fputs("\"}},\n", fp); |
| 55 |
} |
| 56 |
break; |
| 57 |
} |
| 58 |
} |
| 59 |
else { /* string */ |
| 60 |
int i, len = p->tt>>2; |
| 61 |
const char *s = p->u.str; |
| 62 |
fprintf(fp, "{IREP_TT_STR|(%d<<2), {\"", len); |
| 63 |
for (i=0; i<len; i++) { |
| 64 |
fprintf(fp, "\\x%02x", (int)s[i]&0xff); |
| 65 |
} |
| 66 |
fputs("\"}},\n", fp); |
| 67 |
} |
| 68 |
return MRB_DUMP_OK; |
| 69 |
} |
| 70 |
|
| 71 |
static mrb_bool |
| 72 |
sym_name_word_p(const char *name, mrb_int len) |
| 73 |
{ |
| 74 |
if (len == 0) return FALSE; |
| 75 |
if (name[0] != '_' && !ISALPHA(name[0])) return FALSE; |
| 76 |
for (int i = 1; i < len; i++) { |
| 77 |
if (name[i] != '_' && !ISALNUM(name[i])) return FALSE; |
| 78 |
} |
| 79 |
return TRUE; |
| 80 |
} |
| 81 |
|
| 82 |
static mrb_bool |
| 83 |
sym_name_with_equal_p(const char *name, mrb_int len) |
| 84 |
{ |
| 85 |
return len >= 2 && name[len-1] == '=' && sym_name_word_p(name, len-1); |
| 86 |
} |
| 87 |
|
| 88 |
static mrb_bool |
| 89 |
sym_name_with_question_mark_p(const char *name, mrb_int len) |
| 90 |
{ |
| 91 |
return len >= 2 && name[len-1] == '?' && sym_name_word_p(name, len-1); |
| 92 |
} |
| 93 |
|
| 94 |
static mrb_bool |
| 95 |
sym_name_with_bang_p(const char *name, mrb_int len) |
| 96 |
{ |
| 97 |
return len >= 2 && name[len-1] == '!' && sym_name_word_p(name, len-1); |
| 98 |
} |
| 99 |
|
| 100 |
static mrb_bool |
| 101 |
sym_name_ivar_p(const char *name, mrb_int len) |
| 102 |
{ |
| 103 |
return len >= 2 && name[0] == '@' && sym_name_word_p(name+1, len-1); |
| 104 |
} |
| 105 |
|
| 106 |
static mrb_bool |
| 107 |
sym_name_cvar_p(const char *name, mrb_int len) |
| 108 |
{ |
| 109 |
return len >= 3 && name[0] == '@' && sym_name_ivar_p(name+1, len-1); |
| 110 |
} |
| 111 |
|
| 112 |
#define OPERATOR_SYMBOL(sym_name, name) {name, sym_name, sizeof(sym_name)-1} |
| 113 |
struct operator_symbol { |
| 114 |
const char *name; |
| 115 |
const char *sym_name; |
| 116 |
uint16_t sym_name_len; |
| 117 |
}; |
| 118 |
static const struct operator_symbol operator_table[] = { |
| 119 |
OPERATOR_SYMBOL("!", "not"), |
| 120 |
OPERATOR_SYMBOL("%", "mod"), |
| 121 |
OPERATOR_SYMBOL("&", "and"), |
| 122 |
OPERATOR_SYMBOL("*", "mul"), |
| 123 |
OPERATOR_SYMBOL("+", "add"), |
| 124 |
OPERATOR_SYMBOL("-", "sub"), |
| 125 |
OPERATOR_SYMBOL("/", "div"), |
| 126 |
OPERATOR_SYMBOL("<", "lt"), |
| 127 |
OPERATOR_SYMBOL(">", "gt"), |
| 128 |
OPERATOR_SYMBOL("^", "xor"), |
| 129 |
OPERATOR_SYMBOL("`", "tick"), |
| 130 |
OPERATOR_SYMBOL("|", "or"), |
| 131 |
OPERATOR_SYMBOL("~", "neg"), |
| 132 |
OPERATOR_SYMBOL("!=", "neq"), |
| 133 |
OPERATOR_SYMBOL("!~", "nmatch"), |
| 134 |
OPERATOR_SYMBOL("&&", "andand"), |
| 135 |
OPERATOR_SYMBOL("**", "pow"), |
| 136 |
OPERATOR_SYMBOL("+@", "plus"), |
| 137 |
OPERATOR_SYMBOL("-@", "minus"), |
| 138 |
OPERATOR_SYMBOL("<<", "lshift"), |
| 139 |
OPERATOR_SYMBOL("<=", "le"), |
| 140 |
OPERATOR_SYMBOL("==", "eq"), |
| 141 |
OPERATOR_SYMBOL("=~", "match"), |
| 142 |
OPERATOR_SYMBOL(">=", "ge"), |
| 143 |
OPERATOR_SYMBOL(">>", "rshift"), |
| 144 |
OPERATOR_SYMBOL("[]", "aref"), |
| 145 |
OPERATOR_SYMBOL("||", "oror"), |
| 146 |
OPERATOR_SYMBOL("<=>", "cmp"), |
| 147 |
OPERATOR_SYMBOL("===", "eqq"), |
| 148 |
OPERATOR_SYMBOL("[]=", "aset"), |
| 149 |
}; |
| 150 |
|
| 151 |
static const char* |
| 152 |
sym_operator_name(const char *sym_name, mrb_int len) |
| 153 |
{ |
| 154 |
mrb_sym table_size = sizeof(operator_table)/sizeof(struct operator_symbol); |
| 155 |
if (operator_table[table_size-1].sym_name_len < len) return NULL; |
| 156 |
|
| 157 |
mrb_sym start, idx; |
| 158 |
int cmp; |
| 159 |
const struct operator_symbol *op_sym; |
| 160 |
for (start = 0; table_size != 0; table_size/=2) { |
| 161 |
idx = start+table_size/2; |
| 162 |
op_sym = &operator_table[idx]; |
| 163 |
cmp = (int)len-(int)op_sym->sym_name_len; |
| 164 |
if (cmp == 0) { |
| 165 |
cmp = memcmp(sym_name, op_sym->sym_name, len); |
| 166 |
if (cmp == 0) return op_sym->name; |
| 167 |
} |
| 168 |
if (0 < cmp) { |
| 169 |
start = ++idx; |
| 170 |
table_size--; |
| 171 |
} |
| 172 |
} |
| 173 |
return NULL; |
| 174 |
} |
| 175 |
|
| 176 |
static const char* |
| 177 |
sym_var_name(mrb_state *mrb, const char *initname, const char *key, int n) |
| 178 |
{ |
| 179 |
char buf[32]; |
| 180 |
mrb_value s = mrb_str_new_cstr(mrb, initname); |
| 181 |
mrb_str_cat_lit(mrb, s, "_"); |
| 182 |
mrb_str_cat_cstr(mrb, s, key); |
| 183 |
mrb_str_cat_lit(mrb, s, "_"); |
| 184 |
snprintf(buf, sizeof(buf), "%d", n); |
| 185 |
mrb_str_cat_cstr(mrb, s, buf); |
| 186 |
return RSTRING_PTR(s); |
| 187 |
} |
| 188 |
|
| 189 |
static int |
| 190 |
cdump_sym(mrb_state *mrb, mrb_sym sym, const char *var_name, int idx, mrb_value init_syms_code, FILE *fp) |
| 191 |
{ |
| 192 |
if (sym == 0) { |
| 193 |
fputs("0,", fp); |
| 194 |
return MRB_DUMP_OK; |
| 195 |
} |
| 196 |
|
| 197 |
mrb_int len; |
| 198 |
const char *name = mrb_sym_name_len(mrb, sym, &len), *op_name; |
| 199 |
if (!name) return MRB_DUMP_INVALID_ARGUMENT; |
| 200 |
if (sym_name_word_p(name, len)) { |
| 201 |
fprintf(fp, "MRB_SYM(%s)", name); |
| 202 |
} |
| 203 |
else if (sym_name_with_equal_p(name, len)) { |
| 204 |
fprintf(fp, "MRB_SYM_E(%.*s)", (int)(len-1), name); |
| 205 |
} |
| 206 |
else if (sym_name_with_question_mark_p(name, len)) { |
| 207 |
fprintf(fp, "MRB_SYM_Q(%.*s)", (int)(len-1), name); |
| 208 |
} |
| 209 |
else if (sym_name_with_bang_p(name, len)) { |
| 210 |
fprintf(fp, "MRB_SYM_B(%.*s)", (int)(len-1), name); |
| 211 |
} |
| 212 |
else if (sym_name_ivar_p(name, len)) { |
| 213 |
fprintf(fp, "MRB_IVSYM(%s)", name+1); |
| 214 |
} |
| 215 |
else if (sym_name_cvar_p(name, len)) { |
| 216 |
fprintf(fp, "MRB_CVSYM(%s)", name+2); |
| 217 |
} |
| 218 |
else if ((op_name = sym_operator_name(name, len))) { |
| 219 |
fprintf(fp, "MRB_OPSYM(%s)", op_name); |
| 220 |
} |
| 221 |
else { |
| 222 |
char buf[32]; |
| 223 |
mrb_value name_obj = mrb_str_new(mrb, name, len); |
| 224 |
mrb_str_cat_lit(mrb, init_syms_code, " "); |
| 225 |
mrb_str_cat_cstr(mrb, init_syms_code, var_name); |
| 226 |
snprintf(buf, sizeof(buf), "[%d] = ", idx); |
| 227 |
mrb_str_cat_cstr(mrb, init_syms_code, buf); |
| 228 |
mrb_str_cat_lit(mrb, init_syms_code, "mrb_intern_lit(mrb, "); |
| 229 |
mrb_str_cat_str(mrb, init_syms_code, mrb_str_dump(mrb, name_obj)); |
| 230 |
mrb_str_cat_lit(mrb, init_syms_code, ");\n"); |
| 231 |
fputs("0", fp); |
| 232 |
} |
| 233 |
fputs(", ", fp); |
| 234 |
return MRB_DUMP_OK; |
| 235 |
} |
| 236 |
|
| 237 |
static int |
| 238 |
cdump_syms(mrb_state *mrb, const char *name, const char *key, int n, int syms_len, const mrb_sym *syms, mrb_value init_syms_code, FILE *fp) |
| 239 |
{ |
| 240 |
int ai = mrb_gc_arena_save(mrb); |
| 241 |
mrb_int code_len = RSTRING_LEN(init_syms_code); |
| 242 |
const char *var_name = sym_var_name(mrb, name, key, n); |
| 243 |
fprintf(fp, "mrb_DEFINE_SYMS_VAR(%s, %d, (", var_name, syms_len); |
| 244 |
for (int i=0; i<syms_len; i++) { |
| 245 |
cdump_sym(mrb, syms[i], var_name, i, init_syms_code, fp); |
| 246 |
} |
| 247 |
fputs("), ", fp); |
| 248 |
if (code_len == RSTRING_LEN(init_syms_code)) fputs("const", fp); |
| 249 |
fputs(");\n", fp); |
| 250 |
mrb_gc_arena_restore(mrb, ai); |
| 251 |
return MRB_DUMP_OK; |
| 252 |
} |
| 253 |
|
| 254 |
//Handle the simple/common case of debug_info: |
| 255 |
// - 1 file associated with a single irep |
| 256 |
// - mrb_debug_line_ary format only |
| 257 |
static int |
| 258 |
simple_debug_info(mrb_irep_debug_info *info) |
| 259 |
{ |
| 260 |
if (!info || info->flen != 1) { |
| 261 |
return 0; |
| 262 |
} |
| 263 |
return 1; |
| 264 |
} |
| 265 |
|
| 266 |
//Adds debug information to c-structs and |
| 267 |
//adds filenames in init_syms_code block |
| 268 |
static int |
| 269 |
cdump_debug(mrb_state *mrb, const char *name, int n, mrb_irep_debug_info *info, |
| 270 |
mrb_value init_syms_code, FILE *fp) |
| 271 |
{ |
| 272 |
int ai = mrb_gc_arena_save(mrb); |
| 273 |
char buffer[256]; |
| 274 |
const char *filename; |
| 275 |
mrb_int file_len; |
| 276 |
int len, i; |
| 277 |
const char *line_type = "mrb_debug_line_ary"; |
| 278 |
|
| 279 |
if (!simple_debug_info(info)) |
| 280 |
return MRB_DUMP_INVALID_IREP; |
| 281 |
|
| 282 |
len = info->files[0]->line_entry_count; |
| 283 |
|
| 284 |
filename = mrb_sym_name_len(mrb, info->files[0]->filename_sym, &file_len); |
| 285 |
snprintf(buffer, sizeof(buffer), " %s_debug_file_%d.filename_sym = mrb_intern_lit(mrb,", name, n); |
| 286 |
mrb_str_cat_cstr(mrb, init_syms_code, buffer); |
| 287 |
mrb_str_cat_str(mrb, init_syms_code, mrb_str_dump(mrb, mrb_str_new_cstr(mrb, filename))); |
| 288 |
mrb_str_cat_cstr(mrb, init_syms_code, ");\n"); |
| 289 |
|
| 290 |
switch (info->files[0]->line_type) { |
| 291 |
case mrb_debug_line_ary: |
| 292 |
fprintf(fp, "static uint16_t %s_debug_lines_%d[%d] = {", name, n, len); |
| 293 |
for (i=0; i<len; i++) { |
| 294 |
if (i%10 == 0) fputs("\n", fp); |
| 295 |
fprintf(fp, "0x%04x,", info->files[0]->lines.ary[i]); |
| 296 |
} |
| 297 |
fputs("};\n", fp); |
| 298 |
break; |
| 299 |
|
| 300 |
case mrb_debug_line_flat_map: |
| 301 |
line_type = "mrb_debug_line_flat_map"; |
| 302 |
fprintf(fp, "static struct mrb_irep_debug_info_line %s_debug_lines_%d[%d] = {", name, n, len); |
| 303 |
for (i=0; i<len; i++) { |
| 304 |
const mrb_irep_debug_info_line *fmap = &info->files[0]->lines.flat_map[i]; |
| 305 |
fprintf(fp, "\t{.start_pos=0x%04x,.line=%d},\n", fmap->start_pos, fmap->line); |
| 306 |
} |
| 307 |
fputs("};\n", fp); |
| 308 |
break; |
| 309 |
|
| 310 |
case mrb_debug_line_packed_map: |
| 311 |
line_type = "mrb_debug_line_packed_map"; |
| 312 |
fprintf(fp, "static const char %s_debug_lines_%d[] = \"", name, n); |
| 313 |
const uint8_t *pmap = info->files[0]->lines.packed_map; |
| 314 |
for (i=0; i<len; i++) { |
| 315 |
fprintf(fp, "\\x%02x", pmap[i]&0xff); |
| 316 |
} |
| 317 |
fputs("\";\n", fp); |
| 318 |
break; |
| 319 |
} |
| 320 |
fprintf(fp, "static mrb_irep_debug_info_file %s_debug_file_%d = {\n", name, n); |
| 321 |
fprintf(fp, "%d, %d, %d, %s, {%s_debug_lines_%d}};\n", |
| 322 |
info->files[0]->start_pos, |
| 323 |
info->files[0]->filename_sym, |
| 324 |
info->files[0]->line_entry_count, |
| 325 |
line_type, |
| 326 |
name,n); |
| 327 |
fprintf(fp, "static mrb_irep_debug_info_file *%s_debug_file_%d_ = &%s_debug_file_%d;\n", name, n, name, n); |
| 328 |
|
| 329 |
fprintf(fp, "static mrb_irep_debug_info %s_debug_%d = {\n", name, n); |
| 330 |
fprintf(fp, "%d, %d, &%s_debug_file_%d_};\n", info->pc_count, info->flen, name, n); |
| 331 |
|
| 332 |
mrb_gc_arena_restore(mrb, ai); |
| 333 |
return MRB_DUMP_OK; |
| 334 |
} |
| 335 |
|
| 336 |
static int |
| 337 |
cdump_irep_struct(mrb_state *mrb, const mrb_irep *irep, uint8_t flags, FILE *fp, const char *name, int n, mrb_value init_syms_code, int *mp) |
| 338 |
{ |
| 339 |
int i, len; |
| 340 |
int max = *mp; |
| 341 |
int debug_available = 0; |
| 342 |
|
| 343 |
/* dump reps */ |
| 344 |
if (irep->reps) { |
| 345 |
for (i=0,len=irep->rlen; i<len; i++) { |
| 346 |
*mp += len; |
| 347 |
if (cdump_irep_struct(mrb, irep->reps[i], flags, fp, name, max+i, init_syms_code, mp) != MRB_DUMP_OK) |
| 348 |
return MRB_DUMP_INVALID_ARGUMENT; |
| 349 |
} |
| 350 |
fprintf(fp, "static const mrb_irep *%s_reps_%d[%d] = {\n", name, n, len); |
| 351 |
for (i=0,len=irep->rlen; i<len; i++) { |
| 352 |
fprintf(fp, " &%s_irep_%d,\n", name, max+i); |
| 353 |
} |
| 354 |
fputs("};\n", fp); |
| 355 |
} |
| 356 |
/* dump pool */ |
| 357 |
if (irep->pool) { |
| 358 |
len=irep->plen; |
| 359 |
fprintf(fp, "static const mrb_pool_value %s_pool_%d[%d] = {\n", name, n, len); |
| 360 |
for (i=0; i<len; i++) { |
| 361 |
if (cdump_pool(mrb, &irep->pool[i], fp) != MRB_DUMP_OK) |
| 362 |
return MRB_DUMP_INVALID_ARGUMENT; |
| 363 |
} |
| 364 |
fputs("};\n", fp); |
| 365 |
} |
| 366 |
/* dump syms */ |
| 367 |
if (irep->syms) { |
| 368 |
cdump_syms(mrb, name, "syms", n, irep->slen, irep->syms, init_syms_code, fp); |
| 369 |
} |
| 370 |
/* dump iseq */ |
| 371 |
len=irep->ilen+sizeof(struct mrb_irep_catch_handler)*irep->clen; |
| 372 |
fprintf(fp, "static const mrb_code %s_iseq_%d[%d] = {", name, n, len); |
| 373 |
for (i=0; i<len; i++) { |
| 374 |
if (i%20 == 0) fputs("\n", fp); |
| 375 |
fprintf(fp, "0x%02x,", irep->iseq[i]); |
| 376 |
} |
| 377 |
fputs("};\n", fp); |
| 378 |
/* dump lv */ |
| 379 |
if (irep->lv) { |
| 380 |
cdump_syms(mrb, name, "lv", n, irep->nlocals-1, irep->lv, init_syms_code, fp); |
| 381 |
} |
| 382 |
/* dump debug */ |
| 383 |
if (flags & MRB_DUMP_DEBUG_INFO) { |
| 384 |
if (cdump_debug(mrb, name, n, irep->debug_info, init_syms_code, fp) == MRB_DUMP_OK) { |
| 385 |
debug_available = 1; |
| 386 |
} |
| 387 |
} |
| 388 |
|
| 389 |
|
| 390 |
/* dump irep */ |
| 391 |
fprintf(fp, "static const mrb_irep %s_irep_%d = {\n", name, n); |
| 392 |
fprintf(fp, " %d,%d,%d,\n", irep->nlocals, irep->nregs, irep->clen); |
| 393 |
fprintf(fp, " MRB_IREP_STATIC,%s_iseq_%d,\n", name, n); |
| 394 |
if (irep->pool) { |
| 395 |
fprintf(fp, " %s_pool_%d,", name, n); |
| 396 |
} |
| 397 |
else { |
| 398 |
fputs( " NULL,", fp); |
| 399 |
} |
| 400 |
if (irep->syms) { |
| 401 |
fprintf(fp, "%s_syms_%d,", name, n); |
| 402 |
} |
| 403 |
else { |
| 404 |
fputs( "NULL,", fp); |
| 405 |
} |
| 406 |
if (irep->reps) { |
| 407 |
fprintf(fp, "%s_reps_%d,\n", name, n); |
| 408 |
} |
| 409 |
else { |
| 410 |
fputs( "NULL,\n", fp); |
| 411 |
} |
| 412 |
if (irep->lv) { |
| 413 |
fprintf(fp, " %s_lv_%d,\n", name, n); |
| 414 |
} |
| 415 |
else { |
| 416 |
fputs( " NULL,\t\t\t\t\t/* lv */\n", fp); |
| 417 |
} |
| 418 |
if (debug_available) { |
| 419 |
fprintf(fp, " &%s_debug_%d,\n", name, n); |
| 420 |
} |
| 421 |
else { |
| 422 |
fputs(" NULL,\t\t\t\t\t/* debug_info */\n", fp); |
| 423 |
} |
| 424 |
fprintf(fp, " %d,%d,%d,%d,0\n};\n", irep->ilen, irep->plen, irep->slen, irep->rlen); |
| 425 |
|
| 426 |
return MRB_DUMP_OK; |
| 427 |
} |
| 428 |
|
| 429 |
int |
| 430 |
mrb_dump_irep_cstruct(mrb_state *mrb, const mrb_irep *irep, uint8_t flags, FILE *fp, const char *initname) |
| 431 |
{ |
| 432 |
if (fp == NULL || initname == NULL || initname[0] == '\0') { |
| 433 |
return MRB_DUMP_INVALID_ARGUMENT; |
| 434 |
} |
| 435 |
if (fprintf(fp, "#include <mruby.h>\n" |
| 436 |
"#include <mruby/irep.h>\n" |
| 437 |
"#include <mruby/debug.h>\n" |
| 438 |
"#include <mruby/proc.h>\n" |
| 439 |
"#include <mruby/presym.h>\n" |
| 440 |
"\n") < 0) { |
| 441 |
return MRB_DUMP_WRITE_FAULT; |
| 442 |
} |
| 443 |
fputs("#define mrb_BRACED(...) {__VA_ARGS__}\n", fp); |
| 444 |
fputs("#define mrb_DEFINE_SYMS_VAR(name, len, syms, qualifier) \\\n", fp); |
| 445 |
fputs(" static qualifier mrb_sym name[len] = mrb_BRACED syms\n", fp); |
| 446 |
fputs("\n", fp); |
| 447 |
mrb_value init_syms_code = mrb_str_new_capa(mrb, 0); |
| 448 |
int max = 1; |
| 449 |
int n = cdump_irep_struct(mrb, irep, flags, fp, initname, 0, init_syms_code, &max); |
| 450 |
if (n != MRB_DUMP_OK) return n; |
| 451 |
fprintf(fp, |
| 452 |
"%s\n" |
| 453 |
"const struct RProc %s[] = {{\n", |
| 454 |
(flags & MRB_DUMP_STATIC) ? "static" |
| 455 |
: "#ifdef __cplusplus\n" |
| 456 |
"extern\n" |
| 457 |
"#endif", |
| 458 |
initname); |
| 459 |
fprintf(fp, "NULL,NULL,MRB_TT_PROC,MRB_GC_RED,0,{&%s_irep_0},NULL,{NULL},\n}};\n", initname); |
| 460 |
fputs("static void\n", fp); |
| 461 |
fprintf(fp, "%s_init_syms(mrb_state *mrb)\n", initname); |
| 462 |
fputs("{\n", fp); |
| 463 |
fputs(RSTRING_PTR(init_syms_code), fp); |
| 464 |
fputs("}\n", fp); |
| 465 |
return MRB_DUMP_OK; |
| 466 |
} |
| 467 |
#endif |