Search in sources :

Example 6 with Variable

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;
}
Also used : IntegerType(org.robovm.compiler.llvm.IntegerType) Variable(org.robovm.compiler.llvm.Variable) Trunc(org.robovm.compiler.llvm.Trunc) ConstantTrunc(org.robovm.compiler.llvm.ConstantTrunc)

Example 7 with Variable

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();
}
Also used : Call(org.robovm.compiler.llvm.Call) FloatingPointType(org.robovm.compiler.llvm.FloatingPointType) IntegerType(org.robovm.compiler.llvm.IntegerType) PointerType(org.robovm.compiler.llvm.PointerType) NullType(soot.NullType) FunctionType(org.robovm.compiler.llvm.FunctionType) ArrayType(org.robovm.compiler.llvm.ArrayType) CharType(soot.CharType) RefLikeType(soot.RefLikeType) Type(org.robovm.compiler.llvm.Type) PrimType(soot.PrimType) Variable(org.robovm.compiler.llvm.Variable) FunctionType(org.robovm.compiler.llvm.FunctionType)

Example 8 with Variable

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());
}
Also used : GlobalRef(org.robovm.compiler.llvm.GlobalRef) VariableRef(org.robovm.compiler.llvm.VariableRef) Variable(org.robovm.compiler.llvm.Variable) ConstantBitcast(org.robovm.compiler.llvm.ConstantBitcast) PointerType(org.robovm.compiler.llvm.PointerType) FunctionRef(org.robovm.compiler.llvm.FunctionRef) Load(org.robovm.compiler.llvm.Load) FloatingPointConstant(org.robovm.compiler.llvm.FloatingPointConstant) Trampoline(org.robovm.compiler.trampoline.Trampoline) Local(soot.Local) NullConstant(org.robovm.compiler.llvm.NullConstant) IntegerConstant(org.robovm.compiler.llvm.IntegerConstant) FloatingPointType(org.robovm.compiler.llvm.FloatingPointType) IntegerType(org.robovm.compiler.llvm.IntegerType) PointerType(org.robovm.compiler.llvm.PointerType) NullType(soot.NullType) FunctionType(org.robovm.compiler.llvm.FunctionType) ArrayType(org.robovm.compiler.llvm.ArrayType) CharType(soot.CharType) RefLikeType(soot.RefLikeType) Type(org.robovm.compiler.llvm.Type) PrimType(soot.PrimType) LdcClass(org.robovm.compiler.trampoline.LdcClass)

Example 9 with Variable

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);
    }
}
Also used : GlobalRef(org.robovm.compiler.llvm.GlobalRef) Load(org.robovm.compiler.llvm.Load) Variable(org.robovm.compiler.llvm.Variable) Trampoline(org.robovm.compiler.trampoline.Trampoline) ConstantBitcast(org.robovm.compiler.llvm.ConstantBitcast) LdcClass(org.robovm.compiler.trampoline.LdcClass) PointerType(org.robovm.compiler.llvm.PointerType) FunctionRef(org.robovm.compiler.llvm.FunctionRef)

Example 10 with Variable

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;
}
Also used : Ret(org.robovm.compiler.llvm.Ret) Load(org.robovm.compiler.llvm.Load) Variable(org.robovm.compiler.llvm.Variable) Label(org.robovm.compiler.llvm.Label) PointerType(org.robovm.compiler.llvm.PointerType) Getelementptr(org.robovm.compiler.llvm.Getelementptr) IntegerConstant(org.robovm.compiler.llvm.IntegerConstant) Br(org.robovm.compiler.llvm.Br) Function(org.robovm.compiler.llvm.Function) Bitcast(org.robovm.compiler.llvm.Bitcast) ConstantBitcast(org.robovm.compiler.llvm.ConstantBitcast) And(org.robovm.compiler.llvm.And) StructureType(org.robovm.compiler.llvm.StructureType) Value(org.robovm.compiler.llvm.Value) Icmp(org.robovm.compiler.llvm.Icmp)

Aggregations

Variable (org.robovm.compiler.llvm.Variable)38 PointerType (org.robovm.compiler.llvm.PointerType)18 Value (org.robovm.compiler.llvm.Value)18 IntegerConstant (org.robovm.compiler.llvm.IntegerConstant)14 Load (org.robovm.compiler.llvm.Load)12 Type (org.robovm.compiler.llvm.Type)11 FunctionType (org.robovm.compiler.llvm.FunctionType)10 Bitcast (org.robovm.compiler.llvm.Bitcast)9 ConstantBitcast (org.robovm.compiler.llvm.ConstantBitcast)8 Ret (org.robovm.compiler.llvm.Ret)8 VariableRef (org.robovm.compiler.llvm.VariableRef)8 Getelementptr (org.robovm.compiler.llvm.Getelementptr)7 ArrayType (org.robovm.compiler.llvm.ArrayType)6 Br (org.robovm.compiler.llvm.Br)6 Function (org.robovm.compiler.llvm.Function)6 Icmp (org.robovm.compiler.llvm.Icmp)6 IntegerType (org.robovm.compiler.llvm.IntegerType)6 Label (org.robovm.compiler.llvm.Label)6 StructureType (org.robovm.compiler.llvm.StructureType)6 ArrayList (java.util.ArrayList)5