Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: emscripten-core/emscripten
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 1.6.0
Choose a base ref
...
head repository: emscripten-core/emscripten
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 1.6.1
Choose a head ref
  • 9 commits
  • 8 files changed
  • 1 contributor

Commits on Sep 23, 2013

  1. Copy the full SHA
    c145771 View commit details
  2. remove duplicate code

    kripken committed Sep 23, 2013
    Copy the full SHA
    07135d1 View commit details
  3. unwrap tokenizer

    kripken committed Sep 23, 2013
    Copy the full SHA
    d932563 View commit details
  4. Copy the full SHA
    0f5c7d3 View commit details
  5. optimize end of intertyper

    kripken committed Sep 23, 2013
    Copy the full SHA
    f388628 View commit details
  6. Copy the full SHA
    5c33401 View commit details
  7. optimize getNativeTypeSize

    kripken committed Sep 23, 2013
    Copy the full SHA
    bf33ff5 View commit details
  8. Copy the full SHA
    b1f12d5 View commit details
  9. Copy the full SHA
    79b2ee7 View commit details
Showing with 169 additions and 168 deletions.
  1. +1 −1 src/compiler.js
  2. +131 −131 src/intertyper.js
  3. +0 −9 src/jsifier.js
  4. +11 −0 src/preamble.js
  5. +0 −2 src/relooper/Relooper.cpp
  6. +4 −4 src/relooper/emscripten/glue.js
  7. +21 −20 src/runtime.js
  8. +1 −1 tools/shared.py
