Add deserializer
This commit is contained in:
+1
-1
@@ -163,7 +163,7 @@ SOURCES_JERRY = \
|
||||
$(wildcard ./src/libecmaoperations/*.c) \
|
||||
$(wildcard ./src/liballocator/*.c) \
|
||||
$(wildcard ./src/libcoreint/*.c) ) \
|
||||
$(wildcard src/libruntime/target/$(TARGET_SYSTEM)/*)
|
||||
$(wildcard src/libruntime/target/$(TARGET_SYSTEM)/*.c)
|
||||
|
||||
INCLUDES_JERRY = \
|
||||
-I src \
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
/* Copyright 2014 Samsung Electronics Co., Ltd.
|
||||
*
|
||||
* 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 DESERIALIZER_H
|
||||
#define DESERIALIZER_H
|
||||
|
||||
#include "globals.h"
|
||||
|
||||
const char *deserializer_get_string_by_id (uint8_t);
|
||||
int deserializer_get_num_by_id (uint8_t);
|
||||
const void *deserializer_get_bytecode (void);
|
||||
|
||||
#endif //DESERIALIZER_H
|
||||
@@ -0,0 +1,37 @@
|
||||
/* Copyright 2014 Samsung Electronics Co., Ltd.
|
||||
*
|
||||
* 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 BYTECODE_LINUX_H
|
||||
#define BYTECODE_LINUX_H
|
||||
|
||||
#include "opcodes.h"
|
||||
|
||||
#define MAX_OPCODES 255
|
||||
|
||||
/* bytecode_data contains identifiers, string and num literals.
|
||||
Memory map if the following.
|
||||
|
||||
bytecode_data {
|
||||
U8 strs_count;
|
||||
U8 string_offsets[str_count];
|
||||
U8* strings[str_count];
|
||||
|
||||
U8 nums_count;
|
||||
U32 nums[nums_count];
|
||||
} */
|
||||
uint8_t *bytecode_data;
|
||||
OPCODE bytecode_opcodes[MAX_OPCODES];
|
||||
|
||||
#endif // BYTECODE_LINUX_H
|
||||
@@ -0,0 +1,61 @@
|
||||
/* Copyright 2014 Samsung Electronics Co., Ltd.
|
||||
*
|
||||
* 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 "deserializer.h"
|
||||
#include "bytecode-linux.h"
|
||||
|
||||
const char *
|
||||
deserializer_get_string_by_id (uint8_t id)
|
||||
{
|
||||
uint8_t size = *bytecode_data, *data = bytecode_data, offset;
|
||||
|
||||
if (id >= size)
|
||||
return NULL;
|
||||
|
||||
data += id + 1;
|
||||
|
||||
offset = *data;
|
||||
|
||||
return (char*) (bytecode_data + offset);
|
||||
}
|
||||
|
||||
int
|
||||
deserializer_get_num_by_id (uint8_t id)
|
||||
{
|
||||
int *num_data;
|
||||
uint8_t str_size, str_offset, *data, num_size;
|
||||
|
||||
str_size = *bytecode_data;
|
||||
data = bytecode_data + str_size;
|
||||
str_offset = *data;
|
||||
data = bytecode_data + str_offset;
|
||||
|
||||
while (*data)
|
||||
data++;
|
||||
|
||||
num_data = (int *) ++data;
|
||||
num_size = *data;
|
||||
|
||||
if (id >= num_size)
|
||||
return 0;
|
||||
|
||||
return num_data[id];
|
||||
}
|
||||
|
||||
const void *
|
||||
deserializer_get_bytecode (void)
|
||||
{
|
||||
return bytecode_opcodes;
|
||||
}
|
||||
@@ -15,7 +15,7 @@
|
||||
|
||||
#include "serializer.h"
|
||||
#include "jerry-libc.h"
|
||||
#include "opcodes.h"
|
||||
#include "bytecode-linux.h"
|
||||
|
||||
_FILE *dump;
|
||||
|
||||
@@ -44,24 +44,39 @@ uint8_t
|
||||
serializer_dump_strings (const char *strings[], uint8_t size)
|
||||
{
|
||||
uint8_t i;
|
||||
uint8_t offset = size;
|
||||
uint8_t offset = (uint8_t) (size + 1), res;
|
||||
|
||||
__printf ("STRINGS %d:\n", size);
|
||||
for (i = 0; i < size; i++)
|
||||
{
|
||||
__printf ("%3d %3d %20s\n", i, offset, strings[i]);
|
||||
offset = (uint8_t ) (offset + __strlen (strings[i]) + 1);
|
||||
offset = (uint8_t) (offset + __strlen (strings[i]) + 1);
|
||||
}
|
||||
|
||||
return offset;
|
||||
bytecode_data = mem_heap_alloc_block (offset, MEM_HEAP_ALLOC_SHORT_TERM);
|
||||
res = offset;
|
||||
|
||||
bytecode_data[0] = size;
|
||||
offset = (uint8_t) (size + 1);
|
||||
for (i = 0; i < size; i++)
|
||||
{
|
||||
bytecode_data[i + 1] = offset;
|
||||
offset = (uint8_t) (offset + __strlen (strings[i]) + 1);
|
||||
}
|
||||
|
||||
for (i = 0; i < size; i++)
|
||||
__strncpy ((void *) (bytecode_data + bytecode_data[i + 1]), strings[i], __strlen (strings[i]) + 1);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
void
|
||||
serializer_dump_nums (const int nums[], uint8_t size, uint8_t offset, uint8_t strings_num)
|
||||
{
|
||||
uint8_t i;
|
||||
uint8_t i, *data;
|
||||
JERRY_STATIC_ASSERT (sizeof (int) == 4);
|
||||
|
||||
offset = (uint8_t) (offset + size);
|
||||
offset = (uint8_t) (offset + size + 1);
|
||||
__printf ("NUMS %d:\n", size);
|
||||
for (i = 0; i < size; i++)
|
||||
{
|
||||
@@ -70,6 +85,18 @@ serializer_dump_nums (const int nums[], uint8_t size, uint8_t offset, uint8_t st
|
||||
}
|
||||
|
||||
__printf ("\n");
|
||||
|
||||
data = mem_heap_alloc_block ((size_t) (offset + size * 4), MEM_HEAP_ALLOC_LONG_TERM);
|
||||
mem_heap_free_block (bytecode_data);
|
||||
bytecode_data = data;
|
||||
data += offset;
|
||||
data[0] = size;
|
||||
data++;
|
||||
for (i = 0; i < size; i++)
|
||||
{
|
||||
__memcpy (data, nums + i, 4);
|
||||
data += 4;
|
||||
}
|
||||
}
|
||||
|
||||
static int opcode_counter = 0;
|
||||
@@ -80,6 +107,7 @@ serializer_dump_opcode (const void *opcode)
|
||||
uint8_t i;
|
||||
int opcode_num = (int)((char*)opcode)[0];
|
||||
|
||||
bytecode_opcodes[opcode_counter] = *((OPCODE*)opcode);
|
||||
__printf ("%03d: %20s ", opcode_counter++, opcode_names[opcode_num]);
|
||||
for (i = 1; i < opcode_sizes[opcode_num]; i++)
|
||||
__printf ("%4d ", ((char*)opcode)[i]);
|
||||
@@ -93,6 +121,7 @@ serializer_rewrite_opcode (const uint8_t loc, const void *opcode)
|
||||
uint8_t i;
|
||||
int opcode_num = (int)((char*)opcode)[0];
|
||||
|
||||
bytecode_opcodes[loc] = *((OPCODE*)opcode);
|
||||
__printf ("%03d: %20s ", loc, opcode_names[opcode_num]);
|
||||
for (i = 1; i < opcode_sizes[opcode_num]; i++)
|
||||
__printf ("%4d ", ((char*)opcode)[i]);
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
/* Copyright 2014 Samsung Electronics Co., Ltd.
|
||||
*
|
||||
* 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 "deserializer.h"
|
||||
|
||||
TODO (Implement)
|
||||
|
||||
const char *
|
||||
deserializer_get_string_by_id (uint8_t id)
|
||||
{
|
||||
JERRY_UNIMPLEMENTED_REF_UNUSED_VARS (id);
|
||||
}
|
||||
|
||||
int
|
||||
deserializer_get_num_by_id (uint8_t id)
|
||||
{
|
||||
JERRY_UNIMPLEMENTED_REF_UNUSED_VARS (id);
|
||||
}
|
||||
|
||||
const void *
|
||||
deserializer_get_bytecode (void)
|
||||
{
|
||||
JERRY_UNIMPLEMENTED ();
|
||||
}
|
||||
+3
-3
@@ -36,6 +36,7 @@
|
||||
#include "lexer.h"
|
||||
#include "parser.h"
|
||||
#include "serializer.h"
|
||||
#include "deserializer.h"
|
||||
|
||||
#define MAX_STRINGS 100
|
||||
#define MAX_NUMS 25
|
||||
@@ -67,9 +68,8 @@ jerry_run( const char *script_source,
|
||||
parser_init ();
|
||||
parser_parse_program ();
|
||||
|
||||
//gen_bytecode (generated_source);
|
||||
//gen_bytecode ();
|
||||
//run_int ();
|
||||
init_int (deserializer_get_bytecode ());
|
||||
run_int ();
|
||||
} /* jerry_run */
|
||||
|
||||
#ifdef __HOST
|
||||
|
||||
Reference in New Issue
Block a user