New Allocator and improved String handling.
JerryScript-DCO-1.0-Signed-off-by: Dániel Bátyai dbatyai@inf.u-szeged.hu
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
/* Copyright 2015 Samsung Electronics Co., Ltd.
|
||||
* Copyright 2015-2016 University of Szeged
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "lit-cpointer.h"
|
||||
#include "jrt-bit-fields.h"
|
||||
|
||||
/**
|
||||
* Compress pointer to extended compressed pointer.
|
||||
*
|
||||
* @return dynamic storage-specific extended compressed pointer
|
||||
*/
|
||||
lit_cpointer_t __attr_pure___ __attr_always_inline___
|
||||
lit_cpointer_compress (lit_record_t *pointer) /**< pointer to compress */
|
||||
{
|
||||
if (pointer == NULL)
|
||||
{
|
||||
return MEM_CP_NULL;
|
||||
}
|
||||
|
||||
return (lit_cpointer_t) mem_compress_pointer (pointer);
|
||||
} /* lit_cpointer_compress */
|
||||
|
||||
/**
|
||||
* Decompress extended compressed pointer.
|
||||
*
|
||||
* @return decompressed pointer
|
||||
*/
|
||||
lit_record_t * __attr_pure___ __attr_always_inline___
|
||||
lit_cpointer_decompress (lit_cpointer_t compressed_pointer) /**< recordset-specific compressed pointer */
|
||||
{
|
||||
if (compressed_pointer == MEM_CP_NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return (lit_record_t *) mem_decompress_pointer (compressed_pointer);
|
||||
} /* lit_cpointer_decompress */
|
||||
|
||||
/**
|
||||
* Create NULL compressed pointer.
|
||||
*
|
||||
* @return NULL compressed pointer
|
||||
*/
|
||||
lit_cpointer_t __attr_pure___ __attr_always_inline___
|
||||
lit_cpointer_null_cp (void)
|
||||
{
|
||||
return MEM_CP_NULL;
|
||||
} /* lit_cpointer_null_cp */
|
||||
@@ -0,0 +1,38 @@
|
||||
/* Copyright 2015 Samsung Electronics Co., Ltd.
|
||||
* Copyright 2015-2016 University of Szeged
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef LIT_CPOINTER_H
|
||||
#define LIT_CPOINTER_H
|
||||
|
||||
#include "lit-literal-storage.h"
|
||||
#include "mem-allocator.h"
|
||||
|
||||
#define LIT_CPOINTER_WIDTH (MEM_CP_WIDTH + MEM_ALIGNMENT_LOG - MEM_ALIGNMENT_LOG)
|
||||
|
||||
/**
|
||||
* Dynamic storage-specific extended compressed pointer
|
||||
*
|
||||
* Note:
|
||||
* the pointer can represent addresses aligned by lit_DYN_STORAGE_LENGTH_UNIT,
|
||||
* while mem_cpointer_t can only represent addresses aligned by MEM_ALIGNMENT.
|
||||
*/
|
||||
typedef uint16_t lit_cpointer_t;
|
||||
|
||||
extern lit_cpointer_t lit_cpointer_compress (lit_record_t *);
|
||||
extern lit_record_t *lit_cpointer_decompress (lit_cpointer_t);
|
||||
extern lit_cpointer_t lit_cpointer_null_cp ();
|
||||
|
||||
#endif /* !LIT_CPOINTER_H */
|
||||
@@ -17,7 +17,6 @@
|
||||
#define LIT_GLOBALS_H
|
||||
|
||||
#include "jrt.h"
|
||||
#include "rcs-cpointer.h"
|
||||
|
||||
/**
|
||||
* ECMAScript standard defines terms "code unit" and "character" as 16-bit unsigned value
|
||||
@@ -129,21 +128,6 @@ typedef uint32_t lit_code_point_t;
|
||||
*/
|
||||
typedef uint8_t lit_string_hash_t;
|
||||
|
||||
/**
|
||||
* Literal type
|
||||
*/
|
||||
typedef rcs_record_t *lit_literal_t;
|
||||
|
||||
/**
|
||||
* Compressed pointer type
|
||||
*/
|
||||
typedef rcs_cpointer_t lit_cpointer_t;
|
||||
|
||||
/**
|
||||
* Invalid literal
|
||||
*/
|
||||
#define NOT_A_LITERAL (rcs_cpointer_null_cp ())
|
||||
|
||||
/**
|
||||
* ECMA string hash value length, in bits
|
||||
*/
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* Copyright 2015 Samsung Electronics Co., Ltd.
|
||||
* Copyright 2015 University of Szeged
|
||||
* Copyright 2015-2016 University of Szeged
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -15,85 +15,144 @@
|
||||
*/
|
||||
|
||||
#include "lit-literal-storage.h"
|
||||
#include "lit-cpointer.h"
|
||||
|
||||
#include "ecma-helpers.h"
|
||||
#include "rcs-allocator.h"
|
||||
#include "rcs-iterator.h"
|
||||
#include "rcs-records.h"
|
||||
|
||||
rcs_record_set_t rcs_lit_storage;
|
||||
lit_record_t *lit_storage = NULL;
|
||||
|
||||
/**
|
||||
* Create charset record in the literal storage
|
||||
*
|
||||
* @return pointer to the created record
|
||||
*/
|
||||
rcs_record_t *
|
||||
lit_storage_create_charset_literal (rcs_record_set_t *rec_set_p, /**< recordset */
|
||||
const lit_utf8_byte_t *str_p, /**< string to be placed into the record */
|
||||
const lit_utf8_size_t buf_size) /**< size of the string (in bytes) */
|
||||
lit_record_t *
|
||||
lit_create_charset_literal (const lit_utf8_byte_t *str_p, /**< string to be placed into the record */
|
||||
const lit_utf8_size_t buf_size) /**< size in bytes of the buffer which holds the string */
|
||||
{
|
||||
const size_t record_size = RCS_CHARSET_HEADER_SIZE + buf_size;
|
||||
const size_t aligned_record_size = JERRY_ALIGNUP (record_size, RCS_DYN_STORAGE_LENGTH_UNIT);
|
||||
const size_t alignment = aligned_record_size - record_size;
|
||||
lit_charset_record_t *rec_p = (lit_charset_record_t *) mem_heap_alloc_block (buf_size + LIT_CHARSET_HEADER_SIZE);
|
||||
|
||||
rcs_record_t *rec_p = rcs_alloc_record (rec_set_p, RCS_RECORD_TYPE_CHARSET, aligned_record_size);
|
||||
rec_p->type = LIT_RECORD_TYPE_CHARSET;
|
||||
rec_p->next = (uint16_t) lit_cpointer_compress (lit_storage);
|
||||
lit_storage = (lit_record_t *) rec_p;
|
||||
|
||||
rcs_record_set_alignment_bytes_count (rec_p, (uint8_t) alignment);
|
||||
rcs_record_set_charset (rec_set_p, rec_p, str_p, buf_size);
|
||||
rcs_record_set_hash (rec_p, lit_utf8_string_calc_hash (str_p, rcs_record_get_length (rec_p)));
|
||||
rec_p->hash = (uint8_t) lit_utf8_string_calc_hash (str_p, buf_size);
|
||||
rec_p->size = (uint16_t) buf_size;
|
||||
rec_p->length = (uint16_t) lit_utf8_string_length (str_p, buf_size);
|
||||
memcpy (rec_p + 1, str_p, buf_size);
|
||||
|
||||
return rec_p;
|
||||
} /* lit_storage_create_charset_literal */
|
||||
return (lit_record_t *) rec_p;
|
||||
} /* lit_create_charset_literal */
|
||||
|
||||
/**
|
||||
* Create magic string record in the literal storage.
|
||||
*
|
||||
* @return pointer to the created record
|
||||
*/
|
||||
rcs_record_t *
|
||||
lit_storage_create_magic_literal (rcs_record_set_t *rec_set_p, /**< recordset */
|
||||
lit_magic_string_id_t id) /**< id of magic string */
|
||||
lit_record_t *
|
||||
lit_create_magic_literal (const lit_magic_string_id_t id) /**< id of magic string */
|
||||
{
|
||||
rcs_record_t *rec_p = rcs_alloc_record (rec_set_p, RCS_RECORD_TYPE_MAGIC_STR, RCS_MAGIC_STR_HEADER_SIZE);
|
||||
rcs_record_set_magic_str_id (rec_p, id);
|
||||
lit_magic_record_t *rec_p = (lit_magic_record_t *) mem_heap_alloc_block (sizeof (lit_magic_record_t));
|
||||
rec_p->type = LIT_RECORD_TYPE_MAGIC_STR;
|
||||
rec_p->next = (uint16_t) lit_cpointer_compress (lit_storage);
|
||||
lit_storage = (lit_record_t *) rec_p;
|
||||
|
||||
return rec_p;
|
||||
} /* lit_storage_create_magic_literal */
|
||||
rec_p->magic_id = (uint32_t) id;
|
||||
|
||||
return (lit_record_t *) rec_p;
|
||||
} /* lit_create_magic_literal */
|
||||
|
||||
/**
|
||||
* Create external magic string record in the literal storage.
|
||||
*
|
||||
* @return pointer to the created record
|
||||
*/
|
||||
rcs_record_t *
|
||||
lit_storage_create_magic_literal_ex (rcs_record_set_t *rec_set_p, /**< recordset */
|
||||
lit_magic_string_ex_id_t id) /**< id of magic string */
|
||||
lit_record_t *
|
||||
lit_create_magic_literal_ex (const lit_magic_string_ex_id_t id) /**< id of magic string */
|
||||
{
|
||||
rcs_record_t *rec_p = rcs_alloc_record (rec_set_p, RCS_RECORD_TYPE_MAGIC_STR_EX, RCS_MAGIC_STR_HEADER_SIZE);
|
||||
rcs_record_set_magic_str_ex_id (rec_p, id);
|
||||
lit_magic_record_t *rec_p = (lit_magic_record_t *) mem_heap_alloc_block (sizeof (lit_magic_record_t));
|
||||
rec_p->type = LIT_RECORD_TYPE_MAGIC_STR_EX;
|
||||
rec_p->next = (uint16_t) lit_cpointer_compress (lit_storage);
|
||||
lit_storage = (lit_record_t *) rec_p;
|
||||
|
||||
return rec_p;
|
||||
} /* lit_storage_create_magic_literal_ex */
|
||||
rec_p->magic_id = (uint32_t) id;
|
||||
|
||||
return (lit_record_t *) rec_p;
|
||||
} /* lit_create_magic_literal_ex */
|
||||
|
||||
/**
|
||||
* Create number record in the literal storage.
|
||||
*
|
||||
* @return pointer to the created record
|
||||
*/
|
||||
rcs_record_t *
|
||||
lit_storage_create_number_literal (rcs_record_set_t *rec_set_p, /**< recordset */
|
||||
ecma_number_t num) /**< numeric value */
|
||||
lit_record_t *
|
||||
lit_create_number_literal (const ecma_number_t num) /**< numeric value */
|
||||
{
|
||||
const size_t record_size = RCS_NUMBER_HEADER_SIZE + sizeof (ecma_number_t);
|
||||
rcs_record_t *rec_p = rcs_alloc_record (rec_set_p, RCS_RECORD_TYPE_NUMBER, record_size);
|
||||
lit_number_record_t *rec_p = (lit_number_record_t *) mem_heap_alloc_block (sizeof (lit_number_record_t));
|
||||
|
||||
rcs_iterator_t it_ctx = rcs_iterator_create (rec_set_p, rec_p);
|
||||
rcs_iterator_skip (&it_ctx, RCS_NUMBER_HEADER_SIZE);
|
||||
rcs_iterator_write (&it_ctx, &num, sizeof (ecma_number_t));
|
||||
rec_p->type = (uint8_t) LIT_RECORD_TYPE_NUMBER;
|
||||
rec_p->next = (uint16_t) lit_cpointer_compress (lit_storage);
|
||||
lit_storage = (lit_record_t *) rec_p;
|
||||
|
||||
return rec_p;
|
||||
} /* lit_storage_create_number_literal */
|
||||
rec_p->number = num;
|
||||
|
||||
return (lit_record_t *) rec_p;
|
||||
} /* lit_create_number_literal */
|
||||
|
||||
/**
|
||||
* Get size of stored literal
|
||||
*
|
||||
* @return size of literal
|
||||
*/
|
||||
size_t __attr_pure___
|
||||
lit_get_literal_size (const lit_record_t *lit_p) /**< literal record */
|
||||
{
|
||||
const lit_record_type_t type = (const lit_record_type_t) lit_p->type;
|
||||
size_t size = 0;
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case LIT_RECORD_TYPE_NUMBER:
|
||||
{
|
||||
size = sizeof (lit_number_record_t);
|
||||
break;
|
||||
}
|
||||
case LIT_RECORD_TYPE_CHARSET:
|
||||
{
|
||||
const lit_charset_record_t *const rec_p = (const lit_charset_record_t *) lit_p;
|
||||
size = rec_p->size + LIT_CHARSET_HEADER_SIZE;
|
||||
break;
|
||||
}
|
||||
case LIT_RECORD_TYPE_MAGIC_STR:
|
||||
case LIT_RECORD_TYPE_MAGIC_STR_EX:
|
||||
{
|
||||
size = sizeof (lit_magic_record_t);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
JERRY_UNREACHABLE ();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
JERRY_ASSERT (size > 0);
|
||||
return size;
|
||||
} /* lit_get_literal_size */
|
||||
|
||||
|
||||
/**
|
||||
* Free stored literal
|
||||
*
|
||||
* @return pointer to the next literal in the list
|
||||
*/
|
||||
lit_record_t *
|
||||
lit_free_literal (lit_record_t *lit_p) /**< literal record */
|
||||
{
|
||||
lit_record_t *const ret_p = lit_cpointer_decompress (lit_p->next);
|
||||
mem_heap_free_block (lit_p, lit_get_literal_size (lit_p));
|
||||
return ret_p;
|
||||
} /* lit_free_literal */
|
||||
|
||||
/**
|
||||
* Count literal records in the storage
|
||||
@@ -101,85 +160,80 @@ lit_storage_create_number_literal (rcs_record_set_t *rec_set_p, /**< recordset *
|
||||
* @return number of literals
|
||||
*/
|
||||
uint32_t
|
||||
lit_storage_count_literals (rcs_record_set_t *rec_set_p) /**< recordset */
|
||||
lit_count_literals ()
|
||||
{
|
||||
uint32_t num = 0;
|
||||
rcs_record_t *rec_p;
|
||||
lit_record_t *rec_p;
|
||||
|
||||
for (rec_p = rcs_record_get_first (rec_set_p);
|
||||
for (rec_p = lit_storage;
|
||||
rec_p != NULL;
|
||||
rec_p = rcs_record_get_next (rec_set_p, rec_p))
|
||||
rec_p = lit_cpointer_decompress (rec_p->next))
|
||||
{
|
||||
if (rcs_record_get_type (rec_p) >= RCS_RECORD_TYPE_FIRST)
|
||||
if (rec_p->type > LIT_RECORD_TYPE_FREE)
|
||||
{
|
||||
num++;
|
||||
}
|
||||
}
|
||||
|
||||
return num;
|
||||
} /* lit_storage_count_literals */
|
||||
} /* lit_count_literals */
|
||||
|
||||
/**
|
||||
* Dump the contents of the literal storage.
|
||||
*/
|
||||
void
|
||||
lit_storage_dump_literals (rcs_record_set_t *rec_set_p) /**< recordset */
|
||||
lit_dump_literals ()
|
||||
{
|
||||
rcs_record_t *rec_p;
|
||||
lit_record_t *rec_p;
|
||||
size_t i;
|
||||
|
||||
printf ("LITERALS:\n");
|
||||
|
||||
for (rec_p = rcs_record_get_first (rec_set_p);
|
||||
for (rec_p = lit_storage;
|
||||
rec_p != NULL;
|
||||
rec_p = rcs_record_get_next (rec_set_p, rec_p))
|
||||
rec_p = lit_cpointer_decompress (rec_p->next))
|
||||
{
|
||||
printf ("%p ", rec_p);
|
||||
printf ("[%3zu] ", rcs_record_get_size (rec_p));
|
||||
printf ("[%3zu] ", lit_get_literal_size (rec_p));
|
||||
|
||||
switch (rcs_record_get_type (rec_p))
|
||||
switch (rec_p->type)
|
||||
{
|
||||
case RCS_RECORD_TYPE_CHARSET:
|
||||
case LIT_RECORD_TYPE_CHARSET:
|
||||
{
|
||||
rcs_iterator_t it_ctx = rcs_iterator_create (rec_set_p, rec_p);
|
||||
rcs_iterator_skip (&it_ctx, RCS_CHARSET_HEADER_SIZE);
|
||||
|
||||
size_t str_len = rcs_record_get_length (rec_p);
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < str_len; ++i)
|
||||
const lit_charset_record_t *const record_p = (const lit_charset_record_t *) rec_p;
|
||||
char *str = (char *) (record_p + 1);
|
||||
for (i = 0; i < record_p->size; ++i, ++str)
|
||||
{
|
||||
FIXME ("Support proper printing of characters which occupy more than one byte.")
|
||||
|
||||
lit_utf8_byte_t chr;
|
||||
rcs_iterator_read (&it_ctx, &chr, sizeof (lit_utf8_byte_t));
|
||||
rcs_iterator_skip (&it_ctx, sizeof (lit_utf8_byte_t));
|
||||
|
||||
printf ("%c", chr);
|
||||
printf ("%c", *str);
|
||||
}
|
||||
|
||||
printf (" : STRING");
|
||||
|
||||
break;
|
||||
}
|
||||
case RCS_RECORD_TYPE_MAGIC_STR:
|
||||
case LIT_RECORD_TYPE_MAGIC_STR:
|
||||
{
|
||||
lit_magic_string_id_t id = rcs_record_get_magic_str_id (rec_p);
|
||||
lit_magic_string_id_t id = (lit_magic_string_id_t) ((lit_magic_record_t *) rec_p)->magic_id;
|
||||
printf ("%s : MAGIC STRING", lit_get_magic_string_utf8 (id));
|
||||
printf (" [id=%d] ", id);
|
||||
|
||||
break;
|
||||
}
|
||||
case RCS_RECORD_TYPE_MAGIC_STR_EX:
|
||||
case LIT_RECORD_TYPE_MAGIC_STR_EX:
|
||||
{
|
||||
lit_magic_string_ex_id_t id = rcs_record_get_magic_str_ex_id (rec_p);
|
||||
lit_magic_string_ex_id_t id = ((lit_magic_record_t *) rec_p)->magic_id;
|
||||
printf ("%s : EXT MAGIC STRING", lit_get_magic_string_ex_utf8 (id));
|
||||
printf (" [id=%d] ", id);
|
||||
|
||||
break;
|
||||
}
|
||||
case RCS_RECORD_TYPE_NUMBER:
|
||||
case LIT_RECORD_TYPE_NUMBER:
|
||||
{
|
||||
ecma_number_t value = rcs_record_get_number (rec_set_p, rec_p);
|
||||
const lit_number_record_t *const record_p = (const lit_number_record_t *) rec_p;
|
||||
ecma_number_t value;
|
||||
memcpy (&value, &record_p->number, sizeof (ecma_number_t));
|
||||
|
||||
if (ecma_number_is_nan (value))
|
||||
{
|
||||
@@ -200,10 +254,10 @@ lit_storage_dump_literals (rcs_record_set_t *rec_set_p) /**< recordset */
|
||||
}
|
||||
default:
|
||||
{
|
||||
printf (" : EMPTY RECORD");
|
||||
JERRY_UNREACHABLE ();
|
||||
}
|
||||
}
|
||||
|
||||
printf ("\n");
|
||||
}
|
||||
} /* lit_storage_dump_literals */
|
||||
} /* lit_dump_literals */
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* Copyright 2015 Samsung Electronics Co., Ltd.
|
||||
* Copyright 2015 University of Szeged
|
||||
* Copyright 2015-2016 University of Szeged
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -17,16 +17,87 @@
|
||||
#ifndef LIT_LITERAL_STORAGE_H
|
||||
#define LIT_LITERAL_STORAGE_H
|
||||
|
||||
#include "lit-magic-strings.h"
|
||||
#include "lit-globals.h"
|
||||
#include "ecma-globals.h"
|
||||
|
||||
extern rcs_record_set_t rcs_lit_storage;
|
||||
/**
|
||||
* Represents the type of the record.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
LIT_RECORD_TYPE_FREE = 0, /**< Free record that marks an empty space. It doesn't hold any values. */
|
||||
LIT_RECORD_TYPE_CHARSET = 1, /**< Charset record that holds characters. */
|
||||
LIT_RECORD_TYPE_MAGIC_STR = 2, /**< Magic string record that holds a magic string id. */
|
||||
LIT_RECORD_TYPE_MAGIC_STR_EX = 3, /**< External magic string record that holds an extrernal magic string id. */
|
||||
LIT_RECORD_TYPE_NUMBER = 4 /**< Number record that holds a numeric value. */
|
||||
} lit_record_type_t;
|
||||
|
||||
extern rcs_record_t *lit_storage_create_charset_literal (rcs_record_set_t *, const lit_utf8_byte_t *, lit_utf8_size_t);
|
||||
extern rcs_record_t *lit_storage_create_magic_literal (rcs_record_set_t *, lit_magic_string_id_t);
|
||||
extern rcs_record_t *lit_storage_create_magic_literal_ex (rcs_record_set_t *, lit_magic_string_ex_id_t);
|
||||
extern rcs_record_t *lit_storage_create_number_literal (rcs_record_set_t *, ecma_number_t);
|
||||
/**
|
||||
* Record header
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint16_t next; /* Compressed pointer to next record */
|
||||
uint8_t type; /* Type of record */
|
||||
} lit_record_t;
|
||||
|
||||
extern uint32_t lit_storage_count_literals (rcs_record_set_t *);
|
||||
extern void lit_storage_dump_literals (rcs_record_set_t *);
|
||||
/**
|
||||
* Head pointer to literal storage
|
||||
*/
|
||||
extern lit_record_t *lit_storage;
|
||||
|
||||
typedef lit_record_t *lit_literal_t;
|
||||
|
||||
/**
|
||||
* Charset record header
|
||||
*
|
||||
* String is stored after the header.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint16_t next; /* Compressed pointer to next record */
|
||||
uint8_t type; /* Type of record */
|
||||
uint8_t hash; /* Hash of the string */
|
||||
uint16_t size; /* Size of the string in bytes */
|
||||
uint16_t length; /* Number of character in the string */
|
||||
} lit_charset_record_t;
|
||||
|
||||
/**
|
||||
* Number record header
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint16_t next; /* Compressed pointer to next record */
|
||||
uint8_t type; /* Type of record */
|
||||
ecma_number_t number; /* Number stored in the record */
|
||||
} lit_number_record_t;
|
||||
|
||||
/**
|
||||
* Magic record header
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint16_t next; /* Compressed pointer to next record */
|
||||
uint8_t type; /* Type of record */
|
||||
uint32_t magic_id; /* Magic ID stored in the record */
|
||||
} lit_magic_record_t;
|
||||
|
||||
#define LIT_CHARSET_HEADER_SIZE (sizeof(lit_charset_record_t))
|
||||
|
||||
extern lit_record_t *lit_create_charset_literal (const lit_utf8_byte_t *, const lit_utf8_size_t);
|
||||
extern lit_record_t *lit_create_magic_literal (const lit_magic_string_id_t);
|
||||
extern lit_record_t *lit_create_magic_literal_ex (const lit_magic_string_ex_id_t);
|
||||
extern lit_record_t *lit_create_number_literal (const ecma_number_t);
|
||||
extern lit_record_t *lit_free_literal (lit_record_t *);
|
||||
extern size_t lit_get_literal_size (const lit_record_t *);
|
||||
|
||||
extern uint32_t lit_count_literals ();
|
||||
extern void lit_dump_literals ();
|
||||
|
||||
#define LIT_RECORD_IS_CHARSET(lit) (((lit_record_t *) lit)->type == LIT_RECORD_TYPE_CHARSET)
|
||||
#define LIT_RECORD_IS_MAGIC_STR(lit) (((lit_record_t *) lit)->type == LIT_RECORD_TYPE_MAGIC_STR)
|
||||
#define LIT_RECORD_IS_MAGIC_STR_EX(lit) (((lit_record_t *) lit)->type == LIT_RECORD_TYPE_MAGIC_STR_EX)
|
||||
#define LIT_RECORD_IS_NUMBER(lit) (((lit_record_t *) lit)->type == LIT_RECORD_TYPE_NUMBER)
|
||||
|
||||
#endif /* !LIT_LITERAL_STORAGE_H */
|
||||
|
||||
+215
-169
@@ -1,4 +1,5 @@
|
||||
/* Copyright 2015 Samsung Electronics Co., Ltd.
|
||||
* Copyright 2016 University of Szeged.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,21 +17,17 @@
|
||||
#include "lit-literal.h"
|
||||
|
||||
#include "ecma-helpers.h"
|
||||
#include "rcs-allocator.h"
|
||||
#include "rcs-records.h"
|
||||
#include "rcs-iterator.h"
|
||||
#include "lit-cpointer.h"
|
||||
#include "lit-magic-strings.h"
|
||||
#include "lit-literal-storage.h"
|
||||
|
||||
|
||||
/**
|
||||
* Initialize literal storage
|
||||
*/
|
||||
void
|
||||
lit_init (void)
|
||||
{
|
||||
JERRY_ASSERT (rcs_get_node_data_space_size () % RCS_DYN_STORAGE_LENGTH_UNIT == 0);
|
||||
|
||||
rcs_chunked_list_init (&rcs_lit_storage);
|
||||
|
||||
lit_magic_strings_ex_init ();
|
||||
} /* lit_init */
|
||||
|
||||
@@ -40,19 +37,12 @@ lit_init (void)
|
||||
void
|
||||
lit_finalize (void)
|
||||
{
|
||||
rcs_chunked_list_cleanup (&rcs_lit_storage);
|
||||
rcs_chunked_list_free (&rcs_lit_storage);
|
||||
while (lit_storage)
|
||||
{
|
||||
lit_storage = lit_free_literal (lit_storage);
|
||||
}
|
||||
} /* lit_finalize */
|
||||
|
||||
/**
|
||||
* Dump records from the literal storage
|
||||
*/
|
||||
void
|
||||
lit_dump_literals (void)
|
||||
{
|
||||
lit_storage_dump_literals (&rcs_lit_storage);
|
||||
} /* lit_dump_literals */
|
||||
|
||||
/**
|
||||
* Create new literal in literal storage from characters buffer.
|
||||
* Don't check if the same literal already exists.
|
||||
@@ -78,7 +68,7 @@ lit_create_literal_from_utf8_string (const lit_utf8_byte_t *str_p, /**< string t
|
||||
|
||||
if (!strncmp ((const char *) str_p, (const char *) lit_get_magic_string_utf8 (m_str_id), str_size))
|
||||
{
|
||||
return lit_storage_create_magic_literal (&rcs_lit_storage, m_str_id);
|
||||
return lit_create_magic_literal (m_str_id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,11 +84,11 @@ lit_create_literal_from_utf8_string (const lit_utf8_byte_t *str_p, /**< string t
|
||||
|
||||
if (!strncmp ((const char *) str_p, (const char *) lit_get_magic_string_ex_utf8 (m_str_ex_id), str_size))
|
||||
{
|
||||
return lit_storage_create_magic_literal_ex (&rcs_lit_storage, m_str_ex_id);
|
||||
return lit_create_magic_literal_ex (m_str_ex_id);
|
||||
}
|
||||
}
|
||||
|
||||
return lit_storage_create_charset_literal (&rcs_lit_storage, str_p, str_size);
|
||||
return lit_create_charset_literal (str_p, str_size);
|
||||
} /* lit_create_literal_from_utf8_string */
|
||||
|
||||
/**
|
||||
@@ -117,57 +107,73 @@ lit_find_literal_by_utf8_string (const lit_utf8_byte_t *str_p, /**< a string to
|
||||
|
||||
lit_literal_t lit;
|
||||
|
||||
for (lit = rcs_record_get_first (&rcs_lit_storage);
|
||||
for (lit = lit_storage;
|
||||
lit != NULL;
|
||||
lit = rcs_record_get_next (&rcs_lit_storage, lit))
|
||||
lit = lit_cpointer_decompress (lit->next))
|
||||
{
|
||||
rcs_record_type_t type = rcs_record_get_type (lit);
|
||||
const lit_record_type_t type = (lit_record_type_t) lit->type;
|
||||
|
||||
if (RCS_RECORD_TYPE_IS_CHARSET (type))
|
||||
switch (type)
|
||||
{
|
||||
if (rcs_record_get_hash (lit) != str_hash)
|
||||
case LIT_RECORD_TYPE_CHARSET:
|
||||
{
|
||||
continue;
|
||||
}
|
||||
const lit_charset_record_t *const rec_p = (const lit_charset_record_t *) lit;
|
||||
|
||||
if (rcs_record_get_length (lit) != str_size)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (rec_p->hash != str_hash)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (rcs_record_is_equal_charset (&rcs_lit_storage, lit, str_p, str_size))
|
||||
{
|
||||
return lit;
|
||||
}
|
||||
}
|
||||
else if (RCS_RECORD_TYPE_IS_MAGIC_STR (type))
|
||||
{
|
||||
lit_magic_string_id_t magic_id = rcs_record_get_magic_str_id (lit);
|
||||
const lit_utf8_byte_t *magic_str_p = lit_get_magic_string_utf8 (magic_id);
|
||||
if (rec_p->size != str_size)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (lit_get_magic_string_size (magic_id) != str_size)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (!strncmp (rec_p + 1, (const char *) str_p, str_size))
|
||||
{
|
||||
return lit;
|
||||
}
|
||||
|
||||
if (!strncmp ((const char *) magic_str_p, (const char *) str_p, str_size))
|
||||
{
|
||||
return lit;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (RCS_RECORD_TYPE_IS_MAGIC_STR_EX (type))
|
||||
{
|
||||
lit_magic_string_ex_id_t magic_id = rcs_record_get_magic_str_ex_id (lit);
|
||||
const lit_utf8_byte_t *magic_str_p = lit_get_magic_string_ex_utf8 (magic_id);
|
||||
|
||||
if (lit_get_magic_string_ex_size (magic_id) != str_size)
|
||||
case LIT_RECORD_TYPE_MAGIC_STR:
|
||||
{
|
||||
continue;
|
||||
lit_magic_string_id_t magic_id = (lit_magic_string_id_t) ((lit_magic_record_t *) lit)->magic_id;
|
||||
const lit_utf8_byte_t *magic_str_p = lit_get_magic_string_utf8 (magic_id);
|
||||
|
||||
if (lit_get_magic_string_size (magic_id) != str_size)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!strncmp ((const char *) magic_str_p, (const char *) str_p, str_size))
|
||||
{
|
||||
return lit;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if (!strncmp ((const char *) magic_str_p, (const char *) str_p, str_size))
|
||||
case LIT_RECORD_TYPE_MAGIC_STR_EX:
|
||||
{
|
||||
return lit;
|
||||
lit_magic_string_ex_id_t magic_id = ((lit_magic_record_t *) lit)->magic_id;
|
||||
const lit_utf8_byte_t *magic_str_p = lit_get_magic_string_ex_utf8 (magic_id);
|
||||
|
||||
if (lit_get_magic_string_ex_size (magic_id) != str_size)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!strncmp ((const char *) magic_str_p, (const char *) str_p, str_size))
|
||||
{
|
||||
return lit;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
JERRY_ASSERT (type == LIT_RECORD_TYPE_NUMBER);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -183,7 +189,7 @@ lit_find_literal_by_utf8_string (const lit_utf8_byte_t *str_p, /**< a string to
|
||||
*/
|
||||
lit_literal_t
|
||||
lit_find_or_create_literal_from_utf8_string (const lit_utf8_byte_t *str_p, /**< string, could be non-zero-terminated */
|
||||
lit_utf8_size_t str_size) /**< length of the string */
|
||||
const lit_utf8_size_t str_size) /**< length of the string */
|
||||
{
|
||||
lit_literal_t lit = lit_find_literal_by_utf8_string (str_p, str_size);
|
||||
|
||||
@@ -201,10 +207,10 @@ lit_find_or_create_literal_from_utf8_string (const lit_utf8_byte_t *str_p, /**<
|
||||
*
|
||||
* @return pointer to a newly created record
|
||||
*/
|
||||
lit_literal_t
|
||||
lit_create_literal_from_num (ecma_number_t num) /**< number to initialize a new number literal */
|
||||
lit_literal_t __attr_always_inline___
|
||||
lit_create_literal_from_num (const ecma_number_t num) /**< number to initialize a new number literal */
|
||||
{
|
||||
return lit_storage_create_number_literal (&rcs_lit_storage, num);
|
||||
return lit_create_number_literal (num);
|
||||
} /* lit_create_literal_from_num */
|
||||
|
||||
/**
|
||||
@@ -231,21 +237,21 @@ lit_find_or_create_literal_from_num (ecma_number_t num) /**< number which a lite
|
||||
* @return pointer to existing or null
|
||||
*/
|
||||
lit_literal_t
|
||||
lit_find_literal_by_num (ecma_number_t num) /**< a number to search for */
|
||||
lit_find_literal_by_num (const ecma_number_t num) /**< a number to search for */
|
||||
{
|
||||
lit_literal_t lit;
|
||||
for (lit = rcs_record_get_first (&rcs_lit_storage);
|
||||
for (lit = lit_storage;
|
||||
lit != NULL;
|
||||
lit = rcs_record_get_next (&rcs_lit_storage, lit))
|
||||
lit = lit_cpointer_decompress (lit->next))
|
||||
{
|
||||
rcs_record_type_t type = rcs_record_get_type (lit);
|
||||
const lit_record_type_t type = (lit_record_type_t) lit->type;
|
||||
|
||||
if (!RCS_RECORD_TYPE_IS_NUMBER (type))
|
||||
if (type != LIT_RECORD_TYPE_NUMBER)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
ecma_number_t lit_num = rcs_record_get_number (&rcs_lit_storage, lit);
|
||||
const ecma_number_t lit_num = lit_number_literal_get_number (lit);
|
||||
|
||||
if (lit_num == num)
|
||||
{
|
||||
@@ -266,37 +272,37 @@ static bool
|
||||
lit_literal_equal_charset_rec (lit_literal_t lit, /**< literal to compare */
|
||||
lit_literal_t record) /**< charset record to compare */
|
||||
{
|
||||
switch (rcs_record_get_type (lit))
|
||||
switch (lit->type)
|
||||
{
|
||||
case RCS_RECORD_TYPE_CHARSET:
|
||||
case LIT_RECORD_TYPE_CHARSET:
|
||||
{
|
||||
return rcs_record_is_equal (&rcs_lit_storage, lit, record);
|
||||
return lit_literal_equal_charset (lit,
|
||||
lit_charset_literal_get_charset (record),
|
||||
lit_charset_literal_get_size (record));
|
||||
}
|
||||
case RCS_RECORD_TYPE_MAGIC_STR:
|
||||
case LIT_RECORD_TYPE_MAGIC_STR:
|
||||
{
|
||||
lit_magic_string_id_t magic_string_id = rcs_record_get_magic_str_id (lit);
|
||||
return rcs_record_is_equal_charset (&rcs_lit_storage,
|
||||
record,
|
||||
lit_get_magic_string_utf8 (magic_string_id),
|
||||
lit_get_magic_string_size (magic_string_id));
|
||||
lit_magic_string_id_t magic_string_id = lit_magic_literal_get_magic_str_id (lit);
|
||||
return lit_literal_equal_charset (record,
|
||||
lit_get_magic_string_utf8 (magic_string_id),
|
||||
lit_get_magic_string_size (magic_string_id));
|
||||
}
|
||||
case RCS_RECORD_TYPE_MAGIC_STR_EX:
|
||||
case LIT_RECORD_TYPE_MAGIC_STR_EX:
|
||||
{
|
||||
lit_magic_string_ex_id_t magic_string_id = rcs_record_get_magic_str_ex_id (lit);
|
||||
lit_magic_string_ex_id_t magic_string_id = lit_magic_literal_get_magic_str_ex_id (lit);
|
||||
|
||||
return rcs_record_is_equal_charset (&rcs_lit_storage,
|
||||
record,
|
||||
lit_get_magic_string_ex_utf8 (magic_string_id),
|
||||
lit_get_magic_string_ex_size (magic_string_id));
|
||||
return lit_literal_equal_charset (record,
|
||||
lit_get_magic_string_ex_utf8 (magic_string_id),
|
||||
lit_get_magic_string_ex_size (magic_string_id));
|
||||
}
|
||||
case RCS_RECORD_TYPE_NUMBER:
|
||||
case LIT_RECORD_TYPE_NUMBER:
|
||||
{
|
||||
ecma_number_t num = rcs_record_get_number (&rcs_lit_storage, lit);
|
||||
ecma_number_t num = lit_number_literal_get_number (lit);
|
||||
|
||||
lit_utf8_byte_t buff[ECMA_MAX_CHARS_IN_STRINGIFIED_NUMBER];
|
||||
lit_utf8_size_t copied = ecma_number_to_utf8_string (num, buff, sizeof (buff));
|
||||
|
||||
return rcs_record_is_equal_charset (&rcs_lit_storage, record, buff, copied);
|
||||
return lit_literal_equal_charset (record, buff, copied);
|
||||
}
|
||||
default:
|
||||
{
|
||||
@@ -317,25 +323,29 @@ lit_literal_equal_utf8 (lit_literal_t lit, /**< literal to compare */
|
||||
const lit_utf8_byte_t *str_p, /**< utf-8 string to compare */
|
||||
lit_utf8_size_t str_size) /**< string size in bytes */
|
||||
{
|
||||
switch (rcs_record_get_type (lit))
|
||||
switch (lit->type)
|
||||
{
|
||||
case RCS_RECORD_TYPE_CHARSET:
|
||||
case LIT_RECORD_TYPE_CHARSET:
|
||||
{
|
||||
return rcs_record_is_equal_charset (&rcs_lit_storage, lit, str_p, str_size);
|
||||
if (lit_charset_literal_get_size (lit) != str_size)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return !strncmp ((const char *) lit_charset_literal_get_charset (lit), (const char *) str_p, str_size);
|
||||
}
|
||||
case RCS_RECORD_TYPE_MAGIC_STR:
|
||||
case LIT_RECORD_TYPE_MAGIC_STR:
|
||||
{
|
||||
lit_magic_string_id_t magic_id = rcs_record_get_magic_str_id (lit);
|
||||
lit_magic_string_id_t magic_id = lit_magic_literal_get_magic_str_id (lit);
|
||||
return lit_compare_utf8_string_and_magic_string (str_p, str_size, magic_id);
|
||||
}
|
||||
case RCS_RECORD_TYPE_MAGIC_STR_EX:
|
||||
case LIT_RECORD_TYPE_MAGIC_STR_EX:
|
||||
{
|
||||
lit_magic_string_ex_id_t magic_id = rcs_record_get_magic_str_ex_id (lit);
|
||||
lit_magic_string_ex_id_t magic_id = lit_magic_literal_get_magic_str_ex_id (lit);
|
||||
return lit_compare_utf8_string_and_magic_string_ex (str_p, str_size, magic_id);
|
||||
}
|
||||
case RCS_RECORD_TYPE_NUMBER:
|
||||
case LIT_RECORD_TYPE_NUMBER:
|
||||
{
|
||||
ecma_number_t num = rcs_record_get_number (&rcs_lit_storage, lit);
|
||||
ecma_number_t num = lit_number_literal_get_number (lit);
|
||||
|
||||
lit_utf8_byte_t num_buf[ECMA_MAX_CHARS_IN_STRINGIFIED_NUMBER];
|
||||
lit_utf8_size_t num_size = ecma_number_to_utf8_string (num, num_buf, sizeof (num_buf));
|
||||
@@ -356,7 +366,7 @@ lit_literal_equal_utf8 (lit_literal_t lit, /**< literal to compare */
|
||||
* false otherwise
|
||||
*/
|
||||
bool
|
||||
lit_literal_equal_num (lit_literal_t lit, /**< literal to check */
|
||||
lit_literal_equal_num (lit_literal_t lit, /**< literal to check */
|
||||
ecma_number_t num) /**< number to compare with */
|
||||
{
|
||||
lit_utf8_byte_t buff[ECMA_MAX_CHARS_IN_STRINGIFIED_NUMBER];
|
||||
@@ -365,6 +375,29 @@ lit_literal_equal_num (lit_literal_t lit, /**< literal to check */
|
||||
return lit_literal_equal_utf8 (lit, buff, copied);
|
||||
} /* lit_literal_equal_num */
|
||||
|
||||
|
||||
/**
|
||||
* Check if literal contains the string equal to the buffer
|
||||
*
|
||||
* @return true if equal
|
||||
* false otherwise
|
||||
*/
|
||||
bool
|
||||
lit_literal_equal_charset (lit_literal_t lit, /**< literal to checks */
|
||||
const lit_utf8_byte_t *buff, /**< string buffer */
|
||||
lit_utf8_size_t size) /**< buffer size */
|
||||
{
|
||||
JERRY_ASSERT (lit->type == LIT_RECORD_TYPE_CHARSET);
|
||||
|
||||
if (size != lit_charset_literal_get_size (lit))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return !strncmp ((const char *) buff, (const char *) lit_charset_literal_get_charset (lit), size);
|
||||
} /* lit_literal_equal_charset */
|
||||
|
||||
|
||||
/**
|
||||
* Check if two literals are equal
|
||||
*
|
||||
@@ -375,38 +408,42 @@ bool
|
||||
lit_literal_equal (lit_literal_t lit1, /**< first literal */
|
||||
lit_literal_t lit2) /**< second literal */
|
||||
{
|
||||
switch (rcs_record_get_type (lit2))
|
||||
switch (lit2->type)
|
||||
{
|
||||
case RCS_RECORD_TYPE_CHARSET:
|
||||
case LIT_RECORD_TYPE_CHARSET:
|
||||
{
|
||||
return lit_literal_equal_charset_rec (lit1, lit2);
|
||||
}
|
||||
case RCS_RECORD_TYPE_MAGIC_STR:
|
||||
case LIT_RECORD_TYPE_MAGIC_STR:
|
||||
{
|
||||
lit_magic_string_id_t magic_str_id = rcs_record_get_magic_str_id (lit2);
|
||||
lit_magic_string_id_t magic_str_id = lit_magic_literal_get_magic_str_id (lit2);
|
||||
|
||||
return lit_literal_equal_utf8 (lit1,
|
||||
lit_get_magic_string_utf8 (magic_str_id),
|
||||
lit_get_magic_string_size (magic_str_id));
|
||||
}
|
||||
case RCS_RECORD_TYPE_MAGIC_STR_EX:
|
||||
case LIT_RECORD_TYPE_MAGIC_STR_EX:
|
||||
{
|
||||
lit_magic_string_ex_id_t magic_str_ex_id = rcs_record_get_magic_str_ex_id (lit2);
|
||||
lit_magic_string_ex_id_t magic_str_ex_id = lit_magic_literal_get_magic_str_ex_id (lit2);
|
||||
|
||||
return lit_literal_equal_utf8 (lit1,
|
||||
lit_get_magic_string_ex_utf8 (magic_str_ex_id),
|
||||
lit_get_magic_string_ex_size (magic_str_ex_id));
|
||||
}
|
||||
case RCS_RECORD_TYPE_NUMBER:
|
||||
case LIT_RECORD_TYPE_NUMBER:
|
||||
{
|
||||
ecma_number_t num = rcs_record_get_number (&rcs_lit_storage, lit2);
|
||||
ecma_number_t num = lit_number_literal_get_number (lit2);
|
||||
return lit_literal_equal_num (lit1, num);
|
||||
}
|
||||
default:
|
||||
{
|
||||
JERRY_UNREACHABLE ();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
JERRY_UNREACHABLE ();
|
||||
return 0;
|
||||
} /* lit_literal_equal */
|
||||
|
||||
/**
|
||||
@@ -421,9 +458,9 @@ lit_literal_equal_type_utf8 (lit_literal_t lit, /**< literal to compare */
|
||||
const lit_utf8_byte_t *str_p, /**< utf-8 string */
|
||||
lit_utf8_size_t str_size) /**< string size */
|
||||
{
|
||||
rcs_record_type_t type = rcs_record_get_type (lit);
|
||||
const lit_record_type_t type = (const lit_record_type_t) lit->type;
|
||||
|
||||
if (RCS_RECORD_TYPE_IS_NUMBER (type) || RCS_RECORD_TYPE_IS_FREE (type))
|
||||
if (type == LIT_RECORD_TYPE_NUMBER || type == LIT_RECORD_TYPE_FREE)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -456,7 +493,7 @@ bool
|
||||
lit_literal_equal_type_num (lit_literal_t lit, /**< literal to check */
|
||||
ecma_number_t num) /**< number to compare with */
|
||||
{
|
||||
if (!RCS_RECORD_IS_NUMBER (lit))
|
||||
if (lit->type != LIT_RECORD_TYPE_NUMBER)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -475,7 +512,7 @@ bool
|
||||
lit_literal_equal_type (lit_literal_t lit1, /**< first literal */
|
||||
lit_literal_t lit2) /**< second literal */
|
||||
{
|
||||
if (rcs_record_get_type (lit1) != rcs_record_get_type (lit2))
|
||||
if (lit1->type != lit2->type)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -496,29 +533,32 @@ lit_literal_to_utf8_string (lit_literal_t lit, /**< literal to be processed */
|
||||
size_t size) /**< size of the buffer */
|
||||
{
|
||||
JERRY_ASSERT (buff_p != NULL && size > 0);
|
||||
rcs_record_type_t type = rcs_record_get_type (lit);
|
||||
|
||||
if (RCS_RECORD_TYPE_IS_CHARSET (type))
|
||||
switch (lit->type)
|
||||
{
|
||||
rcs_record_get_charset (&rcs_lit_storage, lit, buff_p, size);
|
||||
return buff_p;
|
||||
case LIT_RECORD_TYPE_CHARSET:
|
||||
{
|
||||
const size_t str_size = lit_charset_literal_get_size (lit);
|
||||
memcpy (buff_p, lit_charset_literal_get_charset (lit), (size > str_size) ? str_size : size);
|
||||
return buff_p;
|
||||
}
|
||||
case LIT_RECORD_TYPE_MAGIC_STR:
|
||||
{
|
||||
return lit_get_magic_string_utf8 (lit_magic_literal_get_magic_str_id (lit));
|
||||
}
|
||||
case LIT_RECORD_TYPE_MAGIC_STR_EX:
|
||||
{
|
||||
return lit_get_magic_string_ex_utf8 (lit_magic_literal_get_magic_str_ex_id (lit));
|
||||
}
|
||||
case LIT_RECORD_TYPE_NUMBER:
|
||||
{
|
||||
ecma_number_t number = lit_number_literal_get_number (lit);
|
||||
ecma_number_to_utf8_string (number, buff_p, (ssize_t) size);
|
||||
return buff_p;
|
||||
}
|
||||
}
|
||||
else if (RCS_RECORD_TYPE_IS_MAGIC_STR (type))
|
||||
{
|
||||
return lit_get_magic_string_utf8 (rcs_record_get_magic_str_id (lit));
|
||||
}
|
||||
else if (RCS_RECORD_TYPE_IS_MAGIC_STR_EX (type))
|
||||
{
|
||||
return lit_get_magic_string_ex_utf8 (rcs_record_get_magic_str_ex_id (lit));
|
||||
}
|
||||
else
|
||||
{
|
||||
JERRY_ASSERT (RCS_RECORD_TYPE_IS_NUMBER (type));
|
||||
|
||||
ecma_number_t number = rcs_record_get_number (&rcs_lit_storage, lit);
|
||||
ecma_number_to_utf8_string (number, buff_p, (ssize_t) size);
|
||||
return buff_p;
|
||||
}
|
||||
JERRY_UNREACHABLE ();
|
||||
} /* lit_literal_to_utf8_string */
|
||||
|
||||
/**
|
||||
@@ -548,9 +588,9 @@ lit_literal_exists (lit_literal_t lit) /**< literal to check for existence */
|
||||
{
|
||||
lit_literal_t current_lit;
|
||||
|
||||
for (current_lit = rcs_record_get_first (&rcs_lit_storage);
|
||||
for (current_lit = lit_storage;
|
||||
current_lit != NULL;
|
||||
current_lit = rcs_record_get_next (&rcs_lit_storage, current_lit))
|
||||
current_lit = lit_cpointer_decompress (current_lit->next))
|
||||
{
|
||||
if (current_lit == lit)
|
||||
{
|
||||
@@ -567,10 +607,9 @@ lit_literal_exists (lit_literal_t lit) /**< literal to check for existence */
|
||||
* @return literal
|
||||
*/
|
||||
lit_literal_t
|
||||
lit_get_literal_by_cp (rcs_cpointer_t lit_cp) /**< compressed pointer to literal */
|
||||
lit_get_literal_by_cp (lit_cpointer_t lit_cp) /**< compressed pointer to literal */
|
||||
{
|
||||
JERRY_ASSERT (lit_cp.u.packed_value != MEM_CP_NULL);
|
||||
lit_literal_t lit = rcs_cpointer_decompress (lit_cp);
|
||||
lit_literal_t lit = lit_cpointer_decompress (lit_cp);
|
||||
JERRY_ASSERT (lit_literal_exists (lit));
|
||||
|
||||
return lit;
|
||||
@@ -579,25 +618,41 @@ lit_get_literal_by_cp (rcs_cpointer_t lit_cp) /**< compressed pointer to literal
|
||||
lit_string_hash_t
|
||||
lit_charset_literal_get_hash (lit_literal_t lit) /**< literal */
|
||||
{
|
||||
return rcs_record_get_hash (lit);
|
||||
JERRY_ASSERT (lit->type == LIT_RECORD_TYPE_CHARSET);
|
||||
|
||||
const lit_charset_record_t *const rec_p = (const lit_charset_record_t *) lit;
|
||||
|
||||
return (lit_string_hash_t) rec_p->hash;
|
||||
} /* lit_charset_literal_get_hash */
|
||||
|
||||
lit_magic_string_id_t
|
||||
lit_magic_literal_get_magic_str_id (lit_literal_t lit) /**< literal */
|
||||
{
|
||||
return rcs_record_get_magic_str_id (lit);
|
||||
JERRY_ASSERT (lit->type == LIT_RECORD_TYPE_MAGIC_STR);
|
||||
|
||||
const lit_magic_record_t *const rec_p = (const lit_magic_record_t *) lit;
|
||||
|
||||
return (lit_magic_string_id_t) rec_p->magic_id;
|
||||
} /* lit_magic_literal_get_magic_str_id */
|
||||
|
||||
lit_magic_string_ex_id_t
|
||||
lit_magic_literal_ex_get_magic_str_id (lit_literal_t lit) /**< literal */
|
||||
lit_magic_literal_get_magic_str_ex_id (lit_literal_t lit) /**< literal */
|
||||
{
|
||||
return rcs_record_get_magic_str_ex_id (lit);
|
||||
} /* lit_magic_literal_ex_get_magic_str_id */
|
||||
JERRY_ASSERT (lit->type == LIT_RECORD_TYPE_MAGIC_STR_EX);
|
||||
|
||||
lit_utf8_size_t
|
||||
const lit_magic_record_t *const rec_p = (const lit_magic_record_t *) lit;
|
||||
|
||||
return (lit_magic_string_ex_id_t) rec_p->magic_id;
|
||||
} /* lit_magic_literal_get_magic_str_ex_id */
|
||||
|
||||
lit_utf8_size_t __attr_always_inline___ __attr_pure___
|
||||
lit_charset_literal_get_size (lit_literal_t lit) /**< literal */
|
||||
{
|
||||
return rcs_record_get_length (lit);
|
||||
JERRY_ASSERT (lit->type == LIT_RECORD_TYPE_CHARSET);
|
||||
|
||||
const lit_charset_record_t *const rec_p = (const lit_charset_record_t *) lit;
|
||||
|
||||
return (lit_utf8_size_t) rec_p->size;
|
||||
} /* lit_charset_literal_get_size */
|
||||
|
||||
/**
|
||||
@@ -605,41 +660,32 @@ lit_charset_literal_get_size (lit_literal_t lit) /**< literal */
|
||||
*
|
||||
* @return code units count
|
||||
*/
|
||||
ecma_length_t
|
||||
ecma_length_t __attr_always_inline___ __attr_pure___
|
||||
lit_charset_literal_get_length (lit_literal_t lit) /**< literal */
|
||||
{
|
||||
TODO ("Add special case for literals which doesn't contain long characters");
|
||||
JERRY_ASSERT (lit->type == LIT_RECORD_TYPE_CHARSET);
|
||||
|
||||
rcs_iterator_t it_ctx = rcs_iterator_create (&rcs_lit_storage, lit);
|
||||
rcs_iterator_skip (&it_ctx, RCS_CHARSET_HEADER_SIZE);
|
||||
const lit_charset_record_t *const rec_p = (const lit_charset_record_t *) lit;
|
||||
|
||||
lit_utf8_size_t lit_utf8_str_size = rcs_record_get_length (lit);
|
||||
ecma_length_t length = 0;
|
||||
lit_utf8_size_t i = 0;
|
||||
|
||||
while (i < lit_utf8_str_size)
|
||||
{
|
||||
lit_utf8_byte_t byte;
|
||||
lit_utf8_size_t bytes_to_skip;
|
||||
|
||||
rcs_iterator_read (&it_ctx, &byte, sizeof (lit_utf8_byte_t));
|
||||
bytes_to_skip = lit_get_unicode_char_size_by_utf8_first_byte (byte);
|
||||
rcs_iterator_skip (&it_ctx, bytes_to_skip);
|
||||
|
||||
i += bytes_to_skip;
|
||||
length++;
|
||||
}
|
||||
|
||||
#ifndef JERRY_NDEBUG
|
||||
rcs_iterator_skip (&it_ctx, rcs_record_get_alignment_bytes_count (lit));
|
||||
JERRY_ASSERT (rcs_iterator_finished (&it_ctx));
|
||||
#endif
|
||||
|
||||
return length;
|
||||
return (ecma_length_t) rec_p->length;
|
||||
} /* lit_charset_literal_get_length */
|
||||
|
||||
ecma_number_t
|
||||
ecma_number_t __attr_always_inline___ __attr_pure___
|
||||
lit_number_literal_get_number (lit_literal_t lit) /**< literal */
|
||||
{
|
||||
return rcs_record_get_number (&rcs_lit_storage, lit);
|
||||
JERRY_ASSERT (lit->type == LIT_RECORD_TYPE_NUMBER);
|
||||
|
||||
const lit_number_record_t *const rec_p = (const lit_number_record_t *) lit;
|
||||
|
||||
return rec_p->number;
|
||||
} /* lit_number_literal_get_number */
|
||||
|
||||
lit_utf8_byte_t * __attr_always_inline___ __attr_pure___
|
||||
lit_charset_literal_get_charset (lit_literal_t lit) /**< literal */
|
||||
{
|
||||
JERRY_ASSERT (lit->type == LIT_RECORD_TYPE_CHARSET);
|
||||
|
||||
const lit_charset_record_t *const rec_p = (const lit_charset_record_t *) lit;
|
||||
|
||||
return (lit_utf8_byte_t *) (rec_p + 1);
|
||||
} /* lit_charset_literal_get_charset */
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
/* Copyright 2015 Samsung Electronics Co., Ltd.
|
||||
* Copyright 2016 University of Szeged.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -17,10 +18,18 @@
|
||||
#define LIT_LITERAL_H
|
||||
|
||||
#include "ecma-globals.h"
|
||||
#include "lit-globals.h"
|
||||
#include "lit-literal-storage.h"
|
||||
#include "lit-cpointer.h"
|
||||
|
||||
extern void lit_init (void);
|
||||
extern void lit_finalize (void);
|
||||
extern void lit_dump_literals (void);
|
||||
/**
|
||||
* Invalid literal
|
||||
*/
|
||||
#define NOT_A_LITERAL (lit_cpointer_null_cp ())
|
||||
|
||||
extern void lit_init ();
|
||||
extern void lit_finalize ();
|
||||
extern void lit_dump_literals ();
|
||||
|
||||
extern lit_literal_t lit_create_literal_from_utf8_string (const lit_utf8_byte_t *, lit_utf8_size_t);
|
||||
extern lit_literal_t lit_find_literal_by_utf8_string (const lit_utf8_byte_t *, lit_utf8_size_t);
|
||||
@@ -38,6 +47,7 @@ extern bool lit_literal_equal_type_utf8 (lit_literal_t, const lit_utf8_byte_t *,
|
||||
extern bool lit_literal_equal_type_cstr (lit_literal_t, const char *);
|
||||
extern bool lit_literal_equal_type_num (lit_literal_t, ecma_number_t);
|
||||
extern bool lit_literal_equal_type (lit_literal_t, lit_literal_t);
|
||||
extern bool lit_literal_equal_charset (lit_literal_t, const lit_utf8_byte_t *, lit_utf8_size_t);
|
||||
|
||||
extern const lit_utf8_byte_t *lit_literal_to_utf8_string (lit_literal_t, lit_utf8_byte_t *, size_t);
|
||||
extern const char *lit_literal_to_str_internal_buf (lit_literal_t);
|
||||
@@ -48,8 +58,10 @@ extern ecma_number_t lit_number_literal_get_number (lit_literal_t);
|
||||
extern lit_string_hash_t lit_charset_literal_get_hash (lit_literal_t);
|
||||
extern lit_utf8_size_t lit_charset_literal_get_size (lit_literal_t);
|
||||
extern ecma_length_t lit_charset_literal_get_length (lit_literal_t);
|
||||
extern lit_utf8_byte_t *lit_charset_literal_get_charset (lit_literal_t);
|
||||
extern lit_literal_t lit_literal_get_next (lit_literal_t);
|
||||
|
||||
extern lit_magic_string_id_t lit_magic_literal_get_magic_str_id (lit_literal_t);
|
||||
extern lit_magic_string_ex_id_t lit_magic_literal_ex_get_magic_str_id (lit_literal_t);
|
||||
extern lit_magic_string_ex_id_t lit_magic_literal_get_magic_str_ex_id (lit_literal_t);
|
||||
|
||||
#endif /* LIT_LITERAL_H */
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* Copyright 2015 Samsung Electronics Co., Ltd.
|
||||
* Copyright 2015 University of Szeged
|
||||
/* Copyright 2015 Samsung Electronics Co., Ltd.
|
||||
* Copyright 2015-2016 University of Szeged
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -18,9 +18,6 @@
|
||||
|
||||
#include "lit-literal.h"
|
||||
#include "lit-literal-storage.h"
|
||||
#include "rcs-allocator.h"
|
||||
#include "rcs-iterator.h"
|
||||
#include "rcs-records.h"
|
||||
|
||||
#ifdef JERRY_ENABLE_SNAPSHOT_SAVE
|
||||
|
||||
@@ -36,91 +33,87 @@ lit_snapshot_dump (lit_literal_t lit, /**< literal to dump */
|
||||
size_t buffer_size, /**< buffer size */
|
||||
size_t *in_out_buffer_offset_p) /**< in-out: buffer write offset */
|
||||
{
|
||||
rcs_record_type_t record_type = rcs_record_get_type (lit);
|
||||
|
||||
if (RCS_RECORD_TYPE_IS_NUMBER (record_type))
|
||||
const lit_record_type_t record_type = (lit_record_type_t) lit->type;
|
||||
switch (record_type)
|
||||
{
|
||||
double num_value = rcs_record_get_number (&rcs_lit_storage, lit);
|
||||
size_t size = sizeof (num_value);
|
||||
|
||||
if (!jrt_write_to_buffer_by_offset (buffer_p,
|
||||
buffer_size,
|
||||
in_out_buffer_offset_p,
|
||||
&num_value,
|
||||
size))
|
||||
case LIT_RECORD_TYPE_CHARSET:
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (uint32_t) size;
|
||||
}
|
||||
|
||||
if (RCS_RECORD_TYPE_IS_CHARSET (record_type))
|
||||
{
|
||||
lit_utf8_size_t length = rcs_record_get_length (lit);
|
||||
if (!jrt_write_to_buffer_by_offset (buffer_p,
|
||||
buffer_size,
|
||||
in_out_buffer_offset_p,
|
||||
&length,
|
||||
sizeof (length)))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
rcs_iterator_t it_ctx = rcs_iterator_create (&rcs_lit_storage, lit);
|
||||
rcs_iterator_skip (&it_ctx, RCS_CHARSET_HEADER_SIZE);
|
||||
|
||||
lit_utf8_size_t i;
|
||||
for (i = 0; i < length; ++i)
|
||||
{
|
||||
lit_utf8_byte_t next_byte;
|
||||
rcs_iterator_read (&it_ctx, &next_byte, sizeof (lit_utf8_byte_t));
|
||||
const lit_charset_record_t *const rec_p = (const lit_charset_record_t *) lit;
|
||||
|
||||
lit_utf8_size_t size = lit_charset_literal_get_size (lit);
|
||||
if (!jrt_write_to_buffer_by_offset (buffer_p,
|
||||
buffer_size,
|
||||
in_out_buffer_offset_p,
|
||||
&next_byte,
|
||||
sizeof (next_byte)))
|
||||
&size,
|
||||
sizeof (size)))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
rcs_iterator_skip (&it_ctx, sizeof (lit_utf8_byte_t));
|
||||
|
||||
if (!jrt_write_to_buffer_by_offset (buffer_p,
|
||||
buffer_size,
|
||||
in_out_buffer_offset_p,
|
||||
(void *) (rec_p + 1),
|
||||
size))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (uint32_t) (sizeof (uint32_t) + size * sizeof (uint8_t));
|
||||
|
||||
}
|
||||
|
||||
return (uint32_t) (sizeof (uint32_t) + length * sizeof (uint8_t));
|
||||
}
|
||||
|
||||
if (RCS_RECORD_TYPE_IS_MAGIC_STR (record_type))
|
||||
{
|
||||
lit_magic_string_id_t id = rcs_record_get_magic_str_id (lit);
|
||||
|
||||
if (!jrt_write_to_buffer_by_offset (buffer_p,
|
||||
buffer_size,
|
||||
in_out_buffer_offset_p,
|
||||
&id,
|
||||
sizeof (id)))
|
||||
case LIT_RECORD_TYPE_NUMBER:
|
||||
{
|
||||
return 0;
|
||||
double num_value = lit_number_literal_get_number (lit);
|
||||
const size_t size = sizeof (num_value);
|
||||
|
||||
if (!jrt_write_to_buffer_by_offset (buffer_p,
|
||||
buffer_size,
|
||||
in_out_buffer_offset_p,
|
||||
&num_value,
|
||||
size))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (uint32_t) size;
|
||||
}
|
||||
|
||||
return (uint32_t) sizeof (lit_magic_string_id_t);
|
||||
}
|
||||
|
||||
if (RCS_RECORD_TYPE_IS_MAGIC_STR_EX (record_type))
|
||||
{
|
||||
lit_magic_string_ex_id_t id = rcs_record_get_magic_str_ex_id (lit);
|
||||
|
||||
if (!jrt_write_to_buffer_by_offset (buffer_p,
|
||||
buffer_size,
|
||||
in_out_buffer_offset_p,
|
||||
&id,
|
||||
sizeof (id)))
|
||||
case LIT_RECORD_TYPE_MAGIC_STR:
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
lit_magic_string_id_t id = lit_magic_literal_get_magic_str_id (lit);
|
||||
|
||||
return (uint32_t) sizeof (lit_magic_string_ex_id_t);
|
||||
if (!jrt_write_to_buffer_by_offset (buffer_p,
|
||||
buffer_size,
|
||||
in_out_buffer_offset_p,
|
||||
&id,
|
||||
sizeof (id)))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (uint32_t) sizeof (lit_magic_string_id_t);
|
||||
}
|
||||
case LIT_RECORD_TYPE_MAGIC_STR_EX:
|
||||
{
|
||||
lit_magic_string_ex_id_t id = lit_magic_literal_get_magic_str_ex_id (lit);
|
||||
|
||||
if (!jrt_write_to_buffer_by_offset (buffer_p,
|
||||
buffer_size,
|
||||
in_out_buffer_offset_p,
|
||||
&id,
|
||||
sizeof (id)))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (uint32_t) sizeof (lit_magic_string_ex_id_t);
|
||||
}
|
||||
default:
|
||||
{
|
||||
JERRY_UNREACHABLE ();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
JERRY_UNREACHABLE ();
|
||||
@@ -143,7 +136,7 @@ lit_dump_literals_for_snapshot (uint8_t *buffer_p, /**< output snapshot buffer *
|
||||
uint32_t *out_map_num_p, /**< out: number of literals */
|
||||
uint32_t *out_lit_table_size_p) /**< out: number of bytes, dumped to snapshot buffer */
|
||||
{
|
||||
uint32_t literals_num = lit_storage_count_literals (&rcs_lit_storage);
|
||||
uint32_t literals_num = lit_count_literals ();
|
||||
uint32_t lit_table_size = 0;
|
||||
|
||||
*out_map_p = NULL;
|
||||
@@ -167,18 +160,18 @@ lit_dump_literals_for_snapshot (uint8_t *buffer_p, /**< output snapshot buffer *
|
||||
|
||||
size_t id_map_size = sizeof (lit_mem_to_snapshot_id_map_entry_t) * literals_num;
|
||||
lit_mem_to_snapshot_id_map_entry_t *id_map_p;
|
||||
id_map_p = (lit_mem_to_snapshot_id_map_entry_t *) mem_heap_alloc_block (id_map_size, MEM_HEAP_ALLOC_SHORT_TERM);
|
||||
id_map_p = (lit_mem_to_snapshot_id_map_entry_t *) mem_heap_alloc_block_store_size (id_map_size);
|
||||
|
||||
uint32_t literal_index = 0;
|
||||
lit_literal_t lit;
|
||||
|
||||
for (lit = rcs_record_get_first (&rcs_lit_storage);
|
||||
for (lit = lit_storage;
|
||||
lit != NULL;
|
||||
lit = rcs_record_get_next (&rcs_lit_storage, lit))
|
||||
lit = lit_cpointer_decompress (lit->next))
|
||||
{
|
||||
rcs_record_type_t record_type = rcs_record_get_type (lit);
|
||||
lit_record_type_t record_type = (lit_record_type_t) lit->type;
|
||||
|
||||
if (RCS_RECORD_TYPE_IS_FREE (record_type))
|
||||
if (record_type == LIT_RECORD_TYPE_FREE)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -202,7 +195,7 @@ lit_dump_literals_for_snapshot (uint8_t *buffer_p, /**< output snapshot buffer *
|
||||
break;
|
||||
}
|
||||
|
||||
rcs_cpointer_t lit_cp = rcs_cpointer_compress (lit);
|
||||
lit_cpointer_t lit_cp = lit_cpointer_compress (lit);
|
||||
id_map_p[literal_index].literal_id = lit_cp;
|
||||
id_map_p[literal_index].literal_offset = lit_table_size;
|
||||
|
||||
@@ -214,7 +207,7 @@ lit_dump_literals_for_snapshot (uint8_t *buffer_p, /**< output snapshot buffer *
|
||||
|
||||
if (!is_ok)
|
||||
{
|
||||
mem_heap_free_block (id_map_p);
|
||||
mem_heap_free_block_size_stored (id_map_p);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -291,7 +284,7 @@ lit_load_literals_from_snapshot (const uint8_t *lit_table_p, /**< buffer with li
|
||||
|
||||
size_t id_map_size = sizeof (lit_mem_to_snapshot_id_map_entry_t) * literals_num;
|
||||
lit_mem_to_snapshot_id_map_entry_t *id_map_p;
|
||||
id_map_p = (lit_mem_to_snapshot_id_map_entry_t *) mem_heap_alloc_block (id_map_size, MEM_HEAP_ALLOC_SHORT_TERM);
|
||||
id_map_p = (lit_mem_to_snapshot_id_map_entry_t *) mem_heap_alloc_block_store_size (id_map_size);
|
||||
|
||||
bool is_ok = true;
|
||||
uint32_t lit_index;
|
||||
@@ -301,7 +294,7 @@ lit_load_literals_from_snapshot (const uint8_t *lit_table_p, /**< buffer with li
|
||||
uint32_t offset = (uint32_t) lit_table_read;
|
||||
JERRY_ASSERT (offset == lit_table_read);
|
||||
|
||||
rcs_record_type_t type;
|
||||
lit_record_type_t type;
|
||||
if (!jrt_read_from_buffer_by_offset (lit_table_p,
|
||||
lit_table_size,
|
||||
&lit_table_read,
|
||||
@@ -314,7 +307,7 @@ lit_load_literals_from_snapshot (const uint8_t *lit_table_p, /**< buffer with li
|
||||
|
||||
lit_literal_t lit;
|
||||
|
||||
if (RCS_RECORD_TYPE_IS_CHARSET (type))
|
||||
if (type == LIT_RECORD_TYPE_CHARSET)
|
||||
{
|
||||
lit_utf8_size_t length;
|
||||
if (!jrt_read_from_buffer_by_offset (lit_table_p,
|
||||
@@ -331,7 +324,7 @@ lit_load_literals_from_snapshot (const uint8_t *lit_table_p, /**< buffer with li
|
||||
lit = (lit_literal_t) lit_find_or_create_literal_from_utf8_string (lit_table_p + lit_table_read, length);
|
||||
lit_table_read += length;
|
||||
}
|
||||
else if (RCS_RECORD_TYPE_IS_MAGIC_STR (type))
|
||||
else if (type == LIT_RECORD_TYPE_MAGIC_STR)
|
||||
{
|
||||
lit_magic_string_id_t id;
|
||||
if (!jrt_read_from_buffer_by_offset (lit_table_p,
|
||||
@@ -353,7 +346,7 @@ lit_load_literals_from_snapshot (const uint8_t *lit_table_p, /**< buffer with li
|
||||
*/
|
||||
lit = (lit_literal_t) lit_find_or_create_literal_from_utf8_string (magic_str_p, magic_str_sz);
|
||||
}
|
||||
else if (RCS_RECORD_TYPE_IS_MAGIC_STR_EX (type))
|
||||
else if (type == LIT_RECORD_TYPE_MAGIC_STR_EX)
|
||||
{
|
||||
lit_magic_string_ex_id_t id;
|
||||
if (!jrt_read_from_buffer_by_offset (lit_table_p,
|
||||
@@ -375,7 +368,7 @@ lit_load_literals_from_snapshot (const uint8_t *lit_table_p, /**< buffer with li
|
||||
*/
|
||||
lit = (lit_literal_t) lit_find_or_create_literal_from_utf8_string (magic_str_ex_p, magic_str_ex_sz);
|
||||
}
|
||||
else if (RCS_RECORD_TYPE_IS_NUMBER (type))
|
||||
else if (type == LIT_RECORD_TYPE_NUMBER)
|
||||
{
|
||||
double num;
|
||||
if (!jrt_read_from_buffer_by_offset (lit_table_p,
|
||||
@@ -397,7 +390,7 @@ lit_load_literals_from_snapshot (const uint8_t *lit_table_p, /**< buffer with li
|
||||
}
|
||||
|
||||
id_map_p[lit_index].literal_offset = offset;
|
||||
id_map_p[lit_index].literal_id = rcs_cpointer_compress (lit);
|
||||
id_map_p[lit_index].literal_id = lit_cpointer_compress (lit);
|
||||
}
|
||||
|
||||
if (is_ok)
|
||||
@@ -408,7 +401,7 @@ lit_load_literals_from_snapshot (const uint8_t *lit_table_p, /**< buffer with li
|
||||
return true;
|
||||
}
|
||||
|
||||
mem_heap_free_block (id_map_p);
|
||||
mem_heap_free_block_size_stored (id_map_p);
|
||||
return false;
|
||||
} /* lit_load_literals_from_snapshot */
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* Copyright 2015 Samsung Electronics Co., Ltd.
|
||||
* Copyright 2015 University of Szeged
|
||||
* Copyright 2015-2016 University of Szeged
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -17,11 +17,12 @@
|
||||
#ifndef RCS_SNAPSHOT_H
|
||||
#define RCS_SNAPSHOT_H
|
||||
|
||||
#include "rcs-cpointer.h"
|
||||
#include "lit-cpointer.h"
|
||||
#include "ecma-globals.h"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
rcs_cpointer_t literal_id;
|
||||
lit_cpointer_t literal_id;
|
||||
uint32_t literal_offset;
|
||||
} lit_mem_to_snapshot_id_map_entry_t;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user