@@ -17,6 +17,13 @@ open Cmm
17
17
open Cmm_helpers
18
18
open Arch
19
19
20
+ type error = Bad_immediate of string
21
+
22
+ exception Error of error
23
+
24
+ let bad_immediate fmt =
25
+ Format. kasprintf (fun msg -> raise (Error (Bad_immediate msg))) fmt
26
+
20
27
let four_args name args =
21
28
match args with
22
29
| [arg1; arg2; arg3; arg4] -> arg1, arg2, arg3, arg4
@@ -193,14 +200,14 @@ let rec const_float_args n args name =
193
200
match n, args with
194
201
| 0 , [] -> []
195
202
| n , Cconst_float (f , _ ) :: args -> f :: const_float_args (n - 1 ) args name
196
- | _ -> Misc. fatal_errorf " Invalid float constant arguments for %s" name
203
+ | _ -> bad_immediate " Did not find constant float arguments for %s" name
197
204
198
205
(* Assumes untagged int or unboxed int32, always representable by int63 *)
199
206
let rec const_int_args n args name =
200
207
match n, args with
201
208
| 0 , [] -> []
202
209
| n , Cconst_int (i , _ ) :: args -> i :: const_int_args (n - 1 ) args name
203
- | _ -> Misc. fatal_errorf " Invalid int constant arguments for %s" name
210
+ | _ -> bad_immediate " Did not find constant int arguments for %s" name
204
211
205
212
(* Assumes unboxed int64: no tag, comes as Cconst_int when representable by
206
213
int63, otherwise we get Cconst_natint *)
@@ -211,23 +218,23 @@ let rec const_int64_args n args name =
211
218
Int64. of_int i :: const_int64_args (n - 1 ) args name
212
219
| n , Cconst_natint (i , _ ) :: args ->
213
220
Int64. of_nativeint i :: const_int64_args (n - 1 ) args name
214
- | _ -> Misc. fatal_errorf " Invalid int64 constant arguments for %s" name
221
+ | _ -> bad_immediate " Did not find constant int64 arguments for %s" name
215
222
216
223
let int64_of_int8 i =
217
224
(* CR mslater: (SIMD) replace once we have unboxed int8 *)
218
225
if i < 0 || i > 0xff
219
- then Misc. fatal_errorf " Int8 constant must be in [0x0,0xff]: %016x" i;
226
+ then bad_immediate " Int8 constant not in range [0x0,0xff]: 0x %016x" i;
220
227
Int64. of_int i
221
228
222
229
let int64_of_int16 i =
223
230
(* CR mslater: (SIMD) replace once we have unboxed int16 *)
224
231
if i < 0 || i > 0xffff
225
- then Misc. fatal_errorf " Int16 constant must be in [0x0,0xffff]: %016x" i;
232
+ then bad_immediate " Int16 constant not in range [0x0,0xffff]: 0x %016x" i;
226
233
Int64. of_int i
227
234
228
235
let int64_of_int32 i =
229
236
if i < Int32. to_int Int32. min_int || i > Int32. to_int Int32. max_int
230
- then Misc. fatal_errorf " Constant was not an int32: %016x" i;
237
+ then bad_immediate " Int32 constant not in range [0x0,0xffffffff]: 0x %016x" i;
231
238
Int64. of_int i |> Int64. logand 0xffffffffL
232
239
233
240
let int64_of_float32 f =
@@ -749,3 +756,11 @@ let extcall ~dbg ~returns ~alloc ~is_c_builtin ~effects ~coeffects ~ty_args name
749
756
| Some op -> op
750
757
| None -> default
751
758
else default
759
+
760
+ let report_error ppf = function
761
+ | Bad_immediate msg -> Format. pp_print_string ppf msg
762
+
763
+ let () =
764
+ Location. register_error_of_exn (function
765
+ | Error err -> Some (Location. error_of_printer_file report_error err)
766
+ | _ -> None )
0 commit comments