Commit 5a4ee17f authored by Kunshan Wang's avatar Kunshan Wang

alignment of struct

parent 90f3e558
...@@ -83,7 +83,7 @@ object TypeSizes { ...@@ -83,7 +83,7 @@ object TypeSizes {
} }
def alignOf(ty: Type): Word = ty match { def alignOf(ty: Type): Word = ty match {
case TypeStruct(ftys) => ftys.map(sizeOf).max case TypeStruct(ftys) => ftys.map(alignOf).max
case TypeArray(et, _) => alignOf(et) case TypeArray(et, _) => alignOf(et)
case _: TypeHybrid => throw new IllegalArgumentException("Hybrid should use hybridAlignOf to probe alignment") case _: TypeHybrid => throw new IllegalArgumentException("Hybrid should use hybridAlignOf to probe alignment")
case _: TypeVoid => 1L case _: TypeVoid => 1L
......
...@@ -49,6 +49,13 @@ class UvmMemLayoutSpec extends UvmTestBase with BeforeAndAfter { ...@@ -49,6 +49,13 @@ class UvmMemLayoutSpec extends UvmTestBase with BeforeAndAfter {
alignOf(ty) shouldBe 8 alignOf(ty) shouldBe 8
} }
"Struct types which contains other aggregate types" should "recursively calculate sizes and alignments" in {
val ty1 = TypeStruct(Seq(TypeInt(8), TypeInt(16), TypeInt(32), TypeInt(64)))
val ty2 = TypeStruct(Seq(TypeInt(16), ty1, TypeInt(32)))
sizeOf(ty2) shouldBe 28
alignOf(ty2) shouldBe 8
}
"Array types" should "have the size of all elements plus padding and the alignment of its element" in { "Array types" should "have the size of all elements plus padding and the alignment of its element" in {
val ty = TypeArray(TypeInt(64), 100) val ty = TypeArray(TypeInt(64), 100)
sizeOf(ty) shouldBe 800 sizeOf(ty) shouldBe 800
......
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