Documentation ¶
Overview ¶
Package optlevel contains types that capture information about compiler optimisation levels.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrBadBias occurs when we try to marshal/unmarshal a bias that doesn't exist. ErrBadBias = errors.New("no such bias type") )
Functions ¶
This section is empty.
Types ¶
type Bias ¶
type Bias uint8
Bias is an enumeration of biases for optimisation levels.
const ( // BiasUnknown signifies that we don't know what the bias of this optimisation level is. BiasUnknown Bias = iota // BiasDebug signifies that an optimisation level biases towards debuggability. // Examples include '/Od' in MSVC (which disables optimisations), and '-Og' in GCC (which doesn't). BiasDebug // BiasSize signifies that an optimisation level biases towards size. // Examples include '-Os' in GCC, and '/O1' in MSVC. BiasSize // BiasSpeed signifies that an optimisation level biases towards speed. // Examples include '-O3' in GCC, and '/O2' in MSVC. BiasSpeed // NumBias marks the number of bias members. NumBias )
func BiasOfString ¶
BiasOfString tries to get the bias corresponding to s.
func (Bias) MarshalText ¶
MarshalText tries to marshal this bias into text.
func (*Bias) UnmarshalText ¶
UnmarshalText tries to unmarshal text into a Bias.
type Level ¶
type Level struct { // Optimises is true if this optimisation level actually optimises in any sense. // Counter-examples include '-O0' in gcc, and '/Od' in MSVC. Optimises bool `toml:"optimises,omitempty" json:"optimises,omitempty"` // Bias is this optimisation level's bias, if known. Bias Bias `toml:"bias,omitempty" json:"bias,omitempty"` // BreaksStandards is true if this optimisation level plays hard and fast with the C standard. // Examples include '-Ofast' in GCC. BreaksStandards bool `toml:"breaks_standards" json:"breaks_standards"` }
Level holds information about an optimisation level.
type Named ¶
type Named struct { // Name is the name of the optimisation level, which should be its command-line invocation less any prefix. Name string `toml:"name" json:"name"` Level }
Named wraps a Level with its command-line name.
type Selection ¶
type Selection struct { // Enabled overrides the default selection to insert optimisation levels. Enabled []string `toml:"enabled,omitempty"` // Disabled overrides the default selection to remove optimisation levels. Disabled []string `toml:"disabled,omitempty"` }
Selection represents a piece of compiler configuration that specifies which optimisation levels to select.
func (Selection) Override ¶
func (s Selection) Override(defaults stringhelp.Set) stringhelp.Set
Override inserts enables from this selection into defaults, then removes disables. Disables take priority over enables. The resulting map is a copy; this function doesn't mutate defaults.
Example ¶
ExampleSelection_Override is a testable example for Override.
package main import ( "fmt" "github.com/c4-project/c4t/internal/model/service/compiler/optlevel" ) func main() { sel := optlevel.Selection{ Enabled: []string{"g", "s"}, Disabled: []string{"fast"}, } for o := range sel.Override(map[string]struct{}{ "1": {}, "2": {}, "3": {}, "fast": {}, }) { fmt.Println(o) } }
Output: 1 2 3 g s