Skip to content
This repository has been archived by the owner on Jul 6, 2023. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'origin/pa7' into pa7
Browse files Browse the repository at this point in the history
  • Loading branch information
anmolkabra committed May 15, 2019
2 parents 7757d3b + d85f73b commit b3c3744
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/main/java/kc875/asm/visit/RegAllocationNaiveVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,36 @@ public List<ASMInstr> visit(ASMInstr_2Arg i) {
ASMExpr r = i.getSrc();
List<ASMInstr> instrs = new ArrayList<>();
ASMExpr dest;

// LEAs need a special case
if (i.getOpCode() == ASMOpCode.LEA) {
// LEA's dest must be a register, and its src must be a mem
// when we generate LEAs, we always do so correctly (mem into a temp)
if (l instanceof ASMExprTemp) {
List<String> availRegs = getAvailRegs(getRegsInExpr(r)); // mem expression may contain registers
dest = new ASMExprReg(availRegs.get(0));

instrs.add(new ASMInstr_2Arg(
ASMOpCode.LEA,
dest,
r // has to be a mem
));

// now, we need to spill the left hand side temp onto the stack
ASMExprMem loc = getMemForTemp(((ASMExprTemp) l).getName(), instrs);
instrs.add(new ASMInstr_2Arg(
ASMOpCode.MOV,
loc,
dest
));
} else {
// lhs has to be a register due to our invariant, so this is fine:
instrs.add(i);
}

return instrs;
}

if (l instanceof ASMExprTemp) {//if LHS is a temp it gets turned into a mem
dest = getMemForTemp(((ASMExprTemp) l).getName(), instrs);
} else if (l instanceof ASMExprMem) {// if LHS is a mem it gets turned into a mem
Expand Down

0 comments on commit b3c3744

Please sign in to comment.