llgo build/install: a.out generated

This commit is contained in:
xushiwei
2024-04-25 00:14:02 +08:00
parent 81b3add443
commit cbaf9e21b2
3 changed files with 13 additions and 7 deletions

View File

@@ -305,7 +305,8 @@ func NewPackage(prog llssa.Program, pkg *ssa.Package, files []*ast.File) (ret ll
})
pkgTypes := pkg.Pkg
ret = prog.NewPackage(pkgTypes.Name(), pkgTypes.Path())
pkgName, pkgPath := pkgTypes.Name(), pkgTypes.Path()
ret = prog.NewPackage(pkgName, pkgPath)
ctx := &context{
prog: prog,
@@ -316,7 +317,7 @@ func NewPackage(prog llssa.Program, pkg *ssa.Package, files []*ast.File) (ret ll
link: make(map[string]string),
loaded: make(map[*types.Package]none),
}
ctx.initFiles(pkgTypes.Path(), files)
ctx.initFiles(pkgPath, files)
for _, m := range members {
member := m.val
switch member := member.(type) {

View File

@@ -106,7 +106,11 @@ func (p *context) initLinkname(pkgPath, line string) {
}
func fullName(pkg *types.Package, name string) string {
return pkg.Path() + "." + name
pkgPath := pkg.Name()
if pkgPath != "main" {
pkgPath = pkg.Path()
}
return pkgPath + "." + name
}
func funcName(pkg *types.Package, fn *ssa.Function) string {

View File

@@ -50,7 +50,7 @@ const (
func Do(args []string, mode Mode) {
flags, patterns, verbose := parseArgs(args)
cfg := &packages.Config{
Mode: loadSyntax | packages.NeedExportFile,
Mode: loadSyntax | packages.NeedDeps | packages.NeedExportFile,
BuildFlags: flags,
}
@@ -61,7 +61,8 @@ func Do(args []string, mode Mode) {
check(err)
// Create SSA-form program representation.
_, pkgs, errPkgs := allPkgs(initial, ssa.SanityCheckFunctions)
ssaProg, pkgs, errPkgs := allPkgs(initial, ssa.SanityCheckFunctions)
ssaProg.Build()
for _, errPkg := range errPkgs {
log.Println("cannot build SSA for package", errPkg)
}
@@ -75,11 +76,11 @@ func Do(args []string, mode Mode) {
prog := llssa.NewProgram(nil)
llFiles := make([]string, 0, len(pkgs))
for _, pkg := range pkgs {
pkg.SSA.Build()
llFiles = buildPkg(llFiles, prog, pkg, mode)
}
if mode == ModeInstall {
fmt.Fprintln(os.Stderr, "clang", llFiles)
// TODO(xsw): show work
// fmt.Fprintln(os.Stderr, "clang", llFiles)
err = clang.New("").Exec(llFiles...)
check(err)
}