about summary refs log tree commit diff
path: root/tvix/eval/src/disassembler.rs
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2022-09-02T14·44+0300
committertazjin <tazjin@tvl.su>2022-09-08T12·53+0000
commitcc526a2c873524faa83cad62bde2edda59ea7820 (patch)
treeeea6b9463b97e2d0756c8919a8ddcb95d8fbdee9 /tvix/eval/src/disassembler.rs
parenta3b19ad8be9809205e018146ccba2a6bad53d605 (diff)
feat(tvix/eval): thread codemap through to disassembler r/4747
If the disassembler feature is enabled, make sure that an Rc of the
codemap is available through the chunk.

Change-Id: I700f27ab665a704f73457b19bd2d7efc93828a16
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6414
Reviewed-by: sterni <sternenseemann@systemli.org>
Tested-by: BuildkiteCI
Diffstat (limited to 'tvix/eval/src/disassembler.rs')
-rw-r--r--tvix/eval/src/disassembler.rs13
1 files changed, 11 insertions, 2 deletions
diff --git a/tvix/eval/src/disassembler.rs b/tvix/eval/src/disassembler.rs
index bc5a64fe65e8..e3cc1f16e706 100644
--- a/tvix/eval/src/disassembler.rs
+++ b/tvix/eval/src/disassembler.rs
@@ -5,7 +5,7 @@ use std::io::{Stderr, Write};
 use tabwriter::TabWriter;
 
 use crate::chunk::Chunk;
-use crate::opcode::OpCode;
+use crate::opcode::{CodeIdx, OpCode};
 use crate::value::Value;
 
 /// Helper struct to trace runtime values and automatically flush the
@@ -38,7 +38,16 @@ impl Drop for Tracer {
 }
 
 fn disassemble_op(tw: &mut TabWriter<Stderr>, chunk: &Chunk, width: usize, offset: usize) {
-    write!(tw, "{:0width$}\t ", width = width).ok();
+    write!(tw, "{:0width$}\t ", offset, width = width).ok();
+
+    let span = chunk.get_span(CodeIdx(offset));
+
+    if offset > 0 && chunk.get_span(CodeIdx(offset - 1)) == span {
+        write!(tw, "   |\t").unwrap();
+    } else {
+        let loc = chunk.codemap.look_up_span(span);
+        write!(tw, "{:4}\t", loc.begin.line + 1).unwrap();
+    }
 
     match chunk.code[offset] {
         OpCode::OpConstant(idx) => write!(tw, "OpConstant({})\n", chunk.constant(idx)).ok(),