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

Affichage correct de la trace de calcul #229

Merged
merged 16 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
49 changes: 22 additions & 27 deletions .github/workflows/binary-releases.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ name: binary-releases
on:
push:
branches: [master]
workflow_dispatch:

jobs:

create-release:
runs-on: ubuntu-latest
outputs:
Expand All @@ -20,47 +20,46 @@ jobs:
tag_name: ${{ github.run_number }}
release_name: Release ${{ github.run_number }}


macos-build:
runs-on: macos-latest
needs: create-release

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v2

- name: Opam modules cache
uses: actions/cache@v1
env:
- name: Opam modules cache
uses: actions/cache@v1
env:
cache-name: cache-opam-modules
with:
with:
path: ~/.opam
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('mlang.opam', 'Makefile') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-

- name: Set up OCaml
uses: ocaml/setup-ocaml@v2
with:
- name: Set up OCaml
uses: ocaml/setup-ocaml@v2
with:
ocaml-compiler: 4.11.2

- name: Install dependencies
run: |
brew install gmp mpfr
opam update
make init-without-switch
- name: Install dependencies
run: |
brew install gmp mpfr
opam update
make init-without-switch

- name: Make mlang binary
run: |
- name: Make mlang binary
run: |
eval $(opam env)
make build

- name: Upload release asset
uses: actions/upload-release-asset@v1
env:
- name: Upload release asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
with:
upload_url: ${{ needs.create-release.outputs.upload_url }}
asset_path: ./_build/default/src/main.exe
asset_name: mlang-macos-v${{ github.run_number }}.exe
Expand Down Expand Up @@ -95,19 +94,15 @@ jobs:
uses: ocaml/setup-ocaml@v2
with:
# Version of the OCaml compiler to initialise
ocaml-compiler: ocaml-variants.4.12.0+options,ocaml-option-flambda,ocaml-option-musl,ocaml-option-static
ocaml-compiler: 4.11.2

- name: Install dependencies
run: |
sudo apt update
sudo apt install m4 perl python3 clang git build-essential lzip libgmp-dev libmpfr-dev
wget https://ftp.gnu.org/gnu/gmp/gmp-6.2.1.tar.lz && tar xaf gmp-6.2.1.tar.lz
( cd gmp-6.2.1; CC=musl-gcc ./configure --prefix /tmp/gmp-prefix && make && make install )
wget https://www.mpfr.org/mpfr-4.1.0/mpfr-4.1.0.tar.xz && tar xaf mpfr-4.1.0.tar.xz
( cd mpfr-4.1.0; CC=musl-gcc ./configure --prefix /tmp/gmp-prefix -with-gmp=/tmp/gmp-prefix && make && make install )
eval $(opam env)
opam update
MPFR_PREFIX=/tmp/gmp-prefix GMP_PREFIX=/tmp/gmp-prefix make init-without-switch
make init-without-switch

- name: Make mlang binary
run: |
Expand Down
8 changes: 8 additions & 0 deletions compare_traces.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#! /bin/bash
DGFIP_TARGET_FLAGS=-g,-O,-k4,-t YEAR=2022 make compile_dgfip_c_backend -B
~/fuzzing-calculette/calculette/trunk/2022/AIT \
-f tests/2022/fuzzing/fuzzer_3469.m_test |& \
sed -e 's/\x1b\[[0-9;]*m//g' &> aif_trace.txt
NO_BINARY_COMPARE=1 ./examples/dgfip_c/ml_primitif/cal \
tests/2022/fuzzing/fuzzer_3469.m_test &> mlang_trace.txt
diff aif_trace.txt mlang_trace.txt -u > diff_trace.txt
12 changes: 0 additions & 12 deletions examples/dgfip_c/ml_primitif/c_driver_inline_4/var.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ int nb_penalite = NB_PENALITE;
int nb_restituee = NB_RESTITUEE;
int nb_enchaine = NB_ENCH;

int color = 37;
int typo = 0;

