X-Git-Url: http://git.megacz.com/?p=ghc-hetmet.git;a=blobdiff_plain;f=compiler%2FllvmGen%2FLlvmCodeGen%2FData.hs;h=3e486a544f33e9d087bcd46d10a6abd208a1300a;hp=13da03b8408eb0d3af5066a168091aa9cb278b5d;hb=c5b178be60a5a44abd2f4ddf8c399857678326e2;hpb=09e6aba8000ccf52943ada4fb9ac76e0d93a202f diff --git a/compiler/llvmGen/LlvmCodeGen/Data.hs b/compiler/llvmGen/LlvmCodeGen/Data.hs index 13da03b..3e486a5 100644 --- a/compiler/llvmGen/LlvmCodeGen/Data.hs +++ b/compiler/llvmGen/LlvmCodeGen/Data.hs @@ -13,7 +13,7 @@ import LlvmCodeGen.Base import BlockId import CLabel -import Cmm +import OldCmm import FastString import qualified Outputable @@ -37,8 +37,8 @@ structStr = fsLit "_struct" -- complete this completely though as we need to pass all CmmStatic -- sections before all references can be resolved. This last step is -- done by 'resolveLlvmData'. -genLlvmData :: [CmmStatic] -> LlvmUnresData -genLlvmData (CmmDataLabel lbl:xs) = +genLlvmData :: (Section, [CmmStatic]) -> LlvmUnresData +genLlvmData (sec, CmmDataLabel lbl:xs) = let static = map genData xs label = strCLabel_llvm lbl @@ -47,11 +47,12 @@ genLlvmData (CmmDataLabel lbl:xs) = getStatTypes (Right x) = getStatType x strucTy = LMStruct types - alias = LMAlias (label `appendFS` structStr) strucTy - in (lbl, alias, static) + alias = LMAlias ((label `appendFS` structStr), strucTy) + in (lbl, sec, alias, static) genLlvmData _ = panic "genLlvmData: CmmData section doesn't start with label!" + resolveLlvmDatas :: LlvmEnv -> [LlvmUnresData] -> [LlvmData] -> (LlvmEnv, [LlvmData]) resolveLlvmDatas env [] ldata @@ -63,17 +64,29 @@ resolveLlvmDatas env (udata : rest) ldata -- | Fix up CLabel references now that we should have passed all CmmData. resolveLlvmData :: LlvmEnv -> LlvmUnresData -> (LlvmEnv, LlvmData) -resolveLlvmData env (lbl, alias, unres) = +resolveLlvmData env (lbl, sec, alias, unres) = let (env', static, refs) = resDatas env unres ([], []) refs' = catMaybes refs struct = Just $ LMStaticStruc static alias label = strCLabel_llvm lbl link = if (externallyVisibleCLabel lbl) then ExternallyVisible else Internal - glob = LMGlobalVar label alias link Nothing Nothing + const = isSecConstant sec + glob = LMGlobalVar label alias link Nothing Nothing const in (env', (refs' ++ [(glob, struct)], [alias])) +-- | Should a data in this section be considered constant +isSecConstant :: Section -> Bool +isSecConstant Text = True +isSecConstant Data = False +isSecConstant ReadOnlyData = True +isSecConstant RelocatableReadOnlyData = True +isSecConstant UninitialisedData = False +isSecConstant ReadOnlyData16 = True +isSecConstant (OtherSection _) = False + + -- ---------------------------------------------------------------------------- -- ** Resolve Data/CLabel references -- @@ -93,7 +106,7 @@ resDatas env (cmm : rest) (stats, globs) -- -- We check the 'LlvmEnv' to see if the reference has been defined in this -- module. If it has we can retrieve its type and make a pointer, otherwise --- we introduce a generic external defenition for the referenced label and +-- we introduce a generic external definition for the referenced label and -- then make a pointer. resData :: LlvmEnv -> UnresStatic -> (LlvmEnv, LlvmStatic, [Maybe LMGlobal]) @@ -114,7 +127,7 @@ resData env (Left cmm@(CmmLabel l)) = -- pointer to it. Just ty' -> let var = LMGlobalVar label (LMPointer ty') - ExternallyVisible Nothing Nothing + ExternallyVisible Nothing Nothing False ptr = LMStaticPointer var in (env, LMPtoI ptr lmty, [Nothing])