aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/compiler.js3
-rw-r--r--src/intertyper.js4
-rw-r--r--src/jsifier.js2
-rw-r--r--src/parseTools.js15
-rw-r--r--src/settings.js4
5 files changed, 24 insertions, 4 deletions
diff --git a/src/compiler.js b/src/compiler.js
index 8980da93..9bf81ba4 100644
--- a/src/compiler.js
+++ b/src/compiler.js
@@ -71,6 +71,9 @@ eval(processMacros(preprocess(read('runtime.js'))));
// Read llvm
var raw = read(ll_file);
+if (FAKE_X86_FP80) {
+ raw = raw.replace(/x86_fp80/g, 'double');
+}
var lines = raw.split('\n');
raw = null;
diff --git a/src/intertyper.js b/src/intertyper.js
index b02e3f33..83a49645 100644
--- a/src/intertyper.js
+++ b/src/intertyper.js
@@ -543,7 +543,9 @@ function intertyper(data, parseFunctions, baseLineNum) {
item.intertype = 'bitcast';
item.type = item.tokens[4].text; // The final type
Types.needAnalysis[item.type] = 0;
- item.ident = toNiceIdent(item.tokens[2].text);
+ var to = getTokenIndexByText(item.tokens, 'to');
+ item.params = [parseLLVMSegment(item.tokens.slice(2, to))];
+ item.ident = item.params[0].ident;
item.type2 = item.tokens[1].text; // The original type
Types.needAnalysis[item.type2] = 0;
this.forwardItem(item, 'Reintegrator');
diff --git a/src/jsifier.js b/src/jsifier.js
index 6720e77b..330597bf 100644
--- a/src/jsifier.js
+++ b/src/jsifier.js
@@ -758,7 +758,7 @@ function JSify(data, functionsOnly, givenFunctions, givenGlobalVariables) {
makeFuncLineActor('mathop', processMathop);
makeFuncLineActor('bitcast', function(item) {
- return item.ident;
+ return finalizeLLVMParameter(item.params[0]);
});
function makeFunctionCall(ident, params, funcData) {
diff --git a/src/parseTools.js b/src/parseTools.js
index 1c3f4dee..a3347139 100644
--- a/src/parseTools.js
+++ b/src/parseTools.js
@@ -74,7 +74,7 @@ function toNiceIdent(ident) {
assert(ident);
if (parseFloat(ident) == ident) return ident;
if (ident == 'null') return '0'; // see parseNumerical
- return ident.replace('%', '$').replace(/["&\\ \.@:<>,\*\[\]-]/g, '_');
+ return ident.replace('%', '$').replace(/["&\\ \.@:<>,\*\[\]\(\)-]/g, '_');
}
// Kind of a hack. In some cases we have strings that we do not want
@@ -431,6 +431,9 @@ function parseLLVMFunctionCall(segment) {
if (type === '?') {
if (intertype === 'getelementptr') {
type = '*'; // a pointer, we can easily say, this is
+ } else if (intertype === 'bitcast') {
+ assert(segment[2].item.tokens.slice(-2)[0].text === 'to');
+ type = segment[2].item.tokens.slice(-1)[0].text;
}
}
var ret = {
@@ -487,7 +490,15 @@ function IEEEUnHex(stringy) {
stringy = stringy.substr(2); // leading '0x';
if (stringy.replace(/0/g, '') === '') return 0;
while (stringy.length < 16) stringy = '0' + stringy;
- assert(stringy.length === 16, 'Can only unhex 16-digit double numbers, nothing platform-specific');
+ if (FAKE_X86_FP80 && stringy.length > 16) {
+ stringy = stringy.substr(stringy.length-16, 16);
+ if (!Debugging.shownIEEEUnHexWarning) {
+ dprint('WARNING: .ll contains floating-point values with more than 64 bits. Faking values for them.');
+ dprint(' If they are used, this will almost certainly fail!');
+ Debugging.shownIEEEUnHexWarning = true;
+ }
+ }
+ assert(stringy.length === 16, 'Can only unhex 16-digit double numbers, nothing platform-specific'); // |long double| can cause x86_fp80 which causes this
var top = eval('0x' + stringy[0]);
var neg = !!(top & 8); // sign
if (neg) {
diff --git a/src/settings.js b/src/settings.js
index ed3437b1..1b1665bc 100644
--- a/src/settings.js
+++ b/src/settings.js
@@ -129,6 +129,10 @@ RUNTIME_TYPE_INFO = 0; // Whether to expose type info to the script at run time.
// to more easily perform operations from handwritten JS on
// objects with structures etc.
+FAKE_X86_FP80 = 0; // Replaces x86_fp80 with double. This loses precision. It is better,
+ // if you can, to get the original source code to build without x86_fp80
+ // (which is nonportable anyhow).
+
// Compiler debugging options
DEBUG_TAGS_SHOWING = [];
// Some useful items: