diff options
author | alon@honor <none@none> | 2010-10-24 22:49:26 -0700 |
---|---|---|
committer | alon@honor <none@none> | 2010-10-24 22:49:26 -0700 |
commit | 7c56be83f6807300aac5ab4de79f7754bf9c0eb2 (patch) | |
tree | 694cadc51daab4852617ac2f85d0ee39c8baaea9 | |
parent | 1522f18aab92cfa3e9a58e1eefc40aefcfdc946c (diff) |
progress on cleaning up Runtime
-rw-r--r-- | src/analyzer.js | 2 | ||||
-rw-r--r-- | src/intertyper.js | 4 | ||||
-rw-r--r-- | src/jsifier.js | 10 | ||||
-rw-r--r-- | src/parseTools.js | 13 | ||||
-rw-r--r-- | src/preamble.js | 9 | ||||
-rw-r--r-- | src/runtime.js | 33 |
6 files changed, 36 insertions, 35 deletions
diff --git a/src/analyzer.js b/src/analyzer.js index 61dfbcca..671ba85a 100644 --- a/src/analyzer.js +++ b/src/analyzer.js @@ -84,7 +84,7 @@ function analyzer(data) { if (type.length == 1) return; if (data.types[type]) return; if (['internal', 'inbounds', 'void'].indexOf(type) != -1) return; - if (isNumberType(type)) return; + if (Runtime.isNumberType(type)) return; // 'blocks': [14 x %struct.X] etc. If this is a pointer, we need // to look at the underlying type - it was not defined explicitly diff --git a/src/intertyper.js b/src/intertyper.js index ee59237e..08b40157 100644 --- a/src/intertyper.js +++ b/src/intertyper.js @@ -264,7 +264,7 @@ function intertyper(data) { } if (item.tokens[2].text == 'type') { var fields = []; - if (isNumberType(item.tokens[3].text)) { + if (Runtime.isNumberType(item.tokens[3].text)) { // Clang sometimes has |= i32| instead of |= { i32 }| fields = [item.tokens[3].text]; } else if (item.tokens[3].text != 'opaque') { @@ -510,7 +510,7 @@ function intertyper(data) { processItem: function(item) { item.intertype = 'alloca'; item.allocatedType = item.tokens[1].text; - item.allocatedNum = isNumberType(item.tokens[3].text) ? toNiceIdent(item.tokens[4].text) : 1; + item.allocatedNum = Runtime.isNumberType(item.tokens[3].text) ? toNiceIdent(item.tokens[4].text) : 1; item.type = addPointing(item.tokens[1].text); // type of pointer we will get item.type2 = item.tokens[1].text; // value we will create, and get a pointer to this.forwardItem(item, 'Reintegrator'); diff --git a/src/jsifier.js b/src/jsifier.js index 8880e3e8..8662f523 100644 --- a/src/jsifier.js +++ b/src/jsifier.js @@ -37,9 +37,9 @@ function JSify(data) { if (!USE_TYPED_ARRAYS) { return 'HEAP'; } else { - if (type in FLOAT_TYPES || type === 'int64') { + if (type in Runtime.FLOAT_TYPES || type === 'int64') { return 'FHEAP'; - } else if (type in INT_TYPES || isPointerType(type)) { + } else if (type in Runtime.INT_TYPES || isPointerType(type)) { return 'IHEAP'; } else { return 'HEAP'; @@ -119,7 +119,7 @@ function JSify(data) { // Gets an entire constant expression function parseConst(value, type) { dprint('gconst', '//yyyyy ' + JSON.stringify(value) + ',' + type + '\n'); - if (isNumberType(type) || pointingLevels(type) == 1) { + if (Runtime.isNumberType(type) || pointingLevels(type) == 1) { return makePointer(indexizeFunctions(parseNumerical(toNiceIdent(value.text))), null, 'ALLOC_STATIC', type); } else if (value.text == 'zeroinitializer') { return makePointer(JSON.stringify(makeEmptyStruct(type)), null, 'ALLOC_STATIC', type); @@ -626,7 +626,7 @@ function JSify(data) { }); function makeUnSign(value, type) { - if (type in INT_TYPES) { + if (type in Runtime.INT_TYPES) { return 'unSign(' + value + ', ' + type.substr(1) + ')'; } else { return value; @@ -885,6 +885,6 @@ function JSify(data) { substrate.addItems(data.functionStubs, 'FunctionStub'); var params = { 'QUANTUM_SIZE': QUANTUM_SIZE }; - return preprocess(read('preamble.js') + getRuntime() + finalCombiner(substrate.solve()) + read('postamble.js'), params); + return preprocess(read('preamble.js').replace('{{RUNTIME}}', getRuntime()) + finalCombiner(substrate.solve()) + read('postamble.js'), params); } diff --git a/src/parseTools.js b/src/parseTools.js index 1e14b1ea..fed60d77 100644 --- a/src/parseTools.js +++ b/src/parseTools.js @@ -59,13 +59,6 @@ function toNiceIdent(ident) { return ident.replace(/[" \.@%:<>,\*\[\]-]/g, '_'); } -INT_TYPES = searchable('i1', 'i8', 'i16', 'i32', 'i64'); -FLOAT_TYPES = searchable('float', 'double'); - -function isNumberType(type) { - return type in INT_TYPES || type in FLOAT_TYPES; -} - function isStructPointerType(type) { // This test is necessary for clang - in llvm-gcc, we // could check for %struct. The downside is that %1 can @@ -75,14 +68,14 @@ function isStructPointerType(type) { // we must check later on, in call(), where we have more // context, to differentiate such cases. // A similar thing happns in isStructType() - return !isNumberType(type) && type[0] == '%'; + return !Runtime.isNumberType(type) && type[0] == '%'; } function isStructType(type) { if (isPointerType(type)) return false; if (new RegExp(/^\[\d+\ x\ (.*)\]/g).test(type)) return true; // [15 x ?] blocks. Like structs // See comment in isStructPointerType() - return !isNumberType(type) && type[0] == '%'; + return !Runtime.isNumberType(type) && type[0] == '%'; } function isPointerType(type) { @@ -119,7 +112,7 @@ function isFunctionType(type) { } function isType(type) { // TODO! - return isVoidType(type) || isNumberType(type) || isStructType(type) || isPointerType(type) || isFunctionType(type); + return isVoidType(type) || Runtime.isNumberType(type) || isStructType(type) || isPointerType(type) || isFunctionType(type); } function addIdent(token) { diff --git a/src/preamble.js b/src/preamble.js index fae4c714..6a1f897c 100644 --- a/src/preamble.js +++ b/src/preamble.js @@ -1,11 +1,10 @@ // === Auto-generated preamble library stuff === +{{RUNTIME}} + function __globalConstructor__() { } -// This way of accessing is faster than adding |Runtime.| everywhere -Runtime = this; - // Maps ints ==> functions. This lets us pass around ints, which are // actually pointers to functions, and we convert at call()time FUNCTION_TABLE = []; @@ -75,7 +74,7 @@ function Pointer_make(slab, pos, allocator) { } var slab = flatten(slab); // Finalize - var ret = [_malloc, stackAlloc, staticAlloc][allocator ? allocator : ALLOC_STATIC](Math.max(slab.length - pos, 1)); + var ret = [_malloc, Runtime.stackAlloc, Runtime.staticAlloc][allocator ? allocator : ALLOC_STATIC](Math.max(slab.length - pos, 1)); for (var i = 0; i < slab.length - pos; i++) { var curr = slab[pos + i]; if (typeof curr === 'function') { @@ -126,7 +125,7 @@ function alignMemoryPage(x) { // If we don't have malloc/free implemented, use a simple implementation. if (!this._malloc) { - _malloc = staticAlloc; + _malloc = Runtime.staticAlloc; _free = function() { }; // leak! } diff --git a/src/runtime.js b/src/runtime.js index c8c57244..93688584 100644 --- a/src/runtime.js +++ b/src/runtime.js @@ -70,17 +70,24 @@ Runtime = { staticAlloc: unInline('staticAlloc', ['size']), alignMemory: unInline('alignMemory', ['size', 'quantum']), - FUNCTION_TABLE: [], getFunctionIndex: function getFunctionIndex(func) { - var key = Runtime.FUNCTION_TABLE.length; + var key = FUNCTION_TABLE.length; FUNCTION_TABLE[key] = func; FUNCTION_TABLE[key+1] = null; // Need to have keys be even numbers, see |polymorph| test return key; }, // TODO: cleanup - isNumberType: isNumberType, - INT_TYPES: INT_TYPES, + isNumberType: function(type) { + return type in Runtime.INT_TYPES || type in Runtime.FLOAT_TYPES; + }, + + isPointerType: isPointerType, + isStructType: isStructType, + + INT_TYPES: set('i1', 'i8', 'i16', 'i32', 'i64'), + FLOAT_TYPES: set('float', 'double'), + getNativeFieldSize: getNativeFieldSize, dedup: dedup, @@ -93,10 +100,10 @@ Runtime = { var prev = -1, maxSize = -1; type.flatIndexes = type.fields.map(function(field) { var size; - if (isNumberType(field) || isPointerType(field)) { - size = getNativeFieldSize(field, true); // pack char; char; in structs, also char[X]s. + if (Runtime.isNumberType(field) || Runtime.isPointerType(field)) { + size = Runtime.getNativeFieldSize(field, true); // pack char; char; in structs, also char[X]s. maxSize = Math.max(maxSize, size); - } else if (isStructType(field)) { + } else if (Runtime.isStructType(field)) { size = otherTypes[field].flatSize; maxSize = Math.max(maxSize, QUANTUM_SIZE); } else { @@ -114,7 +121,7 @@ Runtime = { type.flatSize = Runtime.alignMemory(type.flatSize, maxSize); if (diffs.length == 0) { type.flatFactor = type.flatSize; - } else if (dedup(diffs).length == 1) { + } else if (Runtime.dedup(diffs).length == 1) { type.flatFactor = diffs[0]; } type.needsFlattening = (this.flatFactor != 1); @@ -124,15 +131,17 @@ Runtime = { }; function getRuntime() { - var ret = ''; + var ret = 'Runtime = {\n'; for (i in Runtime) { var item = Runtime[i]; + ret += ' ' + i + ': '; if (typeof item === 'function') { - ret += item.toString() + '\n'; + ret += item.toString(); } else { - ret += 'var ' + i + ' = ' + JSON.stringify(item) + ';\n'; + ret += JSON.stringify(item); } + ret += ',\n'; } - return ret + '\n'; + return ret + '}\n'; } |