forked from cs-au-dk/goat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pipeline.go
76 lines (64 loc) · 1.99 KB
/
pipeline.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package main
import (
"fmt"
"log"
"github.com/cs-au-dk/goat/analysis/cfg"
u "github.com/cs-au-dk/goat/analysis/upfront"
"golang.org/x/tools/go/ssa"
)
// pipeline is a wrapper around the analysis pipeline.
type pipeline struct {
prog *ssa.Program
mains []*ssa.Package
}
// standardPTAnalysisQueries is a standard set of queries for types to include in the Andersen points-to analysis.
var standardPTAnalysisQueries = u.IncludeType{
Chan: true,
Function: true,
Interface: true,
}
// preanalysisPipeline executes parts of the pre-analysis,
// by constructing the enhanced CFG and the points-to analysis.
func (p pipeline) preanalysisPipeline(includes u.IncludeType) (*u.PointerResult, *cfg.Cfg) {
fmt.Println()
log.Println("Performing points-to analysis...")
ptaResult := u.Andersen(p.prog, p.mains, includes)
log.Println("Points-to analysis done")
fmt.Println()
log.Println("Extending CFG...")
progCfg := cfg.GetCFG(p.prog, p.mains, &ptaResult.Result)
log.Println("CFG extensions done")
fmt.Println()
opts.OnVerbose(func() {
for val, ptr := range ptaResult.Queries {
fmt.Printf("Points to information for \"%s\" at %d (%s):\n",
val, val.Pos(), p.prog.Fset.Position(val.Pos()))
for _, label := range ptr.PointsTo().Labels() {
fmt.Printf("%s : %d (%s), ", label, (*label).Pos(), p.prog.Fset.Position((*label).Pos()))
}
fmt.Print("\n\n")
}
})
return ptaResult, progCfg
}
// fullPreanalysisPipeline executes the pre-analysis by performing
// a full pre-analysis.
func (p pipeline) fullPreanalysisPipeline(includes u.IncludeType) (
*u.PointerResult,
*cfg.Cfg,
u.GoTopology,
) {
ptaResult, progCfg := p.preanalysisPipeline(includes)
log.Println("Constructing Goroutine topology...")
goros := u.CollectGoros(&ptaResult.Result)
log.Println("Goroutine topology done")
opts.OnVerbose(func() {
fmt.Println("Found the following goroutines:")
for _, goro := range goros {
fmt.Println(goro.String())
fmt.Println()
}
fmt.Println()
})
return ptaResult, progCfg, goros
}