summaryrefslogtreecommitdiff
path: root/src/util.lisp
diff options
context:
space:
mode:
authorSiddarth Suresh <155843085+SiddarthSuresh98@users.noreply.github.com>2025-04-08 10:17:09 -0400
committerGitHub <noreply@github.com>2025-04-08 10:17:09 -0400
commitcc1e5892a25949b996d69a0b07f151a276ef2570 (patch)
tree643d37db692c19d1ef64223eadcac7a28dbbd7db /src/util.lisp
parent19d13c8339ee990fba358417a54aa6f1c94c7bca (diff)
parentb85c10ba1c53f1b442fea6bde4c2a2f73cfe5d6b (diff)
Merge pull request #1 from bdunahu/bdunahu
Add logic to open file, full lexer and tests.
Diffstat (limited to 'src/util.lisp')
-rw-r--r--src/util.lisp22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/util.lisp b/src/util.lisp
index 87e4df9..5edee4a 100644
--- a/src/util.lisp
+++ b/src/util.lisp
@@ -3,3 +3,25 @@
(defun asm-extension? (file)
"Returns t if FILE is extended with .asm, nil otherwise."
(string= (pathname-type file) "asm"))
+
+;; TODO this won't work for negative numbers of odd sizes quite yet.
+(defun format-as-binary (num len)
+ "Formats NUM as a binary number, and pads to LEN with zeros."
+ (declare (type number num))
+ (declare (type (integer 0 *) len))
+ (format nil "~V,'0b" len num))
+
+(defparameter type-r
+ '(ADD SUB MUL QUOT REM SFTR SFTL AND OR NOT XOR ADDV SUBV MULV DIVV CMP CEV)
+ "R-type instructions.")
+
+(defparameter type-i
+ '(LOAD LOADV ADDI SUBI SFTRI SFTLI ANDI ORI XORI STORE STOREV)
+ "I-type instructions.")
+
+(defparameter type-j
+ '(JMP JRL JAL BEQ BGT BUF BOF PUSH POP)
+ "J-type instructions.")
+
+(defparameter label-loc '()
+ "A symbol table mapping label names to line indices.")