Skip to content

Commit

Permalink
Implement blit instruction
Browse files Browse the repository at this point in the history
  • Loading branch information
garritfra committed Dec 15, 2022
1 parent efdf1f5 commit ba92cc6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,15 @@ pub enum Instr<'a> {
/// Loads a value from memory pointed to by source
/// `(type, source)`
Load(Type<'a>, Value),
/// `(source, destination, n)`
///
/// Copy `n` bytes from the source address to the destination address.
///
/// n must be a constant value.
///
/// ## Minimum supported QBE version
/// `1.1`
Blit(Value, Value, u64),
}

impl<'a> fmt::Display for Instr<'a> {
Expand Down Expand Up @@ -141,6 +150,7 @@ impl<'a> fmt::Display for Instr<'a> {

write!(f, "load{} {}", ty, src)
}
Self::Blit(src, dst, n) => write!(f, "blit {}, {}, {}", src, dst, n),
}
}
}
Expand Down
17 changes: 17 additions & 0 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,23 @@ fn block() {
assert_eq!(lines.next().unwrap(), "\tret %foo");
}

#[test]
fn instr_blit() {
let blk = Block {
label: "start".into(),
statements: vec![Statement::Volatile(Instr::Blit(
Value::Temporary("src".into()),
Value::Temporary("dst".into()),
4,
))],
};

let formatted = format!("{}", blk);
let mut lines = formatted.lines();
assert_eq!(lines.next().unwrap(), "@start");
assert_eq!(lines.next().unwrap(), "\tblit %src, %dst, 4");
}

#[test]
fn function() {
let func = Function {
Expand Down

0 comments on commit ba92cc6

Please sign in to comment.