From 480b2ebaeaefbf7ba51473a7a9373a9b4cc18bd2 Mon Sep 17 00:00:00 2001 From: "e.gavrin" Date: Tue, 8 Jul 2014 13:47:33 +0400 Subject: [PATCH 1/2] fix warnings --- src/libcoreint/interpreter.h | 4 +- src/libcoreint/opcode-structures.h | 132 ++++++++++++++--------------- 2 files changed, 68 insertions(+), 68 deletions(-) diff --git a/src/libcoreint/interpreter.h b/src/libcoreint/interpreter.h index 01916337f..f01bf69cc 100644 --- a/src/libcoreint/interpreter.h +++ b/src/libcoreint/interpreter.h @@ -34,8 +34,8 @@ struct __int_data int *root_op_addr; }; -void gen_bytecode (); -void run_int (); +void gen_bytecode (void); +void run_int (void); void run_int_from_pos (struct __int_data *); #endif /* INTERPRETER_H */ diff --git a/src/libcoreint/opcode-structures.h b/src/libcoreint/opcode-structures.h index 3416e012f..4d42f6286 100644 --- a/src/libcoreint/opcode-structures.h +++ b/src/libcoreint/opcode-structures.h @@ -21,11 +21,11 @@ #define OP_CODE_DECL_VOID(name) \ - struct __op_##name { }; \ - OPCODE getop_##name (); + struct __op_##name { T_IDX __do_not_use; }; \ + OPCODE getop_##name ( void ); #define OP_CODE_DECL(name, type, ... ) \ - OP_DEF (name, type##_DECL( __VA_ARGS__ ) ); \ + OP_DEF (name, type##_DECL( __VA_ARGS__ ) ) \ OPCODE getop_##name ( type ); #define T_IDX_IDX T_IDX, T_IDX @@ -49,112 +49,112 @@ /** L < R */ OP_CODE_DECL (is_less_than, T_IDX_IDX, value_left, - value_right); + value_right) /** L <= R */ OP_CODE_DECL (is_less_or_equal, T_IDX_IDX, value_left, - value_right); + value_right) /** L > R */ OP_CODE_DECL (is_greater_than, T_IDX_IDX, value_left, - value_right); + value_right) /** L >= R */ OP_CODE_DECL (is_greater_or_equal, T_IDX_IDX, value_left, - value_right); + value_right) /** L == R */ OP_CODE_DECL (is_equal_value, T_IDX_IDX, value_left, - value_right); + value_right) /** L != R */ OP_CODE_DECL (is_not_equal_value, T_IDX_IDX, value_left, - value_right); + value_right) /** L === R */ OP_CODE_DECL (is_equal_value_type, T_IDX_IDX, value_left, - value_right); + value_right) /** L !== R */ OP_CODE_DECL (is_not_equal_value_type, T_IDX_IDX, value_left, - value_right); + value_right) /** Instruction tests if BOOLEAN value is TRUE and JMP to DST */ OP_CODE_DECL (is_true_jmp, T_IDX_IDX, value, - opcode); + opcode) /** Instruction tests if BOOLEAN value is FALSE and JMP to DST */ OP_CODE_DECL (is_false_jmp, T_IDX_IDX, value, - opcode); + opcode) /** Unconditional JMP to the specified opcode index */ OP_CODE_DECL (jmp, T_IDX, - opcode_idx); + opcode_idx) /** Unconditional JMP on opcode_count up */ OP_CODE_DECL (jmp_up, T_IDX, - opcode_count); + opcode_count) /** Unconditional JMP on opcode_count down */ OP_CODE_DECL (jmp_down, T_IDX, - opcode_count); + opcode_count) /** dst = L + R */ OP_CODE_DECL (addition, T_IDX_IDX_IDX, dst, var_left, - var_right); + var_right) /** dst = L - R */ OP_CODE_DECL (substraction, T_IDX_IDX_IDX, dst, var_left, - var_right); + var_right) /** dst = L / R */ OP_CODE_DECL (division, T_IDX_IDX_IDX, dst, var_left, - var_right); + var_right) /** dst = L * R */ OP_CODE_DECL (multiplication, T_IDX_IDX_IDX, dst, var_left, - var_right); + var_right) /** dst = L % R */ OP_CODE_DECL (remainder, T_IDX_IDX_IDX, dst, var_left, - var_right); + var_right) /** dst = L << R */ OP_CODE_DECL (b_shift_left, T_IDX_IDX_IDX, dst, var_left, - var_right); + var_right) /** dst = L >> R */ OP_CODE_DECL (b_shift_right, T_IDX_IDX_IDX, dst, var_left, - var_right); + var_right) /** dst = L >>> R */ OP_CODE_DECL (b_shift_uright, T_IDX_IDX_IDX, dst, var_left, - var_right); + var_right) // Binary bitwise operators. // Operands is a set of 32 bits @@ -164,19 +164,19 @@ OP_CODE_DECL (b_shift_uright, T_IDX_IDX_IDX, OP_CODE_DECL (b_and, T_IDX_IDX_IDX, dst, var_left, - var_right); + var_right) /** dst = L | R */ OP_CODE_DECL (b_or, T_IDX_IDX_IDX, dst, var_left, - var_right); + var_right) /** dst = L ^ R */ OP_CODE_DECL (b_xor, T_IDX_IDX_IDX, dst, var_left, - var_right); + var_right) // Binary logical operators. // Operands are booleans. @@ -186,13 +186,13 @@ OP_CODE_DECL (b_xor, T_IDX_IDX_IDX, OP_CODE_DECL (logical_and, T_IDX_IDX_IDX, dst, var_left, - var_right); + var_right) /** dst = L || R */ OP_CODE_DECL (logical_or, T_IDX_IDX_IDX, dst, var_left, - var_right); + var_right) // Assignment operators. // Assign value to LEFT operand based on value of RIGHT operand. @@ -200,133 +200,133 @@ OP_CODE_DECL (logical_or, T_IDX_IDX_IDX, /** L = R */ OP_CODE_DECL (assignment, T_IDX_IDX, value_left, - value_right); + value_right) /** L *= R */ OP_CODE_DECL (assignment_multiplication, T_IDX_IDX, value_left, - value_right); + value_right) /** L /= R */ OP_CODE_DECL (assignment_devision, T_IDX_IDX, value_left, - value_right); + value_right) /** L %= R */ OP_CODE_DECL (assignment_remainder, T_IDX_IDX, value_left, - value_right); + value_right) /** L += R */ OP_CODE_DECL (assignment_addition, T_IDX_IDX, value_left, - value_right); + value_right) /** L -= R */ OP_CODE_DECL (assignment_substruction, T_IDX_IDX, value_left, - value_right); + value_right) /** L <<= R */ OP_CODE_DECL (assignment_shift_left, T_IDX_IDX, value_left, - value_right); + value_right) /** L >>= R */ OP_CODE_DECL (assignment_shift_right, T_IDX_IDX, value_left, - value_right); + value_right) /** L >>>= R */ OP_CODE_DECL (assignment_shift_uright, T_IDX_IDX, value_left, - value_right); + value_right) /** L &= R */ OP_CODE_DECL (assignment_b_and, T_IDX_IDX, value_left, - value_right); + value_right) /** L ^= R */ OP_CODE_DECL (assignment_b_xor, T_IDX_IDX, value_left, - value_right); + value_right) /** L |= R */ OP_CODE_DECL (assignment_b_or, T_IDX_IDX, value_left, - value_right); + value_right) // Functions calls, declarations and argument handling /** name(arg1); */ OP_CODE_DECL (call_1, T_IDX_IDX, name_lit_idx, - arg1_lit_idx); + arg1_lit_idx) /** name(arg1, arg2); */ OP_CODE_DECL (call_2, T_IDX_IDX_IDX, name_lit_idx, arg1_lit_idx, - arg2_lit_idx); + arg2_lit_idx) /** name(arg1, arg2, ... */ OP_CODE_DECL (call_n, T_IDX_IDX_IDX, name_lit_idx, arg1_lit_idx, - arg2_lit_idx); + arg2_lit_idx) /** name(arg1); */ OP_CODE_DECL (func_decl_1, T_IDX_IDX, name_lit_idx, - arg1_lit_idx); + arg1_lit_idx) /** name(arg1, arg2); */ OP_CODE_DECL (func_decl_2, T_IDX_IDX_IDX, name_lit_idx, arg1_lit_idx, - arg2_lit_idx); + arg2_lit_idx) /** name(arg1, arg2, ... */ OP_CODE_DECL (func_decl_n, T_IDX_IDX_IDX, name_lit_idx, arg1_lit_idx, - arg2_lit_idx); + arg2_lit_idx) /** ..., arg1, ... */ OP_CODE_DECL (varg_1, T_IDX, - arg1_lit_idx); + arg1_lit_idx) /** ..., arg1); */ OP_CODE_DECL (varg_1_end, T_IDX, - arg1_lit_idx); + arg1_lit_idx) /** ..., arg1, arg2, ... */ OP_CODE_DECL (varg_2, T_IDX_IDX, arg1_lit_idx, - arg2_lit_idx); + arg2_lit_idx) /** ..., arg1, arg2); */ OP_CODE_DECL (varg_2_end, T_IDX_IDX, arg1_lit_idx, - arg2_lit_idx); + arg2_lit_idx) /** arg1, arg2, arg3, ... */ OP_CODE_DECL (varg_3, T_IDX_IDX_IDX, arg1_lit_idx, arg2_lit_idx, - arg3_lit_idx); + arg3_lit_idx) /** arg1, arg2, arg3); */ OP_CODE_DECL (varg_3_end, T_IDX_IDX_IDX, arg1_lit_idx, arg2_lit_idx, - arg3_lit_idx); + arg3_lit_idx) /** return value; */ OP_CODE_DECL (retval, T_IDX, - ret_value); -OP_CODE_DECL_VOID (ret); + ret_value) +OP_CODE_DECL_VOID (ret) // LOOPS // Lately, all loops should be translated into different JMPs in an optimizer. @@ -334,7 +334,7 @@ OP_CODE_DECL_VOID (ret); /** End of body of infinite loop should be ended with unconditional JMP * to loop_root (ie. next op after loop condition) */ OP_CODE_DECL (loop_inf, T_IDX, - loop_root); + loop_root) /** Numeric loop initialization. * for (start,stop,step) @@ -342,7 +342,7 @@ OP_CODE_DECL (loop_inf, T_IDX, OP_CODE_DECL (loop_init_num, T_IDX_IDX_IDX, start, stop, - step); + step) /** Check loop (condition). * if (loop cond is true) @@ -352,7 +352,7 @@ OP_CODE_DECL (loop_init_num, T_IDX_IDX_IDX, */ OP_CODE_DECL (loop_precond_begin_num, T_IDX_IDX, condition, - after_loop_op); + after_loop_op) /** i++; * Increment iterator on step and JMP to PRECOND @@ -360,33 +360,33 @@ OP_CODE_DECL (loop_precond_begin_num, T_IDX_IDX, OP_CODE_DECL (loop_precond_end_num, T_IDX_IDX_IDX, iterator, step, - precond_begin); + precond_begin) /** do {...} while (cond); * If condition is true, JMP to BODY_ROOT */ OP_CODE_DECL (loop_postcond, T_IDX_IDX, condition, - body_root); + body_root) ///** for vars...in iter, state, ctl */ //OP_CODE_DECL (loop_init, T_IDX_IDX_IDX, -// start_idx, stop_idx, step_idx); +// start_idx, stop_idx, step_idx) ///** loop (condition) */ //OP_CODE_DECL (loop_cond_pre_begin, T_IDX_IDX, -// condition, body_root); +// condition, body_root) ///** i++;*/ //OP_CODE_DECL (loop_cond_pre_end, T_IDX, -// iterator, body_root); +// iterator, body_root) // Property accessors (array, objects, strings) /** Array ops for ILMIR*/ //OP_CODE_DECL (array_copy, T_IDX_IDX, /** L = R */ -// var_left, var_right); +// var_left, var_right) //OP_CODE_DECL (array_set, T_IDX_IDX_IDX, /** array[index] = src */ -// dst, var_left, var_right); +// dst, var_left, var_right) //OP_CODE_DECL (array_get, T_IDX_IDX_IDX, /** dst = array[index] */ -// dst, array, index); +// dst, array, index) //// TODO From 972cd2c88564b2151d18874b39cd867b8dfef97f Mon Sep 17 00:00:00 2001 From: "e.gavrin" Date: Tue, 8 Jul 2014 15:43:26 +0400 Subject: [PATCH 2/2] preparation for MCU porting --- Makefile | 36 +++++++++++++----------------- src/libcoreint/interpreter.h | 3 +++ src/libcoreint/opcode-structures.h | 12 +++++----- 3 files changed, 23 insertions(+), 28 deletions(-) diff --git a/Makefile b/Makefile index 6072ba1ed..5d484ef60 100644 --- a/Makefile +++ b/Makefile @@ -13,7 +13,7 @@ # limitations under the License. TARGET ?= jerry -CROSS_COMPILE ?= arm-none-eabi- +CROSS_COMPILE ?= OBJ_DIR = obj OUT_DIR = ./out @@ -58,18 +58,12 @@ OBJS = \ $(sort \ $(patsubst %.c,./$(OBJ_DIR)/%.o,$(notdir $(MAIN_MODULE_SRC) $(SOURCES)))) -CC = gcc#-4.9 -LD = ld -OBJDUMP = objdump -OBJCOPY = objcopy -SIZE = size -STRIP = strip - -CROSS_CC = $(CROSS_COMPILE)gcc#-4.9 -CROSS_LD = $(CROSS_COMPILE)ld -CROSS_OBJDUMP = $(CROSS_COMPILE)objdump -CROSS_OBJCOPY = $(CROSS_COMPILE)objcopy -CROSS_SIZE = $(CROSS_COMPILE)size +CC = $(CROSS_COMPILE)gcc +LD = $(CROSS_COMPILE)ld +OBJDUMP = $(CROSS_COMPILE)objdump +OBJCOPY = $(CROSS_COMPILE)objcopy +SIZE = $(CROSS_COMPILE)size +STRIP = $(CROSS_COMPILE)strip # General flags CFLAGS ?= $(INCLUDES) -std=c99 -m32 #-fdiagnostics-color=always @@ -79,33 +73,33 @@ CFLAGS ?= $(INCLUDES) -std=c99 -m32 #-fdiagnostics-color=always #CFLAGS += -Wstrict-prototypes -Wmissing-prototypes # Flags for MCU -#CFLAGS += -mlittle-endian -mcpu=cortex-m4 -march=armv7e-m -mthumb -#CFLAGS += -mfpu=fpv4-sp-d16 -mfloat-abi=hard -#CFLAGS += -ffunction-sections -fdata-sections +MCU_CFLAGS += -mlittle-endian -mcpu=cortex-m4 -march=armv7e-m -mthumb +MCU_CFLAGS += -mfpu=fpv4-sp-d16 -mfloat-abi=hard +MCU_CFLAGS += -ffunction-sections -fdata-sections -DEBUG_OPTIONS = -g3 -O0 -DDEBUG# -fsanitize=address +DEBUG_OPTIONS = -g3 -O0 -DDEBUG #-fsanitize=address RELEASE_OPTIONS = -Os -Werror -DNDEBUG DEFINES = -DMEM_HEAP_CHUNK_SIZE=256 -DMEM_HEAP_AREA_SIZE=32768 TARGET_HOST = -D__HOST TARGET_MCU = -D__MCU -.PHONY: all debug release clean tests check install +.PHONY: all debug debug.stm32f3 release clean tests check install all: clean debug release check -debug: +debug: clean mkdir -p $(OUT_DIR)/debug.host/ $(CC) $(CFLAGS) $(DEBUG_OPTIONS) $(DEFINES) $(TARGET_HOST) \ $(SOURCES) $(MAIN_MODULE_SRC) -o $(OUT_DIR)/debug.host/$(TARGET) -release: +release: clean mkdir -p $(OUT_DIR)/release.host/ $(CC) $(CFLAGS) $(RELEASE_OPTIONS) $(DEFINES) $(TARGET_HOST) \ $(SOURCES) $(MAIN_MODULE_SRC) -o $(OUT_DIR)/release.host/$(TARGET) $(STRIP) $(OUT_DIR)/release.host/$(TARGET) -tests: +tests: clean mkdir -p $(OUT_DIR)/tests.host/ for unit_test in $(UNITTESTS); \ do \ diff --git a/src/libcoreint/interpreter.h b/src/libcoreint/interpreter.h index f01bf69cc..7b3351f8b 100644 --- a/src/libcoreint/interpreter.h +++ b/src/libcoreint/interpreter.h @@ -23,6 +23,7 @@ #endif #include "opcodes.h" +#include "ecma-globals.h" OPCODE __program[128]; @@ -31,6 +32,8 @@ opfunc __opfuncs[LAST_OP]; struct __int_data { int pos; + ecma_Object_t *pThisBinding; /**< this binding for current context */ + ecma_Object_t *pLexEnv; /**< current lexical environment */ int *root_op_addr; }; diff --git a/src/libcoreint/opcode-structures.h b/src/libcoreint/opcode-structures.h index 4d42f6286..6332dce69 100644 --- a/src/libcoreint/opcode-structures.h +++ b/src/libcoreint/opcode-structures.h @@ -390,13 +390,11 @@ OP_CODE_DECL (loop_postcond, T_IDX_IDX, //// TODO -// Variable declarations +// Variable declaration +OP_CODE_DECL (decl_var, T_IDX, + variable) + // TODO New constructor - - - - -#endif /* OPCODE_STRUCTURES_H */ - +#endif /* OPCODE_STRUCTURES_H */ \ No newline at end of file