Skip to content

Commit

Permalink
refactor main logic
Browse files Browse the repository at this point in the history
  • Loading branch information
moricho committed Sep 3, 2020
1 parent 8033ae3 commit c7ea674
Showing 1 changed file with 17 additions and 18 deletions.
35 changes: 17 additions & 18 deletions tparallel.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,26 +37,13 @@ func run(pass *analysis.Pass) (interface{}, error) {

testMap := getTestMap(ssaanalyzer, testTyp)
for top, subs := range testMap {
isParallelTop, isPararellSub := false, false
for _, block := range top.Blocks {
for _, instr := range block.Instrs {
called := analysisutil.Called(instr, nil, parallel)
if called {
isParallelTop = true
break
}
}
}
isParallelTop := isParallel(top, parallel)

isPararellSub := false
for _, sub := range subs {
for _, block := range sub.Blocks {
for _, instr := range block.Instrs {
called := analysisutil.Called(instr, nil, parallel)
if called {
isPararellSub = true
break
}
}
isPararellSub = isParallel(sub, parallel)
if isPararellSub {
break
}
}

Expand All @@ -72,6 +59,18 @@ func run(pass *analysis.Pass) (interface{}, error) {
return nil, nil
}

func isParallel(f *ssa.Function, typ *types.Func) bool {
for _, block := range f.Blocks {
for _, instr := range block.Instrs {
called := analysisutil.Called(instr, nil, typ)
if called {
return true
}
}
}
return false
}

func getTestMap(ssaanalyzer *buildssa.SSA, testTyp types.Type) map[*ssa.Function][]*ssa.Function {
testMap := map[*ssa.Function][]*ssa.Function{}

Expand Down

0 comments on commit c7ea674

Please sign in to comment.