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

673 коммитов

Автор SHA1 Сообщение Дата
Ayke van Laethem
6cacafb8dc
cgo: add package directory to header include paths 2018-12-10 15:38:03 +01:00
Ayke van Laethem
c6069476a7
cgo: do not rely on stdint.h to be available 2018-12-10 15:38:03 +01:00
Ayke van Laethem
0af7da9bff
cgo: add support for C.int, c.uint, etc 2018-12-10 15:38:02 +01:00
Ayke van Laethem
e8c1b5ab6e
cgo: add support for C typedefs 2018-12-10 15:38:02 +01:00
Ayke van Laethem
ecf6ffa62e
all: add bare-bones Cgo support 2018-12-10 15:38:02 +01:00
Ayke van Laethem
b99bbc880a
main: add support for testing complete packages, not just .go files 2018-12-10 15:38:02 +01:00
Ayke van Laethem
8ee3267260
wasm: compile .c files in packages 2018-12-10 15:38:02 +01:00
Ayke van Laethem
dea660b21c
main: compile C source files in packages
TODO: C++ etc. files
2018-12-10 15:38:01 +01:00
Ayke van Laethem
e10d05c74f
loader: switch to custom program loader 2018-12-10 15:36:23 +01:00
Ayke van Laethem
564b1b3312
compiler: always use fat function pointers with context
This reduces complexity in the compiler without affecting binary sizes
too much.

Cortex-M0:   no changes
Linux x64:   no changes
WebAssembly: some testcases (calls, coroutines, map) are slightly bigger
2018-12-09 18:47:39 +01:00
Ayke van Laethem
3fec22e819
compiler: avoid function pointers in defer calls
Implement defer in a different way, which results in smaller binaries.
The binary produced from testdata/calls.go (the only test case with
defer) is reduced a bit in size, but the savings in bytes greatly vary
by architecture:

Cortex-M0:    -96 .text / flash
WebAssembly: -215 entire file
Linux x64:    -32 .text

Deferred functions in TinyGo were implemented by creating a linked list
of struct objects that contain a function pointer to a thunk, a pointer
to the next object, and a list of parameters. When it was time to run
deferred functions, a helper runtime function called each function
pointer (the thunk) with the struct pointer as a parameter. This thunk
would then in turn extract the saved function parameter from the struct
and call the real function.

What this commit changes, is that the loop to call deferred functions is
moved into the end of the function (practically inlining it) and
replacing the thunks with direct calls inside this loop. This makes it
much easier for LLVM to perform all kinds of optimizations like inlining
and dead argument elimination.
2018-12-09 16:44:37 +01:00
Ayke van Laethem
e42289ce61
arm: add SVCAll with 0 arguments
Some very basic system calls may have no arguments at all.
2018-12-03 20:13:29 +01:00
Ayke van Laethem
9eaa6a7d7f
nrf: set interrupt priorities
The default priority is 0 (highest) which is reserved by the SoftDevice.
For normal operation the exact priority level doesn't matter, only the
relative priority matters. So this change makes the code compatible with
the SoftDevice without actually changing the behavior.
2018-12-03 13:50:41 +01:00
Ayke van Laethem
fa5b75464d
runtime/nrf: use RTC1 instead of RTC0
The SoftDevice reserves RTC0, so to be compatible use RTC1 instead.
2018-12-03 13:50:39 +01:00
Ayke van Laethem
99daa7b38f
arm: implement setting interrupt priorities 2018-12-03 13:50:38 +01:00
Ron Evans
7857c7235b machine/nrf52840: add support for ADC and PWM interfaces
Signed-off-by: Ron Evans <ron@hybridgroup.com>
2018-12-02 19:00:33 +01:00
Ron Evans
06ab3a836f
machine/nrf: SPI master implementation
Signed-off-by: Ron Evans <ron@hybridgroup.com>
2018-12-02 13:26:08 +01:00
Ayke van Laethem
23b283366d
compiler: add header comment to defer.go 2018-12-01 22:43:01 +01:00
Ayke van Laethem
69fbfbddbb
compiler: move defer code out of compiler.go
This puts all defer-related code into a single file, making it easier to
understand it.
2018-12-01 19:23:56 +01:00
Ayke van Laethem
b78562f95c
compiler: add names to some of the IR instructions
This makes debugging LLVM IR easier.
2018-12-01 18:36:05 +01:00
Justin Clift
cf9fc00ae4
all: add stub pieces for GoLand support
The bin/.keep file is just to ensure the bin directory is present,
whereas the zversion.go file is read by GoLand.
2018-12-01 18:32:34 +01:00
Ron Evans
8325f2a53d
reelboard: support Reel Board (nrf52840 dev board)
Signed-off-by: Ron Evans <ron@hybridgroup.com>
2018-12-01 18:25:36 +01:00
Ron Evans
8f35a4711a
pca10056: support this nrf52840-based board
Signed-off-by: Ron Evans <ron@hybridgroup.com>
2018-12-01 18:19:42 +01:00
Ron Evans
70830cd9da
tools: correct error generating board files that calculated the address incorrectly after a cluster type
Signed-off-by: Ron Evans <ron@hybridgroup.com>
2018-12-01 18:17:28 +01:00
Ayke van Laethem
e54a1c4dc0
compiler: disallow exporting functions that have their address taken
This simplifies the ABI a lot and makes future changes easier.
In the future, determining which functions need a context parameter
should be moved from IR generation into an optimization pass, avoiding
the need for recursively scanning the Go SSA.
2018-12-01 17:41:20 +01:00
Ayke van Laethem
da0a02d128
compiler: return error messages with source location
Replace most errors returned by the compiler (using errors.New) with an
error type that includes the source location.
2018-12-01 17:41:15 +01:00
Ayke van Laethem
7bdb606d4f
reflect: update type code type to uintptr
This type was missed after the recent interface updates.
2018-12-01 16:17:35 +01:00
Ayke van Laethem
469193735a
interp: report 'unreachable' instruction as an error
This instruction should never be hit in real programs, but the
interpreter may hit it after a call to panic(). This would always be a
runtime error.
2018-12-01 16:16:59 +01:00
Darren Rush
cea0a5977a
docs: enable tinygo/docker to resolve go dependencies
Example for mapping the GOPATH into the tinygo docker image so that go
dependencies installed on the host can be found by the image.
2018-12-01 13:40:42 +01:00
Ayke van Laethem
b4c90f3677
compiler: lower interfaces in a separate pass
This commit changes many things:

  * Most interface-related operations are moved into an optimization
    pass for more modularity. IR construction creates pseudo-calls which
    are lowered in this pass.
  * Type codes are assigned in this interface lowering pass, after DCE.
  * Type codes are sorted by usage: types more often used in type
    asserts are assigned lower numbers to ease jump table construction
    during machine code generation.
  * Interface assertions are optimized: they are replaced by constant
    false, comparison against a constant, or a typeswitch with only
    concrete types in the general case.
  * Interface calls are replaced with unreachable, direct calls, or a
    concrete type switch with direct calls depending on the number of
    implementing types. This hopefully makes some interface patterns
    zero-cost.

