|
10 | 10 | import com.dat3m.dartagnan.expression.type.*;
|
11 | 11 |
|
12 | 12 | import java.util.ArrayList;
|
13 |
| -import java.util.Collections; |
14 | 13 | import java.util.List;
|
15 |
| -import java.util.stream.Collectors; |
16 | 14 | import java.util.stream.IntStream;
|
17 | 15 |
|
18 | 16 | import static com.dat3m.dartagnan.expression.integers.IntBinaryOp.ADD;
|
@@ -69,23 +67,6 @@ public static Expression getMemberAddress(String id, Expression base, Type type,
|
69 | 67 | return base;
|
70 | 68 | }
|
71 | 69 |
|
72 |
| - public static Expression getAlignedValue(String id, Expression base, Type type) { |
73 |
| - if (type instanceof AggregateType aggregateType && base instanceof ConstructExpr constructExpr) { |
74 |
| - List<Expression> elements = IntStream.range(0, aggregateType.getFields().size()) |
75 |
| - .mapToObj(i -> { |
76 |
| - Type elType = aggregateType.getFields().get(i).type(); |
77 |
| - Expression elBase = constructExpr.getOperands().get(i); |
78 |
| - return getAlignedValue(id, elBase, elType); |
79 |
| - }) |
80 |
| - .collect(Collectors.toList()); |
81 |
| - return expressions.makeConstruct(type, elements); |
82 |
| - } |
83 |
| - if (base.getType().equals(type)) { |
84 |
| - return base; |
85 |
| - } |
86 |
| - throw new ParsingException("Cannot align initializer for variable '" + id + "' of type " + type); |
87 |
| - } |
88 |
| - |
89 | 70 | public static Expression createResultExpression(String id, Type type, Expression op1, Expression op2, IntBinaryOp op) {
|
90 | 71 | if (type instanceof BooleanType || type instanceof IntegerType || type instanceof FloatType) {
|
91 | 72 | return expressions.makeBinary(op1, op, op2);
|
@@ -211,18 +192,13 @@ public static Type getAlignedType(Type type, int alignmentNum) {
|
211 | 192 | }
|
212 | 193 | if (type instanceof ArrayType arrayType) {
|
213 | 194 | Type elementType = arrayType.getElementType();
|
214 |
| - int elementAlignmentNum; |
215 |
| - if (types.getMemorySizeInBytes(elementType) > alignmentNum) { |
216 |
| - elementType = getAlignedType(elementType, alignmentNum); |
217 |
| - elementAlignmentNum = types.getMemorySizeInBytes(elementType); |
218 |
| - } else { |
219 |
| - elementAlignmentNum = alignmentNum; |
| 195 | + int arraySizeInBytes = types.getMemorySizeInBytes(arrayType); |
| 196 | + if (arraySizeInBytes > alignmentNum) { |
| 197 | + return types.getArrayType(getAlignedType(elementType, alignmentNum), arrayType.getNumElements()); |
220 | 198 | }
|
221 |
| - List<Type> elementTypes = Collections.nCopies(arrayType.getNumElements(), elementType); |
222 |
| - List<Integer> alignmentList = IntStream.range(0, arrayType.getNumElements()) |
223 |
| - .mapToObj(i -> i * elementAlignmentNum) |
224 |
| - .collect(Collectors.toList()); |
225 |
| - return types.getAggregateType(elementTypes, alignmentList); |
| 199 | + int paddedSize = alignmentNum / types.getMemorySizeInBytes(elementType); |
| 200 | + int paddingStart = arrayType.getNumElements(); |
| 201 | + return types.getArrayType(elementType, paddedSize, paddingStart); |
226 | 202 | }
|
227 | 203 | throw new ParsingException("Invalid type '%s' for alignment '%d'", type, alignmentNum);
|
228 | 204 | }
|
|
0 commit comments