Jlm
substitution.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2010 2011 2012 Helge Bahmann <hcb@chaoticmind.net>
3  * Copyright 2014 2015 Nico Reißmann <nico.reissmann@gmail.com>
4  * See COPYING for terms of redistribution.
5  */
6 
7 #ifndef JLM_RVSDG_SUBSTITUTION_HPP
8 #define JLM_RVSDG_SUBSTITUTION_HPP
9 
10 #include <jlm/util/common.hpp>
11 
12 #include <unordered_map>
13 
14 namespace jlm::rvsdg
15 {
16 
17 class Output;
18 
19 class SubstitutionMap final
20 {
21 public:
22  bool
23  contains(const Output & original) const noexcept
24  {
25  return outputMap_.find(&original) != outputMap_.end();
26  }
27 
28  Output &
29  lookup(const Output & original) const
30  {
31  if (!contains(original))
32  throw util::Error("Output not in substitution map.");
33 
34  return *outputMap_.find(&original)->second;
35  }
36 
37  void
38  insert(const Output * original, Output * substitute)
39  {
40  outputMap_[original] = substitute;
41  }
42 
43 private:
44  std::unordered_map<const Output *, Output *> outputMap_{};
45 };
46 
47 }
48 
49 #endif
void insert(const Output *original, Output *substitute)
bool contains(const Output &original) const noexcept
std::unordered_map< const Output *, Output * > outputMap_
Output & lookup(const Output &original) const