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

C++ code generation for telemetry packets #632

Open
wants to merge 34 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
49242b1
Update names of generated files
bocchino Feb 24, 2025
5d58a3a
Update unit tests
bocchino Feb 24, 2025
23d3c6c
Revise generated file names
bocchino Feb 24, 2025
bd21972
Revise topology C++ code gen
bocchino Feb 24, 2025
61dc635
Revise C++ code gen for packets
bocchino Feb 25, 2025
47a10be
Revise code gen for tlm packets
bocchino Feb 25, 2025
3b9b0ca
Revise code gen for tlm packets
bocchino Feb 25, 2025
0152af0
Revise tlm packet code gen
bocchino Feb 25, 2025
cfa46c4
Revise code gen for tlm packets
bocchino Feb 25, 2025
7683e88
Revise code gen for tlm packets
bocchino Feb 25, 2025
14ff7f9
Revise code gen for tlm packets
bocchino Feb 25, 2025
f299688
Revise code gen for tlm packets
bocchino Feb 25, 2025
c4d6f4a
Revise code gen for tlm packets
bocchino Feb 25, 2025
f1e4364
Revise code gen for tlm packets
bocchino Feb 25, 2025
bcfbd5c
Revise code gen for tlm packets
bocchino Feb 25, 2025
d2ff134
Revise code gen for tlm packets
bocchino Feb 25, 2025
21819f4
Revise code gen for tlm packets
bocchino Feb 26, 2025
d9461a9
Revise code gen for tlm packets
bocchino Feb 26, 2025
c235cd8
Merge branch 'main' into issue-567-tlm-packet-cpp
bocchino Feb 26, 2025
fc19582
Revise code gen for tlm packets
bocchino Feb 26, 2025
82e9c3c
Revise code gen for tlm packets
bocchino Feb 26, 2025
306ce06
Revise code gen for tlm packets
bocchino Feb 26, 2025
b175afb
Revise code gen for tlm packets
bocchino Feb 26, 2025
02e295e
Revise code gen for tlm packets
bocchino Feb 26, 2025
f50393c
Revise code gen for tlm packets
bocchino Feb 26, 2025
e9b0a7a
Revise code gen for tlm packets
bocchino Feb 26, 2025
eac070d
Add tests for tlm packet code gen
bocchino Feb 26, 2025
2212c1e
Add tests for tlm packet code gen
bocchino Feb 27, 2025
948e833
Revise tests for tlm packet code gen
bocchino Feb 27, 2025
3d2e335
Revise code gen for tlm packets
bocchino Feb 27, 2025
13b6554
Update tests for tlm packet code gen
bocchino Feb 27, 2025
d64afab
Revise tests for tlm packet code gen
bocchino Feb 27, 2025
e76badf
Merge branch 'main' into issue-567-tlm-packet-cpp
bocchino Feb 27, 2025
faeebb7
Merge branch 'main' into issue-567-tlm-packet-cpp
bocchino Feb 28, 2025
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 @@ -84,10 +84,10 @@ object Dictionary {
/** A telemetry channel entry in the dictionary */
case class TlmChannelEntry(instance: ComponentInstance, tlmChannel: TlmChannel) {

def getName = {
def getQualifiedName = {
val instanceName = instance.qualifiedName
val channelName = tlmChannel.getName
s"$instanceName.$channelName"
Name.Qualified.fromIdentList(instanceName.toIdentList :+ channelName)
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ object TlmPacketSet {
if !usedIdSet.contains(id) && !tpg.omittedIdSet.contains(id)
then {
val entry = d.tlmChannelEntryMap(id)
val channelName = entry.getName
val channelName = entry.getQualifiedName
val instanceLoc = t.instanceMap(entry.instance)._2
val channelLoc = entry.tlmChannel.getLoc
val msg = s"""|telemetry channel $channelName is neither used nor marked as omitted
Expand All @@ -109,7 +109,7 @@ object TlmPacketSet {
if usedIdSet.contains(id) && tpg.omittedIdSet.contains(id)
then {
val entry = d.tlmChannelEntryMap(id)
val channelName = entry.getName
val channelName = entry.getQualifiedName
val usedLoc = usedIdLocationMap(id)
val omittedLoc = tpg.omittedLocationMap(id)
val msg = s"""|telemetry channel $channelName is both used and marked omitted
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,24 @@ object AutocodeCppWriter extends CppWriter {
) = {
val node = aNode._2
val data = node.data
val cppDoc = TopologyCppWriter(s, aNode).write
val ts = Symbol.Topology(aNode)
val t = s.a.topologyMap(ts)
val d = s.a.dictionaryMap(ts)
val a = s.a.copy(topology = Some(t), dictionary = Some(d))
val s1 = s.copy(a = a)
val cppDoc = TopologyCppWriter(s1, aNode).write
for {
s <- CppWriter.writeCppDoc(s1, cppDoc)
s <- visitList(s, data.members, matchTopologyMember)
}
yield s
}

override def specTlmPacketSetAnnotatedNode(
s: State,
aNode: Ast.Annotated[AstNode[Ast.SpecTlmPacketSet]]
) = {
val cppDoc = TlmPacketSetCppWriter(s, aNode).write
CppWriter.writeCppDoc(s, cppDoc)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,27 @@ object ComputeAutocodeCppFiles extends ComputeCppFiles {
aNode: Ast.Annotated[AstNode[Ast.DefTopology]]
) = {
val node = aNode._2
val name = node.data.name
val data = node.data
val name = data.name
val loc = Locations.get(node.id)
val a = s.a.copy(parentSymbol = Some(Symbol.Topology(aNode)))
val s1 = s.copy(a = a)
for {
s <- addMappings(s1, ComputeCppFiles.FileNames.getTopology(name), Some(loc))
s <- visitList (s, data.members, matchTopologyMember)
}
yield s
}

override def specTlmPacketSetAnnotatedNode(
s: State,
aNode: Ast.Annotated[AstNode[Ast.SpecTlmPacketSet]]
) = {
val node = aNode._2
val loc = Locations.get(node.id)
addMappings(s, ComputeCppFiles.FileNames.getTopology(name), Some(loc))
val topSymbol = s.a.parentSymbol.get
val name = s"${topSymbol.getUnqualifiedName}_${node.data.name}"
addMappings(s, ComputeCppFiles.FileNames.getTlmPacketSet(name), Some(loc))
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -84,19 +84,22 @@ object ComputeCppFiles {
/** Gets the C++ file name for generated enums */
def getEnum(baseName: String) = s"${baseName}EnumAc"

/** Gets the C++ file name for generated ports */
def getPort(baseName: String) = s"${baseName}PortAc"

/** Gets the C++ file name for state machines */
def getStateMachine(baseName: String, kind: StateMachine.Kind) =
kind match {
case StateMachine.Kind.External => s"${baseName}"
case StateMachine.Kind.Internal => s"${baseName}StateMachineAc"
}

/** Gets the C++ file name for generated ports */
def getPort(baseName: String) = s"${baseName}PortAc"

/** Gets the C++ file name for generated structs */
def getStruct(baseName: String) = s"${baseName}SerializableAc"

/** Gets the C++ file name for a telemetry packet set */
def getTlmPacketSet(baseName: String) = s"${baseName}TlmPacketsAc"

/** Gets the C++ file name for generated topologies */
def getTopology(baseName: String): String = s"${baseName}TopologyAc"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package fpp.compiler.codegen

import fpp.compiler.analysis.*
import fpp.compiler.util.*
import fpp.compiler.analysis._
import fpp.compiler.ast._
import fpp.compiler.util._
import fpp.compiler.codegen.CppWriterState.builtInTypes

/** C++ Writer state */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ trait CppWriterUtils extends LineUtils {
def wrapInEnumClass(
name: String,
ll: List[Line],
tyOpt: Option[String]
tyOpt: Option[String] = None
): List[Line] = {
val prefix = tyOpt match {
case Some(ty) => s"enum class $name : $ty {"
Expand Down
Loading