1 /* 2 * Copyright (c) 2013, 2018, 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 25 package org.graalvm.compiler.phases.util; 26 27 import org.graalvm.compiler.core.common.spi.CodeGenProviders; 28 import org.graalvm.compiler.core.common.spi.ConstantFieldProvider; 29 import org.graalvm.compiler.core.common.spi.ForeignCallsProvider; 30 import org.graalvm.compiler.nodes.spi.CoreProvidersImpl; 31 import org.graalvm.compiler.nodes.spi.LoweringProvider; 32 import org.graalvm.compiler.nodes.spi.Replacements; 33 import org.graalvm.compiler.nodes.spi.StampProvider; 34 import org.graalvm.compiler.phases.tiers.PhaseContext; 35 36 import jdk.vm.ci.code.CodeCacheProvider; 37 import jdk.vm.ci.meta.ConstantReflectionProvider; 38 import jdk.vm.ci.meta.MetaAccessProvider; 39 40 /** 41 * A set of providers, some of which may not be present (i.e., null). 42 */ 43 public class Providers extends CoreProvidersImpl implements CodeGenProviders { 44 45 private final CodeCacheProvider codeCache; 46 47 public Providers(MetaAccessProvider metaAccess, CodeCacheProvider codeCache, ConstantReflectionProvider constantReflection, ConstantFieldProvider constantFieldProvider, 48 ForeignCallsProvider foreignCalls, LoweringProvider lowerer, Replacements replacements, StampProvider stampProvider) { 49 super(metaAccess, constantReflection, constantFieldProvider, lowerer, replacements, stampProvider, foreignCalls); 50 this.codeCache = codeCache; 51 } 52 53 public Providers(Providers copyFrom) { 54 this(copyFrom.getMetaAccess(), copyFrom.getCodeCache(), copyFrom.getConstantReflection(), copyFrom.getConstantFieldProvider(), copyFrom.getForeignCalls(), copyFrom.getLowerer(), 55 copyFrom.getReplacements(), copyFrom.getStampProvider()); 56 } 57 58 public Providers(PhaseContext copyFrom) { 59 this(copyFrom.getMetaAccess(), null, copyFrom.getConstantReflection(), copyFrom.getConstantFieldProvider(), null, copyFrom.getLowerer(), copyFrom.getReplacements(), 60 copyFrom.getStampProvider()); 61 } 62 63 @Override 64 public CodeCacheProvider getCodeCache() { 65 return codeCache; 66 } 67 68 public Providers copyWith(MetaAccessProvider substitution) { 69 assert this.getClass() == Providers.class : "must override"; 70 return new Providers(substitution, codeCache, constantReflection, constantFieldProvider, foreignCalls, lowerer, replacements, stampProvider); 71 } 72 73 public Providers copyWith(CodeCacheProvider substitution) { 74 assert this.getClass() == Providers.class : "must override"; 75 return new Providers(metaAccess, substitution, constantReflection, constantFieldProvider, foreignCalls, lowerer, replacements, stampProvider); 76 } 77 78 public Providers copyWith(ConstantReflectionProvider substitution) { 79 assert this.getClass() == Providers.class : "must override"; 80 return new Providers(metaAccess, codeCache, substitution, constantFieldProvider, foreignCalls, lowerer, replacements, stampProvider); 81 } 82 83 public Providers copyWith(ConstantFieldProvider substitution) { 84 assert this.getClass() == Providers.class : "must override"; 85 return new Providers(metaAccess, codeCache, constantReflection, substitution, foreignCalls, lowerer, replacements, stampProvider); 86 } 87 88 public Providers copyWith(ForeignCallsProvider substitution) { 89 assert this.getClass() == Providers.class : "must override"; 90 return new Providers(metaAccess, codeCache, constantReflection, constantFieldProvider, substitution, lowerer, replacements, stampProvider); 91 } 92 93 public Providers copyWith(LoweringProvider substitution) { 94 assert this.getClass() == Providers.class : "must override"; 95 return new Providers(metaAccess, codeCache, constantReflection, constantFieldProvider, foreignCalls, substitution, replacements, stampProvider); 96 } 97 98 public Providers copyWith(Replacements substitution) { 99 assert this.getClass() == Providers.class : "must override in " + getClass(); 100 return new Providers(metaAccess, codeCache, constantReflection, constantFieldProvider, foreignCalls, lowerer, substitution, stampProvider); 101 } 102 103 public Providers copyWith(StampProvider substitution) { 104 assert this.getClass() == Providers.class : "must override"; 105 return new Providers(metaAccess, codeCache, constantReflection, constantFieldProvider, foreignCalls, lowerer, replacements, substitution); 106 } 107 }