authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2015-12-15 02:47:39-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2015-12-15 02:47:39-07:00
log1f48b626a1cef1168d23654f5a9f21ed2196738e
tree697d703a204b26c2cb34b494a7ab53d75785f936
parent673d638070452d86543c6bb47879e83adcfa73a1

std: even more efficient inline assembly


4 files changed, 8 insertions(+), 15 deletions(-)

example/hello_world/hello.zig+1-1
......@@ -2,7 +2,7 @@ export executable "hello";
22
33use "std.zig";
44
5export fn main(argc: isize, argv: &&u8, env: &&u8) -> i32 {
5pub fn main(argc: isize, argv: &&u8, env: &&u8) -> i32 {
66 // TODO implicit coercion from array to string
77 print_str("Hello, world!\n" as string);
88 return 0;
src/analyze.cpp+1-1
......@@ -315,7 +315,7 @@ static void preview_function_declarations(CodeGen *g, ImportTableEntry *import,
315315 auto entry = import->fn_table.maybe_get(proto_name);
316316 bool skip = false;
317317 bool is_internal = (proto_node->data.fn_proto.visib_mod != FnProtoVisibModExport);
318 bool is_pub = (proto_node->data.fn_proto.visib_mod == FnProtoVisibModPub);
318 bool is_pub = (proto_node->data.fn_proto.visib_mod != FnProtoVisibModPrivate);
319319 if (entry) {
320320 add_node_error(g, node,
321321 buf_sprintf("redefinition of '%s'", buf_ptr(proto_name)));
src/codegen.cpp+1-1
......@@ -1611,7 +1611,7 @@ static ImportTableEntry *codegen_add_code(CodeGen *g, Buf *src_dirname, Buf *src
16111611 assert(proto_node->type == NodeTypeFnProto);
16121612 Buf *proto_name = &proto_node->data.fn_proto.name;
16131613
1614 bool is_exported = (proto_node->data.fn_proto.visib_mod == FnProtoVisibModExport);
1614 bool is_exported = (proto_node->data.fn_proto.visib_mod != FnProtoVisibModPrivate);
16151615
16161616 if (buf_eql_str(proto_name, "main") && is_exported) {
16171617 g->insert_bootstrap_code = true;
std/bootstrap.zig+5-12
......@@ -1,16 +1,9 @@
1use "std.zig";
12
2// TODO conditionally compile this differently for non-ELF
33#attribute("naked")
44export fn _start() -> unreachable {
5 // TODO conditionally compile this differently for other architectures and other OSes
6 asm volatile ("
7 mov (%%rsp), %%rdi // first parameter is argc
8 lea 0x8(%%rsp), %%rsi // second parameter is argv
9 lea 0x10(%%rsp,%%rdi,8), %%rdx // third paremeter is env
10 callq main
11 mov %%rax, %%rdi // return value is the parameter to exit syscall
12 mov $60, %%rax // 60 is exit syscall number
13 syscall
14 ");
15 unreachable
5 const argc = asm("mov (%%rsp), %[argc]" : [argc] "=r" (return isize));
6 const argv = asm("lea 0x8(%%rsp), %[argv]" : [argv] "=r" (return &&u8));
7 const env = asm("lea 0x10(%%rsp,%%rdi,8), %[env]" : [env] "=r" (return &&u8));
8 exit(main(argc, argv, env))
169}