- f (v,e) = (local, make_var_id (Var.varName v), make_ty (idType v),make_exp e)
- where local = not $ elementOfUniqSet (Var.varName v) exports
- -- Top level bindings are unqualified now
-
-make_exp :: CoreExpr -> C.Exp
-make_exp (Var v) =
- case globalIdDetails v of
- -- a DataConId represents the Id of a worker, which is a varName. -- sof 4/02
--- DataConId _ -> C.Dcon (make_con_qid (Var.varName v))
- FCallId (CCall (CCallSpec (StaticTarget nm) _ _)) -> C.External (unpackFS nm) (make_ty (idType v))
- FCallId _ -> error "MkExternalCore died: can't handle non-static-C foreign call"
- _ -> C.Var (make_var_qid (Var.varName v))
-make_exp (Lit (l@(MachLabel s _))) = error "MkExternalCore died: can't handle \"foreign label\" declarations"
-make_exp (Lit l) = C.Lit (make_lit l)
-make_exp (App e (Type t)) = C.Appt (make_exp e) (make_ty t)
-make_exp (App e1 e2) = C.App (make_exp e1) (make_exp e2)
-make_exp (Lam v e) | isTyVar v = C.Lam (C.Tb (make_tbind v)) (make_exp e)
-make_exp (Lam v e) | otherwise = C.Lam (C.Vb (make_vbind v)) (make_exp e)
-make_exp (Let b e) = C.Let (make_vdef b) (make_exp e)
--- gaw 2004
-make_exp (Case e v ty alts) = C.Case (make_exp e) (make_vbind v) (make_ty ty) (map make_alt alts)
-make_exp (Note (SCC cc) e) = C.Note "SCC" (make_exp e) -- temporary
-make_exp (Note (CoreNote s) e) = C.Note s (make_exp e) -- hdaume: core annotations
-make_exp (Note InlineMe e) = C.Note "InlineMe" (make_exp e)
+ f :: (CoreBndr,CoreExpr) -> CoreM C.Vdef
+ f (v,e) = do
+ localN <- isALocal vName
+ let local = not topLevel || localN
+ rhs <- make_exp e
+ -- use local flag to determine where to add the module name
+ return (local, make_qid local True vName, make_ty (varType v),rhs)
+ where vName = Var.varName v
+
+make_exp :: CoreExpr -> CoreM C.Exp
+make_exp (Var v) = do
+ let vName = Var.varName v
+ isLocal <- isALocal vName
+ return $
+ case globalIdVarDetails v of
+ FCallId (CCall (CCallSpec (StaticTarget nm) callconv _))
+ -> C.External (unpackFS nm) (showSDoc (ppr callconv)) (make_ty (varType v))
+ FCallId (CCall (CCallSpec DynamicTarget callconv _))
+ -> C.DynExternal (showSDoc (ppr callconv)) (make_ty (varType v))
+ FCallId _
+ -> pprPanic "MkExternalCore died: can't handle non-{static,dynamic}-C foreign call"
+ (ppr v)
+ -- Constructors are always exported, so make sure to declare them
+ -- with qualified names
+ DataConWorkId _ -> C.Var (make_var_qid False vName)
+ DataConWrapId _ -> C.Var (make_var_qid False vName)
+ _ -> C.Var (make_var_qid isLocal vName)
+make_exp (Lit (MachLabel s _)) = return $ C.Label (unpackFS s)
+make_exp (Lit l) = return $ C.Lit (make_lit l)
+make_exp (App e (Type t)) = make_exp e >>= (\ b -> return $ C.Appt b (make_ty t))
+make_exp (App e1 e2) = do
+ rator <- make_exp e1
+ rand <- make_exp e2
+ return $ C.App rator rand
+make_exp (Lam v e) | isTyVar v = make_exp e >>= (\ b ->
+ return $ C.Lam (C.Tb (make_tbind v)) b)
+make_exp (Lam v e) | otherwise = make_exp e >>= (\ b ->
+ return $ C.Lam (C.Vb (make_vbind v)) b)
+make_exp (Cast e co) = make_exp e >>= (\ b -> return $ C.Cast b (make_ty co))
+make_exp (Let b e) = do
+ vd <- make_vdef False b
+ body <- make_exp e
+ return $ C.Let vd body
+make_exp (Case e v ty alts) = do
+ scrut <- make_exp e
+ newAlts <- mapM make_alt alts
+ return $ C.Case scrut (make_vbind v) (make_ty ty) newAlts
+make_exp (Note (SCC _) e) = make_exp e >>= (return . C.Note "SCC") -- temporary
+make_exp (Note (CoreNote s) e) = make_exp e >>= (return . C.Note s) -- hdaume: core annotations
+make_exp (Note InlineMe e) = make_exp e >>= (return . C.Note "InlineMe")