1260 Commits

Author SHA1 Message Date
Andrew Kelley
6524a64bda stage2: fix referencing decls which appear later in the file 2020-06-02 17:43:51 -04:00
Noam Preil
834e8ac2dc [Stage2/Codegen] Extract REX 2020-05-29 13:33:09 -04:00
Andrew Kelley
5d77fede89 remove debug log statements 2020-05-28 22:43:16 -04:00
Andrew Kelley
0bd89979fd stage2: handle deletions and better dependency resolution
* Deleted decls are deleted; unused decls are also detected as deleted.
   Cycles are not yet detected.
 * Re-analysis is smarter and will not cause a re-analysis of dependants
   when only a function body is changed.
2020-05-28 22:42:13 -04:00
Andrew Kelley
3eed7a4dea stage2: first pass at recursive dependency resolution 2020-05-28 12:19:00 -04:00
Andrew Kelley
c7ca1fe6f7 self-hosted: introduce a virtual address allocation scheme
The binary file abstraction changed its struct named "Decl" to
"TextBlock" and it now represents an allocated slice of memory in
the .text section. It has two new fields: prev and next, making it
a linked list node. This allows a TextBlock to find its neighbors.

The ElfFile struct now has free_list and last_text_block fields.
Doc comments for free_list are reproduced here:

A list of text blocks that have surplus capacity. This list can have false
positives, as functions grow and shrink over time, only sometimes being added
or removed from the freelist.

A text block has surplus capacity when its overcapacity value is greater than
minimum_text_block_size * alloc_num / alloc_den. That is, when it has so
much extra capacity, that we could fit a small new symbol in it, itself with
ideal_capacity or more.

Ideal capacity is defined by size * alloc_num / alloc_den.

Overcapacity is measured by actual_capacity - ideal_capacity. Note that
overcapacity can be negative. A simple way to have negative overcapacity is to
allocate a fresh text block, which will have ideal capacity, and then grow it
by 1 byte. It will then have -1 overcapacity.

The last_text_block keeps track of the end of the .text section.

Allocation, freeing, and resizing decls are all now more sophisticated,
and participate in the virtual address allocation scheme. There is no
longer the possibility for virtual address collisions.
2020-05-27 15:23:27 -04:00
Vexu
cd5b7b9e1d
translate-c: use correct scope in for loop condition 2020-05-27 14:14:17 +03:00
Noam Preil
07472fb453 [Stage2/Codegen] Properly handle arch in genCall 2020-05-24 20:49:29 -04:00
Andrew Kelley
dd05f2be80 run zig fmt on std lib 2020-05-24 10:04:09 -04:00
Andrew Kelley
2ff3995a70
Merge pull request #5378 from ziglang/speed-up-stage2-parsing
improve std.zig.parse performance using flat arrays for AST nodes and tokens
2020-05-24 09:44:08 -04:00
Andrew Kelley
8a3cd82b85 translate-c: fix a use-after-free bug 2020-05-23 23:15:58 -04:00
Andrew Kelley
c78a2e2e8d translate-c: emit local typedefs 2020-05-23 19:59:26 -04:00
Andrew Kelley
395786fd50 translate-c: fix regression in param name mangling 2020-05-23 19:28:14 -04:00
Andrew Kelley
88f5e3a60d translate-c: fix regression in switch statement 2020-05-23 17:58:35 -04:00
Andrew Kelley
f67b8c68a0 translate-c: fix regression on array initialization 2020-05-23 17:52:46 -04:00
Andrew Kelley
32c27daae4 translate-c: fix decl statement regression 2020-05-23 17:50:35 -04:00
Andrew Kelley
46f50ee76c translate-c: fix regression in do-while loop 2020-05-23 17:25:13 -04:00
Andrew Kelley
1a90a5e63a translate-c is building again, but I have 1 @panic in there 2020-05-23 16:24:03 -04:00
Andrew Kelley
e072692e1f update translate-c to new AST API 2020-05-23 12:48:17 -04:00
Noam Preil
63aa9ffedc [Stage2/Codegen] Typo fix 2020-05-22 15:34:32 -04:00
Noam Preil
a52d1476b7 [Stage2/Codegen] Document x64 register enum layout 2020-05-22 15:32:33 -04:00
Andrew Kelley
8df0841d6a stage2 parser: token ids in their own array
To prevent cache misses, token ids go in their own array, and the
start/end offsets go in a different one.

