TYPE ConstFlattened = flat(snum) State = Var -> ConstFlattened PROBLEM Constant_Propagation direction : forward carrier : State init : bot init_start : [-> top] combine : lub TRANSFER // in assignments calculate the new value of the variable and add it to the state ASSIGN(variable, expression) = @\[variable -> evalAExp(expression, @)] // in procedur calls pass the value of the actual argument to the formal parameter CALL(_, param, exp), call_edge = @\[param -> evalAExp(exp, @)] CALL(_, _, _), local_edge = bot // at the end of procedures reset the formal parameter END(_, param) = @\[param -> top] SUPPORT evalAExp :: Expression * State -> ConstFlattened evalAExp(expression, state) = case expType(expression) of "ARITH_BINARY" => case expOp(expression) of "+" => let valLeft <= evalAExp(expSubLeft(expression), state), valRight <= evalAExp(expSubRight(expression), state) in lift((valLeft + valRight)%2); "-" => let valLeft <= evalAExp(expSubLeft(expression), state), valRight <= evalAExp(expSubRight(expression), state) in lift((valLeft - valRight)%2); "*" => let valLeft = evalAExp(expSubLeft(expression), state), valRight = evalAExp(expSubRight(expression), state) in case (valLeft,valRight) of (top,top)=>top; (top,x)=>if drop(x)=0 then lift(0) else top endif; (x,top)=>if drop(x)=0 then lift(0) else top endif; (x,y)=>lift(drop(x)*drop(y)); endcase; "/" => top; endcase; "ARITH_UNARY" => case expOp(expression) of "-" => evalAExp(expSub(expression), state); endcase; "VAR" => state ( expVar(expression) ); "CONST" => lift(expVal(expression)%2); _ => error("Runtime Error: evalAExp applied to nonarithmetic Expression"); endcase