rems-project / sail

Sail architecture definition language
Other
599 stars 107 forks source link

JSON backend #732

Open wxrdnx opened 2 weeks ago

wxrdnx commented 2 weeks ago

I've implemented a simple JSON backend that can dump internal ASTs into JSON files. The goal is to convert the AST into a cross-language representation that it can be used by languages other than Ocaml. Would you guys be interested in adding this feature into your repo?

https://github.com/wxrdnx/sail/tree/json/src/sail_json_backend

Trolldemorted commented 2 weeks ago

Does it export the AST with all inferred types?

Related issue: https://github.com/rems-project/sail/issues/144

Alasdair commented 2 weeks ago

Yes, I think we would be interested.

We currently have a dependency on the Yojson library for all our JSON handling. It might be better to write a 'a ast -> Yojson.Safe.t function, then using Yojson's printing function to produce the final string. That function could also be parameterised by a 'a -> Yojson.Safe.t parameter for the annotations (or using a module to parameterise everything without passing an extra argument explicitly).

wxrdnx commented 2 weeks ago

No, it does not. For example, E_block would output something like

{
  ...
  "E_block": {
    ...
  }
}

So while most types are "preserved" in the keys, the Ocaml types are not preserved.

Does it export the AST with all inferred types?

Related issue: #144