From 2f788d140e94d5a020b90736796d7169fcb2eab8 Mon Sep 17 00:00:00 2001 From: David Li Date: Sun, 20 Dec 2015 18:29:43 -0500 Subject: Introduce type aliases for ISA things --- src/memory.rs | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'src/memory.rs') 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, } @@ -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 { + pub fn read_word(&self, address: isa::Address) -> Option { // 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 { + pub fn read_instruction(&self, pc: isa::Address) -> Option { self.memory.get(pc / 4).map(Clone::clone).map(Instruction::new) } } @@ -74,15 +72,15 @@ impl Cache { } } - fn read_word(&self, address: Address) -> Option { + fn read_word(&self, address: isa::Address) -> Option { 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) { } } -- cgit v1.2.3