Commit faa838cf authored by Julian Kranz's avatar Julian Kranz

Liveness

parent 2d72db89
export = tinsng
export = tinsng turner
val arch-show-id x = case 0 of 1: "" end
......@@ -10,12 +10,27 @@ val test-instructions-0 = do
t2 <- mktemp;
mov 1 t0 (imm 3);
mov 1 t1 (imm 4);
mov 1 t2 (imm 5);
# mov 1 t1 (imm 4);
mov 8 t2 (imm 5);
mov 8 (at-offset t2 20) (imm 5);
print t0;
#_while (/d (var (at-offset t0 99))) __ do
# mov 1 (at-offset t0 33) (var (at-offset t1 33));
add 1 t0 (var t1) (var t2);
# mov 32 t1 (imm 888);
# mov 32 t2 (imm 888)
#end;
mov 32 t2 (imm 888);
_if (/d (var t0)) _then do
mov 1 (at-offset t0 33) (var (at-offset t1 88));
mov 32 t2 (imm 888)
end _else do
mov 1 (at-offset t0 33) (var (at-offset t1 107));
mov 32 t1 (imm 888)
end;
add 32 t0 (var t1) (var t2);
mov 1 t0 (imm 42)
end
......@@ -24,5 +39,11 @@ val tinsng = do
update@{stack=SEM_NIL,tmp=TLIST_NIL};
test-instructions-0;
stack <- query $stack;
return (rreil-stmts-rev stack)
lv-state <- lv-analyze stack;
#print (lv-pretty lv-state.greedy);
#return (("Hallo :-)" +++ "fasel"))
#return (rreil-stmts-rev stack)
return lv-state.conservative
end
val turner x = x
......@@ -10,7 +10,7 @@ export =
lv-union
lv-pretty
lv-analyze
lvstate-pretty
# lvstate-pretty
# lv-sweep-and-collect-upto-native-flow
val lv-kill kills stmt =
......@@ -90,6 +90,8 @@ val lv-gen gens stmt =
SEM_ASSIGN x: visit-op gens x.rhs
| SEM_LOAD x: visit-address gens x.address
| SEM_STORE x: visit-address gens x.address
| SEM_WHILE x: visit-lin gens 1 x.cond
| SEM_ITE x: visit-lin gens 1 x.cond
# | SEM_LABEL x: gens
# | SEM_IF_GOTO_LABEL x: visit-lin gens 1 x.cond
# | SEM_IF_GOTO x: visit-flow gens x
......@@ -233,6 +235,19 @@ val lv-analyze stack =
do lv-push-live x.hd;
sweep x.tl (lvstate-eval state x.hd)
end
| SEM_WHILE y: do
lv-push-live x.hd;
body-state <- sweep y.body (lvstate-empty y.body);
state-new <- return (lvstate-union state body-state);
sweep x.tl (lvstate-eval state-new x.hd)
end
| SEM_ITE y: do
lv-push-live x.hd;
then-state <- sweep y.then_branch (lvstate-empty y.then_branch);
else-state <- sweep y.else_branch (lvstate-empty y.else_branch);
state-new <- return (lvstate-union state (lvstate-union then-state else-state));
sweep x.tl (lvstate-eval state-new x.hd)
end
# | SEM_IF_GOTO y:
# do lv-push-live x.hd;
# sweep x.tl (lvstate-eval state x.hd)
......
......@@ -225,6 +225,118 @@ val cbranch cond target-true target-false = do
push (/CBRANCH cond target-true target-false)
end
val _if c _then a _else b = do
c <- with-subscope c;
stack <- pop-all;
with-subscope a;
t <- pop-all;
t <- return (rreil-stmts-rev t);
with-subscope b;
e <- pop-all;
e <- return (rreil-stmts-rev e);
stack-set stack;
ite c t e
end
val _if c _then a = do
_if c _then a _else (return void)
end
val _while c __ b = let
val eval-cond ct = do
cc <- c;
mov 1 ct cc
end
in do
ct <- mktemp;
with-subscope (eval-cond ct);
stack <- pop-all;
with-subscope b;
with-subscope (eval-cond ct);
body <- pop-all;
body <- return (rreil-stmts-rev body);
stack-set stack;
while (var ct) body
end end
val /d cond = return cond
val /and a b = do
a <- a;
b <- b;
t <- mktemp;
andb 1 t a b;
return (var t)
end
val /or a b = do
a <- a;
b <- b;
t <- mktemp;
orb 1 t a b;
return (var t)
end
val /not a = do
t <- mktemp;
xorb 1 t a (imm 1);
return (var t)
end
val /eq sz a b = do
t <- mktemp;
cmpeq sz t a b;
return (var t)
end
val /neq sz a b = do
t <- mktemp;
cmpneq sz t a b;
return (var t)
end
val /gtu sz a b = do
t <- mktemp;
cmpleu sz t a b;
xorb 1 t (var t) (imm 1);
return (var t)
end
val /gts sz a b = do
t <- mktemp;
cmples sz t a b;
xorb 1 t (var t) (imm 1);
return (var t)
end
val /geu sz a b = do
t <- mktemp;
cmpltu sz t a b;
xorb 1 t (var t) (imm 1);
return (var t)
end
val /lts sz a b = do
t <- mktemp;
cmplts sz t a b;
return (var t)
end
val /ltu sz a b = do
t <- mktemp;
cmpltu sz t a b;
return (var t)
end
val /leu sz a b = do
t <- mktemp;
cmpleu sz t a b;
return (var t)
end
val const i = return (SEM_LIN_IMM{imm=i})
val imm i = SEM_LIN_IMM{imm=i}
......
......@@ -32,7 +32,8 @@ int main (int argc, char** argv) {
size_t size = 256*1024;
char fmt[size];
__pretty(__rreil_pretty__,r,fmt,size);
//__pretty(__rreil_pretty__,r,fmt,size);
__pretty(__lv_pretty__,r,fmt,size);
puts(fmt);
return 1;
......
......@@ -370,118 +370,6 @@ val fLTU = return (_var VIRT_LTU)
val zero = return (SEM_LIN_IMM{imm=0})
val _if c _then a _else b = do
c <- with-subscope c;
stack <- pop-all;
with-subscope a;
t <- pop-all;
t <- return (rreil-stmts-rev t);
with-subscope b;
e <- pop-all;
e <- return (rreil-stmts-rev e);
stack-set stack;
ite c t e
end
val _if c _then a = do
_if c _then a _else (return void)
end
val _while c __ b = let
val eval-cond ct = do
cc <- c;
mov 1 ct cc
end
in do
ct <- mktemp;
with-subscope (eval-cond ct);
stack <- pop-all;
with-subscope b;
with-subscope (eval-cond ct);
body <- pop-all;
body <- return (rreil-stmts-rev body);
stack-set stack;
while (var ct) body
end end
val /d cond = return cond
val /and a b = do
a <- a;
b <- b;
t <- mktemp;
andb 1 t a b;
return (var t)
end
val /or a b = do
a <- a;
b <- b;
t <- mktemp;
orb 1 t a b;
return (var t)
end
val /not a = do
t <- mktemp;
xorb 1 t a (imm 1);
return (var t)
end
val /eq sz a b = do
t <- mktemp;
cmpeq sz t a b;
return (var t)
end
val /neq sz a b = do
t <- mktemp;
cmpneq sz t a b;
return (var t)
end
val /gtu sz a b = do
t <- mktemp;
cmpleu sz t a b;
xorb 1 t (var t) (imm 1);
return (var t)
end
val /gts sz a b = do
t <- mktemp;
cmples sz t a b;
xorb 1 t (var t) (imm 1);
return (var t)
end
val /geu sz a b = do
t <- mktemp;
cmpltu sz t a b;
xorb 1 t (var t) (imm 1);
return (var t)
end
val /lts sz a b = do
t <- mktemp;
cmplts sz t a b;
return (var t)
end
val /ltu sz a b = do
t <- mktemp;
cmpltu sz t a b;
return (var t)
end
val /leu sz a b = do
t <- mktemp;
cmpleu sz t a b;
return (var t)
end
val sem-a sem-cc x = do
cf <- fCF;
zf <- fZF;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment