diff options
| author | Shagun Agrawal <agrawalshagun07@gmail.com> | 2024-11-09 17:27:35 +0530 |
|---|---|---|
| committer | Shagun Agrawal <agrawalshagun07@gmail.com> | 2024-11-09 17:27:35 +0530 |
| commit | 7140310b4cc538d12c1d1285ce96792aa619adcf (patch) | |
| tree | e875b48d9061c8e159ac2bb3a6befb9694bf0303 /src/cljcc/emit.clj | |
| parent | 298a29f7b73fa3b34213ffae2c4c101a9d283ac5 (diff) | |
Add codegen for storage class specifiers
Switch map/filter to eager versions
Diffstat (limited to 'src/cljcc/emit.clj')
| -rw-r--r-- | src/cljcc/emit.clj | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/src/cljcc/emit.clj b/src/cljcc/emit.clj index 1d8c51a..866fe91 100644 --- a/src/cljcc/emit.clj +++ b/src/cljcc/emit.clj @@ -199,28 +199,31 @@ " movq %rsp, %rbp" instructions]))) +(defn- static-variable-definition-emit [{:keys [identifier global? initial-value]}]) + (def emitters-top-level "Map of assembly top level constructs to their emitters." - {:declaration #'function-definition-emit}) + {:function #'function-definition-emit + :static-variable #'static-variable-definition-emit}) -(defn emit-top-level [assembly-ast] - (if-let [[_ emit-fn] (find emitters-top-level (:op assembly-ast))] - (emit-fn assembly-ast) - (throw (AssertionError. (str "Invalid ast: " assembly-ast))))) +(defn emit-top-level [tacky-ast] + (if-let [[_ emit-fn] (find emitters-top-level (:type tacky-ast))] + (emit-fn tacky-ast) + (throw (AssertionError. (str "Invalid ast: " tacky-ast))))) (def linux-assembly-end ".section .note.GNU-stack,\"\",@progbits") -(defn emit [ast] +(defn emit [top-levels] (let [handle-os (fn [ast] (if (= :linux (get-os)) (conj (conj (vec ast) linux-assembly-end) "\n") (conj ast "\n")))] - (->> ast + (->> top-levels (map emit-top-level) concat flatten handle-os - (str/join "\n")))) + (str/join "\n\n")))) (comment |
