-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[move-decompiler] Improvements to the astifier
This PR implements some major improvements to the astifier: - Finally (I think) cracked the way how to do correct topological sorting and managing nested blocks. More complicated examples now produce more reasonable results. - Rewrote AST transformations for if-then-else and loops. - Fixed issues with the fixpoint analysis on the AST - Did some minor fixes in the sourcifier The generated source is still not correct in some cases, but much better then before.
- Loading branch information
Showing
28 changed files
with
2,613 additions
and
1,116 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
160 changes: 160 additions & 0 deletions
160
third_party/move/move-model/bytecode/ast-generator-tests/tests/abort_example.exp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
|
||
=== Processing m::f ===================================================== | ||
--- Source | ||
public fun f(length: u64): u64 { | ||
assert!(length > 0, 1); | ||
assert!(length < 100, 2); | ||
let counter = 0; | ||
while (counter < length) counter += 1; | ||
counter | ||
} | ||
|
||
--- Stackless Bytecode | ||
public fun m::f($t0|length: u64): u64 { | ||
var $t1|$t3: u64 | ||
var $t2|$t11: u64 [unused] | ||
var $t3: u64 | ||
var $t4: u64 | ||
var $t5: bool | ||
var $t6: u64 | ||
var $t7: u64 | ||
var $t8: u64 | ||
var $t9: bool | ||
var $t10: u64 | ||
var $t11: u64 | ||
var $t12: u64 | ||
var $t13: u64 | ||
var $t14: bool | ||
var $t15: u64 | ||
var $t16: u64 | ||
var $t17: u64 | ||
var $t18: u64 | ||
0: $t3 := copy($t0) | ||
1: $t4 := 0 | ||
2: $t5 := >($t3, $t4) | ||
3: if ($t5) goto 4 else goto 6 | ||
4: label L1 | ||
5: goto 9 | ||
6: label L0 | ||
7: $t6 := 1 | ||
8: abort($t6) | ||
9: label L2 | ||
10: $t7 := copy($t0) | ||
11: $t8 := 100 | ||
12: $t9 := <($t7, $t8) | ||
13: if ($t9) goto 14 else goto 16 | ||
14: label L4 | ||
15: goto 19 | ||
16: label L3 | ||
17: $t10 := 2 | ||
18: abort($t10) | ||
19: label L5 | ||
20: $t11 := 0 | ||
21: $t1 := $t11 | ||
22: goto 23 | ||
23: label L10 | ||
24: $t12 := copy($t1) | ||
25: $t13 := copy($t0) | ||
26: $t14 := <($t12, $t13) | ||
27: if ($t14) goto 28 else goto 34 | ||
28: label L7 | ||
29: $t15 := move($t1) | ||
30: $t16 := 1 | ||
31: $t17 := +($t15, $t16) | ||
32: $t1 := $t17 | ||
33: goto 36 | ||
34: label L6 | ||
35: goto 38 | ||
36: label L8 | ||
37: goto 23 | ||
38: label L9 | ||
39: $t18 := move($t1) | ||
40: return $t18 | ||
} | ||
|
||
--- Raw Generated AST | ||
_t3: u64 = length; | ||
_t4: u64 = 0; | ||
_t5: bool = Gt(_t3, _t4); | ||
loop { | ||
if (_t5) break; | ||
_t6: u64 = 1; | ||
Abort(_t6) | ||
}; | ||
_t7: u64 = length; | ||
_t8: u64 = 100; | ||
_t9: bool = Lt(_t7, _t8); | ||
loop { | ||
if (_t9) break; | ||
_t10: u64 = 2; | ||
Abort(_t10) | ||
}; | ||
_t11: u64 = 0; | ||
_t1: u64 = _t11; | ||
loop { | ||
_t12: u64 = _t1; | ||
_t13: u64 = length; | ||
_t14: bool = Lt(_t12, _t13); | ||
if (Not(_t14)) break; | ||
_t15: u64 = _t1; | ||
_t16: u64 = 1; | ||
_t17: u64 = Add(_t15, _t16); | ||
_t1: u64 = _t17; | ||
continue | ||
}; | ||
_t18: u64 = _t1; | ||
return _t18 | ||
|
||
--- Assign-Transformed Generated AST | ||
loop { | ||
if (Gt(length, 0)) break; | ||
Abort(1) | ||
}; | ||
loop { | ||
if (Lt(length, 100)) break; | ||
Abort(2) | ||
}; | ||
_t1: u64 = 0; | ||
loop { | ||
if (Not(Lt(_t1, length))) break; | ||
_t1: u64 = Add(_t1, 1); | ||
continue | ||
}; | ||
return _t1 | ||
|
||
--- If-Transformed Generated AST | ||
if (Not(Gt(length, 0))) Abort(1); | ||
if (Not(Lt(length, 100))) Abort(2); | ||
_t1: u64 = 0; | ||
loop { | ||
if (Not(Lt(_t1, length))) break; | ||
_t1: u64 = Add(_t1, 1); | ||
continue | ||
}; | ||
return _t1 | ||
|
||
--- Var-Bound Generated AST | ||
{ | ||
let _t1: u64; | ||
if (Not(Gt(length, 0))) Abort(1); | ||
if (Not(Lt(length, 100))) Abort(2); | ||
_t1: u64 = 0; | ||
loop { | ||
if (Not(Lt(_t1, length))) break; | ||
_t1: u64 = Add(_t1, 1); | ||
continue | ||
}; | ||
return _t1 | ||
} | ||
|
||
=== Sourcified Output ============================================ | ||
module 0x815::m { | ||
public fun f(length: u64): u64 { | ||
let _t1; | ||
if (!(length > 0)) abort 1; | ||
if (!(length < 100)) abort 2; | ||
_t1 = 0; | ||
while (_t1 < length) _t1 = _t1 + 1; | ||
_t1 | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
third_party/move/move-model/bytecode/ast-generator-tests/tests/abort_example.move
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module 0x815::m { | ||
public fun f(length: u64): u64 { | ||
assert!(length > 0, 1); | ||
assert!(length < 100, 2); | ||
let counter = 0; | ||
while (counter < length) counter += 1; | ||
counter | ||
} | ||
} |
Oops, something went wrong.