Compare commits

..

8 Commits

Author SHA1 Message Date
BCG 6b6b2bfc59 Adding extra files for testing multiline, globbing, etc. 2021-07-23 17:07:25 -04:00
BCG 778c79cc85 Started parsing of //go:embed pragmas 2021-07-19 20:12:44 -04:00
Ayke van Laethem b40703e986 wasm: override dlmalloc heap implementation from wasi-libc
These two heaps conflict with each other, so that if any function uses
the dlmalloc heap implementation it will eventually result in memory
corruption.

This commit fixes this by implementing all heap-related functions. This
overrides the functions that are implemented in wasi-libc. That's why
all of them are implemented (even if they just panic): to make sure no
program accidentally uses the wrong one.
2021-07-15 00:13:17 +02:00
Ayke van Laethem 00ea0b1d57 build: list libraries at the end of the linker command
Static libraries should be added at the end of the linker command, after
all object files. If that isn't done, that's _usually_ not a problem,
unless there are duplicate symbols. In that case, weird dependency
issues can arise. To solve that, object files (that may include symbols
to override symbols in the library) should be listed first on the
command line and then the static libraries should be listed.

This fixes an issue with overriding some symbols in wasi-libc.
2021-07-15 00:13:17 +02:00
Ayke van Laethem efa0410075 interp: fix bug in compiler-time/run-time package initializers
Make sure that if a package initializer cannot be run, later package
initializers won't try to access any global variables touched by the
uninterpretable package initializer.
2021-07-14 22:33:32 +02:00
Ayke van Laethem 607d824211 interp: keep reverted package initializers in order
Previously, a package initializer that could not be reverted correctly
would be called at runtime. But the initializer would be called in the
wrong order: after later packages are initialized.

