cl:compile with clang++

This commit is contained in:
luoliwoshang
2025-06-11 17:01:12 +08:00
parent 47c119a2d7
commit f2f93c7f5f
7 changed files with 23 additions and 21 deletions

View File

@@ -490,6 +490,8 @@ func linkMainPkg(ctx *context, pkg *packages.Package, pkgs []*aPackage, conf *Co
}
linkArgs = append(linkArgs, exargs...)
fmt.Fprintf(os.Stderr, "linkArgs: %v\n", linkArgs)
err = compileAndLinkLLFiles(ctx, app, llFiles, linkArgs, verbose)
check(err)

View File

@@ -1,35 +1,33 @@
typedef union
{
typedef union {
double d;
float f;
long v;
long long ll;
} castUnion;
double llgoToFloat64(long long v)
{
extern "C" {
double llgoToFloat64(long long v) {
castUnion k;
k.ll = v;
return k.d;
}
float llgoToFloat32(int v)
{
float llgoToFloat32(int v) {
castUnion k;
k.v = v;
return k.f;
}
long long llgoFromFloat64(double v)
{
long long llgoFromFloat64(double v) {
castUnion k;
k.d = v;
return k.ll;
}
int llgoFromFloat32(float v)
{
int llgoFromFloat32(float v) {
castUnion k;
k.f = v;
return k.v;
}
}

View File

@@ -19,7 +19,7 @@ package bitcast
import _ "unsafe"
const (
LLGoFiles = "_cast/cast.c"
LLGoFiles = "_cast/cast.cpp"
LLGoPackage = "link"
)

View File

@@ -9,13 +9,11 @@
#include <dlfcn.h>
#include <libunwind.h>
void *llgo_address() {
return __builtin_return_address(0);
}
extern "C" {
int llgo_addrinfo(void *addr, Dl_info *info) {
return dladdr(addr, info);
}
void *llgo_address() { return __builtin_return_address(0); }
int llgo_addrinfo(void *addr, Dl_info *info) { return dladdr(addr, info); }
void llgo_stacktrace(int skip, void *ctx, int (*fn)(void *ctx, void *pc, void *offset, void *sp, char *name)) {
unw_cursor_t cursor;
@@ -33,9 +31,10 @@ void llgo_stacktrace(int skip, void *ctx, int (*fn)(void *ctx, void *pc, void *o
if (unw_get_reg(&cursor, UNW_REG_IP, &pc) == 0) {
unw_get_proc_name(&cursor, fname, sizeof(fname), &offset);
unw_get_reg(&cursor, UNW_REG_SP, &sp);
if (fn(ctx, (void*)pc, (void*)offset, (void*)sp, fname) == 0) {
if (fn(ctx, (void *)pc, (void *)offset, (void *)sp, fname) == 0) {
return;
}
}
}
}
}

View File

@@ -9,7 +9,7 @@ import (
)
const (
LLGoFiles = "_wrap/debug.c"
LLGoFiles = "_wrap/debug.cpp"
)
type Info struct {

View File

@@ -91,6 +91,7 @@ func (p *Cmd) execWithFlags(flags []string, args ...string) error {
if p.Env != nil {
cmd.Env = p.Env
}
fmt.Fprintln(os.Stderr, cmd.String())
return cmd.Run()
}
@@ -131,6 +132,8 @@ func (p *Cmd) CheckLinkArgs(cmdArgs []string, wasm bool) error {
srcIn := strings.NewReader(src)
p.Stdin = srcIn
fmt.Fprintf(os.Stderr, "args: %v\n", args)
// Execute the command
return p.execWithFlags([]string{"LDFLAGS", "CCFLAGS"}, args...)
}

View File

@@ -72,7 +72,7 @@ func (e *Env) BinDir() string { return e.binDir }
// Clang returns a new [clang.Cmd] instance.
func (e *Env) Clang() *clang.Cmd {
bin := filepath.Join(e.BinDir(), "clang")
bin := filepath.Join(e.BinDir(), "clang++")
return clang.New(bin)
}