diff options
Diffstat (limited to 'src/main.zig')
-rw-r--r-- | src/main.zig | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/src/main.zig b/src/main.zig index dd34c53..6692799 100644 --- a/src/main.zig +++ b/src/main.zig @@ -13,16 +13,14 @@ pub fn main() !void { var args = std.process.args(); _ = args.next(); - const arg = args.next() orelse ""; - const run_path, const out_file = if (std.mem.eql(u8, arg, "run")) blk: { - const path = try std.fmt.allocPrint(allocator, "/tmp/{}.elf", .{std.crypto.random.int(u32)}); - break :blk .{ path, try std.fs.createFileAbsolute(path, .{ .mode = 0o777 }) }; - } else if (arg.len > 0) - .{ null, try std.fs.cwd().createFile(arg, .{ .mode = 0o777 }) } + const out_path = args.next(); + const out_file = if (out_path) |path| + try std.fs.cwd().createFile(path, .{ .mode = 0o777 }) else - .{ null, std.io.getStdOut() }; - defer if (run_path) |path| allocator.free(path); + std.io.getStdOut(); + const run = if (args.next()) |arg| std.mem.eql(u8, arg, "run") else false; + const output = out_file.writer(); // var br = std.io.bufferedReader(std.io.getStdIn().reader()); @@ -39,9 +37,9 @@ pub fn main() !void { // } const source = + \\1; 1; 1; 1; 1; \\print 18446744073709551615; - \\print (0 - 1); - \\print 69; + \\print (print (0 - 1)); ; var lexer: Lexer = .{ .source = source }; std.debug.print("Tokens:\n", .{}); @@ -67,15 +65,15 @@ pub fn main() !void { const elf = try codegen.create_elf(allocator, block); try output.writeAll(elf); std.debug.print("Run output:\n", .{}); - if (run_path) |path| { + if (run) { out_file.close(); std.debug.print("{}\n", .{std.process.execv( allocator, if (target.cpu.arch == .riscv64 and target.os.tag == .linux) - &.{path} + &.{out_path} else - &.{ "qemu-riscv64", path }, + &.{ "qemu-riscv64", out_path.? }, )}); } } |