Changeset 4864 for proto/pabloH


Ignore:
Timestamp:
Nov 10, 2015, 7:44:20 AM (4 years ago)
Author:
cameron
Message:

Eliminate trivial reassignments

File:
1 edited

Legend:

Unmodified
Added
Removed
  • proto/pabloH/pabloc1.hs

    r4863 r4864  
    55import System.IO (stdout,stderr,hPutStr,hPutStrLn)
    66import Control.Monad
    7 
    87
    98compileBinary :: (String, Int, PabloE, PabloE, Operator) -> (Int, [PabloInstruction], Operand)
     
    4039        IRvar(t4))
    4140
     41replaceOrAssignTarget(targetVar, (n, [], v)) = (n, [IRassign(targetVar, v)])
     42replaceOrAssignTarget(targetVar, (n, instrs, v)) =
     43    case (last instrs) of
     44        Binary(temp, op, e1, e2) -> (n-1, (init instrs) ++ [Binary(targetVar, op, e1, e2)])
     45        _ -> (n, instrs ++ [IRassign(targetVar, v)])
     46
    4247compileAssigns :: (String, Int, [PabloS]) -> (Int, [PabloInstruction])
    4348compileAssigns (pfx, n, []) = (n, [])
    4449compileAssigns (pfx, n, Assign(varname, e) : more) =
    45    let (n1, instrs, v) = compileE(pfx, n, e)
     50   let (n1, instrs) = replaceOrAssignTarget(varname, compileE(pfx, n, e))
    4651       (n2, moreInstrs) = compileAssigns(pfx, n1, more)
    47    in (n2, instrs ++ (IRassign(varname, v) : moreInstrs))
     52   in (n2, instrs ++ moreInstrs)
    4853
    4954isAssign (Assign(v,e)) = True
     
    7681              in (n4, block1 : block2 : (repeatIR ++ afterIR))
    7782     
    78      
    7983compileMain stmts =
    8084    let (n, compiled) = compileStmts("tmp", 0, "entry", Ret, stmts)
Note: See TracChangeset for help on using the changeset viewer.