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

1853 коммитов

Автор SHA1 Сообщение Дата
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
Ayke van Laethem
3010466c55 reflect: implement PtrTo 2021-01-23 10:55:46 +01:00
Ayke van Laethem
36db75b366 loader: support imports from vendor directories
This fixes https://github.com/tinygo-org/tinygo/issues/1518.
2021-01-21 19:06:02 +01:00
deadprogram
a5e2b27884 docker: update dev docker image to use llvm11
Signed-off-by: deadprogram <ron@hybridgroup.com>
2021-01-19 21:26:06 +01:00
Nia Weiss
a5cf704d83 compiler: test float to int conversions and fix upper-bound calculation 2021-01-19 14:02:32 +01:00
Ayke van Laethem
a90865506d main: use LLVM 11 by default when linking LLVM dynamically
This doesn't affect the release builds but it is helpful for TinyGo
developers.
2021-01-19 08:55:57 +01:00
Nia Weiss
a867b56e5f compiler: saturate float-to-int conversions
This works around some UB in LLVM, where an out-of-bounds conversion would produce a poison value.
The selected behavior is saturating, except that NaN is mapped to the minimum value.
2021-01-16 19:12:36 +01:00
Nia Weiss
f159429152 compiler: emit a nil check when slicing an array pointer 2021-01-15 21:35:49 +01:00
Ayke van Laethem
a848d720db compiler: refactor and add tests
This commit finally introduces unit tests for the compiler, to check
whether input Go code is converted to the expected output IR.

To make this necessary, a few refactors were needed. Hopefully these
refactors (to compile a program package by package instead of all at
once) will eventually become standard, so that packages can all be
compiled separate from each other and be cached between compiles.
2021-01-15 14:43:43 +01:00
Ayke van Laethem
dbc438b2ae loader: use name "main" for the main package
This should make exported names a bit more consistent.

I believe there was a bug report for this issue, but I can't easily find
it. In any case, I think it's an important improvement to match the
behavior of the Go toolchain.
2021-01-15 14:43:43 +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
5af4c073cd runtime: put metadata at the top end of the heap
This commit swaps the layout of the heap. Previously, the metadata was
at the start and the data blocks (the actual heap memory) followed
after. This commit swaps those, so that the heap area starts with the
data blocks followed by the heap metadata.

