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