package printer

import "github.com/mmcloughlin/avo/printer"

Package printer implements printing of avo files in various formats.

Index

Examples

Types

type Builder

type Builder func(Config) Printer

Builder can construct a printer.

type Config

type Config struct {
	// Command-line arguments passed to the generator. If provided, this will be
	// included in a code generation warning.
	Argv []string

	// Name of the code generator.
	Name string

	// Name of Go package the generated code will belong to.
	Pkg string
}

Config represents general printing configuration.

func NewArgvConfig

func NewArgvConfig() Config

NewArgvConfig constructs a Config from os.Args. The package name is guessed from the current directory.

func NewDefaultConfig

func NewDefaultConfig() Config

NewDefaultConfig produces a config with Name "avo". The package name is guessed from the current directory.

func NewGoRunConfig

func NewGoRunConfig() Config

NewGoRunConfig produces a Config for a generator that's expected to be executed via "go run ...".

func (Config) GeneratedBy

func (c Config) GeneratedBy() string

GeneratedBy returns a description of the code generator.

Example

Code:play 

package main

import (
	"fmt"

	"github.com/mmcloughlin/avo/printer"
)

func main() {
	// Default configuration named "avo".
	cfg := printer.NewDefaultConfig()
	fmt.Println(cfg.GeneratedBy())

	// Name can be customized.
	cfg = printer.Config{
		Name: "mildred",
	}
	fmt.Println(cfg.GeneratedBy())

	// Argv takes precedence.
	cfg = printer.Config{
		Argv: []string{"echo", "hello", "world"},
		Name: "mildred",
	}
	fmt.Println(cfg.GeneratedBy())

}

Output:

avo
mildred
command: echo hello world

func (Config) GeneratedWarning

func (c Config) GeneratedWarning() string

GeneratedWarning returns text for a code generation warning. Conforms to https://golang.org/s/generatedcode.

type Printer

type Printer interface {
	Print(*ir.File) ([]byte, error)
}

Printer can produce output for an avo File.

func NewGoAsm

func NewGoAsm(cfg Config) Printer

NewGoAsm constructs a printer for writing Go assembly files.

func NewStubs

func NewStubs(cfg Config) Printer

NewStubs constructs a printer for writing stub function declarations.

Source Files

goasm.go printer.go stubs.go

Version
v0.6.0 (latest)
Published
Jan 7, 2024
Platform
windows/amd64
Imports
11 packages
Last checked
1 month ago

Tools for package owners.