User Guide
|
Hold top level (i.e. More...
Hold top level (i.e.
global) symbol table for mod file
symtab::SymbolTable is sufficient to hold information about all symbols in the mod file. It might be sufficient to keep track of global symbol tables and local symbol tables. But we construct symbol table using visitor pass. In this case we visit ast and recursively create symbol table for each block scope. In this case, ModelSymbolTable provides high level interface to build symbol table as part of visitor.
Definition at line 239 of file symbol_table.hpp.
#include <symbol_table.hpp>
Public Member Functions | |
SymbolTable * | enter_scope (const std::string &name, ast::Ast *node, bool global, SymbolTable *node_symtab) |
entering into new nmodl block More... | |
void | leave_scope () |
leaving current nmodl block More... | |
std::shared_ptr< Symbol > | insert (const std::shared_ptr< Symbol > &symbol) |
insert new symbol into current table More... | |
std::shared_ptr< Symbol > | lookup (const std::string &name) |
lookup for symbol into current as well as all parent tables More... | |
void | set_mode (bool update_mode) |
re-initialize members to throw away old symbol tables this is required as symtab visitor pass runs multiple time More... | |
void | print (std::ostream &ostr) const |
pretty print More... | |
Private Member Functions | |
std::string | get_unique_name (const std::string &name, ast::Ast *node, bool is_global) |
return unique name by appending some counter value More... | |
std::shared_ptr< Symbol > | update_mode_insert (const std::shared_ptr< Symbol > &symbol) |
insert symbol table in update mode More... | |
void | emit_message (const std::shared_ptr< Symbol > &first, const std::shared_ptr< Symbol > &second, bool redefinition) |
void | update_order (const std::shared_ptr< Symbol > &present_symbol, const std::shared_ptr< Symbol > &new_symbol) |
Private Attributes | |
std::shared_ptr< SymbolTable > | symtab |
symbol table for mod file (always top level symbol table) More... | |
SymbolTable * | current_symtab = nullptr |
current symbol table being constructed More... | |
const std::string | GLOBAL_SYMTAB_NAME = "NMODL_GLOBAL" |
name of top level global symbol table More... | |
bool | update_table = false |
default mode of symbol table: if update is true then we update exisiting symbols otherwise we throw away old table and construct new one More... | |
int | definition_order = 0 |
current order of variable being defined More... | |
|
private |
Definition at line 195 of file symbol_table.cpp.
SymbolTable * nmodl::symtab::ModelSymbolTable::enter_scope | ( | const std::string & | name, |
ast::Ast * | node, | ||
bool | global, | ||
SymbolTable * | node_symtab | ||
) |
entering into new nmodl block
Function callback at the entry of every block in nmodl file Every block starts a new scope and hence new symbol table is created.
The same symbol table is returned so that visitor can store pointer to symbol table within a node.
All global blocks in mod file have same global symbol table. If there is already symbol table setup in global scope, return the same.
statement block within global scope is part of global block itself
Definition at line 377 of file symbol_table.cpp.
|
private |
return unique name by appending some counter value
Some blocks can appear multiple times in the nmodl file.
In order to distinguish them we simply append counter.
Definition at line 358 of file symbol_table.cpp.
std::shared_ptr< Symbol > nmodl::symtab::ModelSymbolTable::insert | ( | const std::shared_ptr< Symbol > & | symbol | ) |
insert new symbol into current table
handle update mode insertion
For global symbol tables, same variable can appear in multiple nmodl "global" blocks. It's an error if it appears multiple times in the same nmodl block. To check this we compare symbol properties which are bit flags. If they are not same that means, we have to add new properties to existing symbol. If the properties are same that means symbol are duplicate.
For non-global scopes, check if symbol that we found has same scope name as symbol table. This means variable is being re-declared within the same scope. Otherwise, there is variable with same name in parent scopes and it will shadow the definition. In this case just emit the warning and insert the symbol.
Note: We suppress the warning for the voltage since in most cases it is extern as well as argument and it is fine like that.
Suppress warning for voltage since it is often extern and argument.
Definition at line 286 of file symbol_table.cpp.
void nmodl::symtab::ModelSymbolTable::leave_scope | ( | ) |
leaving current nmodl block
Callback at the exit of every block in nmodl file.
When we reach program node (top most level), there is no parent block and hence use top level symbol table. Otherwise traverse back to parent.
Definition at line 420 of file symbol_table.cpp.
std::shared_ptr< Symbol > nmodl::symtab::ModelSymbolTable::lookup | ( | const std::string & | name | ) |
lookup for symbol into current as well as all parent tables
lookup in current symtab as well as all parent symbol tables
Definition at line 172 of file symbol_table.cpp.
|
inline |
pretty print
Definition at line 290 of file symbol_table.hpp.
void nmodl::symtab::ModelSymbolTable::set_mode | ( | bool | update_mode | ) |
re-initialize members to throw away old symbol tables this is required as symtab visitor pass runs multiple time
Update mode is true if we want to re-use exisiting symbol table.
If there is no symbol table constructed then we toggle mode.
Definition at line 435 of file symbol_table.cpp.
|
private |
insert symbol table in update mode
Insert symbol in the update mode i.e.
symbol table is previously created and we are adding new symbol table.
We set status as "created" because missing symbol means the variable is added by some intermediate passes.
Consider inlining pass which creates a block like:
DERIVATIVE states() { LOCAL xx { LOCAL xx } }
Second xx is not added into symbol table (and hence not visible to other passes like local renamer). In this case we have to do local lookup in the current symtab and insert if doesn't exist.
if no symbol found then safe to insert
for global scope just combine properties
insert into current block's symbol table
Definition at line 244 of file symbol_table.cpp.
|
private |
Definition at line 271 of file symbol_table.cpp.
|
private |
current symbol table being constructed
Definition at line 244 of file symbol_table.hpp.
|
private |
current order of variable being defined
Definition at line 257 of file symbol_table.hpp.
|
private |
name of top level global symbol table
Definition at line 250 of file symbol_table.hpp.
|
private |
symbol table for mod file (always top level symbol table)
Definition at line 241 of file symbol_table.hpp.
|
private |
default mode of symbol table: if update is true then we update exisiting symbols otherwise we throw away old table and construct new one
Definition at line 254 of file symbol_table.hpp.