summaryrefslogtreecommitdiff
path: root/compiler/cmm/CmmParse.y
diff options
context:
space:
mode:
authorMax Bolingbroke <batterseapower@hotmail.com>2011-07-05 09:23:58 +0100
committerMax Bolingbroke <batterseapower@hotmail.com>2011-07-05 09:53:57 +0100
commit54843b5bfdc81b7af6df36a06f7f434c7b74f796 (patch)
tree5e87d9d92707d9a955559b15b6e849fb0594a0e1 /compiler/cmm/CmmParse.y
parente01fffc60ba6a71487f0402f6c79ba2f0a684765 (diff)
downloadhaskell-54843b5bfdc81b7af6df36a06f7f434c7b74f796.tar.gz
Refactoring: use a structured CmmStatics type rather than [CmmStatic]
I observed that the [CmmStatics] within CmmData uses the list in a very stylised way. The first item in the list is almost invariably a CmmDataLabel. Many parts of the compiler pattern match on this list and fail if this is not true. This patch makes the invariant explicit by introducing a structured type CmmStatics that holds the label and the list of remaining [CmmStatic]. There is one wrinkle: the x86 backend sometimes wants to output an alignment directive just before the label. However, this can be easily fixed up by parameterising the native codegen over the type of CmmStatics (though the GenCmmTop parameterisation) and using a pair (Alignment, CmmStatics) there instead. As a result, I think we will be able to remove CmmAlign and CmmDataLabel from the CmmStatic data type, thus nuking a lot of code and failing pattern matches. This change will come as part of my next patch.
Diffstat (limited to 'compiler/cmm/CmmParse.y')
-rw-r--r--compiler/cmm/CmmParse.y17
1 files changed, 10 insertions, 7 deletions
diff --git a/compiler/cmm/CmmParse.y b/compiler/cmm/CmmParse.y
index 60f3bb5623..eceff8350d 100644
--- a/compiler/cmm/CmmParse.y
+++ b/compiler/cmm/CmmParse.y
@@ -188,21 +188,24 @@ cmmtop :: { ExtCode }
-- * we can derive closure and info table labels from a single NAME
cmmdata :: { ExtCode }
- : 'section' STRING '{' statics '}'
- { do ss <- sequence $4;
- code (emitData (section $2) (concat ss)) }
+ : 'section' STRING '{' static_label statics '}'
+ { do lbl <- $4;
+ ss <- sequence $5;
+ code (emitData (section $2) (Statics lbl $ concat ss)) }
statics :: { [ExtFCode [CmmStatic]] }
: {- empty -} { [] }
| static statics { $1 : $2 }
+static_label :: { ExtFCode CLabel }
+ : NAME ':'
+ {% withThisPackage $ \pkg ->
+ return (mkCmmDataLabel pkg $1) }
+
-- Strings aren't used much in the RTS HC code, so it doesn't seem
-- worth allowing inline strings. C-- doesn't allow them anyway.
static :: { ExtFCode [CmmStatic] }
- : NAME ':'
- {% withThisPackage $ \pkg ->
- return [CmmDataLabel (mkCmmDataLabel pkg $1)] }
-
+ : static_label { liftM (\x -> [CmmDataLabel x]) $1 }
| type expr ';' { do e <- $2;
return [CmmStaticLit (getLit e)] }
| type ';' { return [CmmUninitialised