From 9c2a6b6656f9563aa7f8dfbdcad40e13f1c6c9e9 Mon Sep 17 00:00:00 2001 From: Adam Sampson Date: Fri, 14 Mar 2008 22:00:36 +0000 Subject: [PATCH] Handle both addl and subl for stack increases. GCC seems to very occasionally generate addl -N rather than subl N. Also don't allow subl -N any more -- if it's adjusting the stack pointer back up, that doesn't mean it's going to use any less of the stack... --- backends/AnalyseAsm.hs | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/backends/AnalyseAsm.hs b/backends/AnalyseAsm.hs index 9fd1d28..96843ba 100644 --- a/backends/AnalyseAsm.hs +++ b/backends/AnalyseAsm.hs @@ -71,23 +71,18 @@ parseAsmLine s matchInc :: String -> Maybe AsmItem matchInc s = case matchRegex incdecRE s of - Just [v] -> Just $ AsmStackInc (parseVal v) + Just [_, v] -> Just $ AsmStackInc (parseVal v) _ -> Nothing where -- The x86 stack goes downwards, so subl makes the stack deeper. - incdecRE = mkRegex "^subl (.*), %esp$" + -- GCC will sometimes generate "addl $-n" rather than "subl $n". + incdecRE = mkRegex "^(subl \\$|addl \\$-)([0-9]+), %esp$" parseVal :: String -> Int - -- The numbers can be negative: - parseVal ('$':'-':s) - = case readDec s of - [(v, "")] -> -v - _ -> error $ "Don't know how to parse assembly literal: -" ++ s - parseVal ('$':s) + parseVal s = case readDec s of [(v, "")] -> v _ -> error $ "Don't know how to parse assembly literal: " ++ s - parseVal s = error $ "Really don't know how to parse assembly literal: " ++ s matchPush :: String -> Maybe AsmItem matchPush s