Skip to content

Commit

Permalink
Make standalone the LATEX pretty-printer
Browse files Browse the repository at this point in the history
  • Loading branch information
vbgl authored and bgregoir committed Mar 8, 2023
1 parent f635111 commit 156fdc6
Show file tree
Hide file tree
Showing 11 changed files with 96 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ ocaml:
paths:
- compiler/_build/
- compiler/jasminc.native
- compiler/jasminpp.native

eclib:
stage: prove
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@
(e.g., `x /= y`)
([PR #324](https://github.com/jasmin-lang/jasmin/pull/324)).

- The pretty-printer of Jasmin programs to LATEX is now available as a separate
`jazz2tex` tool
([PR #???](https://github.com/jasmin-lang/jasmin/pull/3??)).

## Bug fixes

- The x86 instructions `VMOVSHDUP` and `VMOVSLDUP` accept a size suffix (`_128`
Expand Down
1 change: 1 addition & 0 deletions compiler/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ lib*.a
report.log
/jasmin.mlpack
/jasminc
/jazz2tex
1 change: 1 addition & 0 deletions compiler/.merlin
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ B _build/**

PKG apron
PKG batteries
PKG cmdliner
PKG menhirLib
PKG zarith
PKG apron
Expand Down
15 changes: 9 additions & 6 deletions compiler/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,17 @@ all: build
build: jasmin.mlpack native

define do-build
rm -f jasminc
$(OCAMLBUILD) "$(1)"
ln -sf "_build/$(1)" jasminc
$(RM) jasminc jazz2tex
$(OCAMLBUILD) "entry/jasminc.$(1)" "entry/jazz2tex.$(1)"
ln -sf "_build/entry/jasminc.$(1)" jasminc
ln -sf "_build/entry/jazz2tex.$(1)" jazz2tex
endef

byte:
$(call do-build,entry/jasminc.byte)
$(call do-build,byte)

native:
$(call do-build,entry/jasminc.native)
$(call do-build,native)

jasmin.mlpack: __force__
( echo '# GENERATED - EDIT jasmin.mlpack.in'; \
Expand Down Expand Up @@ -85,9 +86,11 @@ clean:
install:
$(INSTALL) -m 0755 -d $(DESTDIR)$(BINDIR)
$(INSTALL) -m 0755 -T jasminc.native $(DESTDIR)$(BINDIR)/jasminc
$(INSTALL) -m 0755 -T jazz2tex.native $(DESTDIR)$(BINDIR)/jazz2tex

uninstall:
rm -f $(DESTDIR)$(BINDIR)/jasminc
$(RM) $(DESTDIR)$(BINDIR)/jasminc
$(RM) $(DESTDIR)$(BINDIR)/jazz2tex

# --------------------------------------------------------------------
dist: $(DISTDIR).tgz
Expand Down
3 changes: 2 additions & 1 deletion compiler/_tags
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ true : bin_annot
<CIL/*.{ml,mli}>: warn_-20, warn_-32, warn_-33, warn_-34

# --------------------------------------------------------------------
<entry/*>: package(batteries, menhirLib, zarith, apron.octMPQ, apron.ppl, apron.boxMPQ, yojson)
<entry/jasminc.*>: package(batteries, menhirLib, zarith, apron.octMPQ, apron.ppl, apron.boxMPQ, yojson)
<entry/jazz2tex.*>: package(batteries, cmdliner, menhirLib, zarith, apron.ppl, apron.boxMPQ, apron.octMPQ, yojson)
7 changes: 5 additions & 2 deletions compiler/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ stdenv.mkDerivation {
name = "jasmin-0";
src = ./.;
buildInputs = [ mpfr ppl ]
++ (with ocamlPackages; [ ocaml findlib ocamlbuild apron batteries camlidl menhir menhirLib zarith yojson])
++ (with ocamlPackages; [ ocaml findlib ocamlbuild apron batteries camlidl cmdliner menhir menhirLib zarith yojson])
;

installPhase = ''
mkdir -p $out/bin
cp _build/entry/jasminc.native $out/bin/jasminc
for p in jasminc jazz2tex
do
cp _build/entry/$p.native $out/bin/$p
done
'';
}
69 changes: 69 additions & 0 deletions compiler/entry/jazz2tex.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
module J = Jasmin

type arch = Amd64 | CortexM

let parse_and_print arch call_conv =
let module A =
J.Arch_full.Arch_from_Core_arch
((val match arch with
| Amd64 ->
J.CoreArchFactory.core_arch_x86 ~use_lea:false ~use_set0:false
call_conv
| CortexM -> (module J.CoreArchFactory.Core_arch_ARM))) in
fun output file ->
let _, _, ast = J.Compile.parse_file A.reg_size A.asmOp_sopn file in
let out, close =
match output with
| None -> (stdout, ignore)
| Some latexfile -> (open_out latexfile, close_out)
in
let fmt = Format.formatter_of_out_channel out in
Format.fprintf fmt "%a@." J.Latex_printer.pp_prog ast;
close out

open Cmdliner

let file =
let doc = "The Jasmin source file to pretty-print" in
Arg.(required & pos 0 (some non_dir_file) None & info [] ~docv:"JAZZ" ~doc)

let output =
let doc =
"The file in which the result is written (instead of the standard output)"
in
Arg.(value & opt (some string) None & info [ "o"; "output" ] ~docv:"TEX" ~doc)

let arch =
let alts = [ ("x86-64", Amd64); ("arm-m4", CortexM) ] in
let doc =
Format.asprintf "The target architecture (%s)" (Arg.doc_alts_enum alts)
in
let arch = Arg.enum alts in
Arg.(value & opt arch Amd64 & info [ "arch" ] ~doc)

let call_conv =
let alts =
[ ("linux", J.Glob_options.Linux); ("windows", J.Glob_options.Windows) ]
in
let doc = Format.asprintf "Undocumented (%s)" (Arg.doc_alts_enum alts) in
let call_conv = Arg.enum alts in
Arg.(
value
& opt call_conv J.Glob_options.Linux
& info [ "call-conv"; "cc" ] ~docv:"OS" ~doc)

let () =
let doc = "Pretty-print Jasmin source programs into LATEX" in
let man =
[
`S Manpage.s_environment;
Manpage.s_environment_intro;
`I ("OCAMLRUNPARAM", "This is an OCaml program");
`I ("JASMINPATH", "To resolve $(i,require) directives");
]
in
let info =
Cmd.info "jazz2tex" ~version:J.Glob_options.version_string ~doc ~man
in
Cmd.v info Term.(const parse_and_print $ arch $ call_conv $ output $ file)
|> Cmd.eval |> exit
2 changes: 2 additions & 0 deletions compiler/opam
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ build: [
install: [
mkdir -p "%{prefix}%/bin"
cp "_build/entry/jasminc.native" "%{prefix}%/bin/jasminc"
cp "_build/entry/jazz2tex.native" "%{prefix}%/bin/jazz2tex"
]
depends: [
"ocaml" { >= "4.10" & build }
"batteries" {>= "3.4"}
"cmdliner" { build }
"menhir" {>= "20160825" & build }
"menhirLib"
"camlidl"
Expand Down
1 change: 1 addition & 0 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ stdenv.mkDerivation {
++ optionals testDeps ([ curl.bin oP.apron.out libllvm ] ++ (with python3Packages; [ python pyyaml ]))
++ optionals ocamlDeps ([ mpfr ppl ] ++ (with oP; [
ocaml findlib ocamlbuild
cmdliner
(batteries.overrideAttrs (o: { doCheck = false; }))
menhir (oP.menhirLib or null) zarith camlidl apron yojson ]))
++ optionals devTools (with oP; [ merlin ])
Expand Down
1 change: 1 addition & 0 deletions opam
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ install: [
depends: [
"ocaml" { >= "4.10" & build }
"batteries" {>= "3.4"}
"cmdliner" { build }
"menhir" {>= "20160825" & build }
"menhirLib"
"camlidl"
Expand Down

0 comments on commit 156fdc6

Please sign in to comment.