From 4b8be45ee884567b2b2fdb45627ed1f8a4903248 Mon Sep 17 00:00:00 2001 From: jawest Date: Wed, 29 Jan 2025 15:03:35 -0800 Subject: [PATCH 1/2] fix struct member indexes --- .../DictionaryJsonEncoder.scala | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/compiler/lib/src/main/scala/codegen/DictionaryJsonWriter/DictionaryJsonEncoder.scala b/compiler/lib/src/main/scala/codegen/DictionaryJsonWriter/DictionaryJsonEncoder.scala index f04e08c424..102cfcaf74 100644 --- a/compiler/lib/src/main/scala/codegen/DictionaryJsonWriter/DictionaryJsonEncoder.scala +++ b/compiler/lib/src/main/scala/codegen/DictionaryJsonWriter/DictionaryJsonEncoder.scala @@ -237,8 +237,7 @@ case class DictionaryJsonEncoder( jsonWithOptionalValues(json, optionalValues) } case Symbol.Struct(preA, node, postA) => { - val Type.Struct(_, anonStruct, default, sizes, formats) = dictionaryState.a.typeMap(symbol.getNodeId) - val Type.AnonStruct(members) = anonStruct + val Type.Struct(_, _, default, sizes, _) = dictionaryState.a.typeMap(symbol.getNodeId) val memberFormatMap = node.data.members.flatMap { case (_, memberNode, _) => memberNode.data.format.map(format => memberNode.data.name -> format.data) }.toMap @@ -246,17 +245,17 @@ case class DictionaryJsonEncoder( val annotation = (preA ++ postA).mkString("\n") if (annotation.isEmpty) None else Some(memberNode.data.name -> annotation) }.toMap - val membersFormatted = for(((key, t), index) <- members.zipWithIndex) yield { + val membersFormatted = for(((_, m, _), index) <- node.data.members.zipWithIndex) yield { val json = Json.obj( - "type" -> typeAsJson(t).asJson, + "type" -> typeAsJson(dictionaryState.a.typeMap(m.data.typeName.id)), "index" -> index.asJson ) val optionalValues = Map( - "size" -> sizes.get(key), - "format" -> memberFormatMap.get(key), - "annotation" -> memberAnnotationMap.get(key) + "size" -> sizes.get(m.data.name), + "format" -> memberFormatMap.get(m.data.name), + "annotation" -> memberAnnotationMap.get(m.data.name) ) - (key.toString -> jsonWithOptionalValues(json, optionalValues)) + (m.data.name.toString -> jsonWithOptionalValues(json, optionalValues)) } val json = Json.obj( "kind" -> "struct".asJson, @@ -550,4 +549,4 @@ case class DictionaryJsonEncoder( } } -} \ No newline at end of file +} From cfa6e49cccb1035de51f649eb61427c7a7f4e34d Mon Sep 17 00:00:00 2001 From: jawest Date: Wed, 29 Jan 2025 17:06:32 -0800 Subject: [PATCH 2/2] add scalar struct to test case --- .../top/FirstTopTopologyDictionary.ref.json | 138 +++++++++++++++++- .../top/SecondTopTopologyDictionary.ref.json | 138 +++++++++++++++++- .../fpp-to-dict/test/top/multipleTops.fpp | 16 ++ 3 files changed, 276 insertions(+), 16 deletions(-) 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 df93cdfc55..84cf9d9db4 100644 --- a/compiler/tools/fpp-to-dict/test/top/FirstTopTopologyDictionary.ref.json +++ b/compiler/tools/fpp-to-dict/test/top/FirstTopTopologyDictionary.ref.json @@ -59,6 +59,112 @@ ], "default" : "Module1.E2.PASS" }, + { + "kind" : "struct", + "qualifiedName" : "Module1.ScalarStruct", + "members" : { + "u32" : { + "type" : { + "name" : "U32", + "kind" : "integer", + "size" : 32, + "signed" : false + }, + "index" : 6 + }, + "f64" : { + "type" : { + "name" : "F64", + "kind" : "float", + "size" : 64 + }, + "index" : 9 + }, + "f32" : { + "type" : { + "name" : "F32", + "kind" : "float", + "size" : 32 + }, + "index" : 8 + }, + "i8" : { + "type" : { + "name" : "I8", + "kind" : "integer", + "size" : 8, + "signed" : true + }, + "index" : 0 + }, + "i16" : { + "type" : { + "name" : "I16", + "kind" : "integer", + "size" : 16, + "signed" : true + }, + "index" : 1 + }, + "u8" : { + "type" : { + "name" : "U8", + "kind" : "integer", + "size" : 8, + "signed" : false + }, + "index" : 4 + }, + "u64" : { + "type" : { + "name" : "U64", + "kind" : "integer", + "size" : 64, + "signed" : false + }, + "index" : 7 + }, + "i64" : { + "type" : { + "name" : "I64", + "kind" : "integer", + "size" : 64, + "signed" : true + }, + "index" : 3 + }, + "i32" : { + "type" : { + "name" : "I32", + "kind" : "integer", + "size" : 32, + "signed" : true + }, + "index" : 2 + }, + "u16" : { + "type" : { + "name" : "U16", + "kind" : "integer", + "size" : 16, + "signed" : false + }, + "index" : 5 + } + }, + "default" : { + "u32" : 0, + "f64" : 0.0, + "f32" : 0.0, + "i8" : 0, + "i16" : 0, + "u8" : 0, + "u64" : 0, + "i64" : 0, + "i32" : 0, + "u16" : 0 + } + }, { "kind" : "struct", "qualifiedName" : "Module1.S1", @@ -253,14 +359,6 @@ ], "annotation" : "Parameter of type string" }, - { - "name" : "Module1.myFirstC1.PARAM1_PRM_SAVE", - "commandKind" : "save", - "opcode" : 773, - "formalParams" : [ - ], - "annotation" : "Parameter (struct)" - }, { "name" : "Module1.myFirstC1.PARAM3_PRM_SET", "commandKind" : "set", @@ -405,6 +503,30 @@ ], "annotation" : "Command with 2 args (array of strings and U32)" }, + { + "name" : "Module1.myFirstC2.SendScalars", + "commandKind" : "sync", + "opcode" : 1026, + "formalParams" : [ + { + "name" : "s", + "type" : { + "name" : "Module1.ScalarStruct", + "kind" : "qualifiedIdentifier" + }, + "ref" : false + } + ], + "annotation" : "Send scalars" + }, + { + "name" : "Module1.myFirstC1.PARAM1_PRM_SAVE", + "commandKind" : "save", + "opcode" : 773, + "formalParams" : [ + ], + "annotation" : "Parameter (struct)" + }, { "name" : "Module1.myFirstC1.PARAM5_PRM_SET", "commandKind" : "set", 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 98c35e03e4..aa68fc3aa6 100644 --- a/compiler/tools/fpp-to-dict/test/top/SecondTopTopologyDictionary.ref.json +++ b/compiler/tools/fpp-to-dict/test/top/SecondTopTopologyDictionary.ref.json @@ -59,6 +59,112 @@ ], "default" : "Module1.E2.PASS" }, + { + "kind" : "struct", + "qualifiedName" : "Module1.ScalarStruct", + "members" : { + "u32" : { + "type" : { + "name" : "U32", + "kind" : "integer", + "size" : 32, + "signed" : false + }, + "index" : 6 + }, + "f64" : { + "type" : { + "name" : "F64", + "kind" : "float", + "size" : 64 + }, + "index" : 9 + }, + "f32" : { + "type" : { + "name" : "F32", + "kind" : "float", + "size" : 32 + }, + "index" : 8 + }, + "i8" : { + "type" : { + "name" : "I8", + "kind" : "integer", + "size" : 8, + "signed" : true + }, + "index" : 0 + }, + "i16" : { + "type" : { + "name" : "I16", + "kind" : "integer", + "size" : 16, + "signed" : true + }, + "index" : 1 + }, + "u8" : { + "type" : { + "name" : "U8", + "kind" : "integer", + "size" : 8, + "signed" : false + }, + "index" : 4 + }, + "u64" : { + "type" : { + "name" : "U64", + "kind" : "integer", + "size" : 64, + "signed" : false + }, + "index" : 7 + }, + "i64" : { + "type" : { + "name" : "I64", + "kind" : "integer", + "size" : 64, + "signed" : true + }, + "index" : 3 + }, + "i32" : { + "type" : { + "name" : "I32", + "kind" : "integer", + "size" : 32, + "signed" : true + }, + "index" : 2 + }, + "u16" : { + "type" : { + "name" : "U16", + "kind" : "integer", + "size" : 16, + "signed" : false + }, + "index" : 5 + } + }, + "default" : { + "u32" : 0, + "f64" : 0.0, + "f32" : 0.0, + "i8" : 0, + "i16" : 0, + "u8" : 0, + "u64" : 0, + "i64" : 0, + "i32" : 0, + "u16" : 0 + } + }, { "kind" : "struct", "qualifiedName" : "Module1.S1", @@ -283,14 +389,6 @@ ], "annotation" : "Parameter of type string" }, - { - "name" : "Module1.mySecondC1.PARAM1_PRM_SAVE", - "commandKind" : "save", - "opcode" : 1285, - "formalParams" : [ - ], - "annotation" : "Parameter (struct)" - }, { "name" : "Module1.mySecondC1.PARAM3_PRM_SET", "commandKind" : "set", @@ -397,6 +495,30 @@ ], "annotation" : "Command with no args" }, + { + "name" : "Module1.mySecondC2.SendScalars", + "commandKind" : "sync", + "opcode" : 1538, + "formalParams" : [ + { + "name" : "s", + "type" : { + "name" : "Module1.ScalarStruct", + "kind" : "qualifiedIdentifier" + }, + "ref" : false + } + ], + "annotation" : "Send scalars" + }, + { + "name" : "Module1.mySecondC1.PARAM1_PRM_SAVE", + "commandKind" : "save", + "opcode" : 1285, + "formalParams" : [ + ], + "annotation" : "Parameter (struct)" + }, { "name" : "Module1.mySecondC2.Command1", "commandKind" : "sync", diff --git a/compiler/tools/fpp-to-dict/test/top/multipleTops.fpp b/compiler/tools/fpp-to-dict/test/top/multipleTops.fpp index 8d440ab912..cbf037300c 100644 --- a/compiler/tools/fpp-to-dict/test/top/multipleTops.fpp +++ b/compiler/tools/fpp-to-dict/test/top/multipleTops.fpp @@ -45,6 +45,19 @@ module Module1 { y: EnumArray } default { x = E2.PASS } + struct ScalarStruct { + i8: I8, + i16: I16, + i32: I32, + i64: I64, + u8: U8, + u16: U16, + u32: U32, + u64: U64, + f32: F32, + f64: F64 + } + # Component active component Component1 { @@ -193,6 +206,9 @@ module Module1 { @ Command with 3 args (of types string, I32, and bool) sync command Command2(a: string, b: I32, c: bool) + @ Send scalars + sync command SendScalars(s: ScalarStruct) + # Events @ Event with a single U64 arg event Event1(