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.LoweringProvider; 31 import org.graalvm.compiler.nodes.spi.Replacements; 32 import org.graalvm.compiler.nodes.spi.StampProvider; 33 import org.graalvm.compiler.phases.tiers.PhaseContext; 34 35 import jdk.vm.ci.code.CodeCacheProvider; 36 import jdk.vm.ci.meta.ConstantReflectionProvider; 37 import jdk.vm.ci.meta.MetaAccessProvider; 38 39 /** 40 * A set of providers, some of which may not be present (i.e., null). 41 */ 42 public class Providers implements CodeGenProviders { 43 44 private final MetaAccessProvider metaAccess; 45 private final CodeCacheProvider codeCache; 46 private final LoweringProvider lowerer; 47 private final ConstantReflectionProvider constantReflection; 48 private final ConstantFieldProvider constantFieldProvider; 49 private final ForeignCallsProvider foreignCalls; 50 private final Replacements replacements; 51 private final StampProvider stampProvider; 52 53 public Providers(MetaAccessProvider metaAccess, CodeCacheProvider codeCache, ConstantReflectionProvider constantReflection, ConstantFieldProvider constantFieldProvider, 54 ForeignCallsProvider foreignCalls, LoweringProvider lowerer, Replacements replacements, StampProvider stampProvider) { 55 this.metaAccess = metaAccess; 56 this.codeCache = codeCache; 57 this.constantReflection = constantReflection; 58 this.constantFieldProvider = constantFieldProvider; 59 this.foreignCalls = foreignCalls; 60 this.lowerer = lowerer; 61 this.replacements = replacements; 62 this.stampProvider = stampProvider; 63 } 64 65 public Providers(Providers copyFrom) { 66 this(copyFrom.getMetaAccess(), copyFrom.getCodeCache(), copyFrom.getConstantReflection(), copyFrom.getConstantFieldProvider(), copyFrom.getForeignCalls(), copyFrom.getLowerer(), 67 copyFrom.getReplacements(), copyFrom.getStampProvider()); 68 } 69 70 public Providers(PhaseContext copyFrom) { 71 this(copyFrom.getMetaAccess(), null, copyFrom.getConstantReflection(), copyFrom.getConstantFieldProvider(), null, copyFrom.getLowerer(), copyFrom.getReplacements(), 72 copyFrom.getStampProvider()); 73 } 74 75 @Override 76 public MetaAccessProvider getMetaAccess() { 77 return metaAccess; 78 } 79 80 @Override 81 public CodeCacheProvider getCodeCache() { 82 return codeCache; 83 } 84 85 @Override 86 public ForeignCallsProvider getForeignCalls() { 87 return foreignCalls; 88 } 89 90 public LoweringProvider getLowerer() { 91 return lowerer; 92 } 93 94 @Override 95 public ConstantReflectionProvider getConstantReflection() { 96 return constantReflection; 97 } 98 99 public ConstantFieldProvider getConstantFieldProvider() { 100 return constantFieldProvider; 101 } 102 103 public Replacements getReplacements() { 104 return replacements; 105 } 106 107 public StampProvider getStampProvider() { 108 return stampProvider; 109 } 110 111 public Providers copyWith(MetaAccessProvider substitution) { 112 assert this.getClass() == Providers.class : "must override"; 113 return new Providers(substitution, codeCache, constantReflection, constantFieldProvider, foreignCalls, lowerer, replacements, stampProvider); 114 } 115 116 public Providers copyWith(CodeCacheProvider substitution) { 117 assert this.getClass() == Providers.class : "must override"; 118 return new Providers(metaAccess, substitution, constantReflection, constantFieldProvider, foreignCalls, lowerer, replacements, stampProvider); 119 } 120 121 public Providers copyWith(ConstantReflectionProvider substitution) { 122 assert this.getClass() == Providers.class : "must override"; 123 return new Providers(metaAccess, codeCache, substitution, constantFieldProvider, foreignCalls, lowerer, replacements, stampProvider); 124 } 125 126 public Providers copyWith(ConstantFieldProvider substitution) { 127 assert this.getClass() == Providers.class : "must override"; 128 return new Providers(metaAccess, codeCache, constantReflection, substitution, foreignCalls, lowerer, replacements, stampProvider); 129 } 130 131 public Providers copyWith(ForeignCallsProvider substitution) { 132 assert this.getClass() == Providers.class : "must override"; 133 return new Providers(metaAccess, codeCache, constantReflection, constantFieldProvider, substitution, lowerer, replacements, stampProvider); 134 } 135 136 public Providers copyWith(LoweringProvider substitution) { 137 assert this.getClass() == Providers.class : "must override"; 138 return new Providers(metaAccess, codeCache, constantReflection, constantFieldProvider, foreignCalls, substitution, replacements, stampProvider); 139 } 140 141 public Providers copyWith(Replacements substitution) { 142 assert this.getClass() == Providers.class : "must override in " + getClass(); 143 return new Providers(metaAccess, codeCache, constantReflection, constantFieldProvider, foreignCalls, lowerer, substitution, stampProvider); 144 } 145 146 public Providers copyWith(StampProvider substitution) { 147 assert this.getClass() == Providers.class : "must override"; 148 return new Providers(metaAccess, codeCache, constantReflection, constantFieldProvider, foreignCalls, lowerer, replacements, substitution); 149 } 150 }