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;
}
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);
}
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;
}
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;
}
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;
}
Aggregations