This shaves off one syscall (we use one instead of two if we were to
use `windows.OpenFile` wrapper). Clean up flag generation in `OpenFile`.
Hopefully, we're in a much better place to *almost* support `openW`
and `openatW`.
This way, we can remove more `kernel32` calls such as `RemoveDirectoryW`
or `DeleteFileW`, and use `std.os.windows.DeleteFile` instead which
is purely NT-based.
Replace them with `std.os.windows.OpenFile` instead. To allow
creation/opening of directories, `std.os.windows.OpenFileOptions`
now features a `.expect_dir: bool` member which is meant to emualate
POSIX's `O_DIRECTORY` flag.
As discussed in the previous commit, it would be better to avoid
function pointers to syscalls and explicitly split the control
path into two function calls instead. This commit addresses that
for `std.os.windows.DeviceIoControl`.
* multiple returns jump to one canonical function exitlude. This is in
preparation for the defer feature.
* simple elision of trivial jump relocs.
* omit prelude/exitlude for naked calling convention functions.
* fix not switching on arch for prelude/exitlude
* fix swapped registers when setting stack mem from a register
* `optimize_mode` is passed to `link.File` and stored there
* improve the debugging function `Module.dumpInst`
* get rid of `Value.the_one_possible_value` in favor of a few more
specific values for different types. This is less buggy, one less
footgun.
* `Type.onePossibleValue` now returns a `?Value` instead of `bool`.
* codegen handles undefined values. `undef` is a new `MCValue` tag.
It uses 0xaa values depending on optimization mode. However
optimization mode does not yet support scope overrides.
* link.zig: move the `Options` field from `File.Elf` and `File.C` to
the base struct.
- fix the Tag enum to adhere to style conventions
* ZIR now supports emitting undefined values.
* Fix the logic of comptime math to properly compare against zero using
the `compareWithZero` function.
* implement sema for runtime deref, store pointer, coerce_to_ptr_elem,
and store
* identifiers support being lvalues, except for decls is still TODO
* codegen supports load, store, ref, alloc
* introduce more MCValue union tags to support pointers
* add load, ref, store typed IR instructions
* add Type.isVolatilePtr
When there are no format parameters, it simply calls `writeAll`. This
has the effect of no longer emitting a compile error for using `{}` and
not having any parameters, however, at this point in the development
process of Zig I think that tradeoff is worthwhile.
On the other hand, it might be OK to simply define formatting to work
this way. It's a common pattern to use the formatting function's format
string `"like this", .{}` instead of `"{}", .{"like this"}`, which can
lead to accidentally putting control characters in the formatting
string, however, with this change that works just fine.
This commit adds a Zig wrapper for `kernel32.DeviceIoControl` which
applies ReactOS logic for deciding whether to use
`ntdll.NtDeviceIoControlFile` or `ntdll.NtFsControlFile` based on the
value of passed `IO_CONTROL_CODE`. The decision logic is based on the
logic found in ReactOS found in the following [link].
Thanks to Daurnimator for finding this bit in ReactOS!
[link]: https://doxygen.reactos.org/d3/d74/deviceio_8c.html
Comment out non-x86_64 architectures for now in codegen.zig, because
they all have compile errors for their codepaths anyway, and it was
bloating the compilation speed and memory usage when stage1 tried to
build self-hosted. Here's the panic message:
"Backend architectures that don't have good support yet are commented
out, to improve compilation performance. If you are interested in one
of these other backends feel free to uncomment them. Eventually these
will be completed, but stage1 is slow and a memory hog."
This is a workaround to lower the time it takes to build self-hosted
with stage1 as well as use less memory. It should fix the CI.
Additionally:
* Add `single_mut_pointer` support to `Type`
* Trivial implementation of stack allocation in codegen.zig. It does
not deal with freeing yet, and it's missing the stack pointer
adjustment prologue.
* Add the `alloc` IR instruction and semantic analysis for `alloc` ZIR
instruction.
This is an attempt to save memory when building self-hosted.
before:
Total bytes allocated: 5.941 GiB, deallocated: 2.259 GiB, remaining: 3.681 GiB
after:
Total bytes allocated: 5.933 GiB, deallocated: 2.253 GiB, remaining: 3.680 GiB
This makes sense from an organizational point of view, as explained by
this new doc comment at the top of the new file:
//! Semantic analysis of ZIR instructions.
//! This file operates on a `Module` instance, transforming untyped ZIR
//! instructions into semantically-analyzed IR instructions. It does type
//! checking, comptime control flow, and safety-check generation. This is the
//! the heart of the Zig compiler.
//! When deciding if something goes into this file or into Module, here is a
//! guiding principle: if it has to do with (untyped) ZIR instructions, it goes
//! here. If the analysis operates on typed IR instructions, it goes in Module.
Before:
4009 src-self-hosted/Module.zig
After:
2776 src-self-hosted/Module.zig
1128 src-self-hosted/zir_sema.zig
This should be sufficient to avoid the situation we have in stage1 where
ir.cpp is 32,516 lines.