Skip to content

Commit d8ff903

Browse files
phatedospencer
andauthored
fix(compiler): Preserve all configs when compiling (#1207)
chore(compiler)!: Add interface for compile module to hide resume Co-authored-by: Oscar Spencer <oscar@grain-lang.org>
1 parent 725b37b commit d8ff903

File tree

2 files changed

+94
-2
lines changed

2 files changed

+94
-2
lines changed

compiler/src/compile.re

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,9 @@ let compile_string =
303303
cstate_filename: name,
304304
cstate_outfile: outfile,
305305
};
306-
compile_resume(~is_root_file, ~hook?, cstate);
306+
Grain_utils.Config.preserve_all_configs(() =>
307+
compile_resume(~is_root_file, ~hook?, cstate)
308+
);
307309
};
308310

309311
let compile_file =
@@ -317,7 +319,9 @@ let compile_file =
317319
cstate_filename: Some(filename),
318320
cstate_outfile: outfile,
319321
};
320-
compile_resume(~is_root_file, ~hook?, cstate);
322+
Grain_utils.Config.preserve_all_configs(() =>
323+
compile_resume(~is_root_file, ~hook?, cstate)
324+
);
321325
};
322326

323327
let anf = Linearize.transl_anf_module;

compiler/src/compile.rei

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
open Grain_parsing;
2+
open Grain_typed;
3+
open Grain_middle_end;
4+
open Grain_codegen;
5+
open Grain_linking;
6+
7+
type input_source =
8+
| InputString(string)
9+
| InputFile(string);
10+
11+
type compilation_state_desc =
12+
| Initial(input_source)
13+
| Parsed(Parsetree.parsed_program)
14+
| WellFormed(Parsetree.parsed_program)
15+
| TypeChecked(Typedtree.typed_program)
16+
| TypedWellFormed(Typedtree.typed_program)
17+
| Linearized(Anftree.anf_program)
18+
| Optimized(Anftree.anf_program)
19+
| Mashed(Mashtree.mash_program)
20+
| Compiled(Compmod.compiled_program)
21+
| ObjectFileEmitted(Compmod.compiled_program)
22+
| Linked(Compmod.compiled_program)
23+
| Assembled;
24+
25+
type compilation_state = {
26+
cstate_desc: compilation_state_desc,
27+
cstate_filename: option(string),
28+
cstate_outfile: option(string),
29+
};
30+
31+
type compilation_action =
32+
| Continue(compilation_state)
33+
| Stop;
34+
35+
type error =
36+
| Cannot_parse_inline_flags(string)
37+
| Cannot_use_help_or_version;
38+
39+
exception InlineFlagsError(Location.t, error);
40+
41+
let default_output_filename: string => string;
42+
43+
let default_mashtree_filename: string => string;
44+
45+
let stop_after_parse: compilation_state => compilation_action;
46+
47+
let stop_after_well_formed: compilation_state => compilation_action;
48+
49+
let stop_after_typed: compilation_state => compilation_action;
50+
51+
let stop_after_typed_well_formed: compilation_state => compilation_action;
52+
53+
let stop_after_anf: compilation_state => compilation_action;
54+
55+
let stop_after_optimization: compilation_state => compilation_action;
56+
57+
let stop_after_mashed: compilation_state => compilation_action;
58+
59+
let stop_after_compiled: compilation_state => compilation_action;
60+
61+
let stop_after_object_file_emitted: compilation_state => compilation_action;
62+
63+
let stop_after_linked: compilation_state => compilation_action;
64+
65+
let stop_after_assembled: compilation_state => compilation_action;
66+
67+
let compile_string:
68+
(
69+
~is_root_file: bool=?,
70+
~hook: compilation_state => compilation_action=?,
71+
~name: string=?,
72+
~outfile: string=?,
73+
~reset: bool=?,
74+
string
75+
) =>
76+
compilation_state;
77+
78+
let compile_file:
79+
(
80+
~is_root_file: bool=?,
81+
~hook: compilation_state => compilation_action=?,
82+
~outfile: string=?,
83+
~reset: bool=?,
84+
string
85+
) =>
86+
compilation_state;
87+
88+
let save_mashed: (string, string) => unit;

0 commit comments

Comments
 (0)