aboutsummaryrefslogtreecommitdiffhomepage
AgeCommit message (Collapse)Author
2021-04-24builder: fixed a problem with multiple process build casesbitcode-pathsago35
2021-04-23machine/usbcdc: remove remaining heap allocations for USB CDC implementationsdeadprogram
Signed-off-by: deadprogram <[email protected]>
2021-04-23machine: avoid heap allocations in USB codeAyke van Laethem
This commit replaces most heap allocations in USB related code with stack allocations. This is important for several reasons: - It avoids running the GC unnecessarily. - It reduces code size by 400-464 bytes. - USB code might be called from interrupt handlers. The heap may be in an inconsistent state when that happens if main thread code also performs heap allocations. The last one is by far the most important one: not doing heap allocations in interrupts is critical for correctness. But the code size reduction alone should be worth it. There are two heap allocations in USB related code left: in the function receiveUSBControlPacket (SAMD21 and SAMD51). This heap allocation must also be removed because it runs in an interrupt, but I've left that for a future change.
2021-04-22copiler: add function attributes to some runtime callsAyke van Laethem
This allows better escape analysis even without being able to see the entire program. This makes the stack allocation test case more complete but probably won't have much of an effect outside of that (as the compiler is able to infer these attributes in the whole-program functionattrs pass).
2021-04-22main: add -print-allocs flag that lets you print all heap allocationsAyke van Laethem
This flag, if set, is a regexp for function names. If there are heap allocations in the matching function names, these heap allocations will be printed with an explanation why the heap allocation exists (and why the object can't be stack allocated).
2021-04-22transform: move tests to transform_test packageAyke van Laethem
This allows for adding more advanced tests, for example tests that use the compiler package so that test sources can be written in Go instead of LLVM IR.
2021-04-21stm32: support SPI on L4 seriesKenneth Bell
2021-04-21atsamd51: fix PWM support in atsamd51p20sago35
This change is related to the following commit 72acda22b0a8d137405e41e9ed54cbfbcce7b26f
2021-04-21runtime: implement command line arguments in hosted environmentsAyke van Laethem
Implement command line arguments for Linux, MacOS and WASI.
2021-04-21runtime: implement environment variables for LinuxAyke van Laethem
2021-04-21interp: remove map supportAyke van Laethem
The interp package is in many cases able to execute map functions in the runtime directly. This is probably slower than adding special support for them in the interp package and also doesn't cover all cases (most importantly, map keys that contain pointers) but removing this code also removes a large amount of code that needs to be maintained and is susceptible to hard-to-find bugs. As a side effect, this resulted in different output of the testdata/map.go test because the test relied on the existing iteration order of TinyGo maps. I've updated the test to not rely on this test, making the output compatible with what the Go toolchain would output.
2021-04-21interp: fix phi instructionAyke van Laethem
I've discovered a bug in the implementation of the PHI instruction in the interp package. This commit fixes the bug. I've found this issue while investigating an issue with maps after running interp per package.
2021-04-19ci: improve llvm-build cachesago35
2021-04-19builder: hard code Clang compilerAyke van Laethem
At the moment, all targets use the Clang compiler to compile C and assembly files. There is no good reason to make this configurable anymore and in fact it will make future changes more complicated (and thus more likely to have bugs). Therefore, I've removed support for setting the compiler. Note that the same is not true for the linker. While it makes sense to standardize on the Clang compiler (because if Clang doesn't support a target, TinyGo is unlikely to support it either), linkers will remain configurable for the foreseeable future. One example is Xtensa, which is supported by the Xtensa LLVM fork but doesn't have support in ld.lld yet. I've also fixed a bug in compileAndCacheCFile: it wasn't using the right CFlags for caching purposes. This could lead to using stale caches. This commit fixes that too.
2021-04-19ci: improve llvm-source cachesago35
2021-04-17Make fmt-check happy againDan Kegel
2021-04-16atsame51: add initial support for feather-m4-cansago35
2021-04-16PWM Support for atmega1280developer
Add arduino mega 1280 PWM test
2021-04-15add goroot for snap installsTobias Theel
2021-04-15atsame54: add initial support for atsame54-xprosago35
2021-04-15wasm: use WASI ABI for exit functionAyke van Laethem
This improves compatibility between the regular browser target (-target=wasm) and the WASI target (-target=wasi). Specifically, it allows running WASI tests like this: tinygo test -target=wasi encoding/base32
2021-04-15cortexm: add __isr_vector symbolAyke van Laethem
This doesn't change the firmware, but it does make the disassembly of the ELF files. Before: Disassembly of section .text: 00000000 <(machine.UART).Write-0x100>: 0: 20001000 .word 0x20001000 4: 000009db .word 0x000009db 8: 00000f05 .word 0x00000f05 c: 00000f0b .word 0x00000f0b 10: 00000f05 .word 0x00000f05 After: Disassembly of section .text: 00000000 <__isr_vector>: 0: 20001000 .word 0x20001000 4: 000009db .word 0x000009db 8: 00000f05 .word 0x00000f05 c: 00000f0b .word 0x00000f0b 10: 00000f05 .word 0x00000f05 The difference is that the disassembler will now use a proper symbol name instead of using the closest by symbol (in this case, (machine.UART).Write). This makes the disassembly easier to read.
2021-04-14nrf52833: add PWM supportAyke van Laethem
This chip wasn't included in the PR for PWM support. Adding this support is very easy, luckily.
2021-04-14microbit-v2: add support for S113 SoftDeviceAyke van Laethem
This currently doesn't work with `tinygo flash` yet (even with `-programmer=openocd`), you can use pyocd instead. For example, from the Bluetooth package: tinygo build -o test.hex -target=microbit-v2-s113v7 ./examples/advertisement/ pyocd flash --target=nrf52 test.hex I intend to add support for pyocd to work around this issue, so that a simple `tinygo flash` suffices.
2021-04-14microbit: remove LED constantAyke van Laethem
There doesn't appear to be a user-controllable LED outside of the LED matrix. In fact, the pin assigned for this was P13, which was connected to the SPI SCK pin.
2021-04-14all: clean up Cortex-M target filesAyke van Laethem
In this commit I've moved all core-specific flags to files for that specific core. This is a bit of a cleanup (less duplicated JSON) but should also help in the future when core-specific changes are made, such as core specific build tags or when the FPU finally gets supported in TinyGo. Some notable specific changes: - I've removed floating point flags from the Teensy 3.6 target. The reason is that the FPU is not yet supported in TinyGo (in goroutine stack switching for example) and floating point numbers would only be supported by C files, not Go files (because the LLVM FPU feature flags aren't used). This would create an ABI mismatch across CGo. - I've added the "cpu":"cortex-m7" to the cortex-m7.json file to match the configuration for the Teensy 4.0. This implies a change to the nucleo-f722ze (because now it has its CPU field set). Somehow that reduces the code size, so it looks like a good change. I don't believe any of these changes should have any practical consequences. One issue I've found is in the Cortex-M33 target: it uses armv7m, which is incorrect: it should be armv8m. But the chip is backwards compatible so this should mostly work. Switching to armv8m led to a compilation failure because PRIMASK isn't defined, this may be an actual bug.
2021-04-14all: use -Qunused-arguments only for assembly filesAyke van Laethem
The -Qunused-arguments flag disables the warning where some flags are not relevant to a compilation. This commonly happens when compiling assembly files (.s or .S files) because some flags are specific to C and not relevant to assembly. Because practically all baremetal targets need some form of assembly, this flag is added to most CFlags. This creates a lot of noise. And it is also added for compiling C code where it might hide bugs (by hiding the fact a flag is actually unused). This commit adds the flag to all assembly compilations and removes them from all target JSON files.
2021-04-14cmsis-svd: add svd file for the atsame5xsago35
2021-04-13Fix RGBA color interpretation for GameBoyAdvanceAgurato
2021-04-13stm32: make SPI CLK fast to fix data issueKenneth Bell
See "STM32F40x and STM32F41x Errata sheet" - SPI CLK port must be 'fast' or 'very fast' to avoid data corruption on last bit (at the APB clocks we configure).
2021-04-12reflect: implement New functionAyke van Laethem
This is very important for some use cases, for example for Vecty.
2021-04-12compiler: decouple func lowering from interface type codesAyke van Laethem
There is no good reason for func values to refer to interface type codes. The only thing they need is a stable identifier for function signatures, which is easily created as a new kind of globals. Decoupling makes it easier to change interface related code.
2021-04-12compiler: add func testsAyke van Laethem
This is basically just a golden test for the "switch" style of func lowering. The next commit will make changes to this lowering, which will be visible in the test output.
2021-04-12Arduino Mega 1280 supportdeveloper
Fix ldflags Update targets/arduino-mega1280.json Co-authored-by: Ayke <[email protected]> Update atmega1280.json Update Makefile
2021-04-12transform: do not lower zero-sized alloc to allocaAyke van Laethem
The LLVM CoroFrame pass appears to be tripping over this zero-sized alloca. Therefore, do what the runtime would do: return a pointer to runtime.zeroSizedAlloc. Or just don't deal with this case. But don't emit a zero sized alloca to avoid this LLVM bug. More information: https://bugs.llvm.org/show_bug.cgi?id=49916
2021-04-12transform: fix func lowering assertion failureAyke van Laethem
The func-lowering pass has started to fail in the dev branch, probably as a result of replacing the ConstPropagation pass with the IPSCCP pass. This commit makes the code a bit more robust and should be able to handle all possible cases (not just ptrtoint).
2021-04-09main: implement -ldflags="-X ..."Ayke van Laethem
This commit implements replacing some global variables with a different value, if the global variable has no initializer. For example, if you have: package main var version string you can replace the value with -ldflags="-X main.version=0.2". Right now it only works for uninitialized globals. The Go tooling also supports initialized globals (var version = "<undefined>") but that is a bit hard to combine with how initialized globals are currently implemented. The current implementation still allows caching package IR files while making sure the values don't end up in the build cache. This means compiling a program multiple times with different values will use the cached package each time, inserting the string value only late in the build process. Fixes #1045
2021-04-09main: add tests for less common build configurationsAyke van Laethem
Don't run the entire test suite for these options, as that would quickly explode the testing time (making it less likely people actually run it). Instead, run just one test for each configuration that should check for most issues.
2021-04-09main: clean up testsAyke van Laethem
- Explicitly list all test cases. This makes it possible to store tests in testdata/ that aren't tested on all platforms. - Clean up filesystem and env test, by running them in a subtest and deduplicating some code and removing the additionalArgs parameter.
2021-04-09main: remove -cflags and -ldflags flagsAyke van Laethem
These are unnecessary now that they are supported in CGo.
2021-04-09compiler: check for errorsAyke van Laethem
Some errors were generated but never returned or never checked in the test function. That's a problem. Therefore this commit fixes this oversight (by me).
2021-04-08transform: use IPSCCP pass instead of the constant propagation passAyke van Laethem
The constant propagation pass is removed in LLVM 12, so this pass needs to be replaced anyway. The direct replacement would be the SCCP (sparse conditional constant propagation) pass, but perhaps a better replacement is the IPSCCP pass, which is an interprocedural version of the SCCP pass and propagates constants across function calls if possible. This is not always a code size reduction, but it appears to reduce code size in a majority of cases. It certainly reduces code size in almost all WebAssembly tests I did.
2021-04-08builder: run function passes per packageAyke van Laethem
This should result in a small compile time reduction for incremental builds, somewhere around 5-9%. This commit, while small, required many previous commits to not regress binary size. Right now binary size is basically identical with very few changes in size (the only baremetal program that changed in size did so with a 4 byte increase). This commit is one extra step towards doing as much work as possible in the parallel and cached package build step, out of the serial LTO phase. Later improvements in this area have this change as a prerequisite.
2021-04-08interp: add support for switch statementAyke van Laethem
A switch statement is not normally emitted by the compiler package, but LLVM function passes may convert a series of if/else pairs to a switch statement. A future change will run function passes in the package compile phase, so the interp package (which is also run after all modules are merged together) will need to deal with these new switch statements.
2021-04-08compiler: optimize string literals and globalsAyke van Laethem
This commit optimizes string literals and globals by setting the appropriate alignment and using a nil pointer in zero-length strings. - Setting the alignment for string values has a surprisingly large effect, up to around 2% in binary size. I suspect that LLVM will pick some default alignment for larger byte arrays if no alignment has been specified and forcing an alignment of 1 will pack all strings closer together. - Using nil for zero-length strings also has a positive effect, but I'm not sure why. Perhaps it makes some optimizations more trivial. - Always setting the alignment on globals improves code size slightly, probably for the same reasons setting the alignment of string literals improves code size. The effect is much smaller, however. This commit might have an effect on performance, but if it does this should be tested separately and such a large win in binary size should definitely not be ignored for small embedded systems.
2021-04-08transform: don't rely on struct name of runtime.typecodeIDAyke van Laethem
Sometimes, LLVM may rename named structs when merging modules. Therefore, we can't rely on typecodeID structs to retain their struct names. This commit changes the interface lowering pass to not rely on these names. The interp package does however still rely on this name, but I hope to fix that in the future.
2021-04-08builder: add optsize attribute while building the packageAyke van Laethem
This simplifies future changes. While the move itself is very simple, it required some other changes to a few transforms that create new functions to add the optsize attribute manually. It also required abstracting away the optimization level flags (based on the -opt flag) so that it can easily be retrieved from the config object. This commit does not impact binary size on baremetal and WebAssembly. I've seen a few tests on linux/amd64 grow slightly in size, but I'm not too worried about those.
2021-04-08build: improve error messages in getDefaultPort(), support for multiple portssago35
2021-04-07modules: add latest go-llvm because seems like older SHA is missing?deadprogram
Signed-off-by: deadprogram <[email protected]>
2021-04-07stm32: add nucleo-l031k6 supportKenneth Bell
Adds i2c for all L0 series UART, Blinky (LED) and i2c tested