Skip to content
This repository was archived by the owner on Jun 16, 2024. It is now read-only.

Commit 353c7f1

Browse files
committed
BuildTask: print utilisation stats.
1 parent ce7014d commit 353c7f1

File tree

4 files changed

+57
-13
lines changed

4 files changed

+57
-13
lines changed

src/main/scala/ee/hrzn/chryse/platform/ecp5/ECP5Platform.scala

+5-2
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ trait ECP5Platform { this: PlatformBoard[_ <: PlatformBoardResources] =>
5959
val lpfPath = s"$buildDir/${platform.id}/$name.lpf"
6060
writePath(lpfPath, topPlatform.lpf.toString())
6161

62-
val textcfgPath = s"$buildDir/${platform.id}/$name.config"
62+
val textcfgPath = s"$buildDir/${platform.id}/$name.config"
63+
val nextpnrLogPath = s"$buildDir/${platform.id}/$name.config.log"
6364
val textcfgCu = CompilationUnit(
6465
Some(jsonPath),
6566
Seq(lpfPath),
@@ -68,7 +69,7 @@ trait ECP5Platform { this: PlatformBoard[_ <: PlatformBoardResources] =>
6869
"nextpnr-ecp5",
6970
"-q",
7071
"--log",
71-
s"$buildDir/${platform.id}/$name.tim",
72+
nextpnrLogPath,
7273
"--json",
7374
jsonPath,
7475
"--lpf",
@@ -84,6 +85,8 @@ trait ECP5Platform { this: PlatformBoard[_ <: PlatformBoardResources] =>
8485
)
8586
runCu(CmdStepPNR, textcfgCu)
8687

88+
// TODO (ECP5): print statistics like ICE40Platform.
89+
8790
val bitPath = s"$buildDir/${platform.id}/$name.bit"
8891
val svfPath = s"$buildDir/${platform.id}/$name.svf"
8992
val bitCu = CompilationUnit(

src/main/scala/ee/hrzn/chryse/platform/ice40/ICE40Platform.scala

+12-2
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ trait ICE40Platform { this: PlatformBoard[_ <: PlatformBoardResources] =>
5757
val pcfPath = s"$buildDir/${platform.id}/$name.pcf"
5858
writePath(pcfPath, topPlatform.pcf.toString())
5959

60-
val ascPath = s"$buildDir/${platform.id}/$name.asc"
60+
val ascPath = s"$buildDir/${platform.id}/$name.asc"
61+
val nextpnrLogPath = s"$buildDir/${platform.id}/$name.asc.log"
6162
val ascCu = CompilationUnit(
6263
Some(jsonPath),
6364
Seq(pcfPath),
@@ -66,7 +67,7 @@ trait ICE40Platform { this: PlatformBoard[_ <: PlatformBoardResources] =>
6667
"nextpnr-ice40",
6768
"-q",
6869
"--log",
69-
s"$buildDir/${platform.id}/$name.tim",
70+
nextpnrLogPath,
7071
"--json",
7172
jsonPath,
7273
"--pcf",
@@ -80,6 +81,15 @@ trait ICE40Platform { this: PlatformBoard[_ <: PlatformBoardResources] =>
8081
)
8182
runCu(CmdStepPNR, ascCu)
8283

84+
println()
85+
println("Device utilisation:")
86+
logFileBetween(
87+
nextpnrLogPath,
88+
raw"Info: Device utilisation:".r,
89+
raw"Info: Placed .*".r,
90+
Some("Info: "),
91+
)
92+
8393
val binPath = s"$buildDir/${platform.id}/$name.bin"
8494
val binCu = CompilationUnit(
8595
Some(ascPath),

src/main/scala/ee/hrzn/chryse/tasks/BaseTask.scala

+32
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,38 @@ trait BaseTask {
130130
.map(_.toString)
131131
.filter(_.endsWith(ext))
132132

133+
protected def logFileBetween(
134+
path: String,
135+
start: Regex,
136+
end: Regex,
137+
prefix: Option[String] = None,
138+
): Unit = {
139+
var started = false
140+
var ended = false
141+
val lines = Files.lines(Paths.get(path)).iterator.asScala
142+
143+
while (!ended && lines.hasNext) {
144+
val line = lines.next()
145+
if (!started) {
146+
started = start.matches(line)
147+
} else if (end.matches(line)) {
148+
ended = true
149+
} else {
150+
println(prefix match {
151+
case Some(prefix) =>
152+
if (
153+
line.length >= prefix.length && line
154+
.substring(0, prefix.length()) == prefix
155+
)
156+
line.substring(prefix.length())
157+
else line
158+
case None =>
159+
line
160+
})
161+
}
162+
}
163+
}
164+
133165
case class CompilationUnit(
134166
val primaryInPath: Option[String],
135167
val otherInPaths: Seq[String],

src/main/scala/ee/hrzn/chryse/tasks/BuildTask.scala

+8-9
Original file line numberDiff line numberDiff line change
@@ -66,22 +66,21 @@ private[chryse] object BuildTask extends BaseTask {
6666
|write_json $jsonPath""".stripMargin,
6767
)
6868

69+
val yosysLogPath = s"$buildDir/${platform.id}/$name.json.log"
6970
val yosysCu = CompilationUnit(
7071
Some(verilogPath),
7172
Seq(yosysScriptPath),
7273
jsonPath,
73-
Seq(
74-
"yosys",
75-
"-q",
76-
"-g",
77-
"-l",
78-
s"$buildDir/${platform.id}/$name.rpt",
79-
"-s",
80-
yosysScriptPath,
81-
),
74+
Seq("yosys", "-q", "-g", "-l", yosysLogPath, "-s", yosysScriptPath),
8275
)
8376
runCu(CmdStepSynthesise, yosysCu)
8477

78+
logFileBetween(
79+
yosysLogPath,
80+
raw"\d+\.\d+\. Printing statistics\.".r,
81+
raw"\d+\.\d+\. .*".r,
82+
)
83+
8584
val binPath = platform.build(chryse, topPlatform.get, jsonPath)
8685

8786
if (options.program) {

0 commit comments

Comments
 (0)