Created
March 17, 2011 23:23
-
-
Save timmc/875355 to your computer and use it in GitHub Desktop.
Naughty stuff with classes?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns org.timmc.mipsiss.instructions | |
"Abstract MIPS instruction representation.") | |
;; Text formats: | |
;; - :s is RS e.g. $r9 | |
;; - :t is RT e.g. $r9 | |
;; - :d is RD e.g. $r9 | |
;; - :C is Imm e.g. 8 | |
;; - :b is base (RS) e.g. ($r9) | |
(defrecord ^{:doc "Instruction"} | |
Instr | |
[^{:doc "Instruction name as keyword"} | |
name | |
^{:doc "Format as :r, :i, or :j (machine language)"} | |
mform | |
^{:doc "Format as :dst, :tsC, :tCb, :stC, :C, or :s (text format)"} | |
tform | |
]) | |
(def all-instr | |
[ | |
;; arithmetic | |
(Instr. :add :r :dst) | |
(Instr. :sub :r :dst) | |
(Instr. :and :r :dst) | |
(Instr. :or :r :dst) | |
(Instr. :nor :r :dst) | |
(Instr. :slt :r :dst) | |
;; arithmetic -- immediate | |
(Instr. :addi :i :tsC) | |
(Instr. :andi :i :tsC) | |
(Instr. :ori :i :tsC) | |
(Instr. :slti :i :tsC) | |
;; branches and jumps | |
(Instr. :beq :r :stC) | |
(Instr. :bne :r :stC) | |
(Instr. :jr :r :s) | |
(Instr. :j :j :C) | |
;; memory | |
(Instr. :lw :i :tCb) | |
(Instr. :sw :i :tCb) | |
]) | |
(def ^{:doc "Map of instruction names (as keywords) to their info records."} | |
by-name | |
(into {} (map #(vector (.name ^Instr %) %) all-instr))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment