-
|
Hello, I am working on a RISC-V project in a small team and I have been tasked with trying to figure out how to generate an AST from the RISC-V sail files in this repo. Admittedly I am still new to SAIL and learning about what an AST is but I have been told that I should generate an AST file similar to the one in this repo by Derek Tu. I believe the AST file and repo by Derek Tu may have came from this sail-risv repo so I figured this would be a good place to ask. My question is how do I generate a raw AST file using the SAIL compiler? So far I what I have done is dig through the SAIL documentation and found the flag This command ran successfully but the generated file seems to simply be a large concatenated version of all the sail files in Is this something that can be done by the SAIL compiler or am I misunderstanding what an AST should be? Thank you. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 8 replies
-
|
There's a little bit of documentation for There's also There's also I couldn't actually find anything in Sail that dumps the AST in any structured format, so I'm not sure how they generated that file. It's definitely possible to output the AST in any format you want if you write your own printer for it, but that's quite a lot of work. @Alasdair would know for sure. What do you want the AST for just out of interest? |
Beta Was this translation helpful? Give feedback.
-
|
The easiest way to do this is to use some OCaml. I thought it would be easier than it actually is, so I just made a PR to the Sail repository to make it a bit easier, see: rems-project/sail#1497 Once I get that merged, something you can try is to open the Sail library, then: To disable warnings. That's not strictly necessary, but will cut down on the noise. Finally, you can run: to load the sail-riscv model (Changing the directory paths depending on how/where you checked out the repositories). This invokes the compiler frontend to figure out all the module dependencies, load all the source, and parse and type-check everything. From there you can interactively play with the In some ways, I suspect it is easier than you might think, but you will likely run into the issue that we don't have much in the way of documentation so it might be tough going to figure stuff out. |
Beta Was this translation helpful? Give feedback.
-
|
As @Timmmm mentioned, I was working on a Sail-to-JSON project with the goal of providing the essential data in the RISC-V in an easily digested format to facilitate downstream uses, including documentation, but also ecosystem projects like toolchains. For me, at least, the requirements of (1) understanding Sail, (2) understanding the structure of the AST produced by the Sail parser, and (3) having to learn and use OCaml to do it all, were a pretty high bar to clear, especially if you wanted to build an efficient team quickly to do the work. And, there are what I would consider essential pieces of information missing from Sail, and resistance to including them. I've shifted my efforts from using Sail as the upstream source of information to the RISC-V Unified Database. It's not "perfect", nor complete (yet, but neither is Sail), but it does offer the data as a collection of easily-parsed YAML files. Within the project, there are already backends that use the YAML to generate downstream-consumable artifacts like the "encoding.h" file from the riscv-opcodes project (used in several projects), LLVM content, SystemVerilog content, Go content, a RISC-V simulator, etc.. There is a mentorship underway to add new backends to benefit other projects including (hopefully) more LLVM content, V8, riscv-isa-sim, and hopefully more. I'm happy to discuss further if you have interest. |
Beta Was this translation helpful? Give feedback.
Yup, this project is part of the RISC-V Mentorship Program. It seems that the next thing I should try is to explore the SAIL-to-JSON project and see how the extracted information can be used for binutils.
Also just to wrap up this thread, the TLDR for my original question is that the original SAIL compiler does not generate an AST like the "raw" AST found in the Derek Tu's repo. However there may be some alternative for extracting the required information as mentioned above.
If I have any further questions I'll be sure to ask them here, in another thread, or privately.