From 4fcffa46e138d838d1283056fc45688a3ab018cc Mon Sep 17 00:00:00 2001 From: xushiwei Date: Thu, 18 Apr 2024 01:23:01 +0800 Subject: [PATCH] aProgram/aPackage/aFunction/etc --- ssa/decl.go | 14 +++++++------- ssa/package.go | 30 +++++++++++++++--------------- ssa/type.go | 34 +++++++++++++++++----------------- 3 files changed, 39 insertions(+), 39 deletions(-) diff --git a/ssa/decl.go b/ssa/decl.go index 582b909a..7d0843ae 100644 --- a/ssa/decl.go +++ b/ssa/decl.go @@ -28,21 +28,21 @@ import ( // // NB: a NamedConst is not a Value; it contains a constant Value, which // it augments with the name and position of its 'const' declaration. -type TyNamedConst struct { +type aNamedConst struct { } -type NamedConst = *TyNamedConst +type NamedConst = *aNamedConst // A Global is a named Value holding the address of a package-level // variable. // // Pos() returns the position of the ast.ValueSpec.Names[*] // identifier. -type TyGlobal struct { +type aGlobal struct { impl llvm.Value } -type Global = *TyGlobal +type Global = *aGlobal // Function represents the parameters, results, and code of a function // or method. @@ -93,14 +93,14 @@ type Global = *TyGlobal // method, (*Map[K,V]).Get, TypeParams() refers to the parameters [K,V] of // the generic method. TypeArgs() refers to [string,U] or [string,int], // respectively, and is nil in the generic method. -type TyFunction struct { +type aFunction struct { impl llvm.Value prog Program } -type Function = *TyFunction +type Function = *aFunction -func (p *TyFunction) BodyStart() *BasicBlock { +func (p *aFunction) BodyStart() *BasicBlock { body := llvm.AddBasicBlock(p.impl, "entry") return &BasicBlock{body} } diff --git a/ssa/package.go b/ssa/package.go index 5bc7fe8c..b0934708 100644 --- a/ssa/package.go +++ b/ssa/package.go @@ -25,7 +25,7 @@ import ( ) // A Program is a partial or complete Go program converted to SSA form. -type TyProgram struct { +type aProgram struct { ctx llvm.Context b Builder typs typeutil.Map @@ -43,7 +43,7 @@ type TyProgram struct { voidPtrTy llvm.Type } -type Program = *TyProgram +type Program = *aProgram func NewProgram(target *Target) Program { if target == nil { @@ -54,16 +54,16 @@ func NewProgram(target *Target) Program { b := ctx.NewBuilder() b.Finalize() td := llvm.NewTargetData("") // TODO(xsw): target config - return &TyProgram{ctx: ctx, b: Builder{b}, target: target, td: td} + return &aProgram{ctx: ctx, b: Builder{b}, target: target, td: td} } -func (p *TyProgram) NewPackage(name, pkgPath string) Package { +func (p *aProgram) NewPackage(name, pkgPath string) Package { mod := p.ctx.NewModule(pkgPath) mod.Finalize() - return &TyPackage{mod, p} + return &aPackage{mod, p} } -func (p *TyProgram) Builder() Builder { +func (p *aProgram) Builder() Builder { return p.b } @@ -75,28 +75,28 @@ func (p *TyProgram) Builder() Builder { // Members also contains entries for "init" (the synthetic package // initializer) and "init#%d", the nth declared init function, // and unspecified other things too. -type TyPackage struct { +type aPackage struct { mod llvm.Module prog Program } -type Package = *TyPackage +type Package = *aPackage -func (p *TyPackage) NewConst(name string, val constant.Value) NamedConst { - return &TyNamedConst{} +func (p *aPackage) NewConst(name string, val constant.Value) NamedConst { + return &aNamedConst{} } -func (p *TyPackage) NewVar(name string, typ types.Type) Global { +func (p *aPackage) NewVar(name string, typ types.Type) Global { gbl := llvm.AddGlobal(p.mod, p.prog.llvmType(typ), name) - return &TyGlobal{gbl} + return &aGlobal{gbl} } -func (p *TyPackage) NewFunc(name string, sig *types.Signature) Function { +func (p *aPackage) NewFunc(name string, sig *types.Signature) Function { fn := llvm.AddFunction(p.mod, name, p.prog.llvmSignature(sig)) - return &TyFunction{fn, p.prog} + return &aFunction{fn, p.prog} } -func (p *TyPackage) String() string { +func (p *aPackage) String() string { return p.mod.String() } diff --git a/ssa/type.go b/ssa/type.go index 91a660f3..39132d64 100644 --- a/ssa/type.go +++ b/ssa/type.go @@ -29,7 +29,7 @@ type Type struct { } */ -func (p *TyProgram) llvmType(typ types.Type) llvm.Type { +func (p *aProgram) llvmType(typ types.Type) llvm.Type { if v := p.typs.At(typ); v != nil { return v.(llvm.Type) } @@ -38,7 +38,7 @@ func (p *TyProgram) llvmType(typ types.Type) llvm.Type { return ret } -func (p *TyProgram) llvmSignature(sig *types.Signature) llvm.Type { +func (p *aProgram) llvmSignature(sig *types.Signature) llvm.Type { if v := p.typs.At(sig); v != nil { return v.(llvm.Type) } @@ -47,56 +47,56 @@ func (p *TyProgram) llvmSignature(sig *types.Signature) llvm.Type { return ret } -func (p *TyProgram) tyVoidPtr() llvm.Type { +func (p *aProgram) tyVoidPtr() llvm.Type { if p.voidPtrTy.IsNil() { p.voidPtrTy = llvm.PointerType(p.tyVoid(), 0) } return p.voidPtrTy } -func (p *TyProgram) tyVoid() llvm.Type { +func (p *aProgram) tyVoid() llvm.Type { if p.voidType.IsNil() { p.voidType = p.ctx.VoidType() } return p.voidType } -func (p *TyProgram) tyInt() llvm.Type { +func (p *aProgram) tyInt() llvm.Type { if p.intType.IsNil() { p.intType = llvmIntType(p.ctx, p.td.PointerSize()) } return p.intType } -func (p *TyProgram) tyInt8() llvm.Type { +func (p *aProgram) tyInt8() llvm.Type { if p.int8Type.IsNil() { p.int8Type = p.ctx.Int8Type() } return p.int8Type } -func (p *TyProgram) tyInt16() llvm.Type { +func (p *aProgram) tyInt16() llvm.Type { if p.int16Type.IsNil() { p.int16Type = p.ctx.Int16Type() } return p.int16Type } -func (p *TyProgram) tyInt32() llvm.Type { +func (p *aProgram) tyInt32() llvm.Type { if p.int32Type.IsNil() { p.int32Type = p.ctx.Int32Type() } return p.int32Type } -func (p *TyProgram) tyInt64() llvm.Type { +func (p *aProgram) tyInt64() llvm.Type { if p.int64Type.IsNil() { p.int64Type = p.ctx.Int64Type() } return p.int64Type } -func (p *TyProgram) toLLVMType(typ types.Type) llvm.Type { +func (p *aProgram) toLLVMType(typ types.Type) llvm.Type { switch t := typ.(type) { case *types.Basic: switch t.Kind() { @@ -146,19 +146,19 @@ func llvmIntType(ctx llvm.Context, size int) llvm.Type { return ctx.Int64Type() } -func (p *TyProgram) toLLVMNamedStruct(name string, typ *types.Struct) llvm.Type { +func (p *aProgram) toLLVMNamedStruct(name string, typ *types.Struct) llvm.Type { t := p.ctx.StructCreateNamed(name) fields := p.toLLVMFields(typ) t.StructSetBody(fields, false) return t } -func (p *TyProgram) toLLVMStruct(typ *types.Struct) llvm.Type { +func (p *aProgram) toLLVMStruct(typ *types.Struct) llvm.Type { fields := p.toLLVMFields(typ) return p.ctx.StructType(fields, false) } -func (p *TyProgram) toLLVMFields(typ *types.Struct) []llvm.Type { +func (p *aProgram) toLLVMFields(typ *types.Struct) []llvm.Type { n := typ.NumFields() fields := make([]llvm.Type, n) for i := 0; i < n; i++ { @@ -167,11 +167,11 @@ func (p *TyProgram) toLLVMFields(typ *types.Struct) []llvm.Type { return fields } -func (p *TyProgram) toLLVMTuple(t *types.Tuple) llvm.Type { +func (p *aProgram) toLLVMTuple(t *types.Tuple) llvm.Type { return p.ctx.StructType(p.toLLVMTypes(t), false) } -func (p *TyProgram) toLLVMTypes(t *types.Tuple) []llvm.Type { +func (p *aProgram) toLLVMTypes(t *types.Tuple) []llvm.Type { n := t.Len() ret := make([]llvm.Type, n) for i := 0; i < n; i++ { @@ -180,7 +180,7 @@ func (p *TyProgram) toLLVMTypes(t *types.Tuple) []llvm.Type { return ret } -func (p *TyProgram) toLLVMFunc(sig *types.Signature) llvm.Type { +func (p *aProgram) toLLVMFunc(sig *types.Signature) llvm.Type { params := p.toLLVMTypes(sig.Params()) results := sig.Results() var ret llvm.Type @@ -195,7 +195,7 @@ func (p *TyProgram) toLLVMFunc(sig *types.Signature) llvm.Type { return llvm.FunctionType(ret, params, sig.Variadic()) } -func (p *TyProgram) toLLVMNamed(typ *types.Named) llvm.Type { +func (p *aProgram) toLLVMNamed(typ *types.Named) llvm.Type { name := typ.Obj().Name() switch typ := typ.Underlying().(type) { case *types.Struct: