* AST: flatten ControlFlowExpression into Continue, Break, and Return. * AST: unify identifiers and literals into the same AST type: OneToken * AST: ControlFlowExpression uses TrailerFlags to optimize storage space. * astgen: support `var` as well as `const` locals, and support explicitly typed locals. Corresponding Module and codegen code is not implemented yet. * astgen: support result locations. * ZIR: add the following instructions (see the corresponding doc comments for explanations of semantics): - alloc - alloc_inferred - bitcast_result_ptr - coerce_result_block_ptr - coerce_result_ptr - coerce_to_ptr_elem - ensure_result_used - ensure_result_non_error - ret_ptr - ret_type - store - param_type * the skeleton structure for result locations is set up. It's looking pretty clean so far. * add compile error for unused result and compile error for discarding errors. * astgen: split builtin calls up to implemented manually, and implement `@as`, `@bitCast` (and others) with respect to result locations. * add CLI support for hex and raw object formats. They are not supported by the self-hosted compiler yet, and emit errors. * rename `--c` CLI to `-ofmt=[objectformat]` which can be any of the object formats. Only ELF and C are supported so far. Also added missing help to the help text. * Remove hard tabs from C backend test cases. Shame on you Noam, you are grounded, you should know better, etc. Bad boy. * Delete C backend code and test case that relied on comptime_int incorrectly making it all the way to codegen.
70 lines
1.9 KiB
Zig
70 lines
1.9 KiB
Zig
const std = @import("std");
|
|
const TestContext = @import("../../src-self-hosted/test.zig").TestContext;
|
|
|
|
// These tests should work with all platforms, but we're using linux_x64 for
|
|
// now for consistency. Will be expanded eventually.
|
|
const linux_x64 = std.zig.CrossTarget{
|
|
.cpu_arch = .x86_64,
|
|
.os_tag = .linux,
|
|
};
|
|
|
|
pub fn addCases(ctx: *TestContext) !void {
|
|
ctx.c("empty start function", linux_x64,
|
|
\\export fn _start() noreturn {}
|
|
,
|
|
\\noreturn void _start(void) {}
|
|
\\
|
|
);
|
|
ctx.c("less empty start function", linux_x64,
|
|
\\fn main() noreturn {}
|
|
\\
|
|
\\export fn _start() noreturn {
|
|
\\ main();
|
|
\\}
|
|
,
|
|
\\noreturn void main(void);
|
|
\\
|
|
\\noreturn void _start(void) {
|
|
\\ main();
|
|
\\}
|
|
\\
|
|
\\noreturn void main(void) {}
|
|
\\
|
|
);
|
|
// TODO: implement return values
|
|
// TODO: figure out a way to prevent asm constants from being generated
|
|
ctx.c("inline asm", linux_x64,
|
|
\\fn exitGood() void {
|
|
\\ asm volatile ("syscall"
|
|
\\ :
|
|
\\ : [number] "{rax}" (231),
|
|
\\ [arg1] "{rdi}" (0)
|
|
\\ );
|
|
\\}
|
|
\\
|
|
\\export fn _start() noreturn {
|
|
\\ exitGood();
|
|
\\}
|
|
,
|
|
\\#include <stddef.h>
|
|
\\
|
|
\\void exitGood(void);
|
|
\\
|
|
\\const char *const exitGood__anon_0 = "{rax}";
|
|
\\const char *const exitGood__anon_1 = "{rdi}";
|
|
\\const char *const exitGood__anon_2 = "syscall";
|
|
\\
|
|
\\noreturn void _start(void) {
|
|
\\ exitGood();
|
|
\\}
|
|
\\
|
|
\\void exitGood(void) {
|
|
\\ register size_t rax_constant __asm__("rax") = 231;
|
|
\\ register size_t rdi_constant __asm__("rdi") = 0;
|
|
\\ __asm volatile ("syscall" :: ""(rax_constant), ""(rdi_constant));
|
|
\\ return;
|
|
\\}
|
|
\\
|
|
);
|
|
}
|