Skip to content

Commit

Permalink
Tweaks to support functions declared in namespaces
Browse files Browse the repository at this point in the history
Signed-off-by: Matthew Ballance <matt.ballance@gmail.com>
  • Loading branch information
mballance committed Oct 15, 2023
1 parent fab7043 commit 5d310b0
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 36 deletions.
5 changes: 5 additions & 0 deletions src/AstBuilderInt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down
9 changes: 9 additions & 0 deletions src/TaskBuildSymbolTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<ast::ISymbolScope *>(scope->getChildren().at(p_it->second));
new_scope->setUpper(m_scope_s.back());
m_scope_s.push_back(new_scope);
scope = new_scope;
}
Expand Down Expand Up @@ -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<ast::IEnumItemUP>::const_iterator
it=i->getItems().begin();
Expand Down Expand Up @@ -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<ast::IExecStmtUP>::const_iterator
it=i->getChildren().begin();
Expand All @@ -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<ast::IScopeChildUP>::const_iterator
it=i->getChildren().begin();
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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<ast::IScopeChildUP>::const_iterator
it=i->getChildren().begin();
Expand Down
41 changes: 32 additions & 9 deletions src/include/zsp/parser/impl/TaskGetName.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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;
};

}
Expand Down
55 changes: 28 additions & 27 deletions src/stdlib/addr_reg_pkg.pss
Original file line number Diff line number Diff line change
Expand Up @@ -101,47 +101,48 @@ 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<bit[8]> data,
int size);
function void write_bytes(addr_handle_t hndl, list<bit[8]> data);
*/
};

enum reg_access {READWRITE, READONLY, WRITEONLY};
pure component reg_c < type R,
reg_access ACC = READWRITE,
int SZ = (8*sizeof_s<R>::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<R>::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;
int index;
};
*/
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<node_s> 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<node_s> path);
*/
function void set_handle(addr_handle_t addr);
import solve function set_handle;
};

}

0 comments on commit 5d310b0

Please sign in to comment.