Skip to content

Commit 07cb3d8

Browse files
Simon Winwoodsimonjwinwood
Simon Winwood
authored andcommitted
Make 'a signed word have a different name than 'a word
Signed-off-by: Simon Winwood <simonjwinwood@gmail.com>
1 parent dcf271a commit 07cb3d8

10 files changed

+91
-24
lines changed

tools/autocorres/TypHeapSimple.thy

+2-1
Original file line numberDiff line numberDiff line change
@@ -807,7 +807,8 @@ lemmas simple_lift_simps =
807807
simple_lift_field_update_t
808808
c_guard_array_field
809809
nat_to_bin_string_simps
810-
810+
signed_or_unsigned
811+
811812
(* Old name for the above simpset. *)
812813
lemmas typ_simple_heap_simps = simple_lift_simps
813814

tools/c-parser/UMM_Proofs.ML

+2-2
Original file line numberDiff line numberDiff line change
@@ -545,8 +545,8 @@ fun umm_struct_calculation ((recname, flds), st, thy) = let
545545
Simplifier.asm_full_rewrite
546546
((thy2ctxt thy) addsimps
547547
[tag_def_thm, typtag_thm,
548-
@{thm "pad_typ_name_def"}, @{thm "insert_commute"},
549-
@{thm "nat_to_bin_string.simps"}])
548+
@{thm "pad_typ_name_def"}, @{thm "insert_commute"}] @
549+
@{thms "signed_or_unsigned"} @ @{thms "nat_to_bin_string.simps"})
550550
(Thm.cterm_of (thy2ctxt thy) (mk_td_names typtag_lhs)) |> Drule.export_without_context
551551

552552
(* Declare the td_names (typ_info_t ..) = ... and add it to the simpset *)

