[project @ 2004-11-09 16:59:31 by simonmar]
[ghc-hetmet.git] / ghc / utils / genprimopcode / Main.hs
index eedcb72..e486403 100644 (file)
@@ -1,11 +1,16 @@
-
+{-# OPTIONS -cpp #-}
 ------------------------------------------------------------------
 -- A primop-table mangling program                              --
 ------------------------------------------------------------------
 
 module Main where
 
+#if __GLASGOW_HASKELL__ >= 504
+import Text.ParserCombinators.Parsec
+#else
 import Parsec
+#endif
+
 import Monad
 import Char
 import List
@@ -285,10 +290,12 @@ gen_primop_list (Info defaults entries)
      ) where (first:rest) = filter is_primop entries
 
 gen_primop_tag (Info defaults entries)
-   = unlines (zipWith f (filter is_primop entries) [1..])
+   = unlines (max_def : zipWith f primop_entries [1..])
      where
+       primop_entries = filter is_primop entries
         f i n = "tagOf_PrimOp " ++ cons i 
                 ++ " = _ILIT(" ++ show n ++ ") :: FastInt"
+       max_def = "maxPrimOpTag = " ++ show (length primop_entries) ++ " :: Int"
 
 gen_data_decl (Info defaults entries)
    = let conss = map cons (filter is_primop entries)
@@ -352,7 +359,7 @@ mkPOI_RHS_text i
                       ++ listify (map ppType argTys) ++ " "
                       ++ "(" ++ ppType resTy ++ ")"
             
-sl_name i = "SLIT(\"" ++ name i ++ "\") "
+sl_name i = "FSLIT(\"" ++ name i ++ "\") "
 
 ppTyVar "a" = "alphaTyVar"
 ppTyVar "b" = "betaTyVar"
@@ -378,7 +385,7 @@ ppType (TyApp "RealWorld"   []) = "realWorldTy"
 ppType (TyApp "ThreadId#"   []) = "threadIdPrimTy"
 ppType (TyApp "ForeignObj#" []) = "foreignObjPrimTy"
 ppType (TyApp "BCO#"        []) = "bcoPrimTy"
-ppType (TyApp "Unit"        []) = "unitTy"   -- dodgy
+ppType (TyApp "()"          []) = "unitTy"     -- unitTy is TysWiredIn's name for ()
 
 
 ppType (TyVar "a")               = "alphaTy"
@@ -642,7 +649,7 @@ ppT = alts [apply TyVar pTyvar,
            ]
 
 pTyvar       = sat (`notElem` ["section","primop","with"]) pName
-pTycon       = pConstructor
+pTycon       = alts [pConstructor, lexeme (string "()")]
 pName        = lexeme (then2 (:) lower (many isIdChar))
 pConstructor = lexeme (then2 (:) upper (many isIdChar))