98 Commits

Author SHA1 Message Date
Evan Haas
c558a1ae26 translate-c: Implement generic selection expressions
Enables translation of C code that uses the `_Generic` keyword
2021-03-17 00:07:33 +02:00
Evan Haas
c760532be0 translate-c: Add compound literal support 2021-03-08 10:09:12 +02:00
Evan Haas
294ee1bbc9 translate-c: add limited OffsetOfExpr support
Add support for OffsetOfExpr that contain exactly 1 component, when that component
is a field.

For example, given:

```c
struct S {
  float f;
  double d;
};
struct T {
  long l;
  int i;
  struct S s[10];
};
```

Then:
```c
offsetof(struct T, i)       // supported
offsetof(struct T, s[2].d)  // not supported currently
```
2021-02-28 21:56:57 +02:00
Evan Haas
0816981561 translate-c: add typeof support 2021-02-25 22:33:42 -08:00
Veikka Tuominen
9a826ccbe0
translate-c: elide some unecessary casts of literals 2021-02-16 16:40:43 +02:00
Evan Haas
221f1d898c translate-c: Improve function pointer handling
Omit address-of operator if operand is a function.

Improve handling of function-call translation when using function pointers

Fixes #4124
2021-02-08 10:15:00 +02:00
Evan Haas
57b2176e28 translate-c: Improve array support
1. For incomplete arrays with initializer list (`int x[] = {1};`) use the
initializer size as the array size.

2. For arrays initialized with a string literal translate it as an array
of character literals instead of `[*c]const u8`

3. Don't crash if an empty initializer is used for an incomplete array.

4. Add a test for multi-character character constants

Additionally lay some groundwork for supporting wide string literals.

fixes #4831 #7832 #7842
2021-01-25 10:37:23 -08:00
Timon Kruiper
0ed04aac8b stage2: fix building self-hosted compiler with -Dstatic-llvm
This supersedes c81ae52ee0b2e952f8ed9c5c6517af8182bb09c1
2021-01-03 17:23:30 +01:00
Andrew Kelley
79a5151155 Revert "stage2: fix compilation of self-hosted compiler with -Denable-llvm"
This broke compiling with -Dstage1 on Windows, because it added the
cpp_source_files to the compilation multiple times.

This reverts commit c81ae52ee0b2e952f8ed9c5c6517af8182bb09c1.
2020-12-28 22:41:29 -08:00
Timon Kruiper
c81ae52ee0 stage2: fix compilation of self-hosted compiler with -Denable-llvm 2020-12-28 21:15:13 +01:00
Andrew Kelley
5a65caa2a3 ability to build stage1 using only a zig tarball
The main idea here is that there are now 2 ways to get a stage1 zig
binary:

 * The cmake path. Requirements: cmake, system C++ compiler, system
   LLVM, LLD, Clang libraries, compiled by the system C++ compiler.

 * The zig path. Requirements: a zig installation, system LLVM, LLD,
   Clang libraries, compiled by the zig installation.

Note that the former can be used to now take the latter path.

Removed config.h.in and config.zig.in. The build.zig script no longer is
coupled to the cmake script.

cmake no longer tries to determine the zig version. A build with cmake
will yield a stage1 zig binary that reports 0.0.0+zig0. This is going to
get reverted.

`zig build` now accepts `-Dstage1` which will build the stage1 compiler,
and put the stage2 backend behind a feature flag.

build.zig is simplified to only support the use case of enabling LLVM
support when the LLVM, LLD, and Clang libraries were built by zig. This
part is probably sadly going to have to get reverted to make package
maintainers happy.

Zig build system addBuildOption supports a couple new types.

The biggest reason to make this change is that the zig path is an
attractive option for doing compiler development work on Windows. It
allows people to work on the compiler without having MSVC installed,
using only a .zip file that contains Zig + LLVM/LLD/Clang libraries.
2020-12-07 17:27:09 -07:00
Andrew Kelley
e1ca6946be rename ZigClangFloatingLiteral_getValueAsApproximateDouble 2020-10-27 14:16:43 -07:00
Andrew Kelley
8b7539bd95 Merge remote-tracking branch 'origin/master' into llvm11
Conflicts:
  src/clang.zig

