Compare commits

..

No commits in common. "9f8bf0252223370e65e7e3d8182380e53e6e22b5" and "49db07b9ee1b76066ebc5805d458e7b3f8f42ac1" have entirely different histories.

15 changed files with 33 additions and 237 deletions

View File

@ -2,15 +2,14 @@
/// This function returns a dictionary of structures
///
/// Supported formats: #schema.valid-extensions.map(e => raw("." + e)).join(", ")
/// - path-or-schema (str, raw, dictionary): If it is a string, defines the path to load. \
/// If it is a raw block, its content is directly parsed (the block's language will define the format to use) \
/// If it is a dictionary, it directly defines the schema structure
/// - path-or-schema (str, raw): If it is a string, defines the path to load. \
/// If it is a raw block, its content is directly parsed (the block's language will define the format to use)
/// -> dictionary
#let load(path-or-schema) = {}
/// Renders the given schema
/// This functions
/// - schema (dictionary): A schema dictionary, as returned by #doc-ref("schema.load")
/// - structures (dictionary): A schema dictionary, as returned by #doc-ref("schema.load")
/// - config (auto, dictionary): The configuration parameters, as returned by #doc-ref("config.config")
/// - width (ratio, length): The width of the generated figure
#let render(schema, config: auto, width: 100%) = {}
#let render(structures, config: auto, width: 100%) = {}

View File

