gotoc

package
v0.0.0-...-168ccc2 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2021 License: BSD-3-Clause Imports: 13 Imported by: 1

README

Proof of concept Go (Emgo) to C translator.

This code is horrible convoluted. Mess growed when it was forced to handle more and more Go constructs that can't be one to one translated to C. But my knowledge about Go and C spec growed also, so now I probably know enough to write better one. See gotoc-v1.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Upath

func Upath(s string) (ret string)

Types

type CDD

type CDD struct {
	Origin     types.Object // object for this declaration
	DeclUses   map[types.Object]bool
	DefUses    map[types.Object]bool // Function body, variable initialisation.
	Complexity int

	Typ     DeclType
	Export  bool
	Weak    bool
	NoAlloc bool
	Inline  bool // set by DetermineInline()

	Decl []byte
	Def  []byte
	Init []byte
	// contains filtered or unexported fields
}

CDD stores Go declaration translated to C declaration and definition.

func (*CDD) AllCDDS

func (cdd *CDD) AllCDDS() (cdds []*CDD)

func (*CDD) BlockStmt

func (cdd *CDD) BlockStmt(w *bytes.Buffer, bs *ast.BlockStmt, resultT string, tup *types.Tuple) (end bool)

func (*CDD) CallExpr

func (cdd *CDD) CallExpr(w *bytes.Buffer, e *ast.CallExpr, permitaa bool)

func (*CDD) DetermineInline

func (cdd *CDD) DetermineInline()

func (*CDD) Expr

func (cdd *CDD) Expr(w *bytes.Buffer, expr ast.Expr, nilT types.Type, permitaa bool)

func (*CDD) ExprStr

func (cdd *CDD) ExprStr(expr ast.Expr, nilT types.Type, permitaa bool) string

func (*CDD) GoStmt

func (cdd *CDD) GoStmt(w *bytes.Buffer, s *ast.GoStmt)

func (*CDD) Name

func (cdd *CDD) Name(w *bytes.Buffer, obj types.Object, direct bool)

func (*CDD) NameStr

func (cdd *CDD) NameStr(o types.Object, direct bool) string

func (*CDD) Nil

func (cdd *CDD) Nil(w *bytes.Buffer, t types.Type)

func (*CDD) ReturnStmt

func (cdd *CDD) ReturnStmt(w *bytes.Buffer, s *ast.ReturnStmt, resultT string, tup *types.Tuple) (end bool)

func (*CDD) SelectorExpr

func (cdd *CDD) SelectorExpr(w *bytes.Buffer, e *ast.SelectorExpr, permitaa bool) (fun, recvt types.Type, recvs string)

func (*CDD) SelectorExprStr

func (cdd *CDD) SelectorExprStr(e *ast.SelectorExpr, permitaa bool) (s string, fun, recvt types.Type, recvs string)

func (*CDD) SliceExpr

func (cdd *CDD) SliceExpr(w *bytes.Buffer, e *ast.SliceExpr)

func (*CDD) Stmt

func (cdd *CDD) Stmt(w *bytes.Buffer, stmt ast.Stmt, label, resultT string, tup *types.Tuple) (end bool)

func (*CDD) Type

func (cdd *CDD) Type(w *bytes.Buffer, typ types.Type) (dim []string)

func (*CDD) TypeStr

func (cdd *CDD) TypeStr(typ types.Type) (string, []string)

func (*CDD) Value

func (cdd *CDD) Value(w *bytes.Buffer, ev constant.Value, t types.Type)

func (*CDD) WriteDecl

func (cdd *CDD) WriteDecl(wh, wc io.Writer) error

func (*CDD) WriteDef

func (cdd *CDD) WriteDef(wh, wc io.Writer) error

type DeclType

type DeclType int
const (
	FuncDecl DeclType = iota
	VarDecl
	ConstDecl
	TypeDecl
	ImportDecl
)

type GTC

type GTC struct {
	// contains filtered or unexported fields
}

GTC stores information from type checker need for translation.

func NewGTC

func NewGTC(fset *token.FileSet, pkg *types.Package, ti *types.Info, siz types.Sizes) *GTC

func (*GTC) Decl

func (cc *GTC) Decl(decl ast.Decl, il int) []*CDD

func (*GTC) File

func (gtc *GTC) File(f *ast.File) (cdds []*CDD)

func (*GTC) FuncDecl

func (gtc *GTC) FuncDecl(d *ast.FuncDecl, il int) (cdds []*CDD)

func (*GTC) GenDecl

func (gtc *GTC) GenDecl(d *ast.GenDecl, il int) (cdds []*CDD)

func (*GTC) SetBoundsCheck

func (cc *GTC) SetBoundsCheck(bc bool)

func (*GTC) SetFieldNames

func (cc *GTC) SetFieldNames(fn bool)

func (*GTC) SetFullTypeInfo

func (cc *GTC) SetFullTypeInfo(fti bool)

func (*GTC) SetNoinlineThres

func (cc *GTC) SetNoinlineThres(thres int)

func (*GTC) SetTypeNames

func (cc *GTC) SetTypeNames(tn bool)

func (*GTC) Translate

func (gtc *GTC) Translate(wh, wc io.Writer, files []*ast.File) error

Translate translates files to C source. It writes results of translation to:

wh - C header, contains exported and inlined declarations translated to C,
wc - remaining C source.

type StdSizes

type StdSizes struct {
	WordSize int64 // word size in bytes - must be >= 4 (32bits)
	MaxAlign int64 // maximum alignment in bytes - must be >= 1
}

func (*StdSizes) Alignof

func (s *StdSizes) Alignof(T types.Type) int64

func (*StdSizes) Offsetsof

func (s *StdSizes) Offsetsof(fields []*types.Var) []int64

func (*StdSizes) Sizeof

func (s *StdSizes) Sizeof(T types.Type) int64

Jump to

Keyboard shortcuts

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