1 /* 2 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 package jdk.test.lib.jittester.factories; 25 26 import jdk.test.lib.jittester.IRNode; 27 import jdk.test.lib.jittester.OperatorKind; 28 import jdk.test.lib.jittester.ProductionFailedException; 29 import jdk.test.lib.jittester.ProductionLimiter; 30 import jdk.test.lib.jittester.ProductionParams; 31 import jdk.test.lib.jittester.Rule; 32 import jdk.test.lib.jittester.Type;; 33 import jdk.test.lib.jittester.types.TypeKlass; 34 35 class ExpressionFactory extends SafeFactory { 36 private final Rule rule; 37 38 ExpressionFactory(long complexityLimit, int operatorLimit, TypeKlass ownerClass, Type resultType, 39 boolean exceptionSafe, boolean noconsts) throws ProductionFailedException { 40 IRNodeBuilder builder = new IRNodeBuilder() 41 .setComplexityLimit(complexityLimit) 42 .setOperatorLimit(operatorLimit) 43 .setOwnerKlass(ownerClass) 44 .setResultType(resultType) 45 .setExceptionSafe(exceptionSafe) 46 .setNoConsts(noconsts); 47 rule = new Rule("expression"); 48 if (!noconsts) { 49 rule.add("literal", builder.getLiteralFactory()); 50 rule.add("constant", builder.setIsConstant(true) 51 .setIsInitialized(true) 52 //.setVariableType(resultType) 53 .getVariableFactory()); 54 } 55 rule.add("variable", builder.setIsConstant(false).setIsInitialized(true).getVariableFactory()); 56 if (operatorLimit > 0 && complexityLimit > 0) { 57 rule.add("cast", builder.getCastOperatorFactory(), 0.1); 58 rule.add("arithmetic", builder.getArithmeticOperatorFactory()); 59 rule.add("logic", builder.getLogicOperatorFactory()); 60 rule.add("bitwise", new BitwiseOperatorFactory(complexityLimit, operatorLimit, ownerClass, 61 resultType, exceptionSafe, noconsts)); 62 rule.add("assignment", builder.getAssignmentOperatorFactory()); 63 rule.add("ternary", builder.getTernaryOperatorFactory()); 64 rule.add("function", builder.getFunctionFactory(), 0.1); 65 rule.add("str_plus", builder.setOperatorKind(OperatorKind.STRADD).getBinaryOperatorFactory()); 66 if (!ProductionParams.disableArrays.value() && !exceptionSafe) { 67 //rule.add("array_creation", builder.getArrayCreationFactory()); 68 rule.add("array_element", builder.getArrayElementFactory()); 69 rule.add("array_extraction", builder.getArrayExtractionFactory()); 70 } 71 } 72 } 73 74 @Override 75 protected IRNode sproduce() throws ProductionFailedException { 76 ProductionLimiter.limitProduction(); 77 return rule.produce(); 78 } 79 }