aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAyke van Laethem <[email protected]>2019-09-18 19:53:02 +0200
committerRon Evans <[email protected]>2019-09-18 20:15:17 +0200
commitcf2a7b50891a83f07e3d6e014db6b532f2df106b (patch)
tree3728bbc41a3b8fc58193e37ace0125a4e4342c85
parentd40fb5bc46ae92ec54bde72c42e101c0ec5eb52a (diff)
downloadtinygo-cf2a7b50891a83f07e3d6e014db6b532f2df106b.tar.gz
tinygo-cf2a7b50891a83f07e3d6e014db6b532f2df106b.zip
compiler: add //go:align pragma
This is sometimes needed for globals. For example, the atsamd21 chip requires the DMA buffers to be aligned on a 16 byte boundary.
-rw-r--r--compiler/symbol.go10
1 files changed, 10 insertions, 0 deletions
diff --git a/compiler/symbol.go b/compiler/symbol.go
index 4b8fb08bf..c51c1d42f 100644
--- a/compiler/symbol.go
+++ b/compiler/symbol.go
@@ -7,6 +7,7 @@ import (
"go/ast"
"go/token"
"go/types"
+ "strconv"
"strings"
"github.com/tinygo-org/tinygo/loader"
@@ -20,6 +21,7 @@ import (
type globalInfo struct {
linkName string // go:extern
extern bool // go:extern
+ align int // go:align
}
// loadASTComments loads comments on globals from the AST, for use later in the
@@ -64,6 +66,9 @@ func (c *Compiler) getGlobal(g *ssa.Global) llvm.Value {
llvmGlobal.SetInitializer(llvm.ConstNull(llvmType))
llvmGlobal.SetLinkage(llvm.InternalLinkage)
}
+ if info.align > c.targetData.ABITypeAlignment(llvmType) {
+ llvmGlobal.SetAlignment(info.align)
+ }
}
return llvmGlobal
}
@@ -102,6 +107,11 @@ func (info *globalInfo) parsePragmas(doc *ast.CommentGroup) {
if len(parts) == 2 {
info.linkName = parts[1]
}
+ case "//go:align":
+ align, err := strconv.Atoi(parts[1])
+ if err == nil {
+ info.align = align
+ }
}
}
}