aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/cljcc/analyze/typecheck.clj10
-rw-r--r--src/cljcc/compiler.clj20
-rw-r--r--src/cljcc/tacky.clj3
3 files changed, 18 insertions, 15 deletions
diff --git a/src/cljcc/analyze/typecheck.clj b/src/cljcc/analyze/typecheck.clj
index 9390f3d..001c618 100644
--- a/src/cljcc/analyze/typecheck.clj
+++ b/src/cljcc/analyze/typecheck.clj
@@ -532,9 +532,13 @@
A program is a list of declarations."
[program]
- (let [v (typecheck-program program)]
- {:program (:program v)
- :ident->symbol (dissoc (:ident->symbol v) :at-top-level)}))
+ (let [v (typecheck-program program)
+ program (:program v)
+ m (dissoc (:ident->symbol v) :at-top-level)
+ _ (m/coerce p/Program program)
+ _ (m/coerce SymbolMap m)]
+ {:program program
+ :ident->symbol m}))
(comment
diff --git a/src/cljcc/compiler.clj b/src/cljcc/compiler.clj
index 5f77dc4..dad3da3 100644
--- a/src/cljcc/compiler.clj
+++ b/src/cljcc/compiler.clj
@@ -2,7 +2,7 @@
(:require [cljcc.parser :as p]
[cljcc.tacky :as t]
[cljcc.lexer :as l]
- [cljcc.analyzer :as a]
+ [cljcc.analyze.core :as a]
[cljcc.exception :as exc]))
(def registers #{:ax :dx :di :si :r8 :r9 :r10 :r11 :cx :cl})
@@ -305,10 +305,10 @@
(let [operand (get-in inst [path])
operand-type (:operand-type operand)
identifier (:identifier operand)]
- (and
- (= :pseudo operand-type)
- (contains? ident->symbol identifier)
- (= :static (get-in ident->symbol [identifier :attrs :type])))))
+ (and
+ (= :pseudo operand-type)
+ (contains? ident->symbol identifier)
+ (= :static (get-in ident->symbol [identifier :attrs :type])))))
replace-pseudo-with-data-op (fn [inst path]
(if (pseudo-data-operand? inst path)
(assoc inst path (data-operand (get-in inst [path :identifier])))
@@ -403,9 +403,9 @@
[{instructions :instructions max-stack-val :max-stack-val}]
(let [v (abs max-stack-val)
v (cond
- (= (mod v 16) 0) v
- (< v 0) (- v (- 16 (mod v 16)))
- :else (+ v (- 16 (mod v 16))))]
+ (= (mod v 16) 0) v
+ (< v 0) (- v (- 16 (mod v 16)))
+ :else (+ v (- 16 (mod v 16))))]
(cons (allocate-stack-instruction v) instructions)))
(defn- parameters->assembly-instructions
@@ -418,8 +418,8 @@
[register-params stack-params] (split-at 6 parameters)
reg-args-to-pseudo-instructions (mapv (fn [reg param]
[(mov-instruction (reg-operand reg) (pseudo-operand (:identifier param)))])
- registers
- register-params)
+ registers
+ register-params)
stack-args-to-pseudo-instruction (into [] (map-indexed (fn [idx param]
[(mov-instruction (stack-operand (+ 16 (* 8 idx))) (pseudo-operand (:identifier param)))]) stack-params))]
(->> [reg-args-to-pseudo-instructions stack-args-to-pseudo-instruction]
diff --git a/src/cljcc/tacky.clj b/src/cljcc/tacky.clj
index b25039b..58026fd 100644
--- a/src/cljcc/tacky.clj
+++ b/src/cljcc/tacky.clj
@@ -3,8 +3,7 @@
[cljcc.lexer :as l]
[cljcc.util :as u]
[cljcc.parser :as p]
- [cljcc.analyzer :as a]))
-
+ [cljcc.analyze.core :as a]))
(defn- variable
([]