cLoad :: CmmExpr -> CmmType -> SDoc
cLoad expr rep
    = sdocWithPlatform $ \platform ->
      if bewareLoadStoreAlignment (platformArch platform)
      then let decl = machRepCType rep <+> ptext (sLit "x") <> semi
               struct = ptext (sLit "struct") <+> braces (decl)
               packed_attr = ptext (sLit "__attribute__((packed))")
               cast = parens (struct <+> packed_attr <> char '*')
           in parens (cast <+> pprExpr1 expr) <> ptext (sLit "->x")
      else char '*' <> parens (cCast (machRepPtrCType rep) expr)
    where -- On these platforms, unaligned loads are known to cause problems
          bewareLoadStoreAlignment ArchAlpha    = True
          bewareLoadStoreAlignment ArchMipseb   = True
          bewareLoadStoreAlignment ArchMipsel   = True
          bewareLoadStoreAlignment (ArchARM {}) = True
          bewareLoadStoreAlignment ArchARM64    = True
          -- Pessimistically assume that they will also cause problems
          -- on unknown arches
          bewareLoadStoreAlignment ArchUnknown  = True
          bewareLoadStoreAlignment _            = False
cLoad :: CmmExpr -> CmmType -> SDoc
cLoad expr rep
    = sdocWithPlatform $ \platform ->
      if bewareLoadStoreAlignment (platformArch platform)
      then let decl = machRepCType rep <+> ptext (sLit "x") <> semi
               struct = ptext (sLit "struct") <+> braces (decl)
               packed_attr = ptext (sLit "__attribute__((packed))")
               cast = parens (struct <+> packed_attr <> char '*')
           in parens (cast <+> pprExpr1 expr) <> ptext (sLit "->x")
      else char '*' <> parens (cCast (machRepPtrCType rep) expr)
    where -- On these platforms, unaligned loads are known to cause problems
          bewareLoadStoreAlignment ArchAlpha    = True
          bewareLoadStoreAlignment ArchMipseb   = True
          bewareLoadStoreAlignment ArchMipsel   = True
          bewareLoadStoreAlignment (ArchARM {}) = True
          bewareLoadStoreAlignment ArchARM64    = True
          -- Pessimistically assume that they will also cause problems
          -- on unknown arches
          bewareLoadStoreAlignment ArchUnknown  = True
          bewareLoadStoreAlignment _            = False
cLoad expr rep
    = sdocWithPlatform $ \platform ->
      if bewareLoadStoreAlignment (platformArch platform)
      then let decl = machRepCType rep <+> ptext (sLit "x") <> semi
               struct = ptext (sLit "struct") <+> braces (decl)
               packed_attr = ptext (sLit "__attribute__((packed))")
               cast = parens (struct <+> packed_attr <> char '*')
           in parens (cast <+> pprExpr1 expr) <> ptext (sLit "->x")
      else char '*' <> parens (cCast (machRepPtrCType rep) expr)
    where -- On these platforms, unaligned loads are known to cause problems
          bewareLoadStoreAlignment ArchAlpha    = True
          bewareLoadStoreAlignment ArchMipseb   = True
          bewareLoadStoreAlignment ArchMipsel   = True
          bewareLoadStoreAlignment (ArchARM {}) = True
          bewareLoadStoreAlignment ArchARM64    = True
          -- Pessimistically assume that they will also cause problems
          -- on unknown arches
          bewareLoadStoreAlignment ArchUnknown  = True
          bewareLoadStoreAlignment _            = False