Skip to content
Open
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 @@ -77,7 +77,8 @@ object ImpliedUse {
* Each name is a list of identifiers */
def getTopologyConstants(a: Analysis) =
if (a.dictionaryGeneration) then List(
List("Fw", "DpCfg", "CONTAINER_USER_DATA_SIZE")
List("Fw", "DpCfg", "CONTAINER_USER_DATA_SIZE"),
List("FW_FIXED_LENGTH_STRING_SIZE")
)
else Nil

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ case class CppWriterState(
guardPrefix: Option[String] = None,
/** The list of include path prefixes */
pathPrefixes: List[String] = Nil,
/** The default string size */
defaultStringSize: Int = CppWriterState.defaultDefaultStringSize,
/** The name of the tool using the CppWriter */
toolName: Option[String] = None,
/** The map from strings to locations */
Expand Down Expand Up @@ -216,6 +214,15 @@ case class CppWriterState(
case _ => false
}

def getFwDefaultStringSize: BigInt = {
a.frameworkDefinitions.constants.fwFixedLengthStringSize match {
case Some(s: Symbol.Constant) => a.valueMap(s.getNodeId) match {
case Value.Integer(value) => value
case _ => throw InternalError("expected integer value")
}
case None => CppWriterState.defaultDefaultStringSize
}
}
}

object CppWriterState {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,12 +294,12 @@ trait CppWriterUtils extends LineUtils {
val _ @ Value.Integer(value) = s.a.valueMap(node.id).convertToType(Type.Integer).get
value
}
).getOrElse(BigInt(s.defaultStringSize))
).getOrElse(s.getFwDefaultStringSize)

/** Write the size of a string type */
def writeStringSize(s: CppWriterState, t: Type.String): String =
t.size.map(node => ValueCppWriter.write(s, s.a.valueMap(node.id))).
getOrElse(s.defaultStringSize.toString)
getOrElse(s.getFwDefaultStringSize.toString)

/** Write a C++ expression for static serialized size */
def writeStaticSerializedSizeExpr(s: CppWriterState, t: Type, typeName: String): String =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,10 @@ case class DictionaryJsonEncoder(
"name" -> "string".asJson,
"kind" -> "string".asJson
)
val fwDefaultStringSize = dictionaryState.getFwDefaultStringSize
size match {
case Some(s) => Json.obj("size" -> valueAsJson(dictionaryState.a.valueMap(s.id))).deepMerge(jsonObj)
case None => Json.obj("size" -> dictionaryState.defaultStringSize.asJson).deepMerge(jsonObj)
case None => Json.obj("size" -> fwDefaultStringSize.asJson).deepMerge(jsonObj)
}
}
case Type.Array(node, _, _, _) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ case class DictionaryJsonEncoderState(
a: Analysis,
/** The output directory */
dir: String = ".",
/** The default string size */
defaultStringSize: Int = DictionaryJsonEncoderState.defaultDefaultStringSize,
/** The default bool size */
boolSize: Int = DictionaryJsonEncoderState.boolSize,
/** The Dictionary metadata */
Expand All @@ -29,17 +27,24 @@ case class DictionaryJsonEncoderState(
}
}

def getFwDefaultStringSize: BigInt = {
a.frameworkDefinitions.constants.fwFixedLengthStringSize match {
case Some(s: Symbol.Constant) => a.valueMap(s.getNodeId) match {
case Value.Integer(value) => value
case _ => throw InternalError("expected integer value")
}
case None => throw InternalError("FW_FIXED_LENGTH_STRING_SIZE constant not defined")
}
}

}

