Skip to content

Commit

Permalink
Add a --verbose flag that prints out commands run.
Browse files Browse the repository at this point in the history
I found this useful to iterate more quickly on flags provided to clang, so I could see the precise command run by goat and then modify it and try other other things.
  • Loading branch information
asimshankar authored Jul 3, 2024
1 parent 7fa08a9 commit 6506c1a
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (t *TranslateUnit) parseSource() ([]Function, error) {
ast, err := cc.Parse(&cc.Config{}, nil, includePaths,
[]cc.Source{{Name: t.Source, Value: source}})
if err != nil {
return nil, err
return nil, fmt.Errorf("failed to parse source file %v with include paths %v: %w", t.Source, includePaths, err)
}
var functions []Function
for _, nodes := range ast.Scope {
Expand Down Expand Up @@ -269,6 +269,9 @@ func (t *TranslateUnit) convertFunctionParameters(params *cc.ParameterList) ([]s

// runCommand runs a command and extract its output.
func runCommand(name string, arg ...string) (string, error) {
if verbose {
fmt.Fprintf(os.Stderr, "Running %v\n", append([]string{name}, arg...))
}
cmd := exec.Command(name, arg...)
output, err := cmd.CombinedOutput()
if err != nil {
Expand All @@ -281,6 +284,8 @@ func runCommand(name string, arg ...string) (string, error) {
return string(output), nil
}

var verbose bool

var command = &cobra.Command{
Use: "goat source [-o output_directory]",
Args: cobra.ExactArgs(1),
Expand Down Expand Up @@ -315,6 +320,7 @@ func init() {
command.PersistentFlags().StringSliceP("machine-option", "m", nil, "machine option for clang")
command.PersistentFlags().StringSliceP("extra-option", "e", nil, "extra option for clang")
command.PersistentFlags().IntP("optimize-level", "O", 0, "optimization level for clang")
command.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "if set, increase verbosity level")
}

func main() {
Expand Down

0 comments on commit 6506c1a

Please sign in to comment.