Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug in generation of C++ component instance definitions #536

Merged
merged 2 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,8 @@ abstract class TopologyCppWriterUtils(
def getComponentNameAsQualIdent(ci: ComponentInstance): String =
getNameAsQualIdent(getComponentName(ci))

def getShortName(name: Name.Qualified): Name.Qualified = {
val ens = s.a.getEnclosingNames(symbol)
name.shortName(ens)
}

def getNameAsQualIdent(name: Name.Qualified): String =
CppWriter.writeQualifiedName(getShortName(name))
CppWriter.writeQualifiedName(name)

def getSpecifierForPhase (phase: Int) (ci: ComponentInstance):
Option[InitSpecifier] = ci.initSpecifierMap.get(phase)
Expand Down
34 changes: 15 additions & 19 deletions compiler/tools/fpp-to-cpp/test/top/BasicTopologyAc.ref.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,20 @@
// Component instances
// ----------------------------------------------------------------------

namespace M {

Active active1(FW_OPTIONAL_NAME("active1"));

}

namespace M {
Active active2;

}

namespace M {

Active active3(FW_OPTIONAL_NAME("active3"));
M::Active active3(FW_OPTIONAL_NAME("active3"));

}

namespace M {

Passive passive1(FW_OPTIONAL_NAME("passive1"));
M::Passive passive1(FW_OPTIONAL_NAME("passive1"));

}

Expand All @@ -39,6 +33,8 @@ namespace M {

}

M::Active active1(FW_OPTIONAL_NAME("active1"));

namespace M {


Expand All @@ -60,19 +56,19 @@ namespace M {
// ----------------------------------------------------------------------

void initComponents(const TopologyState& state) {
M::active1.init(QueueSizes::M_active1, InstanceIds::M_active1);
M::active2.initSpecial();
M::active3.init(QueueSizes::M_active3, InstanceIds::M_active3);
M::passive1.init(InstanceIds::M_passive1);
M::passive2.init(InstanceIds::M_passive2);
active1.init(QueueSizes::active1, InstanceIds::active1);
}

void configComponents(const TopologyState& state) {
M::active2.config();
}

void setBaseIds() {
M::active1.setIdBase(BaseIds::M_active1);
active1.setIdBase(BaseIds::active1);
M::active2.setIdBase(BaseIds::M_active2);
M::active3.setIdBase(BaseIds::M_active3);
M::passive1.setIdBase(BaseIds::M_passive1);
Expand All @@ -84,7 +80,7 @@ namespace M {
// C1
M::passive1.set_p_OutputPort(
0,
M::active1.get_p_InputPort(0)
active1.get_p_InputPort(0)
);

// C2
Expand All @@ -107,31 +103,31 @@ namespace M {
}

void startTasks(const TopologyState& state) {
M::active1.start(
static_cast<Os::Task::ParamType>(Priorities::M_active1),
static_cast<Os::Task::ParamType>(StackSizes::M_active1),
static_cast<Os::Task::ParamType>(CPUs::M_active1),
static_cast<Os::Task::ParamType>(TaskIds::M_active1)
);
M::active2.startSpecial();
M::active3.start(
Os::Task::TASK_DEFAULT, // Default priority
Os::Task::TASK_DEFAULT, // Default stack size
Os::Task::TASK_DEFAULT, // Default CPU
static_cast<Os::Task::ParamType>(TaskIds::M_active3)
);
active1.start(
static_cast<Os::Task::ParamType>(Priorities::active1),
static_cast<Os::Task::ParamType>(StackSizes::active1),
static_cast<Os::Task::ParamType>(CPUs::active1),
static_cast<Os::Task::ParamType>(TaskIds::active1)
);
}

void stopTasks(const TopologyState& state) {
M::active1.exit();
M::active2.stopSpecial();
M::active3.exit();
active1.exit();
}

void freeThreads(const TopologyState& state) {
(void) M::active1.ActiveComponentBase::join();
M::active2.freeSpecial();
(void) M::active3.ActiveComponentBase::join();
(void) active1.ActiveComponentBase::join();
}

void tearDownComponents(const TopologyState& state) {
Expand Down
30 changes: 13 additions & 17 deletions compiler/tools/fpp-to-cpp/test/top/BasicTopologyAc.ref.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,24 @@
// Component instances
// ----------------------------------------------------------------------

namespace M {

//! active1
extern Active active1;

}

namespace M {

//! active2
extern Active active2;
extern M::Active active2;

}

namespace M {

//! active3
extern Active active3;
extern M::Active active3;

}

namespace M {

//! passive1
extern Passive passive1;
extern M::Passive passive1;

}

Expand All @@ -50,6 +43,9 @@ namespace M {

}

//! active1
extern M::Active active1;

namespace M {

// ----------------------------------------------------------------------
Expand All @@ -67,7 +63,7 @@ namespace M {

namespace BaseIds {
enum {
M_active1 = 0x100,
active1 = 0x100,
M_active2 = 0x200,
M_active3 = 0x300,
M_passive1 = 0x300,
Expand All @@ -77,45 +73,45 @@ namespace M {

namespace CPUs {
enum {
M_active1 = 0,
active1 = 0,
};
}

namespace InstanceIds {
enum {
M_active1,
M_active2,
M_active3,
M_passive1,
M_passive2,
active1,
};
}

namespace Priorities {
enum {
M_active1 = 1,
active1 = 1,
};
}

namespace QueueSizes {
enum {
M_active1 = 10,
M_active2 = 10,
M_active3 = 10,
active1 = 10,
};
}

namespace StackSizes {
enum {
M_active1 = 1024,
active1 = 1024,
};
}

namespace TaskIds {
enum {
M_active1,
M_active2,
M_active3,
active1,
};
}

Expand Down
4 changes: 2 additions & 2 deletions compiler/tools/fpp-to-cpp/test/top/CommandsTopologyAc.ref.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@

namespace M {

C c1(FW_OPTIONAL_NAME("c1"));
M::C c1(FW_OPTIONAL_NAME("c1"));

}

namespace M {

C c2(FW_OPTIONAL_NAME("c2"));
M::C c2(FW_OPTIONAL_NAME("c2"));

}

Expand Down
4 changes: 2 additions & 2 deletions compiler/tools/fpp-to-cpp/test/top/CommandsTopologyAc.ref.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
namespace M {

//! c1
extern C c1;
extern M::C c1;

}

namespace M {

//! c2
extern C c2;
extern M::C c2;

}

Expand Down
4 changes: 2 additions & 2 deletions compiler/tools/fpp-to-cpp/test/top/HealthTopologyAc.ref.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@

namespace M {

C c1(FW_OPTIONAL_NAME("c1"));
M::C c1(FW_OPTIONAL_NAME("c1"));

}

namespace M {

C c2(FW_OPTIONAL_NAME("c2"));
M::C c2(FW_OPTIONAL_NAME("c2"));

}

Expand Down
4 changes: 2 additions & 2 deletions compiler/tools/fpp-to-cpp/test/top/HealthTopologyAc.ref.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
namespace M {

//! c1
extern C c1;
extern M::C c1;

}

namespace M {

//! c2
extern C c2;
extern M::C c2;

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// Component instances
// ----------------------------------------------------------------------

N::O::C c(FW_OPTIONAL_NAME("c"));
M::N::O::C c(FW_OPTIONAL_NAME("c"));

namespace M {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// ----------------------------------------------------------------------

//! c
extern N::O::C c;
extern M::N::O::C c;

namespace M {

Expand Down
4 changes: 2 additions & 2 deletions compiler/tools/fpp-to-cpp/test/top/ParamsTopologyAc.ref.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@

namespace M {

C c1(FW_OPTIONAL_NAME("c1"));
M::C c1(FW_OPTIONAL_NAME("c1"));

}

namespace M {

C c2(FW_OPTIONAL_NAME("c2"));
M::C c2(FW_OPTIONAL_NAME("c2"));

}

Expand Down
4 changes: 2 additions & 2 deletions compiler/tools/fpp-to-cpp/test/top/ParamsTopologyAc.ref.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
namespace M {

//! c1
extern C c1;
extern M::C c1;

}

namespace M {

//! c2
extern C c2;
extern M::C c2;

}

Expand Down
11 changes: 8 additions & 3 deletions compiler/tools/fpp-to-cpp/test/top/basic.fpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,14 @@ module M {

}

instance active1: Active base id 0x100 \
at "Active.hpp" \
queue size 10 stack size 1024 priority 1 cpu 0
}

instance active1: M.Active base id 0x100 \
at "Active.hpp" \
queue size 10 stack size 1024 priority 1 cpu 0

module M {

instance active2: Active base id 0x200 \
queue size 10 \
{
Expand Down
Loading