Skip to content

Commit 41430e2

Browse files
committed
Add Byte variant to Ctype
Needs to be extended with a ternary argument (signed, unsigned, neither) to reflect how to treat it in certain places, but assuming (Integer Char) and signed for now.
1 parent 881feae commit 41430e2

21 files changed

Lines changed: 109 additions & 5 deletions

frontend/model/ail/ailTypesAux.lem

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,8 @@ let rec is_complete sigm ty =
257257
| Nothing ->
258258
false
259259
end
260+
| Byte ->
261+
true
260262
end
261263

262264
(* STD §6.2.5#1, sentence 4 *)
@@ -1263,6 +1265,8 @@ match ty with
12631265
false
12641266
| Union _ ->
12651267
false
1268+
| Byte ->
1269+
false
12661270
end
12671271

12681272

frontend/model/ail/ailWf.lem

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ let rec wf_type sigm (Ctype _ ty) =
114114
return ()
115115
| Union _ ->
116116
return ()
117+
| Byte ->
118+
return ()
117119
(*
118120
| Builtin _ ->
119121
return () *)

frontend/model/ail/genTypes.lem

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ type genType =
2626
| GenStruct of ail_identifier
2727
| GenUnion of ail_identifier
2828
| GenAtomic of genType
29+
| GenByte
2930

3031
val signedInt_gty: genType
3132
let signedInt_gty =
@@ -126,6 +127,8 @@ let rec eq_genType gty1 gty2 =
126127
7
127128
| GenAtomic _ ->
128129
8
130+
| GenByte ->
131+
9
129132
end in
130133
match (gty1, gty2) with
131134
| (GenBasic gbty1, GenBasic gbty2 ) ->
@@ -209,6 +212,8 @@ match ty with
209212
GenStruct tag
210213
| Union tag ->
211214
GenUnion tag
215+
| Byte ->
216+
GenByte
212217
end
213218

214219
val inject_typeCategory: typeCategory -> genTypeCategory

frontend/model/ail/genTypesAux.lem

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,8 @@ let rec interpret_genType loc impl gty =
318318
| GenAtomic gty ->
319319
interpret_genType loc impl gty >>= fun ty ->
320320
ret (Atomic ty)
321+
| GenByte ->
322+
ret Byte
321323
end
322324

323325
val interpret_genTypeCategory: Loc.t -> IntegerImpl.implementation -> genTypeCategory -> errorM typeCategory
@@ -401,6 +403,8 @@ let is_complete sigm gty =
401403
| _ ->
402404
false
403405
end
406+
| GenByte ->
407+
true
404408
end
405409

406410
val is_incomplete: forall 'a. sigma 'a -> genType -> bool

frontend/model/cabs_to_ail.lem

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,8 @@ let rec wip tagDefs acc path_prefix (outer_path, outer_ty) (Ctype.Ctype _ cty) =
173173
| _ ->
174174
error "elemPathFromCtype_aux3, Union"
175175
end
176+
| Ctype.Byte ->
177+
(path_prefix, outer_path, outer_ty) :: acc
176178
end
177179

178180
val elemPathFromCtype3: bool -> map ail_identifier tag_definition -> Ctype.ctype -> list (init_path * init_path * Ctype.ctype)
@@ -422,6 +424,8 @@ let rec innerCtype tagDefs (Ctype.Ctype _ ty as cty) =
422424
| _ ->
423425
error "innerCtype: Union"
424426
end
427+
| Ctype.Byte ->
428+
error "innerCtype: Byte"
425429
end
426430

427431

frontend/model/cabs_to_ail_aux.lem

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,9 @@ let rec mk_zeroInit_aux tagDefs (Ctype.Ctype _ ty) =
151151
| _ ->
152152
error "[Cabs_to_ail.mk_zeroInit_aux] - internal ERROR: Union"
153153
end
154+
| Ctype.Byte ->
155+
(* TODO: check *)
156+
A.ConstantInteger (A.IConstant 0 A.Octal Nothing)
154157
end
155158
let mk_zeroInit tagDefs ty =
156159
A.AnnotatedExpression () [] Loc.unknown
@@ -253,6 +256,8 @@ let rec export_ctype (Ctype.Ctype annot ty_ as ty) =
253256
ty
254257
| Ctype.Union _ ->
255258
ty
259+
| Ctype.Byte ->
260+
ty
256261
end
257262

258263
val has_continue: cabs_statement -> bool

frontend/model/core_aux.lem

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ let rec core_object_type_of_ctype (Ctype _ ty) =
4747
Just (OTy_struct tag_sym)
4848
| Union tag_sym ->
4949
Just (OTy_union tag_sym)
50+
| Byte ->
51+
(* TODO add an OTy_byte? *)
52+
Just OTy_integer
5053
end
5154

5255
val oTy_of_bTy: core_base_type -> maybe core_object_type

frontend/model/ctype.lem

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ type ctype_ (*[name = "^\\([a-z A-Z]*_\\)?ty[0-9]*'?$"]*) =
5858
| Atomic of ctype
5959
| Struct of Symbol.sym
6060
| Union of Symbol.sym
61+
| Byte
6162
and ctype =
6263
Ctype of list Annot.annot * ctype_
6364

@@ -150,6 +151,8 @@ let rec ctypeEqual (Ctype _ ty1) (Ctype _ ty2) =
150151
7
151152
| Union _ ->
152153
8
154+
| Byte ->
155+
9
153156
end in
154157
let paramsEqual (qs1, ty1, b1) (qs2, ty2, b2) =
155158
qs1 = qs2 && ctypeEqual ty1 ty2 && b1 = b2 in

frontend/model/defacto_memory.lem

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,8 @@ let rec mkUnspec (Ctype _ ty) =
434434
| (Union tag_sym) ->
435435
let ((memb_ident, (_, _, _, ty)), _) = Ctype_aux.get_unionDef tag_sym in
436436
MVunion tag_sym memb_ident (mkUnspec ty)
437+
| Byte ->
438+
MVinteger Char (IV Prov_none IVunspecified)
437439
end
438440

439441

@@ -1065,6 +1067,8 @@ let rec impl_sizeof_ival_aux (Ctype _ ty as cty) =
10651067
| Union tag_sym ->
10661068
(* TODO: move the code from mem_simplify *)
10671069
IVsizeof (Ctype [] (Union tag_sym))
1070+
| Byte ->
1071+
IVconcrete 1
10681072
end
10691073

10701074

frontend/model/defacto_memory_aux.lem

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,8 @@ let rec simplify_integer_value_base ival_ =
347347
(* TOOD: move the code from mem_simplify here *)
348348
| Union tag_sym ->
349349
Right ival_ (* error "TODO simplify_integer_value: IVsizeof Union" *)
350+
| Byte ->
351+
Left 1
350352
end
351353
| IValignof (Ctype _ ty) ->
352354
match ty with
@@ -384,6 +386,8 @@ let rec simplify_integer_value_base ival_ =
384386
Right ival_
385387
| Union tag_sym ->
386388
error "TODO simplify_integer_value: IValignof Union"
389+
| Byte ->
390+
Left 1
387391
end
388392
| IVoffsetof _ _ ->
389393
Right ival_

0 commit comments

Comments
 (0)