Improve Js2C converter (#1408)

* Rename 'jerry_targetjs.h' to 'jerry-targetjs.h',
   because we use dashes in filen ames instead of underscores.
 * Made destination and js souce directory configurable.
 * Updated esp8266 target to the recent changes.
 * Updated mbed and mbedos5 target to the recent changes.

JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
This commit is contained in:
László Langó
2016-10-27 09:54:01 +02:00
committed by GitHub
parent ac1bf19c90
commit a30b89c536
10 changed files with 25 additions and 27 deletions
+1 -1
View File
@@ -27,7 +27,7 @@ tags
ID ID
# targets # targets
jerry_targetjs.h jerry-targetjs.h
targets/mbedk64f/libjerry targets/mbedk64f/libjerry
targets/mbedk64f/build targets/mbedk64f/build
targets/mbedk64f/yotta_modules targets/mbedk64f/yotta_modules
+1 -1
View File
@@ -95,7 +95,7 @@ LINKFLAGS_eagle.app.v6 = \
DEPENDS_eagle.app.v6 = \ DEPENDS_eagle.app.v6 = \
$(LD_FILE) \ $(LD_FILE) \
$(LDDIR)/eagle.rom.addr.v6.ld \ $(LDDIR)/eagle.rom.addr.v6.ld \
./source/jerry_targetjs.h \ ./source/jerry-targetjs.h \
./libs/libjerrylibm.a \ ./libs/libjerrylibm.a \
./libs/libjerrycore.a \ ./libs/libjerrycore.a \
./libs/libjerryentry.a ./libs/libjerryentry.a
+1 -1
View File
@@ -34,7 +34,7 @@ ESP_CFLAGS := -D__TARGET_ESP8266 -D__attr_always_inline___=
MFORCE32 = `xtensa-lx106-elf-gcc --help=target | grep mforce-l32` MFORCE32 = `xtensa-lx106-elf-gcc --help=target | grep mforce-l32`
ifneq ($(MFORCE32),) ifneq ($(MFORCE32),)
# Your compiler supports the -mforce-l32 flag which means that # Your compiler supports the -mforce-l32 flag which means that
# constants can be placed in ROM to free additional RAM # constants can be placed in ROM to free additional RAM
ESP_CFLAGS += -DJERRY_CONST_DATA="__attribute__((aligned(4))) __attribute__((section(\".irom.text\")))" ESP_CFLAGS += -DJERRY_CONST_DATA="__attribute__((aligned(4))) __attribute__((section(\".irom.text\")))"
endif endif
+1 -1
View File
@@ -43,7 +43,7 @@ void show_free_mem(int idx) {
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
#include "jerry_targetjs.h" #include "jerry-targetjs.h"
static int jerry_task_init(void) { static int jerry_task_init(void) {
+1 -1
View File
@@ -43,7 +43,7 @@ Basically, you can create a new target in this way (If the mbed OS support your
You can run this rule with the following command: You can run this rule with the following command:
- `make -f targets/mbed/Makefile.mbed board=$(TARGET) jerry` - `make -f targets/mbed/Makefile.mbed board=$(TARGET) jerry`
2. The next rule is the `js2c`. This rule calls a `js2c.py` python script from the `jerryscript/targets/tools` and creates the JavaScript builtin file into the `targets/mbed/source/` folder. This file is the `jerry_targetjs.h`. You can run this rule with the follwoing command: 2. The next rule is the `js2c`. This rule calls a `js2c.py` python script from the `jerryscript/targets/tools` and creates the JavaScript builtin file into the `targets/mbed/source/` folder. This file is the `jerry-targetjs.h`. You can run this rule with the follwoing command:
- `make -f targets/mbed/Makefile.mbed board=$(TARGET) js2c` - `make -f targets/mbed/Makefile.mbed board=$(TARGET) js2c`
+1 -1
View File
@@ -19,7 +19,7 @@
#include "jerry-core/jerry-api.h" #include "jerry-core/jerry-api.h"
#include "jerry_run.h" #include "jerry_run.h"
#include "jerry_targetjs.h" #include "jerry-targetjs.h"
static Serial pc (USBTX, USBRX); //tx, rx static Serial pc (USBTX, USBRX); //tx, rx
+1 -1
View File
@@ -5,4 +5,4 @@ mbed-events
mbed_settings.py mbed_settings.py
js/pins.js js/pins.js
source/pins.cpp source/pins.cpp
source/jerry_targetjs.h source/jerry-targetjs.h
+5 -5
View File
@@ -52,13 +52,13 @@ MBED_CLI_FLAGS += -D "CONFIG_MEM_HEAP_AREA_SIZE=(1024*$(HEAPSIZE))"
MBED_CLI_FLAGS += -t GCC_ARM MBED_CLI_FLAGS += -t GCC_ARM
.PHONY: all js2c getlibs rebuild library .PHONY: all js2c getlibs rebuild library
all: source/jerry_targetjs.h source/pins.cpp .mbed ../../.mbedignore all: source/jerry-targetjs.h source/pins.cpp .mbed ../../.mbedignore
mbed target $(BOARD) mbed target $(BOARD)
mbed compile $(MBED_CLI_FLAGS) mbed compile $(MBED_CLI_FLAGS)
library: .mbed ../../.mbedignore library: .mbed ../../.mbedignore
# delete encoded js code if it exists # delete encoded js code if it exists
rm -f source/jerry_targetjs.h rm -f source/jerry-targetjs.h
mbed target $(BOARD) mbed target $(BOARD)
mbed compile $(MBED_CLI_FLAGS) --library mbed compile $(MBED_CLI_FLAGS) --library
@@ -68,13 +68,13 @@ clean:
js2c: js/main.js js/flash_leds.js js2c: js/main.js js/flash_leds.js
python ../tools/js2c.py --ignore pins.js python ../tools/js2c.py --ignore pins.js
source/pins.cpp: source/pins.cpp:
python tools/generate_pins.py ${BOARD} python tools/generate_pins.py ${BOARD}
ifeq ($(NO_JS),0) ifeq ($(NO_JS),0)
source/jerry_targetjs.h: js2c source/jerry-targetjs.h: js2c
else else
source/jerry_targetjs.h: ; source/jerry-targetjs.h: ;
endif endif
getlibs: .mbed getlibs: .mbed
@@ -25,14 +25,14 @@
#include "jerryscript-mbed-launcher/launcher.h" #include "jerryscript-mbed-launcher/launcher.h"
#include "jerryscript-mbed-launcher/setup.h" #include "jerryscript-mbed-launcher/setup.h"
#include "jerry_targetjs.h" #include "jerry-targetjs.h"
DECLARE_JS_CODES; DECLARE_JS_CODES;
/** /**
* load_javascript * load_javascript
* *
* Parse and run javascript files specified in jerry_targetjs.h * Parse and run javascript files specified in jerry-targetjs.h
*/ */
static int load_javascript() { static int load_javascript() {
for (int src = 0; js_codes[src].source; src++) { for (int src = 0; js_codes[src].source; src++) {
+11 -13
View File
@@ -14,14 +14,13 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
# #
# This file converts ./js/*.js to a C-array in ./source/jerry_targetjs.h file # This file converts ./js/*.js to a C-array in ./source/jerry-targetjs.h file
import sys import argparse
import glob import glob
import os import os
import re import re
import sys
import argparse
special_chars = re.compile(r'[-\\?\'".]') special_chars = re.compile(r'[-\\?\'".]')
@@ -78,21 +77,20 @@ FOOTER = '''
''' '''
OUT_PATH = './source/'
SRC_PATH = './js/'
parser = argparse.ArgumentParser(description="js2c") parser = argparse.ArgumentParser(description="js2c")
parser.add_argument('build_type', help='build type', default='release', nargs='?') parser.add_argument('--build-type', help='build type', default='release', choices=['release', 'debug'])
parser.add_argument('--ignore', help='files to ignore', dest='ignore_files', default=[], action='append') parser.add_argument('--ignore', help='files to ignore', dest='ignore_files', default=[], action='append')
parser.add_argument('--no-main', help='don\'t require a main.js file', dest='main', action='store_false', default=True) parser.add_argument('--no-main', help="don't require a 'main.js' file", dest='main', action='store_false', default=True)
parser.add_argument('--js-source', dest='js_source_path', default='./js', help='Source directory of JavaScript files" (default: %(default)s)')
parser.add_argument('--dest', dest='output_path', default='./source', help="Destination directory of 'jerry-targetjs.h' (default: %(default)s)")
args = parser.parse_args() args = parser.parse_args()
# argument processing # argument processing
buildtype = args.build_type build_type = args.build_type
ignore_files = args.ignore_files ignore_files = args.ignore_files
fout = open(OUT_PATH + 'jerry_targetjs.h', 'w') fout = open(os.path.join(args.output_path, 'jerry-targetjs.h'), 'w')
fout.write(LICENSE); fout.write(LICENSE);
fout.write(HEADER); fout.write(HEADER);
@@ -104,7 +102,7 @@ def exportOneFile(path, name):
code = fin.read() + '\0' code = fin.read() + '\0'
# minimize code when release mode # minimize code when release mode
if buildtype != 'debug': if build_type != 'debug':
code = removeComments(code) code = removeComments(code)
code = removeWhitespaces(code) code = removeWhitespaces(code)
@@ -122,7 +120,7 @@ def exportOneFile(path, name):
def exportOneName(name): def exportOneName(name):
writeLine(fout, '{ ' + name + '_n, ' + name + '_s, ' + name + '_l }, \\', 1) writeLine(fout, '{ ' + name + '_n, ' + name + '_s, ' + name + '_l }, \\', 1)
files = glob.glob(SRC_PATH + '*.js') files = glob.glob(os.path.join(args.js_source_path, '*.js'))
for path in files: for path in files:
name = extractName(path) name = extractName(path)
if os.path.basename(path) not in ignore_files: if os.path.basename(path) not in ignore_files: