mirror of
https://github.com/jerryscript-project/jerryscript.git
synced 2025-12-15 16:29:21 +00:00
Added target to compile zephyr against jerryscript.
This patch contains a project in which you can run a small js test inside the Arduino101. Follows the Nuttx implementation to replicate a command line in the Quark SE Lakemont architecture. Everything is self contained in the targets/arduino_101 folder. It has only been tested with the arduino 101 at the moment. Check the README.md for a more detailed explanation of how to compile and run it. - Command line javascript run test. Use test to get a default test. Write any valid javascript in the shell and get it resolved and executed - Support for qemu - Added extra verbose mode on the demo function - Support to build factory images that can be flashed with dfu-util - Added a few extra examples on the README about commands that work. Small fixes to readme and libc_support.c (#1) - Added a few more instructions to the README.md for arduino_101 - Added the stdint.h include in libc_support.c - Added parameter to check-vera.sh to check a specific folder - Cleared the libc function duplication JerryScript-DCO-1.0-Signed-off-by: Sergio Martinez sergio.martinez.rodriguez@intel.com
This commit is contained in:
parent
308bb3c8e1
commit
7583b63a6e
57
targets/arduino_101/Makefile
Normal file
57
targets/arduino_101/Makefile
Normal file
@ -0,0 +1,57 @@
|
||||
# Copyright © 2016 Intel Corporation
|
||||
#
|
||||
# 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.
|
||||
|
||||
# use TAB-8
|
||||
.DEFAULT_GOAL := all
|
||||
|
||||
ifndef ZEPHYR_BASE
|
||||
$(error Missing zephyr base)
|
||||
endif
|
||||
|
||||
# For testing without real hardware use qemu_x86 instead of arduino_101
|
||||
BOARD ?= arduino_101
|
||||
|
||||
O ?= $(PROJECT_BASE)/outdir
|
||||
|
||||
ZEPHYR ?= $(ZEPHYR_BASE)
|
||||
TYPE ?= release
|
||||
JERRYHEAP ?= 16
|
||||
|
||||
ZEPHYRINC = $(ZEPHYR_BASE)/include
|
||||
ZEPHYRLIB = $(ZEPHYR_BASE)/lib
|
||||
|
||||
SOURCE_DIR = ./targets/arduino_101/src
|
||||
|
||||
export JERRY_INCLUDE = $(CURDIR)/jerry-core/
|
||||
|
||||
MDEF_FILE = $(realpath $(SOURCE_DIR)/../prj.mdef)
|
||||
CONF_FILE = $(realpath $(SOURCE_DIR)/../prj.conf)
|
||||
|
||||
ifdef V
|
||||
$(info Zephyr)
|
||||
$(info SOURCE_DIR=$(SOURCE_DIR))
|
||||
$(info JERRY_INCLUDE=$(JERRY_INCLUDE))
|
||||
$(info CONF_FILE =$(CONF_FILE))
|
||||
endif
|
||||
|
||||
KERNEL_TYPE = micro
|
||||
|
||||
KBUILD_VERBOSE = $(V)
|
||||
|
||||
APP = main-zephyr.c
|
||||
|
||||
include ${ZEPHYR_BASE}/Makefile.inc
|
||||
|
||||
.PHONY = showconfig
|
||||
|
||||
183
targets/arduino_101/Makefile.arduino_101
Normal file
183
targets/arduino_101/Makefile.arduino_101
Normal file
@ -0,0 +1,183 @@
|
||||
# Copyright © 2016 Intel Corporation
|
||||
#
|
||||
# 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.
|
||||
|
||||
.DEFAULT_GOAL := all
|
||||
|
||||
ifeq ($(.DEFAULT_GOAL),)
|
||||
$(warning no default goal is set)
|
||||
endif
|
||||
|
||||
ifeq ($(MAKECMDGOALS),qemu)
|
||||
BOARD ?= qemu_x86
|
||||
else
|
||||
BOARD ?= arduino_101
|
||||
BOARD_NAME ?= arduino_101
|
||||
endif
|
||||
|
||||
ifeq ($(BOARD),qemu_x86)
|
||||
BOARD_NAME ?= qemu_x86
|
||||
endif
|
||||
|
||||
TYPE ?= release
|
||||
JERRYHEAP ?= 16
|
||||
|
||||
# Include functionality like regular expressions
|
||||
# check Jerry script documentation
|
||||
#
|
||||
# -cp
|
||||
# -cp_minimal
|
||||
# -cp_minimal-mem_stats
|
||||
# -mem_stats
|
||||
# -mem_stress_test
|
||||
|
||||
ifndef ZEPHYR_BASE
|
||||
$(error Missing Zephyr base, did you source zephyr-env.sh? )
|
||||
endif
|
||||
|
||||
VARIETY ?= -cp_minimal
|
||||
|
||||
INTERM = build/$(BOARD)/obj-$(BOARD)
|
||||
OUTPUT = build/$(BOARD)
|
||||
|
||||
CC = $(CROSS_COMPILE)gcc
|
||||
|
||||
EXT_CFLAGS := -fno-asynchronous-unwind-tables -fno-omit-frame-pointer
|
||||
EXT_CFLAGS += -fno-stack-protector -fno-strict-overflow -ffreestanding
|
||||
EXT_CFLAGS += -fno-reorder-functions -fno-defer-pop -fdata-sections
|
||||
EXT_CFLAGS += -ffunction-sections -fno-inline-functions
|
||||
|
||||
# TODO @sergioamr Read the arch and cflags from zephyr
|
||||
|
||||
ifeq ($(BOARD),qemu_x86)
|
||||
CONFIG_TOOLCHAIN_VARIANT = x86
|
||||
EXT_CFLAGS += -march=pentium
|
||||
else
|
||||
CONFIG_TOOLCHAIN_VARIANT = iamcu
|
||||
EXT_CFLAGS += -march=lakemont -mtune=lakemont -miamcu -msoft-float
|
||||
endif
|
||||
|
||||
EXT_CFLAGS += -mpreferred-stack-boundary=2 -mno-sse
|
||||
|
||||
EXT_CFLAGS += -Wall -Wno-format-zero-length -Wno-pointer-sign
|
||||
EXT_CFLAGS += -Werror=format -Werror=implicit-int -Wno-unused-but-set-variable
|
||||
EXT_CFLAGS += -Wno-main -Wno-strict-aliasing
|
||||
EXT_CFLAGS += -Wno-error=format=
|
||||
|
||||
EXT_CFLAGS += $(TOOLCHAIN_CFLAGS)
|
||||
EXT_CFLAGS += $(LIB_INCLUDE_DIR)
|
||||
EXT_CFLAGS += -nostdinc -isystem $(shell $(CC) -print-file-name=include)
|
||||
EXT_CFLAGS += -isystem $(shell $(CC) -print-file-name=include-fixed)
|
||||
|
||||
-include $(ZEPHYR_BASE)/boards/$(BOARD_NAME)/Makefile.board
|
||||
-include $(ZEPHYR_BASE)/scripts/Makefile.toolchain.$(ZEPHYR_GCC_VARIANT)
|
||||
|
||||
ZEPHYR_LIBC_INC = $(subst -I,,$(TOOLCHAIN_CFLAGS))
|
||||
LIB_INCLUDE_DIR += -L $(CURDIR)/$(OUTPUT)
|
||||
|
||||
EXTERNAL_LIB = $(INTERM)/lib$(TYPE).external$(VARIETY)-entry.a
|
||||
ZEPHYR_BIN = $(OUTPUT)/zephyr/zephyr.strip
|
||||
|
||||
PREFIX = $(TYPE)$(VARIETY)
|
||||
LIBS = $(TYPE).external$(VARIETY)-entry $(PREFIX).jerry-core $(PREFIX).jerry-libm.lib $(TOOLCHAIN_LIBS) c
|
||||
|
||||
# TODO @sergioamr Change how we link the library to USER_LDFLAGS
|
||||
# https://gerrit.zephyrproject.org/r/#/c/2048/
|
||||
|
||||
BUILD_CONFIG = O="$(OUTPUT)/zephyr" V=$(V) TOOLCHAIN_LIBS="$(LIBS)" LIB_INCLUDE_DIR="$(LIB_INCLUDE_DIR)"
|
||||
|
||||
.PHONY: all
|
||||
all: jerry zephyr
|
||||
|
||||
$(EXTERNAL_LIB):
|
||||
ifdef V
|
||||
@echo "- JERRY SCRIPT -------------------------------------------------"
|
||||
endif
|
||||
mkdir -p $(INTERM)
|
||||
mkdir -p $(OUTPUT)
|
||||
cmake -B$(INTERM) -H./ \
|
||||
-DENABLE_LTO=OFF \
|
||||
-DENABLE_VALGRIND=OFF \
|
||||
-DCMAKE_BUILD_TYPE=Release \
|
||||
-DCMAKE_VERBOSE_MAKEFILE=$(V) \
|
||||
-DEXTERNAL_CMAKE_C_COMPILER=$(CC) \
|
||||
-DEXTERNAL_CMAKE_C_COMPILER_ID=GNU \
|
||||
-DEXTERNAL_CMAKE_SYSTEM_PROCESSOR=x86 \
|
||||
-DEXTERNAL_MEM_HEAP_SIZE_KB=$(JERRYHEAP) \
|
||||
-DEXTERNAL_COMPILE_FLAGS="$(EXT_CFLAGS)" \
|
||||
-DEXTERNAL_CMAKE_SYSTEM_PROCESSOR=lakemont \
|
||||
-DEXTERNAL_LIBC_INTERFACE="$(ZEPHYR_LIBC_INC)" \
|
||||
-DCMAKE_TOOLCHAIN_FILE=build/configs/toolchain_external.cmake \
|
||||
-DEXTERNAL_BUILD_ENTRY_FILE=./targets/arduino_101/src/jerry-entry.c
|
||||
|
||||
make -C $(INTERM) $(TYPE).external$(VARIETY) V=1
|
||||
cp `cat $(INTERM)/$(TYPE).external$(VARIETY)/list` $(OUTPUT)/.
|
||||
cp $(EXTERNAL_LIB) $(OUTPUT)/.
|
||||
|
||||
$(ZEPHYR_BIN):
|
||||
ifdef V
|
||||
@echo "- ZEPHYR -------------------------------------------------------"
|
||||
endif
|
||||
make -f ./targets/arduino_101/Makefile $(BUILD_CONFIG)
|
||||
@echo "Finished"
|
||||
@file $(OUTPUT)/zephyr/zephyr.strip
|
||||
@size $(OUTPUT)/zephyr/zephyr.strip
|
||||
|
||||
jerry: $(EXTERNAL_LIB)
|
||||
@touch $(EXTERNAL_LIB)
|
||||
|
||||
zephyr: $(EXTERNAL_LIB) $(ZEPHYR_BIN)
|
||||
@touch $(ZEPHYR_BIN)
|
||||
|
||||
qemu: $(EXTERNAL_LIB) $(ZEPHYR_BIN)
|
||||
make -f ./targets/arduino_101/Makefile $(BUILD_CONFIG) qemu
|
||||
|
||||
flash: $(EXTERNAL_LIB) $(OUTPUT)/zephyr/zephyr.strip
|
||||
make -f ./targets/arduino_101/Makefile $(BUILD_CONFIG) flash
|
||||
|
||||
usage:
|
||||
help:
|
||||
@echo Usage:
|
||||
@echo showconfig Show parameters and configuration
|
||||
@echo flash Flash into board
|
||||
@echo all Compile jerryscript and zephyr
|
||||
|
||||
showconfig:
|
||||
@echo "- CONFIGURATION ------------------------------------------------"
|
||||
@echo "INTERM = $(INTERM)"
|
||||
@echo "OUTPUT = $(OUTPUT)"
|
||||
@echo "CC = $(CC) "
|
||||
@echo "BOARD = $(ZEPHYR_BASE)/boards/$(BOARD)/Makefile.board "
|
||||
@echo "TOOLCHAIN = $(ZEPHYR_BASE)/scripts/Makefile.toolchain.$(ZEPHYR_GCC_VARIANT) "
|
||||
@echo "TOOLCHAIN_CFLAGS = $(TOOLCHAIN_CFLAGS) "
|
||||
@echo "CROSS_COMPILE = $(CROSS_COMPILE) "
|
||||
@echo "TOOLCHAIN_LIBS = $(TOOLCHAIN_LIBS) "
|
||||
@echo "LIBS = $(LIBS) "
|
||||
@echo "LIB_INCLUDE_DIR = $(LIB_INCLUDE_DIR) "
|
||||
@echo "BUILD_CONFIG = $(BUILD_CONFIG) "
|
||||
make -f ./targets/arduino_101/Makefile $(BUILD_CONFIG) showconfig
|
||||
|
||||
# TODO @sergioamr Temporal cleanup before finding why Zephyr is ignoring my
|
||||
# outdir for the project
|
||||
clean:
|
||||
@echo "Clearing Jerryscript"
|
||||
@rm -rf $(OUTPUT)
|
||||
@rm -rf $(INTERM)
|
||||
@rm -f ./targets/arduino_101/src/.*.o.cmd
|
||||
@rm -f ./targets/arduino_101/src/*.o
|
||||
@echo "Clearing Zephyr"
|
||||
make -f ./targets/arduino_101/Makefile clean
|
||||
make -f ./targets/arduino_101/Makefile pristine
|
||||
|
||||
mrproper:
|
||||
make -f ./targets/arduino_101/Makefile mrproper
|
||||
140
targets/arduino_101/README.md
Normal file
140
targets/arduino_101/README.md
Normal file
@ -0,0 +1,140 @@
|
||||
### About
|
||||
|
||||
This folder contains files to run JerryScript on Zephyr with
|
||||
[Arduino 101 / Genuino 101](https://www.arduino.cc/en/Main/ArduinoBoard101)
|
||||
|
||||
Zephyr project arduino 101
|
||||
[Zephyr Arduino 101](https://www.zephyrproject.org/doc/board/arduino_101.html)
|
||||
|
||||
### How to build
|
||||
|
||||
#### 1. Preface
|
||||
|
||||
1, Directory structure
|
||||
|
||||
Assume `harmony` as the path to the projects to build.
|
||||
The folder tree related would look like this.
|
||||
|
||||
```
|
||||
harmony
|
||||
+ jerry
|
||||
| + targets
|
||||
| + arduino_101
|
||||
+ zephyr
|
||||
```
|
||||
|
||||
|
||||
2, Target board
|
||||
|
||||
Assume [Arduino 101 / Genuino 101](https://www.arduino.cc/en/Main/ArduinoBoard101)
|
||||
as the target board.
|
||||
|
||||
|
||||
#### 2. Prepare Zephyr
|
||||
|
||||
Follow [this](https://www.zephyrproject.org/doc/getting_started/getting_started.html) page to get
|
||||
the Zephyr source and configure the environment.
|
||||
|
||||
Follow "Building a Sample Application" and check that you can flash the Arduino 101
|
||||
|
||||
Remember to source the zephyr environment.
|
||||
|
||||
```
|
||||
source zephyr-env.sh
|
||||
|
||||
export ZEPHYR_GCC_VARIANT=zephyr
|
||||
|
||||
export ZEPHYR_SDK_INSTALL_DIR=<sdk installation directory>
|
||||
```
|
||||
|
||||
#### 3. Build JerryScript for Zephyr
|
||||
|
||||
```
|
||||
# assume you are in harmony folder
|
||||
cd jerry
|
||||
make -f ./targets/arduino_101/Makefile.arduino_101
|
||||
```
|
||||
|
||||
This will generate the following libraries:
|
||||
```
|
||||
./build/arduino_101/librelease-cp_minimal.jerry-core.a
|
||||
./build/arduino_101/librelease-cp_minimal.jerry-libm.lib.a
|
||||
./build/arduino_101/librelease.external-cp_minimal-entry.a
|
||||
```
|
||||
|
||||
The final Zephyr image will be located here:
|
||||
```
|
||||
./build/arduino_101/zephyr/zephyr.strip
|
||||
```
|
||||
|
||||
#### 5. Flashing
|
||||
|
||||
Details on how to flash the image can be found here:
|
||||
[Flashing image](https://www.zephyrproject.org/doc/board/arduino_101.html)
|
||||
|
||||
To be able to use this demo in hardware you will need the serial console
|
||||
which will be generating output to Pins 0 & 1
|
||||
|
||||
Some examples of building the software
|
||||
|
||||
```
|
||||
make -f ./targets/arduino_101/Makefile.arduino_101 clean
|
||||
```
|
||||
|
||||
- Not using a Jtag and having a factory stock Arduino 101.
|
||||
|
||||
```
|
||||
make -f ./targets/arduino_101/Makefile.arduino_101 BOARD=arduino_101_factory
|
||||
```
|
||||
|
||||
Follow the Zephyr instructions to flash using the dfu-util command.
|
||||
|
||||
|
||||
- Using JTAG
|
||||
|
||||
There is a helper function to flash using the JTAG and Flywatter2
|
||||
|
||||

|
||||
```
|
||||
make -f ./targets/arduino_101/Makefile.arduino_101 BOARD=arduino_101 flash
|
||||
|
||||
```
|
||||
|
||||
- Compiling and running with the emulator
|
||||
```
|
||||
make -f ./targets/arduino_101/Makefile.arduino_101 BOARD=qemu_x86 qemu
|
||||
```
|
||||
|
||||
|
||||
#### 6. Serial terminal
|
||||
|
||||
Test command line in a serial terminal.
|
||||
|
||||
|
||||
You should see something similar to this:
|
||||
```
|
||||
Jerry Compilation May 26 2016 13:37:50
|
||||
js>
|
||||
```
|
||||
|
||||
|
||||
Run the example javascript command test function
|
||||
```
|
||||
js> test
|
||||
Script [var test=0; for (t=100; t<1000; t++) test+=t; print ('Hi JS World! '+test);]
|
||||
Hi JS World! 494550
|
||||
```
|
||||
|
||||
|
||||
Try more complex functions:
|
||||
```
|
||||
js>function hello(t){t=t*10;return t}; print("result"+hello(10.5));
|
||||
```
|
||||
|
||||
|
||||
Help will provide a list of commands
|
||||
```
|
||||
> help
|
||||
```
|
||||
|
||||
This program, is built in top of the Zephyr command line, so there is a limit of 10 spaces.
|
||||
BIN
targets/arduino_101/docs/arduino_101.jpg
Normal file
BIN
targets/arduino_101/docs/arduino_101.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 22 KiB |
7
targets/arduino_101/prj.conf
Normal file
7
targets/arduino_101/prj.conf
Normal file
@ -0,0 +1,7 @@
|
||||
CONFIG_STDOUT_CONSOLE=y
|
||||
CONFIG_NEWLIB_LIBC=y
|
||||
CONFIG_FLOAT=y
|
||||
CONFIG_CONSOLE_HANDLER=y
|
||||
CONFIG_CONSOLE_HANDLER_SHELL=y
|
||||
|
||||
|
||||
5
targets/arduino_101/prj.mdef
Normal file
5
targets/arduino_101/prj.mdef
Normal file
@ -0,0 +1,5 @@
|
||||
% Application : JerryScript Sample
|
||||
|
||||
% TASK NAME PRIO ENTRY STACK GROUPS
|
||||
% ==================================
|
||||
TASK TASKA 7 main 2048 [EXE]
|
||||
22
targets/arduino_101/src/Makefile
Executable file
22
targets/arduino_101/src/Makefile
Executable file
@ -0,0 +1,22 @@
|
||||
# Copyright © 2016 Intel Corporation
|
||||
#
|
||||
# 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.
|
||||
|
||||
ifdef V
|
||||
$(info Compiling application)
|
||||
endif
|
||||
|
||||
# Adding path for jerry script APIs
|
||||
ZEPHYRINCLUDE += -I$(JERRY_INCLUDE)
|
||||
|
||||
obj-y += main-zephyr.o
|
||||
45
targets/arduino_101/src/jerry-entry.c
Executable file
45
targets/arduino_101/src/jerry-entry.c
Executable file
@ -0,0 +1,45 @@
|
||||
/* Copyright 2016 Intel Corporation
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
#include "jerry-port.h"
|
||||
|
||||
/**
|
||||
* Provide log message to filestream implementation for the engine.
|
||||
*/
|
||||
int jerry_port_logmsg (FILE *stream, const char *format, ...)
|
||||
{
|
||||
va_list args;
|
||||
int count;
|
||||
va_start (args, format);
|
||||
count = vfprintf (stream, format, args);
|
||||
va_end (args);
|
||||
return count;
|
||||
} /* jerry_port_logmsg */
|
||||
|
||||
|
||||
/**
|
||||
* Provide error message to console implementation for the engine.
|
||||
*/
|
||||
int jerry_port_errormsg (const char *format, ...)
|
||||
{
|
||||
va_list args;
|
||||
int count;
|
||||
va_start (args, format);
|
||||
count = vfprintf (stderr, format, args);
|
||||
va_end (args);
|
||||
return count;
|
||||
} /* jerry_port_errormsg */
|
||||
164
targets/arduino_101/src/main-zephyr.c
Normal file
164
targets/arduino_101/src/main-zephyr.c
Normal file
@ -0,0 +1,164 @@
|
||||
/* Copyright 2016 Intel Corporation
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <zephyr.h>
|
||||
#include <misc/printk.h>
|
||||
#include <misc/shell.h>
|
||||
|
||||
#include "jerry.h"
|
||||
|
||||
#if defined (CONFIG_STDOUT_CONSOLE)
|
||||
#include <stdio.h>
|
||||
#define PRINT printf
|
||||
#else
|
||||
#include <misc/printk.h>
|
||||
#define PRINT printk
|
||||
#endif
|
||||
|
||||
static char *source_buffer = NULL;
|
||||
static unsigned char flags = 0;
|
||||
|
||||
#define VERBOSE 0x01
|
||||
|
||||
/**
|
||||
* Jerryscript simple test loop
|
||||
*/
|
||||
int jerryscript_test ()
|
||||
{
|
||||
jerry_completion_code_t ret_code;
|
||||
|
||||
const char script[] =
|
||||
"var test=0; " \
|
||||
"for (var t=100; t<1000; t++) test+=t; " \
|
||||
"print ('Hi JS World! '+test);";
|
||||
|
||||
printf ("Script [%s]\n",script);
|
||||
ret_code = jerry_run_simple ((jerry_api_char_t *) script,
|
||||
strlen (script),
|
||||
JERRY_FLAG_EMPTY);
|
||||
|
||||
return ret_code;
|
||||
} /* jerryscript_test */
|
||||
|
||||
|
||||
static int shell_cmd_verbose (int argc, char *argv[])
|
||||
{
|
||||
printf ("Enable verbose \n");
|
||||
flags |= VERBOSE;
|
||||
return 0;
|
||||
} /* shell_cmd_verbose */
|
||||
|
||||
|
||||
static int shell_cmd_syntax_help (int argc, char *argv[])
|
||||
{
|
||||
printf ("version jerryscript & zephyr versions\n");
|
||||
return 0;
|
||||
} /* shell_cmd_syntax_help */
|
||||
|
||||
|
||||
static int shell_cmd_version (int argc, char *argv[])
|
||||
{
|
||||
uint32_t version = sys_kernel_version_get ();
|
||||
|
||||
printf ("Jerryscript %s %s %s\n", jerry_branch_name,
|
||||
jerry_build_date,
|
||||
jerry_commit_hash);
|
||||
|
||||
printk ("Zephyr version %d.%d.%d\n", SYS_KERNEL_VER_MAJOR (version),
|
||||
SYS_KERNEL_VER_MINOR (version),
|
||||
SYS_KERNEL_VER_PATCHLEVEL (version));
|
||||
return 0;
|
||||
} /* shell_cmd_version */
|
||||
|
||||
|
||||
static int shell_cmd_test (int argc, char *argv[])
|
||||
{
|
||||
return jerryscript_test ();
|
||||
} /* shell_cmd_test */
|
||||
|
||||
|
||||
static int shell_cmd_handler (int argc, char *argv[])
|
||||
{
|
||||
if (argc <= 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
unsigned int size = 0;
|
||||
for (int t = 0; t < argc; t++)
|
||||
{
|
||||
size += strlen (argv[t]) + 1;
|
||||
}
|
||||
|
||||
source_buffer = (char *) malloc (size);
|
||||
|
||||
char *d = source_buffer;
|
||||
unsigned int len;
|
||||
|
||||
for (int t = 0; t < argc; t++)
|
||||
{
|
||||
len = strlen (argv[t]);
|
||||
memcpy (d, argv[t], len);
|
||||
d += len;
|
||||
*d = ' ';
|
||||
d++;
|
||||
}
|
||||
|
||||
* (d - 1) = '\0';
|
||||
|
||||
if (flags & VERBOSE)
|
||||
{
|
||||
printf ("[%s] %lu\n", source_buffer, strlen (source_buffer));
|
||||
}
|
||||
|
||||
jerry_completion_code_t ret_code;
|
||||
|
||||
ret_code = jerry_run_simple ((jerry_api_char_t *) source_buffer,
|
||||
strlen (source_buffer),
|
||||
JERRY_FLAG_EMPTY);
|
||||
|
||||
free (source_buffer);
|
||||
|
||||
if (ret_code != JERRY_COMPLETION_CODE_OK)
|
||||
{
|
||||
printf ("Failed to run JS\n");
|
||||
}
|
||||
|
||||
return 0;
|
||||
} /* shell_cmd_handler */
|
||||
|
||||
#define SHELL_COMMAND(name,cmd) { name, cmd }
|
||||
|
||||
const struct shell_cmd commands[] =
|
||||
{
|
||||
SHELL_COMMAND ("syntax", shell_cmd_syntax_help),
|
||||
SHELL_COMMAND ("version", shell_cmd_version),
|
||||
SHELL_COMMAND ("test", shell_cmd_test),
|
||||
SHELL_COMMAND ("verbose", shell_cmd_verbose),
|
||||
SHELL_COMMAND (NULL, NULL)
|
||||
};
|
||||
|
||||
|
||||
void main (void)
|
||||
{
|
||||
printf ("Jerry Compilation " __DATE__ " " __TIME__ "\n");
|
||||
shell_register_app_cmd_handler (shell_cmd_handler);
|
||||
shell_init ("js> ", commands);
|
||||
} /* main */
|
||||
|
||||
@ -22,6 +22,11 @@ JERRY_LIBM_FILES=`find ./jerry-libm -name "*.c" -or -name "*.h"`
|
||||
JERRY_MAIN_FILES=`find . -maxdepth 1 -name "*.c" -or -name "*.h"`
|
||||
UNIT_TEST_FILES=`find ./tests/unit -name "*.c" -or -name "*.h"`
|
||||
|
||||
if [ -n "$1" ]
|
||||
then
|
||||
MANUAL_CHECK_FILES=`find $1 -name "*.c" -or -name "*.h"`
|
||||
fi
|
||||
|
||||
vera++ -r tools/vera++ -p jerry \
|
||||
-e --no-duplicate \
|
||||
$JERRY_CORE_FILES $JERRY_PORT_DEFAULT_FILES $JERRY_LIBC_FILES $JERRY_LIBM_FILES $JERRY_MAIN_FILES $UNIT_TEST_FILES
|
||||
$MANUAL_CHECK_FILES $JERRY_CORE_FILES $JERRY_PORT_DEFAULT_FILES $JERRY_LIBC_FILES $JERRY_LIBM_FILES $JERRY_MAIN_FILES $UNIT_TEST_FILES
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user