remove obsolete fastops; generalize load with parseLLVM/finalizeLLVM; fix issue 14
This commit is contained in:
Родитель
77cacaa2fd
Коммит
bcdfcfbfed
|
@ -258,12 +258,12 @@ function analyzer(data) {
|
|||
|
||||
// Normal variables
|
||||
func.lines.forEach(function(item) {
|
||||
if (item.intertype in set('assign', 'fastgetelementptrload')) {
|
||||
if (item.intertype === 'assign') {
|
||||
if (!item.value.tokens.slice(-1)[0].item) throw 'Did you run llvm-dis with -show-annotations?';
|
||||
func.variables[item.ident] = {
|
||||
ident: item.ident,
|
||||
type: item.value.type,
|
||||
origin: item.intertype === 'assign' ? item.value.intertype : 'fastgetelementptrload',
|
||||
origin: item.value.intertype,
|
||||
lineNum: item.lineNum,
|
||||
uses: parseInt(item.value.tokens.slice(-1)[0].item.tokens[0].text.split('=')[1])
|
||||
};
|
||||
|
@ -314,8 +314,7 @@ function analyzer(data) {
|
|||
//print(dump(line))
|
||||
if (line.intertype == 'store' && line.ident == vname) {
|
||||
variable.stores ++;
|
||||
} else if ((line.intertype == 'assign' && line.value.intertype == 'load' && line.value.ident == vname) ||
|
||||
(line.intertype == 'fastgetelementptrload' && line.ident == vname)) {
|
||||
} else if (line.intertype == 'assign' && line.value.intertype == 'load' && line.value.ident == vname) {
|
||||
variable.loads ++;
|
||||
}
|
||||
});
|
||||
|
|
|
@ -494,38 +494,20 @@ function intertyper(data, parseFunctions, baseLineNum) {
|
|||
});
|
||||
|
||||
substrate.addActor('Reintegrator', makeReintegrator(function(parent, child) {
|
||||
// Special re-integration behaviors
|
||||
if (child.intertype == 'fastgetelementptrload') {
|
||||
parent.intertype = 'fastgetelementptrload';
|
||||
}
|
||||
this.forwardItem(parent, '/dev/stdout');
|
||||
}));
|
||||
|
||||
// 'load'
|
||||
substrate.addActor('Load', {
|
||||
processItem: function(item) {
|
||||
item.intertype = 'load';
|
||||
if (item.tokens[0].text == 'volatile') item.tokens.shift(0);
|
||||
item.pointerType = item.tokens[1].text;
|
||||
item.valueType = item.type = removePointing(item.pointerType);
|
||||
Types.needAnalysis[item.type] = 0;
|
||||
if (item.tokens[2].text == 'getelementptr') {
|
||||
var last = getTokenIndexByText(item.tokens, ';');
|
||||
var data = parseLLVMFunctionCall(item.tokens.slice(1, last));
|
||||
item.intertype = 'fastgetelementptrload';
|
||||
item.type = data.type;
|
||||
item.params = data.params;
|
||||
item.pointer = data.ident;
|
||||
item.value = data.value;
|
||||
} else {
|
||||
item.intertype = 'load';
|
||||
if (item.tokens[2].text == 'bitcast') {
|
||||
item.pointer = item.tokens[3].item.tokens[1].text;
|
||||
item.originalType = item.tokens[3].item.tokens[0].text;
|
||||
} else {
|
||||
item.pointer = item.tokens[2].text;
|
||||
}
|
||||
}
|
||||
item.ident = toNiceIdent(item.pointer);
|
||||
var last = getTokenIndexByText(item.tokens, ';');
|
||||
item.pointer = parseLLVMSegment(item.tokens.slice(1, last)); // TODO: Use this everywhere else too
|
||||
item.ident = item.pointer.ident || null;
|
||||
this.forwardItem(item, 'Reintegrator');
|
||||
}
|
||||
});
|
||||
|
|
|
@ -632,13 +632,13 @@ function JSify(data, functionsOnly, givenFunctions, givenGlobalVariables) {
|
|||
return ret;
|
||||
});
|
||||
makeFuncLineActor('load', function(item) {
|
||||
var ident = toNiceIdent(item.ident);
|
||||
var impl = getVarImpl(item.funcData, item.ident);
|
||||
var value = finalizeLLVMParameter(item.pointer);
|
||||
var impl = item.ident ? getVarImpl(item.funcData, item.ident) : VAR_EMULATED;
|
||||
switch (impl) {
|
||||
case VAR_NATIVIZED: {
|
||||
return ident; // We have the actual value here
|
||||
return value; // We have the actual value here
|
||||
}
|
||||
case VAR_EMULATED: return makeGetValue(ident, null, item.type);
|
||||
case VAR_EMULATED: return makeGetValue(value, null, item.type);
|
||||
default: throw "unknown [load] impl: " + impl;
|
||||
}
|
||||
});
|
||||
|
@ -722,15 +722,6 @@ function JSify(data, functionsOnly, givenFunctions, givenGlobalVariables) {
|
|||
return makeFunctionCall(item.ident, item.params, item.funcData) + (item.standalone ? ';' : '');
|
||||
});
|
||||
|
||||
// Optimized intertypes
|
||||
|
||||
makeFuncLineActor('fastgetelementptrload', function(item) {
|
||||
return 'var ' + item.ident + '=' + makeGetValue(parseNumerical(item.value.ident), getGetElementPtrIndexes(item.value), item.value.valueType, true) + ';';
|
||||
});
|
||||
makeFuncLineActor('fastgetelementptrstore', function(item) {
|
||||
return makeSetValue(item.value.ident, getGetElementPtrIndexes(item.value), parseNumerical(item.ident), item.type, true) + ';';
|
||||
});
|
||||
|
||||
makeFuncLineActor('unreachable', function(item) { return 'throw "Reached an unreachable! Original .ll line: ' + item.lineNum + '";' });
|
||||
|
||||
// Final combiner
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
; ModuleID = '/dev/shm/tmp/src.cpp.o'
|
||||
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-f128:128:128-n8:16:32"
|
||||
target triple = "i386-pc-linux-gnu"
|
||||
|
||||
%struct.CPU_Regs = type { [8 x %union.GenReg32] }
|
||||
%union.GenReg32 = type { [1 x i32] }
|
||||
|
||||
@cpu_regs = unnamed_addr global %struct.CPU_Regs zeroinitializer, align 32 ; [#uses=2]
|
||||
@.str = private unnamed_addr constant [14 x i8] c"hello, world!\00", align 1 ; [#uses=1]
|
||||
|
||||
; [#uses=0]
|
||||
define i32 @main() {
|
||||
entry:
|
||||
%retval = alloca i32 ; [#uses=2]
|
||||
%0 = alloca i32 ; [#uses=2]
|
||||
%"alloca point" = bitcast i32 0 to i32 ; [#uses=0]
|
||||
%1 = load i16* bitcast (i32* getelementptr inbounds (%struct.CPU_Regs* @cpu_regs, i32 0, i32 0, i32 1, i32 0, i32 0) to i16*), align 2 ; [#uses=1]
|
||||
store i16 %1, i16* bitcast (%struct.CPU_Regs* @cpu_regs to i16*), align 2
|
||||
%2 = call i32 @puts(i8* getelementptr inbounds ([14 x i8]* @.str, i32 0, i32 0)) ; [#uses=0]
|
||||
store i32 0, i32* %0, align 4
|
||||
%3 = load i32* %0, align 4 ; [#uses=1]
|
||||
store i32 %3, i32* %retval, align 4
|
||||
br label %return
|
||||
|
||||
return: ; preds = %entry
|
||||
%retval1 = load i32* %retval ; [#uses=1]
|
||||
ret i32 %retval1
|
||||
}
|
||||
|
||||
; [#uses=1]
|
||||
declare i32 @puts(i8*)
|
Загрузка…
Ссылка в новой задаче