Commit Graph

605 Commits

Author SHA1 Message Date
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
Ayke van Laethem dbf581b56d interp: do not try to interpret functions with an inttoptr instruction 2018-11-18 18:41:59 +01:00
Ayke van Laethem 27fc397e21 arm: implement arm.ReadRegister
This pseudo-function reads the contents of the specified register, for
example "sp".
2018-11-18 18:40:36 +01:00
Ayke van Laethem 8cb7b583d8 compiler: support creating slices with uncommon initial len/cap types 2018-11-18 18:35:29 +01:00
Ayke van Laethem 9181f2d4ce runtime: add "end of heap" to detect out of memory
This can be used in the future to trigger garbage collection. For now,
it provides a more useful error message in case the heap is completely
filled up.
2018-11-17 15:33:32 +01:00
Ayke van Laethem ef93001ab8 runtime: add "none" garbage collector
This collector does not implement runtime.alloc, so it is a
quick-and-dirty way to check where in a program memory is allocated.
2018-11-17 15:14:29 +01:00
Ayke van Laethem c220c140ef all: make garbage collector configurable 2018-11-17 15:14:05 +01:00
Ayke van Laethem ecb4742316 main: do not run legacy init interpreter with run subcommand
Do not run the new init interpreter either. Just run the code.
2018-11-17 14:48:48 +01:00
Ayke van Laethem 21db7e6099 main: move "tinygo" build tag to compiler
Replace "tgo" with "tinygo" and set it always (even with `tinygo run`).
2018-11-17 14:36:41 +01:00
Ayke van Laethem 15a4afb22a runtime: unify GC interface
Make sure every to-be-implemented GC can use the same interface. As a
result, a 1MB chunk of RAM is allocated on Unix systems on init instead
of allocating on demand.
2018-11-17 14:11:58 +01:00
Ayke van Laethem 4fdffdf8b2 interp: support non-const ptrtoint instruction 2018-11-17 14:09:18 +01:00
Ayke van Laethem c3c4a33b42 main: enable -initinterp by default
It can still be disabled using -initinterp=false.
2018-11-16 23:12:32 +01:00
Ayke van Laethem 1ba463c7ee machine: redesign I2C interface 2018-11-16 23:08:41 +01:00
Ayke van Laethem 100901574b compiler: let escape analysis look across bitcasts
This is necessary to avoid memory allocation in the math packages in
some functions.
2018-11-16 23:03:38 +01:00
Denys Smirnov 46755b774e compiler: fix another usage of the named type 2018-11-16 11:34:22 +01:00
Ayke van Laethem 1ed019771d compiler: set debug info when defining a function
Move attaching debug info to where the function is defined. As LLVM does
not allow setting debug info on declarations, this makes more sense and
is less error-prone.

This commit fixes debug info when using CGo.
2018-11-15 20:00:00 +01:00
Ron Evans ae3535945c all: add support to Dockerfile for AVR and ARM targets
Signed-off-by: Ron Evans <ron@hybridgroup.com>
2018-11-15 12:53:10 +01:00
Ayke van Laethem 668c1741c3 compiler: implement array equality
Implement binops == and != on array types.
2018-11-15 11:51:16 +01:00
Ayke van Laethem 6292a0fd2e compiler: fix bug in for range loop over a named map type 2018-11-14 15:43:50 +01:00