Skip to content
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 @@ -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
24 changes: 7 additions & 17 deletions compiler/lib/src/main/scala/codegen/CppWriter/ArrayCppWriter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -454,18 +454,14 @@ case class ArrayCppWriter (
|tmp.format(\"%s\", tmp.toChar());"""

val formatLoop = indexIterator(lines(
s"""|Fw::String tmp;
s"""|// Array data
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Kronos3 I decided to simplify the code generation here. Testing the old code was difficult, and IMO it is over-optimized. If you are hitting this case (trying to write a large array of strings into a much smaller string) then your system is mistuned anyway -- so I don't think we should try to optimize it.

|Fw::String tmp;
|$fillTmpString
|
|FwSizeType size = tmp.length() + (index > 0 ? 2 : 0);
|if ((size + sb.length()) <= sb.maxLength()) {
| if (index > 0) {
| sb += ", ";
| }
| sb += tmp;
|} else {
| break;
|if (index > 0) {
| sb += ", ";
|}
|sb += tmp;
|"""
))
val serializedSize = eltType.getUnderlyingType match {
Expand Down Expand Up @@ -573,19 +569,13 @@ case class ArrayCppWriter (
|sb = "";
|
|// Array prefix
|if (sb.length() + 2 <= sb.maxLength()) {
| sb += \"[ \";
|} else {
| return;
|}"""),
|sb += \"[ \";"""),
List(Line.blank),
formatLoop,
List(Line.blank),
lines(
s"""|// Array suffix
|if (sb.length() + 2 <= sb.maxLength()) {
| sb += \" ]\";
|}"""),
|sb += \" ]\";""")
),
CppDoc.Function.NonSV,
CppDoc.Function.Const,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ case class ComponentEvents (
case t: Type.String =>
val serialSize = writeStringSize(s, t)
lines(
s"_status = $name.serializeTo(_logBuff, FW_MIN(FW_LOG_STRING_MAX_SIZE, $serialSize));"
s"_status = $name.serializeTo(_logBuff, FW_MIN(static_cast<FwSizeType>(FW_LOG_STRING_MAX_SIZE), $serialSize));"
)
case t => lines(
s"""|#if FW_AMPCS_COMPATIBLE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -627,8 +627,13 @@ case class ComponentInternalStateMachines(
)

/** The signal types and the signal string size */
private val signalTypesAndStringSize: (Set[Type], BigInt) =
internalSmSymbols.foldLeft ((Set(), BigInt(0))) {
private val signalTypesAndStringSize: (Set[Type], String) = {
def max(s1: String, s2: String) = (s1, s2) match {
case ("0", _) => s2
case (_, "0") => s1
case _ => if s1 == s2 then s1 else s"FW_MAX($s1, $s2)"
}
internalSmSymbols.foldLeft ((Set(), "0")) {
case ((ts, maxStringSize), sym) => {
val signals = s.a.stateMachineMap(sym).signals
signals.foldLeft ((ts, maxStringSize)) {
Expand All @@ -638,7 +643,7 @@ case class ComponentInternalStateMachines(
s.a.typeMap(tn.id).getUnderlyingType match {
case t: Type.String => (
ts + Type.String(None),
maxStringSize.max(getStringSize(s, t))
max(maxStringSize, writeStringSize(s, t))
)
case t => (ts + t, maxStringSize)
}
Expand All @@ -647,11 +652,12 @@ case class ComponentInternalStateMachines(
}
}
}
}

private val signalTypes: List[Type] =
signalTypesAndStringSize._1.toList.sortBy(writeSignalTypeName)

private val signalStringSize: BigInt = signalTypesAndStringSize._2
private val signalStringSize: String = signalTypesAndStringSize._2

private val hasSignalTypes: Boolean = !signalTypes.isEmpty

Expand Down Expand Up @@ -692,7 +698,7 @@ case class ComponentInternalStateMachines(
private def writeSignalTypeSize(t: Type): String =
t.getUnderlyingType match {
case _: Type.String =>
s"Fw::StringBase::STATIC_SERIALIZED_SIZE(${signalStringSize.toString})"
s"Fw::StringBase::STATIC_SERIALIZED_SIZE($signalStringSize)"
case _ => writeStaticSerializedSizeExpr(s, t, TypeCppWriter.getName(s, t))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ case class ComponentTelemetry (
channel.channelType.getUnderlyingType match {
case t: Type.String =>
val serialSize = writeStringSize(s, t)
s"Fw::SerializeStatus _stat = arg.serializeTo(_tlmBuff, FW_MIN(FW_TLM_STRING_MAX_SIZE, $serialSize));"
s"Fw::SerializeStatus _stat = arg.serializeTo(_tlmBuff, FW_MIN(static_cast<FwSizeType>(FW_TLM_STRING_MAX_SIZE), $serialSize));"
case _ =>
"Fw::SerializeStatus _stat = _tlmBuff.serializeFrom(arg);"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ object ConstantCppWriter extends CppWriterUtils {
val hppLines = {
val defLine = line(s"$name = $value")
List(
line(s"enum FppConstant_$name {"),
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the enum type here. It was causing the compiler to complain about comparing enum values with different types.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update: I had to add static casts to remove the warnings on gcc. So removing the enum type isn't necessary. However, I also think that the enum type doesn't really add anything there, so we can remove it.

line(s"enum {"),
indentIn(defLine),
line("};")
)
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 @@ -220,8 +218,6 @@ case class CppWriterState(

object CppWriterState {

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

/** Construct a header string */
def headerString(s: String): String = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,19 +287,10 @@ trait CppWriterUtils extends LineUtils {
/** Get a buffer name */
def getBufferName(name: String) = s"__fprime_ac_${name}_buffer"

/** Gets the size of a string type */
def getStringSize(s: CppWriterState, t: Type.String): BigInt =
t.size.map(
node => {
val _ @ Value.Integer(value) = s.a.valueMap(node.id).convertToType(Type.Integer).get
value
}
).getOrElse(BigInt(s.defaultStringSize))

/** 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("static_cast<FwSizeType>(FW_FIXED_LENGTH_STRING_SIZE)")

/** 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 */
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jwest115 I completely removed the default default string size. The code generation now depends only on the symbolic constant FW_FIXED_LENGTH_STRING_SIZE. That is what we said in #903.

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 @@ -31,7 +31,7 @@ class Basic :
SERIALIZED_SIZE =
sizeof(TU32) +
sizeof(TF32) +
Fw::StringBase::STATIC_SERIALIZED_SIZE(80) +
Fw::StringBase::STATIC_SERIALIZED_SIZE(static_cast<FwSizeType>(FW_FIXED_LENGTH_STRING_SIZE)) +
Fw::StringBase::STATIC_SERIALIZED_SIZE(2)
};

Expand Down Expand Up @@ -190,7 +190,7 @@ class Basic :

TU32 m_A;
TF32 m_B;
char m___fprime_ac_C_buffer[Fw::StringBase::BUFFER_SIZE(80)];
char m___fprime_ac_C_buffer[Fw::StringBase::BUFFER_SIZE(static_cast<FwSizeType>(FW_FIXED_LENGTH_STRING_SIZE))];
Fw::ExternalString m_C;
char m___fprime_ac_D_buffer[Fw::StringBase::BUFFER_SIZE(2)];
Fw::ExternalString m_D;
Expand Down
22 changes: 6 additions & 16 deletions compiler/tools/fpp-to-cpp/test/alias/C_AArrayAc.ref.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,31 +187,21 @@ void C_A ::
sb = "";

// Array prefix
if (sb.length() + 2 <= sb.maxLength()) {
sb += "[ ";
} else {
return;
}
sb += "[ ";

for (FwSizeType index = 0; index < SIZE; index++) {
// Array data
Fw::String tmp;
tmp.format("%" PRIu32 "", this->elements[index]);

FwSizeType size = tmp.length() + (index > 0 ? 2 : 0);
if ((size + sb.length()) <= sb.maxLength()) {
if (index > 0) {
sb += ", ";
}
sb += tmp;
} else {
break;
if (index > 0) {
sb += ", ";
}
sb += tmp;
}

// Array suffix
if (sb.length() + 2 <= sb.maxLength()) {
sb += " ]";
}
sb += " ]";
}

#endif
22 changes: 6 additions & 16 deletions compiler/tools/fpp-to-cpp/test/alias/SM_AArrayAc.ref.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,31 +187,21 @@ void SM_A ::
sb = "";

// Array prefix
if (sb.length() + 2 <= sb.maxLength()) {
sb += "[ ";
} else {
return;
}
sb += "[ ";

for (FwSizeType index = 0; index < SIZE; index++) {
// Array data
Fw::String tmp;
tmp.format("%" PRIu32 "", this->elements[index]);

FwSizeType size = tmp.length() + (index > 0 ? 2 : 0);
if ((size + sb.length()) <= sb.maxLength()) {
if (index > 0) {
sb += ", ";
}
sb += tmp;
} else {
break;
if (index > 0) {
sb += ", ";
}
sb += tmp;
}

// Array suffix
if (sb.length() + 2 <= sb.maxLength()) {
sb += " ]";
}
sb += " ]";
}

#endif
22 changes: 6 additions & 16 deletions compiler/tools/fpp-to-cpp/test/array/AArrayAc.ref.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,31 +187,21 @@ void A ::
sb = "";

// Array prefix
if (sb.length() + 2 <= sb.maxLength()) {
sb += "[ ";
} else {
return;
}
sb += "[ ";

for (FwSizeType index = 0; index < SIZE; index++) {
// Array data
Fw::String tmp;
tmp.format("%" PRIu32 "", this->elements[index]);

FwSizeType size = tmp.length() + (index > 0 ? 2 : 0);
if ((size + sb.length()) <= sb.maxLength()) {
if (index > 0) {
sb += ", ";
}
sb += tmp;
} else {
break;
if (index > 0) {
sb += ", ";
}
sb += tmp;
}

// Array suffix
if (sb.length() + 2 <= sb.maxLength()) {
sb += " ]";
}
sb += " ]";
}

#endif
22 changes: 6 additions & 16 deletions compiler/tools/fpp-to-cpp/test/array/AbsTypeArrayAc.ref.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,31 +187,21 @@ void AbsType ::
sb = "";

// Array prefix
if (sb.length() + 2 <= sb.maxLength()) {
sb += "[ ";
} else {
return;
}
sb += "[ ";

for (FwSizeType index = 0; index < SIZE; index++) {
// Array data
Fw::String tmp;
this->elements[index].toString(tmp);

FwSizeType size = tmp.length() + (index > 0 ? 2 : 0);
if ((size + sb.length()) <= sb.maxLength()) {
if (index > 0) {
sb += ", ";
}
sb += tmp;
} else {
break;
if (index > 0) {
sb += ", ";
}
sb += tmp;
}

// Array suffix
if (sb.length() + 2 <= sb.maxLength()) {
sb += " ]";
}
sb += " ]";
}

#endif
Loading