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

27 коммитов

Автор SHA1 Сообщение Дата
Ayke van Laethem
1d7543e2bf all: switch to LLVM 16
This commit adds support for LLVM 16 and switches to it by default. That
means three LLVM versions are supported at the same time: LLVM 14, 15,
and 16.

This commit includes work by QuLogic:

  * Part of this work was based on a PR by QuLogic:
    https://github.com/tinygo-org/tinygo/pull/3649
    But I also had parts of this already implemented in an old branch I
    already made for LLVM 16.
  * QuLogic also provided a CGo fix here, which is also incorporated in
    this commit:
    https://github.com/tinygo-org/tinygo/pull/3869

The difference with the original PR by QuLogic is that this commit is
more complete:
  * It switches to LLVM 16 by default.
  * It updates some things to also make it work with a self-built LLVM.
  * It fixes the CGo bug in a slightly different way, and also fixes
    another one not included in the original PR.
  * It does not keep compiler tests passing on older LLVM versions. I
    have found this to be quite burdensome and therefore don't generally
    do this - the smoke tests should hopefully catch most regressions.
2023-09-18 21:58:02 +02:00
Ayke van Laethem
0d646d8e95 builder: add support for Go 1.20
Not all features work yet, but allow it to compile with this Go version.
2023-01-17 08:38:54 +01:00
Ayke van Laethem
636a151ffe cgo: add support for C.float and C.double
They are not necessary in TinyGo because they always map to float32 and
float64, but it's a good idea to add them regardless for compatibility
with existing software.

(Now I think about it, perhaps it would have been better to require
explicit casts here just in case we want to support some really weird C
system, but then again we even force 64-bit double on AVR even though
avr-gcc defaults to 32-bit double).
2022-10-13 17:13:12 +02:00
Ayke van Laethem
5551ec7a1e cgo: implement support for static functions 2022-09-16 14:05:17 +02:00
Ayke van Laethem
5afb63df60 cgo: refactor
This is a large refactor of the cgo package. It should fix a number of
smaller problems and be a bit more strict (like upstream CGo): it for
example requires every Go file in a package to include the header files
it needs instead of piggybacking on imports in earlier files.

The main benefit is that it should be a bit more maintainable and easier
to add new features in the future (like static functions).

This breaks the tinygo.org/x/bluetooth package, which should be updated
before this change lands.
2022-05-06 17:22:22 +02:00
Ayke van Laethem
c31aef06ba cgo: add support for C.CString and related functions 2021-11-24 21:09:29 +01:00
Ayke van Laethem
1789570f52 cgo: add //go: pragmas to generated functions and globals
This patch adds //go: pragmas directly to declared functions and
globals found during CGo processing. This simplifies the logic in the
compiler: it no longer has to consider special "C." prefixed function
names. It also makes the cgo pass more flexible in the pragmas it emits
for functions and global variables.
2021-11-24 21:09:29 +01:00
Ayke van Laethem
cceb655874 cgo: run CGo parser for all CGo fragments in a file
Previously, libclang was run on each fragment (import "C") separately.
However, in regular Go it's possible for later fragments to refer to
types in earlier fragments so they must have been parsed as one.

This commit changes the behavior to run only one C parser invocation for
each Go file.
2021-11-04 22:26:33 +01:00
Ayke van Laethem
138add2b96 cgo: fix line/column reporting in syntax error messages 2021-09-28 18:44:11 +02:00
Ayke van Laethem
e9f1ed701a cgo: don't normalize CGo tests anymore
Normalization was required because previously we supported Go 1.13 and
Go 1.14 at the same time. Now we've dropped support for both so this
normalization is not necessary anymore.

CGo support remains the same. It's just the test outputs that aren't
normalized anymore.
2021-09-09 13:28:50 +02:00
Ayke van Laethem
70f8eeaca0 cgo: parse binary operators
This follows the Pratt parser design.
2021-05-21 17:54:13 +02:00
Elliott Sales de Andrade
b689f14bb2 Add support for Go 1.16. 2021-02-19 23:46:55 +01:00
Ayke van Laethem
2e9c3a1d8d cgo: add support for variadic functions
This doesn't yet add support for actually making use of variadic
functions, but at least allows (unintended) variadic functions like the
following to work:

    void foo();
2021-02-11 09:51:15 +01:00
Lucas Teske
726d735ad3 cgo: Add LDFlags support 2020-05-21 00:57:19 +02:00
Elliott Sales de Andrade
343bb42644 cgo: normalize test results
This makes the result consistent across Go versions, by running a regex
on the CGo output that wraps all single-line functions in a consistent
way.

Originally written by Elliott Sales de Andrade and modified by Ayke van
Laethem.
2020-04-12 18:41:34 +02:00
Ayke van Laethem
a8da601672 cgo: make -I and -L paths absolute
This is very useful for (conditionally) adding extra include paths
relative to the package path.
2020-03-17 20:43:28 +01:00
Ayke van Laethem
d735df6e16 cgo: add support for symbols 2020-01-03 23:44:58 +01:00
Ayke van Laethem
10e1420237 cgo: implement #cgo CFLAGS
This implementation is still very limited but provides a base to build
upon. Limitations:

  * CGO_CFLAGS etc is not taken into account.
  * These CFLAGS are not used in C files compiled with the package.
  * Other flags (CPPFLAGS, LDFAGS, ...) are not yet implemented.
2019-11-25 09:32:03 +01:00
Ayke van Laethem
6a1bb134f9 cgo: add tests for errors
This commit adds tests for CGo preprocessing. There are various errors
that can be reported while preprocessing, and they should integrate well
with the compiler (including accurate source location tracking).

Also allow CGo preprocessing to continue after Clang encountered an
error, for a better view of what happened.
2019-11-25 09:32:03 +01:00
Ayke van Laethem
b153bd63f2 cgo: add support for nested structs and unions 2019-11-08 08:38:50 +01:00
Ayke van Laethem
6108ee6859 cgo: refactor union support
Instead of putting the magic in the AST, generate regular accessor
methods. This avoids a number of special cases in the compiler, and
avoids missing any of them.

The resulting union accesses are somewhat clunkier to use, but the
compiler implementation has far less coupling between the CGo
implementation and the IR generator.
2019-11-07 21:39:29 +01:00
Ayke van Laethem
76c9f13e13 cgo: include all enums in the CGo Go AST
Not all enums may be used as a type anywhere, which was previously the
only way to include an enum in the AST. This commit makes sure all enums
are included.
2019-11-06 17:46:20 +01:00
Ayke van Laethem
473576e756 cgo: do type checking in CGo testing
Such type checking should hopefully catch more bugs.

This commit also fixes some existing type errors.
2019-11-06 16:30:07 +01:00
Ayke van Laethem
913131bf62 cgo: avoid '"unsafe" imported but not used' error
This can happen when not all CGo features are used.
2019-11-06 16:30:07 +01:00
Ayke van Laethem
b41e58bcb4 cgo: rename reserved field names like type
This commit renames reserved field names like `type` to `_type`, and in
turn renames those fields as well (recursively). This avoids name
clashes when a C struct contains a field named `type`, which is a
reserved keyword in Go.

For some details, see:
https://golang.org/cmd/cgo/#hdr-Go_references_to_C
2019-11-06 15:54:18 +01:00
Ayke van Laethem
be7529b261 cgo: add tests for most C types 2019-11-03 19:15:38 +01:00
Ayke van Laethem
26bdfa9c84 cgo: add bare-bones test 2019-11-03 19:15:38 +01:00