Commit Graph

14761 Commits

Author SHA1 Message Date
Jakub Konka
def1359187 Merge remote-tracking branch 'origin/master' into zld-incremental-2 2021-07-22 09:34:44 +02:00
Jakub Konka
d0edd37f69 macho: fix bug when freeing Decl
Take into account that an already freed Decl will no longer be
available as `decl.link.macho` causing a potential "inactive union field"
panic.
2021-07-21 23:38:20 +02:00
Jakub Konka
e05b1e0e07 macho: fix reloc generation for stubs and GOT entries
The current approach is somewhat hacky, however, works well for
one-off self-hosted linking.
2021-07-21 23:05:03 +02:00
Tau
8d0671157c Correct hasUniqueRepresentation for vectors
Closes #9333.
2021-07-21 15:19:57 -04:00
Jakub Konka
845c906e6a macho: add relocations for GOT cells
in self-hosted compiler.
2021-07-21 17:58:05 +02:00
Jakub Konka
3bfde76cff macho: fix text block management
For the time being, until we rewrite how atoms are handled across
linkers, store two tables in the MachO linker: one for TextBlocks
directly created and managed by the linker, and one for TextBlocks
that were spawned by Module.Decl. This allows for correct memory
clean up after linking is done.
2021-07-21 15:46:57 +02:00
Andrew Kelley
26984852bd
Merge pull request #9353 from ziglang/stage2-air
stage2: rework AIR memory layout
2021-07-21 03:18:39 -04:00
Andrew Kelley
c39c46c0d1 stage2 tests: respect -Dskip-non-native for object formats 2021-07-20 20:05:54 -07:00
Andrew Kelley
d15dd78abd Sema: fix regression in merging error sets
When updating the code, I accidentally made it look at the fact that the
error set operands were a `type` rather than looking at exactly which error
set types they were.
2021-07-20 19:42:59 -07:00
Andrew Kelley
bf09dd87b6 codegen: fix lowering of AIR br instruction
It incorrectly did not process the death of its operand.
2021-07-20 19:30:30 -07:00
Andrew Kelley
f7ee3b4ca5 std.Progress: revert to the older strategy
This reverts the most recent big changes to `std.Progress` changing the
strategy for printing. Before the changes, it would leave the cursor after
the progress line, having better behavior when a stray print happened,
and supporting sub-process progress without any coordination.

After the changes, the cursor was left at the beginning of the line,
making any prints print garbage and often interfering with stack traces
or other debug information.

This commit reverts to before the changes.

Revert "std: Use more common escape sequences in Progress"
This reverts commit 8ebb18d9da.

Revert "Handle some weird edge cases of Win32 API"
This reverts commit b0724a350f.

Revert "Fix many thinkos"
This reverts commit b5a50a26eb.

Revert "Fix Progress printing on Windows systems"
This reverts commit 3010bfb08a.

Revert "std: Better handling of line-wrapping in Progress"
This reverts commit 4fc2e92876.
2021-07-20 19:11:47 -07:00
Andrew Kelley
885477e2df stage2: disable wasm switch test case for now
The wasm codegen for switch was using br_if opcodes, but it needs to be
reworked to use a br_table opcode instead.
2021-07-20 19:01:19 -07:00
Andrew Kelley
1097b0ec77 codegen: fix lowering of AIR return instruction
It incorrectly did not process the death of its operand. Additionally:

 * delete dead code accidentally introduced in fe14e33945
 * improve AIR printing code to include liveness data for operands.
   Now an exclamation point ("!") indicates the tombstone of an AIR
   instruction.
2021-07-20 18:51:40 -07:00
Andrew Kelley
91c4e28c51 Liveness: fix br instruction not tracking its operand 2021-07-20 16:04:46 -07:00
Andrew Kelley
f47cf93b47 stage2: C backend: fix ret AIR instruction
when operand has 0 runtime bits
2021-07-20 15:56:42 -07:00
Andrew Kelley
9c652cc650 stage2: C backend: implement support for switch_br AIR 2021-07-20 15:52:58 -07:00
Andrew Kelley
fe14e33945 stage2: separate work queue item for functions than decls
Previously we had codegen_decl for both constant values as well as
function bodies. A recent commit updated the linker backends to add
updateFunc as a separate function than updateDecl, and now this commit
does the same with work queue tasks.

