transpiler

package
v0.0.0-...-c5400a7 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2023 License: MIT Imports: 23 Imported by: 1

Documentation

Overview

Package transpiler handles the conversion between the Clang AST and the Go AST.

Index

Constants

This section is empty.

Variables

View Source
var AddOutsideStruct bool

Functions

func ConvertToGoFlagFormat

func ConvertToGoFlagFormat(str string) string

ConvertToGoFlagFormat convert format flags from C to Go

func ConvertValueToPointer

func ConvertValueToPointer(nodes []ast.Node, p *program.Program) (expr goast.Expr, ok bool)

func CreateSliceFromReference

func CreateSliceFromReference(goType string, expr goast.Expr) goast.Expr

CreateSliceFromReference - create a slice, like : (*[1]int)(unsafe.Pointer(&a))[:]

func GenerateFuncType

func GenerateFuncType(fields, returns []string) *goast.FuncType

GenerateFuncType in according to types Type: *ast.FuncType { . Func: 13:7 . Params: *ast.FieldList { . . Opening: 13:12 . . List: []*ast.Field (len = 2) { . . . 0: *ast.Field { . . . . Type: *ast.Ident { . . . . . NamePos: 13:13 . . . . . Name: "int" . . . . } . . . } . . . 1: *ast.Field { . . . . Type: *ast.Ident { . . . . . NamePos: 13:17 . . . . . Name: "int" . . . . } . . . } . . } . } . Results: *ast.FieldList { . . Opening: - . . List: []*ast.Field (len = 1) { . . . 0: *ast.Field { . . . . Type: *ast.Ident { . . . . . NamePos: 13:21 . . . . . Name: "string" . . . . } . . . } . . } . } }

func GetPointerAddress

func GetPointerAddress(p *program.Program, expr goast.Expr, cType string, sizeof int) (
	rs goast.Expr, postStmts []goast.Stmt, err error)

GetPointerAddress - return goast expression with pointer address.

pnt       - goast expression. Foe example: `&a`, `&a[11]`.
sizeof    - sizeof of C type.
rs        - result goast expression.
postStmts - slice of goast.Stmt for runtime.KeepAlive of pointer,
            the best way kept that stmts at the end of function.
            Each stmt has `defer` functions.

func GetUnsafeConvertDecls

func GetUnsafeConvertDecls(p *program.Program)

func PntBitCast

func PntBitCast(expr goast.Expr, cFrom, cTo string, p *program.Program) (
	rs goast.Expr, toCtype string, postStmts []goast.Stmt, err error)

PntBitCast - casting pointers

func PntCmpPnt

func PntCmpPnt(
	p *program.Program,
	val1 goast.Expr, val1Type string,
	val2 goast.Expr, val2Type string,
	sizeof int, operator token.Token,
) (
	rs goast.Expr,
	postStmts []goast.Stmt,
	err error,
)

postStmts - slice of goast.Stmt for runtime.KeepAlive of pointer,

the best way kept that stmts at the end of function.
Each stmt has `defer` functions.

func ResolveCgoType

func ResolveCgoType(p *program.Program, goType string, expr goast.Expr) (a goast.Expr, err error)

func SubTwoPnts

func SubTwoPnts(
	p *program.Program,
	val1 goast.Expr, val1Type string,
	val2 goast.Expr, val2Type string,
	sizeof int) (rs goast.Expr, postStmts []goast.Stmt, err error)

SubTwoPnts function for implementation : (pointer1 - pointer2)

func TranspileAST

func TranspileAST(fileName, packageName string, withOutsideStructs bool,
	p *program.Program, root ast.Node, clangFlags []string) (
	source string,
	err error)

TranspileAST iterates through the Clang AST and builds a Go AST

func VaListInit

func VaListInit(p *program.Program, name string) []goast.Decl

Types

This section is empty.

Jump to

Keyboard shortcuts

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