diff --git a/gallery/test.json b/gallery/test.json new file mode 100644 index 0000000..fc15e6d --- /dev/null +++ b/gallery/test.json @@ -0,0 +1,105 @@ +{ + "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" + } + } + } + } +} diff --git a/gallery/test.pdf b/gallery/test.pdf index b9d3795..cac2ecf 100644 Binary files a/gallery/test.pdf and b/gallery/test.pdf differ diff --git a/gallery/test.typ b/gallery/test.typ index 16b0d90..5cb1589 100644 --- a/gallery/test.typ +++ b/gallery/test.typ @@ -1,7 +1,16 @@ #import "../src/lib.typ": * -#let test = schema.load("/gallery/test.yaml") -#schema.render(test, config: config.blueprint( - full-page: true, - default-font-family: "Ubuntu Mono" +#let test-yaml = schema.load("/gallery/test.yaml") +#schema.render(test-yaml, config: config.config( + full-page: true +)) + +#let test-json = schema.load("/gallery/test.json") +#schema.render(test-json, config: config.blueprint( + full-page: true +)) + +#let test-xml = schema.load("/gallery/test.xml") +#schema.render(test-xml, config: config.dark( + full-page: true )) \ No newline at end of file diff --git a/gallery/test.xml b/gallery/test.xml new file mode 100644 index 0000000..ab92e22 --- /dev/null +++ b/gallery/test.xml @@ -0,0 +1,68 @@ + + + + + + + + pre / post indexing bit + + post, add offset after transfer + pre, add offset before transfer + + + + up / down bit + + down, subtract offset from base + up, addition offset to base + + + + byte / word bit + + transfer word quantity + transfer byte quantity + + + + write-back bit + + no write-back + write address into base + + + + load / store bit + + store to memory + load from memory + + + + base register + + + source / destination register + + + + offset is an immediate value + offset is a register + + + + + + unsigned number + + + + + shift applied to Rm + + + offset register + + + \ No newline at end of file diff --git a/src/schema.typ b/src/schema.typ index 8abd894..335b887 100644 --- a/src/schema.typ +++ b/src/schema.typ @@ -1,13 +1,10 @@ #import "config.typ" as conf #import "renderer.typ" #import "structure.typ" +#import "xml-loader.typ" #let valid-extensions = ("yaml", "json", "xml") -#let parse-xml(path) = { - panic("TODO") -} - #let parse-file(path) = { let ext = path.split(".").last() @@ -22,7 +19,7 @@ } else if ext == "json" { return json(path) } else if ext == "xml" { - return parse-xml(path) + return xml-loader.load(path) } } diff --git a/src/xml-loader.typ b/src/xml-loader.typ new file mode 100644 index 0000000..ca7213a --- /dev/null +++ b/src/xml-loader.typ @@ -0,0 +1,100 @@ +#let find(elmt, tag) = { + if not "children" in elmt { + return none + } + + return elmt.children.find(e => "tag" in e and e.tag == tag) +} + +#let find-all(elmt, tag) = { + if not "children" in elmt { + return () + } + + return elmt.children.filter(e => "tag" in e and e.tag == tag) +} + +#let parse-values(elmt) = { + let values = (:) + let case-elmts = find-all(elmt, "case") + + for case-elmt in case-elmts { + let val = case-elmt.attrs.value + let desc = case-elmt.children.first() + let struct = none + if "structure" in case-elmt.attrs { + struct = case-elmt.attrs.structure + } + + values.insert(val, + if struct != none { + ( + description: desc, + structure: struct + ) + } else { + desc + } + ) + } + + return values +} + +#let parse-range(elmt) = { + let range_ = ( + name: elmt.attrs.name + ) + let desc = none + if "children" in elmt { + desc = find(elmt, "description") + } + + if desc != none { + range_.insert("description", desc.children.first()) + } + + let values-elmt = find(elmt, "values") + if values-elmt != none { + range_.insert("values", parse-values(values-elmt)) + } + + if "depends-on" in elmt.attrs { + range_.insert("depends-on", elmt.attrs.depends-on) + } + + return range_ +} + +#let parse-structure(elmt) = { + let ranges = (:) + let range-elmts = elmt.children.filter(e => "tag" in e and e.tag == "range") + + for range-elmt in range-elmts { + let span = range-elmt.attrs.end + "-" + range-elmt.attrs.start + ranges.insert(span, parse-range(range-elmt)) + } + + return ( + bits: elmt.attrs.bits, + ranges: ranges + ) +} + +#let load(path) = { + let content = xml(path).first() + let struct-elmts = content.children.filter(e => "tag" in e and e.tag == "structure") + + let structures = (:) + + for struct-elmt in struct-elmts { + structures.insert( + struct-elmt.attrs.id, + parse-structure(struct-elmt) + ) + } + + return ( + structures: structures + ) +} \ No newline at end of file