Add import facility to cmm parser
authorClemens Fruhwirth <clemens@endorphin.org>
Fri, 13 Jul 2007 21:08:45 +0000 (21:08 +0000)
committerClemens Fruhwirth <clemens@endorphin.org>
Fri, 13 Jul 2007 21:08:45 +0000 (21:08 +0000)
The cmm parser classified all unknown variables as imported. This
behaviour is not changed with this patch. Explicitly imported
variables get a different internal label type, namely ForeignLabel
instead of RtsLabel. In PIC compilation, the NCG creates dynamic
access for ForeignLabel, while RtsLabel are not treated as PIC when
-package rts. Hence, putting explicit imports into cmm files enables
the NCG to distinguish between RTS-external and RTS-internal symbols,
and create the appropriate code.

compiler/cmm/CmmParse.y

index fa822f6..579df5e 100644 (file)
@@ -294,7 +294,7 @@ decl        :: { ExtCode }
        | STRING type names ';'         {% do k <- parseKind $1;
                                              return $ mapM_ (newLocal k $2) $3 }
 
        | STRING type names ';'         {% do k <- parseKind $1;
                                              return $ mapM_ (newLocal k $2) $3 }
 
-       | 'import' names ';'            { return () }  -- ignore imports
+       | 'import' names ';'            { mapM_ newImport $2 }
        | 'export' names ';'            { return () }  -- ignore exports
 
 names  :: { [FastString] }
        | 'export' names ';'            { return () }  -- ignore exports
 
 names  :: { [FastString] }
@@ -793,6 +793,13 @@ newLocal kind ty name = do
    addVarDecl name (CmmReg (CmmLocal reg))
    return reg
 
    addVarDecl name (CmmReg (CmmLocal reg))
    return reg
 
+-- Creates a foreign label in the import. CLabel's labelDynamic
+-- classifies these labels as dynamic, hence the code generator emits the
+-- PIC code for them.
+newImport :: FastString -> ExtFCode ()
+newImport name =
+       addVarDecl name (CmmLit (CmmLabel (mkForeignLabel name Nothing True)))
+
 newLabel :: FastString -> ExtFCode BlockId
 newLabel name = do
    u <- code newUnique
 newLabel :: FastString -> ExtFCode BlockId
 newLabel name = do
    u <- code newUnique