1 : // Copyright 2015 Google Inc. All Rights Reserved.
2 : //
3 : // Licensed under the Apache License, Version 2.0 (the "License");
4 : // you may not use this file except in compliance with the License.
5 : // You may obtain a copy of the License at
6 : //
7 : // http://www.apache.org/licenses/LICENSE-2.0
8 : //
9 : // Unless required by applicable law or agreed to in writing, software
10 : // distributed under the License is distributed on an "AS IS" BASIS,
11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 : // See the License for the specific language governing permissions and
13 : // limitations under the License.
14 :
15 : #ifndef SYZYGY_REFINERY_ANALYZERS_ANALYZER_FACTORY_H_
16 : #define SYZYGY_REFINERY_ANALYZERS_ANALYZER_FACTORY_H_
17 :
18 : #include <string>
19 : #include <vector>
20 :
21 : #include "base/strings/string_piece.h"
22 : #include "syzygy/refinery/analyzers/analyzer.h"
23 : #include "syzygy/refinery/process_state/process_state.h"
24 :
25 m : namespace refinery {
26 :
27 : // An analyzer factory knows of a set of analyzers and their layer
28 : // dependencies.
29 m : class AnalyzerFactory {
30 m : public:
31 m : using Layer = ProcessState::LayerEnum;
32 m : using Layers = std::vector<Layer>;
33 m : using AnalyzerNames = std::vector<std::string>;
34 :
35 : // Retrieves the names of the analyzers known to this analyzer list.
36 m : virtual void GetAnalyzerNames(AnalyzerNames* analyzer_names) const = 0;
37 :
38 : // Creates the analyzer named @p name.
39 : // @returns the created analyzer, or nullptr if @p name is invalid.
40 m : virtual Analyzer* CreateAnalyzer(const base::StringPiece& name) const = 0;
41 :
42 : // Retrieve the input/output layers for a named analyzer.
43 : // @param name the name of the analyzer of interest.
44 : // @param layers on success contains the input/output layers.
45 : // @returns true on success, false if @p name is invalid.
46 : // @{
47 m : virtual bool GetInputLayers(const base::StringPiece& name,
48 m : Layers* layers) const = 0;
49 m : virtual bool GetOutputLayers(const base::StringPiece& name,
50 m : Layers* layers) const = 0;
51 : // @}
52 :
53 : // Retrieve the analyzers inputting or outputting a for a given layer.
54 : // @param layer the layer of interest.
55 : // @param analyzer_names the analyzers inputting or outputting @p layer.
56 : // @{
57 m : virtual void GetAnalyzersOutputting(Layer layer,
58 m : AnalyzerNames* analyzer_names) const = 0;
59 m : virtual void GetAnalyzersInputting(Layer layer,
60 m : AnalyzerNames* analyzer_names) const = 0;
61 : // @}
62 m : };
63 :
64 : // This implementation of AnalyzerFactory knows of all analyzers linked into
65 : // this binary.
66 m : class StaticAnalyzerFactory : public AnalyzerFactory {
67 m : public:
68 : // @name AnalyzerFactory implementation.
69 : // @{
70 m : void GetAnalyzerNames(AnalyzerNames* analyzer_names) const override;
71 m : Analyzer* CreateAnalyzer(const base::StringPiece& name) const override;
72 :
73 m : bool GetInputLayers(const base::StringPiece& name,
74 m : Layers* layers) const override;
75 m : bool GetOutputLayers(const base::StringPiece& name,
76 m : Layers* layers) const override;
77 m : virtual void GetAnalyzersOutputting(
78 m : Layer layer,
79 m : AnalyzerNames* analyzer_names) const override;
80 m : virtual void GetAnalyzersInputting(Layer layer, AnalyzerNames* analyzer_names)
81 m : const override;
82 : // @}
83 m : };
84 :
85 m : } // namespace refinery
86 :
87 : #endif // SYZYGY_REFINERY_ANALYZERS_ANALYZER_FACTORY_H_
|