12 #ifndef OPENVDB_AX_CODEGEN_SYMBOL_TABLE_HAS_BEEN_INCLUDED 13 #define OPENVDB_AX_CODEGEN_SYMBOL_TABLE_HAS_BEEN_INCLUDED 15 #include <openvdb/version.h> 17 #include <llvm/IR/Value.h> 21 #include <unordered_map> 37 using MapType = std::unordered_map<std::string, llvm::Value*>;
46 inline llvm::Value*
get(
const std::string& name)
const 48 const auto iter = mMap.find(name);
49 if (iter == mMap.end())
return nullptr;
57 inline bool exists(
const std::string& name)
const 59 const auto iter = mMap.find(name);
60 return (iter != mMap.end());
69 inline bool insert(
const std::string& name, llvm::Value*
value)
71 if (exists(name))
return false;
84 const bool existed = exists(name);
91 inline void clear() { mMap.clear(); }
114 using MapType = std::map<size_t, SymbolTable>;
130 inline bool erase(
const size_t index)
133 throw std::runtime_error(
"Attempted to erase global variables which is disallowed.");
136 const bool existed = (mTables.find(index) != mTables.end());
137 mTables.erase(index);
147 return &(mTables[index]);
156 auto iter = mTables.find(index);
157 if (iter == mTables.end())
return nullptr;
158 return &(iter->second);
169 inline llvm::Value*
find(
const std::string& name,
const size_t startIndex)
const 175 auto it = mTables.lower_bound(startIndex);
176 if (it == mTables.end() || it->first != startIndex) --it;
181 assert(it != mTables.end());
182 MapType::const_reverse_iterator iter(++it);
184 for (; iter != mTables.crend(); ++iter) {
185 llvm::Value*
value = iter->second.get(name);
186 if (value)
return value;
197 inline llvm::Value*
find(
const std::string& name)
const 199 return this->find(name, mTables.crbegin()->first);
210 for (
auto it = mTables.rbegin(); it != mTables.rend(); ++it) {
211 if (it->second.get(name)) {
212 it->second.replace(name, value);
229 #endif // OPENVDB_AX_CODEGEN_SYMBOL_TABLE_HAS_BEEN_INCLUDED SymbolTable & globals()
Access to the list of global variables which are always accessible.
Definition: SymbolTable.h:121
std::unordered_map< std::string, llvm::Value * > MapType
Definition: SymbolTable.h:37
SymbolTable()
Definition: SymbolTable.h:39
void clear()
Clear all symbols in this table.
Definition: SymbolTable.h:91
const MapType & map() const
Access to the underlying map.
Definition: SymbolTable.h:95
Definition: Exceptions.h:13
bool replace(const std::string &name, llvm::Value *value)
Replace the first occurrance of a variable with a given name with a replacement value. Returns true if a replacement occurred.
Definition: SymbolTable.h:208
bool replace(const std::string &name, llvm::Value *value)
Replace a variable in this symbol table. Returns true if the variable previously existed and false if...
Definition: SymbolTable.h:82
ValueT value
Definition: GridBuilder.h:1287
llvm::Value * find(const std::string &name, const size_t startIndex) const
Find a variable within the program starting at a given table index. If the given index does not exist...
Definition: SymbolTable.h:169
llvm::Value * find(const std::string &name) const
Find a variable within the program starting at the lowest level SymbolTable.
Definition: SymbolTable.h:197
const SymbolTable & globals() const
Definition: SymbolTable.h:122
A symbol table which can be used to represent a single scoped set of a programs variables. This is simply an unordered map of strings to llvm::Values.
Definition: SymbolTable.h:35
bool exists(const std::string &name) const
Returns true if a variable exists in this symbol table with the given name.
Definition: SymbolTable.h:57
SymbolTable * getOrInsert(const size_t index)
Get or insert and get a SymbolTable with a unique index.
Definition: SymbolTable.h:145
bool erase(const size_t index)
Erase a given scoped indexed SymbolTable from the list of held SymbolTables. Returns true if the tabl...
Definition: SymbolTable.h:130
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h.in:116
bool insert(const std::string &name, llvm::Value *value)
Insert a variable to this symbol table if it does not exist. Returns true if successfully, false if a variable already exists with the given name.
Definition: SymbolTable.h:69
std::map< size_t, SymbolTable > MapType
Definition: SymbolTable.h:114
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h.in:202
SymbolTableBlocks()
Definition: SymbolTable.h:116
A map of unique ids to symbol tables which can be used to represent local variables within a program...
Definition: SymbolTable.h:112