-
Notifications
You must be signed in to change notification settings - Fork 106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add experimental support for WebAssembly #20
base: master
Are you sure you want to change the base?
Changes from all commits
8158b20
594bb51
b30080d
d38a771
b3eb35e
65f5033
f1681fe
46a5603
982d811
8575e85
2e41e89
fdcf282
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#!/usr/bin/env python3 | ||
|
||
""" | ||
Filters the EMSCRIPTEN_BINDINGS section of the bindings.cpp file, keeping only what is used in every file given as parameters. | ||
Outputs the result to bindings2.cpp | ||
""" | ||
|
||
import sys | ||
import os | ||
import re | ||
|
||
import argparse | ||
|
||
SRC_BINDINGS = "bindings.cpp" | ||
DST_BINDINGS = "bindings2.cpp" | ||
|
||
|
||
parser = argparse.ArgumentParser() | ||
parser.add_argument( "files", nargs = "+", default = None, help="The .js files to analyze" ) | ||
|
||
args = parser.parse_args() | ||
|
||
props = set() | ||
rePropFinder = re.compile( r"\bcv\s*\.\s*([a-zA-Z_][a-zA-Z0-9_]*)\b" ) | ||
#rePropFinder = re.compile( "\bcv\.([a-zA-Z_][a-zA-Z0-9_]*)" ) | ||
|
||
for f in args.files: | ||
jssource = open( f, "r" ).read() | ||
for match in rePropFinder.finditer( jssource ): | ||
props.add( match.group( 1 ) ) | ||
|
||
#print( props ) | ||
|
||
def replace( match ): | ||
lines = [] | ||
inSection = False | ||
keepSection = False | ||
# each "section" starts with a first line naming the prop, and ends with a line ending with a semicolon (it may be the same) | ||
for line in match.group(2).split( "\n" ): | ||
if not inSection: | ||
inSection = bool( line.strip() ) | ||
if inSection: # start of a section | ||
identifierMatched = re.search( r'"([^"]+)"', line ) | ||
keepSection = identifierMatched and identifierMatched.group(1) in props | ||
if keepSection: | ||
lines.append( "" ) # new section: insert a blank line before it | ||
|
||
if inSection and keepSection: | ||
lines.append( line ) | ||
|
||
if inSection and re.search( r";$", line ): | ||
inSection = keepSection = False | ||
|
||
return match.group(1) + "\n".join(lines) + match.group(3) | ||
|
||
text = open( SRC_BINDINGS, 'r' ).read() | ||
text = re.sub( r"(\bEMSCRIPTEN_BINDINGS\b\s*\(\s*\btestBinding\b\s*\)\s*\{)([^{}]*)(\})", replace, text ) | ||
|
||
open( DST_BINDINGS, 'w' ).write( text ) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
--- ./emscripten/master/system/include/emscripten/bind.h 2016-12-20 13:05:20.498980029 -0800 | ||
+++ ./emscripten/master/system/include/emscripten/bind.h 2016-12-20 13:12:11.599146929 -0800 | ||
--- ./system/include/emscripten/bind.h 2016-12-20 13:05:20.498980029 -0800 | ||
+++ ./system/include/emscripten/bind.h 2016-12-20 13:12:11.599146929 -0800 | ||
@@ -999,7 +999,7 @@ | ||
}; | ||
} | ||
|
@@ -54,8 +54,8 @@ | |
template<typename WrapperType> | ||
val wrapped_extend(const std::string& name, const val& properties) { | ||
|
||
--- ./emscripten/master/src/embind/embind.js 2016-12-20 13:05:20.498980029 -0800 | ||
+++ ./emscripten/master/src/embind/embind.js 2016-12-20 13:12:11.599146929 -0800 | ||
--- ./src/embind/embind.js 2016-12-20 13:05:20.498980029 -0800 | ||
+++ ./src/embind/embind.js 2016-12-20 13:12:11.599146929 -0800 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this file change needed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It makes the patch more generic, and usable with both emscripten/master and emscripten/incoming by changing just the patch command line (cf readme). |
||
@@ -2077,6 +2077,7 @@ | ||
var invokerArgsArray = [argTypes[0] /* return value */, null /* no class 'this'*/].concat(argTypes.slice(1) /* actual params */); | ||
var func = craftInvokerFunction(humanName, invokerArgsArray, null /* no class 'this'*/, rawInvoker, fn); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about following directory structure?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, putting all the files in the same folder with different names seemed simpler to me for the time being, as the .js file generated by emscripten expects to find its related .data (and .wasm, in case of WebAssembly) in the same folder as the .html file.
Having all the files in the same folder with different names depending on the technology used (WebAssembly or asm.js) simplifies the use: the user can just copy everything in build/ to the folder of his/her .html file, and then either load cv.js or cv-wasm.js depending on what technology s/he wants to use.