Граф коммитов

235 коммитов

Автор SHA1 Сообщение Дата
Ayke van Laethem
896a848001 builder: add support for -x flag
Print commands as they are executed with the -x flag. This is not yet
complete: library builds don't print commands yet. But it's a step
closer.
2021-04-05 20:52:04 +02:00
sago35
16e7dd83a3 gdb: enable to specify multiple candidates for gdb 2021-03-29 00:21:38 +02:00
Ayke van Laethem
c60c36f0a8 all: use ExitCode() call to get exit code of exited process
This is an addition that landed in Go 1.12 but we couldn't use before
because we were supporting Go back until Go 1.11. It simplifies the code
around processes a bit.
2021-03-09 18:15:49 +01:00
Ayke van Laethem
e3aa13c2a6 all: replace strings.Replace with strings.ReplaceAll
This was an addition to Go 1.13 and results in slightly easier to read
code.
2021-03-09 18:15:49 +01:00
Ayke van Laethem
3d13f9cfe1 transform: show better error message in coroutines lowering
A common error is when someone tries to export a blocking function. This
is not possible with the coroutines scheduler. Previously, it resulted
in an error like this:

    panic: trying to make exported function async: messageHandler

With this change, the error is much better and shows where it comes from
exactly:

    /home/ayke/tmp/export-async.go:8: blocking operation in exported function: messageHandler

    traceback:
    messageHandler
            /home/ayke/tmp/export-async.go:9:5
    main.foo
            /home/ayke/tmp/export-async.go:15:2
    runtime.chanSend
            /home/ayke/src/github.com/tinygo-org/tinygo/src/runtime/chan.go:494:12

This should make it easier to identify and fix the problem. And it
avoids a compiler panic, which is a really bad way of showing
diagnostics.
2021-03-05 14:42:43 +01:00
sago35
c4191da2a5 gdb: support -ocd-output on windows 2021-03-05 13:02:01 +01:00
sago35
3fdd1a9249 gdb: kill openocd if it does not exit 2021-03-05 11:16:42 +01:00
Ayke van Laethem
d85ac4b3cc builder: parallelize most of the build
This commit parallelizes almost everything that can currently be
parallelized. With that, it also introduces a framework for easily
parallelizing other parts of the compiler.

