ROSE 0.11.145.147
ToSource.h
1#ifndef ROSE_BinaryAnalysis_ToSource_H
2#define ROSE_BinaryAnalysis_ToSource_H
3#include <featureTests.h>
4#ifdef ROSE_ENABLE_BINARY_ANALYSIS
5
6#include <Rose/BinaryAnalysis/Disassembler/BasicTypes.h>
7#include <Rose/BinaryAnalysis/Partitioner2/BasicTypes.h>
8#include <Rose/BinaryAnalysis/InstructionSemantics/SourceAstSemantics.h>
9#include <Rose/BinaryAnalysis/InstructionSemantics/TraceSemantics.h>
10#include <Rose/Diagnostics.h>
11#include <Rose/Exception.h>
12
13#include <Sawyer/CommandLine.h>
14
15namespace Rose {
16namespace BinaryAnalysis {
17
23public:
24
54
56 class Exception: public Rose::Exception {
57 public:
59 Exception(const std::string &mesg): Rose::Exception(mesg) {}
60 };
61
62private:
63 static Diagnostics::Facility mlog;
64 Settings settings_;
65 Disassembler::BasePtr disassembler_;
69
70public:
76
81 explicit BinaryToSource(const Settings&);
82
84
87
91 static void initDiagnostics();
92
96 const Settings& settings() const { return settings_; }
97
105
106#if 0 // [Robb P. Matzke 2015-10-06]: not implemented yet
112 void generateSource(const Partitioner2::PartitionerConstPtr&, SgSourceFile *sourceAst);
113#endif
114
115private:
116 // (Re)initialize the instruction semantics machinery so it is suitable for this architecture.
117 void init(const Partitioner2::PartitionerConstPtr&);
118
119 // Emit the file prologue, #include statements, extern declarations, etc.
120 void emitFilePrologue(const Partitioner2::PartitionerConstPtr&, std::ostream&);
121
122 // Declare the global register variables
123 void declareGlobalRegisters(std::ostream&);
124
125 // Define interrupt handlers
126 void defineInterrupts(std::ostream&);
127
128 // Emit accumulated side effects and/or SSA. */
129 void emitEffects(std::ostream&);
130
131 // Emit code for one instruction
132 void emitInstruction(SgAsmInstruction*, std::ostream&);
133
134 // Emit code for one basic block
135 void emitBasicBlock(const Partitioner2::PartitionerConstPtr&, const Partitioner2::BasicBlockPtr&, std::ostream&);
136
137 // Emit code for one function
138 void emitFunction(const Partitioner2::PartitionerConstPtr&, const Partitioner2::FunctionPtr&, std::ostream&);
139
140 // Emit code for all functions
141 void emitAllFunctions(const Partitioner2::PartitionerConstPtr&, std::ostream&);
142
143 // Emit the function_call dispatcher that decides which C function should be called next.
144 void emitFunctionDispatcher(const Partitioner2::PartitionerConstPtr&, std::ostream&);
145
146 // Emit the initialize_memory function.
147 void emitMemoryInitialization(const Partitioner2::PartitionerConstPtr&, std::ostream&);
148
149 // Emit the "main" function.
150 void emitMain(const Partitioner2::PartitionerConstPtr&, std::ostream&);
151};
152
153} // namespace
154} // namespace
155
156#endif
157#endif
Exceptions thrown by this analysis.
Definition ToSource.h:56
Exception(const std::string &mesg)
Constructs an exception with the specified message.
Definition ToSource.h:59
Convert binary to low-level C source code.
Definition ToSource.h:22
static Sawyer::CommandLine::SwitchGroup commandLineSwitches(Settings &)
Command-line switch parsing.
static void initDiagnostics()
Initialize diagnostic streams.
BinaryToSource(const Settings &)
Construct the analyzer with specified settings.
const Settings & settings() const
Property: Configuration settings.
Definition ToSource.h:96
BinaryToSource()
Default constructor.
void generateSource(const Partitioner2::PartitionerConstPtr &, std::ostream &)
Generate source code as text.
Base class for all ROSE exceptions.
A collection of related switch declarations.
Collection of streams.
Definition Message.h:1606
Holds a value or nothing.
Definition Optional.h:56
Base class for machine instructions.
boost::shared_ptr< Dispatcher > DispatcherPtr
Shared-ownership pointer to a semantics instruction dispatcher.
boost::shared_ptr< class RiscOperators > RiscOperatorsPtr
Shared-ownership pointer for basic semantic operations.
boost::shared_ptr< class RiscOperators > RiscOperatorsPtr
Shared-ownership pointer to trace-semantics RISC operations.
The ROSE library.
Settings to control this translator's behavior.
Definition ToSource.h:26
Sawyer::Optional< rose_addr_t > initialStackPointer
Optional initial value for the stack pointer.
Definition ToSource.h:39
Settings()
Constructs the default settings.
Definition ToSource.h:51
Sawyer::Optional< rose_addr_t > initialInstructionPointer
Optional initial value for the instruction pointer.
Definition ToSource.h:36
bool zeroMemoryArray
Whether to zero the memory array, or just allocated with malloc.
Definition ToSource.h:48
Sawyer::Optional< rose_addr_t > allocateMemoryArray
Whether to allocate the global memory array.
Definition ToSource.h:45
bool traceRiscOps
Trace the RISC operators for debugging.
Definition ToSource.h:29
bool traceInsnExecution
Generate code that prints instructions.
Definition ToSource.h:33