parent
118d41ef83
commit
b184ae5ca5
124
doc/docgen.zig
124
doc/docgen.zig
@ -365,11 +365,13 @@ fn genToc(allocator: &mem.Allocator, tokenizer: &Tokenizer) !Toc {
|
||||
header_stack_size += 1;
|
||||
|
||||
const urlized = try urlize(allocator, content);
|
||||
try nodes.append(Node{.HeaderOpen = HeaderOpen {
|
||||
try nodes.append(Node{
|
||||
.HeaderOpen = HeaderOpen{
|
||||
.name = content,
|
||||
.url = urlized,
|
||||
.n = header_stack_size,
|
||||
}});
|
||||
},
|
||||
});
|
||||
if (try urls.put(urlized, tag_token)) |other_tag_token| {
|
||||
parseError(tokenizer, tag_token, "duplicate header url: #{}", urlized) catch {};
|
||||
parseError(tokenizer, other_tag_token, "other tag here") catch {};
|
||||
@ -514,8 +516,10 @@ fn genToc(allocator: &mem.Allocator, tokenizer: &Tokenizer) !Toc {
|
||||
return parseError(tokenizer, end_code_tag, "invalid token inside code_begin: {}", end_tag_name);
|
||||
}
|
||||
_ = try eatToken(tokenizer, Token.Id.BracketClose);
|
||||
} else unreachable; // TODO issue #707
|
||||
try nodes.append(Node {.Code = Code {
|
||||
} else
|
||||
unreachable; // TODO issue #707
|
||||
try nodes.append(Node{
|
||||
.Code = Code{
|
||||
.id = code_kind_id,
|
||||
.name = name,
|
||||
.source_token = source_token,
|
||||
@ -524,7 +528,8 @@ fn genToc(allocator: &mem.Allocator, tokenizer: &Tokenizer) !Toc {
|
||||
.link_objects = link_objects.toOwnedSlice(),
|
||||
.target_windows = target_windows,
|
||||
.link_libc = link_libc,
|
||||
}});
|
||||
},
|
||||
});
|
||||
tokenizer.code_node_count += 1;
|
||||
} else {
|
||||
return parseError(tokenizer, tag_token, "unrecognized tag name: {}", tag_name);
|
||||
@ -734,9 +739,12 @@ fn genHtml(allocator: &mem.Allocator, tokenizer: &Tokenizer, toc: &Toc, out: var
|
||||
const tmp_bin_file_name = try os.path.join(allocator, tmp_dir_name, name_plus_bin_ext);
|
||||
var build_args = std.ArrayList([]const u8).init(allocator);
|
||||
defer build_args.deinit();
|
||||
try build_args.appendSlice([][]const u8 {zig_exe,
|
||||
"build-exe", tmp_source_file_name,
|
||||
"--output", tmp_bin_file_name,
|
||||
try build_args.appendSlice([][]const u8{
|
||||
zig_exe,
|
||||
"build-exe",
|
||||
tmp_source_file_name,
|
||||
"--output",
|
||||
tmp_bin_file_name,
|
||||
});
|
||||
try out.print("<pre><code class=\"shell\">$ zig build-exe {}.zig", code.name);
|
||||
switch (code.mode) {
|
||||
@ -766,8 +774,7 @@ fn genHtml(allocator: &mem.Allocator, tokenizer: &Tokenizer, toc: &Toc, out: var
|
||||
try build_args.append("c");
|
||||
try out.print(" --library c");
|
||||
}
|
||||
_ = exec(allocator, build_args.toSliceConst()) catch return parseError(
|
||||
tokenizer, code.source_token, "example failed to compile");
|
||||
_ = exec(allocator, build_args.toSliceConst()) catch return parseError(tokenizer, code.source_token, "example failed to compile");
|
||||
|
||||
const run_args = [][]const u8{tmp_bin_file_name};
|
||||
|
||||
@ -777,7 +784,10 @@ fn genHtml(allocator: &mem.Allocator, tokenizer: &Tokenizer, toc: &Toc, out: var
|
||||
os.ChildProcess.Term.Exited => |exit_code| {
|
||||
if (exit_code == 0) {
|
||||
warn("{}\nThe following command incorrectly succeeded:\n", result.stderr);
|
||||
for (run_args) |arg| warn("{} ", arg) else warn("\n");
|
||||
for (run_args) |arg|
|
||||
warn("{} ", arg)
|
||||
else
|
||||
warn("\n");
|
||||
return parseError(tokenizer, code.source_token, "example incorrectly compiled");
|
||||
}
|
||||
},
|
||||
@ -785,11 +795,9 @@ fn genHtml(allocator: &mem.Allocator, tokenizer: &Tokenizer, toc: &Toc, out: var
|
||||
}
|
||||
break :blk result;
|
||||
} else blk: {
|
||||
break :blk exec(allocator, run_args) catch return parseError(
|
||||
tokenizer, code.source_token, "example crashed");
|
||||
break :blk exec(allocator, run_args) catch return parseError(tokenizer, code.source_token, "example crashed");
|
||||
};
|
||||
|
||||
|
||||
const escaped_stderr = try escapeHtml(allocator, result.stderr);
|
||||
const escaped_stdout = try escapeHtml(allocator, result.stdout);
|
||||
|
||||
@ -802,7 +810,11 @@ fn genHtml(allocator: &mem.Allocator, tokenizer: &Tokenizer, toc: &Toc, out: var
|
||||
var test_args = std.ArrayList([]const u8).init(allocator);
|
||||
defer test_args.deinit();
|
||||
|
||||
try test_args.appendSlice([][]const u8 {zig_exe, "test", tmp_source_file_name});
|
||||
try test_args.appendSlice([][]const u8{
|
||||
zig_exe,
|
||||
"test",
|
||||
tmp_source_file_name,
|
||||
});
|
||||
try out.print("<pre><code class=\"shell\">$ zig test {}.zig", code.name);
|
||||
switch (code.mode) {
|
||||
builtin.Mode.Debug => {},
|
||||
@ -821,13 +833,15 @@ fn genHtml(allocator: &mem.Allocator, tokenizer: &Tokenizer, toc: &Toc, out: var
|
||||
}
|
||||
if (code.target_windows) {
|
||||
try test_args.appendSlice([][]const u8{
|
||||
"--target-os", "windows",
|
||||
"--target-arch", "x86_64",
|
||||
"--target-environ", "msvc",
|
||||
"--target-os",
|
||||
"windows",
|
||||
"--target-arch",
|
||||
"x86_64",
|
||||
"--target-environ",
|
||||
"msvc",
|
||||
});
|
||||
}
|
||||
const result = exec(allocator, test_args.toSliceConst()) catch return parseError(
|
||||
tokenizer, code.source_token, "test failed");
|
||||
const result = exec(allocator, test_args.toSliceConst()) catch return parseError(tokenizer, code.source_token, "test failed");
|
||||
const escaped_stderr = try escapeHtml(allocator, result.stderr);
|
||||
const escaped_stdout = try escapeHtml(allocator, result.stdout);
|
||||
try out.print("\n{}{}</code></pre>\n", escaped_stderr, escaped_stdout);
|
||||
@ -836,7 +850,13 @@ fn genHtml(allocator: &mem.Allocator, tokenizer: &Tokenizer, toc: &Toc, out: var
|
||||
var test_args = std.ArrayList([]const u8).init(allocator);
|
||||
defer test_args.deinit();
|
||||
|
||||
try test_args.appendSlice([][]const u8 {zig_exe, "test", "--color", "on", tmp_source_file_name});
|
||||
try test_args.appendSlice([][]const u8{
|
||||
zig_exe,
|
||||
"test",
|
||||
"--color",
|
||||
"on",
|
||||
tmp_source_file_name,
|
||||
});
|
||||
try out.print("<pre><code class=\"shell\">$ zig test {}.zig", code.name);
|
||||
switch (code.mode) {
|
||||
builtin.Mode.Debug => {},
|
||||
@ -858,13 +878,19 @@ fn genHtml(allocator: &mem.Allocator, tokenizer: &Tokenizer, toc: &Toc, out: var
|
||||
os.ChildProcess.Term.Exited => |exit_code| {
|
||||
if (exit_code == 0) {
|
||||
warn("{}\nThe following command incorrectly succeeded:\n", result.stderr);
|
||||
for (test_args.toSliceConst()) |arg| warn("{} ", arg) else warn("\n");
|
||||
for (test_args.toSliceConst()) |arg|
|
||||
warn("{} ", arg)
|
||||
else
|
||||
warn("\n");
|
||||
return parseError(tokenizer, code.source_token, "example incorrectly compiled");
|
||||
}
|
||||
},
|
||||
else => {
|
||||
warn("{}\nThe following command crashed:\n", result.stderr);
|
||||
for (test_args.toSliceConst()) |arg| warn("{} ", arg) else warn("\n");
|
||||
for (test_args.toSliceConst()) |arg|
|
||||
warn("{} ", arg)
|
||||
else
|
||||
warn("\n");
|
||||
return parseError(tokenizer, code.source_token, "example compile crashed");
|
||||
},
|
||||
}
|
||||
@ -881,7 +907,11 @@ fn genHtml(allocator: &mem.Allocator, tokenizer: &Tokenizer, toc: &Toc, out: var
|
||||
var test_args = std.ArrayList([]const u8).init(allocator);
|
||||
defer test_args.deinit();
|
||||
|
||||
try test_args.appendSlice([][]const u8 {zig_exe, "test", tmp_source_file_name});
|
||||
try test_args.appendSlice([][]const u8{
|
||||
zig_exe,
|
||||
"test",
|
||||
tmp_source_file_name,
|
||||
});
|
||||
switch (code.mode) {
|
||||
builtin.Mode.Debug => {},
|
||||
builtin.Mode.ReleaseSafe => try test_args.append("--release-safe"),
|
||||
@ -894,13 +924,19 @@ fn genHtml(allocator: &mem.Allocator, tokenizer: &Tokenizer, toc: &Toc, out: var
|
||||
os.ChildProcess.Term.Exited => |exit_code| {
|
||||
if (exit_code == 0) {
|
||||
warn("{}\nThe following command incorrectly succeeded:\n", result.stderr);
|
||||
for (test_args.toSliceConst()) |arg| warn("{} ", arg) else warn("\n");
|
||||
for (test_args.toSliceConst()) |arg|
|
||||
warn("{} ", arg)
|
||||
else
|
||||
warn("\n");
|
||||
return parseError(tokenizer, code.source_token, "example test incorrectly succeeded");
|
||||
}
|
||||
},
|
||||
else => {
|
||||
warn("{}\nThe following command crashed:\n", result.stderr);
|
||||
for (test_args.toSliceConst()) |arg| warn("{} ", arg) else warn("\n");
|
||||
for (test_args.toSliceConst()) |arg|
|
||||
warn("{} ", arg)
|
||||
else
|
||||
warn("\n");
|
||||
return parseError(tokenizer, code.source_token, "example compile crashed");
|
||||
},
|
||||
}
|
||||
@ -918,9 +954,15 @@ fn genHtml(allocator: &mem.Allocator, tokenizer: &Tokenizer, toc: &Toc, out: var
|
||||
var build_args = std.ArrayList([]const u8).init(allocator);
|
||||
defer build_args.deinit();
|
||||
|
||||
try build_args.appendSlice([][]const u8 {zig_exe, "build-obj", tmp_source_file_name,
|
||||
"--color", "on",
|
||||
"--output", tmp_obj_file_name});
|
||||
try build_args.appendSlice([][]const u8{
|
||||
zig_exe,
|
||||
"build-obj",
|
||||
tmp_source_file_name,
|
||||
"--color",
|
||||
"on",
|
||||
"--output",
|
||||
tmp_obj_file_name,
|
||||
});
|
||||
|
||||
if (!code.is_inline) {
|
||||
try out.print("<pre><code class=\"shell\">$ zig build-obj {}.zig", code.name);
|
||||
@ -954,13 +996,19 @@ fn genHtml(allocator: &mem.Allocator, tokenizer: &Tokenizer, toc: &Toc, out: var
|
||||
os.ChildProcess.Term.Exited => |exit_code| {
|
||||
if (exit_code == 0) {
|
||||
warn("{}\nThe following command incorrectly succeeded:\n", result.stderr);
|
||||
for (build_args.toSliceConst()) |arg| warn("{} ", arg) else warn("\n");
|
||||
for (build_args.toSliceConst()) |arg|
|
||||
warn("{} ", arg)
|
||||
else
|
||||
warn("\n");
|
||||
return parseError(tokenizer, code.source_token, "example build incorrectly succeeded");
|
||||
}
|
||||
},
|
||||
else => {
|
||||
warn("{}\nThe following command crashed:\n", result.stderr);
|
||||
for (build_args.toSliceConst()) |arg| warn("{} ", arg) else warn("\n");
|
||||
for (build_args.toSliceConst()) |arg|
|
||||
warn("{} ", arg)
|
||||
else
|
||||
warn("\n");
|
||||
return parseError(tokenizer, code.source_token, "example compile crashed");
|
||||
},
|
||||
}
|
||||
@ -975,8 +1023,7 @@ fn genHtml(allocator: &mem.Allocator, tokenizer: &Tokenizer, toc: &Toc, out: var
|
||||
try out.print("</code></pre>\n");
|
||||
}
|
||||
} else {
|
||||
_ = exec(allocator, build_args.toSliceConst()) catch return parseError(
|
||||
tokenizer, code.source_token, "example failed to compile");
|
||||
_ = exec(allocator, build_args.toSliceConst()) catch return parseError(tokenizer, code.source_token, "example failed to compile");
|
||||
}
|
||||
if (!code.is_inline) {
|
||||
try out.print("</code></pre>\n");
|
||||
@ -987,7 +1034,6 @@ fn genHtml(allocator: &mem.Allocator, tokenizer: &Tokenizer, toc: &Toc, out: var
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fn exec(allocator: &mem.Allocator, args: []const []const u8) !os.ChildProcess.ExecResult {
|
||||
@ -996,13 +1042,19 @@ fn exec(allocator: &mem.Allocator, args: []const []const u8) !os.ChildProcess.Ex
|
||||
os.ChildProcess.Term.Exited => |exit_code| {
|
||||
if (exit_code != 0) {
|
||||
warn("{}\nThe following command exited with code {}:\n", result.stderr, exit_code);
|
||||
for (args) |arg| warn("{} ", arg) else warn("\n");
|
||||
for (args) |arg|
|
||||
warn("{} ", arg)
|
||||
else
|
||||
warn("\n");
|
||||
return error.ChildExitError;
|
||||
}
|
||||
},
|
||||
else => {
|
||||
warn("{}\nThe following command crashed:\n", result.stderr);
|
||||
for (args) |arg| warn("{} ", arg) else warn("\n");
|
||||
for (args) |arg|
|
||||
warn("{} ", arg)
|
||||
else
|
||||
warn("\n");
|
||||
return error.ChildCrashed;
|
||||
},
|
||||
}
|
||||
|
@ -8,8 +8,7 @@ const c = @cImport({
|
||||
const msg = c"Hello, world!\n";
|
||||
|
||||
export fn main(argc: c_int, argv: &&u8) c_int {
|
||||
if (c.printf(msg) != c_int(c.strlen(msg)))
|
||||
return -1;
|
||||
if (c.printf(msg) != c_int(c.strlen(msg))) return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -4,9 +4,7 @@ pub fn build(b: &Builder) void {
|
||||
const obj = b.addObject("base64", "base64.zig");
|
||||
|
||||
const exe = b.addCExecutable("test");
|
||||
exe.addCompileFlags([][]const u8 {
|
||||
"-std=c99",
|
||||
});
|
||||
exe.addCompileFlags([][]const u8{"-std=c99"});
|
||||
exe.addSourceFile("test.c");
|
||||
exe.addObject(obj);
|
||||
|
||||
|
@ -4,9 +4,7 @@ pub fn build(b: &Builder) void {
|
||||
const lib = b.addSharedLibrary("mathtest", "mathtest.zig", b.version(1, 0, 0));
|
||||
|
||||
const exe = b.addCExecutable("test");
|
||||
exe.addCompileFlags([][]const u8 {
|
||||
"-std=c99",
|
||||
});
|
||||
exe.addCompileFlags([][]const u8{"-std=c99"});
|
||||
exe.addSourceFile("test.c");
|
||||
exe.linkLibrary(lib);
|
||||
|
||||
|
@ -48,9 +48,7 @@ pub fn resolveZigLibDir(allocator: &mem.Allocator) ![]u8 {
|
||||
\\Unable to find zig lib directory: {}.
|
||||
\\Reinstall Zig or use --zig-install-prefix.
|
||||
\\
|
||||
,
|
||||
@errorName(err)
|
||||
);
|
||||
, @errorName(err));
|
||||
|
||||
return error.ZigLibDirNotFound;
|
||||
};
|
||||
|
@ -108,5 +108,4 @@ pub const Instruction = struct {
|
||||
ArgType,
|
||||
Export,
|
||||
};
|
||||
|
||||
};
|
||||
|
@ -64,21 +64,60 @@ pub fn main() !void {
|
||||
}
|
||||
|
||||
const commands = []Command{
|
||||
Command { .name = "build", .exec = cmdBuild },
|
||||
Command { .name = "build-exe", .exec = cmdBuildExe },
|
||||
Command { .name = "build-lib", .exec = cmdBuildLib },
|
||||
Command { .name = "build-obj", .exec = cmdBuildObj },
|
||||
Command { .name = "fmt", .exec = cmdFmt },
|
||||
Command { .name = "run", .exec = cmdRun },
|
||||
Command { .name = "targets", .exec = cmdTargets },
|
||||
Command { .name = "test", .exec = cmdTest },
|
||||
Command { .name = "translate-c", .exec = cmdTranslateC },
|
||||
Command { .name = "version", .exec = cmdVersion },
|
||||
Command { .name = "zen", .exec = cmdZen },
|
||||
Command{
|
||||
.name = "build",
|
||||
.exec = cmdBuild,
|
||||
},
|
||||
Command{
|
||||
.name = "build-exe",
|
||||
.exec = cmdBuildExe,
|
||||
},
|
||||
Command{
|
||||
.name = "build-lib",
|
||||
.exec = cmdBuildLib,
|
||||
},
|
||||
Command{
|
||||
.name = "build-obj",
|
||||
.exec = cmdBuildObj,
|
||||
},
|
||||
Command{
|
||||
.name = "fmt",
|
||||
.exec = cmdFmt,
|
||||
},
|
||||
Command{
|
||||
.name = "run",
|
||||
.exec = cmdRun,
|
||||
},
|
||||
Command{
|
||||
.name = "targets",
|
||||
.exec = cmdTargets,
|
||||
},
|
||||
Command{
|
||||
.name = "test",
|
||||
.exec = cmdTest,
|
||||
},
|
||||
Command{
|
||||
.name = "translate-c",
|
||||
.exec = cmdTranslateC,
|
||||
},
|
||||
Command{
|
||||
.name = "version",
|
||||
.exec = cmdVersion,
|
||||
},
|
||||
Command{
|
||||
.name = "zen",
|
||||
.exec = cmdZen,
|
||||
},
|
||||
|
||||
// undocumented commands
|
||||
Command { .name = "help", .exec = cmdHelp },
|
||||
Command { .name = "internal", .exec = cmdInternal },
|
||||
Command{
|
||||
.name = "help",
|
||||
.exec = cmdHelp,
|
||||
},
|
||||
Command{
|
||||
.name = "internal",
|
||||
.exec = cmdInternal,
|
||||
},
|
||||
};
|
||||
|
||||
for (commands) |command| {
|
||||
@ -321,11 +360,19 @@ const usage_build_generic =
|
||||
|
||||
const args_build_generic = []Flag{
|
||||
Flag.Bool("--help"),
|
||||
Flag.Option("--color", []const []const u8 { "auto", "off", "on" }),
|
||||
Flag.Option("--color", []const []const u8{
|
||||
"auto",
|
||||
"off",
|
||||
"on",
|
||||
}),
|
||||
|
||||
Flag.ArgMergeN("--assembly", 1),
|
||||
Flag.Arg1("--cache-dir"),
|
||||
Flag.Option("--emit", []const []const u8 { "asm", "bin", "llvm-ir" }),
|
||||
Flag.Option("--emit", []const []const u8{
|
||||
"asm",
|
||||
"bin",
|
||||
"llvm-ir",
|
||||
}),
|
||||
Flag.Bool("--enable-timing-info"),
|
||||
Flag.Arg1("--libc-include-dir"),
|
||||
Flag.Arg1("--name"),
|
||||
@ -493,8 +540,7 @@ fn buildOutputType(allocator: &Allocator, args: []const []const u8, out_type: Mo
|
||||
const zig_lib_dir = introspect.resolveZigLibDir(allocator) catch os.exit(1);
|
||||
defer allocator.free(zig_lib_dir);
|
||||
|
||||
var module =
|
||||
try Module.create(
|
||||
var module = try Module.create(
|
||||
allocator,
|
||||
root_name,
|
||||
zig_root_source_file,
|
||||
@ -502,7 +548,7 @@ fn buildOutputType(allocator: &Allocator, args: []const []const u8, out_type: Mo
|
||||
out_type,
|
||||
build_mode,
|
||||
zig_lib_dir,
|
||||
full_cache_dir
|
||||
full_cache_dir,
|
||||
);
|
||||
defer module.destroy();
|
||||
|
||||
@ -641,9 +687,7 @@ const usage_fmt =
|
||||
\\
|
||||
;
|
||||
|
||||
const args_fmt_spec = []Flag {
|
||||
Flag.Bool("--help"),
|
||||
};
|
||||
const args_fmt_spec = []Flag{Flag.Bool("--help")};
|
||||
|
||||
fn cmdFmt(allocator: &Allocator, args: []const []const u8) !void {
|
||||
var flags = try Args.parse(allocator, args_fmt_spec, args);
|
||||
@ -675,7 +719,6 @@ fn cmdFmt(allocator: &Allocator, args: []const []const u8) !void {
|
||||
};
|
||||
defer tree.deinit();
|
||||
|
||||
|
||||
var error_it = tree.errors.iterator(0);
|
||||
while (error_it.next()) |parse_error| {
|
||||
const token = tree.tokens.at(parse_error.loc());
|
||||
@ -721,8 +764,7 @@ fn cmdTargets(allocator: &Allocator, args: []const []const u8) !void {
|
||||
inline while (i < @memberCount(builtin.Arch)) : (i += 1) {
|
||||
comptime const arch_tag = @memberName(builtin.Arch, i);
|
||||
// NOTE: Cannot use empty string, see #918.
|
||||
comptime const native_str =
|
||||
if (comptime mem.eql(u8, arch_tag, @tagName(builtin.arch))) " (native)\n" else "\n";
|
||||
comptime const native_str = if (comptime mem.eql(u8, arch_tag, @tagName(builtin.arch))) " (native)\n" else "\n";
|
||||
|
||||
try stdout.print(" {}{}", arch_tag, native_str);
|
||||
}
|
||||
@ -735,8 +777,7 @@ fn cmdTargets(allocator: &Allocator, args: []const []const u8) !void {
|
||||
inline while (i < @memberCount(builtin.Os)) : (i += 1) {
|
||||
comptime const os_tag = @memberName(builtin.Os, i);
|
||||
// NOTE: Cannot use empty string, see #918.
|
||||
comptime const native_str =
|
||||
if (comptime mem.eql(u8, os_tag, @tagName(builtin.os))) " (native)\n" else "\n";
|
||||
comptime const native_str = if (comptime mem.eql(u8, os_tag, @tagName(builtin.os))) " (native)\n" else "\n";
|
||||
|
||||
try stdout.print(" {}{}", os_tag, native_str);
|
||||
}
|
||||
@ -749,8 +790,7 @@ fn cmdTargets(allocator: &Allocator, args: []const []const u8) !void {
|
||||
inline while (i < @memberCount(builtin.Environ)) : (i += 1) {
|
||||
comptime const environ_tag = @memberName(builtin.Environ, i);
|
||||
// NOTE: Cannot use empty string, see #918.
|
||||
comptime const native_str =
|
||||
if (comptime mem.eql(u8, environ_tag, @tagName(builtin.environ))) " (native)\n" else "\n";
|
||||
comptime const native_str = if (comptime mem.eql(u8, environ_tag, @tagName(builtin.environ))) " (native)\n" else "\n";
|
||||
|
||||
try stdout.print(" {}{}", environ_tag, native_str);
|
||||
}
|
||||
@ -774,10 +814,7 @@ const usage_test =
|
||||
\\
|
||||
;
|
||||
|
||||
const args_test_spec = []Flag {
|
||||
Flag.Bool("--help"),
|
||||
};
|
||||
|
||||
const args_test_spec = []Flag{Flag.Bool("--help")};
|
||||
|
||||
fn cmdTest(allocator: &Allocator, args: []const []const u8) !void {
|
||||
var flags = try Args.parse(allocator, args_build_spec, args);
|
||||
@ -812,10 +849,7 @@ const usage_run =
|
||||
\\
|
||||
;
|
||||
|
||||
const args_run_spec = []Flag {
|
||||
Flag.Bool("--help"),
|
||||
};
|
||||
|
||||
const args_run_spec = []Flag{Flag.Bool("--help")};
|
||||
|
||||
fn cmdRun(allocator: &Allocator, args: []const []const u8) !void {
|
||||
var compile_args = args;
|
||||
@ -957,9 +991,10 @@ fn cmdInternal(allocator: &Allocator, args: []const []const u8) !void {
|
||||
os.exit(1);
|
||||
}
|
||||
|
||||
const sub_commands = []Command {
|
||||
Command { .name = "build-info", .exec = cmdInternalBuildInfo },
|
||||
};
|
||||
const sub_commands = []Command{Command{
|
||||
.name = "build-info",
|
||||
.exec = cmdInternalBuildInfo,
|
||||
}};
|
||||
|
||||
for (sub_commands) |sub_command| {
|
||||
if (mem.eql(u8, sub_command.name, args[0])) {
|
||||
|
@ -38,8 +38,7 @@ pub const Target = union(enum) {
|
||||
|
||||
pub fn isDarwin(self: &const Target) bool {
|
||||
return switch (self.getOs()) {
|
||||
builtin.Os.ios,
|
||||
builtin.Os.macosx => true,
|
||||
builtin.Os.ios, builtin.Os.macosx => true,
|
||||
else => false,
|
||||
};
|
||||
}
|
||||
|
@ -150,7 +150,10 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type {
|
||||
};
|
||||
|
||||
pub fn iterator(self: &const Self) Iterator {
|
||||
return Iterator { .list = self, .count = 0 };
|
||||
return Iterator{
|
||||
.list = self,
|
||||
.count = 0,
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -41,12 +41,10 @@ pub const Base64Encoder = struct {
|
||||
dest[out_index] = encoder.alphabet_chars[(source[i] >> 2) & 0x3f];
|
||||
out_index += 1;
|
||||
|
||||
dest[out_index] = encoder.alphabet_chars[((source[i] & 0x3) << 4) |
|
||||
((source[i + 1] & 0xf0) >> 4)];
|
||||
dest[out_index] = encoder.alphabet_chars[((source[i] & 0x3) << 4) | ((source[i + 1] & 0xf0) >> 4)];
|
||||
out_index += 1;
|
||||
|
||||
dest[out_index] = encoder.alphabet_chars[((source[i + 1] & 0xf) << 2) |
|
||||
((source[i + 2] & 0xc0) >> 6)];
|
||||
dest[out_index] = encoder.alphabet_chars[((source[i + 1] & 0xf) << 2) | ((source[i + 2] & 0xc0) >> 6)];
|
||||
out_index += 1;
|
||||
|
||||
dest[out_index] = encoder.alphabet_chars[source[i + 2] & 0x3f];
|
||||
@ -64,8 +62,7 @@ pub const Base64Encoder = struct {
|
||||
dest[out_index] = encoder.pad_char;
|
||||
out_index += 1;
|
||||
} else {
|
||||
dest[out_index] = encoder.alphabet_chars[((source[i] & 0x3) << 4) |
|
||||
((source[i + 1] & 0xf0) >> 4)];
|
||||
dest[out_index] = encoder.alphabet_chars[((source[i] & 0x3) << 4) | ((source[i + 1] & 0xf0) >> 4)];
|
||||
out_index += 1;
|
||||
|
||||
dest[out_index] = encoder.alphabet_chars[(source[i + 1] & 0xf) << 2];
|
||||
@ -131,26 +128,20 @@ pub const Base64Decoder = struct {
|
||||
// common case
|
||||
if (!decoder.char_in_alphabet[source[src_cursor + 2]]) return error.InvalidCharacter;
|
||||
if (!decoder.char_in_alphabet[source[src_cursor + 3]]) return error.InvalidCharacter;
|
||||
dest[dest_cursor + 0] = decoder.char_to_index[source[src_cursor + 0]] << 2 |
|
||||
decoder.char_to_index[source[src_cursor + 1]] >> 4;
|
||||
dest[dest_cursor + 1] = decoder.char_to_index[source[src_cursor + 1]] << 4 |
|
||||
decoder.char_to_index[source[src_cursor + 2]] >> 2;
|
||||
dest[dest_cursor + 2] = decoder.char_to_index[source[src_cursor + 2]] << 6 |
|
||||
decoder.char_to_index[source[src_cursor + 3]];
|
||||
dest[dest_cursor + 0] = decoder.char_to_index[source[src_cursor + 0]] << 2 | decoder.char_to_index[source[src_cursor + 1]] >> 4;
|
||||
dest[dest_cursor + 1] = decoder.char_to_index[source[src_cursor + 1]] << 4 | decoder.char_to_index[source[src_cursor + 2]] >> 2;
|
||||
dest[dest_cursor + 2] = decoder.char_to_index[source[src_cursor + 2]] << 6 | decoder.char_to_index[source[src_cursor + 3]];
|
||||
dest_cursor += 3;
|
||||
} else if (source[src_cursor + 2] != decoder.pad_char) {
|
||||
// one pad char
|
||||
if (!decoder.char_in_alphabet[source[src_cursor + 2]]) return error.InvalidCharacter;
|
||||
dest[dest_cursor + 0] = decoder.char_to_index[source[src_cursor + 0]] << 2 |
|
||||
decoder.char_to_index[source[src_cursor + 1]] >> 4;
|
||||
dest[dest_cursor + 1] = decoder.char_to_index[source[src_cursor + 1]] << 4 |
|
||||
decoder.char_to_index[source[src_cursor + 2]] >> 2;
|
||||
dest[dest_cursor + 0] = decoder.char_to_index[source[src_cursor + 0]] << 2 | decoder.char_to_index[source[src_cursor + 1]] >> 4;
|
||||
dest[dest_cursor + 1] = decoder.char_to_index[source[src_cursor + 1]] << 4 | decoder.char_to_index[source[src_cursor + 2]] >> 2;
|
||||
if (decoder.char_to_index[source[src_cursor + 2]] << 6 != 0) return error.InvalidPadding;
|
||||
dest_cursor += 2;
|
||||
} else {
|
||||
// two pad chars
|
||||
dest[dest_cursor + 0] = decoder.char_to_index[source[src_cursor + 0]] << 2 |
|
||||
decoder.char_to_index[source[src_cursor + 1]] >> 4;
|
||||
dest[dest_cursor + 0] = decoder.char_to_index[source[src_cursor + 0]] << 2 | decoder.char_to_index[source[src_cursor + 1]] >> 4;
|
||||
if (decoder.char_to_index[source[src_cursor + 1]] << 4 != 0) return error.InvalidPadding;
|
||||
dest_cursor += 1;
|
||||
}
|
||||
@ -223,10 +214,12 @@ pub const Base64DecoderWithIgnore = struct {
|
||||
} else if (decoder_with_ignore.char_is_ignored[c]) {
|
||||
// we can even ignore chars during the padding
|
||||
continue;
|
||||
} else return error.InvalidCharacter;
|
||||
} else
|
||||
return error.InvalidCharacter;
|
||||
}
|
||||
break;
|
||||
} else return error.InvalidCharacter;
|
||||
} else
|
||||
return error.InvalidCharacter;
|
||||
}
|
||||
|
||||
switch (available_chars) {
|
||||
@ -234,22 +227,17 @@ pub const Base64DecoderWithIgnore = struct {
|
||||
// common case
|
||||
if (dest_cursor + 3 > dest.len) return error.OutputTooSmall;
|
||||
assert(pad_char_count == 0);
|
||||
dest[dest_cursor + 0] = decoder.char_to_index[next_4_chars[0]] << 2 |
|
||||
decoder.char_to_index[next_4_chars[1]] >> 4;
|
||||
dest[dest_cursor + 1] = decoder.char_to_index[next_4_chars[1]] << 4 |
|
||||
decoder.char_to_index[next_4_chars[2]] >> 2;
|
||||
dest[dest_cursor + 2] = decoder.char_to_index[next_4_chars[2]] << 6 |
|
||||
decoder.char_to_index[next_4_chars[3]];
|
||||
dest[dest_cursor + 0] = decoder.char_to_index[next_4_chars[0]] << 2 | decoder.char_to_index[next_4_chars[1]] >> 4;
|
||||
dest[dest_cursor + 1] = decoder.char_to_index[next_4_chars[1]] << 4 | decoder.char_to_index[next_4_chars[2]] >> 2;
|
||||
dest[dest_cursor + 2] = decoder.char_to_index[next_4_chars[2]] << 6 | decoder.char_to_index[next_4_chars[3]];
|
||||
dest_cursor += 3;
|
||||
continue;
|
||||
},
|
||||
3 => {
|
||||
if (dest_cursor + 2 > dest.len) return error.OutputTooSmall;
|
||||
if (pad_char_count != 1) return error.InvalidPadding;
|
||||
dest[dest_cursor + 0] = decoder.char_to_index[next_4_chars[0]] << 2 |
|
||||
decoder.char_to_index[next_4_chars[1]] >> 4;
|
||||
dest[dest_cursor + 1] = decoder.char_to_index[next_4_chars[1]] << 4 |
|
||||
decoder.char_to_index[next_4_chars[2]] >> 2;
|
||||
dest[dest_cursor + 0] = decoder.char_to_index[next_4_chars[0]] << 2 | decoder.char_to_index[next_4_chars[1]] >> 4;
|
||||
dest[dest_cursor + 1] = decoder.char_to_index[next_4_chars[1]] << 4 | decoder.char_to_index[next_4_chars[2]] >> 2;
|
||||
if (decoder.char_to_index[next_4_chars[2]] << 6 != 0) return error.InvalidPadding;
|
||||
dest_cursor += 2;
|
||||
break;
|
||||
@ -257,8 +245,7 @@ pub const Base64DecoderWithIgnore = struct {
|
||||
2 => {
|
||||
if (dest_cursor + 1 > dest.len) return error.OutputTooSmall;
|
||||
if (pad_char_count != 2) return error.InvalidPadding;
|
||||
dest[dest_cursor + 0] = decoder.char_to_index[next_4_chars[0]] << 2 |
|
||||
decoder.char_to_index[next_4_chars[1]] >> 4;
|
||||
dest[dest_cursor + 0] = decoder.char_to_index[next_4_chars[0]] << 2 | decoder.char_to_index[next_4_chars[1]] >> 4;
|
||||
if (decoder.char_to_index[next_4_chars[1]] << 4 != 0) return error.InvalidPadding;
|
||||
dest_cursor += 1;
|
||||
break;
|
||||
@ -280,7 +267,6 @@ pub const Base64DecoderWithIgnore = struct {
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
pub const standard_decoder_unsafe = Base64DecoderUnsafe.init(standard_alphabet_chars, standard_pad_char);
|
||||
|
||||
pub const Base64DecoderUnsafe = struct {
|
||||
@ -321,16 +307,13 @@ pub const Base64DecoderUnsafe = struct {
|
||||
}
|
||||
|
||||
while (in_buf_len > 4) {
|
||||
dest[dest_index] = decoder.char_to_index[source[src_index + 0]] << 2 |
|
||||
decoder.char_to_index[source[src_index + 1]] >> 4;
|
||||
dest[dest_index] = decoder.char_to_index[source[src_index + 0]] << 2 | decoder.char_to_index[source[src_index + 1]] >> 4;
|
||||
dest_index += 1;
|
||||
|
||||
dest[dest_index] = decoder.char_to_index[source[src_index + 1]] << 4 |
|
||||
decoder.char_to_index[source[src_index + 2]] >> 2;
|
||||
dest[dest_index] = decoder.char_to_index[source[src_index + 1]] << 4 | decoder.char_to_index[source[src_index + 2]] >> 2;
|
||||
dest_index += 1;
|
||||
|
||||
dest[dest_index] = decoder.char_to_index[source[src_index + 2]] << 6 |
|
||||
decoder.char_to_index[source[src_index + 3]];
|
||||
dest[dest_index] = decoder.char_to_index[source[src_index + 2]] << 6 | decoder.char_to_index[source[src_index + 3]];
|
||||
dest_index += 1;
|
||||
|
||||
src_index += 4;
|
||||
@ -338,18 +321,15 @@ pub const Base64DecoderUnsafe = struct {
|
||||
}
|
||||
|
||||
if (in_buf_len > 1) {
|
||||
dest[dest_index] = decoder.char_to_index[source[src_index + 0]] << 2 |
|
||||
decoder.char_to_index[source[src_index + 1]] >> 4;
|
||||
dest[dest_index] = decoder.char_to_index[source[src_index + 0]] << 2 | decoder.char_to_index[source[src_index + 1]] >> 4;
|
||||
dest_index += 1;
|
||||
}
|
||||
if (in_buf_len > 2) {
|
||||
dest[dest_index] = decoder.char_to_index[source[src_index + 1]] << 4 |
|
||||
decoder.char_to_index[source[src_index + 2]] >> 2;
|
||||
dest[dest_index] = decoder.char_to_index[source[src_index + 1]] << 4 | decoder.char_to_index[source[src_index + 2]] >> 2;
|
||||
dest_index += 1;
|
||||
}
|
||||
if (in_buf_len > 3) {
|
||||
dest[dest_index] = decoder.char_to_index[source[src_index + 2]] << 6 |
|
||||
decoder.char_to_index[source[src_index + 3]];
|
||||
dest[dest_index] = decoder.char_to_index[source[src_index + 2]] << 6 | decoder.char_to_index[source[src_index + 3]];
|
||||
dest_index += 1;
|
||||
}
|
||||
}
|
||||
@ -367,7 +347,6 @@ fn calcDecodedSizeExactUnsafe(source: []const u8, pad_char: u8) usize {
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
test "base64" {
|
||||
@setEvalBranchQuota(8000);
|
||||
testBase64() catch unreachable;
|
||||
@ -427,8 +406,7 @@ fn testAllApis(expected_decoded: []const u8, expected_encoded: []const u8) !void
|
||||
|
||||
// Base64DecoderWithIgnore
|
||||
{
|
||||
const standard_decoder_ignore_nothing = Base64DecoderWithIgnore.init(
|
||||
standard_alphabet_chars, standard_pad_char, "");
|
||||
const standard_decoder_ignore_nothing = Base64DecoderWithIgnore.init(standard_alphabet_chars, standard_pad_char, "");
|
||||
var buffer: [0x100]u8 = undefined;
|
||||
var decoded = buffer[0..Base64DecoderWithIgnore.calcSizeUpperBound(expected_encoded.len)];
|
||||
var written = try standard_decoder_ignore_nothing.decode(decoded, expected_encoded);
|
||||
@ -446,8 +424,7 @@ fn testAllApis(expected_decoded: []const u8, expected_encoded: []const u8) !void
|
||||
}
|
||||
|
||||
fn testDecodeIgnoreSpace(expected_decoded: []const u8, encoded: []const u8) !void {
|
||||
const standard_decoder_ignore_space = Base64DecoderWithIgnore.init(
|
||||
standard_alphabet_chars, standard_pad_char, " ");
|
||||
const standard_decoder_ignore_space = Base64DecoderWithIgnore.init(standard_alphabet_chars, standard_pad_char, " ");
|
||||
var buffer: [0x100]u8 = undefined;
|
||||
var decoded = buffer[0..Base64DecoderWithIgnore.calcSizeUpperBound(encoded.len)];
|
||||
var written = try standard_decoder_ignore_space.decode(decoded, encoded);
|
||||
@ -455,8 +432,7 @@ fn testDecodeIgnoreSpace(expected_decoded: []const u8, encoded: []const u8) !voi
|
||||
}
|
||||
|
||||
fn testError(encoded: []const u8, expected_err: error) !void {
|
||||
const standard_decoder_ignore_space = Base64DecoderWithIgnore.init(
|
||||
standard_alphabet_chars, standard_pad_char, " ");
|
||||
const standard_decoder_ignore_space = Base64DecoderWithIgnore.init(standard_alphabet_chars, standard_pad_char, " ");
|
||||
var buffer: [0x100]u8 = undefined;
|
||||
if (standard_decoder.calcSize(encoded)) |decoded_size| {
|
||||
var decoded = buffer[0..decoded_size];
|
||||
@ -471,8 +447,7 @@ fn testError(encoded: []const u8, expected_err: error) !void {
|
||||
}
|
||||
|
||||
fn testOutputTooSmallError(encoded: []const u8) !void {
|
||||
const standard_decoder_ignore_space = Base64DecoderWithIgnore.init(
|
||||
standard_alphabet_chars, standard_pad_char, " ");
|
||||
const standard_decoder_ignore_space = Base64DecoderWithIgnore.init(standard_alphabet_chars, standard_pad_char, " ");
|
||||
var buffer: [0x100]u8 = undefined;
|
||||
var decoded = buffer[0..calcDecodedSizeExactUnsafe(encoded, standard_pad_char) - 1];
|
||||
if (standard_decoder_ignore_space.decode(decoded, encoded)) |_| {
|
||||
|
@ -12,9 +12,7 @@ pub const BufMap = struct {
|
||||
const BufMapHashMap = HashMap([]const u8, []const u8, mem.hash_slice_u8, mem.eql_slice_u8);
|
||||
|
||||
pub fn init(allocator: &Allocator) BufMap {
|
||||
var self = BufMap {
|
||||
.hash_map = BufMapHashMap.init(allocator),
|
||||
};
|
||||
var self = BufMap{ .hash_map = BufMapHashMap.init(allocator) };
|
||||
return self;
|
||||
}
|
||||
|
||||
|
@ -10,9 +10,7 @@ pub const BufSet = struct {
|
||||
const BufSetHashMap = HashMap([]const u8, void, mem.hash_slice_u8, mem.eql_slice_u8);
|
||||
|
||||
pub fn init(a: &Allocator) BufSet {
|
||||
var self = BufSet {
|
||||
.hash_map = BufSetHashMap.init(a),
|
||||
};
|
||||
var self = BufSet{ .hash_map = BufSetHashMap.init(a) };
|
||||
return self;
|
||||
}
|
||||
|
||||
|
@ -420,15 +420,7 @@ pub const Builder = struct {
|
||||
const release_fast = self.option(bool, "release-fast", "optimizations on and safety off") ?? false;
|
||||
const release_small = self.option(bool, "release-small", "size optimizations on and safety off") ?? false;
|
||||
|
||||
const mode = if (release_safe and !release_fast and !release_small)
|
||||
builtin.Mode.ReleaseSafe
|
||||
else if (release_fast and !release_safe and !release_small)
|
||||
builtin.Mode.ReleaseFast
|
||||
else if (release_small and !release_fast and !release_safe)
|
||||
builtin.Mode.ReleaseSmall
|
||||
else if (!release_fast and !release_safe and !release_small)
|
||||
builtin.Mode.Debug
|
||||
else x: {
|
||||
const mode = if (release_safe and !release_fast and !release_small) builtin.Mode.ReleaseSafe else if (release_fast and !release_safe and !release_small) builtin.Mode.ReleaseFast else if (release_small and !release_fast and !release_safe) builtin.Mode.ReleaseSmall else if (!release_fast and !release_safe and !release_small) builtin.Mode.Debug else x: {
|
||||
warn("Multiple release modes (of -Drelease-safe, -Drelease-fast and -Drelease-small)");
|
||||
self.markInvalidUserInput();
|
||||
break :x builtin.Mode.Debug;
|
||||
@ -649,11 +641,7 @@ pub const Builder = struct {
|
||||
if (builtin.environ == builtin.Environ.msvc) {
|
||||
return "cl.exe";
|
||||
} else {
|
||||
return os.getEnvVarOwned(self.allocator, "CC") catch |err|
|
||||
if (err == error.EnvironmentVariableNotFound)
|
||||
([]const u8)("cc")
|
||||
else
|
||||
debug.panic("Unable to get environment variable: {}", err);
|
||||
return os.getEnvVarOwned(self.allocator, "CC") catch |err| if (err == error.EnvironmentVariableNotFound) ([]const u8)("cc") else debug.panic("Unable to get environment variable: {}", err);
|
||||
}
|
||||
}
|
||||
|
||||
@ -782,8 +770,7 @@ pub const Target = union(enum) {
|
||||
|
||||
pub fn isDarwin(self: &const Target) bool {
|
||||
return switch (self.getOs()) {
|
||||
builtin.Os.ios,
|
||||
builtin.Os.macosx => true,
|
||||
builtin.Os.ios, builtin.Os.macosx => true,
|
||||
else => false,
|
||||
};
|
||||
}
|
||||
@ -990,8 +977,7 @@ pub const LibExeObjStep = struct {
|
||||
self.out_filename = self.builder.fmt("lib{}.a", self.name);
|
||||
} else {
|
||||
switch (self.target.getOs()) {
|
||||
builtin.Os.ios,
|
||||
builtin.Os.macosx => {
|
||||
builtin.Os.ios, builtin.Os.macosx => {
|
||||
self.out_filename = self.builder.fmt("lib{}.{d}.{d}.{d}.dylib", self.name, self.version.major, self.version.minor, self.version.patch);
|
||||
self.major_only_filename = self.builder.fmt("lib{}.{d}.dylib", self.name, self.version.major);
|
||||
self.name_only_filename = self.builder.fmt("lib{}.dylib", self.name);
|
||||
@ -1011,11 +997,13 @@ pub const LibExeObjStep = struct {
|
||||
}
|
||||
|
||||
pub fn setTarget(self: &LibExeObjStep, target_arch: builtin.Arch, target_os: builtin.Os, target_environ: builtin.Environ) void {
|
||||
self.target = Target{ .Cross = CrossTarget{
|
||||
self.target = Target{
|
||||
.Cross = CrossTarget{
|
||||
.arch = target_arch,
|
||||
.os = target_os,
|
||||
.environ = target_environ,
|
||||
} };
|
||||
},
|
||||
};
|
||||
self.computeOutFileNames();
|
||||
}
|
||||
|
||||
@ -1079,10 +1067,7 @@ pub const LibExeObjStep = struct {
|
||||
}
|
||||
|
||||
pub fn getOutputPath(self: &LibExeObjStep) []const u8 {
|
||||
return if (self.output_path) |output_path|
|
||||
output_path
|
||||
else
|
||||
os.path.join(self.builder.allocator, self.builder.cache_root, self.out_filename) catch unreachable;
|
||||
return if (self.output_path) |output_path| output_path else os.path.join(self.builder.allocator, self.builder.cache_root, self.out_filename) catch unreachable;
|
||||
}
|
||||
|
||||
pub fn setOutputHPath(self: &LibExeObjStep, file_path: []const u8) void {
|
||||
@ -1095,10 +1080,7 @@ pub const LibExeObjStep = struct {
|
||||
}
|
||||
|
||||
pub fn getOutputHPath(self: &LibExeObjStep) []const u8 {
|
||||
return if (self.output_h_path) |output_h_path|
|
||||
output_h_path
|
||||
else
|
||||
os.path.join(self.builder.allocator, self.builder.cache_root, self.out_h_filename) catch unreachable;
|
||||
return if (self.output_h_path) |output_h_path| output_h_path else os.path.join(self.builder.allocator, self.builder.cache_root, self.out_h_filename) catch unreachable;
|
||||
}
|
||||
|
||||
pub fn addAssemblyFile(self: &LibExeObjStep, path: []const u8) void {
|
||||
@ -1352,8 +1334,7 @@ pub const LibExeObjStep = struct {
|
||||
args.append("ssp-buffer-size=4") catch unreachable;
|
||||
}
|
||||
},
|
||||
builtin.Mode.ReleaseFast,
|
||||
builtin.Mode.ReleaseSmall => {
|
||||
builtin.Mode.ReleaseFast, builtin.Mode.ReleaseSmall => {
|
||||
args.append("-O2") catch unreachable;
|
||||
args.append("-fno-stack-protector") catch unreachable;
|
||||
},
|
||||
@ -1652,11 +1633,13 @@ pub const TestStep = struct {
|
||||
}
|
||||
|
||||
pub fn setTarget(self: &TestStep, target_arch: builtin.Arch, target_os: builtin.Os, target_environ: builtin.Environ) void {
|
||||
self.target = Target{ .Cross = CrossTarget{
|
||||
self.target = Target{
|
||||
.Cross = CrossTarget{
|
||||
.arch = target_arch,
|
||||
.os = target_os,
|
||||
.environ = target_environ,
|
||||
} };
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
pub fn setExecCmd(self: &TestStep, args: []const ?[]const u8) void {
|
||||
|
@ -21,8 +21,7 @@ pub extern "c" fn raise(sig: c_int) c_int;
|
||||
pub extern "c" fn read(fd: c_int, buf: &c_void, nbyte: usize) isize;
|
||||
pub extern "c" fn stat(noalias path: &const u8, noalias buf: &Stat) c_int;
|
||||
pub extern "c" fn write(fd: c_int, buf: &const c_void, nbyte: usize) isize;
|
||||
pub extern "c" fn mmap(addr: ?&c_void, len: usize, prot: c_int, flags: c_int,
|
||||
fd: c_int, offset: isize) ?&c_void;
|
||||
pub extern "c" fn mmap(addr: ?&c_void, len: usize, prot: c_int, flags: c_int, fd: c_int, offset: isize) ?&c_void;
|
||||
pub extern "c" fn munmap(addr: &c_void, len: usize) c_int;
|
||||
pub extern "c" fn unlink(path: &const u8) c_int;
|
||||
pub extern "c" fn getcwd(buf: &u8, size: usize) ?&u8;
|
||||
@ -34,8 +33,7 @@ pub extern "c" fn mkdir(path: &const u8, mode: c_uint) c_int;
|
||||
pub extern "c" fn symlink(existing: &const u8, new: &const u8) c_int;
|
||||
pub extern "c" fn rename(old: &const u8, new: &const u8) c_int;
|
||||
pub extern "c" fn chdir(path: &const u8) c_int;
|
||||
pub extern "c" fn execve(path: &const u8, argv: &const ?&const u8,
|
||||
envp: &const ?&const u8) c_int;
|
||||
pub extern "c" fn execve(path: &const u8, argv: &const ?&const u8, envp: &const ?&const u8) c_int;
|
||||
pub extern "c" fn dup(fd: c_int) c_int;
|
||||
pub extern "c" fn dup2(old_fd: c_int, new_fd: c_int) c_int;
|
||||
pub extern "c" fn readlink(noalias path: &const u8, noalias buf: &u8, bufsize: usize) isize;
|
||||
@ -54,9 +52,7 @@ pub extern "c" fn realloc(&c_void, usize) ?&c_void;
|
||||
pub extern "c" fn free(&c_void) void;
|
||||
pub extern "c" fn posix_memalign(memptr: &&c_void, alignment: usize, size: usize) c_int;
|
||||
|
||||
pub extern "pthread" fn pthread_create(noalias newthread: &pthread_t,
|
||||
noalias attr: ?&const pthread_attr_t, start_routine: extern fn(?&c_void) ?&c_void,
|
||||
noalias arg: ?&c_void) c_int;
|
||||
pub extern "pthread" fn pthread_create(noalias newthread: &pthread_t, noalias attr: ?&const pthread_attr_t, start_routine: extern fn(?&c_void) ?&c_void, noalias arg: ?&c_void) c_int;
|
||||
pub extern "pthread" fn pthread_attr_init(attr: &pthread_attr_t) c_int;
|
||||
pub extern "pthread" fn pthread_attr_setstack(attr: &pthread_attr_t, stackaddr: &c_void, stacksize: usize) c_int;
|
||||
pub extern "pthread" fn pthread_attr_destroy(attr: &pthread_attr_t) c_int;
|
||||
|
@ -6,12 +6,25 @@ const debug = @import("../debug/index.zig");
|
||||
const fmt = @import("../fmt/index.zig");
|
||||
|
||||
const RoundParam = struct {
|
||||
a: usize, b: usize, c: usize, d: usize,
|
||||
k: usize, s: u32, t: u32
|
||||
a: usize,
|
||||
b: usize,
|
||||
c: usize,
|
||||
d: usize,
|
||||
k: usize,
|
||||
s: u32,
|
||||
t: u32,
|
||||
};
|
||||
|
||||
fn Rp(a: usize, b: usize, c: usize, d: usize, k: usize, s: u32, t: u32) RoundParam {
|
||||
return RoundParam { .a = a, .b = b, .c = c, .d = d, .k = k, .s = s, .t = t };
|
||||
return RoundParam{
|
||||
.a = a,
|
||||
.b = b,
|
||||
.c = c,
|
||||
.d = d,
|
||||
.k = k,
|
||||
.s = s,
|
||||
.t = t,
|
||||
};
|
||||
}
|
||||
|
||||
pub const Md5 = struct {
|
||||
@ -119,7 +132,10 @@ pub const Md5 = struct {
|
||||
}
|
||||
|
||||
var v: [4]u32 = []u32{
|
||||
d.s[0], d.s[1], d.s[2], d.s[3],
|
||||
d.s[0],
|
||||
d.s[1],
|
||||
d.s[2],
|
||||
d.s[3],
|
||||
};
|
||||
|
||||
const round0 = comptime []RoundParam{
|
||||
|
@ -7,11 +7,23 @@ const builtin = @import("builtin");
|
||||
pub const u160 = @IntType(false, 160);
|
||||
|
||||
const RoundParam = struct {
|
||||
a: usize, b: usize, c: usize, d: usize, e: usize, i: u32,
|
||||
a: usize,
|
||||
b: usize,
|
||||
c: usize,
|
||||
d: usize,
|
||||
e: usize,
|
||||
i: u32,
|
||||
};
|
||||
|
||||
fn Rp(a: usize, b: usize, c: usize, d: usize, e: usize, i: u32) RoundParam {
|
||||
return RoundParam { .a = a, .b = b, .c = c, .d = d, .e = e, .i = i };
|
||||
return RoundParam{
|
||||
.a = a,
|
||||
.b = b,
|
||||
.c = c,
|
||||
.d = d,
|
||||
.e = e,
|
||||
.i = i,
|
||||
};
|
||||
}
|
||||
|
||||
pub const Sha1 = struct {
|
||||
@ -109,7 +121,11 @@ pub const Sha1 = struct {
|
||||
var s: [16]u32 = undefined;
|
||||
|
||||
var v: [5]u32 = []u32{
|
||||
d.s[0], d.s[1], d.s[2], d.s[3], d.s[4],
|
||||
d.s[0],
|
||||
d.s[1],
|
||||
d.s[2],
|
||||
d.s[3],
|
||||
d.s[4],
|
||||
};
|
||||
|
||||
const round0a = comptime []RoundParam{
|
||||
@ -131,13 +147,9 @@ pub const Sha1 = struct {
|
||||
Rp(0, 1, 2, 3, 4, 15),
|
||||
};
|
||||
inline for (round0a) |r| {
|
||||
s[r.i] = (u32(b[r.i * 4 + 0]) << 24) |
|
||||
(u32(b[r.i * 4 + 1]) << 16) |
|
||||
(u32(b[r.i * 4 + 2]) << 8) |
|
||||
(u32(b[r.i * 4 + 3]) << 0);
|
||||
s[r.i] = (u32(b[r.i * 4 + 0]) << 24) | (u32(b[r.i * 4 + 1]) << 16) | (u32(b[r.i * 4 + 2]) << 8) | (u32(b[r.i * 4 + 3]) << 0);
|
||||
|
||||
v[r.e] = v[r.e] +% math.rotl(u32, v[r.a], u32(5)) +% 0x5A827999 +% s[r.i & 0xf]
|
||||
+% ((v[r.b] & v[r.c]) | (~v[r.b] & v[r.d]));
|
||||
v[r.e] = v[r.e] +% math.rotl(u32, v[r.a], u32(5)) +% 0x5A827999 +% s[r.i & 0xf] +% ((v[r.b] & v[r.c]) | (~v[r.b] & v[r.d]));
|
||||
v[r.b] = math.rotl(u32, v[r.b], u32(30));
|
||||
}
|
||||
|
||||
@ -151,8 +163,7 @@ pub const Sha1 = struct {
|
||||
const t = s[(r.i - 3) & 0xf] ^ s[(r.i - 8) & 0xf] ^ s[(r.i - 14) & 0xf] ^ s[(r.i - 16) & 0xf];
|
||||
s[r.i & 0xf] = math.rotl(u32, t, u32(1));
|
||||
|
||||
v[r.e] = v[r.e] +% math.rotl(u32, v[r.a], u32(5)) +% 0x5A827999 +% s[r.i & 0xf]
|
||||
+% ((v[r.b] & v[r.c]) | (~v[r.b] & v[r.d]));
|
||||
v[r.e] = v[r.e] +% math.rotl(u32, v[r.a], u32(5)) +% 0x5A827999 +% s[r.i & 0xf] +% ((v[r.b] & v[r.c]) | (~v[r.b] & v[r.d]));
|
||||
v[r.b] = math.rotl(u32, v[r.b], u32(30));
|
||||
}
|
||||
|
||||
@ -182,8 +193,7 @@ pub const Sha1 = struct {
|
||||
const t = s[(r.i - 3) & 0xf] ^ s[(r.i - 8) & 0xf] ^ s[(r.i - 14) & 0xf] ^ s[(r.i - 16) & 0xf];
|
||||
s[r.i & 0xf] = math.rotl(u32, t, u32(1));
|
||||
|
||||
v[r.e] = v[r.e] +% math.rotl(u32, v[r.a], u32(5)) +% 0x6ED9EBA1 +% s[r.i & 0xf]
|
||||
+% (v[r.b] ^ v[r.c] ^ v[r.d]);
|
||||
v[r.e] = v[r.e] +% math.rotl(u32, v[r.a], u32(5)) +% 0x6ED9EBA1 +% s[r.i & 0xf] +% (v[r.b] ^ v[r.c] ^ v[r.d]);
|
||||
v[r.b] = math.rotl(u32, v[r.b], u32(30));
|
||||
}
|
||||
|
||||
@ -213,8 +223,7 @@ pub const Sha1 = struct {
|
||||
const t = s[(r.i - 3) & 0xf] ^ s[(r.i - 8) & 0xf] ^ s[(r.i - 14) & 0xf] ^ s[(r.i - 16) & 0xf];
|
||||
s[r.i & 0xf] = math.rotl(u32, t, u32(1));
|
||||
|
||||
v[r.e] = v[r.e] +% math.rotl(u32, v[r.a], u32(5)) +% 0x8F1BBCDC +% s[r.i & 0xf]
|
||||
+% ((v[r.b] & v[r.c]) ^ (v[r.b] & v[r.d]) ^ (v[r.c] & v[r.d]));
|
||||
v[r.e] = v[r.e] +% math.rotl(u32, v[r.a], u32(5)) +% 0x8F1BBCDC +% s[r.i & 0xf] +% ((v[r.b] & v[r.c]) ^ (v[r.b] & v[r.d]) ^ (v[r.c] & v[r.d]));
|
||||
v[r.b] = math.rotl(u32, v[r.b], u32(30));
|
||||
}
|
||||
|
||||
@ -244,8 +253,7 @@ pub const Sha1 = struct {
|
||||
const t = s[(r.i - 3) & 0xf] ^ s[(r.i - 8) & 0xf] ^ s[(r.i - 14) & 0xf] ^ s[(r.i - 16) & 0xf];
|
||||
s[r.i & 0xf] = math.rotl(u32, t, u32(1));
|
||||
|
||||
v[r.e] = v[r.e] +% math.rotl(u32, v[r.a], u32(5)) +% 0xCA62C1D6 +% s[r.i & 0xf]
|
||||
+% (v[r.b] ^ v[r.c] ^ v[r.d]);
|
||||
v[r.e] = v[r.e] +% math.rotl(u32, v[r.a], u32(5)) +% 0xCA62C1D6 +% s[r.i & 0xf] +% (v[r.b] ^ v[r.c] ^ v[r.d]);
|
||||
v[r.b] = math.rotl(u32, v[r.b], u32(30));
|
||||
}
|
||||
|
||||
|
@ -9,12 +9,31 @@ const htest = @import("test.zig");
|
||||
// Sha224 + Sha256
|
||||
|
||||
const RoundParam256 = struct {
|
||||
a: usize, b: usize, c: usize, d: usize, e: usize, f: usize, g: usize, h: usize,
|
||||
i: usize, k: u32,
|
||||
a: usize,
|
||||
b: usize,
|
||||
c: usize,
|
||||
d: usize,
|
||||
e: usize,
|
||||
f: usize,
|
||||
g: usize,
|
||||
h: usize,
|
||||
i: usize,
|
||||
k: u32,
|
||||
};
|
||||
|
||||
fn Rp256(a: usize, b: usize, c: usize, d: usize, e: usize, f: usize, g: usize, h: usize, i: usize, k: u32) RoundParam256 {
|
||||
return RoundParam256 { .a = a, .b = b, .c = c, .d = d, .e = e, .f = f, .g = g, .h = h, .i = i, .k = k };
|
||||
return RoundParam256{
|
||||
.a = a,
|
||||
.b = b,
|
||||
.c = c,
|
||||
.d = d,
|
||||
.e = e,
|
||||
.f = f,
|
||||
.g = g,
|
||||
.h = h,
|
||||
.i = i,
|
||||
.k = k,
|
||||
};
|
||||
}
|
||||
|
||||
const Sha2Params32 = struct {
|
||||
@ -56,7 +75,8 @@ const Sha256Params = Sha2Params32 {
|
||||
pub const Sha224 = Sha2_32(Sha224Params);
|
||||
pub const Sha256 = Sha2_32(Sha256Params);
|
||||
|
||||
fn Sha2_32(comptime params: Sha2Params32) type { return struct {
|
||||
fn Sha2_32(comptime params: Sha2Params32) type {
|
||||
return struct {
|
||||
const Self = this;
|
||||
const block_size = 64;
|
||||
const digest_size = params.out_len / 8;
|
||||
@ -165,14 +185,18 @@ fn Sha2_32(comptime params: Sha2Params32) type { return struct {
|
||||
s[i] |= u32(b[i * 4 + 3]) << 0;
|
||||
}
|
||||
while (i < 64) : (i += 1) {
|
||||
s[i] =
|
||||
s[i-16] +% s[i-7] +%
|
||||
(math.rotr(u32, s[i-15], u32(7)) ^ math.rotr(u32, s[i-15], u32(18)) ^ (s[i-15] >> 3)) +%
|
||||
(math.rotr(u32, s[i-2], u32(17)) ^ math.rotr(u32, s[i-2], u32(19)) ^ (s[i-2] >> 10));
|
||||
s[i] = s[i - 16] +% s[i - 7] +% (math.rotr(u32, s[i - 15], u32(7)) ^ math.rotr(u32, s[i - 15], u32(18)) ^ (s[i - 15] >> 3)) +% (math.rotr(u32, s[i - 2], u32(17)) ^ math.rotr(u32, s[i - 2], u32(19)) ^ (s[i - 2] >> 10));
|
||||
}
|
||||
|
||||
var v: [8]u32 = []u32{
|
||||
d.s[0], d.s[1], d.s[2], d.s[3], d.s[4], d.s[5], d.s[6], d.s[7],
|
||||
d.s[0],
|
||||
d.s[1],
|
||||
d.s[2],
|
||||
d.s[3],
|
||||
d.s[4],
|
||||
d.s[5],
|
||||
d.s[6],
|
||||
d.s[7],
|
||||
};
|
||||
|
||||
const round0 = comptime []RoundParam256{
|
||||
@ -242,18 +266,11 @@ fn Sha2_32(comptime params: Sha2Params32) type { return struct {
|
||||
Rp256(1, 2, 3, 4, 5, 6, 7, 0, 63, 0xC67178F2),
|
||||
};
|
||||
inline for (round0) |r| {
|
||||
v[r.h] =
|
||||
v[r.h] +%
|
||||
(math.rotr(u32, v[r.e], u32(6)) ^ math.rotr(u32, v[r.e], u32(11)) ^ math.rotr(u32, v[r.e], u32(25))) +%
|
||||
(v[r.g] ^ (v[r.e] & (v[r.f] ^ v[r.g]))) +%
|
||||
r.k +% s[r.i];
|
||||
v[r.h] = v[r.h] +% (math.rotr(u32, v[r.e], u32(6)) ^ math.rotr(u32, v[r.e], u32(11)) ^ math.rotr(u32, v[r.e], u32(25))) +% (v[r.g] ^ (v[r.e] & (v[r.f] ^ v[r.g]))) +% r.k +% s[r.i];
|
||||
|
||||
v[r.d] = v[r.d] +% v[r.h];
|
||||
|
||||
v[r.h] =
|
||||
v[r.h] +%
|
||||
(math.rotr(u32, v[r.a], u32(2)) ^ math.rotr(u32, v[r.a], u32(13)) ^ math.rotr(u32, v[r.a], u32(22))) +%
|
||||
((v[r.a] & (v[r.b] | v[r.c])) | (v[r.b] & v[r.c]));
|
||||
v[r.h] = v[r.h] +% (math.rotr(u32, v[r.a], u32(2)) ^ math.rotr(u32, v[r.a], u32(13)) ^ math.rotr(u32, v[r.a], u32(22))) +% ((v[r.a] & (v[r.b] | v[r.c])) | (v[r.b] & v[r.c]));
|
||||
}
|
||||
|
||||
d.s[0] +%= v[0];
|
||||
@ -265,7 +282,8 @@ fn Sha2_32(comptime params: Sha2Params32) type { return struct {
|
||||
d.s[6] +%= v[6];
|
||||
d.s[7] +%= v[7];
|
||||
}
|
||||
};}
|
||||
};
|
||||
}
|
||||
|
||||
test "sha224 single" {
|
||||
htest.assertEqualHash(Sha224, "d14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f", "");
|
||||
@ -328,17 +346,35 @@ test "sha256 aligned final" {
|
||||
h.final(out[0..]);
|
||||
}
|
||||
|
||||
|
||||
/////////////////////
|
||||
// Sha384 + Sha512
|
||||
|
||||
const RoundParam512 = struct {
|
||||
a: usize, b: usize, c: usize, d: usize, e: usize, f: usize, g: usize, h: usize,
|
||||
i: usize, k: u64,
|
||||
a: usize,
|
||||
b: usize,
|
||||
c: usize,
|
||||
d: usize,
|
||||
e: usize,
|
||||
f: usize,
|
||||
g: usize,
|
||||
h: usize,
|
||||
i: usize,
|
||||
k: u64,
|
||||
};
|
||||
|
||||
fn Rp512(a: usize, b: usize, c: usize, d: usize, e: usize, f: usize, g: usize, h: usize, i: usize, k: u64) RoundParam512 {
|
||||
return RoundParam512 { .a = a, .b = b, .c = c, .d = d, .e = e, .f = f, .g = g, .h = h, .i = i, .k = k };
|
||||
return RoundParam512{
|
||||
.a = a,
|
||||
.b = b,
|
||||
.c = c,
|
||||
.d = d,
|
||||
.e = e,
|
||||
.f = f,
|
||||
.g = g,
|
||||
.h = h,
|
||||
.i = i,
|
||||
.k = k,
|
||||
};
|
||||
}
|
||||
|
||||
const Sha2Params64 = struct {
|
||||
@ -374,13 +410,14 @@ const Sha512Params = Sha2Params64 {
|
||||
.iv5 = 0x9B05688C2B3E6C1F,
|
||||
.iv6 = 0x1F83D9ABFB41BD6B,
|
||||
.iv7 = 0x5BE0CD19137E2179,
|
||||
.out_len = 512
|
||||
.out_len = 512,
|
||||
};
|
||||
|
||||
pub const Sha384 = Sha2_64(Sha384Params);
|
||||
pub const Sha512 = Sha2_64(Sha512Params);
|
||||
|
||||
fn Sha2_64(comptime params: Sha2Params64) type { return struct {
|
||||
fn Sha2_64(comptime params: Sha2Params64) type {
|
||||
return struct {
|
||||
const Self = this;
|
||||
const block_size = 128;
|
||||
const digest_size = params.out_len / 8;
|
||||
@ -493,14 +530,18 @@ fn Sha2_64(comptime params: Sha2Params64) type { return struct {
|
||||
s[i] |= u64(b[i * 8 + 7]) << 0;
|
||||
}
|
||||
while (i < 80) : (i += 1) {
|
||||
s[i] =
|
||||
s[i-16] +% s[i-7] +%
|
||||
(math.rotr(u64, s[i-15], u64(1)) ^ math.rotr(u64, s[i-15], u64(8)) ^ (s[i-15] >> 7)) +%
|
||||
(math.rotr(u64, s[i-2], u64(19)) ^ math.rotr(u64, s[i-2], u64(61)) ^ (s[i-2] >> 6));
|
||||
s[i] = s[i - 16] +% s[i - 7] +% (math.rotr(u64, s[i - 15], u64(1)) ^ math.rotr(u64, s[i - 15], u64(8)) ^ (s[i - 15] >> 7)) +% (math.rotr(u64, s[i - 2], u64(19)) ^ math.rotr(u64, s[i - 2], u64(61)) ^ (s[i - 2] >> 6));
|
||||
}
|
||||
|
||||
var v: [8]u64 = []u64{
|
||||
d.s[0], d.s[1], d.s[2], d.s[3], d.s[4], d.s[5], d.s[6], d.s[7],
|
||||
d.s[0],
|
||||
d.s[1],
|
||||
d.s[2],
|
||||
d.s[3],
|
||||
d.s[4],
|
||||
d.s[5],
|
||||
d.s[6],
|
||||
d.s[7],
|
||||
};
|
||||
|
||||
const round0 = comptime []RoundParam512{
|
||||
@ -586,18 +627,11 @@ fn Sha2_64(comptime params: Sha2Params64) type { return struct {
|
||||
Rp512(1, 2, 3, 4, 5, 6, 7, 0, 79, 0x6C44198C4A475817),
|
||||
};
|
||||
inline for (round0) |r| {
|
||||
v[r.h] =
|
||||
v[r.h] +%
|
||||
(math.rotr(u64, v[r.e], u64(14)) ^ math.rotr(u64, v[r.e], u64(18)) ^ math.rotr(u64, v[r.e], u64(41))) +%
|
||||
(v[r.g] ^ (v[r.e] & (v[r.f] ^ v[r.g]))) +%
|
||||
r.k +% s[r.i];
|
||||
v[r.h] = v[r.h] +% (math.rotr(u64, v[r.e], u64(14)) ^ math.rotr(u64, v[r.e], u64(18)) ^ math.rotr(u64, v[r.e], u64(41))) +% (v[r.g] ^ (v[r.e] & (v[r.f] ^ v[r.g]))) +% r.k +% s[r.i];
|
||||
|
||||
v[r.d] = v[r.d] +% v[r.h];
|
||||
|
||||
v[r.h] =
|
||||
v[r.h] +%
|
||||
(math.rotr(u64, v[r.a], u64(28)) ^ math.rotr(u64, v[r.a], u64(34)) ^ math.rotr(u64, v[r.a], u64(39))) +%
|
||||
((v[r.a] & (v[r.b] | v[r.c])) | (v[r.b] & v[r.c]));
|
||||
v[r.h] = v[r.h] +% (math.rotr(u64, v[r.a], u64(28)) ^ math.rotr(u64, v[r.a], u64(34)) ^ math.rotr(u64, v[r.a], u64(39))) +% ((v[r.a] & (v[r.b] | v[r.c])) | (v[r.b] & v[r.c]));
|
||||
}
|
||||
|
||||
d.s[0] +%= v[0];
|
||||
@ -609,7 +643,8 @@ fn Sha2_64(comptime params: Sha2Params64) type { return struct {
|
||||
d.s[6] +%= v[6];
|
||||
d.s[7] +%= v[7];
|
||||
}
|
||||
};}
|
||||
};
|
||||
}
|
||||
|
||||
test "sha384 single" {
|
||||
const h1 = "38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b";
|
||||
|
@ -9,7 +9,6 @@ pub const line_sep = switch (builtin.os) {
|
||||
else => "\n",
|
||||
};
|
||||
|
||||
|
||||
pub fn len(ptr: &const u8) usize {
|
||||
var count: usize = 0;
|
||||
while (ptr[count] != 0) : (count += 1) {}
|
||||
@ -107,4 +106,3 @@ pub const NullTerminated2DArray = struct {
|
||||
self.allocator.free(buf[0..self.byte_count]);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -227,8 +227,7 @@ fn printSourceAtAddress(debug_info: &ElfStackTrace, out_stream: var, address: us
|
||||
else => return err,
|
||||
}
|
||||
} else |err| switch (err) {
|
||||
error.MissingDebugInfo,
|
||||
error.InvalidDebugInfo => {
|
||||
error.MissingDebugInfo, error.InvalidDebugInfo => {
|
||||
try out_stream.print(ptr_hex ++ " in ??? ({})\n", address, compile_unit_name);
|
||||
},
|
||||
else => return err,
|
||||
@ -597,10 +596,12 @@ fn parseFormValueBlock(allocator: &mem.Allocator, in_stream: var, size: usize) !
|
||||
}
|
||||
|
||||
fn parseFormValueConstant(allocator: &mem.Allocator, in_stream: var, signed: bool, size: usize) !FormValue {
|
||||
return FormValue{ .Const = Constant{
|
||||
return FormValue{
|
||||
.Const = Constant{
|
||||
.signed = signed,
|
||||
.payload = try readAllocBytes(allocator, in_stream, size),
|
||||
} };
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
fn parseFormValueDwarfOffsetSize(in_stream: var, is_64: bool) !u64 {
|
||||
@ -645,8 +646,7 @@ fn parseFormValue(allocator: &mem.Allocator, in_stream: var, form_id: u64, is_64
|
||||
DW.FORM_data2 => parseFormValueConstant(allocator, in_stream, false, 2),
|
||||
DW.FORM_data4 => parseFormValueConstant(allocator, in_stream, false, 4),
|
||||
DW.FORM_data8 => parseFormValueConstant(allocator, in_stream, false, 8),
|
||||
DW.FORM_udata,
|
||||
DW.FORM_sdata => {
|
||||
DW.FORM_udata, DW.FORM_sdata => {
|
||||
const block_len = try readULeb128(in_stream);
|
||||
const signed = form_id == DW.FORM_sdata;
|
||||
return parseFormValueConstant(allocator, in_stream, signed, block_len);
|
||||
|
@ -337,7 +337,6 @@ pub const AT_PGI_lbase = 0x3a00;
|
||||
pub const AT_PGI_soffset = 0x3a01;
|
||||
pub const AT_PGI_lstride = 0x3a02;
|
||||
|
||||
|
||||
pub const OP_addr = 0x03;
|
||||
pub const OP_deref = 0x06;
|
||||
pub const OP_const1u = 0x08;
|
||||
@ -577,7 +576,6 @@ pub const ATE_HP_unsigned_fixed = 0x8e; // Cobol.
|
||||
pub const ATE_HP_VAX_complex_float = 0x8f; // F or G floating complex.
|
||||
pub const ATE_HP_VAX_complex_float_d = 0x90; // D floating complex.
|
||||
|
||||
|
||||
pub const CFA_advance_loc = 0x40;
|
||||
pub const CFA_offset = 0x80;
|
||||
pub const CFA_restore = 0xc0;
|
||||
|
12
std/elf.zig
12
std/elf.zig
@ -123,13 +123,11 @@ pub const DT_SYMINFO = 0x6ffffeff;
|
||||
pub const DT_ADDRRNGHI = 0x6ffffeff;
|
||||
pub const DT_ADDRNUM = 11;
|
||||
|
||||
|
||||
pub const DT_VERSYM = 0x6ffffff0;
|
||||
|
||||
pub const DT_RELACOUNT = 0x6ffffff9;
|
||||
pub const DT_RELCOUNT = 0x6ffffffa;
|
||||
|
||||
|
||||
pub const DT_FLAGS_1 = 0x6ffffffb;
|
||||
pub const DT_VERDEF = 0x6ffffffc;
|
||||
|
||||
@ -139,13 +137,10 @@ pub const DT_VERNEED = 0x6ffffffe;
|
||||
pub const DT_VERNEEDNUM = 0x6fffffff;
|
||||
pub const DT_VERSIONTAGNUM = 16;
|
||||
|
||||
|
||||
|
||||
pub const DT_AUXILIARY = 0x7ffffffd;
|
||||
pub const DT_FILTER = 0x7fffffff;
|
||||
pub const DT_EXTRANUM = 3;
|
||||
|
||||
|
||||
pub const DT_SPARC_REGISTER = 0x70000001;
|
||||
pub const DT_SPARC_NUM = 2;
|
||||
|
||||
@ -434,9 +429,7 @@ pub const Elf = struct {
|
||||
try elf.in_file.seekForward(4);
|
||||
|
||||
const header_size = try in.readInt(elf.endian, u16);
|
||||
if ((elf.is_64 and header_size != 64) or
|
||||
(!elf.is_64 and header_size != 52))
|
||||
{
|
||||
if ((elf.is_64 and header_size != 64) or (!elf.is_64 and header_size != 52)) {
|
||||
return error.InvalidFormat;
|
||||
}
|
||||
|
||||
@ -513,8 +506,7 @@ pub const Elf = struct {
|
||||
pub fn close(elf: &Elf) void {
|
||||
elf.allocator.free(elf.section_headers);
|
||||
|
||||
if (elf.auto_close_stream)
|
||||
elf.in_file.close();
|
||||
if (elf.auto_close_stream) elf.in_file.close();
|
||||
}
|
||||
|
||||
pub fn findSection(elf: &Elf, name: []const u8) !?&SectionHeader {
|
||||
|
@ -76,19 +76,14 @@ pub const TcpServer = struct {
|
||||
}
|
||||
continue;
|
||||
},
|
||||
error.ConnectionAborted,
|
||||
error.FileDescriptorClosed => continue,
|
||||
error.ConnectionAborted, error.FileDescriptorClosed => continue,
|
||||
|
||||
error.PageFault => unreachable,
|
||||
error.InvalidSyscall => unreachable,
|
||||
error.FileDescriptorNotASocket => unreachable,
|
||||
error.OperationNotSupported => unreachable,
|
||||
|
||||
error.SystemFdQuotaExceeded,
|
||||
error.SystemResources,
|
||||
error.ProtocolFailure,
|
||||
error.BlockedByFirewall,
|
||||
error.Unexpected => {
|
||||
error.SystemFdQuotaExceeded, error.SystemResources, error.ProtocolFailure, error.BlockedByFirewall, error.Unexpected => {
|
||||
@panic("TODO handle this error");
|
||||
},
|
||||
}
|
||||
@ -121,7 +116,6 @@ pub const Loop = struct {
|
||||
pub fn removeFd(self: &Loop, fd: i32) void {
|
||||
std.os.linuxEpollCtl(self.epollfd, std.os.linux.EPOLL_CTL_DEL, fd, undefined) catch {};
|
||||
}
|
||||
|
||||
async fn waitFd(self: &Loop, fd: i32) !void {
|
||||
defer self.removeFd(fd);
|
||||
suspend |p| {
|
||||
@ -169,7 +163,6 @@ test "listen on a port, send bytes, receive bytes" {
|
||||
tcp_server: TcpServer,
|
||||
|
||||
const Self = this;
|
||||
|
||||
async<&mem.Allocator> fn handler(tcp_server: &TcpServer, _addr: &const std.net.Address, _socket: &const std.os.File) void {
|
||||
const self = @fieldParentPtr(Self, "tcp_server", tcp_server);
|
||||
var socket = _socket.*; // TODO https://github.com/ziglang/zig/issues/733
|
||||
@ -184,7 +177,6 @@ test "listen on a port, send bytes, receive bytes" {
|
||||
cancel p;
|
||||
}
|
||||
}
|
||||
|
||||
async fn errorableHandler(self: &Self, _addr: &const std.net.Address, _socket: &const std.os.File) !void {
|
||||
const addr = _addr.*; // TODO https://github.com/ziglang/zig/issues/733
|
||||
var socket = _socket.*; // TODO https://github.com/ziglang/zig/issues/733
|
||||
@ -207,7 +199,6 @@ test "listen on a port, send bytes, receive bytes" {
|
||||
defer cancel p;
|
||||
loop.run();
|
||||
}
|
||||
|
||||
async fn doAsyncTest(loop: &Loop, address: &const std.net.Address) void {
|
||||
errdefer @panic("test failure");
|
||||
|
||||
|
@ -879,4 +879,3 @@ pub const enum3_data = []Slab {
|
||||
slab("32216657306260762", 218),
|
||||
slab("30423431424080128", 219),
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user