This arrangement is not very relevant for baremetal targets that always
have all RAM allocated, but it is an important improvement for other
targets such as WebAssembly where growing the heap is possible but
starting with a small heap is a good idea. Because the metadata lives at
the end, and because the metadata does not contain pointers, it can
easily be moved. The data itself cannot be moved as the conservative GC
does not know all the pointer locations, plus moving the data could be
very expensive.
2021-01-10 21:08:52 +01:00
Ayke van Laethem
154c7c691b stm32: use stm32-rs SVDs which are of much higher quality
This commit changes the number of wait states for the stm32f103 chip to
2 instead of 4. This gets it back in line with the datasheet, but it
also has the side effect of breaking I2C. Therefore, another (seemingly
unrelated) change is needed: the i2cTimeout constant must be increased
to a higher value to adjust to the lower flash wait states - presumably
because the lower number of wait states allows the chip to run code
faster.
2021-01-09 21:45:07 +01:00
Fauchon
65caf777dd
Support for STM32L0 MCUs and Dragino LGT92 device (#1561)
machine/stm32l0: add support for stm32l0 family and Dragino LGT92 Board
2021-01-08 22:27:25 +01:00
Ayke van Laethem
a4d0877cf0 stacksize: add support for DW_CFA_offset_extended
It should be possible to ignore this directive, but we still have to
consume the two operands.
2021-01-06 19:41:47 +01:00
deadprogram
6ec868710b machine/microbit-v2: add initial support based on work done by @alankrantas thank you!
Signed-off-by: deadprogram <ron@hybridgroup.com>
2021-01-06 18:50:46 +01:00
deadprogram
086645153e tools/gen: ignore cluster registers with no actual clusters in them, and handle parsing binary integer fields in versions of Go before 1.13
Signed-off-by: deadprogram <ron@hybridgroup.com>
2021-01-06 18:50:46 +01:00
deadprogram
cf930f652e nrfx: updare submodule to latest commit
Signed-off-by: deadprogram <ron@hybridgroup.com>
2021-01-06 18:50:46 +01:00
Quentin Smith
0dcff35d3a machine/p1am-100: rename MISO/MOSI
This makes p1am-100 work again after commit d1c4ed6.
2021-01-06 13:35:30 +01:00
Quentin Smith
75f13491b6 Add support for the P1AM-100 (similar to Arduino MKR) 2021-01-06 00:36:57 +01:00
Wu Han
533d2c9ce0 README: fix bluepill link
STM32Duino wiki url has been updated.
2021-01-05 23:59:03 +01:00
Jacques Supcik
2f4200a01b
Add support for additional openocd commands (#1492)
main: add ability to define specific OpenOCD commands to be executed for a target.
2020-12-30 09:19:41 +01:00
deadprogram
939b393325 machine/clue: correct volume name and add alias for release version of Adafruit Clue board
Signed-off-by: deadprogram <ron@hybridgroup.com>
2020-12-29 15:17:38 +01:00
deadprogram
a5ee1ba4b3 machine/nrf52840: ensure that USB CDC interface is only initialized once
Signed-off-by: deadprogram <ron@hybridgroup.com>
2020-12-29 12:20:33 +01:00
Ayke van Laethem
fb0bb69f62 compiler: fix non-int integer constants
Before this change, the compiler could panic with the following message:

    panic: 20 not an Int

That of course doesn't make much sense. But it apparently is expected
behavior, see https://github.com/golang/go/issues/43165 for details.

This commit fixes this issue by converting the constant to an integer if
needed.
2020-12-27 16:13:36 +01:00
Ayke van Laethem
5917b8baa2 interp: fix alignment of untyped globals
During a run of interp, some memory (for example, memory allocated
through runtime.alloc) may not have a known LLVM type. This memory is
alllocated by creating an i8 array.
This does not necessarily work, as i8 has no alignment requirements
while the allocated object may have allocation requirements. Therefore,
the resulting global may have an alignment that is too loose.
This works on some microcontrollers but notably does not work on a
Cortex-M0 or Cortex-M0+, as all load/store operations must be aligned.

This commit fixes this by setting the alignment of untyped memory to the
maximum alignment. The determination of "maximum alignment" is not
great but should get the job done on most architectures.
2020-12-27 11:21:35 +01:00
Ayke van Laethem
30df912565 interp: rewrite entire package
For a full explanation, see interp/README.md. In short, this rewrite is
a redesign of the partial evaluator which improves it over the previous
partial evaluator. The main functional difference is that when
interpreting a function, the interpretation can be rolled back when an
unsupported instruction is encountered (for example, an actual unknown
instruction or a branch on a value that's only known at runtime). This
also means that it is no longer necessary to scan functions to see
whether they can be interpreted: instead, this package now just tries to
interpret it and reverts when it can't go further.

This new design has several benefits:

  * Most errors coming from the interp package are avoided, as it can
    simply skip the code it can't handle. This has long been an issue.
  * The memory model has been improved, which means some packages now
    pass all tests that previously didn't pass them.
  * Because of a better design, it is in fact a bit faster than the
    previous version.

This means the following packages now pass tests with `tinygo test`:

  * hash/adler32: previously it would hang in an infinite loop
  * math/cmplx: previously it resulted in errors

This also means that the math/big package can be imported. It would
previously fail with a "interp: branch on a non-constant" error.
2020-12-22 15:54:23 +01:00
Ayke van Laethem
e9d549d211 compiler: fix incorrect "exported function" panic
Because the parentHandle parameter wasn't always set to the right value,
the coroutine lowering pass would sometimes panic with "trying to make
exported function async" even though there was no exported function
involved. Therefore, it should unconditionally be set to avoid this.

The parent function doesn't always have the parentHandle function
parameter set because it can only be set after defining a function, not
when it is only declared.
2020-12-22 15:54:23 +01:00
Ayke van Laethem
6ad631539d compiler: fix undefined behavior in wordpack
Previously, EmitPointerPack would generate an out-of-bounds read from an
alloca. This commit fixes that by creating an alloca of the appropriate
size instead of using the size of the to-be-packed data (which might be
smaller than a pointer).

I discovered this error while working on a rewrite of the interp
package, which checks for out-of-bounds reads and writes. There I
discovered this issue when the image package was compiled.
2020-12-22 15:54:23 +01:00
Ayke van Laethem
cda5fffd98 nrf: use SPIM peripheral instead of the legacy SPI peripheral
This newer peripheral supports DMA (through EasyDMA) and should
generally be faster. Importantly for some operations: interrupts (within
255 byte buffers) will not interfere with the SPI transfer.
2020-12-22 14:41:06 +01:00
Ayke van Laethem
ce539ce583 nrf: refactor code a bit to reduce duplication
The nrf52 series is all very similar and copying the code only makes it
harder to maintain the code or to add more chips in the nrf52 series
(for example, the nrf52833 as used in the micro:bit v2).

This commit also has a small improvement regarding pins: it now includes
chip-level pin names (P0.00, P0.01, etc) to the machine package.
2020-12-22 14:41:06 +01:00
kenbell
43a31467d3
Nucleo f722ze (#1526)
machine/nucleo-f722ze: Add support for ST Micro NUCLEO-F722ZE
2020-12-15 06:51:35 +01:00
Ayke van Laethem
ae92ea149c esp32: enable the FPU
This allows working with float32 values, for example it allows
testdata/float.go to work correctly (assuming an Xtensa backend bug is
fixed, see https://github.com/espressif/llvm-project/issues/41).
2020-12-11 12:11:46 +01:00
Ayke van Laethem
4568de556e esp32: use the compiler-rt library for extra routines
These routines are necessary to compile testdata/float.go.
2020-12-11 12:11:46 +01:00
ardnew
7a4ccd916f
matrixportal-m4: Add support for board Adafruit Matrix Portal M4 (#1529)
machine/matrixportal-m4: add Adafruit Matrix Portal M4 board definition
2020-12-11 10:00:41 +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
Ayke van Laethem
bb27bbcb41 all: switch to LLVM 11 for static builds
This commit switches to LLVM 11 for builds with LLVM linked statically
(e.g. `make`). It does not yet switch the default for builds dynamically
linked to LLVM, that should be done in a later change.

This commit also changes to use the default host toolchain (probably
GCC) instead of Clang as the default compiler in CI. There were some
issues with Clang 3.8 in CI and hopefully this will fix it.

Additionally it updates the way LLVM is built on Windows, with
-DLLVM_ENABLE_PIC=OFF (which should have been used all along). This
change makes it possible to revert a hack to build libclang manually and
instead uses the libclang static library like on all other operating
systems, simplifying the Makefile.
2020-12-10 07:01:32 +01:00
deadprogram
9c2d2b662b build: remove release build job for arch release until it can be debugged
Signed-off-by: deadprogram <ron@hybridgroup.com>
2020-12-07 17:12:19 +01:00
Ayke van Laethem
098f900363 esp8266: implement task based scheduler
I have chosed to call this implementation `esp8266` instead of `xtensa`
as it has been written specifically for the ESP8266 and there are no
other Xtensa chips with the CALL0 ABI (no windowing) that I know of. The
only other related chip is the ESP32, which does implement register
windowing and thus needs a very different implementation.
2020-12-05 11:09:46 +01:00
Ayke van Laethem
caf35cfc41 esp32: implement task based scheduler
This has been a *lot* of work, trying to understand the Xtensa windowed
registers ABI. But in the end I managed to come up with a very simple
implementation that so far seems to work very well.

I tested this with both blinky examples (with blinky2 slightly edited)
and ./testdata/coroutines.go to verify that it actually works.
Most development happened on the ESP32 QEMU fork from Espressif
(https://github.com/espressif/qemu/wiki) but I also verified that it
works on a real ESP32.
2020-12-05 09:02:11 +01:00
Ayke van Laethem
abb09e869e runtime, internal/task: refactor to simplify stack switching
The Cortex-M target isn't much changed, but much of the logic for the
AVR stack switcher that was previously in assembly has now been moved to
Go to make it more maintainable and in fact smaller in code size. Three
functions (tinygo_getCurrentStackPointer, tinygo_switchToTask,
tinygo_switchToScheduler) have been changed to one: tinygo_swapTask.

This reduction in assembly code should make the code more maintainable
and should make it easier to port stack switching to other
architectures.

I've also moved the assembly files to src/internal/task, which seems
like a more appropriate location to me.
2020-12-05 09:02:11 +01:00
Ayke van Laethem
bb58783158 ci: switch to Go 1.15 for MacOS builds
Unfortunately, CircleCI doesn't seem to provide Debian stretch builds
with Go 1.15. We should be using Debian stretch (an older distro) to
make sure the tinygo binary runs on as many Linux systems as possible
(including older ones), and I think using Go 1.14 for these builds is
unfortunate but the better tradeoff.
2020-12-03 08:42:04 +01:00
fleshin
7abc67107d
sam: add support for the MKR1000 board 2020-12-03 00:33:23 +01:00
sago35
2540172cc5
atsam: add a length check to findPinPadMapping 2020-12-02 01:21:38 +01:00
sago35
0c4f0b1ebf version: update TinyGo version to 0.17.0-dev 2020-11-27 18:55:02 +01:00
Ayke van Laethem
15361c829e main: release 0.16.0 2020-11-17 11:15:15 +01:00
Ayke van Laethem
3f680b75f3 sam: remove redundant build tags
Some build tags were duplicated. This commit removes them.
2020-11-15 16:19:51 +01:00
Ayke van Laethem
9a7e633997 teensy36: add to smoketest
This required some changes to the UART code to get it to compile on Go
1.11.
2020-11-15 13:08:36 +01:00
ardnew
39b1f8b6f5 teensy40: UART: add missing godocs, rename Flush to Sync 2020-11-15 12:34:15 +01:00