예제 #1
0
void
serializer_dump_op_meta (op_meta op)
{
  JERRY_ASSERT (scopes_tree_instrs_num (current_scope) < MAX_OPCODES);

  scopes_tree_add_op_meta (current_scope, op);

#ifdef JERRY_ENABLE_PRETTY_PRINTER
  if (print_instrs)
  {
    pp_op_meta (NULL, (vm_instr_counter_t) (scopes_tree_instrs_num (current_scope) - 1), op, false);
  }
#endif
}
예제 #2
0
/**
 * Dump variable declaration into the current scope
 */
void
serializer_dump_var_decl (op_meta op) /**< variable declaration instruction */
{
  JERRY_ASSERT (scopes_tree_instrs_num (current_scope) + current_scope->var_decls_cout < MAX_OPCODES);

  scopes_tree_add_var_decl (current_scope, op);
} /* serializer_dump_var_decl */
예제 #3
0
vm_instr_counter_t
serializer_count_instrs_in_subscopes (void)
{
  return (vm_instr_counter_t) (scopes_tree_count_instructions (current_scope) - scopes_tree_instrs_num (current_scope));
}
예제 #4
0
vm_instr_counter_t
serializer_get_current_instr_counter (void)
{
  return scopes_tree_instrs_num (current_scope);
}
예제 #5
0
/**
 * Dump single scopes tree into bytecode
 *
 * @return pointer to bytecode header of the outer most scope
 */
bytecode_data_header_t *
bc_dump_single_scope (scopes_tree scope_p) /**< a node of scopes tree */
{
  const size_t entries_count = scope_p->max_uniq_literals_num;
  const vm_instr_counter_t instrs_count = scopes_tree_instrs_num (scope_p);
  const size_t blocks_count = JERRY_ALIGNUP (instrs_count, BLOCK_SIZE) / BLOCK_SIZE;
  const size_t func_scopes_count = scopes_tree_child_scopes_num (scope_p);
  const uint16_t var_decls_count = linked_list_get_length (scope_p->var_decls);
  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 (entries_count, blocks_count);
  const size_t declarations_area_size = JERRY_ALIGNUP (func_scopes_count * sizeof (mem_cpointer_t)
                                                       + var_decls_count * sizeof (lit_cpointer_t),
                                                       MEM_ALIGNMENT);
  const size_t header_and_tables_size = JERRY_ALIGNUP ((sizeof (bytecode_data_header_t)
                                                        + hash_table_size
                                                        + declarations_area_size),
                                                       MEM_ALIGNMENT);

  uint8_t *buffer_p = (uint8_t *) mem_heap_alloc_block (bytecode_size + header_and_tables_size,
                                                        MEM_HEAP_ALLOC_LONG_TERM);

  lit_id_hash_table *lit_id_hash_p = lit_id_hash_table_init (buffer_p + sizeof (bytecode_data_header_t),
                                                             hash_table_size,
                                                             entries_count, blocks_count);

  mem_cpointer_t *declarations_p = (mem_cpointer_t *) (buffer_p + sizeof (bytecode_data_header_t) + hash_table_size);

  for (size_t i = 0; i < func_scopes_count; i++)
  {
    declarations_p[i] = MEM_CP_NULL;
  }

  scopes_tree_dump_var_decls (scope_p, (lit_cpointer_t *) (declarations_p + func_scopes_count));

  vm_instr_t *bytecode_p = (vm_instr_t *) (buffer_p + header_and_tables_size);

  JERRY_ASSERT (scope_p->max_uniq_literals_num >= lit_id_hash_p->current_bucket_pos);

  bytecode_data_header_t *header_p = (bytecode_data_header_t *) buffer_p;

  if ((uint16_t) func_scopes_count != func_scopes_count)
  {
    jerry_fatal (ERR_OUT_OF_MEMORY);
  }

  bc_fill_bytecode_data_header (header_p,
                                lit_id_hash_p, bytecode_p,
                                declarations_p,
                                (uint16_t) func_scopes_count,
                                var_decls_count,
                                scope_p->strict_mode,
                                scope_p->ref_arguments,
                                scope_p->ref_eval,
                                scope_p->is_vars_and_args_to_regs_possible,
                                false,
                                false);

  JERRY_ASSERT (scope_p->bc_header_cp == MEM_CP_NULL);
  MEM_CP_SET_NON_NULL_POINTER (scope_p->bc_header_cp, header_p);

  return header_p;
} /* bc_dump_single_scope */