aboutsummaryrefslogtreecommitdiffhomepage
path: root/ir
diff options
context:
space:
mode:
authorAyke <[email protected]>2019-02-08 13:04:03 +0100
committerRon Evans <[email protected]>2019-02-08 13:04:03 +0100
commit01f6aff4227120abf7dc98baef26f09d6576d856 (patch)
tree0ca0fd7ec3c4f2aa49a2369db3cbea7630265eeb /ir
parent7dd5839f4741a2bf697ae9438019028a4058aa56 (diff)
downloadtinygo-01f6aff4227120abf7dc98baef26f09d6576d856.tar.gz
tinygo-01f6aff4227120abf7dc98baef26f09d6576d856.zip
loader: support global variables in CGo (#173)
Global variables (like functions) must be declared in the import "C" preamble and can then be used from Go.
Diffstat (limited to 'ir')
-rw-r--r--ir/ir.go16
1 files changed, 15 insertions, 1 deletions
diff --git a/ir/ir.go b/ir/ir.go
index bcbf128fa..884b78bea 100644
--- a/ir/ir.go
+++ b/ir/ir.go
@@ -389,11 +389,25 @@ func (g *Global) LinkName() string {
if g.linkName != "" {
return g.linkName
}
+ if name := g.CName(); name != "" {
+ return name
+ }
return g.RelString(nil)
}
func (g *Global) IsExtern() bool {
- return g.extern
+ return g.extern || g.CName() != ""
+}
+
+// Return the name of the C global if this is a CGo wrapper. Otherwise, return a
+// zero-length string.
+func (g *Global) CName() string {
+ name := g.Name()
+ if strings.HasPrefix(name, "C.") {
+ // created by ../loader/cgo.go
+ return name[2:]
+ }
+ return ""
}
func (g *Global) Initializer() Value {