Remove -cformatter flag

This commit is contained in:
Nigel Tao committed 2020-06-05 00:08:05 +10:00
1 parent 12b0f4c0bc
commit 8cd39fc1dd
5 files changed
+5 -56

No files matched your search

+3 -37
View File
@@ -17,16 +17,12 @@
package cgen
import (
"bytes"
"errors"
"flag"
"fmt"
"math/big"
"os"
"os/exec"
"sort"
"strings"
"time"
"github.com/google/wuffs/lang/builtin"
"github.com/google/wuffs/lang/generate"
@@ -114,19 +110,9 @@ var BaseSubModules = []string{
// The generated program is written to stdout.
func Do(args []string) error {
flags := flag.FlagSet{}
cformatterFlag := flags.String("cformatter", cf.CformatterDefault, cf.CformatterUsage)
genlinenumFlag := flags.Bool("genlinenum", cf.GenlinenumDefault, cf.GenlinenumUsage)
return generate.Do(&flags, args, func(pkgName string, tm *t.Map, files []*a.File) ([]byte, error) {
// printTimings set true will print the time taken for the cformatter
// and other work.
const printTimings = false
now := time.Now()
if !cf.IsAlphaNumericIsh(*cformatterFlag) {
return nil, fmt.Errorf("bad -cformatter flag value %q", *cformatterFlag)
}
unformatted := []byte(nil)
if pkgName == "base" {
if len(files) != 0 {
@@ -189,35 +175,15 @@ func Do(args []string) error {
}
}
if printTimings {
fmt.Fprintf(os.Stderr, "%8d milliseconds generating the C code\n",
time.Since(now).Milliseconds())
now = time.Now()
}
// The base package is largely hand-written C, not transpiled from
// Wuffs, and that part is presumably already formatted. The rest is
// generated by this package. We take care here to print well indented
// C code, so further C formatting is unnecessary (and not costless).
if (*cformatterFlag == "") || (pkgName == "base") {
// C code, so further C formatting is unnecessary.
if pkgName == "base" {
return unformatted, nil
} else if *cformatterFlag == "dumbindent" {
return dumbindent.Format(unformatted)
}
stdout := &bytes.Buffer{}
cmd := exec.Command(*cformatterFlag, "-style=Chromium")
cmd.Stdin = bytes.NewReader(unformatted)
cmd.Stdout = stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
return nil, err
}
if printTimings {
fmt.Fprintf(os.Stderr, "%8d milliseconds formatting the C code via %q\n",
time.Since(now).Milliseconds(), *cformatterFlag)
}
return stdout.Bytes(), nil
return dumbindent.Format(unformatted)
})
}