These changes lead to a ~0.5K reduction in code size on Cortex-M for
testdata/interface.go. It appears that a major cause for this is the
replacement of function pointers with direct calls, which are far more
susceptible to optimization. Also, not having a fixed global array of
function pointers greatly helps dead code elimination.

This change also makes future optimizations easier, like optimizations
on interface value comparisons.
2018-12-01 13:26:06 +01:00
Ayke van Laethem
e45c4ac182
arm: set default GC to marksweep 2018-11-28 17:34:59 +01:00
Ayke van Laethem
e817bd38ec
main: configure default GC in target JSON file 2018-11-28 17:34:57 +01:00
Ayke van Laethem
05d70d288d
wasm: fix printing from Go code 2018-11-25 18:07:24 +01:00
Ayke van Laethem
f0fb1bd41a
compiler: fix binops on named types in struct fields 2018-11-24 22:13:01 +01:00
Ayke van Laethem
dbb3211485
wasm: add glue JS code
The file wasm_glue.js was copied from the Go wasm port and was modified,
most importantly to match the TinyGo calling convention.
2018-11-24 19:03:58 +01:00
Ayke van Laethem
242a1843d1
wasm: fix heap end address 2018-11-24 19:00:42 +01:00
Ayke van Laethem
e101937589
wasm: fix .json file after compiler updates 2018-11-24 18:36:44 +01:00
Ayke van Laethem
5c08eaf777
Dockerfile: remove arm-none-eabi-gcc dependency 2018-11-22 16:20:15 +01:00
Ayke van Laethem
44068ef396
travis: remove gcc dependency 2018-11-22 16:20:15 +01:00
Ayke van Laethem
62d74d8329
all: compile and link using clang, where possible 2018-11-22 16:20:10 +01:00
Ayke van Laethem
4a8ced590b
tools/gen-device-svd: generate .s files compatible with lld
The llvm linker expects some flags to line up in input sections mapped
to a particular output section, which the GNU linker ignored. Make sure
this flag is set in the input section, see:
https://svnweb.freebsd.org/base/stable/11/sys/arm/arm/locore-v4.S?r1=321049&r2=321048&pathrev=321049
2018-11-22 12:35:17 +01:00
Ayke van Laethem
d887d645f7
arm: implement SVCall
The SVCall function call is lowered to an inline "svc" instruction. The
first parameter *must* be a constant number.
2018-11-21 17:06:56 +01:00
Ron Evans
ce0ad1daa2
pca10031: add support for PCA10031 nrf51 wireless dongle
Signed-off-by: Ron Evans <ron@hybridgroup.com>
2018-11-21 10:36:36 +01:00
Ayke van Laethem
bf4a43ef04
machine/avr: implement raw GPIO access for bitbanged drivers 2018-11-20 21:04:43 +01:00
Ayke van Laethem
9392ef900d
avr: add support for the digispark
Blinking the on-board LED works. Nothing else has been tested yet.
2018-11-20 18:50:24 +01:00
Ayke van Laethem
a96e2879b2
avr: make stack size configurable 2018-11-20 18:20:24 +01:00
Ayke van Laethem
760bc5d0a4
targets: let specific targets inherit more general targets
This avoids a ton of duplication and makes it easier to change a generic
target (for example, the "cortex-m" target) for all boards that use it.

Also, by making it possible to inherit properties from a parent target
specification, it is easier to support out-of-tree boards that don't
have to be updated so often. A target specification for a
special-purpose board can simply inherit the specification of a
supported chip and override the properites it needs to override (like
the programming interface).
2018-11-19 21:08:12 +01:00
Ayke van Laethem
f02766265c
targets: make compiler runtime selection more configurable 2018-11-19 20:17:42 +01:00
Ayke van Laethem
74b5e28a38
docs: add documentation for the -gc compiler flag 2018-11-18 19:32:57 +01:00
Ayke van Laethem
8402e84b6d
runtime: implement a simple mark/sweep garbage collector 2018-11-18 19:18:39 +01:00