std: even more efficient inline assembly
This commit is contained in:
parent
673d638070
commit
1f48b626a1
@ -2,7 +2,7 @@ export executable "hello";
|
||||
|
||||
use "std.zig";
|
||||
|
||||
export fn main(argc: isize, argv: &&u8, env: &&u8) -> i32 {
|
||||
pub fn main(argc: isize, argv: &&u8, env: &&u8) -> i32 {
|
||||
// TODO implicit coercion from array to string
|
||||
print_str("Hello, world!\n" as string);
|
||||
return 0;
|
||||
|
@ -315,7 +315,7 @@ static void preview_function_declarations(CodeGen *g, ImportTableEntry *import,
|
||||
auto entry = import->fn_table.maybe_get(proto_name);
|
||||
bool skip = false;
|
||||
bool is_internal = (proto_node->data.fn_proto.visib_mod != FnProtoVisibModExport);
|
||||
bool is_pub = (proto_node->data.fn_proto.visib_mod == FnProtoVisibModPub);
|
||||
bool is_pub = (proto_node->data.fn_proto.visib_mod != FnProtoVisibModPrivate);
|
||||
if (entry) {
|
||||
add_node_error(g, node,
|
||||
buf_sprintf("redefinition of '%s'", buf_ptr(proto_name)));
|
||||
|
@ -1611,7 +1611,7 @@ static ImportTableEntry *codegen_add_code(CodeGen *g, Buf *src_dirname, Buf *src
|
||||
assert(proto_node->type == NodeTypeFnProto);
|
||||
Buf *proto_name = &proto_node->data.fn_proto.name;
|
||||
|
||||
bool is_exported = (proto_node->data.fn_proto.visib_mod == FnProtoVisibModExport);
|
||||
bool is_exported = (proto_node->data.fn_proto.visib_mod != FnProtoVisibModPrivate);
|
||||
|
||||
if (buf_eql_str(proto_name, "main") && is_exported) {
|
||||
g->insert_bootstrap_code = true;
|
||||
|
@ -1,16 +1,9 @@
|
||||
use "std.zig";
|
||||
|
||||
// TODO conditionally compile this differently for non-ELF
|
||||
#attribute("naked")
|
||||
export fn _start() -> unreachable {
|
||||
// TODO conditionally compile this differently for other architectures and other OSes
|
||||
asm volatile ("
|
||||
mov (%%rsp), %%rdi // first parameter is argc
|
||||
lea 0x8(%%rsp), %%rsi // second parameter is argv
|
||||
lea 0x10(%%rsp,%%rdi,8), %%rdx // third paremeter is env
|
||||
callq main
|
||||
mov %%rax, %%rdi // return value is the parameter to exit syscall
|
||||
mov $60, %%rax // 60 is exit syscall number
|
||||
syscall
|
||||
");
|
||||
unreachable
|
||||
const argc = asm("mov (%%rsp), %[argc]" : [argc] "=r" (return isize));
|
||||
const argv = asm("lea 0x8(%%rsp), %[argv]" : [argv] "=r" (return &&u8));
|
||||
const env = asm("lea 0x10(%%rsp,%%rdi,8), %[env]" : [env] "=r" (return &&u8));
|
||||
exit(main(argc, argv, env))
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user