Search in sources :

Example 1 with GeneratedTypeMirror

use of com.oracle.truffle.dsl.processor.java.model.GeneratedTypeMirror in project graal by oracle.

the class FlatNodeGenFactory method initializeSpecializationClass.

private Collection<? extends IfTriple> initializeSpecializationClass(FrameState frameState, SpecializationData specialization) {
    boolean useSpecializationClass = useSpecializationClass(specialization);
    if (useSpecializationClass) {
        String localName = createSpecializationLocalName(specialization);
        String typeName = createSpecializationTypeName(specialization);
        // we cannot use local name, because its used track reads not init writes
        String classInitialized = createSpecializationClassInitialized(specialization);
        if (!frameState.getBoolean(classInitialized, false)) {
            GeneratedTypeMirror type = new GeneratedTypeMirror("", typeName);
            CodeTreeBuilder initBuilder = new CodeTreeBuilder(null);
            initBuilder.startNew(typeName);
            if (specialization.getMaximumNumberOfInstances() > 1) {
                initBuilder.string(createSpecializationFieldName(specialization));
            }
            // new
            initBuilder.end();
            CodeTree init = initBuilder.build();
            CodeTreeBuilder builder = new CodeTreeBuilder(null);
            builder.startStatement();
            if (frameState.get(localName) == null) {
                // not yet declared
                builder.string(typeName);
                builder.string(" ");
            }
            builder.string(localName);
            builder.string(" = ");
            builder.tree(init);
            builder.end();
            frameState.setBoolean(classInitialized, true);
            frameState.set(localName, new LocalVariable(type, localName, CodeTreeBuilder.singleString(localName)));
            return Arrays.asList(new IfTriple(builder.build(), null, null));
        }
    }
    return Collections.emptyList();
}
Also used : CodeTree(com.oracle.truffle.dsl.processor.java.model.CodeTree) GeneratedTypeMirror(com.oracle.truffle.dsl.processor.java.model.GeneratedTypeMirror) CodeTreeBuilder(com.oracle.truffle.dsl.processor.java.model.CodeTreeBuilder)

Example 2 with GeneratedTypeMirror

use of com.oracle.truffle.dsl.processor.java.model.GeneratedTypeMirror in project graal by oracle.

the class FlatNodeGenFactory method loadSpecializationClass.

private CodeTree loadSpecializationClass(FrameState frameState, SpecializationData specialization) {
    if (!useSpecializationClass(specialization)) {
        return null;
    }
    String localName = createSpecializationLocalName(specialization);
    String typeName = createSpecializationTypeName(specialization);
    LocalVariable var = frameState.get(localName);
    CodeTreeBuilder builder = new CodeTreeBuilder(null);
    builder.startStatement();
    if (var == null) {
        builder.string(typeName);
        builder.string(" ");
    }
    builder.string(localName);
    builder.string(" = ");
    builder.tree(createSpecializationFieldReference(frameState, specialization, null));
    builder.end();
    if (var == null) {
        frameState.set(localName, new LocalVariable(new GeneratedTypeMirror("", typeName), localName, null));
    }
    return builder.build();
}
Also used : GeneratedTypeMirror(com.oracle.truffle.dsl.processor.java.model.GeneratedTypeMirror) CodeTreeBuilder(com.oracle.truffle.dsl.processor.java.model.CodeTreeBuilder)

Aggregations

CodeTreeBuilder (com.oracle.truffle.dsl.processor.java.model.CodeTreeBuilder)2 GeneratedTypeMirror (com.oracle.truffle.dsl.processor.java.model.GeneratedTypeMirror)2 CodeTree (com.oracle.truffle.dsl.processor.java.model.CodeTree)1