@@ -13,8 +13,8 @@ import (
13
13
14
14
analysis "github.com/xlab-uiuc/acto/ssa/passes"
15
15
"github.com/xlab-uiuc/acto/ssa/util"
16
+ "golang.org/x/tools/go/callgraph/cha"
16
17
"golang.org/x/tools/go/packages"
17
- "golang.org/x/tools/go/pointer"
18
18
"golang.org/x/tools/go/ssa"
19
19
"golang.org/x/tools/go/ssa/ssautil"
20
20
)
@@ -48,7 +48,7 @@ func analyze(projectPath string, seedType string, seedPkgPath string) string {
48
48
}
49
49
50
50
// Create SSA packages for well-typed packages and their dependencies.
51
- prog , _ := ssautil .AllPackages (initial , 0 )
51
+ prog , _ := ssautil .AllPackages (initial , ssa . PrintFunctions )
52
52
53
53
// Build SSA code for the whole program.
54
54
prog .Build ()
@@ -75,17 +75,8 @@ func analyze(projectPath string, seedType string, seedPkgPath string) string {
75
75
log .Println ("Running initial pass..." )
76
76
log .Printf ("Root Module is %s\n " , context .RootModule .Path )
77
77
78
- log .Println ("Constructing call graph using pointer analysis" )
79
- pointerCfg := pointer.Config {
80
- Mains : context .MainPackages ,
81
- BuildCallGraph : true ,
82
- }
83
- log .Printf ("Main packages %s\n " , context .MainPackages )
84
- result , err := pointer .Analyze (& pointerCfg )
85
- if err != nil {
86
- log .Fatalf ("Failed to run pointer analysis to construct callgraph %V\n " , err )
87
- }
88
- context .CallGraph = result .CallGraph
78
+ log .Println ("Constructing call graph using CHA" )
79
+ context .CallGraph = cha .CallGraph (context .Program )
89
80
log .Println ("Finished constructing call graph" )
90
81
91
82
valueFieldSetMap , frontierSet := analysis .GetValueToFieldMappingPass (context , prog , & seedType , & seedPkgPath )
@@ -106,43 +97,43 @@ func analyze(projectPath string, seedType string, seedPkgPath string) string {
106
97
for _ , field := range mergedFieldSet .Fields () {
107
98
analysisResult .UsedPaths = append (analysisResult .UsedPaths , field .Path )
108
99
}
109
- taintedFieldSet := analysis .TaintAnalysisPass (context , prog , frontierSet , valueFieldSetMap )
110
- for _ , field := range taintedFieldSet .Fields () {
111
- analysisResult .TaintedPaths = append (analysisResult .TaintedPaths , field .Path )
112
- }
100
+ // taintedFieldSet := analysis.TaintAnalysisPass(context, prog, frontierSet, valueFieldSetMap)
101
+ // for _, field := range taintedFieldSet.Fields() {
102
+ // analysisResult.TaintedPaths = append(analysisResult.TaintedPaths, field.Path)
103
+ // }
113
104
114
- analysis .GetDefaultValue (context , frontierSet , valueFieldSetMap )
115
- for value , constant := range context .DefaultValueMap {
116
- for _ , field := range context .ValueFieldMap [value ].Fields () {
117
- analysisResult .DefaultValues [field .String ()] = constant .Value .ExactString ()
118
- }
119
- }
105
+ // analysis.GetDefaultValue(context, frontierSet, valueFieldSetMap)
106
+ // for value, constant := range context.DefaultValueMap {
107
+ // for _, field := range context.ValueFieldMap[value].Fields() {
108
+ // analysisResult.DefaultValues[field.String()] = constant.Value.ExactString()
109
+ // }
110
+ // }
120
111
121
- analysis .Dominators (context , frontierSet )
122
- log .Printf ("%s\n " , context .String ())
112
+ // analysis.Dominators(context, frontierSet)
113
+ // log.Printf("%s\n", context.String())
123
114
124
- for field , conditionSet := range context .DomineeToConditions {
125
- var path []string
126
- json .Unmarshal ([]byte (field ), & path )
115
+ // for field, conditionSet := range context.DomineeToConditions {
116
+ // var path []string
117
+ // json.Unmarshal([]byte(field), &path)
127
118
128
- analysisResult .FieldConditions = append (analysisResult .FieldConditions , conditionSet .ToPlainConditionSet (path ))
119
+ // analysisResult.FieldConditions = append(analysisResult.FieldConditions, conditionSet.ToPlainConditionSet(path))
129
120
130
- }
121
+ // }
131
122
132
- copiedOverFieldSet := analysis .GetCopyOverFields (context )
123
+ // copiedOverFieldSet := analysis.GetCopyOverFields(context)
133
124
134
- for _ , field := range copiedOverFieldSet .Fields () {
135
- analysisResult .CopiedOverPaths = append (analysisResult .CopiedOverPaths , field .Path )
136
- log .Printf ("Copied over path %s" , field .Path )
137
- }
125
+ // for _, field := range copiedOverFieldSet.Fields() {
126
+ // analysisResult.CopiedOverPaths = append(analysisResult.CopiedOverPaths, field.Path)
127
+ // log.Printf("Copied over path %s", field.Path)
128
+ // }
138
129
139
130
// analysis.FindUsesInConditions(context, frontierSet)
140
- analysis .FindAllUses (context )
131
+ // analysis.FindAllUses(context)
141
132
142
- analysis .GetFieldToK8sMapping (context , context .Program , & seedType , & seedPkgPath )
143
- for field , mapping := range context .FieldToK8sMapping {
144
- analysisResult .FieldToK8sMapping [field .EncodedPath ()] = mapping
145
- }
133
+ // analysis.GetFieldToK8sMapping(context, context.Program, &seedType, &seedPkgPath)
134
+ // for field, mapping := range context.FieldToK8sMapping {
135
+ // analysisResult.FieldToK8sMapping[field.EncodedPath()] = mapping
136
+ // }
146
137
147
138
marshalled , _ := json .MarshalIndent (analysisResult , "" , "\t " )
148
139
return string (marshalled [:])
@@ -191,7 +182,13 @@ func main() {
191
182
192
183
log .Printf ("Building ssa program for project %s\n " , * projectPath )
193
184
194
- analyze (* projectPath , * seedType , * seedPkgPath )
185
+ result := analyze (* projectPath , * seedType , * seedPkgPath )
186
+ resultFile , err := os .Create ("result.json" )
187
+ if err != nil {
188
+ fmt .Fprintf (os .Stderr , "failed to create file for result: %v" , err )
189
+ return
190
+ }
191
+ resultFile .WriteString (result )
195
192
}
196
193
197
194
type AnalysisResult struct {
0 commit comments