Computer Laboratory

tesla-macros.h
Go to the documentation of this file.
1 
2 /*
3  * Copyright (c) 2013 Jonathan Anderson
4  * All rights reserved.
5  *
6  * This software was developed by SRI International and the University of
7  * Cambridge Computer Laboratory under DARPA/AFRL contract (FA8750-10-C-0237)
8  * ("CTSRD"), as part of the DARPA CRASH research programme.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in the
17  * documentation and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29  * SUCH DAMAGE.
30  */
31 
32 #ifndef TESLA_MACROS_H
33 #define TESLA_MACROS_H
34 
40 #include <tesla.h>
41 
42 /*
43  * Macros to make TESLA assertions a little easier to read.
44  */
45 
47 #define TESLA_WITHIN(function, expression) \
48  TESLA_PERTHREAD( \
49  callee(called(function)), \
50  callee(returned(function)), \
51  expression \
52  )
53 
55 #define TESLA_ASSERT(locality, start, end, expression) \
56  __tesla_inline_assertion( \
57  __FILE__, __LINE__, __COUNTER__, \
58  locality, start, end, expression \
59  )
60 
62 #define TESLA_GLOBAL(...) TESLA_ASSERT(__tesla_global, __VA_ARGS__)
63 
65 #define TESLA_PERTHREAD(...) TESLA_ASSERT(__tesla_perthread, __VA_ARGS__)
66 
68 #define TIGNORE __tesla_ignore
69 
71 #define TSEQUENCE(...) __tesla_sequence(TIGNORE, __VA_ARGS__)
72 
73 #define called(...) __tesla_call(((void)__VA_ARGS__, TIGNORE))
74 #define returned(...) __tesla_return(__VA_ARGS__)
75 
76 #define callee(...) __tesla_callee(TIGNORE, __VA_ARGS__)
77 #define caller(...) __tesla_caller(TIGNORE, __VA_ARGS__)
78 #define strict(...) __tesla_strict(TIGNORE, __VA_ARGS__)
79 #define conditional(...) __tesla_conditional(TIGNORE, __VA_ARGS__)
80 
81 #define flags(...) __tesla_flags(__VA_ARGS__)
82 #define bitmask(...) __tesla_mask(__VA_ARGS__)
83 
84 #define TESLA_NOW __tesla_now
85 
86 
87 #define TESLA_STRUCT_AUTOMATON(...) __tesla_struct_usage(__VA_ARGS__)
88 
89 #define automaton(name, ...) __tesla_automaton(name, __VA_ARGS__)
90 #define tesla_done return (__tesla_automaton_done())
91 
92 #define optional(...) __tesla_optional(TIGNORE, __VA_ARGS__)
93 #define ANY_REP INT_MAX
94 #define REPEAT(m, n, ...) __tesla_repeat(m, n, __VA_ARGS__)
95 #define UPTO(n, ...) __tesla_repeat(0, n, __VA_ARGS__)
96 #define ATLEAST(n, ...) __tesla_repeat(n, ANY_REP, __VA_ARGS__)
97 #define ANY(int_type) __tesla_any(int_type)
98 
100 #define previously(...) TSEQUENCE(__VA_ARGS__, TESLA_NOW)
101 
103 #define eventually(...) TSEQUENCE(TESLA_NOW, __VA_ARGS__)
104 
107 #endif /* !TESLA_MACROS_H */