001/*
002 * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation.
008 *
009 * This code is distributed in the hope that it will be useful, but WITHOUT
010 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
011 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
012 * version 2 for more details (a copy is included in the LICENSE file that
013 * accompanied this code).
014 *
015 * You should have received a copy of the GNU General Public License version
016 * 2 along with this work; if not, write to the Free Software Foundation,
017 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
018 *
019 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
020 * or visit www.oracle.com if you need additional information or have any
021 * questions.
022 */
023package com.oracle.graal.phases.util;
024
025import jdk.internal.jvmci.code.*;
026import jdk.internal.jvmci.meta.*;
027
028import com.oracle.graal.compiler.common.spi.*;
029import com.oracle.graal.nodes.spi.*;
030import com.oracle.graal.phases.tiers.*;
031
032/**
033 * A set of providers, some of which may not be present (i.e., null).
034 */
035public class Providers implements CodeGenProviders {
036
037    private final MetaAccessProvider metaAccess;
038    private final CodeCacheProvider codeCache;
039    private final LoweringProvider lowerer;
040    private final ConstantReflectionProvider constantReflection;
041    private final ForeignCallsProvider foreignCalls;
042    private final Replacements replacements;
043    private final StampProvider stampProvider;
044
045    public Providers(MetaAccessProvider metaAccess, CodeCacheProvider codeCache, ConstantReflectionProvider constantReflection, ForeignCallsProvider foreignCalls, LoweringProvider lowerer,
046                    Replacements replacements, StampProvider stampProvider) {
047        this.metaAccess = metaAccess;
048        this.codeCache = codeCache;
049        this.constantReflection = constantReflection;
050        this.foreignCalls = foreignCalls;
051        this.lowerer = lowerer;
052        this.replacements = replacements;
053        this.stampProvider = stampProvider;
054    }
055
056    public Providers(Providers copyFrom) {
057        this(copyFrom.getMetaAccess(), copyFrom.getCodeCache(), copyFrom.getConstantReflection(), copyFrom.getForeignCalls(), copyFrom.getLowerer(), copyFrom.getReplacements(),
058                        copyFrom.getStampProvider());
059    }
060
061    public Providers(PhaseContext copyFrom) {
062        this(copyFrom.getMetaAccess(), null, copyFrom.getConstantReflection(), null, copyFrom.getLowerer(), copyFrom.getReplacements(), copyFrom.getStampProvider());
063    }
064
065    public MetaAccessProvider getMetaAccess() {
066        return metaAccess;
067    }
068
069    public CodeCacheProvider getCodeCache() {
070        return codeCache;
071    }
072
073    public ForeignCallsProvider getForeignCalls() {
074        return foreignCalls;
075    }
076
077    public LoweringProvider getLowerer() {
078        return lowerer;
079    }
080
081    public ConstantReflectionProvider getConstantReflection() {
082        return constantReflection;
083    }
084
085    public Replacements getReplacements() {
086        return replacements;
087    }
088
089    public StampProvider getStampProvider() {
090        return stampProvider;
091    }
092
093    public Providers copyWith(MetaAccessProvider substitution) {
094        return new Providers(substitution, codeCache, constantReflection, foreignCalls, lowerer, replacements, stampProvider);
095    }
096
097    public Providers copyWith(CodeCacheProvider substitution) {
098        return new Providers(metaAccess, substitution, constantReflection, foreignCalls, lowerer, replacements, stampProvider);
099    }
100
101    public Providers copyWith(ConstantReflectionProvider substitution) {
102        return new Providers(metaAccess, codeCache, substitution, foreignCalls, lowerer, replacements, stampProvider);
103    }
104
105    public Providers copyWith(ForeignCallsProvider substitution) {
106        return new Providers(metaAccess, codeCache, constantReflection, substitution, lowerer, replacements, stampProvider);
107    }
108
109    public Providers copyWith(LoweringProvider substitution) {
110        return new Providers(metaAccess, codeCache, constantReflection, foreignCalls, substitution, replacements, stampProvider);
111    }
112
113    public Providers copyWith(Replacements substitution) {
114        return new Providers(metaAccess, codeCache, constantReflection, foreignCalls, lowerer, substitution, stampProvider);
115    }
116
117    public Providers copyWith(StampProvider substitution) {
118        return new Providers(metaAccess, codeCache, constantReflection, foreignCalls, lowerer, replacements, substitution);
119    }
120}