This commit fixes this oversight and adds a test to verify the new
behavior.
2021-07-14 22:33:32 +02:00
Ayke van Laethem 8cc7c6d572 interp: populate Inst field in interp.Error
It is used in the main package but wasn't actually set anywhere.
2021-07-14 22:33:32 +02:00
Ayke van Laethem cdba4fa8cc interp: don't ignore array indices for untyped objects
This fixes https://github.com/tinygo-org/tinygo/issues/1884.
My original plan to fix this was much more complicated, but then I
realized that the output type doesn't matter anyway and I can simply
cast the type to an *i8 and perform a GEP on that pointer.
2021-07-14 07:55:05 +02:00
189 changed files with 533 additions and 241 deletions
+26 -24
View File
@@ -470,33 +470,10 @@ func Build(pkgName, outpath string, config *compileopts.Config, action func(Buil
linkerDependencies = append(linkerDependencies, job)
}
// Add libc dependency if needed.
root := goenv.Get("TINYGOROOT")
switch config.Target.Libc {
case "picolibc":
job, err := Picolibc.load(config.Triple(), config.CPU(), dir)
if err != nil {
return err
}
// The library needs to be compiled (cache miss).
jobs = append(jobs, job.dependencies...)
jobs = append(jobs, job)
linkerDependencies = append(linkerDependencies, job)
case "wasi-libc":
path := filepath.Join(root, "lib/wasi-libc/sysroot/lib/wasm32-wasi/libc.a")
if _, err := os.Stat(path); os.IsNotExist(err) {
return errors.New("could not find wasi-libc, perhaps you need to run `make wasi-libc`?")
}
ldflags = append(ldflags, path)
case "":
// no library specified, so nothing to do
default:
return fmt.Errorf("unknown libc: %s", config.Target.Libc)
}
// Add jobs to compile extra files. These files are in C or assembly and
// contain things like the interrupt vector table and low level operations
// such as stack switching.
root := goenv.Get("TINYGOROOT")
for _, path := range config.ExtraFiles() {
abspath := filepath.Join(root, path)
job := &compileJob{
@@ -537,6 +514,31 @@ func Build(pkgName, outpath string, config *compileopts.Config, action func(Buil
ldflags = append(ldflags, lprogram.LDFlags...)
}
// Add libc dependency if needed.
switch config.Target.Libc {
case "picolibc":
job, err := Picolibc.load(config.Triple(), config.CPU(), dir)
if err != nil {
return err
}
// The library needs to be compiled (cache miss).
jobs = append(jobs, job.dependencies...)
jobs = append(jobs, job)
linkerDependencies = append(linkerDependencies, job)
case "wasi-libc":
path := filepath.Join(root, "lib/wasi-libc/sysroot/lib/wasm32-wasi/libc.a")
if _, err := os.Stat(path); os.IsNotExist(err) {
return errors.New("could not find wasi-libc, perhaps you need to run `make wasi-libc`?")
}
job := dummyCompileJob(path)
jobs = append(jobs, job)
linkerDependencies = append(linkerDependencies, job)
case "":
// no library specified, so nothing to do
default:
return fmt.Errorf("unknown libc: %s", config.Target.Libc)
}
// Create a linker job, which links all object files together and does some
// extra stuff that can only be done after linking.
jobs = append(jobs, &compileJob{
+36 -5
View File
@@ -693,6 +693,7 @@ func (c *compilerContext) getDIFile(filename string) llvm.Metadata {
// createPackage builds the LLVM IR for all types, methods, and global variables
// in the given package.
func (c *compilerContext) createPackage(irbuilder llvm.Builder, pkg *ssa.Package) {
println("called create package:", pkg.Pkg.Name())
// Sort by position, so that the order of the functions in the IR matches
// the order of functions in the source file. This is useful for testing,
// for example.
@@ -758,6 +759,35 @@ func (c *compilerContext) createPackage(irbuilder llvm.Builder, pkg *ssa.Package
case *ssa.Global:
// Global variable.
info := c.getGlobalInfo(member)
// process go:embed pragmas
// TODO: skip this if not Go 1.16 or higher
if strings.TrimSpace(info.embeds) != "" {
embeds, err := parseGoEmbed(info.embeds)
if err != nil {
c.addError(member.Pos(), `invalid go:embed pragma: `+err.Error())
goto getGlobal
}
importsEmbedPkg := false
for _, imprt := range pkg.Pkg.Imports() {
if imprt.Name() == "embed" {
importsEmbedPkg = true
break
}
}
if !importsEmbedPkg {
// FIXME: technically the "embed" package needs to be imported in every
// *source file* that has a //go:embed pragma... that will always be the
// case when referencing embed.FS but not necessarily when a go:embed
// pragma is added to a string or []byte. For now, as long as the embed
// package is imported in at least one source file, TinyGo will process
// any go:embed pragmas in the entire package.
c.addError(member.Pos(), `//go:embed only allowed in Go files that import "embed"`)
goto getGlobal
}
fmt.Printf("file embed found at %v (import: %v): %v\n", info.linkName, importsEmbedPkg, embeds)
}
getGlobal:
global := c.getGlobal(member)
if !info.extern {
global.SetInitializer(llvm.ConstNull(global.Type().ElementType()))
@@ -766,6 +796,7 @@ func (c *compilerContext) createPackage(irbuilder llvm.Builder, pkg *ssa.Package
global.SetSection(info.section)
}
}
}
}
}
@@ -1298,15 +1329,15 @@ func (b *builder) createFunctionCall(instr *ssa.CallCommon) (llvm.Value, error)
return b.createMemoryCopyCall(fn, instr.Args)
case name == "runtime.memzero":
return b.createMemoryZeroCall(instr.Args)
case name == "github.com/sago35/device.Asm" || name == "github.com/sago35/device/arm.Asm" || name == "github.com/sago35/device/arm64.Asm" || name == "github.com/sago35/device/avr.Asm" || name == "github.com/sago35/device/riscv.Asm":
case name == "device.Asm" || name == "device/arm.Asm" || name == "device/arm64.Asm" || name == "device/avr.Asm" || name == "device/riscv.Asm":
return b.createInlineAsm(instr.Args)
case name == "github.com/sago35/device.AsmFull" || name == "github.com/sago35/device/arm.AsmFull" || name == "github.com/sago35/device/arm64.AsmFull" || name == "github.com/sago35/device/avr.AsmFull" || name == "github.com/sago35/device/riscv.AsmFull":
case name == "device.AsmFull" || name == "device/arm.AsmFull" || name == "device/arm64.AsmFull" || name == "device/avr.AsmFull" || name == "device/riscv.AsmFull":
return b.createInlineAsmFull(instr)
case strings.HasPrefix(name, "github.com/sago35/device/arm.SVCall"):
case strings.HasPrefix(name, "device/arm.SVCall"):
return b.emitSVCall(instr.Args)
case strings.HasPrefix(name, "github.com/sago35/device/arm64.SVCall"):
case strings.HasPrefix(name, "device/arm64.SVCall"):
return b.emitSV64Call(instr.Args)
case strings.HasPrefix(name, "(github.com/sago35/device/riscv.CSR)."):
case strings.HasPrefix(name, "(device/riscv.CSR)."):
return b.emitCSROperation(instr)
case strings.HasPrefix(name, "syscall.Syscall"):
return b.createSyscall(instr)
+70
View File
@@ -0,0 +1,70 @@
package compiler
import (
"fmt"
"strconv"
"strings"
"unicode"
"unicode/utf8"
)
// parseGoEmbed parses the text following "//go:embed" to extract the glob patterns.
// It accepts unquoted space-separated patterns as well as double-quoted and back-quoted Go strings.
// Copied from https://github.com/golang/go/blob/219fe9d547d09d3de1b024c6c8b8314dd0bf12e4/src/cmd/compile/internal/noder/noder.go#L1717-L1776
func parseGoEmbed(args string) ([]string, error) {
var list []string
for args = strings.TrimSpace(args); args != ""; args = strings.TrimSpace(args) {
var path string
Switch:
switch args[0] {
default:
i := len(args)
for j, c := range args {
if unicode.IsSpace(c) {
i = j
break
}
}
path = args[:i]
args = args[i:]
case '`':
i := strings.Index(args[1:], "`")
if i < 0 {
return nil, fmt.Errorf("invalid quoted string in //go:embed: %s", args)
}
path = args[1 : 1+i]
args = args[1+i+1:]
case '"':
i := 1
for ; i < len(args); i++ {
if args[i] == '\\' {
i++
continue
}
if args[i] == '"' {
q, err := strconv.Unquote(args[:i+1])
if err != nil {
return nil, fmt.Errorf("invalid quoted string in //go:embed: %s", args[:i+1])
}
path = q
args = args[i+1:]
break Switch
}
}
if i >= len(args) {
return nil, fmt.Errorf("invalid quoted string in //go:embed: %s", args)
}
}
if args != "" {
r, _ := utf8.DecodeRuneInString(args)
if !unicode.IsSpace(r) {
return nil, fmt.Errorf("invalid quoted string in //go:embed: %s", args)
}
}
list = append(list, path)
}
return list, nil
}
+4
View File
@@ -331,6 +331,7 @@ type globalInfo struct {
extern bool // go:extern
align int // go:align
section string // go:section
embeds string // go:embed
}
// loadASTComments loads comments on globals from the AST, for use later in the
@@ -448,6 +449,9 @@ func (info *globalInfo) parsePragmas(doc *ast.CommentGroup) {
if len(parts) == 2 {
info.section = parts[1]
}
case "//go:embed":
raw := strings.TrimPrefix(comment.Text, "//go:embed")
info.embeds += " " + raw
}
}
}
+1 -2
View File
@@ -1,6 +1,6 @@
module github.com/tinygo-org/tinygo
go 1.13
go 1.16
require (
github.com/blakesmith/ar v0.0.0-20150311145944-8bd4349a67f2
@@ -9,7 +9,6 @@ require (
github.com/google/shlex v0.0.0-20181106134648-c34317bd91bf
github.com/marcinbor85/gohex v0.0.0-20200531091804-343a4b548892
github.com/mattn/go-colorable v0.1.8
github.com/sago35/device v0.0.0-20210708114705-5c2c56419249
go.bug.st/serial v1.1.2
golang.org/x/sys v0.0.0-20210113181707-4bcb84eeeb78
golang.org/x/tools v0.0.0-20200216192241-b320d3a0f5a2
+6 -7
View File
@@ -8,7 +8,6 @@ github.com/chromedp/sysutil v1.0.0 h1:+ZxhTpfpZlmchB58ih/LBHX52ky7w2VhQVKQMucy3I
github.com/chromedp/sysutil v1.0.0/go.mod h1:kgWmDdq8fTzXYcKIBqIYvRRTnYb9aNS9moAV0xufSww=
github.com/creack/goselect v0.1.1 h1:tiSSgKE1eJtxs1h/VgGQWuXUP0YS4CDIFMp6vaI1ls0=
github.com/creack/goselect v0.1.1/go.mod h1:a/NhLweNvqIYMuxcMOuWY516Cimucms3DglDzQP3hKY=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/gobwas/httphead v0.1.0 h1:exrUm0f4YX0L7EBwZHuCF4GDp8aJfVeBrlLQrs6NqWU=
github.com/gobwas/httphead v0.1.0/go.mod h1:O/RXo79gxV8G+RqlR/otEwx4Q36zl9rqC5u12GKvMCM=
@@ -28,13 +27,11 @@ github.com/mattn/go-colorable v0.1.8 h1:c1ghPdyEDarC70ftn0y+A/Ee++9zz8ljHG1b13eJ
github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sago35/device v0.0.0-20210708114705-5c2c56419249 h1:GU6dEpii0PsE4TF8RuOcEWzbbCZQPtcqdVdZsQXy/Uw=
github.com/sago35/device v0.0.0-20210708114705-5c2c56419249/go.mod h1:N8KfLtl2y31BvW1T9LmO7P+QkfoJk7SurI+0N0lCuOo=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
go.bug.st/serial v1.0.0 h1:ogEPzrllCsnG00EqKRjeYvPRsO7NJW6DqykzkdD6E/k=
go.bug.st/serial v1.0.0/go.mod h1:rpXPISGjuNjPTRTcMlxi9lN6LoIPxd1ixVjBd8aSk/Q=
go.bug.st/serial v1.1.2 h1:6xDpbta8KJ+VLRTeM8ghhxXRMLE/Lr8h9iDKwydarAY=
go.bug.st/serial v1.1.2/go.mod h1:VmYBeyJWp5BnJ0tw2NUJHZdJTGl2ecBGABHlzRK1knY=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
@@ -46,6 +43,8 @@ golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLL
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191128015809-6d18c012aee9 h1:ZBzSG/7F4eNKz2L3GE9o300RX0Az1Bw5HF7PDraD+qU=
golang.org/x/sys v0.0.0-20191128015809-6d18c012aee9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200909081042-eff7692f9009/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
@@ -56,9 +55,9 @@ golang.org/x/tools v0.0.0-20200216192241-b320d3a0f5a2 h1:0sfSpGSa544Fwnbot3Oxq/U
golang.org/x/tools v0.0.0-20200216192241-b320d3a0f5a2/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898 h1:/atklqdjdhuosWIl6AIbOeHJjicWYPqR9bpxqxYG2pA=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
tinygo.org/x/go-llvm v0.0.0-20210308112806-9ef958b6bed4 h1:CMUHxVTb+UuUePuMf8vkWjZ3gTp9BBK91KrgOCwoNHs=
tinygo.org/x/go-llvm v0.0.0-20210308112806-9ef958b6bed4/go.mod h1:fv1F0BSNpxMfCL0zF3M4OPFbgYHnhtB6ST0HvUtu/LE=
tinygo.org/x/go-llvm v0.0.0-20210325115028-e7b85195e81c h1:vn9IPshzYmzZis10UEVrsIBRv9FpykADw6M3/tHHROg=
tinygo.org/x/go-llvm v0.0.0-20210325115028-e7b85195e81c/go.mod h1:fv1F0BSNpxMfCL0zF3M4OPFbgYHnhtB6ST0HvUtu/LE=
+1
View File
@@ -57,6 +57,7 @@ func (r *runner) errorAt(inst instruction, err error) *Error {
pos := getPosition(inst.llvmInst)
return &Error{
ImportPath: r.pkgName,
Inst: inst.llvmInst,
Pos: pos,
Err: err,
Traceback: []ErrorLine{{pos, inst.llvmInst}},
+27 -2
View File
@@ -15,7 +15,7 @@ import (
// package is changed in a way that affects the output so that cached package
// builds will be invalidated.
// This version is independent of the TinyGo version number.
const Version = 1
const Version = 2 // last change: fix GEP on untyped pointers
// Enable extra checks, which should be disabled by default.
// This may help track down bugs by adding a few more sanity checks.
@@ -110,17 +110,26 @@ func Run(mod llvm.Module, debug bool) error {
fmt.Fprintln(os.Stderr, "call:", fn.Name())
}
_, mem, callErr := r.run(r.getFunction(fn), nil, nil, " ")
call.EraseFromParentAsInstruction()
if callErr != nil {
if isRecoverableError(callErr.Err) {
if r.debug {
fmt.Fprintln(os.Stderr, "not interpreting", r.pkgName, "because of error:", callErr.Error())
}
// Remove instructions that were created as part of interpreting
// the package.
mem.revert()
// Create a call to the package initializer (which was
// previously deleted).
i8undef := llvm.Undef(r.i8ptrType)
r.builder.CreateCall(fn, []llvm.Value{i8undef, i8undef}, "")
// Make sure that any globals touched by the package
// initializer, won't be accessed by later package initializers.
r.markExternalLoad(fn)
continue
}
return callErr
}
call.EraseFromParentAsInstruction()
for index, obj := range mem.objects {
r.objects[index] = obj
}
@@ -270,3 +279,19 @@ func (r *runner) getFunction(llvmFn llvm.Value) *function {
r.functionCache[llvmFn] = fn
return fn
}
// markExternalLoad marks the given llvmValue as being loaded externally. This
// is primarily used to mark package initializers that could not be run at
// compile time. As an example, a package initialize might store to a global
// variable. Another package initializer might read from the same global
// variable. By marking this function as being run at runtime, that load
// instruction will need to be run at runtime instead of at compile time.
func (r *runner) markExternalLoad(llvmValue llvm.Value) {
mem := memoryView{r: r}
mem.markExternalLoad(llvmValue)
for index, obj := range mem.objects {
if obj.marked > r.objects[index].marked {
r.objects[index].marked = obj.marked
}
}
}
+1
View File
@@ -17,6 +17,7 @@ func TestInterp(t *testing.T) {
"slice-copy",
"consteval",
"interface",
"revert",
} {
name := name // make tc local to this closure
t.Run(name, func(t *testing.T) {
+11
View File
@@ -572,6 +572,17 @@ func (v pointerValue) toLLVMValue(llvmType llvm.Type, mem *memoryView) (llvm.Val
}
if llvmType.IsNil() {
if v.offset() != 0 {
// If there is an offset, make sure to use a GEP to index into the
// pointer. Because there is no expected type, we use whatever is
// most convenient: an *i8 type. It is trivial to index byte-wise.
if llvmValue.Type() != mem.r.i8ptrType {
llvmValue = llvm.ConstBitCast(llvmValue, mem.r.i8ptrType)
}
llvmValue = llvm.ConstInBoundsGEP(llvmValue, []llvm.Value{
llvm.ConstInt(llvmValue.Type().Context().Int32Type(), uint64(v.offset()), false),
})
}
return llvmValue, nil
}
+32
View File
@@ -0,0 +1,32 @@
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64--linux"
declare void @externalCall(i64)
@foo.knownAtRuntime = global i64 0
@bar.knownAtRuntime = global i64 0
define void @runtime.initAll() unnamed_addr {
entry:
call void @foo.init(i8* undef, i8* undef)
call void @bar.init(i8* undef, i8* undef)
call void @main.init(i8* undef, i8* undef)
ret void
}
define internal void @foo.init(i8* %context, i8* %parentHandle) unnamed_addr {
store i64 5, i64* @foo.knownAtRuntime
unreachable ; this triggers a revert of @foo.init.
}
define internal void @bar.init(i8* %context, i8* %parentHandle) unnamed_addr {
%val = load i64, i64* @foo.knownAtRuntime
store i64 %val, i64* @bar.knownAtRuntime
ret void
}
define internal void @main.init(i8* %context, i8* %parentHandle) unnamed_addr {
entry:
call void @externalCall(i64 3)
ret void
}
+21
View File
@@ -0,0 +1,21 @@
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64--linux"
@foo.knownAtRuntime = local_unnamed_addr global i64 0
@bar.knownAtRuntime = local_unnamed_addr global i64 0
declare void @externalCall(i64) local_unnamed_addr
define void @runtime.initAll() unnamed_addr {
entry:
call fastcc void @foo.init(i8* undef, i8* undef)
%val = load i64, i64* @foo.knownAtRuntime, align 8
store i64 %val, i64* @bar.knownAtRuntime, align 8
call void @externalCall(i64 3)
ret void
}
define internal fastcc void @foo.init(i8* %context, i8* %parentHandle) unnamed_addr {
store i64 5, i64* @foo.knownAtRuntime, align 8
unreachable
}
+14 -15
View File
@@ -125,7 +125,7 @@ func TestCompiler(t *testing.T) {
// Test with few optimizations enabled (no inlining, etc).
t.Run("opt=1", func(t *testing.T) {
t.Parallel()
runTestWithConfig("stdlib.go", "", t, &compileopts.Options{
runTestWithConfig("stdlib.go", "", t, compileopts.Options{
Opt: "1",
}, nil, nil)
})
@@ -134,15 +134,14 @@ func TestCompiler(t *testing.T) {
// TODO: fix this for stdlib.go, which currently fails.
t.Run("opt=0", func(t *testing.T) {
t.Parallel()
runTestWithConfig("print.go", "", t, &compileopts.Options{
runTestWithConfig("print.go", "", t, compileopts.Options{
Opt: "0",
}, nil, nil)
})
t.Run("ldflags", func(t *testing.T) {
t.Parallel()
runTestWithConfig("ldflags.go", "", t, &compileopts.Options{
Opt: "z",
runTestWithConfig("ldflags.go", "", t, compileopts.Options{
GlobalValues: map[string]map[string]string{
"main": {
"someGlobal": "foobar",
@@ -188,20 +187,20 @@ func runBuild(src, out string, opts *compileopts.Options) error {
}
func runTest(name, target string, t *testing.T, cmdArgs, environmentVars []string) {
options := &compileopts.Options{
Target: target,
Opt: "z",
PrintIR: false,
DumpSSA: false,
VerifyIR: true,
Debug: true,
PrintSizes: "",
WasmAbi: "",
options := compileopts.Options{
Target: target,
}
runTestWithConfig(name, target, t, options, cmdArgs, environmentVars)
}
func runTestWithConfig(name, target string, t *testing.T, options *compileopts.Options, cmdArgs, environmentVars []string) {
func runTestWithConfig(name, target string, t *testing.T, options compileopts.Options, cmdArgs, environmentVars []string) {
// Set default config.
options.Debug = true
options.VerifyIR = true
if options.Opt == "" {
options.Opt = "z"
}
// Get the expected output for this test.
// Note: not using filepath.Join as it strips the path separator at the end
// of the path.
@@ -230,7 +229,7 @@ func runTestWithConfig(name, target string, t *testing.T, options *compileopts.O
// Build the test binary.
binary := filepath.Join(tmpdir, "test")
err = runBuild("./"+path, binary, options)
err = runBuild("./"+path, binary, &options)
if err != nil {
printCompilerError(t.Log, err)
t.Fail()
+1 -1
View File
@@ -7,7 +7,7 @@
package nxp
import (
"github.com/sago35/device/arm"
"device/arm"
"runtime/volatile"
"unsafe"
)
+1 -1
View File
@@ -1,7 +1,7 @@
package main
import (
"github.com/sago35/device/sam"
"device/sam"
"fmt"
"machine"
"time"
+22
View File
@@ -0,0 +1,22 @@
package main
import (
"embed"
"log"
)
//go:embed file*.txt
//go:embed index.html styles.css
var files embed.FS
func main() {
println(".....")
println(msg)
contents, err := files.ReadDir(".")
if err != nil {
log.Fatal(err)
}
for _, c := range contents {
println("file:", c.Name())
}
}
+1
View File
@@ -0,0 +1 @@
file 1
+1
View File
@@ -0,0 +1 @@
file 2
+1
View File
@@ -0,0 +1 @@
file 3
View File
+1
View File
@@ -0,0 +1 @@
hello world!
View File
+6
View File
@@ -0,0 +1,6 @@
package main
import _ "embed"
//go:embed message.txt
var msg string
+1 -1
View File
@@ -1,7 +1,7 @@
package main
import (
"github.com/sago35/device/arm"
"device/arm"
"machine"
)
+1 -1
View File
@@ -9,7 +9,7 @@ package task
// space for interrupts.
import (
"github.com/sago35/device/arm"
"device/arm"
"unsafe"
)
@@ -3,7 +3,7 @@
package machine
import (
"github.com/sago35/device/sam"
"device/sam"
"runtime/interrupt"
)
+1 -1
View File
@@ -3,7 +3,7 @@
package machine
import (
"github.com/sago35/device/sam"
"device/sam"
"runtime/interrupt"
)
+1 -1
View File
@@ -3,7 +3,7 @@
package machine
import (
"github.com/sago35/device/stm32"
"device/stm32"
"runtime/interrupt"
)
@@ -3,7 +3,7 @@
package machine
import (
"github.com/sago35/device/sam"
"device/sam"
"runtime/interrupt"
)
+1 -1
View File
@@ -3,7 +3,7 @@
package machine
import (
"github.com/sago35/device/sam"
"device/sam"
"runtime/interrupt"
)
+1 -1
View File
@@ -3,7 +3,7 @@
package machine
import (
"github.com/sago35/device/sam"
"device/sam"
"runtime/interrupt"
)
+1 -1
View File
@@ -3,7 +3,7 @@
package machine
import (
"github.com/sago35/device/sam"
"device/sam"
"runtime/interrupt"
)
+1 -1
View File
@@ -3,7 +3,7 @@
package machine
import (
"github.com/sago35/device/stm32"
"device/stm32"
"runtime/interrupt"
)
@@ -3,7 +3,7 @@
package machine
import (
"github.com/sago35/device/sam"
"device/sam"
"runtime/interrupt"
)
+1 -1
View File
@@ -2,7 +2,7 @@
package machine
import "github.com/sago35/device/sifive"
import "device/sifive"
// SPI on the HiFive1.
var (
+1 -1
View File
@@ -3,7 +3,7 @@
package machine
import (
"github.com/sago35/device/sam"
"device/sam"
"runtime/interrupt"
)
+1 -1
View File
@@ -3,7 +3,7 @@
package machine
import (
"github.com/sago35/device/sam"
"device/sam"
"runtime/interrupt"
)
+1 -1
View File
@@ -3,7 +3,7 @@
package machine
import (
"github.com/sago35/device/stm32"
"device/stm32"
"runtime/interrupt"
)
+1 -1
View File
@@ -2,7 +2,7 @@
package machine
import "github.com/sago35/device/kendryte"
import "device/kendryte"
// SPI on the MAix Bit.
var (
@@ -3,7 +3,7 @@
package machine
import (
"github.com/sago35/device/sam"
"device/sam"
"runtime/interrupt"
)
@@ -3,7 +3,7 @@
package machine
import (
"github.com/sago35/device/sam"
"device/sam"
"runtime/interrupt"
)
+1 -1
View File
@@ -3,7 +3,7 @@
package machine
import (
"github.com/sago35/device/stm32"
"device/stm32"
"runtime/interrupt"
)
+1 -1
View File
@@ -3,7 +3,7 @@
package machine
import (
"github.com/sago35/device/stm32"
"device/stm32"
"runtime/interrupt"
)
+1 -1
View File
@@ -3,7 +3,7 @@
package machine
import (
"github.com/sago35/device/stm32"
"device/stm32"
"runtime/interrupt"
)
+1 -1
View File
@@ -3,7 +3,7 @@
package machine
import (
"github.com/sago35/device/stm32"
"device/stm32"
"runtime/interrupt"
)
+1 -1
View File
@@ -3,7 +3,7 @@
package machine
import (
"github.com/sago35/device/stm32"
"device/stm32"
"runtime/interrupt"
)
+1 -1
View File
@@ -3,7 +3,7 @@
package machine
import (
"github.com/sago35/device/sam"
"device/sam"
"runtime/interrupt"
)
+1 -1
View File
@@ -3,7 +3,7 @@
package machine
import (
"github.com/sago35/device/sam"
"device/sam"
"runtime/interrupt"
)
+1 -1
View File
@@ -2,7 +2,7 @@
package machine
import "github.com/sago35/device/sam"
import "device/sam"
// used to reset into bootloader
const RESET_MAGIC_VALUE = 0xf01669ef
+1 -1
View File
@@ -3,7 +3,7 @@
package machine
import (
"github.com/sago35/device/sam"
"device/sam"
"runtime/interrupt"
)
+1 -1
View File
@@ -3,7 +3,7 @@
package machine
import (
"github.com/sago35/device/sam"
"device/sam"
"runtime/interrupt"
)
+1 -1
View File
@@ -3,7 +3,7 @@
package machine
import (
"github.com/sago35/device/stm32"
"device/stm32"
"runtime/interrupt"
)
+1 -1
View File
@@ -3,7 +3,7 @@
package machine
import (
"github.com/sago35/device/nxp"
"device/nxp"
"runtime/interrupt"
)
+1 -1
View File
@@ -3,7 +3,7 @@
package machine
import (
"github.com/sago35/device/sam"
"device/sam"
"runtime/interrupt"
)
+1 -1
View File
@@ -3,7 +3,7 @@
package machine
import (
"github.com/sago35/device/sam"
"device/sam"
"runtime/interrupt"
)
+1 -1
View File
@@ -3,7 +3,7 @@
package machine
import (
"github.com/sago35/device/sam"
"device/sam"
"runtime/interrupt"
)
+1 -1
View File
@@ -3,7 +3,7 @@
package machine
import (
"github.com/sago35/device/avr"
"device/avr"
"runtime/interrupt"
"runtime/volatile"
"unsafe"
+1 -1
View File
@@ -3,7 +3,7 @@
package machine
import (
"github.com/sago35/device/avr"
"device/avr"
"runtime/interrupt"
"runtime/volatile"
)
+1 -1
View File
@@ -3,7 +3,7 @@
package machine
import (
"github.com/sago35/device/avr"
"device/avr"
"runtime/volatile"
)
+1 -1
View File
@@ -3,7 +3,7 @@
package machine
import (
"github.com/sago35/device/avr"
"device/avr"
"runtime/volatile"
)
+1 -1
View File
@@ -3,7 +3,7 @@
package machine
import (
"github.com/sago35/device/avr"
"device/avr"
"runtime/interrupt"
"runtime/volatile"
)
+1 -1
View File
@@ -3,7 +3,7 @@
package machine
import (
"github.com/sago35/device/avr"
"device/avr"
"runtime/volatile"
)
+2 -2
View File
@@ -8,8 +8,8 @@
package machine
import (
"github.com/sago35/device/arm"
"github.com/sago35/device/sam"
"device/arm"
"device/sam"
"errors"
"runtime/interrupt"
"runtime/volatile"
+1 -1
View File
@@ -8,7 +8,7 @@
package machine
import (
"github.com/sago35/device/sam"
"device/sam"
)
// Return the register and mask to enable a given GPIO pin. This can be used to
+1 -1
View File
@@ -8,7 +8,7 @@
package machine
import (
"github.com/sago35/device/sam"
"device/sam"
)
// Return the register and mask to enable a given GPIO pin. This can be used to
+2 -2
View File
@@ -8,8 +8,8 @@
package machine
import (
"github.com/sago35/device/arm"
"github.com/sago35/device/sam"
"device/arm"
"device/sam"
"errors"
"runtime/interrupt"
"runtime/volatile"
+1 -1
View File
@@ -7,7 +7,7 @@
//
package machine
import "github.com/sago35/device/sam"
import "device/sam"
const HSRAM_SIZE = 0x00030000
+1 -1
View File
@@ -7,7 +7,7 @@
//
package machine
import "github.com/sago35/device/sam"
import "device/sam"
const HSRAM_SIZE = 0x00030000
+1 -1
View File
@@ -7,7 +7,7 @@
//
package machine
import "github.com/sago35/device/sam"
import "device/sam"
const HSRAM_SIZE = 0x00040000
+1 -1
View File
@@ -7,7 +7,7 @@
//
package machine
import "github.com/sago35/device/sam"
import "device/sam"
const HSRAM_SIZE = 0x00030000
+1 -1
View File
@@ -7,7 +7,7 @@
//
package machine
import "github.com/sago35/device/sam"
import "device/sam"
const HSRAM_SIZE = 0x00040000
+1 -1
View File
@@ -7,7 +7,7 @@
//
package machine
import "github.com/sago35/device/sam"
import "device/sam"
const HSRAM_SIZE = 0x00030000
+1 -1
View File
@@ -7,7 +7,7 @@
//
package machine
import "github.com/sago35/device/sam"
import "device/sam"
const HSRAM_SIZE = 0x00040000
+1 -1
View File
@@ -3,7 +3,7 @@
package machine
import (
"github.com/sago35/device/sam"
"device/sam"
"errors"
"runtime/interrupt"
"unsafe"
+1 -1
View File
@@ -3,7 +3,7 @@
package machine
import (
"github.com/sago35/device/avr"
"device/avr"
"runtime/volatile"
)
+1 -1
View File
@@ -3,7 +3,7 @@
package machine
import (
"github.com/sago35/device/avr"
"device/avr"
"runtime/volatile"
"unsafe"
)
+1 -1
View File
@@ -3,7 +3,7 @@
package machine
import (
"github.com/sago35/device/esp"
"device/esp"
"errors"
"runtime/volatile"
"unsafe"
+1 -1
View File
@@ -3,7 +3,7 @@
package machine
import (
"github.com/sago35/device/esp"
"device/esp"
"runtime/volatile"
)
+1 -1
View File
@@ -3,7 +3,7 @@
package machine
import (
"github.com/sago35/device/sifive"
"device/sifive"
"runtime/interrupt"
"unsafe"
)
+2 -2
View File
@@ -3,8 +3,8 @@
package machine
import (
"github.com/sago35/device/kendryte"
"github.com/sago35/device/riscv"
"device/kendryte"
"device/riscv"
"errors"
"runtime/interrupt"
"unsafe"
+1 -1
View File
@@ -3,7 +3,7 @@
package machine
import (
"github.com/sago35/device/nxp"
"device/nxp"
"math/bits"
"runtime/interrupt"
"runtime/volatile"
+1 -1
View File
@@ -3,7 +3,7 @@
package machine
import (
"github.com/sago35/device/nxp"
"device/nxp"
"runtime/interrupt"
"runtime/volatile"
)
+1 -1
View File
@@ -3,7 +3,7 @@
package machine
import (
"github.com/sago35/device/nrf"
"device/nrf"
"errors"
"runtime/interrupt"
"unsafe"
+1 -1
View File
@@ -3,7 +3,7 @@
package machine
import (
"github.com/sago35/device/nrf"
"device/nrf"
)
func CPUFrequency() uint32 {
+1 -1
View File
@@ -3,7 +3,7 @@
package machine
import (
"github.com/sago35/device/nrf"
"device/nrf"
)
// Hardware pins
+1 -1
View File
@@ -3,7 +3,7 @@
package machine
import (
"github.com/sago35/device/nrf"
"device/nrf"
)
// Hardware pins
+1 -1
View File
@@ -3,7 +3,7 @@
package machine
import (
"github.com/sago35/device/nrf"
"device/nrf"
)
// Hardware pins
+2 -2
View File
@@ -3,8 +3,8 @@
package machine
import (
"github.com/sago35/device/arm"
"github.com/sago35/device/nrf"
"device/arm"
"device/nrf"
"runtime/interrupt"
"runtime/volatile"
"unsafe"
@@ -3,8 +3,8 @@
package machine
import (
"github.com/sago35/device/arm"
"github.com/sago35/device/nrf"
"device/arm"
"device/nrf"
)
const DFU_MAGIC_SERIAL_ONLY_RESET = 0xb0
@@ -3,8 +3,8 @@
package machine
import (
"github.com/sago35/device/arm"
"github.com/sago35/device/nrf"
"device/arm"
"device/nrf"
)
const (
+1 -1
View File
@@ -3,7 +3,7 @@
package machine
import (
"github.com/sago35/device/nrf"
"device/nrf"
"runtime/volatile"
"unsafe"
)
+1 -1
View File
@@ -32,7 +32,7 @@
package machine
import (
"github.com/sago35/device/nxp"
"device/nxp"
"runtime/volatile"
"unsafe"
)
+2 -2
View File
@@ -32,8 +32,8 @@
package machine
import (
"github.com/sago35/device/arm"
"github.com/sago35/device/nxp"
"device/arm"
"device/nxp"
"errors"
"runtime/interrupt"
"runtime/volatile"
+1 -1
View File
@@ -3,7 +3,7 @@
package machine
import (
"github.com/sago35/device/rp"
"device/rp"
"runtime/interrupt"
)
+1 -1
View File
@@ -3,7 +3,7 @@
package machine
import (
"github.com/sago35/device/rp"
"device/rp"
)
func InitADC() {
+2 -2
View File
@@ -3,8 +3,8 @@
package machine
import (
"github.com/sago35/device/arm"
"github.com/sago35/device/rp"
"device/arm"
"device/rp"
"runtime/volatile"
"unsafe"
)
+1 -1
View File
@@ -3,7 +3,7 @@
package machine
import (
"github.com/sago35/device/rp"
"device/rp"
"runtime/volatile"
"unsafe"
)
+1 -1
View File
@@ -3,7 +3,7 @@
package machine
import (
"github.com/sago35/device/rp"
"device/rp"
"runtime/volatile"
"unsafe"
)
+1 -1
View File
@@ -3,7 +3,7 @@
package machine
import (
"github.com/sago35/device/rp"
"device/rp"
"runtime/volatile"
"unsafe"
)
+1 -1
View File
@@ -3,7 +3,7 @@
package machine
import (
"github.com/sago35/device/rp"
"device/rp"
"runtime/volatile"
"unsafe"
)

Some files were not shown because too many files have changed in this diff Show More