manualy generated blinky opcodes

This commit is contained in:
e.gavrin committed 2014-07-03 16:23:25 +04:00
1 parent 1c4873f4b6
commit 3fde3400f4
33 files changed
+186 -102

No files matched your search

+23 -11
View File
@@ -13,29 +13,41 @@
# limitations under the License. # limitations under the License.
TARGET ?= jerry TARGET ?= jerry
#CROSS_COMPILE ?= arm-none-eabi- CROSS_COMPILE ?= arm-none-eabi-
OBJ_DIR = obj OBJ_DIR = obj
SOURCES = \ SOURCES = \
$(sort \ $(sort \
$(wildcard ./src/*.c)\ $(wildcard ./src/*.c) \
$(wildcard ./src/libperipherals/*.c)\ $(wildcard ./src/libperipherals/*.c) \
$(wildcard ./src/libcoreint/*.c)) $(wildcard ./src/libjsparser/*.c) \
$(wildcard ./src/libecmaobjects/*.c) \
$(wildcard ./src/liballocator/*.c) \
$(wildcard ./src/libcoreint/*.c) )
INCLUDES = \ INCLUDES = \
-I src \ -I src \
-I src/libperipherals \ -I src/libperipherals \
-I src/libjsparser \
-I src/libecmaobjects \
-I src/liballocator \
-I src/libcoreint -I src/libcoreint
OBJS = \ OBJS = \
$(sort \ $(sort \
$(patsubst %.c,./$(OBJ_DIR)/%.o,$(notdir $(SOURCES)))) $(patsubst %.c,./$(OBJ_DIR)/%.o,$(notdir $(SOURCES))))
CC = $(CROSS_COMPILE)gcc-4.9 CC = gcc-4.9
LD = $(CROSS_COMPILE)ld LD = ld
OBJDUMP = $(CROSS_COMPILE)objdump OBJDUMP = objdump
OBJCOPY = $(CROSS_COMPILE)objcopy OBJCOPY = objcopy
SIZE = $(CROSS_COMPILE)size 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 # General flags
CFLAGS ?= $(INCLUDES) -std=c99 -m32 -fdiagnostics-color=always 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 += -mfpu=fpv4-sp-d16 -mfloat-abi=hard
#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
DEFINES = -DMEM_HEAP_CHUNK_SIZE=256 -DMEM_HEAP_AREA_SIZE=32768 DEFINES = -DMEM_HEAP_CHUNK_SIZE=256 -DMEM_HEAP_AREA_SIZE=32768
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
+18 -26
View File
@@ -18,21 +18,9 @@
#include "parser.h" #include "parser.h"
#include "pretty-printer.h" #include "pretty-printer.h"
#include "interpreter.h" #include "interpreter.h"
#include "opcode.h" #include "opcodes.h"
#include "actuators.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);
}
}
void void
gen_bytecode (FILE *src_file) gen_bytecode (FILE *src_file)
@@ -51,14 +39,15 @@ gen_bytecode (FILE *src_file)
pp_finish (); pp_finish ();
FILE *file = fopen (FILE_NAME, "w+b"); FILE *file = fopen (FILE_NAME, "w+b");
int i;
union __opcodes op0;
for (i = 0; i <= 10; i++)
{ save_op_loop_inf (file, op0, 1);
safe_opcode (file, control_op, i, i); save_op_call_1 (file, op0, 0, LED_GREEN);
safe_opcode (file, decl_op, i, i); save_op_call_1 (file, op0, 0, LED_BLUE);
safe_opcode (file, call_op, i, i); 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); fclose (file);
} }
@@ -67,6 +56,7 @@ void
run_int () run_int ()
{ {
FILE *file = fopen (FILE_NAME, "rb"); FILE *file = fopen (FILE_NAME, "rb");
union __opcodes op_curr;
if (file == NULL) if (file == NULL)
{ {
@@ -76,10 +66,12 @@ run_int ()
while (!feof (file)) while (!feof (file))
{ {
fread (&curr_opcode, sizeof (struct opcode_packed), 1, file); if (!fread (&op_curr, sizeof (union __opcodes), 1, file))
{
//printf ("read %d, %d, %p\n", curr_opcode.arg1, curr_opcode.arg2, curr_opcode.func); break;
curr_opcode.func (curr_opcode.arg1, curr_opcode.arg2); }
op_curr.opfunc_ptr (op_curr);
} }
fclose (file); fclose (file);
+1 -9
View File
@@ -13,13 +13,6 @@
* limitations under the License. * limitations under the License.
*/ */
/*
* File: interpreter.h
* Author: egavrin
*
* Created on July 2, 2014, 3:10 PM
*/
#ifndef INTERPRETER_H #ifndef INTERPRETER_H
#define INTERPRETER_H #define INTERPRETER_H
@@ -27,11 +20,10 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "opcode.h" #include "opcodes.h"
#define FILE_NAME "application.bin" #define FILE_NAME "application.bin"
void safe_opcode(FILE *, opcode_ptr, int, int);
void gen_bytecode(FILE*); void gen_bytecode(FILE*);
void run_int(); void run_int();
+84 -7
View File
@@ -13,21 +13,98 @@
* limitations under the License. * limitations under the License.
*/ */
#include "opcode.h" #include "opcodes.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
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);
} }
+34 -28
View File
@@ -13,43 +13,49 @@
* limitations under the License. * limitations under the License.
*/ */
/* #ifndef OPCODES_H
* File: opcode.h #define OPCODES_H
* Author: egavrin
*
* Created on July 2, 2014, 3:12 PM
*/
#ifndef OPCODE_H #include "stdio.h"
#define OPCODE_H
#define OP_RET_TYPE void #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 union __opcodes;
#define OP_ATTR_DEF OP_ARG_TYPE arg1, OP_ARG_TYPE arg2
#define OP_DECLARATION(opname) OP_RET_TYPE opname (OP_ATTR_DECL) typedef OP_RET_TYPE (*op_proxy_ptr)(union __opcodes);
#define OP_DEFINITION(opname) OP_RET_TYPE opname (OP_ATTR_DEF)
// opcode ptr typedef OP_RET_TYPE (*opfunc_int_ptr)(union __opcodes);
typedef OP_RET_TYPE (*opcode_ptr)(OP_ATTR_DECL); typedef OP_RET_TYPE (*opfunc_int_int_ptr)(union __opcodes);
struct union __opcodes
__attribute__ ((__packed__))
opcode_packed
{ {
opcode_ptr func; op_proxy_ptr opfunc_ptr;
OP_ARG_TYPE arg1;
OP_ARG_TYPE arg2; struct __op_loop_inf
} {
curr_opcode; 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); struct __op_jmp
OP_DECLARATION (call_op); {
OP_DECLARATION (control_op); 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 */
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
+17
View File
@@ -13,4 +13,21 @@
* limitations under the License. * limitations under the License.
*/ */
#include <stdio.h>
#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);
}
+9 -7
View File
@@ -13,16 +13,18 @@
* limitations under the License. * limitations under the License.
*/ */
/*
* File: actuators.h
* Author: egavrin
*
* Created on July 2, 2014, 2:06 PM
*/
#ifndef ACTUATORS_H #ifndef ACTUATORS_H
#define 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 */ #endif /* ACTUATORS_H */
-7
View File
@@ -13,13 +13,6 @@
* limitations under the License. * limitations under the License.
*/ */
/*
* File: common-io.h
* Author: egavrin
*
* Created on July 2, 2014, 2:14 PM
*/
#ifndef COMMON_IO_H #ifndef COMMON_IO_H
#define COMMON_IO_H #define COMMON_IO_H
-7
View File
@@ -13,13 +13,6 @@
* limitations under the License. * limitations under the License.
*/ */
/*
* File: sensors.h
* Author: egavrin
*
* Created on July 2, 2014, 2:05 PM
*/
#ifndef SENSORS_H #ifndef SENSORS_H
#define SENSORS_H #define SENSORS_H