-
Notifications
You must be signed in to change notification settings - Fork 3
Mjo analysis
Compiled .mjo
scripts are very literal when translated into instructions. There are no optimizations (with one exception of the switch
instruction).
Because of this, and also because of the line
instructions, there are a lot of hints that make it easy to price back the original source code.
Lines are marked in every file, regardless of the #use_readflg
preprocessor option. This is because they are also used by the Majiro debugger for handling breakpoints.
Line instructions appear when:
- block closing (
}
brace) -
case
labels - Function signatures
They do not appear for:
- Named labels
- Anything in global scope (besides function signatures)
- Empty/white space lines
- Lines with only comments
- Preprocessors (
#if
/#else
/#endif
/etc.) -
setskip {
block opening
Switches can take two forms:
- The actual
switch
instruction - Or the
br.case
instruction set:-
switch:
br.case
-
case:
bne.case
-
range:
blt.case
,ble.case
,bgt.case
,bge.case
-
switch:
(These will eventually be moved to their own sections)
while
and for
loops use brfalse
, do ... while
loops use brtrue
.
some notes:
- If a block ends in
brtrue
, it must be the condition block of ado ... while
loop. In this case the jump target must always be a dominator of the condition block (i.e. a block that is executed first on every path from the function entry to the condition block). - If a block ends in
brfalse
and contains anything except the condition evaluation, it must be the condition block of anif
statement or a?:
expression. The condition block must be a dominator of the jump target. Whether it is part of a?:
expression can be determined by observing whether the merge block contains any phi nodes. - If a block ends in
brfalse
and has exactly one predecessor, it must also be anif
or?:
condition. - If a block ends in
brfalse
and has exactly two predecessors, it could either be the condition of anif
or condition immediately preceded by another if statement, or the condition of awhile
loop. In the case of a while loop there must exist a path from the fall-through block of the condition to one of the predecessors, which does not pass through the other predecessor.
Block A "dominates" block B if A is always executed before B on every possible execution path.
That relationship is commonly used in all sorts of static analyses.