Skip to content

Commit 71cdc77

Browse files
authored
Merge pull request #1095 from Nadrieril/multi-target
Support multi-target compilation
2 parents ee26ef7 + 319d43e commit 71cdc77

59 files changed

Lines changed: 2280 additions & 261 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

charon-ml/src/CharonVersion.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
(* This is an automatically generated file, generated from `charon/Cargo.toml`. *)
22
(* To re-generate this file, rune `make` in the root directory *)
3-
let supported_charon_version = "0.1.178"
3+
let supported_charon_version = "0.1.179"

charon-ml/src/GAst.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ type target_info = { target_pointer_size : int; is_little_endian : bool }
4747
type 'fun_body gcrate = {
4848
name : string;
4949
options : cli_options;
50-
target_information : target_info;
50+
target_information : (string * target_info) list;
5151
declarations : declaration_group list;
5252
type_decls : type_decl TypeDeclId.Map.t;
5353
fun_decls : 'fun_body gfun_decl FunDeclId.Map.t;

charon-ml/src/GAstOfJson.ml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,11 @@ and gtranslated_crate_of_json
112112

113113
let* crate_name = string_of_json ctx crate_name in
114114
let* options = cli_options_of_json ctx options in
115-
let* target_information = target_info_of_json ctx target_info in
115+
let* target_information =
116+
list_of_json
117+
(key_value_pair_of_json string_of_json target_info_of_json)
118+
ctx target_info
119+
in
116120
let* _item_names =
117121
list_of_json
118122
(key_value_pair_of_json item_id_of_json name_of_json)
@@ -140,14 +144,17 @@ and gtranslated_crate_of_json
140144
in
141145
let* unit_metadata = global_decl_ref_of_json ctx unit_metadata in
142146
let* ordered_decls =
143-
list_of_json declaration_group_of_json ctx ordered_decls
147+
option_of_json
148+
(list_of_json declaration_group_of_json)
149+
ctx ordered_decls
144150
in
145151

146152
let type_decls = TypeDeclId.map_of_indexed_list type_decls in
147153
let fun_decls = FunDeclId.map_of_indexed_list fun_decls in
148154
let global_decls = GlobalDeclId.map_of_indexed_list global_decls in
149155
let trait_decls = TraitDeclId.map_of_indexed_list trait_decls in
150156
let trait_impls = TraitImplId.map_of_indexed_list trait_impls in
157+
let ordered_decls = Option.value ordered_decls ~default:[] in
151158

