vellvm / vellvm-legacy

33 stars 1 forks source link

LLVM parser in Vellvm? #10

Open wintersmind opened 9 years ago

wintersmind commented 9 years ago

This is also a question, not an issue (is there a better place to post questions?): I assume there is a Vellvm parser somewhere in the repo, to allow transformation of source code to some sort of AST representation. If so, could someone identify its location for me? Thanks, -chris

dgarbuzov commented 9 years ago

The AST is generated from the ott definitions in src/Vellvm/syntax_base.ott. If you have ott in your path, you can generate the Coq file with make src/Vellvm/syntax_base.v. It is somewhat simplified and out of date: it doesn't include e.g. metadata, aliases, exception handling instructions, etc.

There is, unfortunately, no parser in the repository. Previously, Vellvm used a (heavily) modified version of the LLVM OCaml bindings to generate an AST from the in-memory C++ representation of the IR. Due to changes in LLVM's interals, these will only compile against LLVM 3.0, which itself doesn't compile with relatively new versions of GCC or Clang!

I actually started writing an updated AST/parser without dependencies on the rest of the project based on the AST of the llvm-general library but haven't gotten very far. I can update this issue if that ever becomes usable.

wintersmind commented 9 years ago

Thanks for the info. So I guess the ott definitions allow Vellvm to recognize LLVM IR code written in the syntax defined e.g. in the POPL12 paper, so there isn't a practical need for a parser to experiment with non-trivial code examples.

dgarbuzov commented 9 years ago

I don't think Ott really helps us with parsing, though I haven't kept up with new versions.

Like I mentioned above, the OCaml bindings that were used to generate the AST from LLVM bitcode don't work with newer versions of LLVM. If we would like to, for example, test the Vellvm interpreter using recent versions of LLVM we really do need a replacement. Writing a standalone parser and new AST seems better from a maintenance and code reuse perspective than trying to update Vellvm's AST and the OCaml bindings.