Skip to content

Commit 6e2b745

Browse files
authored
Merge pull request #225 from DFiantHDL/docsupdate7
Docsupdate7
2 parents 374bf92 + afea8b8 commit 6e2b745

File tree

10 files changed

+90
-68
lines changed

10 files changed

+90
-68
lines changed

.github/workflows/dfdocs.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,14 @@ jobs:
3535
- name: Setup Python
3636
uses: actions/setup-python@v4
3737
with:
38-
python-version: '3.x'
38+
python-version: '3.x'
39+
- name: Install Node.js
40+
uses: actions/setup-node@v3
41+
with:
42+
node-version: '22'
43+
- name: Install npm packages
44+
run: |
45+
npm install elkjs @svgdotjs/svg.js svgdom
3946
- name: Build
4047
run: |
4148
python -m pip install --upgrade pip

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,6 @@ sandbox/
2828
.vscode/
2929
project/metals.sbt
3030
**/__pycache__/**
31+
node_modules/
32+
package.json
33+
package-lock.json

compiler/stages/src/main/scala/dfhdl/compiler/stages/vhdl/VHDLOwnerPrinter.scala

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,12 @@ protected trait VHDLOwnerPrinter extends AbstractOwnerPrinter:
3636
}
3737
.mkString(";\n")
3838
val designParamList = designMembers.collect { case param: DesignParam =>
39-
val defaultValue = if (design.isTop) s" := ${param.dfValRef.refCodeString}" else ""
39+
val defaultValue =
40+
if (design.isTop) s" := ${param.dfValRef.refCodeString}"
41+
else
42+
param.defaultRef.get match
43+
case DFMember.Empty => ""
44+
case _ => s" := ${param.defaultRef.refCodeString}"
4045
s"${param.getName} : ${printer.csDFType(param.dfType)}$defaultValue"
4146
}
4247
val genericBlock =

compiler/stages/src/test/scala/StagesSpec/PrintVHDLCodeSpec.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,12 @@ class PrintVHDLCodeSpec extends StageSpec:
113113
)
114114
}
115115
test("Basic hierarchy design with parameters") {
116-
class ID(val width: Int <> CONST) extends DFDesign:
116+
class ID(val width: Int <> CONST = 7) extends DFDesign:
117117
val x = SInt(width) <> IN
118118
val y = SInt(width) <> OUT
119119
y := x
120120

121-
class IDTop(val width: Int <> CONST) extends DFDesign:
121+
class IDTop(val width: Int <> CONST = 9) extends DFDesign:
122122
val x = SInt(width) <> IN
123123
val y = SInt(width) <> OUT
124124
val id1 = ID(width)
@@ -137,7 +137,7 @@ class PrintVHDLCodeSpec extends StageSpec:
137137
|
138138
|entity ID is
139139
|generic (
140-
| width : integer
140+
| width : integer := 7
141141
|);
142142
|port (
143143
| x : in signed(width - 1 downto 0);

docs/css/d2.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
div svg * {
1+
div.d2 svg * {
22
font-family: var(--md-code-font-family) !important;
33
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
//> using scala 3.6.3
2-
//> using dep io.github.dfianthdl::dfhdl::0.9.1
3-
//> using plugin io.github.dfianthdl:::dfhdl-plugin:0.9.1
2+
//> using dep io.github.dfianthdl::dfhdl::0.9.2
3+
//> using plugin io.github.dfianthdl:::dfhdl-plugin:0.9.2
44
//> using option -deprecation -language:implicitConversions

docs/getting-started/hello-world/scala-single-file/Counter8.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//> using scala 3.6.3
2-
//> using dep io.github.dfianthdl::dfhdl::0.9.1
3-
//> using plugin io.github.dfianthdl:::dfhdl-plugin:0.9.1
2+
//> using dep io.github.dfianthdl::dfhdl::0.9.2
3+
//> using plugin io.github.dfianthdl:::dfhdl-plugin:0.9.2
44
//> using option -deprecation -language:implicitConversions
55

66
import dfhdl.* //import all the DFHDL goodness

docs/include/hdelk_hook.py

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,40 @@
11
import re
2-
from pyhocon import ConfigFactory
32
import json
3+
import subprocess
4+
import tempfile
5+
import os
6+
from pyhocon import ConfigFactory
7+
8+
CACHE_DIR = os.path.join('.cache', 'plugin', 'hdelk')
49

510
def replace_hdelk(match):
611
width = match.group(1) or "100%" # Default to 100% if width is not specified
712
diagram_json = json.dumps(ConfigFactory.parse_string(match.group(2)), indent=2)
813
diagram_id = f"hdelk-diagram-{hash(diagram_json)}" # Generate a unique ID
14+
svg_file_path = os.path.join(CACHE_DIR, f"{diagram_id}.svg")
15+
16+
# Ensure the cache directory exists
17+
os.makedirs(CACHE_DIR, exist_ok=True)
18+
19+
# Check if the cached SVG file already exists
20+
if not os.path.exists(svg_file_path):
21+
# Create a temporary file for the JSON input
22+
with tempfile.NamedTemporaryFile(mode="w", delete=False, suffix='.json') as temp_json_file:
23+
temp_json_file.write(diagram_json)
24+
temp_json_file_path = temp_json_file.name
25+
26+
# Run the Node.js script to generate the SVG
27+
subprocess.run(['node', 'docs/javascripts/hdelk.js', temp_json_file_path, svg_file_path], check=True)
28+
os.remove(temp_json_file_path)
29+
30+
# Read the generated SVG content
31+
with open(svg_file_path, 'r') as f:
32+
svg_content = f.read()
33+
934
return f"""
10-
<div id="{diagram_id}" class="hdelk-diagram" style="width: {width};"></div>
11-
<script type="text/javascript">
12-
document.addEventListener("DOMContentLoaded", function() {{
13-
var diagram = {diagram_json};
14-
hdelk.layout(diagram, "{diagram_id}");
15-
}});
16-
</script>
35+
<div id="{diagram_id}" class="hdelk-diagram" style="width: {width};">
36+
{svg_content}
37+
</div>
1738
"""
1839

1940
def on_page_markdown(markdown, **kwargs):

docs/javascripts/hdelk.js

Lines changed: 35 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
1-
var hdelk = (function(){
1+
const fs = require('fs');
2+
const { createSVGWindow } = require('svgdom');
3+
const { SVG, registerWindow } = require('@svgdotjs/svg.js');
4+
const ELK = require('elkjs/lib/elk.bundled.js');
5+
6+
const window = createSVGWindow();
7+
const document = window.document;
8+
registerWindow(window, document);
9+
10+
var hdelk = (function() {
211

312
/**
413
* HDElkJS Style Section
@@ -57,55 +66,29 @@ var hdelk = (function(){
5766
/**
5867
* Creates an SVG diagram from a JSON description.
5968
* @param {object} graph
60-
* @param {string} divname
69+
* @param {string} outputFilePath
6170
*/
62-
var layout = function( graph, divname ) {
63-
const elk = new ELK({
64-
})
71+
var layout = async function(graph, outputFilePath) {
72+
const elk = new ELK();
6573

6674
// create a dummy drawing just to get text sizes
67-
var drawDummy = SVG().addTo('#' + divname).size(0, 0);
75+
var drawDummy = SVG(document.documentElement).size(0, 0);
6876

69-
transformNode( drawDummy, graph );
77+
transformNode(drawDummy, graph);
7078

7179
drawDummy.clear();
7280

73-
var mp = document.getElementById( divname + "_message" );
74-
if ( mp ) {
75-
mp.style.display = "none";
76-
}
77-
7881
try {
79-
var ep = elk.layout(graph);
80-
81-
ep.then(function(g) {
82-
var dp = document.getElementById( divname + "_preprocessed" );
83-
if ( dp )
84-
dp.innerHTML = "<pre style='font-size:10px'>" + JSON.stringify(graph, null, " ") + "</pre>";
82+
var g = await elk.layout(graph);
8583

86-
var d = document.getElementById( divname + "_elk" );
87-
if ( d )
88-
d.innerHTML = "<pre style='font-size:8px'>" + JSON.stringify(g, null, " ") + "</pre>";
84+
var svgContent = diagram(g);
8985

90-
diagram( divname, g );
91-
92-
})
93-
94-
ep.catch( function(err){
95-
var dp = document.getElementById( divname );
96-
dp.innerHTML = "";
97-
var mp = document.getElementById( divname + "_message" );
98-
if ( mp ) {
99-
mp.innerHTML = err;
100-
mp.style.display = "block";
101-
}
102-
})
103-
} catch( err ) {
104-
var dp = document.getElementById( divname );
105-
dp.innerHTML = "";
106-
console.log( err );
86+
fs.writeFileSync(outputFilePath, svgContent);
87+
// console.log(`SVG file saved to ${outputFilePath}`);
88+
} catch (err) {
89+
console.error(err);
10790
}
108-
}
91+
};
10992

