# HG changeset patch # User Christian Humer # Date 1362157463 -3600 # Node ID 33e08aca06ff90f5506e6ef1d8cb97ac2bdf11ac # Parent 8fa2eed07f81fa7d970af26223d68d305f5a26c2 Codegen API change. Simplified definition of guards. diff -r 8fa2eed07f81 -r 33e08aca06ff graal/com.oracle.truffle.api.codegen/src/com/oracle/truffle/api/codegen/GuardCheck.java --- a/graal/com.oracle.truffle.api.codegen/src/com/oracle/truffle/api/codegen/GuardCheck.java Fri Mar 01 17:06:08 2013 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.truffle.api.codegen; - -import java.lang.annotation.*; - -/** - * - * - * @see SpecializationGuard - */ -@Retention(RetentionPolicy.CLASS) -@Target({ElementType.METHOD}) -public @interface GuardCheck { - -} diff -r 8fa2eed07f81 -r 33e08aca06ff graal/com.oracle.truffle.api.codegen/src/com/oracle/truffle/api/codegen/Specialization.java --- a/graal/com.oracle.truffle.api.codegen/src/com/oracle/truffle/api/codegen/Specialization.java Fri Mar 01 17:06:08 2013 +0100 +++ b/graal/com.oracle.truffle.api.codegen/src/com/oracle/truffle/api/codegen/Specialization.java Fri Mar 01 18:04:23 2013 +0100 @@ -34,6 +34,6 @@ SpecializationThrows[] exceptions() default {}; - SpecializationGuard[] guards() default {}; + String[] guards() default {}; } diff -r 8fa2eed07f81 -r 33e08aca06ff graal/com.oracle.truffle.api.codegen/src/com/oracle/truffle/api/codegen/SpecializationGuard.java --- a/graal/com.oracle.truffle.api.codegen/src/com/oracle/truffle/api/codegen/SpecializationGuard.java Fri Mar 01 17:06:08 2013 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.truffle.api.codegen; - -import java.lang.annotation.*; - -/** - * Specifies the use of a guard for a specialization. - */ -@Retention(RetentionPolicy.CLASS) -@Target({ElementType.METHOD}) -public @interface SpecializationGuard { - - /** - * Specifies the name of the guard method annotated by {@link GuardCheck} specified as method in - * the {@link TypeSystem} class. - */ - String methodName(); - - /** - * Determines if a guard check is invoked on specialization. Defaults to true. - */ - boolean onSpecialization() default true; - - /** - * Determines if a guard check is invoked on execution. Defaults to true. - */ - boolean onExecution() default true; - -} diff -r 8fa2eed07f81 -r 33e08aca06ff graal/com.oracle.truffle.api.codegen/src/com/oracle/truffle/api/codegen/TypeSystem.java --- a/graal/com.oracle.truffle.api.codegen/src/com/oracle/truffle/api/codegen/TypeSystem.java Fri Mar 01 17:06:08 2013 +0100 +++ b/graal/com.oracle.truffle.api.codegen/src/com/oracle/truffle/api/codegen/TypeSystem.java Fri Mar 01 18:04:23 2013 +0100 @@ -28,8 +28,8 @@ *

* Annotates a type system class that represents type information for a node. Generates code for * converting and managing types. Methods contained in the type system may be annotated with - * {@link TypeCast}, {@link TypeCheck} or {@link GuardCheck}. These methods alter the default - * behavior of the type system. + * {@link TypeCast} or {@link TypeCheck}. These methods alter the default behavior of the type + * system. *

