Commit 1b6f6624 authored by Simon Schulz's avatar Simon Schulz

Fixed intialization bug

parent 78f02e6b
......@@ -9,7 +9,7 @@ import model.CacheModel
class SimulatedProgramException extends Exception{}
class SimulatedProgramException(message : String) extends Exception(message){}
/**
* Representation of a memory value.
......@@ -60,12 +60,12 @@ object MemVal{
class MemObject(numElements : Int, base : Int, cache : CacheModel, dataTypeSizeInByte : Int = 4) {
val map = new Array[MemVal](numElements)
for(i <- 1 to numElements-1)
for(i <- 0 to numElements-1)
map(i) = new MemVal(base + i * dataTypeSizeInByte, 0, cache)
def apply (pos : Int): MemVal =
if (pos < numElements) map(pos)
else throw new SimulatedProgramException
else throw new SimulatedProgramException("Memory access out of allocated region.")
}
/**
......@@ -84,8 +84,8 @@ abstract class Program(var name : String) {
* @return
*/
def alloc(size : Int, base : Int) : MemObject = {
if(cache == null) throw new SimulatedProgramException
if(base % cache.lineSize != 0) throw new SimulatedProgramException
if(cache == null) throw new SimulatedProgramException("No cache for program " + name + "set.")
if(base % cache.lineSize != 0) throw new SimulatedProgramException("Base address (" + base + ") must be a multiple of the cache-line size " + "(" + cache.lineSize + ")")
new MemObject(size , base, cache)
}
......
......@@ -8,13 +8,13 @@ import model.CacheModel
*/
class Test extends Program("Test") {
override def program: Int = {
val a = alloc(10, 0)
val b = alloc(10, 16384)
val c = alloc(10, 32768)
a(1) := 10
b(1) := 20
c(1) := 30
a(1) := 10
val length = 1000
val a = alloc(length, 0)
val b = alloc(length, 1024)
for(i <- 0 to length-1) {
printf("i: " + i + "\n")
a(i) := b(i)
}
return a(1)
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment