Skip to content

Commit 940a757

Browse files
committed
Random cleanups
1 parent 66e7bcd commit 940a757

File tree

3 files changed

+14
-20
lines changed

3 files changed

+14
-20
lines changed

src/com/plasstech/lang/c/codegen/AssemblyType.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
* Page 261.
77
*/
88
public enum AssemblyType {
9-
Longword("l"),
10-
Quadword("q");
9+
Longword("l"), // 4 bytes
10+
Quadword("q"); // 8 bytes
1111

1212
private final String suffix;
1313

@@ -16,9 +16,9 @@ public enum AssemblyType {
1616
}
1717

1818
public static AssemblyType from(Type type) {
19-
if (type.equals(Type.LONG)) {
19+
if (type.equals(Type.LONG) || type.equals(Type.UNSIGNED_LONG)) {
2020
return Quadword;
21-
} else if (type.equals(Type.INT)) {
21+
} else if (type.equals(Type.INT) || type.equals(Type.UNSIGNED_INT)) {
2222
return Longword;
2323
}
2424
throw new IllegalStateException(

src/com/plasstech/lang/c/codegen/tacky/FixupVisitor.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import com.plasstech.lang.c.codegen.Movsx;
2727
import com.plasstech.lang.c.codegen.Operand;
2828
import com.plasstech.lang.c.codegen.Push;
29-
import com.plasstech.lang.c.codegen.RegisterOperand;
3029
import com.plasstech.lang.c.codegen.Ret;
3130
import com.plasstech.lang.c.codegen.SetCC;
3231

@@ -89,9 +88,9 @@ public List<Instruction> visit(AsmBinary n) {
8988
n.dst().inMemory() || (n.type() == AssemblyType.Quadword && immOutOfRange(n.src()));
9089
if (needsIntermediary) {
9190
return ImmutableList.of(
92-
new Mov(n.type(), n.src(), RegisterOperand.R11), // NOTYPO
93-
new AsmBinary(n.operator(), n.type(), n.dst(), RegisterOperand.R11),
94-
new Mov(n.type(), RegisterOperand.R11, n.dst()));
91+
new Mov(n.type(), n.src(), R11), // NOTYPO
92+
new AsmBinary(n.operator(), n.type(), n.dst(), R11),
93+
new Mov(n.type(), R11, n.dst()));
9594
}
9695
}
9796
break;

test/com/plasstech/lang/c/codegen/tacky/TackyCodeGenTest.java

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -233,14 +233,9 @@ int main(void) {
233233
""";
234234
TackyProgram tp = generate(input);
235235
assertThat(tp.topLevelDefinitions()).hasSize(1);
236-
for (var tld : tp.topLevelDefinitions()) {
237-
if (tld instanceof TackyFunction fn) {
238-
List<TackyInstruction> instructions = fn.body();
239-
assertThat(instructions.size()).isGreaterThan(0);
240-
} else {
241-
fail("Expected TackyFunctionDef");
242-
}
243-
}
236+
TackyFunction fn = (TackyFunction) tp.topLevelDefinitions().get(0);
237+
List<TackyInstruction> instructions = fn.body();
238+
assertThat(instructions.size()).isGreaterThan(0);
244239
}
245240

246241
@Test
@@ -312,9 +307,9 @@ long main(void) {
312307
Program prog = new Parser(new Scanner(input)).parse();
313308
prog = semanticAnalyzer.validate(prog);
314309
TackyCodeGen cg = new TackyCodeGen(symtab);
315-
Collection<Symbol> beforeGeneration = ImmutableSet.copyOf(symtab.values());
310+
Collection<Symbol> beforeGenerationSymbols = ImmutableSet.copyOf(symtab.values());
316311
cg.generate(prog);
317-
assertThat(beforeGeneration).isEqualTo(ImmutableSet.copyOf(symtab.values()));
312+
assertThat(beforeGenerationSymbols).isEqualTo(ImmutableSet.copyOf(symtab.values()));
318313
}
319314

320315
@Test
@@ -342,8 +337,8 @@ int main(void) {
342337
Program prog = p.parse();
343338
prog = semanticAnalyzer.validate(prog);
344339
TackyCodeGen cg = new TackyCodeGen(symtab);
345-
Collection<Symbol> beforeGeneration = ImmutableSet.copyOf(symtab.values());
340+
Collection<Symbol> beforeGenerationSymbols = ImmutableSet.copyOf(symtab.values());
346341
cg.generate(prog);
347-
assertThat(beforeGeneration).isNotEqualTo(symtab.values());
342+
assertThat(beforeGenerationSymbols).isNotEqualTo(symtab.values());
348343
}
349344
}

0 commit comments

Comments
 (0)