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

119 коммитов

Автор SHA1 Сообщение Дата
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
95e18f36d0
main: compile and run a program directly
Do not try to use the ExectutionEngine of Go, instead compile the
program in the conventional way and run the binary.

This fixes some code duplication that causes slight (but problematic)
misbehavior between `tinygo build` and `tinygo run`.
2019-01-16 17:06:34 +01:00
Ayke
107fccb288 all: add support for more architectures and GOOS/GOARCH (#118)
This commit does two things:

  * It adds support for the GOOS and GOARCH environment variables. They
    fall back to runtime.GO* only when not available.
  * It adds support for 3 new architectures: 386, arm, and arm64. For
    now, this is Linux-only.
2019-01-05 11:46:25 +01:00
Ayke
873c1c3b4d Reduce code size for AVR (#116)
* all: add support for specifying target CPU in target config
* avr: specify the chip name in the target CPU

This reduces code size by a large margin. For examples/blinky, it
reduces code size from 1360 to 1266 when compiling for the Arduino Uno
(94 bytes, or ~7%).
2019-01-04 14:58:35 +01:00
Konstantin Yegupov
a8dd82538e
all: add flag to enable i64 parameters in WebAssembly 2019-01-03 18:09:33 +01:00
Ron Evans
cb648d8ae1
compiler: pass -cflags and -ldflags to tinygo CLI command
Signed-off-by: Ron Evans <ron@hybridgroup.com>
2018-12-13 20:10:27 +01:00
Ayke van Laethem
6cacafb8dc
cgo: add package directory to header include paths 2018-12-10 15:38:03 +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
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
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
e817bd38ec
main: configure default GC in target JSON file 2018-11-28 17:34:57 +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
f02766265c
targets: make compiler runtime selection more configurable 2018-11-19 20:17:42 +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
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
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
101d41dc58
compiler: pass i64 return value in an extra pointer param
To support the WebAssembly<->JS barrier, return values also have to be
passed in memory. i64 return values are used by syscall/js, so must be
supported across this ABI barrier.
2018-11-14 12:35:43 +01:00
Ayke van Laethem
3d0ccb81c6
main: fix -initinterp flag
It got accidentally replaced by -interp just before finalizing the
previous commit.
2018-11-05 13:11:15 +01:00
Ayke van Laethem
bb3d05169d
interp: add new compile-time package initialization interpreter
This interpreter currently complements the Go SSA level interpreter. It
may stay complementary or may be the only interpreter in the future.

This interpreter is experimental and not yet finished (there are known
bugs!) so it is disabled by default. It can be enabled by passing the
-initinterp flag.

The goal is to be able to run all initializations at compile time except
for the ones having side effects. This mostly works except perhaps for a
few edge cases.

In the future, this interpeter may be used to actually run regular Go
code, perhaps in a shell.
2018-11-04 18:40:51 +01:00
Ayke van Laethem
3823870d07
main: print IR even when verification failed 2018-11-03 18:26:46 +01:00
Ayke van Laethem
60eefe1568
compiler: do not abort on verification failure 2018-11-03 18:24:57 +01:00
Ayke van Laethem
2e22d53e5d
compiler: work around i64 limitation in JavaScript
JavaScript does not support i64 directly, so make sure we pass a pointer
instead which can be read from JavaScript.

This is a temporary workaround which should be removed once JavaScript
supports some form of i64 (probably in the form of BigInt).
2018-11-03 12:03:49 +01:00
Ayke van Laethem
4e4f91bea7
main: cleanup printing of IR
Panics don't usually happen nowadays, instead the compiler package
returns errors while compiling. If it still panics, this is usually from
within LLVM from where deferred functions are not run.
2018-10-31 10:10:49 +01:00
Marc-Antoine Ruel
a3d87456cd tinygo: add 'tinygo' build tag
This enables project to conditionally skip code that can't compile on tinygo.
2018-10-27 16:44:10 -04:00
Ayke van Laethem
c84fc6a670
main: gofmt 2018-10-26 23:31:27 +02:00
Ayke van Laethem
97d4558d81
main: update help text with new subcommands 2018-10-25 20:36:11 +02:00
Ayke van Laethem
980dceb192
main: refactor build option passing
The list of options passed to build/run/gdb/etc commands was getting
unwieldly and hard to add extra options to. Put all common build options
in a single build config struct so that these options are more
centralized.
2018-10-24 23:53:44 +02:00
Ayke van Laethem
e5e09747f0
all: add WebAssembly backend 2018-10-21 19:47:47 +02:00
Ayke van Laethem
9406a4d74a
main: add -opt= flag for the optimization level 2018-10-10 14:14:45 +02:00
Ayke van Laethem
a63af97e86
all: add emulation support for Cortex-M3 with QEMU 2018-10-08 17:07:19 +02:00
Ayke van Laethem
e50c6f1af1
main: generate binary files when compiling to .bin 2018-10-07 22:48:33 +02:00
Ayke van Laethem
22da104530
all: use compiler-rt for builtins 2018-10-07 19:04:29 +02:00
Ayke van Laethem
9d408b7cbc
main: hide OCD output by default in gdb subcommand
In most cases, it's useless. But in some cases it may be critical if the
OCD server (like openocd) has a problem.

It would be nice if openocd would differentiate between stdout and
stderr, and only write errors to stderr. But sadly it doesn't.
2018-10-03 19:33:36 +02:00
Ayke van Laethem
b08c8a0cf0
all: implement gdb sub-command for easy debugging 2018-10-03 19:03:22 +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
802350f8da
main: helpful error message for flash cmd without -target 2018-09-29 22:39:44 +02:00
Ayke van Laethem
b6db84e916
main: use GOPATH from the environment
Be more compatible with the Go toolchain by setting GOPATH in the same
way. This makes it possible to flash and run examples from the standard
GOPATH instead of only from the source tree.
2018-09-29 22:30:45 +02:00
Ayke van Laethem
0e813c4cb7
main: add -no-debug flag to avoid DWARF debug info 2018-09-25 20:17:46 +02:00
Ayke van Laethem
ed227b8fd3
all: fix errors reported by go vet 2018-09-24 17:22:59 +02:00
Ayke van Laethem
a2eaaa42a0
main: optimize 'tinygo run'
Apparently -Oz without inliner is the fastest, probably because it
removes code that would otherwise need to be emitted.

TODO: does this mean that the ExecutionEngine compiles the module before
running it? Can we control this?
2018-09-24 16:22:09 +02:00
Ayke van Laethem
6191d4e1ac
compiler: rename .Parse() to .Compiler()
The fact it was called Parse() is more of a historical accident, as the
compiler started out using the Go AST directly instead of Go SSA.
2018-09-24 15:55:38 +02:00
Ayke van Laethem
8a468786df
compiler: use config struct for options 2018-09-24 15:46:05 +02:00
Ayke van Laethem
fd6dda5e4f
main: run the compiler from any path 2018-09-24 12:25:33 +02:00
Ayke van Laethem
b2cbfa78ca
compiler: refactor compiler into separate package 2018-09-22 20:32:28 +02:00
Ayke van Laethem
895d109fc4
compiler: run flash command in a shell 2018-09-22 01:40:46 +02:00
Ayke van Laethem
87963d3d5b
compiler: add -size flag to replace size utility
The size flag has two modes:
  -size=short: prints data basically equivalent to the `size` program.
  -size=full:  tries to determine sizes per package (not entirely
               accurate).
2018-09-18 00:04:21 +02:00