Skip to content

Commit f2dcf6d

Browse files
authored
Merge pull request #960 from nasa/topology-ports-users-guide
Topology ports users guide
2 parents f40109a + 987ff77 commit f2dcf6d

18 files changed

Lines changed: 1200 additions & 222 deletions

compiler/lib/src/main/resources/META-INF/native-image/reflect-config.json

Lines changed: 172 additions & 182 deletions
Large diffs are not rendered by default.

compiler/lib/src/main/scala/analysis/Semantics/Connection.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ object Connection {
222222
case InterfaceInstance.InterfaceComponentInstance(ci) => this
223223
case InterfaceInstance.InterfaceTopology(top) => this.copy(
224224
// Look up the mapping for this port instance
225-
port = top.portMap(port.portInstance.getUnqualifiedName)._1,
225+
port = top.portMap(port.portInstance.getUnqualifiedName).pii,
226226
topologyPort = Some(this)
227227
// Recursively resolve the endpoint to a component instance
228228
).getUnderlyingEndpoint()

compiler/lib/src/main/scala/analysis/Semantics/ResolveTopology/ResolvePartiallyNumbered.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,9 @@ object ResolvePartiallyNumbered {
2828

2929
/** Check that connection instances are legal */
3030
private def checkPortInstances(t: Topology): Result.Result[Unit] = {
31-
def checkPort(i: (PortInstanceIdentifier, Location)) = {
32-
val (port, loc) = i
31+
def checkPort(i: TopologyPort) = {
3332
for {
34-
_ <- t.lookUpInstanceAt(port.interfaceInstance, loc)
33+
_ <- t.lookUpInstanceAt(i.pii.interfaceInstance, i.getUnderlyingPortLoc)
3534
}
3635
yield ()
3736
}

compiler/lib/src/main/scala/analysis/Semantics/ResolveTopology/ResolveTopologyPortInterface.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ object ResolveTopologyPortInterface {
1616
t <- t.addPort(
1717
aNode,
1818
instance,
19-
Locations.get(node.id)
2019
)
2120
} yield t
2221
})

compiler/lib/src/main/scala/analysis/Semantics/Topology.scala

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ case class Topology(
2020
/** List of the ports in the topology to resolve later */
2121
ports: List[Ast.Annotated[AstNode[Ast.SpecTopPort]]] = List(),
2222
/** The ports in the topology resolved to their port instance identifiers */
23-
portMap: Map[Name.Unqualified, (PortInstanceIdentifier, Location)] = Map(),
23+
portMap: Map[Name.Unqualified, TopologyPort] = Map(),
2424
/** Resolved port interface of the topology */
2525
portInterface: PortInterface = PortInterface("topology"),
2626
/** The connection patterns of this topology */
@@ -53,17 +53,17 @@ case class Topology(
5353

5454
/** Add a port to the topology */
5555
def addPort(
56-
node: Ast.Annotated[AstNode[Ast.SpecTopPort]],
56+
aNode: Ast.Annotated[AstNode[Ast.SpecTopPort]],
5757
underlyingPort: PortInstanceIdentifier,
58-
loc: Location,
5958
) = {
60-
val name = node._2.data.name
59+
val (_, node, _) = aNode
60+
val name = node.data.name
6161

6262
for {
6363
// Check that the topology port for a general port
6464
pi <- underlyingPort.portInstance match {
6565
case _: PortInstance.Internal => Left(SemanticError.InvalidPortInstance(
66-
loc,
66+
Locations.get(node.id),
6767
"topology port cannot point to an internal port",
6868
Locations.get(underlyingPort.portInstance.getNodeId)
6969
))
@@ -72,7 +72,7 @@ case class Topology(
7272
for {
7373
iface <- this.portInterface.addPortInstance(
7474
PortInstance.Topology(
75-
node,
75+
aNode,
7676
underlyingPort.portInstance
7777
)
7878
)
@@ -81,17 +81,20 @@ case class Topology(
8181
}
8282

8383
t <- portMap.get(name) match {
84-
case Some((_, prevPortLoc)) =>
84+
case Some(prevPort) =>
8585
Left(SemanticError.DuplicatePortInstance(
8686
name,
87-
loc,
87+
Locations.get(node.id),
8888
List(),
89-
prevPortLoc,
89+
prevPort.getLoc,
9090
List()
9191
))
9292
case None =>
9393
Right(this.copy(
94-
portMap = portMap + (name -> (underlyingPort, loc)),
94+
portMap = portMap + (name -> TopologyPort(
95+
aNode,
96+
underlyingPort
97+
)),
9598
portInterface = pi
9699
))
97100
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package fpp.compiler.analysis
2+
3+
import fpp.compiler.ast._
4+
import fpp.compiler.util._
5+
6+
/** An FPP topology port */
7+
case class TopologyPort(
8+
aNode: Ast.Annotated[AstNode[Ast.SpecTopPort]],
9+
pii: PortInstanceIdentifier
10+
) {
11+
12+
def getLoc: Location = Locations.get(aNode._2.id)
13+
14+
def getUnderlyingPortLoc = Locations.get(aNode._2.data.underlyingPort.id)
15+
16+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
port P
2+
3+
active component C1 {
4+
5+
output port pOut: [2] P
6+
7+
internal port P(x: U32)
8+
9+
}
10+
11+
passive component C2 {
12+
13+
sync input port pIn: P
14+
15+
}
16+
17+
instance c1: C1 base id 0x100 queue size 10
18+
instance c2: C2 base id 0x200
19+
20+
topology A {
21+
instance c1
22+
23+
port a = c1.pOut
24+
port b = c2.pIn
25+
}
26+
27+
topology B {
28+
29+
instance A
30+
31+
connections P {
32+
A.a -> A.b
33+
}
34+
35+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
fpp-check
2+
[ local path prefix ]/compiler/tools/fpp-check/test/top_ports/interface_instance_not_member.fpp:24.12
3+
port b = c2.pIn
4+
^
5+
error: instance c2 is not a member of topology A

compiler/tools/fpp-check/test/top_ports/tests.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ implements
44
implements_port_mismatch_1
55
implements_port_mismatch_2
66
implements_port_missing
7+
interface_instance_not_member
78
internal_port
89
nested
910
out_to_out

docs/code-prettify/run_prettify.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,7 @@ var IN_GLOBAL_SCOPE = false;
447447
"hook," +
448448
"id," +
449449
"if," +
450+
"implements," +
450451
"import," +
451452
"include," +
452453
"initial," +

0 commit comments

Comments
 (0)