-
Notifications
You must be signed in to change notification settings - Fork 603
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add custom mdoc modifier for emitted Verilog (#1666)
- Loading branch information
1 parent
9f1d6cb
commit e6192ea
Showing
7 changed files
with
124 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,6 @@ generated/ | |
.idea_modules/ | ||
.project | ||
target/ | ||
docs-target/ | ||
*.iml | ||
*.swp | ||
*.fir | ||
|
1 change: 1 addition & 0 deletions
1
docs-target/src/main/resources/META-INF/services/mdoc.PostModifier
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
chisel3.docs.VerilogMdocModifier |
34 changes: 34 additions & 0 deletions
34
docs-target/src/main/scala/chisel3/docs/VerilogMdocModifier.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package chisel3.docs | ||
|
||
import java.nio.file.Files | ||
import java.nio.file.Paths | ||
import mdoc._ | ||
import scala.meta.inputs.Position | ||
|
||
/** Custom modifier for rendering Chisel-generated Verilog | ||
* | ||
* See chisel3/docs/README.md for use | ||
*/ | ||
class VerilogMdocModifier extends PostModifier { | ||
val name = "verilog" | ||
def process(ctx: PostModifierContext): String = { | ||
val result = | ||
ctx.variables.foldLeft(Option("")) { | ||
case (Some(acc), variable) if variable.staticType == "String" => | ||
Some(acc + variable.runtimeValue) | ||
case (Some(_), badVar) => | ||
ctx.reporter.error( | ||
badVar.pos, | ||
s"""type mismatch: | ||
|expected: String | ||
|received: ${badVar.runtimeValue}""".stripMargin | ||
) | ||
None | ||
case (None, _) => None | ||
} | ||
result match { | ||
case Some(content) => s"```verilog\n$content```" | ||
case None => "" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters