@@ -28,11 +28,62 @@ void link_to_library(
28
28
void (const std::set<irep_idt> &, symbol_tablet &, message_handlert &)>
29
29
&library)
30
30
{
31
- link_to_library (
32
- goto_model.symbol_table ,
33
- goto_model.goto_functions ,
34
- message_handler,
35
- library);
31
+ // this needs a fixedpoint, as library functions
32
+ // may depend on other library functions
33
+
34
+ std::set<irep_idt> added_functions;
35
+
36
+ while (true )
37
+ {
38
+ std::unordered_set<irep_idt> called_functions =
39
+ compute_called_functions (goto_model.goto_functions );
40
+
41
+ // eliminate those for which we already have a body
42
+
43
+ std::set<irep_idt> missing_functions;
44
+
45
+ for (const auto &id : called_functions)
46
+ {
47
+ goto_functionst::function_mapt::const_iterator f_it =
48
+ goto_model.goto_functions .function_map .find (id);
49
+
50
+ if (
51
+ f_it != goto_model.goto_functions .function_map .end () &&
52
+ f_it->second .body_available ())
53
+ {
54
+ // it's overridden!
55
+ }
56
+ else if (added_functions.find (id) != added_functions.end ())
57
+ {
58
+ // already added
59
+ }
60
+ else
61
+ missing_functions.insert (id);
62
+ }
63
+
64
+ // done?
65
+ if (missing_functions.empty ())
66
+ break ;
67
+
68
+ library (missing_functions, goto_model.symbol_table , message_handler);
69
+
70
+ // convert to CFG
71
+ for (const auto &id : missing_functions)
72
+ {
73
+ if (
74
+ goto_model.symbol_table .symbols .find (id) !=
75
+ goto_model.symbol_table .symbols .end ())
76
+ {
77
+ goto_convert (
78
+ id,
79
+ goto_model.symbol_table ,
80
+ goto_model.goto_functions ,
81
+ message_handler);
82
+ }
83
+
84
+ added_functions.insert (id);
85
+ }
86
+ }
36
87
}
37
88
38
89
// / Complete missing function definitions using the \p library.
0 commit comments