Skip to content

Commit 70b9359

Browse files
authored
Merge pull request #98 from riscv-software-src/ruby_doc
Split YARD docs for idl/arch_def, add prose
2 parents 964567b + c7d9303 commit 70b9359

File tree

6 files changed

+105
-4
lines changed

6 files changed

+105
-4
lines changed

.yardopts

Lines changed: 0 additions & 1 deletion
This file was deleted.

README.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,5 +107,5 @@ Quick start:
107107
== More info
108108

109109
* xref:arch/README.adoc[Architecture specification format]
110-
* xref:arch/README.adoc[Documentation for the generator tool and IDL]
111-
** https://riscv-software-src.github.io/riscv-unified-db/ruby/index.html[YARD docs for the generator tool and IDL]
110+
* xref:_site/ruby/arch_def/index.html[Ruby database object model documentation]
111+
* xref:_site/ruby/idl/index.html[IDL Compiler documentation]

Rakefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ namespace :gen do
3131
desc "Generate documentation for the ruby tooling"
3232
task tool_doc: "#{$root}/.stamps/dev_gems" do
3333
Dir.chdir($root) do
34-
sh "bundle exec yard doc"
34+
sh "bundle exec yard doc --yardopts arch_def.yardopts"
35+
sh "bundle exec yard doc --yardopts idl.yardopts"
3536
end
3637
end
3738
end

arch_def.yardopts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-o _site/ruby/arch_def --no-private --embed-mixins --readme 'lib/DB_MODEL.README.adoc' 'lib/arch_obj_models/*.rb' lib/arch_def.rb

idl.yardopts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-o _site/ruby/idl --title 'IDL Compiler' --no-private --embed-mixins 'lib/idl/*.rb' lib/idl.rb

lib/DB_MODEL.README.adoc

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
= Ruby interface to database
2+
3+
A Ruby interface for https://github.com/riscv-software-src/riscv-unified-db[`riscv-unified-db`] is located in the `lib` directory. It can be used to query the database in the context of a configuration through a set of object models.
4+
5+
The main class is `ArchDef`, which represents all of the database information plus any known configuration parameters. An `ArchDef` must be initialized from a configuration in the `cfg` directory. Two configurations are provided -- _32 and _64 -- that represent generic RV32/RV64 machines (_i.e._, the only known configuration parameter is `MXLEN`).
6+
7+
== Configuration files
8+
9+
A configuration consists of a folder under `cfgs`. Inside that folder, there are three required files and one optional directory.
10+
11+
=== Required configuration files
12+
13+
`cfg.yaml`::
14+
A YAML object (hash) that currently contains only one field `type`. `type` can be one of:
15+
16+
* "partially configured": The configuration has some parameters and/or implemented extensions known, but others are not known. Examples of a _partially configured_ configuration are the generic _32/_64 configs and a profile (which has some known/mandatory extensions, but also many unknown/optional extensions).
17+
* "fully configured": The configuration exhaustively lists a set of implmented extensions and parameters. An example of a _fully configured_ configuration is the `generic_rv64` example, which represents a theoritical implementation of RV64. In a _fully configured_ configuration, any extension that isn't known to be implemented is treated as unimplmented, and will be pruned out of the database for certain operations.
18+
19+
`implemented_exts.yaml`::
20+
21+
A YAML file with an array of known implemented extensions along with their versions.
22+
23+
.Example `implemented_exts.yaml`
24+
[source,yaml]
25+
----
26+
implemented_extensions:
27+
- [A, "2.1.0"]
28+
- [B, "1.0.0"]
29+
- [C, "2.2.0"]
30+
- [D, "2.2.0"]
31+
- [F, "2.2.0"]
32+
# ...
33+
----
34+
35+
`params.yaml`::
36+
37+
A YAML file with values for parameters defined by the implemented extensions. Params must be exhuastive for a _fully configured_ configuration. Params will be schema checked using information stored in the database.
38+
39+
.Example `params.yaml`
40+
[source,yaml]
41+
----
42+
params:
43+
MISALIGNED_LDST: true
44+
MISALIGNED_LDST_EXCEPTION_PRIORITY: high
45+
MAX_MISALIGNED_ATOMICITY_GRANULE_SIZE: 0
46+
MISALIGNED_SPLIT_STRATEGY: by_byte
47+
# ...
48+
----
49+
50+
=== Optional overlay
51+
52+
A configuration can customize the standard RISC-V specification by providing an `arch_overlay` directory. This can be used to, for example, describe a custom extension or to create custom behavior of a standard instructions.
53+
54+
The `arch_overlay` directory is treated as an overlay on the standard `arch` directory. The contents of any file found in `arch_overlay` is either merged on top of the corresponding file in `arch`, if such a file exists, or added to the overall specification (_e.g._, when defining a new extension). An example of an overlay can be found in `cfgs/generic_rv64/arch_overlay`.
55+
56+
== ArchDef interface
57+
58+
An `ArchDef` is most easily obtained by using the convience function `arch_def_for(String)`, which takes the name of a folder under `cfgs`. Once you have an `ArchDef`, you can begin to query the database.
59+
60+
.Architecture queries
61+
[source,ruby]
62+
----
63+
# get a configuration
64+
arch_def = arch_def_for("_64")
65+
66+
# all extensions, implemented or not
67+
arch_def.extensions #=> Array<Extension>
68+
69+
# all implemented extensions
70+
arch_def.implemented_extensions #=> Array<Extension>
71+
72+
# All Parameters for the 'C' extension
73+
arch_def.extension("C").params #=> Array<Param>
74+
75+
# all ratified extensions
76+
arch_def.extensions.select { |ext| ext.state == "ratified" } #=> Array<Extension>
77+
78+
# all RISC-V instructions, implemented or not
79+
arch_def.instructions #=> Array<Instruction>
80+
81+
# all instructions defined by an implemented extension
82+
arch_def.implemented_instructions #=> Array<Instruction>
83+
84+
# the `addi` instruction
85+
arch_def.instruction("addi") #=> Instruction
86+
87+
# abstract syntax tree of the `addi` execution
88+
arch_def.instruction("addi").operation_ast #=> Idl::AstNode
89+
90+
# all CSRs, implemented or not
91+
arch_def.csrs
92+
93+
# all CSRs defined by an implemented extension
94+
arch_def.implemented_csrs
95+
96+
# the `mstatus.MPRV` CSR field
97+
arch_def.csr("mstatus").field("MPRV") #=> CsrField
98+
99+
----

0 commit comments

Comments
 (0)