415 Commits

Author SHA1 Message Date
Andrew Kelley
2f5892671e move compiler's CType logic to std.Target
This API only depends on std.Target and is extremely useful in build
scripts when populating configure files.
2023-01-31 15:09:35 -07:00
kcbanner
a9b68308b9 cbe: fixes for tls, support for not linking libc, and enabling tests
- cbe: Implement linksection support, to support TLS when not linking libc
- cbe: Support under-aligned variables / struct fields
- cbe: Support packed structs (in the C definition of packed)
- windows: Fix regression with x86 _tls_array
- compiler_rt: Add 128-bit atomics to compiler_rt
- tests: Re-enable threadlocal tests on cbe+windows, and llvm+x86
- tests: Re-enable f80 tests that now pass
- ci: change windows ci to run the CBE behaviour tests with -lc, to match how the compiler is bootstrapped
- update zig1.wasm
2023-01-29 15:04:13 -05:00
kcbanner
fcb05ee2e7 cbe: don't emit unused undefined array literals 2023-01-29 15:02:04 -05:00
kcbanner
8dd0107255 zig fmt fixup 2023-01-23 13:48:37 -05:00
kcbanner
1aa2c32055 cbe: fixes for x86
- Emit calling convention
- Fix .Naked handling for msvc
- Add teb helper for x86
- Fix 128-bit shl implementation when rhs is >= 64
- Add 128-bit shl tests
2023-01-23 13:48:36 -05:00
kcbanner
9c951cc874 fmt fixups 2023-01-02 13:56:32 -07:00
kcbanner
676e4f3824 cbe: changes to get zig2.c compiling under msvc
- Add cpuid / getXCR0 functions for the cbe to use instead of asm blocks
- Don't cast between 128 bit types during truncation
- Fixup truncation to use functions for shifts / adds
- Fixup float casts for undefined values
- Add test for 128 bit integer truncation
2023-01-01 16:44:29 -05:00
kcbanner
f07d33f54b cbe: fixes for compiling zig2.c under msvc
- add zig_mul_i128
- render slice structs in static initializers without casts / c99 style init
- add negative numbers and u128 to 128-bit multiply test
2023-01-01 16:44:29 -05:00
kcbanner
6ed049fe36 cbe: all behaviour tests now pass on msvc
- Fix zig_clz_u128 not respecting the bits argument. This was crashing the compile-rt addxf3 tests with the cbe
- Instead of redering a negation for negative 128 bit int literals, render the literal as twos complement. This allows
rendering int representations of floats correctly (specifically f80).
2023-01-01 16:44:29 -05:00
kcbanner
2d34477dbb cbe: msvc atomics
- Implement most atomic operations for msvc
- Disable "atomicrmw with floats" test for cbe
2023-01-01 16:44:28 -05:00
kcbanner
b86a8b4a5b cbe: airNot emits zig_not_ calls for integers 2023-01-01 16:44:28 -05:00
kcbanner
3d4ff4fdda cbe: 32 bit fixup for update-zig1 2023-01-01 16:44:28 -05:00
kcbanner
7fb3683c32 cbe: more msvc compatibility work
- Add .StaticInitializer to ValueRenderLocation to indicate that the emitted values
must be constant expressions (no function calls, struct casting).
- Add new path for special float types (nan, inf) that works in constant expressions
- Implement windows.teb() using a syscall for .stage2_c because x64 MSVC
doesn't support any kind of inline asm
2023-01-01 16:44:28 -05:00
kcbanner
7f3bc45772 cbe: nan builtins on msvc, fixup C2099 errors in static initializers
- Map the __builtin_nan(f|l)? functions to nan(f|l)? on msvc
- MSVC throws C2099 when initializing a struct with cast syntax
in a global initializer.  Added zig_as_init_  to handle this case,
 and generate it only in static initializers for > 64 bit ints.
