/*
RegIndOperand.java
(c) 2008-2013 Edward Swartz
All rights reserved. This program and the accompanying materials
are made available under the terms of the Eclipse Public License v1.0
which accompanies this distribution, and is available at
http://www.eclipse.org/legal/epl-v10.html
*/
package v9t9.tools.asm.operand.hl;
import v9t9.common.asm.IInstruction;
import v9t9.common.asm.ResolveException;
import v9t9.tools.asm.IAssembler;
import v9t9.tools.asm.operand.ll.LLOperand;
import v9t9.tools.asm.operand.ll.LLRegIndOperand;
import v9t9.tools.asm.operand.ll.LLRegisterOperand;
/**
* *Rx
* @author ejs
*
*/
public class RegIndOperand extends RegisterOperand {
public RegIndOperand(AssemblerOperand reg) {
super(reg);
}
@Override
public String toString() {
return "*" + super.toString();
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((getReg() == null) ? 0 : getReg().hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
RegIndOperand other = (RegIndOperand) obj;
if (getReg() == null) {
if (other.getReg() != null) {
return false;
}
} else if (!getReg().equals(other.getReg())) {
return false;
}
return true;
}
/* (non-Javadoc)
* @see v9t9.tools.asm.operand.hl.AssemblerOperand#isMemory()
*/
@Override
public boolean isMemory() {
return true;
}
/* (non-Javadoc)
* @see v9t9.tools.asm.operand.hl.AssemblerOperand#isRegister()
*/
@Override
public boolean isRegister() {
return false;
}
public LLOperand resolve(IAssembler assembler, IInstruction inst)
throws ResolveException {
LLRegisterOperand regRes = (LLRegisterOperand) super.resolve(assembler, inst);
return new LLRegIndOperand(regRes.getRegister());
}
/* (non-Javadoc)
* @see v9t9.tools.asm.operand.hl.BaseOperand#replaceOperand(v9t9.tools.asm.operand.hl.AssemblerOperand, v9t9.tools.asm.operand.hl.AssemblerOperand)
*/
@Override
public AssemblerOperand replaceOperand(AssemblerOperand src,
AssemblerOperand dst) {
if (src.equals(this))
return dst;
AssemblerOperand newReg = getReg().replaceOperand(src, dst);
if (newReg != getReg()) {
if (newReg.isRegister() || newReg instanceof NumberOperand) {
return new RegIndOperand(newReg);
} else if (newReg.isMemory()) {
// assume we replaced a reg with an address with the address, as in "MOV *R(local), ..."
return new AddrOperand(newReg);
} else {
assert false;
}
}
return this;
}
/* (non-Javadoc)
* @see v9t9.tools.asm.operand.hl.RegisterOperand#addOffset(int)
*/
@Override
public AssemblerOperand addOffset(int i) {
return new RegOffsOperand(new NumberOperand(i), getReg());
}
}