Skip to content

Commit

Permalink
added input params to generate memory files through cmd (#327)
Browse files Browse the repository at this point in the history
* added input params to generate memory files through cmd

* removed comments

---------

Co-authored-by: lanaivina <31368580+lana-shanghai@users.noreply.github.com>
  • Loading branch information
aniketpr01 and lana-shanghai authored Jan 29, 2024
1 parent 3b66658 commit 790f743
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/cmd/cmd.zig
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ var app = &cli.App{
&enable_trace,
&program_option,
&output_trace,
&output_memory,
},
// Action to be executed for the subcommand.
.target = .{ .action = .{ .exec = execute } },
Expand Down
17 changes: 9 additions & 8 deletions src/vm/cairo_run.zig
Original file line number Diff line number Diff line change
Expand Up @@ -63,24 +63,25 @@ pub fn runConfig(allocator: Allocator, config: Config) !void {
try runner.endRun();
// TODO readReturnValues necessary for builtins

if (config.output_trace) |trace_path| {
if (config.output_trace != null or config.output_memory != null) {
try runner.relocate();
}

if (config.output_trace) |trace_path| {
const trace_file = try std.fs.cwd().createFile(trace_path, .{});
defer trace_file.close();

var trace_writer = trace_file.writer();
try writeEncodedTrace(runner.relocated_trace, &trace_writer);
}

// blocked until memory relocation is implemented
// if (config.output_memory) |mem_path| {
// const mem_file = try std.fs.cwd().createFile(mem_path, .{});
// defer mem_file.close();
if (config.output_memory) |mem_path| {
const mem_file = try std.fs.cwd().createFile(mem_path, .{});
defer mem_file.close();

// var mem_writer = mem_file.writer();
// try writeEncodedMemory(runner.relocated_trace, &mem_writer);
// }
var mem_writer = mem_file.writer();
try writeEncodedMemory(runner.relocated_memory.items, &mem_writer);
}
}

const expect = std.testing.expect;
Expand Down
2 changes: 1 addition & 1 deletion src/vm/runners/cairo_runner.zig
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ pub const CairoRunner = struct {

const relocation_table = try self.vm.segments.relocateSegments(self.allocator);
try self.vm.relocateTrace(relocation_table);
// relocate_memory here
try self.relocateMemory(relocation_table);
self.relocated_trace = try self.vm.getRelocatedTrace();
}

Expand Down

0 comments on commit 790f743

Please sign in to comment.