diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2020-06-24 22:37:58 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-06-24 22:37:58 -0400 |
| commit | d337469e4484ffd160b4508e2366fefd435f6c8a (patch) | |
| tree | 7ad577eb66febb985ed029ae75c47461611775e2 /lib/std/zig.zig | |
| parent | 7875649c2481f90b918581670c9268d6033f873f (diff) | |
| parent | 20b4a2cf2cded8904a57714ed2b90c857f12c6b1 (diff) | |
| download | zig-d337469e4484ffd160b4508e2366fefd435f6c8a.tar.gz zig-d337469e4484ffd160b4508e2366fefd435f6c8a.zip | |
Merge pull request #5583 from ziglang/zig-ast-to-zir
self-hosted: hook up Zig AST to ZIR
Diffstat (limited to 'lib/std/zig.zig')
| -rw-r--r-- | lib/std/zig.zig | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/lib/std/zig.zig b/lib/std/zig.zig index bb4f955797..841827cc19 100644 --- a/lib/std/zig.zig +++ b/lib/std/zig.zig @@ -1,4 +1,6 @@ +const std = @import("std.zig"); const tokenizer = @import("zig/tokenizer.zig"); + pub const Token = tokenizer.Token; pub const Tokenizer = tokenizer.Tokenizer; pub const parse = @import("zig/parse.zig").parse; @@ -9,6 +11,21 @@ pub const ast = @import("zig/ast.zig"); pub const system = @import("zig/system.zig"); pub const CrossTarget = @import("zig/cross_target.zig").CrossTarget; +pub const SrcHash = [16]u8; + +/// If the source is small enough, it is used directly as the hash. +/// If it is long, blake3 hash is computed. +pub fn hashSrc(src: []const u8) SrcHash { + var out: SrcHash = undefined; + if (src.len <= SrcHash.len) { + std.mem.copy(u8, &out, src); + std.mem.set(u8, out[src.len..], 0); + } else { + std.crypto.Blake3.hash(src, &out); + } + return out; +} + pub fn findLineColumn(source: []const u8, byte_offset: usize) struct { line: usize, column: usize } { var line: usize = 0; var column: usize = 0; @@ -26,6 +43,27 @@ pub fn findLineColumn(source: []const u8, byte_offset: usize) struct { line: usi return .{ .line = line, .column = column }; } +/// Returns the standard file system basename of a binary generated by the Zig compiler. +pub fn binNameAlloc( + allocator: *std.mem.Allocator, + root_name: []const u8, + target: std.Target, + output_mode: std.builtin.OutputMode, + link_mode: ?std.builtin.LinkMode, +) error{OutOfMemory}![]u8 { + switch (output_mode) { + .Exe => return std.fmt.allocPrint(allocator, "{}{}", .{ root_name, target.exeFileExt() }), + .Lib => { + const suffix = switch (link_mode orelse .Static) { + .Static => target.staticLibSuffix(), + .Dynamic => target.dynamicLibSuffix(), + }; + return std.fmt.allocPrint(allocator, "{}{}{}", .{ target.libPrefix(), root_name, suffix }); + }, + .Obj => return std.fmt.allocPrint(allocator, "{}{}", .{ root_name, target.oFileExt() }), + } +} + test "" { @import("std").meta.refAllDecls(@This()); } |
