blob: a53da20226dd79b222bd554844110e8f167afb60 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
|
#!/bin/bash
#
# mkrewriter
# Morgan Deters <mdeters@cs.nyu.edu> for CVC4
# Copyright (c) 2010-2011 The CVC4 Project
#
# The purpose of this script is to create rewriter_tables.h from a template
# and a list of theory kinds.
#
# Invocation:
#
# mkrewriter template-file theory-kind-files...
#
# Output is to standard out.
#
copyright=2010-2011
cat <<EOF
/********************* */
/** rewriter_tables.h
**
** Copyright $copyright The AcSys Group, New York University, and as below.
**
** This header file automatically generated by:
**
** $0 $@
**
** for the CVC4 project.
**/
EOF
me=$(basename "$0")
template=$1; shift
rewriter_includes=
rewrite_init=
rewrite_shutdown=
pre_rewrite_calls=
pre_rewrite_get_cache=
pre_rewrite_set_cache=
post_rewrite_calls=
post_rewrite_get_cache=
post_rewrite_set_cache=
seen_theory=false
seen_theory_builtin=false
function theory {
# theory T header
lineno=${BASH_LINENO[0]}
# this script doesn't care about the theory class information, but
# makes does make sure it's there
seen_theory=true
if [ "$1" = THEORY_BUILTIN ]; then
if $seen_theory_builtin; then
echo "$kf:$lineno: error: \"builtin\" theory redefined" >&2
exit 1
fi
seen_theory_builtin=true
elif [ -z "$1" -o -z "$2" -o -z "$3" ]; then
echo "$kf:$lineno: error: \"theory\" directive missing class or header argument" >&2
exit 1
elif ! expr "$2" : '\(::*\)' >/dev/null; then
echo "$kf:$lineno: warning: theory class \`$2' isn't fully-qualified (e.g., ::CVC4::theory::foo)" >&2
elif ! expr "$2" : '\(::CVC4::theory::*\)' >/dev/null; then
echo "$kf:$lineno: warning: theory class not under ::CVC4::theory namespace" >&2
fi
theory_id="$1"
}
function properties {
# properties prop*
lineno=${BASH_LINENO[0]}
check_theory_seen
}
function endtheory {
# endtheory
lineno=${BASH_LINENO[0]}
check_theory_seen
}
function rewriter {
# rewriter class header
class="$1"
header="$2"
rewriter_includes="${rewriter_includes}#include \"$header\"
"
rewrite_init="${rewrite_init} ${class}::init();
"
rewrite_shutdown="${rewrite_shutdown} ${class}::shutdown();
"
pre_rewrite_calls="${pre_rewrite_calls} case ${theory_id}: return ${class}::preRewrite(node);
"
pre_rewrite_get_cache="${pre_rewrite_get_cache} case ${theory_id}: return RewriteAttibute<${theory_id}>::getPreRewriteCache(node);
"
pre_rewrite_set_cache="${pre_rewrite_set_cache} case ${theory_id}: return RewriteAttibute<${theory_id}>::setPreRewriteCache(node, cache);
"
post_rewrite_calls="${post_rewrite_calls} case ${theory_id}: return ${class}::postRewrite(node);
"
post_rewrite_get_cache="${post_rewrite_get_cache} case ${theory_id}: return RewriteAttibute<${theory_id}>::getPostRewriteCache(node);
"
post_rewrite_set_cache="${post_rewrite_set_cache} case ${theory_id}: return RewriteAttibute<${theory_id}>::setPostRewriteCache(node, cache);
"
lineno=${BASH_LINENO[0]}
check_theory_seen
}
function sort {
# sort TYPE ["comment"]
lineno=${BASH_LINENO[0]}
check_theory_seen
}
function variable {
# variable K ["comment"]
lineno=${BASH_LINENO[0]}
check_theory_seen
}
function operator {
# operator K #children ["comment"]
lineno=${BASH_LINENO[0]}
check_theory_seen
}
function parameterized {
# parameterized K1 K2 #children ["comment"]
lineno=${BASH_LINENO[0]}
check_theory_seen
}
function constant {
# constant K T Hasher header ["comment"]
lineno=${BASH_LINENO[0]}
check_theory_seen
}
function check_theory_seen {
if ! $seen_theory; then
echo "$kf:$lineno: error: no \"theory\" declaration found (it has to be first)" >&2
exit 1
fi
}
function check_builtin_theory_seen {
if ! $seen_theory_builtin; then
echo "$me: warning: no declaration for the builtin theory found" >&2
fi
}
while [ $# -gt 0 ]; do
kf=$1
seen_theory=false
b=$(basename $(dirname "$kf"))
source "$kf"
check_theory_seen
shift
done
check_builtin_theory_seen
## output
text=$(cat "$template")
for var in rewriter_includes pre_rewrite_calls post_rewrite_calls pre_rewrite_get_cache post_rewrite_get_cache pre_rewrite_set_cache post_rewrite_set_cache rewrite_init rewrite_shutdown; do
eval text="\${text//\\\$\\{$var\\}/\${$var}}"
done
error=`expr "$text" : '.*\${\([^}]*\)}.*'`
if [ -n "$error" ]; then
echo "$template:0: error: undefined replacement \${$error}" >&2
exit 1
fi
echo "$text"
|