perf measurement before:
         2,667,914      cache-misses:u
     2,139,139,935      instructions:u
       894,167,331      cycles:u

perf measurement after:
         1,757,723      cache-misses:u
     2,069,932,298      instructions:u
       858,105,570      cycles:u
2020-05-22 12:34:12 -04:00
Andrew Kelley
e694cd265a more progress on updating translate-c 2020-05-21 00:14:55 -04:00
Andrew Kelley
3c5d581ce3 update translate-c to the new fn params AST node API 2020-05-20 23:28:31 -04:00
Andrew Kelley
5db9f306ba update translate-c for new Root and ContainerDecl AST 2020-05-20 16:54:21 -04:00
Andrew Kelley
8c10178a1e golly jeepers it's taking a long time to update translate-c 2020-05-20 13:53:53 -04:00
Noam Preil
70239802c9 [Stage2/Codegen] Fix a typo 2020-05-19 22:27:22 -04:00
Andrew Kelley
8d3cca7fc2 stage2: function calls using the global offset table
so far they don't support parameters or return values
2020-05-19 13:51:46 -04:00
Andrew Kelley
8d812dba30 stage2: set up a trampoline table for functions
However there does not appear to be an x86 encoding for calling an
immediate address. So there's no point of setting this up. We should
just emit an indirect call to the got addr.
2020-05-19 13:33:36 -04:00
Andrew Kelley
16f100b82e
Merge pull request #5307 from ziglang/self-hosted-incremental-compilation
rework self-hosted compiler for incremental builds
2020-05-17 13:53:27 -04:00
Andrew Kelley
b0968abccb update ZIR compare output test to test incremental updates 2020-05-17 13:49:22 -04:00
Andrew Kelley
88c8ff6e37 move some files around 2020-05-17 12:08:47 -04:00
Noam Preil
e198eec76a Document register functions 2020-05-17 12:03:01 -04:00
Noam Preil
773281c1f4 Remove trailing whitespace 2020-05-17 12:03:01 -04:00
Noam Preil
e2196a458f Minor cleanup 2020-05-17 12:03:01 -04:00
Noam Preil
497eb31820 Fix the dumb in x86 too 2020-05-17 12:03:01 -04:00
Noam Preil
638554544a Fix a dumb (thanks daurminator!) 2020-05-17 12:03:01 -04:00
Noam Preil
13ea698a40 rework x64 genSetReg 2020-05-17 12:03:01 -04:00
Andrew Kelley
54820a3005 fix source not being loaded when printing errors 2020-05-16 20:23:15 -04:00
Andrew Kelley
017ecc5148 self hosted repl: close executables between updates
This allows the executable to be executed
2020-05-16 15:44:20 -04:00
Andrew Kelley
b0375978ba self-hosted: remove zig libc command for now
Since it depends on the C++ Windows SDK code. For now, self-hosted is
staying pure self hosted, no C/C++ components.
2020-05-16 13:25:39 -04:00
Andrew Kelley
cd5f69794d cross compile the stage2 tests for the target that they work for 2020-05-16 12:19:31 -04:00
Vexu
74f7d710bb
Merge pull request #5032 from LakeByTheWoods/redo_translate_c
Translate C: Redo Add comment containing c source location for failed decls.
2020-05-16 17:37:19 +03:00
Vexu
3e375ee2b9
translate-c use tagName for token id 2020-05-16 14:17:50 +03:00
Vexu
5ac684ec50
fix building translate-c 2020-05-16 13:05:43 +03:00
Andrew Kelley
69a5f0d797 Merge remote-tracking branch 'origin/master' into self-hosted-incremental-compilation 2020-05-16 01:26:18 -04:00
Andrew Kelley
294bfb3321 stage2 zir tests passing 2020-05-15 23:54:13 -04:00
Andrew Kelley
f2feb4e47a move Module to its own file 2020-05-15 21:44:33 -04:00
Andrew Kelley
5135238f86 ZIR: emit proper string literals 2020-05-15 19:11:00 -04:00
Andrew Kelley
8980f150e9 fix memory leaks of one of the ZIR test cases 2020-05-15 18:54:48 -04:00