aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2014-01-07 15:40:53 -0800
committerAlon Zakai <alonzakai@gmail.com>2014-01-07 15:40:53 -0800
commit0b3416a1dcd808fb71043a9f400f3ef2aa636abc (patch)
tree9a7ff926af193e432f5646afbcfb2c7365b17879 /src
parent6fee37fceb9e06a805c8074aa68bf678f406ff5b (diff)
parente4e8063f6d568277b297f19d51801cd7dda9545c (diff)
Merge branch 'incoming' into llvm-3.41.8.6
Conflicts: tests/test_benchmark.py tools/shared.py
Diffstat (limited to 'src')
-rw-r--r--src/closure-externs.js110
-rw-r--r--src/library_uuid.js140
-rw-r--r--src/modules.js2
-rw-r--r--src/parseTools.js9
-rw-r--r--src/settings.js2
-rw-r--r--src/struct_info.json12
6 files changed, 272 insertions, 3 deletions
diff --git a/src/closure-externs.js b/src/closure-externs.js
new file mode 100644
index 00000000..a82aa669
--- /dev/null
+++ b/src/closure-externs.js
@@ -0,0 +1,110 @@
+/**
+ * This file contains definitions for things that we'd really rather the closure compiler *didn't* minify.
+ * See http://code.google.com/p/closure-compiler/wiki/FAQ#How_do_I_write_an_externs_file
+ * See also the discussion here: https://github.com/kripken/emscripten/issues/1979
+ *
+ * The closure_compiler() method in tools/shared.py refers to this file when calling closure.
+ */
+
+// Closure externs used by library_uuid.js
+
+/**
+ * @param {Array} typedArray
+ */
+crypto.getRandomValues = function(typedArray) {};
+
+/**
+ BEGIN_NODE_INCLUDE
+ var crypto = require('crypto');
+ END_NODE_INCLUDE
+ */
+
+/**
+ * @type {Object.<string,*>}
+ */
+var crypto = {};
+
+/**
+ * @param {number} size
+ * @param {function(Error, buffer.Buffer)} callback
+ */
+crypto.randomBytes = function(size, callback) {};
+
+
+// Closure externs used by library_sockfs.js
+
+/**
+ BEGIN_NODE_INCLUDE
+ var ws = require('ws');
+ END_NODE_INCLUDE
+ */
+
+/**
+ * @type {Object.<string,*>}
+ */
+var ws = {};
+
+/**
+ * @param {string} event
+ * @param {function()} callback
+ */
+ws.on = function(event, callback) {};
+
+/**
+ * @param {Object} data
+ * @param {Object} flags
+ * @param {function()=} callback
+ */
+ws.send = function(data, flags, callback) {};
+
+/**
+* @type {boolean}
+*/
+ws.binaryType;
+
+/**
+ * @type {Object.<string,*>}
+ */
+var wss = ws.Server;
+
+/**
+ * @param {string} event
+ * @param {function()} callback
+ */
+wss.on = function(event, callback) {};
+
+/**
+ * @param {function()} callback
+ */
+wss.broadcast = function(callback) {};
+
+/**
+* @type {Object.<string,*>}
+*/
+wss._socket;
+
+/**
+* @type {string}
+*/
+wss.url;
+
+/**
+* @type {string}
+*/
+wss._socket.remoteAddress;
+
+/**
+* @type {number}
+*/
+wss._socket.remotePort;
+
+/**
+* @type {Object.<string,*>}
+*/
+var flags = {};
+/**
+* @type {boolean}
+*/
+flags.binary;
+
+
diff --git a/src/library_uuid.js b/src/library_uuid.js
new file mode 100644
index 00000000..adfd1882
--- /dev/null
+++ b/src/library_uuid.js
@@ -0,0 +1,140 @@
+// Implementation of libuuid creating RFC4122 version 4 random UUIDs.
+
+mergeInto(LibraryManager.library, {
+ // Clear a 'compact' UUID.
+ uuid_clear: function(uu) {
+ // void uuid_clear(uuid_t uu);
+ _memset(uu, 0, 16);
+ },
+
+ // Compare whether or not two 'compact' UUIDs are the same.
+ // Returns an integer less than, equal to, or greater than zero if uu1 is found, respectively, to be
+ // lexigraphically less than, equal, or greater than uu2.
+ uuid_compare__deps: ['memcmp'],
+ uuid_compare: function(uu1, uu2) {
+ // int uuid_compare(const uuid_t uu1, const uuid_t uu2);
+ return _memcmp(uu1, uu2, 16);
+ },
+
+ // Copies the 'compact' UUID variable from src to dst.
+ uuid_copy: function(dst, src) {
+ // void uuid_copy(uuid_t dst, const uuid_t src);
+ _memcpy(dst, src, 16);
+ },
+
+ // Write a RFC4122 version 4 compliant UUID largely based on the method found in
+ // http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript
+ // tweaked slightly in order to use the 'compact' UUID form used by libuuid.
+ uuid_generate: function(out) {
+ // void uuid_generate(uuid_t out);
+ var uuid = null;
+
+ if (ENVIRONMENT_IS_NODE) {
+ // If Node.js try to use crypto.randomBytes
+ try {
+ var rb = require('crypto').randomBytes;
+ uuid = rb(16);
+ } catch(e) {}
+ } else if (ENVIRONMENT_IS_WEB &&
+ typeof(window.crypto) !== 'undefined' &&
+ typeof(window.crypto.getRandomValues) !== 'undefined') {
+ // If crypto.getRandomValues is available try to use it.
+ uuid = new Uint8Array(16);
+ window.crypto.getRandomValues(uuid);
+ }
+
+ // Fall back to Math.random if a higher quality random number generator is not available.
+ if (!uuid) {
+ uuid = new Array(16);
+ var d = new Date().getTime();
+ for (var i = 0; i < 16; i++) {
+ var r = (d + Math.random()*256)%256 | 0;
+ d = Math.floor(d/256);
+ uuid[i] = r;
+ }
+ }
+
+ uuid[6] = (uuid[6] & 0x0F) | 0x40;
+ uuid[8] = (uuid[8] & 0x7F) | 0x80;
+ writeArrayToMemory(uuid, out);
+ },
+
+ // Compares the value of the supplied 'compact' UUID variable uu to the NULL value.
+ // If the value is equal to the NULL UUID, 1 is returned, otherwise 0 is returned.
+ uuid_is_null: function(uu) {
+ // int uuid_is_null(const uuid_t uu);
+ for (var i = 0; i < 4; i++, uu = (uu+4)|0) {
+ var val = {{{ makeGetValue('uu', 0, 'i32') }}};
+ if (val) {
+ return 0;
+ }
+ }
+ return 1;
+ },
+
+ // converts the UUID string given by inp into the binary representation. The input UUID is a string of
+ // the form "%08x-%04x-%04x-%04x-%012x" 36 bytes plus the trailing '\0'.
+ // Upon successfully parsing the input string, 0 is returned, and the UUID is stored in the location
+ // pointed to by uu, otherwise -1 is returned.
+ uuid_parse: function(inp, uu) {
+ // int uuid_parse(const char *in, uuid_t uu);
+ var inp = Pointer_stringify(inp);
+ if (inp.length === 36) {
+ var i = 0;
+ var uuid = new Array(16);
+ inp.toLowerCase().replace(/[0-9a-f]{2}/g, function(byte) {
+ if (i < 16) {
+ uuid[i++] = parseInt(byte, 16);
+ }
+ });
+
+ if (i < 16) {
+ return -1;
+ } else {
+ writeArrayToMemory(uuid, uu);
+ return 0;
+ }
+ } else {
+ return -1;
+ }
+ },
+
+ // Convert a 'compact' form UUID to a string, if the upper parameter is supplied make the string upper case.
+ uuid_unparse: function(uu, out, upper) {
+ // void uuid_unparse(const uuid_t uu, char *out);
+ var i = 0;
+ var uuid = 'xxxx-xx-xx-xx-xxxxxx'.replace(/[x]/g, function(c) {
+ var r = upper ? ({{{ makeGetValue('uu', 'i', 'i8', 0, 1) }}}).toString(16).toUpperCase() :
+ ({{{ makeGetValue('uu', 'i', 'i8', 0, 1) }}}).toString(16);
+ r = (r.length === 1) ? '0' + r : r; // Zero pad single digit hex values
+ i++;
+ return r;
+ });
+ writeStringToMemory(uuid, out);
+ },
+
+ // Convert a 'compact' form UUID to a lower case string.
+ uuid_unparse_lower__deps: ['uuid_unparse'],
+ uuid_unparse_lower: function(uu, out) {
+ // void uuid_unparse_lower(const uuid_t uu, char *out);
+ _uuid_unparse(uu, out);
+ },
+
+ // Convert a 'compact' form UUID to an upper case string.
+ uuid_unparse_upper__deps: ['uuid_unparse'],
+ uuid_unparse_upper: function(uu, out) {
+ // void uuid_unparse_upper(const uuid_t uu, char *out);
+ _uuid_unparse(uu, out, true);
+ },
+
+ uuid_type: function(uu) {
+ // int uuid_type(const uuid_t uu);
+ return {{{ cDefine('UUID_TYPE_DCE_RANDOM') }}};
+ },
+
+ uuid_variant: function(uu) {
+ // int uuid_variant(const uuid_t uu);
+ return {{{ cDefine('UUID_VARIANT_DCE') }}};
+ }
+});
+
diff --git a/src/modules.js b/src/modules.js
index e2d3433f..c0b98f6f 100644
--- a/src/modules.js
+++ b/src/modules.js
@@ -424,7 +424,7 @@ var LibraryManager = {
load: function() {
if (this.library) return;
- var libraries = ['library.js', 'library_path.js', 'library_fs.js', 'library_idbfs.js', 'library_memfs.js', 'library_nodefs.js', 'library_sockfs.js', 'library_tty.js', 'library_browser.js', 'library_sdl.js', 'library_gl.js', 'library_glut.js', 'library_xlib.js', 'library_egl.js', 'library_gc.js', 'library_jansson.js', 'library_openal.js', 'library_glfw.js'].concat(additionalLibraries);
+ var libraries = ['library.js', 'library_path.js', 'library_fs.js', 'library_idbfs.js', 'library_memfs.js', 'library_nodefs.js', 'library_sockfs.js', 'library_tty.js', 'library_browser.js', 'library_sdl.js', 'library_gl.js', 'library_glut.js', 'library_xlib.js', 'library_egl.js', 'library_gc.js', 'library_jansson.js', 'library_openal.js', 'library_glfw.js', 'library_uuid.js'].concat(additionalLibraries);
for (var i = 0; i < libraries.length; i++) {
eval(processMacros(preprocess(read(libraries[i]))));
}
diff --git a/src/parseTools.js b/src/parseTools.js
index 655248b3..4d6d7bd3 100644
--- a/src/parseTools.js
+++ b/src/parseTools.js
@@ -49,7 +49,8 @@ function preprocess(text) {
showStack.push(ident in this && this[ident] > 0);
}
} else if (line[2] == 'n') { // include
- ret += '\n' + read(line.substr(line.indexOf(' ')+1)) + '\n'
+ var included = read(line.substr(line.indexOf(' ')+1));
+ ret += '\n' + preprocess(included) + '\n'
}
} else if (line[2] == 'l') { // else
showStack.push(!showStack.pop());
@@ -1639,7 +1640,10 @@ function getFastValue(a, op, b, type) {
}
function getFastValues(list, op, type) {
- assert(op == '+');
+ assert(op === '+' && type === 'i32');
+ for (var i = 0; i < list.length; i++) {
+ if (isNumber(list[i])) list[i] = (list[i]|0) + '';
+ }
var changed = true;
while (changed) {
changed = false;
@@ -1647,6 +1651,7 @@ function getFastValues(list, op, type) {
var fast = getFastValue(list[i], op, list[i+1], type);
var raw = list[i] + op + list[i+1];
if (fast.length < raw.length || fast.indexOf(op) < 0) {
+ if (isNumber(fast)) fast = (fast|0) + '';
list[i] = fast;
list.splice(i+1, 1);
i--;
diff --git a/src/settings.js b/src/settings.js
index 753e2367..04b2cc79 100644
--- a/src/settings.js
+++ b/src/settings.js
@@ -156,6 +156,8 @@ var OUTLINING_LIMIT = 0; // A function size above which we try to automatically
// with, but something around 20,000 to 100,000 might make sense.
// (The unit size is number of AST nodes.)
+var AGGRESSIVE_VARIABLE_ELIMINATION = 0; // Run aggressiveVariableElimination in js-optimizer.js
+
// Generated code debugging options
var SAFE_HEAP = 0; // Check each write to the heap, for example, this will give a clear
// error on what would be segfaults in a native build (like deferencing
diff --git a/src/struct_info.json b/src/struct_info.json
index c136cc8b..a22851b6 100644
--- a/src/struct_info.json
+++ b/src/struct_info.json
@@ -1061,5 +1061,17 @@
"patch"
]
}
+ },
+ {
+ "file": "uuid/uuid.h",
+ "defines": [
+ "UUID_VARIANT_NCS",
+ "UUID_VARIANT_DCE",
+ "UUID_VARIANT_MICROSOFT",
+ "UUID_VARIANT_OTHER",
+ "UUID_TYPE_DCE_TIME",
+ "UUID_TYPE_DCE_RANDOM"
+ ],
+ "structs": {}
}
]