From 0c49b3f13dc00eb5811002f230e1a6e4cc52d705 Mon Sep 17 00:00:00 2001 From: Jed Barber Date: Thu, 20 Nov 2014 22:11:03 +1100 Subject: Factored out graph node/edge and instruction pointer types --- src/Grasp/Node.hs | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 src/Grasp/Node.hs (limited to 'src/Grasp/Node.hs') diff --git a/src/Grasp/Node.hs b/src/Grasp/Node.hs new file mode 100644 index 0000000..ce84163 --- /dev/null +++ b/src/Grasp/Node.hs @@ -0,0 +1,47 @@ +module Grasp.Node ( + GNode, + GNodeType, + + singleton, + uSingleton, + fromStringList, + lab, + inst, + idNo + ) where + + + +import Data.Graph.Inductive.Graph( LNode ) +import Data.Map( Map ) +import qualified Data.Map as Map + + + +type GNode = LNode (Maybe String, String) +type GNodeType = (Maybe String, String) + + + +singleton :: Int -> String -> String -> GNode +singleton i m s = (i,(Just m,s)) + +uSingleton :: Int -> String -> GNode +uSingleton i s = (i,(Nothing,s)) + +fromStringList :: Map String Int -> [(String,String)] -> [GNode] +fromStringList m ns = + let change x = case (Map.lookup x m) of + Just a -> a + Nothing -> error "Grasp.Node.fromStringList: no value for key " ++ x + in map (\(x,y) -> (change x, (Just x, y))) ns + +lab :: GNode -> Maybe String +lab (_,(x,_)) = x + +inst :: GNode -> String +inst (_,(_,x)) = x + +idNo :: GNode -> Int +idNo (x,(_,_)) = x + -- cgit