X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=compiler%2Fcmm%2FCmmLint.hs;h=a849924af6853b093c48cad4d87d6f0bdf8eb941;hb=7fc749a43b4b6b85d234fa95d4928648259584f4;hp=83444e5d63e59756ee107efa5c6ac03f03a3ef59;hpb=ba40c9828ce8ce18e834af4f832792365d82e319;p=ghc-hetmet.git diff --git a/compiler/cmm/CmmLint.hs b/compiler/cmm/CmmLint.hs index 83444e5..a849924 100644 --- a/compiler/cmm/CmmLint.hs +++ b/compiler/cmm/CmmLint.hs @@ -1,8 +1,15 @@ +{-# OPTIONS -w #-} +-- The above warning supression flag is a temporary kludge. +-- While working on this module you are encouraged to remove it and fix +-- any warnings in the module. See +-- http://hackage.haskell.org/trac/ghc/wiki/Commentary/CodingStyle#Warnings +-- for details + ----------------------------------------------------------------------------- -- --- 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,22 +20,22 @@ 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: -cmmLint :: Cmm -> Maybe SDoc +cmmLint :: GenCmm d h CmmStmt -> Maybe SDoc cmmLint (Cmm tops) = runCmmLint $ mapM_ lintCmmTop tops -cmmLintTop :: CmmTop -> Maybe SDoc +cmmLintTop :: GenCmmTop d h CmmStmt -> Maybe SDoc cmmLintTop top = runCmmLint $ lintCmmTop top runCmmLint :: CmmLint a -> Maybe SDoc @@ -37,7 +44,7 @@ runCmmLint l = Left err -> Just (ptext SLIT("Cmm lint error:") $$ nest 2 err) Right _ -> Nothing -lintCmmTop (CmmProc _info lbl _args blocks) +lintCmmTop (CmmProc _ lbl _ blocks) = addLintInfo (text "in proc " <> pprCLabel lbl) $ mapM_ lintCmmBlock blocks lintCmmTop _other @@ -63,7 +70,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)]) @@ -88,7 +95,8 @@ cmmCheckMachOp op args = return (resultRepOfMachOp op) isWordOffsetReg (CmmGlobal Sp) = True -isWordOffsetReg (CmmGlobal Hp) = True +-- No warnings for unaligned arithmetic, which is used to tag dynamic constructor closures. +--isWordOffsetReg (CmmGlobal Hp) = True isWordOffsetReg _ = False isOffsetOp (MO_Add _) = True @@ -98,14 +106,18 @@ isOffsetOp _ = False -- This expression should be an address from which a word can be loaded: -- check for funny-looking sub-word offsets. cmmCheckWordAddress e@(CmmMachOp op [arg, CmmLit (CmmInt i _)]) - | isOffsetOp op && i `rem` fromIntegral wORD_SIZE /= 0 + | isOffsetOp op && notNodeReg arg && i `rem` fromIntegral wORD_SIZE /= 0 = cmmLintDubiousWordOffset e cmmCheckWordAddress e@(CmmMachOp op [CmmLit (CmmInt i _), arg]) - | isOffsetOp op && i `rem` fromIntegral wORD_SIZE /= 0 + | isOffsetOp op && notNodeReg arg && i `rem` fromIntegral wORD_SIZE /= 0 = cmmLintDubiousWordOffset e cmmCheckWordAddress _ = return () +-- No warnings for unaligned arithmetic with the node register, +-- which is used to extract fields from tagged constructor closures. +notNodeReg (CmmReg reg) | reg == nodeReg = False +notNodeReg _ = True lintCmmStmt :: CmmStmt -> CmmLint () lintCmmStmt stmt@(CmmAssign reg expr) = do @@ -117,9 +129,13 @@ lintCmmStmt (CmmStore l r) = do lintCmmExpr l lintCmmExpr r return () -lintCmmStmt (CmmCall _target _res args _vols) = mapM_ (lintCmmExpr.fst) args +lintCmmStmt (CmmCall _target _res args _ _) = mapM_ (lintCmmExpr.fst) args lintCmmStmt (CmmCondBranch e _id) = lintCmmExpr e >> checkCond e >> return () -lintCmmStmt (CmmSwitch e _branches) = lintCmmExpr 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 () @@ -149,9 +165,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: " $$