add vector isa comparison to PDF
[libreriscv.git] / openpower / pandoc_img.py
1 #!/usr/bin/env python3
2
3 import os
4 import subprocess
5 from pandocfilters import (toJSONFilter, RawInline, Space, Str, walk, Image,
6 Link)
7
8 """
9 Pandoc filter for Markdown that converts most endnotes into
10 Pandoc's inline notes. If input notes had multiple paragraphs,
11 the paragraphs are joined by a space. But if an input note
12 had any blocks other than paragraphs, the note is left as is.
13 """
14
15 #inkscape -z sv/bridge_phy.svg --export-png=bridge.png
16 out = open("/tmp/log.txt", "w")
17
18 def query(k, v, f, meta):
19 global inlines
20 if k == 'BlockQuote':
21 inlines.append(v)
22 elif isinstance(v, list):
23 if inlines and k == 'Para':
24 inlines.append(Space())
25 inlines.extend(v)
26 return v
27
28 def inlinenotes(k, v, f, meta):
29 out.write("k v f meta %s %s %s %s\n" % \
30 (repr(k), repr(v), repr(f), repr(meta)))
31 global inlines
32 inlines = []
33 if k == u'Image' and f == 'latex':
34 imgname = v[2][0]
35 out.write(" image %s\n" % (imgname))
36 # HACK! works only relative to openpower directory!
37 if imgname.startswith("/"):
38 imgname = ".." + imgname
39 png = imgname.replace(".svg", ".png")
40 png = os.path.split(png)[1]
41 png = "tex_out/%s" % png
42 subprocess.run(["inkscape", "-z", "-C", imgname,
43 "--export-png=%s" % png],
44 stdout=subprocess.PIPE)
45 v[2][0] = png
46 return Image(*v)
47 if k == 'Str' and f == 'latex':
48 # link page
49 if not v.startswith("[["):
50 return
51 find_brack = v.find(']]')
52 if find_brack == -1:
53 return
54 link = v[2:find_brack]
55 out.write(" link %s\n" % link)
56 lookups = {'sv': 'Scalable Vectors for Power ISA',
57 'SV|sv': 'Scalable Vectors for Power ISA',
58 'sv/overview': 'Overview Chapter',
59 'sv/vector_isa_comparison': 'Vector ISA Comparison',
60 'sv/compliancy_levels': 'Compliancy Levels',
61 'sv/svp64': 'SVP64 Chapter',
62 'sv/sprs': 'SPRs',
63 'sv/normal': 'Arithmetic Mode',
64 'sv/ldst': 'Load/Store Mode',
65 'sv/cr_ops': 'Condition Register Fields Mode',
66 'sv/branches': 'Branch Mode',
67 'sv/setvl': 'setvl instruction',
68 'sv/svstep': 'svstep instruction',
69 'sv/remap': 'REMAP subsystem',
70 'sv/mv.swizzle': 'Swizzle Move',
71 'sv/mv.vec': 'Pack / Unpack',
72 'svp64/appendix': 'SVP64 Appendix',
73 'sv/svp64_quirks': 'SVP64 Quirks',
74 'openpower/isa/simplev': 'Simple-V pseudocode',
75 'opcode_regs_deduped': 'SVP64 Augmentation Table',
76 }
77 if link in lookups:
78 out.write(" found %s\n" % lookups[link])
79 return [Link(['', [], []],
80 [Str("{"+lookups[link]+"}")],
81 ['#%s' % link, '']), Str(v[find_brack+2:])]
82 if '|' in link:
83 link, ref = link.split("|")
84 return [Link(['', [], []],
85 [Str(link)],
86 [ref, '']), Str(v[find_brack+2:])]
87 if k == 'Link':
88 out.write(" link type %s\n" % \
89 (type(v[1][0])))
90
91
92 if __name__ == "__main__":
93 toJSONFilter(inlinenotes)