Skip to content

Commit 75d9363

Browse files
committed
Add initial support for Sail snippets
This updates the Makefile to download `riscv_RV64.json` and then add a couple of example Sail snippets to the document. There are some caveats: * No syntax highlighting or hyperlinking in the code. Alasdair demonstrated this recently but I don't know if he pushed the feature to asciidoctor-sail (or maybe the version in the Docker image is too old). * There's an encoding issue with the JSON. I temporarily worked around it with iconv. In future I will probably just remove the non-ASCII characters from the Sail code. * The Sail code is not really written with inclusion in documentation in mind. For example the scaddr code basically calls another function which you can't see in the docs, so it's kind of useless currently. There are a few ways I can think of to fix the last point. 1. Alasdair has some fancy system to automatically modify the Sail code that is generated. He demonstrated it before to split up `execute` clauses that switch on a union, but I think we could also do things like inlining functions. 2. The output with hyperlinks will be way more useful because you can just click on the function to see its source. 3. We could probably rewrite the code a bit to focus more on readability in a spec and less on good software development practices. For example use raw bit values instead of enums.
1 parent 51d96fe commit 75d9363

File tree

5 files changed

+24
-11
lines changed

5 files changed

+24
-11
lines changed

Makefile

+17-4
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ CSVS = $(wildcard $(CSV_DIR)/*.csv)
3838
GEN_DIR = $(SRC_DIR)/generated
3939
SCRIPTS_DIR = $(SRC_DIR)/scripts
4040

41+
# Downloaded Sail Asciidoc JSON, which includes all of
42+
# the Sail code and can be embedded. We don't vendor it
43+
# into this repo since it's quite large (~4MB).
44+
SAIL_ASCIIDOC_JSON_URL_FILE = riscv_RV64.json.url
45+
SAIL_ASCIIDOC_JSON = $(GEN_DIR)/riscv_RV64.json
46+
4147
# Output files
4248
PDF_RESULT := $(BUILD_DIR)/riscv-cheri.pdf
4349
HTML_RESULT := $(BUILD_DIR)/riscv-cheri.html
@@ -89,7 +95,8 @@ ASCIIDOC_OPTIONS = --trace --verbose \
8995
--failure-level=ERROR $(EXTRA_ASCIIDOC_OPTIONS)
9096
ASCIIDOC_REQUIRES = --require=asciidoctor-bibtex \
9197
--require=asciidoctor-diagram \
92-
--require=asciidoctor-mathematical
98+
--require=asciidoctor-mathematical \
99+
--require=asciidoctor-sail
93100

94101
# File extension to backend map.
95102
ASCIIDOC_BACKEND_.html = html5
@@ -130,11 +137,11 @@ $(BUILD_DIR):
130137
@echo " DIR $@"
131138
@mkdir -p $@
132139

133-
%.pdf: $(SRCS) $(IMGS) $(GEN_SRC) | $(BUILD_DIR)
140+
%.pdf: $(SRCS) $(IMGS) $(GEN_SRC) $(SAIL_ASCIIDOC_JSON) | $(BUILD_DIR)
134141
@echo " DOC $@"
135142
$(BUILD_COMMAND)
136143

137-
%.html: $(SRCS) $(IMGS) $(GEN_SRC) | $(BUILD_DIR)
144+
%.html: $(SRCS) $(IMGS) $(GEN_SRC) $(SAIL_ASCIIDOC_JSON) | $(BUILD_DIR)
138145
@echo " DOC $@"
139146
$(BUILD_COMMAND)
140147

@@ -143,9 +150,15 @@ $(GEN_SRC) &: $(CSVS) $(GEN_SCRIPT)
143150
@echo " GEN $@"
144151
@$(GEN_SCRIPT) -o $(GEN_DIR) --csr $(CSV_DIR)/CHERI_CSR.csv --isa $(CSV_DIR)/CHERI_ISA.csv
145152

153+
# Download the Sail JSON. The URL is stored in a file so if the URL changes
154+
# Make will know to download it again.
155+
# TODO: Remove iconv once this is fixed: https://github.com/Alasdair/asciidoctor-sail/issues/6
156+
$(SAIL_ASCIIDOC_JSON): $(SAIL_ASCIIDOC_JSON_URL_FILE)
157+
@curl --location '$(shell cat $<)' | iconv -f UTF-8 -t ASCII//TRANSLIT >$@
158+
146159
# Clean
147160
clean:
148161
@echo " CLEAN"
149-
@$(RM) -r $(PDF_RESULT) $(HTML_RESULT) $(GEN_SRC)
162+
@$(RM) -r $(PDF_RESULT) $(HTML_RESULT) $(GEN_SRC) $(SAIL_ASCIIDOC_JSON)
150163

151164
.PHONY: all generate clean

riscv_RV64.json.url

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://github.com/CHERI-Alliance/sail-cheri-riscv/releases/download/2024-12-19/riscv_RV64.json

src/attributes.adoc

+3
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ endif::[]
3636
:xrefstyle: short
3737
:attribute-missing: warn
3838

39+
// Sail source code
40+
:sail-doc: src/generated/riscv_RV64.json
41+
3942
///////////////////////////////////////////////////////////////////////////////
4043
// Top-level CHERI definitions
4144
///////////////////////////////////////////////////////////////////////////////

src/insns/modesw_32bit.adoc

+2-4
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,5 @@ Prerequisites::
3434
{cheri_default_ext_name}
3535

3636
Operation::
37-
[source,SAIL,subs="verbatim,quotes"]
38-
--
39-
TODO
40-
--
37+
+
38+
sail::execute[clause="MODESW()",part=body,unindent]

src/insns/scaddr_32bit.adoc

+1-3
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,4 @@ Prerequisites::
3434

3535
Operation::
3636
+
37-
--
38-
TODO
39-
--
37+
sail::execute[clause="SCADDR(_, _, _)",part=body,unindent]

0 commit comments

Comments
 (0)