dwarf-assembly/src/CodeGenerator.hpp

49 lines
1.3 KiB
C++
Raw Normal View History

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-04-23 18:58:05 +02:00
#include "SimpleDwarf.hpp"
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();
void gen_of_fde(const SimpleDwarf::Fde& fde);
void gen_of_row(
const SimpleDwarf::DwRow& row,
uintptr_t row_end);
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-04-24 17:44:09 +02:00
NamingScheme naming_scheme;
2018-04-23 18:58:05 +02:00
};