Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 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
2 changes: 2 additions & 0 deletions compiler/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ test-output.txt
*.o
native-fpp-*
*.class
# Version is not checked in during typical development
lib/src/main/scala/util/Version.scala
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ trait UseAnalyzer extends TypeExpressionAnalyzer {
case direct : Ast.SpecConnectionGraph.Direct => visitList(a, direct.connections, connection)
case pattern : Ast.SpecConnectionGraph.Pattern => for {
a <- qualIdentNode (componentInstanceUse) (a, pattern.source)
a <- visitList(a, pattern.targets, qualIdentNode (componentInstanceUse) _)
a <- visitList(a, pattern.targets, qualIdentNode(componentInstanceUse))
} yield a
}
}
Expand Down
59 changes: 29 additions & 30 deletions compiler/lib/src/main/scala/codegen/CppWriter/AliasCppWriter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -120,39 +120,34 @@ case class AliasCppWriter (
return linesMember(List())
}

val systemHHeaders = List(
"FpConfig.h"
).map(CppWriter.systemHeaderString).map(line)

// Include Fw/Types/BasicTypes.h here
// To avoid an include cycle, don't depend on Fw/FPrimeBasicTypes.hpp
// If the alias refers to one of those types, the header will appear
// in symbolHeaders
val standardHeaders = List(
"Fw/Types/BasicTypes.h",
).map(CppWriter.headerString)

val symbolHeaders = writeHIncludeDirectives(s, aNode)
val headers = (standardHeaders ++ symbolHeaders).distinct.sorted.map(line)
linesMember(List.concat(
addBlankPrefix(systemHHeaders),
addBlankPrefix(headers)
))
linesMember(addBlankPrefix(headers))
}

private def getHppIncludes: CppDoc.Member.Lines = {
val systemHppHeaders = List(
"FpConfig.hpp"
).map(CppWriter.systemHeaderString).map(line)

val standardHeaders = List(
// Include BasicTypes.h or Fw/Types/String.hpp here
// Fw/Types/String.hpp includes Fw/Types/BasicTypes.h
// To avoid an include cycle, don't depend on Fw/FPrimeBasicTypes.hpp
// If the alias refers to one of those types, the header will appear
// in symbolHeaders
aliasType.aliasType match {
case Type.String(_) => "Fw/Types/String.hpp"
case _ => "Fw/Types/BasicTypes.h"
case _ => "Fw/Types/BasicTypes.hpp"
},
).map(CppWriter.headerString)
val symbolHeaders = writeHppIncludeDirectives(s, aNode)
val headers = standardHeaders ++ symbolHeaders
linesMember(List.concat(
addBlankPrefix(systemHppHeaders),
addBlankPrefix(headers.distinct.sorted.map(line))
))
linesMember(addBlankPrefix(headers.distinct.sorted.map(line)))
}

