diff --git a/src/libruntime/target/linux/bytecode-linux.h b/src/liboptimizer/bytecode-data.h similarity index 100% rename from src/libruntime/target/linux/bytecode-linux.h rename to src/liboptimizer/bytecode-data.h diff --git a/src/libruntime/target/linux/deserializer.c b/src/liboptimizer/deserializer.c similarity index 98% rename from src/libruntime/target/linux/deserializer.c rename to src/liboptimizer/deserializer.c index 8356015b7..f2f7c88fe 100644 --- a/src/libruntime/target/linux/deserializer.c +++ b/src/liboptimizer/deserializer.c @@ -14,7 +14,7 @@ */ #include "deserializer.h" -#include "bytecode-linux.h" +#include "bytecode-data.h" int *num_data = NULL; uint8_t num_size = 0; diff --git a/src/libruntime/deserializer.h b/src/liboptimizer/deserializer.h similarity index 100% rename from src/libruntime/deserializer.h rename to src/liboptimizer/deserializer.h diff --git a/src/libruntime/target/linux/pretty-printer.c b/src/liboptimizer/pretty-printer.c similarity index 100% rename from src/libruntime/target/linux/pretty-printer.c rename to src/liboptimizer/pretty-printer.c diff --git a/src/libruntime/target/linux/pretty-printer.h b/src/liboptimizer/pretty-printer.h similarity index 100% rename from src/libruntime/target/linux/pretty-printer.h rename to src/liboptimizer/pretty-printer.h diff --git a/src/libruntime/target/linux/serializer.c b/src/liboptimizer/serializer.c similarity index 99% rename from src/libruntime/target/linux/serializer.c rename to src/liboptimizer/serializer.c index ed6f8b3d5..e3ef9feeb 100644 --- a/src/libruntime/target/linux/serializer.c +++ b/src/liboptimizer/serializer.c @@ -16,7 +16,7 @@ #include "serializer.h" #include "parser.h" #include "jerry-libc.h" -#include "bytecode-linux.h" +#include "bytecode-data.h" #include "deserializer.h" #include "pretty-printer.h" diff --git a/src/libruntime/serializer.h b/src/liboptimizer/serializer.h similarity index 100% rename from src/libruntime/serializer.h rename to src/liboptimizer/serializer.h diff --git a/src/libruntime/target/stm32f4/bytecode-stm.h b/src/libruntime/target/stm32f4/bytecode-stm.h deleted file mode 100644 index 7e7fcda2e..000000000 --- a/src/libruntime/target/stm32f4/bytecode-stm.h +++ /dev/null @@ -1,37 +0,0 @@ -/* 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_STM_H -#define BYTECODE_STM_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_STM_H \ No newline at end of file diff --git a/src/libruntime/target/stm32f4/deserializer.c b/src/libruntime/target/stm32f4/deserializer.c deleted file mode 100644 index a44b27f6f..000000000 --- a/src/libruntime/target/stm32f4/deserializer.c +++ /dev/null @@ -1,96 +0,0 @@ -/* 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-stm.h" - -TODO (Read from flash) - -int *num_data = NULL; -uint8_t num_size = 0; - -const ecma_char_t * -deserialize_string_by_id (uint8_t id) -{ - uint8_t size, *data; - uint16_t offset; - - if (bytecode_data == NULL) - return NULL; - - size = *bytecode_data; - - if (id >= size) - return NULL; - - data = bytecode_data; - - data += id * 2 + 1; - - offset = *((uint16_t *) data); - - return ((const ecma_char_t *) bytecode_data + offset); -} - -int -deserialize_num_by_id (uint8_t id) -{ - uint16_t str_size, str_offset; - - str_size = *bytecode_data; - if (id < str_size) - { - return 0; - } - id = (uint8_t) (id - str_size); - - if (num_data == NULL) - { - // Go to last string's offset - uint8_t *data = (uint8_t *) (bytecode_data + str_size * 2 - 1); - str_offset = *((uint16_t *) data); - data = bytecode_data + str_offset; - - while (*data) - data++; - - num_size = *(++data); - num_data = (int *) ++data; - } - - if (id >= num_size) - return 0; - - return num_data[id]; -} - -const void * -deserialize_bytecode (void) -{ - return bytecode_opcodes; -} - -uint8_t -deserialize_min_temp (void) -{ - uint8_t str_size = *bytecode_data; - - if (num_size == 0) - { - deserialize_num_by_id (str_size); // Init num_data and num_size - } - - return (uint8_t) (str_size + num_size); -} diff --git a/src/libruntime/target/stm32f4/serializer.c b/src/libruntime/target/stm32f4/serializer.c deleted file mode 100644 index cf35b2e77..000000000 --- a/src/libruntime/target/stm32f4/serializer.c +++ /dev/null @@ -1,119 +0,0 @@ -/* 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 "serializer.h" -#include "parser.h" -#include "globals.h" -#include "serializer.h" -#include "jerry-libc.h" -#include "bytecode-stm.h" -#include "deserializer.h" - -TODO (Dump to flash) - -void -serializer_init (bool show_opcodes __unused) -{ -} - -uint16_t -serializer_dump_strings (const char *strings[], uint8_t size) -{ - uint8_t i; - uint16_t offset = (uint8_t) (size * 2 + 1), res; - - for (i = 0; i < size; i++) - { - offset = (uint16_t) (offset + __strlen (strings[i]) + 1); - } - - bytecode_data = mem_heap_alloc_block (offset, MEM_HEAP_ALLOC_SHORT_TERM); - res = offset; - - bytecode_data[0] = size; - offset = (uint16_t) (size * 2 + 1); - for (i = 0; i < size; i++) - { - *((uint16_t *) (bytecode_data + i * 2 + 1)) = offset; - offset = (uint16_t) (offset + __strlen (strings[i]) + 1); - } - - for (i = 0; i < size; i++) - { - offset = *((uint16_t *) (bytecode_data + i * 2 + 1)); - __strncpy ((char *) (bytecode_data + offset), strings[i], __strlen (strings[i]) + 1); - } - -#ifndef JERRY_NDEBUG - for (i = 0; i < size; i++) - { - JERRY_ASSERT (!__strcmp (strings[i], (const char *) deserialize_string_by_id (i))); - } -#endif - - return res; -} - -void -serializer_dump_nums (const int32_t nums[], uint8_t size, uint16_t offset, uint8_t strings_num __unused) -{ - uint8_t i, *data; - - data = mem_heap_alloc_block ((size_t) (offset + size * 4 + 1), MEM_HEAP_ALLOC_LONG_TERM); - if (!data) - parser_fatal (ERR_MEMORY); - - __memcpy (data, bytecode_data, offset); - 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; - } - -#ifndef JERRY_NDEBUG - for (i = 0; i < size; i++) - { - JERRY_ASSERT (nums[i] == deserialize_num_by_id ((uint8_t) (i + strings_num))); - } - - JERRY_ASSERT (deserialize_min_temp () == (uint8_t) (size + strings_num)); -#endif -} - -static int opcode_counter = 0; - -void -serializer_dump_opcode (OPCODE opcode) -{ - bytecode_opcodes[opcode_counter++] = opcode; -} - -void -serializer_rewrite_opcode (const opcode_counter_t loc, OPCODE opcode) -{ - bytecode_opcodes[loc] = opcode; -} - -void -serializer_print_opcodes (void) -{ - JERRY_UNREACHABLE (); -}