@@ -19,15 +19,12 @@ Author: CM Wintersteiger
19
19
20
20
#include < goto-programs/goto_model.h>
21
21
22
- // / Writes a goto program to disc, using goto binary format
23
- bool write_goto_binary (
22
+ // / Writes the symbol table to file.
23
+ static void write_symbol_table_binary (
24
24
std::ostream &out,
25
25
const symbol_table_baset &symbol_table,
26
- const goto_functionst &goto_functions,
27
26
irep_serializationt &irepconverter)
28
27
{
29
- // first write symbol table
30
-
31
28
write_gb_word (out, symbol_table.symbols .size ());
32
29
33
30
for (const auto &symbol_pair : symbol_table.symbols )
@@ -70,9 +67,45 @@ bool write_goto_binary(
70
67
71
68
write_gb_word (out, flags);
72
69
}
70
+ }
71
+
72
+ static void write_instructions_binary (
73
+ std::ostream &out,
74
+ irep_serializationt &irepconverter,
75
+ const std::pair<const irep_idt, goto_functiont> &fct)
76
+ {
77
+ write_gb_word (out, fct.second .body .instructions .size ());
78
+
79
+ for (const auto &instruction : fct.second .body .instructions )
80
+ {
81
+ irepconverter.reference_convert (instruction.code (), out);
82
+ irepconverter.reference_convert (instruction.source_location (), out);
83
+ write_gb_word (out, (long )instruction.type ());
84
+
85
+ const auto condition =
86
+ instruction.has_condition () ? instruction.condition () : true_exprt ();
87
+ irepconverter.reference_convert (condition, out);
73
88
74
- // now write functions, but only those with body
89
+ write_gb_word (out, instruction. target_number );
75
90
91
+ write_gb_word (out, instruction.targets .size ());
92
+
93
+ for (const auto &t_it : instruction.targets )
94
+ write_gb_word (out, t_it->target_number );
95
+
96
+ write_gb_word (out, instruction.labels .size ());
97
+
98
+ for (const auto &l_it : instruction.labels )
99
+ irepconverter.write_string_ref (out, l_it);
100
+ }
101
+ }
102
+
103
+ // / Writes the functions to file, but only those with non-empty body.
104
+ static void write_goto_functions_binary (
105
+ std::ostream &out,
106
+ const goto_functionst &goto_functions,
107
+ irep_serializationt &irepconverter)
108
+ {
76
109
unsigned cnt=0 ;
77
110
for (const auto &gf_entry : goto_functions.function_map )
78
111
{
@@ -84,43 +117,27 @@ bool write_goto_binary(
84
117
85
118
for (const auto &fct : goto_functions.function_map )
86
119
{
87
- if (fct.second .body_available ())
88
- {
89
- // Since version 2, goto functions are not converted to ireps,
90
- // instead they are saved in a custom binary format
120
+ if (!fct.second .body_available ())
121
+ continue ;
91
122
92
- write_gb_string (out, id2string (fct.first )); // name
93
- write_gb_word (out, fct.second .body .instructions .size ()); // # instructions
94
-
95
- for (const auto &instruction : fct.second .body .instructions )
96
- {
97
- irepconverter.reference_convert (instruction.code (), out);
98
- irepconverter.reference_convert (instruction.source_location (), out);
99
- write_gb_word (out, (long )instruction.type ());
100
-
101
- const auto condition =
102
- instruction.has_condition () ? instruction.condition () : true_exprt ();
103
- irepconverter.reference_convert (condition, out);
104
-
105
- write_gb_word (out, instruction.target_number );
106
-
107
- write_gb_word (out, instruction.targets .size ());
108
-
109
- for (const auto &t_it : instruction.targets )
110
- write_gb_word (out, t_it->target_number );
111
-
112
- write_gb_word (out, instruction.labels .size ());
123
+ // Since version 2, goto functions are not converted to ireps,
124
+ // instead they are saved in a custom binary format
113
125
114
- for (const auto &l_it : instruction.labels )
115
- irepconverter.write_string_ref (out, l_it);
116
- }
117
- }
126
+ const auto function_name = id2string (fct.first );
127
+ write_gb_string (out, function_name);
128
+ write_instructions_binary (out, irepconverter, fct);
118
129
}
130
+ }
119
131
120
- // irepconverter.output_map(f);
121
- // irepconverter.output_string_map(f);
122
-
123
- return false ;
132
+ // / Writes a goto program to disc, using goto binary format
133
+ static void write_goto_binary (
134
+ std::ostream &out,
135
+ const symbol_table_baset &symbol_table,
136
+ const goto_functionst &goto_functions,
137
+ irep_serializationt &irepconverter)
138
+ {
139
+ write_symbol_table_binary (out, symbol_table, irepconverter);
140
+ write_goto_functions_binary (out, goto_functions, irepconverter);
124
141
}
125
142
126
143
// / Writes a goto program to disc
@@ -151,15 +168,19 @@ bool write_goto_binary(
151
168
irep_serializationt irepconverter (irepc);
152
169
153
170
if (version < GOTO_BINARY_VERSION)
171
+ {
154
172
throw invalid_command_line_argument_exceptiont (
155
173
" version " + std::to_string (version) + " no longer supported" ,
156
174
" supported version = " + std::to_string (GOTO_BINARY_VERSION));
157
- else if (version > GOTO_BINARY_VERSION)
175
+ }
176
+ if (version > GOTO_BINARY_VERSION)
177
+ {
158
178
throw invalid_command_line_argument_exceptiont (
159
179
" unknown goto binary version " + std::to_string (version),
160
180
" supported version = " + std::to_string (GOTO_BINARY_VERSION));
161
- else
162
- return write_goto_binary (out, symbol_table, goto_functions, irepconverter);
181
+ }
182
+ write_goto_binary (out, symbol_table, goto_functions, irepconverter);
183
+ return false ;
163
184
}
164
185
165
186
// / Writes a goto program to disc
0 commit comments