Skip to content

Commit 72c64df

Browse files
Roland TakacsRoland Takacs
authored andcommitted
Refactor literal-storage to not use C++ features
JerryScript-DCO-1.0-Signed-off-by: Roland Takacs [email protected]
1 parent 50d124b commit 72c64df

33 files changed

+2528
-3064
lines changed

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

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
#include "lit-globals.h"
2929
#include "lit-magic-strings.h"
3030
#include "mem-allocator.h"
31-
#include "rcs-recordset.h"
3231

3332
/** \addtogroup compressedpointer Compressed pointer
3433
* @{
@@ -787,16 +786,6 @@ typedef enum
787786
ECMA_STRING_CONTAINER_MAGIC_STRING_EX /**< the ecma-string is equal to one of external magic strings */
788787
} ecma_string_container_t;
789788

790-
FIXME (Move to library that should define the type (literal.h /* ? */))
791-
792-
/**
793-
* Literal and compressed pointer to literal
794-
*/
795-
typedef rcs_record_t *literal_t;
796-
typedef rcs_cpointer_t lit_cpointer_t;
797-
798-
#define NOT_A_LITERAL (lit_cpointer_t::null_cp ())
799-
800789
/**
801790
* ECMA string-value descriptor
802791
*/

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-char-helpers.h"
3232
#include "lit-magic-strings.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: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
#include "ecma-objects.h"
2929
#include "ecma-objects-general.h"
3030
#include "ecma-try-catch-macro.h"
31-
#include "lit-literal.h"
3231
#include "lit-magic-strings.h"
3332
#include "parser.h"
3433

@@ -1679,7 +1678,8 @@ jerry_parse_and_save_snapshot (const jerry_api_char_t* source_p, /**< script sou
16791678
if (!jrt_write_to_buffer_by_offset (buffer_p,
16801679
buffer_size,
16811680
&buffer_write_offset,
1682-
version))
1681+
&version,
1682+
sizeof (version)))
16831683
{
16841684
return 0;
16851685
}
@@ -1695,7 +1695,7 @@ jerry_parse_and_save_snapshot (const jerry_api_char_t* source_p, /**< script sou
16951695
lit_mem_to_snapshot_id_map_entry_t* lit_map_p = NULL;
16961696
uint32_t literals_num;
16971697

1698-
if (!lit_dump_literals_for_snapshot (buffer_p,
1698+
if (!rcs_dump_literals_for_snapshot (buffer_p,
16991699
buffer_size,
17001700
&buffer_write_offset,
17011701
&lit_map_p,
@@ -1732,7 +1732,7 @@ jerry_parse_and_save_snapshot (const jerry_api_char_t* source_p, /**< script sou
17321732
return 0;
17331733
}
17341734

1735-
is_ok = jrt_write_to_buffer_by_offset (buffer_p, buffer_size, &header_offset, header);
1735+
is_ok = jrt_write_to_buffer_by_offset (buffer_p, buffer_size, &header_offset, &header, sizeof (header));
17361736
JERRY_ASSERT (is_ok && header_offset < buffer_write_offset);
17371737

17381738
return buffer_write_offset;
@@ -1777,7 +1777,8 @@ jerry_exec_snapshot (const void *snapshot_p, /**< snapshot */
17771777
if (!jrt_read_from_buffer_by_offset (snapshot_data_p,
17781778
snapshot_size,
17791779
&snapshot_read,
1780-
&version))
1780+
&version,
1781+
sizeof (version)))
17811782
{
17821783
return JERRY_COMPLETION_CODE_INVALID_SNAPSHOT_FORMAT;
17831784
}
@@ -1803,11 +1804,10 @@ jerry_exec_snapshot (const void *snapshot_p, /**< snapshot */
18031804
lit_mem_to_snapshot_id_map_entry_t *lit_map_p = NULL;
18041805
uint32_t literals_num;
18051806

1806-
if (!lit_load_literals_from_snapshot (snapshot_data_p + snapshot_read,
1807+
if (!rcs_load_literals_from_snapshot (snapshot_data_p + snapshot_read,
18071808
header_p->lit_table_size,
18081809
&lit_map_p,
1809-
&literals_num,
1810-
is_copy))
1810+
&literals_num))
18111811
{
18121812
JERRY_ASSERT (lit_map_p == NULL);
18131813
return JERRY_COMPLETION_CODE_INVALID_SNAPSHOT_FORMAT;

jerry-core/jrt/jrt.h

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -227,57 +227,57 @@ inline void *operator new (size_t, void *where)
227227
} /* operator new */
228228

229229
/**
230-
* Read data of specified type (T) from specified buffer
230+
* Read data from a specified buffer.
231231
*
232232
* Note:
233233
* Offset is in-out and is incremented if the read operation completes successfully.
234234
*
235-
* @return true, if read was successful, i.e. offset + sizeof (T) doesn't exceed buffer size,
235+
* @return true, if read was successful, i.e. offset + data_size doesn't exceed buffer size,
236236
* false - otherwise.
237237
*/
238-
template<typename T>
239-
bool __attr_always_inline___
238+
inline bool
240239
jrt_read_from_buffer_by_offset (const uint8_t *buffer_p, /**< buffer */
241240
size_t buffer_size, /**< size of buffer */
242241
size_t *in_out_buffer_offset_p, /**< in: offset to read from,
243242
* out: offset, incremented on sizeof (T) */
244-
T *out_data_p) /**< out: data */
243+
void *out_data_p, /**< out: data */
244+
size_t out_data_size) /**< size of the readable data */
245245
{
246-
if (*in_out_buffer_offset_p + sizeof (T) > buffer_size)
246+
if (*in_out_buffer_offset_p + out_data_size > buffer_size)
247247
{
248248
return false;
249249
}
250250

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

254254
return true;
255255
} /* jrt_read_from_buffer_by_offset */
256256

