178 Commits

Author SHA1 Message Date
Jakub Konka
e4039cecc7 x64: fix (un)wrapping error unions + refactor 2022-03-06 19:02:02 +01:00
Luuk de Gram
43cb19ea4d wasm: Implement @wasmMemoryGrow builtin
Similarly to the other wasm builtin, this implements the grow variation where the memory
index is a comptime known value. The operand as well as the result are runtime values.
This also verifies during semantic analysis the target we're building for is wasm, or else
emits a compilation error. This means that other backends do not have to handle this AIR instruction,
other than the wasm and LLVM backends.
2022-03-03 16:33:46 -07:00
Jakub Konka
3ec74a1cd8 codegen: handle elem_ptr when lowering to memory
* x64: handle storing from-to non-stack memory
2022-03-02 20:04:34 -05:00
Jakub Konka
77072d1a17 x64: fix bug in lowering optionals directly to immediate 2022-03-02 17:40:37 +01:00
Jakub Konka
c9d1db7e8e x64: fix incorrect calc of rdi spill stack loc for backpatching 2022-03-02 14:53:02 +01:00
Jakub Konka
350bf9db13 x64: fix intCast to properly clear out dest register 2022-03-02 14:34:43 +01:00
Jakub Konka
d35cae551e x64: rectify and add missing optionals bits
Includes changes/additions to:
* `wrap_optional`
* `optional_payload`
* `isNull` helper
2022-03-02 14:05:29 +01:00
Jakub Konka
e8eb9778cc codegen: lower field_ptr to memory across linking backends
This requires generating an addend for the target relocation as
the field pointer might point at a field inner to the container.
2022-03-01 22:03:18 +01:00
Jakub Konka
52205a3c16 x64: fix array to slice impl 2022-03-01 17:59:39 +01:00
Jakub Konka
caa4e30ef4 x64: impl airMemset using inline memset 2022-03-01 15:21:10 +01:00
Jakub Konka
5a6f4395e6 x64: impl airMemcpy using inline memcpy 2022-03-01 14:29:48 +01:00
Jakub Konka
cfbc3537ef x64: pass more behavior tests 2022-02-28 23:20:05 +01:00
Jakub Konka
66d28d0f20 x64: implement get_union_tag for register 2022-02-28 23:20:05 +01:00
Jakub Konka
decc90e0e7 x64: clean up loadMemPtrIntoRegister abstraction 2022-02-28 23:20:05 +01:00
Jakub Konka
12cdb36c5b codegen: fix padding calculation for error unions when lowering
* do not track `rdi` register before `call` inst, but instead freeze
  it from further use, until `call` has been realised
* pass more error union tests
2022-02-28 23:20:05 +01:00
Jakub Konka
05431d7c4a x64: impl unwrap_errunion_payload and unwrap_errunion_err for register 2022-02-28 23:20:05 +01:00
Andrew Kelley
d5100dc815 stage2: fix frame_address AIR instruction
Various places were assuming different union tags. Now it is
consistently a no-op instruction, just like the similar
instruction ret_addr.
2022-02-28 13:38:33 -07:00
Veikka Tuominen
90bce11f62 stage2: implement @frameAddress 2022-02-28 13:09:14 -07:00
Jakub Konka
16f9774d2d x64: fix switch condition mir; pass more union tests 2022-02-28 15:25:40 +01:00
Jakub Konka
a61ac9ecbf x64: fix store with ABI size > 8 on stack; pass union tests 2022-02-28 12:14:41 +01:00
Jakub Konka
57a823582c x64: impl airGetUnionTag 2022-02-28 11:40:25 +01:00
Jakub Konka
4d0c48738b x64: make lowerUnnamedConst a fallthrough condition 2022-02-28 11:40:25 +01:00
Jakub Konka
1dc05e9e77 x64: impl airSetUnionTag 2022-02-28 11:40:21 +01:00
Andrew Kelley
2687b8f7f4 stage2: implement @unionInit
The ZIR instruction `union_init_ptr` is renamed to `union_init`.
I made it always use by-value semantics for now, not taking the time to
invest in result location semantics, in case we decide to change the
rules for unions. This way is much simpler.

