Skip to content

Commit

Permalink
Add val-ops hooks for addr-space and addr-handle types
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 Jan 5, 2024
1 parent f6e5f2b commit c79fc65
Show file tree
Hide file tree
Showing 12 changed files with 494 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/EvalContextBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
#include "BuiltinFuncInfo.h"
#include "EvalContextBase.h"
#include "EvalStackFrame.h"
#include "TaskBindDataTypeValOps.h"
#include "ValOpsAddrSpaceTransparent.h"
#include "ValOpsDataTypeAddrHandle.h"


namespace zsp {
Expand Down Expand Up @@ -95,6 +98,18 @@ void EvalContextBase::init() {
ERROR("Failed to find tool-called function %s", tool_call_funcs.at(i).c_str());
}
}

m_valops[(int)CoreValOpsE::AddrSpaceTransparent] =
vsc::dm::IValOpsUP(new ValOpsAddrSpaceTransparent(this));
m_valops[(int)CoreValOpsE::AddrHandle] =
vsc::dm::IValOpsUP(new ValOpsDataTypeAddrHandle(this));

TaskBindDataTypeValOps binder(this);
for (std::vector<vsc::dm::IDataTypeStructUP>::const_iterator
it=m_ctxt->getDataTypeStructs().begin();
it!=m_ctxt->getDataTypeStructs().end(); it++) {
binder.bind(it->get());
}
}

void EvalContextBase::pushEval(IEval *e, bool owned) {
Expand Down Expand Up @@ -292,6 +307,10 @@ IBuiltinFuncInfo *EvalContextBase::getBuiltinFuncInfo(
}
}

vsc::dm::IValOps *EvalContextBase::getValOps(CoreValOpsE kind) {
return m_valops[(int)kind].get();
}

