1 \documentclass[10pt,oneside]{article}
3 \usepackage[titles]{tocloft}
10 \usepackage{bytefield}
11 \usepackage[colorlinks=true, pdfstartview=FitV, linkcolor=blue, citecolor=blue, urlcolor=blue]{hyperref}
12 \renewcommand{\ttdefault}{cmtt}
13 \title{The FleetTwo Toolchain Manual\\{\normalsize A Compiler Writer's View of FleetTwo}}
18 \begin{thebibliography}{[GDG01]}
19 \bibitem[ArchMan]{ArchMan}
20 {\it The FleetTwo Architecture Manual}
22 Megacz, Adam, {\it Scannerless Boolean Parsing}. Electronic Notes in
23 Theoretical Computer Science 1368, (Volume 164, Issue 2):
24 Proceedings of the Sixth Workshop on Language Descriptions, Tools,
25 and Applications (LDTA 2006)
31 Fleet compilers and tools work primarily with three entities: Ships,
32 Instructions, and Test Cases. In order to promote greater
33 interoperability, the FleetTwo Toolchain defines both a Java API and a
34 text file format for each of these.
38 \fbox{\parbox{5in}{\footnotesize
40 The software described in this memo may be obtained using
41 \href{http://www.darcs.net/}{\tt darcs}, with the command:
43 {\tt darcs get http://research.cs.berkeley.edu/class/fleet/repos/fleet/}
51 \section{Introduction}
53 Fleet compilers and tools work primarily with three entities: Ships,
54 Instructions, and Test Cases. In order to promote greater
55 interoperability, the FleetTwo Toolchain defines both a Java API and a
56 textual file format for each of these.
58 In the case of ships, this takes the form of the {\tt .ship} file
59 format for describing ships and the {\tt ShipDescription} Java class
60 which an implementation of Fleet uses to inform the toolchain of what
61 ships it contains and how they may be used. The toolchain includes a
62 library for parsing the textual file format into the Java
65 In the case of instructions, and more generally programs, this takes
66 the form of the {\tt .fleet} assembly language file format for
67 representing Fleet programs and the {\tt Instruction} and {\tt
68 CodeBag} Java classes for representing programs and manipulating
69 them. A library is provided for parsing Fleet assembly language
70 programs into {\tt CodeBag}s of {\tt Instruction}s, and for writing
71 those objects back out as text.
73 In the case of Test Cases, the FleetTwo Toolchain defines a very
74 simple debugging interface, {\tt Device}, which lets a program
75 dispatch a codebag to a running Fleet implementation or emulator and
76 read back the words which arrive at its {\tt Debug} port. A test
77 harness has been written which makes no assumptions about the device
78 under test other than that it supports this debugging interface and
79 that it is capable of describing itself via the {\tt ShipDescription}
80 API. By meeting these relatively modest requirements, a new Fleet
81 implementation can immediately take advantage of a great deal of
82 prebuilt testing infrastructure. This API has been implemented and is
83 fully functional for both the software interpreter implementation of
84 Fleet and the FPGA simulation of Fleet.
89 \subsection{Ship Description Files (FleetDoc)}
91 Inspired by JavaDoc, the Fleet software toolchain includes a tool
92 called {\tt FleetDoc}, which processes {\it ship description files}
93 with the extension {\tt .ship}. These files contain sections for:
96 \item The name of the ship
97 \item A list of its ports
98 \item A prose description of the ship
99 \item A list of the constants associated with a ship
100 \item Java source code for a software simulation of the ship
101 \item Verilog source code for an FPGA simulation of the ship
102 \item A test case for the ship
103 \item A list of the people who contributed to all of the above
106 Keeping all of this information in a single file ensures that changes
107 to one item -- such as the list of ports -- are propagated to the
108 other items -- such as the verilog code for simulation purposes.
110 Keeping this information in {\it machine-readable} format makes it
111 possible to automatically generate tools which depend on the precise
112 details of ship ports without the risk
113 inherent in manual synchronization.
115 The latter half of the architecture manual \cite{ArchMan} -- including
116 the ship diagrams -- is generated automatically from the contents of
117 the {\tt .ship} files.
120 \subsubsection{An Example FleetDoc File}
124 == Ports ===========================================================
127 constant lsbFirst: ....................................1
128 constant msbFirst: ....................................0
129 constant drop: .............................uuuuuu..
130 constant take: .......................uuuuuu........
133 == TeX ==============================================================
134 The BitFifo internally stores some number of bits in a fifo structure.
135 Its capacity is guaranteed to be at least two full machine words or
139 == Fleeterpreter ====================================================
140 public void service() {
141 if (box_inOp.dataReadyForShip() && box_in.dataReadyForShip()) {
144 == FPGA ==============================================================
145 always @(posedge clk) begin
146 if (!in_r && in_a) in_a <= 0;
147 if (!inOp_r && inOp_a) inOp_a <= 0;
150 == Test ==============================================================
154 #ship bitfifo : BitFifo
156 bitfifo.outOp: literal BitFifo.outOp[take=37]; [*] deliver;
159 == Contributors =========================================================
160 Amir Kamil <kamil@cs.berkeley.edu>
161 Adam Megacz <megacz@cs.berkeley.edu>
166 \subsection{Java API for Ship Descriptions}
168 The FleetTwo toolchain includes a utility for parsing a {\tt .ship}
169 file into a {\tt ShipDescription}. There is one {\tt ShipDescription}
170 for each {\it kind} of ship. This distinction will become important
171 later, when we introduce classes to represent {\it instances} of ship
175 /** a description of a ship */
176 public class ShipDescription implements Iterable<DockDescription> {
177 public String getName();
178 public Iterable<ConstantDescription> getConstantDescriptions();
179 public Iterable<DockDescription> getDockDescriptions();
182 /** a description of a valve */
183 public class DockDescription {
184 public String getName();
185 public boolean isInbox();
186 public boolean isOutbox();
187 public DockDescription getShortcut();
190 /** a constant declared by a ship */
191 public class ConstantDescription {
192 public final long setbits;
193 public final long clearbits;
194 public final boolean signExtend;
195 public final int numberOffset;
196 public final int numberWidth;
202 \section{Instructions}
203 \subsection{Fleet Assembly Language}
205 The Fleet Assembly language is designed to be a human-readable
206 depiction of the bits which comprise a Fleet program.
208 \subsubsection{Formal Grammar}
210 The formal syntax is given below. The metagrammar used is that of the
211 Scannerless Boolean Parser \cite{sbp}.
213 \verbatiminput{fleet.g}
215 \subsubsection{Translation To Machine Code}
217 Please refer to \cite{ArchMan} for the details of the Fleet
218 instruction encoding.
220 As shown in the grammar above, the start symbol for the grammar ({\tt
221 s}) yields a {\tt Program} surrounded by optional whitespace. A
222 program is a sequence of {\tt Directive}s followed by a {\tt
223 CodeBagBody}. A {\tt CodeBagBody} consists of zero or more
224 elements, each of which is either a {\tt Fiber} or a (nested) {\tt
227 A {\tt Fiber} is a set of {\tt Instruction}s which all share a common
228 execution point ({\tt Pump}). Each instruction can be {\tt unclog},
229 {\tt clog}, {\tt kill}, {\tt literal}, or a set of {\tt Command}s. It
230 should be fairly clear how to translate all but the last sort of
231 instruction into machine code, based on the encodings in
232 \cite{ArchMan}. Take particular note of the fact that {\tt literal}s
233 may have a {\tt RequeueCount} but not a {\tt RepeatCount}.
235 The repetition count for an instruction is placed in square brackets
236 and prefixes the instruction. The requeueing count for an instruction
237 is placed at the end of the instruction because, {\it conceptually},
238 requeueing takes place after the instruction executes.
240 A {\tt Command} is either {\tt wait}, {\tt nop}, {\tt discard}, {\tt
241 recieve}, {\tt take}, {\tt deliver}, {\tt send}, {\tt sendto}, {\tt
242 notify}, or {\tt notifyLast}. These are compiled as shown below:
245 \item[\tt nop] is not valid in combination with any other command; it sets all control bits to {\tt 0}
246 \item[\tt wait] is valid only on an output port, and sets {\tt Ti=1}
247 \item[\tt discard] sets {\tt Di=1,Dc=0}
248 \item[\tt recieve] is valid only on an input port, and sets {\tt Di=1,Dc=1}
249 \item[\tt take] is valid only on an output port, and sets {\tt Di=1,Dc=1}
250 \item[\tt deliver] is valid only on an input port, and sets {\tt Do=1}
251 \item[\tt sendto] is valid only on an output port, and sets {\tt Do=1}
252 \item[\tt send] is valid only on an output port, and sets {\tt Do=1,To=1}\footnote{see \cite{ArchMan} for the special meaning this bit combination has}
253 \item[\tt notify] sets {\tt To=1} and is not valid in combination with {\tt send} or {\tt sendto}
254 \item[\tt notifyLast] sets {\tt To=1,Ig=1} and is not valid in combination with {\tt send} or {\tt sendto}
257 It is an error to specify two commands within a single instruction if
258 both of the commands attempt to set the same bit, even if they attempt
259 to set it to the same value.
261 Note that un-named ``anonymous'' codebags may appear as literals.
262 This means that it is possible to write interesting programs such as
267 #ship memory : Memory
269 memory.inCBD: literal {
270 memory.inCBD: literal {
271 memory.inCBD: literal {
284 \subsection{Java API for Fleet Machine Code}
288 public abstract class Ship {
290 /** return the description for this ship */
291 public ShipDescription getShipDescription();
293 /** return all pumps which feed this ship; order is NOT significant */
294 public Iterable<Dock> getDocks();
295 public Dock getDock(String s);
297 /** if this is the 4th fifo ship, this method returns 4 */
298 public int getOrdinal();
300 /** return the Fleet that this Ship belongs to, if any */
301 public Device getDevice();
309 /** the descriptive name of this pump (relative to its ship) */
310 public abstract String getName();
312 /** return the Ship to which this Dock belongs */
313 public abstract Ship getShip();
315 /** the maximum number of instructions we can put in the Dock instruction fifo,
316 * or Integer.MAX_VALUE if unbounded */
317 public abstract int getInstructionFifoLength();
319 /** returns true if this is an inbox */
320 public abstract boolean isInbox();
322 /** returns true if this is an outbox */
323 public abstract boolean isOutbox();
325 /** return the Dock which is the destination of this Box's shortcut (if any) */
326 public Destination getShortcut() { return null; }
330 \subsection{Instructions}
332 public abstract class Instruction {
333 public final Pump pump;
335 public static class UnClog extends Instruction {
338 public static class Clog extends Instruction {
341 public static abstract class CountingInstruction extends Instruction {
342 public final int count;
343 public CountingInstruction decrementCount();
346 public static class Kill extends CountingInstruction {
349 public static class Executable extends CountingInstruction {
351 public final Destination dest;
353 public final boolean tokenIn;
354 public final boolean dataIn;
355 public final boolean latch;
356 public final boolean send;
357 public final boolean sendTo;
358 public final boolean tokenOut;
359 public final boolean requeue;
360 public final boolean ignoreUntilLast;
362 public boolean isStanding();
365 public static class Literal extends CountingInstruction {
366 public final long literal;
374 \subsection{Test Case File Format}
376 The test case file format is quite simple -- it is nothing more than a
377 regular Fleet assembly language program with {\tt \#expect} statements
378 to indicate the values which should arrive at the {\tt Debug.in} port
379 if the test runs correctly.
381 \subsection{Java API for Controlling Device Under Test}
383 \subsection{The Device}
385 public abstract class Device implements Iterable<Ship> {
387 /** read a machine-formatted instruction from a file (into a Java object) */
388 public abstract Instruction
389 readInstruction(DataInputStream is) throws IOException;
391 /** write a machine-formatted instruction to a file (from a Java object) */
393 writeInstruction(DataOutputStream os, Instruction instr) throws IOException;
395 public abstract Iterator<Ship> iterator();
397 /** if possible, run the given code and create a FleetProcess */
398 public FleetProcess run(byte[] code);
402 \subsection{A Running Test}
405 /** represents a <i>running</i> "slave" fleet with a debug connection */
406 public abstract class FleetProcess {
408 /** dumps an instruction into the fetch unit */
409 public abstract void invokeInstruction(Instruction i);
411 /** reads a word back from the debug port */
412 public abstract long readWord();
414 public final synchronized void terminate();
416 public final boolean isTerminated();