Improve DUMP_READ_OBJECT (#382)
- improve `JS_DumpString`: use `L` prefix for wide strings - dump variable kind and flags for locals and closures - disassemble byte code in DUMP_READ_OBJECT - pass start_pos to `dump_byte_code` and `dump_single_byte_code` - write constant pool before function bytecode (bump version to 11) - update generated code
This commit is contained in:
parent
2c47b7beb1
commit
5797f2a716
6 changed files with 11567 additions and 11542 deletions
|
@ -5,54 +5,54 @@
|
|||
const uint32_t qjsc_function_source_size = 384;
|
||||
|
||||
const uint8_t qjsc_function_source[384] = {
|
||||
0x0a, 0x06, 0x0c, 0x61, 0x63, 0x74, 0x75, 0x61,
|
||||
0x6c, 0x02, 0x66, 0x0c, 0x65, 0x78, 0x70, 0x65,
|
||||
0x63, 0x74, 0x14, 0x75, 0x73, 0x65, 0x20, 0x73,
|
||||
0x74, 0x72, 0x69, 0x63, 0x74, 0x34, 0x66, 0x75,
|
||||
0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x66,
|
||||
0x28, 0x29, 0x20, 0x7b, 0x20, 0x72, 0x65, 0x74,
|
||||
0x75, 0x72, 0x6e, 0x20, 0x34, 0x32, 0x20, 0x7d,
|
||||
0x30, 0x74, 0x65, 0x73, 0x74, 0x73, 0x2f, 0x66,
|
||||
0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x5f,
|
||||
0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x2e, 0x6a,
|
||||
0x73, 0x0c, 0x00, 0x02, 0x01, 0x9e, 0x01, 0x00,
|
||||
0x0b, 0x06, 0x0c, 0x61, 0x63, 0x74, 0x75, 0x61,
|
||||
0x6c, 0x02, 0x66, 0x30, 0x74, 0x65, 0x73, 0x74,
|
||||
0x73, 0x2f, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69,
|
||||
0x6f, 0x6e, 0x5f, 0x73, 0x6f, 0x75, 0x72, 0x63,
|
||||
0x65, 0x2e, 0x6a, 0x73, 0x0c, 0x65, 0x78, 0x70,
|
||||
0x65, 0x63, 0x74, 0x14, 0x75, 0x73, 0x65, 0x20,
|
||||
0x73, 0x74, 0x72, 0x69, 0x63, 0x74, 0x34, 0x66,
|
||||
0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20,
|
||||
0x66, 0x28, 0x29, 0x20, 0x7b, 0x20, 0x72, 0x65,
|
||||
0x74, 0x75, 0x72, 0x6e, 0x20, 0x34, 0x32, 0x20,
|
||||
0x7d, 0x0c, 0x00, 0x02, 0x01, 0x9e, 0x01, 0x00,
|
||||
0x06, 0x00, 0x03, 0x00, 0x01, 0xa0, 0x01, 0x06,
|
||||
0xa0, 0x01, 0x00, 0x00, 0x00, 0xb2, 0x03, 0x02,
|
||||
0x00, 0x30, 0xb4, 0x03, 0x04, 0x00, 0x70, 0xb2,
|
||||
0x03, 0x04, 0x03, 0x70, 0x10, 0x00, 0x01, 0x00,
|
||||
0xe0, 0x01, 0x00, 0x01, 0x00, 0x0c, 0x03, 0xc1,
|
||||
0x05, 0x08, 0xc1, 0x04, 0x3f, 0xdb, 0x00, 0x00,
|
||||
0x00, 0x80, 0x3f, 0xda, 0x00, 0x00, 0x00, 0x40,
|
||||
0x3e, 0xdb, 0x00, 0x00, 0x00, 0x80, 0xbe, 0x00,
|
||||
0x40, 0xda, 0x00, 0x00, 0x00, 0x00, 0x04, 0xdc,
|
||||
0x00, 0x00, 0x00, 0xc8, 0x04, 0xdd, 0x00, 0x00,
|
||||
0x00, 0x3a, 0xdb, 0x00, 0x00, 0x00, 0x61, 0x01,
|
||||
0x00, 0x38, 0xda, 0x00, 0x00, 0x00, 0x42, 0x36,
|
||||
0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0xc9, 0x06,
|
||||
0xc8, 0x62, 0x01, 0x00, 0x38, 0xdb, 0x00, 0x00,
|
||||
0x00, 0xaf, 0xe9, 0x0b, 0x38, 0x92, 0x00, 0x00,
|
||||
0x00, 0x62, 0x01, 0x00, 0xee, 0x2f, 0x61, 0x03,
|
||||
0x00, 0x61, 0x02, 0x00, 0x38, 0x39, 0x00, 0x00,
|
||||
0x00, 0x38, 0xdb, 0x00, 0x00, 0x00, 0x04, 0xda,
|
||||
0x00, 0x00, 0x00, 0x9d, 0x31, 0x01, 0x00, 0x04,
|
||||
0x00, 0xca, 0x62, 0x02, 0x00, 0x42, 0x36, 0x00,
|
||||
0x00, 0x00, 0x24, 0x00, 0x00, 0xcb, 0x06, 0xc8,
|
||||
0x62, 0x03, 0x00, 0x38, 0xdb, 0x00, 0x00, 0x00,
|
||||
0xaf, 0xe9, 0x0b, 0x38, 0x92, 0x00, 0x00, 0x00,
|
||||
0x62, 0x03, 0x00, 0xee, 0x2f, 0x68, 0x03, 0x00,
|
||||
0x68, 0x02, 0x00, 0xc4, 0x28, 0xbc, 0x03, 0x01,
|
||||
0x01, 0x28, 0x60, 0x01, 0x49, 0x02, 0x21, 0x1a,
|
||||
0x1b, 0x04, 0x1e, 0x1d, 0x12, 0x26, 0x49, 0x1d,
|
||||
0x0c, 0x06, 0x11, 0x18, 0x2a, 0x1c, 0x37, 0x41,
|
||||
0x21, 0x1c, 0x34, 0x18, 0x1b, 0x04, 0x26, 0x11,
|
||||
0x3f, 0x1d, 0x0c, 0x06, 0x11, 0x18, 0x2a, 0x1c,
|
||||
0x53, 0x41, 0x00, 0x0c, 0x43, 0x02, 0x01, 0xb4,
|
||||
0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x03,
|
||||
0x00, 0xbb, 0x2a, 0x28, 0xbc, 0x03, 0x03, 0x01,
|
||||
0x04, 0x02, 0x1e, 0x0c, 0x0e, 0x1a, 0x66, 0x75,
|
||||
0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x66,
|
||||
0x28, 0x29, 0x20, 0x7b, 0x20, 0x72, 0x65, 0x74,
|
||||
0x75, 0x72, 0x6e, 0x20, 0x34, 0x32, 0x20, 0x7d,
|
||||
0xe0, 0x01, 0x00, 0x01, 0x00, 0x0c, 0x43, 0x02,
|
||||
0x01, 0xb4, 0x03, 0x00, 0x00, 0x00, 0x01, 0x00,
|
||||
0x00, 0x03, 0x00, 0xbb, 0x2a, 0x28, 0xb6, 0x03,
|
||||
0x03, 0x01, 0x04, 0x02, 0x1e, 0x0c, 0x0e, 0x1a,
|
||||
0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e,
|
||||
0x20, 0x66, 0x28, 0x29, 0x20, 0x7b, 0x20, 0x72,
|
||||
0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x34, 0x32,
|
||||
0x20, 0x7d, 0x0c, 0x03, 0xc1, 0x05, 0x08, 0xc1,
|
||||
0x04, 0x3f, 0xdc, 0x00, 0x00, 0x00, 0x80, 0x3f,
|
||||
0xda, 0x00, 0x00, 0x00, 0x40, 0x3e, 0xdc, 0x00,
|
||||
0x00, 0x00, 0x80, 0xbe, 0x00, 0x40, 0xda, 0x00,
|
||||
0x00, 0x00, 0x00, 0x04, 0xdd, 0x00, 0x00, 0x00,
|
||||
0xc8, 0x04, 0xde, 0x00, 0x00, 0x00, 0x3a, 0xdc,
|
||||
0x00, 0x00, 0x00, 0x61, 0x01, 0x00, 0x38, 0xda,
|
||||
0x00, 0x00, 0x00, 0x42, 0x36, 0x00, 0x00, 0x00,
|
||||
0x24, 0x00, 0x00, 0xc9, 0x06, 0xc8, 0x62, 0x01,
|
||||
0x00, 0x38, 0xdc, 0x00, 0x00, 0x00, 0xaf, 0xe9,
|
||||
0x0b, 0x38, 0x92, 0x00, 0x00, 0x00, 0x62, 0x01,
|
||||
0x00, 0xee, 0x2f, 0x61, 0x03, 0x00, 0x61, 0x02,
|
||||
0x00, 0x38, 0x39, 0x00, 0x00, 0x00, 0x38, 0xdc,
|
||||
0x00, 0x00, 0x00, 0x04, 0xda, 0x00, 0x00, 0x00,
|
||||
0x9d, 0x31, 0x01, 0x00, 0x04, 0x00, 0xca, 0x62,
|
||||
0x02, 0x00, 0x42, 0x36, 0x00, 0x00, 0x00, 0x24,
|
||||
0x00, 0x00, 0xcb, 0x06, 0xc8, 0x62, 0x03, 0x00,
|
||||
0x38, 0xdc, 0x00, 0x00, 0x00, 0xaf, 0xe9, 0x0b,
|
||||
0x38, 0x92, 0x00, 0x00, 0x00, 0x62, 0x03, 0x00,
|
||||
0xee, 0x2f, 0x68, 0x03, 0x00, 0x68, 0x02, 0x00,
|
||||
0xc4, 0x28, 0xb6, 0x03, 0x01, 0x01, 0x28, 0x60,
|
||||
0x01, 0x49, 0x02, 0x21, 0x1a, 0x1b, 0x04, 0x1e,
|
||||
0x1d, 0x12, 0x26, 0x49, 0x1d, 0x0c, 0x06, 0x11,
|
||||
0x18, 0x2a, 0x1c, 0x37, 0x41, 0x21, 0x1c, 0x34,
|
||||
0x18, 0x1b, 0x04, 0x26, 0x11, 0x3f, 0x1d, 0x0c,
|
||||
0x06, 0x11, 0x18, 0x2a, 0x1c, 0x53, 0x41, 0x00,
|
||||
};
|
||||
|
||||
static JSContext *JS_NewCustomContext(JSRuntime *rt)
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
const uint32_t qjsc_hello_size = 89;
|
||||
|
||||
const uint8_t qjsc_hello[89] = {
|
||||
0x0a, 0x04, 0x0e, 0x63, 0x6f, 0x6e, 0x73, 0x6f,
|
||||
0x0b, 0x04, 0x0e, 0x63, 0x6f, 0x6e, 0x73, 0x6f,
|
||||
0x6c, 0x65, 0x06, 0x6c, 0x6f, 0x67, 0x16, 0x48,
|
||||
0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x57, 0x6f, 0x72,
|
||||
0x6c, 0x64, 0x22, 0x65, 0x78, 0x61, 0x6d, 0x70,
|
||||
|
|
|
@ -5,51 +5,51 @@
|
|||
const uint32_t qjsc_fib_module_size = 310;
|
||||
|
||||
const uint8_t qjsc_fib_module[310] = {
|
||||
0x0a, 0x03, 0x2c, 0x65, 0x78, 0x61, 0x6d, 0x70,
|
||||
0x0b, 0x03, 0x2c, 0x65, 0x78, 0x61, 0x6d, 0x70,
|
||||
0x6c, 0x65, 0x73, 0x2f, 0x66, 0x69, 0x62, 0x5f,
|
||||
0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x2e, 0x6a,
|
||||
0x73, 0x06, 0x66, 0x69, 0x62, 0x02, 0x6e, 0x0d,
|
||||
0xb2, 0x03, 0x00, 0x01, 0x00, 0x00, 0xb4, 0x03,
|
||||
0x00, 0x00, 0x0c, 0x20, 0x02, 0x01, 0x9e, 0x01,
|
||||
0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x09, 0x00,
|
||||
0xb4, 0x03, 0x00, 0x01, 0x08, 0xe9, 0x05, 0xbe,
|
||||
0x00, 0xe0, 0x29, 0x06, 0x2e, 0xb2, 0x03, 0x01,
|
||||
0x01, 0x06, 0x01, 0x01, 0x00, 0x07, 0x14, 0x02,
|
||||
0x00, 0x0c, 0x43, 0x02, 0x01, 0xb4, 0x03, 0x01,
|
||||
0x00, 0x01, 0x04, 0x01, 0x00, 0x1a, 0x01, 0xb6,
|
||||
0x03, 0x00, 0x01, 0x00, 0xb4, 0x03, 0x00, 0x00,
|
||||
0xd0, 0xb3, 0xa7, 0xe9, 0x03, 0xb3, 0x28, 0xd0,
|
||||
0xb4, 0xac, 0xe9, 0x03, 0xb4, 0x28, 0xdc, 0xd0,
|
||||
0xb4, 0x9e, 0xee, 0xdc, 0xd0, 0xb5, 0x9e, 0xee,
|
||||
0x9d, 0x28, 0xb2, 0x03, 0x02, 0x08, 0x20, 0x04,
|
||||
0x00, 0x07, 0x06, 0x07, 0x06, 0x12, 0x09, 0x08,
|
||||
0x07, 0x07, 0x10, 0x07, 0x06, 0x07, 0x06, 0x12,
|
||||
0x13, 0x08, 0x07, 0x08, 0x16, 0x0c, 0x0c, 0x07,
|
||||
0x04, 0x0c, 0x0a, 0x0c, 0x0c, 0x07, 0x04, 0x8d,
|
||||
0x01, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f,
|
||||
0x6e, 0x20, 0x66, 0x69, 0x62, 0x28, 0x6e, 0x29,
|
||||
0x0a, 0x7b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x69,
|
||||
0x66, 0x20, 0x28, 0x6e, 0x20, 0x3c, 0x3d, 0x20,
|
||||
0x30, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||
0x20, 0x20, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72,
|
||||
0x6e, 0x20, 0x30, 0x3b, 0x0a, 0x20, 0x20, 0x20,
|
||||
0x20, 0x65, 0x6c, 0x73, 0x65, 0x20, 0x69, 0x66,
|
||||
0x20, 0x28, 0x6e, 0x20, 0x3d, 0x3d, 0x20, 0x31,
|
||||
0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||
0x20, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e,
|
||||
0x20, 0x31, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20,
|
||||
0x65, 0x6c, 0x73, 0x65, 0x0a, 0x20, 0x20, 0x20,
|
||||
0xb4, 0x03, 0x00, 0x01, 0x0c, 0x43, 0x02, 0x01,
|
||||
0xb4, 0x03, 0x01, 0x00, 0x01, 0x04, 0x01, 0x00,
|
||||
0x1a, 0x01, 0xb6, 0x03, 0x00, 0x01, 0x00, 0xb4,
|
||||
0x03, 0x00, 0x00, 0xd0, 0xb3, 0xa7, 0xe9, 0x03,
|
||||
0xb3, 0x28, 0xd0, 0xb4, 0xac, 0xe9, 0x03, 0xb4,
|
||||
0x28, 0xdc, 0xd0, 0xb4, 0x9e, 0xee, 0xdc, 0xd0,
|
||||
0xb5, 0x9e, 0xee, 0x9d, 0x28, 0xb2, 0x03, 0x02,
|
||||
0x08, 0x20, 0x04, 0x00, 0x07, 0x06, 0x07, 0x06,
|
||||
0x12, 0x09, 0x08, 0x07, 0x07, 0x10, 0x07, 0x06,
|
||||
0x07, 0x06, 0x12, 0x13, 0x08, 0x07, 0x08, 0x16,
|
||||
0x0c, 0x0c, 0x07, 0x04, 0x0c, 0x0a, 0x0c, 0x0c,
|
||||
0x07, 0x04, 0x8d, 0x01, 0x66, 0x75, 0x6e, 0x63,
|
||||
0x74, 0x69, 0x6f, 0x6e, 0x20, 0x66, 0x69, 0x62,
|
||||
0x28, 0x6e, 0x29, 0x0a, 0x7b, 0x0a, 0x20, 0x20,
|
||||
0x20, 0x20, 0x69, 0x66, 0x20, 0x28, 0x6e, 0x20,
|
||||
0x3c, 0x3d, 0x20, 0x30, 0x29, 0x0a, 0x20, 0x20,
|
||||
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x72, 0x65,
|
||||
0x74, 0x75, 0x72, 0x6e, 0x20, 0x30, 0x3b, 0x0a,
|
||||
0x20, 0x20, 0x20, 0x20, 0x65, 0x6c, 0x73, 0x65,
|
||||
0x20, 0x69, 0x66, 0x20, 0x28, 0x6e, 0x20, 0x3d,
|
||||
0x3d, 0x20, 0x31, 0x29, 0x0a, 0x20, 0x20, 0x20,
|
||||
0x20, 0x20, 0x20, 0x20, 0x20, 0x72, 0x65, 0x74,
|
||||
0x75, 0x72, 0x6e, 0x20, 0x66, 0x69, 0x62, 0x28,
|
||||
0x6e, 0x20, 0x2d, 0x20, 0x31, 0x29, 0x20, 0x2b,
|
||||
0x20, 0x66, 0x69, 0x62, 0x28, 0x6e, 0x20, 0x2d,
|
||||
0x20, 0x32, 0x29, 0x3b, 0x0a, 0x7d,
|
||||
0x75, 0x72, 0x6e, 0x20, 0x31, 0x3b, 0x0a, 0x20,
|
||||
0x20, 0x20, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x0a,
|
||||
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||
0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x66,
|
||||
0x69, 0x62, 0x28, 0x6e, 0x20, 0x2d, 0x20, 0x31,
|
||||
0x29, 0x20, 0x2b, 0x20, 0x66, 0x69, 0x62, 0x28,
|
||||
0x6e, 0x20, 0x2d, 0x20, 0x32, 0x29, 0x3b, 0x0a,
|
||||
0x7d, 0x08, 0xe9, 0x05, 0xbe, 0x00, 0xe0, 0x29,
|
||||
0x06, 0x2e, 0xb2, 0x03, 0x01, 0x01, 0x06, 0x01,
|
||||
0x01, 0x00, 0x07, 0x14, 0x02, 0x00,
|
||||
};
|
||||
|
||||
const uint32_t qjsc_hello_module_size = 177;
|
||||
|
||||
const uint8_t qjsc_hello_module[177] = {
|
||||
0x0a, 0x07, 0x30, 0x65, 0x78, 0x61, 0x6d, 0x70,
|
||||
0x0b, 0x07, 0x30, 0x65, 0x78, 0x61, 0x6d, 0x70,
|
||||
0x6c, 0x65, 0x73, 0x2f, 0x68, 0x65, 0x6c, 0x6c,
|
||||
0x6f, 0x5f, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65,
|
||||
0x2e, 0x6a, 0x73, 0x1e, 0x2e, 0x2f, 0x66, 0x69,
|
||||
|
|
22808
gen/repl.c
22808
gen/repl.c
File diff suppressed because it is too large
Load diff
|
@ -5,7 +5,7 @@
|
|||
const uint32_t qjsc_test_fib_size = 166;
|
||||
|
||||
const uint8_t qjsc_test_fib[166] = {
|
||||
0x0a, 0x07, 0x28, 0x65, 0x78, 0x61, 0x6d, 0x70,
|
||||
0x0b, 0x07, 0x28, 0x65, 0x78, 0x61, 0x6d, 0x70,
|
||||
0x6c, 0x65, 0x73, 0x2f, 0x74, 0x65, 0x73, 0x74,
|
||||
0x5f, 0x66, 0x69, 0x62, 0x2e, 0x6a, 0x73, 0x10,
|
||||
0x2e, 0x2f, 0x66, 0x69, 0x62, 0x2e, 0x73, 0x6f,
|
||||
|
|
139
quickjs.c
139
quickjs.c
|
@ -2480,8 +2480,11 @@ static __maybe_unused void JS_DumpString(JSRuntime *rt,
|
|||
printf("<null>");
|
||||
return;
|
||||
}
|
||||
if (p->header.ref_count != 1)
|
||||
printf("%d", p->header.ref_count);
|
||||
sep = (p->header.ref_count == 1) ? '\"' : '\'';
|
||||
if (p->is_wide_char)
|
||||
putchar('L');
|
||||
sep = '\"';
|
||||
putchar(sep);
|
||||
for(i = 0; i < p->len; i++) {
|
||||
c = string_get(p, i);
|
||||
|
@ -14510,7 +14513,7 @@ typedef enum {
|
|||
|
||||
#ifdef DUMP_BYTECODE
|
||||
static void dump_single_byte_code(JSContext *ctx, const uint8_t *pc,
|
||||
JSFunctionBytecode *b);
|
||||
JSFunctionBytecode *b, int start_pos);
|
||||
static void print_func_name(JSFunctionBytecode *b);
|
||||
#endif
|
||||
|
||||
|
@ -14533,7 +14536,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
|
|||
|
||||
#ifdef DUMP_BYTECODE_STEP
|
||||
#define DUMP_BYTECODE_OR_DONT(pc) \
|
||||
if (check_dump_flag(ctx->rt, DUMP_BYTECODE_STEP)) dump_single_byte_code(ctx, pc, b);
|
||||
if (check_dump_flag(ctx->rt, DUMP_BYTECODE_STEP)) dump_single_byte_code(ctx, pc, b, 0);
|
||||
#else
|
||||
#define DUMP_BYTECODE_OR_DONT(pc)
|
||||
#endif
|
||||
|
@ -27557,13 +27560,17 @@ static void dump_byte_code(JSContext *ctx, int pass,
|
|||
const JSClosureVar *closure_var, int closure_var_count,
|
||||
const JSValue *cpool, uint32_t cpool_count,
|
||||
const char *source, int line_num,
|
||||
const LabelSlot *label_slots, JSFunctionBytecode *b)
|
||||
const LabelSlot *label_slots, JSFunctionBytecode *b,
|
||||
int start_pos)
|
||||
{
|
||||
const JSOpCode *oi;
|
||||
int pos, pos_next, op, size, idx, addr, line, line1, in_source;
|
||||
uint8_t *bits = js_mallocz(ctx, len * sizeof(*bits));
|
||||
BOOL use_short_opcodes = (b != NULL);
|
||||
|
||||
if (start_pos != 0 || bits == NULL)
|
||||
goto no_labels;
|
||||
|
||||
/* scan for jump targets */
|
||||
for (pos = 0; pos < len; pos = pos_next) {
|
||||
op = tab[pos];
|
||||
|
@ -27604,6 +27611,7 @@ static void dump_byte_code(JSContext *ctx, int pass,
|
|||
}
|
||||
}
|
||||
}
|
||||
no_labels:
|
||||
in_source = 0;
|
||||
if (source) {
|
||||
/* Always print first line: needed if single line */
|
||||
|
@ -27660,12 +27668,12 @@ static void dump_byte_code(JSContext *ctx, int pass,
|
|||
printf("%*s", x0 + 20 - x, "");
|
||||
}
|
||||
#endif
|
||||
if (bits[pos]) {
|
||||
if (bits && bits[pos]) {
|
||||
printf("%5d: ", pos);
|
||||
} else {
|
||||
printf(" ");
|
||||
}
|
||||
printf("%s", oi->name);
|
||||
printf("%-15s", oi->name); /* align opcode arguments */
|
||||
pos++;
|
||||
switch(oi->fmt) {
|
||||
case OP_FMT_none_int:
|
||||
|
@ -27706,24 +27714,20 @@ static void dump_byte_code(JSContext *ctx, int pass,
|
|||
addr = get_i16(tab + pos);
|
||||
goto has_addr1;
|
||||
case OP_FMT_label:
|
||||
addr = get_u32(tab + pos);
|
||||
goto has_addr1;
|
||||
has_addr1:
|
||||
if (pass == 1)
|
||||
printf(" %u:%u", addr, label_slots[addr].pos);
|
||||
if (pass == 2)
|
||||
printf(" %u:%u", addr, label_slots[addr].pos2);
|
||||
if (pass == 3)
|
||||
printf(" %u", addr + pos);
|
||||
break;
|
||||
case OP_FMT_label_u16:
|
||||
addr = get_u32(tab + pos);
|
||||
has_addr1:
|
||||
if (pass == 1)
|
||||
printf(" %u:%u", addr, label_slots[addr].pos);
|
||||
printf(" %d:%u", addr, label_slots[addr].pos);
|
||||
if (pass == 2)
|
||||
printf(" %u:%u", addr, label_slots[addr].pos2);
|
||||
if (pass == 3)
|
||||
printf(" %u", addr + pos);
|
||||
printf(" %d:%u", addr, label_slots[addr].pos2);
|
||||
if (pass == 3) {
|
||||
if (start_pos)
|
||||
printf(" %04x", addr + pos + start_pos);
|
||||
else
|
||||
printf(" %d", addr + pos);
|
||||
}
|
||||
if (oi->fmt == OP_FMT_label_u16)
|
||||
printf(",%u", get_u16(tab + pos + 4));
|
||||
break;
|
||||
case OP_FMT_const8:
|
||||
|
@ -27733,7 +27737,7 @@ static void dump_byte_code(JSContext *ctx, int pass,
|
|||
idx = get_u32(tab + pos);
|
||||
goto has_pool_idx;
|
||||
has_pool_idx:
|
||||
printf(" %u: ", idx);
|
||||
printf(" %-4u ; ", idx);
|
||||
if (idx < cpool_count) {
|
||||
JS_DumpValue(ctx->rt, cpool[idx]);
|
||||
}
|
||||
|
@ -27777,7 +27781,7 @@ static void dump_byte_code(JSContext *ctx, int pass,
|
|||
case OP_FMT_loc:
|
||||
idx = get_u16(tab + pos);
|
||||
has_loc:
|
||||
printf(" %d: ", idx);
|
||||
printf(" %-4d ; ", idx);
|
||||
if (idx < var_count) {
|
||||
print_atom(ctx, vars[idx].var_name);
|
||||
}
|
||||
|
@ -27788,7 +27792,7 @@ static void dump_byte_code(JSContext *ctx, int pass,
|
|||
case OP_FMT_arg:
|
||||
idx = get_u16(tab + pos);
|
||||
has_arg:
|
||||
printf(" %d: ", idx);
|
||||
printf(" %-4d ; ", idx);
|
||||
if (idx < arg_count) {
|
||||
print_atom(ctx, args[idx].var_name);
|
||||
}
|
||||
|
@ -27799,7 +27803,7 @@ static void dump_byte_code(JSContext *ctx, int pass,
|
|||
case OP_FMT_var_ref:
|
||||
idx = get_u16(tab + pos);
|
||||
has_var_ref:
|
||||
printf(" %d: ", idx);
|
||||
printf(" %-4d ; ", idx);
|
||||
if (idx < closure_var_count) {
|
||||
print_atom(ctx, closure_var[idx].var_name);
|
||||
}
|
||||
|
@ -27822,7 +27826,8 @@ static void dump_byte_code(JSContext *ctx, int pass,
|
|||
// and only works for pass3 bytecode
|
||||
static __maybe_unused void dump_single_byte_code(JSContext *ctx,
|
||||
const uint8_t *pc,
|
||||
JSFunctionBytecode *b)
|
||||
JSFunctionBytecode *b,
|
||||
int start_pos)
|
||||
{
|
||||
JSVarDef *args, *vars;
|
||||
|
||||
|
@ -27835,7 +27840,7 @@ static __maybe_unused void dump_single_byte_code(JSContext *ctx,
|
|||
b->closure_var, b->closure_var_count,
|
||||
b->cpool, b->cpool_count,
|
||||
NULL, b->line_num,
|
||||
NULL, b);
|
||||
NULL, b, start_pos);
|
||||
}
|
||||
|
||||
static __maybe_unused void print_func_name(JSFunctionBytecode *b)
|
||||
|
@ -27962,7 +27967,7 @@ static __maybe_unused void js_dump_function_bytecode(JSContext *ctx, JSFunctionB
|
|||
b->vardefs ? b->vardefs + b->arg_count : NULL, b->var_count,
|
||||
b->closure_var, b->closure_var_count,
|
||||
b->cpool, b->cpool_count,
|
||||
b->source, b->line_num, NULL, b);
|
||||
b->source, b->line_num, NULL, b, 0);
|
||||
#ifdef DUMP_BYTECODE_PC2LINE
|
||||
if (check_dump_flag(ctx->rt, DUMP_BYTECODE_PC2LINE))
|
||||
dump_pc2line(ctx, b->pc2line_buf, b->pc2line_len, b->line_num, b->col_num);
|
||||
|
@ -31272,7 +31277,7 @@ static JSValue js_create_function(JSContext *ctx, JSFunctionDef *fd)
|
|||
fd->args, fd->arg_count, fd->vars, fd->var_count,
|
||||
fd->closure_var, fd->closure_var_count,
|
||||
fd->cpool, fd->cpool_count, fd->source, fd->line_num,
|
||||
fd->label_slots, NULL);
|
||||
fd->label_slots, NULL, 0);
|
||||
printf("\n");
|
||||
}
|
||||
#endif
|
||||
|
@ -31287,7 +31292,7 @@ static JSValue js_create_function(JSContext *ctx, JSFunctionDef *fd)
|
|||
fd->args, fd->arg_count, fd->vars, fd->var_count,
|
||||
fd->closure_var, fd->closure_var_count,
|
||||
fd->cpool, fd->cpool_count, fd->source, fd->line_num,
|
||||
fd->label_slots, NULL);
|
||||
fd->label_slots, NULL, 0);
|
||||
printf("\n");
|
||||
}
|
||||
#endif
|
||||
|
@ -32600,7 +32605,7 @@ typedef enum BCTagEnum {
|
|||
BC_TAG_OBJECT_REFERENCE,
|
||||
} BCTagEnum;
|
||||
|
||||
#define BC_VERSION 10
|
||||
#define BC_VERSION 11
|
||||
|
||||
typedef struct BCWriterState {
|
||||
JSContext *ctx;
|
||||
|
@ -33016,6 +33021,13 @@ static int JS_WriteFunctionTag(BCWriterState *s, JSValue obj)
|
|||
bc_put_u8(s, flags);
|
||||
}
|
||||
|
||||
// write constant pool before code so code can be disassembled
|
||||
// on the fly at read time
|
||||
for(i = 0; i < b->cpool_count; i++) {
|
||||
if (JS_WriteObjectRec(s, b->cpool[i]))
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (JS_WriteFunctionBytecode(s, b))
|
||||
goto fail;
|
||||
|
||||
|
@ -33026,11 +33038,6 @@ static int JS_WriteFunctionTag(BCWriterState *s, JSValue obj)
|
|||
dbuf_put(&s->dbuf, b->pc2line_buf, b->pc2line_len);
|
||||
bc_put_leb128(s, b->source_len);
|
||||
dbuf_put(&s->dbuf, b->source, b->source_len);
|
||||
|
||||
for(i = 0; i < b->cpool_count; i++) {
|
||||
if (JS_WriteObjectRec(s, b->cpool[i]))
|
||||
goto fail;
|
||||
}
|
||||
return 0;
|
||||
fail:
|
||||
return -1;
|
||||
|
@ -33461,10 +33468,9 @@ typedef struct BCReaderState {
|
|||
int objects_count;
|
||||
int objects_size;
|
||||
|
||||
#ifdef DUMP_READ_OBJECT
|
||||
/* used for DUMP_READ_OBJECT */
|
||||
const uint8_t *ptr_last;
|
||||
int level;
|
||||
#endif
|
||||
} BCReaderState;
|
||||
|
||||
#ifdef DUMP_READ_OBJECT
|
||||
|
@ -33736,18 +33742,23 @@ static int JS_ReadFunctionBytecode(BCReaderState *s, JSFunctionBytecode *b,
|
|||
return -1;
|
||||
}
|
||||
put_u32(bc_buf + pos + 1, atom);
|
||||
#ifdef DUMP_READ_OBJECT
|
||||
if (check_dump_flag(s->ctx->rt, DUMP_READ_OBJECT)) {
|
||||
bc_read_trace(s, "at %d, fixup atom: ", pos + 1);
|
||||
print_atom(s->ctx, atom);
|
||||
printf("\n");
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
default:
|
||||
assert(!is_ic_op(op)); // should not end up in serialized bytecode
|
||||
break;
|
||||
}
|
||||
#ifdef DUMP_READ_OBJECT
|
||||
if (check_dump_flag(s->ctx->rt, DUMP_READ_OBJECT)) {
|
||||
const uint8_t *save_ptr = s->ptr;
|
||||
s->ptr = s->ptr_last + len;
|
||||
s->level -= 4;
|
||||
bc_read_trace(s, ""); // hex dump + indent
|
||||
dump_single_byte_code(s->ctx, bc_buf + pos, b,
|
||||
s->ptr - s->buf_start - len);
|
||||
s->level += 4;
|
||||
s->ptr = save_ptr;
|
||||
}
|
||||
#endif
|
||||
pos += len;
|
||||
}
|
||||
return 0;
|
||||
|
@ -33950,6 +33961,7 @@ static JSValue JS_ReadFunctionTag(BCReaderState *s)
|
|||
|
||||
if (local_count != 0) {
|
||||
bc_read_trace(s, "vars {\n");
|
||||
bc_read_trace(s, "off flags scope name\n");
|
||||
for(i = 0; i < local_count; i++) {
|
||||
JSVarDef *vd = &b->vardefs[i];
|
||||
if (bc_get_atom(s, &vd->var_name))
|
||||
|
@ -33968,7 +33980,12 @@ static JSValue JS_ReadFunctionTag(BCReaderState *s)
|
|||
vd->is_captured = bc_get_flags(v8, &idx, 1);
|
||||
#ifdef DUMP_READ_OBJECT
|
||||
if (check_dump_flag(s->ctx->rt, DUMP_READ_OBJECT)) {
|
||||
bc_read_trace(s, "name: ");
|
||||
bc_read_trace(s, "%3d %d%c%c%c %4d ",
|
||||
i, vd->var_kind,
|
||||
vd->is_const ? 'C' : '.',
|
||||
vd->is_lexical ? 'L' : '.',
|
||||
vd->is_captured ? 'X' : '.',
|
||||
vd->scope_level);
|
||||
print_atom(s->ctx, vd->var_name);
|
||||
printf("\n");
|
||||
}
|
||||
|
@ -33978,6 +33995,7 @@ static JSValue JS_ReadFunctionTag(BCReaderState *s)
|
|||
}
|
||||
if (b->closure_var_count != 0) {
|
||||
bc_read_trace(s, "closure vars {\n");
|
||||
bc_read_trace(s, "off flags idx name\n");
|
||||
for(i = 0; i < b->closure_var_count; i++) {
|
||||
JSClosureVar *cv = &b->closure_var[i];
|
||||
int var_idx;
|
||||
|
@ -33996,7 +34014,13 @@ static JSValue JS_ReadFunctionTag(BCReaderState *s)
|
|||
cv->var_kind = bc_get_flags(v8, &idx, 4);
|
||||
#ifdef DUMP_READ_OBJECT
|
||||
if (check_dump_flag(s->ctx->rt, DUMP_READ_OBJECT)) {
|
||||
bc_read_trace(s, "name: ");
|
||||
bc_read_trace(s, "%3d %d%c%c%c%c %3d ",
|
||||
i, cv->var_kind,
|
||||
cv->is_local ? 'L' : '.',
|
||||
cv->is_arg ? 'A' : '.',
|
||||
cv->is_const ? 'C' : '.',
|
||||
cv->is_lexical ? 'X' : '.',
|
||||
cv->var_idx);
|
||||
print_atom(s->ctx, cv->var_name);
|
||||
printf("\n");
|
||||
}
|
||||
|
@ -34004,6 +34028,17 @@ static JSValue JS_ReadFunctionTag(BCReaderState *s)
|
|||
}
|
||||
bc_read_trace(s, "}\n");
|
||||
}
|
||||
if (b->cpool_count != 0) {
|
||||
bc_read_trace(s, "cpool {\n");
|
||||
for(i = 0; i < b->cpool_count; i++) {
|
||||
JSValue val;
|
||||
val = JS_ReadObjectRec(s);
|
||||
if (JS_IsException(val))
|
||||
goto fail;
|
||||
b->cpool[i] = val;
|
||||
}
|
||||
bc_read_trace(s, "}\n");
|
||||
}
|
||||
{
|
||||
bc_read_trace(s, "bytecode {\n");
|
||||
if (JS_ReadFunctionBytecode(s, b, byte_code_offset, b->byte_code_len))
|
||||
|
@ -34039,23 +34074,13 @@ static JSValue JS_ReadFunctionTag(BCReaderState *s)
|
|||
goto fail;
|
||||
if (b->source_len) {
|
||||
bc_read_trace(s, "source: %d bytes\n", b->source_len);
|
||||
s->ptr_last += b->source_len; // omit source code hex dump
|
||||
b->source = js_mallocz(ctx, b->source_len);
|
||||
if (!b->source)
|
||||
goto fail;
|
||||
if (bc_get_buf(s, b->source, b->source_len))
|
||||
goto fail;
|
||||
}
|
||||
if (b->cpool_count != 0) {
|
||||
bc_read_trace(s, "cpool {\n");
|
||||
for(i = 0; i < b->cpool_count; i++) {
|
||||
JSValue val;
|
||||
val = JS_ReadObjectRec(s);
|
||||
if (JS_IsException(val))
|
||||
goto fail;
|
||||
b->cpool[i] = val;
|
||||
}
|
||||
bc_read_trace(s, "}\n");
|
||||
}
|
||||
bc_read_trace(s, "}\n");
|
||||
b->realm = JS_DupContext(ctx);
|
||||
return obj;
|
||||
|
|
Loading…
Reference in a new issue