There is a new AIR instruction: union_init. This is for a comptime known
tag, runtime-known field value.
vector_init is renamed to aggregate_init, which solves a TODO comment.
2022-02-26 20:59:36 -07:00
Jakub Konka
e0f5627d4a x64+aarch64: check for pointer to zero-bit type when lowering decl
Unless the pointer is a pointer to a function, if the pointee type
has zero-bits, we need to return `MCValue.none` as the `Decl` has
not been lowered to memory, and therefore, any GOT reference will be
wrong.
2022-02-25 21:59:19 +01:00
Jakub Konka
4b14384989 aarch64: check if type has runtime bits before allocating mem ptr 2022-02-25 21:59:19 +01:00
Veikka Tuominen
b034c45b2b stage2: implement fieldParentPtr 2022-02-24 19:48:34 +02:00
Jakub Konka
2f0299c3cf x64: account for multiple returns from functions
This is necessary to correctly adjust for spilling of the %rdi
register in the callee.
2022-02-23 19:29:47 +01:00
Jakub Konka
d657ede324 x64: disable printing results on macos until I fix the linker
Hopefully, this will make the CI green, and in the meantime I can
fix the bugs in the MachO linker.
2022-02-22 21:57:44 +01:00
Jakub Konka
3be6c79ca2 x64: spill compare flags between blocks, extern calls, and cmp insts
This is just the first step towards the final solution as to get
here I had omit a safety assert check in `getResolvedInst` helper.
2022-02-22 21:56:34 +01:00
Jakub Konka
b9b4e4671f x64: add naive impl of else in switch 2022-02-22 21:56:34 +01:00
Jakub Konka
2617117221 x64: fix lowering of error unions (we didn't pad to alignment)
* fix returning large values on stack from procedure calls - we
  need to explicitly specify source and dest base registers for
  `genSetStack` as well
2022-02-22 21:56:34 +01:00
Jakub Konka
87a0d754be x64: add basic, naive impl of switch 2022-02-22 21:56:34 +01:00
Jakub Konka
5ba66911fa x64: add basic impl of shl for integers 2022-02-22 21:56:34 +01:00
Jakub Konka
71dda25f14 x64: add basic impl of minimum builtin for ints 2022-02-22 21:56:34 +01:00
Jakub Konka
57c9eec232 x64: implement unwrap_err_payload and unwrap_err_err for stack offset 2022-02-22 21:56:34 +01:00
Jakub Konka
f4f23e307c codegen: lower error_set and error_union 2022-02-22 21:56:34 +01:00
Jakub Konka
358b544157 x64: recover address in rdi if was spilled 2022-02-22 21:56:34 +01:00
Jakub Konka
630da643c6 x64: pass pointer to stack for return value in .rdi register 2022-02-22 21:56:34 +01:00
Jakub Konka
478f770053 x64: first, really horrible attempt at returning values on stack 2022-02-22 21:56:34 +01:00
Jakub Konka
e582c0a043 x64: reorder resolving call params: return values first, then params 2022-02-22 21:56:34 +01:00
Jakub Konka
8bc95b22dc x64: sub is non-commutative 2022-02-22 21:56:34 +01:00
Andrew Kelley
74303a3d95
Merge pull request #10925 from Vexu/stage2
stage2: support anon init through error unions and optionals
2022-02-21 14:18:17 -05:00
Veikka Tuominen
27c63bf433 stage2: implement errunion_payload_ptr_set 2022-02-19 20:48:00 +02:00
Jakub Konka
da86839af0 x64: clean up implementation of divs, mod, rem for integers 2022-02-19 14:24:03 +01:00
Jakub Konka
bd396d7e07 x64: add unsigned div and move logic into a helper fn 2022-02-19 14:24:03 +01:00
Jakub Konka
2c13a4b87e x64: implement div_exact for ints (signed+unsigned) 2022-02-19 14:24:03 +01:00
Andrew Kelley
2e1c16d649
Merge pull request #10924 from ziglang/air-independence-day
AIR independence day
2022-02-19 02:57:48 -05:00
Andrew Kelley
4e1e5ab622 stage2: make AIR not reference ZIR for inline assembly
Instead it stores all the information it needs to into AIR.

closes #10784
2022-02-18 19:41:32 -07:00
Cody Tapscott
ef417f19e1 stage2: Implement @bitReverse and @byteSwap
This change implements the above built-ins for Sema and the LLVM
backend. Other backends have had placeholders added for lowering.
2022-02-18 14:28:32 -07:00