diff options
-rw-r--r-- | src/parseTools.js | 25 | ||||
-rw-r--r-- | tests/cases/ptrtoi64.ll | 8 | ||||
-rw-r--r-- | tests/cases/ptrtoi64.txt | 2 |
3 files changed, 18 insertions, 17 deletions
diff --git a/src/parseTools.js b/src/parseTools.js index 88c7ce68..75c827bc 100644 --- a/src/parseTools.js +++ b/src/parseTools.js @@ -463,8 +463,7 @@ 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'); + } else if (segment[2].item.tokens.slice(-2)[0].text === 'to') { type = segment[2].item.tokens.slice(-1)[0].text; } } @@ -1586,7 +1585,7 @@ function processMathop(item) { if (item.type[0] === 'i') { bits = parseInt(item.type.substr(1)); } - var bitsLeft = item.param2 ? item.param2.ident.substr(1) : null; // remove i to leave number. This value is important in float ops + var bitsLeft = parseInt((item.param2 ? item.param2.ident : item.type).substr(1)); // remove i to leave the number of bits left after this operation function integerizeBignum(value) { return makeInlineCalculation('VALUE-VALUE%1', value, 'tempBigIntI'); @@ -1768,14 +1767,6 @@ function processMathop(item) { // then unsigning that i32... which would give something huge. case 'zext': case 'fpext': case 'sext': return ident1; case 'fptrunc': return ident1; - case 'trunc': { - // Unlike extending, which we just 'do' (by doing nothing), - // truncating can change the number, e.g. by truncating to an i1 - // in order to get the first bit - assert(ident2[1] == 'i'); - assert(bitsLeft <= 32, 'Cannot truncate to more than 32 bits, since we use a native & op'); - return '((' + ident1 + ') & ' + (Math.pow(2, bitsLeft)-1) + ')'; - } case 'select': return ident1 + ' ? ' + ident2 + ' : ' + ident3; case 'ptrtoint': case 'inttoptr': { var ret = ''; @@ -1784,9 +1775,17 @@ function processMathop(item) { 'The safest thing is to investigate every appearance, and modify the source code to avoid this. ' + 'Emscripten will print a list of the .ll lines, and also annotate the .js.'); dprint(' ' + op + ' on .ll line ' + item.lineNum); - ret = ' /* Warning: ' + op + ', .ll line ' + item.lineNum + ' */'; + ident1 += ' /* Warning: ' + op + ', .ll line ' + item.lineNum + ' */'; } - return ident1 + ret; + if (op == 'inttoptr' || bitsLeft >= 32) return ident1; + // For ptrtoint and <32 bits, fall through into trunc since we need to truncate here + } + case 'trunc': { + // Unlike extending, which we just 'do' (by doing nothing), + // truncating can change the number, e.g. by truncating to an i1 + // in order to get the first bit + assert(bitsLeft <= 32, 'Cannot truncate to more than 32 bits, since we use a native & op'); + return '((' + ident1 + ') & ' + (Math.pow(2, bitsLeft)-1) + ')'; } case 'bitcast': return ident1; default: throw 'Unknown mathcmp op: ' + item.op; diff --git a/tests/cases/ptrtoi64.ll b/tests/cases/ptrtoi64.ll index a820efc4..01e466fe 100644 --- a/tests/cases/ptrtoi64.ll +++ b/tests/cases/ptrtoi64.ll @@ -4,7 +4,7 @@ target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32" target triple = "i386-pc-linux-gnu" -@.str2 = private constant [6 x i8] c"*%d*\0A\00", align 1 ; [#uses=1] +@.str2 = private constant [9 x i8] c"*%d,%d*\0A\00", align 1 ; [#uses=1] ; [#uses=1] declare i32 @puts(i8*) @@ -17,9 +17,11 @@ entry: %retval = alloca i32 ; [#uses=2] %0 = alloca i32 ; [#uses=2] %"alloca point" = bitcast i32 0 to i32 ; [#uses=0] - %sz.i7 = inttoptr i32 512 to i32* ; [#uses=1 type=i32*] + %sz.i7 = inttoptr i32 400 to i32* ; [#uses=1 type=i32*] %10 = ptrtoint i32* %sz.i7 to i64, !dbg !8557 ; [#uses=1 type=i64] [debug line = 99:3] %conv5 = trunc i64 %10 to i32, !dbg !8557 ; [#uses=1 type=i32] [debug line = 99:3] - %55 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([6 x i8]* @.str2, i32 0, i32 0), i32 %conv5) ; [#uses=0] + %11 = ptrtoint i32* %sz.i7 to i8, !dbg !8557 ; [#uses=1 type=i64] [debug line = 99:3] + %conv6 = zext i8 %11 to i32, !dbg !8557 ; [#uses=1 type=i32] [debug line = 99:3] + %55 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([9 x i8]* @.str2, i32 0, i32 0), i32 %conv5, i32 %conv6) ; [#uses=0] ret i32 0 } diff --git a/tests/cases/ptrtoi64.txt b/tests/cases/ptrtoi64.txt index 6e1c004a..605caba1 100644 --- a/tests/cases/ptrtoi64.txt +++ b/tests/cases/ptrtoi64.txt @@ -1 +1 @@ -*512* +*400,144* |