diff options
author | Ayke <[email protected]> | 2019-02-08 13:04:03 +0100 |
---|---|---|
committer | Ron Evans <[email protected]> | 2019-02-08 13:04:03 +0100 |
commit | 01f6aff4227120abf7dc98baef26f09d6576d856 (patch) | |
tree | 0ca0fd7ec3c4f2aa49a2369db3cbea7630265eeb /ir | |
parent | 7dd5839f4741a2bf697ae9438019028a4058aa56 (diff) | |
download | tinygo-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.go | 16 |
1 files changed, 15 insertions, 1 deletions
@@ -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 { |