The frontend now distinguishes between function pointers and function
bodies.
2021-07-20 15:22:37 -07:00
Jakub Konka
5276ce8e63 macho: use adapters to directly reference strtab
Thanks to this, we no longer need to do allocs per symbol name
landing in the symbol resolver, plus we do not need to actively
track if the string was already inserted into the string table.
2021-07-20 23:37:22 +02:00
Andrew Kelley
a97e5e119a stage2: switch: fix Sema bugs and implement AIR printing 2021-07-20 12:19:17 -07:00
Andrew Kelley
495e60d641 std.ArrayList: add missing assertion in appendSliceAssumeCapacity 2021-07-20 12:19:17 -07:00
Andrew Kelley
ea902ffe8f Sema: reimplement runtime switch
Now supports multiple items pointing to the same body. This is a common
pattern even when using a jump table, with multiple cases pointing to
the same block of code.

In the case of a range specified, the items are moved to branches in the
else body. A future improvement may make it possible to have jump table
items as well as ranges pointing to the same block of code.
2021-07-20 12:19:17 -07:00
Luuk de Gram
caa0de545e Resolve regressions
- Get correct types in wasm backend.
- `arg` is already a `Ref`, therefore simply use `@intToEnum`.
- Fix regression in `zirBoolBr, where the order of insertion was incorrect.
2021-07-20 12:19:17 -07:00
Luuk de Gram
1150fc13dc wasm: Resolve regressions, add intcast support 2021-07-20 12:19:16 -07:00
Andrew Kelley
95756299af stage2: fix compile errors in LLVM backend 2021-07-20 12:19:16 -07:00
Lewis Gaul
bf8e347b1b Get codegen.zig to compile - use '{d}' format for Air.Inst.Index values 2021-07-20 12:19:16 -07:00
Lewis Gaul
7381431e68 Get register_manager.zig tests to compile - use value '1' as mock Air.Inst.Index 2021-07-20 12:19:16 -07:00
Luuk de Gram
1bc3bfc04b Implement switch_br dump 2021-07-20 12:19:16 -07:00
Luuk de Gram
480242b78a Debug info - Implement more instructions:
- bin_op
- un_op
- block
- struct_field_ptr
- br
- condbr

Also updates constant to write the actual Type, rather than the enum tag of the `Ref`.
2021-07-20 12:19:16 -07:00
Andrew Kelley
44fe9c52e1 stage2: wasm backend: update to latest naming convention 2021-07-20 12:19:16 -07:00
Andrew Kelley
934ebbe900 stage2: fix AIR not instruction (see prev commit) 2021-07-20 12:19:16 -07:00
Jacob G-W
414b144257 cbe: fix not (it is a ty_op, not un_op) 2021-07-20 12:19:16 -07:00
Andrew Kelley
4a0f38bb76 stage2: update LLVM backend to new AIR memory layout
Also fix compile errors when not using -Dskip-non-native
2021-07-20 12:19:16 -07:00
Andrew Kelley
33aab2c1bb stage2: ELF linking: avoid crashing for stupidly large functions 2021-07-20 12:19:16 -07:00
Andrew Kelley
b2733a36f8 Sema: memoize decl_val instructions when result is constant 2021-07-20 12:19:16 -07:00
Andrew Kelley
761f36ff93 stage2: rework C backend for new AIR memory layout 2021-07-20 12:19:16 -07:00
Jacob G-W
a804de13c8 plan9 linker: fix after testing
* exports get rendered properly in symbol table
* global offset table is at the start of data section
  instead of after symtab
* various null use fixes
2021-07-20 12:19:16 -07:00
Andrew Kelley
d17f492017 stage2: miscellaneous fixes for the branch
* Breaking language change: inline assembly must use string literal
   syntax. This is in preparation for inline assembly improvements that
   involve more integration with the Zig language. This means we cannot
   rely on text substitution.
 * Liveness: properly handle inline assembly and function calls with
   more than 3 operands.
   - More than 35 operands is not yet supported. This is a low priority
     to implement.
   - This required implementation in codegen.zig as well.
 * Liveness: fix bug causing incorrect tomb bits.
 * Sema: enable switch expressions that are evaluated at compile-time.
   - Runtime switch instructions still need to be reworked in this
     branch. There was a TODO left here (by me) with a suggestion to do
     some bigger changes as part of the AIR memory reworking. Now that
     time has come and I plan to honor the suggestion in a future commit
     before merging this branch.
 * AIR printing: fix missing ')' on alive instructions.

We're back to "hello world" working for the x86_64 backend.
2021-07-20 12:19:16 -07:00
Luuk de Gram
2438f61f1c Refactor entire wasm-backend to use new AIR memory layout 2021-07-20 12:19:16 -07:00
Luuk de Gram
424f260f85 Fix wasm-related compile errors:
- Update `fail()` to not require a `srcLoc`.
This brings it in line with other backends, and we were always passing 'node_offset = 0', anyway.
- Fix unused local due to change of architecture wrt function/decl generation.
- Replace all old instructions to indexes within the function signatures.
2021-07-20 12:19:16 -07:00
Andrew Kelley
8082660118 stage2: codegen.zig updated to new AIR memory layout 2021-07-20 12:19:16 -07:00
Andrew Kelley
eadbee2041 stage2: first pass at printing AIR/Liveness to text
* some instructions are not implemented yet
 * fix off-by-1 in Air.getMainBody
 * Compilation: use `@import("builtin")` rather than `std.builtin`
   for the values that are different for different build configurations.
 * Sema: avoid calling `addType` in between
   air_instructions.ensureUnusedCapacity and corresponding
   appendAssumeCapacity because it can possibly add an instruction.
 * Value: functions print their names
2021-07-20 12:19:16 -07:00
Andrew Kelley
12c10139e3 Sema: finish reworking for AIR memory layout except switch 2021-07-20 12:19:16 -07:00
Andrew Kelley
0da6633909 Sema: fix implementation of getTypeOf
and rename it to typeOf
2021-07-20 12:19:16 -07:00
Andrew Kelley
1294ebe1f5 Sema: AIR memory layout reworking for noreturn instructions 2021-07-20 12:19:16 -07:00
Andrew Kelley
c020a30296 Sema: remove br_block_flat AIR instruction
Thanks to the new AIR memory layout, we can do this by turning a br
operand into a block, rather than having this special purpose
instruction.
2021-07-20 12:19:16 -07:00
Andrew Kelley
27be4f3140 Sema: more AIR memory layout reworking progress
Additionally: ZIR encoding for floats now supports float literals up to
f64, not only f32. This is because we no longer need a source location
for this instruction.
2021-07-20 12:19:16 -07:00
Andrew Kelley
7bb2d13a09 stage2: remove ZIR instructions bool_and and bool_or
These were unused. I believe this happened with the introduction of
bool_br_and and bool_br_or instructions.
2021-07-20 12:19:16 -07:00
Andrew Kelley
3c5927fb87 Sema: add a strategy for handling costly source locations
Now you can pass `.unneeded` for a `LazySrcLoc` and if there ended up
being a compile error that needed it, you'll get
`error.NeededSourceLocation`.

Callsites can now exploit this error to do the expensive computation
to produce a source location object and then repeat the operation.
2021-07-20 12:19:16 -07:00
Andrew Kelley
dbd3529d1f Sema: first pass reworking for AIR memory layout 2021-07-20 12:19:16 -07:00
Andrew Kelley
f17a05bfb7 CLI: add plan9 -ofmt help text 2021-07-20 12:19:16 -07:00