X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=compiler%2Fcmm%2FCmmLint.hs;h=0812347c06335220c774cc314aaf9a8966efd172;hb=bd3a364da7956c269d31645995d0d775c52f6a84;hp=fbfb14c1653d42d9bdaa941c3650ede3f028e9bd;hpb=0065d5ab628975892cea1ec7303f968c3338cbe1;p=ghc-hetmet.git diff --git a/compiler/cmm/CmmLint.hs b/compiler/cmm/CmmLint.hs index fbfb14c..0812347 100644 --- a/compiler/cmm/CmmLint.hs +++ b/compiler/cmm/CmmLint.hs @@ -1,8 +1,8 @@ ----------------------------------------------------------------------------- -- --- CmmLint: checking the correctness of Cmm statements and expressions +-- (c) The University of Glasgow 2004-2006 -- --- (c) The University of Glasgow 2004 +-- CmmLint: checking the correctness of Cmm statements and expressions -- ----------------------------------------------------------------------------- @@ -13,14 +13,14 @@ module CmmLint ( #include "HsVersions.h" import Cmm -import CLabel ( pprCLabel ) +import CLabel import MachOp import Outputable import PprCmm -import Unique ( getUnique ) -import Constants ( wORD_SIZE ) +import Unique +import Constants -import Monad ( when ) +import Control.Monad -- ----------------------------------------------------------------------------- -- Exported entry points: @@ -63,7 +63,7 @@ lintCmmExpr expr@(CmmMachOp op args) = do mapM_ lintCmmExpr args if map cmmExprRep args == machOpArgReps op then cmmCheckMachOp op args - else cmmLintMachOpErr expr + else cmmLintMachOpErr expr (map cmmExprRep args) (machOpArgReps op) lintCmmExpr (CmmRegOff reg offset) = lintCmmExpr (CmmMachOp (MO_Add rep) [CmmReg reg, CmmLit (CmmInt (fromIntegral offset) rep)]) @@ -117,12 +117,20 @@ lintCmmStmt (CmmStore l r) = do lintCmmExpr l lintCmmExpr r return () -lintCmmStmt (CmmCall _target _res args _vols) = mapM_ (lintCmmExpr.fst) args -lintCmmStmt (CmmCondBranch e _id) = lintCmmExpr e >> return () -lintCmmStmt (CmmSwitch e _branches) = lintCmmExpr e >> return () +lintCmmStmt (CmmCall _target _res args) = mapM_ (lintCmmExpr.fst) args +lintCmmStmt (CmmCondBranch e _id) = lintCmmExpr e >> checkCond e >> return () +lintCmmStmt (CmmSwitch e _branches) = do + erep <- lintCmmExpr e + if (erep == wordRep) + then return () + else cmmLintErr (text "switch scrutinee is not a word: " <> ppr e) lintCmmStmt (CmmJump e _args) = lintCmmExpr e >> return () lintCmmStmt _other = return () +checkCond (CmmMachOp mop _) | isComparisonMachOp mop = return () +checkCond expr = cmmLintErr (hang (text "expression is not a conditional:") 2 + (ppr expr)) + -- ----------------------------------------------------------------------------- -- CmmLint monad @@ -145,9 +153,12 @@ addLintInfo info thing = CmmLint $ Left err -> Left (hang info 2 err) Right a -> Right a -cmmLintMachOpErr :: CmmExpr -> CmmLint a -cmmLintMachOpErr expr = cmmLintErr (text "in MachOp application: " $$ - nest 2 (pprExpr expr)) +cmmLintMachOpErr :: CmmExpr -> [MachRep] -> [MachRep] -> CmmLint a +cmmLintMachOpErr expr argsRep opExpectsRep + = cmmLintErr (text "in MachOp application: " $$ + nest 2 (pprExpr expr) $$ + (text "op is expecting: " <+> ppr opExpectsRep) $$ + (text "arguments provide: " <+> ppr argsRep)) cmmLintAssignErr :: CmmStmt -> CmmLint a cmmLintAssignErr stmt = cmmLintErr (text "in assignment: " $$