Skip to content

Commit

Permalink
XX
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 Feb 7, 2024
1 parent 6c33266 commit 46d9128
Show file tree
Hide file tree
Showing 10 changed files with 168 additions and 19 deletions.
16 changes: 9 additions & 7 deletions src/Ast2ArlContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ ast::ISymbolScope *Ast2ArlContext::typeScope() const {
return dynamic_cast<ast::ISymbolScope *>(ret);
}

vsc::dm::IDataTypeStruct *Ast2ArlContext::findType(ast::IScopeChild *t) {
std::map<ast::IScopeChild *, vsc::dm::IDataTypeStruct *>::const_iterator it;
vsc::dm::IDataType *Ast2ArlContext::findType(ast::IScopeChild *t) {
std::map<ast::IScopeChild *, vsc::dm::IDataType *>::const_iterator it;

if ((it=m_type_m.find(t)) != m_type_m.end()) {
return it->second;
Expand All @@ -185,21 +185,23 @@ vsc::dm::IDataTypeStruct *Ast2ArlContext::findType(ast::IScopeChild *t) {
}
}

void Ast2ArlContext::addType(ast::IScopeChild *t, vsc::dm::IDataTypeStruct *dmt) {
void Ast2ArlContext::addType(ast::IScopeChild *t, vsc::dm::IDataType *dmt) {
m_type_m.insert({t, dmt});
}

vsc::dm::IDataTypeStruct *Ast2ArlContext::getType(ast::IScopeChild *t) {
std::map<ast::IScopeChild *, vsc::dm::IDataTypeStruct *>::const_iterator it;
vsc::dm::IDataTypeStruct *ret = 0;
vsc::dm::IDataType *Ast2ArlContext::getType(ast::IScopeChild *t) {
std::map<ast::IScopeChild *, vsc::dm::IDataType *>::const_iterator it;
vsc::dm::IDataType *ret = 0;
it = m_type_m.find(t);

if (it == m_type_m.end()) {
// Failed to find
DEBUG("TODO: failed to find type %p (%s)",
t, zsp::parser::TaskGetName().get(t).c_str());
for (it=m_type_m.begin(); it!=m_type_m.end(); it++) {
DEBUG(" Type: %p %s", it->first, it->second->name().c_str());
DEBUG(" Type: %p %s", it->first,
dynamic_cast<vsc::dm::IDataTypeStruct *>(it->second)?
dynamic_cast<vsc::dm::IDataTypeStruct *>(it->second)->name().c_str():"<primitive>");
}
} else {
ret = it->second;
Expand Down
8 changes: 4 additions & 4 deletions src/Ast2ArlContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ class Ast2ArlContext : public virtual IAst2ArlContext {

virtual ast::ISymbolScope *typeScope() const override;

virtual vsc::dm::IDataTypeStruct *findType(ast::IScopeChild *t) override;
virtual vsc::dm::IDataType *findType(ast::IScopeChild *t) override;

virtual void addType(ast::IScopeChild *t, vsc::dm::IDataTypeStruct *dmt) override;
virtual void addType(ast::IScopeChild *t, vsc::dm::IDataType *dmt) override;

vsc::dm::IDataTypeStruct *getType(ast::IScopeChild *t);
vsc::dm::IDataType *getType(ast::IScopeChild *t);

virtual ast::ISymbolScope *getRoot() override {
return m_root;
Expand Down Expand Up @@ -122,7 +122,7 @@ class Ast2ArlContext : public virtual IAst2ArlContext {
ast::ISymbolScope *m_root;
zsp::parser::IMarkerUP m_marker;
std::vector<std::vector<ast::ISymbolChildrenScope *>> m_scope_s;
std::map<ast::IScopeChild *, vsc::dm::IDataTypeStruct *> m_type_m;
std::map<ast::IScopeChild *, vsc::dm::IDataType *> m_type_m;
std::vector<int32_t> m_type_s_idx_s;
std::vector<bool> m_pyref_s;
std::vector<vsc::dm::ITypeExpr *> m_base_s;
Expand Down
58 changes: 58 additions & 0 deletions src/ElemFactoryPyObj.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* ElemFactoryPyObj.cpp
*
* Copyright 2023 Matthew Ballance and Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Created on:
* Author:
*/
#include "dmgr/impl/DebugMacros.h"
#include "ElemFactoryPyObj.h"


namespace zsp {
namespace fe {
namespace parser {


ElemFactoryPyObj::ElemFactoryPyObj(dmgr::IDebugMgr *dmgr) {
DEBUG_INIT("zsp::fe::parser::ElemFactoryPyObj", dmgr);
}

ElemFactoryPyObj::~ElemFactoryPyObj() {

}

vsc::dm::IDataType *ElemFactoryPyObj::mkDataType(
IAst2ArlContext *ctx,
const std::string &name,
ast::IScopeChild *type) {
DEBUG_ENTER("mkDataType");
vsc::dm::IDataTypeStruct *ret;

ret = ctx->ctxt()->mkDataTypePackedStruct(
name,
arl::dm::Endian::Little
);

DEBUG_LEAVE("mkDataType");
return ret;
}

dmgr::IDebug *ElemFactoryPyObj::m_dbg = 0;

}
}
}
55 changes: 55 additions & 0 deletions src/ElemFactoryPyObj.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**
* ElemFactoryPyObj.h
*
* Copyright 2023 Matthew Ballance and Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Created on:
* Author:
*/
#pragma once
#include "dmgr/IDebugMgr.h"
#include "zsp/fe/parser/impl/ElemFactoryAssocDataBase.h"

namespace zsp {
namespace fe {
namespace parser {



class ElemFactoryPyObj : public virtual ElemFactoryAssocDataBase {
public:
ElemFactoryPyObj(dmgr::IDebugMgr *dmgr);

virtual ~ElemFactoryPyObj();

virtual vsc::dm::IDataType *mkDataType(
IAst2ArlContext *ctx,
const std::string &name,
ast::IScopeChild *type) override;

static ElemFactoryPyObj *create(dmgr::IDebugMgr *dmgr) {
return new ElemFactoryPyObj(dmgr);
}

private:
static dmgr::IDebug *m_dbg;

};

}
}
}


2 changes: 1 addition & 1 deletion src/TaskBuildActivity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ void TaskBuildActivity::visitActivityActionTypeTraversal(ast::IActivityActionTyp
for (uint32_t j=0; j<i->getTarget()->getType_id()->getElems().size(); j++) {
DEBUG(" Elem: %s", i->getTarget()->getType_id()->getElems().at(j)->getId()->getId().c_str());
}
vsc::dm::IDataTypeStruct *dt = m_ctxt->getType(t);
vsc::dm::IDataTypeStruct *dt = dynamic_cast<vsc::dm::IDataTypeStruct *>(m_ctxt->getType(t));

if (dt) {
arl::dm::IDataTypeAction *at = dynamic_cast<arl::dm::IDataTypeAction *>(dt);
Expand Down
22 changes: 22 additions & 0 deletions src/TaskBuildDataType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,28 @@ void TaskBuildDataType::visitStruct(ast::IStruct *i) {
DEBUG_LEAVE("visitStruct");
}

void TaskBuildDataType::visitTypeScope(ast::ITypeScope *i) {
DEBUG_ENTER("visitTypeScope %s", i->getName()->getId().c_str());

if (!m_depth && !(m_type=findType(m_ctxt->symScope()))) {
zsp::ast::IAssocData *assoc_d = TaskGetDataTypeAssocData(m_ctxt).get(m_ctxt->symScope());
IElemFactoryAssocData *elem_f = dynamic_cast<IElemFactoryAssocData *>(assoc_d);

vsc::dm::IDataType *dt = 0;
std::string fullname = getNamespacePrefix() + i->getName()->getId();
if (elem_f && (dt=elem_f->mkDataType(m_ctxt, fullname, i))) {
DEBUG("Using result of element factory");
m_ctxt->addType(m_ctxt->symScope(), dt);

m_type = dt;
} else {
ERROR("Bare TypeScope must provide an element factory");
}
}

DEBUG_LEAVE("visitTypeScope %s", i->getName()->getId().c_str());
}

void TaskBuildDataType::visitField(ast::IField *i) {
DEBUG_ENTER("visitField %s %d", i->getName()->getId().c_str(), m_depth);

Expand Down
2 changes: 2 additions & 0 deletions src/TaskBuildDataType.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ class TaskBuildDataType : public ast::VisitorBase {

virtual void visitStruct(ast::IStruct *i) override;

virtual void visitTypeScope(ast::ITypeScope *i) override;

/**
* Build body elements
*/
Expand Down
16 changes: 12 additions & 4 deletions src/TaskBuildExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,8 +341,7 @@ void TaskBuildExpr::visitExprRefPathContext(ast::IExprRefPathContext *i) {
// scope is a function and we need to look in the
// parameters scope
ast::ISymbolFunctionScope *func = dynamic_cast<ast::ISymbolFunctionScope *>(scope);
scope = func->getPlist();
c = scope->getChildren().at(
c = func->getPlist()->getChildren().at(
i->getTarget()->getPath().at(ii).idx).get();
} break;
default:
Expand Down Expand Up @@ -471,8 +470,10 @@ void TaskBuildExpr::visitExprRefPathContext(ast::IExprRefPathContext *i) {
m_ctxt->getDebugMgr(),
m_ctxt->getRoot());
ast::IScopeChild *ast_scope = resolver.resolve(i->getTarget());
for (uint32_t ii=0; ii<i->getHier_id()->getElems().size(); ii++) {
DEBUG("Path[%d]: %d", ii, i->getHier_id()->getElems().at(ii)->getTarget());
if (DEBUG_EN) {
for (uint32_t ii=0; ii<i->getHier_id()->getElems().size(); ii++) {
DEBUG("Path[%d]: %d", ii, i->getHier_id()->getElems().at(ii)->getTarget());
}
}

for (uint32_t ii=0; ii<i->getHier_id()->getElems().size(); ii++) {
Expand Down Expand Up @@ -606,6 +607,10 @@ void TaskBuildExpr::visitExprRefPathContext(ast::IExprRefPathContext *i) {
DEBUG("Note: root is an expression");
}

if (!m_expr) {
ERROR("Failed to build RefPathContext expression");
}


DEBUG_LEAVE("visitExprRefPathContext %p", m_expr);
}
Expand Down Expand Up @@ -739,6 +744,9 @@ vsc::dm::ITypeExpr *TaskBuildExpr::expr(ast::IExpr *e) {
DEBUG_ENTER("expr");
m_expr = 0;
e->accept(m_this);
if (!m_expr) {
ERROR("Failed to build expression");
}
DEBUG_LEAVE("expr");
return m_expr;
}
Expand Down
2 changes: 2 additions & 0 deletions src/TaskLinkBuiltinTypeElemFactories.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "ElemFactoryAddrClaim.h"
#include "ElemFactoryAddrHandle.h"
#include "ElemFactoryPackedStruct.h"
#include "ElemFactoryPyObj.h"
#include "ElemFactoryReg.h"
#include "ElemFactoryRegGroup.h"
#include "ElemFactoryTransparentAddrSpace.h"
Expand All @@ -43,6 +44,7 @@ static struct LinkTabEntry {
std::function<IElemFactoryAssocData *(dmgr::IDebugMgr *)> ctor;
// IElemFactoryAssocData *(*ctor)();
} LinkTab[] = {
{ {"pyobj"}, &ElemFactoryPyObj::create },
{ {"addr_reg_pkg", "addr_claim_s"}, &ElemFactoryAddrClaim::create },
{ {"addr_reg_pkg", "reg_c"}, &ElemFactoryReg::create },
{ {"addr_reg_pkg", "reg_group_c"}, &ElemFactoryRegGroup::create },
Expand Down
6 changes: 3 additions & 3 deletions src/include/zsp/fe/parser/IAst2ArlContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ class IAst2ArlContext {

virtual ast::ISymbolScope *typeScope() const = 0;

virtual vsc::dm::IDataTypeStruct *findType(ast::IScopeChild *t) = 0;
virtual vsc::dm::IDataType *findType(ast::IScopeChild *t) = 0;

virtual void addType(ast::IScopeChild *t, vsc::dm::IDataTypeStruct *dmt) = 0;
virtual void addType(ast::IScopeChild *t, vsc::dm::IDataType *dmt) = 0;

virtual vsc::dm::IDataTypeStruct *getType(ast::IScopeChild *t) = 0;
virtual vsc::dm::IDataType *getType(ast::IScopeChild *t) = 0;

virtual std::string getQName(const std::string &name) = 0;

Expand Down

0 comments on commit 46d9128

Please sign in to comment.