-
Notifications
You must be signed in to change notification settings - Fork 14
DOOML: add compiler doing everything for A (well, we hope to add everything) #50
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
Changes from all commits
293e856
7534f16
7b29df1
d3cc923
be95b2f
63fc9ec
259f23a
9be0316
4b03091
7ade878
f2393ff
8097cfc
21539ad
4255794
17c267b
293ca3a
8c86231
7f88207
ccaacd2
3fc57d2
b6fc30b
7fdd7e1
c398da6
784240c
01d55fe
8f6a9a1
2c88ac1
a879fa7
ef9cbec
6534ece
faa4555
2083d82
d8ef5ea
2afd24e
cf216c4
b105279
bf4026d
0e80e36
e35f838
98d42ad
db035a5
6062681
b49c17a
bcb0e79
49aecf7
ad9c277
54bb99a
bb052d6
ddad515
b138e2c
afbd2d4
323362d
8080f62
005a669
6552e64
cbca94f
37222fb
280856f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| /_build | ||
| /_coverage | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| version=0.27.0 | ||
| profile=janestreet | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| # This file is generated by dune, edit dune-project instead | ||
| opam-version: "2.0" | ||
| synopsis: "A short LLVM demo" | ||
| maintainer: ["Georgiy Belyanin" "Ignatiy Sergeev"] | ||
| authors: ["Georgiy Belyanin" "Ignatiy Sergeev"] | ||
| license: "LGPL-3.0-or-later WITH OCaml-LGPL-linking-exception" | ||
| homepage: "https://github.com/Kakadu/comp24" | ||
| bug-reports: "https://github.com/Kakadu/comp24/issues" | ||
| depends: [ | ||
| "ocaml" | ||
| "dune" {>= "3.8" & = "3.19.1"} | ||
| "angstrom" {= "0.16.0"} | ||
| "qcheck" | ||
| "bisect_ppx" | ||
| "llvm" {= "18-shared"} | ||
| "qcheck" {with-tests} | ||
| "ppx_expect" | ||
| "ppx_inline_test" | ||
| "ppx_variants_conv" | ||
| "odoc" {with-doc} | ||
| ] | ||
| build: [ | ||
| ["dune" "subst"] {dev} | ||
| [ | ||
| "dune" | ||
| "build" | ||
| "-p" | ||
| name | ||
| "-j" | ||
| jobs | ||
| "@install" | ||
| "@runtest" {with-test} | ||
| "@doc" {with-doc} | ||
| ] | ||
| ] | ||
| dev-repo: "git+https://github.com/Kakadu/comp24.git" | ||
| depexts: [ | ||
| [ "llvm-18-dev" "clang-18" "gcc-riscv64-linux-gnu" "g++-riscv64-linux-gnu" "qemu-user"] {os-distribution = "ubuntu"} | ||
| ] | ||
| pin-depends: [ | ||
| ["ppx_deriving_qcheck.0.6" "git+https://github.com/c-cube/qcheck.git#42429bf06ba12373cad02b1404f50d0ad6238af5"] | ||
| ] | ||
| # Don't edit '*.opam' file manually. Use 'dune b @install' |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| depexts: [ | ||
| [ "llvm-18-dev" "clang-18" "gcc-riscv64-linux-gnu" "g++-riscv64-linux-gnu" "qemu-user"] {os-distribution = "ubuntu"} | ||
| ] | ||
| pin-depends: [ | ||
| ["ppx_deriving_qcheck.0.6" "git+https://github.com/c-cube/qcheck.git#42429bf06ba12373cad02b1404f50d0ad6238af5"] | ||
| ] | ||
| # Don't edit '*.opam' file manually. Use 'dune b @install' |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| .PHONY: all test | ||
| all: | ||
| dune build | ||
|
|
||
| test: | ||
| dune test | ||
|
|
||
| TEST_COV_D = /tmp/cov | ||
| COVERAGE_OPTS = --coverage-path $(TEST_COV_D) --expect bin/ | ||
|
|
||
| .PHONY: test_coverage coverage | ||
| test_coverage: coverage | ||
| coverage: | ||
| $(RM) -r $(TEST_COV_D) | ||
| mkdir -p $(TEST_COV_D) | ||
| BISECT_FILE=$(TEST_COV_D)/language dune runtest --no-print-directory \ | ||
| --instrument-with bisect_ppx --force | ||
| bisect-ppx-report html $(COVERAGE_OPTS) | ||
| bisect-ppx-report summary $(COVERAGE_OPTS) | ||
| @echo "Use 'xdg-open _coverage/index.html' to see coverage report" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| (executable | ||
| (public_name Dooml-Llvm) | ||
| (name llvm) | ||
| (modules llvm) | ||
| (libraries DOOML) | ||
| (instrumentation | ||
| (backend bisect_ppx))) | ||
|
|
||
| (executable | ||
| (public_name Dooml-Riscv) | ||
| (name riscv) | ||
| (modules riscv) | ||
| (libraries DOOML) | ||
| (instrumentation | ||
| (backend bisect_ppx))) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| (** Copyright 2025-2026, Georgiy Belyanin, Ignat Sergeev *) | ||
|
|
||
| (** SPDX-License-Identifier: LGPL-3.0-or-later *) | ||
|
|
||
| open DOOML | ||
| module Map = Base.Map.Poly | ||
|
|
||
| let failf fmt = Format.kasprintf failwith fmt | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using |
||
|
|
||
| let parse input = | ||
| let code = In_channel.with_open_text input In_channel.input_all in | ||
| match Fe.parse code with | ||
| | Error msg -> Error msg | ||
| | Ok ast_list -> Ok (ast_list |> Cc.cc |> Ll.ll |> Anf.anf) | ||
| ;; | ||
|
|
||
| let () = | ||
| match Array.to_list Sys.argv with | ||
| | [ _exe; input; output ] -> | ||
| let riscv_triple = "riscv64-unknown-linux-gnu" in | ||
| let riscv_features = "+d" in | ||
| let module_ = | ||
| match parse input with | ||
| | Error msg -> failf "%s" msg | ||
| | Ok anf_list -> Codegen.emit_ir ~triple:riscv_triple anf_list | ||
| in | ||
| Codegen.optimize_ir ~triple:riscv_triple module_; | ||
| Codegen.emit_binary ~triple:riscv_triple ~features:riscv_features module_ output | ||
| | _ -> exit 1 | ||
| ;; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| (** Copyright 2025-2026, Georgiy Belyanin, Ignat Sergeev *) | ||
|
|
||
| (** SPDX-License-Identifier: LGPL-3.0-or-later *) | ||
|
|
||
| open DOOML | ||
| module Map = Base.Map.Poly | ||
|
|
||
| let failf fmt = Format.kasprintf failwith fmt | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using |
||
|
|
||
| let parse input = | ||
| let code = In_channel.with_open_text input In_channel.input_all in | ||
| match Fe.parse code with | ||
| | Error msg -> Error msg | ||
| | Ok ast_list -> | ||
| Ok | ||
| (ast_list | ||
| |> Cc.cc | ||
| (*|> fun asts -> | ||
| Format.printf | ||
| "CC: %a\n\n" | ||
| (Format.pp_print_list ~pp_sep:Format.pp_print_newline Ast.pp_top_level) | ||
| asts; | ||
| asts*) | ||
| |> Ll.ll | ||
| (*|> fun asts -> | ||
| Format.printf | ||
| "LL: %a\n\n" | ||
| (Format.pp_print_list ~pp_sep:Format.pp_print_newline Ast.pp_top_level) | ||
| asts; | ||
| asts*) | ||
| (*Cc.cc |> Ll.ll *) | ||
| |> Anf.anf | ||
| (*|> fun asts -> | ||
| Format.printf | ||
| "ANF %a\n\n" | ||
| (Format.pp_print_list ~pp_sep:Format.pp_print_newline Anf.pp_decl) | ||
| asts; | ||
| asts | ||
| *)) | ||
| ;; | ||
|
|
||
| let () = | ||
| match parse Sys.argv.(1) with | ||
| | Error msg -> failf "%s" msg | ||
| | Ok anf_list -> Format.printf "%a\n" Riscv.pp_code (Riscv.riscv anf_list) | ||
| ;; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| (lang dune 3.8) | ||
|
|
||
| (name DOOML) | ||
|
|
||
| (generate_opam_files true) | ||
|
|
||
| (source | ||
| (github Kakadu/comp24)) | ||
|
|
||
| (authors "Georgiy Belyanin" "Ignatiy Sergeev") | ||
|
|
||
| (maintainers "Georgiy Belyanin" "Ignatiy Sergeev") | ||
|
|
||
| (license "LGPL-3.0-or-later WITH OCaml-LGPL-linking-exception") | ||
|
|
||
| (package | ||
| (name DOOML) | ||
| (synopsis "A short LLVM demo") | ||
| (depends | ||
| ocaml | ||
| (dune | ||
| (= "3.19.1")) | ||
| (angstrom | ||
| (= "0.16.0")) | ||
| qcheck | ||
| bisect_ppx | ||
| (llvm | ||
| (= "18-shared")) | ||
| (qcheck :with-tests) | ||
| ppx_expect | ||
| ppx_inline_test | ||
| ppx_variants_conv)) | ||
|
|
||
| ; See the complete stanza docs at https://dune.readthedocs.io/en/stable/dune-files.html#dune-project |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using
failwith(orassert false) usually is a clue that a corner case is not being handled properly. To report errors we recommend using error monad instead. In princliple, these construction are OK for temporary work-in-progress code, but in release they should be eliminated