mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-16 18:53:29 +00:00
compiler: support pragmas on generic functions
This commit is contained in:
committed by
Ron Evans
parent
dcca47f1f6
commit
37460ad60a
+6
-2
@@ -250,10 +250,14 @@ func (c *compilerContext) getFunctionInfo(f *ssa.Function) functionInfo {
|
|||||||
// parsePragmas is used by getFunctionInfo to parse function pragmas such as
|
// parsePragmas is used by getFunctionInfo to parse function pragmas such as
|
||||||
// //export or //go:noinline.
|
// //export or //go:noinline.
|
||||||
func (c *compilerContext) parsePragmas(info *functionInfo, f *ssa.Function) {
|
func (c *compilerContext) parsePragmas(info *functionInfo, f *ssa.Function) {
|
||||||
if f.Syntax() == nil {
|
syntax := f.Syntax()
|
||||||
|
if f.Origin() != nil {
|
||||||
|
syntax = f.Origin().Syntax()
|
||||||
|
}
|
||||||
|
if syntax == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if decl, ok := f.Syntax().(*ast.FuncDecl); ok && decl.Doc != nil {
|
if decl, ok := syntax.(*ast.FuncDecl); ok && decl.Doc != nil {
|
||||||
for _, comment := range decl.Doc.List {
|
for _, comment := range decl.Doc.List {
|
||||||
text := comment.Text
|
text := comment.Text
|
||||||
if strings.HasPrefix(text, "//export ") {
|
if strings.HasPrefix(text, "//export ") {
|
||||||
|
|||||||
Vendored
+16
@@ -48,6 +48,22 @@ func inlineFunc() {
|
|||||||
func noinlineFunc() {
|
func noinlineFunc() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Int interface {
|
||||||
|
int8 | int16
|
||||||
|
}
|
||||||
|
|
||||||
|
// Same for generic functions (but the compiler may miss the pragma due to it
|
||||||
|
// being generic).
|
||||||
|
//
|
||||||
|
//go:noinline
|
||||||
|
func noinlineGenericFunc[T Int]() {
|
||||||
|
}
|
||||||
|
|
||||||
|
func useGeneric() {
|
||||||
|
// Make sure the generic function above is instantiated.
|
||||||
|
noinlineGenericFunc[int8]()
|
||||||
|
}
|
||||||
|
|
||||||
// This function should have the specified section.
|
// This function should have the specified section.
|
||||||
//
|
//
|
||||||
//go:section .special_function_section
|
//go:section .special_function_section
|
||||||
|
|||||||
Vendored
+13
@@ -48,6 +48,19 @@ entry:
|
|||||||
ret void
|
ret void
|
||||||
}
|
}
|
||||||
|
|
||||||
|
; Function Attrs: nounwind
|
||||||
|
define hidden void @main.useGeneric(ptr %context) unnamed_addr #2 {
|
||||||
|
entry:
|
||||||
|
call void @"main.noinlineGenericFunc[int8]"(ptr undef)
|
||||||
|
ret void
|
||||||
|
}
|
||||||
|
|
||||||
|
; Function Attrs: noinline nounwind
|
||||||
|
define linkonce_odr hidden void @"main.noinlineGenericFunc[int8]"(ptr %context) unnamed_addr #5 {
|
||||||
|
entry:
|
||||||
|
ret void
|
||||||
|
}
|
||||||
|
|
||||||
; Function Attrs: noinline nounwind
|
; Function Attrs: noinline nounwind
|
||||||
define hidden void @main.functionInSection(ptr %context) unnamed_addr #5 section ".special_function_section" {
|
define hidden void @main.functionInSection(ptr %context) unnamed_addr #5 section ".special_function_section" {
|
||||||
entry:
|
entry:
|
||||||
|
|||||||
Reference in New Issue
Block a user