- Change float initialization to emit the integer representation
in global initializers to avoid C2099 caused by calling nan.
2023-01-01 16:44:28 -05:00
kcbanner
351025dc05 cbe: msvc compatible int casting inside renderValue .Packed branch
- Handle non-abiInt source types (like packed union) as sources in renderIntCast
2023-01-01 16:44:28 -05:00
kcbanner
00b54a5fe5 cbe: more msvc fixes
- Add Function.renderIntcast to handle common casting cases
- Fixup casting inside aggregate initialization
- Remove redundant cast in aggregate initialization
- Fix renderValue .Packed branch for > 64 bit types
2023-01-01 16:44:28 -05:00
kcbanner
36212e9d17 cbe: msvc compatibility for > 64 bit intcasts and truncating from > 64 to < 64 bit
- Uses zig_as/zig_lo as necessary when int casting to support !zig_has_int128
- Remove redundant cast if the type is the same
- Use zig_lo when truncating > 64 bits
2023-01-01 16:44:28 -05:00
kcbanner
7225a0043e cbe: handle msvc struct casting quirk
MSVC can't explicitly cast a struct to a typedef of itself (ie. f128 to i128). Added a
set of macros to handle float casting, and to not produce a cast for this specific
case on MSVC. A better approach would probably be to know if the cast is redundant
and not do it.
2023-01-01 16:44:27 -05:00
kcbanner
e6ef579609 cbe: fixup casting to/from 128 bit int types, as they may not have compiler support 2023-01-01 16:44:27 -05:00
kcbanner
a43fdc1620 cbe: first set of changes for msvc compatibility
- Forward declare int builtins, so the definitions aren't assumed incorrectly
- Add define to handle MSVC not support static const in function parameter array lengths
- Fixup several spots where int128 support was assumed.
- Support zig_align
- Support zig_export
- Stub out some missing non-builtin functions
- Added StringLiteral to automatically split string literals when they get to 16380 in size,
which is the maxmimum pre-concatenation string literal size on MSVC.
2023-01-01 16:44:27 -05:00
Jacob Young
bc913295b5 CBE: fix emitting a partially undefined string literal 2022-12-24 02:40:33 -05:00
Jacob Young
a52dcdd3c5 CBE: fix bitwise not
Closes #13911
2022-12-21 03:04:59 -05:00
Jacob Young
202e8a0589 cbe: fix type passed to renderParentPtr 2022-12-18 23:39:01 -05:00
Jacob Young
0e3feebb04 codegen: fix taking the address of a zero-bit field in a zero-bit struct
Normally when we want a pointer to the end of a struct we just add 1 to
the struct pointer.  However, when it is a zero-bit struct, the pointer
type being used during lowering is often a dummy pointer type that
actually points to a non-zero-bit type, so we actually want to add 0
instead, since a zero-bit struct begins and ends at the same address.
2022-12-18 22:11:26 -05:00
Veikka Tuominen
9bb1104e37 implement defining C variadic functions 2022-12-17 13:22:09 +02:00
Veikka Tuominen
8a0a6b7387 port packed vector elem ptr logic from stage1
Closes #12812
Closes #13925
2022-12-15 21:06:35 -05:00
Veikka Tuominen
7b2a936173 remove stack option from @call 2022-12-13 12:52:21 +02:00
Jacob Young
fc6d7d2799 CBE: fix compiling for aarch64-windows
These bugs were triggered in the C backend by aarch64-specific code in
os/windows.zig.  Intentionally not updating zig1.wasm yet because of
upcoming changes and since aarch64-windows is not tested on master yet.
2022-12-10 09:15:40 -05:00
Veikka Tuominen
9d93b2ccf1 Eliminate BoundFn type from the language
Closes #9484
2022-12-09 20:37:18 -07:00
Andrew Kelley
50eb7983cd remove most conditional compilation based on stage1
There are still a few occurrences of "stage1" in the standard library
and self-hosted compiler source, however, these instances need a bit
more careful inspection to ensure no breakage.
2022-12-06 20:38:54 -07:00
Jacob Young
91e489174b CBE: avoid trailing space 2022-12-06 12:27:28 -07:00
Jacob Young
3686787f67 CBE: add windows-specific reserved identifiers 2022-12-06 12:27:28 -07:00
Jacob Young
f421efbcc1 CBE: fix bad local reuse for volatile memset 2022-12-06 12:15:04 -07:00
Jacob Young
4ee79aa33c CBE: revert broken change that got missed 2022-12-04 22:37:48 -05:00
Jacob Young
7d3cc3bc8d CBE: defer invariant local reuse in loops
When a local defined outside a loop dies inside the loop, it can still
be needed on subsequent loop iterations, so reuse of the local must be
deferred until after the loop ends. This causes behavior tests to pass.
2022-12-04 15:57:40 -07:00
Andrew Kelley
cc8bcae8c0 CBE: fix liveness issue with wrapping optionals 2022-12-04 15:57:40 -07:00
Andrew Kelley
4a6deaff5f CBE: remove stray comment 2022-12-04 15:57:40 -07:00
Andrew Kelley
701cebeb30 CBE: fix union init wrong field name 2022-12-04 15:57:40 -07:00
Andrew Kelley
aa98517b3e CBE: aggregate_init: resolve all operands before processing Liveness 2022-12-04 15:57:40 -07:00
Andrew Kelley
4aae0b09cf CBE and LLVM: handle unused try instructions
In both backends they did not observe the Liveness information for try
instructions. Now they do. For the C backend this is necessary for
correctness; for the LLVM backend, it improves code generation.
2022-12-04 15:57:40 -07:00
Andrew Kelley
f2e59e41c1 CBE: fix various regressions caught by behavior tests 2022-12-04 15:57:40 -07:00
Andrew Kelley
6c0a1417c6 CBE: fix static allocs being double allocated 2022-12-04 15:57:40 -07:00
Andrew Kelley
da73410e7f CBE: avoid curly inits because they don't work in assignments 2022-12-04 15:57:40 -07:00
Andrew Kelley
db1819e8ed CBE: fix use-after-free of Type keys in free_locals map 2022-12-04 15:57:40 -07:00
Andrew Kelley
7bd63a602a CBE: fix assignment expr and switch free tracking 2022-12-04 15:57:40 -07:00
Andrew Kelley
8bfbfa589c CBE: fix clone of freed locals not being deep clone 2022-12-04 15:57:40 -07:00
Andrew Kelley
73a76b45c5 CBE: take advantage of switch_br and cond_br liveness 2022-12-04 15:57:40 -07:00
Andrew Kelley
8d8b2c834d CBE: exploit Liveness analysis to reuse locals 2022-12-04 15:57:40 -07:00
Andrew Kelley
2a0efbee56 Revert "cbe: reduce amount of temporary locals"
This reverts commit 15cc83e27ae8a1740d9b7e2ec14044903979a832.
2022-12-04 15:57:40 -07:00
Andrew Kelley
46f4a97d05 Revert "cbe: write more instructions inline"
This reverts commit f8b779c114a5fcb82f08168912f2300d7027a2fd.
2022-12-04 15:57:39 -07:00