diff options
| author | Alasdair | 2018-07-05 20:57:44 +0100 |
|---|---|---|
| committer | Alasdair | 2018-07-05 21:02:08 +0100 |
| commit | f62edee6988476ed8ba78424c870461ac8d44256 (patch) | |
| tree | b38cfadc19babf0739f27cb468a72f39f3e0c3ab /src | |
| parent | 9a0cbbedbe281807f70bf2206756624315096642 (diff) | |
Fix equality comparisons for structs
Add a test case in test/c/eq_struct.sail. Ensure that the macro EQUAL(type) will always give a valid equality function for any
builtin type in sail.h.
Diffstat (limited to 'src')
| -rw-r--r-- | src/c_backend.ml | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/src/c_backend.ml b/src/c_backend.ml index 6f1379e3..6097e996 100644 --- a/src/c_backend.ml +++ b/src/c_backend.ml @@ -2120,7 +2120,19 @@ let codegen_type_def ctx = function rbrace in let codegen_eq = - string (Printf.sprintf "static bool eq_%s(struct %s op1, struct %s op2) { return true; }" (sgen_id id) (sgen_id id) (sgen_id id)) + let codegen_eq_test (id, ctyp) = + if is_stack_ctyp ctyp then + string (Printf.sprintf "op1.%s == op2.%s" (sgen_id id) (sgen_id id)) + else + string (Printf.sprintf "EQUAL(%s)(op1.%s, op2.%s)" (sgen_ctyp_name ctyp) (sgen_id id) (sgen_id id)) + in + string (Printf.sprintf "static bool EQUAL(%s)(struct %s op1, struct %s op2)" (sgen_id id) (sgen_id id) (sgen_id id)) + ^^ space + ^^ surround 2 0 lbrace + (string "return" ^^ space + ^^ separate_map (string " && ") codegen_eq_test ctors + ^^ string ";") + rbrace in (* Generate the struct and add the generated functions *) let codegen_ctor (id, ctyp) = |
