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

38 коммитов

Автор SHA1 Сообщение Дата
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
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
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
Jaden Weiss
2501602b4f ir: add descriptive error messages to SimpleDCE pass
This commit modifies the SimpleDCE pass to emit errors similar to those emitted by gc when the main function is missing.
2020-03-28 20:52:53 +01:00
Jaden Weiss
6a50f25a48 refactor coroutine lowering and tasks 2020-03-17 12:16:10 +01:00
Ayke van Laethem
a5ed993f8d all: add compiler support for interrupts
This commit lets the compiler know about interrupts and allows
optimizations to be performed based on that: interrupts are eliminated
when they appear to be unused in a program. This is done with a new
pseudo-call (runtime/interrupt.New) that is treated specially by the
compiler.
2020-01-20 21:19:12 +01:00
Jaden Weiss
7732c6f449 fix bug in IR regarding type aliases 2019-09-20 10:35:49 +02:00
Phil Kedy
55144ad608 WASM: Support for setting an imported function's module name (#455)
* wasm: add support for setting a function's Wasm import module name by using the //go:wasm-module comment.
2019-09-12 08:35:43 +02:00
Ayke van Laethem
7ed6b45149 compiler: add the //go:noinline pragma
This is directly useful to avoid some unsafety around runtime.alloc and
should be useful in general.

This pragma has the same form as in the main Go compiler:
https://github.com/golang/go/issues/12312
2019-07-08 00:02:28 +02:00
Ayke van Laethem
b0e767c4a7 compiler: move global handling from ir to compiler package
This is part of a larger rafactor that tries to shrink the ir package
and in general tries to shrink the amount of state that is kept around
in the compiler. The end goal is being able to compile packages
independent of each other, linking them together in a later stage. Along
the way, it cleans up lots of old cruft that has accumulated over the
months.

This refactor also results in globals being loaded lazily. This may be a
problem for some specific programs but will probably change back in a
commit in the near future.
2019-06-08 22:17:09 +02:00
Ayke van Laethem
6b5b4a681d compiler: refactor named types to create them lazily
This commit refactors named types to be created lazily. Instead of
defining all types in advance, do it only when necessary.
2019-06-08 22:17:09 +02:00
Ayke van Laethem
5cf7fba1a4 compiler: remove //go:volatile support 2019-06-06 19:46:49 +02:00
Ayke van Laethem
6f6afb0515 compiler: add //go:inline pragma 2019-05-14 12:24:01 +02:00
Justin Clift
064d001550 Trivial typo fixes 2019-05-13 17:11:19 +02:00
Ayke van Laethem
856e5fa179 ir: remove old cgo related code
There is now a custom implementation of CGo based on libclang.
2019-02-19 09:08:13 +01:00
Ayke van Laethem
92d9b780b5 all: remove init interpretation during IR construction
The interp package does a much better job at interpretation, and is
implemented as a pass on the IR which makes it much easier to compose.
Also, the implementation works much better as it is based on LLVM IR
instead of Go SSA.
2019-02-19 09:08:13 +01:00
Ayke van Laethem
95d895646a
loader/cgo: add support for function pointers 2019-02-08 13:19:02 +01:00
Ayke
01f6aff422 loader: support global variables in CGo (#173)
Global variables (like functions) must be declared in the import "C" preamble and can then be used from Go.
2019-02-08 13:04:03 +01:00
Ayke van Laethem
6360e318a7 runtime: add support for math package
The math package uses routines written in Go assembly language which
LLVM/Clang cannot parse. Additionally, not all instruction sets are
supported.

Redirect all math functions written in assembly to their Go equivalent.
This is not the fastest option, but it gets packages requiring math
functions to work.
2019-02-05 19:37:21 +01:00
Ayke van Laethem
914d383a96
all: update import paths to github.com/tinygo-org/tinygo 2019-01-31 17:43:19 +01:00
Ayke van Laethem
1db9a162da
all: go fmt
The import path changes changed the order of imports, but no `go fmt`
was run before the commit. Oops...
2019-01-31 16:22:05 +01:00
Ayke van Laethem
9092dbcc53
all: rename go-llvm to new import path
the new import path is:

    tinygo.org/x/go-llvm
2019-01-27 19:26:16 +01:00
Ayke van Laethem
602c264749
all: rewrite goroutine lowering
Before this commit, goroutine support was spread through the compiler.
This commit changes this support, so that the compiler itself only
generates simple intrinsics and leaves the real support to a compiler
pass that runs as one of the TinyGo-specific optimization passes.

The biggest change, that was done together with the rewrite, was support
for goroutines in WebAssembly for JavaScript. The challenge in
JavaScript is that in general no blocking operations are allowed, which
means that programs that call time.Sleep() but do not start goroutines
also have to be scheduled by the scheduler.
2019-01-21 22:09:33 +01:00
Ayke van Laethem
ecf6ffa62e
all: add bare-bones Cgo support 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
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
1b283c11c1
ir: do not throw an error on unknown conversions 2018-10-31 10:19:25 +01:00
Ayke van Laethem
dda9c1cc6e
ir: fix interface call edge case
A function on a type that is put in an interface must not be assumed to
not need a context pointer when it isn't directly put in a function
pointer, because the interface call side won't know this and pass an
extra parameter with that extra function pointer.

This is usually not a problem but WebAssembly has strict checks on
function signatures so this resulted in an error when running
src/examples/test/test.go.
2018-10-21 01:33:40 +02:00
Ayke van Laethem
f107a24b72
all: use LLVM library provided by the system 2018-09-30 15:10:04 +02:00
Ayke van Laethem
318567f398
ir: fix nil pointer dereference in IsVolatile 2018-09-29 00:11:05 +02:00
Ayke van Laethem
8d170d3bd2
all: change special type __volatile to pragma //go:volatile
This is one step towards removing unnecessary special casts in most
cases. It is also part of removing as much magic as possible from the
compiler (the pragma is explicit, the special name is not).
2018-09-28 13:17:03 +02:00
Ayke van Laethem
13cb7d6503
avr: add interrupt support
Interrupts are supported using a special //go:interrupt pragma.
For example:

//go:interrupt INT0_vect
func handleINT0() {
    // do something here
}
2018-09-25 13:47:20 +02:00
Ayke van Laethem
1b229a8f8b
compiler: support compiling individual .go files
For example:

    tinygo run ./src/examples/test/test.go
2018-09-24 15:46:30 +02:00
Ayke van Laethem
a561e9a9ac
ir: move adding packages from the compiler 2018-09-24 15:46:30 +02:00
Ayke van Laethem
453450f40d
ir: sort function pragmas 2018-09-23 23:30:13 +02:00
Ayke van Laethem
b75a02e66d
compiler: refactor IR parts into separate package 2018-09-22 20:32:07 +02:00