2018-04-23 18:58:05 +02:00
|
|
|
/** Generates C code from SimpleDwarf */
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <ostream>
|
2018-04-24 17:44:09 +02:00
|
|
|
#include <functional>
|
2018-05-11 13:09:35 +02:00
|
|
|
#include <memory>
|
2018-04-23 18:58:05 +02:00
|
|
|
|
|
|
|
#include "SimpleDwarf.hpp"
|
2018-05-11 13:09:35 +02:00
|
|
|
#include "PcListReader.hpp"
|
2018-04-23 18:58:05 +02:00
|
|
|
|
|
|
|
class CodeGenerator {
|
|
|
|
public:
|
2018-04-24 17:44:09 +02:00
|
|
|
/// A function deriving a generated function name from a FDE
|
|
|
|
typedef std::function<std::string(const SimpleDwarf::Fde&)>
|
|
|
|
NamingScheme;
|
|
|
|
|
2018-04-23 18:58:05 +02:00
|
|
|
/// Unimplemented case
|
|
|
|
class NotImplementedCase: public std::exception {};
|
|
|
|
|
|
|
|
/** Create a CodeGenerator to generate code for the given dwarf, on the
|
|
|
|
* given std::ostream object (eg. cout). */
|
2018-04-24 17:44:09 +02:00
|
|
|
CodeGenerator(const SimpleDwarf& dwarf, std::ostream& os,
|
|
|
|
NamingScheme naming_scheme);
|
2018-04-23 18:58:05 +02:00
|
|
|
|
|
|
|
/// Actually generate the code on the given stream
|
|
|
|
void generate();
|
|
|
|
|
|
|
|
private: //meth
|
2018-04-24 17:44:09 +02:00
|
|
|
struct LookupEntry {
|
|
|
|
std::string name;
|
|
|
|
uintptr_t beg, end;
|
|
|
|
};
|
|
|
|
|
2018-04-23 18:58:05 +02:00
|
|
|
void gen_of_dwarf();
|
2018-04-30 13:23:48 +02:00
|
|
|
void gen_unwind_func_header(const std::string& name);
|
|
|
|
void gen_unwind_func_footer();
|
|
|
|
void gen_function_of_fde(const SimpleDwarf::Fde& fde);
|
|
|
|
void gen_switchpart_of_fde(const SimpleDwarf::Fde& fde);
|
2018-04-23 18:58:05 +02:00
|
|
|
void gen_of_row(
|
|
|
|
const SimpleDwarf::DwRow& row,
|
|
|
|
uintptr_t row_end);
|
2018-05-11 13:09:35 +02:00
|
|
|
void gen_case(uintptr_t low_bound, uintptr_t high_bound);
|
2018-04-23 18:58:05 +02:00
|
|
|
void gen_of_reg(
|
|
|
|
const SimpleDwarf::DwRegister& reg);
|
|
|
|
|
2018-04-24 17:44:09 +02:00
|
|
|
void gen_lookup(const std::vector<LookupEntry>& entries);
|
|
|
|
|
2018-04-23 18:58:05 +02:00
|
|
|
private:
|
|
|
|
SimpleDwarf dwarf;
|
|
|
|
std::ostream& os;
|
2018-05-11 13:09:35 +02:00
|
|
|
std::unique_ptr<PcListReader> pc_list;
|
2018-04-24 17:44:09 +02:00
|
|
|
|
|
|
|
NamingScheme naming_scheme;
|
2018-04-23 18:58:05 +02:00
|
|
|
};
|