Mjo analysis - AtomCrafty/MajiroTools GitHub Wiki
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.
Line instruction
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) caselabels- 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
Switch instructions
Switches can take two forms:
- The actual
switchinstruction - Or the
br.caseinstruction set:- switch:
br.case - case:
bne.case - range:
blt.case,ble.case,bgt.case,bge.case
- switch:
Unsorted notes
(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 ... whileloop. 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
brfalseand contains anything except the condition evaluation, it must be the condition block of anifstatement 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
brfalseand has exactly one predecessor, it must also be anifor?:condition. - If a block ends in
brfalseand has exactly two predecessors, it could either be the condition of anifor condition immediately preceded by another if statement, or the condition of awhileloop. 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.
Term: "dominates"
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.