257257
/**
258-
* Write data of specified type (T) to specified buffer
258+
* Write data to a specified buffer.
259259
*
260260
* Note:
261261
* Offset is in-out and is incremented if the write operation completes successfully.
262262
*
263-
* @return true, if write was successful, i.e. offset + sizeof (T) doesn't exceed buffer size,
263+
* @return true, if write was successful, i.e. offset + data_size doesn't exceed buffer size,
264264
* false - otherwise.
265265
*/
266-
template<typename T>
267-
bool __attr_always_inline___
266+
inline bool
268267
jrt_write_to_buffer_by_offset (uint8_t *buffer_p, /**< buffer */
269268
size_t buffer_size, /**< size of buffer */
270269
size_t *in_out_buffer_offset_p, /**< in: offset to read from,
271270
* out: offset, incremented on sizeof (T) */
272-
T data) /**< data */
271+
void *data_p, /**< data */
272+
size_t data_size) /**< size of the writable data */
273273
{
274-
if (*in_out_buffer_offset_p + sizeof (T) > buffer_size)
274+
if (*in_out_buffer_offset_p + data_size > buffer_size)
275275
{
276276
return false;
277277
}
278278

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

282282
return true;
283283
} /* jrt_write_to_buffer_by_offset */

jerry-core/lit/lit-globals.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#define LIT_GLOBALS_H
1818

1919
#include "jrt.h"
20+
#include "rcs-cpointer.h"
2021

2122
/**
2223
* ECMAScript standard defines terms "code unit" and "character" as 16-bit unsigned value
@@ -123,6 +124,21 @@ typedef uint32_t lit_code_point_t;
123124
*/
124125
typedef uint8_t lit_string_hash_t;
125126

127+
/**
128+
* Literal type
129+
*/
130+
typedef record_t *literal_t;
131+
132+
/**
133+
* Compressed pointer type
134+
*/
135+
typedef cpointer_t lit_cpointer_t;
136+
137+
/**
138+
* Invalid literal
139+
*/
140+
#define NOT_A_LITERAL (rcs_cpointer_null_cp ())
141+
126142
/**
127143
* ECMA string hash value length, in bits
128144
*/

0 commit comments

Comments
 (0)