summaryrefslogtreecommitdiff
path: root/language/manual.tex
blob: 2052ea0e0baa68d7a9f85884ba8c2809736ea74e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
\documentclass[11pt]{article}

\usepackage{amsmath,amssymb,supertabular,geometry,fullpage}
\geometry{a4paper,twoside,landscape,left=10.5mm,right=10.5mm,top=20mm,bottom=30mm}
\usepackage{color}

\begin{document}

\input{doc_in}

\title{Sail Manual}
\author{Kathryn E Gray, Gabriel Kerneis, Peter Sewell}

\maketitle

\tableofcontents

\newpage

\section{Introduction}

This is a manual describing the Sail specification language, its
common library, compiler, interpreter and type system. However it is
currently in early stages of being written, so questions to the
developers are highly encouraged.

\section{Tips for Writing Sail specifications}

This section attempts to offer advice for writing Sail specifications
that will work well with the Sail executable interpreter and
compilers.

These tips use ideomatic Sail code; the Sail syntax is formally
defined in following section.

Some tips might also be advice for good ways to specify instructions;
this will come from a combination of users and Sail developers.

\begin{itemize}

\item Declare memory access functions as one read, one write for each
  kind of access.

For basic user-mode instructions, there should be the need for only
one memory read and one memory write function. These should each be
declared using {\tt val extern} and should have effect {\tt wmem} and
{\tt rmem} accordingly. 

Commonly, a memory read function will take as parameters a size (an
number below 32) and an address and return a bit vector with length (8
* size). The sequential and concurrent interpreters both only read and
write memory as a factor of bytes.

\item Declare a default vector order

Vectors can be either decreasing or increasing, i.e. if we have a
vector \emph{a} with elements [1,2,3] then in an increasing specification the 1 is accessed
with {\tt a[0]} but with {\tt a[2]} in a decreasing system. Early in
your specification, it is beneficial to clarity to say default Ord inc
or default Ord dec.

\item Vectors don't necessarily begin indexing at 0 or n-1

Without any additional specification, a vector will begin indexing at
0 in an increasing spec and n-1 in a decreasing specification. A type
declaration can reset this first position to any number. 

Importantly, taking a slice of a vector does not reset the indexes. So
if {\tt a = [1,2,3,4]} in an increasing system the slice {\tt a[2
  ..3]} generates the vector {\tt [3,4]} and the 3 is indexed at 2 in either vector.

\item Be precise in numeric types. 

While Sail includes very wide types like int and nat, consider that
for bounds checking, numeric operations, and and clear understanding,
these really are unbounded quantities. If you know that a number in
the specification will range only between 0 and 32, 0 and 4, $-32$ to
32, it is better to use a specific range type such as $[|32|]$. 

Similarly, if you don't know the range precisely, it may also be best
to remain polymorphic and let Sail's type resolution work out bounds
in a particular use rather than removing all bounds; to do this, use
[:'n:] to say that it will polymorphically take some number.

\item Use bit vectors for registers.

Sail the language will readily allow a register to store a value of
any type. However, the Sail executable interpreter expects that it is
simulating a uni-processor machine where all registers are bit
vectors.

A vector of length one, such as \emph{a} can read the element of a \emph{a}
either with {\tt a} or {\tt a[0]}.

\item Have functions named decode and execute to evaluate
  instructions.

The sail interpreter is hard-wired to look for functions with these names.

\end{itemize}



\section{Sail syntax}

\ottgrammartabular{
\ottl\ottinterrule
\ottannot\ottinterrule
\ottid\ottinterrule
\ottkid\ottinterrule
\ottbaseXXkind\ottinterrule
\ottkind\ottinterrule
\ottnexp\ottinterrule
\ottorder\ottinterrule
\ottbaseXXeffect\ottinterrule
\otteffect\ottinterrule
\otttyp\ottinterrule
\otttypXXarg\ottinterrule
\ottnXXconstraint\ottinterrule
\ottkindedXXid\ottinterrule
\ottquantXXitem\ottinterrule
\otttypquant\ottinterrule
\otttypschm\ottinterrule
\ottnameXXscmXXopt\ottinterrule
\otttypeXXdef\ottinterrule
\otttypeXXunion\ottinterrule
\ottindexXXrange\ottinterrule
\ottlit\ottinterrule
\ottsemiXXopt\ottinterrule
\ottpat\ottinterrule
\ottfpat\ottinterrule
\ottexp\ottinterrule
\ottlexp\ottinterrule
\ottfexp\ottinterrule
\ottfexps\ottinterrule
\ottoptXXdefault\ottinterrule
\ottpexp\ottinterrule
\otttannotXXopt\ottinterrule
\ottrecXXopt\ottinterrule
\otteffectXXopt\ottinterrule
\ottfuncl\ottinterrule
\ottfundef\ottinterrule
\ottletbind\ottinterrule
\ottvalXXspec\ottinterrule
\ottdefaultXXspec\ottinterrule
\ottscatteredXXdef\ottinterrule
\ottregXXid\ottinterrule
\ottaliasXXspec\ottinterrule
\ottdecXXspec\ottinterrule
\ottdef\ottinterrule
\ottdefs\ottinterrule}

\newpage
\section{Sail primitive types and functions}

\ottgrammartabular{
\ottbuiltXXinXXtypes\ottinterrule}

\ottgrammartabular{
\ottbuiltXXinXXtypeXXabbreviations\ottinterrule
\ottfunctions\ottinterrule
\ottfunctionsXXwithXXcoercions\ottinterrule}
\newpage

\section{Sail type system}

\subsection{Internal type syntax}

\ottgrammartabular{
\ottk\ottinterrule
\ottt\ottinterrule
\ottoptx\ottinterrule
\otttag\ottinterrule
\ottne\ottinterrule
\otttXXarg\ottinterrule
\otttXXargs\ottinterrule
\ottnec\ottinterrule
\ottSXXN\ottinterrule
\ottEXXd\ottinterrule
\ottkinf\ottinterrule
\otttid\ottinterrule
\ottEXXk\ottinterrule
\otttinf\ottinterrule
\ottEXXa\ottinterrule
\ottfieldXXtyps\ottinterrule
\ottEXXr\ottinterrule
\ottenumerateXXmap\ottinterrule
\ottEXXe\ottinterrule
\ottEXXt\ottinterrule
\ottts\ottinterrule
\ottE\ottinterrule
\ottI\ottinterrule
\ottformula\ottinterrule}


\subsection{ Type relations }
\ottdefnss

\section{Sail operational semantics \{TODO\}}

\end{document}