case object DictionaryJsonEncoderState {

/** The default string size */
val defaultDefaultStringSize = 80

/** The default bool size */
val boolSize = 8

/** Gets the generated JSON file name for a topology definition */
def getTopologyFileName(baseName: String): String = s"${baseName}TopologyDictionary.json"

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class StringArray :
enum {
//! The size of the serial representation
SERIALIZED_SIZE =
Fw::StringBase::STATIC_SERIALIZED_SIZE(80) +
Fw::StringBase::STATIC_SERIALIZED_SIZE(60) +
Fw::StringBase::STATIC_SERIALIZED_SIZE(40) * 16
};

Expand Down Expand Up @@ -175,7 +175,7 @@ class StringArray :
// Member variables
// ----------------------------------------------------------------------

char m___fprime_ac_s1_buffer[Fw::StringBase::BUFFER_SIZE(80)];
char m___fprime_ac_s1_buffer[Fw::StringBase::BUFFER_SIZE(60)];
Fw::ExternalString m_s1;
char m___fprime_ac_s2_buffer[16][Fw::StringBase::BUFFER_SIZE(40)];
Fw::ExternalString m_s2[16];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class String :
enum {
//! The size of the serial representation
SERIALIZED_SIZE =
Fw::StringBase::STATIC_SERIALIZED_SIZE(80) +
Fw::StringBase::STATIC_SERIALIZED_SIZE(60) +
Fw::StringBase::STATIC_SERIALIZED_SIZE(40)
};

Expand Down Expand Up @@ -160,7 +160,7 @@ class String :
// Member variables
// ----------------------------------------------------------------------

char m___fprime_ac_s1_buffer[Fw::StringBase::BUFFER_SIZE(80)];
char m___fprime_ac_s1_buffer[Fw::StringBase::BUFFER_SIZE(60)];
Fw::ExternalString m_s1;
char m___fprime_ac_s2_buffer[Fw::StringBase::BUFFER_SIZE(40)];
Fw::ExternalString m_s2;
Expand Down
2 changes: 2 additions & 0 deletions compiler/tools/fpp-to-cpp/test/struct/string.fpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
constant FW_FIXED_LENGTH_STRING_SIZE = 60

struct String {
s1: string
s2: string size 40
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,29 @@
}
],
"constants" : [
{
"kind" : "constant",
"qualifiedName" : "FW_FIXED_LENGTH_STRING_SIZE",
"type" : {
"name" : "U64",
"kind" : "integer",
"size" : 64,
"signed" : false
},
"value" : 256
},
{
"kind" : "constant",
"qualifiedName" : "Fw.DpCfg.CONTAINER_USER_DATA_SIZE",
"type" : {
"name" : "U64",
"kind" : "integer",
"size" : 64,
"signed" : false
},
"value" : 32,
"annotation" : "The container user data size"
},
{
"kind" : "constant",
"qualifiedName" : "FW_SERIALIZE_TRUE_VALUE",
Expand All @@ -337,15 +360,14 @@
},
{
"kind" : "constant",
"qualifiedName" : "Fw.DpCfg.CONTAINER_USER_DATA_SIZE",
"qualifiedName" : "STRING_SIZE",
"type" : {
"name" : "U64",
"kind" : "integer",
"size" : 64,
"signed" : false
},
"value" : 32,
"annotation" : "The container user data size"
"value" : 256
}
],
"commands" : [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,14 +249,26 @@
"constants" : [
{
"kind" : "constant",
"qualifiedName" : "FW_SERIALIZE_FALSE_VALUE",
"qualifiedName" : "FW_FIXED_LENGTH_STRING_SIZE",
"type" : {
"name" : "U64",
"kind" : "integer",
"size" : 64,
"signed" : false
},
"value" : 0
"value" : 256
},
{
"kind" : "constant",
"qualifiedName" : "Fw.DpCfg.CONTAINER_USER_DATA_SIZE",
"type" : {
"name" : "U64",
"kind" : "integer",
"size" : 64,
"signed" : false
},
"value" : 32,
"annotation" : "The container user data size"
},
{
"kind" : "constant",
Expand All @@ -271,15 +283,25 @@
},
{
"kind" : "constant",
"qualifiedName" : "Fw.DpCfg.CONTAINER_USER_DATA_SIZE",
"qualifiedName" : "FW_SERIALIZE_FALSE_VALUE",
"type" : {
"name" : "U64",
"kind" : "integer",
"size" : 64,
"signed" : false
},
"value" : 32,
"annotation" : "The container user data size"
"value" : 0
},
{
"kind" : "constant",
"qualifiedName" : "STRING_SIZE",
"type" : {
"name" : "U64",
"kind" : "integer",
"size" : 64,
"signed" : false
},
"value" : 256
}
],
"commands" : [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,45 +86,6 @@
"signed" : false
}
},
{
"kind" : "struct",
"qualifiedName" : "S",
"members" : {
"X" : {
"type" : {
"name" : "string",
"kind" : "string",
"size" : 80
},
"index" : 0
},
"Y" : {
"type" : {
"name" : "A2",
"kind" : "qualifiedIdentifier"
},
"index" : 1
},
"Z" : {
"type" : {
"name" : "S2",
"kind" : "qualifiedIdentifier"
},
"index" : 2
}
},
"default" : {
"X" : "",
"Y" : [
0,
0,
0
],
"Z" : {
"X" : 0
}
}
},
{
"kind" : "alias",
"qualifiedName" : "FwEventIdType",
Expand Down Expand Up @@ -345,6 +306,45 @@
"signed" : false
}
},
{
"kind" : "struct",
"qualifiedName" : "S",
"members" : {
"X" : {
"type" : {
"name" : "string",
"kind" : "string",
"size" : 256
},
"index" : 0
},
"Y" : {
"type" : {
"name" : "A2",
"kind" : "qualifiedIdentifier"
},
"index" : 1
},
"Z" : {
"type" : {
"name" : "S2",
"kind" : "qualifiedIdentifier"
},
"index" : 2
}
},
"default" : {
"X" : "",
"Y" : [
0,
0,
0
],
"Z" : {
"X" : 0
}
}
},
{
"kind" : "alias",
"qualifiedName" : "FwSizeType",
Expand Down Expand Up @@ -408,6 +408,17 @@
}
],
"constants" : [
{
"kind" : "constant",
"qualifiedName" : "FW_FIXED_LENGTH_STRING_SIZE",
"type" : {
"name" : "U64",
"kind" : "integer",
"size" : 64,
"signed" : false
},
"value" : 256
},
{
"kind" : "constant",
"qualifiedName" : "Fw.DpCfg.CONTAINER_USER_DATA_SIZE",
Expand All @@ -431,6 +442,17 @@
},
"value" : 255
},
{
"kind" : "constant",
"qualifiedName" : "STRING_SIZE",
"type" : {
"name" : "U64",
"kind" : "integer",
"size" : 64,
"signed" : false
},
"value" : 256
},
{
"kind" : "constant",
"qualifiedName" : "P.C",
Expand Down
Loading