Search in sources :

Example 1 with CodeAnnotationMirror

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

the class FlatNodeGenFactory method createExplodeLoop.

private CodeAnnotationMirror createExplodeLoop() {
    DeclaredType explodeLoopType = context.getDeclaredType(ExplodeLoop.class);
    CodeAnnotationMirror explodeLoop = new CodeAnnotationMirror(explodeLoopType);
    DeclaredType loopExplosionKind = context.getDeclaredType(ExplodeLoop.LoopExplosionKind.class);
    if (loopExplosionKind != null) {
        VariableElement kindValue = ElementUtils.findVariableElement(loopExplosionKind, "FULL_EXPLODE_UNTIL_RETURN");
        if (kindValue != null) {
            explodeLoop.setElementValue(ElementUtils.findExecutableElement(explodeLoopType, "kind"), new CodeAnnotationValue(kindValue));
        }
    }
    return explodeLoop;
}
Also used : CodeAnnotationMirror(com.oracle.truffle.dsl.processor.java.model.CodeAnnotationMirror) ExplodeLoop(com.oracle.truffle.api.nodes.ExplodeLoop) CodeVariableElement(com.oracle.truffle.dsl.processor.java.model.CodeVariableElement) VariableElement(javax.lang.model.element.VariableElement) DeclaredType(javax.lang.model.type.DeclaredType) CodeAnnotationValue(com.oracle.truffle.dsl.processor.java.model.CodeAnnotationValue)

Example 2 with CodeAnnotationMirror

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

the class FlatNodeGenFactory method setFieldCompilationFinal.

private static void setFieldCompilationFinal(CodeVariableElement field, int dimensions) {
    if (field.getModifiers().contains(Modifier.FINAL) && dimensions <= 0) {
        // no need for the compilation final annotation.
        return;
    }
    CodeAnnotationMirror annotation = new CodeAnnotationMirror(ProcessorContext.getInstance().getDeclaredType(CompilationFinal.class));
    if (dimensions > 0 || field.getType().getKind() == TypeKind.ARRAY) {
        annotation.setElementValue(annotation.findExecutableElement("dimensions"), new CodeAnnotationValue(dimensions < 0 ? 0 : dimensions));
    }
    field.getAnnotationMirrors().add(annotation);
}
Also used : CodeAnnotationMirror(com.oracle.truffle.dsl.processor.java.model.CodeAnnotationMirror) CompilationFinal(com.oracle.truffle.api.CompilerDirectives.CompilationFinal) CodeAnnotationValue(com.oracle.truffle.dsl.processor.java.model.CodeAnnotationValue)

Example 3 with CodeAnnotationMirror

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

the class FlatNodeGenFactory method createNodeField.

private static CodeVariableElement createNodeField(Modifier visibility, TypeMirror type, String name, Class<?> annotationClass, Modifier... modifiers) {
    CodeVariableElement childField = new CodeVariableElement(modifiers(modifiers), type, name);
    if (annotationClass != null) {
        if (annotationClass == CompilationFinal.class) {
            setFieldCompilationFinal(childField, 0);
        } else {
            childField.getAnnotationMirrors().add(new CodeAnnotationMirror(ProcessorContext.getInstance().getDeclaredType(annotationClass)));
        }
    }
    setVisibility(childField.getModifiers(), visibility);
    return childField;
}
Also used : CodeAnnotationMirror(com.oracle.truffle.dsl.processor.java.model.CodeAnnotationMirror) CodeVariableElement(com.oracle.truffle.dsl.processor.java.model.CodeVariableElement)

Example 4 with CodeAnnotationMirror

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

the class FlatNodeGenFactory method createGetCostMethod.

private Element createGetCostMethod() {
    TypeMirror returnType = getType(NodeCost.class);
    CodeExecutableElement executable = new CodeExecutableElement(modifiers(PUBLIC), returnType, "getCost");
    executable.getAnnotationMirrors().add(new CodeAnnotationMirror(context.getDeclaredType(Override.class)));
    CodeTreeBuilder builder = executable.createBuilder();
    FrameState frameState = FrameState.load(this);
    builder.tree(state.createLoad(frameState));
    if (node.needsRewrites(context)) {
        builder.startIf().tree(state.createIs(frameState, new Object[0], reachableSpecializationsArray)).end();
        builder.startBlock();
        builder.startReturn().staticReference(getType(NodeCost.class), "UNINITIALIZED").end();
        builder.end();
        if (reachableSpecializations.size() == 1 && !reachableSpecializations.iterator().next().hasMultipleInstances()) {
            builder.startElseBlock();
            builder.startReturn().staticReference(getType(NodeCost.class), "MONOMORPHIC").end();
            builder.end();
        } else {
            builder.startElseIf();
            builder.tree(state.createIsOneBitOf(frameState, reachableSpecializationsArray));
            builder.end();
            builder.startBlock();
            List<CodeTree> additionalChecks = new ArrayList<>();
            for (SpecializationData specialization : reachableSpecializations) {
                if (useSpecializationClass(specialization) && specialization.getMaximumNumberOfInstances() > 1) {
                    String typeName = createSpecializationTypeName(specialization);
                    String fieldName = createSpecializationFieldName(specialization);
                    String localName = createSpecializationLocalName(specialization);
                    builder.declaration(typeName, localName, "this." + fieldName);
                    CodeTree check = builder.create().startParantheses().string(localName, " == null || ", localName, ".next_ == null").end().build();
                    additionalChecks.add(check);
                }
            }
            if (!additionalChecks.isEmpty()) {
                builder.startIf().tree(combineTrees(" && ", additionalChecks.toArray(new CodeTree[0]))).end().startBlock();
            }
            builder.startReturn().staticReference(getType(NodeCost.class), "MONOMORPHIC").end();
            if (!additionalChecks.isEmpty()) {
                builder.end();
            }
            builder.end();
            builder.startReturn().staticReference(getType(NodeCost.class), "POLYMORPHIC").end();
        }
    } else {
        builder.startReturn().staticReference(getType(NodeCost.class), "MONOMORPHIC").end();
    }
    return executable;
}
Also used : CodeAnnotationMirror(com.oracle.truffle.dsl.processor.java.model.CodeAnnotationMirror) CodeExecutableElement(com.oracle.truffle.dsl.processor.java.model.CodeExecutableElement) DeclaredCodeTypeMirror(com.oracle.truffle.dsl.processor.java.model.CodeTypeMirror.DeclaredCodeTypeMirror) ArrayCodeTypeMirror(com.oracle.truffle.dsl.processor.java.model.CodeTypeMirror.ArrayCodeTypeMirror) GeneratedTypeMirror(com.oracle.truffle.dsl.processor.java.model.GeneratedTypeMirror) TypeMirror(javax.lang.model.type.TypeMirror) CodeTree(com.oracle.truffle.dsl.processor.java.model.CodeTree) ArrayList(java.util.ArrayList) SpecializationData(com.oracle.truffle.dsl.processor.model.SpecializationData) CodeTreeBuilder(com.oracle.truffle.dsl.processor.java.model.CodeTreeBuilder)

