2021-07-01 21:38:19 -04:00
|
|
|
#include "static_refs.h"
|
2021-03-14 19:06:51 -04:00
|
|
|
#include "common/goos/PrettyPrinter.h"
|
|
|
|
#include "decompiler/Function/Function.h"
|
|
|
|
#include "decompiler/ObjectFile/LinkedObjectFile.h"
|
|
|
|
#include "decompiler/analysis/final_output.h"
|
|
|
|
|
|
|
|
namespace decompiler {
|
2021-07-01 21:38:19 -04:00
|
|
|
int insert_static_refs(Form* top_level_form,
|
|
|
|
FormPool& pool,
|
|
|
|
const Function& function,
|
|
|
|
const DecompilerTypeSystem&) {
|
2021-03-14 19:06:51 -04:00
|
|
|
int replaced = 0;
|
|
|
|
top_level_form->apply_form([&](Form* f) {
|
|
|
|
auto atom = form_as_atom(f);
|
|
|
|
if (atom && atom->is_static_addr()) {
|
|
|
|
auto lab = function.ir2.env.file->labels.at(atom->label());
|
|
|
|
auto& env = function.ir2.env;
|
|
|
|
auto label_kv = env.label_types().find(lab.name);
|
|
|
|
if (label_kv != env.label_types().end()) {
|
|
|
|
if (label_kv->second.type_name == "_lambda_") {
|
|
|
|
auto& file = env.file;
|
|
|
|
auto other_func = file->try_get_function_at_label(atom->label());
|
|
|
|
if (other_func) {
|
2021-07-02 12:27:46 -04:00
|
|
|
auto result = final_output_lambda(*other_func);
|
2021-03-14 19:06:51 -04:00
|
|
|
f->clear();
|
|
|
|
f->push_back(pool.alloc_element<LambdaDefinitionElement>(result));
|
2021-06-04 13:43:19 -04:00
|
|
|
replaced++;
|
2021-03-14 19:06:51 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2021-07-01 21:38:19 -04:00
|
|
|
|
|
|
|
top_level_form->apply([&](FormElement* fe) {
|
|
|
|
auto as_static_data = dynamic_cast<DecompiledDataElement*>(fe);
|
|
|
|
if (as_static_data) {
|
|
|
|
as_static_data->do_decomp(function.ir2.env, function.ir2.env.file);
|
|
|
|
}
|
|
|
|
});
|
2021-03-14 19:06:51 -04:00
|
|
|
return replaced;
|
|
|
|
}
|
|
|
|
} // namespace decompiler
|