rems-project / sail

Sail architecture definition language
Other
617 stars 112 forks source link

Sail -> JSON export #144

Open martinberger opened 3 years ago

martinberger commented 3 years ago

Are there any plans to add a Sail to JSON exporter to the official Sail distribution? (A JSON exporter seems to be a popular feature request and not particularly difficult to write, if it became official code duplication would be avoided.)

PeterSewell commented 3 years ago

No plans at present. As far as we can see, most usages of such would be better done with OCaml code, as then one can see the native datastructures and use the existing code to manipulate them. A naive JSON export would be easy (albeit tedious) to write, but it would either have to massively duplicate type environment information or erase it, which would only be satisfactory for very lightweight uses of the spec. Did you have some particular usage of a JSON export in mind?

Peter

On Tue, 3 Aug 2021 at 13:00, Martin Berger @.***> wrote:

Are there any plans to add a Sail to JSON exporter to the official Sail distribution? (A JSON exporter seems to be a popular feature request and not particularly difficult to write, if it became official code duplication would be avoided.)

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/rems-project/sail/issues/144, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABFMZZX76URZRDD6LGGJU2LT27K2HANCNFSM5BOVZ4OA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&utm_campaign=notification-email .

martinberger commented 3 years ago

I agree that writing OCaml is the best way of dealing with Sail code, but JSON is widely known and has already many existing tools. JSON export has been the most frequently requested feature here.

There are many lightweight uses of a Sail spec that are rather useful in practise, like extracting register definitions or the assembly syntax of instructions, which programmers without OCaml knowledge might need to do.

PeterSewell commented 3 years ago

On Wed, 4 Aug 2021 at 20:26, Martin Berger @.***> wrote:

I agree that writing OCaml is the best way of dealing with Sail code, but JSON is widely known and has already many existing tools. JSON export has been the most frequently requested feature here.

y, but keeping it working and fixing bugs is more important still :-)

There are many lightweight uses of a Sail spec that are rather useful in practise, like extracting register definitions or the assembly syntax of instructions, which programmers without OCaml knowledge might need to do.

Sure. Well, it wouldn't be hard for someone to hand-write something from the AST, though one would need thought to get the type structure right - and without that, only very lightweight uses are possible. We wouldn't want anyone trying to recreate the type inference in another language; that'd be certain to go wrong.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/rems-project/sail/issues/144#issuecomment-892914413, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABFMZZWPUSZC6E624SWL7YTT3GH5NANCNFSM5BOVZ4OA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&utm_campaign=notification-email .

martinberger commented 3 years ago

I agree, but lightweight uses help beginners a great deal. CSV and JSON exporters have been written already, probably multiple times.

buggfg commented 2 years ago

Excuse me, I want to extract information such as registers and instructions from the sail file, what do I need to do? please

leonardopsantos commented 7 months ago

Exporting to a more universal language than SAIL would be great. From what I understand, SAIL is written in the OTT grammar. If SAIL's grammar was in BNF, at least I could use something like ANTLR to eat SAIL and generate Python. The next best thing would be exporting SAIL to JSON. At least for me, learning OcamML isn't really an option.

My use cases for ingesting SAIL in Python would be to:

Alasdair commented 7 months ago

Once you get past the weird syntax, OCaml is actually a really nice well-designed language.

Exporting to JSON would be fairly easy for anyone who had the time and wherewithal to do it, but working with a JSON dump of the syntax tree would be a pretty miserable experience as JSON just isn't a natural representation for that kind of data. Most of the engineering effort would be writing libraries to consume that JSON and turn it back into a usable form. You'd also loose some of the most valuable information - the OCaml API works with type-annotated structures, and you'd need a clever encoding to preserve that in JSON, assuming it would even be possible (internally it relies on sharing information between the annotations, making the actual internal structure graph-like).

PeterSewell commented 7 months ago

On Thu, 4 Apr 2024 at 20:37, Leonardo Pereira Santos < @.***> wrote:

Exporting to a more universal language than SAIL would be great. From what I understand, SAIL is written in the OTT grammar https://github.com/ott-lang/ott. If SAIL's grammar was in BNF, at least I could use something like ANTLR https://github.com/antlr/antlr4 to eat SAIL and generate Python. The next best thing would be exporting SAIL to JSON. At least for me, learning OcamML isn't really an option.

What do you want to do with such Python? The Ott grammar for Sail is essentially just a specific version of BNF, but there's a lot of machinery in the Sail implementation for generating code in various targets, and that's nontrivial - just having the syntax in Python might not help you.

Peter

— Reply to this email directly, view it on GitHub https://github.com/rems-project/sail/issues/144#issuecomment-2038066390, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABFMZZTLR7TWXOM46Z5NT6LY3WTY5AVCNFSM5BOVZ4OKU5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TEMBTHAYDMNRTHEYA . You are receiving this because you commented.Message ID: @.***>

leonardopsantos commented 7 months ago

Once you get past the weird syntax, OCaml is actually a really nice well-designed language.

I don't doubt that for a second.

I work for a company that has adopted RISC-V in our ASICs. We currently have very little automation in terms of design verification. We also rolled out our own RISC-V C++ simulator (long story). I'm trying to evaluate whether using SAIL would benefit us. Having someone learn OCaml to use SAIL would probably be a non-starter due to the time it takes.

What do you want to do with such Python

My use cases for ingesting SAIL in Python would be to:

I'm sure if there was a Python backend, people way more clever than me would find all sorts of interesting uses.

but there's a lot of machinery in the Sail implementation for generating code in various targets, and that's nontrivial

This is another reason for asking for a back end in a more popular language than OCaml.

rjiejie commented 3 months ago

Excuse me, I want to extract information such as registers and instructions from the sail file, what do I need to do? please

@PeterSewell I have same question about how to parse registers or instructions from sail file or AST, I use sail option -ddump_tc_ast to get AST but it seems to be difficult to extract information :( BTW, I want to extract information in C/C++ project. Any suggestions ?