f4pga / ideas

Random ideas and interesting ideas for things we hope to eventually do.
86 stars 9 forks source link

Rewrite the xml parser in vpr to be based on DTD and auto generated. #4

Open mithro opened 6 years ago

mithro commented 6 years ago

Currently the xml parser in vpr is hand coded.

It would be good to rip it out and replace it with a auto-generated xml parser based around a DTD which defines the file format.

Create a XML definition using DTD, XSD or Relax-NG -- unsure the best format... See;

Existing XML file formats in order of importance;

New XML file formats needing to be created;

The idea is eventually to auto-generate parser / code structures from the definitions; IE see --

mithro commented 6 years ago

XML formats include;

Laksen commented 6 years ago

I created schemas for the packed netlist and routing resource formats here: https://gist.github.com/Laksen/dc3fdf65a7eb6bb1186c46381215ac55

They don't match the examples 100% as the examples contain some undocumented values, but that should be easy to change

Gist
VPR XML Schemas
VPR XML Schemas
Laksen commented 6 years ago

I updated some types to use xs:double instead of xs:decimal to allow scientific notation. Also a preliminary version of the architecture description has been added. There might be a few bits missing, but with the files I could find they almost passed validation.

There were some inconsistencies like default_* names in <fc> attributes where I chose the values from the documentation

https://gist.github.com/Laksen/cf67f1103e5c539bb44cd183d617aee8

Gist
fpga_architecture.xsd
GitHub is where people build software. More than 28 million people use GitHub to discover, fork, and contribute to over 85 million projects.
mithro commented 6 years ago

@Laksen this is awesome! Do you want to send them as a pull request in the https://github.com/SymbiFlow/symbiflow-arch-defs repo? The common/xml directory would be the right place.

GitHub
SymbiFlow/symbiflow-arch-defs
symbiflow-arch-defs - FOSS architecture definitions of FPGA hardware useful for doing PnR device generation.
mithro commented 6 years ago

@Laksen has added a schema for the existing XML formats in the pull request here -> https://github.com/SymbiFlow/symbiflow-arch-defs/pull/195 - Thank you so much.

The next steps would be; a) Figuring out the best way to generate Python and C++ code from the schemas. b) Designing a new XML format (and appropriate schema) for the placement and route formats from VtR. c) Using the XML schema's for automatic validation of the files.

mithro commented 6 years ago

https://www.codesynthesis.com/products/xsd/ looks pretty good but is under a GPL license and we really want to keep things open. The alternative is probably to follow an example shown at this page https://blind.guru/bmmlcxx.html and use Python + Jinja2 templates to create C++ code.

CodeSynthesis XSD - XML Data Binding for C++
W3C XML Schema to C++ data binding compiler is an open-source, cross-platform XML Data Binding implementation for C++
Generating C++ from a DTD with Jinja2 and lxml
mithro commented 6 years ago

The best example I have found is https://github.com/mlang/xsdcxx-musicxml

GitHub
mlang/xsdcxx-musicxml
Contribute to mlang/xsdcxx-musicxml development by creating an account on GitHub.