Skip to content

Commit 60f13e6

Browse files
authored
Regenerate projects with latest Alire (#3)
* Regenerated the cobs and unit_tests projects with Alire 1.2.0. * Use default style checks generated by Alire in validation builds: * Removed explicit 'in' mode. * Reduced line lengths to fit in 80 columns. * Added a nested crate used to run gnatprove.
1 parent e80e17b commit 60f13e6

12 files changed

+217
-188
lines changed

.gitignore

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
obj
2-
lib
3-
alire
1+
/obj/
2+
/lib/
3+
/alire/
4+
/config/

alire.toml

+4-15
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,10 @@
11
name = "cobs"
2-
description = "Encoder and decoder for Consistent Overhead Byte Stuffing (COBS)"
3-
version = "1.0.1"
2+
description = "Consistent Overhead Byte Stuffing (COBS) encoder/decoder"
3+
version = "1.1.0-dev"
44

5-
licenses = ["MIT"]
5+
licenses = "MIT"
66
authors = ["Daniel King"]
77
maintainers = ["Daniel King <damaki.gh@gmail.com>"]
88
maintainers-logins = ["damaki"]
99
website = "https://github.com/damaki/cobs"
10-
tags = ["cobs", "spark", "embedded", "nostd"]
11-
12-
[[depends-on]]
13-
gnat = ">=2020"
14-
15-
[gpr-externals]
16-
COBS_LIBRARY_TYPE = ["relocatable", "static", "static-pic"]
17-
COBS_COMPILE_CHECKS = ["enabled", "disabled"]
18-
COBS_RUNTIME_CHECKS = ["enabled", "disabled"]
19-
COBS_STYLE_CHECKS = ["enabled", "disabled"]
20-
COBS_CONTRACTS = ["enabled", "disabled"]
21-
COBS_BUILD_MODE = ["debug", "optimize"]
10+
tags = ["cobs", "spark", "embedded", "nostd"]

cobs.gpr

+24-71
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
with "config/cobs_config.gpr";
12
project Cobs is
23

3-
for Library_Name use "cobs";
4-
for Library_Version use "1.0.1";
4+
for Library_Name use "Cobs";
5+
for Library_Version use Project'Library_Name & ".so." & Cobs_Config.Crate_Version;
56

6-
for Source_Dirs use ("src");
7-
for Object_Dir use "obj";
7+
for Source_Dirs use ("src/", "config/");
8+
for Object_Dir use "obj/" & Cobs_Config.Build_Profile;
89
for Create_Missing_Dirs use "True";
910
for Library_Dir use "lib";
1011

@@ -13,77 +14,29 @@ project Cobs is
1314
external ("COBS_LIBRARY_TYPE", external ("LIBRARY_TYPE", "static"));
1415
for Library_Kind use Library_Type;
1516

16-
type Enabled_Kind is ("enabled", "disabled");
17-
Compile_Checks : Enabled_Kind := External ("COBS_COMPILE_CHECKS", "enabled");
18-
Runtime_Checks : Enabled_Kind := External ("COBS_RUNTIME_CHECKS", "enabled");
19-
Style_Checks : Enabled_Kind := External ("COBS_STYLE_CHECKS", "enabled");
20-
Contracts_Checks : Enabled_Kind := External ("COBS_CONTRACTS", "enabled");
21-
22-
type Build_Kind is ("debug", "optimize");
23-
Build_Mode : Build_Kind := External ("COBS_BUILD_MODE", "debug");
24-
25-
Compile_Checks_Switches := ();
26-
case Compile_Checks is
27-
when "enabled" =>
28-
Compile_Checks_Switches :=
29-
("-gnatwa", -- All warnings
30-
"-gnatVa", -- All validity checks
31-
"-gnatw.X", -- Disable warning may call Last_Chance_Handler
32-
"-gnatwe"); -- Warnings as errors
33-
when others => null;
34-
end case;
35-
36-
Runtime_Checks_Switches := ();
37-
case Runtime_Checks is
38-
when "enabled" => null;
39-
when others =>
40-
Runtime_Checks_Switches :=
41-
("-gnatp"); -- Supress checks
42-
end case;
43-
44-
Style_Checks_Switches := ();
45-
case Style_Checks is
46-
when "enabled" => null;
47-
Style_Checks_Switches :=
48-
("-gnatyg", -- GNAT Style checks
49-
"-gnaty-d", -- Disable no DOS line terminators
50-
"-gnaty-I", -- Disable check mode IN keywords
51-
"-gnatyM100", -- Maximum line length
52-
"-gnatyO"); -- Overriding subprograms explicitly marked as such
53-
when others => null;
54-
end case;
55-
56-
Contracts_Switches := ();
57-
case Contracts_Checks is
58-
when "enabled" => null;
59-
Contracts_Switches :=
60-
("-gnata"); -- Enable assertions and contracts
61-
when others =>
62-
end case;
63-
64-
Compiler_Switches := ();
65-
case Build_Mode is
66-
when "optimize" =>
67-
Compiler_Switches := ("-O3", -- Optimization
68-
"-funroll-loops", -- Unroll loops
69-
"-gnatn"); -- Enable inlining
70-
when "debug" =>
71-
Compiler_Switches := ("-g", -- Debug info
72-
"-Og"); -- No optimization
73-
end case;
74-
7517
package Compiler is
76-
for Default_Switches ("Ada") use
77-
Compile_Checks_Switches &
78-
Compiler_Switches &
79-
Runtime_Checks_Switches &
80-
Style_Checks_Switches &
81-
Contracts_Switches &
82-
("-gnatQ"); -- Don't quit. Generate ALI and tree files even if illegalities
18+
for Default_Switches ("Ada") use Cobs_Config.Ada_Compiler_Switches;
8319
end Compiler;
8420

8521
package Binder is
8622
for Switches ("Ada") use ("-Es"); -- Symbolic traceback
8723
end Binder;
8824

89-
end Cobs;
25+
package Install is
26+
for Artifacts (".") use ("share");
27+
end Install;
28+
29+
package Prove is
30+
for Proof_Switches ("Ada") use ("--proof=per_path",
31+
"-j0",
32+
"--no-global-generation",
33+
"--no-inlining",
34+
"--no-loop-unrolling",
35+
"--prover=cvc4,z3,altergo",
36+
"--timeout=60",
37+
"--memlimit=0",
38+
"--steps=15000",
39+
"--report=statistics");
40+
end Prove;
41+
42+
end Cobs;

prove/.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/obj/
2+
/bin/
3+
/alire/
4+
/config/

prove/alire.toml

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name = "prove"
2+
description = "Shiny new project"
3+
version = "0.1.0-dev"
4+
5+
authors = ["Daniel King"]
6+
maintainers = ["Daniel King <damaki.gh@gmail.com>"]
7+
maintainers-logins = ["damaki"]
8+
9+
executables = ["prove"]
10+
11+
[[depends-on]]
12+
gnatprove = "^11.2.3"
13+
cobs = "*"
14+
15+
[[pins]]
16+
cobs = { path = "../" }

src/generic_cobs.adb

+42-25
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ is
2727
-- Decode --
2828
------------
2929

30-
procedure Decode (Input : in Byte_Array;
31-
Output : out Byte_Array;
32-
Length : out Byte_Count) is
30+
procedure Decode (Input : Byte_Array;
31+
Output : out Byte_Array;
32+
Length : out Byte_Count) is
3333
B : Byte;
3434
Code : Byte := Byte'Last;
3535
Run_Length : Byte_Count := 0;
@@ -39,8 +39,10 @@ is
3939

4040
for I in 0 .. Index'Base (Input'Length - 1) loop
4141
pragma Loop_Invariant (Length <= Byte_Count (I));
42-
pragma Loop_Invariant (for all J in 0 .. Length - 1 =>
43-
Output (Output'First + Index'Base (J))'Initialized);
42+
43+
pragma Loop_Invariant
44+
(for all J in 0 .. Length - 1 =>
45+
Output (Output'First + Index'Base (J))'Initialized);
4446

4547
B := Input (Input'First + I);
4648

@@ -70,9 +72,9 @@ is
7072
-- Encode --
7173
------------
7274

73-
procedure Encode (Input : in Byte_Array;
74-
Output : out Byte_Array;
75-
Length : out Byte_Count) is
75+
procedure Encode (Input : Byte_Array;
76+
Output : out Byte_Array;
77+
Length : out Byte_Count) is
7678
Block_Length : Positive_Byte_Count;
7779
Offset : Byte_Count;
7880
Remaining : Byte_Count;
@@ -92,16 +94,23 @@ is
9294
Increases => Offset,
9395
Increases => Length,
9496
Increases => Nb_Overhead_Bytes);
97+
9598
pragma Loop_Invariant (Offset + Remaining = Input'Length);
99+
96100
pragma Loop_Invariant (Length = Offset + Nb_Overhead_Bytes);
97-
pragma Loop_Invariant (Nb_Overhead_Bytes < Max_Overhead_Bytes (Offset));
98-
pragma Loop_Invariant (for all I in Output'First ..
99-
Output'First + Index'Base (Length - 1) =>
100-
Output (I)'Initialized);
101101

102-
Encode_Block (Input (Input'First + Index'Base (Offset) .. Input'Last),
103-
Output (Output'First + Index'Base (Length) .. Output'Last),
104-
Block_Length);
102+
pragma Loop_Invariant
103+
(Nb_Overhead_Bytes < Max_Overhead_Bytes (Offset));
104+
105+
pragma Loop_Invariant
106+
(for all I in Output'First ..
107+
Output'First + Index'Base (Length - 1) =>
108+
Output (I)'Initialized);
109+
110+
Encode_Block
111+
(Input (Input'First + Index'Base (Offset) .. Input'Last),
112+
Output (Output'First + Index'Base (Length) .. Output'Last),
113+
Block_Length);
105114

106115
Nb_Overhead_Bytes := Nb_Overhead_Bytes + 1;
107116

@@ -119,9 +128,9 @@ is
119128
-- Encode_Block --
120129
--------------------
121130

122-
procedure Encode_Block (Input : in Byte_Array;
123-
Output : out Byte_Array;
124-
Length : out Byte_Count) is
131+
procedure Encode_Block (Input : Byte_Array;
132+
Output : out Byte_Array;
133+
Length : out Byte_Count) is
125134
B : Byte;
126135

127136
Code : Positive_Byte_Count := 1;
@@ -142,14 +151,22 @@ is
142151
if Input'Length > 0 then
143152
for I in Byte_Count range 0 .. Input'Length - 1 loop
144153
pragma Loop_Invariant (Code <= Maximum_Run_Length + 1);
145-
pragma Loop_Invariant (Code = Length - Byte_Count (Code_Pos - Output'First));
146-
pragma Loop_Invariant (Code_Pos in Output'First ..
147-
Output'First + Index'Base (Length) - 1);
154+
155+
pragma Loop_Invariant
156+
(Code = Length - Byte_Count (Code_Pos - Output'First));
157+
158+
pragma Loop_Invariant
159+
(Code_Pos in Output'First ..
160+
Output'First + Index'Base (Length) - 1);
161+
148162
pragma Loop_Invariant (Length = Byte_Count (I + 1));
149-
pragma Loop_Invariant (for all I in Output'First ..
150-
Output'First + Index'Base (Length) - 1 =>
151-
(if I /= Code_Pos then
152-
Output (I)'Initialized));
163+
164+
-- All bytes written so far are initialized, except the
165+
-- one at Code_Pos which is written later.
166+
pragma Loop_Invariant
167+
(for all I in Output'First ..
168+
Output'First + Index'Base (Length) - 1 =>
169+
(if I /= Code_Pos then Output (I)'Initialized));
153170

154171
-- Stop when a complete block is reached.
155172
exit when Code = Maximum_Run_Length + 1;

0 commit comments

Comments
 (0)