packages feed

graphwiz-3.0.0: example/Main.hs

module Main where

import Control.Lens
import Data.Text.IO qualified as T
import Text.Dot
import TextBuilder  qualified as TB

main :: IO ()
main =
  T.putStrLn $ TB.toText $
    digraph do
      defaults Node . style ?= "filled"

      ast <- cluster do
        its label ?= "front end"

        source <- node "source code"
        its fillcolor ?= "#c3ffd8"

        ast <- node "AST"
        its fillcolor ?= "yellow"

        source --> ast
        its label ?= "parsing"

        pure ast

      cluster do
        its label ?= "middle end"

        ir <- node "IR"
        its shape   ?= "diamond"
        its fillcolor ?= "salmon"

        ast --> ir
        its label ?= "lowering"
        its style ?= "dotted"

        ir --> retrieve "backend"

      cluster do
        its label ?= "back end"
        registerItAs "backend"
        node "{%1 = cmp %0,0 | br i1 i2 %1}"
        its shape ?= "record"