Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge in Datomic sources #9

Merged
merged 35 commits into from
May 10, 2013
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
5a61c8c
work adding datomic
Mar 9, 2013
968e487
Added float, pointer, and fn types to ssa
Mar 9, 2013
ce8d9fe
latest work on ssa
Mar 11, 2013
19af157
latest work on datomic code
Mar 14, 2013
97634bb
more fixups to the datomic code
Mar 15, 2013
957d97c
Functions are commited
Mar 15, 2013
3b4d1c3
start of ssa refactor using state modnads(-ish)
Mar 21, 2013
a1c6637
If blocks are kindof implemented
Mar 26, 2013
5c61e2f
need validation/type inference next
Mar 28, 2013
b19b463
more work on the datomic backend
Mar 30, 2013
3058b58
fixed phi node linking
Mar 30, 2013
dce71cc
loops are working now
Apr 3, 2013
1e28bcc
reworked the binop system
Apr 4, 2013
df849ed
removing out-dated tests
Apr 4, 2013
6033e37
updated project.clj
Apr 4, 2013
6c00ba1
forgot to add some recent files
Apr 4, 2013
ea0d1ec
fixed malloc bug and other changes
Apr 25, 2013
7f5c3bf
added aset
Apr 27, 2013
4fd1c33
started fixing up the bf example to the new api
Apr 30, 2013
8e2fc49
bf compiler is working
May 1, 2013
d420f23
rewrote inference with pure clojure
May 2, 2013
6a4cab0
added fn translator
May 4, 2013
e697998
tons of updates, but tests are still broken
May 5, 2013
d349b89
some fixes, still some issues
May 6, 2013
c350f49
fixed a ugly bug with args
May 7, 2013
bbf305d
mandelbrot tests compile now
May 7, 2013
c068460
removed a ton of unused code in expressions.clj
May 7, 2013
a10a596
implementing structs, set, get
May 8, 2013
ae31ff6
added get
May 9, 2013
058b8d9
simple_lisp.clj can now compile to datomic
May 10, 2013
e7de853
more debugging
May 10, 2013
5fd7b4f
latest updates and fixes
May 10, 2013
5f72ef4
Update README.md
halgari May 10, 2013
a408004
updated version
May 10, 2013
8df3a6c
Merge branch 'datomic' of https://github.com/halgari/mjolnir into dat…
May 10, 2013
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
bf compiler is working
  • Loading branch information
Timothy Baldridge committed May 1, 2013
commit 8e2fc494a4fe87b751e6992976784c91faf39a85
1 change: 1 addition & 0 deletions src/examples/bf.clj
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@
cfn)
conn (core/to-db module)
built (core/to-llvm-module conn)

