Commit Graph

5132 Commits

Author SHA1 Message Date
Veikka Tuominen
6f6568b1fd translate-c: correctly add semicolon to if statements 2021-02-19 20:48:06 +02:00
Veikka Tuominen
d672c20b8a Merge pull request #7479 from ziglang/translate-c-ast
Make translate-c use intermediate AST
2021-02-19 13:03:29 +02:00
Veikka Tuominen
974a1c5525 translate-c: small fixes to avoid generating invalid code for macros 2021-02-19 12:50:42 +02:00
Andrew Kelley
914540ddb5 astgen: fix remaining compile errors
Now it builds and what remains in this branch is:
 * fix the stage2 compiler regressions from this branch
 * finish the rest of zig fmt test cases, get them passing
 * Merge in Vexu's translate-c AST branch & fix translate-c regressions
2021-02-19 00:04:31 -07:00
Andrew Kelley
9010bd8aec stage2: astgen: fix most of the remaining compile errors
more progress on converting astgen to the new AST memory layout.
only a few code paths left to update.
2021-02-18 20:09:29 -07:00
Veikka Tuominen
3aba1fa04f translate-c: ensure failed macros don't get defined multiple times 2021-02-19 01:52:27 +02:00
Veikka Tuominen
df5a8120df translate-c: small miscellaneous improvements 2021-02-18 21:34:31 +02:00
Andrew Kelley
29daf10639 stage2: fix a couple more compilation errors 2021-02-17 22:34:06 -07:00
Andrew Kelley
5a2620fcca stage2: fix some of the compilation errors in this branch 2021-02-17 22:22:10 -07:00
Andrew Kelley
c66481f9bc astgen: finish updating expressions to new mem layout
Now all that is left is compile errors and whatever regressions this
branch introduced.
2021-02-17 20:59:21 -07:00
Veikka Tuominen
7ca53bdfaa translate-c: improve switch translation 2021-02-17 22:11:26 +02:00
Veikka Tuominen
d5fecbd0ba translate-c: support scoped typedef, enum and record decls
Closes #5256
2021-02-17 16:26:11 +02:00
Veikka Tuominen
e2974759dd translate-c: demote untranslatable declarations to externs 2021-02-17 14:11:49 +02:00
Isaac Freund
070e548acf std: remove io.AutoIndentingStream
This type is not widely applicable enough to be a public part of the
public interface of the std.

The current implementation in only fully utilized by the zig fmt
implementation, which could benefit by even tighter integration as
will be demonstrated in the next commit. Therefore, move the current
io.AutoIndentingStream to lib/std/zig/render.zig.

