Skip to content

Commit

Permalink
Separate commands for showing the different passes
Browse files Browse the repository at this point in the history
  • Loading branch information
dougalm committed Oct 4, 2019
1 parent bd126ce commit dc4d021
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 29 deletions.
4 changes: 2 additions & 2 deletions src/lib/DeShadow.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ sourcePass = TopPass sourcePass'

sourcePass' :: SourceBlock -> TopPassM () UTopDecl
sourcePass' block = case sbContents block of
UTopDecl (EvalCmd (Command Parse expr)) -> emitOutput $ TextOut $ pprint expr
UTopDecl (EvalCmd (Command ShowParse expr)) -> emitOutput $ TextOut $ pprint expr
UTopDecl decl -> return decl
UnParseable s -> throwTopErr $ Err ParseErr Nothing s
ProseBlock _ -> emitOutput NoOutput
Expand All @@ -37,7 +37,7 @@ deShadowPass = TopPass $ \topDecl -> case topDecl of
EvalCmd (Command cmd expr) -> do
expr' <- deShadowTop expr
case cmd of
Passes -> emitOutput $ TextOut $ "\n\nDeshadowed\n" ++ show expr'
ShowDeshadowed -> emitOutput $ TextOut $ show expr'
_ -> return $ EvalCmd (Command cmd expr')

deShadowTop :: UExpr -> TopPassM (DeShadowEnv, FreshScope) UExpr
Expand Down
2 changes: 1 addition & 1 deletion src/lib/Imp.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impPass = TopPass $ \decl -> case decl of
let bs = [Name "%imptmp" i :> t | (i, t) <- zip [0..] ts']
prog <- liftTop $ toImp (map asDest bs) expr
case cmd of
Passes -> emitOutput $ TextOut $ "\n\nImp\n" ++ pprint prog
ShowImp -> emitOutput $ TextOut $ pprint prog
_ -> return $ ImpEvalCmd (reconstruct ty) bs (Command cmd prog)
where
liftTop :: ImpM a -> TopPassM ImpEnv a
Expand Down
4 changes: 2 additions & 2 deletions src/lib/Inference.hs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ typePass = TopPass $ \tdecl -> case tdecl of
_ -> do
(_, expr') <- liftTop $ solveLocalMonomorphic $ infer expr
case cmd of
Passes -> emitOutput $ TextOut $ "\nSystem F\n" ++ pprint expr'
_ -> return $ EvalCmd (Command cmd expr')
ShowTyped -> emitOutput $ TextOut $ pprint expr'
_ -> return $ EvalCmd (Command cmd expr')

liftTop :: InferM a -> TopPassM TypeEnv a
liftTop m = do
Expand Down
40 changes: 22 additions & 18 deletions src/lib/JIT.hs
Original file line number Diff line number Diff line change
Expand Up @@ -77,24 +77,28 @@ jitPass' decl = case decl of
extend $ bindFold $ zipWith replaceAnnot bs vals
emitOutput NoOutput
ImpEvalCmd cont bs (Command cmd prog) -> case cmd of
LLVM -> do (_, CompiledProg m) <- toLLVM bs prog
llvm <- liftIO $ showLLVM m
emitOutput $ TextOut llvm
Asm -> do (_, CompiledProg m) <- toLLVM bs prog
asm <- liftIO $ showAsm m
emitOutput $ TextOut asm
EvalExpr fmt -> do vals <- evalProg bs prog
vecs <- liftIO $ mapM asVec vals
env <- look
let tenv = flip envMapMaybe env $ \v ->
case v of
ScalarVal w _ -> Just (fromIntegral w)
_ -> Nothing
emitOutput $ ValOut fmt $ cont tenv vecs
TimeIt -> do t1 <- liftIO getCurrentTime
_ <- evalProg bs prog
t2 <- liftIO getCurrentTime
emitOutput $ TextOut $ show (t2 `diffUTCTime` t1)
ShowLLVM -> do
(_, CompiledProg m) <- toLLVM bs prog
llvm <- liftIO $ showLLVM m
emitOutput $ TextOut llvm
ShowAsm -> do
(_, CompiledProg m) <- toLLVM bs prog
asm <- liftIO $ showAsm m
emitOutput $ TextOut asm
EvalExpr fmt -> do
vals <- evalProg bs prog
vecs <- liftIO $ mapM asVec vals
env <- look
let tenv = flip envMapMaybe env $ \v ->
case v of
ScalarVal w _ -> Just (fromIntegral w)
_ -> Nothing
emitOutput $ ValOut fmt $ cont tenv vecs
TimeIt -> do
t1 <- liftIO getCurrentTime
_ <- evalProg bs prog
t2 <- liftIO getCurrentTime
emitOutput $ TextOut $ show (t2 `diffUTCTime` t1)
_ -> error $ "Unexpected command: " ++ show cmd

evalProg :: [IBinder] -> ImpProg -> TopPassM PersistEnv [PersistVal]
Expand Down
4 changes: 2 additions & 2 deletions src/lib/Normalize.hs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ normalizePass = TopPass $ \topDecl -> case topDecl of
(expr', _) <- asTopPassM $ normalizeScoped expr
(ntys , _) <- asTopPassM $ normalizeTy ty
case cmd of
Passes -> emitOutput $ TextOut $ "\n\nNormalized\n" ++ pprint expr'
ShowNormalized -> emitOutput $ TextOut $ pprint expr'
_ -> return $ NEvalCmd (Command cmd (ty, toList ntys, expr'))

asTopPassM :: NormM a -> TopPassM (NormEnv, Scope) (a, [NDecl])
Expand Down Expand Up @@ -238,7 +238,7 @@ simpPass = TopPass $ \topDecl -> case topDecl of
-- TODO: handle type vars
expr' <- simpAsTopPassM $ simplify expr
case cmd of
Passes -> emitOutput $ TextOut $ "\n\nSimp\n" ++ pprint expr'
ShowSimp -> emitOutput $ TextOut $ pprint expr'
_ -> return $ NEvalCmd (Command cmd (ty, ntys, expr'))

simpAsTopPassM :: SimplifyM a -> TopPassM SimpEnv a
Expand Down
11 changes: 7 additions & 4 deletions src/lib/Syntax.hs
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,11 @@ builtinNames = M.fromList [

commandNames :: M.Map String CmdName
commandNames = M.fromList [
("p", EvalExpr Printed), ("t", GetType), ("passes", Passes), ("llvm", LLVM),
("asm", Asm), ("time", TimeIt), ("plot", EvalExpr Scatter),
("plotmat", EvalExpr Heatmap), ("flops", Flops), ("parse", Parse)]
("p", EvalExpr Printed), ("t", GetType), ("typed", ShowTyped),
("llvm", ShowLLVM), ("deshadowed", ShowDeshadowed),
("normalized", ShowNormalized), ("imp", ShowImp), ("asm", ShowAsm),
("time", TimeIt), ("plot", EvalExpr Scatter),
("plotmat", EvalExpr Heatmap), ("flops", Flops), ("parse", ShowParse)]

builtinStrs :: M.Map Builtin String
builtinStrs = M.fromList $ map swap (M.toList builtinNames)
Expand All @@ -142,7 +144,8 @@ instance Show Builtin where
show (FFICall _ s) = "%%" ++ s
show b = "%" ++ fromJust (M.lookup b builtinStrs)

data CmdName = GetType | Parse | Passes | LLVM | Asm | TimeIt | Flops
data CmdName = GetType | ShowParse | ShowTyped | ShowLLVM | ShowDeshadowed
| ShowNormalized | ShowSimp | ShowImp | ShowAsm | TimeIt | Flops
| EvalExpr OutFormat
deriving (Show, Eq, Generic)

Expand Down

0 comments on commit dc4d021

Please sign in to comment.