Package org.teavm.model

Examples of org.teavm.model.Program


* @author Alexey Andreev
*/
public class ProgramIOTest {
    @Test
    public void emptyInstruction() {
        Program program = new Program();
        BasicBlock block = program.createBasicBlock();
        block.getInstructions().add(new EmptyInstruction());

        program = inputOutput(program);
        block = program.basicBlockAt(0);

        assertThat(block.getInstructions().size(), is(1));
        assertThat(block.getInstructions().get(0), instanceOf(EmptyInstruction.class));
    }
View Full Code Here


        assertThat(block.getInstructions().get(0), instanceOf(EmptyInstruction.class));
    }

    @Test
    public void constants() {
        Program program = new Program();
        BasicBlock block = program.createBasicBlock();
        ClassConstantInstruction classConstInsn = new ClassConstantInstruction();
        classConstInsn.setConstant(ValueType.BYTE);
        classConstInsn.setReceiver(program.createVariable());
        block.getInstructions().add(classConstInsn);
        NullConstantInstruction nullConstInsn = new NullConstantInstruction();
        nullConstInsn.setReceiver(program.createVariable());
        block.getInstructions().add(nullConstInsn);
        IntegerConstantInstruction intConsInsn = new IntegerConstantInstruction();
        intConsInsn.setReceiver(program.createVariable());
        intConsInsn.setConstant(23);
        block.getInstructions().add(intConsInsn);
        LongConstantInstruction longConsInsn = new LongConstantInstruction();
        longConsInsn.setReceiver(program.createVariable());
        longConsInsn.setConstant(234);
        block.getInstructions().add(longConsInsn);
        FloatConstantInstruction floatConsInsn = new FloatConstantInstruction();
        floatConsInsn.setReceiver(program.createVariable());
        floatConsInsn.setConstant(3.14f);
        block.getInstructions().add(floatConsInsn);
        DoubleConstantInstruction doubleConsInsn = new DoubleConstantInstruction();
        doubleConsInsn.setReceiver(program.createVariable());
        doubleConsInsn.setConstant(3.14159);
        block.getInstructions().add(doubleConsInsn);
        StringConstantInstruction stringConsInsn = new StringConstantInstruction();
        stringConsInsn.setReceiver(program.createVariable());
        stringConsInsn.setConstant("foo");
        block.getInstructions().add(stringConsInsn);

        program = inputOutput(program);
        block = program.basicBlockAt(0);

        assertThat(block.getInstructions().size(), is(7));
        assertThat(block.getInstructions().get(0), instanceOf(ClassConstantInstruction.class));
        assertThat(block.getInstructions().get(1), instanceOf(NullConstantInstruction.class));
        assertThat(block.getInstructions().get(2), instanceOf(IntegerConstantInstruction.class));
View Full Code Here

        assertThat(stringConsInsn.getReceiver().getIndex(), is(6));
    }

    @Test
    public void binaryOperation() {
        Program program = new Program();
        BasicBlock block = program.createBasicBlock();
        IntegerConstantInstruction constInsn = new IntegerConstantInstruction();
        constInsn.setConstant(3);
        constInsn.setReceiver(program.createVariable());
        block.getInstructions().add(constInsn);
        constInsn = new IntegerConstantInstruction();
        constInsn.setConstant(2);
        constInsn.setReceiver(program.createVariable());
        block.getInstructions().add(constInsn);
        BinaryInstruction addInsn = new BinaryInstruction(BinaryOperation.ADD, NumericOperandType.INT);
        addInsn.setFirstOperand(program.variableAt(0));
        addInsn.setSecondOperand(program.variableAt(1));
        addInsn.setReceiver(program.createVariable());
        block.getInstructions().add(addInsn);
        BinaryInstruction subInsn = new BinaryInstruction(BinaryOperation.SUBTRACT, NumericOperandType.INT);
        subInsn.setFirstOperand(program.variableAt(2));
        subInsn.setSecondOperand(program.variableAt(0));
        subInsn.setReceiver(program.createVariable());
        block.getInstructions().add(subInsn);

        assertThat(block.getInstructions().size(), is(4));
        assertThat(block.getInstructions().get(2), instanceOf(BinaryInstruction.class));
        assertThat(block.getInstructions().get(3), instanceOf(BinaryInstruction.class));
View Full Code Here

    public void optimizeAll(ListableClassHolderSource classSource) {
        for (String className : classSource.getClassNames()) {
            ClassHolder cls = classSource.get(className);
            for (MethodHolder method : cls.getMethods()) {
                if (method.getProgram() != null && method.getProgram().basicBlockCount() > 0) {
                    Program program = ProgramUtils.copy(method.getProgram());
                    for (MethodOptimization optimization : getOptimizations()) {
                        optimization.optimize(method, program);
                    }
                    method.setProgram(program);
                }
View Full Code Here

TOP

Related Classes of org.teavm.model.Program

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.