From: sewardj Date: Thu, 6 Apr 2000 17:14:08 +0000 (+0000) Subject: [project @ 2000-04-06 17:14:08 by sewardj] X-Git-Tag: Approximately_9120_patches~4788 X-Git-Url: http://git.megacz.com/?a=commitdiff_plain;h=55b30ac226e0afeb0b982fd3361660fd3b4f9057;p=ghc-hetmet.git [project @ 2000-04-06 17:14:08 by sewardj] pprInstr (ASCII True str): avoid escapery probs by translating into hex --- diff --git a/ghc/compiler/nativeGen/PprMach.lhs b/ghc/compiler/nativeGen/PprMach.lhs index ea296ef..51a6838 100644 --- a/ghc/compiler/nativeGen/PprMach.lhs +++ b/ghc/compiler/nativeGen/PprMach.lhs @@ -407,10 +407,28 @@ pprInstr (ASCII False{-no backslash conversion-} str) = hcat [ ptext SLIT("\t.asciz "), char '\"', text str, char '"' ] pprInstr (ASCII True str) - = (<>) (text "\t.ascii \"") (asciify str 60) + = --(<>) (text "\t.ascii \"") (asciify 60 str) + asciify str where + asciify :: String -> SDoc + asciify "" = text "\t.ascii \"\\0\"" + asciify str + = let fst = take 16 str + rest = drop 16 str + this = text ("\t.ascii \"" + ++ concat (map asciify_char fst) + ++ "\"") + in this $$ asciify rest + asciify_char :: Char -> String + asciify_char c = '\\' : 'x' : hshow (ord c) + + hshow :: Int -> String + hshow n | n >= 0 && n <= 255 + = [ tab !! (n `div` 16), tab !! (n `mod` 16)] + tab = "0123456789abcdef" + +{- asciify :: String -> Int -> SDoc - asciify [] _ = text "\\0\"" asciify s n | n <= 0 = (<>) (text "\"\n\t.ascii \"") (asciify s 60) asciify ('\\':cs) n = (<>) (text "\\\\") (asciify cs (n-1)) @@ -420,6 +438,8 @@ pprInstr (ASCII True str) asciify (c:(cs@(d:_))) n | isDigit d = (<>) (text (charToC c)) (asciify cs 0) | otherwise = (<>) (text (charToC c)) (asciify cs (n-1)) + asciify [] _ = text "\\0\ +-} #if 0 pprInstr (DATA s xs)