void serializer_dump_literals (void) { #ifdef JERRY_ENABLE_PRETTY_PRINTER if (print_opcodes) { lit_dump_literals (); } #endif }
/** * Finalize literal storage */ void lit_finalize (void) { #ifdef JERRY_ENABLE_LOG lit_dump_literals (); #endif /* JERRY_ENABLE_LOG */ while (lit_storage) { lit_storage = lit_free_literal (lit_storage); } } /* lit_finalize */
/** * Merge scopes tree into bytecode * * @return pointer to generated bytecode */ const bytecode_data_header_t * serializer_merge_scopes_into_bytecode (void) { const size_t buckets_count = scopes_tree_count_literals_in_blocks (current_scope); const vm_instr_counter_t instrs_count = scopes_tree_count_instructions (current_scope); const size_t blocks_count = JERRY_ALIGNUP (instrs_count, BLOCK_SIZE) / BLOCK_SIZE; const size_t bytecode_size = JERRY_ALIGNUP (instrs_count * sizeof (vm_instr_t), MEM_ALIGNMENT); const size_t hash_table_size = lit_id_hash_table_get_size_for_table (buckets_count, blocks_count); const size_t header_and_hash_table_size = JERRY_ALIGNUP (sizeof (bytecode_data_header_t) + hash_table_size, MEM_ALIGNMENT); uint8_t *buffer_p = (uint8_t*) mem_heap_alloc_block (bytecode_size + header_and_hash_table_size, MEM_HEAP_ALLOC_LONG_TERM); lit_id_hash_table *lit_id_hash = lit_id_hash_table_init (buffer_p + sizeof (bytecode_data_header_t), hash_table_size, buckets_count, blocks_count); vm_instr_t *bytecode_p = scopes_tree_raw_data (current_scope, buffer_p + header_and_hash_table_size, bytecode_size, lit_id_hash); bytecode_data_header_t *header_p = (bytecode_data_header_t *) buffer_p; MEM_CP_SET_POINTER (header_p->lit_id_hash_cp, lit_id_hash); header_p->instrs_p = bytecode_p; header_p->instrs_count = instrs_count; MEM_CP_SET_POINTER (header_p->next_header_cp, first_bytecode_header_p); first_bytecode_header_p = header_p; if (print_instrs) { lit_dump_literals (); serializer_print_instrs (header_p); } return header_p; } /* serializer_merge_scopes_into_bytecode */
const vm_instr_t * serializer_merge_scopes_into_bytecode (void) { bytecode_data.instrs_count = scopes_tree_count_instructions (current_scope); const size_t buckets_count = scopes_tree_count_literals_in_blocks (current_scope); const size_t blocks_count = (size_t) bytecode_data.instrs_count / BLOCK_SIZE + 1; const vm_instr_counter_t instrs_count = scopes_tree_count_instructions (current_scope); const size_t bytecode_array_size = JERRY_ALIGNUP (sizeof (insts_data_header_t) + instrs_count * sizeof (vm_instr_t), MEM_ALIGNMENT); const size_t lit_id_hash_table_size = JERRY_ALIGNUP (lit_id_hash_table_get_size_for_table (buckets_count, blocks_count), MEM_ALIGNMENT); uint8_t *buffer_p = (uint8_t*) mem_heap_alloc_block (bytecode_array_size + lit_id_hash_table_size, MEM_HEAP_ALLOC_LONG_TERM); lit_id_hash_table *lit_id_hash = lit_id_hash_table_init (buffer_p + bytecode_array_size, lit_id_hash_table_size, buckets_count, blocks_count); const vm_instr_t *instrs_p = scopes_tree_raw_data (current_scope, buffer_p, bytecode_array_size, lit_id_hash); insts_data_header_t *header_p = (insts_data_header_t*) buffer_p; MEM_CP_SET_POINTER (header_p->next_instrs_cp, bytecode_data.instrs_p); header_p->instructions_number = instrs_count; bytecode_data.instrs_p = instrs_p; if (print_instrs) { lit_dump_literals (); serializer_print_instrs (instrs_p, bytecode_data.instrs_count); } return instrs_p; }