Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement blit instruction #20

Merged
merged 2 commits into from
Dec 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ All notable changes to this project will be documented in this file.
- `Type::size()` can now correctly calculate the size of aggregate types
([#12](https://github.com/garritfra/qbe-rs/pull/12)).
- `Function::add_block()` returns a reference to the created block ([#18](https://github.com/garritfra/qbe-rs/pull/18))
- Add `blit` instruction, in preparation for QBE release 1.1 ([#20](https://github.com/garritfra/qbe-rs/pull/20)).

### Changed

Expand Down
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