fixed Makefile and tests, wrapped interpreter and opcodes
This commit is contained in:
@@ -15,6 +15,7 @@
|
|||||||
TARGET ?= jerry
|
TARGET ?= jerry
|
||||||
CROSS_COMPILE ?= arm-none-eabi-
|
CROSS_COMPILE ?= arm-none-eabi-
|
||||||
OBJ_DIR = obj
|
OBJ_DIR = obj
|
||||||
|
OUT_DIR = ./out
|
||||||
|
|
||||||
SOURCES = \
|
SOURCES = \
|
||||||
$(sort \
|
$(sort \
|
||||||
@@ -51,6 +52,7 @@ LD = ld
|
|||||||
OBJDUMP = objdump
|
OBJDUMP = objdump
|
||||||
OBJCOPY = objcopy
|
OBJCOPY = objcopy
|
||||||
SIZE = size
|
SIZE = size
|
||||||
|
STRIP = strip
|
||||||
|
|
||||||
CROSS_CC = $(CROSS_COMPILE)gcc-4.9
|
CROSS_CC = $(CROSS_COMPILE)gcc-4.9
|
||||||
CROSS_LD = $(CROSS_COMPILE)ld
|
CROSS_LD = $(CROSS_COMPILE)ld
|
||||||
@@ -71,35 +73,50 @@ CFLAGS ?= $(INCLUDES) -std=c99 -m32 -fdiagnostics-color=always
|
|||||||
#CFLAGS += -ffunction-sections -fdata-sections
|
#CFLAGS += -ffunction-sections -fdata-sections
|
||||||
|
|
||||||
DEBUG_OPTIONS = -g3 -O0 -DDEBUG# -fsanitize=address
|
DEBUG_OPTIONS = -g3 -O0 -DDEBUG# -fsanitize=address
|
||||||
RELEASE_OPTIONS = -Os -Werror
|
RELEASE_OPTIONS = -Os -Werror -DNDEBUG
|
||||||
|
|
||||||
DEFINES = -DMEM_HEAP_CHUNK_SIZE=256 -DMEM_HEAP_AREA_SIZE=32768
|
DEFINES = -DMEM_HEAP_CHUNK_SIZE=256 -DMEM_HEAP_AREA_SIZE=32768
|
||||||
|
TARGET_HOST = -D__HOST
|
||||||
|
TARGET_MCU = -D__MCU
|
||||||
|
|
||||||
.PHONY: all debug release clean check install
|
.PHONY: all debug release clean check install
|
||||||
|
|
||||||
all: debug
|
all: clean debug release check
|
||||||
|
|
||||||
debug:
|
debug:
|
||||||
$(CC) $(INCLUDES) $(CFLAGS) $(DEBUG_OPTIONS) $(DEFINES) $(SOURCES) \
|
mkdir -p $(OUT_DIR)/debug.host/
|
||||||
-o $(TARGET)
|
$(CC) $(CFLAGS) $(DEBUG_OPTIONS) $(DEFINES) $(TARGET_HOST) \
|
||||||
|
$(SOURCES) -o $(OUT_DIR)/debug.host/$(TARGET)
|
||||||
|
|
||||||
release:
|
release:
|
||||||
$(CC) $(INCLUDES) $(CFLAGS) $(RELEASE_OPTIONS) $(DEFINES) $(SOURCES) \
|
mkdir -p $(OUT_DIR)/release.host/
|
||||||
-o $(TARGET)
|
$(CC) $(CFLAGS) $(RELEASE_OPTIONS) $(DEFINES) $(TARGET_HOST) \
|
||||||
|
$(SOURCES) -o $(OUT_DIR)/release.host/$(TARGET)
|
||||||
|
$(STRIP) $(OUT_DIR)/release.host/$(TARGET)
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f $(OBJ_DIR)/*.o *.bin *.o *~ *.log *.log
|
rm -f $(OBJ_DIR)/*.o *.bin *.o *~ *.log *.log
|
||||||
|
rm -rf $(OUT_DIR)
|
||||||
rm -f $(TARGET)
|
rm -f $(TARGET)
|
||||||
rm -f $(TARGET).elf
|
rm -f $(TARGET).elf
|
||||||
rm -f $(TARGET).bin
|
rm -f $(TARGET).bin
|
||||||
rm -f $(TARGET).map
|
rm -f $(TARGET).map
|
||||||
rm -f $(TARGET).hex
|
rm -f $(TARGET).hex
|
||||||
rm -f $(TARGET).lst
|
rm -f $(TARGET).lst
|
||||||
rm -f jerry.error js.files
|
|
||||||
|
|
||||||
check:
|
check:
|
||||||
|
mkdir -p $(OUT_DIR)
|
||||||
|
cd $(OUT_DIR)
|
||||||
cppcheck $(HEADERS) $(SOURCES) --enable=all --std=c99
|
cppcheck $(HEADERS) $(SOURCES) --enable=all --std=c99
|
||||||
./tools/jerry_test.sh
|
|
||||||
|
if [ -f $(OUT_DIR)/release.host/$(TARGET) ]; then \
|
||||||
|
./tools/jerry_test.sh $(OUT_DIR)/release.host/$(TARGET);\
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -f $(OUT_DIR)/debug.host/$(TARGET) ]; then \
|
||||||
|
./tools/jerry_test.sh $(OUT_DIR)/debug.host/$(TARGET);\
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
install:
|
install:
|
||||||
st-flash write $(TARGET).bin 0x08000000
|
st-flash write $(TARGET).bin 0x08000000
|
||||||
|
|||||||
@@ -13,37 +13,38 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "error.h"
|
|
||||||
#include "lexer.h"
|
|
||||||
#include "parser.h"
|
|
||||||
#include "pretty-printer.h"
|
|
||||||
#include "interpreter.h"
|
#include "interpreter.h"
|
||||||
#include "opcodes.h"
|
|
||||||
|
|
||||||
#include "actuators.h"
|
|
||||||
|
|
||||||
void
|
void
|
||||||
gen_bytecode ()
|
gen_bytecode ()
|
||||||
{
|
{
|
||||||
|
#ifdef __HOST
|
||||||
FILE *file = fopen (FILE_NAME, "w+b");
|
FILE *file = fopen (FILE_NAME, "w+b");
|
||||||
|
#endif
|
||||||
|
|
||||||
save_op_data(file, get_op_loop_inf (1));
|
//TODO REMOVE
|
||||||
save_op_data(file, get_op_call_1(0, LED_GREEN));
|
{
|
||||||
save_op_data(file, get_op_call_1(0, LED_BLUE));
|
save_op_data (file, get_op_loop_inf (1));
|
||||||
save_op_data(file, get_op_call_1(0, LED_ORANGE));
|
save_op_data (file, get_op_call_1 (0, 12));
|
||||||
save_op_data(file, get_op_call_1(0, LED_RED));
|
save_op_data (file, get_op_call_1 (0, 13));
|
||||||
save_op_data(file, get_op_jmp(0));
|
save_op_data (file, get_op_call_1 (0, 14));
|
||||||
|
save_op_data (file, get_op_call_1 (0, 15));
|
||||||
|
save_op_data (file, get_op_jmp (0)); // mandatory!
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef __HOST
|
||||||
fclose (file);
|
fclose (file);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
run_int ()
|
run_int ()
|
||||||
{
|
{
|
||||||
FILE *file = fopen (FILE_NAME, "rb");
|
|
||||||
OPCODE op_curr;
|
OPCODE op_curr;
|
||||||
__int_data.pos = 0;
|
__int_data.pos = 0;
|
||||||
|
|
||||||
|
#ifdef __HOST
|
||||||
|
FILE *file = fopen (FILE_NAME, "rb");
|
||||||
|
|
||||||
if (file == NULL)
|
if (file == NULL)
|
||||||
{
|
{
|
||||||
@@ -59,11 +60,12 @@ run_int ()
|
|||||||
}
|
}
|
||||||
|
|
||||||
__int_data.pos++;
|
__int_data.pos++;
|
||||||
|
|
||||||
op_curr.opfunc_ptr (op_curr);
|
op_curr.opfunc_ptr (op_curr);
|
||||||
|
|
||||||
fseek (file, __int_data.pos * sizeof (OPCODE), SEEK_SET);
|
fseek (file, __int_data.pos * sizeof (OPCODE), SEEK_SET);
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose (file);
|
fclose (file);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,20 +16,22 @@
|
|||||||
#ifndef INTERPRETER_H
|
#ifndef INTERPRETER_H
|
||||||
#define INTERPRETER_H
|
#define INTERPRETER_H
|
||||||
|
|
||||||
|
#ifdef __HOST
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "opcodes.h"
|
|
||||||
|
|
||||||
#define FILE_NAME "application.bin"
|
#define FILE_NAME "application.bin"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "opcodes.h"
|
||||||
|
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
int pos;
|
int pos;
|
||||||
|
int *root_op_addr;
|
||||||
} __int_data;
|
} __int_data;
|
||||||
|
|
||||||
|
|
||||||
void gen_bytecode ();
|
void gen_bytecode ();
|
||||||
void run_int ();
|
void run_int ();
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,88 @@
|
|||||||
|
/* 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 OPCODE_STRUCTURES_H
|
||||||
|
#define OPCODE_STRUCTURES_H
|
||||||
|
|
||||||
|
OP_DEF (nop) { };
|
||||||
|
|
||||||
|
OP_DEF (jmp)
|
||||||
|
{
|
||||||
|
OP_TYPE_IDX opcode_idx;
|
||||||
|
};
|
||||||
|
|
||||||
|
OP_DEF (decl) { };
|
||||||
|
|
||||||
|
OP_DEF (decl_func_named)
|
||||||
|
{
|
||||||
|
OP_TYPE_IDX name_literal_idx;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
OP_DEF (decl_func_anon) { };
|
||||||
|
|
||||||
|
OP_DEF (decl_var_global) { };
|
||||||
|
|
||||||
|
OP_DEF (decl_var_local) { };
|
||||||
|
|
||||||
|
/** Call with 1 argument */
|
||||||
|
OP_DEF (call_1)
|
||||||
|
{
|
||||||
|
OP_TYPE_IDX name_literal_idx;
|
||||||
|
OP_TYPE_IDX arg1_literal_idx;
|
||||||
|
};
|
||||||
|
|
||||||
|
OP_DEF (call_2)
|
||||||
|
{
|
||||||
|
OP_TYPE_IDX name_literal_idx;
|
||||||
|
OP_TYPE_IDX arg1_literal_idx;
|
||||||
|
OP_TYPE_IDX arg2_literal_idx;
|
||||||
|
};
|
||||||
|
|
||||||
|
OP_DEF (call_n) { };
|
||||||
|
|
||||||
|
OP_DEF (list_header) { };
|
||||||
|
OP_DEF (list_element) { };
|
||||||
|
OP_DEF (list_tail) { };
|
||||||
|
|
||||||
|
OP_DEF (try_begin) { };
|
||||||
|
|
||||||
|
OP_DEF (try_end) { };
|
||||||
|
|
||||||
|
OP_DEF (catch_begin) { };
|
||||||
|
|
||||||
|
OP_DEF (catch_end) { };
|
||||||
|
|
||||||
|
OP_DEF (finally_begin) { };
|
||||||
|
|
||||||
|
OP_DEF (finally_end) { };
|
||||||
|
|
||||||
|
OP_DEF (with_begin) { };
|
||||||
|
|
||||||
|
OP_DEF (with_end) { };
|
||||||
|
|
||||||
|
OP_DEF (loop_inf)
|
||||||
|
{
|
||||||
|
OP_TYPE_IDX opcode_idx;
|
||||||
|
};
|
||||||
|
|
||||||
|
OP_DEF (loop_cond_pre) { };
|
||||||
|
|
||||||
|
OP_DEF (loop_cond_post) { };
|
||||||
|
|
||||||
|
OP_DEF (swtch) { };
|
||||||
|
|
||||||
|
#endif /* OPCODE_STRUCTURES_H */
|
||||||
|
|
||||||
+25
-13
@@ -16,14 +16,33 @@
|
|||||||
#include "opcodes.h"
|
#include "opcodes.h"
|
||||||
#include "interpreter.h"
|
#include "interpreter.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
void
|
||||||
#include <stdlib.h>
|
#ifdef __HOST
|
||||||
|
save_op_data (FILE *file, OPCODE opdata)
|
||||||
|
#elif __MCU
|
||||||
|
save_op_data (OPCODE opdata)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
#ifdef __HOST
|
||||||
|
if (file == NULL)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
fwrite (&opdata, sizeof (OPCODE), 1, file);
|
||||||
|
|
||||||
|
#elif __MCU
|
||||||
|
JERRY_STATIC_ASSERT (false);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
opfunc_loop_inf (OPCODE opdata)
|
opfunc_loop_inf (OPCODE opdata)
|
||||||
{
|
{
|
||||||
|
#ifdef __HOST
|
||||||
printf ("loop_inf:idx:%d\n",
|
printf ("loop_inf:idx:%d\n",
|
||||||
opdata.data.loop_inf.opcode_idx);
|
opdata.data.loop_inf.opcode_idx);
|
||||||
|
#endif
|
||||||
|
|
||||||
__int_data.pos = opdata.data.loop_inf.opcode_idx;
|
__int_data.pos = opdata.data.loop_inf.opcode_idx;
|
||||||
}
|
}
|
||||||
@@ -31,16 +50,20 @@ opfunc_loop_inf (OPCODE opdata)
|
|||||||
void
|
void
|
||||||
opfunc_op_call_1 (OPCODE opdata)
|
opfunc_op_call_1 (OPCODE opdata)
|
||||||
{
|
{
|
||||||
|
#ifdef __HOST
|
||||||
printf ("op_call_1:idx:%d:%d\n",
|
printf ("op_call_1:idx:%d:%d\n",
|
||||||
opdata.data.call_1.name_literal_idx,
|
opdata.data.call_1.name_literal_idx,
|
||||||
opdata.data.call_1.arg1_literal_idx);
|
opdata.data.call_1.arg1_literal_idx);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
opfunc_op_jmp (OPCODE opdata)
|
opfunc_op_jmp (OPCODE opdata)
|
||||||
{
|
{
|
||||||
|
#ifdef __HOST
|
||||||
printf ("op_jmp:idx:%d\n",
|
printf ("op_jmp:idx:%d\n",
|
||||||
opdata.data.jmp.opcode_idx);
|
opdata.data.jmp.opcode_idx);
|
||||||
|
#endif
|
||||||
|
|
||||||
__int_data.pos = opdata.data.jmp.opcode_idx;
|
__int_data.pos = opdata.data.jmp.opcode_idx;
|
||||||
}
|
}
|
||||||
@@ -78,14 +101,3 @@ get_op_loop_inf (int arg1)
|
|||||||
|
|
||||||
return opdata;
|
return opdata;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
save_op_data (FILE *file, OPCODE opdata)
|
|
||||||
{
|
|
||||||
if (file == NULL)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
fwrite (&opdata, sizeof (OPCODE), 1, file);
|
|
||||||
}
|
|
||||||
@@ -16,7 +16,9 @@
|
|||||||
#ifndef OPCODES_H
|
#ifndef OPCODES_H
|
||||||
#define OPCODES_H
|
#define OPCODES_H
|
||||||
|
|
||||||
|
#ifdef __HOST
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "globals.h"
|
#include "globals.h"
|
||||||
|
|
||||||
@@ -30,77 +32,8 @@ OPCODE;
|
|||||||
|
|
||||||
typedef void (*opfunc)(OPCODE);
|
typedef void (*opfunc)(OPCODE);
|
||||||
|
|
||||||
OP_DEF (nop) { };
|
#include "opcode-structures.h"
|
||||||
|
|
||||||
OP_DEF (jmp)
|
|
||||||
{
|
|
||||||
OP_TYPE_IDX opcode_idx;
|
|
||||||
};
|
|
||||||
|
|
||||||
OP_DEF (decl) { };
|
|
||||||
|
|
||||||
OP_DEF (decl_func_named)
|
|
||||||
{
|
|
||||||
OP_TYPE_IDX name_literal_idx;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
OP_DEF (decl_func_anon) { };
|
|
||||||
|
|
||||||
OP_DEF (decl_var_global) { };
|
|
||||||
|
|
||||||
OP_DEF (decl_var_local) { };
|
|
||||||
|
|
||||||
/** Call with 1 argument */
|
|
||||||
OP_DEF (call_1)
|
|
||||||
{
|
|
||||||
OP_TYPE_IDX name_literal_idx;
|
|
||||||
OP_TYPE_IDX arg1_literal_idx;
|
|
||||||
};
|
|
||||||
|
|
||||||
OP_DEF (call_2)
|
|
||||||
{
|
|
||||||
OP_TYPE_IDX name_literal_idx;
|
|
||||||
OP_TYPE_IDX arg1_literal_idx;
|
|
||||||
OP_TYPE_IDX arg2_literal_idx;
|
|
||||||
};
|
|
||||||
|
|
||||||
OP_DEF (call_n) { };
|
|
||||||
|
|
||||||
OP_DEF (list_header) { };
|
|
||||||
|
|
||||||
OP_DEF (list_element) { };
|
|
||||||
|
|
||||||
OP_DEF (list_tail) { };
|
|
||||||
|
|
||||||
OP_DEF (try_begin) { };
|
|
||||||
|
|
||||||
OP_DEF (try_end) { };
|
|
||||||
|
|
||||||
OP_DEF (catch_begin) { };
|
|
||||||
|
|
||||||
OP_DEF (catch_end) { };
|
|
||||||
|
|
||||||
OP_DEF (finally_begin) { };
|
|
||||||
|
|
||||||
OP_DEF (finally_end) { };
|
|
||||||
|
|
||||||
OP_DEF (with_begin) { };
|
|
||||||
|
|
||||||
OP_DEF (with_end) { };
|
|
||||||
|
|
||||||
OP_DEF (loop_inf)
|
|
||||||
{
|
|
||||||
OP_TYPE_IDX opcode_idx;
|
|
||||||
};
|
|
||||||
|
|
||||||
OP_DEF (loop_cond_pre) { };
|
|
||||||
|
|
||||||
OP_DEF (loop_cond_post) { };
|
|
||||||
|
|
||||||
OP_DEF (swtch) { };
|
|
||||||
|
|
||||||
/** OPCODES */
|
|
||||||
union __opdata
|
union __opdata
|
||||||
{
|
{
|
||||||
OP (loop_inf);
|
OP (loop_inf);
|
||||||
@@ -118,8 +51,12 @@ OPCODE{
|
|||||||
}
|
}
|
||||||
__packed;
|
__packed;
|
||||||
|
|
||||||
|
#ifdef __HOST
|
||||||
|
void save_op_data (FILE*, OPCODE);
|
||||||
|
#elif __MCU
|
||||||
|
void save_op_data (OPCODE);
|
||||||
|
#endif
|
||||||
|
|
||||||
void save_op_data (FILE *, OPCODE);
|
|
||||||
|
|
||||||
OPCODE get_op_loop_inf (int);
|
OPCODE get_op_loop_inf (int);
|
||||||
OPCODE get_op_call_1 (int, int);
|
OPCODE get_op_call_1 (int, int);
|
||||||
|
|||||||
+1
-1
@@ -73,7 +73,7 @@ main (int argc, char **argv)
|
|||||||
|
|
||||||
//gen_bytecode (generated_source);
|
//gen_bytecode (generated_source);
|
||||||
gen_bytecode (file);
|
gen_bytecode (file);
|
||||||
run_int ();
|
// run_int ();
|
||||||
|
|
||||||
#ifdef __TARGET_MCU
|
#ifdef __TARGET_MCU
|
||||||
fake_exit ();
|
fake_exit ();
|
||||||
|
|||||||
Reference in New Issue
Block a user