diff --git a/src/Factory.cpp b/src/Factory.cpp index 5d1a2f2..11fb7bb 100644 --- a/src/Factory.cpp +++ b/src/Factory.cpp @@ -28,6 +28,7 @@ #include "MarkerCollector.h" #include "NameResolver.h" #include "TaskFindElementByLocation.h" +#include "ValInt.h" #include "pss_stdlib.h" @@ -108,6 +109,13 @@ ITaskFindElementByLocation *Factory::mkTaskFindElementByLocation() { return new TaskFindElementByLocation(m_dmgr); } +IValInt *Factory::mkValInt( + bool is_signed, + int32_t width, + int64_t init) { + return new ValInt(is_signed, width, init); +} + IFactory *Factory::inst() { if (!m_inst) { m_inst = FactoryUP(new Factory()); diff --git a/src/Factory.h b/src/Factory.h index 45063a6..b3a4e7d 100644 --- a/src/Factory.h +++ b/src/Factory.h @@ -75,6 +75,11 @@ class Factory : public virtual IFactory { virtual ITaskFindElementByLocation *mkTaskFindElementByLocation() override; + virtual IValInt *mkValInt( + bool is_signed, + int32_t width, + int64_t init=0) override; + static IFactory *inst(); private: diff --git a/src/TaskCompareParamLists.cpp b/src/TaskCompareParamLists.cpp index f678d21..722871e 100644 --- a/src/TaskCompareParamLists.cpp +++ b/src/TaskCompareParamLists.cpp @@ -26,8 +26,9 @@ namespace zsp { namespace parser { -TaskCompareParamLists::TaskCompareParamLists(dmgr::IDebugMgr *dmgr) { - DEBUG_INIT("TaskCompareParamLists", dmgr); +TaskCompareParamLists::TaskCompareParamLists(IFactory *factory) : + m_tref_comp(factory) { + DEBUG_INIT("TaskCompareParamLists", factory->getDebugMgr()); } @@ -71,7 +72,9 @@ bool TaskCompareParamLists::equal( // How do we compare? if (type_value[0]) { - type_value[0]->getDflt()->accept(m_this); + ret = !m_tref_comp.equal( + type_value[0]->getDflt(), + type_value[1]->getDflt()); } else if (expr_value[0] && expr_value[0]->getDflt()) { expr_value[0]->getDflt()->accept(m_this); } else { diff --git a/src/TaskCompareParamLists.h b/src/TaskCompareParamLists.h index 29cb901..065f880 100644 --- a/src/TaskCompareParamLists.h +++ b/src/TaskCompareParamLists.h @@ -21,13 +21,15 @@ #pragma once #include "dmgr/IDebugMgr.h" #include "zsp/ast/impl/VisitorBase.h" +#include "zsp/parser/IFactory.h" +#include "TaskCompareTypeRefs.h" namespace zsp { namespace parser { class TaskCompareParamLists : public ast::VisitorBase { public: - TaskCompareParamLists(dmgr::IDebugMgr *dmgr); + TaskCompareParamLists(IFactory *factory); virtual ~TaskCompareParamLists(); @@ -57,6 +59,7 @@ class TaskCompareParamLists : public ast::VisitorBase { ast::ITemplateValueParamDecl *m_expr_value; const ast::ITemplateParamDeclList *m_plist1; const ast::ITemplateParamDeclList *m_plist2; + TaskCompareTypeRefs m_tref_comp; }; diff --git a/src/TaskCompareTypeRefs.cpp b/src/TaskCompareTypeRefs.cpp new file mode 100644 index 0000000..4fc6b23 --- /dev/null +++ b/src/TaskCompareTypeRefs.cpp @@ -0,0 +1,123 @@ +/* + * TaskCompareTypeRefs.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 "zsp/parser/IVal.h" +#include "zsp/parser/IValInt.h" +#include "TaskCompareTypeRefs.h" +#include "TaskCompareVal.h" + + +namespace zsp { +namespace parser { + + +TaskCompareTypeRefs::TaskCompareTypeRefs(IFactory *factory) : + m_expr_eval(factory), m_comp_val(factory->getDebugMgr()) { + DEBUG_INIT("zsp::parser::TaskCompareTypeRefs", factory->getDebugMgr()); +} + +TaskCompareTypeRefs::~TaskCompareTypeRefs() { + +} + +bool TaskCompareTypeRefs::equal( + ast::IDataType *tref1, + ast::IDataType *tref2) { + DEBUG_ENTER("equal"); + bool ret = true; + ast::IDataTypeInt *type_int = 0; + ast::IDataTypeString *type_str = 0; + + m_type_int = 0; + m_type_int = 0; + tref1->accept(m_this); + type_int = m_type_int; + type_str = m_type_str; + + m_type_int = 0; + m_type_int = 0; + tref2->accept(m_this); + + if (m_type_int && type_int) { + // Both are type int + IVal *w1 = m_expr_eval.eval(m_type_int->getWidth()); + IVal *w2 = m_expr_eval.eval(type_int->getWidth()); + DEBUG("Both are type 'int'"); + DEBUG("T1: width=%d signed=%d", m_type_int->getWidth(), m_type_int->getIs_signed()); + DEBUG("T2: width=%d signed=%d", type_int->getWidth(), type_int->getIs_signed()); + ret &= m_comp_val.equal(w1, w2); + } else if (m_type_str && type_str) { + DEBUG("Both are type 'str'"); + // Nothing else to do... + } else { + ret = false; + } + DEBUG_LEAVE("equal %d", ret); + return ret; +} + +void TaskCompareTypeRefs::visitExprRefPath(ast::IExprRefPath *i) { + DEBUG_ENTER("visitExprRefPath"); + + DEBUG_LEAVE("visitExprRefPath"); +} + +void TaskCompareTypeRefs::visitExprRefPathContext(ast::IExprRefPathContext *i) { + DEBUG_ENTER("visitExprRefPathContext"); + + DEBUG_LEAVE("visitExprRefPathContext"); +} + +void TaskCompareTypeRefs::visitExprRefPathStatic(ast::IExprRefPathStatic *i) { + DEBUG_ENTER("visitExprRefPathStatic"); + + DEBUG_LEAVE("visitExprRefPathStatic"); +} + + +void TaskCompareTypeRefs::visitDataTypeInt(ast::IDataTypeInt *i) { + DEBUG_ENTER("visitDataTypeInt"); + m_type_int = i; + DEBUG_LEAVE("visitDataTypeInt"); +} + +void TaskCompareTypeRefs::visitDataTypeRef(ast::IDataTypeRef *i) { + DEBUG_ENTER("visitDataTypeRef"); + + DEBUG_LEAVE("visitDataTypeRef"); +} + +void TaskCompareTypeRefs::visitDataTypeString(ast::IDataTypeString *i) { + DEBUG_ENTER("visitDataTypeString"); + m_type_str = i; + DEBUG_LEAVE("visitDataTypeString"); +} + +void TaskCompareTypeRefs::visitDataTypeUserDefined(ast::IDataTypeUserDefined *i) { + DEBUG_ENTER("visitDataTypeUserDefined"); + + DEBUG_LEAVE("visitDataTypeUserDefined"); +} + +dmgr::IDebug *TaskCompareTypeRefs::m_dbg = 0; + +} +} diff --git a/src/TaskCompareTypeRefs.h b/src/TaskCompareTypeRefs.h new file mode 100644 index 0000000..1ecfb7e --- /dev/null +++ b/src/TaskCompareTypeRefs.h @@ -0,0 +1,70 @@ +/** + * TaskCompareTypeRefs.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/ast/impl/VisitorBase.h" +#include "zsp/parser/IFactory.h" +#include "TaskEvalExpr.h" +#include "TaskCompareVal.h" + +namespace zsp { +namespace parser { + + + +class TaskCompareTypeRefs : public virtual ast::VisitorBase { +public: + TaskCompareTypeRefs(IFactory *factory); + + virtual ~TaskCompareTypeRefs(); + + bool equal( + ast::IDataType *tref1, + ast::IDataType *tref2); + + virtual void visitExprRefPath(ast::IExprRefPath *i) override; + + virtual void visitExprRefPathContext(ast::IExprRefPathContext *i) override; + + virtual void visitExprRefPathStatic(ast::IExprRefPathStatic *i) override; + + virtual void visitDataTypeInt(ast::IDataTypeInt *i) override; + + virtual void visitDataTypeRef(ast::IDataTypeRef *i) override; + + virtual void visitDataTypeString(ast::IDataTypeString *i) override; + + virtual void visitDataTypeUserDefined(ast::IDataTypeUserDefined *i) override; + + +private: + static dmgr::IDebug *m_dbg; + TaskEvalExpr m_expr_eval; + TaskCompareVal m_comp_val; + ast::IDataTypeInt *m_type_int; + ast::IDataTypeString *m_type_str; + +}; + +} +} + + diff --git a/src/TaskCompareVal.cpp b/src/TaskCompareVal.cpp new file mode 100644 index 0000000..db22f18 --- /dev/null +++ b/src/TaskCompareVal.cpp @@ -0,0 +1,77 @@ +/* + * TaskCompareVal.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 "TaskCompareVal.h" + + +namespace zsp { +namespace parser { + + +TaskCompareVal::TaskCompareVal(dmgr::IDebugMgr *dmgr) { + DEBUG_INIT("zsp::parser::TaskCompareVal", dmgr); +} + +TaskCompareVal::~TaskCompareVal() { + +} + +bool TaskCompareVal::equal(IVal *v1, IVal *v2) { + DEBUG_ENTER("equal"); + m_ret = true; + + if (!v1 || !v2) { + m_ret = false; + } else if (v1->getKind() != v2->getKind()) { + m_ret = false; + } else { + m_val2 = v2; + v1->accept(this); + } + + DEBUG_LEAVE("equal %d", m_ret); + return m_ret; +} + +void TaskCompareVal::visitValInt(IValInt *v) { + DEBUG_ENTER("visitValInt"); + if (m_val2->getKind() != ValKind::Int) { + DEBUG("Unequal values: v_val2::kind=%d", m_val2->getKind()); + m_ret = false; + } else { + IValInt *v2 = dynamic_cast(m_val2); + if (!v->isSigned() && !v2->isSigned()) { + // Perform unsigned comparison + DEBUG("v1=%llu v2=%llu", v->getValS(), v2->getValU()); + m_ret &= (v->getValU() == v2->getValU()); + } else { + // Signed comparison + DEBUG("v1=%lld v2=%lld", v->getValS(), v2->getValU()); + m_ret &= (v->getValS() == v2->getValS()); + } + } + DEBUG_LEAVE("visitValInt ret=%d", m_ret); +} + +dmgr::IDebug *TaskCompareVal::m_dbg = 0; + +} +} diff --git a/src/TaskCompareVal.h b/src/TaskCompareVal.h new file mode 100644 index 0000000..bd74cac --- /dev/null +++ b/src/TaskCompareVal.h @@ -0,0 +1,49 @@ +/** + * TaskCompareVal.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/parser/impl/ValVisitorBase.h" + +namespace zsp { +namespace parser { + + + +class TaskCompareVal : public virtual ValVisitorBase { +public: + TaskCompareVal(dmgr::IDebugMgr *dmgr); + + virtual ~TaskCompareVal(); + + bool equal(IVal *v1, IVal *v2); + + virtual void visitValInt(IValInt *v) override; + +private: + static dmgr::IDebug *m_dbg; + IVal *m_val2; + bool m_ret; +}; + +} +} + + diff --git a/src/TaskEvalExpr.cpp b/src/TaskEvalExpr.cpp new file mode 100644 index 0000000..d85d209 --- /dev/null +++ b/src/TaskEvalExpr.cpp @@ -0,0 +1,160 @@ +/* + * TaskEvalExpr.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 "TaskEvalExpr.h" + + +namespace zsp { +namespace parser { + + +TaskEvalExpr::TaskEvalExpr(IFactory *factory) : m_factory(factory) { + DEBUG_INIT("zsp::parser::TaskEvalExpr", factory->getDebugMgr()); +} + +TaskEvalExpr::~TaskEvalExpr() { + +} + +IVal *TaskEvalExpr::eval(ast::IExpr *expr) { + m_val.reset(); + expr->accept(m_this); + return m_val.release(); +} + +void TaskEvalExpr::visitExprAggregateLiteral(ast::IExprAggregateLiteral *i) { + DEBUG_ENTER("visitExprAggregateLiteral"); + DEBUG("TODO: visitExprAggregateLiteral"); + DEBUG_LEAVE("visitExprAggregateLiteral"); +} + +void TaskEvalExpr::visitExprBin(ast::IExprBin *i) { + DEBUG_ENTER("visitExprBin"); + DEBUG("TODO: visitExprBin"); + DEBUG_LEAVE("visitExprBin"); +} + +void TaskEvalExpr::visitExprBitSlice(ast::IExprBitSlice *i) { + DEBUG_ENTER("visitExprBitSlice"); + DEBUG("TODO: visitExprBitSlice"); + DEBUG_LEAVE("visitExprBitSlice"); +} + +void TaskEvalExpr::visitExprBool(ast::IExprBool *i) { + DEBUG_ENTER("visitExprBool"); + DEBUG("TODO: visitExprBool"); + DEBUG_LEAVE("visitExprBool"); +} + +void TaskEvalExpr::visitExprCast(ast::IExprCast *i) { + DEBUG_ENTER("visitExprCast"); + DEBUG("TODO: visitExprCast"); + DEBUG_LEAVE("visitExprCast"); +} + +void TaskEvalExpr::visitExprCompileHas(ast::IExprCompileHas *i) { + DEBUG_ENTER("visitExprCompileHas"); + DEBUG("TODO: visitExprCompileHas"); + DEBUG_LEAVE("visitExprCompileHas"); +} + +void TaskEvalExpr::visitExprCond(ast::IExprCond *i) { + DEBUG_ENTER("visitExprCond"); + DEBUG("TODO: visitExprCond"); + DEBUG_LEAVE("visitExprCond"); +} + +void TaskEvalExpr::visitExprDomainOpenRangeList(ast::IExprDomainOpenRangeList *i) { + DEBUG_ENTER("visitExprDomainOpenRangeList"); + DEBUG("TODO: visitExprDomainOpenRangeList"); + DEBUG_LEAVE("visitExprDomainOpenRangeList"); +} + +void TaskEvalExpr::visitExprDomainOpenRangeValue(ast::IExprDomainOpenRangeValue *i) { + DEBUG_ENTER("visitExprDomainOpenRangeValue"); + DEBUG("TODO: visitExprDomainOpenRangeValue"); + DEBUG_LEAVE("visitExprDomainOpenRangeValue"); +} + +void TaskEvalExpr::visitExprId(ast::IExprId *i) { + DEBUG_ENTER("visitExprId"); + DEBUG("TODO: visitExprId"); + DEBUG_LEAVE("visitExprId"); +} + +void TaskEvalExpr::visitExprIn(ast::IExprIn *i) { + DEBUG_ENTER("visitExprIn"); + DEBUG("TODO: visitExprIn"); + DEBUG_LEAVE("visitExprIn"); +} + +void TaskEvalExpr::visitExprOpenRangeList(ast::IExprOpenRangeList *i) { + DEBUG_ENTER("visitExprOpenRangeList"); + DEBUG("TODO: visitExprOpenRangeList"); + DEBUG_LEAVE("visitExprOpenRangeList"); +} + +void TaskEvalExpr::visitExprOpenRangeValue(ast::IExprOpenRangeValue *i) { + DEBUG_ENTER("visitExprOpenRangeValue"); + DEBUG("TODO: visitExprOpenRangeValue"); + DEBUG_LEAVE("visitExprOpenRangeValue"); +} + +void TaskEvalExpr::visitExprNull(ast::IExprNull *i) { + DEBUG_ENTER("visitExprNull"); + DEBUG("TODO: visitExprNull"); + DEBUG_LEAVE("visitExprNull"); +} + +void TaskEvalExpr::visitExprSignedNumber(ast::IExprSignedNumber *i) { + DEBUG_ENTER("visitExprSignedNumber"); + m_val = IValUP(m_factory->mkValInt(true, i->getWidth(), i->getValue())); + DEBUG_LEAVE("visitExprSignedNumber"); +} + +void TaskEvalExpr::visitExprString(ast::IExprString *i) { + DEBUG_ENTER("visitExprString"); + DEBUG("TODO: visitExprString"); + DEBUG_LEAVE("visitExprString"); +} + +void TaskEvalExpr::visitExprSubscript(ast::IExprSubscript *i) { + DEBUG_ENTER("visitExprSubscript"); + DEBUG("TODO: visitExprSubscript"); + DEBUG_LEAVE("visitExprSubscript"); +} + +void TaskEvalExpr::visitExprUnary(ast::IExprUnary *i) { + DEBUG_ENTER("visitExprUnary"); + DEBUG("TODO: visitExprUnary"); + DEBUG_LEAVE("visitExprUnary"); +} + +void TaskEvalExpr::visitExprUnsignedNumber(ast::IExprUnsignedNumber *i) { + DEBUG_ENTER("visitExprUnsignedNumber"); + m_val = IValUP(m_factory->mkValInt(false, i->getWidth(), i->getValue())); + DEBUG_LEAVE("visitExprUnsignedNumber"); +} + +dmgr::IDebug *TaskEvalExpr::m_dbg = 0; + +} +} diff --git a/src/TaskEvalExpr.h b/src/TaskEvalExpr.h new file mode 100644 index 0000000..b0a4cf0 --- /dev/null +++ b/src/TaskEvalExpr.h @@ -0,0 +1,92 @@ +/** + * TaskEvalExpr.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/ast/impl/VisitorBase.h" +#include "zsp/parser/IFactory.h" +#include "zsp/parser/IVal.h" + +namespace zsp { +namespace parser { + + + +class TaskEvalExpr : public virtual ast::VisitorBase { +public: + TaskEvalExpr(IFactory *factory); + + virtual ~TaskEvalExpr(); + + IVal *eval(ast::IExpr *expr); + + template T *evalT(ast::IExpr *expr) { + return dynamic_cast(eval(expr)); + } + + virtual void visitExprAggregateLiteral(ast::IExprAggregateLiteral *i) override; + + virtual void visitExprBin(ast::IExprBin *i) override; + + virtual void visitExprBitSlice(ast::IExprBitSlice *i) override; + + virtual void visitExprBool(ast::IExprBool *i) override; + + virtual void visitExprCast(ast::IExprCast *i) override; + + virtual void visitExprCompileHas(ast::IExprCompileHas *i) override; + + virtual void visitExprCond(ast::IExprCond *i) override; + + virtual void visitExprDomainOpenRangeList(ast::IExprDomainOpenRangeList *i) override; + + virtual void visitExprDomainOpenRangeValue(ast::IExprDomainOpenRangeValue *i) override; + + virtual void visitExprId(ast::IExprId *i) override; + + virtual void visitExprIn(ast::IExprIn *i) override; + + virtual void visitExprOpenRangeList(ast::IExprOpenRangeList *i) override; + + virtual void visitExprOpenRangeValue(ast::IExprOpenRangeValue *i) override; + + virtual void visitExprNull(ast::IExprNull *i) override; + + virtual void visitExprSignedNumber(ast::IExprSignedNumber *i) override; + + virtual void visitExprString(ast::IExprString *i) override; + + virtual void visitExprSubscript(ast::IExprSubscript *i) override; + + virtual void visitExprUnary(ast::IExprUnary *i) override; + + virtual void visitExprUnsignedNumber(ast::IExprUnsignedNumber *i) override; + +private: + static dmgr::IDebug *m_dbg; + IFactory *m_factory; + IValUP m_val; + +}; + +} +} + + diff --git a/src/TaskGetSpecializedTemplateType.cpp b/src/TaskGetSpecializedTemplateType.cpp index 5a087a2..62deb71 100644 --- a/src/TaskGetSpecializedTemplateType.cpp +++ b/src/TaskGetSpecializedTemplateType.cpp @@ -57,7 +57,7 @@ ast::ISymbolRefPath *TaskGetSpecializedTemplateType::find( // Search through the list of available specializations for // a matching one - TaskCompareParamLists p_comp(m_factory->getDebugMgr()); + TaskCompareParamLists p_comp(m_factory); for (int32_t i=0; igetSpec_types().size(); i++) { ast::ISymbolTypeScope *sym_type_s_t = type_up->getSpec_types().at(i).get(); ast::ITypeScope *type_s_t = dynamic_cast(sym_type_s_t->getTarget()); diff --git a/src/Val.cpp b/src/Val.cpp new file mode 100644 index 0000000..b0105c7 --- /dev/null +++ b/src/Val.cpp @@ -0,0 +1,37 @@ +/* + * Val.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 "Val.h" + + +namespace zsp { +namespace parser { + + +Val::Val(ValKind kind) : m_kind(kind) { + +} + +Val::~Val() { + +} + +} +} diff --git a/src/Val.h b/src/Val.h new file mode 100644 index 0000000..97ac04e --- /dev/null +++ b/src/Val.h @@ -0,0 +1,47 @@ +/** + * Val.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 "zsp/parser/IVal.h" + +namespace zsp { +namespace parser { + + + +class Val : public virtual IVal { +public: + Val(ValKind kind); + + virtual ~Val(); + + virtual ValKind getKind() const override { + return m_kind; + } + + +protected: + ValKind m_kind; +}; + +} +} + + diff --git a/src/ValArray.cpp b/src/ValArray.cpp new file mode 100644 index 0000000..390727b --- /dev/null +++ b/src/ValArray.cpp @@ -0,0 +1,37 @@ +/* + * ValArray.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 "ValArray.h" + + +namespace zsp { +namespace parser { + + +ValArray::ValArray() { + +} + +ValArray::~ValArray() { + +} + +} +} diff --git a/src/ValArray.h b/src/ValArray.h new file mode 100644 index 0000000..29c33b1 --- /dev/null +++ b/src/ValArray.h @@ -0,0 +1,39 @@ +/** + * ValArray.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 + +namespace zsp { +namespace parser { + + + +class ValArray { +public: + ValArray(); + + virtual ~ValArray(); + +}; + +} +} + + diff --git a/src/ValInt.cpp b/src/ValInt.cpp new file mode 100644 index 0000000..5a5d152 --- /dev/null +++ b/src/ValInt.cpp @@ -0,0 +1,49 @@ +/* + * ValInt.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 "ValInt.h" + + +namespace zsp { +namespace parser { + + +ValInt::ValInt( + bool is_signed, + int32_t width, + int64_t init) : Val(ValKind::Int), + m_is_signed(is_signed), m_width(width) { + m_val.vs = init; +} + +ValInt::~ValInt() { + +} + +int64_t ValInt::getValS() const { + return m_val.vs; +} + +uint64_t ValInt::getValU() const { + return m_val.vs; +} + +} +} diff --git a/src/ValInt.h b/src/ValInt.h new file mode 100644 index 0000000..11475c8 --- /dev/null +++ b/src/ValInt.h @@ -0,0 +1,71 @@ +/** + * ValInt.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 "zsp/parser/IValInt.h" +#include "Val.h" + +namespace zsp { +namespace parser { + + + +class ValInt : + public virtual IValInt, + public virtual Val { +public: + ValInt( + bool is_signed, + int32_t width, + int64_t init + ); + + virtual ~ValInt(); + + virtual bool isSigned() const override { + return m_is_signed; + } + + virtual int32_t getWidth() const override { + return m_width; + } + + virtual void accept(IValVisitor *v) override { + v->visitValInt(this); + } + + virtual int64_t getValS() const override; + + virtual uint64_t getValU() const override; + +private: + bool m_is_signed; + int32_t m_width; + union { + uint64_t vs; + uint64_t *vp; + } m_val; + +}; + +} +} + + diff --git a/src/ValStr.cpp b/src/ValStr.cpp new file mode 100644 index 0000000..1347bff --- /dev/null +++ b/src/ValStr.cpp @@ -0,0 +1,37 @@ +/* + * ValStr.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 "ValStr.h" + + +namespace zsp { +namespace parser { + + +ValStr::ValStr() { + +} + +ValStr::~ValStr() { + +} + +} +} diff --git a/src/ValStr.h b/src/ValStr.h new file mode 100644 index 0000000..52f360c --- /dev/null +++ b/src/ValStr.h @@ -0,0 +1,39 @@ +/** + * ValStr.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 + +namespace zsp { +namespace parser { + + + +class ValStr { +public: + ValStr(); + + virtual ~ValStr(); + +}; + +} +} + + diff --git a/src/ValStruct.cpp b/src/ValStruct.cpp new file mode 100644 index 0000000..f64fe70 --- /dev/null +++ b/src/ValStruct.cpp @@ -0,0 +1,37 @@ +/* + * ValStruct.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 "ValStruct.h" + + +namespace zsp { +namespace parser { + + +ValStruct::ValStruct() { + +} + +ValStruct::~ValStruct() { + +} + +} +} diff --git a/src/ValStruct.h b/src/ValStruct.h new file mode 100644 index 0000000..8b0dc41 --- /dev/null +++ b/src/ValStruct.h @@ -0,0 +1,39 @@ +/** + * ValStruct.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 + +namespace zsp { +namespace parser { + + + +class ValStruct { +public: + ValStruct(); + + virtual ~ValStruct(); + +}; + +} +} + + diff --git a/src/include/zsp/parser/IFactory.h b/src/include/zsp/parser/IFactory.h index e1b56f1..0369e7b 100644 --- a/src/include/zsp/parser/IFactory.h +++ b/src/include/zsp/parser/IFactory.h @@ -1,6 +1,7 @@ #pragma once #include "dmgr/IDebugMgr.h" +#include "zsp/ast/IFactory.h" #include "zsp/parser/IAstBuilder.h" #include "zsp/parser/ILinker.h" #include "zsp/parser/IMarkerCollector.h" @@ -8,7 +9,7 @@ #include "zsp/parser/INameResolver.h" #include "zsp/parser/ISymbolTable.h" #include "zsp/parser/ITaskFindElementByLocation.h" -#include "zsp/ast/IFactory.h" +#include "zsp/parser/IValFactory.h" namespace zsp { namespace parser { @@ -18,7 +19,7 @@ class IMarkerListener; class IFactory; using IFactoryUP=std::unique_ptr; -class IFactory { +class IFactory : public virtual IValFactory { public: virtual ~IFactory() { } diff --git a/src/include/zsp/parser/IVal.h b/src/include/zsp/parser/IVal.h new file mode 100644 index 0000000..3031ceb --- /dev/null +++ b/src/include/zsp/parser/IVal.h @@ -0,0 +1,53 @@ +/** + * IVal.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 +#include +#include "zsp/parser/IValVisitor.h" + +namespace zsp { +namespace parser { + +enum class ValKind { + Bool, + Int, + Str, + Struct, + Array +}; + +class IVal; +using IValUP=std::unique_ptr; +class IVal { +public: + + virtual ~IVal() { } + + virtual ValKind getKind() const = 0; + + virtual void accept(IValVisitor *v) = 0; + +}; + +} /* namespace parser */ +} /* namespace zsp */ + + diff --git a/src/include/zsp/parser/IValArray.h b/src/include/zsp/parser/IValArray.h new file mode 100644 index 0000000..37414d0 --- /dev/null +++ b/src/include/zsp/parser/IValArray.h @@ -0,0 +1,39 @@ +/** + * IValArray.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 "zsp/parser/IVal.h" + +namespace zsp { +namespace parser { + + + +class IValArray : public virtual IVal { +public: + + virtual ~IValArray() { } + +}; + +} /* namespace parser */ +} /* namespace zsp */ + + diff --git a/src/include/zsp/parser/IValFactory.h b/src/include/zsp/parser/IValFactory.h new file mode 100644 index 0000000..92c1812 --- /dev/null +++ b/src/include/zsp/parser/IValFactory.h @@ -0,0 +1,47 @@ +/** + * IValFactory.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 "zsp/parser/IValInt.h" +#include "zsp/parser/IValStr.h" +#include "zsp/parser/IValStruct.h" +#include "zsp/parser/IValArray.h" + +namespace zsp { +namespace parser { + + + +class IValFactory { +public: + + virtual ~IValFactory() { } + + virtual IValInt *mkValInt( + bool is_signed, + int32_t width, + int64_t init=0) = 0; + +}; + +} /* namespace parser */ +} /* namespace zsp */ + + diff --git a/src/include/zsp/parser/IValInt.h b/src/include/zsp/parser/IValInt.h new file mode 100644 index 0000000..935f516 --- /dev/null +++ b/src/include/zsp/parser/IValInt.h @@ -0,0 +1,47 @@ +/** + * IValInt.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 "zsp/parser/IVal.h" + +namespace zsp { +namespace parser { + + + +class IValInt : public virtual IVal { +public: + + virtual ~IValInt() { } + + virtual bool isSigned() const = 0; + + virtual int32_t getWidth() const = 0; + + virtual int64_t getValS() const = 0; + + virtual uint64_t getValU() const = 0; + +}; + +} /* namespace parser */ +} /* namespace zsp */ + + diff --git a/src/include/zsp/parser/IValStr.h b/src/include/zsp/parser/IValStr.h new file mode 100644 index 0000000..a7a51a3 --- /dev/null +++ b/src/include/zsp/parser/IValStr.h @@ -0,0 +1,39 @@ +/** + * IValStr.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 "zsp/parser/IVal.h" + +namespace zsp { +namespace parser { + + + +class IValStr : public virtual IVal { +public: + + virtual ~IValStr() { } + +}; + +} /* namespace parser */ +} /* namespace zsp */ + + diff --git a/src/include/zsp/parser/IValStruct.h b/src/include/zsp/parser/IValStruct.h new file mode 100644 index 0000000..1f55211 --- /dev/null +++ b/src/include/zsp/parser/IValStruct.h @@ -0,0 +1,39 @@ +/** + * IValStruct.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 "zsp/parser/IVal.h" + +namespace zsp { +namespace parser { + + + +class IValStruct : public virtual IVal { +public: + + virtual ~IValStruct() { } + +}; + +} /* namespace parser */ +} /* namespace zsp */ + + diff --git a/src/include/zsp/parser/IValVisitor.h b/src/include/zsp/parser/IValVisitor.h new file mode 100644 index 0000000..b396e6a --- /dev/null +++ b/src/include/zsp/parser/IValVisitor.h @@ -0,0 +1,53 @@ +/** + * IValVisitor.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 + +namespace zsp { +namespace parser { + +class IVal; +class IValInt; +class IValStr; +class IValStruct; +class IValArray; + + +class IValVisitor { +public: + + virtual ~IValVisitor() { } + + virtual void visitVal(IVal *v) = 0; + + virtual void visitValInt(IValInt *v) = 0; + + virtual void visitValStr(IValStr *v) = 0; + + virtual void visitValStruct(IValStruct *v) = 0; + + virtual void visitValArray(IValArray *v) = 0; + +}; + +} /* namespace parser */ +} /* namespace zsp */ + + diff --git a/src/include/zsp/parser/impl/ValVisitorBase.h b/src/include/zsp/parser/impl/ValVisitorBase.h new file mode 100644 index 0000000..77d25a5 --- /dev/null +++ b/src/include/zsp/parser/impl/ValVisitorBase.h @@ -0,0 +1,61 @@ +/** + * ValVisitorBase.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 "zsp/parser/IValVisitor.h" +#include "zsp/parser/IValInt.h" +#include "zsp/parser/IValStr.h" +#include "zsp/parser/IValStruct.h" +#include "zsp/parser/IValArray.h" + +namespace zsp { +namespace parser { + + + +class ValVisitorBase : public virtual IValVisitor { +public: + + virtual ~ValVisitorBase() { } + + virtual void visitVal(IVal *v) override { } + + virtual void visitValInt(IValInt *v) override { + visitVal(v); + } + + virtual void visitValStr(IValStr *v) override { + visitVal(v); + } + + virtual void visitValStruct(IValStruct *v) override { + + } + + virtual void visitValArray(IValArray *v) override { + + } + +}; + +} /* namespace parser */ +} /* namespace zsp */ + + diff --git a/tests/src/TestRegModel.cpp b/tests/src/TestRegModel.cpp index 916f70d..f6b7e35 100644 --- a/tests/src/TestRegModel.cpp +++ b/tests/src/TestRegModel.cpp @@ -65,6 +65,7 @@ TEST_F(TestRegModel, reg_group_c_field) { component my_regs : reg_group_c { reg_c r1; + reg_c r2; } component pss_top {