Master branch renamed an enum; this branch gave it an explicit tag type
and explicitly initialized values. This commit combines the changes
together.
2020-10-08 15:47:45 -07:00
Tadeo Kondrak
83eda21488 zig_clang/translate_c: Use opaque declarations in Zig 2020-10-08 12:29:59 +03:00
Andrew Kelley
7067764ed3 Merge remote-tracking branch 'origin/master' into llvm11
The changes to install_files.h needed to put into src/libcxx.zig
2020-09-30 02:55:41 -07:00
Andrew Kelley
afac5d2895 fix regressed stage2 test harness 2020-09-21 21:14:01 -07:00
Andrew Kelley
1de2c647df Merge remote-tracking branch 'origin/master' into llvm11 2020-08-18 15:32:42 -07:00
Vexu
cf5932b236
translate-c: convert int to bool if bool is expected 2020-08-11 12:24:45 +03:00
Andrew Kelley
c6e0df6213 Merge remote-tracking branch 'origin/master' into llvm11 2020-08-04 17:09:40 -07:00
Vexu
4ab2f947f9
translate-c: recognize other type trait expressions
Closes #5979
2020-08-04 00:48:29 +03:00
Andrew Kelley
c8ea8cf5df update LLVM C++ API wrappers from llvm 10 to 11 2020-07-24 16:49:57 -07:00
Andrew Kelley
41cb49eb58
stage1 fixes to support building with 32-bit mingw-w64 2020-04-06 20:30:34 -04:00
Andrew Kelley
e7f555ca55
stage1: fix build for i386-linux 2020-04-02 19:07:52 -04:00
Andrew Kelley
656ba530d8
Merge remote-tracking branch 'origin/master' into llvm10 2020-03-13 15:17:53 -04:00
Vexu
cb4c488cbd
translate-c support struct field alignment 2020-03-10 15:57:57 +02:00
Vexu
692a974c3e
translate-c reject structs with VLAs 2020-03-08 12:11:37 +02:00
Andrew Kelley
f33bf48af7
Merge remote-tracking branch 'origin/master' into llvm10 2020-02-25 16:30:40 -05:00
Andrew Kelley
20f3b0efff rename libuserland to libstage2 2020-02-16 19:16:08 -05:00
Andrew Kelley
a63a2fdf76
update zig_clang bindings to release/10.x 2020-01-29 23:50:24 -05:00
Andrew Kelley
a95dce15ae
Merge remote-tracking branch 'origin/master' into llvm10 2020-01-29 23:33:12 -05:00
Feix Weiglhofer
a4a9330648 translate-c: Don't make const parameters mutable. (#4273)
* translate-c: Remove arg-prefix from const parameters.
* translate-c: Add unittest for const parameters.
2020-01-24 15:32:32 -05:00
Andrew Kelley
72589dbffe
zig_clang builds with llvm 10 2020-01-23 17:22:13 -05:00
Andrew Kelley
32dafbdadc
zig_clang: update StmtClass to llvm 10 2020-01-23 16:52:40 -05:00
Andrew Kelley
3588f99719
zig_clang: update TypeClass enum 2020-01-23 14:35:12 -05:00
LemonBoy
a284be3f69 Fix unsafe cast in translate_c
Fixes #4250
2020-01-22 17:58:57 -05:00
Andrew Kelley
fbe6af81fd
Merge remote-tracking branch 'origin/master' into llvm10 2020-01-16 13:01:36 -05:00
LemonBoy
34ae1d9aa8 Fix unsafe cast in translate_c
* Handle EmptyDecls to clean up the generated code

Closes #4143
2020-01-11 15:51:10 -05:00
LemonBoy
570ffc470e Handle forward-declared functions
Closes #4130
2020-01-10 16:34:40 -05:00
LemonBoy
fd7e69a2c0 More translate-c fixes
* Translate OpaqueValueExpr
* Translate BinaryConditionalOperator
* Fix translation of boolean->int casts
* Reoder some tokens to avoid rendering errors
2020-01-08 08:43:37 +01:00
via
9390e8b848 Preserve packed attribute in C translated struct (#4085)
* Preserve packed attribute in C translated struct

* Add tests for packed C struct
2020-01-07 02:36:07 -05:00
Andrew Kelley
baaef7ed97
Merge pull request #4083 from LemonBoy/better-stdbool
Better _Bool translation
2020-01-06 19:21:55 -05:00
LemonBoy
1dc25d7550
Translate anonymous union/struct 2020-01-06 19:17:47 -05:00
LemonBoy
cd39f6df95 Better _Bool translation 2020-01-06 00:12:18 +01:00
LemonBoy
6ff70d3c31 Better InitListExpr translation 2020-01-05 17:39:29 -05:00
LemonBoy
b0fa2ff853
Translate struct/union initializer expressions 2020-01-02 14:16:39 -05:00
LemonBoy
d908ca4823
Translate align attribute 2020-01-02 12:33:19 -05:00
LemonBoy
8e89bdfe99
Translate linksection attribute 2020-01-02 12:32:51 -05:00
Andrew Kelley
88c5e2a96e
translate-c: don't export inline functions 2020-01-01 20:54:17 -05:00
Vexu
122a9bad39
translate-c-2 fix some casts 2019-12-19 01:38:42 +02:00
Vexu
daa22d42b0
translate-c-2 floats 2019-12-17 11:28:56 +02:00