gcc

package
Version: v0.0.0-...-0d16973 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 10, 2021 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	ErrMalformedArchId    = errors.New("bad arch ID")
	ErrUnsupportedFamily  = errors.New("unsupported cpu family")
	ErrUnsupportedVariant = errors.New("unsupported cpu variant")
)
View Source
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

func AddKindArg(args []string, k compiler.Target) []string

AddKindArg adds to args the appropriate GCC argument for achieving the compile kind mentioned in k.

func AddStringArg

func AddStringArg(args []string, k, v string) []string

AddStringArg adds the argument '-[k][v]' (note lack of equals sign) to args if v is non-blank; else, returns args.

func Args

func Args(j compiler.Job) []string

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

func MOpts

func MOpts(arch id.ID) (stringhelp.Set, error)

MOpts gets the default 'm' invocations (march, mcpu, etc.) to consider for compilers with archID arch.

Types

type GCC

type GCC service.ExtClass

GCC represents GCC-style compilers such as GCC and Clang.

func (GCC) DefaultMOpts

func (g GCC) DefaultMOpts(c *compiler.Compiler) (stringhelp.Set, error)

DefaultMOpts adapts the GCC mopts calculation to the interface needed for a compiler.

func (GCC) DefaultOptLevels

func (g GCC) DefaultOptLevels(_ *compiler.Compiler) (stringhelp.Set, error)

DefaultOptLevels gets the default level set for GCC.

func (GCC) OptLevels

func (_ GCC) OptLevels(_ *compiler.Compiler) (map[string]optlevel.Level, error)

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

func (g GCC) RunCompiler(ctx context.Context, j compiler.Job, sr service.Runner) error

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL