use of com.android.dx.rop.cst.Constant in project J2ME-Loader by nikita36078.
the class Form45cc method isCompatible.
/**
* {@inheritDoc}
*/
@Override
public boolean isCompatible(DalvInsn insn) {
if (!(insn instanceof MultiCstInsn)) {
return false;
}
MultiCstInsn mci = (MultiCstInsn) insn;
if (mci.getNumberOfConstants() != 2) {
return false;
}
int methodIdx = mci.getIndex(0);
int protoIdx = mci.getIndex(1);
if (!unsignedFitsInShort(methodIdx) || !unsignedFitsInShort(protoIdx)) {
return false;
}
Constant methodRef = mci.getConstant(0);
if (!(methodRef instanceof CstMethodRef)) {
return false;
}
Constant protoRef = mci.getConstant(1);
if (!(protoRef instanceof CstProtoRef)) {
return false;
}
RegisterSpecList regs = mci.getRegisters();
return (wordCount(regs) >= 0);
}
use of com.android.dx.rop.cst.Constant in project J2ME-Loader by nikita36078.
the class Form51l method isCompatible.
/**
* {@inheritDoc}
*/
@Override
public boolean isCompatible(DalvInsn insn) {
RegisterSpecList regs = insn.getRegisters();
if (!((insn instanceof CstInsn) && (regs.size() == 1) && unsignedFitsInByte(regs.get(0).getReg()))) {
return false;
}
CstInsn ci = (CstInsn) insn;
Constant cst = ci.getConstant();
return (cst instanceof CstLiteral64);
}
use of com.android.dx.rop.cst.Constant in project J2ME-Loader by nikita36078.
the class AnnotationUtils method makeInnerClass.
/**
* Constructs a standard {@code InnerClass} annotation.
*
* @param name {@code null-ok;} the original name of the class, or
* {@code null} to represent an anonymous class
* @param accessFlags the original access flags
* @return {@code non-null;} the annotation
*/
public static Annotation makeInnerClass(CstString name, int accessFlags) {
Annotation result = new Annotation(INNER_CLASS_TYPE, SYSTEM);
Constant nameCst = (name != null) ? name : CstKnownNull.THE_ONE;
result.put(new NameValuePair(NAME_STRING, nameCst));
result.put(new NameValuePair(ACCESS_FLAGS_STRING, CstInteger.make(accessFlags)));
result.setImmutable();
return result;
}
use of com.android.dx.rop.cst.Constant in project J2ME-Loader by nikita36078.
the class ValueEncoder method writeArray.
/**
* Writes out the encoded form of the given array, that is, as
* an {@code encoded_array} and not including a
* {@code value_type} prefix. If the output stream keeps
* (debugging) annotations and {@code topLevel} is
* {@code true}, then this method will write (debugging)
* annotations.
*
* @param array {@code non-null;} array instance to write
* @param topLevel {@code true} iff the given annotation is the
* top-level annotation or {@code false} if it is a sub-annotation
* of some other annotation
*/
public void writeArray(CstArray array, boolean topLevel) {
boolean annotates = topLevel && out.annotates();
CstArray.List list = ((CstArray) array).getList();
int size = list.size();
if (annotates) {
out.annotate(" size: " + Hex.u4(size));
}
out.writeUleb128(size);
for (int i = 0; i < size; i++) {
Constant cst = list.get(i);
if (annotates) {
out.annotate(" [" + Integer.toHexString(i) + "] " + constantToHuman(cst));
}
writeConstant(cst);
}
if (annotates) {
out.endAnnotation();
}
}
use of com.android.dx.rop.cst.Constant in project J2ME-Loader by nikita36078.
the class PlainInsn method withSourceLiteral.
/**
* {@inheritDoc}
*/
@Override
public Insn withSourceLiteral() {
RegisterSpecList sources = getSources();
int szSources = sources.size();
if (szSources == 0) {
return this;
}
TypeBearer lastType = sources.get(szSources - 1).getTypeBearer();
if (!lastType.isConstant()) {
// Check for reverse subtraction, where first source is constant
TypeBearer firstType = sources.get(0).getTypeBearer();
if (szSources == 2 && firstType.isConstant()) {
Constant cst = (Constant) firstType;
RegisterSpecList newSources = sources.withoutFirst();
Rop newRop = Rops.ropFor(getOpcode().getOpcode(), getResult(), newSources, cst);
return new PlainCstInsn(newRop, getPosition(), getResult(), newSources, cst);
}
return this;
} else {
Constant cst = (Constant) lastType;
RegisterSpecList newSources = sources.withoutLast();
Rop newRop;
try {
// Check for constant subtraction and flip it to be addition
int opcode = getOpcode().getOpcode();
if (opcode == RegOps.SUB && cst instanceof CstInteger) {
opcode = RegOps.ADD;
cst = CstInteger.make(-((CstInteger) cst).getValue());
}
newRop = Rops.ropFor(opcode, getResult(), newSources, cst);
} catch (IllegalArgumentException ex) {
// There's no rop for this case
return this;
}
return new PlainCstInsn(newRop, getPosition(), getResult(), newSources, cst);
}
}
Aggregations