mirror of
https://github.com/jerryscript-project/jerryscript.git
synced 2025-12-15 16:29:21 +00:00
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:
parent
ac1bf19c90
commit
a30b89c536
2
.gitignore
vendored
2
.gitignore
vendored
@ -27,7 +27,7 @@ tags
|
||||
ID
|
||||
|
||||
# targets
|
||||
jerry_targetjs.h
|
||||
jerry-targetjs.h
|
||||
targets/mbedk64f/libjerry
|
||||
targets/mbedk64f/build
|
||||
targets/mbedk64f/yotta_modules
|
||||
|
||||
@ -95,7 +95,7 @@ LINKFLAGS_eagle.app.v6 = \
|
||||
DEPENDS_eagle.app.v6 = \
|
||||
$(LD_FILE) \
|
||||
$(LDDIR)/eagle.rom.addr.v6.ld \
|
||||
./source/jerry_targetjs.h \
|
||||
./source/jerry-targetjs.h \
|
||||
./libs/libjerrylibm.a \
|
||||
./libs/libjerrycore.a \
|
||||
./libs/libjerryentry.a
|
||||
|
||||
@ -34,7 +34,7 @@ ESP_CFLAGS := -D__TARGET_ESP8266 -D__attr_always_inline___=
|
||||
MFORCE32 = `xtensa-lx106-elf-gcc --help=target | grep mforce-l32`
|
||||
|
||||
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
|
||||
ESP_CFLAGS += -DJERRY_CONST_DATA="__attribute__((aligned(4))) __attribute__((section(\".irom.text\")))"
|
||||
endif
|
||||
|
||||
@ -43,7 +43,7 @@ void show_free_mem(int idx) {
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "jerry_targetjs.h"
|
||||
#include "jerry-targetjs.h"
|
||||
|
||||
|
||||
static int jerry_task_init(void) {
|
||||
|
||||
@ -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:
|
||||
- `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`
|
||||
|
||||
|
||||
@ -19,7 +19,7 @@
|
||||
#include "jerry-core/jerry-api.h"
|
||||
#include "jerry_run.h"
|
||||
|
||||
#include "jerry_targetjs.h"
|
||||
#include "jerry-targetjs.h"
|
||||
|
||||
static Serial pc (USBTX, USBRX); //tx, rx
|
||||
|
||||
|
||||
2
targets/mbedos5/.gitignore
vendored
2
targets/mbedos5/.gitignore
vendored
@ -5,4 +5,4 @@ mbed-events
|
||||
mbed_settings.py
|
||||
js/pins.js
|
||||
source/pins.cpp
|
||||
source/jerry_targetjs.h
|
||||
source/jerry-targetjs.h
|
||||
|
||||
@ -52,13 +52,13 @@ MBED_CLI_FLAGS += -D "CONFIG_MEM_HEAP_AREA_SIZE=(1024*$(HEAPSIZE))"
|
||||
MBED_CLI_FLAGS += -t GCC_ARM
|
||||
|
||||
.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 compile $(MBED_CLI_FLAGS)
|
||||
|
||||
library: .mbed ../../.mbedignore
|
||||
# delete encoded js code if it exists
|
||||
rm -f source/jerry_targetjs.h
|
||||
rm -f source/jerry-targetjs.h
|
||||
mbed target $(BOARD)
|
||||
mbed compile $(MBED_CLI_FLAGS) --library
|
||||
|
||||
@ -68,13 +68,13 @@ clean:
|
||||
js2c: js/main.js js/flash_leds.js
|
||||
python ../tools/js2c.py --ignore pins.js
|
||||
|
||||
source/pins.cpp:
|
||||
source/pins.cpp:
|
||||
python tools/generate_pins.py ${BOARD}
|
||||
|
||||
ifeq ($(NO_JS),0)
|
||||
source/jerry_targetjs.h: js2c
|
||||
source/jerry-targetjs.h: js2c
|
||||
else
|
||||
source/jerry_targetjs.h: ;
|
||||
source/jerry-targetjs.h: ;
|
||||
endif
|
||||
|
||||
getlibs: .mbed
|
||||
|
||||
@ -25,14 +25,14 @@
|
||||
#include "jerryscript-mbed-launcher/launcher.h"
|
||||
#include "jerryscript-mbed-launcher/setup.h"
|
||||
|
||||
#include "jerry_targetjs.h"
|
||||
#include "jerry-targetjs.h"
|
||||
|
||||
DECLARE_JS_CODES;
|
||||
|
||||
/**
|
||||
* 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() {
|
||||
for (int src = 0; js_codes[src].source; src++) {
|
||||
|
||||
@ -14,14 +14,13 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# 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 os
|
||||
import re
|
||||
|
||||
import argparse
|
||||
import sys
|
||||
|
||||
special_chars = re.compile(r'[-\\?\'".]')
|
||||
|
||||
@ -78,21 +77,20 @@ FOOTER = '''
|
||||
|
||||
'''
|
||||
|
||||
OUT_PATH = './source/'
|
||||
SRC_PATH = './js/'
|
||||
|
||||
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('--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()
|
||||
|
||||
# argument processing
|
||||
buildtype = args.build_type
|
||||
build_type = args.build_type
|
||||
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(HEADER);
|
||||
|
||||
@ -104,7 +102,7 @@ def exportOneFile(path, name):
|
||||
code = fin.read() + '\0'
|
||||
|
||||
# minimize code when release mode
|
||||
if buildtype != 'debug':
|
||||
if build_type != 'debug':
|
||||
code = removeComments(code)
|
||||
code = removeWhitespaces(code)
|
||||
|
||||
@ -122,7 +120,7 @@ def exportOneFile(path, name):
|
||||
def exportOneName(name):
|
||||
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:
|
||||
name = extractName(path)
|
||||
if os.path.basename(path) not in ignore_files:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user