aboutsummaryrefslogtreecommitdiff
path: root/src/memory.rs
diff options
context:
space:
mode:
authorDavid Li <li.davidm96@gmail.com>2015-12-20 18:29:43 -0500
committerDavid Li <li.davidm96@gmail.com>2015-12-20 18:29:43 -0500
commit2f788d140e94d5a020b90736796d7169fcb2eab8 (patch)
tree22aa3c4b0d13b50b56f603e82c4152d759d1c755 /src/memory.rs
parentea76448fb43b760afa6a9380756b038c62ed9792 (diff)
Introduce type aliases for ISA things
Diffstat (limited to 'src/memory.rs')
-rw-r--r--src/memory.rs16
1 files changed, 7 insertions, 9 deletions
diff --git a/src/memory.rs b/src/memory.rs
index c15bd84..ffe37c4 100644
--- a/src/memory.rs
+++ b/src/memory.rs
@@ -1,8 +1,6 @@
use isa::{self, Instruction};
use binary::{Binary};
-pub type Address = usize;
-
pub struct Memory {
memory: Vec<u32>,
}
@@ -28,7 +26,7 @@ pub struct Cache {
// TODO: refactor impls into a MemoryController(?) trait
impl Memory {
- pub fn new(size: Address, binary: Binary) -> Memory {
+ pub fn new(size: isa::Address, binary: Binary) -> Memory {
let mut memory = binary.words.clone();
if size > memory.len() {
let remainder = size - memory.len();
@@ -39,12 +37,12 @@ impl Memory {
}
}
- pub fn read_word(&self, address: Address) -> Option<isa::Word> {
+ pub fn read_word(&self, address: isa::Address) -> Option<isa::Word> {
// memory is word-addressed but addresses are byte-addressed
self.memory.get(address / 4).map(Clone::clone)
}
- pub fn write_word(&mut self, address: Address, value: isa::Word) -> Option<()> {
+ pub fn write_word(&mut self, address: isa::Address, value: isa::Word) -> Option<()> {
let address = address / 4;
if address >= self.memory.len() {
None
@@ -55,7 +53,7 @@ impl Memory {
}
}
- pub fn read_instruction(&self, pc: Address) -> Option<Instruction> {
+ pub fn read_instruction(&self, pc: isa::Address) -> Option<Instruction> {
self.memory.get(pc / 4).map(Clone::clone).map(Instruction::new)
}
}
@@ -74,15 +72,15 @@ impl Cache {
}
}
- fn read_word(&self, address: Address) -> Option<isa::Word> {
+ fn read_word(&self, address: isa::Address) -> Option<isa::Word> {
None
}
- fn write_word(&mut self, address: Address, value: isa::Word) -> Option<()> {
+ fn write_word(&mut self, address: isa::Address, value: isa::Word) -> Option<()> {
None
}
- fn invalidate(&mut self, address: Address) {
+ fn invalidate(&mut self, address: isa::Address) {
}
}