File tree Expand file tree Collapse file tree
rocq-brick-libstdcpp/test Expand file tree Collapse file tree Original file line number Diff line number Diff line change 3535 (run cpp2v - v %{input} - o N2_input_cpp.v -- no - elaborate -- - std =c ++ 20 - stdlib=libstdc ++ )))
3636 (alias (name srcs) (deps N2_input.cpp))
3737)
38+ (subdir geeks_for_geeks_examples
39+ (rule
40+ (targets N3_sum_cpp.v)
41+ (alias test_ast)
42+ (deps (:input N3_sum.cpp) (glob_files_rec ../ * .hpp) (universe))
43+ (action
44+ (run cpp2v - v %{input} - o N3_sum_cpp.v -- no - elaborate -- - std =c ++ 20 - stdlib=libstdc ++ )))
45+ (alias (name srcs) (deps N3_sum.cpp))
46+ )
47+ (subdir geeks_for_geeks_examples
48+ (rule
49+ (targets N3_sum_a_cpp.v)
50+ (alias test_ast)
51+ (deps (:input N3_sum_a.cpp) (glob_files_rec ../ * .hpp) (universe))
52+ (action
53+ (run cpp2v - v %{input} - o N3_sum_a_cpp.v -- no - elaborate -- - std =c ++ 20 - stdlib=libstdc ++ )))
54+ (alias (name srcs) (deps N3_sum_a.cpp))
55+ )
3856(subdir geeks_for_geeks_examples
3957 (rule
4058 (targets iostream_cpp.v)
Original file line number Diff line number Diff line change 1+ #include < iostream>
2+ using namespace std ;
3+
4+ int main () {
5+ int a = 11 , b = 9 ;
6+
7+ // Adding the two numbers and printing
8+ // their sum
9+ cout << a + b;
10+ return 0 ;
11+ }
Original file line number Diff line number Diff line change 1+ Require Import skylabs.auto.cpp.prelude.proof.
2+ Require Import skylabs.brick.libstdcpp.test.geeks_for_geeks_examples.spec.
3+
4+ Require Import skylabs.brick.libstdcpp.test.geeks_for_geeks_examples.N3_sum_cpp.
5+
6+ Import linearity.
7+
8+ Section with_cpp.
9+ Context `{Σ : cpp_logic, σ : genv}.
10+
11+ cpp.spec "main()" from source as main_spec with (
12+ \prepost{osM} _global "std::cout" |-> ostreamR 1$m osM
13+ \pre{str} _global "std::cout" |-> ostream_contentR 1$m str
14+ \post[Vint 0]
15+ _global "std::cout" |-> ostream_contentR 1$m (str ++ Z_to_string 20)
16+ ).
17+
18+ Lemma main_ok : verify?[source] main_spec.
19+ Proof . verify_spec; go. Qed .
20+ End with_cpp.
Original file line number Diff line number Diff line change 1+ #include < iostream>
2+ using namespace std ;
3+
4+ int main () {
5+ int a = 11 , b = 9 ;
6+
7+ // If b is positive, increment a to b times
8+ for (int i = 0 ; i < b; i++)
9+ a++;
10+
11+ // If b is negative, decrement a to |b| times
12+ for (int i = 0 ; i > b; i--)
13+ a--;
14+
15+ cout << a;
16+
17+ return 0 ;
18+ }
Original file line number Diff line number Diff line change 1+ Require Import skylabs.auto.cpp.prelude.proof.
2+ Require Import skylabs.brick.libstdcpp.test.geeks_for_geeks_examples.spec.
3+
4+ Require Import skylabs.brick.libstdcpp.test.geeks_for_geeks_examples.N3_sum_a_cpp.
5+
6+ Import linearity.
7+
8+ Section with_cpp.
9+ Context `{Σ : cpp_logic, σ : genv}.
10+
11+ cpp.spec "main()" from source as main_spec with (
12+ \prepost{osM} _global "std::cout" |-> ostreamR 1$m osM
13+ \pre{str} _global "std::cout" |-> ostream_contentR 1$m str
14+ \post[Vint 0]
15+ _global "std::cout" |-> ostream_contentR 1$m (str ++ Z_to_string 20)
16+ ).
17+
18+ #[global] Declare Instance Z_to_string_inj : Inj eq eq Z_to_string.
19+
20+ Lemma main_ok : verify?[source] main_spec.
21+ Proof .
22+ verify_spec; go.
23+
24+ wp_for (fun ρ =>
25+ \pre{i1} _local ρ "i" |-> intR 1$m i1
26+ \pre _local ρ "a" |-> intR 1$m (11 + i1)
27+ \require 0 <= i1 <= 9
28+ \post* _local ρ "i" |-> anyR "int" 1$m
29+ \post* _local ρ "a" |-> intR 1$m 20
30+ \post emp
31+ ).
32+
33+ go.
34+ wp_if; go.
35+ wp_for (fun ρ => emp); go.
36+ Qed .
37+ End with_cpp.
You can’t perform that action at this time.
0 commit comments