Example 5 with CodeAnnotationMirror

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

the class GeneratorUtils method createClass.

static CodeTypeElement createClass(Template sourceModel, TemplateMethod sourceMethod, Set<Modifier> modifiers, String simpleName, TypeMirror superType) {
    TypeElement templateType = sourceModel.getTemplateType();
    ProcessorContext context = ProcessorContext.getInstance();
    PackageElement pack = context.getEnvironment().getElementUtils().getPackageOf(templateType);
    CodeTypeElement clazz = new CodeTypeElement(modifiers, ElementKind.CLASS, pack, simpleName);
    TypeMirror resolvedSuperType = superType;
    if (resolvedSuperType == null) {
        resolvedSuperType = context.getType(Object.class);
    }
    clazz.setSuperClass(resolvedSuperType);
    CodeAnnotationMirror generatedByAnnotation = new CodeAnnotationMirror((DeclaredType) context.getType(GeneratedBy.class));
    generatedByAnnotation.setElementValue(generatedByAnnotation.findExecutableElement("value"), new CodeAnnotationValue(templateType.asType()));
    if (sourceMethod != null && sourceMethod.getMethod() != null) {
        generatedByAnnotation.setElementValue(generatedByAnnotation.findExecutableElement("methodName"), new CodeAnnotationValue(sourceMethod.createReferenceName()));
    }
    clazz.addAnnotationMirror(generatedByAnnotation);
    return clazz;
}
Also used : CodeAnnotationMirror(com.oracle.truffle.dsl.processor.java.model.CodeAnnotationMirror) CodeTypeElement(com.oracle.truffle.dsl.processor.java.model.CodeTypeElement) ElementUtils.fromTypeMirror(com.oracle.truffle.dsl.processor.java.ElementUtils.fromTypeMirror) TypeMirror(javax.lang.model.type.TypeMirror) TypeElement(javax.lang.model.element.TypeElement) CodeTypeElement(com.oracle.truffle.dsl.processor.java.model.CodeTypeElement) PackageElement(javax.lang.model.element.PackageElement) ProcessorContext(com.oracle.truffle.dsl.processor.ProcessorContext) CodeAnnotationValue(com.oracle.truffle.dsl.processor.java.model.CodeAnnotationValue)

Aggregations

CodeAnnotationMirror (com.oracle.truffle.dsl.processor.java.model.CodeAnnotationMirror)13 CodeAnnotationValue (com.oracle.truffle.dsl.processor.java.model.CodeAnnotationValue)8 CodeVariableElement (com.oracle.truffle.dsl.processor.java.model.CodeVariableElement)4 DeclaredType (javax.lang.model.type.DeclaredType)4 TypeMirror (javax.lang.model.type.TypeMirror)4 CodeTypeElement (com.oracle.truffle.dsl.processor.java.model.CodeTypeElement)3 CodeExecutableElement (com.oracle.truffle.dsl.processor.java.model.CodeExecutableElement)2 CodeTreeBuilder (com.oracle.truffle.dsl.processor.java.model.CodeTreeBuilder)2 Assumption (com.oracle.truffle.api.Assumption)1 CompilationFinal (com.oracle.truffle.api.CompilerDirectives.CompilationFinal)1 GeneratedBy (com.oracle.truffle.api.dsl.GeneratedBy)1 ExplodeLoop (com.oracle.truffle.api.nodes.ExplodeLoop)1 Child (com.oracle.truffle.api.nodes.Node.Child)1 ProcessorContext (com.oracle.truffle.dsl.processor.ProcessorContext)1 ElementUtils.fromTypeMirror (com.oracle.truffle.dsl.processor.java.ElementUtils.fromTypeMirror)1 CodeTree (com.oracle.truffle.dsl.processor.java.model.CodeTree)1 ArrayCodeTypeMirror (com.oracle.truffle.dsl.processor.java.model.CodeTypeMirror.ArrayCodeTypeMirror)1 DeclaredCodeTypeMirror (com.oracle.truffle.dsl.processor.java.model.CodeTypeMirror.DeclaredCodeTypeMirror)1 GeneratedTypeMirror (com.oracle.truffle.dsl.processor.java.model.GeneratedTypeMirror)1 SpecializationData (com.oracle.truffle.dsl.processor.model.SpecializationData)1