1 2 module Main where 3 4 import Char ( isSpace ) 5 6 {- Compares a .sorted file with a raw printout of instructions 7 and shows differences. 8 9 First file (REF) is has lines of format 10 11 hex-digits SPACEs insn(possibly with spaces) 12 13 Second file (TEST) has lines of format 14 15 insn(possibly with spaces) 16 17 Purpose is to extract the insn (text), remove spaces, and compare. 18 19 How to use: 20 (cd .. && make) && (../vex test1.orig | grep LALALA | cut -b 22- > out.txt) 21 /home/sewardj/Tools/HugsInst/bin/runhugs Compare.hs | grep FAIL 22 -} 23 24 main = mayn "test2.sorted" "out.txt" 25 26 mayn :: String -> String -> IO () 27 28 mayn sorted_fn dump_fn 29 = do sorted <- readFile sorted_fn 30 dump <- readFile dump_fn 31 let ress = zipWith check (lines (deTab sorted)) 32 (lines (deTab dump)) 33 putStrLn (unlines ress) 34 35 36 check :: String -> String -> String 37 check ref test 38 = let ref_clean = dropWhile isHex ref 39 ok = compere ref_clean test 40 summary = grok ("REF: " ++ trim ref_clean) 41 ++ " " ++ grok ("TEST: " ++ trim test) 42 in 43 if ok 44 then "pass: " ++ summary 45 else "FAIL: " ++ summary 46 47 trim = reverse . dropWhile isSpace . reverse . dropWhile isSpace 48 49 compere s1 s2 = filter (not . isSpace) s1 == filter (not . isSpace) s2 50 51 isHex c = c `elem` "ABCDEF0123456789abcdef" 52 53 grok str 54 = let n = length str 55 limit = 40 56 in 57 if n >= limit 58 then str 59 else take limit (str ++ repeat ' ') 60 61 deTab [] = [] 62 deTab (c:cs) = if c == '\t' then " " ++ deTab cs 63 else c: deTab cs 64