flag = m20 > 0
if (flag) m222 = m3 else m222 = m4
-- convert 2-op conditional operator to 1-op <br>
removePhi [] = []<br>
removePhi ((Cmpz cond condr1) : (Phi addr r1 r2) : xs) = <br>
Noop addr : If cond condr1 addr r1 r2 : removePhi xs<br>
removePhi (x : xs) = x : removePhi xs<br>
main = do <br>
(len,buf) <- readMyFile<br>
let nframes = fromInteger $ len `div` 12 -- . <br>
-- opcode/data memory in tuples <br>
ids <- mapM ( \ i -> instruction (plusPtr buf $ i * 12 ) i) [ 0 .. nframes - 1 ]<br>
-- code AST <br>
let code = removePhi $ map disasm $ zip (map fst ids) [ O.. ]<br>
-- print code<br>
putStrLn $ produceCode code (map snd ids)<br>
free buf
Source: https://habr.com/ru/post/70185/
All Articles