private def getHppDefinition: CppDoc.Member.Lines = {
Expand All @@ -178,20 +173,24 @@ case class AliasCppWriter (

private def getHDefinition: CppDoc.Member.Lines = {
val name = s.getName(symbol)
def getTypePRI(ty: Type): String = {
ty match {
case Type.Float(f) => aliasType.aliasType.toString().toLowerCase()
case Type.PrimitiveInt(i) => aliasType.aliasType.toString().toLowerCase()
case _ => typeCppWriter.write(ty)
}
}

val fmtSpec = getTypePRI(aliasType.aliasType)
val fmtSpecList = aliasType.aliasType match {
// C-style floating-poing format strings (f, g) are platform-independent
// In F Prime code, we just use them
case Type.Float(f) => Nil
// C-style integer format strings (d, u, ld, lu, etc.) are platform-specific
// In F Prime code we don't use them. Instead we use a platform-independent macro.
// Write out the macro here
case _ => List("_" + typeCppWriter.write(aliasType.aliasType))
}

linesMember(addBlankPrefix(
AnnotationCppWriter.writePreComment(aNode) ++ lines(
s"""|typedef ${typeCppWriter.write(aliasType.aliasType)} $name;
|#define PRI_$name PRI_${fmtSpec}""")
))
linesMember(
addBlankPrefix(
AnnotationCppWriter.writePreComment(aNode) ++ (
s"typedef ${typeCppWriter.write(aliasType.aliasType)} $name;" ::
fmtSpecList.map(s => s"#define PRI_$name PRI$s")
).map(line)
)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ case class ArrayCppWriter (

private def getHppIncludes: CppDoc.Member = {
val standardHeaders = List(
"FpConfig.hpp",
"Fw/FPrimeBasicTypes.hpp",
"Fw/Types/ExternalString.hpp",
"Fw/Types/Serializable.hpp",
"Fw/Types/String.hpp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,13 @@ case class ComponentCppWriter (
val internalStrHeaders =
guardedList (hasInternalPorts) (List("Fw/Types/InternalInterfaceString.hpp"))
val systemHeaders =
("FpConfig.hpp" :: guardedList (hasEvents) (
(guardedList (hasEvents) (
List("atomic")
)).map(CppWriter.systemHeaderString).sortBy(_.toLowerCase()).map(line)
val userHeaders = {
val standardHeaders = List.concat(
List(
"Fw/FPrimeBasicTypes.hpp",
"Fw/Port/InputSerializePort.hpp",
"Fw/Port/OutputSerializePort.hpp",
"Fw/Comp/ActiveComponentBase.hpp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ object ConstantCppWriter extends CppWriterUtils {
case constantMembers =>
val fileName = ComputeCppFiles.FileNames.getConstants
val hppHeaderLines = {
val headers = List("FpConfig.hpp")
val headers = List("Fw/FPrimeBasicTypes.hpp")
Line.blank :: headers.map(CppWriter.headerLine)
}
val cppHeaderLines = {
Expand Down
37 changes: 2 additions & 35 deletions compiler/lib/src/main/scala/codegen/CppWriter/CppWriterState.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package fpp.compiler.codegen
import fpp.compiler.analysis._
import fpp.compiler.ast._
import fpp.compiler.util._
import fpp.compiler.codegen.CppWriterState.builtInTypes

/** C++ Writer state */
case class CppWriterState(
Expand Down Expand Up @@ -137,8 +136,7 @@ case class CppWriterState(
val name = getName(sym)
for {
fileName <- sym match {
case _: Symbol.AbsType =>
if isBuiltInType(name) then None else Some(name)
case _: Symbol.AbsType => Some(name)
case _: Symbol.AliasType => Some(
ComputeCppFiles.FileNames.getAliasType(name)
)
Expand Down Expand Up @@ -172,9 +170,6 @@ case class CppWriterState(
usedSymbols.map(getIncludeFiles).filter(_.isDefined).map(_.get).map(CppWriterState.headerString).toList
}

/** Is t a built-in type? */
def isBuiltInType(typeName: String): Boolean = builtInTypes.contains(typeName)

def isTypeSupportedInC(t: Type): Boolean = {
t match {
case Type.AliasType(node, aliasType) =>
Expand All @@ -184,20 +179,14 @@ case class CppWriterState(
// Make sure all types in the alias chain meet the C requirements
case None => isTypeSupportedInC(aliasType)
}
case Type.AbsType(node) => isBuiltInType(getName(Symbol.AbsType(node)))
case Type.PrimitiveInt(_) => true
case Type.Float(_) => true
case _ => false
}
}

/** Is t a primitive type (not serializable)? */
def isPrimitive(t: Type, typeName: String): Boolean = (
isBuiltInType(typeName) ||
t.getUnderlyingType.isPrimitive ||
// See if this an alias of a builtin type
isBuiltInType(t.getUnderlyingType.toString())
)
def isPrimitive(t: Type, typeName: String): Boolean = t.getUnderlyingType.isPrimitive

/** Is t a string type? */
def isStringType(t: Type) = t.getUnderlyingType match {
Expand All @@ -212,28 +201,6 @@ object CppWriterState {
/** The default default string size */
val defaultDefaultStringSize = 80

/** A mapping from special built-in types to their
* default values */
val zero: Value.Integer = Value.Integer(0)
val builtInTypes: Map[String,Value.Integer] = Map(
"FwChanIdType" -> zero,
"FwDpIdType" -> zero,
"FwDpPriorityType" -> zero,
"FwEnumStoreType" -> zero,
"FwEventIdType" -> zero,
"FwIndexType" -> zero,
"FwOpcodeType" -> zero,
"FwPacketDescriptorType" -> zero,
"FwPrmIdType" -> zero,
"FwSignedSizeType" -> zero,
"FwSizeStoreType" -> zero,
"FwSizeType" -> zero,
"FwTimeBaseStoreType" -> zero,
"FwTimeContextStoreType" -> zero,
"FwTlmPacketizeIdType" -> zero,
"FwTraceIdType" -> zero,
)

/** Construct a header string */
def headerString(s: String): String = {
val q = "\""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,18 @@ import fpp.compiler.analysis._
trait CppWriterUtils extends LineUtils {

/** Standard system hpp headers */
val standardSystemHppHeaders = List(
"FpConfig.hpp"
).map(CppWriter.systemHeaderString)
val standardSystemHppHeaders = Nil.map(CppWriter.systemHeaderString)

/** Standard user hpp headers */
val standardUserHppHeaders = List(
"Fw/FPrimeBasicTypes.hpp",
"Fw/Types/ExternalString.hpp",
"Fw/Types/Serializable.hpp",
"Fw/Types/String.hpp"
).map(CppWriter.headerString)

/** Standard system cpp headers */
val standardSystemCppHeaders = Nil
val standardSystemCppHeaders = Nil.map(CppWriter.systemHeaderString)

/** Standard user cpp headers */
val standardUserCppHeaders = List(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ case class EnumCppWriter(

private def getHppIncludes: CppDoc.Member = {
val strings = List(
"FpConfig.hpp",
"Fw/FPrimeBasicTypes.hpp",
"Fw/Types/Serializable.hpp",
"Fw/Types/String.hpp"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,15 @@ case class PortCppWriter (
private def getHppIncludes: CppDoc.Member = {
val systemHeaders = List(
"cstdio",
"cstring",
"FpConfig.hpp"
"cstring"
).map(CppWriter.systemHeaderString).map(line)
val serializableHeader = data.returnType match {
case Some(_) => Nil
case None => List("Fw/Types/Serializable.hpp")
}
val standardHeaders = (
List(
"Fw/FPrimeBasicTypes.hpp",
"Fw/Comp/PassiveComponentBase.hpp",
"Fw/Port/InputPortBase.hpp",
"Fw/Port/OutputPortBase.hpp",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ case class StructCppWriter(

private def getHppIncludes: CppDoc.Member = {
val userHeaders = List(
"FpConfig.hpp",
"Fw/FPrimeBasicTypes.hpp",
"Fw/Types/ExternalString.hpp",
"Fw/Types/Serializable.hpp",
"Fw/Types/String.hpp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@ object ValueCppWriter {

override def absType(s: CppWriterState, v: Value.AbsType) = {
val aNode = v.t.node
val cppName = s.writeSymbol(Symbol.AbsType(aNode))
CppWriterState.builtInTypes.get(cppName) match {
case Some(v) => write(s, v)
case None => TypeCppWriter.getName(s, v.getType) ++ "()"
}
TypeCppWriter.getName(s, v.getType) ++ "()"
}

override def array(s: CppWriterState, v: Value.Array) = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,8 @@ case class XmlWriterState(
tagFileName <- sym match {
case Symbol.AbsType(aNode) =>
val symbol = Symbol.AbsType(aNode)
// Don't import headers for built-in types
val cppName = writeSymbol(symbol)
if (CppWriterState.builtInTypes.contains(cppName)) None
else {
val name = getName(symbol)
Some("include_header", s"${name}.hpp")
}
val name = getName(symbol)
Some("include_header", s"${name}.hpp")
case Symbol.Array(aNode) => Some(
"import_array_type",
XmlWriterState.getArrayFileName(getName(Symbol.Array(aNode)))
Expand Down
11 changes: 10 additions & 1 deletion compiler/scripts/fprime-gcc
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,13 @@ case "$os" in
;;
esac

g++ --std=c++11 $flags $os_flags -DTGT_OS_TYPE_$os_type -I $FPRIME -I $FPRIME/config -I $FPRIME/cmake/platform/types -I . $FPRIME_GCC_FLAGS $@
g++ --std=c++11 \
$flags \
$os_flags \
-DTGT_OS_TYPE_$os_type \
-I $FPRIME \
-I $FPRIME/config \
-I $FPRIME/cmake/platform/types \
-I . \
$FPRIME_GCC_FLAGS \
$@
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ EEnumAc.hpp
EEnumAi.xml
FppConstantsAc.cpp
FppConstantsAc.hpp
FwOpcodeTypeAliasAc.hpp
PPortAc.cpp
PPortAc.hpp
PPortAi.xml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ EEnumAc.hpp
EEnumAi.xml
FppConstantsAc.cpp
FppConstantsAc.hpp
FwOpcodeTypeAliasAc.hpp
PPortAc.cpp
PPortAc.hpp
PPortAi.xml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ EEnumAc.hpp
EEnumAi.xml
FppConstantsAc.cpp
FppConstantsAc.hpp
FwOpcodeTypeAliasAc.hpp
PPortAc.cpp
PPortAc.hpp
PPortAi.xml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ EEnumAc.hpp
EEnumAi.xml
FppConstantsAc.cpp
FppConstantsAc.hpp
FwOpcodeTypeAliasAc.hpp
PPortAc.cpp
PPortAc.hpp
PPortAi.xml
Expand Down
1 change: 1 addition & 0 deletions compiler/tools/fpp-filenames/test/include.ref.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ EEnumAc.hpp
EEnumAi.xml
FppConstantsAc.cpp
FppConstantsAc.hpp
FwOpcodeTypeAliasAc.hpp
PPortAc.cpp
PPortAc.hpp
PPortAi.xml
Expand Down
2 changes: 1 addition & 1 deletion compiler/tools/fpp-filenames/test/ok.fpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ state machine SM2 {
state S
}

type FwOpcodeType
type FwOpcodeType = U32
type WithCDefinition = U32
type WithCDefinitionBuiltin = FwOpcodeType
type WithoutCDefinition = A
Expand Down
1 change: 1 addition & 0 deletions compiler/tools/fpp-filenames/test/ok.ref.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ EEnumAc.hpp
EEnumAi.xml
FppConstantsAc.cpp
FppConstantsAc.hpp
FwOpcodeTypeAliasAc.hpp
PPortAc.cpp
PPortAc.hpp
PPortAi.xml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#define AbsSerializableAc_HPP

#include "AbsTypeAliasAc.hpp"
#include "FpConfig.hpp"
#include "Fw/FPrimeBasicTypes.hpp"
#include "Fw/Types/ExternalString.hpp"
#include "Fw/Types/Serializable.hpp"
#include "Fw/Types/String.hpp"
Expand Down
4 changes: 1 addition & 3 deletions compiler/tools/fpp-to-cpp/test/alias/AbsTypeAliasAc.ref.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
#ifndef AbsTypeAliasAc_HPP
#define AbsTypeAliasAc_HPP

#include <FpConfig.hpp>

#include "Fw/Types/BasicTypes.h"
#include "Fw/Types/BasicTypes.hpp"
#include "T.hpp"

//! An alias of abstract type
Expand Down
Loading