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.
Этот коммит содержится в:
родитель
d40fb5bc46
коммит
cf2a7b5089
1 изменённых файлов: 10 добавлений и 0 удалений
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче