Refactor literal-storage to not use C++ features

JerryScript-DCO-1.0-Signed-off-by: Roland Takacs rtakacs.u-szeged@partner.samsung.com
This commit is contained in:
Roland Takacs
2015-12-24 17:24:46 +03:00
committed by Peter Gal
parent f932b7d48c
commit 21f561f8ef
36 changed files with 2603 additions and 3134 deletions
+14 -7
View File
@@ -354,7 +354,7 @@ bc_align_data_in_output_buffer (uint32_t *in_out_size, /**< in: unaligned size,
for (uint32_t i = 0; i < padding_bytes_num; i++)
{
if (!jrt_write_to_buffer_by_offset (buffer_p, buffer_size, in_out_buffer_offset_p, padding))
if (!jrt_write_to_buffer_by_offset (buffer_p, buffer_size, in_out_buffer_offset_p, &padding, sizeof (padding)))
{
return false;
}
@@ -426,7 +426,7 @@ bc_save_bytecode_with_idx_map (uint8_t *buffer_p, /**< buffer to dump to */
}
uint32_t offset = bc_find_lit_offset (lit_cp, lit_map_p, literals_num);
if (!jrt_write_to_buffer_by_offset (buffer_p, buffer_size, in_out_buffer_offset_p, offset))
if (!jrt_write_to_buffer_by_offset (buffer_p, buffer_size, in_out_buffer_offset_p, &offset, sizeof (offset)))
{
return false;
}
@@ -466,7 +466,11 @@ bc_save_bytecode_with_idx_map (uint8_t *buffer_p, /**< buffer to dump to */
}
/* Dump header at the saved offset */
if (!jrt_write_to_buffer_by_offset (buffer_p, buffer_size, &bytecode_header_offset, bytecode_header))
if (!jrt_write_to_buffer_by_offset (buffer_p,
buffer_size,
&bytecode_header_offset,
&bytecode_header,
sizeof (bytecode_header)))
{
return false;
}
@@ -583,7 +587,8 @@ bc_load_bytecode_with_idx_map (const uint8_t *snapshot_data_p, /**< buffer with
if (!jrt_read_from_buffer_by_offset (snapshot_data_p,
snapshot_size,
&buffer_offset,
&bytecode_header))
&bytecode_header,
sizeof (bytecode_header)))
{
return NULL;
}
@@ -609,7 +614,8 @@ bc_load_bytecode_with_idx_map (const uint8_t *snapshot_data_p, /**< buffer with
if (!jrt_read_from_buffer_by_offset (idx_to_lit_map_p,
bytecode_header.idx_to_lit_map_size,
&idx_to_lit_map_offset,
&idx_num_total))
&idx_num_total,
sizeof (idx_num_total)))
{
return NULL;
}
@@ -671,7 +677,8 @@ bc_load_bytecode_with_idx_map (const uint8_t *snapshot_data_p, /**< buffer with
if (!jrt_read_from_buffer_by_offset (snapshot_data_p,
buffer_offset + bytecode_header.var_decls_count * sizeof (uint32_t),
&buffer_offset,
&lit_offset_from_snapshot))
&lit_offset_from_snapshot,
sizeof (lit_offset_from_snapshot)))
{
mem_heap_free_block (buffer_p);
return NULL;
@@ -679,7 +686,7 @@ bc_load_bytecode_with_idx_map (const uint8_t *snapshot_data_p, /**< buffer with
/**
* TODO: implement binary search here
*/
lit_cpointer_t lit_cp = lit_cpointer_t::null_cp ();
lit_cpointer_t lit_cp = NOT_A_LITERAL;
uint32_t j;
for (j = 0; j < literals_num; j++)
{
@@ -14,7 +14,6 @@
*/
#include "lit-id-hash-table.h"
#include "lit-literal-storage.h"
#include "bytecode-data.h"
/** \addtogroup jsparser ECMAScript parser
@@ -172,7 +171,11 @@ lit_id_hash_table_dump_for_snapshot (uint8_t *buffer_p, /**< buffer to dump to *
uint32_t idx_num_total = (uint32_t) table_p->current_bucket_pos;
JERRY_ASSERT (idx_num_total == table_p->current_bucket_pos);
if (!jrt_write_to_buffer_by_offset (buffer_p, buffer_size, in_out_buffer_offset_p, idx_num_total))
if (!jrt_write_to_buffer_by_offset (buffer_p,
buffer_size,
in_out_buffer_offset_p,
&idx_num_total,
sizeof (idx_num_total)))
{
return 0;
}
@@ -207,7 +210,11 @@ lit_id_hash_table_dump_for_snapshot (uint8_t *buffer_p, /**< buffer to dump to *
idx_num_in_block = 0;
}
if (!jrt_write_to_buffer_by_offset (buffer_p, buffer_size, in_out_buffer_offset_p, idx_num_in_block))
if (!jrt_write_to_buffer_by_offset (buffer_p,
buffer_size,
in_out_buffer_offset_p,
&idx_num_in_block,
sizeof (idx_num_in_block)))
{
return 0;
}
@@ -220,7 +227,7 @@ lit_id_hash_table_dump_for_snapshot (uint8_t *buffer_p, /**< buffer to dump to *
uint32_t offset = bc_find_lit_offset (lit_cp, lit_map_p, literals_num);
if (!jrt_write_to_buffer_by_offset (buffer_p, buffer_size, in_out_buffer_offset_p, offset))
if (!jrt_write_to_buffer_by_offset (buffer_p, buffer_size, in_out_buffer_offset_p, &offset, sizeof (offset)))
{
return 0;
}
@@ -230,7 +237,11 @@ lit_id_hash_table_dump_for_snapshot (uint8_t *buffer_p, /**< buffer to dump to *
{
idx_num_in_block = 0;
if (!jrt_write_to_buffer_by_offset (buffer_p, buffer_size, in_out_buffer_offset_p, idx_num_in_block))
if (!jrt_write_to_buffer_by_offset (buffer_p,
buffer_size,
in_out_buffer_offset_p,
&idx_num_in_block,
sizeof (idx_num_in_block)))
{
return 0;
}
@@ -278,7 +289,8 @@ lit_id_hash_table_load_from_snapshot (size_t blocks_count, /**< number of byte-c
if (!jrt_read_from_buffer_by_offset (idx_to_lit_map_p,
idx_to_lit_map_size,
&idx_to_lit_map_offset,
&idx_num_in_block))
&idx_num_in_block,
sizeof (idx_num_in_block)))
{
return false;
}
@@ -302,7 +314,8 @@ lit_id_hash_table_load_from_snapshot (size_t blocks_count, /**< number of byte-c
if (!jrt_read_from_buffer_by_offset (idx_to_lit_map_p,
idx_to_lit_map_size,
&idx_to_lit_map_offset,
&lit_offset_from_snapshot))
&lit_offset_from_snapshot,
sizeof (lit_offset_from_snapshot)))
{
return false;
}
@@ -310,7 +323,7 @@ lit_id_hash_table_load_from_snapshot (size_t blocks_count, /**< number of byte-c
/**
* TODO: implement binary search here
*/
lit_cpointer_t lit_cp = lit_cpointer_t::null_cp ();
lit_cpointer_t lit_cp = rcs_cpointer_null_cp ();
uint32_t i;
for (i = 0; i < literals_num; i++)
{
@@ -20,6 +20,7 @@
#include "ecma-globals.h"
#include "opcodes.h"
#include "lit-literal.h"
#include "lit-snapshot.h"
typedef struct
{
+3 -3
View File
@@ -38,7 +38,7 @@ jsp_early_error_t jsp_early_error_type;
typedef struct
{
prop_type type;
literal_t lit;
lit_literal_t lit;
} prop_literal;
enum
@@ -97,7 +97,7 @@ jsp_early_error_get_type (void)
} /* jsp_early_error_get_type */
static prop_literal
create_prop_literal (literal_t lit, prop_type type)
create_prop_literal (lit_literal_t lit, prop_type type)
{
prop_literal ret;
@@ -189,7 +189,7 @@ jsp_early_error_check_for_duplication_of_prop_names (bool is_strict, locus loc _
}
void
jsp_early_error_emit_error_on_eval_and_arguments (literal_t lit, /**< literal to check */
jsp_early_error_emit_error_on_eval_and_arguments (lit_literal_t lit, /**< literal to check */
locus loc) /**< location of the literal in source code */
{
if (lit_literal_equal_type_utf8 (lit,
+1 -1
View File
@@ -78,7 +78,7 @@ void jsp_early_error_start_checking_of_prop_names (void);
void jsp_early_error_add_prop_name (jsp_operand_t, prop_type);
void jsp_early_error_check_for_duplication_of_prop_names (bool, locus);
void jsp_early_error_emit_error_on_eval_and_arguments (literal_t, locus);
void jsp_early_error_emit_error_on_eval_and_arguments (lit_literal_t, locus);
void jsp_early_error_check_for_eval_and_arguments_in_strict_mode (jsp_operand_t, bool, locus);
void jsp_early_error_check_delete (bool, locus);
+10 -7
View File
@@ -22,6 +22,7 @@
#include "lit-magic-strings.h"
#include "lit-strings.h"
#include "jsp-early-error.h"
#include "rcs-records.h"
static token saved_token, prev_token, sent_token, empty_token;
@@ -119,13 +120,13 @@ dump_current_line (void)
} /* dump_current_line */
static token
create_token_from_lit (jsp_token_type_t type, literal_t lit)
create_token_from_lit (jsp_token_type_t type, lit_literal_t lit)
{
token ret;
ret.type = type;
ret.loc = current_locus ();
ret.uid = lit_cpointer_t::compress (lit).packed_value;
ret.uid = rcs_cpointer_compress (lit).packed_value;
return ret;
}
@@ -195,7 +196,7 @@ lexer_create_token_for_charset (jsp_token_type_t tt, /**< token type */
JERRY_ASSERT (lit_is_cesu8_string_valid (converted_str_p, new_length));
}
literal_t lit = lit_find_literal_by_utf8_string (converted_str_p, new_length);
lit_literal_t lit = lit_find_literal_by_utf8_string (converted_str_p, new_length);
if (lit != NULL)
{
if (unlikely (should_convert))
@@ -206,9 +207,11 @@ lexer_create_token_for_charset (jsp_token_type_t tt, /**< token type */
return create_token_from_lit (tt, lit);
}
lit = lit_create_literal_from_utf8_string (converted_str_p, new_length);
JERRY_ASSERT (lit->get_type () == LIT_STR_T
|| lit->get_type () == LIT_MAGIC_STR_T
|| lit->get_type () == LIT_MAGIC_STR_EX_T);
rcs_record_type_t type = rcs_record_get_type (lit);
JERRY_ASSERT (RCS_RECORD_TYPE_IS_CHARSET (type)
|| RCS_RECORD_TYPE_IS_MAGIC_STR (type)
|| RCS_RECORD_TYPE_IS_MAGIC_STR_EX (type));
if (unlikely (should_convert))
{
@@ -661,7 +664,7 @@ lexer_parse_reserved_word (const lit_utf8_byte_t *str_p, /**< characters buffer
static token
convert_seen_num_to_token (ecma_number_t num)
{
literal_t lit = lit_find_literal_by_num (num);
lit_literal_t lit = lit_find_literal_by_num (num);
if (lit != NULL)
{
return create_token_from_lit (TOK_NUMBER, lit);
+1 -1
View File
@@ -19,7 +19,7 @@
#include "lit-literal.h"
#include "lit-strings.h"
#define INVALID_LITERAL (rcs_cpointer_t::null_cp ())
#define INVALID_LITERAL (rcs_cpointer_null_cp ())
/* Keywords. */
typedef enum __attr_packed___
+11 -10
View File
@@ -21,6 +21,7 @@
#include "lexer.h"
#include "lit-literal.h"
#include "opcodes.h"
#include "rcs-records.h"
#include "scopes-tree.h"
/**
@@ -163,11 +164,11 @@ public:
JERRY_ASSERT (lit_id.packed_value != NOT_A_LITERAL.packed_value);
#ifndef JERRY_NDEBUG
literal_t lit = lit_get_literal_by_cp (lit_id);
lit_literal_t lit = lit_get_literal_by_cp (lit_id);
JERRY_ASSERT (lit->get_type () == LIT_STR_T
|| lit->get_type () == LIT_MAGIC_STR_T
|| lit->get_type () == LIT_MAGIC_STR_EX_T);
JERRY_ASSERT (RCS_RECORD_IS_CHARSET (lit)
|| RCS_RECORD_IS_MAGIC_STR (lit)
|| RCS_RECORD_IS_MAGIC_STR_EX (lit));
#endif /* !JERRY_NDEBUG */
jsp_operand_t ret;
@@ -189,11 +190,11 @@ public:
JERRY_ASSERT (lit_id.packed_value != NOT_A_LITERAL.packed_value);
#ifndef JERRY_NDEBUG
literal_t lit = lit_get_literal_by_cp (lit_id);
lit_literal_t lit = lit_get_literal_by_cp (lit_id);
JERRY_ASSERT (lit->get_type () == LIT_STR_T
|| lit->get_type () == LIT_MAGIC_STR_T
|| lit->get_type () == LIT_MAGIC_STR_EX_T);
JERRY_ASSERT (RCS_RECORD_IS_CHARSET (lit)
|| RCS_RECORD_IS_MAGIC_STR (lit)
|| RCS_RECORD_IS_MAGIC_STR_EX (lit));
#endif /* !JERRY_NDEBUG */
jsp_operand_t ret;
@@ -215,9 +216,9 @@ public:
JERRY_ASSERT (lit_id.packed_value != NOT_A_LITERAL.packed_value);
#ifndef JERRY_NDEBUG
literal_t lit = lit_get_literal_by_cp (lit_id);
lit_literal_t lit = lit_get_literal_by_cp (lit_id);
JERRY_ASSERT (lit->get_type () == LIT_NUMBER_T);
JERRY_ASSERT (RCS_RECORD_IS_NUMBER (lit));
#endif /* !JERRY_NDEBUG */
jsp_operand_t ret;
+17 -15
View File
@@ -16,6 +16,7 @@
#include "bytecode-data.h"
#include "ecma-helpers.h"
#include "jrt-bit-fields.h"
#include "jrt-libc-includes.h"
#include "jsp-mm.h"
#include "opcodes.h"
@@ -27,6 +28,7 @@
#include "jsp-early-error.h"
#include "jsp-internal.h"
#include "vm.h"
#include "rcs-records.h"
/**
* Flag, indicating whether result of expression
@@ -975,9 +977,9 @@ parse_property_name (void)
if (is_keyword (tt))
{
const char *s = lexer_token_type_to_string (lexer_get_token_type (tok));
literal_t lit = lit_find_or_create_literal_from_utf8_string ((const lit_utf8_byte_t *) s,
lit_literal_t lit = lit_find_or_create_literal_from_utf8_string ((const lit_utf8_byte_t *) s,
(lit_utf8_size_t)strlen (s));
return jsp_operand_t::make_string_lit_operand (lit_cpointer_t::compress (lit));
return jsp_operand_t::make_string_lit_operand (rcs_cpointer_compress (lit));
}
else
{
@@ -995,9 +997,9 @@ parse_property_name (void)
if (lexer_get_token_type (tok) == TOK_NUMBER)
{
literal_t num_lit = lit_get_literal_by_cp (token_data_as_lit_cp ());
JERRY_ASSERT (num_lit->get_type () == LIT_NUMBER_T);
num = lit_charset_literal_get_number (num_lit);
lit_literal_t num_lit = lit_get_literal_by_cp (token_data_as_lit_cp ());
JERRY_ASSERT (RCS_RECORD_IS_NUMBER (num_lit));
num = lit_number_literal_get_number (num_lit);
}
else
{
@@ -1008,8 +1010,8 @@ parse_property_name (void)
lit_utf8_size_t sz = ecma_number_to_utf8_string (num, buff, sizeof (buff));
JERRY_ASSERT (sz <= ECMA_MAX_CHARS_IN_STRINGIFIED_NUMBER);
literal_t str_lit = lit_find_or_create_literal_from_utf8_string (buff, sz);
return jsp_operand_t::make_string_lit_operand (lit_cpointer_t::compress (str_lit));
lit_literal_t str_lit = lit_find_or_create_literal_from_utf8_string (buff, sz);
return jsp_operand_t::make_string_lit_operand (rcs_cpointer_compress (str_lit));
}
case TOK_NULL:
case TOK_BOOL:
@@ -1017,9 +1019,9 @@ parse_property_name (void)
lit_magic_string_id_t id = (token_is (TOK_NULL)
? LIT_MAGIC_STRING_NULL
: (tok.uid ? LIT_MAGIC_STRING_TRUE : LIT_MAGIC_STRING_FALSE));
literal_t lit = lit_find_or_create_literal_from_utf8_string (lit_get_magic_string_utf8 (id),
lit_literal_t lit = lit_find_or_create_literal_from_utf8_string (lit_get_magic_string_utf8 (id),
lit_get_magic_string_size (id));
return jsp_operand_t::make_string_lit_operand (lit_cpointer_t::compress (lit));
return jsp_operand_t::make_string_lit_operand (rcs_cpointer_compress (lit));
}
default:
{
@@ -1387,7 +1389,7 @@ jsp_start_parse_function_scope (jsp_ctx_t *ctx_p,
{
current_token_must_be (TOK_NAME);
literal_t current_parameter_name_lit = lit_get_literal_by_cp (token_data_as_lit_cp ());
lit_literal_t current_parameter_name_lit = lit_get_literal_by_cp (token_data_as_lit_cp ());
locus current_parameter_loc = tok.loc;
skip_token (ctx_p);
@@ -1409,7 +1411,7 @@ jsp_start_parse_function_scope (jsp_ctx_t *ctx_p,
if (lit_utf8_iterator_pos_cmp (tok.loc, current_parameter_loc) != 0)
{
literal_t iter_parameter_name_lit = lit_get_literal_by_cp (token_data_as_lit_cp ());
lit_literal_t iter_parameter_name_lit = lit_get_literal_by_cp (token_data_as_lit_cp ());
if (lit_literal_equal_type (current_parameter_name_lit, iter_parameter_name_lit))
{
@@ -2310,24 +2312,24 @@ jsp_get_prop_name_after_dot (void)
else if (is_keyword (lexer_get_token_type (tok)))
{
const char *s = lexer_token_type_to_string (lexer_get_token_type (tok));
literal_t lit = lit_find_or_create_literal_from_utf8_string ((lit_utf8_byte_t *) s,
lit_literal_t lit = lit_find_or_create_literal_from_utf8_string ((lit_utf8_byte_t *) s,
(lit_utf8_size_t) strlen (s));
if (lit == NULL)
{
EMIT_ERROR (JSP_EARLY_ERROR_SYNTAX, "Expected identifier");
}
return lit_cpointer_t::compress (lit);
return rcs_cpointer_compress (lit);
}
else if (token_is (TOK_BOOL) || token_is (TOK_NULL))
{
lit_magic_string_id_t id = (token_is (TOK_NULL)
? LIT_MAGIC_STRING_NULL
: (tok.uid ? LIT_MAGIC_STRING_TRUE : LIT_MAGIC_STRING_FALSE));
literal_t lit = lit_find_or_create_literal_from_utf8_string (lit_get_magic_string_utf8 (id),
lit_literal_t lit = lit_find_or_create_literal_from_utf8_string (lit_get_magic_string_utf8 (id),
lit_get_magic_string_size (id));
return lit_cpointer_t::compress (lit);
return rcs_cpointer_compress (lit);
}
else
{