Skip to content

Commit 5219470

Browse files
author
Roland Takacs
committed
Refactor literal-storage to not use C++ features
JerryScript-DCO-1.0-Signed-off-by: Roland Takacs [email protected]
1 parent 4f44071 commit 5219470

34 files changed

+2614
-3143
lines changed

jerry-core/ecma/base/ecma-globals.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
#include "lit-globals.h"
2929
#include "lit-magic-strings.h"
3030
#include "mem-allocator.h"
31-
#include "rcs-recordset.h"
31+
#include "rcs-globals.h"
32+
#include "rcs-cpointer.h"
3233

3334
/** \addtogroup compressedpointer Compressed pointer
3435
* @{
@@ -792,8 +793,8 @@ FIXME (Move to library that should define the type (literal.h /* ? */))
792793
/**
793794
* Literal and compressed pointer to literal
794795
*/
795-
typedef rcs_record_t *literal_t;
796-
typedef rcs_cpointer_t lit_cpointer_t;
796+
typedef record_t *literal_t;
797+
typedef cpointer_t lit_cpointer_t;
797798

798799
/**
799800
* ECMA string-value descriptor

jerry-core/ecma/base/ecma-helpers-string.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "lit-magic-strings.h"
3232
#include "serializer.h"
3333
#include "vm.h"
34+
#include "rcs-records.h"
3435

3536
/**
3637
* Maximum length of strings' concatenation
@@ -329,23 +330,26 @@ ecma_init_ecma_string_from_lit_cp (ecma_string_t *string_p, /**< descriptor to i
329330
#endif /* !JERRY_NDEBUG */
330331

331332
literal_t lit = lit_get_literal_by_cp (lit_cp);
332-
if (lit->get_type () == LIT_MAGIC_STR_T)
333+
record_type_t type = rcs_record_get_type (lit);
334+
335+
if (RCS_RECORD_TYPE_IS_MAGIC_STR (type))
333336
{
334337
ecma_init_ecma_string_from_magic_string_id (string_p,
335338
lit_magic_record_get_magic_str_id (lit),
336339
is_stack_var);
337340

338341
return;
339342
}
340-
else if (lit->get_type () == LIT_MAGIC_STR_EX_T)
343+
344+
if (RCS_RECORD_TYPE_IS_MAGIC_STR_EX (type))
341345
{
342346
ecma_init_ecma_string_from_magic_string_ex_id (string_p,
343347
lit_magic_record_ex_get_magic_str_id (lit),
344348
is_stack_var);
345349
return;
346350
}
347351

348-
JERRY_ASSERT (lit->get_type () == LIT_STR_T);
352+
JERRY_ASSERT (RCS_RECORD_TYPE_IS_CHARSET (type));
349353