#ifdef FLG_DEBUG
int nb_err = NB_ERR;
#if NB_DEBUG_C <= 0
Expand Down Expand Up @@ -54,15 +51,6 @@ T_discord * une_verif(T_irdata *irdata, struct S_discord *(*proc)(T_irdata *irda
#endif /* FLG_MULTITHREAD */
}

int change_couleur(int couleur, int typographie) {
color = couleur;
typo = typographie;
return 0;
}

int get_couleur(void) {
return color;
}

struct S_discord * verif_saisie_cohe_primitive_isf(T_irdata *irdata, int appel) {
#ifdef FLG_MULTITHREAD
Expand Down
4 changes: 0 additions & 4 deletions examples/dgfip_c/ml_primitif/c_driver_inline_4/var.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,5 @@ extern int nb_verif;
#endif /* FLG_DEBUG || FLG_CONTROLE_IMMEDIAT */

extern T_discord *une_verif _PROTS((T_irdata *irdata, struct S_discord *(*proc)(T_irdata *irdata)));

extern int change_couleur(int couleur, int typographie);
extern int get_couleur(void);

#endif

13 changes: 0 additions & 13 deletions examples/dgfip_c/ml_primitif/c_driver_with_macro/var.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ int nb_penalite = NB_PENALITE;
int nb_restituee = NB_RESTITUEE;
int nb_enchaine = NB_ENCH;

int color = 37;
int typo = 0;

#ifdef FLG_DEBUG
int nb_err = NB_ERR;
#if NB_DEBUG_C <= 0
Expand Down Expand Up @@ -54,16 +51,6 @@ T_discord * une_verif(T_irdata *irdata, struct S_discord *(*proc)(T_irdata *irda
#endif /* FLG_MULTITHREAD */
}

int change_couleur(int couleur, int typographie) {
color = couleur;
typo = typographie;
return 0;
}

int get_couleur(void) {
return color;
}

struct S_discord * verif_saisie_cohe_primitive_isf(T_irdata *irdata, int appel) {
#ifdef FLG_MULTITHREAD
init_erreur(irdata);
Expand Down
3 changes: 0 additions & 3 deletions examples/dgfip_c/ml_primitif/c_driver_with_macro/var.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,5 @@ extern int nb_verif;

extern T_discord *une_verif _PROTS((T_irdata *irdata, struct S_discord *(*proc)(T_irdata *irdata)));

extern int change_couleur(int couleur, int typographie);
extern int get_couleur(void);

#endif

5 changes: 2 additions & 3 deletions makefiles/mlang.mk
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,12 @@ dune: FORCE
ifeq ($(call is_in,),)
$(call make_in,,$@)
else
dune build $(DUNE_OPTIONS)
LINKING_MODE=$(LINKING_MODE) dune build $(DUNE_OPTIONS)
endif

build: FORCE | format dune

# Run only in an opam switch with musl and static options activated
build-static: DUNE_OPTIONS+=--profile=static
build-static: LINKING_MODE=static
build-static: FORCE build

##################################################
Expand Down
11 changes: 8 additions & 3 deletions src/dune
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
(env
(static
(ocamlopt_flags
(-ccopt -static -O3)))
(dev
(flags
(:standard -warn-error -A))))

(rule
(with-stdout-to
linking-flags-mlang.sexp
(run ./gen-linking-flags.sh %{env:LINKING_MODE=} %{ocaml-config:system})))

(executable
(name main)
(package mlang)
(public_name mlang)
(flags
(:standard
(:include linking-flags-mlang.sexp)))
(libraries mlang))
41 changes: 41 additions & 0 deletions src/gen-linking-flags.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/sh
set -ue

# Copied on https://ocamlpro.com/fr/blog/2021_09_02_generating_static_and_portable_executables_with_ocaml/

LINKING_MODE="$1"
OS="$2"
FLAGS=
CCLIB=

case "$LINKING_MODE" in
'')
;; # No extra flags needed
static)
case "$OS" in
linux)
FLAGS="-noautolink"
CCLIB="-Wl,-Bstatic -lgmp_caml -lmpfr -lgmp -lnums \
-lthreadsnat -lparmap_stubs -lANSITerminal_stubs \
-Wl,-Bdynamic -lpthread -lunix"
LIBS=""
OCAML_LIBS="camlidl"
for lib in $LIBS; do
CCLIB="$CCLIB $(pkg-config $lib --variable libdir)/$lib.a"
done
for lib in $OCAML_LIBS; do
CCLIB="$CCLIB $(ocamlfind query $lib)/lib$lib.a"
done;;
*)
echo "No known static compilation flags for '$OS'" >&2
exit 1
esac;;
*)
echo "Invalid linking mode '$LINKING_MODE'" >&2
exit 2
esac