@ -1,40 +0,0 @@
#!/bin/bash
PDFS=false
while getopts "p" flag
do
case "${flag}" in
p) PDFS=true;;
esac
done
echo "Generating gallery images"
set -- ./gallery/example*.typ
cnt="$#"
i=1
for f
do
f2="${f/typ/png}"
echo "($i/$cnt) $f -> $f2"
typst c --root ./ "$f" "$f2"
i=$((i+1))
done
if [ "$PDFS" = true ]
then
echo
echo "Generating gallery PDFs"
set -- ./gallery/*.typ
cnt="$#"
i=1
for f
do
f2="${f/typ/pdf}"
echo "($i/$cnt) $f -> $f2"
typst c --root ./ "$f" "$f2"
i=$((i+1))
done
fi

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 376 KiB

After

Width:  |  Height:  |  Size: 378 KiB

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 302 KiB

After

Width:  |  Height:  |  Size: 303 KiB

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 487 KiB

View File

@ -1,23 +0,0 @@
#import "../src/lib.typ": schema, config
#let example = schema.load("/gallery/example1.yaml")
//#schema.render(example)
= Chapter 1
#lorem(50)
= Chapter 2
#lorem(50)
== Section 2.1
#lorem(20)
#figure(
schema.render(example, config: config.config(all-bit-i: false)),
caption: "Test schema"
)
#lorem(20)
= Chapter 3

View File

@ -1,12 +0,0 @@
structures:
main:
bits: 32
ranges:
31-24:
name: op
23-16:
name: r1
15-8:
name: r2
7-0:
name: r3

Binary file not shown.

View File

@ -25,115 +25,4 @@ structures:
```)
#schema.render(test-raw, config: config.config(
full-page: true
))
#let test-typ = schema.load((
structures: (
main: (
bits: 32,
ranges: (
"31-28": (name: "cond"),
"27": (name: "0"),
"26": (name: "1"),
"25": (name: "I"),
"24": (
name: "P",
description: "pre / post indexing bit",
values: (
"0": "post, add offset after transfer",
"1": "pre, add offset before transfer"
)
),
"23": (
name: "U",
description: "up / down bit",
values: (
"0": "down, subtract offset from base",
"1": "up, addition offset to base"
)
),
"22": (
name: "B",
description: "byte / word bit",
values: (
"0": "transfer word quantity",
"1": "transfer byte quantity"
)
),
"21": (
name: "W",
description: "write-back bit",
values: (
"0": "no write-back",
"1": "write address into base"
)
),
"20": (
name: "L",
description: "load / store bit",
values: (
"0": "store to memory",
"1": "load from memory"
)
),
"19-16": (
name: "Rn",
description: "base register"
),
"15-12": (
name: "Rd",
description: "source / destination register"
),
"11-0": (
name: "offset",
depends-on: "25",
values: (
"0": (
description: "offset is an immediate value",
structure: "immediateOffset"
),
"1": (
description: "offset is a register",
structure: "registerOffset"
)
)
)
)
),
immediateOffset: (
bits: 12,
ranges: (
"11-0": (
name: "12-bit immediate offset",
description: "unsigned number"
)
)
),
registerOffset: (
bits: 12,
ranges: (
"11-4": (
name: "shift",
description: "shift applied to Rm"
),
"3-0": (
name: "Rm",
description: "offset register"
)
)
)
),
colors: (
main: (
"31-28": red,
"11-4": green
),
registerOffset: (
"11-4": rgb(240, 140, 80)
)
)
))
#schema.render(test-typ, config: config.config(
full-page: true
))

Binary file not shown.

View File

@ -32,12 +32,20 @@
if italic {
text-params.insert("style", "italic")
}
let content-params = (:)
if fill != none {
content-params.insert("fill", fill)
content-params.insert("frame", "rect")
content-params.insert("padding", (4pt, 0pt))
}
draw.content(
(x, -y),
text(txt, fill: color, size: size, ..text-params),
anchor: anchor,
stroke: none
stroke: none,
..content-params
)
}
@ -245,7 +253,7 @@
#let draw-dependency(
draw-struct, config,
struct, schema, bits-x, bits-y, range_, desc-x, desc-y
struct, structures, bits-x, bits-y, range_, desc-x, desc-y
) = {
let shapes = ()
@ -293,7 +301,7 @@
val-struct = structure.load("", val-struct)
let shapes_
(shapes_, ..) = draw-struct(config, val-struct, schema, ox: depend-start-x, oy: desc-y)
(shapes_, ..) = draw-struct(config, val-struct, structures, ox: depend-start-x, oy: desc-y)
shapes += shapes_
let y = desc-y + bit-h * 1.5
@ -324,7 +332,7 @@
prev-range-y = prev-depend-y
depend-range.last-value-y = prev-depend-y
(shapes_, desc-y) = draw-struct(config, schema.structures.at(data.structure), schema, ox: start-x, oy: desc-y)
(shapes_, desc-y) = draw-struct(config, structures.at(data.structure), structures, ox: start-x, oy: desc-y)
shapes += shapes_
}
@ -333,9 +341,8 @@
return (shapes, desc-x, desc-y, struct)
}
#let draw-structure(config, struct, schema, ox: 0, oy: 0) = {
#let draw-structure(config, struct, structures, ox: 0, oy: 0) = {
let shapes
let colors = schema.at("colors", default: (:))
let bg-col = config.background
let txt-col = config.text-color
let border-col = config.border-color
@ -345,30 +352,6 @@
let (bits-x, bits-y) = (ox, oy + bit-h)
let bits-width = struct.bits * bit-w
let start-bit = struct.start
let bit-colors = (:)
for i in range(struct.bits) {
bit-colors.insert(str(i), bg-col)
}
if struct.name in colors {
for (s, col) in colors.at(struct.name) {
let (start, end) = rng.parse-span(s)
for i in range(start, end + 1) {
let real-i = struct.bits - i - 1 + start-bit
bit-colors.insert(str(real-i), col)
}
}
}
let range-boundaries = ()
for r in struct.ranges.values() {
let i = struct.bits - r.end - 1 + start-bit
range-boundaries.push(i)
}
// Draw colors
for i in range(struct.bits) {
let bit-x = ox + i * bit-w
shapes += draw-rect(bit-colors.at(str(i)), bit-x, bits-y, bit-w+1, bit-h)
}
// Draw rectangle around structure
shapes += draw-rect(border-col, bits-x, bits-y, bits-width, bit-h, thickness: 2)
@ -396,9 +379,8 @@
}
// Draw separator
if i != 0 and not i in range-boundaries {
shapes += draw-line(border-col, (bit-x, bits-y), (bit-x, bits-y + bit-h * 0.2))
shapes += draw-line(border-col, (bit-x, bits-y + bit-h * 0.8), (bit-x, bits-y + bit-h))
if i != 0 {
shapes += draw-line(border-col, (bit-x, bits-y), (bit-x, bits-y + bit-h))
}
}
@ -431,7 +413,13 @@
let name-x = start-x + width / 2
let name-y = bits-y + bit-h / 2
shapes += draw-line(border-col, (start-x, bits-y), (start-x, bits-y + bit-h))
shapes += draw-rect(
bg-col,
start-x + bit-w / 2,
name-y - bit-h * 0.3,
width - bit-w,
bit-h * 0.6
)
shapes += draw-text(range_.name, txt-col, name-x, name-y, fill: bg-col)
if range_.description != "" {
@ -449,7 +437,7 @@
let shapes_
(shapes_, desc-x, desc-y, struct) = draw-dependency(
draw-structure, config,
struct, schema, bits-x, bits-y, range_, desc-x, desc-y,
struct, structures, bits-x, bits-y, range_, desc-x, desc-y
)
shapes += shapes_
}
@ -458,13 +446,13 @@
return (shapes, desc-y)
}
#let render(config, schema, width: 100%) = {
#let render(config, structures, width: 100%) = {
set text(
font: config.default-font-family,
size: config.default-font-size
)
let main = schema.structures.main
let main = structures.main
let ox = config.margins.at(3)
if config.left-labels {
ox = config.width - ox - main.bits * config.bit-width
@ -485,7 +473,7 @@
let cnvs = canvas(length: 1pt, background: config.background, {
let (shapes, _) = draw-structure(
config, main, schema,
config, main, structures,
ox: ox,
oy: config.margins.at(0)
)

View File

@ -44,8 +44,6 @@
#let load(path-or-schema) = {
let schema = if type(path-or-schema) == str {
parse-file(path-or-schema)
} else if type(path-or-schema) == dictionary {
path-or-schema
} else {
parse-raw(path-or-schema)
}
@ -55,16 +53,13 @@
id = str(id)
structures.insert(id, structure.load(id, data))
}
return (
structures: structures,
colors: schema.at("colors", default: (:))
)
return structures
}
#let render(schema, width: 100%, config: auto) = {
#let render(structures, width: 100%, config: auto) = {
if config == auto {
config = conf.config()
}
let renderer_ = renderer.make(config)
(renderer_.render)(schema, width: width)
(renderer_.render)(structures, width: width)
}