comp  Cmpl = CMPL
comp  Cmple = CMPLE
comp  Cmpg = CMPG
comp  Cmpge = CMPGE



compile :: [IR.IR] -> Program
compile is = Program $ evalState (compile' is) (CS 0 emptyFrame)
    where
      compile' :: [IR.IR] -> State C
defineVar var@(Var v) = do
  defd <- alreadyDefinedVar var
  when defd (error $ "already defined var: " ++ v)
  reg <- use (frame.intRest) <&> head
  frame.intVars %= ((var, reg) :)
  frame.intRest %= tail
  return $ reg
defineVar var@(Var v) = do
  defd <- alreadyDefinedVar var
  when defd (error $ "already defined var: " ++ v)
  reg <- use (frame.intRest) <&> head
  frame.intVars %= ((var, reg) :)
  frame.intRest %= tail
  return $ reg