diff --git a/Makefile b/Makefile index b0732af98..65b2051ab 100644 --- a/Makefile +++ b/Makefile @@ -13,29 +13,41 @@ # limitations under the License. TARGET ?= jerry -#CROSS_COMPILE ?= arm-none-eabi- +CROSS_COMPILE ?= arm-none-eabi- OBJ_DIR = obj SOURCES = \ $(sort \ - $(wildcard ./src/*.c)\ - $(wildcard ./src/libperipherals/*.c)\ - $(wildcard ./src/libcoreint/*.c)) + $(wildcard ./src/*.c) \ + $(wildcard ./src/libperipherals/*.c) \ + $(wildcard ./src/libjsparser/*.c) \ + $(wildcard ./src/libecmaobjects/*.c) \ + $(wildcard ./src/liballocator/*.c) \ + $(wildcard ./src/libcoreint/*.c) ) INCLUDES = \ -I src \ -I src/libperipherals \ + -I src/libjsparser \ + -I src/libecmaobjects \ + -I src/liballocator \ -I src/libcoreint OBJS = \ $(sort \ $(patsubst %.c,./$(OBJ_DIR)/%.o,$(notdir $(SOURCES)))) -CC = $(CROSS_COMPILE)gcc-4.9 -LD = $(CROSS_COMPILE)ld -OBJDUMP = $(CROSS_COMPILE)objdump -OBJCOPY = $(CROSS_COMPILE)objcopy -SIZE = $(CROSS_COMPILE)size +CC = gcc-4.9 +LD = ld +OBJDUMP = objdump +OBJCOPY = objcopy +SIZE = size + +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 # General flags CFLAGS ?= $(INCLUDES) -std=c99 -m32 -fdiagnostics-color=always @@ -49,8 +61,8 @@ CFLAGS ?= $(INCLUDES) -std=c99 -m32 -fdiagnostics-color=always #CFLAGS += -mfpu=fpv4-sp-d16 -mfloat-abi=hard #CFLAGS += -ffunction-sections -fdata-sections -DEBUG_OPTIONS = -g3 -O0 -DDEBUG #-fsanitize=address -RELEASE_OPTIONS = -Os # -Werror +DEBUG_OPTIONS = -g3 -O0 -DDEBUG# -fsanitize=address +RELEASE_OPTIONS = -Os -Werror DEFINES = -DMEM_HEAP_CHUNK_SIZE=256 -DMEM_HEAP_AREA_SIZE=32768 diff --git a/src/mem-allocator.c b/src/liballocator/mem-allocator.c similarity index 100% rename from src/mem-allocator.c rename to src/liballocator/mem-allocator.c diff --git a/src/mem-allocator.h b/src/liballocator/mem-allocator.h similarity index 100% rename from src/mem-allocator.h rename to src/liballocator/mem-allocator.h diff --git a/src/mem-heap.c b/src/liballocator/mem-heap.c similarity index 100% rename from src/mem-heap.c rename to src/liballocator/mem-heap.c diff --git a/src/mem-heap.h b/src/liballocator/mem-heap.h similarity index 100% rename from src/mem-heap.h rename to src/liballocator/mem-heap.h diff --git a/src/mem-pool.c b/src/liballocator/mem-pool.c similarity index 100% rename from src/mem-pool.c rename to src/liballocator/mem-pool.c diff --git a/src/mem-pool.h b/src/liballocator/mem-pool.h similarity index 100% rename from src/mem-pool.h rename to src/liballocator/mem-pool.h diff --git a/src/mem-poolman.c b/src/liballocator/mem-poolman.c similarity index 100% rename from src/mem-poolman.c rename to src/liballocator/mem-poolman.c diff --git a/src/mem-poolman.h b/src/liballocator/mem-poolman.h similarity index 100% rename from src/mem-poolman.h rename to src/liballocator/mem-poolman.h diff --git a/src/libcoreint/interpreter.c b/src/libcoreint/interpreter.c index 18320c462..aa8284d71 100644 --- a/src/libcoreint/interpreter.c +++ b/src/libcoreint/interpreter.c @@ -18,21 +18,9 @@ #include "parser.h" #include "pretty-printer.h" #include "interpreter.h" -#include "opcode.h" +#include "opcodes.h" - -void -safe_opcode (FILE *file, opcode_ptr ptr, int arg1, int arg2) -{ - curr_opcode.func = ptr; - curr_opcode.arg1 = arg1; - curr_opcode.arg2 = arg2; - - if (file != NULL) - { - fwrite (&curr_opcode, sizeof (struct opcode_packed), 1, file); - } -} +#include "actuators.h" void gen_bytecode (FILE *src_file) @@ -51,14 +39,15 @@ gen_bytecode (FILE *src_file) pp_finish (); FILE *file = fopen (FILE_NAME, "w+b"); - int i; - - for (i = 0; i <= 10; i++) - { - safe_opcode (file, control_op, i, i); - safe_opcode (file, decl_op, i, i); - safe_opcode (file, call_op, i, i); - } + + union __opcodes op0; + + save_op_loop_inf (file, op0, 1); + save_op_call_1 (file, op0, 0, LED_GREEN); + save_op_call_1 (file, op0, 0, LED_BLUE); + save_op_call_1 (file, op0, 0, LED_ORANGE); + save_op_call_1 (file, op0, 0, LED_RED); + save_op_jmp (file, op0, 0); fclose (file); } @@ -67,6 +56,7 @@ void run_int () { FILE *file = fopen (FILE_NAME, "rb"); + union __opcodes op_curr; if (file == NULL) { @@ -76,10 +66,12 @@ run_int () while (!feof (file)) { - fread (&curr_opcode, sizeof (struct opcode_packed), 1, file); - - //printf ("read %d, %d, %p\n", curr_opcode.arg1, curr_opcode.arg2, curr_opcode.func); - curr_opcode.func (curr_opcode.arg1, curr_opcode.arg2); + if (!fread (&op_curr, sizeof (union __opcodes), 1, file)) + { + break; + } + + op_curr.opfunc_ptr (op_curr); } fclose (file); diff --git a/src/libcoreint/interpreter.h b/src/libcoreint/interpreter.h index a2f172913..ca0410143 100644 --- a/src/libcoreint/interpreter.h +++ b/src/libcoreint/interpreter.h @@ -13,13 +13,6 @@ * limitations under the License. */ -/* - * File: interpreter.h - * Author: egavrin - * - * Created on July 2, 2014, 3:10 PM - */ - #ifndef INTERPRETER_H #define INTERPRETER_H @@ -27,11 +20,10 @@ #include #include -#include "opcode.h" +#include "opcodes.h" #define FILE_NAME "application.bin" -void safe_opcode(FILE *, opcode_ptr, int, int); void gen_bytecode(FILE*); void run_int(); diff --git a/src/libcoreint/opcodes.c b/src/libcoreint/opcodes.c index 7a05f325d..864a582d4 100644 --- a/src/libcoreint/opcodes.c +++ b/src/libcoreint/opcodes.c @@ -13,21 +13,98 @@ * limitations under the License. */ -#include "opcode.h" +#include "opcodes.h" #include +#include -OP_DEFINITION (control_op) +void +opfunc_loop_inf (union __opcodes opdata) { - printf ("control_op %d, %d\n", arg1, arg2); + printf ("loop_inf:idx:%d\n", + opdata.op_loop_inf.opcode_idx); } -OP_DEFINITION (decl_op) +void +opfunc_op_call_1 (union __opcodes opdata) { - printf ("decl_op %d, %d\n", arg1, arg2); + printf ("op_call_1:idx:%d:%d\n", + opdata.op_call_1.name_literal_idx, + opdata.op_call_1.arg_literal_idx); } -OP_DEFINITION (call_op) + + +void +opfunc_op_jmp (union __opcodes opdata) { - printf ("call_op %d, %d\n", arg1, arg2); + printf ("op_jmp:idx:%d\n", + opdata.op_jmp.opcode_idx); +} + +void proxy_loop_inf (union __opcodes opdata) +{ + opdata.op_loop_inf.opfunc_ptr (opdata); +} + + +void proxy_op_call_1 (union __opcodes opdata) +{ + opdata.op_call_1.opfunc_ptr (opdata); +} + +void proxy_op_jmp (union __opcodes opdata) +{ + opdata.op_jmp.opfunc_ptr (opdata); +} + + + +void +save_op_jmp (FILE *file, union __opcodes opdata, int arg1) +{ + if (file == NULL) + { + return; + } + + opdata.opfunc_ptr = proxy_op_jmp; + + opdata.op_jmp.opfunc_ptr = opfunc_op_jmp; + opdata.op_jmp.opcode_idx = arg1; + + fwrite (&opdata, sizeof (union __opcodes), 1, file); +} + +void +save_op_call_1 (FILE *file, union __opcodes opdata, int arg1, int arg2) +{ + if (file == NULL) + { + return; + } + + opdata.opfunc_ptr = proxy_op_call_1; + + opdata.op_call_1.opfunc_ptr = opfunc_op_call_1; + opdata.op_call_1.name_literal_idx = arg1; + opdata.op_call_1.arg_literal_idx = arg2; + + fwrite (&opdata, sizeof (union __opcodes), 1, file); +} + +void +save_op_loop_inf (FILE *file, union __opcodes opdata, int arg1) +{ + if (file == NULL) + { + return; + } + + opdata.opfunc_ptr = proxy_loop_inf; + + opdata.op_loop_inf.opfunc_ptr = opfunc_loop_inf; + opdata.op_loop_inf.opcode_idx = arg1; + + fwrite (&opdata, sizeof (union __opcodes), 1, file); } \ No newline at end of file diff --git a/src/libcoreint/opcodes.h b/src/libcoreint/opcodes.h index 3571f0db4..dc5ca6bd1 100644 --- a/src/libcoreint/opcodes.h +++ b/src/libcoreint/opcodes.h @@ -13,43 +13,49 @@ * limitations under the License. */ -/* - * File: opcode.h - * Author: egavrin - * - * Created on July 2, 2014, 3:12 PM - */ +#ifndef OPCODES_H +#define OPCODES_H -#ifndef OPCODE_H -#define OPCODE_H +#include "stdio.h" #define OP_RET_TYPE void -#define OP_ARG_TYPE int +#define OP_INT_TYPE int -#define OP_ATTR_DECL OP_ARG_TYPE, OP_ARG_TYPE -#define OP_ATTR_DEF OP_ARG_TYPE arg1, OP_ARG_TYPE arg2 +union __opcodes; -#define OP_DECLARATION(opname) OP_RET_TYPE opname (OP_ATTR_DECL) -#define OP_DEFINITION(opname) OP_RET_TYPE opname (OP_ATTR_DEF) +typedef OP_RET_TYPE (*op_proxy_ptr)(union __opcodes); -// opcode ptr -typedef OP_RET_TYPE (*opcode_ptr)(OP_ATTR_DECL); +typedef OP_RET_TYPE (*opfunc_int_ptr)(union __opcodes); +typedef OP_RET_TYPE (*opfunc_int_int_ptr)(union __opcodes); -struct -__attribute__ ((__packed__)) -opcode_packed +union __opcodes { - opcode_ptr func; - OP_ARG_TYPE arg1; - OP_ARG_TYPE arg2; -} -curr_opcode; + op_proxy_ptr opfunc_ptr; + + struct __op_loop_inf + { + opfunc_int_ptr opfunc_ptr; + int opcode_idx; + } op_loop_inf; -#define INIT_OPCODE_PTR(func) opcode_ptr func_ptr = ptr; + /** Call with 1 argument */ + struct __op_call_1 + { + opfunc_int_int_ptr opfunc_ptr; + int name_literal_idx; + int arg_literal_idx; + } op_call_1; -OP_DECLARATION (decl_op); -OP_DECLARATION (call_op); -OP_DECLARATION (control_op); + struct __op_jmp + { + opfunc_int_ptr opfunc_ptr; + int opcode_idx; + } op_jmp; +} __packed; -#endif /* OPCODE_H */ +void save_op_jmp(FILE *, union __opcodes, int); +void save_op_call_1(FILE *, union __opcodes, int, int); +void save_op_loop_inf(FILE *, union __opcodes, int); + +#endif /* OPCODES_H */ diff --git a/src/ctx-manager.c b/src/libecmaobjects/ctx-manager.c similarity index 100% rename from src/ctx-manager.c rename to src/libecmaobjects/ctx-manager.c diff --git a/src/ctx-manager.h b/src/libecmaobjects/ctx-manager.h similarity index 100% rename from src/ctx-manager.h rename to src/libecmaobjects/ctx-manager.h diff --git a/src/ctx-reference.c b/src/libecmaobjects/ctx-reference.c similarity index 100% rename from src/ctx-reference.c rename to src/libecmaobjects/ctx-reference.c diff --git a/src/ctx-reference.h b/src/libecmaobjects/ctx-reference.h similarity index 100% rename from src/ctx-reference.h rename to src/libecmaobjects/ctx-reference.h diff --git a/src/ecma-alloc.c b/src/libecmaobjects/ecma-alloc.c similarity index 100% rename from src/ecma-alloc.c rename to src/libecmaobjects/ecma-alloc.c diff --git a/src/ecma-alloc.h b/src/libecmaobjects/ecma-alloc.h similarity index 100% rename from src/ecma-alloc.h rename to src/libecmaobjects/ecma-alloc.h diff --git a/src/ecma-conversion.h b/src/libecmaobjects/ecma-conversion.h similarity index 100% rename from src/ecma-conversion.h rename to src/libecmaobjects/ecma-conversion.h diff --git a/src/ecma-gc.c b/src/libecmaobjects/ecma-gc.c similarity index 100% rename from src/ecma-gc.c rename to src/libecmaobjects/ecma-gc.c diff --git a/src/ecma-gc.h b/src/libecmaobjects/ecma-gc.h similarity index 100% rename from src/ecma-gc.h rename to src/libecmaobjects/ecma-gc.h diff --git a/src/ecma-globals.h b/src/libecmaobjects/ecma-globals.h similarity index 100% rename from src/ecma-globals.h rename to src/libecmaobjects/ecma-globals.h diff --git a/src/ecma-helpers.c b/src/libecmaobjects/ecma-helpers.c similarity index 100% rename from src/ecma-helpers.c rename to src/libecmaobjects/ecma-helpers.c diff --git a/src/ecma-helpers.h b/src/libecmaobjects/ecma-helpers.h similarity index 100% rename from src/ecma-helpers.h rename to src/libecmaobjects/ecma-helpers.h diff --git a/src/lexer.c b/src/libjsparser/lexer.c similarity index 100% rename from src/lexer.c rename to src/libjsparser/lexer.c diff --git a/src/lexer.h b/src/libjsparser/lexer.h similarity index 100% rename from src/lexer.h rename to src/libjsparser/lexer.h diff --git a/src/parser.c b/src/libjsparser/parser.c similarity index 100% rename from src/parser.c rename to src/libjsparser/parser.c diff --git a/src/parser.h b/src/libjsparser/parser.h similarity index 100% rename from src/parser.h rename to src/libjsparser/parser.h diff --git a/src/libperipherals/actuators.c b/src/libperipherals/actuators.c index 609246d9a..267120650 100644 --- a/src/libperipherals/actuators.c +++ b/src/libperipherals/actuators.c @@ -13,4 +13,21 @@ * limitations under the License. */ +#include +#include "actuators.h" + +void led_toggle(int led_id) +{ + printf("led_toogle: %d", led_id); +} + +void led_on(int led_id) +{ + printf("led_on: %d", led_id); +} + +void led_off(int led_id) +{ + printf("led_off: %d", led_id); +} \ No newline at end of file diff --git a/src/libperipherals/actuators.h b/src/libperipherals/actuators.h index 928f714b5..40114e69f 100644 --- a/src/libperipherals/actuators.h +++ b/src/libperipherals/actuators.h @@ -13,16 +13,18 @@ * limitations under the License. */ -/* - * File: actuators.h - * Author: egavrin - * - * Created on July 2, 2014, 2:06 PM - */ - #ifndef ACTUATORS_H #define ACTUATORS_H +// STM32 F4 +#define LED_GREEN 12 +#define LED_ORANGE 13 +#define LED_RED 14 +#define LED_BLUE 15 + +void led_toggle(int); +void led_on(int); +void led_off(int); #endif /* ACTUATORS_H */ diff --git a/src/libperipherals/common-io.h b/src/libperipherals/common-io.h index 1193d5970..b5da0692b 100644 --- a/src/libperipherals/common-io.h +++ b/src/libperipherals/common-io.h @@ -13,13 +13,6 @@ * limitations under the License. */ -/* - * File: common-io.h - * Author: egavrin - * - * Created on July 2, 2014, 2:14 PM - */ - #ifndef COMMON_IO_H #define COMMON_IO_H diff --git a/src/libperipherals/sensors.h b/src/libperipherals/sensors.h index 9a677b5f4..4240aea74 100644 --- a/src/libperipherals/sensors.h +++ b/src/libperipherals/sensors.h @@ -13,13 +13,6 @@ * limitations under the License. */ -/* - * File: sensors.h - * Author: egavrin - * - * Created on July 2, 2014, 2:05 PM - */ - #ifndef SENSORS_H #define SENSORS_H