aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMITSUNARI Shigeo <herumi@nifty.com>2017-09-10 21:08:15 +0800
committerMITSUNARI Shigeo <herumi@nifty.com>2017-09-10 21:08:15 +0800
commit40a6dbab6099831752999875c16124ef54955edd (patch)
tree4af191a39e0e43df1114f33e4f3de6e5c04c69de
parent1f9fb7a74146cc307e843db44de13116e6349eb3 (diff)
downloaddexon-mcl-40a6dbab6099831752999875c16124ef54955edd.tar.gz
dexon-mcl-40a6dbab6099831752999875c16124ef54955edd.tar.zst
dexon-mcl-40a6dbab6099831752999875c16124ef54955edd.zip
change option of export_functions.py
-rw-r--r--Makefile4
-rw-r--r--ffi/js/export-functions.py67
2 files changed, 37 insertions, 34 deletions
diff --git a/Makefile b/Makefile
index 84e87f4..e076657 100644
--- a/Makefile
+++ b/Makefile
@@ -195,7 +195,7 @@ $(EXPORTED_TXT): ./include/mcl/bn.h
python ffi/js/export-functions.py $< > $@
$(EXPORTED_JS): ./include/mcl/bn.h
- python ffi/js/export-functions.py $< -js mcl > $@
+ python ffi/js/export-functions.py -js mcl $< > $@
EXPORTED_MCL=$(shell cat $(EXPORTED_TXT))
@@ -203,7 +203,7 @@ docs/demo/mclbn.js: src/fp.cpp src/bn_c256.cpp $(EXPORTED_TXT) $(EXPORTED_JS)
emcc -o $@ src/fp.cpp src/bn_c256.cpp -I./include -I../cybozulib/include -s WASM=1 -s "MODULARIZE=1" -s "EXPORTED_FUNCTIONS=[$(EXPORTED_MCL)]" -O3 -DNDEBUG -DMCLBN_FP_UNIT_SIZE=4 -DMCL_MAX_BIT_SIZE=256 -DDISABLE_EXCEPTION_CATCHING=2
clean:
- $(RM) $(MCL_LIB) $(MCL_SLIB) $(BN256_LIB) $(BN256_SLIB) $(BN384_LIB) $(BN384_SLIB) $(OBJ_DIR)/*.o $(OBJ_DIR)/*.d $(EXE_DIR)/*.exe $(GEN_EXE) $(ASM_OBJ) $(LIB_OBJ) $(BN256_OBJ) $(BN384_OBJ) $(LLVM_SRC) $(FUNC_LIST) src/*.ll $(EXPORTED_JS) $(EXPORTED_MCL) docs/demo/mclbn.js docs/demo/mclbn.wasm
+ $(RM) $(MCL_LIB) $(MCL_SLIB) $(BN256_LIB) $(BN256_SLIB) $(BN384_LIB) $(BN384_SLIB) $(OBJ_DIR)/*.o $(OBJ_DIR)/*.d $(EXE_DIR)/*.exe $(GEN_EXE) $(ASM_OBJ) $(LIB_OBJ) $(BN256_OBJ) $(BN384_OBJ) $(LLVM_SRC) $(FUNC_LIST) src/*.ll $(EXPORTED_JS) $(EXPORTED_TXT) docs/demo/mclbn.js docs/demo/mclbn.wasm
ALL_SRC=$(SRC_SRC) $(TEST_SRC) $(SAMPLE_SRC)
DEPEND_FILE=$(addprefix $(OBJ_DIR)/, $(addsuffix .d,$(basename $(ALL_SRC))))
diff --git a/ffi/js/export-functions.py b/ffi/js/export-functions.py
index f0026a3..67e99d1 100644
--- a/ffi/js/export-functions.py
+++ b/ffi/js/export-functions.py
@@ -1,46 +1,49 @@
import sys, re
#RE_PROTOTYPE = re.compile(r'MCLBN_DLL_API\s\w\s\w\([^)]*\);')
-RE_PROTOTYPE = re.compile(r'MCLBN_DLL_API\s(\w*)\s(\w*)\(([^)]*)\);')
+RE_PROTOTYPE = re.compile(r'\w*\s(\w*)\s(\w*)\(([^)]*)\);')
RE_SPECIAL_FUNCTION_NAME = re.compile(r'(setStr|getStr|serialize|setLittleEndian|setHashOf|hashAndMapTo)')
-def export_functions(fileName, modName):
- with open(fileName, 'rb') as f:
- if modName:
- print 'function define_exported_' + modName + '(mod) {'
- comma = ''
- for line in f.readlines():
- p = RE_PROTOTYPE.search(line)
- if p:
- ret = p.group(1)
- name = p.group(2)
- arg = p.group(3)
- if modName:
- retType = 'null' if ret == 'void' else 'number'
- if arg == '' or arg == 'void':
- paramType = '[]'
+def export_functions(modName, fileNames):
+ if modName:
+ print 'function define_exported_' + modName + '(mod) {'
+ comma = ''
+ for fileName in fileNames:
+ with open(fileName, 'rb') as f:
+ for line in f.readlines():
+ p = RE_PROTOTYPE.search(line)
+ if p:
+ ret = p.group(1)
+ name = p.group(2)
+ arg = p.group(3)
+ if modName:
+ retType = 'null' if ret == 'void' else 'number'
+ if arg == '' or arg == 'void':
+ paramType = '[]'
+ else:
+ paramType = '[' + ("'number', " * len(arg.split(','))) + ']'
+ if RE_SPECIAL_FUNCTION_NAME.search(name):
+ exportName = '_' + name # to wrap function
+ else:
+ exportName = name
+ print "{0} = mod.cwrap('{1}', '{2}', {3})".format(exportName, name, retType, paramType)
else:
- paramType = '[' + ("'number', " * len(arg.split(','))) + ']'
- if RE_SPECIAL_FUNCTION_NAME.search(name):
- exportName = '_' + name # to wrap function
- else:
- exportName = name
- print "{0} = mod.cwrap('{1}', '{2}', {3})".format(exportName, name, retType, paramType)
- else:
- print comma + "'_" + name + "'",
- if comma == '':
- comma = ','
- if modName:
- print '}'
+ print comma + "'_" + name + "'",
+ if comma == '':
+ comma = ','
+ if modName:
+ print '}'
def main():
args = len(sys.argv)
modName = ''
if args <= 1:
- print 'export_functions header [-js <modName>]'
+ print 'export_functions [-js <modName>] header+'
sys.exit(1)
- if args == 4 and sys.argv[2] == '-js':
- modName = sys.argv[3]
- export_functions(sys.argv[1], modName)
+ pos = 1
+ if args >= 3 and sys.argv[1] == '-js':
+ modName = sys.argv[2]
+ pos = 3
+ export_functions(modName, sys.argv[pos:])
if __name__ == '__main__':
main()