github.com/tinygo-org/tinygo@v0.31.3-0.20240404173401-90b0bf646c27/compiler/testdata/pragma.go (about) 1 package main 2 3 import _ "unsafe" 4 5 // Creates an external global with name extern_global. 6 // 7 //go:extern extern_global 8 var externGlobal [0]byte 9 10 // Creates a 11 // 12 //go:align 32 13 var alignedGlobal [4]uint32 14 15 // Test conflicting pragmas (the last one counts). 16 // 17 //go:align 64 18 //go:align 16 19 var alignedGlobal16 [4]uint32 20 21 // Test exported functions. 22 // 23 //export extern_func 24 func externFunc() { 25 } 26 27 // Define a function in a different package using go:linkname. 28 // 29 //go:linkname withLinkageName1 somepkg.someFunction1 30 func withLinkageName1() { 31 } 32 33 // Import a function from a different package using go:linkname. 34 // 35 //go:linkname withLinkageName2 somepkg.someFunction2 36 func withLinkageName2() 37 38 // Function has an 'inline hint', similar to the inline keyword in C. 39 // 40 //go:inline 41 func inlineFunc() { 42 } 43 44 // Function should never be inlined, equivalent to GCC 45 // __attribute__((noinline)). 46 // 47 //go:noinline 48 func noinlineFunc() { 49 } 50 51 // This function should have the specified section. 52 // 53 //go:section .special_function_section 54 func functionInSection() { 55 } 56 57 //export exportedFunctionInSection 58 //go:section .special_function_section 59 func exportedFunctionInSection() { 60 } 61 62 //go:wasmimport modulename import1 63 func declaredImport() 64 65 // Legacy way of importing a function. 66 // 67 //go:wasm-module foobar 68 //export imported 69 func foobarImport() 70 71 // The wasm-module pragma is not functional here, but it should be safe. 72 // 73 //go:wasm-module foobar 74 //export exported 75 func foobarExportModule() { 76 } 77 78 // This function should not: it's only a declaration and not a definition. 79 // 80 //go:section .special_function_section 81 func undefinedFunctionNotInSection() 82 83 //go:section .special_global_section 84 var globalInSection uint32 85 86 //go:section .special_global_section 87 //go:extern undefinedGlobalNotInSection 88 var undefinedGlobalNotInSection uint32 89 90 //go:align 1024 91 //go:section .global_section 92 var multipleGlobalPragmas uint32