fixed Makefile and tests, wrapped interpreter and opcodes

This commit is contained in:
e.gavrin 2014-07-04 21:34:44 +04:00
parent 7759e4b99f
commit aace544c55
7 changed files with 170 additions and 112 deletions

View File

@ -15,6 +15,7 @@
TARGET ?= jerry
CROSS_COMPILE ?= arm-none-eabi-
OBJ_DIR = obj
OUT_DIR = ./out
SOURCES = \
$(sort \
@ -51,6 +52,7 @@ LD = ld
OBJDUMP = objdump
OBJCOPY = objcopy
SIZE = size
STRIP = strip
CROSS_CC = $(CROSS_COMPILE)gcc-4.9
CROSS_LD = $(CROSS_COMPILE)ld
@ -71,35 +73,50 @@ CFLAGS ?= $(INCLUDES) -std=c99 -m32 -fdiagnostics-color=always
#CFLAGS += -ffunction-sections -fdata-sections
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
TARGET_HOST = -D__HOST
TARGET_MCU = -D__MCU
.PHONY: all debug release clean check install
all: debug
all: clean debug release check
debug:
$(CC) $(INCLUDES) $(CFLAGS) $(DEBUG_OPTIONS) $(DEFINES) $(SOURCES) \
-o $(TARGET)
mkdir -p $(OUT_DIR)/debug.host/
$(CC) $(CFLAGS) $(DEBUG_OPTIONS) $(DEFINES) $(TARGET_HOST) \
$(SOURCES) -o $(OUT_DIR)/debug.host/$(TARGET)
release:
$(CC) $(INCLUDES) $(CFLAGS) $(RELEASE_OPTIONS) $(DEFINES) $(SOURCES) \
-o $(TARGET)
mkdir -p $(OUT_DIR)/release.host/
$(CC) $(CFLAGS) $(RELEASE_OPTIONS) $(DEFINES) $(TARGET_HOST) \
$(SOURCES) -o $(OUT_DIR)/release.host/$(TARGET)
$(STRIP) $(OUT_DIR)/release.host/$(TARGET)
clean:
rm -f $(OBJ_DIR)/*.o *.bin *.o *~ *.log *.log
rm -rf $(OUT_DIR)
rm -f $(TARGET)
rm -f $(TARGET).elf
rm -f $(TARGET).bin
rm -f $(TARGET).map
rm -f $(TARGET).hex
rm -f $(TARGET).lst
rm -f jerry.error js.files
check:
mkdir -p $(OUT_DIR)
cd $(OUT_DIR)
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:
st-flash write $(TARGET).bin 0x08000000

View File

@ -13,37 +13,38 @@
* limitations under the License.
*/
#include "error.h"
#include "lexer.h"
#include "parser.h"
#include "pretty-printer.h"
#include "interpreter.h"
#include "opcodes.h"
#include "actuators.h"
void
gen_bytecode ()
{
#ifdef __HOST
FILE *file = fopen (FILE_NAME, "w+b");
#endif
save_op_data(file, get_op_loop_inf (1));
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_call_1(0, LED_ORANGE));
save_op_data(file, get_op_call_1(0, LED_RED));
save_op_data(file, get_op_jmp(0));
//TODO REMOVE
{
save_op_data (file, get_op_loop_inf (1));
save_op_data (file, get_op_call_1 (0, 12));
save_op_data (file, get_op_call_1 (0, 13));
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);
#endif
}
void
run_int ()
{
FILE *file = fopen (FILE_NAME, "rb");
OPCODE op_curr;
__int_data.pos = 0;
#ifdef __HOST
FILE *file = fopen (FILE_NAME, "rb");
if (file == NULL)
{
@ -59,11 +60,12 @@ run_int ()
}
__int_data.pos++;
op_curr.opfunc_ptr (op_curr);
fseek (file, __int_data.pos * sizeof (OPCODE), SEEK_SET);
}
fclose (file);
#endif
}

View File

@ -16,20 +16,22 @@
#ifndef INTERPRETER_H
#define INTERPRETER_H
#ifdef __HOST
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "opcodes.h"
#define FILE_NAME "application.bin"
#endif
#include "opcodes.h"
struct
{
int pos;
int *root_op_addr;
} __int_data;
void gen_bytecode ();
void run_int ();

View File

@ -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 */

View File

@ -16,14 +16,33 @@
#include "opcodes.h"
#include "interpreter.h"
#include <stdio.h>
#include <stdlib.h>
void
#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
opfunc_loop_inf (OPCODE opdata)
{
#ifdef __HOST
printf ("loop_inf:idx:%d\n",
opdata.data.loop_inf.opcode_idx);
#endif
__int_data.pos = opdata.data.loop_inf.opcode_idx;
}
@ -31,16 +50,20 @@ opfunc_loop_inf (OPCODE opdata)
void
opfunc_op_call_1 (OPCODE opdata)
{
#ifdef __HOST
printf ("op_call_1:idx:%d:%d\n",
opdata.data.call_1.name_literal_idx,
opdata.data.call_1.arg1_literal_idx);
#endif
}
void
opfunc_op_jmp (OPCODE opdata)
{
#ifdef __HOST
printf ("op_jmp:idx:%d\n",
opdata.data.jmp.opcode_idx);
#endif
__int_data.pos = opdata.data.jmp.opcode_idx;
}
@ -78,14 +101,3 @@ get_op_loop_inf (int arg1)
return opdata;
}
void
save_op_data (FILE *file, OPCODE opdata)
{
if (file == NULL)
{
return;
}
fwrite (&opdata, sizeof (OPCODE), 1, file);
}

View File

@ -16,7 +16,9 @@
#ifndef OPCODES_H
#define OPCODES_H
#ifdef __HOST
#include <stdio.h>
#endif
#include "globals.h"
@ -30,77 +32,8 @@ 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
{
OP (loop_inf);
@ -118,8 +51,12 @@ OPCODE{
}
__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_call_1 (int, int);

View File

@ -73,7 +73,7 @@ main (int argc, char **argv)
//gen_bytecode (generated_source);
gen_bytecode (file);
run_int ();
// run_int ();
#ifdef __TARGET_MCU
fake_exit ();