Mercurial > hg > graal-compiler
comparison graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/node/SpecializationMethodParser.java @ 16755:bd28da642eea
Truffle-DSL: Several new features implemented:
Implementation of a new code generation layout which shares code between generated nodes.
Declaration order of specializations is now used as specialization order.
Specializations do no longer perform fallthrough on respecialization, they now always respecialize from the first specialization.
Implemented support for contains relations between specializations.
Improved reachability error messages.
Preliminary support for @Implies.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Mon, 11 Aug 2014 15:53:05 +0200 |
parents | 5a0c694ef735 |
children |
comparison
equal
deleted
inserted
replaced
16754:55fd5be68a52 | 16755:bd28da642eea |
---|---|
30 | 30 |
31 import com.oracle.truffle.api.dsl.*; | 31 import com.oracle.truffle.api.dsl.*; |
32 import com.oracle.truffle.dsl.processor.*; | 32 import com.oracle.truffle.dsl.processor.*; |
33 import com.oracle.truffle.dsl.processor.node.SpecializationData.SpecializationKind; | 33 import com.oracle.truffle.dsl.processor.node.SpecializationData.SpecializationKind; |
34 import com.oracle.truffle.dsl.processor.template.*; | 34 import com.oracle.truffle.dsl.processor.template.*; |
35 import com.oracle.truffle.dsl.processor.typesystem.*; | |
35 | 36 |
36 public class SpecializationMethodParser extends NodeMethodParser<SpecializationData> { | 37 public class SpecializationMethodParser extends NodeMethodParser<SpecializationData> { |
37 | 38 |
38 public SpecializationMethodParser(ProcessorContext context, NodeData operation) { | 39 public SpecializationMethodParser(ProcessorContext context, NodeData operation) { |
39 super(context, operation); | 40 super(context, operation); |
53 public Class<? extends Annotation> getAnnotationType() { | 54 public Class<? extends Annotation> getAnnotationType() { |
54 return Specialization.class; | 55 return Specialization.class; |
55 } | 56 } |
56 | 57 |
57 private SpecializationData parseSpecialization(TemplateMethod method) { | 58 private SpecializationData parseSpecialization(TemplateMethod method) { |
58 int order = Utils.getAnnotationValue(Integer.class, method.getMarkerAnnotation(), "order"); | |
59 if (order < 0 && order != Specialization.DEFAULT_ORDER) { | |
60 method.addError("Invalid order attribute %d. The value must be >= 0 or the default value."); | |
61 } | |
62 | |
63 AnnotationValue rewriteValue = Utils.getAnnotationValue(method.getMarkerAnnotation(), "rewriteOn"); | 59 AnnotationValue rewriteValue = Utils.getAnnotationValue(method.getMarkerAnnotation(), "rewriteOn"); |
64 List<TypeMirror> exceptionTypes = Utils.getAnnotationValueList(TypeMirror.class, method.getMarkerAnnotation(), "rewriteOn"); | 60 List<TypeMirror> exceptionTypes = Utils.getAnnotationValueList(TypeMirror.class, method.getMarkerAnnotation(), "rewriteOn"); |
65 List<SpecializationThrowsData> exceptionData = new ArrayList<>(); | 61 List<SpecializationThrowsData> exceptionData = new ArrayList<>(); |
66 for (TypeMirror exceptionType : exceptionTypes) { | 62 for (TypeMirror exceptionType : exceptionTypes) { |
67 SpecializationThrowsData throwsData = new SpecializationThrowsData(method.getMarkerAnnotation(), rewriteValue, exceptionType); | 63 SpecializationThrowsData throwsData = new SpecializationThrowsData(method.getMarkerAnnotation(), rewriteValue, exceptionType); |
76 @Override | 72 @Override |
77 public int compare(SpecializationThrowsData o1, SpecializationThrowsData o2) { | 73 public int compare(SpecializationThrowsData o1, SpecializationThrowsData o2) { |
78 return Utils.compareByTypeHierarchy(o1.getJavaClass(), o2.getJavaClass()); | 74 return Utils.compareByTypeHierarchy(o1.getJavaClass(), o2.getJavaClass()); |
79 } | 75 } |
80 }); | 76 }); |
81 SpecializationData specialization = new SpecializationData(getNode(), method, SpecializationKind.SPECIALIZED, order, exceptionData); | 77 SpecializationData specialization = new SpecializationData(getNode(), method, SpecializationKind.SPECIALIZED, exceptionData); |
78 | |
79 String insertBeforeName = Utils.getAnnotationValue(String.class, method.getMarkerAnnotation(), "insertBefore"); | |
80 if (!insertBeforeName.equals("")) { | |
81 specialization.setInsertBeforeName(insertBeforeName); | |
82 } | |
83 | |
82 List<String> guardDefs = Utils.getAnnotationValueList(String.class, specialization.getMarkerAnnotation(), "guards"); | 84 List<String> guardDefs = Utils.getAnnotationValueList(String.class, specialization.getMarkerAnnotation(), "guards"); |
83 specialization.setGuardDefinitions(guardDefs); | 85 List<GuardExpression> guardExpressions = new ArrayList<>(); |
86 for (String guardDef : guardDefs) { | |
87 guardExpressions.add(new GuardExpression(guardDef)); | |
88 } | |
89 specialization.setGuards(guardExpressions); | |
90 | |
91 List<String> containsDefs = Utils.getAnnotationValueList(String.class, specialization.getMarkerAnnotation(), "contains"); | |
92 Set<String> containsNames = specialization.getContainsNames(); | |
93 containsNames.clear(); | |
94 if (containsDefs != null) { | |
95 for (String include : containsDefs) { | |
96 if (!containsNames.contains(include)) { | |
97 specialization.getContainsNames().add(include); | |
98 } else { | |
99 AnnotationValue value = Utils.getAnnotationValue(specialization.getMarkerAnnotation(), "contains"); | |
100 specialization.addError(value, "Duplicate contains declaration '%s'.", include); | |
101 } | |
102 } | |
103 | |
104 } | |
84 | 105 |
85 List<String> assumptionDefs = Utils.getAnnotationValueList(String.class, specialization.getMarkerAnnotation(), "assumptions"); | 106 List<String> assumptionDefs = Utils.getAnnotationValueList(String.class, specialization.getMarkerAnnotation(), "assumptions"); |
86 specialization.setAssumptions(assumptionDefs); | 107 specialization.setAssumptions(assumptionDefs); |
87 | 108 |
88 for (String assumption : assumptionDefs) { | 109 for (String assumption : assumptionDefs) { |