11093
/**
11194
* Takes the child object and recursively transforms sub-objects into a form that Elk.JS can use
@@ -462,21 +445,18 @@ var hdelk = (function(){
462445

463446
/**
464447
* Takes the output from ElkJS, renders it into SVG using SVG.js and returns the result
465-
* @param {string} div_id
466448
* @param {elkObject} diagram_layout
467449
* @returns {string} svg
468450
*/
469-
var diagram = function( div_id, diagram_layout ) {
470-
471-
var diagramElement = document.getElementById(div_id);
472-
diagramElement.innerHTML = "";
451+
var diagram = function(diagram_layout) {
452+
var draw = SVG(document.documentElement)
453+
.viewbox(0, 0, diagram_layout.width, diagram_layout.height)
454+
.size(diagram_layout.width, diagram_layout.height);
473455

474-
var draw = SVG().addTo('#' + div_id)
475-
.viewbox(0, 0, diagram_layout.width, diagram_layout.height)
476-
.size('100%', '100%');
456+
node(draw, diagram_layout, 0, 0);
477457

478-
node( draw, diagram_layout, 0, 0 );
479-
}
458+
return draw.svg();
459+
};
480460

481461
var node = function( draw, child, offsetX, offsetY ) {
482462
var group = draw.group();
@@ -691,3 +671,9 @@ var hdelk = (function(){
691671
};
692672
})();
693673

674+
const inputFilePath = process.argv[2];
675+
const outputFilePath = process.argv[3];
676+
677+
const graph = JSON.parse(fs.readFileSync(inputFilePath, 'utf8'));
678+
679+
hdelk.layout(graph, outputFilePath);

docs/javascripts/scastie.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
let dfhdlVersion = "0.9.1";
1+
let dfhdlVersion = "0.9.2";
22
let scalaVersion = "3.6.3";
33

44
let sbtConfig = `

0 commit comments

Comments
 (0)