diff --git a/src/AstBuilderInt.cpp b/src/AstBuilderInt.cpp index 43af8d1..2954839 100644 --- a/src/AstBuilderInt.cpp +++ b/src/AstBuilderInt.cpp @@ -1766,6 +1766,7 @@ void AstBuilderInt::addChild(ast::IConstraintScope *c, Token *start, Token *end) (int32_t)end->getLine(), (int32_t)end->getCharPositionInLine()+1 }); + c->setParent(scope()); scope()->getChildren().push_back(ast::IScopeChildUP(c)); if (m_collectDocStrings && start) { @@ -1784,6 +1785,7 @@ void AstBuilderInt::addChild(ast::IExecScope *c, Token *start, Token *end) { (int32_t)end->getLine(), (int32_t)end->getCharPositionInLine()+1 }); + c->setParent(scope()); scope()->getChildren().push_back(ast::IScopeChildUP(c)); if (m_collectDocStrings && start) { @@ -1802,6 +1804,7 @@ void AstBuilderInt::addChild(ast::IFunctionDefinition *c, Token *start, Token *e (int32_t)end->getLine(), (int32_t)end->getCharPositionInLine()+1 }); + c->setParent(scope()); scope()->getChildren().push_back(ast::IScopeChildUP(c)); if (m_collectDocStrings && start) { @@ -1820,6 +1823,7 @@ void AstBuilderInt::addChild(ast::INamedScope *c, Token *start, Token *end) { (int32_t)end->getLine(), (int32_t)end->getCharPositionInLine()+1 }); + c->setParent(scope()); scope()->getChildren().push_back(ast::IScopeChildUP(c)); if (m_collectDocStrings && start) { @@ -1838,6 +1842,7 @@ void AstBuilderInt::addChild(ast::IScope *c, Token *start, Token *end) { (int32_t)end->getLine(), (int32_t)end->getCharPositionInLine() }); + c->setParent(scope()); scope()->getChildren().push_back(ast::IScopeChildUP(c)); if (m_collectDocStrings && start) { diff --git a/src/TaskBuildSymbolTree.cpp b/src/TaskBuildSymbolTree.cpp index 2679a86..8dee064 100644 --- a/src/TaskBuildSymbolTree.cpp +++ b/src/TaskBuildSymbolTree.cpp @@ -122,11 +122,13 @@ void TaskBuildSymbolTree::visitPackageScope(ast::IPackageScope *i) { scope->getSymtab().insert({(*id_it)->getId(), id}); scope->getChildren().push_back(pkg); scope->getOwned().push_back(ast::IScopeChildUP(pkg)); + pkg->setUpper(m_scope_s.back()); m_scope_s.push_back(pkg); scope = pkg; } else { ast::ISymbolScope *new_scope = dynamic_cast(scope->getChildren().at(p_it->second)); + new_scope->setUpper(m_scope_s.back()); m_scope_s.push_back(new_scope); scope = new_scope; } @@ -169,6 +171,7 @@ void TaskBuildSymbolTree::visitEnumDecl(ast::IEnumDecl *i) { scope->getChildren().push_back(ts); scope->getOwned().push_back(ast::IScopeChildUP(ts)); + ts->setUpper(m_scope_s.back()); m_scope_s.push_back(ts); for (std::vector::const_iterator it=i->getItems().begin(); @@ -220,6 +223,7 @@ void TaskBuildSymbolTree::visitExecScope(ast::IExecScope *i) { scope->setTarget(i); m_scope_s.back()->getChildren().push_back(scope); m_scope_s.back()->getOwned().push_back(ast::IScopeChildUP(scope)); + scope->setUpper(m_scope_s.back()); m_scope_s.push_back(scope); for (std::vector::const_iterator it=i->getChildren().begin(); @@ -241,6 +245,7 @@ void TaskBuildSymbolTree::visitExtendType(ast::IExtendType *i) { m_scope_s.back()->getOwned().push_back(ast::IScopeChildUP(ext)); m_scope_s.back()->getChildren().push_back(ext); + ext->setUpper(m_scope_s.back()); m_scope_s.push_back(ext); for (std::vector::const_iterator it=i->getChildren().begin(); @@ -311,6 +316,7 @@ void TaskBuildSymbolTree::visitFunctionDefinition(ast::IFunctionDefinition *i) { id, i->getProto()->getName()->getId()); func_sym->setLocation(i->getLocation()); + func_sym->setUpper(m_scope_s.back()); m_scope_s.back()->getSymtab().insert({func_sym->getName(), id}); m_scope_s.back()->getChildren().push_back(func_sym); @@ -343,6 +349,7 @@ void TaskBuildSymbolTree::visitFunctionDefinition(ast::IFunctionDefinition *i) { int32_t id = func_sym->getChildren().size(); ast::ISymbolScope *body = m_factory->mkSymbolScope(id, ""); body->setLocation(i->getLocation()); + body->setUpper(m_scope_s.back()); m_scope_s.push_back(body); func_sym->setBody(body); func_sym->getChildren().push_back(body); @@ -443,6 +450,7 @@ void TaskBuildSymbolTree::visitFunctionPrototype(ast::IFunctionPrototype *i) { id, i->getName()->getId()); func_sym->setLocation(i->getLocation()); + func_sym->setUpper(m_scope_s.back()); m_scope_s.back()->getSymtab().insert({func_sym->getName(), id}); m_scope_s.back()->getChildren().push_back(func_sym); } @@ -551,6 +559,7 @@ void TaskBuildSymbolTree::visitTypeScope(ast::ITypeScope *i) { scope->getChildren().push_back(ts); scope->getOwned().push_back(ast::IScopeChildUP(ts)); + ts->setUpper(m_scope_s.back()); m_scope_s.push_back(ts); for (std::vector::const_iterator it=i->getChildren().begin(); diff --git a/src/include/zsp/parser/impl/TaskGetName.h b/src/include/zsp/parser/impl/TaskGetName.h index b31caea..649e758 100644 --- a/src/include/zsp/parser/impl/TaskGetName.h +++ b/src/include/zsp/parser/impl/TaskGetName.h @@ -34,22 +34,42 @@ class TaskGetName : public virtual ast::VisitorBase { const std::string &get(ast::IScopeChild *c, bool bottom_up=false) { m_ret = ""; if (bottom_up) { - ast::IScopeChild *ci = c; + m_sym_s = 0; c->accept(m_this); std::string full_path; - do { - m_ret = ""; - c->accept(m_this); + if (m_sym_s) { + // This is a symbol scope + ast::ISymbolScope *ss = m_sym_s; + + full_path = m_ret; + + while ((ss=ss->getUpper())) { + m_ret = ""; + ss->accept(m_this); - if (full_path.size() && m_ret.size()) { - full_path = "::" + full_path; + if (full_path.size() && m_ret.size()) { + full_path = "::" + full_path; + } + full_path = m_ret + full_path; } - full_path = m_ret + full_path; - } while ((ci=ci->getParent())); - m_ret = full_path; + m_ret = full_path; + } else { + ast::IScopeChild *ci = c; + do { + m_ret = ""; + ci->accept(m_this); + + if (full_path.size() && m_ret.size()) { + full_path = "::" + full_path; + } + full_path = m_ret + full_path; + } while ((ci=ci->getParent())); + + m_ret = full_path; + } } else { c->accept(m_this); } @@ -66,14 +86,17 @@ class TaskGetName : public virtual ast::VisitorBase { virtual void visitSymbolScope(ast::ISymbolScope *i) override { m_ret = i->getName(); + m_sym_s = i; } virtual void visitSymbolTypeScope(ast::ISymbolTypeScope *i) override { m_ret = i->getName(); + m_sym_s = i; } private: std::string m_ret; + ast::ISymbolScope *m_sym_s; }; } diff --git a/src/stdlib/addr_reg_pkg.pss b/src/stdlib/addr_reg_pkg.pss index d983c32..1c3c347 100644 --- a/src/stdlib/addr_reg_pkg.pss +++ b/src/stdlib/addr_reg_pkg.pss @@ -101,33 +101,34 @@ function void read_struct (addr_handle_t hndl, struct packed_struct); function void write_struct(addr_handle_t hndl, struct packed_struct); */ extend component executor_base_c { - function bit[8] read8(addr_handle_t hndl); - function bit[16] read16(addr_handle_t hndl); - function bit[32] read32(addr_handle_t hndl); - function bit[64] read64(addr_handle_t hndl); - function void write8 (addr_handle_t hndl, bit[8] data); - function void write16(addr_handle_t hndl, bit[16] data); - function void write32(addr_handle_t hndl, bit[32] data); - function void write64(addr_handle_t hndl, bit[64] data); + function bit[8] read8(addr_handle_t hndl); + function bit[16] read16(addr_handle_t hndl); + function bit[32] read32(addr_handle_t hndl); + function bit[64] read64(addr_handle_t hndl); + function void write8 (addr_handle_t hndl, bit[8] data); + function void write16(addr_handle_t hndl, bit[16] data); + function void write32(addr_handle_t hndl, bit[32] data); + function void write64(addr_handle_t hndl, bit[64] data); /** TODO: list function void read_bytes (addr_handle_t hndl, list data, int size); function void write_bytes(addr_handle_t hndl, list data); */ }; + enum reg_access {READWRITE, READONLY, WRITEONLY}; -pure component reg_c < type R, - reg_access ACC = READWRITE, -int SZ = (8*sizeof_s::nbytes)> { -function R read(); - import target function read; - function void write(R r); - import target function write; - function bit[SZ] read_val(); - import target function read_val; - function void write_val(bit[SZ] r); -import target function write_val; + +pure component reg_c < type R, reg_access ACC = READWRITE, int SZ = (8*sizeof_s::nbytes)> { + function R read(); + import target function read; + function void write(R r); + import target function write; + function bit[SZ] read_val(); + import target function read_val; + function void write_val(bit[SZ] r); + import target function write_val; }; + /* struct node_s { string name; @@ -135,13 +136,13 @@ struct node_s { }; */ pure component reg_group_c { - pure function bit[64] get_offset_of_instance(string name); - pure function bit[64] get_offset_of_instance_array(string name, - int index); - /** TODO: list - pure function bit[64] get_offset_of_path(list path); - */ - function void set_handle(addr_handle_t addr); - import solve function set_handle; + pure function bit[64] get_offset_of_instance(string name); + pure function bit[64] get_offset_of_instance_array(string name, int index); + /** TODO: list + pure function bit[64] get_offset_of_path(list path); + */ + function void set_handle(addr_handle_t addr); + import solve function set_handle; }; + }