tools/c-parser/umm_heap/AARCH64/Word_Mem_Encoding.thy

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ where
1717
(len_exp TYPE('a))
1818
\<lparr> field_access = \<lambda>v bs. (rev o word_rsplit) v,
1919
field_update = \<lambda>bs v. (word_rcat (rev bs)::'a::len8 word) \<rparr>)
20-
(''word'' @ nat_to_bin_string (len_of TYPE('a)))"
20+
(signed_or_unsigned_as_str TYPE('a) @ ''word'' @ nat_to_bin_string (len_of TYPE('a)))"
2121

2222
end

tools/c-parser/umm_heap/ARM/Word_Mem_Encoding.thy

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ begin
1212
definition
1313
word_tag :: "'a::len8 word itself \<Rightarrow> 'a word typ_info"
1414
where
15-
"word_tag (w::'a::len8 word itself) \<equiv> TypDesc (TypScalar (len_of TYPE('a) div 8) (len_exp TYPE('a)) \<lparr> field_access = \<lambda>v bs. (rev o word_rsplit) v, field_update = \<lambda>bs v. (word_rcat (rev bs)::'a::len8 word) \<rparr>) (''word'' @ nat_to_bin_string (len_of TYPE('a)) )"
15+
"word_tag (w::'a::len8 word itself) \<equiv> TypDesc (TypScalar (len_of TYPE('a) div 8) (len_exp TYPE('a)) \<lparr> field_access = \<lambda>v bs. (rev o word_rsplit) v, field_update = \<lambda>bs v. (word_rcat (rev bs)::'a::len8 word) \<rparr>) (signed_or_unsigned_as_str TYPE('a) @ ''word'' @ nat_to_bin_string (len_of TYPE('a)) )"
1616

1717
end

tools/c-parser/umm_heap/ARM_HYP/Word_Mem_Encoding.thy

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ begin
1212
definition
1313
word_tag :: "'a::len8 word itself \<Rightarrow> 'a word typ_info"
1414
where
15-
"word_tag (w::'a::len8 word itself) \<equiv> TypDesc (TypScalar (len_of TYPE('a) div 8) (len_exp TYPE('a)) \<lparr> field_access = \<lambda>v bs. (rev o word_rsplit) v, field_update = \<lambda>bs v. (word_rcat (rev bs)::'a::len8 word) \<rparr>) (''word'' @ nat_to_bin_string (len_of TYPE('a)) )"
15+
"word_tag (w::'a::len8 word itself) \<equiv> TypDesc (TypScalar (len_of TYPE('a) div 8) (len_exp TYPE('a)) \<lparr> field_access = \<lambda>v bs. (rev o word_rsplit) v, field_update = \<lambda>bs v. (word_rcat (rev bs)::'a::len8 word) \<rparr>) (signed_or_unsigned_as_str TYPE('a) @ ''word'' @ nat_to_bin_string (len_of TYPE('a)) )"
1616

1717
end

tools/c-parser/umm_heap/RISCV64/Word_Mem_Encoding.thy

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ where
1717
(len_exp TYPE('a))
1818
\<lparr> field_access = \<lambda>v bs. (rev o word_rsplit) v,
1919
field_update = \<lambda>bs v. (word_rcat (rev bs)::'a::len8 word) \<rparr>)
20-
(''word'' @ nat_to_bin_string (len_of TYPE('a)))"
20+
(signed_or_unsigned_as_str TYPE('a) @ ''word'' @ nat_to_bin_string (len_of TYPE('a)))"
2121

2222
end

tools/c-parser/umm_heap/StructSupport.thy

+3-3
Original file line numberDiff line numberDiff line change
@@ -485,15 +485,15 @@ lemma td_names_ptr [simp]:
485485
lemma td_names_word8 [simp]:
486486
fixes x :: "byte itself"
487487
shows "td_names (typ_info_t x) = {''word00010''}"
488-
by (simp add: pad_typ_name_def nat_to_bin_string.simps)
488+
by (simp add: pad_typ_name_def nat_to_bin_string.simps signed_or_unsigned)
489489

490490
lemma td_names_word32 [simp]:
491491
"td_names (typ_info_t TYPE(32 word)) = {''word0000010''}"
492-
by (simp add: pad_typ_name_def nat_to_bin_string.simps)
492+
by (simp add: pad_typ_name_def nat_to_bin_string.simps signed_or_unsigned)
493493

494494
lemma td_names_word64 [simp]:
495495
"td_names (typ_info_t TYPE(64 word)) = {''word00000010''}"
496-
by (simp add: pad_typ_name_def nat_to_bin_string.simps)
496+
by (simp add: pad_typ_name_def nat_to_bin_string.simps signed_or_unsigned)
497497

498498
lemma td_names_export_uinfo [simp]:
499499
"td_names (export_uinfo td) = td_names td"

tools/c-parser/umm_heap/Vanilla32.thy

+11-12
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ theory Vanilla32
99
imports Word_Mem_Encoding CTypes
1010
begin
1111

12-
1312
overloading typ_info_word \<equiv> typ_info_t begin
1413
definition
1514
typ_info_word: "typ_info_word (w::'a::len8 word itself) \<equiv> word_tag w"
@@ -337,7 +336,7 @@ lemma ptr_typ_name [simp]:
337336
by simp
338337

339338
lemma word_typ_name [simp]:
340-
"typ_name (typ_info_t TYPE('a::len8 word)) = ''word'' @ nat_to_bin_string (len_of TYPE('a))"
339+
"typ_name (typ_info_t TYPE('a::len8 word)) = signed_or_unsigned_as_str TYPE('a) @ ''word'' @ nat_to_bin_string (len_of TYPE('a))"
341340
by simp
342341

343342
lemma nat_to_bin_string_word_sizes [simp]:
@@ -357,19 +356,19 @@ lemma typ_name_words [simp]:
357356
"typ_name (typ_info_t TYPE(16 word)) = ''word000010''"
358357
"typ_name (typ_info_t TYPE(32 word)) = ''word0000010''"
359358
"typ_name (typ_info_t TYPE(64 word)) = ''word00000010''"
360-
by (auto simp: typ_uinfo_t_def)
359+
by (auto simp: typ_uinfo_t_def signed_or_unsigned)
361360

362361
lemma typ_name_swords [simp]:
363-
"typ_name (typ_uinfo_t TYPE(8 sword)) = ''word00010''"
364-
"typ_name (typ_uinfo_t TYPE(16 sword)) = ''word000010''"
365-
"typ_name (typ_uinfo_t TYPE(32 sword)) = ''word0000010''"
366-
"typ_name (typ_uinfo_t TYPE(64 sword)) = ''word00000010''"
362+
"typ_name (typ_uinfo_t TYPE(8 sword)) = ''sword00010''"
363+
"typ_name (typ_uinfo_t TYPE(16 sword)) = ''sword000010''"
364+
"typ_name (typ_uinfo_t TYPE(32 sword)) = ''sword0000010''"
365+
"typ_name (typ_uinfo_t TYPE(64 sword)) = ''sword00000010''"
367366
(* these do not fire in a simple simp, because typ_info_word takes precedence (innermost term): *)
368-
"typ_name (typ_info_t TYPE(8 sword)) = ''word00010''"
369-
"typ_name (typ_info_t TYPE(16 sword)) = ''word000010''"
370-
"typ_name (typ_info_t TYPE(32 sword)) = ''word0000010''"
371-
"typ_name (typ_info_t TYPE(64 sword)) = ''word00000010''"
372-
by (auto simp: typ_uinfo_t_def)
367+
"typ_name (typ_info_t TYPE(8 sword)) = ''sword00010''"
368+
"typ_name (typ_info_t TYPE(16 sword)) = ''sword000010''"
369+
"typ_name (typ_info_t TYPE(32 sword)) = ''sword0000010''"
370+
"typ_name (typ_info_t TYPE(64 sword)) = ''sword00000010''"
371+
by (auto simp: typ_uinfo_t_def signed_or_unsigned)
373372

374373
lemma ptr_arith[simp]:
375374
"(x +\<^sub>p a = y +\<^sub>p a) = ((x::('a::c_type) ptr) = (y::'a ptr))"

tools/c-parser/umm_heap/Vanilla32_Preliminaries.thy

+68-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,74 @@ by (simp add: len_exp_def bogus_log2lessthree_def)
8080
lemma lx_signed' [simp]: "len_exp (x::('a::len) signed itself) = len_exp (TYPE('a))"
8181
by (simp add: len_exp_def)
8282

83-
class len8 = len +
83+
(* Maybe not required, but keeps everything neat *)
84+
class typ_num
85+
86+
instantiation num0 and num1 :: typ_num
87+
begin
88+
instance ..
89+
end
90+
91+
instantiation bit0 and bit1 :: (typ_num) typ_num
92+
begin
93+
instance ..
94+
end
95+
96+
class signed_or_unsigned =
97+
fixes signed_or_unsigned_as_str :: "'a itself \<Rightarrow> char list"
98+
99+
instantiation num0 :: signed_or_unsigned
100+
begin
101+
102+
definition
103+
num0_signed_or_unsigned_def: "signed_or_unsigned_as_str (w :: num0 itself) = []"
104+
105+
instance ..
106+
end
107+
108+
instantiation num1 :: signed_or_unsigned
109+
begin
110+
111+
definition
112+
num1_signed_or_unsigned_def: "signed_or_unsigned_as_str (w :: num1 itself) = []"
113+
114+
instance ..
115+
end
116+
117+
instantiation bit0 :: (type) signed_or_unsigned
118+
begin
119+
120+
definition
121+
bit0_signed_or_unsigned_def: "signed_or_unsigned_as_str (w :: 'a bit0 itself) = []"
122+
123+
instance ..
124+
end
125+
126+
instantiation bit1 :: (type) signed_or_unsigned
127+
begin
128+
129+
definition
130+
bit1_signed_or_unsigned_def: "signed_or_unsigned_as_str (w :: 'a bit1 itself) = []"
131+
132+
instance ..
133+
end
134+
135+
instantiation signed :: (type) signed_or_unsigned
136+
begin
137+
138+
definition
139+
signed_signed_or_unsigned_def: "signed_or_unsigned_as_str (w :: 'a signed itself) = ''s''"
140+
141+
instance ..
142+
end
143+
144+
lemmas signed_or_unsigned = num0_signed_or_unsigned_def
145+
num1_signed_or_unsigned_def
146+
bit0_signed_or_unsigned_def
147+
bit1_signed_or_unsigned_def
148+
signed_signed_or_unsigned_def
149+
150+
class len8 = signed_or_unsigned + len +
84151
(* this constraint gives us (in the most convoluted way possible) that we're only
85152
interested in words with a length that is divisible by 8 *)
86153
assumes len8_bytes: "len_of TYPE('a::len) = 8 * (2^len_exp TYPE('a))"

tools/c-parser/umm_heap/X64/Word_Mem_Encoding.thy

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ where
1717
(len_exp TYPE('a))
1818
\<lparr> field_access = \<lambda>v bs. (rev o word_rsplit) v,
1919
field_update = \<lambda>bs v. (word_rcat (rev bs)::'a::len8 word) \<rparr>)
20-
(''word'' @ nat_to_bin_string (len_of TYPE('a)))"
20+
(signed_or_unsigned_as_str TYPE('a) @ ''word'' nat_to_bin_string (len_of TYPE('a)))"
2121

2222
end

0 commit comments

Comments
 (0)