mirror of
https://github.com/jerryscript-project/jerryscript.git
synced 2025-12-15 16:29:21 +00:00
Splitting main.cpp into jerry.cpp, main_linux.cpp and main_mcu.cpp; leaving __TARGET* defines usage only in jrt and plugins.
This commit is contained in:
parent
145fba4109
commit
ccc0453f34
@ -193,7 +193,7 @@ project (Jerry CXX C ASM)
|
||||
JERRY_BRANCH_NAME="${JERRY_GIT_BRANCH}")
|
||||
|
||||
# Debug
|
||||
set(DEFINES_JERRY_DEBUG )
|
||||
set(DEFINES_JERRY_DEBUG JERRY_ENABLE_PRETTY_PRINTER)
|
||||
|
||||
# Release
|
||||
set(DEFINES_JERRY_RELEASE JERRY_NDEBUG)
|
||||
@ -234,7 +234,8 @@ project (Jerry CXX C ASM)
|
||||
# Linux
|
||||
set(DEFINES_JERRY_LINUX __TARGET_HOST JERRY_SOURCE_BUFFER_SIZE=1048576)
|
||||
# MCU
|
||||
set(DEFINES_JERRY_MCU __TARGET_MCU)
|
||||
math(EXPR MEM_HEAP_AREA_SIZE_16K "16 * 1024")
|
||||
set(DEFINES_JERRY_MCU CONFIG_MEM_HEAP_AREA_SIZE=${MEM_HEAP_AREA_SIZE_16K} __TARGET_MCU)
|
||||
# stm32f3
|
||||
set(DEFINES_JERRY_MCU_STM32F3 __TARGET_MCU_STM32F3)
|
||||
# stm32f4
|
||||
@ -310,6 +311,7 @@ project (Jerry CXX C ASM)
|
||||
file(GLOB SOURCE_PLUGINS_LIB_DEVICE_STM plugins/lib-device-stm/*.cpp)
|
||||
|
||||
set(SOURCE_CORE
|
||||
src/jerry.cpp
|
||||
${SOURCE_CORE_MEM}
|
||||
${SOURCE_CORE_VM}
|
||||
${SOURCE_CORE_ECMA_BUILTINS}
|
||||
@ -320,13 +322,16 @@ project (Jerry CXX C ASM)
|
||||
${SOURCE_CORE_JRT}
|
||||
${SOURCE_PLUGINS_LIB_DEVICE_STM})
|
||||
|
||||
# Jerry standalone
|
||||
set(SOURCE_JERRY_STANDALONE_MAIN src/main.cpp)
|
||||
|
||||
# Platform-specific
|
||||
# Linux
|
||||
# Jerry standalone
|
||||
set(SOURCE_JERRY_STANDALONE_MAIN_LINUX src/main_linux.cpp)
|
||||
|
||||
file(GLOB SOURCE_CORE_JRT_LINUX src/jrt/target/linux/*.cpp src/jrt/target/linux/*.S)
|
||||
# MCU
|
||||
# Jerry standalone
|
||||
set(SOURCE_JERRY_STANDALONE_MAIN_MCU src/main_mcu.cpp)
|
||||
|
||||
# stm32f3
|
||||
file(GLOB SOURCE_CORE_JRT_STM32F3 src/jrt/target/stm32f3/*.cpp src/jrt/target/stm32f3/*.S)
|
||||
# stm32f4
|
||||
@ -410,7 +415,7 @@ project (Jerry CXX C ASM)
|
||||
target_compile_definitions(${TARGET_NAME}.lib PRIVATE ${DEFINES_JERRY})
|
||||
target_include_directories(${TARGET_NAME}.lib PRIVATE ${INCLUDE_CORE})
|
||||
|
||||
add_executable(${TARGET_NAME} ${SOURCE_JERRY_STANDALONE_MAIN})
|
||||
add_executable(${TARGET_NAME} ${SOURCE_JERRY_STANDALONE_MAIN_LINUX})
|
||||
target_compile_options(${TARGET_NAME} PRIVATE ${CXX_FLAGS_JERRY} ${CXX_FLAGS_COMMON_ARCH} ${CXX_FLAGS_COMMON_${BUILD_MODE}})
|
||||
set_property(TARGET ${TARGET_NAME} PROPERTY LINK_FLAGS "${LINKER_FLAGS_JERRY} ${LINKER_FLAGS_STATIC}")
|
||||
target_compile_definitions(${TARGET_NAME} PRIVATE ${DEFINES_JERRY})
|
||||
@ -517,7 +522,7 @@ project (Jerry CXX C ASM)
|
||||
target_include_directories(${TARGET_NAME}.third_party.lib PRIVATE
|
||||
${INCLUDE_THIRD_PARTY_MCU_${PLATFORM}})
|
||||
|
||||
add_executable(${TARGET_NAME} ${SOURCE_JERRY_STANDALONE_MAIN})
|
||||
add_executable(${TARGET_NAME} ${SOURCE_JERRY_STANDALONE_MAIN_MCU})
|
||||
target_compile_options(${TARGET_NAME} PRIVATE
|
||||
${CXX_FLAGS_JERRY}
|
||||
${CXX_FLAGS_COMMON_${BUILD_MODE}}
|
||||
|
||||
@ -51,13 +51,9 @@
|
||||
/**
|
||||
* Size of heap
|
||||
*/
|
||||
#ifdef __TARGET_HOST
|
||||
#ifndef CONFIG_MEM_HEAP_AREA_SIZE
|
||||
# define CONFIG_MEM_HEAP_AREA_SIZE (64 * 1024)
|
||||
#elif defined (__TARGET_MCU)
|
||||
# define CONFIG_MEM_HEAP_AREA_SIZE (16 * 1024)
|
||||
#else /* !__TARGET_HOST && !__TARGET_MCU */
|
||||
# error "!__TARGET_HOST && !__TARGET_MCU"
|
||||
#endif /* !__TARGET_HOST && !__TARGET_MCU */
|
||||
#endif /* !CONFIG_MEM_HEAP_AREA_SIZE */
|
||||
|
||||
/**
|
||||
* Log2 of maximum possible offset in the heap
|
||||
|
||||
55
src/jerry.cpp
Normal file
55
src/jerry.cpp
Normal file
@ -0,0 +1,55 @@
|
||||
/* Copyright 2015 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 "jerry.h"
|
||||
#include "jrt.h"
|
||||
#include "parser.h"
|
||||
#include "serializer.h"
|
||||
#include "vm.h"
|
||||
|
||||
bool
|
||||
jerry_run (const char *script_source, size_t script_source_size,
|
||||
bool is_parse_only, bool is_show_opcodes, bool is_show_mem_stats)
|
||||
{
|
||||
const opcode_t *opcodes;
|
||||
|
||||
mem_init ();
|
||||
deserializer_init ();
|
||||
|
||||
parser_init (script_source, script_source_size, is_show_opcodes);
|
||||
parser_parse_program ();
|
||||
|
||||
opcodes = (const opcode_t*) deserialize_bytecode ();
|
||||
|
||||
serializer_print_opcodes ();
|
||||
parser_free ();
|
||||
|
||||
if (is_parse_only)
|
||||
{
|
||||
deserializer_free ();
|
||||
mem_finalize (is_show_mem_stats);
|
||||
return true;
|
||||
}
|
||||
|
||||
init_int (opcodes, is_show_mem_stats);
|
||||
|
||||
bool is_success = run_int ();
|
||||
|
||||
deserializer_free ();
|
||||
mem_finalize (is_show_mem_stats);
|
||||
|
||||
return is_success;
|
||||
} /* jerry_run */
|
||||
36
src/jerry.h
Normal file
36
src/jerry.h
Normal file
@ -0,0 +1,36 @@
|
||||
/* Copyright 2015 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 JERRY_H
|
||||
#define JERRY_H
|
||||
|
||||
#include "jrt_types.h"
|
||||
|
||||
/** \addtogroup jerry Jerry engine interface
|
||||
* @{
|
||||
*/
|
||||
|
||||
extern bool
|
||||
jerry_run (const char *script_source,
|
||||
size_t script_source_size,
|
||||
bool is_parse_only,
|
||||
bool is_show_opcodes,
|
||||
bool is_show_mem_stats);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* !JERRY_H */
|
||||
@ -16,16 +16,7 @@
|
||||
#ifndef JERRY_GLOBALS_H
|
||||
#define JERRY_GLOBALS_H
|
||||
|
||||
#include <float.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
/**
|
||||
* Types
|
||||
*/
|
||||
typedef unsigned long mword_t;
|
||||
#include "jrt_types.h"
|
||||
|
||||
/**
|
||||
* Attributes
|
||||
@ -213,11 +204,4 @@ extern void __noreturn jerry_exit (jerry_status_t code);
|
||||
#define JERRY_MIN(v1, v2) ((v1 < v2) ? v1 : v2)
|
||||
#define JERRY_MAX(v1, v2) ((v1 < v2) ? v2 : v1)
|
||||
|
||||
/**
|
||||
* Enable --show-opcodes key.
|
||||
*/
|
||||
#if defined (__TARGET_HOST) && !defined (JERRY_NDEBUG)
|
||||
# define JERRY_ENABLE_PP
|
||||
#endif
|
||||
|
||||
#endif /* !JERRY_GLOBALS_H */
|
||||
|
||||
25
src/jrt/jrt_types.h
Normal file
25
src/jrt/jrt_types.h
Normal file
@ -0,0 +1,25 @@
|
||||
/* Copyright 2015 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 JRT_TYPES_H
|
||||
#define JRT_TYPES_H
|
||||
|
||||
#include <float.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#endif /* !JRT_TYPES_H */
|
||||
@ -13,64 +13,10 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifdef __TARGET_MCU
|
||||
#include "common-io.h"
|
||||
#include "actuators.h"
|
||||
#include "sensors.h"
|
||||
|
||||
#include JERRY_MCU_SCRIPT_HEADER
|
||||
static const char generated_source [] = JERRY_MCU_SCRIPT;
|
||||
|
||||
#endif
|
||||
|
||||
#include "jrt.h"
|
||||
#include "vm.h"
|
||||
#include "config.h"
|
||||
#include "jerry.h"
|
||||
#include "jerry-libc.h"
|
||||
#include "lexer.h"
|
||||
#include "parser.h"
|
||||
#include "serializer.h"
|
||||
#include "deserializer.h"
|
||||
|
||||
#define MAX_STRINGS 100
|
||||
#define MAX_NUMS 25
|
||||
|
||||
static bool
|
||||
jerry_run (const char *script_source, size_t script_source_size,
|
||||
bool is_parse_only, bool is_show_opcodes, bool is_show_mem_stats)
|
||||
{
|
||||
const opcode_t *opcodes;
|
||||
|
||||
mem_init ();
|
||||
deserializer_init ();
|
||||
|
||||
parser_init (script_source, script_source_size, is_show_opcodes);
|
||||
parser_parse_program ();
|
||||
|
||||
opcodes = (const opcode_t*) deserialize_bytecode ();
|
||||
|
||||
#ifdef __TARGET_HOST
|
||||
serializer_print_opcodes ();
|
||||
#endif /* __TARGET_HOST */
|
||||
parser_free ();
|
||||
|
||||
if (is_parse_only)
|
||||
{
|
||||
deserializer_free ();
|
||||
mem_finalize (is_show_mem_stats);
|
||||
return true;
|
||||
}
|
||||
|
||||
init_int (opcodes, is_show_mem_stats);
|
||||
|
||||
bool is_success = run_int ();
|
||||
|
||||
deserializer_free ();
|
||||
mem_finalize (is_show_mem_stats);
|
||||
|
||||
return is_success;
|
||||
} /* jerry_run */
|
||||
|
||||
#ifdef __TARGET_HOST
|
||||
static uint8_t source_buffer[ JERRY_SOURCE_BUFFER_SIZE ];
|
||||
|
||||
static const char*
|
||||
@ -149,7 +95,7 @@ main (int argc __unused,
|
||||
int i;
|
||||
size_t files_counter = 0;
|
||||
|
||||
jrt_set_mem_limits (MEM_HEAP_AREA_SIZE + CONFIG_MEM_DATA_LIMIT_MINUS_HEAP_SIZE,
|
||||
jrt_set_mem_limits (CONFIG_MEM_HEAP_AREA_SIZE + CONFIG_MEM_DATA_LIMIT_MINUS_HEAP_SIZE,
|
||||
CONFIG_MEM_STACK_LIMIT);
|
||||
|
||||
for (i = 1; i < argc; i++)
|
||||
@ -177,12 +123,7 @@ main (int argc __unused,
|
||||
}
|
||||
else if (!__strcmp ("--show-opcodes", argv[i]))
|
||||
{
|
||||
#ifdef JERRY_ENABLE_PP
|
||||
show_opcodes = true;
|
||||
#else /* !JERRY_ENABLE_PP */
|
||||
__printf ("Ignoring --show-opcodes since target is not x86_64 or debug is not enabled.\n");
|
||||
show_opcodes = false;
|
||||
#endif /* JERRY_ENABLE_PP */
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -202,28 +143,3 @@ main (int argc __unused,
|
||||
|
||||
jerry_exit (is_success ? ERR_OK : ERR_FAILED_ASSERTION_IN_SCRIPT);
|
||||
}
|
||||
#endif /* __TARGET_HOST */
|
||||
|
||||
#ifdef __TARGET_MCU
|
||||
static uint32_t start __unused;
|
||||
static uint32_t finish_native_ms __unused;
|
||||
static uint32_t finish_parse_ms __unused;
|
||||
static uint32_t finish_int_ms __unused;
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
initialize_sys_tick ();
|
||||
initialize_leds ();
|
||||
initialize_timer ();
|
||||
|
||||
const char *source_p = generated_source;
|
||||
const size_t source_size = sizeof (generated_source);
|
||||
|
||||
set_sys_tick_counter ((uint32_t) - 1);
|
||||
start = get_sys_tick_counter ();
|
||||
jerry_run (source_p,
|
||||
source_size, false, false, false);
|
||||
finish_parse_ms = (start - get_sys_tick_counter ()) / 1000;
|
||||
}
|
||||
#endif /* __TARGET_MCU */
|
||||
45
src/main_mcu.cpp
Normal file
45
src/main_mcu.cpp
Normal file
@ -0,0 +1,45 @@
|
||||
/* Copyright 2015 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 "jerry.h"
|
||||
|
||||
#include "common-io.h"
|
||||
#include "actuators.h"
|
||||
#include "sensors.h"
|
||||
|
||||
#include JERRY_MCU_SCRIPT_HEADER
|
||||
static const char generated_source [] = JERRY_MCU_SCRIPT;
|
||||
|
||||
static uint32_t start __unused;
|
||||
static uint32_t finish_native_ms __unused;
|
||||
static uint32_t finish_parse_ms __unused;
|
||||
static uint32_t finish_int_ms __unused;
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
initialize_sys_tick ();
|
||||
initialize_leds ();
|
||||
initialize_timer ();
|
||||
|
||||
const char *source_p = generated_source;
|
||||
const size_t source_size = sizeof (generated_source);
|
||||
|
||||
set_sys_tick_counter ((uint32_t) - 1);
|
||||
start = get_sys_tick_counter ();
|
||||
jerry_run (source_p,
|
||||
source_size, false, false, false);
|
||||
finish_parse_ms = (start - get_sys_tick_counter ()) / 1000;
|
||||
}
|
||||
@ -45,7 +45,7 @@ serializer_merge_scopes_into_bytecode (void)
|
||||
void
|
||||
serializer_dump_literals (const literal literals[], literal_index_t literals_count)
|
||||
{
|
||||
#ifdef JERRY_ENABLE_PP
|
||||
#ifdef JERRY_ENABLE_PRETTY_PRINTER
|
||||
if (print_opcodes)
|
||||
{
|
||||
pp_literals (literals, literals_count);
|
||||
@ -63,7 +63,7 @@ serializer_dump_op_meta (op_meta op)
|
||||
|
||||
scopes_tree_add_op_meta (current_scope, op);
|
||||
|
||||
#ifdef JERRY_ENABLE_PP
|
||||
#ifdef JERRY_ENABLE_PRETTY_PRINTER
|
||||
if (print_opcodes)
|
||||
{
|
||||
pp_op_meta ((opcode_counter_t) (scopes_tree_opcodes_num (current_scope) - 1), op, false);
|
||||
@ -94,7 +94,7 @@ serializer_rewrite_op_meta (const opcode_counter_t loc, op_meta op)
|
||||
{
|
||||
scopes_tree_set_op_meta (current_scope, loc, op);
|
||||
|
||||
#ifdef JERRY_ENABLE_PP
|
||||
#ifdef JERRY_ENABLE_PRETTY_PRINTER
|
||||
if (print_opcodes)
|
||||
{
|
||||
pp_op_meta (loc, op, true);
|
||||
@ -105,7 +105,7 @@ serializer_rewrite_op_meta (const opcode_counter_t loc, op_meta op)
|
||||
void
|
||||
serializer_print_opcodes (void)
|
||||
{
|
||||
#ifdef JERRY_ENABLE_PP
|
||||
#ifdef JERRY_ENABLE_PRETTY_PRINTER
|
||||
opcode_counter_t loc;
|
||||
|
||||
if (!print_opcodes)
|
||||
|
||||
@ -14,7 +14,7 @@
|
||||
*/
|
||||
|
||||
#include "jrt.h"
|
||||
#ifdef JERRY_ENABLE_PP
|
||||
#ifdef JERRY_ENABLE_PRETTY_PRINTER
|
||||
#include "pretty-printer.h"
|
||||
#include "jerry-libc.h"
|
||||
#include "lexer.h"
|
||||
@ -650,4 +650,4 @@ pp_op_meta (opcode_counter_t oc, op_meta opm, bool rewrite)
|
||||
|
||||
__printf ("\n");
|
||||
}
|
||||
#endif /* JERRY_ENABLE_PP */
|
||||
#endif /* JERRY_ENABLE_PRETTY_PRINTER */
|
||||
|
||||
@ -17,7 +17,7 @@
|
||||
#define PRETTY_PRINTER
|
||||
|
||||
#include "jrt.h"
|
||||
#ifdef JERRY_ENABLE_PP
|
||||
#ifdef JERRY_ENABLE_PRETTY_PRINTER
|
||||
#include "vm.h"
|
||||
#include "literal.h"
|
||||
#include "scopes-tree.h"
|
||||
@ -25,6 +25,6 @@
|
||||
void pp_opcode (opcode_counter_t, opcode_t, bool);
|
||||
void pp_op_meta (opcode_counter_t, op_meta, bool);
|
||||
void pp_literals (const literal *, literal_index_t);
|
||||
#endif // JERRY_ENABLE_PP
|
||||
#endif // JERRY_ENABLE_PRETTY_PRINTER
|
||||
|
||||
#endif // PRETTY_PRINTER
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user