Code for baremetal targets already compiles slightly faster because it
can parallelize the compilation of supporting assembly files. However,
the speedup is especially noticeable when libraries (compiler-rt,
picolibc) also need to be compiled: they will be compiled in parallel
next to the Go files using all available cores. On my dual core laptop
(4 cores if you count hyperthreading) this cuts compilation time roughly
in half when compiling something for a Cortex-M board after running
`tinygo clean`.
2021-01-24 09:13:02 +01:00
Fauchon
c4d642007e
New tinygo -x option to print commands (#1572)
main: add '-x' runtime flag that displays the executed external commands when performing operations like flashing.
2021-01-14 21:35:01 +01:00
Ayke van Laethem
da0161d6ab wasm: implement a growable heap
On WebAssembly it is possible to grow the heap with the memory.grow
instruction. This commit implements this feature and with that also
removes the -heap-size flag that was reportedly broken (I haven't
verified that). This should make it easier to use TinyGo for
WebAssembly, where there was no good reason to use a fixed heap size.

This commit has no effect on baremetal targets with optimizations
enabled.
2021-01-10 21:08:52 +01:00
Ayke van Laethem
4cc1cdf672 main: support gdb debugging with AVR
Be able to run `tinygo gdb -target=arduino examples/serial` and debug a
program with the power of a real debugger.

Note that this only works on LLVM 11 because older versions have a bug
in the AVR backend that cause it to produce invalid debug information:
https://reviews.llvm.org/D74213.
2020-12-10 16:44:27 +01:00
Takeshi Yoneda
9a015f4f64
add wasm-abi field in TargetSpec && set generic for WASI by default (#1421)
Signed-off-by: mathetake <takeshi@tetrate.io>
2020-10-03 19:52:01 +02:00
Ayke van Laethem
7123941df0 main: add support for debugging qemu-user targets
This commit allows debugging like the following:

    GOARCH=arm tinygo gdb ./testdata/alias.go

This can be very useful to debug issues on a different instruction set
architecture but still on a host system.

I tested the following 7 configurations to make sure it works and I
didn't break anything:

    GOOS=amd64
    GOOS=386
    GOOS=arm
    GOOS=arm64
    tinygo gdb -target=hifive1-qemu
    tinygo gdb -target=cortex-m-qemu
    tinygo gdb -target=microbit
2020-10-02 08:54:43 +02:00
Ayke van Laethem
54602fe0c3 main: add support for -c and -o flags to tinygo test 2020-09-25 16:18:10 +02:00
Ayke van Laethem
c10dcd429c main: refactor -o flag 2020-09-25 16:18:10 +02:00
Ayke van Laethem
b713001313 test: support non-host tests
For example, for running tests with -target=wasm or
-target=cortex-m-qemu. It looks at the output to determine whether tests
were successful in the absence of a status code.
2020-09-24 21:17:26 +02:00
Ayke van Laethem
e7227df80d main: implement tinygo targets to list usable targets
This patch adds the `tinygo targets` command, which lists usable
targets (targets that can be used in the `-target` flag).

The assumption here is that usable targets can either be flashed or
emulated by TinyGo. There is one exception where it doesn't work yet:
the nintendoswitch target. Right now it requires some manual steps to
build a .nro file which can then be run by yuzu, hence why it doesn't
show up in the list.
2020-09-09 13:05:14 +02:00
Ayke van Laethem
de3ffe0af7 main: add cached GOROOT to info subcommand
This is necessary for an upcoming VS Code extension to support TinyGo,
and may be useful for other people wanting to use proper autocompletion
etc in their IDE.
2020-09-07 13:07:17 +02:00
Ayke van Laethem
88fd2823df all: run test binaries in the correct directory
Test binaries must be run in the source directory of the package to be
tested. This wasn't done, leading to a few "file not found" errors.

This commit implements this. Unfortunately, it does not allow more
packages to be tested as both affected packages (debug/macho and
debug/plan9obj) will still fail with this patch even though the "file
not found" errors are gone.
2020-09-04 12:21:19 +02:00
Ayke van Laethem
c810628a20 loader: rewrite/refactor much of the code to use go list directly
There were a few problems with the go/packages package. While it is more
or less designed for our purpose, it didn't work quite well as it didn't
provide access to indirectly imported packages (most importantly the
runtime package). This led to a workaround that sometimes broke
`tinygo test`.

This PR contains a number of related changes:

  * It uses `go list` directly to retrieve the list of packages/files to
    compile, instead of relying on the go/packages package.
  * It replaces our custom TestMain replace code with the standard code
    for running tests (generated by `go list`).
  * It adds a dummy runtime/pprof package and modifies the testing
    package, to get tests to run again with the code generated by
    `go list`.
2020-09-03 22:10:14 +02:00
sago35
946184b8ba flash: call PortReset only on other than openocd 2020-08-31 20:01:22 +02:00
sago35
e5e324f93e
main: embed git-hash in tinygo-dev executable 2020-08-25 16:23:16 +02:00
sago35
d1ac0138e6 main: use ToSlash() to specify program path 2020-08-25 14:25:49 +02:00
deadprogram
743254d5bc main: use simpler file copy instead of file renaming to avoid issues on nrf52840 UF2 bootloaders
Signed-off-by: deadprogram <ron@hybridgroup.com>
2020-08-25 13:51:15 +02:00
Ayke van Laethem
d606315515 builder: try to determine stack size information at compile time
For now, this is just an extra flag that can be used to print stack
frame information, but this is intended to provide a way to determine
stack sizes for goroutines at compile time in many cases.

Stack sizes are often somewhere around 350 bytes so are in fact not all
that big usually. Once this can be determined at compile time in many
cases, it is possible to use this information when available and as a
result increase the fallback stack size if the size cannot be determined
at compile time. This should reduce stack overflows while at the same
time reducing RAM consumption in many cases.

Interesting output for testdata/channel.go:

    function                                 stack usage (in bytes)
    Reset_Handler                            332
    .Lcommand-line-arguments.fastreceiver    220
    .Lcommand-line-arguments.fastsender      192
    .Lcommand-line-arguments.iterator        192
    .Lcommand-line-arguments.main$1          184
    .Lcommand-line-arguments.main$2          200
    .Lcommand-line-arguments.main$3          200
    .Lcommand-line-arguments.main$4          328
    .Lcommand-line-arguments.receive         176
    .Lcommand-line-arguments.selectDeadlock  72
    .Lcommand-line-arguments.selectNoOp      72
    .Lcommand-line-arguments.send            184
    .Lcommand-line-arguments.sendComplex     192
    .Lcommand-line-arguments.sender          192
    .Lruntime.run$1                          548

This shows that the stack size (if these numbers are correct) can in
fact be determined automatically in many cases, especially for small
goroutines. One of the great things about Go is lightweight goroutines,
and reducing stack sizes is very important to make goroutines
lightweight on microcontrollers.
2020-07-11 14:47:43 +02:00
sago35
3e8cdb62c9
main: use ToSlash() to specify pkgName
This change allows windows users to specify the package with backslash
as a path separator
2020-06-23 19:20:18 +02:00
sago35
72064e12db WIP flash: fix touchSerialPortAt1200bps on windows 2020-06-03 15:26:03 +02:00
deadprogram
bcbc241d81 main: improve/simplify auto-retry to locate MSD for UF2 and HEX flashing
Signed-off-by: deadprogram <ron@hybridgroup.com>
2020-05-31 13:23:19 +02:00
deadprogram
5e2a8024a3 main: use auto-retry (up to 10 seconds) to locate MSD for UF2 and HEX flashing
Signed-off-by: deadprogram <ron@hybridgroup.com>
2020-05-31 13:23:19 +02:00
Ayke van Laethem
4ca2d3f0cf loader: load packages using Go modules
This commit replaces the existing ad-hoc package loader with a package
loader that uses the x/tools/go/packages package to find all
to-be-loaded packages.
2020-05-27 13:08:17 +02:00
Ayke van Laethem
35015a7918 loader: merge roots from both Go and TinyGo in a cached directory
This commit changes the way that packages are looked up. Instead of
working around the loader package by modifying the GOROOT variable for
specific packages, create a new GOROOT using symlinks. This GOROOT is
cached for the specified configuration (Go version, underlying GOROOT
path, TinyGo path, whether to override the syscall package).

This will also enable go module support in the future.

Windows is a bit harder to support, because it only allows the creation
of symlinks when developer mode is enabled. This is worked around by
using symlinks and if that fails, using directory junctions or hardlinks
instead. This should work in the vast majority of cases. The only case
it doesn't work, is if developer mode is disabled and TinyGo, the Go
toolchain, and the cache directory are not all on the same filesystem.
If this is a problem, it is still possible to improve the code by using
file copies instead.

As a side effect, this also makes diagnostics use a relative file path
only when the file is not in GOROOT or in TINYGOROOT.
2020-05-27 13:08:17 +02:00
Ayke van Laethem
bde73fc214 main: fix test subcommand
It was broken for quite some time without anybody noticing...
2020-05-27 13:08:17 +02:00
Ayke van Laethem
ab2a81cc52 main: move TinyGo version to goenv
This is needed to make it available to more packages, for caching
purposes.

For caching, the version itself may not be enough during development.
But for regular releases, the version provides some protection against
accidentally using a cache entry that is invalid in a newer version.
2020-05-27 13:08:17 +02:00
Ayke van Laethem
2a98433c8e builder: move Go version code to goenv package
This is necessary to avoid a circular dependency in the loader (which
soon will need to read the Go version) and because it seems like a
better place anyway.
2020-05-27 13:08:17 +02:00
cebernardi
76fb3bd177
compileopts: improve error reporting of unsupported flags 2020-05-16 23:29:47 +02:00
sago35
8ce3cfad40 flash: fix getDefaultPort() fails on Windows locales such as Japan 2020-05-07 22:47:45 +02:00
Ron Evans
bb540df2d1 flash: retry 3 times when attempting to reset the serial port
Signed-off-by: Ron Evans <ron@hybridgroup.com>
2020-04-13 16:18:48 +02:00
Ayke van Laethem
0afd42c439 main: switch to LLVM 10
This commit also adds a bit of version independence, in particular for
external commands. It also adds the LLVM version to the `tinygo version`
command, which might help while debugging.
2020-04-09 20:23:51 +02:00
Ayke van Laethem
f06d7d1bd6 builder: run tools (clang, ...) as separate processes
This is necessary because LLVM defines many options in global variables
that are modified when invoking Clang. In particular, LLVM 10 seems to
have a bug in which it always sets the -pgo-warn-misexpect flag. Setting
it multiple times (over various cc1 invocations) results in an error:

    clang (LLVM option parsing): for the --pgo-warn-misexpect option: may only occur zero or one times!

This is fixed by running the Clang invocation in a new `tinygo`
invocation.

Because we've had issues with lld in the past, also run lld in a
separate process so similar issues won't happen with lld in the future.
2020-04-03 12:41:44 +02:00
Jaden Weiss
62e78c0a26 runtime (gc): add garbage collector that uses an external allocator 2020-03-30 14:35:29 +02:00
Ayke van Laethem
cc4a4c755f interp: show backtrace with error
This should make it much easier to figure out why and where an error
happens at package initialization time.
2020-03-28 21:55:12 +01:00
Ayke van Laethem
f316ebc23b all: include picolibc for bare metal targets
This is necessary for better CGo support on bare metal. Existing
libraries expect to be able to include parts of libc and expect to be
able to link to those symbols.

Because with this all targets have a working libc, it is now possible to
add tests to check that a libc in fact works basically.

Not all parts of picolibc are included, such as the math or stdio parts.
These should be added later, when needed.

This commit also avoids the need for the custom memcpy/memset/memcmp
symbols that are sometimes emitted by LLVM. The C library will take care
of that.
2020-03-22 17:14:59 +01:00
Ayke van Laethem
9ec426e25e builder: refactor compiler-rt library
This refactor makes adding a new library (such as a libc) much easier in
the future as it avoids a lot of duplicate code. Additionally, CI should
become a little bit faster (~15s) as build-builtins now uses the build
cache.
2020-03-22 17:14:59 +01:00
Ayke van Laethem
63cfb09e9e main: move some duplicate code to a single place
This makes fixes like https://github.com/tinygo-org/tinygo/pull/915
easier to apply. And in general, avoiding duplication is a good thing.
2020-03-17 13:24:41 +01:00
Ayke van Laethem
982b2d06ab main: improve error reporting while running go test
This commit switches integration tests to use the same error reporting
mechanism as the tinygo compiler normally uses. It replaces errors like
this:

    main_test.go:139: failed to build: interp: branch on a non-constant

With this:

    main.go:693: # math/rand
    main.go:695: interp: branch on a non-constant

In this particular case the error isn't much better (it gives the
relevant package, though) but other errors should also include the
source location where they happen.
2020-03-16 07:40:23 -07:00
Ayke van Laethem
53688c86c8 gameboy-advance: enable debugging with GDB 2020-02-26 20:39:43 +01:00
Ayke van Laethem
b3d3debd4c main: check for error after starting the OCD daemon
This replaces a panic with an informative error message if the right
tool (such as OpenOCD) is not installed.
2020-02-26 20:04:32 +01:00
Elliott Sales de Andrade
d11abb33fe
main: use go mod expected path for go.bug.st/serial 2020-02-11 20:09:22 +01:00
Ayke van Laethem
46ccb6793e main: differentiate between various serial/USB error messages
This way it is possible to determine the source of an error when it
happens.
2020-01-27 19:46:53 +01:00
Ron Evans
3f9609560e flash: remove default port check for Digispark as micronucleus communicates directly using HID
Signed-off-by: Ron Evans <ron@hybridgroup.com>
2020-01-25 13:49:27 +01:00