litmus

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: 18 Imported by: 0

Documentation

Overview

Package litmus contains the parts of a Herdtools backend specific to litmus7.

Index

Examples

Constants

View Source
const (
	// IncludeStdbool is the include directive that the litmus patcher will insert if needed.
	// It is exported for testing purposes.
	IncludeStdbool = "#include <stdbool.h>"
)

Variables

View Source
var (
	// ErrNoFileIn occurs when the input file is empty.
	ErrNoFileIn = errors.New("need input file")

	// ErrNoDirOut occurs when the output directory is empty.
	ErrNoDirOut = errors.New("need output directory")
)

Functions

This section is empty.

Types

type Fixset

type Fixset struct {
	// InjectStdbool is true when the Litmus header needs includes to 'stdbool.h' enabling.
	InjectStdbool bool

	// UseAsCall is true when Litmus needs the '-ascall' flag enabling.
	UseAsCall bool

	// RemoveAtomicCasts is true when casts to (_Atomic int) in the outcome dumper must be removed.
	RemoveAtomicCasts bool
}

Fixset contains the various fix-ups that the litmus tool needs to do before and after the run to Litmus.

func (*Fixset) Args

func (f *Fixset) Args() []string

Args converts the part of the fixset that relates to litmus7 arguments into an argument slice to send to litmus7.

Example

ExampleFixset_Args is a runnable example for Args.

package main

import (
	"fmt"

	"github.com/c4-project/c4t/internal/serviceimpl/backend/herdstyle/litmus"
)

func main() {
	f := litmus.Fixset{InjectStdbool: true, UseAsCall: true}
	for _, s := range f.Args() {
		fmt.Println(s)
	}

}
Output:

-ascall
true

func (*Fixset) Dump

func (f *Fixset) Dump(w io.Writer) error

Dump dumps a human-readable description of the fixset to the given writer.

Example

ExampleFixset_Dump is a runnable example for Write.

package main

import (
	"os"

	"github.com/c4-project/c4t/internal/serviceimpl/backend/herdstyle/litmus"
)

func main() {
	f := litmus.Fixset{InjectStdbool: true, UseAsCall: true}
	_ = f.Dump(os.Stdout)

}
Output:

injecting stdbool
using -ascall

func (*Fixset) NeedsPatch

func (f *Fixset) NeedsPatch() bool

NeedsPatch checks whether patching the litmus harness is necessary.

Example

ExampleFixset_NeedsPatch is a runnable example for NeedsPatch.

package main

import (
	"fmt"

	"github.com/c4-project/c4t/internal/serviceimpl/backend/herdstyle/litmus"
)

func main() {
	fmt.Println((&litmus.Fixset{}).NeedsPatch())
	fmt.Println((&litmus.Fixset{UseAsCall: true}).NeedsPatch())
	fmt.Println((&litmus.Fixset{InjectStdbool: true}).NeedsPatch())

}
Output:

false
false
true

func (*Fixset) PatchMainFile

func (f *Fixset) PatchMainFile(r io.Reader, w io.Writer) error

PatchMainFile patches the main C file represented by rw according to this fixset.

func (*Fixset) PopulateFromLitmus

func (f *Fixset) PopulateFromLitmus(l *litmus.Litmus)

PopulateFromLitmus switches various fixes on as appropriate for the Litmus file l.

func (*Fixset) PopulateFromStats

func (f *Fixset) PopulateFromStats(s *litmus.Statset)

PopulateFromStats switches various fixes on according to the statistics in s.

type Instance

type Instance struct {
	// Job contains the lifting job being processed.
	Job backend.LiftJob

	// RunInfo contains the appropriately resolved run info for running Litmus.
	RunInfo service.RunInfo

	// Runner is the thing that actually runs Litmus.
	Runner service.Runner
}

Instance holds all state needed to do one run of Litmus.

func (*Instance) Run

func (l *Instance) Run(ctx context.Context) error

Run runs the litmus wrapper according to the configuration c.