152159
Ok
153160
{

charon-ml/src/GAstUtils.ml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@ open Types
22
open TypesUtils
33
open GAst
44

5+
let get_target_information crate =
6+
match crate.target_information with
7+
| [ (_, info) ] -> info
8+
| _ ->
9+
failwith "`get_target_information` can't be used in a multi-layout crate"
10+
511
(** Small utility: list the transitive parents of a region var group. We don't
612
do that in an efficient manner, but it doesn't matter.
713

charon-ml/src/LlbcAstUtils.ml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,11 @@ class ['self] map_crate =
153153
in
154154
let name = self#visit_string env name in
155155
let options = self#visit_cli_options env options in
156-
let target_information = self#visit_target_info env target_information in
156+
let target_information =
157+
List.map
158+
(fun (name, info) -> (name, self#visit_target_info env info))
159+
target_information
160+
in
157161
let declarations =
158162
List.map (self#visit_declaration_group env) declarations
159163
in

charon-ml/src/NameMatcher.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -978,7 +978,7 @@ and path_elem_with_generic_args_to_pattern (ctx : 'fun_body ctx)
978978
| Some args -> [ PIdent (s, d, args) ]
979979
end
980980
| PeImpl impl -> [ impl_elem_to_pattern ctx c impl ]
981-
| PeInstantiated _ ->
981+
| PeInstantiated _ | PeTarget _ ->
982982
(* In pattern generation, we skip monomorphized elements since patterns
983983
are meant to match the logical structure, not the instantiation details *)
984984
[]

charon-ml/src/PrintTypes.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,7 @@ and path_elem_to_string (env : 'a fmt_env) (e : path_elem) : string =
480480
let env = fmt_env_push_generics_and_preds env binder.binder_params in
481481
let explicits, _ = generic_args_to_strings env binder.binder_value in
482482
"<" ^ String.concat ", " explicits ^ ">"
483+
| PeTarget target -> target
483484

484485
and name_to_string (env : 'a fmt_env) (n : name) : string =
485486
let name = List.map (path_elem_to_string env) n in

charon-ml/src/TypesUtils.ml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,11 @@ let generic_params_lengths (args : generic_params) : int * int * int * int =
320320
variant[TagEncoding::Niche::untagged_variant]. *)
321321
let get_variant_from_tag ptr_size ty_decl (tag : Values.scalar_value) =
322322
let ( let* ) = Option.bind in
323-
let* layout = ty_decl.layout in
323+
let layout =
324+
match ty_decl.layout with
325+
| [ (_, layout) ] -> layout
326+
| _ -> failwith "get_variant_from_tag can't be used in a multi-layout crate"
327+
in
324328
let* discr_layout = layout.discriminant_layout in
325329
match ty_decl.kind with
326330
| Enum variants -> begin

charon-ml/src/generated/Generated_GAst.ml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,11 @@ type cli_options = {
402402
(** The MIR stage to extract. This is only relevant for the current crate;
403403
for dpendencies only MIR optimized is available. *)
404404
rustc_args : string list; (** Extra flags to pass to rustc. *)
405+
targets : string list;
406+
(** A list of target architectures to translate for. Charon will run the
407+
compiler once for each target and aggregate the results, which is
408+
useful if the code includes [#[cfg(..)]] filters. Warning: this is an
409+
initial implementation which is extremely slow. *)
405410
monomorphize : bool;
406411
(** Monomorphize the items encountered when possible. Generic items found
407412
in the crate are skipped. To only translate a particular call graph,

charon-ml/src/generated/Generated_GAstOfJson.ml

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,7 @@ and cli_options_of_json (ctx : of_json_ctx) (js : json) :
414414
("skip_borrowck", skip_borrowck);
415415
("mir", mir);
416416
("rustc_args", rustc_args);
417+
("targets", targets);
417418
("monomorphize", monomorphize);
418419
("monomorphize_mut", monomorphize_mut);
419420
("start_from", start_from);
@@ -456,6 +457,7 @@ and cli_options_of_json (ctx : of_json_ctx) (js : json) :
456457
let* skip_borrowck = bool_of_json ctx skip_borrowck in
457458
let* mir = option_of_json mir_level_of_json ctx mir in
458459
let* rustc_args = list_of_json string_of_json ctx rustc_args in
460+
let* targets = list_of_json string_of_json ctx targets in
459461
let* monomorphize = bool_of_json ctx monomorphize in
460462
let* monomorphize_mut =
461463
option_of_json monomorphize_mut_of_json ctx monomorphize_mut
@@ -515,6 +517,7 @@ and cli_options_of_json (ctx : of_json_ctx) (js : json) :
515517
skip_borrowck;
516518
mir;
517519
rustc_args;
520+
targets;
518521
monomorphize;
519522
monomorphize_mut;
520523
start_from;
@@ -1006,17 +1009,17 @@ and generic_args_of_json (ctx : of_json_ctx) (js : json) :
10061009
("trait_refs", trait_refs);
10071010
] ->
10081011
let* regions =
1009-
index_map_of_json region_id_of_json region_of_json ctx regions
1012+
indexed_map_of_json region_id_of_json region_of_json ctx regions
10101013
in
10111014
let* types =
1012-
index_map_of_json type_var_id_of_json ty_of_json ctx types
1015+
indexed_map_of_json type_var_id_of_json ty_of_json ctx types
10131016
in
10141017
let* const_generics =
1015-
index_map_of_json const_generic_var_id_of_json constant_expr_of_json
1018+
indexed_map_of_json const_generic_var_id_of_json constant_expr_of_json
10161019
ctx const_generics
10171020
in
10181021
let* trait_refs =
1019-
index_map_of_json trait_clause_id_of_json trait_ref_of_json ctx
1022+
indexed_map_of_json trait_clause_id_of_json trait_ref_of_json ctx
10201023
trait_refs
10211024
in
10221025
Ok ({ regions; types; const_generics; trait_refs } : generic_args)
@@ -1037,17 +1040,17 @@ and generic_params_of_json (ctx : of_json_ctx) (js : json) :
10371040
("trait_type_constraints", trait_type_constraints);
10381041
] ->
10391042
let* regions =
1040-
index_map_of_json region_id_of_json region_param_of_json ctx regions
1043+
indexed_map_of_json region_id_of_json region_param_of_json ctx regions
10411044
in
10421045
let* types =
1043-
index_map_of_json type_var_id_of_json type_param_of_json ctx types
1046+
indexed_map_of_json type_var_id_of_json type_param_of_json ctx types
10441047
in
10451048
let* const_generics =
1046-
index_map_of_json const_generic_var_id_of_json
1049+
indexed_map_of_json const_generic_var_id_of_json
10471050
const_generic_param_of_json ctx const_generics
10481051
in
10491052
let* trait_clauses =
1050-
index_map_of_json trait_clause_id_of_json trait_param_of_json ctx
1053+
indexed_map_of_json trait_clause_id_of_json trait_param_of_json ctx
10511054
trait_clauses
10521055
in
10531056
let* regions_outlive =
@@ -1063,7 +1066,7 @@ and generic_params_of_json (ctx : of_json_ctx) (js : json) :
10631066
ctx types_outlive
10641067
in
10651068
let* trait_type_constraints =
1066-
index_map_of_json trait_type_constraint_id_of_json
1069+
indexed_map_of_json trait_type_constraint_id_of_json
10671070
(region_binder_of_json trait_type_constraint_of_json)
10681071
ctx trait_type_constraints
10691072
in
@@ -1156,7 +1159,7 @@ and impl_elem_of_json (ctx : of_json_ctx) (js : json) :
11561159
Ok (ImplElemTrait trait)
11571160
| _ -> Error "")
11581161

1159-
and index_map_of_json :
1162+
and indexed_map_of_json :
11601163
'a0 'a1.
11611164
(of_json_ctx -> json -> ('a0, string) result) ->
11621165
(of_json_ctx -> json -> ('a1, string) result) ->
@@ -1171,6 +1174,21 @@ and index_map_of_json :
11711174
Ok (List.filter_map (fun x -> x) list)
11721175
| _ -> Error "")
11731176

1177+
and index_map_of_json :
1178+
'a0 'a1 'a2.
1179+
(of_json_ctx -> json -> ('a0, string) result) ->
1180+
(of_json_ctx -> json -> ('a1, string) result) ->
1181+
(of_json_ctx -> json -> ('a2, string) result) ->
1182+
of_json_ctx ->
1183+
json ->
1184+
(('a0 * 'a1) list, string) result =
1185+
fun arg0_of_json arg1_of_json arg2_of_json ctx js ->
1186+
combine_error_msgs js __FUNCTION__
1187+
(match js with
1188+
| json ->
1189+
list_of_json (key_value_pair_of_json arg0_of_json arg1_of_json) ctx json
1190+
| _ -> Error "")
1191+
11741192
and index_vec_of_json :
11751193
'a0 'a1.
11761194
(of_json_ctx -> json -> ('a0, string) result) ->
@@ -1314,7 +1332,7 @@ and item_source_of_json (ctx : of_json_ctx) (js : json) :
13141332
index_vec_of_json field_id_of_json v_table_field_of_json ctx field_map
13151333
in
13161334
let* supertrait_map =
1317-
index_map_of_json trait_clause_id_of_json
1335+
indexed_map_of_json trait_clause_id_of_json
13181336
(option_of_json field_id_of_json)
13191337
ctx supertrait_map
13201338
in
@@ -1538,6 +1556,9 @@ and path_elem_of_json (ctx : of_json_ctx) (js : json) :
15381556
box_of_json (binder_of_json generic_args_of_json) ctx instantiated
15391557
in
15401558
Ok (PeInstantiated instantiated)
1559+
| `Assoc [ ("Target", target) ] ->
1560+
let* target = string_of_json ctx target in
1561+
Ok (PeTarget target)
15411562
| _ -> Error "")
15421563

15431564
and place_of_json (ctx : of_json_ctx) (js : json) : (place, string) result =
@@ -1671,7 +1692,7 @@ and region_binder_of_json :
16711692
(match js with
16721693
| `Assoc [ ("regions", regions); ("skip_binder", skip_binder) ] ->
16731694
let* binder_regions =
1674-
index_map_of_json region_id_of_json region_param_of_json ctx regions
1695+
indexed_map_of_json region_id_of_json region_param_of_json ctx regions
16751696
in
16761697
let* binder_value = arg0_of_json ctx skip_binder in
16771698
Ok ({ binder_regions; binder_value } : _ region_binder)
@@ -1884,7 +1905,7 @@ and trait_assoc_ty_of_json (ctx : of_json_ctx) (js : json) :
18841905
let* attr_info = attr_info_of_json ctx attr_info in
18851906
let* default = option_of_json trait_assoc_ty_impl_of_json ctx default in
18861907
let* implied_clauses =
1887-
index_map_of_json trait_clause_id_of_json trait_param_of_json ctx
1908+
indexed_map_of_json trait_clause_id_of_json trait_param_of_json ctx
18881909
implied_clauses
18891910
in
18901911
Ok ({ name; attr_info; default; implied_clauses } : trait_assoc_ty)
@@ -1925,7 +1946,7 @@ and trait_decl_of_json (ctx : of_json_ctx) (js : json) :
19251946
let* item_meta = item_meta_of_json ctx item_meta in
19261947
let* generics = generic_params_of_json ctx generics in
19271948
let* implied_clauses =
1928-
index_map_of_json trait_clause_id_of_json trait_param_of_json ctx
1949+
indexed_map_of_json trait_clause_id_of_json trait_param_of_json ctx
19291950
implied_clauses
19301951
in
19311952
let* consts = list_of_json trait_assoc_const_of_json ctx consts in
@@ -1988,7 +2009,7 @@ and trait_impl_of_json (ctx : of_json_ctx) (js : json) :
19882009
let* impl_trait = trait_decl_ref_of_json ctx impl_trait in
19892010
let* generics = generic_params_of_json ctx generics in
19902011
let* implied_trait_refs =
1991-
index_map_of_json trait_clause_id_of_json trait_ref_of_json ctx
2012+
indexed_map_of_json trait_clause_id_of_json trait_ref_of_json ctx
19922013
implied_trait_refs
19932014
in
19942015
let* consts =
@@ -2131,7 +2152,7 @@ and trait_ref_kind_of_json (ctx : of_json_ctx) (js : json) :
21312152
] ->
21322153
let* builtin_data = builtin_impl_data_of_json ctx builtin_data in
21332154
let* parent_trait_refs =
2134-
index_map_of_json trait_clause_id_of_json trait_ref_of_json ctx
2155+
indexed_map_of_json trait_clause_id_of_json trait_ref_of_json ctx
21352156
parent_trait_refs
21362157
in
21372158
let* types =
@@ -2244,7 +2265,9 @@ and type_decl_of_json (ctx : of_json_ctx) (js : json) :
22442265
let* generics = generic_params_of_json ctx generics in
22452266
let* src = item_source_of_json ctx src in
22462267
let* kind = type_decl_kind_of_json ctx kind in
2247-
let* layout = option_of_json layout_of_json ctx layout in
2268+
let* layout =
2269+
index_map_of_json string_of_json layout_of_json int_of_json ctx layout
2270+
in
22482271
let* ptr_metadata = ptr_metadata_of_json ctx ptr_metadata in
22492272
let* repr = option_of_json repr_options_of_json ctx repr in
22502273
Ok

0 commit comments

Comments
 (0)