25 Commits

Author SHA1 Message Date
Andrew Kelley
fd7a97b3b2 fix memory leak of anonymous decl name 2020-06-24 16:20:02 -04:00
Andrew Kelley
14aa08fcd3 self-hosted: restore ZIR functionality 2020-06-24 03:46:32 -04:00
Andrew Kelley
b1b7708cc8 self-hosted: hook up incremental compilation to .zig source code 2020-06-23 23:29:51 -04:00
Andrew Kelley
d9c1d8fed3 self-hosted: improve handling of anonymous decls
* anonymous decls have automatically generated names and symbols, and
   participate in the same memory management as named decls.
 * the Ref instruction is deleted
 * the DeclRef instruction now takes a `[]const u8` and DeclRefStr takes
   an arbitrary string instruction operand.
 * introduce a `zir.Decl` type for ZIR Module decls which holds
   content_hash and name - fields that are not needed for `zir.Inst`
   which are created as part of semantic analysis. This improves the
   function signatures of Module.zig and lowers memory usage.
 * the Str instruction is now defined to create an anonymous Decl and
   reference it.
2020-06-23 19:53:32 -04:00
Vexu
7b68385d7d self-hosted: astGenIntegerLiteral support other bases 2020-06-22 23:19:12 -04:00
Vexu
d98aed6eff self-hosted: generalize astGenBuiltinCall 2020-06-22 23:19:12 -04:00
Andrew Kelley
c9a0ec25e0 self-hosted: add Tracy integration
This tool helps give an intuitive picture of performance. This will help
us understand where to improve the code.
2020-06-18 21:55:37 -04:00
Andrew Kelley
7e44302260 stage2: explicit hash and equality function for the DeclTable 2020-06-18 17:12:56 -04:00
Andrew Kelley
02f688d710 remove std.debug.warn debugging logs 2020-06-18 17:12:56 -04:00
Andrew Kelley
7e58c56ca7 self-hosted: implement Decl lookup
* Take advantage of coercing anonymous struct literals to struct types.
 * Reworks Module to favor Zig source as the primary use case.
   Breaks ZIR compilation, which will have to be restored in a future commit.
 * Decl uses src_index rather then src, pointing to an AST Decl node
   index, or ZIR Module Decl index, rather than a byte offset.
 * ZIR instructions have an `analyzed_inst` field instead of Module
   having a hash table.
 * Module.Fn loses the `fn_type` field since it is redundant with
   its `owner_decl` `TypedValue` type.
 * Implement Type and Value copying. A ZIR Const instruction's TypedValue
   is copied to the Decl arena during analysis, which allows freeing the
   ZIR text instructions post-analysis.
 * Don't flush the ELF file if there are compilation errors.
 * Function return types allow arbitrarily complex expressions.
 * AST->ZIR for function calls and return statements.
2020-06-18 17:12:56 -04:00
Andrew Kelley
b4eac0414a stage2: hook up Zig AST to ZIR
* Introduce the concept of anonymous Decls
 * Primitive Hello, World with inline asm works
 * There is still an unsolved problem of how to manage ZIR instructions
   memory when generating from AST. Currently it leaks.
2020-06-18 17:12:56 -04:00
Andrew Kelley
47090d234e stage2: add passing test for compile error in unreferenced cycle 2020-06-08 15:16:40 -04:00
Andrew Kelley
9ea4965ceb self-hosted: remove deleted Decls from failed_decls 2020-06-08 15:16:40 -04:00
Andrew Kelley
91930a4ff0 stage2: fix not re-loading source file for updates after errors 2020-06-08 15:16:40 -04:00
Andrew Kelley
cf654b52d6 stage2: -femit-zir respects decl names and supports cycles 2020-06-08 15:16:40 -04:00
Andrew Kelley
6524a64bda stage2: fix referencing decls which appear later in the file 2020-06-02 17:43:51 -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
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
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
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