6 - Transform code involving standing moves into two sequential
7 blocks: setup and teardown. Then establish proper sequencing
8 between them. The teardown block consists only of kills.
10 - Implement sequencing.
19 main = do t <- parseFile "src/edu/berkeley/fleet/f0/f0.g" "contrib/demo.f0"
21 putStrLn $ show $ coalesceFlatHeadlessNodes t
23 putStrLn $ join "\n\n" $ map show $ ((fromTree $ coalesceFlatHeadlessNodes t) :: [Def])
25 compiled <- return $ join "\n\n" $ map compileDef $ ((fromTree $ coalesceFlatHeadlessNodes t) :: [Def])
27 writeFile "compiled.fleet" ("// compiled with f0\n\n"++compiled++"\n")
30 compile :: Expr -> [Inst]
31 compile (Decl _ _) = []
32 compile (Seq s) = error "bleh"
33 compile (Par e) = concatMap compile e
34 compile (Move 1 s [d]) = [ (move s) { m_dest=(Just d) }, (accept d) ]
35 compile (Move 1 s d) = [itake s]++sends++recvs
37 sends = map (\x -> ((send s) { m_dest=(Just x) })) d
38 recvs = map (\x -> ((accept x) )) d
39 compile (Literal 0 lit ds) = concatMap (\d -> [ ILiteral lit d, (accept d) {m_count=0} ]) ds
40 compile (Literal 1 lit ds) = concatMap (\d -> [ ILiteral lit d, (accept d) ]) ds
41 compile (Literal n lit ds) = concatMap (\d -> [ ILiteral lit d, (accept d) {m_count=n} ]) ds
43 getdecls (Decl n t) = ["#ship " ++ n ++ " : " ++ t]
44 getdecls (Seq es) = concatMap getdecls es
45 getdecls (Par es) = concatMap getdecls es
48 compileDef (Def s _ _ e) =
50 (join "\n" $ getdecls e)++"\n"++
51 (join "\n" $ map show (compile e))
53 itake box = IMove { m_count=1, m_recycle=False, m_tokenIn=False, m_dataIn=True,
54 m_latch=True, m_dataOut=False, m_tokenOut=False, m_dest=Nothing,
56 move box = (itake box){ m_dataOut=True }
57 send box = (move box){ m_dataIn=False, m_latch=False }