structure Set = Color.Set fun igNodeAttrToStr(attr) = case attr of Color.PRECOLORED => "Precolored" | Color.INITIAL => "Initial" | Color.SIMPLIFYWORK => "Simplifywork" | Color.FREEZEWORK => "Freezework" | Color.SPILLWORK => "Spillwork" | Color.SPILLED => "Spilled" | Color.COALESCED => "Coalesced" | Color.COLORED => "Colored" | Color.SELECTED => "Selected" fun showIgNode output tnode gtemp igNodeAttrTbl getAdjacentTemps igNode = let fun getIgNodeAttr node = valOf(Graph.Table.look(igNodeAttrTbl, node)) fun getIgNodeStr node = let val igNodeAttr = getIgNodeAttr node in "\"" ^ Main.makestring(gtemp(node)) ^ "\\n" ^ igNodeAttrToStr(igNodeAttr) ^ "\"" end fun getIgNodeExtAttrStr node = let val igNodeAttr = getIgNodeAttr node in case igNodeAttr of Color.PRECOLORED => "[color=red,fontcolor=red]" | Color.INITIAL => "[color=black,fontcolor=black]" | _ => "" end val adjTempsSetInitial = Set.addList(Set.empty, List.map gtemp (Graph.adj(igNode))) val adjTempsSetCurrent = getAdjacentTemps igNode val adjTempsList = Set.listItems(adjTempsSetInitial) fun getAdjIgNodesStr temp = "\t" ^ getIgNodeStr igNode ^ " -- " ^ getIgNodeStr (tnode temp) fun getAdjIgNodesAttrStr temp = let val isAdj = Set.exists (fn n => n = temp) adjTempsSetCurrent in if isAdj = true then " [style=solid]" else " [style=invis]" end in (output("\t" ^ getIgNodeStr igNode ^ getIgNodeExtAttrStr igNode ^ "\n"); app (fn n => output(getAdjIgNodesStr n ^ getAdjIgNodesAttrStr n ^ "\n")) adjTempsList) end fun putIGraph out filename = let fun output(str) = TextIO.output(out,str) val instrsAndFrameList = Main.getInstrsAndFrameList filename val (instrs,frame) = hd(instrsAndFrameList) val (fGraph as Flow.FGRAPH{control=fControl, ismove=isMoveTable,...}, fgNodes) = MakeGraph.instrs2graph(instrs) val (interference, gtMap) = Liveness.interferenceGraph(fGraph) fun initMoveAttr(fgNode,moveAttrTbl) = if valOf(Graph.Table.look(isMoveTable,fgNode)) = true then Graph.Table.enter(moveAttrTbl,fgNode,Color.WORKLIST_MOVE) else moveAttrTbl val fgNodeList = Graph.nodes(fControl) val moveAttrTblInitial = foldl initMoveAttr Graph.Table.empty fgNodeList val initial = Frame.tempMap val Liveness.IGRAPH{graph=iGraph, tnode=tnode, gtemp=gtemp, moves=moves} = interference val igNodeList = Graph.nodes(iGraph) val igNodeAttrTblInitial = Color.getInitialIgNodeAttrTbl(gtemp, initial, igNodeList) val getAdjacentTemps = Color.getAdjacentTempsBase (igNodeAttrTblInitial, igNodeList, gtemp) in (output("graph G {\n"); output("\tnode[fontsize=10,width=.1,height=.05]\n"); output("\tedge[len=2]\n"); app (showIgNode output tnode gtemp igNodeAttrTblInitial getAdjacentTemps) igNodeList; output("}\n")) end fun writeIGraph filename = Main.withOpenFile (filename ^ ".nto") (fn out => putIGraph out filename) (* A test just to make sure RegAlloc.alloc won't crash *) fun regAllocTest filename = let val instrsAndFrameList = Main.getInstrsAndFrameList filename val instrsAndFrame = hd(instrsAndFrameList) val result = RegAlloc.alloc instrsAndFrame in () (* discarding result for now - will be checked in future tests *) end