350354
string_p->refs = 1;
351355
string_p->is_stack_var = (is_stack_var != 0);
@@ -973,7 +977,7 @@ ecma_string_to_utf8_string (const ecma_string_t *string_desc_p, /**< ecma-string
973977
case ECMA_STRING_CONTAINER_LIT_TABLE:
974978
{
975979
literal_t lit = lit_get_literal_by_cp (string_desc_p->u.lit_cp);
976-
JERRY_ASSERT (lit->get_type () == LIT_STR_T);
980+
JERRY_ASSERT (RCS_RECORD_IS_CHARSET (lit));
977981
lit_literal_to_utf8_string (lit, buffer_p, (size_t) required_buffer_size);
978982
break;
979983
}
@@ -1309,7 +1313,7 @@ ecma_string_get_length (const ecma_string_t *string_p) /**< ecma-string */
13091313
if (container == ECMA_STRING_CONTAINER_LIT_TABLE)
13101314
{
13111315
literal_t lit = lit_get_literal_by_cp (string_p->u.lit_cp);
1312-
JERRY_ASSERT (lit->get_type () == LIT_STR_T);
1316+
JERRY_ASSERT (RCS_RECORD_IS_CHARSET (lit));
13131317
return lit_charset_record_get_length (lit);
13141318
}
13151319
else if (container == ECMA_STRING_CONTAINER_MAGIC_STRING)
@@ -1386,7 +1390,7 @@ ecma_string_get_size (const ecma_string_t *string_p) /**< ecma-string */
13861390
if (container == ECMA_STRING_CONTAINER_LIT_TABLE)
13871391
{
13881392
literal_t lit = lit_get_literal_by_cp (string_p->u.lit_cp);
1389-
JERRY_ASSERT (lit->get_type () == LIT_STR_T);
1393+
JERRY_ASSERT (RCS_RECORD_IS_CHARSET (lit));
13901394

13911395
return lit_charset_record_get_size (lit);
13921396
}

jerry-core/ecma/builtin-objects/ecma-builtin-global.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "lit-strings.h"
3030
#include "vm.h"
3131
#include "jrt-libc-includes.h"
32+
#include "jrt-bit-fields.h"
3233

3334
#define ECMA_BUILTINS_INTERNAL
3435
#include "ecma-builtins-internal.h"

jerry-core/jerry.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1677,7 +1677,8 @@ jerry_parse_and_save_snapshot (const jerry_api_char_t* source_p, /**< script sou
16771677
if (!jrt_write_to_buffer_by_offset (buffer_p,
16781678
buffer_size,
16791679
&buffer_write_offset,
1680-
version))
1680+
&version,
1681+
sizeof (version)))
16811682
{
16821683
return 0;
16831684
}
@@ -1726,7 +1727,7 @@ jerry_parse_and_save_snapshot (const jerry_api_char_t* source_p, /**< script sou
17261727
return 0;
17271728
}
17281729

1729-
is_ok = jrt_write_to_buffer_by_offset (buffer_p, buffer_size, &header_offset, header);
1730+
is_ok = jrt_write_to_buffer_by_offset (buffer_p, buffer_size, &header_offset, &header, sizeof (header));
17301731
JERRY_ASSERT (is_ok && header_offset < buffer_write_offset);
17311732

17321733
return buffer_write_offset;
@@ -1771,7 +1772,8 @@ jerry_exec_snapshot (const void *snapshot_p, /**< snapshot */
17711772
if (!jrt_read_from_buffer_by_offset (snapshot_data_p,
17721773
snapshot_size,
17731774
&snapshot_read,
1774-
&version))
1775+
&version,
1776+
sizeof (version)))
17751777
{
17761778
return JERRY_COMPLETION_CODE_INVALID_SNAPSHOT_FORMAT;
17771779
}
@@ -1797,11 +1799,10 @@ jerry_exec_snapshot (const void *snapshot_p, /**< snapshot */
17971799
lit_mem_to_snapshot_id_map_entry_t *lit_map_p = NULL;
17981800
uint32_t literals_num;
17991801

1800-
if (!lit_load_literals_from_snapshot (snapshot_data_p + snapshot_read,
1802+
if (!rcs_load_literals_from_snapshot (snapshot_data_p + snapshot_read,
18011803
header_p->lit_table_size,
18021804
&lit_map_p,
1803-
&literals_num,
1804-
is_copy))
1805+
&literals_num))
18051806
{
18061807
JERRY_ASSERT (lit_map_p == NULL);
18071808
return JERRY_COMPLETION_CODE_INVALID_SNAPSHOT_FORMAT;

jerry-core/jrt/jrt.h

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -226,58 +226,40 @@ inline void *operator new (size_t, void *where)
226226
return where;
227227
} /* operator new */
228228

229-
/**
230-
* Read data of specified type (T) from specified buffer
231-
*
232-
* Note:
233-
* Offset is in-out and is incremented if the read operation completes successfully.
234-
*
235-
* @return true, if read was successful, i.e. offset + sizeof (T) doesn't exceed buffer size,
236-
* false - otherwise.
237-
*/
238-
template<typename T>
239-
bool __attr_always_inline___
229+
inline bool
240230
jrt_read_from_buffer_by_offset (const uint8_t *buffer_p, /**< buffer */
241231
size_t buffer_size, /**< size of buffer */
242232
size_t *in_out_buffer_offset_p, /**< in: offset to read from,
243233
* out: offset, incremented on sizeof (T) */
244-
T *out_data_p) /**< out: data */
234+
void *out_data_p, /**< out: data */
235+
size_t out_data_size) /**< size of the out_data */
245236
{
246-
if (*in_out_buffer_offset_p + sizeof (T) > buffer_size)
237+
if (*in_out_buffer_offset_p + out_data_size > buffer_size)
247238
{
248239
return false;
249240
}
250241

251-
memcpy (out_data_p, buffer_p + *in_out_buffer_offset_p, sizeof (T));
252-
*in_out_buffer_offset_p += sizeof (T);
242+
memcpy (out_data_p, buffer_p + *in_out_buffer_offset_p, out_data_size);
243+
*in_out_buffer_offset_p += out_data_size;
253244

254245
return true;
255246
} /* jrt_read_from_buffer_by_offset */
256247

257-
/**
258-
* Write data of specified type (T) to specified buffer
259-
*
260-
* Note:
261-
* Offset is in-out and is incremented if the write operation completes successfully.
262-
*
263-
* @return true, if write was successful, i.e. offset + sizeof (T) doesn't exceed buffer size,
264-
* false - otherwise.
265-
*/
266-
template<typename T>
267-
bool __attr_always_inline___
248+
inline bool
268249
jrt_write_to_buffer_by_offset (uint8_t *buffer_p, /**< buffer */
269250
size_t buffer_size, /**< size of buffer */
270251
size_t *in_out_buffer_offset_p, /**< in: offset to read from,
271252
* out: offset, incremented on sizeof (T) */
272-
T data) /**< data */
253+
void *data_p, /**< data */
254+
size_t data_size) /**< size of data */
273255
{
274-
if (*in_out_buffer_offset_p + sizeof (T) > buffer_size)
256+
if (*in_out_buffer_offset_p + data_size > buffer_size)
275257
{
276258
return false;
277259
}
278260

279-
memcpy (buffer_p + *in_out_buffer_offset_p, &data, sizeof (T));
280-
*in_out_buffer_offset_p += sizeof (T);
261+
memcpy (buffer_p + *in_out_buffer_offset_p, data_p, data_size);
262+
*in_out_buffer_offset_p += data_size;
281263

282264
return true;
283265
} /* jrt_write_to_buffer_by_offset */

0 commit comments

Comments
 (0)