Example

ExampleInstance_Run is a testable example for Run.

package main

import (
	"context"
	"os"

	"github.com/c4-project/c4t/internal/model/service/backend"

	"github.com/c4-project/c4t/internal/helper/srvrun"

	"github.com/c4-project/c4t/internal/serviceimpl/backend/herdstyle/litmus"

	"github.com/c4-project/c4t/internal/id"
	mdl "github.com/c4-project/c4t/internal/model/litmus"
	"github.com/c4-project/c4t/internal/model/service"
)

func main() {
	i := litmus.Instance{
		Job: backend.LiftJob{
			Arch: id.ArchX8664,
			In:   backend.LiftLitmusInput(mdl.NewOrPanic("in.litmus", mdl.WithArch(id.ArchC))),
			Out:  backend.LiftOutput{Dir: "out", Target: backend.ToExeRecipe},
		},
		RunInfo: service.RunInfo{Cmd: "litmus7", Args: []string{"-v"}},
		Runner:  srvrun.DryRunner{Writer: os.Stdout},
	}

	// We don't ask for a fixset, so we won't have any patching.
	_ = i.Run(context.Background())

}
Output:

litmus7 -v -o out -carch X86_64 -c11 true in.litmus

type Litmus

type Litmus struct{}

Litmus describes the parts of a backend invocation that are specific to Litmus.

func (Litmus) LiftExe

LiftExe runs litmus in a mode that generates files compilable into an executable.

func (Litmus) LiftStandalone

func (l Litmus) LiftStandalone(ctx context.Context, j backend.LiftJob, r service.RunInfo, x service.Runner, w io.Writer) error

LiftStandalone runs litmus in standalone mode. It currently doesn't do the same patching as LiftExe does.

func (Litmus) ParsePreTestLine

func (Litmus) ParsePreTestLine([]string) (obs.Flag, error)

ParsePreTestLine does nothing, as pre-Test lines have no meaning in Litmus.

func (Litmus) ParseStateCount

func (l Litmus) ParseStateCount(fields []string) (k uint64, ok bool, err error)

ParseStateCount parses a Litmus state count.

func (Litmus) ParseStateLine

func (l Litmus) ParseStateLine(tt parser.TestType, fields []string) (*parser.StateLine, error)

type Pathset

type Pathset struct {
	// FileIn is the input file path.
	FileIn string

	// DirOut is the output directory path.
	DirOut string
}

Pathset contains the paths used in a litmus invocation.

func (*Pathset) Args

func (p *Pathset) Args() []string

Args gets this pathset's contribution to the litmus invocation arguments. These arguments should go at the end of the invocation.

Example

ExamplePathset_Args is a runnable example for Args.

package main

import (
	"fmt"

	litmus2 "github.com/c4-project/c4t/internal/serviceimpl/backend/herdstyle/litmus"
)

func main() {
	for _, arg := range (&litmus2.Pathset{
		FileIn: "/home/foo/bar/baz.litmus",
		DirOut: "/tmp/scratch/",
	}).Args() {
		fmt.Println(arg)
	}

}
Output:

-o
/tmp/scratch/
/home/foo/bar/baz.litmus

func (*Pathset) Check

func (p *Pathset) Check() error

Check checks that the various paths in Pathset are populated. It doesn't check that they exist.

func (*Pathset) MainCFile

func (p *Pathset) MainCFile() string

MainCFile guesses where Litmus is going to put the main file in its generated harness.

Example

ExamplePathset_MainCFile is a runnable example for MainCFile.

package main

import (
	"fmt"

	litmus2 "github.com/c4-project/c4t/internal/serviceimpl/backend/herdstyle/litmus"
)

func main() {
	fmt.Println((&litmus2.Pathset{
		FileIn: "/home/foo/bar/baz.litmus",
		DirOut: "/tmp/scratch/",
	}).MainCFile())

}
Output:

/tmp/scratch/baz.c

Jump to

Keyboard shortcuts

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