Skip to content

Commit acb9c98

Browse files
authored
Fix LLVM byte alignment for real (#803)
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.
1 parent e6a82e2 commit acb9c98

File tree

4 files changed

+157
-2
lines changed

4 files changed

+157
-2
lines changed

effekt/shared/src/main/scala/effekt/generator/llvm/PrettyPrinter.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ ${indentedLines(instructions.map(show).mkString("\n"))}
141141
case DoubleType() => "double"
142142
case PointerType() => "ptr"
143143
case ArrayType(size, of) => s"[$size x ${show(of)}]"
144-
case StructureType(elementTypes) => s"{${commaSeparated(elementTypes.map(show))}}"
144+
case StructureType(elementTypes) => s"<{${commaSeparated(elementTypes.map(show))}}>"
145145
case FunctionType(returnType, argumentTypes) => s"${show(returnType)} (${commaSeparated(argumentTypes.map(show))})"
146146
case NamedType(name) => localName(name)
147147
}

effekt/shared/src/main/scala/effekt/generator/llvm/Transformer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ object Transformer {
428428
case machine.Type.Prompt() => 8 // TODO Make fat?
429429
case machine.Type.Stack() => 8 // TODO Make fat?
430430
case machine.Type.Int() => 8 // TODO Make fat?
431-
case machine.Type.Byte() => 8
431+
case machine.Type.Byte() => 1
432432
case machine.Type.Double() => 8 // TODO Make fat?
433433
case machine.Type.Reference(_) => 16
434434
}

examples/llvm/byte-alignment.check

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
1
2+
42
3+
2
4+
42
5+
42
6+
3
7+
42
8+
42
9+
42
10+
4
11+
42
12+
42
13+
42
14+
42
15+
5
16+
42
17+
42
18+
42
19+
42
20+
42
21+
6
22+
42
23+
42
24+
42
25+
42
26+
42
27+
42
28+
7
29+
42
30+
42
31+
42
32+
42
33+
42
34+
42
35+
42
36+
8
37+
42
38+
42
39+
42
40+
42
41+
42
42+
42
43+
42
44+
42
45+
9
46+
42
47+
42
48+
42
49+
42
50+
42
51+
42
52+
42
53+
42
54+
42

examples/llvm/byte-alignment.effekt

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
def oneByte { action: (Byte) => Unit }: Unit =
2+
action(42.toByte)
3+
4+
def twoByte { action: (Byte, Byte) => Unit }: Unit =
5+
action(42.toByte, 42.toByte)
6+
7+
def threeByte { action: (Byte, Byte, Byte) => Unit }: Unit =
8+
action(42.toByte, 42.toByte, 42.toByte)
9+
10+
def fourByte { action: (Byte, Byte, Byte, Byte) => Unit }: Unit =
11+
action(42.toByte, 42.toByte, 42.toByte, 42.toByte)
12+
13+
def fiveByte { action: (Byte, Byte, Byte, Byte, Byte) => Unit }: Unit =
14+
action(42.toByte, 42.toByte, 42.toByte, 42.toByte, 42.toByte)
15+
16+
def sixByte { action: (Byte, Byte, Byte, Byte, Byte, Byte) => Unit }: Unit =
17+
action(42.toByte, 42.toByte, 42.toByte, 42.toByte, 42.toByte, 42.toByte)
18+
19+
def sevenByte { action: (Byte, Byte, Byte, Byte, Byte, Byte, Byte) => Unit }: Unit =
20+
action(42.toByte, 42.toByte, 42.toByte, 42.toByte, 42.toByte, 42.toByte, 42.toByte)
21+
22+
def eightByte { action: (Byte, Byte, Byte, Byte, Byte, Byte, Byte, Byte) => Unit }: Unit =
23+
action(42.toByte, 42.toByte, 42.toByte, 42.toByte, 42.toByte, 42.toByte, 42.toByte, 42.toByte)
24+
25+
def nineByte { action: (Byte, Byte, Byte, Byte, Byte, Byte, Byte, Byte, Byte) => Unit }: Unit =
26+
action(42.toByte, 42.toByte, 42.toByte, 42.toByte, 42.toByte, 42.toByte, 42.toByte, 42.toByte, 42.toByte)
27+
28+
def main() = {
29+
oneByte { (b0) =>
30+
println(1)
31+
println(b0)
32+
}
33+
twoByte { (b0, b1) =>
34+
println(2)
35+
println(b0)
36+
println(b1)
37+
}
38+
threeByte { (b0, b1, b2) =>
39+
println(3)
40+
println(b0)
41+
println(b1)
42+
println(b2)
43+
}
44+
fourByte { (b0, b1, b2, b3) =>
45+
println(4)
46+
println(b0)
47+
println(b1)
48+
println(b2)
49+
println(b3)
50+
}
51+
fiveByte { (b0, b1, b2, b3, b4) =>
52+
println(5)
53+
println(b0)
54+
println(b1)
55+
println(b2)
56+
println(b3)
57+
println(b4)
58+
}
59+
sixByte { (b0, b1, b2, b3, b4, b5) =>
60+
println(6)
61+
println(b0)
62+
println(b1)
63+
println(b2)
64+
println(b3)
65+
println(b4)
66+
println(b5)
67+
}
68+
sevenByte { (b0, b1, b2, b3, b4, b5, b6) =>
69+
println(7)
70+
println(b0)
71+
println(b1)
72+
println(b2)
73+
println(b3)
74+
println(b4)
75+
println(b5)
76+
println(b6)
77+
}
78+
eightByte { (b0, b1, b2, b3, b4, b5, b6, b7) =>
79+
println(8)
80+
println(b0)
81+
println(b1)
82+
println(b2)
83+
println(b3)
84+
println(b4)
85+
println(b5)
86+
println(b6)
87+
println(b7)
88+
}
89+
nineByte { (b0, b1, b2, b3, b4, b5, b6, b7, b8) =>
90+
println(9)
91+
println(b0)
92+
println(b1)
93+
println(b2)
94+
println(b3)
95+
println(b4)
96+
println(b5)
97+
println(b6)
98+
println(b7)
99+
println(b8)
100+
}
101+
}

0 commit comments

Comments
 (0)