Jlm
variable.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2015 Nico Reißmann <nico.reissmann@gmail.com>
3  * See COPYING for terms of redistribution.
4  */
5 
6 #ifndef JLM_LLVM_IR_VARIABLE_HPP
7 #define JLM_LLVM_IR_VARIABLE_HPP
8 
10 #include <jlm/rvsdg/type.hpp>
11 #include <jlm/util/strfmt.hpp>
12 
13 #include <memory>
14 #include <sstream>
15 
16 namespace jlm::llvm
17 {
18 
19 class Variable
20 {
21 public:
22  virtual ~Variable() noexcept;
23 
24  Variable(std::shared_ptr<const jlm::rvsdg::Type> type, const std::string & name)
25  : name_(name),
26  type_(std::move(type))
27  {}
28 
29  Variable(Variable && other) noexcept
30  : name_(std::move(other.name_)),
31  type_(std::move(other.type_))
32  {}
33 
34  Variable &
35  operator=(Variable && other) noexcept
36  {
37  if (this == &other)
38  return *this;
39 
40  name_ = std::move(other.name_);
41  type_ = std::move(other.type_);
42 
43  return *this;
44  }
45 
46  virtual std::string
47  debug_string() const;
48 
49  inline const std::string &
50  name() const noexcept
51  {
52  return name_;
53  }
54 
55  inline const jlm::rvsdg::Type &
56  type() const noexcept
57  {
58  return *type_;
59  }
60 
61  inline const std::shared_ptr<const jlm::rvsdg::Type>
62  Type() const noexcept
63  {
64  return type_;
65  }
66 
67 private:
68  std::string name_;
69  std::shared_ptr<const jlm::rvsdg::Type> type_;
70 };
71 
72 template<class T>
73 static inline bool
74 is(const llvm::Variable * variable) noexcept
75 {
76  static_assert(
77  std::is_base_of<llvm::Variable, T>::value,
78  "Template parameter T must be derived from jlm::Variable.");
79 
80  return dynamic_cast<const T *>(variable) != nullptr;
81 }
82 
83 class GlobalVariable : public Variable
84 {
85 public:
86  ~GlobalVariable() noexcept override;
87 
88  GlobalVariable(std::shared_ptr<const jlm::rvsdg::Type> type, const std::string & name)
89  : Variable(std::move(type), name)
90  {}
91 };
92 
93 }
94 
95 #endif
~GlobalVariable() noexcept override
Variable & operator=(Variable &&other) noexcept
Definition: variable.hpp:35
const std::string & name() const noexcept
Definition: variable.hpp:50
const jlm::rvsdg::Type & type() const noexcept
Definition: variable.hpp:56
virtual std::string debug_string() const
Definition: variable.cpp:14
std::string name_
Definition: variable.hpp:68
Variable(Variable &&other) noexcept
Definition: variable.hpp:29
std::shared_ptr< const jlm::rvsdg::Type > type_
Definition: variable.hpp:69
virtual ~Variable() noexcept
const std::shared_ptr< const jlm::rvsdg::Type > Type() const noexcept
Definition: variable.hpp:62
Global memory state passed between functions.
static bool is(const AggregationNode *node)