blob: 969260337592df554773cd1b1a840e9f9452febe (
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
|
(in-package #:rva)
(defvar *banner*
" _/_/ _/_/
_/ _/
_/ _/ _/_/ _/ _/ _/_/_/ _/
_/ _/_/ _/ _/ _/ _/ _/
_/ _/ _/ _/ _/ _/ _/
_/ _/ _/ _/_/_/ _/
_/_/ _/_/ "
"Stylized ASCII logo.")
(defun print-splash ()
"Prints a pretty splash-screen."
(format t "~a~%" *banner*))
(defun cli/options ()
"Returns options for the `rva' assembler."
(list
(clingon:make-option
:flag
:description "run the parser, but stop before emission"
:long-name "parse"
:short-name #\p
:required nil
:key :parse)))
(defun driver (cmd)
"Reads in a file and directs lexing, parsing, and binary emission."
(print-splash)
(let* ((args (clingon:command-arguments cmd))
(file (car args))
(emit? (not (clingon:getopt cmd :parse))))
(cond
;; complain about num arguments
((/= (length args) 1) (error "Wrong number of arguments.~%"))
((not (util:asm-extension? file))
(error "The file is not an asm source code file.~%"))
(t (let ((str (uiop:read-file-string file)))
(if str
(progn (pprint (esrap:parse 'parse:str->ast (string-upcase str)))
(terpri)
(maphash #'(lambda (k v) (format t "~A => ~A~%" k v)) util:label-table)
(format t "---~%"))
(error "The file does not exist, or it could not be opened.~%"))
(format t "Nitimur in Vetitum~%"))))))
(defun cli/command ()
"Returns a clingon command."
(clingon:make-command
:name "rva"
:description "generates a binary compatible with the RISC V[ECTOR] simulator"
:usage "[options] file"
:version(asdf:component-version
(asdf:find-system "rva" nil))
:options (cli/options)
:handler #'driver))
(defun main ()
(clingon:run (cli/command)))
|