aboutsummaryrefslogtreecommitdiff
path: root/cljcc-compiler/src/cljcc/emit.cljc
diff options
context:
space:
mode:
authorYour Name <agrawalshagun07@gmail.com>2025-03-16 14:53:45 +0530
committerYour Name <agrawalshagun07@gmail.com>2025-03-16 14:53:45 +0530
commit277319fa392f5ee9f21eedf2c4d224739f045690 (patch)
treef2e3a89de7946647d7560db242e7ce22fda25a5c /cljcc-compiler/src/cljcc/emit.cljc
parent39b6930e14cfda58fd066805f5da447c685ab67f (diff)
Add common functions for handling cljcc compiler
Diffstat (limited to 'cljcc-compiler/src/cljcc/emit.cljc')
-rw-r--r--cljcc-compiler/src/cljcc/emit.cljc11
1 files changed, 6 insertions, 5 deletions
diff --git a/cljcc-compiler/src/cljcc/emit.cljc b/cljcc-compiler/src/cljcc/emit.cljc
index 0686b31..b4fdc13 100644
--- a/cljcc-compiler/src/cljcc/emit.cljc
+++ b/cljcc-compiler/src/cljcc/emit.cljc
@@ -2,8 +2,9 @@
(:require
[cljcc.util :refer [get-os]]
[cljcc.compiler :as c]
+ [cljcc.core.format :refer [safe-format]]
[clojure.string :as str]
- [cljcc.exception :as exc]))
+ [cljcc.core.exception :as exc]))
(defn- handle-label [identifier]
(condp = (get-os)
@@ -26,13 +27,13 @@
;;;; Operand Emit
(defn- imm-opernad-emit [operand _opts]
- (format "$%d" (:value operand)))
+ (safe-format "$%d" (:value operand)))
(defn- stack-operand-emit [operand _opts]
- (format "%d(%%rbp)" (:value operand)))
+ (safe-format "%d(%%rbp)" (:value operand)))
(defn- data-operand-emit [operand _opts]
- (format "%s(%%rip)" (handle-symbol-name (:identifier operand))))
+ (safe-format "%s(%%rip)" (handle-symbol-name (:identifier operand))))
(defn- register-operand [{:keys [register] :as operand} {register-width :register-width :or {register-width :4-byte}}]
(let [register->width->output {:ax {:8-byte "%rax"
@@ -95,7 +96,7 @@
([operand opts]
(if-let [[_ operand-emit-fn] (find operand-emitters (:operand operand))]
(operand-emit-fn operand opts)
- (throw (AssertionError. (str "Invalid operand: " operand))))))
+ (exc/emit-error "Invalid operand" {:operand operand}))))
;;;; Instruction Emit