* * @@ -62,7 +62,6 @@ * * @see TypeCast * @see TypeCheck - * @see GuardCheck */ @Retention(RetentionPolicy.CLASS) @Target({ElementType.TYPE}) diff -r 8fa2eed07f81 -r 33e08aca06ff graal/com.oracle.truffle.codegen.processor/src/com/oracle/truffle/codegen/processor/node/NodeParser.java --- a/graal/com.oracle.truffle.codegen.processor/src/com/oracle/truffle/codegen/processor/node/NodeParser.java Fri Mar 01 17:06:08 2013 +0100 +++ b/graal/com.oracle.truffle.codegen.processor/src/com/oracle/truffle/codegen/processor/node/NodeParser.java Fri Mar 01 18:04:23 2013 +0100 @@ -41,8 +41,8 @@ public class NodeParser extends TemplateParser { - public static final List> ANNOTATIONS = Arrays.asList(Generic.class, GuardCheck.class, TypeSystemReference.class, ShortCircuit.class, Specialization.class, - SpecializationGuard.class, SpecializationListener.class, SpecializationThrows.class); + public static final List> ANNOTATIONS = Arrays.asList(Generic.class, TypeSystemReference.class, ShortCircuit.class, Specialization.class, SpecializationListener.class, + SpecializationThrows.class); private Map parsedNodes; private TypeElement originalType; diff -r 8fa2eed07f81 -r 33e08aca06ff graal/com.oracle.truffle.codegen.processor/src/com/oracle/truffle/codegen/processor/node/SpecializationMethodParser.java --- a/graal/com.oracle.truffle.codegen.processor/src/com/oracle/truffle/codegen/processor/node/SpecializationMethodParser.java Fri Mar 01 17:06:08 2013 +0100 +++ b/graal/com.oracle.truffle.codegen.processor/src/com/oracle/truffle/codegen/processor/node/SpecializationMethodParser.java Fri Mar 01 18:04:23 2013 +0100 @@ -87,24 +87,24 @@ }); SpecializationData specialization = new SpecializationData(method, order, exceptionData); boolean valid = true; - List guardDefs = Utils.collectAnnotations(getContext(), method.getMarkerAnnotation(), "guards", method.getMethod(), SpecializationGuard.class); + List guardDefs = Utils.getAnnotationValueList(specialization.getMarkerAnnotation(), "guards"); SpecializationGuardData[] guardData = new SpecializationGuardData[guardDefs.size()]; for (int i = 0; i < guardData.length; i++) { - AnnotationMirror guardMirror = guardDefs.get(i); - String guardMethod = Utils.getAnnotationValueString(guardMirror, "methodName"); - boolean onSpecialization = Utils.getAnnotationValueBoolean(guardMirror, "onSpecialization"); - boolean onExecution = Utils.getAnnotationValueBoolean(guardMirror, "onExecution"); + String guardMethod = guardDefs.get(i); + + boolean onSpecialization = true; + boolean onExecution = true; if (!onSpecialization && !onExecution) { String message = "Either onSpecialization, onExecution or both must be enabled."; - getContext().getLog().error(method.getMethod(), guardMirror, message); + getContext().getLog().error(method.getMethod(), message); valid = false; continue; } guardData[i] = new SpecializationGuardData(guardMethod, onSpecialization, onExecution); - GuardData compatibleGuard = matchSpecializationGuard(guardMirror, specialization, guardData[i]); + GuardData compatibleGuard = matchSpecializationGuard(specialization, guardData[i]); if (compatibleGuard != null) { guardData[i].setGuardDeclaration(compatibleGuard); } else { @@ -121,7 +121,7 @@ return specialization; } - private GuardData matchSpecializationGuard(AnnotationMirror mirror, SpecializationData specialization, SpecializationGuardData specializationGuard) { + private GuardData matchSpecializationGuard(SpecializationData specialization, SpecializationGuardData specializationGuard) { List foundGuards = getNode().findGuards(specializationGuard.getGuardMethod()); GuardData compatibleGuard = null; @@ -142,8 +142,8 @@ } List typeDefs = createTypeDefinitions(returnTypeSpec, expectedParameterSpecs); String expectedSignature = TemplateMethodParser.createExpectedSignature(specializationGuard.getGuardMethod(), returnTypeSpec, expectedParameterSpecs, typeDefs); - AnnotationValue value = Utils.getAnnotationValue(mirror, "methodName"); - getContext().getLog().error(specialization.getMethod(), mirror, value, "No guard with signature '%s' found in type system.", expectedSignature); + AnnotationValue value = Utils.getAnnotationValue(specialization.getMarkerAnnotation(), "guards"); + getContext().getLog().error(specialization.getMethod(), specialization.getMarkerAnnotation(), value, "No guard with signature '%s' found in type system.", expectedSignature); return null; } diff -r 8fa2eed07f81 -r 33e08aca06ff graal/com.oracle.truffle.codegen.processor/src/com/oracle/truffle/codegen/processor/typesystem/GuardParser.java --- a/graal/com.oracle.truffle.codegen.processor/src/com/oracle/truffle/codegen/processor/typesystem/GuardParser.java Fri Mar 01 17:06:08 2013 +0100 +++ b/graal/com.oracle.truffle.codegen.processor/src/com/oracle/truffle/codegen/processor/typesystem/GuardParser.java Fri Mar 01 18:04:23 2013 +0100 @@ -27,7 +27,6 @@ import javax.lang.model.element.*; -import com.oracle.truffle.api.codegen.*; import com.oracle.truffle.codegen.processor.*; import com.oracle.truffle.codegen.processor.template.*; import com.oracle.truffle.codegen.processor.template.ParameterSpec.Cardinality; @@ -39,6 +38,8 @@ public GuardParser(ProcessorContext context, Template template, TypeSystemData typeSystem) { super(context, template); this.typeSystem = typeSystem; + setEmitErrors(false); + setParseNullOnError(false); } @Override @@ -51,7 +52,7 @@ @Override public boolean isParsable(ExecutableElement method) { - return Utils.findAnnotationMirror(getContext().getEnvironment(), method, getAnnotationType()) != null; + return true; } @Override @@ -61,7 +62,7 @@ @Override public Class getAnnotationType() { - return GuardCheck.class; + return null; } } diff -r 8fa2eed07f81 -r 33e08aca06ff graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/ArithmeticNode.java --- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/ArithmeticNode.java Fri Mar 01 17:06:08 2013 +0100 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/ArithmeticNode.java Fri Mar 01 18:04:23 2013 +0100 @@ -68,8 +68,7 @@ return left + right; } - @Specialization - @SpecializationGuard(methodName = "isString") + @Specialization(guards = "isString") String doString(Object left, Object right) { return left.toString() + right.toString(); } diff -r 8fa2eed07f81 -r 33e08aca06ff graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/LessThanNode.java --- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/LessThanNode.java Fri Mar 01 17:06:08 2013 +0100 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/LessThanNode.java Fri Mar 01 18:04:23 2013 +0100 @@ -46,8 +46,7 @@ return left.compareTo(right) < 0; } - @Specialization - @SpecializationGuard(methodName = "isString") + @Specialization(guards = "isString") public boolean doString(Object left, Object right) { return left.toString().compareTo(right.toString()) < 0; } diff -r 8fa2eed07f81 -r 33e08aca06ff graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/TypedNode.java --- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/TypedNode.java Fri Mar 01 17:06:08 2013 +0100 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/TypedNode.java Fri Mar 01 18:04:23 2013 +0100 @@ -24,7 +24,6 @@ import java.math.*; -import com.oracle.truffle.api.codegen.*; import com.oracle.truffle.api.frame.*; import com.oracle.truffle.api.nodes.*; @@ -49,7 +48,6 @@ public abstract Object executeGeneric(VirtualFrame frame); - @GuardCheck public boolean isString(Object a, Object b) { return a instanceof String || b instanceof String; }