blob: f6e5754773b7504c770a76c9f52fe3cc822cab33 (
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
|
(in-package #:rva)
(defparameter *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 lexer, but stop before parsing"
:long-name "lex"
:short-name #\l
:required nil
:key :lex)
(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))
(parse? (not (clingon:getopt cmd :lex)))
(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 ((tokens (lex:file->tokens file)))
(if tokens
(progn (pprint tokens)
(terpri))
(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)))
|