aboutsummaryrefslogtreecommitdiff
path: root/src/codegen
AgeCommit message (Collapse)Author
2021-07-20stage2: C backend: fix ret AIR instructionAndrew Kelley
when operand has 0 runtime bits
2021-07-20stage2: C backend: implement support for switch_br AIRAndrew Kelley
2021-07-20Sema: reimplement runtime switchAndrew Kelley
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-20Resolve regressionsLuuk de Gram
- 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-20wasm: Resolve regressions, add intcast supportLuuk de Gram
2021-07-20stage2: fix compile errors in LLVM backendAndrew Kelley
2021-07-20stage2: wasm backend: update to latest naming conventionAndrew Kelley
2021-07-20stage2: fix AIR not instruction (see prev commit)Andrew Kelley
2021-07-20cbe: fix not (it is a ty_op, not un_op)Jacob G-W
2021-07-20stage2: update LLVM backend to new AIR memory layoutAndrew Kelley
Also fix compile errors when not using -Dskip-non-native
2021-07-20stage2: rework C backend for new AIR memory layoutAndrew Kelley
2021-07-20Refactor entire wasm-backend to use new AIR memory layoutLuuk de Gram
2021-07-20Fix wasm-related compile errors:Luuk de Gram
- 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-20stage2: compile error fixes for AIR memory layout branchAndrew Kelley
Now the branch is compiling again, provided that one uses `-Dskip-non-native`, but many code paths are disabled. The code paths can now be re-enabled one at a time and updated to conform to the new AIR memory layout.
2021-07-20stage2: Air and Liveness are passed ephemerallyAndrew Kelley
to the link infrastructure, instead of being stored with Module.Fn. This moves towards a strategy to make more efficient use of memory by not storing Air or Liveness data in the Fn struct, but computing it on demand, immediately sending it to the backend, and then immediately freeing it. Backends which want to defer codegen until flush() such as SPIR-V must move the Air/Liveness data upon `updateFunc` being called and keep track of that data in the backend implementation itself.
2021-07-20stage2: first pass over Module.zig for AIR memory layoutAndrew Kelley
2021-07-20stage2: update Liveness, SPIR-V for new AIR memory layoutAndrew Kelley
also do the inline assembly instruction
2021-07-20stage2: rework AIR memory layoutAndrew Kelley
This commit changes the AIR file and the documentation of the memory layout. The actual work of modifying the surrounding code (in Sema and codegen) is not yet done.
2021-07-12C backend: TypedefMap is now ArrayHashMapAndrew Kelley
The C backend depends on insertion order into this map so that type definitions will be declared before they are used.
2021-07-08initial plan9 boilerplatejacob gw
The code now compiles and fails with Plan9ObjectFormatUnimplemented
2021-07-08C backend: cleanups to wrapping int operationsAndrew Kelley
* less branching by passing parameters in the main op code switch. * properly pass the target when asking the type system for int info. * handle u8, i16, etc when it is represented using int_unsigned/int_signed tag. * compile error instead of assertion failure for unimplemented cases (greater than 64 bits integer). * control flow cleanups * zig.h: expand macros into inline functions * reduce the complexity of the test case by making it one test case that calls multiple functions. Also fix the problem of c_int max value mismatch between host and target.
2021-07-08C backend: add/sub/mul wrapping for the C backendMatt Knight
2021-07-07stage2: basic inferred error set supportAndrew Kelley
* Inferred error sets are stored in the return Type of the function, owned by the Module.Fn. So it cleans up that memory in deinit(). * Sema: update the inferred error set in zirRetErrValue - Update relevant code in wrapErrorUnion * C backend: improve some some instructions to take advantage of liveness analysis to avoid being emitted when unused. * C backend: when an error union has a payload type with no runtime bits, emit the error union as the same type as the error set.
2021-07-07stage2: fix if expressions on error unionsAndrew Kelley
AstGen had the then-else logic backwards for if expressions on error unions. This commit fixes it. Turns out AstGen only really needs `is_non_null` and `is_non_err`, and does not need the `is_null` or `is_err` variants. So I removed the `is_null{,_ptr}` and `is_err{,_ptr}` ZIR instructions (-4) and added `is_non_err`, `is_non_err_ptr` ZIR instructions (+2) for a total of (-2) ZIR instructions, giving us a tiny bit more headroom within the 256 tag limit. This required swapping the order of then/else blocks in a handful of cases, but ultimately means the ZIR will be in the same as source order, which is convenient when debugging. AIR code on the other hand, gains the `is_non_err` and `is_non_err_ptr` instructions. Sema: fix logic in zirErrUnionCode and zirErrUnionCodePtr returning the wrong result type.
2021-07-07stage2: implement `@panic` and beginnigs of inferred error setsAndrew Kelley
* ZIR: add two instructions: - ret_err_value_code - ret_err_value * AstGen: add countDefers and utilize it to emit more efficient ZIR for return expressions in the presence of defers. * AstGen: implement |err| payloads for `errdefer` syntax. - There is not an "unused capture" error for it yet. * AstGen: `return error.Foo` syntax gets a hot path in return expressions, using the new ZIR instructions. This also is part of implementing inferred error sets, since we need to tell Sema to add an error value to the inferred error set before it gets coerced. * Sema: implement `@setCold`. - Implement `@setCold` support for C backend. * `@panic` and regular safety panics such as `unreachable` now properly invoke `std.builtin.panic`. * C backend: improve pointer and function value rendering. * C linker: fix redundant typedefs. * Add Type.error_set_inferred. * Fix Value.format for enum_literal, enum_field_index, bytes. * Remove the C backend test that checks for identical text I measured a 14% reduction in Total ZIR Bytes from master branch for std/os.zig.
2021-06-29Remove mention of lldMachO from the projectJakub Konka
including: * finding lldMachO in CMake config * punting `ld64.lld` to LLD linker * providing bindings to LLD linker
2021-06-23stage2: slightly improve error reporting for missing importsAndrew Kelley
There is now a distinction between `@import` with a .zig extension and without. Without a .zig extension it assumes it is a package name, and returns error.PackageNotFound if not mapped into the package table.
2021-06-21cleanups related to unused paramsAndrew Kelley
2021-06-21fix code broken from previous commitJacob G-W
2021-06-21std, src, doc, test: remove unused variablesJacob G-W
2021-06-21stage2: simplify codegen for errorToInt and intToErrorJacob G-W
We can just use bitcast instead of error_to_int, int_to_error since errorToInt and intToError do not actually do anything, just change types. This allows us to remove 2 air ops that were the exact same as bitcast
2021-06-14add ast-check flag to zig fmt, fix found bugsVeikka Tuominen
2021-06-10zig fmtAndrew Kelley
2021-06-03Breaking hash map changes for 0.8.0Martin Wickham
- hash/eql functions moved into a Context object - *Context functions pass an explicit context - *Adapted functions pass specialized keys and contexts - new getPtr() function returns a pointer to value - remove functions renamed to fetchRemove - new remove functions return bool - removeAssertDiscard deleted, use assert(remove(...)) instead - Keys and values are stored in separate arrays - Entry is now {*K, *V}, the new KV is {K, V} - BufSet/BufMap functions renamed to match other set/map types - fixed iterating-while-modifying bug in src/link/C.zig
2021-05-28wasm: Add stage2 tests for error unionsLuuk de Gram
2021-05-28wasm: Reverse the order of error and payloadLuuk de Gram
This will set us up to correctly retrieve the error local index and payload index depending on that of the multi_value's index. As from now, the error will always use the multi_value's index, and the payload will use the following locals.
2021-05-28wasm: Add support for error union as return typeLuuk de Gram
- This currently uses the multi-value feature to return both the possible error, and its payload. - Also genAlloc and the logic to allocate the locals itself have been seperated, so we can create more locals whenever needed, and not only when `genAlloc` is called.
2021-05-28wasm: Implement error unions and unwrappingLuuk de Gram
- Slightly refactored `Wvalue.multi_value` to also contain the amount of locals it contains, this allows us to set all fields at once.
2021-05-28wasm: Support error setsLuuk de Gram
2021-05-22stage2: Move BlockData out of ir.Inst.Blockjoachimschmidt557
2021-05-22Merge pull request #8852 from Snektron/spirvAndrew Kelley
SPIR-V: More codegen
2021-05-22stage2: rename ir.zig to air.zigAndrew Kelley
We've settled on the nomenclature for the artifacts the compiler pipeline produces: 1. Tokens 2. AST (Abstract Syntax Tree) 3. ZIR (Zig Intermediate Representation) 4. AIR (Analyzed Intermediate Representation) 5. Machine Code Renaming `ir` identifiers to `air` will come with the inevitable air-memory-layout branch that I plan to start after the 0.8.0 release.
2021-05-22SPIR-V: Make functions which always return a null result return void insteadRobin Voetter
2021-05-22SPIR-V: Generate locals at the start of a functionRobin Voetter
2021-05-22SPIR-V: Debug line info/source infoRobin Voetter
2021-05-22SPIR-V: DeclGen constructor/destructorRobin Voetter
2021-05-22SPIR-V: branchingRobin Voetter
2021-05-22SPIR-V: Pass source location to genType and genConstant for better error ↵Robin Voetter
reporting
2021-05-22SPIR-V: Preliminary alloc/store/load generationRobin Voetter
2021-05-22SPIR-V: Split out genCmp from genBinOpRobin Voetter