Skip to content

Commit

Permalink
Move ssadump to cmd/ssadump
Browse files Browse the repository at this point in the history
  • Loading branch information
picatz committed Jan 3, 2024
1 parent 7bc76a8 commit 97994d7
Showing 1 changed file with 30 additions and 3 deletions.
33 changes: 30 additions & 3 deletions ssadump/main.go → cmd/ssadump/main.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,31 @@
package main

import (
"context"
"fmt"
"go/ast"
"go/parser"
"go/token"
"os"
"os/signal"

"golang.org/x/tools/go/packages"
"golang.org/x/tools/go/ssa"
"golang.org/x/tools/go/ssa/ssautil"
)

func main() {
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt)
defer cancel()

patterns := os.Args[1:]

var allNeeds = packages.NeedName |
if len(patterns) == 0 {
fmt.Fprintf(os.Stderr, "usage: %s <patterns>\n", os.Args[0])
os.Exit(1)
}

loadMode := packages.NeedName |
packages.NeedFiles |
packages.NeedCompiledGoFiles |
packages.NeedImports |
Expand All @@ -22,8 +35,22 @@ func main() {
packages.NeedTypesInfo |
packages.NeedDeps

var cfg = &packages.Config{
Mode: allNeeds,
parseMode := parser.SkipObjectResolution

dir, err := os.Getwd()
if err != nil {
fmt.Fprintf(os.Stderr, "failed to get current working directory: %v\n", err.Error())
os.Exit(1)
}

cfg := &packages.Config{
Mode: loadMode,
Context: ctx,
Dir: dir,
Env: os.Environ(),
ParseFile: func(fset *token.FileSet, filename string, src []byte) (*ast.File, error) {
return parser.ParseFile(fset, filename, src, parseMode)
},
}

initial, err := packages.Load(cfg, patterns...)
Expand Down

0 comments on commit 97994d7

Please sign in to comment.