4 import Char ( isSpace )
6 {- Compares a .sorted file with a raw printout of instructions
9 First file (REF) is has lines of format
11 hex-digits SPACEs insn(possibly with spaces)
13 Second file (TEST) has lines of format
15 insn(possibly with spaces)
17 Purpose is to extract the insn (text), remove spaces, and compare.
20 (cd .. && make) && (../vex test1.orig | grep LALALA | cut -b 22- > out.txt)
21 /home/sewardj/Tools/HugsInst/bin/runhugs Compare.hs | grep FAIL
24 main = mayn "test2.sorted" "out.txt"
26 mayn :: String -> String -> IO ()
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))
33 putStrLn (unlines ress)
36 check :: String -> String -> String
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)
44 then "pass: " ++ summary
45 else "FAIL: " ++ summary
47 trim = reverse . dropWhile isSpace . reverse . dropWhile isSpace
49 compere s1 s2 = filter (not . isSpace) s1 == filter (not . isSpace) s2
51 isHex c = c `elem` "ABCDEF0123456789abcdef"
59 else take limit (str ++ repeat ' ')
62 deTab (c:cs) = if c == '\t' then " " ++ deTab cs