ROSE 0.11.145.192
Unparser/Base.h
1#ifndef ROSE_BinaryAnalysis_Unparser_Base_H
2#define ROSE_BinaryAnalysis_Unparser_Base_H
3#include <featureTests.h>
4#ifdef ROSE_ENABLE_BINARY_ANALYSIS
5
6#include <Rose/BinaryAnalysis/BasicTypes.h>
7#include <Rose/BinaryAnalysis/Partitioner2/BasicTypes.h>
8#include <Rose/BinaryAnalysis/Partitioner2/ControlFlowGraph.h>
9#include <Rose/BinaryAnalysis/Partitioner2/FunctionCallGraph.h>
10#include <Rose/BinaryAnalysis/Reachability.h>
11#include <Rose/BinaryAnalysis/RegisterNames.h>
12#include <Rose/BinaryAnalysis/Unparser/EdgeArrows.h>
13#include <Rose/BinaryAnalysis/Unparser/Settings.h>
14#include <Rose/BitFlags.h>
15#include <Rose/Progress.h>
16
17#include <Sawyer/Map.h>
18#include <Sawyer/Message.h>
19#include <Sawyer/SharedObject.h>
20
21namespace Rose {
22namespace BinaryAnalysis {
23namespace Unparser {
24
26typedef std::map<uint64_t, std::string> LabelMap;
27
30
31// used internally to initialize mlog
32void initDiagnostics();
33
35// Supporting functions
37
42 ROSE_DEPRECATED("not called by anything");
43
45// Margins containing arrows
47
92
94// Output style
96
99 std::vector<Style> stack_;
100 Style current_;
101 Color::Colorization colorization_;
102
103public:
104 StyleStack() {}
105
109 Color::Colorization colorization() const { return colorization_; }
110 void colorization(const Color::Colorization c) { colorization_ = c; }
116 size_t push(const Style&);
117
121 void pop();
122
124 void popTo(size_t);
125
127 void reset();
128
130 size_t size() const;
131
137 const Style& current() const;
138
139private:
140 void merge(const Style &style); // merge style into current_
141 void mergeAll(); // recalculate current_ based on stack_
142};
143
146 StyleStack &stack_;
147 size_t n_;
148 Style current_;
149 Style previous_;
150public:
155 StyleGuard(StyleStack &stack, const Style &style)
156 : stack_(stack) {
157 previous_ = stack_.current();
158 n_ = stack_.push(style);
159 current_ = stack_.current();
160 }
161
162 StyleGuard(StyleStack &stack, const Style &first, const Style &second)
163 : stack_(stack) {
164 previous_ = stack_.current();
165 n_ = stack_.push(first);
166 stack_.push(second);
167 current_ = stack_.current();
168 }
169
170 ~StyleGuard() {
171 stack_.popTo(n_);
172 }
173
175 std::string render() const;
176
178 std::string restore() const;
179
181 const Style& current() const {
182 return current_;
183 }
184
186 const Style& previous() const {
187 return previous_;
188 }
189};
190
192// State of the unparser (the unparser itself is const during unparsing)
194
199class State {
200public:
203private:
206 Partitioner2::FunctionPtr currentFunction_;
207 Partitioner2::BasicBlockPtr currentBasicBlock_;
209 SgAsmExpression *currentExpression_;
210 std::string nextInsnLabel_;
211 AddrString basicBlockLabels_;
212 RegisterNames registerNames_;
213 const Base &frontUnparser_;
214 std::vector<Reachability::ReasonFlags> cfgVertexReachability_;
215 Sawyer::Container::Map<Reachability::ReasonFlags::Vector, std::string> reachabilityNames_; // map reachability value to name
216 ArrowMargin intraFunctionCfgArrows_; // arrows for the intra-function control flow graphs
217 ArrowMargin intraFunctionBlockArrows_; // user-defined intra-function arrows to/from blocks
218 ArrowMargin globalBlockArrows_; // user-defined global arrows to/from blocks
219 bool cfgArrowsPointToInsns_; // arrows point to insns? else predecessor/successor lines
220 StyleStack styleStack_; // styles
221 bool isPostInstruction_ = false; // show extra information appearing after an instruction
222
223public:
225 virtual ~State();
226
229
232
239 const std::vector<Reachability::ReasonFlags> cfgVertexReachability() const;
240 void cfgVertexReachability(const std::vector<Reachability::ReasonFlags>&);
248
261 const ArrowMargin& intraFunctionCfgArrows() const { return intraFunctionCfgArrows_; }
262 ArrowMargin& intraFunctionCfgArrows() { return intraFunctionCfgArrows_; }
278 const ArrowMargin& intraFunctionBlockArrows() const { return intraFunctionBlockArrows_; }
279 ArrowMargin& intraFunctionBlockArrows() { return intraFunctionBlockArrows_; }
290 const ArrowMargin& globalBlockArrows() const { return globalBlockArrows_; }
291 ArrowMargin& globalBlockArrows() { return globalBlockArrows_; }
296
299
307 Sawyer::Optional<EdgeArrows::EndpointId> currentPredSuccId() const { return currentPredSuccId_; }
318 bool cfgArrowsPointToInsns() const { return cfgArrowsPointToInsns_; }
319 void cfgArrowsPointToInsns(bool b) { cfgArrowsPointToInsns_ = b; }
325 const StyleStack& styleStack() const { return styleStack_; }
326 StyleStack& styleStack() { return styleStack_; }
343 void reachabilityName(Reachability::Reason value, const std::string &name);
347 Partitioner2::FunctionPtr currentFunction() const;
348 void currentFunction(const Partitioner2::FunctionPtr&);
349
350 Partitioner2::BasicBlockPtr currentBasicBlock() const;
351 void currentBasicBlock(const Partitioner2::BasicBlockPtr&);
352
353 SgAsmExpression* currentExpression() const;
354 void currentExpression(SgAsmExpression*);
355
356 const std::string& nextInsnLabel() const;
357 void nextInsnLabel(const std::string&);
358
359 const RegisterNames& registerNames() const;
360 void registerNames(const RegisterNames &r);
361
362 const AddrString& basicBlockLabels() const;
363 AddrString& basicBlockLabels();
364
365 bool isPostInstruction() const;
366 void isPostInstruction(bool);
367
369 const Base& frontUnparser() const;
370};
371
373// Base unparser
375
423public:
425
426private:
427 Architecture::BaseConstPtr architecture_; // non-null architecture
428 Ptr nextUnparser_;
429
430protected:
431 explicit Base(const Architecture::BaseConstPtr&);
432 explicit Base(const Ptr &nextUnparser);
433
434public:
435 virtual Ptr copy() const = 0;
436 virtual ~Base();
437
447 virtual const Settings& settings() const = 0;
448 virtual Settings& settings() = 0;
449 void settings(const Settings &s) {
450 settings() = s;
451 }
461 Ptr nextUnparser() const { return nextUnparser_; }
462 void nextUnparser(Ptr next) { nextUnparser_ = next; }
469
477 void operator()(std::ostream&, const Partitioner2::PartitionerConstPtr&) const /*final*/;
478 void operator()(std::ostream&, const Partitioner2::PartitionerConstPtr&, SgAsmInstruction*) const /*final*/;
479 void operator()(std::ostream&, const Partitioner2::PartitionerConstPtr&, SgAsmExpression*) const /*final*/;
480 void operator()(std::ostream&, const Partitioner2::PartitionerConstPtr&, const Partitioner2::BasicBlockPtr&) const /*final*/;
481 void operator()(std::ostream&, const Partitioner2::PartitionerConstPtr&, const Partitioner2::DataBlockPtr&) const /*final*/;
482 void operator()(std::ostream&, const Partitioner2::PartitionerConstPtr&, const Partitioner2::FunctionPtr&) const /*final*/;
483 void operator()(std::ostream&, SgAsmInstruction*) const /*final*/;
491 std::string operator()(const Partitioner2::PartitionerConstPtr&, const Progress::Ptr& = Progress::Ptr()) const /*final*/;
492 std::string operator()(const Partitioner2::PartitionerConstPtr&, SgAsmInstruction*) const /*final*/;
493 std::string operator()(const Partitioner2::PartitionerConstPtr&, SgAsmExpression*) const /*final*/;
494 std::string operator()(const Partitioner2::PartitionerConstPtr&, const Partitioner2::BasicBlockPtr&) const /*final*/;
495 std::string operator()(const Partitioner2::PartitionerConstPtr&, const Partitioner2::DataBlockPtr&) const /*final*/;
496 std::string operator()(const Partitioner2::PartitionerConstPtr&, const Partitioner2::FunctionPtr&) const /*final*/;
497 std::string operator()(SgAsmInstruction*) const /*final*/;
500public:
506 void unparse(std::ostream&, const Partitioner2::PartitionerConstPtr&, const Progress::Ptr& = Progress::Ptr()) const /*final*/;
507 void unparse(std::ostream&, const Partitioner2::PartitionerConstPtr&, SgAsmInstruction*) const /*final*/;
508 void unparse(std::ostream&, const Partitioner2::PartitionerConstPtr&, SgAsmExpression*) const /*final*/;
509 void unparse(std::ostream&, const Partitioner2::PartitionerConstPtr&, const Partitioner2::BasicBlockPtr&) const /*final*/;
510 void unparse(std::ostream&, const Partitioner2::PartitionerConstPtr&, const Partitioner2::DataBlockPtr&) const /*final*/;
511 void unparse(std::ostream&, const Partitioner2::PartitionerConstPtr&, const Partitioner2::FunctionPtr&) const /*final*/;
512 void unparse(std::ostream&, SgAsmInstruction*) const /*final*/;
513 void unparse(std::ostream&, SgAsmExpression*) const /*final*/;
514
515 std::string unparse(const Partitioner2::PartitionerConstPtr&, const Progress::Ptr& = Progress::Ptr()) const /*final*/;
516 std::string unparse(const Partitioner2::PartitionerConstPtr&, SgAsmInstruction*) const /*final*/;
517 std::string unparse(const Partitioner2::PartitionerConstPtr&, SgAsmExpression*) const /*final*/;
518 std::string unparse(const Partitioner2::PartitionerConstPtr&, const Partitioner2::BasicBlockPtr&) const /*final*/;
519 std::string unparse(const Partitioner2::PartitionerConstPtr&, const Partitioner2::DataBlockPtr&) const /*final*/;
520 std::string unparse(const Partitioner2::PartitionerConstPtr&, const Partitioner2::FunctionPtr&) const /*final*/;
521 std::string unparse(SgAsmInstruction*) const /*final*/;
522 std::string unparse(SgAsmExpression*) const /*final*/;
525public:
548 virtual void emitFunction(std::ostream&, const Partitioner2::FunctionPtr&, State&) const;
549 virtual void emitFunctionPrologue(std::ostream&, const Partitioner2::FunctionPtr&, State&) const;
550 virtual void emitFunctionBody(std::ostream&, const Partitioner2::FunctionPtr&, State&) const;
551 virtual void emitFunctionEpilogue(std::ostream&, const Partitioner2::FunctionPtr&, State&) const;
552
553 virtual void emitFunctionSourceLocation(std::ostream&, const Partitioner2::FunctionPtr&, State&) const;
554 virtual void emitFunctionReasons(std::ostream&, const Partitioner2::FunctionPtr&, State&) const;
555 virtual void emitFunctionCallers(std::ostream&, const Partitioner2::FunctionPtr&, State&) const;
556 virtual void emitFunctionCallees(std::ostream&, const Partitioner2::FunctionPtr&, State&) const;
557 virtual void emitFunctionComment(std::ostream&, const Partitioner2::FunctionPtr&, State&) const;
558 virtual void emitFunctionStackDelta(std::ostream&, const Partitioner2::FunctionPtr&, State&) const;
559 virtual void emitFunctionCallingConvention(std::ostream&, const Partitioner2::FunctionPtr&, State&) const;
560 virtual void emitFunctionNoopAnalysis(std::ostream&, const Partitioner2::FunctionPtr&, State&) const;
561 virtual void emitFunctionMayReturn(std::ostream&, const Partitioner2::FunctionPtr&, State&) const;
562
563 virtual void emitDataBlockSourceLocation(std::ostream&, const Partitioner2::DataBlockPtr&, State&) const;
564 virtual void emitDataBlock(std::ostream&, const Partitioner2::DataBlockPtr&, State&) const;
565 virtual void emitDataBlockPrologue(std::ostream&, const Partitioner2::DataBlockPtr&, State&) const;
566 virtual void emitDataBlockBody(std::ostream&, const Partitioner2::DataBlockPtr&, State&) const;
567 virtual void emitDataBlockEpilogue(std::ostream&, const Partitioner2::DataBlockPtr&, State&) const;
568
569 virtual void emitBasicBlock(std::ostream&, const Partitioner2::BasicBlockPtr&, State&) const;
570 virtual void emitBasicBlockPrologue(std::ostream&, const Partitioner2::BasicBlockPtr&, State&) const;
571 virtual void emitBasicBlockBody(std::ostream&, const Partitioner2::BasicBlockPtr&, State&) const;
572 virtual void emitBasicBlockEpilogue(std::ostream&, const Partitioner2::BasicBlockPtr&, State&) const;
573
574 virtual void emitBasicBlockSourceLocation(std::ostream&, const Partitioner2::BasicBlockPtr&, State&) const;
575 virtual void emitBasicBlockComment(std::ostream&, const Partitioner2::BasicBlockPtr&, State&) const;
576 virtual void emitBasicBlockSharing(std::ostream&, const Partitioner2::BasicBlockPtr&, State&) const;
577 virtual void emitBasicBlockPredecessors(std::ostream&, const Partitioner2::BasicBlockPtr&, State&) const;
578 virtual void emitBasicBlockSuccessors(std::ostream&, const Partitioner2::BasicBlockPtr&, State&) const;
579 virtual void emitBasicBlockReachability(std::ostream&, const Partitioner2::BasicBlockPtr&, State&) const;
580
581 virtual void emitInstruction(std::ostream&, SgAsmInstruction*, State&) const;
582 virtual void emitInstructionPrologue(std::ostream&, SgAsmInstruction*, State&) const;
583 virtual void emitInstructionBody(std::ostream&, SgAsmInstruction*, State&) const;
584 virtual void emitInstructionEpilogue(std::ostream&, SgAsmInstruction*, State&) const;
585
586 virtual void emitInstructionAddress(std::ostream&, SgAsmInstruction*, State&) const;
587 virtual void emitInstructionBytes(std::ostream&, SgAsmInstruction*, State&) const;
588 virtual void emitInstructionStackDelta(std::ostream&, SgAsmInstruction*, State&) const;
589 virtual void emitInstructionFrameDelta(std::ostream&, SgAsmInstruction*, State&) const;
590 virtual void emitInstructionMnemonic(std::ostream&, SgAsmInstruction*, State&) const;
591 virtual void emitInstructionOperands(std::ostream&, SgAsmInstruction*, State&) const;
592 virtual void emitInstructionComment(std::ostream&, SgAsmInstruction*, State&) const;
593
594 virtual void emitInstructionSemantics(std::ostream&, SgAsmInstruction*, State&) const;
595
596 virtual void emitOperand(std::ostream&, SgAsmExpression*, State&) const;
597 virtual void emitOperandPrologue(std::ostream&, SgAsmExpression*, State&) const;
598 virtual void emitOperandBody(std::ostream&, SgAsmExpression*, State&) const;
599 virtual void emitOperandEpilogue(std::ostream&, SgAsmExpression*, State&) const;
600
601 virtual void emitExpression(std::ostream&, SgAsmExpression*, State&) const;
602#ifdef ROSE_ENABLE_ASM_AARCH32
603 virtual std::vector<std::string> emitAarch32Coprocessor(std::ostream&, SgAsmAarch32Coprocessor*, State&) const;
604#endif
605#ifdef ROSE_ENABLE_ASM_AARCH64
606 virtual std::vector<std::string> emitAarch64AtOperand(std::ostream&, SgAsmAarch64AtOperand*, State&) const;
607 virtual std::vector<std::string> emitAarch64BarrierOperand(std::ostream&, SgAsmAarch64BarrierOperand*, State&) const;
608 virtual std::vector<std::string> emitAarch64CImmediateOperand(std::ostream&, SgAsmAarch64CImmediateOperand*, State&) const;
609 virtual std::vector<std::string> emitAarch64PrefetchOperand(std::ostream&, SgAsmAarch64PrefetchOperand*, State&) const;
610 virtual std::vector<std::string> emitAarch64PState(std::ostream&, SgAsmAarch64PState*, State&) const;
611 virtual std::vector<std::string> emitAarch64SysMoveOperand(std::ostream&, SgAsmAarch64SysMoveOperand*, State&) const;
612#endif
613 virtual std::vector<std::string> emitBinaryAdd(std::ostream&, SgAsmBinaryAdd*, State&) const;
614 virtual std::vector<std::string> emitBinaryAsr(std::ostream&, SgAsmBinaryAsr*, State&) const;
615 virtual std::vector<std::string> emitBinaryConcat(std::ostream&, SgAsmBinaryConcat*, State&) const;
616 virtual std::vector<std::string> emitBinaryDivide(std::ostream&, SgAsmBinaryDivide*, State&) const;
617 virtual std::vector<std::string> emitBinaryLsl(std::ostream&, SgAsmBinaryLsl*, State&) const;
618 virtual std::vector<std::string> emitBinaryLsr(std::ostream&, SgAsmBinaryLsr*, State&) const;
619 virtual std::vector<std::string> emitBinaryMsl(std::ostream&, SgAsmBinaryMsl*, State&) const;
620 virtual std::vector<std::string> emitBinaryMultiply(std::ostream&, SgAsmBinaryMultiply*, State&) const;
621 virtual std::vector<std::string> emitBinaryMod(std::ostream&, SgAsmBinaryMod*, State&) const;
622 virtual std::vector<std::string> emitBinaryPreupdate(std::ostream&, SgAsmBinaryPreupdate*, State&) const;
623 virtual std::vector<std::string> emitBinaryPostupdate(std::ostream&, SgAsmBinaryPostupdate*, State&) const;
624 virtual std::vector<std::string> emitBinaryRor(std::ostream&, SgAsmBinaryRor*, State&) const;
625 virtual std::vector<std::string> emitBinarySubtract(std::ostream&, SgAsmBinarySubtract*, State&) const;
626 virtual std::vector<std::string> emitByteOrder(std::ostream&, SgAsmByteOrder*, State&) const;
627 virtual std::vector<std::string> emitDirectRegisterExpression(std::ostream&, SgAsmDirectRegisterExpression*, State&) const;
628 virtual std::vector<std::string> emitExprListExp(std::ostream&, SgAsmExprListExp*, State&) const;
629 virtual std::vector<std::string> emitFloatValueExpression(std::ostream&, SgAsmFloatValueExpression*, State&) const;
630 virtual std::vector<std::string> emitIndirectRegisterExpression(std::ostream&, SgAsmIndirectRegisterExpression*, State&) const;
631 virtual std::vector<std::string> emitIntegerValueExpression(std::ostream&, SgAsmIntegerValueExpression*, State&) const;
632 virtual std::vector<std::string> emitMemoryReferenceExpression(std::ostream&, SgAsmMemoryReferenceExpression*, State&) const;
633 virtual std::vector<std::string> emitRegisterNames(std::ostream&, SgAsmRegisterNames*, State&) const;
634 virtual std::vector<std::string> emitRiscOperation(std::ostream&, SgAsmRiscOperation*, State&) const;
635 virtual std::vector<std::string> emitStackExpression(std::ostream&, SgAsmStackExpression*, State&) const;
636 virtual std::vector<std::string> emitUnaryMinus(std::ostream&, SgAsmUnaryMinus*, State&) const;
637 virtual std::vector<std::string> emitUnaryPlus(std::ostream&, SgAsmUnaryPlus*, State&) const;
638 virtual std::vector<std::string> emitUnarySignedExtend(std::ostream&, SgAsmUnarySignedExtend*, State&) const;
639 virtual std::vector<std::string> emitUnaryTruncate(std::ostream&, SgAsmUnaryTruncate*, State&) const;
640 virtual std::vector<std::string> emitUnaryUnsignedExtend(std::ostream&, SgAsmUnaryUnsignedExtend*, State&) const;
641
642 virtual void emitRegister(std::ostream&, RegisterDescriptor, State&) const;
643 virtual std::vector<std::string> emitUnsignedInteger(std::ostream&, const Sawyer::Container::BitVector&, State&) const;
644 virtual std::vector<std::string> emitSignedInteger(std::ostream&, const Sawyer::Container::BitVector&, State&) const;
645 virtual std::vector<std::string> emitInteger(std::ostream&, const Sawyer::Container::BitVector&, State&,
646 bool isSigned) const;
647 virtual bool emitAddress(std::ostream&, rose_addr_t, State&, bool always=true) const;
648 virtual bool emitAddress(std::ostream&, const Sawyer::Container::BitVector&, State&, bool always=true) const;
649 virtual void emitCommentBlock(std::ostream&, const std::string&, State&, const std::string &prefix = ";;; ") const;
650 virtual void emitTypeName(std::ostream&, SgAsmType*, State&) const;
651
652 virtual void emitLinePrefix(std::ostream&, State&) const;
655 //----- Other overrridable things -----
656public:
662 virtual void initializeState(State&) const;
663
669 virtual void updateIntraFunctionArrows(State&) const;
670
671 //----- Utility functions -----
672public:
674 static std::string leftJustify(const std::string&, size_t nchars);
675
681 static std::string juxtaposeColumns(const std::vector<std::string> &content, const std::vector<size_t> &minWidths,
682 const std::vector<std::pair<std::string, std::string> > &colorEscapes,
683 const std::string &columnSeparator = " ");
684
690 static bool ascendingSourceAddress(Partitioner2::ControlFlowGraph::ConstEdgeIterator a,
691 Partitioner2::ControlFlowGraph::ConstEdgeIterator b);
692
698 static bool ascendingTargetAddress(Partitioner2::ControlFlowGraph::ConstEdgeIterator a,
699 Partitioner2::ControlFlowGraph::ConstEdgeIterator b);
700
705 static std::vector<Partitioner2::ControlFlowGraph::ConstEdgeIterator>
707
712 static std::vector<Partitioner2::ControlFlowGraph::ConstEdgeIterator>
714};
715
717// Python API wrappers and functions
719
720#ifdef ROSE_ENABLE_PYTHON_API
721class PythonBase {
722 Base::Ptr base_;
723
724public:
725 PythonBase() {}
726
727 explicit PythonBase(const Base::Ptr &base)
728 : base_(base) {
729 ASSERT_not_null(base);
730 }
731
732 std::string unparse(const Partitioner2::PartitionerConstPtr &p) const {
733 return base_->unparse(p);
734 }
735
736 void print(const Partitioner2::PartitionerConstPtr &p) const {
737 base_->unparse(std::cout, p);
738 }
739};
740#endif
741
742} // namespace
743} // namespace
744} // namespace
745
746#endif
747#endif
Reason
Predefined bit flags for why something is reachable.
Describes (part of) a physical CPU register.
Convert a register descriptor to a name.
State associated with printing arrows in the margin.
Sawyer::Optional< EdgeArrows::EndpointId > latestEntity
Latest pointable entity that was encountered in the output.
Flags
Flags controlling the finer aspects of margin arrows.
@ POINTABLE_ENTITY_INSIDE
This flag is modified automatically by the emitLinePrefix function.
@ POINTABLE_ENTITY_START
Set this flag when you want the emitLinePrefix function to treat the next possible line as the start ...
@ POINTABLE_ENTITY_END
Set this flag when you want the emitLinePrefix function to treat the next line as the end of a pointa...
@ ALWAYS_RENDER
If set, then emit the prefix area even if we seem to be generating output that the unparser would oth...
void reset()
Reset the marging arrow state.
EdgeArrows arrows
The arrows to be displayed.
std::string render(Sawyer::Optional< EdgeArrows::EndpointId > currentEntity)
Generate the string to print in the margin.
BitFlags< Flags > flags
Flags that hold and/or control the output state.
Abstract base class for unparsers.
virtual void emitFunctionStackDelta(std::ostream &, const Partitioner2::FunctionPtr &, State &) const
Mid-level unparser function.
virtual std::vector< std::string > emitExprListExp(std::ostream &, SgAsmExprListExp *, State &) const
Mid-level unparser function.
virtual std::vector< std::string > emitBinaryPreupdate(std::ostream &, SgAsmBinaryPreupdate *, State &) const
Mid-level unparser function.
virtual Settings & settings()=0
Property: Settings associated with this unparser.
virtual std::vector< std::string > emitBinaryDivide(std::ostream &, SgAsmBinaryDivide *, State &) const
Mid-level unparser function.
virtual void emitInstructionPrologue(std::ostream &, SgAsmInstruction *, State &) const
Mid-level unparser function.
virtual void emitBasicBlockSuccessors(std::ostream &, const Partitioner2::BasicBlockPtr &, State &) const
Mid-level unparser function.
void operator()(std::ostream &, const Partitioner2::PartitionerConstPtr &, SgAsmInstruction *) const
Emit the entity to an output stream.
virtual std::vector< std::string > emitFloatValueExpression(std::ostream &, SgAsmFloatValueExpression *, State &) const
Mid-level unparser function.
virtual std::vector< std::string > emitIntegerValueExpression(std::ostream &, SgAsmIntegerValueExpression *, State &) const
Mid-level unparser function.
virtual void emitFunction(std::ostream &, const Partitioner2::FunctionPtr &, State &) const
Mid-level unparser function.
static bool ascendingSourceAddress(Partitioner2::ControlFlowGraph::ConstEdgeIterator a, Partitioner2::ControlFlowGraph::ConstEdgeIterator b)
Return true if edges are in order by source address.
void operator()(std::ostream &, const Partitioner2::PartitionerConstPtr &, const Partitioner2::BasicBlockPtr &) const
Emit the entity to an output stream.
virtual bool emitAddress(std::ostream &, const Sawyer::Container::BitVector &, State &, bool always=true) const
Mid-level unparser function.
virtual std::vector< std::string > emitInteger(std::ostream &, const Sawyer::Container::BitVector &, State &, bool isSigned) const
Mid-level unparser function.
virtual std::vector< std::string > emitBinaryMod(std::ostream &, SgAsmBinaryMod *, State &) const
Mid-level unparser function.
virtual std::vector< std::string > emitBinaryMultiply(std::ostream &, SgAsmBinaryMultiply *, State &) const
Mid-level unparser function.
void operator()(std::ostream &, const Partitioner2::PartitionerConstPtr &, SgAsmExpression *) const
Emit the entity to an output stream.
virtual std::vector< std::string > emitBinarySubtract(std::ostream &, SgAsmBinarySubtract *, State &) const
Mid-level unparser function.
virtual std::vector< std::string > emitUnaryUnsignedExtend(std::ostream &, SgAsmUnaryUnsignedExtend *, State &) const
Mid-level unparser function.
virtual std::vector< std::string > emitUnaryMinus(std::ostream &, SgAsmUnaryMinus *, State &) const
Mid-level unparser function.
virtual void emitDataBlockPrologue(std::ostream &, const Partitioner2::DataBlockPtr &, State &) const
Mid-level unparser function.
virtual void emitInstructionOperands(std::ostream &, SgAsmInstruction *, State &) const
Mid-level unparser function.
virtual std::vector< std::string > emitBinaryMsl(std::ostream &, SgAsmBinaryMsl *, State &) const
Mid-level unparser function.
virtual void emitInstructionFrameDelta(std::ostream &, SgAsmInstruction *, State &) const
Mid-level unparser function.
virtual void emitFunctionReasons(std::ostream &, const Partitioner2::FunctionPtr &, State &) const
Mid-level unparser function.
virtual void emitTypeName(std::ostream &, SgAsmType *, State &) const
Mid-level unparser function.
void operator()(std::ostream &, const Partitioner2::PartitionerConstPtr &, const Partitioner2::DataBlockPtr &) const
Emit the entity to an output stream.
virtual std::vector< std::string > emitUnaryTruncate(std::ostream &, SgAsmUnaryTruncate *, State &) const
Mid-level unparser function.
virtual void emitFunctionCallingConvention(std::ostream &, const Partitioner2::FunctionPtr &, State &) const
Mid-level unparser function.
virtual std::vector< std::string > emitBinaryLsl(std::ostream &, SgAsmBinaryLsl *, State &) const
Mid-level unparser function.
virtual void emitInstructionBody(std::ostream &, SgAsmInstruction *, State &) const
Mid-level unparser function.
virtual void emitBasicBlockSharing(std::ostream &, const Partitioner2::BasicBlockPtr &, State &) const
Mid-level unparser function.
virtual void initializeState(State &) const
Finish initializing the unparser state.
virtual void emitFunctionPrologue(std::ostream &, const Partitioner2::FunctionPtr &, State &) const
Mid-level unparser function.
virtual void emitDataBlock(std::ostream &, const Partitioner2::DataBlockPtr &, State &) const
Mid-level unparser function.
virtual const Settings & settings() const =0
Property: Settings associated with this unparser.
static bool ascendingTargetAddress(Partitioner2::ControlFlowGraph::ConstEdgeIterator a, Partitioner2::ControlFlowGraph::ConstEdgeIterator b)
Return true if edges are in order by target address.
virtual void emitDataBlockEpilogue(std::ostream &, const Partitioner2::DataBlockPtr &, State &) const
Mid-level unparser function.
virtual void emitInstructionEpilogue(std::ostream &, SgAsmInstruction *, State &) const
Mid-level unparser function.
void operator()(std::ostream &, SgAsmInstruction *) const
Emit the entity to an output stream.
virtual void emitCommentBlock(std::ostream &, const std::string &, State &, const std::string &prefix=";;; ") const
Mid-level unparser function.
virtual std::vector< std::string > emitSignedInteger(std::ostream &, const Sawyer::Container::BitVector &, State &) const
Mid-level unparser function.
void settings(const Settings &s)
Property: Settings associated with this unparser.
virtual void emitDataBlockBody(std::ostream &, const Partitioner2::DataBlockPtr &, State &) const
Mid-level unparser function.
virtual void emitBasicBlockComment(std::ostream &, const Partitioner2::BasicBlockPtr &, State &) const
Mid-level unparser function.
static std::vector< Partitioner2::ControlFlowGraph::ConstEdgeIterator > orderedBlockPredecessors(const Partitioner2::PartitionerConstPtr &, const Partitioner2::BasicBlockPtr &)
Ordered incoming CFG edges.
virtual void emitInstructionBytes(std::ostream &, SgAsmInstruction *, State &) const
Mid-level unparser function.
virtual void emitOperand(std::ostream &, SgAsmExpression *, State &) const
Mid-level unparser function.
virtual void emitLinePrefix(std::ostream &, State &) const
Mid-level unparser function.
virtual void emitInstructionAddress(std::ostream &, SgAsmInstruction *, State &) const
Mid-level unparser function.
Ptr nextUnparser() const
Property: Next parser in chain.
virtual std::vector< std::string > emitIndirectRegisterExpression(std::ostream &, SgAsmIndirectRegisterExpression *, State &) const
Mid-level unparser function.
void nextUnparser(Ptr next)
Property: Next parser in chain.
virtual void emitBasicBlockPrologue(std::ostream &, const Partitioner2::BasicBlockPtr &, State &) const
Mid-level unparser function.
virtual void emitBasicBlockReachability(std::ostream &, const Partitioner2::BasicBlockPtr &, State &) const
Mid-level unparser function.
virtual std::vector< std::string > emitUnsignedInteger(std::ostream &, const Sawyer::Container::BitVector &, State &) const
Mid-level unparser function.
virtual std::vector< std::string > emitMemoryReferenceExpression(std::ostream &, SgAsmMemoryReferenceExpression *, State &) const
Mid-level unparser function.
virtual void emitOperandEpilogue(std::ostream &, SgAsmExpression *, State &) const
Mid-level unparser function.
virtual void emitFunctionMayReturn(std::ostream &, const Partitioner2::FunctionPtr &, State &) const
Mid-level unparser function.
virtual std::vector< std::string > emitBinaryPostupdate(std::ostream &, SgAsmBinaryPostupdate *, State &) const
Mid-level unparser function.
virtual void emitDataBlockSourceLocation(std::ostream &, const Partitioner2::DataBlockPtr &, State &) const
Mid-level unparser function.
virtual void emitBasicBlockEpilogue(std::ostream &, const Partitioner2::BasicBlockPtr &, State &) const
Mid-level unparser function.
void operator()(std::ostream &, const Partitioner2::PartitionerConstPtr &) const
Emit the entity to an output stream.
virtual bool emitAddress(std::ostream &, rose_addr_t, State &, bool always=true) const
Mid-level unparser function.
virtual void emitInstructionComment(std::ostream &, SgAsmInstruction *, State &) const
Mid-level unparser function.
virtual std::vector< std::string > emitBinaryAsr(std::ostream &, SgAsmBinaryAsr *, State &) const
Mid-level unparser function.
virtual std::vector< std::string > emitRiscOperation(std::ostream &, SgAsmRiscOperation *, State &) const
Mid-level unparser function.
virtual std::vector< std::string > emitBinaryAdd(std::ostream &, SgAsmBinaryAdd *, State &) const
Mid-level unparser function.
std::string operator()(const Partitioner2::PartitionerConstPtr &, const Progress::Ptr &=Progress::Ptr()) const
Emit the entity to a string.
virtual void emitExpression(std::ostream &, SgAsmExpression *, State &) const
Mid-level unparser function.
virtual std::vector< std::string > emitUnarySignedExtend(std::ostream &, SgAsmUnarySignedExtend *, State &) const
Mid-level unparser function.
static std::vector< Partitioner2::ControlFlowGraph::ConstEdgeIterator > orderedBlockSuccessors(const Partitioner2::PartitionerConstPtr &, const Partitioner2::BasicBlockPtr &)
Ordered outgoing CFG edges.
void operator()(std::ostream &, const Partitioner2::PartitionerConstPtr &, const Partitioner2::FunctionPtr &) const
Emit the entity to an output stream.
virtual void emitInstructionStackDelta(std::ostream &, SgAsmInstruction *, State &) const
Mid-level unparser function.
virtual void emitBasicBlock(std::ostream &, const Partitioner2::BasicBlockPtr &, State &) const
Mid-level unparser function.
virtual void emitBasicBlockPredecessors(std::ostream &, const Partitioner2::BasicBlockPtr &, State &) const
Mid-level unparser function.
virtual void emitRegister(std::ostream &, RegisterDescriptor, State &) const
Mid-level unparser function.
virtual void emitBasicBlockSourceLocation(std::ostream &, const Partitioner2::BasicBlockPtr &, State &) const
Mid-level unparser function.
virtual void emitFunctionCallers(std::ostream &, const Partitioner2::FunctionPtr &, State &) const
Mid-level unparser function.
static std::string juxtaposeColumns(const std::vector< std::string > &content, const std::vector< size_t > &minWidths, const std::vector< std::pair< std::string, std::string > > &colorEscapes, const std::string &columnSeparator=" ")
Render a table row.
virtual void emitBasicBlockBody(std::ostream &, const Partitioner2::BasicBlockPtr &, State &) const
Mid-level unparser function.
virtual std::vector< std::string > emitBinaryConcat(std::ostream &, SgAsmBinaryConcat *, State &) const
Mid-level unparser function.
void unparse(std::ostream &, const Partitioner2::PartitionerConstPtr &, const Progress::Ptr &=Progress::Ptr()) const
High-level unparsing function.
virtual std::vector< std::string > emitBinaryLsr(std::ostream &, SgAsmBinaryLsr *, State &) const
Mid-level unparser function.
virtual void emitFunctionEpilogue(std::ostream &, const Partitioner2::FunctionPtr &, State &) const
Mid-level unparser function.
virtual void emitInstruction(std::ostream &, SgAsmInstruction *, State &) const
Mid-level unparser function.
virtual std::vector< std::string > emitDirectRegisterExpression(std::ostream &, SgAsmDirectRegisterExpression *, State &) const
Mid-level unparser function.
virtual void emitFunctionBody(std::ostream &, const Partitioner2::FunctionPtr &, State &) const
Mid-level unparser function.
virtual std::vector< std::string > emitBinaryRor(std::ostream &, SgAsmBinaryRor *, State &) const
Mid-level unparser function.
Architecture::BaseConstPtr architecture() const
Property: Architecture.
virtual void emitInstructionMnemonic(std::ostream &, SgAsmInstruction *, State &) const
Mid-level unparser function.
virtual void emitFunctionComment(std::ostream &, const Partitioner2::FunctionPtr &, State &) const
Mid-level unparser function.
virtual void emitFunctionCallees(std::ostream &, const Partitioner2::FunctionPtr &, State &) const
Mid-level unparser function.
virtual void emitFunctionSourceLocation(std::ostream &, const Partitioner2::FunctionPtr &, State &) const
Mid-level unparser function.
virtual std::vector< std::string > emitStackExpression(std::ostream &, SgAsmStackExpression *, State &) const
Mid-level unparser function.
virtual void emitInstructionSemantics(std::ostream &, SgAsmInstruction *, State &) const
Mid-level unparser function.
virtual std::vector< std::string > emitRegisterNames(std::ostream &, SgAsmRegisterNames *, State &) const
Mid-level unparser function.
static std::string leftJustify(const std::string &, size_t nchars)
Render a string left justified.
virtual void emitOperandPrologue(std::ostream &, SgAsmExpression *, State &) const
Mid-level unparser function.
virtual std::vector< std::string > emitUnaryPlus(std::ostream &, SgAsmUnaryPlus *, State &) const
Mid-level unparser function.
virtual void updateIntraFunctionArrows(State &) const
Calculate intra-function arrows.
virtual void emitOperandBody(std::ostream &, SgAsmExpression *, State &) const
Mid-level unparser function.
virtual void emitFunctionNoopAnalysis(std::ostream &, const Partitioner2::FunctionPtr &, State &) const
Mid-level unparser function.
virtual std::vector< std::string > emitByteOrder(std::ostream &, SgAsmByteOrder *, State &) const
Mid-level unparser function.
Renders textual margin arrows.
Definition EdgeArrows.h:36
bool cfgArrowsPointToInsns() const
Property: Whether CFG margin arrows point to instructions.
void currentPredSuccId(Sawyer::Optional< EdgeArrows::EndpointId > id)
Property: ID for CFG edge arrow endpoint.
const std::vector< Reachability::ReasonFlags > cfgVertexReachability() const
Property: Reachability analysis results.
Sawyer::Optional< EdgeArrows::EndpointId > currentPredSuccId() const
Property: ID for CFG edge arrow endpoint.
ArrowMargin & intraFunctionBlockArrows()
User-defined intra-function margin arrows.
ArrowMargin & globalBlockArrows()
User-defined arrows to basic blocks across entire output.
ArrowMargin & intraFunctionCfgArrows()
Control flow graph arrows within a function.
std::string reachabilityName(Reachability::ReasonFlags value) const
Assign a reachability name to a reachability value.
const Base & frontUnparser() const
First unparser in the chained list of unparsers.
const ArrowMargin & intraFunctionCfgArrows() const
Control flow graph arrows within a function.
Sawyer::Container::Map< rose_addr_t, std::string > AddrString
Map from address to string.
void thisIsBasicBlockFirstInstruction()
Call this when you're about to output the first instruction of a basic block.
void cfgArrowsPointToInsns(bool b)
Property: Whether CFG margin arrows point to instructions.
const StyleStack & styleStack() const
Property: Stack of styles.
Partitioner2::PartitionerConstPtr partitioner() const
Property: Partitioner, which may be null.
StyleStack & styleStack()
Property: Stack of styles.
Reachability::ReasonFlags isCfgVertexReachable(size_t vertexId) const
Returns reachability based on the cfgVertexReachability property.
void reachabilityName(Reachability::Reason value, const std::string &name)
Assign a reachability name to a reachability value.
const ArrowMargin & intraFunctionBlockArrows() const
User-defined intra-function margin arrows.
const Partitioner2::FunctionCallGraph & cg() const
Property: Call grap, which may be empty.
const ArrowMargin & globalBlockArrows() const
User-defined arrows to basic blocks across entire output.
void cfgVertexReachability(const std::vector< Reachability::ReasonFlags > &)
Property: Reachability analysis results.
void thisIsBasicBlockLastInstruction()
Call this when you're about to output the last instruction of a basic block.
Pushes a style and arranges for it to be popped later.
std::string render() const
Render style entry.
StyleGuard(StyleStack &stack, const Style &style)
Push style onto stack.
const Style & previous() const
Style before pushing.
std::string restore() const
Render style exit.
const Style & current() const
Current merged style.
size_t push(const Style &)
Push style onto stack.
const Style & current() const
Merged style.
size_t size() const
Number of styles on the stack.
void colorization(const Color::Colorization c)
Property: Colorization settings.
Color::Colorization colorization() const
Property: Colorization settings.
void popTo(size_t)
Pop until stack is a certain size.
void pop()
Pop top style from stack.
Stores a vector of enum bit flags.
A general, thread-safe way to report progress made on some task.
Definition Progress.h:167
Container associating values with keys.
Definition Sawyer/Map.h:72
Collection of streams.
Definition Message.h:1606
Represents no value.
Definition Optional.h:36
Holds a value or nothing.
Definition Optional.h:56
Base class for reference counted objects.
Operand referencing a Co-processor.
Expression that adds two operands.
Expression that performs an arithmetic, sign-bit preserving right shift.
Expression that concatenates two values to form a wider value.
Expression that divides the first operand by the second.
Expression that performs a logical left shift operation.
Expression that performs a logical, sign-bit non-preserving right shift.
Expression that returns the remainder when dividing the first operand by the second.
Expression that performs a logical left shift operation filling low-order bits with one.
Expression that multiplies two operands.
Expression that represents an update to a storage location.
Expression that represents an update to a storage location.
Expression that performs a right rotate.
Expression that subtracts the second operand from the first.
Byte order specification.
Expression representing a machine register.
List of expression nodes.
Base class for expressions.
Registers accessed indirectly.
Base class for machine instructions.
Base class for integer values.
Reference to memory locations.
An ordered list of registers.
Static representation of instruction semantics.
Base class for references to a machine register.
Base class for binary types.
Expression represting negation.
Expression representing a (no-op) unary plus operation.
Expression representing sign extending.
Expression representing truncation.
Expression representing unsigned extending.
std::shared_ptr< const Base > BaseConstPtr
Reference counted pointer for Architecture::Base.
std::map< uint64_t, std::string > LabelMap
Map from address to label.
Sawyer::Message::Facility mlog
Diagnostic output for unparsing.
std::string invalidRegister(SgAsmInstruction *, RegisterDescriptor, const RegisterDictionaryPtr &)
Constructs a string to describe the invalid register.
The ROSE library.
Settings that control unparsing.
Control colored command output.
Definition Color.h:37