diff --git a/compiler/lib/src/main/scala/analysis/Analysis.scala b/compiler/lib/src/main/scala/analysis/Analysis.scala index f8999ddfa..e4956353f 100644 --- a/compiler/lib/src/main/scala/analysis/Analysis.scala +++ b/compiler/lib/src/main/scala/analysis/Analysis.scala @@ -47,7 +47,7 @@ case class Analysis( /** The mapping from type and constant symbols, expressions, * and type names to their types */ typeMap: Map[AstNode.Id, Type] = Map(), - /** THe mapping from constant symbols and expressions to their values. */ + /** The mapping from constant symbols and expressions to their values. */ valueMap: Map[AstNode.Id, Value] = Map(), /** The set of symbols used. Used during code generation. */ usedSymbolSet: Set[Symbol] = Set(), @@ -70,7 +70,11 @@ case class Analysis( /** The dictionary under construction */ dictionary: Option[Dictionary] = None, /** The telemetry packet set under construction */ - tlmPacketSet: Option[TlmPacketSet] = None + tlmPacketSet: Option[TlmPacketSet] = None, + /** Whether a dictionary is needed in code generation */ + dictionaryNeeded: Boolean = false, + /** The set of type symbols used by the dictionary */ + dictionaryTypeSymbolSet: Set[Symbol] = Set() ) { /** Gets the qualified name of a symbol */ diff --git a/compiler/lib/src/main/scala/analysis/CheckSemantics/CheckUses.scala b/compiler/lib/src/main/scala/analysis/CheckSemantics/CheckUses.scala index 1449aac50..a1ed78db9 100644 --- a/compiler/lib/src/main/scala/analysis/CheckSemantics/CheckUses.scala +++ b/compiler/lib/src/main/scala/analysis/CheckSemantics/CheckUses.scala @@ -117,6 +117,33 @@ object CheckUses extends UseAnalyzer { yield a.copy(nestedScope = a.nestedScope.pop) } + override def defTopologyAnnotatedNode(a: Analysis, node: Ast.Annotated[AstNode[Ast.DefTopology]]) = { + a.dictionaryNeeded match { + case true => { + val impliedTypeUses = List( + "FwChanIdType", + "FwEventIdType", + "FwOpcodeType", + "FwPacketDescriptorType", + "FwTlmPacketizeIdType" + ) + val (_, node1, _) = node + val mapping = a.nestedScope.get (NameGroup.Type) _ + for { + a <- Result.foldLeft (impliedTypeUses) (a) ((a, t) => { + for { + symbol <- Result.annotateResult( + helpers.getSymbolForName(mapping)(node1.id, t), + s"Dictionary requires type ${t} to be defined.") + } yield a.copy(dictionaryTypeSymbolSet = a.dictionaryTypeSymbolSet + symbol) + }) + a <- super.defTopologyAnnotatedNode(a, node) + } yield a + } + case false => super.defTopologyAnnotatedNode(a, node) + } + } + override def portUse(a: Analysis, node: AstNode[Ast.QualIdent], use: Name.Qualified) = helpers.visitQualIdentNode (NameGroup.Port) (a, node) diff --git a/compiler/lib/src/main/scala/analysis/CheckSemantics/FinalizeTypeDefs.scala b/compiler/lib/src/main/scala/analysis/CheckSemantics/FinalizeTypeDefs.scala index 5e91c8f62..2cd47b0a5 100644 --- a/compiler/lib/src/main/scala/analysis/CheckSemantics/FinalizeTypeDefs.scala +++ b/compiler/lib/src/main/scala/analysis/CheckSemantics/FinalizeTypeDefs.scala @@ -174,6 +174,21 @@ object FinalizeTypeDefs visitIfNeeded(symbol, visitor)(a, aNode) } + override def defTopologyAnnotatedNode(a: Analysis, node: Ast.Annotated[AstNode[Ast.DefTopology]]) = { + for { + a <- Result.foldLeft (a.dictionaryTypeSymbolSet.toList) (a) ((a, s) => { + val t = a.typeMap(s.getNodeId) + val loc = Locations.get(s.getNodeId) + t match { + case x : Type.AliasType => + if(x.getUnderlyingType.isInt) Right(a) + else Left(SemanticError.InvalidType(loc, s"underlying type must be an integer.")) + case _ => Left(SemanticError.InvalidType(loc, s"type must be an alias of an integer type.")) + } + }) + } yield a + } + override def transUnit(a: Analysis, tu: Ast.TransUnit) = super.transUnit(a.copy(visitedSymbolSet = Set()), tu) diff --git a/compiler/lib/src/main/scala/analysis/Semantics/ConstructDictionary/DictionaryUsedSymbols.scala b/compiler/lib/src/main/scala/analysis/Semantics/ConstructDictionary/DictionaryUsedSymbols.scala index 503583b0b..9bd1aed29 100644 --- a/compiler/lib/src/main/scala/analysis/Semantics/ConstructDictionary/DictionaryUsedSymbols.scala +++ b/compiler/lib/src/main/scala/analysis/Semantics/ConstructDictionary/DictionaryUsedSymbols.scala @@ -13,6 +13,7 @@ final case class DictionaryUsedSymbols(a: Analysis, t: Topology) { private def getUsedSymbolsForInstance(ci: ComponentInstance) = { val component = ci.component + val dictionaryTypeSymbols = a.dictionaryTypeSymbolSet val commandSymbols = getUsedSymbolsForSpecifier( component.commandMap, { @@ -42,6 +43,7 @@ final case class DictionaryUsedSymbols(a: Analysis, t: Topology) { container => UsedSymbols.specContainerAnnotatedNode(a, container.aNode) ) Set.concat( + dictionaryTypeSymbols, commandSymbols, eventSymbols, tlmChannelSymbols, diff --git a/compiler/lib/src/main/scala/codegen/DictionaryJsonWriter/DictionaryJsonEncoder.scala b/compiler/lib/src/main/scala/codegen/DictionaryJsonWriter/DictionaryJsonEncoder.scala index 4b1714d21..7fa2f98cc 100644 --- a/compiler/lib/src/main/scala/codegen/DictionaryJsonWriter/DictionaryJsonEncoder.scala +++ b/compiler/lib/src/main/scala/codegen/DictionaryJsonWriter/DictionaryJsonEncoder.scala @@ -546,7 +546,7 @@ case class DictionaryJsonEncoder( /** Main interface for the class. JSON Encoding for a complete dictionary */ def dictionaryAsJson: Json = { - /** Split set into individual sets consisting of each symbol type (arrays, enums, structs) */ + /** Split set into individual sets consisting of each symbol type (arrays, enums, structs, aliases) */ val typeDefSymbols = splitTypeSymbolSet(dictionary.usedSymbolSet, Set()) /** Convert each dictionary element to JSON and return the complete dictionary JSON */ Json.obj( diff --git a/compiler/lib/src/main/scala/util/Error.scala b/compiler/lib/src/main/scala/util/Error.scala index 6638351e1..7cb57e1bf 100644 --- a/compiler/lib/src/main/scala/util/Error.scala +++ b/compiler/lib/src/main/scala/util/Error.scala @@ -19,7 +19,7 @@ sealed trait Error { System.err.println("previous occurrence is here:") System.err.println(prevLoc) } - + /*** Print the error */ def print: Unit = { this match { @@ -305,11 +305,16 @@ sealed trait Error { case SemanticError.UseDefCycle(loc, msg) => Error.print (Some(loc)) (msg) case XmlError.ParseError(file, msg) => Error.printXml (file) (msg) case XmlError.SemanticError(file, msg) => Error.printXml (file) (msg) + case AnnotatedError(error, note) => + error.print + System.err.println(s"note: ${note}") } } } +/** An error with a note */ +final case class AnnotatedError(error: Error, note: String) extends Error /** A syntax error */ final case class SyntaxError(loc: Location, msg: String) extends Error diff --git a/compiler/lib/src/main/scala/util/Result.scala b/compiler/lib/src/main/scala/util/Result.scala index d09605858..80d8991c1 100644 --- a/compiler/lib/src/main/scala/util/Result.scala +++ b/compiler/lib/src/main/scala/util/Result.scala @@ -4,6 +4,13 @@ package fpp.compiler.util object Result { type Result[T] = Either[Error, T] + + /** Wraps error as an AnnotatedError with note */ + def annotateResult[A](r: Result[A], note: String): Result[A] = + r match { + case Right(v) => Right(v) + case Left(e: Error) => Left(AnnotatedError(e, note)) + } /** Left fold with a function that returns a result */ def foldLeft[A,B] diff --git a/compiler/tools/fpp-to-dict/src/main/scala/fpp-to-dict.scala b/compiler/tools/fpp-to-dict/src/main/scala/fpp-to-dict.scala index 06eab9aed..2f885fb2b 100644 --- a/compiler/tools/fpp-to-dict/src/main/scala/fpp-to-dict.scala +++ b/compiler/tools/fpp-to-dict/src/main/scala/fpp-to-dict.scala @@ -27,7 +27,7 @@ object FPPToDict { case Nil => List(File.StdIn) case list => list } - val a = Analysis(inputFileSet = options.files.toSet) + val a = Analysis(inputFileSet = options.files.toSet, dictionaryNeeded = true) val metadata = DictionaryMetadata( projectVersion=options.projectVersion, frameworkVersion=options.frameworkVersion, diff --git a/compiler/tools/fpp-to-dict/test/top/BasicDpTopologyDictionary.ref.json b/compiler/tools/fpp-to-dict/test/top/BasicDpTopologyDictionary.ref.json index cc774d537..bede989ff 100644 --- a/compiler/tools/fpp-to-dict/test/top/BasicDpTopologyDictionary.ref.json +++ b/compiler/tools/fpp-to-dict/test/top/BasicDpTopologyDictionary.ref.json @@ -8,6 +8,85 @@ "dictionarySpecVersion" : "1.0.0" }, "typeDefinitions" : [ + { + "kind" : "struct", + "qualifiedName" : "FppTest.DpTestComponent.Complex", + "members" : { + "f1" : { + "type" : { + "name" : "FppTest.DpTestComponent.Data", + "kind" : "qualifiedIdentifier" + }, + "index" : 0, + "annotation" : "A struct in the struct" + }, + "f2" : { + "type" : { + "name" : "U32", + "kind" : "integer", + "size" : 32, + "signed" : false + }, + "index" : 1, + "annotation" : "A simple U32 field" + } + }, + "default" : { + "f1" : { + "u16Field" : 0 + }, + "f2" : 0 + }, + "annotation" : "Data for a ComplexRecord" + }, + { + "kind" : "alias", + "qualifiedName" : "FwTlmPacketizeIdType", + "type" : { + "name" : "U16", + "kind" : "integer", + "size" : 16, + "signed" : false + }, + "underlyingType" : { + "name" : "U16", + "kind" : "integer", + "size" : 16, + "signed" : false + } + }, + { + "kind" : "alias", + "qualifiedName" : "FwEventIdType", + "type" : { + "name" : "U32", + "kind" : "integer", + "size" : 32, + "signed" : false + }, + "underlyingType" : { + "name" : "U32", + "kind" : "integer", + "size" : 32, + "signed" : false + } + }, + { + "kind" : "alias", + "qualifiedName" : "FwPacketDescriptorType", + "type" : { + "name" : "U32", + "kind" : "integer", + "size" : 32, + "signed" : false + }, + "underlyingType" : { + "name" : "U32", + "kind" : "integer", + "size" : 32, + "signed" : false + } + }, { "kind" : "alias", "qualifiedName" : "FppTest.DpTestComponent.AliasU16", @@ -44,35 +123,36 @@ "annotation" : "Data for a DataRecord" }, { - "kind" : "struct", - "qualifiedName" : "FppTest.DpTestComponent.Complex", - "members" : { - "f1" : { - "type" : { - "name" : "FppTest.DpTestComponent.Data", - "kind" : "qualifiedIdentifier" - }, - "index" : 0, - "annotation" : "A struct in the struct" - }, - "f2" : { - "type" : { - "name" : "U32", - "kind" : "integer", - "size" : 32, - "signed" : false - }, - "index" : 1, - "annotation" : "A simple U32 field" - } + "kind" : "alias", + "qualifiedName" : "FwOpcodeType", + "type" : { + "name" : "U32", + "kind" : "integer", + "size" : 32, + "signed" : false }, - "default" : { - "f1" : { - "u16Field" : 0 - }, - "f2" : 0 + "underlyingType" : { + "name" : "U32", + "kind" : "integer", + "size" : 32, + "signed" : false + } + }, + { + "kind" : "alias", + "qualifiedName" : "FwChanIdType", + "type" : { + "name" : "U32", + "kind" : "integer", + "size" : 32, + "signed" : false }, - "annotation" : "Data for a ComplexRecord" + "underlyingType" : { + "name" : "U32", + "kind" : "integer", + "size" : 32, + "signed" : false + } } ], "commands" : [ diff --git a/compiler/tools/fpp-to-dict/test/top/FirstTopTopologyDictionary.ref.json b/compiler/tools/fpp-to-dict/test/top/FirstTopTopologyDictionary.ref.json index 95750abff..68c006021 100644 --- a/compiler/tools/fpp-to-dict/test/top/FirstTopTopologyDictionary.ref.json +++ b/compiler/tools/fpp-to-dict/test/top/FirstTopTopologyDictionary.ref.json @@ -10,34 +10,6 @@ "dictionarySpecVersion" : "1.0.0" }, "typeDefinitions" : [ - { - "kind" : "struct", - "qualifiedName" : "Module1.S2", - "members" : { - "x" : { - "type" : { - "name" : "Module1.E2", - "kind" : "qualifiedIdentifier" - }, - "index" : 0 - }, - "y" : { - "type" : { - "name" : "Module1.EnumArray", - "kind" : "qualifiedIdentifier" - }, - "index" : 1 - } - }, - "default" : { - "x" : "Module1.E2.PASS", - "y" : [ - "Module1.E3.YES", - "Module1.E3.YES", - "Module1.E3.YES" - ] - } - }, { "kind" : "enum", "qualifiedName" : "Module1.E2", @@ -59,6 +31,22 @@ ], "default" : "Module1.E2.PASS" }, + { + "kind" : "alias", + "qualifiedName" : "FwEventIdType", + "type" : { + "name" : "U32", + "kind" : "integer", + "size" : 32, + "signed" : false + }, + "underlyingType" : { + "name" : "U32", + "kind" : "integer", + "size" : 32, + "signed" : false + } + }, { "kind" : "alias", "qualifiedName" : "Module1.AliasT1", @@ -241,6 +229,22 @@ ], "annotation" : "An array of 2 String values" }, + { + "kind" : "alias", + "qualifiedName" : "FwPacketDescriptorType", + "type" : { + "name" : "U32", + "kind" : "integer", + "size" : 32, + "signed" : false + }, + "underlyingType" : { + "name" : "U32", + "kind" : "integer", + "size" : 32, + "signed" : false + } + }, { "kind" : "alias", "qualifiedName" : "Module1.AliasT3", @@ -320,6 +324,50 @@ ], "annotation" : "An array of 3 enum values" }, + { + "kind" : "alias", + "qualifiedName" : "FwTlmPacketizeIdType", + "type" : { + "name" : "U16", + "kind" : "integer", + "size" : 16, + "signed" : false + }, + "underlyingType" : { + "name" : "U16", + "kind" : "integer", + "size" : 16, + "signed" : false + } + }, + { + "kind" : "struct", + "qualifiedName" : "Module1.S2", + "members" : { + "x" : { + "type" : { + "name" : "Module1.E2", + "kind" : "qualifiedIdentifier" + }, + "index" : 0 + }, + "y" : { + "type" : { + "name" : "Module1.EnumArray", + "kind" : "qualifiedIdentifier" + }, + "index" : 1 + } + }, + "default" : { + "x" : "Module1.E2.PASS", + "y" : [ + "Module1.E3.YES", + "Module1.E3.YES", + "Module1.E3.YES" + ] + } + }, { "kind" : "array", "qualifiedName" : "Module1.F64x4", @@ -354,6 +402,38 @@ 4 ], "annotation" : "An array of 4 U32 values" + }, + { + "kind" : "alias", + "qualifiedName" : "FwOpcodeType", + "type" : { + "name" : "U32", + "kind" : "integer", + "size" : 32, + "signed" : false + }, + "underlyingType" : { + "name" : "U32", + "kind" : "integer", + "size" : 32, + "signed" : false + } + }, + { + "kind" : "alias", + "qualifiedName" : "FwChanIdType", + "type" : { + "name" : "U32", + "kind" : "integer", + "size" : 32, + "signed" : false + }, + "underlyingType" : { + "name" : "U32", + "kind" : "integer", + "size" : 32, + "signed" : false + } } ], "commands" : [ diff --git a/compiler/tools/fpp-to-dict/test/top/QualifiedCompInstTopologyDictionary.ref.json b/compiler/tools/fpp-to-dict/test/top/QualifiedCompInstTopologyDictionary.ref.json index 5a44fa428..048db6a09 100644 --- a/compiler/tools/fpp-to-dict/test/top/QualifiedCompInstTopologyDictionary.ref.json +++ b/compiler/tools/fpp-to-dict/test/top/QualifiedCompInstTopologyDictionary.ref.json @@ -10,6 +10,22 @@ "dictionarySpecVersion" : "1.0.0" }, "typeDefinitions" : [ + { + "kind" : "alias", + "qualifiedName" : "FwTlmPacketizeIdType", + "type" : { + "name" : "U16", + "kind" : "integer", + "size" : 16, + "signed" : false + }, + "underlyingType" : { + "name" : "U16", + "kind" : "integer", + "size" : 16, + "signed" : false + } + }, { "kind" : "enum", "qualifiedName" : "M.E1", @@ -34,6 +50,70 @@ } ], "default" : "M.E1.X" + }, + { + "kind" : "alias", + "qualifiedName" : "FwEventIdType", + "type" : { + "name" : "U32", + "kind" : "integer", + "size" : 32, + "signed" : false + }, + "underlyingType" : { + "name" : "U32", + "kind" : "integer", + "size" : 32, + "signed" : false + } + }, + { + "kind" : "alias", + "qualifiedName" : "FwPacketDescriptorType", + "type" : { + "name" : "U32", + "kind" : "integer", + "size" : 32, + "signed" : false + }, + "underlyingType" : { + "name" : "U32", + "kind" : "integer", + "size" : 32, + "signed" : false + } + }, + { + "kind" : "alias", + "qualifiedName" : "FwOpcodeType", + "type" : { + "name" : "U32", + "kind" : "integer", + "size" : 32, + "signed" : false + }, + "underlyingType" : { + "name" : "U32", + "kind" : "integer", + "size" : 32, + "signed" : false + } + }, + { + "kind" : "alias", + "qualifiedName" : "FwChanIdType", + "type" : { + "name" : "U32", + "kind" : "integer", + "size" : 32, + "signed" : false + }, + "underlyingType" : { + "name" : "U32", + "kind" : "integer", + "size" : 32, + "signed" : false + } } ], "commands" : [ diff --git a/compiler/tools/fpp-to-dict/test/top/SecondTopTopologyDictionary.ref.json b/compiler/tools/fpp-to-dict/test/top/SecondTopTopologyDictionary.ref.json index b0cc4451c..c0556d62a 100644 --- a/compiler/tools/fpp-to-dict/test/top/SecondTopTopologyDictionary.ref.json +++ b/compiler/tools/fpp-to-dict/test/top/SecondTopTopologyDictionary.ref.json @@ -10,34 +10,6 @@ "dictionarySpecVersion" : "1.0.0" }, "typeDefinitions" : [ - { - "kind" : "struct", - "qualifiedName" : "Module1.S2", - "members" : { - "x" : { - "type" : { - "name" : "Module1.E2", - "kind" : "qualifiedIdentifier" - }, - "index" : 0 - }, - "y" : { - "type" : { - "name" : "Module1.EnumArray", - "kind" : "qualifiedIdentifier" - }, - "index" : 1 - } - }, - "default" : { - "x" : "Module1.E2.PASS", - "y" : [ - "Module1.E3.YES", - "Module1.E3.YES", - "Module1.E3.YES" - ] - } - }, { "kind" : "enum", "qualifiedName" : "Module1.E2", @@ -59,6 +31,22 @@ ], "default" : "Module1.E2.PASS" }, + { + "kind" : "alias", + "qualifiedName" : "FwEventIdType", + "type" : { + "name" : "U32", + "kind" : "integer", + "size" : 32, + "signed" : false + }, + "underlyingType" : { + "name" : "U32", + "kind" : "integer", + "size" : 32, + "signed" : false + } + }, { "kind" : "alias", "qualifiedName" : "Module1.AliasT1", @@ -241,6 +229,22 @@ ], "annotation" : "An array of 2 String values" }, + { + "kind" : "alias", + "qualifiedName" : "FwPacketDescriptorType", + "type" : { + "name" : "U32", + "kind" : "integer", + "size" : 32, + "signed" : false + }, + "underlyingType" : { + "name" : "U32", + "kind" : "integer", + "size" : 32, + "signed" : false + } + }, { "kind" : "alias", "qualifiedName" : "Module1.AliasT3", @@ -320,6 +324,50 @@ ], "annotation" : "An array of 3 enum values" }, + { + "kind" : "alias", + "qualifiedName" : "FwTlmPacketizeIdType", + "type" : { + "name" : "U16", + "kind" : "integer", + "size" : 16, + "signed" : false + }, + "underlyingType" : { + "name" : "U16", + "kind" : "integer", + "size" : 16, + "signed" : false + } + }, + { + "kind" : "struct", + "qualifiedName" : "Module1.S2", + "members" : { + "x" : { + "type" : { + "name" : "Module1.E2", + "kind" : "qualifiedIdentifier" + }, + "index" : 0 + }, + "y" : { + "type" : { + "name" : "Module1.EnumArray", + "kind" : "qualifiedIdentifier" + }, + "index" : 1 + } + }, + "default" : { + "x" : "Module1.E2.PASS", + "y" : [ + "Module1.E3.YES", + "Module1.E3.YES", + "Module1.E3.YES" + ] + } + }, { "kind" : "array", "qualifiedName" : "Module1.F64x4", @@ -354,6 +402,38 @@ 4 ], "annotation" : "An array of 4 U32 values" + }, + { + "kind" : "alias", + "qualifiedName" : "FwOpcodeType", + "type" : { + "name" : "U32", + "kind" : "integer", + "size" : 32, + "signed" : false + }, + "underlyingType" : { + "name" : "U32", + "kind" : "integer", + "size" : 32, + "signed" : false + } + }, + { + "kind" : "alias", + "qualifiedName" : "FwChanIdType", + "type" : { + "name" : "U32", + "kind" : "integer", + "size" : 32, + "signed" : false + }, + "underlyingType" : { + "name" : "U32", + "kind" : "integer", + "size" : 32, + "signed" : false + } } ], "commands" : [ diff --git a/compiler/tools/fpp-to-dict/test/top/UnqualifiedCompInstTopologyDictionary.ref.json b/compiler/tools/fpp-to-dict/test/top/UnqualifiedCompInstTopologyDictionary.ref.json index 7703d031f..de571167c 100644 --- a/compiler/tools/fpp-to-dict/test/top/UnqualifiedCompInstTopologyDictionary.ref.json +++ b/compiler/tools/fpp-to-dict/test/top/UnqualifiedCompInstTopologyDictionary.ref.json @@ -10,6 +10,22 @@ "dictionarySpecVersion" : "1.0.0" }, "typeDefinitions" : [ + { + "kind" : "alias", + "qualifiedName" : "FwTlmPacketizeIdType", + "type" : { + "name" : "U16", + "kind" : "integer", + "size" : 16, + "signed" : false + }, + "underlyingType" : { + "name" : "U16", + "kind" : "integer", + "size" : 16, + "signed" : false + } + }, { "kind" : "enum", "qualifiedName" : "M.E1", @@ -34,6 +50,70 @@ } ], "default" : "M.E1.X" + }, + { + "kind" : "alias", + "qualifiedName" : "FwEventIdType", + "type" : { + "name" : "U32", + "kind" : "integer", + "size" : 32, + "signed" : false + }, + "underlyingType" : { + "name" : "U32", + "kind" : "integer", + "size" : 32, + "signed" : false + } + }, + { + "kind" : "alias", + "qualifiedName" : "FwPacketDescriptorType", + "type" : { + "name" : "U32", + "kind" : "integer", + "size" : 32, + "signed" : false + }, + "underlyingType" : { + "name" : "U32", + "kind" : "integer", + "size" : 32, + "signed" : false + } + }, + { + "kind" : "alias", + "qualifiedName" : "FwOpcodeType", + "type" : { + "name" : "U32", + "kind" : "integer", + "size" : 32, + "signed" : false + }, + "underlyingType" : { + "name" : "U32", + "kind" : "integer", + "size" : 32, + "signed" : false + } + }, + { + "kind" : "alias", + "qualifiedName" : "FwChanIdType", + "type" : { + "name" : "U32", + "kind" : "integer", + "size" : 32, + "signed" : false + }, + "underlyingType" : { + "name" : "U32", + "kind" : "integer", + "size" : 32, + "signed" : false + } } ], "commands" : [ diff --git a/compiler/tools/fpp-to-dict/test/top/arrayFwEventIdType.fpp b/compiler/tools/fpp-to-dict/test/top/arrayFwEventIdType.fpp new file mode 100644 index 000000000..a40bb66f1 --- /dev/null +++ b/compiler/tools/fpp-to-dict/test/top/arrayFwEventIdType.fpp @@ -0,0 +1,9 @@ +type FwPacketDescriptorType = U32 +type FwOpcodeType = U32 +type FwChanIdType = U32 +type FwTlmPacketizeIdType = U16 +array FwEventIdType = [3] F32 + +topology T { + +} diff --git a/compiler/tools/fpp-to-dict/test/top/arrayFwEventIdType.ref.txt b/compiler/tools/fpp-to-dict/test/top/arrayFwEventIdType.ref.txt new file mode 100644 index 000000000..677aa92a9 --- /dev/null +++ b/compiler/tools/fpp-to-dict/test/top/arrayFwEventIdType.ref.txt @@ -0,0 +1,5 @@ +fpp-to-dict +[ local path prefix ]/tools/fpp-to-dict/test/top/arrayFwEventIdType.fpp:5.1 +array FwEventIdType = [3] F32 +^ +error: type must be an alias of an integer type. diff --git a/compiler/tools/fpp-to-dict/test/top/floatFwEventIdType.fpp b/compiler/tools/fpp-to-dict/test/top/floatFwEventIdType.fpp new file mode 100644 index 000000000..5c61abfb3 --- /dev/null +++ b/compiler/tools/fpp-to-dict/test/top/floatFwEventIdType.fpp @@ -0,0 +1,9 @@ +type FwPacketDescriptorType = U32 +type FwOpcodeType = U32 +type FwChanIdType = U32 +type FwTlmPacketizeIdType = U16 +type FwEventIdType = F32 + +topology T { + +} diff --git a/compiler/tools/fpp-to-dict/test/top/floatFwEventIdType.ref.txt b/compiler/tools/fpp-to-dict/test/top/floatFwEventIdType.ref.txt new file mode 100644 index 000000000..0c2c023b1 --- /dev/null +++ b/compiler/tools/fpp-to-dict/test/top/floatFwEventIdType.ref.txt @@ -0,0 +1,5 @@ +fpp-to-dict +[ local path prefix ]/tools/fpp-to-dict/test/top/floatFwEventIdType.fpp:5.1 +type FwEventIdType = F32 +^ +error: underlying type must be an integer. diff --git a/compiler/tools/fpp-to-dict/test/top/fwTypes.fpp b/compiler/tools/fpp-to-dict/test/top/fwTypes.fpp new file mode 100644 index 000000000..002e3da89 --- /dev/null +++ b/compiler/tools/fpp-to-dict/test/top/fwTypes.fpp @@ -0,0 +1,5 @@ +type FwEventIdType = U32 +type FwChanIdType = U32 +type FwOpcodeType = U32 +type FwPacketDescriptorType = U32 +type FwTlmPacketizeIdType = U16 diff --git a/compiler/tools/fpp-to-dict/test/top/missingFwOpcodeType.fpp b/compiler/tools/fpp-to-dict/test/top/missingFwOpcodeType.fpp new file mode 100644 index 000000000..71238a213 --- /dev/null +++ b/compiler/tools/fpp-to-dict/test/top/missingFwOpcodeType.fpp @@ -0,0 +1,8 @@ +type FwPacketDescriptorType = U32 +type FwEventIdType = U32 +type FwChanIdType = U32 +type FwTlmPacketizeIdType = U16 + +topology T { + +} diff --git a/compiler/tools/fpp-to-dict/test/top/missingFwOpcodeType.ref.txt b/compiler/tools/fpp-to-dict/test/top/missingFwOpcodeType.ref.txt new file mode 100644 index 000000000..ab0b3ec22 --- /dev/null +++ b/compiler/tools/fpp-to-dict/test/top/missingFwOpcodeType.ref.txt @@ -0,0 +1,6 @@ +fpp-to-dict +[ local path prefix ]/tools/fpp-to-dict/test/top/missingFwOpcodeType.fpp:6.1 +topology T { +^ +error: undefined symbol FwOpcodeType +note: Dictionary requires type FwOpcodeType to be defined. diff --git a/compiler/tools/fpp-to-dict/test/top/run.sh b/compiler/tools/fpp-to-dict/test/top/run.sh index e2e604e00..fa4b88207 100644 --- a/compiler/tools/fpp-to-dict/test/top/run.sh +++ b/compiler/tools/fpp-to-dict/test/top/run.sh @@ -1,6 +1,6 @@ multipleTops() { - run_test "-i builtin.fpp -p 1.0.0 -f 3.4.3 -l lib1-1.0.0,lib2-2.0.0" multipleTops && \ + run_test "-i builtin.fpp,fwTypes.fpp -p 1.0.0 -f 3.4.3 -l lib1-1.0.0,lib2-2.0.0" multipleTops && \ validate_json_schema FirstTop && \ validate_json_schema SecondTop && \ diff_json FirstTop && \ @@ -9,20 +9,38 @@ multipleTops() dataProducts() { - run_test "-i builtin.fpp -p 1.0.0 -f 3.4.3" dataProducts && \ + run_test "-i builtin.fpp,fwTypes.fpp -p 1.0.0 -f 3.4.3" dataProducts && \ validate_json_schema BasicDp && \ diff_json BasicDp } duplicate() { - run_test '' duplicate && \ + run_test '-i fwTypes.fpp' duplicate && \ compare duplicate } +missingFwOpcodeType() +{ + run_test '' missingFwOpcodeType && \ + compare missingFwOpcodeType +} + +arrayFwEventType() +{ + run_test '' arrayFwEventType && \ + compare arrayFwEventType +} + +floatFwEventType() +{ + run_test '' floatFwEventType && \ + compare floatFwEventType +} + unqualifiedComponentInstances() { - run_test "-i builtin.fpp -p 1.0.0 -f 3.4.3 -l lib1-1.0.0,lib2-2.0.0" unqualifiedComponentInstances && \ + run_test "-i builtin.fpp,fwTypes.fpp -p 1.0.0 -f 3.4.3 -l lib1-1.0.0,lib2-2.0.0" unqualifiedComponentInstances && \ validate_json_schema QualifiedCompInst && \ validate_json_schema UnqualifiedCompInst && \ diff_json QualifiedCompInst && \ diff --git a/compiler/tools/fpp-to-dict/test/top/tests.sh b/compiler/tools/fpp-to-dict/test/top/tests.sh index 347daf0d0..6e2bee900 100644 --- a/compiler/tools/fpp-to-dict/test/top/tests.sh +++ b/compiler/tools/fpp-to-dict/test/top/tests.sh @@ -2,5 +2,8 @@ tests=" multipleTops dataProducts duplicate +missingFwOpcodeType +arrayFwEventIdType +floatFwEventIdType unqualifiedComponentInstances " diff --git a/compiler/tools/fpp-to-dict/test/top/update-ref.sh b/compiler/tools/fpp-to-dict/test/top/update-ref.sh index 2b091d650..31fa4497e 100644 --- a/compiler/tools/fpp-to-dict/test/top/update-ref.sh +++ b/compiler/tools/fpp-to-dict/test/top/update-ref.sh @@ -1,19 +1,25 @@ multipleTops() { - update "-i builtin.fpp -p 1.0.0 -f 3.4.3 -l lib1-1.0.0,lib2-2.0.0" multipleTops + update "-i builtin.fpp,fwTypes.fpp -p 1.0.0 -f 3.4.3 -l lib1-1.0.0,lib2-2.0.0" multipleTops move_json FirstTop move_json SecondTop } dataProducts() { - update "-i builtin.fpp -p 1.0.0 -f 3.4.3" dataProducts + update "-i builtin.fpp,fwTypes.fpp -p 1.0.0 -f 3.4.3" dataProducts move_json BasicDp } + +duplicate() +{ + update '-i fwTypes.fpp' duplicate +} + unqualifiedComponentInstances() { - update "-i builtin.fpp -p 1.0.0 -f 3.4.3 -l lib1-1.0.0,lib2-2.0.0" unqualifiedComponentInstances + update "-i builtin.fpp,fwTypes.fpp -p 1.0.0 -f 3.4.3 -l lib1-1.0.0,lib2-2.0.0" unqualifiedComponentInstances move_json QualifiedCompInst move_json UnqualifiedCompInst } diff --git a/docs/fpp-users-guide.html b/docs/fpp-users-guide.html index 4aea48eaf..8e2ea669b 100644 --- a/docs/fpp-users-guide.html +++ b/docs/fpp-users-guide.html @@ -14625,6 +14625,35 @@

14.8. G documentation.

+

When generating dictionaries with fpp-to-dict, the following types must be defined +in FPP (either in the input model itself or in a dependency file) and each type must be +an alias of an integer type:

+
+
+ +
+
+

For more information on defining types, see the +alias type +definition section.

+
+

Here is a common use case:

@@ -15561,7 +15590,7 @@

15.4. S

diff --git a/docs/index.html b/docs/index.html index 11deeafad..a8f6ff460 100644 --- a/docs/index.html +++ b/docs/index.html @@ -140,7 +140,7 @@ #content::before{content:none} #header>h1:first-child{color:rgba(0,0,0,.85);margin-top:2.25rem;margin-bottom:0} #header>h1:first-child+#toc{margin-top:8px;border-top:1px solid #dddddf} -#header>h1:only-child,body.toc2 #header>h1:nth-last-child(2){border-bottom:1px solid #dddddf;padding-bottom:8px} +#header>h1:only-child{border-bottom:1px solid #dddddf;padding-bottom:8px} #header .details{border-bottom:1px solid #dddddf;line-height:1.45;padding-top:.25em;padding-bottom:.25em;padding-left:.25em;color:rgba(0,0,0,.6);display:flex;flex-flow:row wrap} #header .details span:first-child{margin-left:-.125em} #header .details span.email a{color:rgba(0,0,0,.85)} @@ -162,6 +162,7 @@ #toctitle{color:#7a2518;font-size:1.2em} @media screen and (min-width:768px){#toctitle{font-size:1.375em} body.toc2{padding-left:15em;padding-right:0} +body.toc2 #header>h1:nth-last-child(2){border-bottom:1px solid #dddddf;padding-bottom:8px} #toc.toc2{margin-top:0!important;background:#f8f8f7;position:fixed;width:15em;left:0;top:0;border-right:1px solid #e7e7e9;border-top-width:0!important;border-bottom-width:0!important;z-index:1000;padding:1.25em 1em;height:100%;overflow:auto} #toc.toc2 #toctitle{margin-top:0;margin-bottom:.8rem;font-size:1.2em} #toc.toc2>ul{font-size:.9em;margin-bottom:0} @@ -327,7 +328,7 @@ a.image object{pointer-events:none} sup.footnote,sup.footnoteref{font-size:.875em;position:static;vertical-align:super} sup.footnote a,sup.footnoteref a{text-decoration:none} -sup.footnote a:active,sup.footnoteref a:active{text-decoration:underline} +sup.footnote a:active,sup.footnoteref a:active,#footnotes .footnote a:first-of-type:active{text-decoration:underline} #footnotes{padding-top:.75em;padding-bottom:.75em;margin-bottom:.625em} #footnotes hr{width:20%;min-width:6.25em;margin:-.25em 0 .75em;border-width:1px 0 0} #footnotes .footnote{padding:0 .375em 0 .225em;line-height:1.3334;font-size:.875em;margin-left:1.2em;margin-bottom:.2em} @@ -463,8 +464,8 @@

F Prime Prime (FPP)

- \ No newline at end of file + diff --git a/docs/users-guide/Analyzing-and-Translating-Models.adoc b/docs/users-guide/Analyzing-and-Translating-Models.adoc index b33548e49..001f827e2 100644 --- a/docs/users-guide/Analyzing-and-Translating-Models.adoc +++ b/docs/users-guide/Analyzing-and-Translating-Models.adoc @@ -1452,6 +1452,24 @@ The JSON format is specified in the https://fprime.jpl.nasa.gov/devel/docs/reference/fpp-json-dict/[F Prime design documentation]. +When generating dictionaries with `fpp-to-dict`, the following types must be defined +in FPP (either in the input model itself or in a dependency file) and each type must be +an alias of an integer type: + +* `FwChanIdType` + +* `FwEventIdType` + +* `FwOpcodeType` + +* `FwPacketDescriptorType` + +* `FwTlmPacketizeIdType` + +For more information on defining types, see the +<> section. + Here is a common use case: * The input files _F_ define a single topology _T_.