Documentation ¶
Index ¶
- Variables
- func AddKindArg(args []string, k compiler.Target) []string
- func AddStringArg(args []string, k, v string) []string
- func Args(j compiler.Job) []string
- func MOpts(arch id.ID) (stringhelp.Set, error)
- type GCC
- func (g GCC) DefaultMOpts(c *compiler.Compiler) (stringhelp.Set, error)
- func (g GCC) DefaultOptLevels(_ *compiler.Compiler) (stringhelp.Set, error)
- func (_ GCC) OptLevels(_ *compiler.Compiler) (map[string]optlevel.Level, error)
- func (g GCC) Probe(ctx context.Context, sr service.Runner, classId id.ID, ...) error
- func (g GCC) RunCompiler(ctx context.Context, j compiler.Job, sr service.Runner) error
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrMalformedArchId = errors.New("bad arch ID") ErrUnsupportedFamily = errors.New("unsupported cpu family") ErrUnsupportedVariant = errors.New("unsupported cpu variant") )
var ( // OptLevels contains the optimisation levels known to exist on GCC, Clang, AppleClang etc. OptLevels = map[string]optlevel.Level{ "0": { Optimises: false, Bias: optlevel.BiasDebug, BreaksStandards: false, }, "1": { Optimises: true, Bias: optlevel.BiasSpeed, BreaksStandards: false, }, "2": { Optimises: true, Bias: optlevel.BiasSpeed, BreaksStandards: false, }, "3": { Optimises: true, Bias: optlevel.BiasSpeed, BreaksStandards: false, }, "fast": { Optimises: true, Bias: optlevel.BiasSpeed, BreaksStandards: true, }, "s": { Optimises: true, Bias: optlevel.BiasSize, BreaksStandards: false, }, "z": { Optimises: true, Bias: optlevel.BiasSize, BreaksStandards: false, }, "g": { Optimises: true, Bias: optlevel.BiasDebug, BreaksStandards: false, }, "": { Optimises: true, Bias: optlevel.BiasSpeed, BreaksStandards: false, }, } // OptLevelNames is a consistently named list of the optimisation levels in OptLevels. OptLevelNames = []string{"", "0", "1", "2", "3", "fast", "s", "z", "g"} // OptLevelDisabledNames contains optimisation levels that are disabled by default, as they are redundant or non-portable. OptLevelDisabledNames = []string{"", "0", "g", "z"} )
Functions ¶
func AddKindArg ¶
AddKindArg adds to args the appropriate GCC argument for achieving the compile kind mentioned in k.
func AddStringArg ¶
AddStringArg adds the argument '-[k][v]' (note lack of equals sign) to args if v is non-blank; else, returns args.
func Args ¶
Args computes the arguments to pass to GCC for running job j. It does not take j's run info into consideration, and assumes this has already been done.
Example ¶
ExampleArgs is a runnable example for Args.
package main import ( "fmt" "github.com/c4-project/c4t/internal/model/service/compiler" "github.com/c4-project/c4t/internal/serviceimpl/compiler/gcc" ) func main() { args := gcc.Args( *compiler.NewJob(compiler.Exe, nil, "a.out", "foo.c", "bar.c"), ) for _, arg := range args { fmt.Println(arg) } }
Output: -o a.out foo.c bar.c
Example (Opt) ¶
ExampleArgs_opt is a runnable example for Args that shows optimisation level selection.
package main import ( "fmt" "github.com/c4-project/c4t/internal/model/service/compiler" "github.com/c4-project/c4t/internal/model/service/compiler/optlevel" "github.com/c4-project/c4t/internal/serviceimpl/compiler/gcc" ) func main() { args := gcc.Args( *compiler.NewJob( compiler.Exe, &compiler.Instance{SelectedOpt: &optlevel.Named{Name: "size"}}, "a.out", "foo.c", "bar.c", ), ) for _, arg := range args { fmt.Println(arg) } }
Output: -Osize -o a.out foo.c bar.c
Types ¶
type GCC ¶
GCC represents GCC-style compilers such as GCC and Clang.
func (GCC) DefaultMOpts ¶
DefaultMOpts adapts the GCC mopts calculation to the interface needed for a compiler.
func (GCC) DefaultOptLevels ¶
DefaultOptLevels gets the default level set for GCC.
func (GCC) Probe ¶
func (g GCC) Probe(ctx context.Context, sr service.Runner, classId id.ID, target compiler.ConfigMap) error
Probe probes for GCC-style compilers, adding them to target.
func (GCC) RunCompiler ¶
RunCompiler compiles j using a GCC-friendly invocation.
Example ¶
ExampleGCC_RunCompiler is a runnable example for GCC.RunCompiler.
package main import ( "context" "os" "github.com/c4-project/c4t/internal/helper/srvrun" "github.com/c4-project/c4t/internal/model/service/compiler" "github.com/c4-project/c4t/internal/model/service/compiler/optlevel" "github.com/c4-project/c4t/internal/serviceimpl/compiler/gcc" "github.com/c4-project/c4t/internal/model/service" ) func main() { g := gcc.GCC{DefaultRunInfo: service.RunInfo{Cmd: "gcc"}} j := compiler.Job{ Compiler: &compiler.Instance{ SelectedMOpt: "arch=skylake", SelectedOpt: &optlevel.Named{ Name: "3", Level: optlevel.Level{Optimises: true, Bias: optlevel.BiasSpeed, BreaksStandards: false}, }, Compiler: compiler.Compiler{ Run: &service.RunInfo{Env: map[string]string{"TMPDIR": "/tmp"}}, }, }, In: []string{"foo.c", "bar.c"}, Out: "a.out", Kind: compiler.Exe, } sr := srvrun.DryRunner{Writer: os.Stdout} _ = g.RunCompiler(context.Background(), j, sr) }
Output: TMPDIR=/tmp gcc -O3 -march=skylake -o a.out foo.c bar.c