Documentation ¶
Overview ¶
Package pogo provides the generic components of a tool for transforming the go.tools/go/ssa form of Go programs to other languages
Index ¶
- Constants
- Variables
- func FindTargetLang(s string) (k int, e error)
- func MemberNamesSorted(pkg *ssa.Package) []string
- type Compilation
- func (comp *Compilation) CodePosition(pos token.Pos) string
- func (comp *Compilation) FloatVal(eVal constant.Value, bits int, posStr string) string
- func (comp *Compilation) FnIsCalled(fn *ssa.Function) bool
- func (comp *Compilation) FuncPathName(fn *ssa.Function) (path, name string)
- func (comp *Compilation) FuncValue(obj *types.Func) ssa.Value
- func (comp *Compilation) GetFnNameParts(fn *ssa.Function) (pack, nam string)
- func (comp *Compilation) GlobalList() []GlobalInfo
- func (comp *Compilation) InlineMap(key string) (val string, ok bool)
- func (comp *Compilation) IntVal(eVal constant.Value, posStr string) (high, low int32)
- func (comp *Compilation) IsOverloaded(f *ssa.Function) bool
- func (comp *Compilation) IsValidInPogo(et types.Type, posStr string) bool
- func (comp *Compilation) LogError(loc, lang string, err error)
- func (comp *Compilation) LogTypeUse(t types.Type) string
- func (comp *Compilation) LogWarning(loc, lang string, err error)
- func (comp *Compilation) MakePosHash(pos token.Pos) PosHash
- func (comp *Compilation) MethodSetFor(T types.Type) *types.MethodSet
- func (comp *Compilation) Recycle()
- func (comp *Compilation) RegisterName(val ssa.Value) string
- func (comp *Compilation) RootProgram() *ssa.Program
- func (comp *Compilation) TypesWithMethodSets() (sets []types.Type)
- func (comp *Compilation) WriteAsClass(name, code string)
- type FileOutput
- type GlobalInfo
- type Language
- type LanguageEntry
- type PackageSorter
- type PosHash
- type PosHashFileStruct
- type TypeSorter
Constants ¶
const NoPosHash = PosHash(0)
NoPosHash is a code position hash constant to represent none, lines number from 1, so 0 is invalid.
Variables ¶
var LanguageList = make([]LanguageEntry, 0, 10)
LanguageList holds the languages that can be targeted, and compilation run data
Functions ¶
func FindTargetLang ¶
FindTargetLang returns the 1st LanguageList entry for the given language
func MemberNamesSorted ¶
MemberNamesSorted provides a sorted list of package member names
Types ¶
type Compilation ¶
type Compilation struct { TargetLang int // TargetLang holds the language currently being targeted, offset into LanguageList. LibListNoDCE []string PosHashFileList []PosHashFileStruct // PosHashFileList holds the list of input go files with their posHash information LatestValidPosHash PosHash // LatestValidPosHash holds the latest valid PosHash value seen, for use when an invalid one requires a "near" reference. TypesEncountered typeutil.Map // TypesEncountered keeps track of the types we encounter using the excellent go.tools/go/types/typesmap package. NextTypeID int // NextTypeID is used to give each type we come across its own ID - entry zero is invalid // flags DebugFlag bool // DebugFlag is used to signal if we are emitting debug information TraceFlag bool // TraceFlag is used to signal if we are emitting trace information (big) // contains filtered or unexported fields }
Compilation contains global variables for an individual pogo run
func Compile ¶
func Compile(mainPkg *ssa.Package, debug, trace bool, langName, testFSname string) (*Compilation, error)
Compile provides the entry point for the pogo package, returning a pogo.Compilation structure and error
func (*Compilation) CodePosition ¶
func (comp *Compilation) CodePosition(pos token.Pos) string
CodePosition is a utility to provide a string version of token.Pos. this string should be used for documentation & debug only.
func (*Compilation) FloatVal ¶
FloatVal is a utility function returns a string constant value from a constant.Value.
func (*Compilation) FnIsCalled ¶
func (comp *Compilation) FnIsCalled(fn *ssa.Function) bool
FnIsCalled tells if the function is called
func (*Compilation) FuncPathName ¶
func (comp *Compilation) FuncPathName(fn *ssa.Function) (path, name string)
FuncPathName returns a unique function path and name.
func (*Compilation) FuncValue ¶
func (comp *Compilation) FuncValue(obj *types.Func) ssa.Value
FuncValue is a utility function to avoid publishing rootProgram from this package.
func (*Compilation) GetFnNameParts ¶
func (comp *Compilation) GetFnNameParts(fn *ssa.Function) (pack, nam string)
GetFnNameParts gets the elements of the function's name
func (*Compilation) GlobalList ¶
func (comp *Compilation) GlobalList() []GlobalInfo
GlobalList returns all of the globals in the Compilation
func (*Compilation) InlineMap ¶
func (comp *Compilation) InlineMap(key string) (val string, ok bool)
InlineMap reads the value of a key, tracking if it has been seen
func (*Compilation) IntVal ¶
func (comp *Compilation) IntVal(eVal constant.Value, posStr string) (high, low int32)
IntVal is a utility function returns an int64 constant value from a constant.Value, split into high and low int32.
func (*Compilation) IsOverloaded ¶
func (comp *Compilation) IsOverloaded(f *ssa.Function) bool
IsOverloaded reports if a function reference should be replaced
func (*Compilation) IsValidInPogo ¶
func (comp *Compilation) IsValidInPogo(et types.Type, posStr string) bool
IsValidInPogo exists to screen out any types that the system does not handle correctly. Currently it should say everything is valid. TODO review if still required in this form.
func (*Compilation) LogError ¶
func (comp *Compilation) LogError(loc, lang string, err error)
LogError and potentially stop the compilation process.
func (*Compilation) LogTypeUse ¶
func (comp *Compilation) LogTypeUse(t types.Type) string
LogTypeUse : As the code generator encounters new types it logs them here, returning a string of the ID for insertion into the code.
func (*Compilation) LogWarning ¶
func (comp *Compilation) LogWarning(loc, lang string, err error)
LogWarning but a warning does not stop the compiler from claiming success.
func (*Compilation) MakePosHash ¶
func (comp *Compilation) MakePosHash(pos token.Pos) PosHash
MakePosHash keeps track of references put into the code for later extraction in a runtime debug function. It returns the PosHash integer to be used for exception handling that was passed in.
func (*Compilation) MethodSetFor ¶
func (comp *Compilation) MethodSetFor(T types.Type) *types.MethodSet
MethodSetFor is a conveniance function
func (*Compilation) RegisterName ¶
func (comp *Compilation) RegisterName(val ssa.Value) string
RegisterName returns the name of an ssa.Value, a utility function in case it needs to be altered.
func (*Compilation) RootProgram ¶
func (comp *Compilation) RootProgram() *ssa.Program
RootProgram is a conveniance function
func (*Compilation) TypesWithMethodSets ¶
func (comp *Compilation) TypesWithMethodSets() (sets []types.Type)
TypesWithMethodSets in a utility function to only return seen types
func (*Compilation) WriteAsClass ¶
func (comp *Compilation) WriteAsClass(name, code string)
WriteAsClass writes the contents of the buffer as a given class file name.
type FileOutput ¶
type FileOutput struct {
// contains filtered or unexported fields
}
FileOutput provides temporary storage of output file data, pending correct compilation
type GlobalInfo ¶
GlobalInfo holds the description of an individual global declaration
type Language ¶
type Language interface { RegisterName(val ssa.Value) string DeclareTempVar(ssa.Value) string LanguageName() string FileTypeSuffix() string // e.g. ".go" ".js" ".hx" FileStart(packageName, headerText string) string FileEnd() string SetPosHash() string RunDefers(usesGr bool) string GoClassStart() string GoClassEnd(*ssa.Package) string SubFnStart(int, bool, []ssa.Instruction) string SubFnEnd(id int, pos int, mustSplit bool) string SubFnCall(int) string FuncName(*ssa.Function) string FieldAddr(register string, v interface{}, errorInfo string) string IndexAddr(register string, v interface{}, errorInfo string) string Comment(string) string LangName(p, o string) string Const(lit ssa.Const, position string) (string, string) NamedConst(packageName, objectName string, val ssa.Const, position string) string Global(packageName, objectName string, glob ssa.Global, position string, isPublic bool) string FuncStart(pName, mName string, fn *ssa.Function, blks []*ssa.BasicBlock, posStr string, isPublic, trackPhi, usesGr bool, canOptMap map[string]bool, reconstruct []tgossa.BlockFormat) string RunEnd(fn *ssa.Function) string FuncEnd(fn *ssa.Function) string BlockStart(block []*ssa.BasicBlock, num int, emitPhi bool) string BlockEnd(block []*ssa.BasicBlock, num int, emitPhi bool) string Jump(to int, from int, code string) string If(v interface{}, trueNext, falseNext, phi int, trueCode, falseCode, errorInfo string) string Phi(register string, phiEntries []int, valEntries []interface{}, defaultValue, errorInfo string) string LangType(types.Type, bool, string) string Value(v interface{}, errorInfo string) string BinOp(register string, regTyp types.Type, op string, v1, v2 interface{}, errorInfo string) string UnOp(register string, regTyp types.Type, op string, v interface{}, commaOK bool, errorInfo string) string Store(v1, v2 interface{}, errorInfo string) string Send(v1, v2 interface{}, errorInfo string) string Ret(values []*ssa.Value, errorInfo string) string RegEq(r string) string Call(register string, cc ssa.CallCommon, args []ssa.Value, isBuiltin, isGo, isDefer, usesGr bool, fnToCall, errorInfo string) string Convert(register, langType string, destType types.Type, v interface{}, errorInfo string) string MakeInterface(register string, regTyp types.Type, v interface{}, errorInfo string) string ChangeInterface(register string, regTyp types.Type, v interface{}, errorInfo string) string ChangeType(register string, regTyp, v interface{}, errorInfo string) string Alloc(register string, heap bool, v interface{}, errorInfo string) string MakeClosure(register string, v interface{}, errorInfo string) string MakeSlice(register string, v interface{}, errorInfo string) string MakeChan(register string, v interface{}, errorInfo string) string MakeMap(register string, v interface{}, errorInfo string) string Slice(register string, x, low, high interface{}, errorInfo string) string Index(register string, v1, v2 interface{}, errorInfo string) string RangeCheck(x, i interface{}, length int, errorInfo string) string Field(register string, v interface{}, fNum int, name, errorInfo string, isFunctionName bool) string MapUpdate(Map, Key, Value interface{}, errorInfo string) string Lookup(register string, Map, Key interface{}, commaOk bool, errorInfo string) string Extract(register string, tuple interface{}, index int, errorInfo string) string Range(register string, v interface{}, errorInfo string) string Next(register string, v interface{}, isString bool, errorInfo string) string Panic(v1 interface{}, errorInfo string, usesGr bool) string TypeStart(*types.Named, string) string //TypeEnd(*types.Named, string) string TypeAssert(Register string, X ssa.Value, AssertedType types.Type, CommaOk bool, errorInfo string) string EmitTypeInfo() string EmitInvoke(register, path string, isGo, isDefer, usesGr bool, callCommon interface{}, errorInfo string) string FunctionOverloaded(pkg, fun string) bool Select(isSelect bool, register string, v interface{}, CommaOK bool, errorInfo string) string PeepholeOpt(opt, register string, code []ssa.Instruction, errorInfo string) string DebugRef(userName string, v interface{}, errorInfo string) string CanInline(v interface{}) bool PhiCode(allTargets bool, targetPhi int, code []ssa.Instruction, errorInfo string) string InitLang(*Compilation, *LanguageEntry) Language }
The Language interface enables multiple target languages for TARDIS Go.
type LanguageEntry ¶
type LanguageEntry struct { Language // A type implementing all of the interface methods. InstructionLimit int // How many instructions in a function before we need to split it up. SubFnInstructionLimit int // When we split up a function, how large can each sub-function be? PackageConstVarName string // The special constant name to specify a Package/Module name in the target language. HeaderConstVarName string // The special constant name for a target-specific header. Goruntime string // The location of the core implementation go runtime code for this target language. TestFS string // the location of the test zipped file system, if present LineCommentMark string // what marks the comment at the end of a line StatementTerminator string // what marks the end of a statement, usually ";" PseudoPkgPaths []string // paths of packages containing pseudo-functions IgnorePrefixes []string // the prefixes to code to ignore during peephole optimization GOROOT string // static part of the GOROOT path TgtDir string // Target directory to write to // contains filtered or unexported fields }
LanguageEntry holds the static infomation about each of the languages, expect this list to extend as more languages are added.
type PackageSorter ¶
PackageSorter is a type to allow packages to be sorted by name
func (PackageSorter) Len ¶
func (a PackageSorter) Len() int
func (PackageSorter) Less ¶
func (a PackageSorter) Less(i, j int) bool
func (PackageSorter) Swap ¶
func (a PackageSorter) Swap(i, j int)
type PosHash ¶
type PosHash int
A PosHash is a hash of the code position, set -ve if a nearby PosHash is used.
type PosHashFileStruct ¶
type PosHashFileStruct struct { FileName string // The name of the file. LineCount int // The number of lines in that file. BasePosHash int // The base posHash value for this file. }
PosHashFileStruct stores the code position information for each file in order to generate PosHash values.
type TypeSorter ¶
TypeSorter is a type to allow types to be sorted
func (TypeSorter) Len ¶
func (a TypeSorter) Len() int
func (TypeSorter) Less ¶
func (a TypeSorter) Less(i, j int) bool
func (TypeSorter) Swap ¶
func (a TypeSorter) Swap(i, j int)