optimized built
_ (println "Writing Object File")
compiled (time (emit-to-file config/*target*
Expand Down
9 changes: 7 additions & 2 deletions src/mjolnir/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[datomic.api :refer [q db] :as d]
[mjolnir.config :refer [*int-type* *target* default-target]]
[mjolnir.ssa :refer :all]
[mjolnir.llvm-builder :refer [build]]))
[mjolnir.llvm-builder :refer [build dump verify]]))

(defn to-db [m]
(let [conn (new-db)]
Expand All @@ -20,5 +20,10 @@
(defn to-llvm-module [conn]
(infer-all conn)
(validate (db conn))
(build (db conn)))
(let [built (build (db conn))]
#_(dump built)
(verify built)
built))



130 changes: 7 additions & 123 deletions src/mjolnir/expressions.clj
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
ptr (write-ssa ptr)
casted (add-instruction :inst.type/cast
{:inst.cast/type tp-id
:inst.arg/arg0 ptr
:node/return-type tp-id})]
casted)))

Expand Down Expand Up @@ -502,19 +503,19 @@
test-id (write-ssa test)
test-block (get-block)

pre-then-block (add-block fnc)
pre-then-block (add-block fnc "then")
_ (set-block pre-then-block)
then-val (write-ssa then)
post-then-block (get-block)
then-terminated? (terminated? post-then-block)

pre-else-block (add-block fnc)
pre-else-block (add-block fnc "else")
_ (set-block pre-else-block)
else-val (write-ssa else)
post-else-block (get-block)
else-terminated? (terminated? post-else-block)

merge-block (add-block fnc)
merge-block (add-block fnc "merge")
_ (set-block merge-block)
phi-val (add-phi)

Expand Down Expand Up @@ -705,8 +706,6 @@
(first exprs)
(next exprs))
build)))


(defrecord *Op [exprs]
Validatable
(validate [this]
Expand All @@ -729,66 +728,12 @@


(defrecord Loop [itms body]
Validatable
(validate [this]
(doseq [[nm init] itms]
(assure (string? nm))
(assure (valid? init)))
(binding [*locals* (merge *locals*
(zipmap (map first itms)
(map (comp return-type second) itms)))
*recur-point* (map (comp return-type second) itms)]
(assure (valid? body))))
Expression
(return-type [this]
(binding [*locals* (merge *locals*
(zipmap (map first itms)
(map (comp return-type second) itms)))]
(return-type body)))
(build [this]
(binding [*locals* (merge *locals*
(zipmap (map first itms)
(map (comp return-type second) itms)))
*recur-point* (map (comp return-type second) itms)]
(let [inits (doall (map (fn [itm]
(build itm))
(map second itms)))
loopblk (llvm/AppendBasicBlock *llvm-fn* (genname "loop_"))
endblk (llvm/AppendBasicBlock *llvm-fn* (genname "loopexit_"))
_ (llvm/BuildBr *builder* loopblk)
_ (llvm/PositionBuilderAtEnd *builder* loopblk)
fromblk @*block*
_ (reset! *block* loopblk)
phis (doall (map (fn [[built exp]]
(let [phi (llvm/BuildPhi *builder*
(llvm-type (return-type exp))
(genname "loopval_"))]
(llvm/AddIncoming phi
(into-array Pointer [built])
(into-array Pointer [fromblk])
1)
phi))
(map vector inits (map second itms))))]



(binding [*llvm-locals* (merge *llvm-locals*
(zipmap (map first itms)
phis))
*llvm-recur-point* loopblk
*llvm-recur-phi* phis]

(let [ret (build body)]
(llvm/BuildBr *builder* endblk)
(reset! *block* endblk)
(llvm/PositionBuilderAtEnd *builder* endblk)
ret)))))
SSAWriter
(write-ssa [this]
(gen-plan
[fnc (get-in-plan [:state :fn])
itm-ids (add-all (map (comp write-ssa second) itms))
recur-pnt (add-block fnc)
recur-pnt (add-block fnc "body")
_ (terminate-block :inst.type/jmp recur-pnt)
prev-block (get-block)
_ (set-block recur-pnt)
Expand All @@ -799,7 +744,6 @@
phis
itm-ids))
_ (apply push-alter-binding :locals assoc (mapcat (fn [[nm _] val]
(println "->>>> " nm " " val)
[nm val])
itms
phis))
Expand All @@ -809,12 +753,10 @@
_ (pop-binding :recur-phis)
_ (pop-binding :recur)
_ (pop-binding :locals)
end-block (add-block fnc)
end-block (add-block fnc "end")
_ (terminate-block :inst.type/jmp end-block)
_ (set-block end-block)]
(do
(println "phis----" phis)
return-val))))
return-val)))

(defrecord Let [nm bind body]
Validatable
Expand Down Expand Up @@ -844,17 +786,6 @@
_ (pop-binding :locals)]
val)))

(defrecord Malloc-old [type cnt]
Validatable
(validate [this]
(assure (type? type))
(assure (integer? cnt)))
Expression
(return-type [this]
(->ArrayType type cnt))
(build [this]
(llvm/BuildMalloc *builder* (llvm-type (->ArrayType type cnt)) (genname "malloc_"))))

(defrecord Malloc [type]
SSAWriter
(write-ssa [this]
Expand All @@ -876,18 +807,6 @@
:node/return-type void})]
inst-id)))

#_(defrecord Alloc [type cnt]
Validatable
(validate [this]
(assure (type? type))
(assure (integer? cnt)))
Expression
(return-type [this]
(->ArrayType type cnt))
(build [this]
(llvm/BuildAlloc *builder* (llvm-type (->ArrayType type cnt)) (genname "malloc_"))))


(defrecord ASet [arr idx val]
Validatable
(validate [this]
Expand Down Expand Up @@ -1088,28 +1007,6 @@
(llvm/BuildStore *builder* (build (nth vals idx)) gep)))
malloc)))

(defrecord Recur-old [items]
Validatable
(validate [this]
(assure (= (count items) (count *recur-point*)))
(assure (type? type))
(dotimes [x (count items)]
(let [itm (nth items x)
rp-itm (nth *recur-point* x)]
(assure-same-type (return-type itm) rp-itm))))
Expression
(return-type [this]
type)
(build [this]
(let [d (mapv build items)]
(llvm/BuildBr *builder* *llvm-recur-point*)
(dotimes [idx (count *llvm-recur-phi*)]
(llvm/AddIncoming (nth *llvm-recur-phi* idx)
(into-array Pointer [(nth d idx)])
(into-array Pointer [@*block*])
1))
:terminated)))

(defrecord Recur [items]
SSAWriter
(write-ssa [this]
Expand All @@ -1118,25 +1015,13 @@
this-block (get-block)
phis (get-binding :recur-phis)
_ (add-all (map (fn [phi val]
(println "<---" phi " ")
(add-to-phi phi this-block val))
phis
item-ids))
recur-pnt (get-binding :recur)
_ (terminate-block :inst.type/jmp recur-pnt)]
nil)))

(defrecord Free-old [val]
Validatable
(validate [this]
(ElementPointer? (return-type val)))
Expression
(return-type [this]
Int32)
(build [this]
(llvm/BuildFree *builder* (build val))
(build 0)))

(defrecord Do [body]
Validatable
(validate [this]
Expand Down Expand Up @@ -1174,7 +1059,6 @@
gbl)))
GlobalExpression
(stub-global [this]
(println name)
(llvm/AddGlobalInAddressSpace *module*
(llvm-type type)
name
Expand Down
4 changes: 4 additions & 0 deletions src/mjolnir/inference.clj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
(q '[:find ?id ?attr ?val
:in $ %
:where
[?id :node/type _]
[(datomic.api/entity $ ?id) ?ent]
[(:node/return-type ?ent) ?rval]
[(nil? ?rval)]
(infer-node ?id ?attr ?val)]
db
@rules))
Expand Down
Loading