2 changes: 1 addition & 1 deletion src/compiler.js
Original file line number Diff line number Diff line change
@@ -213,7 +213,7 @@ load('parseTools.js');
load('intertyper.js');
load('analyzer.js');
load('jsifier.js');
if (RELOOP) {
if (phase == 'funcs' && RELOOP) { // XXX handle !singlePhase
RelooperModule = { TOTAL_MEMORY: ceilPowerOfTwo(2*RELOOPER_BUFFER_SIZE) };
load(RELOOPER);
assert(typeof Relooper != 'undefined');
262 changes: 131 additions & 131 deletions src/intertyper.js
Original file line number Diff line number Diff line change
@@ -4,151 +4,148 @@
// to be processed by the later stages.

// Line tokenizer
var tokenizer = {
processItem: function _tokenizer(item, inner) {
//assert(item.lineNum != 40000);
//if (item.lineNum) print(item.lineNum);
var tokens = [];
var quotes = 0;
var lastToken = null;
var CHUNKSIZE = 64; // How much forward to peek forward. Too much means too many string segments copied
// Note: '{' is not an encloser, as its use in functions is split over many lines
var enclosers = {
'[': 0,
']': '[',
'(': 0,
')': '(',
'<': 0,
'>': '<'
};
var totalEnclosing = 0;
function makeToken(text) {
if (text.length == 0) return;
// merge certain tokens
if (lastToken && ( (lastToken.text == '%' && text[0] == '"') || /^\**$/.test(text) ) ) {
lastToken.text += text;
return;
}
function tokenizer(item, inner) {
//assert(item.lineNum != 40000);
//if (item.lineNum) print(item.lineNum);
var tokens = [];
var quotes = 0;
var lastToken = null;
var CHUNKSIZE = 64; // How much forward to peek forward. Too much means too many string segments copied
// Note: '{' is not an encloser, as its use in functions is split over many lines
var enclosers = {
'[': 0,
']': '[',
'(': 0,
')': '(',
'<': 0,
'>': '<'
};
var totalEnclosing = 0;
function makeToken(text) {
if (text.length == 0) return;
// merge certain tokens
if (lastToken && ( (lastToken.text == '%' && text[0] == '"') || /^\**$/.test(text) ) ) {
lastToken.text += text;
return;
}

var token = {
text: text
};
if (text[0] in enclosers) {
token.item = tokenizer.processItem({
lineText: text.substr(1, text.length-2)
}, true);
token.type = text[0];
}
// merge certain tokens
if (lastToken && isType(lastToken.text) && isFunctionDef(token)) {
lastToken.text += ' ' + text;
} else if (lastToken && text[0] == '}') { // }, }*, etc.
var openBrace = tokens.length-1;
while (tokens[openBrace].text.substr(-1) != '{') openBrace --;
token = combineTokens(tokens.slice(openBrace+1));
tokens.splice(openBrace, tokens.length-openBrace+1);
tokens.push(token);
token.type = '{';
token.text = '{ ' + token.text + ' }';
var pointingLevelsToAdd = pointingLevels(text) - pointingLevels(token.text);
while (pointingLevelsToAdd > 0) {
token.text += '*';
pointingLevelsToAdd--;
}
lastToken = token;
} else {
tokens.push(token);
lastToken = token;
var token = {
text: text
};
if (text[0] in enclosers) {
token.item = tokenizer({
lineText: text.substr(1, text.length-2)
}, true);
token.type = text[0];
}
// merge certain tokens
if (lastToken && isType(lastToken.text) && isFunctionDef(token)) {
lastToken.text += ' ' + text;
} else if (lastToken && text[0] == '}') { // }, }*, etc.
var openBrace = tokens.length-1;
while (tokens[openBrace].text.substr(-1) != '{') openBrace --;
token = combineTokens(tokens.slice(openBrace+1));
tokens.splice(openBrace, tokens.length-openBrace+1);
tokens.push(token);
token.type = '{';
token.text = '{ ' + token.text + ' }';
var pointingLevelsToAdd = pointingLevels(text) - pointingLevels(token.text);
while (pointingLevelsToAdd > 0) {
token.text += '*';
pointingLevelsToAdd--;
}
lastToken = token;
} else {
tokens.push(token);
lastToken = token;
}
// Split using meaningful characters
var lineText = item.lineText + ' ';
var re = /[\[\]\(\)<>, "]/g;
var segments = lineText.split(re);
segments.pop();
var len = segments.length;
var i = -1;
var curr = '';
var segment, letter;
for (var s = 0; s < len; s++) {
segment = segments[s];
i += segment.length + 1;
letter = lineText[i];
curr += segment;
switch (letter) {
case ' ':
if (totalEnclosing == 0 && quotes == 0) {
makeToken(curr);
curr = '';
} else {
curr += ' ';
}
break;
case '"':
if (totalEnclosing == 0) {
if (quotes == 0) {
if (curr == '@' || curr == '%') {
curr += '"';
} else {
makeToken(curr);
curr = '"';
}
}
// Split using meaningful characters
var lineText = item.lineText + ' ';
var re = /[\[\]\(\)<>, "]/g;
var segments = lineText.split(re);
segments.pop();
var len = segments.length;
var i = -1;
var curr = '';
var segment, letter;
for (var s = 0; s < len; s++) {
segment = segments[s];
i += segment.length + 1;
letter = lineText[i];
curr += segment;
switch (letter) {
case ' ':
if (totalEnclosing == 0 && quotes == 0) {
makeToken(curr);
curr = '';
} else {
curr += ' ';
}
break;
case '"':
if (totalEnclosing == 0) {
if (quotes == 0) {
if (curr == '@' || curr == '%') {
curr += '"';
} else {
makeToken(curr + '"');
curr = '';
makeToken(curr);
curr = '"';
}
} else {
curr += '"';
makeToken(curr + '"');
curr = '';
}
quotes = 1-quotes;
} else {
curr += '"';
}
quotes = 1-quotes;
break;
case ',':
if (totalEnclosing == 0 && quotes == 0) {
makeToken(curr);
curr = '';
tokens.push({ text: ',' });
} else {
curr += ',';
}
break;
default:
assert(letter in enclosers);
if (quotes) {
curr += letter;
break;
case ',':
if (totalEnclosing == 0 && quotes == 0) {
}
if (letter in ENCLOSER_STARTERS) {
if (totalEnclosing == 0) {
makeToken(curr);
curr = '';
tokens.push({ text: ',' });
} else {
curr += ',';
}
break;
default:
assert(letter in enclosers);
if (quotes) {
curr += letter;
break;
}
if (letter in ENCLOSER_STARTERS) {
if (totalEnclosing == 0) {
makeToken(curr);
curr = '';
}
curr += letter;
enclosers[letter]++;
totalEnclosing++;
curr += letter;
enclosers[letter]++;
totalEnclosing++;
} else {
enclosers[enclosers[letter]]--;
totalEnclosing--;
if (totalEnclosing == 0) {
makeToken(curr + letter);
curr = '';
} else {
enclosers[enclosers[letter]]--;
totalEnclosing--;
if (totalEnclosing == 0) {
makeToken(curr + letter);
curr = '';
} else {
curr += letter;
}
curr += letter;
}
}
}
}
var newItem = {
tokens: tokens,
indent: lineText.search(/[^ ]/),
lineNum: item.lineNum
};
return newItem;
return null;
}
};
var newItem = {
tokens: tokens,
indent: lineText.search(/[^ ]/),
lineNum: item.lineNum
};
return newItem;
}

function tokenize(text) {
return tokenizer.processItem({ lineText: text }, true);
return tokenizer({ lineText: text }, true);
}

// Handy sets
@@ -252,7 +249,7 @@ function intertyper(lines, sidePass, baseLineNums) {
if (mainPass && /^}.*/.test(line)) {
inFunction = false;
if (mainPass) {
var func = funcHeaderHandler(tokenizer.processItem({ lineText: currFunctionLines[0], lineNum: currFunctionLineNum }, true));
var func = funcHeaderHandler(tokenizer({ lineText: currFunctionLines[0], lineNum: currFunctionLineNum }, true));

if (SKIP_STACK_IN_SMALL && /emscripten_autodebug/.exec(func.ident)) {
warnOnce('Disabling SKIP_STACK_IN_SMALL because we are apparently processing autodebugger data');
@@ -991,10 +988,13 @@ function intertyper(lines, sidePass, baseLineNums) {

// Input

return lineSplitter().map(tokenizer.processItem).filter(function(item) { return item }).map(triager).filter(function(result) {
var ret = lineSplitter().map(tokenizer).map(triager).filter(function(result) {
if (!result) return false;
if (result.tokens) result.tokens = null; // We do not need tokens, past the intertyper. Clean them up as soon as possible here.
return true;
}).concat(unparsedBundles).concat(extraResults);
});
if (unparsedBundles.length > 0) ret = ret.concat(unparsedBundles);
if (extraResults.length > 0) ret = ret.concat(extraResults);
return ret;
}

9 changes: 0 additions & 9 deletions src/jsifier.js
Original file line number Diff line number Diff line change
@@ -60,15 +60,6 @@ function JSify(data, functionsOnly, givenFunctions) {
}
}

// Does simple 'macro' substitution, using Django-like syntax,
// {{{ code }}} will be replaced with |eval(code)|.
function processMacros(text) {
return text.replace(/{{{[^}]+}}}/g, function(str) {
str = str.substr(3, str.length-6);
return eval(str).toString();
});
}

if (mainPass) {
// Handle unparsed types TODO: Batch them
analyzer(intertyper(data.unparsedTypess[0].lines, true), true);
11 changes: 11 additions & 0 deletions src/preamble.js
Original file line number Diff line number Diff line change
@@ -908,6 +908,17 @@ function writeArrayToMemory(array, buffer) {
}
Module['writeArrayToMemory'] = writeArrayToMemory;

function writeAsciiToMemory(str, buffer, dontAddNull) {
for (var i = 0; i < str.length; i++) {
#if ASSERTIONS
assert(str.charCodeAt(i) === str.charCodeAt(i)&0xff);
#endif
{{{ makeSetValue('buffer', 'i', 'str.charCodeAt(i)', 'i8') }}}
}
if (!dontAddNull) {{{ makeSetValue('buffer', 'str.length', 0, 'i8') }}}
}
Module['writeAsciiToMemory'] = writeAsciiToMemory;

{{{ unSign }}}
{{{ reSign }}}

2 changes: 0 additions & 2 deletions src/relooper/Relooper.cpp
Original file line number Diff line number Diff line change
@@ -8,8 +8,6 @@

#include "ministring.h"

// TODO: move all set to unorderedset

template <class T, class U> bool contains(const T& container, const U& contained) {
return container.find(contained) != container.end();
}
8 changes: 4 additions & 4 deletions src/relooper/emscripten/glue.js
Original file line number Diff line number Diff line change
@@ -19,10 +19,10 @@
RelooperGlue['addBlock'] = function(text, branchVar) {
assert(this.r);
assert(text.length+1 < TBUFFER_SIZE, 'buffer too small, increase RELOOPER_BUFFER_SIZE');
writeStringToMemory(text, tbuffer);
writeAsciiToMemory(text, tbuffer);
if (branchVar) {
assert(branchVar.length+1 < VBUFFER_SIZE, 'buffer too small, increase RELOOPER_BUFFER_SIZE');
writeStringToMemory(branchVar, vbuffer);
writeAsciiToMemory(branchVar, vbuffer);
}
var b = _rl_new_block(tbuffer, branchVar ? vbuffer : 0);
_rl_relooper_add_block(this.r, b);
@@ -32,14 +32,14 @@
assert(this.r);
if (condition) {
assert(condition.length+1 < TBUFFER_SIZE/2, 'buffer too small, increase RELOOPER_BUFFER_SIZE');
writeStringToMemory(condition, tbuffer);
writeAsciiToMemory(condition, tbuffer);
condition = tbuffer;
} else {
condition = 0; // allow undefined, null, etc. as inputs
}
if (code) {
assert(code.length+1 < TBUFFER_SIZE/2, 'buffer too small, increase RELOOPER_BUFFER_SIZE');
writeStringToMemory(code, tbuffer + TBUFFER_SIZE/2);
writeAsciiToMemory(code, tbuffer + TBUFFER_SIZE/2);
code = tbuffer + TBUFFER_SIZE/2;
} else {
code = 0; // allow undefined, null, etc. as inputs
Loading