use of org.robovm.compiler.llvm.Variable in project robovm by robovm.
the class MethodCompiler method narrowFromI32Value.
private Value narrowFromI32Value(Unit unit, Type type, Value value) {
if (value.getType() == I32 && ((IntegerType) type).getBits() < 32) {
Variable t = function.newVariable(type);
function.add(new Trunc(t, value, type)).attach(unit);
value = t.ref();
}
return value;
}
use of org.robovm.compiler.llvm.Variable in project robovm by robovm.
the class MethodCompiler method call.
private Value call(Unit unit, Value fn, Value... args) {
Variable result = null;
Type returnType = ((FunctionType) fn.getType()).getReturnType();
if (returnType != VOID) {
result = function.newVariable(returnType);
}
function.add(new Call(result, fn, args)).attach(unit);
return result == null ? null : result.ref();
}
use of org.robovm.compiler.llvm.Variable in project robovm by robovm.
the class MethodCompiler method immediate.
private Value immediate(Unit unit, Immediate v) {
// v is either a soot.Local or a soot.jimple.Constant
if (v instanceof soot.Local) {
Local local = (Local) v;
Type type = getLocalType(v.getType());
VariableRef var = new VariableRef(local.getName(), new PointerType(type));
Variable tmp = function.newVariable(type);
function.add(new Load(tmp, var, !sootMethod.getActiveBody().getTraps().isEmpty())).attach(unit);
return new VariableRef(tmp);
} else if (v instanceof soot.jimple.IntConstant) {
return new IntegerConstant(((soot.jimple.IntConstant) v).value);
} else if (v instanceof soot.jimple.LongConstant) {
return new IntegerConstant(((soot.jimple.LongConstant) v).value);
} else if (v instanceof soot.jimple.FloatConstant) {
return new FloatingPointConstant(((soot.jimple.FloatConstant) v).value);
} else if (v instanceof soot.jimple.DoubleConstant) {
return new FloatingPointConstant(((soot.jimple.DoubleConstant) v).value);
} else if (v instanceof soot.jimple.NullConstant) {
return new NullConstant(OBJECT_PTR);
} else if (v instanceof soot.jimple.StringConstant) {
String s = ((soot.jimple.StringConstant) v).value;
return call(unit, ldcString(s), env);
} else if (v instanceof soot.jimple.ClassConstant) {
// ClassConstant is either the internal name of a class or the descriptor of an array
String targetClassName = ((soot.jimple.ClassConstant) v).getValue();
if (isArray(targetClassName) && isPrimitiveComponentType(targetClassName)) {
String primitiveDesc = targetClassName.substring(1);
Variable result = function.newVariable(OBJECT_PTR);
function.add(new Load(result, new ConstantBitcast(new GlobalRef("array_" + primitiveDesc, CLASS_PTR), new PointerType(OBJECT_PTR)))).attach(unit);
return result.ref();
} else {
FunctionRef fn = null;
if (targetClassName.equals(this.className)) {
fn = FunctionBuilder.ldcInternal(sootMethod.getDeclaringClass()).ref();
} else {
Trampoline trampoline = new LdcClass(className, ((soot.jimple.ClassConstant) v).getValue());
trampolines.add(trampoline);
fn = trampoline.getFunctionRef();
}
return call(unit, fn, env);
}
}
throw new IllegalArgumentException("Unknown Immediate type: " + v.getClass());
}
use of org.robovm.compiler.llvm.Variable in project robovm by robovm.
the class BroMethodCompiler method ldcClass.
protected Value ldcClass(Function fn, String name, Value env) {
if (isArray(name) && isPrimitiveBaseType(name)) {
String primitiveDesc = name.substring(name.length() - 1);
Variable result = fn.newVariable(OBJECT_PTR);
fn.add(new Load(result, new ConstantBitcast(new GlobalRef("array_" + primitiveDesc, CLASS_PTR), new PointerType(OBJECT_PTR))));
return result.ref();
} else {
FunctionRef ldcClassFn = null;
if (name.equals(this.className)) {
ldcClassFn = FunctionBuilder.ldcInternal(this.className).ref();
} else {
Trampoline trampoline = new LdcClass(this.className, name);
trampolines.add(trampoline);
ldcClassFn = trampoline.getFunctionRef();
}
return call(fn, ldcClassFn, env);
}
}
use of org.robovm.compiler.llvm.Variable in project robovm by robovm.
the class ClassCompiler method createClassInitWrapperFunction.
private Function createClassInitWrapperFunction(FunctionRef targetFn) {
Function fn = FunctionBuilder.clinitWrapper(targetFn);
Value info = getInfoStruct(fn, sootClass);
Variable infoHeader = fn.newVariable(new PointerType(new StructureType(I8_PTR, I32)));
fn.add(new Bitcast(infoHeader, info, infoHeader.getType()));
Variable infoHeaderFlags = fn.newVariable(new PointerType(I32));
fn.add(new Getelementptr(infoHeaderFlags, infoHeader.ref(), 0, 1));
Variable flags = fn.newVariable(I32);
fn.add(new Load(flags, infoHeaderFlags.ref()));
Variable initializedFlag = fn.newVariable(I32);
fn.add(new And(initializedFlag, flags.ref(), new IntegerConstant(CI_INITIALIZED)));
Variable initialized = fn.newVariable(I1);
fn.add(new Icmp(initialized, Icmp.Condition.eq, initializedFlag.ref(), new IntegerConstant(CI_INITIALIZED)));
Label trueLabel = new Label();
Label falseLabel = new Label();
fn.add(new Br(initialized.ref(), fn.newBasicBlockRef(trueLabel), fn.newBasicBlockRef(falseLabel)));
fn.newBasicBlock(trueLabel);
Value result = call(fn, targetFn, fn.getParameterRefs());
fn.add(new Ret(result));
fn.newBasicBlock(falseLabel);
call(fn, BC_INITIALIZE_CLASS, fn.getParameterRef(0), info);
fn.add(new Br(fn.newBasicBlockRef(trueLabel)));
return fn;
}
Aggregations