Skip to content

Commit

Permalink
use u64 as absolute addresses when converting from labels
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-ferdinand committed Oct 4, 2023
1 parent 03893cf commit f8f6beb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 19 deletions.
33 changes: 15 additions & 18 deletions triton-vm/src/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ impl LabelledInstruction {
pub const fn op_stack_size_influence(&self) -> i32 {
match self {
LabelledInstruction::Instruction(instruction) => instruction.op_stack_size_influence(),
LabelledInstruction::Label(_) => 0,
_ => 0,
}
}
}
Expand Down Expand Up @@ -453,9 +453,7 @@ pub fn convert_all_labels_to_addresses(program: &[LabelledInstruction]) -> Vec<I
.collect()
}

pub(crate) fn build_label_to_address_map(
program: &[LabelledInstruction],
) -> HashMap<String, usize> {
pub(crate) fn build_label_to_address_map(program: &[LabelledInstruction]) -> HashMap<String, u64> {
use LabelledInstruction::*;

let mut label_map = HashMap::new();
Expand All @@ -469,7 +467,7 @@ pub(crate) fn build_label_to_address_map(
entry.insert(instruction_pointer);
}
},
Instruction(instruction) => instruction_pointer += instruction.size(),
Instruction(instruction) => instruction_pointer += instruction.size() as u64,
}
}
label_map
Expand All @@ -479,20 +477,19 @@ pub(crate) fn build_label_to_address_map(
/// address as the call target. Discards all labels.
fn convert_label_to_address_for_instruction(
labelled_instruction: &LabelledInstruction,
label_map: &HashMap<String, usize>,
label_map: &HashMap<String, u64>,
) -> Option<Instruction> {
match labelled_instruction {
LabelledInstruction::Label(_) => None,
LabelledInstruction::Instruction(instruction) => {
let instruction_with_absolute_address = instruction.map_call_address(|label| {
let &absolute_address = label_map
.get(label)
.unwrap_or_else(|| panic!("Label not found: {label}"));
BFieldElement::new(absolute_address as u64)
});
Some(instruction_with_absolute_address)
}
}
let LabelledInstruction::Instruction(instruction) = labelled_instruction else {
return None;
};

let instruction_with_absolute_address = instruction.map_call_address(|label| {
label_map
.get(label)
.map(|&address| BFieldElement::new(address))
.unwrap_or_else(|| panic!("Label not found: {label}"))
});
Some(instruction_with_absolute_address)
}

const fn all_instructions_without_args() -> [AnInstruction<BFieldElement>; Instruction::COUNT] {
Expand Down
2 changes: 1 addition & 1 deletion triton-vm/src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ impl Program {
let mut state = VMState::new(&program, public_input, non_determinism);
while !state.halting {
if let Instruction::Call(address) = state.current_instruction()? {
let address = address.value() as usize;
let address = address.value();
let label = address_to_label_map[&address].to_owned();
let profile_line = ProfileLine::new(call_stack.len(), label, 0);
let profile_line_number = profile.len();
Expand Down

0 comments on commit f8f6beb

Please sign in to comment.