optlevel

package
v0.0.0-...-1dd1f65 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2023 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package optlevel contains types that capture information about compiler optimisation levels.

Index

Examples

Constants

This section is empty.

Variables

View Source
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

func BiasOfString(s string) (Bias, error)

BiasOfString tries to get the bias corresponding to s.

func (Bias) MarshalText

func (b Bias) MarshalText() ([]byte, error)

MarshalText tries to marshal this bias into text.

func (Bias) String

func (b Bias) String() string

String converts this bias into a human-readable string.

func (*Bias) UnmarshalText

func (b *Bias) UnmarshalText(text []byte) error

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

Jump to

Keyboard shortcuts

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