TestVar done

This commit is contained in:
xushiwei
2024-04-16 00:43:29 +08:00
parent b736f27275
commit 88cd652c43
3 changed files with 24 additions and 8 deletions

View File

@@ -19,8 +19,6 @@ package ssa
import (
"go/constant"
"go/types"
"io"
"os"
"github.com/goplus/llvm"
"golang.org/x/tools/go/types/typeutil"
@@ -33,7 +31,7 @@ type Program struct {
target *Target
td llvm.TargetData
tm llvm.TargetMachine
// tm llvm.TargetMachine
intType llvm.Type
int8Type llvm.Type
@@ -88,6 +86,11 @@ func (p *Package) NewFunc(name string, sig *types.Signature) *Function {
return &Function{}
}
func (p *Package) String() string {
return p.mod.String()
}
/*
type CodeGenFileType = llvm.CodeGenFileType
const (
@@ -125,3 +128,4 @@ func (p *Package) WriteFile(file string) (err error) {
defer f.Close()
return llvm.WriteBitcodeToFile(p.mod, f)
}
*/

View File

@@ -21,7 +21,8 @@ import (
"testing"
)
func assertPkg(t *testing.T, p *Package) {
/*
func asmPkg(t *testing.T, p *Package) {
b, err := p.CodeGen(AssemblyFile)
if err != nil {
t.Fatal("ctx.ParseIR:", err)
@@ -30,10 +31,21 @@ func assertPkg(t *testing.T, p *Package) {
t.Log(v)
}
}
*/
func assertPkg(t *testing.T, p *Package, expected string) {
if v := p.String(); v != expected {
t.Fatalf("\n==> got:\n%s\n==> expected:\n%s\n", v, expected)
}
}
func TestVar(t *testing.T) {
prog := NewProgram(nil)
pkg := prog.NewPackage("foo", "foo")
pkg := prog.NewPackage("bar", "foo/bar")
pkg.NewVar("a", types.Typ[types.Int])
assertPkg(t, pkg)
assertPkg(t, pkg, `; ModuleID = 'foo/bar'
source_filename = "foo/bar"
@a = external global i64
`)
}

View File

@@ -17,8 +17,6 @@
package ssa
import (
"runtime"
"github.com/goplus/llvm"
)
@@ -36,6 +34,7 @@ type Target struct {
GOARM string // "5", "6", "7" (default)
}
/*
func (p *Program) targetMachine() llvm.TargetMachine {
if p.tm.C == nil {
spec := p.target.toSpec()
@@ -150,3 +149,4 @@ func (p *Target) toSpec() (spec targetSpec) {
}
return
}
*/