The C backend of the self hosted compiler also use this type currently,
but it does not require anywhere near its full complexity. Therefore,
implement a greatly simplified version of this interface in
src/codegen/c.zig.
2021-02-16 23:20:46 +01:00
Veikka Tuominen
9a826ccbe0 translate-c: elide some unecessary casts of literals 2021-02-16 16:40:43 +02:00
Veikka Tuominen
74e9d4ca82 translate-c: get all translate-c tests passing 2021-02-16 16:40:43 +02:00
Veikka Tuominen
78fba4e021 translate-c: get all run-translated-c tests passing 2021-02-16 16:40:43 +02:00
Veikka Tuominen
77a11e6873 translate-c: render records and enums 2021-02-16 16:40:43 +02:00
Veikka Tuominen
c0540967e9 translate-c: render array stuff 2021-02-16 16:40:43 +02:00
Veikka Tuominen
62162a0717 translate-c: render control flow 2021-02-16 16:40:42 +02:00
Veikka Tuominen
c4dfabf4dc translate-c: render macro functions, use cast type as return type
Closes #8004
2021-02-16 16:40:42 +02:00
Veikka Tuominen
f191251ddb translate-c: render functions 2021-02-16 16:40:42 +02:00
Veikka Tuominen
227f167958 translate-c: render binops and break/continue 2021-02-16 16:40:42 +02:00
Veikka Tuominen
685778c5a7 translate-c: render unary ops 2021-02-16 16:40:42 +02:00
Veikka Tuominen
1147ecc5fd translate-c: render variables and builtin calls 2021-02-16 16:40:42 +02:00
Veikka Tuominen
d7460db044 translate-c: render a bunch of simple nodes and calls 2021-02-16 16:40:39 +02:00
Veikka Tuominen
13a9db2085 translate-c: begin implementing ast.render 2021-02-16 16:40:06 +02:00
Veikka Tuominen
2a74a1ebaa translate-c: bunch of small fixes to get it compiling 2021-02-16 16:40:06 +02:00
Veikka Tuominen
66bbd75a83 translate-c: convert macro translation 2021-02-16 16:40:06 +02:00
Veikka Tuominen
c30c2f7c13 translate-c: convert assignment and conditional exprs 2021-02-16 16:40:05 +02:00
Veikka Tuominen
450b718b9e translate-c: convert field/array access, call, pre/postcrement 2021-02-16 16:40:05 +02:00
Veikka Tuominen
cadd4483be translate-c: convert switch 2021-02-16 16:40:05 +02:00
Veikka Tuominen
66dd64ec15 translate-c: convert most control flow 2021-02-16 16:40:05 +02:00
Veikka Tuominen
d8b9fca0b1 translate-c: convert casts and string/array init 2021-02-16 16:40:05 +02:00
Veikka Tuominen
5dac3683c9 translate-c: convert record and enum decls 2021-02-16 16:40:05 +02:00
Veikka Tuominen
bb867b071a translate-c: convert vardecl and typedef 2021-02-16 16:40:02 +02:00
Veikka Tuominen
f36849fed2 translate-c: convert function translation 2021-02-16 16:37:08 +02:00
Veikka Tuominen
7514c0ad0d translate-c: unary operator, integers and misc 2021-02-16 16:37:08 +02:00
Veikka Tuominen
f5041caa2e translate-c: more binaryoperator chagnes, blocks and unary type expressions 2021-02-16 16:37:07 +02:00
Veikka Tuominen
4c0c9b0755 translate-c: convert transBinaryOperator 2021-02-16 16:37:07 +02:00
Veikka Tuominen
d835f5cce5 translate-c: make Node more like Type 2021-02-16 16:37:07 +02:00
Veikka Tuominen
6ecec4c8b7 translate-c: translate C types to stage2 types 2021-02-16 16:37:07 +02:00
Veikka Tuominen
7051ef32bf translate-c: start creating intermediate AST 2021-02-16 16:37:07 +02:00
Andrew Kelley
4006a3afb3 astgen: update more expression types to new mem layout
additionally introduce a new file to centralize all the data about
builtin functions that we have, including:
 * enum tag identifying the builtin function
 * number of parameters.
 * whether the expression may need a memory location.
 * whether the expression allows an lvalue (currently only true for
   `@field`).
Now there is only one ComptimeStringMap that has this data as the value,
and we dispatch on the enum tag in order to asgen the builtin function.
In particular this simplifies the logic for checking the number of
parameters.

This removes some untested code paths from if and while, which need to
be restored with #7929 in mind.

After this there are only a handful left of expression types to rework
to the new memory layout, and then it will be only compile errors left
to solve.
2021-02-15 22:36:46 -07:00
Andrew Kelley
c2b4d51749 astgen: update a handful of expression types to new mem layout
break, continue, blocks, bit_not, negation, identifiers, string
literals, integer literals, inline assembly

also gave multiline string literals a different node tag from regular
string literals, for code clarity and to avoid an unnecessary load from
token_tags array.
2021-02-13 21:40:12 -07:00
Andrew Kelley
7630a5c566 stage2: more progress towards Module/astgen building with new mem layout 2021-02-12 23:47:17 -07:00
Andrew Kelley
b4e344bcf8 Merge remote-tracking branch 'origin/master' into ast-memory-layout
Conflicts:
 * lib/std/zig/ast.zig
 * lib/std/zig/parse.zig
 * lib/std/zig/parser_test.zig
 * lib/std/zig/render.zig
 * src/Module.zig
 * src/zir.zig

I resolved some of the conflicts by reverting a small portion of
@tadeokondrak's stage2 logic here regarding `callconv(.Inline)`.
It will need to get reworked as part of this branch.
2021-02-11 23:45:40 -07:00
Andrew Kelley
3d0f4b9030 stage2: start reworking Module/astgen for memory layout changes
This commit does not reach any particular milestone, it is
work-in-progress towards getting things to build.

There's a `@panic("TODO")` in translate-c that should be removed when
working on translate-c stuff.
2021-02-11 23:29:55 -07:00
Andrew Kelley
d3565ed6b4 Merge pull request #7749 from tadeokondrak/6429-callconv-inline
Replace inline fn with callconv(.Inline)
2021-02-11 16:01:58 -08:00
Evan Haas
d98f09e4f6 translate-c: comma operator should introduce a new scope
This prevents inadvertent side-effects when an expression is not evaluated
due to boolean short-circuiting

Fixes #7989
2021-02-12 01:40:43 +02:00