示例#1
0
文件: merge.go 项目: decomp/decomp
// dump stores the graph as a DOT file and an image representation of the graph
// as a PNG file with filenames based on "-o" flag.
func dump(graph *dot.Graph) error {
	// Store graph to DOT file.
	dotPath := flagOut
	if !flagQuiet {
		log.Printf("Creating: %q\n", dotPath)
	}
	err := ioutil.WriteFile(dotPath, []byte(graph.String()), 0644)
	if err != nil {
		return errutil.Err(err)
	}

	// Generate an image representation of the graph.
	if flagImage {
		pngPath := pathutil.TrimExt(dotPath) + ".png"
		if !flagQuiet {
			log.Printf("Creating: %q\n", pngPath)
		}
		cmd := exec.Command("dot", "-Tpng", "-o", pngPath, dotPath)
		cmd.Stdout = os.Stdout
		cmd.Stderr = os.Stderr
		err = cmd.Run()
		if err != nil {
			return errutil.Err(err)
		}
	}

	return nil
}
示例#2
0
// createDOT creates a DOT graph with the given file name.
func createDOT(stepName string, graph *dot.Graph) error {
	dotPath := stepName + ".dot"
	if !flagQuiet {
		log.Printf("Creating: %q", dotPath)
	}
	buf := []byte(graph.String())
	if err := ioutil.WriteFile(dotPath, buf, 0644); err != nil {
		return errutil.Err(err)
	}

	// Generate an image representation of the control flow graph.
	if flagImage {
		pngPath := stepName + ".png"
		if !flagQuiet {
			log.Printf("Creating: %q", pngPath)
		}
		cmd := exec.Command("dot", "-Tpng", "-o", pngPath, dotPath)
		cmd.Stdout = os.Stdout
		cmd.Stderr = os.Stderr
		if err := cmd.Run(); err != nil {
			return errutil.Err(err)
		}
	}
	return nil
}
示例#3
0
文件: merge.go 项目: decomp/decomp
// Merge merges the nodes of the isomorphism of sub in graph into a single node.
// If successful it returns the name of the new node.
func Merge(graph *dot.Graph, m map[string]string, sub *graphs.SubGraph) (name string, err error) {
	var nodes []*dot.Node
	for _, gname := range m {
		node, ok := graph.Nodes.Lookup[gname]
		if !ok {
			return "", errutil.Newf("unable to locate mapping for node %q", gname)
		}
		nodes = append(nodes, node)
	}
	name = uniqName(graph, sub.Name)
	entry, ok := graph.Nodes.Lookup[m[sub.Entry()]]
	if !ok {
		return "", errutil.Newf("unable to locate mapping for entry node %q", sub.Entry())
	}
	exit, ok := graph.Nodes.Lookup[m[sub.Exit()]]
	if !ok {
		return "", errutil.Newf("unable to locate mapping for exit node %q", sub.Exit())
	}
	err = graph.Replace(nodes, name, entry, exit)
	if err != nil {
		return "", errutil.Err(err)
	}
	return name, nil
}