echo '('
for f in $FLAGS; do echo " $f"; done
for f in $CCLIB; do echo " -cclib $f"; done
echo ')'
9 changes: 6 additions & 3 deletions src/mlang/backend_compilers/bir_to_dgfip_c.ml
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,9 @@ let generate_m_assign (dgfip_flags : Dgfip_options.flags)
def def_var
(D.format_assign dgfip_flags var_indexes val_var)
value val_var;
if dgfip_flags.flg_trace then
let var = Bir.var_to_mir var in
(* If the trace flag is set, we print the value of all non-temp variables *)
let var = Bir.var_to_mir var in
if dgfip_flags.flg_trace && not var.Mir.Variable.is_temp then
Format.fprintf oc "@;aff2(\"%s\", irdata, %s);"
(Pos.unmark var.Mir.Variable.name)
(Dgfip_varid.gen_access_pos_from_start var_indexes var)
Expand Down Expand Up @@ -631,11 +632,13 @@ let generate_target (dgfip_flags : Dgfip_options.flags) (program : Bir.program)
(var_indexes : Dgfip_varid.var_id_map) (oc : Format.formatter)
((f, ret_type) : Bir.function_name * bool) =
let { tmp_vars; stmts; is_verif; _ } = Mir.TargetMap.find f program.targets in
Format.fprintf oc "@[<v 2>%a{@,%a%a%s@]@,}@,"
Format.fprintf oc "@[<v 2>%a{@,%a%s@\n%a%s@\n%s@]@,}@,"
(generate_target_prototype false is_verif)
f generate_var_tmp_decls tmp_vars
(if dgfip_flags.flg_trace then "aff1(\"debut " ^ f ^ "\\n\") ;" else "")
(generate_stmts dgfip_flags program var_indexes)
stmts
(if dgfip_flags.flg_trace then "aff1(\"fin " ^ f ^ "\\n\") ;" else "")
(if ret_type then
{|
#ifdef FLG_MULTITHREAD
Expand Down
10 changes: 6 additions & 4 deletions src/mlang/backend_compilers/decoupledExpr.ml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ type offset =
| None

let rec generate_variable (vm : Dgfip_varid.var_id_map) (offset : offset)
?(def_flag = false) ?(debug_flag = false) (var : Bir.variable) : string =
?(def_flag = false) ?(trace_flag = false) (var : Bir.variable) : string =
let mvar = Bir.var_to_mir var in
try
match offset with
Expand All @@ -25,7 +25,9 @@ let rec generate_variable (vm : Dgfip_varid.var_id_map) (offset : offset)
if def_flag then Dgfip_varid.gen_access_def vm mvar offset
else
let access_val = Dgfip_varid.gen_access_val vm mvar offset in
if debug_flag then
(* When the trace flag is present, we print the value of the
non-temporary variable being used *)
if trace_flag && not mvar.Mir.Variable.is_temp then
let vn = Pos.unmark mvar.Mir.Variable.name in
let pos_tgv = Dgfip_varid.gen_access_pos_from_start vm mvar in
Format.asprintf "(aff3(\"%s\",irdata, %s), %s)" vn pos_tgv
Expand Down Expand Up @@ -429,7 +431,7 @@ let format_expr_var (dgfip_flags : Dgfip_options.flags)
| M (var, offset, df) ->
let def_flag = df = Def in
Format.fprintf fmt "%s"
(generate_variable ~debug_flag:dgfip_flags.flg_trace vm offset ~def_flag
(generate_variable ~trace_flag:dgfip_flags.flg_trace vm offset ~def_flag
var)

let rec format_dexpr (dgfip_flags : Dgfip_options.flags)
Expand Down Expand Up @@ -488,7 +490,7 @@ let rec format_dexpr (dgfip_flags : Dgfip_options.flags)
| Daccess (var, dflag, de) ->
Format.fprintf fmt "(%s[(int)%a])"
(generate_variable ~def_flag:(dflag = Def)
~debug_flag:dgfip_flags.flg_trace vm PassPointer var)
~trace_flag:dgfip_flags.flg_trace vm PassPointer var)
format_dexpr de
| Dite (dec, det, dee) ->
Format.fprintf fmt "@[<hov 2>(%a ?@ %a@ : %a@])" format_dexpr dec
Expand Down
2 changes: 1 addition & 1 deletion src/mlang/backend_compilers/decoupledExpr.mli
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ val generate_variable :
Dgfip_varid.var_id_map ->
offset ->
?def_flag:bool ->
?debug_flag:bool ->
?trace_flag:bool ->
Bir.variable ->
string

Expand Down
Loading
Loading