vsc::dm::ValRef EvalContextBase::getImmVal(
vsc::dm::ITypeExprFieldRef::RootRefKind root_kind,
int32_t root_offset,
Expand Down
3 changes: 3 additions & 0 deletions src/EvalContextBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ class EvalContextBase :
virtual IBuiltinFuncInfo *getBuiltinFuncInfo(
dm::IDataTypeFunction *func) override;

virtual vsc::dm::IValOps *getValOps(CoreValOpsE kind) override;

virtual vsc::dm::ValRef getImmVal(
vsc::dm::ITypeExprFieldRef::RootRefKind root_kind,
int32_t root_offset,
Expand Down Expand Up @@ -219,6 +221,7 @@ class EvalContextBase :
std::vector<dm::IDataTypeFunction *> m_target_functions;
std::vector<IEvalListener *> m_listeners;
dm::IDataTypeFunction *m_functions[(int)EvalContextFunc::NumFunctions];
vsc::dm::IValOpsUP m_valops[(int)CoreValOpsE::Number];
std::unordered_map<dm::IDataTypeFunction *, FuncT> m_func_impl;

EvalContextFlags m_ctxt_flags;
Expand Down
8 changes: 8 additions & 0 deletions src/EvalTypeExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -643,13 +643,21 @@ void EvalTypeExpr::visitTypeExprPythonMethodCall(dm::ITypeExprPythonMethodCall *
break;
*/
} else {
pyapi::IPyEval *py_eval = m_ctxt->getPyEval();
pyapi::PyEvalObj *obj = base.getObj() /*m_ctxt->getPyEval()->getAttr(
base.getObj(), t->getName())*/;
DEBUG("obj=%p", obj);
pyapi::PyEvalObj *args = m_ctxt->getPyEval()->mkTuple(0);
pyapi::PyEvalObj *ret = m_ctxt->getPyEval()->call(obj, args, 0);
DEBUG("ret=%p", ret);

PyObject *ptype, *pvalue, *ptraceback;
py_eval->PyErr_Fetch(&ptype, &pvalue, &ptraceback);
if (ptype || pvalue || ptraceback) {
py_eval->PyErr_Display(ptype, pvalue, ptraceback);
ERROR("Exception occurred");
}

if (!ret) {
setError("Failed to evaluate Python method");
} else {
Expand Down
65 changes: 65 additions & 0 deletions src/TaskBindDataTypeValOps.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* TaskBindDataTypeValOps.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 "TaskBindDataTypeValOps.h"


namespace zsp {
namespace arl {
namespace eval {


TaskBindDataTypeValOps::TaskBindDataTypeValOps(IEvalContextInt *ctxt) : m_ctxt(ctxt) {
DEBUG_INIT("zsp::arl::eval::TaskBindDataTypeValOps", ctxt->getDebugMgr());
}

TaskBindDataTypeValOps::~TaskBindDataTypeValOps() {

}

void TaskBindDataTypeValOps::bind(vsc::dm::IDataType *t) {
DEBUG_ENTER("bind");
t->accept(m_this);
DEBUG_LEAVE("bind");
}

void TaskBindDataTypeValOps::visitDataTypeStruct(vsc::dm::IDataTypeStruct *t) {
DEBUG("visitDataTypeStruct %s", t->name().c_str());
}

void TaskBindDataTypeValOps::visitDataTypeAddrHandle(dm::IDataTypeAddrHandle *t) {
DEBUG_ENTER("visitDataTypeAddrHandle %s", t->name().c_str());
t->setValOps(m_ctxt->getValOps(CoreValOpsE::AddrHandle));
DEBUG("valOps=%p", t->getValOps());
DEBUG_LEAVE("visitDataTypeAddrHandle");
}

void TaskBindDataTypeValOps::visitDataTypeAddrSpaceTransparentC(dm::IDataTypeAddrSpaceTransparentC *t) {
DEBUG_ENTER("visitDataTypeAddrSpaceTransparentC %s", t->name().c_str());
t->setValOps(m_ctxt->getValOps(CoreValOpsE::AddrSpaceTransparent));
DEBUG_LEAVE("visitDataTypeAddrSpaceTransparentC");
}

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

}
}
}
56 changes: 56 additions & 0 deletions src/TaskBindDataTypeValOps.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
* TaskBindDataTypeValOps.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/arl/dm/impl/VisitorBase.h"
#include "zsp/arl/eval/IEvalContextInt.h"

namespace zsp {
namespace arl {
namespace eval {



class TaskBindDataTypeValOps : public virtual dm::VisitorBase {
public:
TaskBindDataTypeValOps(IEvalContextInt *ctxt);

virtual ~TaskBindDataTypeValOps();

void bind(vsc::dm::IDataType *t);

virtual void visitDataTypeStruct(vsc::dm::IDataTypeStruct *t) override;

virtual void visitDataTypeAddrHandle(dm::IDataTypeAddrHandle *t) override;

virtual void visitDataTypeAddrSpaceTransparentC(dm::IDataTypeAddrSpaceTransparentC *t) override;

private:
static dmgr::IDebug *m_dbg;
IEvalContextInt *m_ctxt;

};

}
}
}


59 changes: 59 additions & 0 deletions src/ValOpsAddrSpaceTransparent.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* ValOpsAddrSpaceTransparent.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 "ValOpsAddrSpaceTransparent.h"


namespace zsp {
namespace arl {
namespace eval {


ValOpsAddrSpaceTransparent::ValOpsAddrSpaceTransparent(IEvalContextInt *ctxt) : m_ctxt(ctxt) {
DEBUG_INIT("zsp::arl::eval::ValOpsAddrSpaceTransparent", ctxt->getDebugMgr());

}

ValOpsAddrSpaceTransparent::~ValOpsAddrSpaceTransparent() {

}

void ValOpsAddrSpaceTransparent::initVal(vsc::dm::ValRef &v) {
DEBUG_ENTER("initVal");
DEBUG_LEAVE("initVal");
}

void ValOpsAddrSpaceTransparent::finiVal(vsc::dm::ValRef &v) {
DEBUG_ENTER("finiVal");
DEBUG_LEAVE("finiVal");
}

vsc::dm::ValRef ValOpsAddrSpaceTransparent::copyVal(const vsc::dm::ValRef &src) {
DEBUG_ENTER("copyVal");

DEBUG_LEAVE("copyVal");
}

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

}
}
}
54 changes: 54 additions & 0 deletions src/ValOpsAddrSpaceTransparent.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
* ValOpsAddrSpaceTransparent.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 "vsc/dm/IValOps.h"
#include "zsp/arl/eval/IEvalContextInt.h"

namespace zsp {
namespace arl {
namespace eval {



class ValOpsAddrSpaceTransparent : public virtual vsc::dm::IValOps {
public:
ValOpsAddrSpaceTransparent(IEvalContextInt *ctxt);

virtual ~ValOpsAddrSpaceTransparent();

virtual void initVal(vsc::dm::ValRef &v) override;

virtual void finiVal(vsc::dm::ValRef &v) override;

virtual vsc::dm::ValRef copyVal(const vsc::dm::ValRef &src) override;

private:
static dmgr::IDebug *m_dbg;
IEvalContextInt *m_ctxt;

};

}
}
}


58 changes: 58 additions & 0 deletions src/ValOpsDataTypeAddrHandle.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* ValOpsDataTypeAddrHandle.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 "ValOpsDataTypeAddrHandle.h"


namespace zsp {
namespace arl {
namespace eval {


ValOpsDataTypeAddrHandle::ValOpsDataTypeAddrHandle(IEvalContextInt *ctxt) : m_ctxt(ctxt) {
DEBUG_INIT("zsp::arl::eval::ValOpsDataTypeAddrHandle", ctxt->getDebugMgr());
}

ValOpsDataTypeAddrHandle::~ValOpsDataTypeAddrHandle() {

}

void ValOpsDataTypeAddrHandle::initVal(vsc::dm::ValRef &v) {
DEBUG_ENTER("initVal");
DEBUG_LEAVE("initVal");
}

void ValOpsDataTypeAddrHandle::finiVal(vsc::dm::ValRef &v) {
DEBUG_ENTER("finiVal");
DEBUG_LEAVE("finiVal");
}

vsc::dm::ValRef ValOpsDataTypeAddrHandle::copyVal(const vsc::dm::ValRef &src) {
DEBUG_ENTER("copyVal");

DEBUG_LEAVE("copyVal");
}

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

}
}
}
Loading

0 comments on commit c79fc65

Please sign in to comment.