Skip to content

Commit

Permalink
Update optimize to handle both bytes removed
Browse files Browse the repository at this point in the history
  • Loading branch information
kadenzipfel committed Oct 8, 2022
1 parent ac4c390 commit f06ba4a
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions src/peephole.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ pub fn optimize(bytecode: &Bytecode) -> Bytecode {

// Check peephole for rule violations, and place first optimized byte in bytecode
let peeped_bytes = check_rules(&mut bytes);

// Handle both bytes removed
if peeped_bytes.len() == 0 {
i += 2;
continue;
}

let byte: ByteData = peeped_bytes[0].clone();
let byte_code_index = ByteData {
code_index: code_index,
Expand Down Expand Up @@ -95,26 +102,36 @@ mod tests {
},
ByteData {
code_index: 5,
opcode: Opcode::Not,
pushdata: None,
},
ByteData {
code_index: 6,
opcode: Opcode::Not,
pushdata: None,
},
ByteData {
code_index: 7,
opcode: Opcode::Push2,
pushdata: Some(String::from("8080")),
},
ByteData {
code_index: 8,
code_index: 10,
opcode: Opcode::Push2,
pushdata: Some(String::from("8080")),
},
ByteData {
code_index: 11,
code_index: 13,
opcode: Opcode::Push1,
pushdata: Some(String::from("54")),
},
ByteData {
code_index: 12,
code_index: 14,
opcode: Opcode::Swap1,
pushdata: None,
},
ByteData {
code_index: 13,
code_index: 15,
opcode: Opcode::Add,
pushdata: None,
},
Expand Down

0 comments on commit f06ba4a

Please sign in to comment.