Skip to content

Commit

Permalink
Fix LLVM byte alignment for real (#803)
Browse files Browse the repository at this point in the history
Closes #794.

I've also added a test but it's a bit useless since the buggy parts all
get optimized away and we currently only run tests *with* optimizations.
  • Loading branch information
marvinborner authored Jan 27, 2025
1 parent e6a82e2 commit acb9c98
Show file tree
Hide file tree
Showing 4 changed files with 157 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ ${indentedLines(instructions.map(show).mkString("\n"))}
case DoubleType() => "double"
case PointerType() => "ptr"
case ArrayType(size, of) => s"[$size x ${show(of)}]"
case StructureType(elementTypes) => s"{${commaSeparated(elementTypes.map(show))}}"
case StructureType(elementTypes) => s"<{${commaSeparated(elementTypes.map(show))}}>"
case FunctionType(returnType, argumentTypes) => s"${show(returnType)} (${commaSeparated(argumentTypes.map(show))})"
case NamedType(name) => localName(name)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ object Transformer {
case machine.Type.Prompt() => 8 // TODO Make fat?
case machine.Type.Stack() => 8 // TODO Make fat?
case machine.Type.Int() => 8 // TODO Make fat?
case machine.Type.Byte() => 8
case machine.Type.Byte() => 1
case machine.Type.Double() => 8 // TODO Make fat?
case machine.Type.Reference(_) => 16
}
Expand Down
54 changes: 54 additions & 0 deletions examples/llvm/byte-alignment.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
1
42
2
42
42
3
42
42
42
4
42
42
42
42
5
42
42
42
42
42
6
42
42
42
42
42
42
7
42
42
42
42
42
42
42
8
42
42
42
42
42
42
42
42
9
42
42
42
42
42
42
42
42
42
101 changes: 101 additions & 0 deletions examples/llvm/byte-alignment.effekt
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
def oneByte { action: (Byte) => Unit }: Unit =
action(42.toByte)

def twoByte { action: (Byte, Byte) => Unit }: Unit =
action(42.toByte, 42.toByte)

def threeByte { action: (Byte, Byte, Byte) => Unit }: Unit =
action(42.toByte, 42.toByte, 42.toByte)

def fourByte { action: (Byte, Byte, Byte, Byte) => Unit }: Unit =
action(42.toByte, 42.toByte, 42.toByte, 42.toByte)

def fiveByte { action: (Byte, Byte, Byte, Byte, Byte) => Unit }: Unit =
action(42.toByte, 42.toByte, 42.toByte, 42.toByte, 42.toByte)

def sixByte { action: (Byte, Byte, Byte, Byte, Byte, Byte) => Unit }: Unit =
action(42.toByte, 42.toByte, 42.toByte, 42.toByte, 42.toByte, 42.toByte)

def sevenByte { action: (Byte, Byte, Byte, Byte, Byte, Byte, Byte) => Unit }: Unit =
action(42.toByte, 42.toByte, 42.toByte, 42.toByte, 42.toByte, 42.toByte, 42.toByte)

def eightByte { action: (Byte, Byte, Byte, Byte, Byte, Byte, Byte, Byte) => Unit }: Unit =
action(42.toByte, 42.toByte, 42.toByte, 42.toByte, 42.toByte, 42.toByte, 42.toByte, 42.toByte)

def nineByte { action: (Byte, Byte, Byte, Byte, Byte, Byte, Byte, Byte, Byte) => Unit }: Unit =
action(42.toByte, 42.toByte, 42.toByte, 42.toByte, 42.toByte, 42.toByte, 42.toByte, 42.toByte, 42.toByte)

def main() = {
oneByte { (b0) =>
println(1)
println(b0)
}
twoByte { (b0, b1) =>
println(2)
println(b0)
println(b1)
}
threeByte { (b0, b1, b2) =>
println(3)
println(b0)
println(b1)
println(b2)
}
fourByte { (b0, b1, b2, b3) =>
println(4)
println(b0)
println(b1)
println(b2)
println(b3)
}
fiveByte { (b0, b1, b2, b3, b4) =>
println(5)
println(b0)
println(b1)
println(b2)
println(b3)
println(b4)
}
sixByte { (b0, b1, b2, b3, b4, b5) =>
println(6)
println(b0)
println(b1)
println(b2)
println(b3)
println(b4)
println(b5)
}
sevenByte { (b0, b1, b2, b3, b4, b5, b6) =>
println(7)
println(b0)
println(b1)
println(b2)
println(b3)
println(b4)
println(b5)
println(b6)
}
eightByte { (b0, b1, b2, b3, b4, b5, b6, b7) =>
println(8)
println(b0)
println(b1)
println(b2)
println(b3)
println(b4)
println(b5)
println(b6)
println(b7)
}
nineByte { (b0, b1, b2, b3, b4, b5, b6, b7, b8) =>
println(9)
println(b0)
println(b1)
println(b2)
println(b3)
println(b4)
println(b5)
println(b6)
println(b7)
println(b8)
}
}

0 comments on commit acb9c98

Please sign in to comment.