aboutsummaryrefslogtreecommitdiff
path: root/src/jsifier.js
diff options
context:
space:
mode:
authorLars Schneider <lars.schneider@autodesk.com>2012-09-25 14:44:54 +0200
committerLars Schneider <lars.schneider@autodesk.com>2012-09-26 19:30:19 +0200
commit0c33345f226af403d15f5f83811488aead85b71b (patch)
treecc1787e201bb3184fb901500e94175f22d322c6a /src/jsifier.js
parentc74da50989604747e3174429d0538f668b4ff7e7 (diff)
Add emcc option "--split <size>" to split javascript file.
Splits the resulting javascript file into pieces to ease debugging. This option only works if Javascript is generated (target -o <name>.js). Files with function declarations must be loaded before main file upon execution. Without "-g" option: Creates files with function declarations up to the given size with the suffix "_functions.partxxx.js" and a main file with the suffix ".js". With "-g" option: Recreates the directory structure of the C source files and stores function declarations in their respective C files with the suffix ".js". If such a file exceeds the given size, files with the suffix ".partxxx.js" are created. The main file resides in the base directory and has the suffix ".js".
Diffstat (limited to 'src/jsifier.js')
-rw-r--r--src/jsifier.js17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/jsifier.js b/src/jsifier.js
index 92b39b7d..8021f8a1 100644
--- a/src/jsifier.js
+++ b/src/jsifier.js
@@ -522,6 +522,11 @@ function JSify(data, functionsOnly, givenFunctions) {
func.JS += ' */\n';
}
+ if (PRINT_SPLIT_FILE_MARKER) {
+ func.JS += '\n//FUNCTION_BEGIN_MARKER\n'
+ var associatedSourceFile = "NO_SOURCE";
+ }
+
func.JS += 'function ' + func.ident + '(' + paramIdents.join(', ') + ') {\n';
if (PROFILE) {
@@ -572,6 +577,13 @@ function JSify(data, functionsOnly, givenFunctions) {
if (EXECUTION_TIMEOUT > 0) {
ret += indent + 'if (Date.now() - START_TIME >= ' + (EXECUTION_TIMEOUT*1000) + ') throw "Timed out!" + (new Error().stack);\n';
}
+
+ if (PRINT_SPLIT_FILE_MARKER && Debugging.on && Debugging.getAssociatedSourceFile(line.lineNum)) {
+ // Overwrite the associated source file for every line. The last line should contain the source file associated to
+ // the return value/address of outer most block (the marked function).
+ associatedSourceFile = Debugging.getAssociatedSourceFile(line.lineNum);
+ }
+
// for special labels we care about (for phi), mark that we visited them
return ret + label.lines.map(function(line) { return line.JS + (Debugging.on ? Debugging.getComment(line.lineNum) : '') })
.join('\n')
@@ -653,6 +665,11 @@ function JSify(data, functionsOnly, givenFunctions) {
func.JS += ' return' + (func.returnType !== 'void' ? ' null' : '') + ';\n';
}
func.JS += '}\n';
+
+ if (PRINT_SPLIT_FILE_MARKER) {
+ func.JS += '\n//FUNCTION_END_MARKER_OF_SOURCE_FILE_' + associatedSourceFile + '\n';
+ }
+
if (func.ident in EXPORTED_FUNCTIONS) {
func.JS += 'Module["' + func.ident + '"] = ' + func.ident + ';';
}