diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/action.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/action.cc index 7b1b2062ab..9a4e2e26d0 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/action.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/action.cc @@ -18,6 +18,8 @@ #include "coreaction.hh" +namespace ghidra { + /// Specify the name, group, and properties of the Action /// \param f is the collection of property flags /// \param nm is the Action name @@ -1156,3 +1158,5 @@ Action *ActionDatabase::deriveAction(const string &baseaction, const string &grp registerAction(grp,newact); return newact; } + +} // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/action.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/action.hh index 645c811199..6cd69a3026 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/action.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/action.hh @@ -15,11 +15,13 @@ */ /// \file action.hh /// \brief Action, Rule, and other associates classes supporting transformations on function data-flow -#ifndef __CPUI_ACTION__ -#define __CPUI_ACTION__ +#ifndef __ACTION_HH__ +#define __ACTION_HH__ #include "block.hh" +namespace ghidra { + /// \brief The list of groups defining a \e root Action /// /// Any Rule or \e leaf Action belongs to a \b group. This class @@ -321,4 +323,5 @@ public: void universalAction(Architecture *glb); ///< Build the universal action }; +} // End ghidra namespace #endif diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/address.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/address.cc index 26694b558f..2eb08b96ab 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/address.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/address.cc @@ -16,6 +16,8 @@ #include "address.hh" #include "translate.hh" +namespace ghidra { + AttributeId ATTRIB_FIRST = AttributeId("first",27); AttributeId ATTRIB_LAST = AttributeId("last",28); AttributeId ATTRIB_UNIQ = AttributeId("uniq",29); @@ -991,3 +993,5 @@ int4 power2Divide(int4 n,uint8 divisor,uint8 &q,uint8 &r) } return 0; } + +} // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/address.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/address.hh index 8ca8477d51..81c65a72ac 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/address.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/address.hh @@ -23,11 +23,13 @@ /// by placing them in their own space, separate from RAM. Indirection /// (i.e. pointers) must be simulated through the LOAD and STORE ops. -#ifndef __CPUI_ADDR__ -#define __CPUI_ADDR__ +#ifndef __ADDRESS_HH__ +#define __ADDRESS_HH__ #include "space.hh" +namespace ghidra { + class AddrSpaceManager; extern AttributeId ATTRIB_FIRST; ///< Marshaling attribute "first" @@ -555,4 +557,5 @@ extern void unsignedSubtract128(uint8 *a,uint8 *b); extern int4 unsignedCompare128(uint8 *a,uint8 *b); extern int4 power2Divide(int4 n,uint8 divisor,uint8 &q,uint8 &r); +} // End namespace ghidra #endif diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/architecture.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/architecture.cc index fdd607cc22..271b3ff9c0 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/architecture.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/architecture.cc @@ -22,6 +22,11 @@ #endif #ifdef CPUI_STATISTICS #include +#endif + +namespace ghidra { + +#ifdef CPUI_STATISTICS using std::sqrt; #endif @@ -1532,3 +1537,5 @@ void Statistics::printResults(ostream &s) } #endif + +} // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/architecture.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/architecture.hh index 20cb06f0d1..7c840e9193 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/architecture.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/architecture.hh @@ -15,8 +15,8 @@ */ /// \file architecture.hh /// \brief Architecture and associated classes that help manage a single processor architecture and load image -#ifndef __CPUI_ARCHITECTURE__ -#define __CPUI_ARCHITECTURE__ +#ifndef __ARCHITECTURE_HH__ +#define __ARCHITECTURE_HH__ #include "capability.hh" #include "varmap.hh" @@ -34,6 +34,8 @@ #include "transform.hh" #include "prefersplit.hh" +namespace ghidra { + #ifdef CPUI_STATISTICS /// \brief Class for collecting statistics while processing over multiple functions /// @@ -397,4 +399,5 @@ inline bool Architecture::highPtrPossible(const Address &loc,int4 size) const { return !nohighptr.inRange(loc,size); } +} // End namespace ghidra #endif diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/bfd_arch.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/bfd_arch.cc index b9a495500b..a3f111f173 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/bfd_arch.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/bfd_arch.cc @@ -16,6 +16,8 @@ */ #include "bfd_arch.hh" +namespace ghidra { + // Constructing this object registers capability BfdArchitectureCapability BfdArchitectureCapability::bfdArchitectureCapability; @@ -169,3 +171,5 @@ void BfdArchitecture::restoreXml(DocumentStorage &store) SleighArchitecture::restoreXml(store); } } + +} // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/bfd_arch.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/bfd_arch.hh index 875d3bb78c..69ab22e146 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/bfd_arch.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/bfd_arch.hh @@ -16,10 +16,14 @@ */ /// \file bfd_arch.hh /// \brief Specific implementation of Architecture using GNU BFD libraries +#ifndef __BFD_ARCH_HH__ +#define __BFD_ARCH_HH__ #include "sleigh_arch.hh" #include "loadimage_bfd.hh" +namespace ghidra { + extern ElementId ELEM_BFD_SAVEFILE; ///< Marshaling element \ /// \brief Extension point for building a GNU BFD capable Architecture @@ -47,3 +51,6 @@ public: BfdArchitecture(const string &fname,const string &targ,ostream *estream); ///< Constructor virtual ~BfdArchitecture(void) {} }; + +} // End namespace ghidra +#endif diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/block.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/block.cc index eef4a58b97..ec05214ebd 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/block.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/block.cc @@ -17,6 +17,8 @@ #include "block.hh" #include "funcdata.hh" +namespace ghidra { + AttributeId ATTRIB_ALTINDEX = AttributeId("altindex",75); AttributeId ATTRIB_DEPTH = AttributeId("depth",76); AttributeId ATTRIB_END = AttributeId("end",77); @@ -3566,3 +3568,5 @@ FlowBlock *BlockMap::createBlock(const string &name) sortlist.push_back(bl); return bl; } + +} // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/block.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/block.hh index 1844f8a715..69c3465647 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/block.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/block.hh @@ -16,11 +16,13 @@ /// \file block.hh /// \brief Classes related to \e basic \e blocks and control-flow structuring -#ifndef __CPUI_BLOCK__ -#define __CPUI_BLOCK__ +#ifndef __BLOCK_HH__ +#define __BLOCK_HH__ #include "jumptable.hh" +namespace ghidra { + class BlockBasic; // Forward declarations class BlockList; class BlockCopy; @@ -816,4 +818,5 @@ inline bool BlockSwitch::CaseOrder::compare(const CaseOrder &a,const CaseOrder & return (a.depth < b.depth); } +} // End namespace ghidra #endif diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/blockaction.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/blockaction.cc index 80265a458f..ece85ac09b 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/blockaction.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/blockaction.cc @@ -16,6 +16,8 @@ #include "blockaction.hh" #include "funcdata.hh" +namespace ghidra { + /// Retrieve the current edge (as a \e top FlowBlock and the index of the outgoing edge). /// If the end-points have been collapsed together, this returns NULL. /// The top and bottom nodes of the edge are updated to FlowBlocks in the current collapsed graph. @@ -2350,3 +2352,5 @@ int4 ActionNodeJoin::apply(Funcdata &data) } return 0; } + +} // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/blockaction.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/blockaction.hh index 09b1779dca..6cebf98850 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/blockaction.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/blockaction.hh @@ -13,14 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef __BLOCK_ACTION__ -#define __BLOCK_ACTION__ +#ifndef __BLOCKACTION_HH__ +#define __BLOCKACTION_HH__ /// \file blockaction.hh /// \brief Actions and classes associated with transforming and structuring the control-flow graph #include "action.hh" +namespace ghidra { + /// \brief Class for holding an edge while the underlying graph is being manipulated /// /// The original FlowBlock nodes that define the end-points of the edge may get @@ -355,4 +357,5 @@ public: virtual int4 apply(Funcdata &data); }; +} // End namespace ghidra #endif diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/callgraph.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/callgraph.cc index 26406c2880..88ae140a38 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/callgraph.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/callgraph.cc @@ -16,6 +16,8 @@ #include "callgraph.hh" #include "funcdata.hh" +namespace ghidra { + ElementId ELEM_CALLGRAPH = ElementId("callgraph",226); ElementId ELEM_NODE = ElementId("node",227); @@ -463,3 +465,4 @@ void CallGraph::decoder(Decoder &decoder) decoder.closeElement(elemId); } +} // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/callgraph.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/callgraph.hh index f8419f15aa..67be2bdba7 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/callgraph.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/callgraph.hh @@ -13,11 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef __CPUI_CALLGRAPH__ -#define __CPUI_CALLGRAPH__ +#ifndef __CALLGRAPH_HH__ +#define __CALLGRAPH_HH__ #include "address.hh" +namespace ghidra { + // Forward declarations class Architecture; class Funcdata; @@ -122,4 +124,5 @@ public: void decoder(Decoder &decoder); }; +} // End namespace ghidra #endif diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/capability.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/capability.cc index 87e40dbbf0..eaecfcda3b 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/capability.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/capability.cc @@ -15,6 +15,8 @@ */ #include "capability.hh" +namespace ghidra { + /// Access static vector of CapabilityPoint objects that are registered during static initialization /// The list itself is created once on the first call to this method /// \e after all the static initializers have run @@ -46,3 +48,4 @@ void CapabilityPoint::initializeAll(void) list.clear(); } +} // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/capability.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/capability.hh index a4d58691d6..2c0701d12e 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/capability.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/capability.hh @@ -15,13 +15,15 @@ */ /// \file capability.hh /// \brief Infrastructure for discovering code extensions to the decompiler -#ifndef __CAPABILITY__ -#define __CAPABILITY__ +#ifndef __CAPABILITY_HH__ +#define __CAPABILITY_HH__ #include "types.h" #include #include +namespace ghidra { + using std::vector; using std::string; @@ -49,5 +51,5 @@ public: static void initializeAll(void); ///< Finish initialization for all extension points }; - +} // End namespace ghidra #endif diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/cast.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/cast.cc index dc8baa764e..14d63871fc 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/cast.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/cast.cc @@ -16,6 +16,8 @@ #include "cast.hh" #include "op.hh" +namespace ghidra { + /// Sets the TypeFactory used to produce data-types for the arithmeticOutputStandard() method /// \param t is the TypeFactory void CastStrategy::setTypeFactory(TypeFactory *t) @@ -530,3 +532,5 @@ bool CastStrategyJava::isZextCast(Datatype *outtype,Datatype *intype) const if (intype->getSize()>=4) return false; // cast is not zext for int and long return true; } + +} // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/cast.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/cast.hh index 3db280331e..6d8dadff51 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/cast.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/cast.hh @@ -16,11 +16,13 @@ /// \file cast.hh /// \brief API and specific strategies for applying type casts -#ifndef __CPUI_CAST__ -#define __CPUI_CAST__ +#ifndef __CAST_HH__ +#define __CAST_HH__ #include "type.hh" +namespace ghidra { + class Varnode; class PcodeOp; @@ -199,4 +201,5 @@ public: virtual bool isZextCast(Datatype *outtype,Datatype *intype) const; }; +} // End namespace ghidra #endif diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/codedata.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/codedata.cc index 92690f4220..4a4235ca8b 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/codedata.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/codedata.cc @@ -17,6 +17,8 @@ #include "codedata.hh" #include "loadimage_bfd.hh" +namespace ghidra { + // Constructing this registers the capability IfaceCodeDataCapability IfaceCodeDataCapability::ifaceCodeDataCapability; @@ -786,3 +788,5 @@ void IfcCodeDataDumpTargetHits::execute(istream &s) { codedata->dumpTargetHits(*status->fileoptr); } + +} // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/codedata.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/codedata.hh index 3b5a4b031a..29e676d7e1 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/codedata.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/codedata.hh @@ -13,11 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef __CPUI_CODEDATA__ -#define __CPUI_CODEDATA__ +#ifndef __CODEDATA_HH__ +#define __CODEDATA_HH__ #include "ifacedecomp.hh" +namespace ghidra { + class IfaceCodeDataCapability : public IfaceCapability { static IfaceCodeDataCapability ifaceCodeDataCapability; // Singleton instance IfaceCodeDataCapability(void); // Singleton @@ -194,4 +196,5 @@ public: virtual void execute(istream &s); }; +} // End namespace ghidra #endif diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/comment.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/comment.cc index b5bc0a16da..d9d2000e55 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/comment.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/comment.cc @@ -16,6 +16,8 @@ #include "comment.hh" #include "funcdata.hh" +namespace ghidra { + ElementId ELEM_COMMENT = ElementId("comment",86); ElementId ELEM_COMMENTDB = ElementId("commentdb",87); ElementId ELEM_TEXT = ElementId("text",88); @@ -400,3 +402,5 @@ void CommentSorter::setupHeader(uint4 headerType) subsort.pos = 0xffffffff; opstop = commmap.upper_bound(subsort); } + +} // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/comment.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/comment.hh index b2be60f0fc..5c1dfe9da4 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/comment.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/comment.hh @@ -16,11 +16,13 @@ /// \file comment.hh /// \brief A database interface for high-level language comments -#ifndef __CPUI_COMMENT__ -#define __CPUI_COMMENT__ +#ifndef __COMMENT_HH__ +#define __COMMENT_HH__ #include "address.hh" +namespace ghidra { + class FlowBlock; class PcodeOp; class Funcdata; @@ -249,4 +251,5 @@ public: Comment *getNext(void) const { Comment *res=(*start).second; ++start; return res; } ///< Advance to the next comment }; +} // End namespace ghidra #endif diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/comment_ghidra.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/comment_ghidra.cc index 04a4c2cf0d..6dfcde1fd9 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/comment_ghidra.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/comment_ghidra.cc @@ -15,6 +15,8 @@ */ #include "comment_ghidra.hh" +namespace ghidra { + CommentDatabaseGhidra::CommentDatabaseGhidra(ArchitectureGhidra *g) : CommentDatabase() { @@ -78,3 +80,4 @@ CommentSet::const_iterator CommentDatabaseGhidra::endComment(const Address &fad) return cache.endComment(fad); } +} // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/comment_ghidra.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/comment_ghidra.hh index c0dc59c890..cf3f9f893b 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/comment_ghidra.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/comment_ghidra.hh @@ -15,12 +15,14 @@ */ /// \file comment_ghidra.hh /// \brief Obtain comments by talking to a Ghidra client -#ifndef __COMMENT_GHIDRA__ -#define __COMMENT_GHIDRA__ +#ifndef __COMMENT_GHIDRA_HH__ +#define __COMMENT_GHIDRA_HH__ #include "comment.hh" #include "ghidra_arch.hh" +namespace ghidra { + /// \brief An implementation of CommentDatabase backed by a Ghidra client /// /// Comment information about particular functions is obtained by querying @@ -51,4 +53,5 @@ public: throw LowlevelError("CommentDatabaseGhidra::decode unimplemented"); } }; +} // End namespace ghidra #endif diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/condexe.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/condexe.cc index 962f35d5d4..163aa10b7d 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/condexe.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/condexe.cc @@ -15,6 +15,8 @@ */ #include "condexe.hh" +namespace ghidra { + ConditionMarker::ConditionMarker(void) { @@ -1094,3 +1096,5 @@ int4 RuleOrPredicate::applyOp(PcodeOp *op,Funcdata &data) data.opSetOpcode(op,CPUI_COPY); return 1; } + +} // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/condexe.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/condexe.hh index bf2e546150..a800756e7c 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/condexe.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/condexe.hh @@ -15,11 +15,13 @@ */ /// \file condexe.hh /// \brief Classes for simplifying control-flow with shared conditional expressions -#ifndef __CONDEXE__ -#define __CONDEXE__ +#ifndef __CONDEXE_HH__ +#define __CONDEXE_HH__ #include "funcdata.hh" +namespace ghidra { + /// \brief A helper class for describing the similarity of the boolean condition between 2 CBRANCH operations /// /// This class determines if two CBRANCHs share the same condition. It also determines if the conditions @@ -234,4 +236,5 @@ public: virtual int4 applyOp(PcodeOp *op,Funcdata &data); }; +} // End namespace ghidra #endif diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/consolemain.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/consolemain.cc index 29d2bd63b7..d31e287580 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/consolemain.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/consolemain.cc @@ -15,13 +15,14 @@ */ #include #include +#include "libdecomp.hh" + +namespace ghidra { using std::cin; using std::cout; using std::cerr; -#include "libdecomp.hh" - class IfcLoadFile : public IfaceDecompCommand { public: virtual void execute(istream &s); @@ -170,9 +171,13 @@ void IfcRestore::execute(istream &s) *status->optr << savefile << " successfully loaded: " << dcp->conf->getDescription() << endl; } +} // End namespace ghidra + int main(int argc,char **argv) { + using namespace ghidra; + const char *initscript = (const char *)0; { @@ -244,4 +249,3 @@ int main(int argc,char **argv) exit(retval); } - diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/context.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/context.cc index 51157f3a7c..1a0a35f3e1 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/context.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/context.cc @@ -17,6 +17,8 @@ #include "slghsymbol.hh" #include "translate.hh" +namespace ghidra { + ParserContext::ParserContext(ContextCache *ccache,Translate *trans) { @@ -234,3 +236,4 @@ void ParserWalkerChange::calcCurrentLength(int4 length,int4 numopers) point->length = length - point->offset; // Convert back to relative length } +} // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/context.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/context.hh index 8ae7012a69..79fbe1eff6 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/context.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/context.hh @@ -13,12 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef __CONTEXT__ -#define __CONTEXT__ +#ifndef __CONTEXT_HH__ +#define __CONTEXT_HH__ #include "globalcontext.hh" #include "opcodes.hh" +namespace ghidra { + class Token { // A multiple-byte sized chunk of pattern in a bitstream string name; int4 size; // Number of bytes in token; @@ -198,4 +200,5 @@ inline void ParserContext::allocateOperand(int4 i,ParserWalkerChange &walker) { walker.breadcrumb[walker.depth] = 0; } +} // End namespace ghidra #endif diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/coreaction.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/coreaction.cc index 686cf295bc..3d1e52238f 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/coreaction.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/coreaction.cc @@ -18,6 +18,8 @@ #include "double.hh" #include "subflow.hh" +namespace ghidra { + /// \brief A stack equation struct StackEqn { int4 var1; ///< Variable with 1 coefficient @@ -5500,3 +5502,5 @@ void ActionDatabase::universalAction(Architecture *conf) act->addAction( new ActionPrototypeWarnings("protorecovery") ); act->addAction( new ActionStop("base") ); } + +} // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/coreaction.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/coreaction.hh index d33fa3302d..11d520d772 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/coreaction.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/coreaction.hh @@ -21,13 +21,15 @@ /// (if they do they must check the covers themselves) -#ifndef __CORE_ACTION__ -#define __CORE_ACTION__ +#ifndef __COREACTION_HH__ +#define __COREACTION_HH__ #include "ruleaction.hh" #include "blockaction.hh" #include "funcdata.hh" +namespace ghidra { + /// \brief Gather raw p-code for a function. class ActionStart : public Action { public: @@ -1088,4 +1090,5 @@ public: inline bool TermOrder::additiveCompare(const AdditiveEdge *op1,const AdditiveEdge *op2) { return (-1 == op1->getVarnode()->termOrder(op2->getVarnode())); } +} // End namespace ghidra #endif diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/cover.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/cover.cc index 6e2b88a063..8ac34fc292 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/cover.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/cover.cc @@ -16,6 +16,8 @@ #include "cover.hh" #include "block.hh" +namespace ghidra { + const CoverBlock Cover::emptyBlock; /// PcodeOp objects and a CoverBlock start/stop boundaries have @@ -562,3 +564,5 @@ void Cover::print(ostream &s) const s << endl; } } + +} // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/cover.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/cover.hh index 4d874ff9fd..b5a4b2fe02 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/cover.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/cover.hh @@ -15,11 +15,13 @@ */ /// \file cover.hh /// \brief Classes describing the topological scope of variables within a function -#ifndef __CPUI_COVER__ -#define __CPUI_COVER__ +#ifndef __COVER_HH__ +#define __COVER_HH__ #include "type.hh" +namespace ghidra { + class PcodeOp; class FlowBlock; class Varnode; @@ -89,4 +91,5 @@ public: map::const_iterator end(void) const { return cover.end(); } ///< Get end of CoverBlocks }; +} // End namespace ghidra #endif diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/cpool.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/cpool.cc index 42b1531add..e73485a861 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/cpool.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/cpool.cc @@ -15,6 +15,8 @@ */ #include "cpool.hh" +namespace ghidra { + AttributeId ATTRIB_A = AttributeId("a",80); AttributeId ATTRIB_B = AttributeId("b",81); AttributeId ATTRIB_LENGTH = AttributeId("length",82); @@ -239,3 +241,5 @@ void ConstantPoolInternal::decode(Decoder &decoder,TypeFactory &typegrp) } decoder.closeElement(elemId); } + +} // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/cpool.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/cpool.hh index ce9b9809a2..f3fedca4be 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/cpool.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/cpool.hh @@ -16,11 +16,13 @@ /// \file cpool.hh /// \brief Definitions to support a constant pool for \e deferred compilation languages (i.e. java byte-code) -#ifndef __CPOOL__ -#define __CPOOL__ +#ifndef __CPOOL_HH__ +#define __CPOOL_HH__ #include "type.hh" +namespace ghidra { + extern AttributeId ATTRIB_A; ///< Marshaling attribute "a" extern AttributeId ATTRIB_B; ///< Marshaling attribute "b" extern AttributeId ATTRIB_LENGTH; ///< Marshaling attribute "length" @@ -205,4 +207,5 @@ public: virtual void decode(Decoder &decoder,TypeFactory &typegrp); }; +} // End namespace ghidra #endif diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/cpool_ghidra.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/cpool_ghidra.cc index e8dee82567..3fcb044b23 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/cpool_ghidra.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/cpool_ghidra.cc @@ -15,6 +15,8 @@ */ #include "cpool_ghidra.hh" +namespace ghidra { + ConstantPoolGhidra::ConstantPoolGhidra(ArchitectureGhidra *g) { @@ -64,3 +66,5 @@ void ConstantPoolGhidra::decode(Decoder &decoder,TypeFactory &typegrp) { throw LowlevelError("Cannot access constant pool with this method"); } + +} // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/cpool_ghidra.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/cpool_ghidra.hh index af65a8d2bb..fad868ecbd 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/cpool_ghidra.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/cpool_ghidra.hh @@ -16,11 +16,13 @@ /// \file cpool_ghidra.hh /// \brief Utility for implementing a \e constant \e pool backed by a Ghidra client -#ifndef __CPOOL_GHIDRA__ -#define __CPOOL_GHIDRA__ +#ifndef __CPOOL_GHIDRA_HH__ +#define __CPOOL_GHIDRA_HH__ #include "ghidra_arch.hh" +namespace ghidra { + /// \brief An implementation of ConstantPool using a Ghidra client as the backing storage /// /// The actual CPoolRecord objects are cached locally, but new queries are placed @@ -41,4 +43,5 @@ public: virtual void decode(Decoder &decoder,TypeFactory &typegrp); }; +} // End namespace ghidra #endif diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/crc32.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/crc32.cc index 2881ab711f..8e8f129b76 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/crc32.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/crc32.cc @@ -1,6 +1,5 @@ /* ### * IP: GHIDRA - * REVIEWED: YES * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,6 +15,8 @@ */ #include "crc32.hh" +namespace ghidra { + // Table for bytewise calculation of a 32-bit Cyclic Redundancy Check uint4 crc32tab[] = { 0x0,0x77073096,0xee0e612c,0x990951ba,0x76dc419,0x706af48f, @@ -70,3 +71,4 @@ uint4 crc32tab[] = { 0x54de5729,0x23d967bf,0xb3667a2e,0xc4614ab8,0x5d681b02, 0x2a6f2b94,0xb40bbe37,0xc30c8ea1,0x5a05df1b,0x2d02ef8d }; +} // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/crc32.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/crc32.hh index ead3179175..87c61ae86f 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/crc32.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/crc32.hh @@ -16,11 +16,13 @@ /// \file crc32.hh /// \brief Table and function for computing a CRC32 -#ifndef __CRC32__ -#define __CRC32__ +#ifndef __CRC32_HH__ +#define __CRC32_HH__ #include "types.h" +namespace ghidra { + extern uint4 crc32tab[]; ///< Table for quickly computing a 32-bit Cyclic Redundacy Check (CRC) /// \brief Feed 8 bits into a CRC register @@ -31,4 +33,5 @@ extern uint4 crc32tab[]; ///< Table for quickly computing a 32-bit Cyclic Redund inline uint4 crc_update(uint4 reg,uint4 val) { return crc32tab[(reg ^ val)&0xff] ^ (reg>>8); } +} // End namespace ghidra #endif diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/database.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/database.cc index eaf2c498da..d729824641 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/database.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/database.cc @@ -18,6 +18,8 @@ #include "crc32.hh" #include +namespace ghidra { + AttributeId ATTRIB_CAT = AttributeId("cat",61); AttributeId ATTRIB_FIELD = AttributeId("field",62); AttributeId ATTRIB_MERGE = AttributeId("merge",63); @@ -3364,3 +3366,5 @@ void Database::decodeScope(Decoder &decoder,Scope *newScope) } decoder.closeElement(elemId); } + +} // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/database.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/database.hh index 10eaee7ab5..542a0d7b9c 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/database.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/database.hh @@ -20,13 +20,15 @@ /// scopes, namespaces etc. Search can be by name or the address of the Symbol storage /// location. -#ifndef __CPUI_DATABASE__ -#define __CPUI_DATABASE__ +#ifndef __DATABASE_HH__ +#define __DATABASE_HH__ #include "variable.hh" #include "partmap.hh" #include "rangemap.hh" +namespace ghidra { + class Architecture; class Funcdata; class Scope; @@ -976,4 +978,5 @@ inline Symbol::Symbol(Scope *sc) depthResolution = 0; } +} // End namespace ghidra #endif diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/database_ghidra.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/database_ghidra.cc index 35030ffe0c..fbe0bf85c7 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/database_ghidra.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/database_ghidra.cc @@ -16,6 +16,8 @@ #include "database_ghidra.hh" #include "funcdata.hh" +namespace ghidra { + Scope *ScopeGhidra::buildSubScope(uint8 id,const string &nm) { @@ -389,3 +391,5 @@ bool ScopeGhidraNamespace::isNameUsed(const string &nm,const Scope *op2) const uint8 otherId = (otherScope != (const ScopeGhidraNamespace *)0) ? otherScope->getId() : 0; return ghidra->isNameUsed(nm, uniqueId, otherId); } + +} // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/database_ghidra.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/database_ghidra.hh index 304bd2914b..7b8c5f8e4a 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/database_ghidra.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/database_ghidra.hh @@ -16,12 +16,14 @@ /// \file database_ghidra.hh /// \brief Facilities for retrieving symbol information from a Ghidra client -#ifndef __DATABASE_GHIDRA__ -#define __DATABASE_GHIDRA__ +#ifndef __DATABASE_GHIDRA_HH__ +#define __DATABASE_GHIDRA_HH__ #include "database.hh" #include "ghidra_arch.hh" +namespace ghidra { + /// \brief An implementation of the Scope interface by querying a Ghidra client for Symbol information /// /// This object is generally instantiated once for an executable and @@ -137,4 +139,5 @@ public: virtual bool isNameUsed(const string &nm,const Scope *op2) const; }; +} // End namespace ghidra #endif diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/double.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/double.cc index ce5706bcd6..8eb11963ef 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/double.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/double.cc @@ -15,6 +15,8 @@ */ #include "double.hh" +namespace ghidra { + /// Internally, the \b lo and \b hi Varnodes are set to null, and the \b val field /// holds the constant value. /// \param sz is the size in bytes of the constant @@ -3484,3 +3486,5 @@ void RuleDoubleStore::reassignIndirects(Funcdata &data,PcodeOp *newStore,const v data.opSetInput(op,data.newVarnodeIop(newStore),1); // Assign the INDIRECT to the new STORE } } + +} // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/double.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/double.hh index 418d1f85ed..3463086523 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/double.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/double.hh @@ -13,12 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef __CPUI_DOUBLE__ -#define __CPUI_DOUBLE__ +#ifndef __DOUBLE_HH__ +#define __DOUBLE_HH__ #include "ruleaction.hh" #include "funcdata.hh" +namespace ghidra { + /// \brief A logical value whose storage is split between two Varnodes /// /// This is usually a pair of Varnodes \b lo and \b hi holding the least and @@ -339,4 +341,6 @@ public: static bool testIndirectUse(PcodeOp *op1,PcodeOp *op2,const vector &indirects); static void reassignIndirects(Funcdata &data,PcodeOp *newStore,const vector &indirects); }; + +} // End namespace ghidra #endif diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/dynamic.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/dynamic.cc index 562584d8ef..84da5edc42 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/dynamic.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/dynamic.cc @@ -17,6 +17,8 @@ #include "funcdata.hh" #include "crc32.hh" +namespace ghidra { + // Table for how to hash opcodes, lumps certain operators (i.e. ADD SUB PTRADD PTRSUB) into one hash // zero indicates the operator should be skipped const uint4 DynamicHash::transtable[] = { @@ -763,3 +765,5 @@ void DynamicHash::clearTotalPosition(uint8 &h) val = ~val; h &= val; } + +} // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/dynamic.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/dynamic.hh index 1355f9fe11..ca150ff5ef 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/dynamic.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/dynamic.hh @@ -17,11 +17,13 @@ /// \brief Utilities for making references to \b dynamic variables: defined as /// locations and constants that can only be identified by their context within the data-flow graph. -#ifndef __CPUI_DYNAMIC__ -#define __CPUI_DYNAMIC__ +#ifndef __DYNAMIC_HH__ +#define __DYNAMIC_HH__ #include "varnode.hh" +namespace ghidra { + /// \brief An edge between a Varnode and a PcodeOp /// /// A DynamicHash is defined on a sub-graph of the data-flow, and this defines an edge @@ -102,4 +104,5 @@ public: static const uint4 transtable[]; ///< Translation of op-codes to hash values }; +} // End namespace ghidra #endif diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/emulate.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/emulate.cc index 88936cedd4..cbb0522f31 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/emulate.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/emulate.cc @@ -15,6 +15,8 @@ */ #include "emulate.hh" +namespace ghidra { + /// Any time the emulator is about to execute a user-defined pcode op with the given name, /// the indicated breakpoint is invoked first. The break table does \e not assume responsibility /// for freeing the breakpoint object. @@ -454,3 +456,5 @@ void EmulatePcodeCache::executeInstruction(void) executeCurrentOp(); } while(!instruction_start); } + +} // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/emulate.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/emulate.hh index bfe8747519..953b045086 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/emulate.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/emulate.hh @@ -16,12 +16,14 @@ /// \file emulate.hh /// \brief Classes for emulating p-code -#ifndef __CPUI_EMULATE__ -#define __CPUI_EMULATE__ +#ifndef __EMULATE_HH__ +#define __EMULATE_HH__ #include "memstate.hh" #include "translate.hh" +namespace ghidra { + class Emulate; // Forward declaration /// \brief A collection of breakpoints for the emulator @@ -545,4 +547,5 @@ inline Address EmulatePcodeCache::getExecuteAddress(void) const - VarnodeData */ +} // End namespace ghidra #endif diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/emulateutil.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/emulateutil.cc index fe37a7be21..73fcfec97f 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/emulateutil.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/emulateutil.cc @@ -16,6 +16,8 @@ #include "architecture.hh" #include "emulateutil.hh" +namespace ghidra { + /// \param g is the Architecture providing the LoadImage EmulatePcodeOp::EmulatePcodeOp(Architecture *g) @@ -391,3 +393,5 @@ uintb EmulateSnippet::getTempValue(uintb offset) const return 0; return (*iter).second; } + +} // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/emulateutil.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/emulateutil.hh index a06b49ce38..f82fa816cc 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/emulateutil.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/emulateutil.hh @@ -16,12 +16,14 @@ /// \file emulateutil.hh /// \brief (Lightweight) emulation interface for executing PcodeOp objects within a syntax tree /// or for executing snippets defined with PcodeOpRaw objects -#ifndef __CPUI_EMUTREE__ -#define __CPUI_EMUTREE__ +#ifndef __EMULATEUTIL_HH__ +#define __EMULATEUTIL_HH__ #include "emulate.hh" #include "op.hh" +namespace ghidra { + /// \brief Emulation based on (existing) PcodeOps and Varnodes. /// /// This is still an abstract class. It does most of the work of emulating @@ -172,4 +174,5 @@ public: uintb getTempValue(uintb offset) const; }; +} // End namespace ghidra #endif diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/error.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/error.hh index 6cb1c11563..02fbc9964c 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/error.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/error.hh @@ -18,8 +18,8 @@ /// /// This is also doubles as a place to list the common include files -#ifndef __CPUI_ERROR__ -#define __CPUI_ERROR__ +#ifndef __ERROR_HH__ +#define __ERROR_HH__ #include "types.h" #include @@ -33,6 +33,8 @@ #include #include +namespace ghidra { + using std::string; using std::map; using std::set; @@ -95,4 +97,5 @@ struct ParseError : public LowlevelError { // Parsing error ParseError(const string &s) : LowlevelError(s) {} }; +} // End namespace ghidra #endif diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/filemanage.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/filemanage.cc index 9ab665cd3e..aa1d06cafc 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/filemanage.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/filemanage.cc @@ -29,6 +29,8 @@ extern "C" { } #endif +namespace ghidra { + // Path name separator #ifdef _WINDOWS char FileManage::separator = '\\'; @@ -381,3 +383,5 @@ string FileManage::discoverGhidraRoot(const char *argv0) } return ""; } + +} // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/filemanage.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/filemanage.hh index 9393802a48..defa54e7e3 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/filemanage.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/filemanage.hh @@ -15,8 +15,8 @@ */ // Generic (POSIX) class for searching files and managing paths -#ifndef __FILEMANAGE__ -#define __FILEMANAGE__ +#ifndef __FILEMANAGE_HH__ +#define __FILEMANAGE_HH__ #include #include @@ -24,6 +24,8 @@ #include #include +namespace ghidra { + using std::vector; using std::string; using std::ifstream; @@ -49,4 +51,5 @@ public: static string discoverGhidraRoot(const char *argv0); }; +} // End namespace ghidra #endif diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/float.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/float.cc index 115d697497..2698643b49 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/float.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/float.cc @@ -19,6 +19,9 @@ #include #include + +namespace ghidra { + using std::ldexp; using std::frexp; using std::signbit; @@ -687,3 +690,5 @@ void FloatFormat::restoreXml(const Element *el) maxexponent = (1< &newTables,vector &qlst) for(;lastChangematchCallCount = num; } + +} // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/fspec.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/fspec.hh index 64ec45e2cd..e3841ed42a 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/fspec.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/fspec.hh @@ -16,12 +16,14 @@ /// \file fspec.hh /// \brief Definitions for specifying functions prototypes -#ifndef __CPUI_FSPEC__ -#define __CPUI_FSPEC__ +#ifndef __FSPEC_HH__ +#define __FSPEC_HH__ #include "op.hh" #include "rangemap.hh" +namespace ghidra { + class JoinRecord; extern AttributeId ATTRIB_CUSTOM; ///< Marshaling attribute "custom" @@ -1717,4 +1719,5 @@ inline bool EffectRecord::operator!=(const EffectRecord &op2) const return (type != op2.type); } +} // End namespace ghidra #endif diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/funcdata.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/funcdata.cc index 24756f0b79..6ac908c7d1 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/funcdata.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/funcdata.cc @@ -15,6 +15,8 @@ */ #include "funcdata.hh" +namespace ghidra { + AttributeId ATTRIB_NOCODE = AttributeId("nocode",84); ElementId ELEM_AST = ElementId("ast",115); @@ -1044,3 +1046,4 @@ void Funcdata::debugPrintRange(int4 i) const #endif +} // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/funcdata.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/funcdata.hh index fe3841beda..b54590848b 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/funcdata.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/funcdata.hh @@ -13,8 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef __CPUI_FUNCDATA__ -#define __CPUI_FUNCDATA__ +#ifndef __FUNCDATA_HH__ +#define __FUNCDATA_HH__ /// \file funcdata.hh /// \brief Utilities for processing data structures associated with a single function @@ -26,6 +26,8 @@ #include "dynamic.hh" #include "unionresolve.hh" +namespace ghidra { + class FlowInfo; extern AttributeId ATTRIB_NOCODE; ///< Marshaling attribute "nocode" @@ -682,4 +684,5 @@ extern PcodeOp *cseElimination(Funcdata &data,PcodeOp *op1,PcodeOp *op2); extern void cseEliminateList(Funcdata &data,vector< pair > &list, vector &outlist); +} // End namespace ghidra #endif diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/funcdata_block.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/funcdata_block.cc index d67f5252ca..5b90c1d97e 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/funcdata_block.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/funcdata_block.cc @@ -16,6 +16,8 @@ #include "funcdata.hh" #include "flow.hh" +namespace ghidra { + // Funcdata members pertaining directly to blocks /// A description of each block in the current structure hierarchy is @@ -1085,3 +1087,5 @@ void Funcdata::spliceBlockBasic(BlockBasic *bl) bblocks.spliceBlock(bl); structureReset(); } + +} // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/funcdata_op.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/funcdata_op.cc index d546e58b67..2ecc1bd22e 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/funcdata_op.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/funcdata_op.cc @@ -16,6 +16,8 @@ #include "funcdata.hh" #include "flow.hh" +namespace ghidra { + // Funcdata members pertaining directly to ops /// \param op is the given PcodeOp @@ -1412,3 +1414,5 @@ bool Funcdata::moveRespectingCover(PcodeOp *op,PcodeOp *lastOp) } return false; } + +} // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/funcdata_varnode.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/funcdata_varnode.cc index e5b85187db..f77817073b 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/funcdata_varnode.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/funcdata_varnode.cc @@ -15,6 +15,8 @@ */ #include "funcdata.hh" +namespace ghidra { + // Funcdata members pertaining directly to varnodes /// Properties of a given storage location are gathered from symbol information and @@ -2044,3 +2046,5 @@ bool AncestorRealistic::execute(PcodeOp *op,int4 slot,ParamTrial *t,bool allowFa } return false; } + +} // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/ghidra_arch.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/ghidra_arch.cc index b5dd6c4691..812dbf158b 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/ghidra_arch.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/ghidra_arch.cc @@ -23,6 +23,8 @@ #include "cpool_ghidra.hh" #include "inject_ghidra.hh" +namespace ghidra { + //AttributeId ATTRIB_BADDATA = AttributeId("baddata",145); ElementId ELEM_COMMAND_ISNAMEUSED = ElementId("command_isnameused",239); @@ -935,3 +937,4 @@ bool ArchitectureGhidra::isDynamicSymbolName(const string &nm) return true; } +} // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/ghidra_arch.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/ghidra_arch.hh index 20dabcb6c1..ba65bcc745 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/ghidra_arch.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/ghidra_arch.hh @@ -16,11 +16,13 @@ /// \file ghidra_arch.hh /// \brief Ghidra specific architecture information and connection to a Ghidra client -#ifndef __GHIDRA_ARCH__ -#define __GHIDRA_ARCH__ +#ifndef __GHIDRA_ARCH_HH__ +#define __GHIDRA_ARCH_HH__ #include "architecture.hh" +namespace ghidra { + extern ElementId ELEM_COMMAND_ISNAMEUSED; ///< Marshaling element \ extern ElementId ELEM_COMMAND_GETBYTES; ///< Marshaling element \ extern ElementId ELEM_COMMAND_GETCALLFIXUP; ///< Marshaling element \ @@ -166,4 +168,5 @@ public: static bool isDynamicSymbolName(const string &nm); ///< Check if name is of form FUN_.. or DAT_.. }; +} // End namespace ghidra #endif diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/ghidra_context.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/ghidra_context.cc index 226c3249c8..f1ffc604e9 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/ghidra_context.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/ghidra_context.cc @@ -15,6 +15,8 @@ */ #include "ghidra_context.hh" +namespace ghidra { + const TrackedSet &ContextGhidra::getTrackedSet(const Address &addr) const { @@ -40,3 +42,4 @@ void ContextGhidra::decodeFromSpec(Decoder &decoder) decoder.skipElement(); // Ignore details handled by ghidra } +} // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/ghidra_context.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/ghidra_context.hh index 68c201a334..b6ca66ac42 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/ghidra_context.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/ghidra_context.hh @@ -13,8 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef __CONTEXT_GHIDRA__ -#define __CONTEXT_GHIDRA__ +#ifndef __GHIDRA_CONTEXT_HH__ +#define __GHIDRA_CONTEXT_HH__ /// \file ghidra_context.hh /// \brief Obtaining context information from a Ghidra client @@ -22,6 +22,8 @@ #include "globalcontext.hh" #include "ghidra_arch.hh" +namespace ghidra { + /// \brief An implementation of a ContextDatabase obtaining context information via a Ghidra client /// /// This only implements the tracked register parts of the interface. In fact, this only implements @@ -72,4 +74,5 @@ public: throw LowlevelError("getTrackedDefault should not be called for GHIDRA"); } }; +} // End namespace ghidra #endif diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/ghidra_process.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/ghidra_process.cc index a2cc2299be..9ec6788370 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/ghidra_process.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/ghidra_process.cc @@ -23,9 +23,12 @@ #endif #ifdef __REMOTE_SOCKET__ - #include "ifacedecomp.hh" +#endif +namespace ghidra { + +#ifdef __REMOTE_SOCKET__ static IfaceStatus *ghidra_dcp = (IfaceStatus *)0; static RemoteSocket *remote = (RemoteSocket *)0; @@ -502,9 +505,13 @@ void GhidraDecompCapability::initialize(void) commandmap["setOptions"] = new SetOptions(); } +} // End namespace ghidra + int main(int argc,char **argv) { + using namespace ghidra; + signal(SIGSEGV, &ArchitectureGhidra::segvHandler); // Exit on SEGV errors #ifdef _WINDOWS // Force i/o streams to be in binary mode @@ -520,4 +527,3 @@ int main(int argc,char **argv) } GhidraCapability::shutDown(); } - diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/ghidra_process.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/ghidra_process.hh index 6ee255caa4..db72be59bd 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/ghidra_process.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/ghidra_process.hh @@ -16,8 +16,8 @@ /// \file ghidra_process.hh /// \brief The formal commands that can be issued to the decompiler by the Ghidra client -#ifndef __GHIDRA_PROCESS__ -#define __GHIDRA_PROCESS__ +#ifndef __GHIDRA_PROCESS_HH__ +#define __GHIDRA_PROCESS_HH__ #include "capability.hh" #include "ghidra_arch.hh" @@ -27,6 +27,8 @@ #include #include +namespace ghidra { + using std::cin; using std::cout; @@ -239,4 +241,5 @@ public: extern void connect_to_console(Funcdata *fd); #endif +} // End namespace ghidra #endif diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/ghidra_translate.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/ghidra_translate.cc index dd2c0274a2..437012be84 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/ghidra_translate.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/ghidra_translate.cc @@ -16,6 +16,8 @@ #include "ghidra_translate.hh" #include "funcdata.hh" +namespace ghidra { + /// \brief Associate a Varnode with a register name /// /// \param nm is the register name @@ -154,3 +156,4 @@ void GhidraTranslate::decode(Decoder &decoder) decoder.closeElement(elemId); } +} // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/ghidra_translate.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/ghidra_translate.hh index 207f2f375f..b01f5f2fe7 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/ghidra_translate.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/ghidra_translate.hh @@ -16,12 +16,14 @@ /// \file ghidra_translate.hh /// \brief Class for fetching p-code from a Ghidra client -#ifndef __TRANSLATE_GHIDRA__ -#define __TRANSLATE_GHIDRA__ +#ifndef __GHIDRA_TRANSLATE_HH__ +#define __GHIDRA_TRANSLATE_HH__ #include "translate.hh" #include "ghidra_arch.hh" +namespace ghidra { + /// \brief An implementation of Translate that queries a Ghidra client for p-code information /// /// This class provides: @@ -53,4 +55,5 @@ public: throw LowlevelError("Cannot dump assembly through this interface"); } }; +} // End namespace ghidra #endif diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/globalcontext.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/globalcontext.cc index 15badbad3d..ef2d8800c1 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/globalcontext.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/globalcontext.cc @@ -15,6 +15,8 @@ */ #include "globalcontext.hh" +namespace ghidra { + ElementId ELEM_CONTEXT_DATA = ElementId("context_data",120); ElementId ELEM_CONTEXT_POINTS = ElementId("context_points",121); ElementId ELEM_CONTEXT_POINTSET = ElementId("context_pointset",122); @@ -613,3 +615,4 @@ void ContextCache::setContext(const Address &addr1,const Address &addr2,int4 num curspace = (AddrSpace *)0; // Invalidate cache } +} // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/globalcontext.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/globalcontext.hh index 6bf5ae0fe6..2a9abad542 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/globalcontext.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/globalcontext.hh @@ -13,8 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef __GLOBALCONTEXT__ -#define __GLOBALCONTEXT__ +#ifndef __GLOBALCONTEXT_HH__ +#define __GLOBALCONTEXT_HH__ /// \file globalcontext.hh /// \brief Utilities for getting address-based context to the disassembler and decompiler @@ -22,6 +22,8 @@ #include "pcoderaw.hh" #include "partmap.hh" +namespace ghidra { + extern ElementId ELEM_CONTEXT_DATA; ///< Marshaling element \ extern ElementId ELEM_CONTEXT_POINTS; ///< Marshaling element \ extern ElementId ELEM_CONTEXT_POINTSET; ///< Marshaling element \ @@ -328,4 +330,5 @@ public: void setContext(const Address &addr1,const Address &addr2,int4 num,uintm mask,uintm value); }; +} // End namespace ghidra #endif diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/grammar.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/grammar.cc index 01c43f3ce5..4ce16ce5f4 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/grammar.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/grammar.cc @@ -90,6 +90,8 @@ #include "grammar.hh" +namespace ghidra { + extern int grammarlex(void); extern int grammarerror(const char *str); static CParse *parse; @@ -484,14 +486,14 @@ static const yytype_uint8 yytranslate[] = /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */ static const yytype_uint8 yyrline[] = { - 0, 60, 60, 61, 65, 66, 70, 71, 72, 73, - 74, 75, 76, 77, 81, 82, 86, 91, 92, 93, - 97, 98, 99, 100, 101, 102, 106, 107, 111, 115, - 116, 117, 118, 122, 123, 127, 132, 133, 134, 135, - 136, 140, 141, 145, 146, 150, 151, 155, 156, 157, - 158, 160, 165, 166, 167, 168, 172, 173, 177, 178, - 182, 183, 187, 188, 189, 193, 194, 195, 199, 201, - 203, 207 + 0, 62, 62, 63, 67, 68, 72, 73, 74, 75, + 76, 77, 78, 79, 83, 84, 88, 93, 94, 95, + 99, 100, 101, 102, 103, 104, 108, 109, 113, 117, + 118, 119, 120, 124, 125, 129, 134, 135, 136, 137, + 138, 142, 143, 147, 148, 152, 153, 157, 158, 159, + 160, 162, 167, 168, 169, 170, 174, 175, 179, 180, + 184, 185, 189, 190, 191, 195, 196, 197, 201, 203, + 205, 209 }; #endif @@ -3360,3 +3362,4 @@ Address parse_machaddr(istream &s,int4 &defaultsize,const TypeFactory &typegrp,b return res; } +} // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/grammar.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/grammar.hh index 3f9115e72a..7bbdc0aaf3 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/grammar.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/grammar.hh @@ -13,11 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef __CPUI_GRAMMAR__ -#define __CPUI_GRAMMAR__ +#ifndef __GRAMMAR_HH__ +#define __GRAMMAR_HH__ #include "funcdata.hh" +namespace ghidra { + class GrammarToken { friend class GrammarLexer; public: @@ -288,4 +290,5 @@ extern Address parse_machaddr(istream &s,int4 &defaultsize,const TypeFactory &ty extern Address parse_varnode(istream &s,int4 &size,Address &pc,uintm &uq,const TypeFactory &typegrp); extern Address parse_op(istream &s,uintm &uq,const TypeFactory &typegrp); +} // End namespace ghidra #endif diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/grammar.y b/Ghidra/Features/Decompiler/src/decompile/cpp/grammar.y index c8ce159534..c740c426f6 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/grammar.y +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/grammar.y @@ -17,6 +17,8 @@ %{ #include "grammar.hh" +namespace ghidra { + extern int grammarlex(void); extern int grammarerror(const char *str); static CParse *parse; @@ -1567,3 +1569,4 @@ Address parse_machaddr(istream &s,int4 &defaultsize,const TypeFactory &typegrp,b return res; } +} // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/graph.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/graph.cc index 20d7cd1962..af787c4727 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/graph.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/graph.cc @@ -16,6 +16,8 @@ */ #include "graph.hh" +namespace ghidra { + static void print_varnode_vertex(Varnode *vn,ostream &s) { @@ -496,3 +498,5 @@ void dump_dom_graph(const string &name,const BlockGraph &graph,ostream &s) dump_block_vertex(graph,s,falsenode); dump_dom_edges(graph,s,falsenode); } + +} // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/graph.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/graph.hh index 364a5258d8..ef65d6e886 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/graph.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/graph.hh @@ -1,6 +1,5 @@ /* ### * IP: GHIDRA - * REVIEWED: YES * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,8 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#ifndef __GRAPH_HH__ +#define __GRAPH_HH__ + #include "funcdata.hh" +namespace ghidra { + extern void dump_dataflow_graph(Funcdata &data,ostream &s); extern void dump_controlflow_graph(const string &name,const BlockGraph &graph,ostream &s); extern void dump_dom_graph(const string &name,const BlockGraph &graph,ostream &s); + +} // End namespace ghidra +#endif diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/heritage.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/heritage.cc index 0630e8bba6..07d1fdf483 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/heritage.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/heritage.cc @@ -17,6 +17,8 @@ #include "funcdata.hh" #include "prefersplit.hh" +namespace ghidra { + /// Update disjoint cover making sure (addr,size) is contained in a single element and return /// an iterator to this element. The element's \b pass number is set to be the smallest value /// of any previous intersecting element. Additionally an \b intersect code is passed back: @@ -2670,3 +2672,5 @@ void Heritage::clear(void) maxdepth = -1; pass = 0; } + +} // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/heritage.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/heritage.hh index 76f731a586..f644e7f989 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/heritage.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/heritage.hh @@ -17,11 +17,13 @@ /// \file heritage.hh /// \brief Utilities for building Static Single Assignment (SSA) form -#ifndef __CPUI_HERITAGE__ -#define __CPUI_HERITAGE__ +#ifndef __HERITAGE_HH__ +#define __HERITAGE_HH__ #include "block.hh" +namespace ghidra { + /// Container holding the stack system for the renaming algorithm. Every disjoint address /// range (indexed by its initial address) maps to its own Varnode stack. typedef map > VariableStack; @@ -294,4 +296,5 @@ public: const LoadGuard *getStoreGuard(PcodeOp *op) const; ///< Get LoadGuard record associated with given PcodeOp }; +} // End namespace ghidra #endif diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/ifacedecomp.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/ifacedecomp.cc index fd0087cb60..7b3747f590 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/ifacedecomp.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/ifacedecomp.cc @@ -20,6 +20,8 @@ extern "C" { #include "pcodeparse.hh" #include "blockaction.hh" +namespace ghidra { + // Constructing this registers the capability IfaceDecompCapability IfaceDecompCapability::ifaceDecompCapability; @@ -3612,3 +3614,5 @@ void IfcSource::execute(istream &s) s >> filename; status->pushScript(filename,filename+"> "); } + +} // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/ifacedecomp.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/ifacedecomp.hh index 41bb994258..1f8d1f31ab 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/ifacedecomp.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/ifacedecomp.hh @@ -16,8 +16,8 @@ /// \file ifacedecomp.hh /// \brief Console interface commands for the decompiler engine -#ifndef __IFACE_DECOMP__ -#define __IFACE_DECOMP__ +#ifndef __IFACEDECOMP_HH__ +#define __IFACEDECOMP_HH__ #include "graph.hh" #include "grammar.hh" @@ -28,6 +28,8 @@ #include "rulecompile.hh" #endif +namespace ghidra { + /// \brief Interface capability point for all decompiler commands class IfaceDecompCapability : public IfaceCapability { static IfaceDecompCapability ifaceDecompCapability; ///< Singleton instance @@ -656,4 +658,5 @@ public: #endif +} // End namespace ghidra #endif diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/ifaceterm.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/ifaceterm.cc index 44a5843058..20ca9f663a 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/ifaceterm.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/ifaceterm.cc @@ -15,6 +15,8 @@ */ #include "ifaceterm.hh" +namespace ghidra { + IfaceTerm::IfaceTerm(const string &prmpt,istream &is,ostream &os) : IfaceStatus(prmpt,os) { @@ -265,3 +267,5 @@ bool IfaceTerm::isStreamFinished(void) const if (done||inerror) return true; return sptr->eof(); } + +} // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/ifaceterm.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/ifaceterm.hh index 3ca912dd6b..82786532ec 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/ifaceterm.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/ifaceterm.hh @@ -16,6 +16,9 @@ /// \file ifaceterm.hh /// \brief Add some terminal capabilities to the command-line interface (IfaceStatus) +#ifndef __IFACETERM_HH__ +#define __IFACETERM_HH__ + #include "interface.hh" #ifdef __TERMINAL__ @@ -25,6 +28,8 @@ extern "C" { } #endif +namespace ghidra { + /// \brief Implement the command-line interface on top of a specific input stream /// /// An initial input stream is provided as the base stream to parse for commands. @@ -48,3 +53,6 @@ public: virtual void popScript(void); virtual bool isStreamFinished(void) const; }; + +} // End namespace ghidra +#endif diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/inject_ghidra.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/inject_ghidra.cc index 1f14d2a55b..37181d168d 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/inject_ghidra.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/inject_ghidra.cc @@ -15,6 +15,8 @@ */ #include "inject_ghidra.hh" +namespace ghidra { + void InjectContextGhidra::encode(Encoder &encoder) const { @@ -230,3 +232,5 @@ int4 PcodeInjectLibraryGhidra::manualCallOtherFixup(const string &name,const str { return 0; // We don't have to do anything } + +} // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/inject_ghidra.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/inject_ghidra.hh index c0678039c7..578abf66bf 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/inject_ghidra.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/inject_ghidra.hh @@ -16,12 +16,14 @@ /// \file inject_ghidra.hh /// \brief P-code injection classes using a Ghidra client as the back-end for generating p-code -#ifndef __INJECT_GHIDRA__ -#define __INJECT_GHIDRA__ +#ifndef __INJECT_GHIDRA_HH__ +#define __INJECT_GHIDRA_HH__ #include "pcodeinject.hh" #include "ghidra_arch.hh" +namespace ghidra { + /// \brief An injection context that can be serialized and sent to the Ghidra client /// /// This adds the capability to wrap up the context data in \ XML tag @@ -91,4 +93,5 @@ public: virtual const vector &getBehaviors(void); }; +} // End namespace ghidra #endif diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/inject_sleigh.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/inject_sleigh.cc index e37e3f4695..cc8ed87b80 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/inject_sleigh.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/inject_sleigh.cc @@ -17,6 +17,8 @@ #include "pcodeparse.hh" #include "architecture.hh" +namespace ghidra { + InjectContextSleigh::~InjectContextSleigh(void) { @@ -468,3 +470,5 @@ int4 PcodeInjectLibrarySleigh::manualCallOtherFixup(const string &name,const str registerInject(injectid); return injectid; } + +} // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/inject_sleigh.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/inject_sleigh.hh index be86fbcf6e..2de9eaae66 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/inject_sleigh.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/inject_sleigh.hh @@ -13,12 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef __INJECT_SLEIGH__ -#define __INJECT_SLEIGH__ +#ifndef __INJECT_SLEIGH_HH__ +#define __INJECT_SLEIGH_HH__ #include "pcodeinject.hh" #include "sleigh.hh" +namespace ghidra { + class InjectContextSleigh : public InjectContext { public: PcodeCacher cacher; @@ -109,4 +111,5 @@ public: virtual const vector &getBehaviors(void); }; +} // End namespace ghidra #endif diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/interface.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/interface.cc index 8ac61f8892..85f5f91df3 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/interface.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/interface.cc @@ -21,6 +21,8 @@ #include "ext/stdio_filebuf.h" #endif +namespace ghidra { + vector IfaceCapability::thelist; void IfaceCapability::initialize(void) @@ -612,3 +614,5 @@ void IfcEcho::execute(istream &s) status->fileoptr->put(c); *status->fileoptr << endl; } + +} // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/interface.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/interface.hh index 03755410b7..d862fa2c36 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/interface.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/interface.hh @@ -16,8 +16,8 @@ /// \file interface.hh /// \brief Classes and utilities for a \e generic command-line interface -#ifndef __INTERFACE__ -#define __INTERFACE__ +#ifndef __INTERFACE_HH__ +#define __INTERFACE_HH__ #include "capability.hh" #include @@ -26,6 +26,8 @@ #include #include +namespace ghidra { + using std::map; using std::istream; using std::ostream; @@ -295,4 +297,5 @@ public: virtual void execute(istream &s); }; +} // End namespace ghidra #endif diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/jumptable.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/jumptable.cc index 47d220df0a..c689c75430 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/jumptable.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/jumptable.cc @@ -17,6 +17,9 @@ #include "emulate.hh" #include "flow.hh" +namespace ghidra { + + AttributeId ATTRIB_LABEL = AttributeId("label",131); AttributeId ATTRIB_NUM = AttributeId("num",132); @@ -2811,3 +2814,5 @@ bool JumpTable::checkForMultistage(Funcdata *fd) } return false; } + +} // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/jumptable.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/jumptable.hh index 4c9b6d552d..cd9acf2c97 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/jumptable.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/jumptable.hh @@ -16,12 +16,14 @@ /// \file jumptable.hh /// \brief Classes to support jump-tables and their recovery -#ifndef __CPUI_JUMPTABLE__ -#define __CPUI_JUMPTABLE__ +#ifndef __JUMPTABLE_HH__ +#define __JUMPTABLE_HH__ #include "emulateutil.hh" #include "rangeutil.hh" +namespace ghidra { + class EmulateFunction; extern AttributeId ATTRIB_LABEL; ///< Marshaling attribute "label" @@ -601,4 +603,5 @@ inline bool JumpTable::IndexPair::compareByPosition(const IndexPair &op1,const I return (op1.blockPosition < op2.blockPosition); } +} // End namespace ghidra #endif diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/libdecomp.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/libdecomp.cc index b60a349fe7..869c131f53 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/libdecomp.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/libdecomp.cc @@ -15,6 +15,8 @@ */ #include "libdecomp.hh" +namespace ghidra { + void startDecompilerLibrary(const char *sleighhome) { @@ -59,3 +61,4 @@ void shutdownDecompilerLibrary(void) { } +} // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/libdecomp.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/libdecomp.hh index e7f5ae179d..1c1dcdd827 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/libdecomp.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/libdecomp.hh @@ -17,13 +17,15 @@ // You should be able to include this header to get all functionality // and we put a startup and shutdown routine here -#ifndef __LIBDECOMP__ -#define __LIBDECOMP__ +#ifndef __LIBDECOMP_HH__ +#define __LIBDECOMP_HH__ #include "architecture.hh" #include "sleigh_arch.hh" #include "ifacedecomp.hh" +namespace ghidra { + // Initialize all decompiler capabilities and register any sleigh specifications // If you have an entire ghidra distribution, you can specify its root with the -sleighhome- input, // otherwise you can provide a list of directories that contain '.lspec' files. @@ -33,4 +35,5 @@ extern void startDecompilerLibrary(const char *sleighhome,const vector & extern void shutdownDecompilerLibrary(void); +} // End namespace ghidra #endif diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/loadimage.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/loadimage.cc index e14109b328..87bcb5de89 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/loadimage.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/loadimage.cc @@ -15,6 +15,8 @@ */ #include "loadimage.hh" +namespace ghidra { + /// This is a convenience method wrapped around the core /// loadFill() routine. It automatically allocates an array /// of the desired size, and then fills it with load image data. @@ -110,3 +112,5 @@ void RawLoadImage::loadFill(uint1 *ptr,int4 size,const Address &addr) throw DataUnavailError(errmsg.str()); } } + +} // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/loadimage.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/loadimage.hh index 59d4c9a5d4..76dce9bada 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/loadimage.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/loadimage.hh @@ -16,11 +16,13 @@ /// \file loadimage.hh /// \brief Classes and API for accessing a binary load image -#ifndef __CPUI_LOADIMAGE__ -#define __CPUI_LOADIMAGE__ +#ifndef __LOADIMAGE_HH__ +#define __LOADIMAGE_HH__ #include "address.hh" +namespace ghidra { + /// \brief Exception indicating data was not available /// /// This exception is thrown when a request for load image @@ -224,4 +226,5 @@ inline void LoadImage::getReadonly(RangeList &list) const { /// \param size is the number of bytes to retrieve from the image /// \param addr is the starting address of the bytes to retrieve +} // End namespace ghidra #endif diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/loadimage_bfd.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/loadimage_bfd.cc index 7e9f1ad8a5..477c17e817 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/loadimage_bfd.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/loadimage_bfd.cc @@ -16,6 +16,8 @@ */ #include "loadimage_bfd.hh" +namespace ghidra { + int4 LoadImageBfd::bfdinit = 0; // Global initialization variable LoadImageBfd::LoadImageBfd(const string &f,const string &t) : LoadImage(f) @@ -297,3 +299,5 @@ void LoadImageBfd::getReadonly(RangeList &list) const } } } + +} // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/loadimage_bfd.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/loadimage_bfd.hh index 9d69fcca5c..2e9929db08 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/loadimage_bfd.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/loadimage_bfd.hh @@ -16,8 +16,8 @@ */ // Use the GNU bfd library to manipulate a load image -#ifndef __LOADIMAGE_BFD__ -#define __LOADIMAGE_BFD__ +#ifndef __LOADIMAGE_BFD_HH__ +#define __LOADIMAGE_BFD_HH__ #include "loadimage.hh" @@ -46,6 +46,8 @@ #undef __LOADIMAGE_BFD__DEFINED_PACKAGE_VERSION #endif +namespace ghidra { + struct ImportRecord { string dllname; string funcname; @@ -88,4 +90,5 @@ public: virtual void adjustVma(long adjust); }; +} // End namespace ghidra #endif diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/loadimage_ghidra.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/loadimage_ghidra.cc index 069a1f9563..df50952bb5 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/loadimage_ghidra.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/loadimage_ghidra.cc @@ -15,6 +15,8 @@ */ #include "loadimage_ghidra.hh" +namespace ghidra { + LoadImageGhidra::LoadImageGhidra(ArchitectureGhidra *g) : LoadImage("ghidra_progam") @@ -49,3 +51,5 @@ void LoadImageGhidra::adjustVma(long adjust) { throw LowlevelError("Cannot adjust GHIDRA virtual memory"); } + +} // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/loadimage_ghidra.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/loadimage_ghidra.hh index 95c56dcdf9..a615a2af9d 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/loadimage_ghidra.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/loadimage_ghidra.hh @@ -15,12 +15,14 @@ */ /// \file loadimage_ghidra.hh /// \brief Use the Ghidra client as a load image -#ifndef __LOADIMAGE_GHIDRA__ -#define __LOADIMAGE_GHIDRA__ +#ifndef __LOADIMAGE_GHIDRA_HH__ +#define __LOADIMAGE_GHIDRA_HH__ #include "loadimage.hh" #include "ghidra_arch.hh" +namespace ghidra { + class ArchitectureGhidra; /// \brief An implementation of the LoadImage interface using a Ghidra client as the back-end @@ -39,4 +41,5 @@ public: virtual void adjustVma(long adjust); }; +} // End namespace ghidra #endif diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/loadimage_xml.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/loadimage_xml.cc index b7a9a30c48..6847a5ebcb 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/loadimage_xml.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/loadimage_xml.cc @@ -16,6 +16,8 @@ #include "loadimage_xml.hh" #include "translate.hh" +namespace ghidra { + AttributeId ATTRIB_ARCH = AttributeId("arch",135); ElementId ELEM_BINARYIMAGE = ElementId("binaryimage",230); @@ -292,3 +294,5 @@ void LoadImageXml::adjustVma(long adjust) } addrtosymbol = newsymbol; } + +} // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/loadimage_xml.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/loadimage_xml.hh index 018cc06bb1..350ccfba1c 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/loadimage_xml.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/loadimage_xml.hh @@ -16,11 +16,13 @@ /// \file loadimage_xml.hh /// \brief Support for programs stored using an XML schema -#ifndef __LOADIMAGE_XML__ -#define __LOADIMAGE_XML__ +#ifndef __LOADIMAGE_XML_HH__ +#define __LOADIMAGE_XML_HH__ #include "loadimage.hh" +namespace ghidra { + extern AttributeId ATTRIB_ARCH; ///< Marshaling attribute "arch" extern ElementId ELEM_BINARYIMAGE; ///< Marshaling element \ @@ -53,4 +55,5 @@ public: virtual void adjustVma(long adjust); }; +} // End namespace ghidra #endif diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/marshal.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/marshal.cc index 9be7a178f2..5327b104fa 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/marshal.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/marshal.cc @@ -16,6 +16,8 @@ #include "marshal.hh" #include "translate.hh" +namespace ghidra { + using namespace PackedFormat; unordered_map AttributeId::lookupAttributeId; @@ -1159,3 +1161,5 @@ ElementId ELEM_VALUE = ElementId("value",9); ElementId ELEM_VOID = ElementId("void",10); ElementId ELEM_UNKNOWN = ElementId("XMLunknown",270); // Number serves as next open index + +} // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/marshal.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/marshal.hh index 46478206d3..572ba92065 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/marshal.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/marshal.hh @@ -13,13 +13,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef __CPUI_MARSHAL__ -#define __CPUI_MARSHAL__ +#ifndef __MARSHAL_HH__ +#define __MARSHAL_HH__ #include "xml.hh" #include #include +namespace ghidra { + using std::list; using std::unordered_map; @@ -685,4 +687,5 @@ extern ElementId ELEM_VAL; ///< Marshaling element \ extern ElementId ELEM_VALUE; ///< Marshaling element \ extern ElementId ELEM_VOID; ///< Marshaling element \ +} // End namespace ghidra #endif diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/memstate.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/memstate.cc index be9a570a09..874909f0dc 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/memstate.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/memstate.cc @@ -16,6 +16,8 @@ #include "memstate.hh" #include "translate.hh" +namespace ghidra { + /// This is a static convenience routine for decoding a value from a sequence of bytes depending /// on the desired endianness /// \param ptr is the pointer to the bytes to decode @@ -733,3 +735,4 @@ void MemoryState::setChunk(const uint1 *val,AddrSpace *spc,uintb off,int4 size) mspace->setChunk(off,size,val); } +} // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/memstate.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/memstate.hh index 6a260c4669..7f1ccfe498 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/memstate.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/memstate.hh @@ -16,12 +16,14 @@ /// \file memstate.hh /// \brief Classes for keeping track of memory state during emulation -#ifndef __CPUI_MEMSTATE__ -#define __CPUI_MEMSTATE__ +#ifndef __MEMSTATE_HH__ +#define __MEMSTATE_HH__ #include "pcoderaw.hh" #include "loadimage.hh" +namespace ghidra { + /// \brief Memory storage/state for a single AddressSpace /// /// Class for setting and getting memory values within a space @@ -202,4 +204,5 @@ inline uintb MemoryState::getValue(const VarnodeData *vn) const return getValue(vn->space,vn->offset,vn->size); } +} // End namespace ghidra #endif diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/merge.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/merge.cc index 1fa81812de..baf31f1997 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/merge.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/merge.cc @@ -16,6 +16,8 @@ #include "merge.hh" #include "funcdata.hh" +namespace ghidra { + /// This instance assumes the identity of the given Varnode and the defining index is /// cached to facilitate quick sorting. /// \param v is the given Varnode @@ -1669,3 +1671,5 @@ void Merge::verifyHighCovers(void) } } #endif + +} // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/merge.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/merge.hh index f801b60a8b..bcce463261 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/merge.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/merge.hh @@ -13,14 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef __CPUI_MERGE__ -#define __CPUI_MERGE__ +#ifndef __MERGE_HH__ +#define __MERGE_HH__ /// \file merge.hh /// \brief Utilities for merging low-level Varnodes into high-level variables #include "op.hh" +namespace ghidra { + /// \brief Helper class associating a Varnode with the block where it is defined /// /// This class explicitly stores a Varnode with the index of the BlockBasic that defines it. @@ -156,4 +158,5 @@ inline bool Merge::compareHighByBlock(const HighVariable *a,const HighVariable * return (result < 0); } +} // End namespace ghidra #endif diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/op.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/op.cc index 00962c6b31..0e3decc80d 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/op.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/op.cc @@ -16,6 +16,8 @@ #include "op.hh" #include "funcdata.hh" +namespace ghidra { + ElementId ELEM_IOP = ElementId("iop",113); ElementId ELEM_UNIMPL = ElementId("unimpl",114); @@ -1329,3 +1331,5 @@ bool functionalDifference(Varnode *vn1,Varnode *vn2,int4 depth) return true; return false; } + +} // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/op.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/op.hh index 7e9ca00986..02e6906f24 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/op.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/op.hh @@ -15,11 +15,13 @@ */ /// \file op.hh /// \brief The PcodeOp and PcodeOpBank classes -#ifndef __CPUI_OP__ -#define __CPUI_OP__ +#ifndef __OP_HH__ +#define __OP_HH__ #include "typeop.hh" +namespace ghidra { + extern ElementId ELEM_IOP; ///< Marshaling element \ extern ElementId ELEM_UNIMPL; ///< Marshaling element \ @@ -371,4 +373,5 @@ inline bool PcodeOpNode::operator<(const PcodeOpNode &op2) const return false; } +} // End namespace ghidra #endif diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/opbehavior.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/opbehavior.cc index bbf2de8f5f..fcd75cc7da 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/opbehavior.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/opbehavior.cc @@ -16,6 +16,8 @@ #include "opbehavior.hh" #include "translate.hh" +namespace ghidra { + /// This routine generates a vector of OpBehavior objects indexed by opcode /// \param inst is the vector of behaviors to be filled /// \param trans is the translator object needed by the floating point behaviors @@ -763,3 +765,5 @@ uintb OpBehaviorLzcount::evaluateUnary(int4 sizeout,int4 sizein,uintb in1) const { return (uintb)(count_leading_zeros(in1) - 8*(sizeof(uintb) - sizein)); } + +} // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/opbehavior.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/opbehavior.hh index b7a4c04091..2eb9752bac 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/opbehavior.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/opbehavior.hh @@ -15,12 +15,14 @@ */ /// \file opbehavior.hh /// \brief Classes for describing the behavior of individual p-code operations -#ifndef __CPUI_OPBEHAVIOR__ -#define __CPUI_OPBEHAVIOR__ +#ifndef __OPBEHAVIOR_HH__ +#define __OPBEHAVIOR_HH__ #include "error.hh" #include "opcodes.hh" +namespace ghidra { + class Translate; // Forward declaration /// This exception is thrown when emulation evaluation of an operator fails for some reason. @@ -518,4 +520,5 @@ public: virtual uintb evaluateUnary(int4 sizeout,int4 sizein,uintb in1) const; }; +} // End namespace ghidra #endif diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/opcodes.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/opcodes.cc index 1c1a1ea272..cdde06fa71 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/opcodes.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/opcodes.cc @@ -16,6 +16,8 @@ #include "opcodes.hh" #include "types.h" +namespace ghidra { + /// \brief Names of operations associated with their opcode number /// /// Some of the names have been replaced with special placeholder @@ -131,3 +133,5 @@ OpCode get_booleanflip(OpCode opc,bool &reorder) } return CPUI_MAX; } + +} // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/opcodes.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/opcodes.hh index e06bcd4ae0..5cb4482737 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/opcodes.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/opcodes.hh @@ -16,11 +16,13 @@ /// \file opcodes.hh /// \brief All the individual p-code operations -#ifndef __CPUI_OPCODES__ -#define __CPUI_OPCODES__ +#ifndef __OPCODES_HH__ +#define __OPCODES_HH__ #include +namespace ghidra { + using std::string; /// \brief The op-code defining a specific p-code operation (PcodeOp) @@ -133,4 +135,5 @@ extern OpCode get_opcode(const string &nm); ///< Convert a name string to the m extern OpCode get_booleanflip(OpCode opc,bool &reorder); ///< Get the complementary OpCode +} // End namespace ghidra #endif diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/options.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/options.cc index 0ee439e447..c422cc3f99 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/options.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/options.cc @@ -18,6 +18,8 @@ #include "flow.hh" #include "printc.hh" +namespace ghidra { + ElementId ELEM_ALIASBLOCK = ElementId("aliasblock",174); ElementId ELEM_ALLOWCONTEXTSET = ElementId("allowcontextset",175); ElementId ELEM_ANALYZEFORLOOPS = ElementId("analyzeforloops",176); @@ -917,3 +919,5 @@ string OptionNamespaceStrategy::apply(Architecture *glb,const string &p1,const s glb->print->setNamespaceStrategy(strategy); return "Namespace strategy set"; } + +} // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/options.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/options.hh index 474ee70715..d9cff786da 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/options.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/options.hh @@ -16,12 +16,14 @@ /// \file options.hh /// \brief Classes for processing architecture configuration options -#ifndef __ARCH_OPTIONS__ -#define __ARCH_OPTIONS__ +#ifndef __OPTIONS_HH__ +#define __OPTIONS_HH__ #include "error.hh" #include "marshal.hh" +namespace ghidra { + class Architecture; extern ElementId ELEM_ALIASBLOCK; ///< Marshaling element \ @@ -320,4 +322,5 @@ public: virtual string apply(Architecture *glb,const string &p1,const string &p2,const string &p3) const; }; +} // End namespace ghidra #endif diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/override.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/override.cc index f64cb03ca6..f6fd0f5524 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/override.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/override.cc @@ -16,6 +16,8 @@ #include "override.hh" #include "funcdata.hh" +namespace ghidra { + ElementId ELEM_DEADCODEDELAY = ElementId("deadcodedelay",218); ElementId ELEM_FLOW = ElementId("flow",219); ElementId ELEM_FORCEGOTO = ElementId("forcegoto",220); @@ -429,3 +431,5 @@ uint4 Override::stringToType(const string &nm) return Override::RETURN; return Override::NONE; } + +} // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/override.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/override.hh index 1a76e46e1d..693c2e62b3 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/override.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/override.hh @@ -16,11 +16,13 @@ /// \file override.hh /// \brief A system for sending override commands to the decompiler -#ifndef __OVERRIDE__ -#define __OVERRIDE__ +#ifndef __OVERRIDE_HH__ +#define __OVERRIDE_HH__ #include "database.hh" +namespace ghidra { + class FuncCallSpecs; // Forward declaration extern ElementId ELEM_DEADCODEDELAY; ///< Marshaling element \ @@ -89,4 +91,5 @@ public: static uint4 stringToType(const string &nm); ///< Convert a string to a flow override type }; +} // End namespace ghidra #endif diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/paramid.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/paramid.cc index 093a8b232d..66c239e66f 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/paramid.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/paramid.cc @@ -15,6 +15,8 @@ */ #include "paramid.hh" +namespace ghidra { + ElementId ELEM_PARAMMEASURES = ElementId("parammeasures",106); ElementId ELEM_PROTO = ElementId("proto",107); ElementId ELEM_RANK = ElementId("rank",108); @@ -278,3 +280,5 @@ void ParamIDAnalysis::savePretty( ostream &s,bool moredetail ) const } s << "\n"; } + +} // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/paramid.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/paramid.hh index 7eb7d78c97..e2b1847839 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/paramid.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/paramid.hh @@ -13,11 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef __CPUI_PARAMID__ -#define __CPUI_PARAMID__ +#ifndef __PARAMID_HH__ +#define __PARAMID_HH__ #include "funcdata.hh" +namespace ghidra { + extern ElementId ELEM_PARAMMEASURES; ///< Marshaling element \ extern ElementId ELEM_PROTO; ///< Marshaling element \ extern ElementId ELEM_RANK; ///< Marshaling element \ @@ -76,4 +78,5 @@ public: void savePretty( ostream &s, bool moredetail ) const; }; -#endif //ifndef __CPUI_PARAMID__ +} // End namespace ghidra +#endif //ifndef __PARAMID_HH__ diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/partmap.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/partmap.hh index 4573f4960a..6bed941ed4 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/partmap.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/partmap.hh @@ -16,11 +16,13 @@ */ /// \file partmap.hh /// \brief The partmap<> template mapping a linear space to value objects -#ifndef __PARTMAP__ -#define __PARTMAP__ +#ifndef __PARTMAP_HH__ +#define __PARTMAP_HH__ #include +namespace ghidra { + /// \brief A map from a linear space to value objects /// /// The partmap is a template class taking: @@ -194,6 +196,8 @@ template after = (*enditer).first; return defaultvalue; } + +} // End namespace ghidra #endif #if 0 diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/pcodecompile.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/pcodecompile.cc index 49128f7e6e..ca9d71ab99 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/pcodecompile.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/pcodecompile.cc @@ -15,6 +15,8 @@ */ #include "pcodecompile.hh" +namespace ghidra { + string Location::format(void) const { @@ -778,3 +780,5 @@ VarnodeTpl *PcodeCompile::addressOf(VarnodeTpl *var,uint4 size) delete var; return res; } + +} // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/pcodecompile.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/pcodecompile.hh index 3c7f2b26f4..3caa57c69f 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/pcodecompile.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/pcodecompile.hh @@ -13,11 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef __PCODE_COMPILE__ -#define __PCODE_COMPILE__ +#ifndef __PCODECOMPILE_HH__ +#define __PCODECOMPILE_HH__ #include "slghsymbol.hh" +namespace ghidra { + class Location { string filename; int4 lineno; @@ -102,4 +104,5 @@ public: static bool propagateSize(ConstructTpl *ct); }; +} // End namespace ghidra #endif diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/pcodeinject.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/pcodeinject.cc index 7a317f47fb..f322320228 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/pcodeinject.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/pcodeinject.cc @@ -16,6 +16,8 @@ #include "pcodeinject.hh" #include "architecture.hh" +namespace ghidra { + AttributeId ATTRIB_DYNAMIC = AttributeId("dynamic",70); AttributeId ATTRIB_INCIDENTALCOPY = AttributeId("incidentalcopy",71); AttributeId ATTRIB_INJECT = AttributeId("inject",72); @@ -355,3 +357,5 @@ int4 PcodeInjectLibrary::decodeInject(const string &src,const string &nm,int4 tp registerInject(injectid); return injectid; } + +} // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/pcodeinject.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/pcodeinject.hh index d57215bc7c..f123ac769e 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/pcodeinject.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/pcodeinject.hh @@ -16,11 +16,13 @@ /// \file pcodeinject.hh /// \brief Classes for managing \b p-code \b injection. -#ifndef __PCODEINJECT__ -#define __PCODEINJECT__ +#ifndef __PCODEINJECT_HH__ +#define __PCODEINJECT_HH__ #include "emulateutil.hh" +namespace ghidra { + class Architecture; extern AttributeId ATTRIB_DYNAMIC; ///< Marshaling attribute "dynamic" @@ -271,4 +273,5 @@ public: virtual const vector &getBehaviors(void)=0; }; +} // End namespace ghidra #endif diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/pcodeparse.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/pcodeparse.cc index 8441427171..3ab453daa8 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/pcodeparse.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/pcodeparse.cc @@ -90,10 +90,12 @@ #include "pcodeparse.hh" - //#define YYERROR_VERBOSE - extern int pcodelex(void); - static PcodeSnippet *pcode; - extern int pcodeerror(const char *str ); +//#define YYERROR_VERBOSE +namespace ghidra { + +extern int pcodelex(void); +static PcodeSnippet *pcode; +extern int pcodeerror(const char *str ); @@ -543,19 +545,19 @@ static const yytype_uint8 yytranslate[] = /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */ static const yytype_uint8 yyrline[] = { - 0, 102, 102, 104, 105, 106, 107, 109, 110, 111, - 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, - 122, 123, 124, 125, 126, 127, 129, 130, 131, 132, - 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, - 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, - 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, - 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, - 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, - 183, 184, 185, 186, 187, 188, 189, 190, 191, 193, - 194, 195, 196, 198, 199, 200, 201, 202, 203, 204, - 205, 207, 208, 209, 211, 212, 213, 214, 215, 217, - 218, 220, 221, 223, 224, 225, 226, 227, 229, 230, - 231 + 0, 104, 104, 106, 107, 108, 109, 111, 112, 113, + 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, + 124, 125, 126, 127, 128, 129, 131, 132, 133, 134, + 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, + 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, + 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, + 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, + 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, + 185, 186, 187, 188, 189, 190, 191, 192, 193, 195, + 196, 197, 198, 200, 201, 202, 203, 204, 205, 206, + 207, 209, 210, 211, 213, 214, 215, 216, 217, 219, + 220, 222, 223, 225, 226, 227, 228, 229, 231, 232, + 233 }; #endif @@ -3442,3 +3444,5 @@ int pcodeerror(const char *s) pcode->reportError((const Location *)0,s); return 0; } + +} // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/pcodeparse.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/pcodeparse.hh index 587604237a..8be3185755 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/pcodeparse.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/pcodeparse.hh @@ -13,12 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef __PCODE_SNIPPET__ -#define __PCODE_SNIPPET__ +#ifndef __PCODEPARSE_HH__ +#define __PCODEPARSE_HH__ #include "pcodecompile.hh" #include "sleighbase.hh" +namespace ghidra { + // Classes for compiling a standalone snippet of pcode, given an existing sleigh language struct IdentRec { @@ -95,5 +97,5 @@ public: void addOperand(const string &name,int4 index); }; - +} // End namespace ghidra #endif diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/pcodeparse.y b/Ghidra/Features/Decompiler/src/decompile/cpp/pcodeparse.y index 9f93f7b0c4..387f38512c 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/pcodeparse.y +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/pcodeparse.y @@ -17,10 +17,12 @@ %{ #include "pcodeparse.hh" - //#define YYERROR_VERBOSE - extern int pcodelex(void); - static PcodeSnippet *pcode; - extern int pcodeerror(const char *str ); +//#define YYERROR_VERBOSE +namespace ghidra { + +extern int pcodelex(void); +static PcodeSnippet *pcode; +extern int pcodeerror(const char *str ); %} %union { @@ -810,3 +812,5 @@ int pcodeerror(const char *s) pcode->reportError((const Location *)0,s); return 0; } + +} // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/pcoderaw.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/pcoderaw.cc index 317d4dbf1c..3a052d536e 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/pcoderaw.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/pcoderaw.cc @@ -16,6 +16,8 @@ #include "pcoderaw.hh" #include "translate.hh" +namespace ghidra { + /// Build this VarnodeData from an \, \, or \ element. /// \param decoder is the stream decoder void VarnodeData::decode(Decoder &decoder) @@ -99,3 +101,5 @@ OpCode PcodeOpRaw::decode(Decoder &decoder,int4 isize,VarnodeData *invar,Varnode } return opcode; } + +} // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/pcoderaw.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/pcoderaw.hh index fd70a956e7..273c2bac6d 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/pcoderaw.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/pcoderaw.hh @@ -15,12 +15,14 @@ */ /// \file pcoderaw.hh /// \brief Raw descriptions of varnodes and p-code ops -#ifndef __CPUI_PCODERAW__ -#define __CPUI_PCODERAW__ +#ifndef __PCODERAW_HH__ +#define __PCODERAW_HH__ #include "address.hh" #include "opbehavior.hh" +namespace ghidra { + /// \brief Data defining a specific memory location /// /// Within the decompiler's model of a processor, any register, @@ -234,4 +236,5 @@ inline VarnodeData *PcodeOpRaw::getInput(int4 i) const return in[i]; } +} // End namespace ghidra #endif diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/prefersplit.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/prefersplit.cc index 6359418856..826ff069d1 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/prefersplit.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/prefersplit.cc @@ -16,6 +16,8 @@ #include "prefersplit.hh" #include "funcdata.hh" +namespace ghidra { + ElementId ELEM_PREFERSPLIT = ElementId("prefersplit",225); bool PreferSplitRecord::operator<(const PreferSplitRecord &op2) const @@ -625,3 +627,5 @@ void PreferSplitManager::splitAdditional(void) } } } + +} // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/prefersplit.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/prefersplit.hh index 9654ceedd1..4f8d33a2d8 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/prefersplit.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/prefersplit.hh @@ -13,10 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef __PREFERSPLIT__ -#define __PREFERSPLIT__ +#ifndef __PREFERSPLIT_HH__ +#define __PREFERSPLIT_HH__ #include "varnode.hh" + +namespace ghidra { + class Funcdata; // Forward declaration extern ElementId ELEM_PREFERSPLIT; ///< Marshaling element \ @@ -68,4 +71,5 @@ public: void splitAdditional(void); }; +} // End namespace ghidra #endif diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/prettyprint.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/prettyprint.cc index 388708030a..3e8d18ade7 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/prettyprint.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/prettyprint.cc @@ -16,6 +16,8 @@ #include "prettyprint.hh" #include "funcdata.hh" +namespace ghidra { + AttributeId ATTRIB_BLOCKREF = AttributeId("blockref",35); AttributeId ATTRIB_CLOSE = AttributeId("close",36); AttributeId ATTRIB_COLOR = AttributeId("color",37); @@ -1169,3 +1171,5 @@ void EmitPrettyPrint::resetDefaults(void) resetDefaultsInternal(); resetDefaultsPrettyPrint(); } + +} // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/prettyprint.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/prettyprint.hh index cc81dad23d..6e7124ccc5 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/prettyprint.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/prettyprint.hh @@ -16,11 +16,13 @@ /// \file prettyprint.hh /// \brief Routines for emitting high-level (C) language syntax in a well formatted way. -#ifndef __PRETTYPRINT__ -#define __PRETTYPRINT__ +#ifndef __PRETTYPRINT_HH__ +#define __PRETTYPRINT_HH__ #include "type.hh" +namespace ghidra { + class Varnode; class PcodeOp; class FlowBlock; @@ -1060,4 +1062,5 @@ inline void Emit::emitPending(void) } } +} // End namespace ghidra #endif diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/printc.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/printc.cc index d93f044fb3..a84562e971 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/printc.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/printc.cc @@ -16,6 +16,8 @@ #include "printc.hh" #include "funcdata.hh" +namespace ghidra { + // Operator tokens for expressions // token #in prec assoc optype space bump OpToken PrintC::hidden = { "", "", 1, 70, false, OpToken::hiddenfunction, 0, 0, (OpToken *)0 }; @@ -3343,3 +3345,5 @@ string PrintC::genericTypeName(const Datatype *ct) s << dec << ct->getSize(); return s.str(); } + +} // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/printc.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/printc.hh index f8d1e93092..9009784a8d 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/printc.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/printc.hh @@ -16,12 +16,14 @@ /// \file printc.hh /// \brief Classes to support the c-language back-end of the decompiler -#ifndef __PRINTC__ -#define __PRINTC__ +#ifndef __PRINTC_HH__ +#define __PRINTC_HH__ #include "printlanguage.hh" #include "comment.hh" +namespace ghidra { + class FuncProto; class JumpTable; @@ -356,4 +358,5 @@ inline void PrintC::pushTypePointerRel(const PcodeOp *op) pushAtom(Atom(typePointerRelToken,optoken,EmitMarkup::funcname_color,op)); } +} // End namespace ghidra #endif diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/printjava.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/printjava.cc index 473bab08af..3084ffee21 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/printjava.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/printjava.cc @@ -16,6 +16,8 @@ #include "printjava.hh" #include "funcdata.hh" +namespace ghidra { + OpToken PrintJava::instanceof = { "instanceof", "", 2, 60, true, OpToken::binary, 1, 0, (OpToken *)0 }; // Constructing this registers the capability @@ -359,3 +361,5 @@ void PrintJava::opCpoolRefOp(const PcodeOp *op) } } } + +} // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/printjava.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/printjava.hh index f3f200d115..1c610063ee 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/printjava.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/printjava.hh @@ -16,11 +16,13 @@ /// \file printjava.hh /// \brief Classes supporting the java-language back-end to the decompiler -#ifndef __PRINTJAVA__ -#define __PRINTJAVA__ +#ifndef __PRINTJAVA_HH__ +#define __PRINTJAVA_HH__ #include "printc.hh" +namespace ghidra { + /// \brief Factory and static initializer for the "java-language" back-end to the decompiler /// /// The singleton adds itself to the list of possible back-end languages for the decompiler @@ -71,4 +73,6 @@ public: virtual void opCallind(const PcodeOp *op); virtual void opCpoolRefOp(const PcodeOp *op); }; + +} // End namespace ghidra #endif diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/printlanguage.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/printlanguage.cc index aad62c9f40..c3b4317372 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/printlanguage.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/printlanguage.cc @@ -17,6 +17,8 @@ #include "printlanguage.hh" #include "funcdata.hh" +namespace ghidra { + const string PrintLanguage::OPEN_PAREN = "("; const string PrintLanguage::CLOSE_PAREN = ")"; @@ -811,3 +813,5 @@ void PrintLanguage::formatBinary(ostream &s,uintb val) mask >>= 1; } } + +} // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/printlanguage.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/printlanguage.hh index 5a182b39dc..ef5bbccc49 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/printlanguage.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/printlanguage.hh @@ -16,13 +16,15 @@ /// \file printlanguage.hh /// \brief Classes for printing tokens in a high-level language -#ifndef __PRINT_LANGUAGE__ -#define __PRINT_LANGUAGE__ +#ifndef __PRINTLANGUAGE_HH__ +#define __PRINTLANGUAGE_HH__ #include "capability.hh" #include "cast.hh" #include "prettyprint.hh" +namespace ghidra { + class PrintLanguage; class ResolvedUnion; @@ -561,4 +563,5 @@ public: static void formatBinary(ostream &s,uintb val); ///< Print a number in binary form }; +} // End namespace ghidra #endif diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/rangemap.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/rangemap.hh index 05e315ca0a..ba29f9886f 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/rangemap.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/rangemap.hh @@ -16,12 +16,14 @@ /// \file rangemap.hh /// \brief Templates to define interval map containers -#ifndef __RANGEMAP__ -#define __RANGEMAP__ +#ifndef __RANGEMAP_HH__ +#define __RANGEMAP_HH__ #include #include +namespace ghidra { + /// \brief An interval map container /// /// A container for records occupying (possibly overlapping) @@ -420,4 +422,5 @@ rangemap<_recordtype>::find_overlap(linetype point,linetype end) const return tree.end(); } +} // End namespace ghidra #endif diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/rangeutil.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/rangeutil.cc index d989984262..a557204e59 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/rangeutil.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/rangeutil.cc @@ -16,6 +16,8 @@ #include "rangeutil.hh" #include "block.hh" +namespace ghidra { + const char CircleRange::arrange[] = "gcgbegdagggggggeggggcgbggggggggcdfgggggggegdggggbgggfggggcgbegda"; /// All the instantiations where left == right represent the same set. We @@ -2600,3 +2602,5 @@ void ValueSetSolver::dumpValueSets(ostream &s) const } #endif + +} // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/rangeutil.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/rangeutil.hh index e4f37b0639..6c7cc05858 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/rangeutil.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/rangeutil.hh @@ -15,11 +15,13 @@ */ /// \file rangeutil.hh /// \brief Documentation for the CircleRange class -#ifndef __RANGEUTIL__ -#define __RANGEUTIL__ +#ifndef __RANGEUTIL_HH__ +#define __RANGEUTIL_HH__ #include "op.hh" +namespace ghidra { + /// \brief A class for manipulating integer value ranges. /// /// The idea is to have a representation of common sets of @@ -404,4 +406,5 @@ inline void ValueSetSolver::partitionPrepend(const Partition &head,Partition &pa part.stopNode = head.stopNode; } +} // End namespace ghidra #endif diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/raw_arch.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/raw_arch.cc index 3b83cf3ce7..9e4169cc18 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/raw_arch.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/raw_arch.cc @@ -15,6 +15,8 @@ */ #include "raw_arch.hh" +namespace ghidra { + ElementId ELEM_RAW_SAVEFILE = ElementId("raw_savefile",237); // Constructing this object registers the capability @@ -124,3 +126,5 @@ void RawBinaryArchitecture::restoreXml(DocumentStorage &store) SleighArchitecture::restoreXml(store); } } + +} // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/raw_arch.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/raw_arch.hh index 2245840a0f..8952c58171 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/raw_arch.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/raw_arch.hh @@ -15,9 +15,14 @@ */ /// \file raw_arch.hh /// \brief Bare bones capability for treating a file as a raw executable image +#ifndef __RAW_ARCH_HH__ +#define __RAW_ARCH_HH__ + #include "sleigh_arch.hh" #include "loadimage.hh" +namespace ghidra { + extern ElementId ELEM_RAW_SAVEFILE; ///< Marshaling element \ /// \brief Extension point for building an Architecture that reads in raw images @@ -46,3 +51,5 @@ public: virtual ~RawBinaryArchitecture(void) {} }; +} // End namespace ghidra +#endif diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/ruleaction.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/ruleaction.cc index 036583ad65..f11ab8dea3 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/ruleaction.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/ruleaction.cc @@ -18,6 +18,8 @@ #include "subflow.hh" #include "rangeutil.hh" +namespace ghidra { + /// \class RuleEarlyRemoval /// \brief Get rid of unused PcodeOp objects where we can guarantee the output is unused int4 RuleEarlyRemoval::applyOp(PcodeOp *op,Funcdata &data) @@ -10225,3 +10227,5 @@ int4 RuleLzcountShiftBool::applyOp(PcodeOp *op,Funcdata &data) } return 0; } + +} // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/ruleaction.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/ruleaction.hh index 18d6f7093a..483b8f023d 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/ruleaction.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/ruleaction.hh @@ -22,11 +22,13 @@ /// to produce an emergent transformation. The Rules are applied repeatedly until /// no Rule can make any additional transformations. -#ifndef __RULE_ACTION__ -#define __RULE_ACTION__ +#ifndef __RULEACTION_HH__ +#define __RULEACTION_HH__ #include "action.hh" +namespace ghidra { + /// \brief Structure for sorting out pointer expression trees /// /// Given a base pointer of known data-type and an additive expression involving @@ -1605,4 +1607,6 @@ public: virtual void getOpList(vector &oplist) const; virtual int4 applyOp(PcodeOp *op,Funcdata &data); }; + +} // End namespace ghidra #endif diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/rulecompile.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/rulecompile.cc index af4e191c79..fe8a413014 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/rulecompile.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/rulecompile.cc @@ -17,6 +17,8 @@ #include "rulecompile.hh" #include "ruleparse.hh" +namespace ghidra { + RuleCompile *rulecompile; extern int4 ruleparsedebug; extern int4 ruleparseparse(void); @@ -883,6 +885,7 @@ RuleGeneric *RuleGeneric::build(const string &nm,const string &gp,const string & return res; } +} // End namespace ghidra #endif /* diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/rulecompile.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/rulecompile.hh index 8cce8fc2fc..e3babe0ce4 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/rulecompile.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/rulecompile.hh @@ -13,11 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef __CPUI_RULE_COMPILE__ -#define __CPUI_RULE_COMPILE__ +#ifndef __RULECOMPILE_HH__ +#define __RULECOMPILE_HH__ #include "unify.hh" +namespace ghidra { + class RuleLexer { static int4 identlist[256]; // 1 is identifier, 2 is digit, 4=namechar map keywordmap; @@ -198,4 +200,5 @@ public: */ +} // End namespace ghidra #endif diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/semantics.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/semantics.cc index ecebc09704..2e3531ea27 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/semantics.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/semantics.cc @@ -16,6 +16,8 @@ #include "semantics.hh" #include "translate.hh" +namespace ghidra { + ConstTpl::ConstTpl(const_type tp) { // Constructor for relative jump constants and uniques @@ -976,3 +978,5 @@ void PcodeBuilder::build(ConstructTpl *construct,int4 secnum) } labelbase = oldbase; // Restore old labelbase } + +} // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/semantics.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/semantics.hh index 3b836244c6..8e283dca0f 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/semantics.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/semantics.hh @@ -13,11 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef __SEMANTICS__ -#define __SEMANTICS__ +#ifndef __SEMANTICS_HH__ +#define __SEMANTICS_HH__ #include "context.hh" +namespace ghidra { + // We remap these opcodes for internal use during pcode generation #define BUILD CPUI_MULTIEQUAL @@ -208,4 +210,5 @@ public: virtual void appendCrossBuild(OpTpl *bld,int4 secnum)=0; }; +} // End namespace ghidra #endif diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/sleigh.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/sleigh.cc index 0fd86e645b..06b9776c7f 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/sleigh.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/sleigh.cc @@ -16,6 +16,8 @@ #include "sleigh.hh" #include "loadimage.hh" +namespace ghidra { + PcodeCacher::PcodeCacher(void) { @@ -795,3 +797,5 @@ void Sleigh::allowContextSet(bool val) const { cache->allowSet(val); } + +} // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/sleigh.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/sleigh.hh index 74fc5cbf8d..32ef8565ef 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/sleigh.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/sleigh.hh @@ -16,11 +16,13 @@ /// \file sleigh.hh /// \brief Classes and utilities for the main SLEIGH engine -#ifndef __SLEIGH__ -#define __SLEIGH__ +#ifndef __SLEIGH_HH__ +#define __SLEIGH_HH__ #include "sleighbase.hh" +namespace ghidra { + class LoadImage; /// \brief Class for describing a relative p-code branch destination @@ -522,4 +524,6 @@ public: */ + +} // End namespace ghidra #endif diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/sleigh_arch.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/sleigh_arch.cc index aebec0e4c9..13e0a324f9 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/sleigh_arch.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/sleigh_arch.cc @@ -16,6 +16,8 @@ #include "sleigh_arch.hh" #include "inject_sleigh.hh" +namespace ghidra { + AttributeId ATTRIB_DEPRECATED = AttributeId("deprecated",136); AttributeId ATTRIB_ENDIAN = AttributeId("endian",137); AttributeId ATTRIB_PROCESSOR = AttributeId("processor",138); @@ -617,3 +619,5 @@ void SleighArchitecture::shutdown(void) translators.clear(); // description.clear(); // static vector is destroyed by the normal exit handler } + +} // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/sleigh_arch.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/sleigh_arch.hh index 203a33ee6f..695622e608 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/sleigh_arch.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/sleigh_arch.hh @@ -16,13 +16,15 @@ /// \file sleigh_arch.hh /// \brief Architecture objects that use a Translate object derived from Sleigh -#ifndef __SLEIGH_ARCH__ -#define __SLEIGH_ARCH__ +#ifndef __SLEIGH_ARCH_HH__ +#define __SLEIGH_ARCH_HH__ #include "filemanage.hh" #include "architecture.hh" #include "sleigh.hh" +namespace ghidra { + extern AttributeId ATTRIB_DEPRECATED; ///< Marshaling attribute "deprecated" extern AttributeId ATTRIB_ENDIAN; ///< Marshaling attribute "endian" extern AttributeId ATTRIB_PROCESSOR; ///< Marshaling attribute "processor" @@ -146,4 +148,5 @@ public: static FileManage specpaths; ///< Known directories that contain .ldefs files. }; +} // End namespace ghidra #endif diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/sleighbase.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/sleighbase.cc index 6b170df8e6..080de2b0b3 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/sleighbase.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/sleighbase.cc @@ -15,6 +15,8 @@ */ #include "sleighbase.hh" +namespace ghidra { + const int4 SleighBase::SLA_FORMAT_VERSION = 3; const uint4 SleighBase::MAX_UNIQUE_SIZE = 128; @@ -278,3 +280,5 @@ void SleighBase::restoreXml(const Element *el) if (!errorPairs.empty()) throw SleighError("Duplicate register pairs"); } + +} // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/sleighbase.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/sleighbase.hh index 560c5a203c..21c9f995ae 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/sleighbase.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/sleighbase.hh @@ -15,12 +15,14 @@ */ /// \file sleighbase.hh /// \brief Base class for applications that process SLEIGH format specifications -#ifndef __SLEIGHBASE__ -#define __SLEIGHBASE__ +#ifndef __SLEIGHBASE_HH__ +#define __SLEIGHBASE_HH__ #include "translate.hh" #include "slghsymbol.hh" +namespace ghidra { + /// \brief class for recording source file information for SLEIGH constructors. /// @@ -84,4 +86,5 @@ public: void saveXml(ostream &s) const; ///< Write out the SLEIGH specification as an XML \ tag. }; +} // End namespace ghidra #endif diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/slgh_compile.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/slgh_compile.cc index df6cbe4e4f..b40f74389e 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/slgh_compile.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/slgh_compile.cc @@ -17,13 +17,16 @@ #include "filemanage.hh" #include +extern FILE *sleighin; // Global pointer to file for lexer +extern int sleighlex_destroy(void); + +namespace ghidra { + SleighCompile *slgh; // Global pointer to sleigh object for use with parser #ifdef YYDEBUG -extern int yydebug; // Global debugging state for parser +extern int sleighdebug; // Global debugging state for parser #endif -extern FILE *yyin; // Global pointer to file for lexer -extern int yyparse(void); -extern int yylex_destroy(void); +extern int sleighparse(void); /// This must be constructed with the \e main section of p-code, which can contain no p-code /// \param rtl is the \e main section of p-code @@ -3579,15 +3582,15 @@ int4 SleighCompile::run_compilation(const string &filein,const string &fileout) { parseFromNewFile(filein); slgh = this; // Set global pointer up for parser - yyin = fopen(filein.c_str(),"r"); // Open the file for the lexer - if (yyin == (FILE *)0) { + sleighin = fopen(filein.c_str(),"r"); // Open the file for the lexer + if (sleighin == (FILE *)0) { cerr << "Unable to open specfile: " << filein << endl; return 2; } try { - int4 parseres = yyparse(); // Try to parse - fclose(yyin); + int4 parseres = sleighparse(); // Try to parse + fclose(sleighin); if (parseres==0) process(); // Do all the post-processing if ((parseres==0)&&(numErrors()==0)) { // If no errors @@ -3604,7 +3607,7 @@ int4 SleighCompile::run_compilation(const string &filein,const string &fileout) cerr << "No output produced" < #include +namespace ghidra { + using std::cout; using std::cerr; using std::out_of_range; @@ -450,3 +454,6 @@ public: extern SleighCompile *slgh; ///< A global reference to the SLEIGH compiler accessible to the parse functions extern int yydebug; ///< Debug state for the SLEIGH parse functions + +} // End namespace ghidra +#endif diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/slghparse.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/slghparse.cc index 6a57bcc0fd..92f3983c43 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/slghparse.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/slghparse.cc @@ -73,22 +73,32 @@ /* Pull parsers. */ #define YYPULL 1 +/* Substitute the type names. */ +#define YYSTYPE SLEIGHSTYPE +/* Substitute the variable and function names. */ +#define yyparse sleighparse +#define yylex sleighlex +#define yyerror sleigherror +#define yydebug sleighdebug +#define yynerrs sleighnerrs - +#define yylval sleighlval +#define yychar sleighchar /* Copy the first part of user declarations. */ #include "slgh_compile.hh" -#define YYERROR_VERBOSE +extern FILE *sleighin; +extern int sleighlex(void); - extern SleighCompile *slgh; - extern int4 actionon; - extern FILE *yyin; - extern int yydebug; - extern int yylex(void); - extern int yyerror(const char *str ); +namespace ghidra { + +extern SleighCompile *slgh; +extern int4 actionon; +extern int sleighdebug; +extern int sleigherror(const char *str ); @@ -110,20 +120,28 @@ /* In a future release of Bison, this section will be replaced by #include "slghparse.hh". */ -#ifndef YY_YY_SLGHPARSE_HH_INCLUDED -# define YY_YY_SLGHPARSE_HH_INCLUDED +#ifndef YY_SLEIGH_SLGHPARSE_HH_INCLUDED +# define YY_SLEIGH_SLGHPARSE_HH_INCLUDED /* Debug traces. */ -#ifndef YYDEBUG -# define YYDEBUG 0 -#endif +#ifndef SLEIGHDEBUG +# if defined YYDEBUG #if YYDEBUG -extern int yydebug; +# define SLEIGHDEBUG 1 +# else +# define SLEIGHDEBUG 0 +# endif +# else /* ! defined YYDEBUG */ +# define SLEIGHDEBUG 0 +# endif /* ! defined YYDEBUG */ +#endif /* ! defined SLEIGHDEBUG */ +#if SLEIGHDEBUG +extern int sleighdebug; #endif /* Token type. */ -#ifndef YYTOKENTYPE -# define YYTOKENTYPE - enum yytokentype +#ifndef SLEIGHTOKENTYPE +# define SLEIGHTOKENTYPE + enum sleightokentype { OP_BOOL_OR = 258, OP_BOOL_AND = 259, @@ -242,9 +260,9 @@ extern int yydebug; #endif /* Value type. */ -#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED +#if ! defined SLEIGHSTYPE && ! defined SLEIGHSTYPE_IS_DECLARED -union YYSTYPE +union SLEIGHSTYPE { @@ -294,17 +312,17 @@ union YYSTYPE }; -typedef union YYSTYPE YYSTYPE; -# define YYSTYPE_IS_TRIVIAL 1 -# define YYSTYPE_IS_DECLARED 1 +typedef union SLEIGHSTYPE SLEIGHSTYPE; +# define SLEIGHSTYPE_IS_TRIVIAL 1 +# define SLEIGHSTYPE_IS_DECLARED 1 #endif -extern YYSTYPE yylval; +extern SLEIGHSTYPE sleighlval; -int yyparse (void); +int sleighparse (void); -#endif /* !YY_YY_SLGHPARSE_HH_INCLUDED */ +#endif /* !YY_SLEIGH_SLGHPARSE_HH_INCLUDED */ /* Copy the second part of user declarations. */ @@ -489,7 +507,7 @@ void free (void *); /* INFRINGES ON USER NAME SPACE */ #if (! defined yyoverflow \ && (! defined __cplusplus \ - || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))) + || (defined SLEIGHSTYPE_IS_TRIVIAL && SLEIGHSTYPE_IS_TRIVIAL))) /* A type that is properly aligned for any stack member. */ union yyalloc @@ -613,49 +631,49 @@ static const yytype_uint8 yytranslate[] = 128 }; -#if YYDEBUG +#if SLEIGHDEBUG /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */ static const yytype_uint16 yyrline[] = { - 0, 158, 158, 159, 160, 161, 163, 164, 165, 166, - 167, 168, 169, 170, 171, 172, 174, 175, 176, 177, - 179, 180, 182, 184, 186, 187, 188, 189, 190, 192, - 194, 195, 198, 199, 200, 201, 202, 204, 205, 206, - 207, 208, 209, 211, 213, 214, 215, 216, 217, 218, - 219, 221, 223, 225, 227, 228, 230, 233, 235, 237, - 239, 241, 244, 246, 247, 248, 250, 252, 253, 254, - 257, 258, 261, 263, 264, 265, 267, 268, 270, 271, - 272, 273, 274, 275, 276, 277, 278, 280, 281, 282, - 283, 285, 287, 290, 291, 292, 293, 294, 295, 296, - 297, 298, 299, 300, 301, 302, 304, 305, 306, 307, - 309, 310, 312, 313, 315, 316, 318, 319, 320, 321, - 322, 323, 324, 327, 328, 329, 330, 332, 333, 335, - 336, 337, 338, 339, 340, 342, 343, 345, 347, 348, - 350, 351, 352, 353, 354, 356, 357, 358, 359, 361, - 362, 363, 364, 365, 366, 367, 368, 369, 370, 371, - 372, 373, 374, 375, 376, 377, 378, 379, 380, 381, - 382, 383, 384, 385, 387, 388, 389, 390, 391, 392, - 393, 394, 395, 396, 397, 398, 399, 400, 401, 402, - 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, - 413, 414, 415, 416, 417, 418, 419, 420, 421, 422, - 423, 424, 425, 426, 427, 428, 429, 430, 431, 432, - 433, 434, 435, 436, 437, 438, 439, 440, 441, 442, - 443, 444, 445, 446, 447, 448, 449, 450, 451, 452, - 453, 455, 456, 457, 458, 460, 461, 462, 463, 464, - 465, 466, 467, 468, 470, 471, 472, 473, 475, 476, - 477, 478, 479, 481, 482, 483, 485, 486, 488, 489, - 490, 491, 492, 493, 495, 496, 497, 498, 499, 501, - 502, 503, 504, 505, 506, 508, 509, 511, 512, 513, - 515, 516, 517, 519, 520, 521, 524, 525, 527, 528, - 529, 531, 533, 534, 535, 536, 538, 539, 540, 542, - 543, 544, 545, 546, 548, 549, 551, 552, 554, 555, - 558, 559, 560, 562, 563, 564, 566, 567, 568, 569, - 570, 571, 572, 573, 574, 575, 576, 577, 578, 579, - 580, 581, 582 + 0, 160, 160, 161, 162, 163, 165, 166, 167, 168, + 169, 170, 171, 172, 173, 174, 176, 177, 178, 179, + 181, 182, 184, 186, 188, 189, 190, 191, 192, 194, + 196, 197, 200, 201, 202, 203, 204, 206, 207, 208, + 209, 210, 211, 213, 215, 216, 217, 218, 219, 220, + 221, 223, 225, 227, 229, 230, 232, 235, 237, 239, + 241, 243, 246, 248, 249, 250, 252, 254, 255, 256, + 259, 260, 263, 265, 266, 267, 269, 270, 272, 273, + 274, 275, 276, 277, 278, 279, 280, 282, 283, 284, + 285, 287, 289, 292, 293, 294, 295, 296, 297, 298, + 299, 300, 301, 302, 303, 304, 306, 307, 308, 309, + 311, 312, 314, 315, 317, 318, 320, 321, 322, 323, + 324, 325, 326, 329, 330, 331, 332, 334, 335, 337, + 338, 339, 340, 341, 342, 344, 345, 347, 349, 350, + 352, 353, 354, 355, 356, 358, 359, 360, 361, 363, + 364, 365, 366, 367, 368, 369, 370, 371, 372, 373, + 374, 375, 376, 377, 378, 379, 380, 381, 382, 383, + 384, 385, 386, 387, 389, 390, 391, 392, 393, 394, + 395, 396, 397, 398, 399, 400, 401, 402, 403, 404, + 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, + 415, 416, 417, 418, 419, 420, 421, 422, 423, 424, + 425, 426, 427, 428, 429, 430, 431, 432, 433, 434, + 435, 436, 437, 438, 439, 440, 441, 442, 443, 444, + 445, 446, 447, 448, 449, 450, 451, 452, 453, 454, + 455, 457, 458, 459, 460, 462, 463, 464, 465, 466, + 467, 468, 469, 470, 472, 473, 474, 475, 477, 478, + 479, 480, 481, 483, 484, 485, 487, 488, 490, 491, + 492, 493, 494, 495, 497, 498, 499, 500, 501, 503, + 504, 505, 506, 507, 508, 510, 511, 513, 514, 515, + 517, 518, 519, 521, 522, 523, 526, 527, 529, 530, + 531, 533, 535, 536, 537, 538, 540, 541, 542, 544, + 545, 546, 547, 548, 550, 551, 553, 554, 556, 557, + 560, 561, 562, 564, 565, 566, 568, 569, 570, 571, + 572, 573, 574, 575, 576, 577, 578, 579, 580, 581, + 582, 583, 584 }; #endif -#if YYDEBUG || YYERROR_VERBOSE || 0 +#if SLEIGHDEBUG || YYERROR_VERBOSE || 0 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. First, the terminals, then, starting at YYNTOKENS, nonterminals. */ static const char *const yytname[] = @@ -1657,7 +1675,7 @@ while (0) /* Enable debugging if requested. */ -#if YYDEBUG +#if SLEIGHDEBUG # ifndef YYFPRINTF # include /* INFRINGES ON USER NAME SPACE */ @@ -1778,12 +1796,12 @@ do { \ /* Nonzero means print parse trace. It is left uninitialized so that multiple parsers can coexist. */ int yydebug; -#else /* !YYDEBUG */ +#else /* !SLEIGHDEBUG */ # define YYDPRINTF(Args) # define YY_SYMBOL_PRINT(Title, Type, Value, Location) # define YY_STACK_PRINT(Bottom, Top) # define YY_REDUCE_PRINT(Rule) -#endif /* !YYDEBUG */ +#endif /* !SLEIGHDEBUG */ /* YYINITDEPTH -- initial size of the parser's stacks. */ @@ -2349,7 +2367,7 @@ yyreduce: case 28: - { string errmsg=(yyvsp[0].anysym)->getName()+": redefined as a token"; yyerror(errmsg.c_str()); YYERROR; } + { string errmsg=(yyvsp[0].anysym)->getName()+": redefined as a token"; slgh->reportError(errmsg); YYERROR; } break; @@ -2368,7 +2386,7 @@ yyreduce: case 31: { (yyval.varsym) = (yyvsp[-1].varsym); if (!slgh->addContextField( (yyvsp[-1].varsym), (yyvsp[0].fieldqual) )) - { yyerror("All context definitions must come before constructors"); YYERROR; } } + { slgh->reportError("All context definitions must come before constructors"); YYERROR; } } break; @@ -2380,7 +2398,7 @@ yyreduce: case 33: - { delete (yyvsp[-3].i); delete (yyvsp[-1].i); string errmsg = (yyvsp[-6].anysym)->getName()+": redefined as field"; yyerror(errmsg.c_str()); YYERROR; } + { delete (yyvsp[-3].i); delete (yyvsp[-1].i); string errmsg = (yyvsp[-6].anysym)->getName()+": redefined as field"; slgh->reportError(errmsg); YYERROR; } break; @@ -2410,7 +2428,7 @@ yyreduce: case 38: - { delete (yyvsp[-3].i); delete (yyvsp[-1].i); string errmsg = (yyvsp[-6].anysym)->getName()+": redefined as field"; yyerror(errmsg.c_str()); YYERROR; } + { delete (yyvsp[-3].i); delete (yyvsp[-1].i); string errmsg = (yyvsp[-6].anysym)->getName()+": redefined as field"; slgh->reportError(errmsg); YYERROR; } break; @@ -2452,7 +2470,7 @@ yyreduce: case 45: - { string errmsg = (yyvsp[0].anysym)->getName()+": redefined as space"; yyerror(errmsg.c_str()); YYERROR; } + { string errmsg = (yyvsp[0].anysym)->getName()+": redefined as space"; slgh->reportError(errmsg); YYERROR; } break; @@ -2495,7 +2513,7 @@ yyreduce: case 52: - { yyerror("Parsed integer is too big (overflow)"); YYERROR; } + { slgh->reportError("Parsed integer is too big (overflow)"); YYERROR; } break; @@ -2634,7 +2652,7 @@ yyreduce: case 81: - { (yyval.construct) = (yyvsp[-1].construct); if (!slgh->isInRoot((yyvsp[-1].construct))) { yyerror("Unexpected '^' at start of print pieces"); YYERROR; } } + { (yyval.construct) = (yyvsp[-1].construct); if (!slgh->isInRoot((yyvsp[-1].construct))) { slgh->reportError("Unexpected '^' at start of print pieces"); YYERROR; } } break; @@ -2701,7 +2719,7 @@ yyreduce: case 92: { if ((actionon==1)&&((yyvsp[0].famsym)->getType() != SleighSymbol::context_symbol)) - { string errmsg="Global symbol "+(yyvsp[0].famsym)->getName(); errmsg += " is not allowed in action expression"; yyerror(errmsg.c_str()); } (yyval.patexp) = (yyvsp[0].famsym)->getPatternValue(); } + { string errmsg="Global symbol "+(yyvsp[0].famsym)->getName(); errmsg += " is not allowed in action expression"; slgh->reportError(errmsg); } (yyval.patexp) = (yyvsp[0].famsym)->getPatternValue(); } break; @@ -2859,7 +2877,7 @@ yyreduce: { (yyval.pateq) = slgh->constrainOperand((yyvsp[-2].operandsym),(yyvsp[0].patexp)); if ((yyval.pateq) == (PatternEquation *)0) - { string errmsg="Constraining currently undefined operand "+(yyvsp[-2].operandsym)->getName(); yyerror(errmsg.c_str()); } } + { string errmsg="Constraining currently undefined operand "+(yyvsp[-2].operandsym)->getName(); slgh->reportError(errmsg); } } break; @@ -2907,7 +2925,7 @@ yyreduce: case 130: - { (yyval.contop) = (yyvsp[-4].contop); if (!slgh->contextMod((yyvsp[-4].contop),(yyvsp[-3].contextsym),(yyvsp[-1].patexp))) { string errmsg="Cannot use 'inst_next' or 'inst_next2' to set context variable: "+(yyvsp[-3].contextsym)->getName(); yyerror(errmsg.c_str()); YYERROR; } } + { (yyval.contop) = (yyvsp[-4].contop); if (!slgh->contextMod((yyvsp[-4].contop),(yyvsp[-3].contextsym),(yyvsp[-1].patexp))) { string errmsg="Cannot use 'inst_next' or 'inst_next2' to set context variable: "+(yyvsp[-3].contextsym)->getName(); slgh->reportError(errmsg); YYERROR; } } break; @@ -2931,7 +2949,7 @@ yyreduce: case 134: - { string errmsg="Expecting context symbol, not "+*(yyvsp[0].str); delete (yyvsp[0].str); yyerror(errmsg.c_str()); YYERROR; } + { string errmsg="Expecting context symbol, not "+*(yyvsp[0].str); delete (yyvsp[0].str); slgh->reportError(errmsg); YYERROR; } break; @@ -2985,13 +3003,13 @@ yyreduce: case 143: - { string errmsg="Unknown export varnode: "+*(yyvsp[0].str); delete (yyvsp[0].str); yyerror(errmsg.c_str()); YYERROR; } + { string errmsg="Unknown export varnode: "+*(yyvsp[0].str); delete (yyvsp[0].str); slgh->reportError(errmsg); YYERROR; } break; case 144: - { string errmsg="Unknown pointer varnode: "+*(yyvsp[0].str); delete (yyvsp[-1].starqual); delete (yyvsp[0].str); yyerror(errmsg.c_str()); YYERROR; } + { string errmsg="Unknown pointer varnode: "+*(yyvsp[0].str); delete (yyvsp[-1].starqual); delete (yyvsp[0].str); slgh->reportError(errmsg); YYERROR; } break; @@ -3003,7 +3021,7 @@ yyreduce: case 146: - { (yyval.sem) = (yyvsp[-1].sem); if (!(yyval.sem)->addOpList(*(yyvsp[0].stmt))) { delete (yyvsp[0].stmt); yyerror("Multiple delayslot declarations"); YYERROR; } delete (yyvsp[0].stmt); } + { (yyval.sem) = (yyvsp[-1].sem); if (!(yyval.sem)->addOpList(*(yyvsp[0].stmt))) { delete (yyvsp[0].stmt); slgh->reportError("Multiple delayslot declarations"); YYERROR; } delete (yyvsp[0].stmt); } break; @@ -3051,7 +3069,7 @@ yyreduce: case 154: - { (yyval.stmt) = (vector *)0; string errmsg = "Redefinition of symbol: "+(yyvsp[-1].specsym)->getName(); yyerror(errmsg.c_str()); YYERROR; } + { (yyval.stmt) = (vector *)0; string errmsg = "Redefinition of symbol: "+(yyvsp[-1].specsym)->getName(); slgh->reportError(errmsg); YYERROR; } break; @@ -3081,13 +3099,13 @@ yyreduce: case 159: - { delete (yyvsp[-3].varnode); delete (yyvsp[-1].i); yyerror("Illegal truncation on left-hand side of assignment"); YYERROR; } + { delete (yyvsp[-3].varnode); delete (yyvsp[-1].i); slgh->reportError("Illegal truncation on left-hand side of assignment"); YYERROR; } break; case 160: - { delete (yyvsp[-3].varnode); delete (yyvsp[-1].i); yyerror("Illegal subpiece on left-hand side of assignment"); YYERROR; } + { delete (yyvsp[-3].varnode); delete (yyvsp[-1].i); slgh->reportError("Illegal subpiece on left-hand side of assignment"); YYERROR; } break; @@ -3147,7 +3165,7 @@ yyreduce: case 170: - { yyerror("Must specify an indirect parameter for return"); YYERROR; } + { slgh->reportError("Must specify an indirect parameter for return"); YYERROR; } break; @@ -3567,7 +3585,7 @@ yyreduce: case 240: - { if ((*(yyvsp[-1].param)).size() < 2) { string errmsg = "Must at least two inputs to cpool"; yyerror(errmsg.c_str()); YYERROR; } (yyval.tree) = slgh->pcode.createVariadic(CPUI_CPOOLREF,(yyvsp[-1].param)); } + { if ((*(yyvsp[-1].param)).size() < 2) { string errmsg = "Must at least two inputs to cpool"; slgh->reportError(errmsg); YYERROR; } (yyval.tree) = slgh->pcode.createVariadic(CPUI_CPOOLREF,(yyvsp[-1].param)); } break; @@ -3621,7 +3639,7 @@ yyreduce: case 249: - { (yyval.varnode) = new VarnodeTpl(ConstTpl(ConstTpl::j_curspace),ConstTpl(ConstTpl::real,0),ConstTpl(ConstTpl::j_curspace_size)); yyerror("Parsed integer is too big (overflow)"); } + { (yyval.varnode) = new VarnodeTpl(ConstTpl(ConstTpl::j_curspace),ConstTpl(ConstTpl::real,0),ConstTpl(ConstTpl::j_curspace_size)); slgh->reportError("Parsed integer is too big (overflow)"); } break; @@ -3645,7 +3663,7 @@ yyreduce: case 253: - { string errmsg = "Unknown jump destination: "+*(yyvsp[0].str); delete (yyvsp[0].str); yyerror(errmsg.c_str()); YYERROR; } + { string errmsg = "Unknown jump destination: "+*(yyvsp[0].str); delete (yyvsp[0].str); slgh->reportError(errmsg); YYERROR; } break; @@ -3663,13 +3681,13 @@ yyreduce: case 256: - { string errmsg = "Unknown varnode parameter: "+*(yyvsp[0].str); delete (yyvsp[0].str); yyerror(errmsg.c_str()); YYERROR; } + { string errmsg = "Unknown varnode parameter: "+*(yyvsp[0].str); delete (yyvsp[0].str); slgh->reportError(errmsg); YYERROR; } break; case 257: - { string errmsg = "Subtable not attached to operand: "+(yyvsp[0].subtablesym)->getName(); yyerror(errmsg.c_str()); YYERROR; } + { string errmsg = "Subtable not attached to operand: "+(yyvsp[0].subtablesym)->getName(); slgh->reportError(errmsg); YYERROR; } break; @@ -3681,7 +3699,7 @@ yyreduce: case 259: - { (yyval.varnode) = new VarnodeTpl(ConstTpl(slgh->getConstantSpace()),ConstTpl(ConstTpl::real,0),ConstTpl(ConstTpl::real,0)); yyerror("Parsed integer is too big (overflow)"); } + { (yyval.varnode) = new VarnodeTpl(ConstTpl(slgh->getConstantSpace()),ConstTpl(ConstTpl::real,0),ConstTpl(ConstTpl::real,0)); slgh->reportError("Parsed integer is too big (overflow)"); } break; @@ -3711,13 +3729,13 @@ yyreduce: case 264: - { string errmsg = "Unknown assignment varnode: "+*(yyvsp[0].str); delete (yyvsp[0].str); yyerror(errmsg.c_str()); YYERROR; } + { string errmsg = "Unknown assignment varnode: "+*(yyvsp[0].str); delete (yyvsp[0].str); slgh->reportError(errmsg); YYERROR; } break; case 265: - { string errmsg = "Subtable not attached to operand: "+(yyvsp[0].subtablesym)->getName(); yyerror(errmsg.c_str()); YYERROR; } + { string errmsg = "Subtable not attached to operand: "+(yyvsp[0].subtablesym)->getName(); slgh->reportError(errmsg); YYERROR; } break; @@ -3759,13 +3777,13 @@ yyreduce: case 272: - { string errmsg="Unknown export varnode: "+*(yyvsp[0].str); delete (yyvsp[0].str); yyerror(errmsg.c_str()); YYERROR; } + { string errmsg="Unknown export varnode: "+*(yyvsp[0].str); delete (yyvsp[0].str); slgh->reportError(errmsg); YYERROR; } break; case 273: - { string errmsg = "Subtable not attached to operand: "+(yyvsp[0].subtablesym)->getName(); yyerror(errmsg.c_str()); YYERROR; } + { string errmsg = "Subtable not attached to operand: "+(yyvsp[0].subtablesym)->getName(); slgh->reportError(errmsg); YYERROR; } break; @@ -3879,7 +3897,7 @@ yyreduce: case 292: - { if (*(yyvsp[0].str)!="_") { string errmsg = "Expecting integer but saw: "+*(yyvsp[0].str); delete (yyvsp[0].str); yyerror(errmsg.c_str()); YYERROR; } + { if (*(yyvsp[0].str)!="_") { string errmsg = "Expecting integer but saw: "+*(yyvsp[0].str); delete (yyvsp[0].str); slgh->reportError(errmsg); YYERROR; } (yyval.biglist) = new vector; (yyval.biglist)->push_back((intb)0xBADBEEF); delete (yyvsp[0].str); } break; @@ -3898,7 +3916,7 @@ yyreduce: case 295: - { if (*(yyvsp[0].str)!="_") { string errmsg = "Expecting integer but saw: "+*(yyvsp[0].str); delete (yyvsp[0].str); yyerror(errmsg.c_str()); YYERROR; } + { if (*(yyvsp[0].str)!="_") { string errmsg = "Expecting integer but saw: "+*(yyvsp[0].str); delete (yyvsp[0].str); slgh->reportError(errmsg); YYERROR; } (yyval.biglist) = (yyvsp[-1].biglist); (yyval.biglist)->push_back((intb)0xBADBEEF); delete (yyvsp[0].str); } break; @@ -3929,7 +3947,7 @@ yyreduce: case 300: - { string errmsg = (yyvsp[0].anysym)->getName()+": redefined"; yyerror(errmsg.c_str()); YYERROR; } + { string errmsg = (yyvsp[0].anysym)->getName()+": redefined"; slgh->reportError(errmsg); YYERROR; } break; @@ -4007,7 +4025,7 @@ yyreduce: case 313: - { string errmsg = *(yyvsp[0].str)+": is not a value pattern"; delete (yyvsp[0].str); yyerror(errmsg.c_str()); YYERROR; } + { string errmsg = *(yyvsp[0].str)+": is not a value pattern"; delete (yyvsp[0].str); slgh->reportError(errmsg); YYERROR; } break; @@ -4031,7 +4049,7 @@ yyreduce: case 317: - { if (*(yyvsp[0].str)!="_") { string errmsg = *(yyvsp[0].str)+": is not a varnode symbol"; delete (yyvsp[0].str); yyerror(errmsg.c_str()); YYERROR; } + { if (*(yyvsp[0].str)!="_") { string errmsg = *(yyvsp[0].str)+": is not a varnode symbol"; delete (yyvsp[0].str); slgh->reportError(errmsg); YYERROR; } (yyval.symlist) = new vector; (yyval.symlist)->push_back((SleighSymbol *)0); delete (yyvsp[0].str); } break; @@ -4044,7 +4062,7 @@ yyreduce: case 319: - { if (*(yyvsp[0].str)!="_") { string errmsg = *(yyvsp[0].str)+": is not a varnode symbol"; delete (yyvsp[0].str); yyerror(errmsg.c_str()); YYERROR; } + { if (*(yyvsp[0].str)!="_") { string errmsg = *(yyvsp[0].str)+": is not a varnode symbol"; delete (yyvsp[0].str); slgh->reportError(errmsg); YYERROR; } (yyval.symlist) = (yyvsp[-1].symlist); (yyval.symlist)->push_back((SleighSymbol *)0); delete (yyvsp[0].str); } break; @@ -4419,9 +4437,11 @@ yyreturn: -int yyerror(const char *s) +int sleigherror(const char *s) { slgh->reportError(s); return 0; } + +} // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/slghparse.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/slghparse.hh index e9a86da632..c3103bd490 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/slghparse.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/slghparse.hh @@ -45,20 +45,28 @@ This special exception was added by the Free Software Foundation in version 2.2 of Bison. */ -#ifndef YY_YY_SLGHPARSE_HH_INCLUDED -# define YY_YY_SLGHPARSE_HH_INCLUDED +#ifndef YY_SLEIGH_SLGHPARSE_HH_INCLUDED +# define YY_SLEIGH_SLGHPARSE_HH_INCLUDED /* Debug traces. */ -#ifndef YYDEBUG -# define YYDEBUG 0 -#endif +#ifndef SLEIGHDEBUG +# if defined YYDEBUG #if YYDEBUG -extern int yydebug; +# define SLEIGHDEBUG 1 +# else +# define SLEIGHDEBUG 0 +# endif +# else /* ! defined YYDEBUG */ +# define SLEIGHDEBUG 0 +# endif /* ! defined YYDEBUG */ +#endif /* ! defined SLEIGHDEBUG */ +#if SLEIGHDEBUG +extern int sleighdebug; #endif /* Token type. */ -#ifndef YYTOKENTYPE -# define YYTOKENTYPE - enum yytokentype +#ifndef SLEIGHTOKENTYPE +# define SLEIGHTOKENTYPE + enum sleightokentype { OP_BOOL_OR = 258, OP_BOOL_AND = 259, @@ -177,9 +185,9 @@ extern int yydebug; #endif /* Value type. */ -#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED +#if ! defined SLEIGHSTYPE && ! defined SLEIGHSTYPE_IS_DECLARED -union YYSTYPE +union SLEIGHSTYPE { @@ -229,14 +237,14 @@ union YYSTYPE }; -typedef union YYSTYPE YYSTYPE; -# define YYSTYPE_IS_TRIVIAL 1 -# define YYSTYPE_IS_DECLARED 1 +typedef union SLEIGHSTYPE SLEIGHSTYPE; +# define SLEIGHSTYPE_IS_TRIVIAL 1 +# define SLEIGHSTYPE_IS_DECLARED 1 #endif -extern YYSTYPE yylval; +extern SLEIGHSTYPE sleighlval; -int yyparse (void); +int sleighparse (void); -#endif /* !YY_YY_SLGHPARSE_HH_INCLUDED */ +#endif /* !YY_SLEIGH_SLGHPARSE_HH_INCLUDED */ diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/slghparse.y b/Ghidra/Features/Decompiler/src/decompile/cpp/slghparse.y index 51edd86129..0ee2acf826 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/slghparse.y +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/slghparse.y @@ -13,17 +13,19 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +%define api.prefix {sleigh} %{ #include "slgh_compile.hh" -#define YYERROR_VERBOSE +extern FILE *sleighin; +extern int sleighlex(void); - extern SleighCompile *slgh; - extern int4 actionon; - extern FILE *yyin; - extern int yydebug; - extern int yylex(void); - extern int yyerror(const char *str ); +namespace ghidra { + +extern SleighCompile *slgh; +extern int4 actionon; +extern int sleighdebug; +extern int sleigherror(const char *str ); %} %union { @@ -187,22 +189,22 @@ tokenprop: DEFINE_KEY TOKEN_KEY STRING '(' INTEGER ')' { $$ = slgh->defineToken( | DEFINE_KEY TOKEN_KEY STRING '(' INTEGER ')' ENDIAN_KEY '=' LITTLE_KEY { $$ = slgh->defineToken($3,$5,-1); } | DEFINE_KEY TOKEN_KEY STRING '(' INTEGER ')' ENDIAN_KEY '=' BIG_KEY { $$ = slgh->defineToken($3,$5,1); } | tokenprop fielddef { $$ = $1; slgh->addTokenField($1,$2); } - | DEFINE_KEY TOKEN_KEY anysymbol { string errmsg=$3->getName()+": redefined as a token"; yyerror(errmsg.c_str()); YYERROR; } + | DEFINE_KEY TOKEN_KEY anysymbol { string errmsg=$3->getName()+": redefined as a token"; slgh->reportError(errmsg); YYERROR; } ; contextdef: contextprop ';' {} ; contextprop: DEFINE_KEY CONTEXT_KEY VARSYM { $$ = $3; } | contextprop contextfielddef { $$ = $1; if (!slgh->addContextField( $1, $2 )) - { yyerror("All context definitions must come before constructors"); YYERROR; } } + { slgh->reportError("All context definitions must come before constructors"); YYERROR; } } ; fielddef: STRING '=' '(' INTEGER ',' INTEGER ')' { $$ = new FieldQuality($1,$4,$6); } - | anysymbol '=' '(' INTEGER ',' INTEGER ')' { delete $4; delete $6; string errmsg = $1->getName()+": redefined as field"; yyerror(errmsg.c_str()); YYERROR; } + | anysymbol '=' '(' INTEGER ',' INTEGER ')' { delete $4; delete $6; string errmsg = $1->getName()+": redefined as field"; slgh->reportError(errmsg); YYERROR; } | fielddef SIGNED_KEY { $$ = $1; $$->signext = true; } | fielddef HEX_KEY { $$ = $1; $$->hex = true; } | fielddef DEC_KEY { $$ = $1; $$->hex = false; } ; contextfielddef: STRING '=' '(' INTEGER ',' INTEGER ')' { $$ = new FieldQuality($1,$4,$6); } - | anysymbol '=' '(' INTEGER ',' INTEGER ')' { delete $4; delete $6; string errmsg = $1->getName()+": redefined as field"; yyerror(errmsg.c_str()); YYERROR; } + | anysymbol '=' '(' INTEGER ',' INTEGER ')' { delete $4; delete $6; string errmsg = $1->getName()+": redefined as field"; slgh->reportError(errmsg); YYERROR; } | contextfielddef SIGNED_KEY { $$ = $1; $$->signext = true; } | contextfielddef NOFLOW_KEY { $$ = $1; $$->flow = false; } | contextfielddef HEX_KEY { $$ = $1; $$->hex = true; } @@ -211,7 +213,7 @@ contextfielddef: STRING '=' '(' INTEGER ',' INTEGER ')' { $$ = new FieldQuality( spacedef: spaceprop ';' { slgh->newSpace($1); } ; spaceprop: DEFINE_KEY SPACE_KEY STRING { $$ = new SpaceQuality(*$3); delete $3; } - | DEFINE_KEY SPACE_KEY anysymbol { string errmsg = $3->getName()+": redefined as space"; yyerror(errmsg.c_str()); YYERROR; } + | DEFINE_KEY SPACE_KEY anysymbol { string errmsg = $3->getName()+": redefined as space"; slgh->reportError(errmsg); YYERROR; } | spaceprop TYPE_KEY '=' RAM_KEY { $$ = $1; $$->type = SpaceQuality::ramtype; } | spaceprop TYPE_KEY '=' REGISTER_KEY { $$ = $1; $$->type = SpaceQuality::registertype; } | spaceprop SIZE_KEY '=' INTEGER { $$ = $1; $$->size = *$4; delete $4; } @@ -220,7 +222,7 @@ spaceprop: DEFINE_KEY SPACE_KEY STRING { $$ = new SpaceQuality(*$3); delete $3; ; varnodedef: DEFINE_KEY SPACESYM OFFSET_KEY '=' INTEGER SIZE_KEY '=' INTEGER stringlist ';' { slgh->defineVarnodes($2,$5,$8,$9); } - | DEFINE_KEY SPACESYM OFFSET_KEY '=' BADINTEGER { yyerror("Parsed integer is too big (overflow)"); YYERROR; } + | DEFINE_KEY SPACESYM OFFSET_KEY '=' BADINTEGER { slgh->reportError("Parsed integer is too big (overflow)"); YYERROR; } ; bitrangedef: DEFINE_KEY BITRANGE_KEY bitrangelist ';' ; @@ -270,7 +272,7 @@ constructor: constructprint IS_KEY pequation contextblock rtlbody { slgh->buildC constructprint: subtablestart STRING { $$ = $1; $$->addSyntax(*$2); delete $2; } | subtablestart charstring { $$ = $1; $$->addSyntax(*$2); delete $2; } | subtablestart SYMBOLSTRING { $$ = $1; if (slgh->isInRoot($1)) { $$->addSyntax(*$2); delete $2; } else slgh->newOperand($1,$2); } - | subtablestart '^' { $$ = $1; if (!slgh->isInRoot($1)) { yyerror("Unexpected '^' at start of print pieces"); YYERROR; } } + | subtablestart '^' { $$ = $1; if (!slgh->isInRoot($1)) { slgh->reportError("Unexpected '^' at start of print pieces"); YYERROR; } } | constructprint '^' { $$ = $1; } | constructprint STRING { $$ = $1; $$->addSyntax(*$2); delete $2; } | constructprint charstring { $$ = $1; $$->addSyntax(*$2); delete $2; } @@ -285,7 +287,7 @@ subtablestart: SUBTABLESYM ':' { $$ = slgh->createConstructor($1); } pexpression: INTB { $$ = new ConstantValue(*$1); delete $1; } // familysymbol is not acceptable in an action expression because it isn't attached to an offset | familysymbol { if ((actionon==1)&&($1->getType() != SleighSymbol::context_symbol)) - { string errmsg="Global symbol "+$1->getName(); errmsg += " is not allowed in action expression"; yyerror(errmsg.c_str()); } $$ = $1->getPatternValue(); } + { string errmsg="Global symbol "+$1->getName(); errmsg += " is not allowed in action expression"; slgh->reportError(errmsg); } $$ = $1->getPatternValue(); } // | CONTEXTSYM { $$ = $1->getPatternValue(); } | specificsymbol { $$ = $1->getPatternExpression(); } | '(' pexpression ')' { $$ = $2; } @@ -323,7 +325,7 @@ constraint: familysymbol '=' pexpression { $$ = new EqualEquation($1->getPattern | familysymbol OP_GREATEQUAL pexpression { $$ = new GreaterEqualEquation($1->getPatternValue(),$3); } | OPERANDSYM '=' pexpression { $$ = slgh->constrainOperand($1,$3); if ($$ == (PatternEquation *)0) - { string errmsg="Constraining currently undefined operand "+$1->getName(); yyerror(errmsg.c_str()); } } + { string errmsg="Constraining currently undefined operand "+$1->getName(); slgh->reportError(errmsg); } } | OPERANDSYM { $$ = new OperandEquation($1->getIndex()); slgh->selfDefine($1); } | SPECSYM { $$ = new UnconstrainedEquation($1->getPatternExpression()); } | familysymbol { $$ = slgh->defineInvisibleOperand($1); } @@ -333,11 +335,11 @@ contextblock: { $$ = (vector *)0; } | '[' contextlist ']' { $$ = $2; } ; contextlist: { $$ = new vector; } - | contextlist CONTEXTSYM '=' pexpression ';' { $$ = $1; if (!slgh->contextMod($1,$2,$4)) { string errmsg="Cannot use 'inst_next' or 'inst_next2' to set context variable: "+$2->getName(); yyerror(errmsg.c_str()); YYERROR; } } + | contextlist CONTEXTSYM '=' pexpression ';' { $$ = $1; if (!slgh->contextMod($1,$2,$4)) { string errmsg="Cannot use 'inst_next' or 'inst_next2' to set context variable: "+$2->getName(); slgh->reportError(errmsg); YYERROR; } } | contextlist GLOBALSET_KEY '(' familysymbol ',' CONTEXTSYM ')' ';' { $$ = $1; slgh->contextSet($1,$4,$6); } | contextlist GLOBALSET_KEY '(' specificsymbol ',' CONTEXTSYM ')' ';' { $$ = $1; slgh->contextSet($1,$4,$6); } | contextlist OPERANDSYM '=' pexpression ';' { $$ = $1; slgh->defineOperand($2,$4); } - | contextlist STRING { string errmsg="Expecting context symbol, not "+*$2; delete $2; yyerror(errmsg.c_str()); YYERROR; } + | contextlist STRING { string errmsg="Expecting context symbol, not "+*$2; delete $2; slgh->reportError(errmsg); YYERROR; } ; section_def: OP_LEFT STRING OP_RIGHT { $$ = slgh->newSectionSymbol( *$2 ); delete $2; } | OP_LEFT SECTIONSYM OP_RIGHT { $$ = $2; } @@ -350,11 +352,11 @@ rtlcontinue: rtlfirstsection { $$ = $1; } rtl: rtlmid { $$ = $1; if ($$->getOpvec().empty() && ($$->getResult() == (HandleTpl *)0)) slgh->recordNop(); } | rtlmid EXPORT_KEY exportvarnode ';' { $$ = slgh->setResultVarnode($1,$3); } | rtlmid EXPORT_KEY sizedstar lhsvarnode ';' { $$ = slgh->setResultStarVarnode($1,$3,$4); } - | rtlmid EXPORT_KEY STRING { string errmsg="Unknown export varnode: "+*$3; delete $3; yyerror(errmsg.c_str()); YYERROR; } - | rtlmid EXPORT_KEY sizedstar STRING { string errmsg="Unknown pointer varnode: "+*$4; delete $3; delete $4; yyerror(errmsg.c_str()); YYERROR; } + | rtlmid EXPORT_KEY STRING { string errmsg="Unknown export varnode: "+*$3; delete $3; slgh->reportError(errmsg); YYERROR; } + | rtlmid EXPORT_KEY sizedstar STRING { string errmsg="Unknown pointer varnode: "+*$4; delete $3; delete $4; slgh->reportError(errmsg); YYERROR; } ; rtlmid: /* EMPTY */ { $$ = new ConstructTpl(); } - | rtlmid statement { $$ = $1; if (!$$->addOpList(*$2)) { delete $2; yyerror("Multiple delayslot declarations"); YYERROR; } delete $2; } + | rtlmid statement { $$ = $1; if (!$$->addOpList(*$2)) { delete $2; slgh->reportError("Multiple delayslot declarations"); YYERROR; } delete $2; } | rtlmid LOCAL_KEY STRING ';' { $$ = $1; slgh->pcode.newLocalDefinition($3); } | rtlmid LOCAL_KEY STRING ':' INTEGER ';' { $$ = $1; slgh->pcode.newLocalDefinition($3,*$5); delete $5; } ; @@ -363,13 +365,13 @@ statement: lhsvarnode '=' expr ';' { $3->setOutput($1); $$ = ExprTree::toVector( | STRING '=' expr ';' { $$ = slgh->pcode.newOutput(false,$3,$1); } | LOCAL_KEY STRING ':' INTEGER '=' expr ';' { $$ = slgh->pcode.newOutput(true,$6,$2,*$4); delete $4; } | STRING ':' INTEGER '=' expr ';' { $$ = slgh->pcode.newOutput(true,$5,$1,*$3); delete $3; } - | LOCAL_KEY specificsymbol '=' { $$ = (vector *)0; string errmsg = "Redefinition of symbol: "+$2->getName(); yyerror(errmsg.c_str()); YYERROR; } + | LOCAL_KEY specificsymbol '=' { $$ = (vector *)0; string errmsg = "Redefinition of symbol: "+$2->getName(); slgh->reportError(errmsg); YYERROR; } | sizedstar expr '=' expr ';' { $$ = slgh->pcode.createStore($1,$2,$4); } | USEROPSYM '(' paramlist ')' ';' { $$ = slgh->pcode.createUserOpNoOut($1,$3); } | lhsvarnode '[' INTEGER ',' INTEGER ']' '=' expr ';' { $$ = slgh->pcode.assignBitRange($1,(uint4)*$3,(uint4)*$5,$8); delete $3, delete $5; } | BITSYM '=' expr ';' { $$=slgh->pcode.assignBitRange($1->getParentSymbol()->getVarnode(),$1->getBitOffset(),$1->numBits(),$3); } - | varnode ':' INTEGER '=' { delete $1; delete $3; yyerror("Illegal truncation on left-hand side of assignment"); YYERROR; } - | varnode '(' INTEGER ')' { delete $1; delete $3; yyerror("Illegal subpiece on left-hand side of assignment"); YYERROR; } + | varnode ':' INTEGER '=' { delete $1; delete $3; slgh->reportError("Illegal truncation on left-hand side of assignment"); YYERROR; } + | varnode '(' INTEGER ')' { delete $1; delete $3; slgh->reportError("Illegal subpiece on left-hand side of assignment"); YYERROR; } | BUILD_KEY OPERANDSYM ';' { $$ = slgh->pcode.createOpConst(BUILD,$2->getIndex()); } | CROSSBUILD_KEY varnode ',' SECTIONSYM ';' { $$ = slgh->createCrossBuild($2,$4); } | CROSSBUILD_KEY varnode ',' STRING ';' { $$ = slgh->createCrossBuild($2,slgh->newSectionSymbol(*$4)); delete $4; } @@ -379,7 +381,7 @@ statement: lhsvarnode '=' expr ';' { $3->setOutput($1); $$ = ExprTree::toVector( | GOTO_KEY '[' expr ']' ';' { $$ = slgh->pcode.createOpNoOut(CPUI_BRANCHIND,$3); } | CALL_KEY jumpdest ';' { $$ = slgh->pcode.createOpNoOut(CPUI_CALL,new ExprTree($2)); } | CALL_KEY '[' expr ']' ';' { $$ = slgh->pcode.createOpNoOut(CPUI_CALLIND,$3); } - | RETURN_KEY ';' { yyerror("Must specify an indirect parameter for return"); YYERROR; } + | RETURN_KEY ';' { slgh->reportError("Must specify an indirect parameter for return"); YYERROR; } | RETURN_KEY '[' expr ']' ';' { $$ = slgh->pcode.createOpNoOut(CPUI_RETURN,$3); } | MACROSYM '(' paramlist ')' ';' { $$ = slgh->createMacroUse($1,$3); } | label { $$ = slgh->pcode.placeLabel( $1 ); } @@ -450,7 +452,7 @@ expr: varnode { $$ = new ExprTree($1); } | specificsymbol '[' INTEGER ',' INTEGER ']' { $$ = slgh->pcode.createBitRange($1,(uint4)*$3,(uint4)*$5); delete $3, delete $5; } | BITSYM { $$=slgh->pcode.createBitRange($1->getParentSymbol(),$1->getBitOffset(),$1->numBits()); } | USEROPSYM '(' paramlist ')' { $$ = slgh->pcode.createUserOp($1,$3); } - | OP_CPOOLREF '(' paramlist ')' { if ((*$3).size() < 2) { string errmsg = "Must at least two inputs to cpool"; yyerror(errmsg.c_str()); YYERROR; } $$ = slgh->pcode.createVariadic(CPUI_CPOOLREF,$3); } + | OP_CPOOLREF '(' paramlist ')' { if ((*$3).size() < 2) { string errmsg = "Must at least two inputs to cpool"; slgh->reportError(errmsg); YYERROR; } $$ = slgh->pcode.createVariadic(CPUI_CPOOLREF,$3); } ; sizedstar: '*' '[' SPACESYM ']' ':' INTEGER { $$ = new StarQuality; $$->size = *$6; delete $6; $$->id=ConstTpl($3->getSpace()); } | '*' '[' SPACESYM ']' { $$ = new StarQuality; $$->size = 0; $$->id=ConstTpl($3->getSpace()); } @@ -461,26 +463,26 @@ jumpdest: STARTSYM { VarnodeTpl *sym = $1->getVarnode(); $$ = new VarnodeTpl(Co | ENDSYM { VarnodeTpl *sym = $1->getVarnode(); $$ = new VarnodeTpl(ConstTpl(ConstTpl::j_curspace),sym->getOffset(),ConstTpl(ConstTpl::j_curspace_size)); delete sym; } | NEXT2SYM { VarnodeTpl *sym = $1->getVarnode(); $$ = new VarnodeTpl(ConstTpl(ConstTpl::j_curspace),sym->getOffset(),ConstTpl(ConstTpl::j_curspace_size)); delete sym; } | INTEGER { $$ = new VarnodeTpl(ConstTpl(ConstTpl::j_curspace),ConstTpl(ConstTpl::real,*$1),ConstTpl(ConstTpl::j_curspace_size)); delete $1; } - | BADINTEGER { $$ = new VarnodeTpl(ConstTpl(ConstTpl::j_curspace),ConstTpl(ConstTpl::real,0),ConstTpl(ConstTpl::j_curspace_size)); yyerror("Parsed integer is too big (overflow)"); } + | BADINTEGER { $$ = new VarnodeTpl(ConstTpl(ConstTpl::j_curspace),ConstTpl(ConstTpl::real,0),ConstTpl(ConstTpl::j_curspace_size)); slgh->reportError("Parsed integer is too big (overflow)"); } | OPERANDSYM { $$ = $1->getVarnode(); $1->setCodeAddress(); } | INTEGER '[' SPACESYM ']' { AddrSpace *spc = $3->getSpace(); $$ = new VarnodeTpl(ConstTpl(spc),ConstTpl(ConstTpl::real,*$1),ConstTpl(ConstTpl::real,spc->getAddrSize())); delete $1; } | label { $$ = new VarnodeTpl(ConstTpl(slgh->getConstantSpace()),ConstTpl(ConstTpl::j_relative,$1->getIndex()),ConstTpl(ConstTpl::real,sizeof(uintm))); $1->incrementRefCount(); } - | STRING { string errmsg = "Unknown jump destination: "+*$1; delete $1; yyerror(errmsg.c_str()); YYERROR; } + | STRING { string errmsg = "Unknown jump destination: "+*$1; delete $1; slgh->reportError(errmsg); YYERROR; } ; varnode: specificsymbol { $$ = $1->getVarnode(); } | integervarnode { $$ = $1; } - | STRING { string errmsg = "Unknown varnode parameter: "+*$1; delete $1; yyerror(errmsg.c_str()); YYERROR; } - | SUBTABLESYM { string errmsg = "Subtable not attached to operand: "+$1->getName(); yyerror(errmsg.c_str()); YYERROR; } + | STRING { string errmsg = "Unknown varnode parameter: "+*$1; delete $1; slgh->reportError(errmsg); YYERROR; } + | SUBTABLESYM { string errmsg = "Subtable not attached to operand: "+$1->getName(); slgh->reportError(errmsg); YYERROR; } ; integervarnode: INTEGER { $$ = new VarnodeTpl(ConstTpl(slgh->getConstantSpace()),ConstTpl(ConstTpl::real,*$1),ConstTpl(ConstTpl::real,0)); delete $1; } - | BADINTEGER { $$ = new VarnodeTpl(ConstTpl(slgh->getConstantSpace()),ConstTpl(ConstTpl::real,0),ConstTpl(ConstTpl::real,0)); yyerror("Parsed integer is too big (overflow)"); } + | BADINTEGER { $$ = new VarnodeTpl(ConstTpl(slgh->getConstantSpace()),ConstTpl(ConstTpl::real,0),ConstTpl(ConstTpl::real,0)); slgh->reportError("Parsed integer is too big (overflow)"); } | INTEGER ':' INTEGER { $$ = new VarnodeTpl(ConstTpl(slgh->getConstantSpace()),ConstTpl(ConstTpl::real,*$1),ConstTpl(ConstTpl::real,*$3)); delete $1; delete $3; } | '&' varnode { $$ = slgh->pcode.addressOf($2,0); } | '&' ':' INTEGER varnode { $$ = slgh->pcode.addressOf($4,*$3); delete $3; } ; lhsvarnode: specificsymbol { $$ = $1->getVarnode(); } - | STRING { string errmsg = "Unknown assignment varnode: "+*$1; delete $1; yyerror(errmsg.c_str()); YYERROR; } - | SUBTABLESYM { string errmsg = "Subtable not attached to operand: "+$1->getName(); yyerror(errmsg.c_str()); YYERROR; } + | STRING { string errmsg = "Unknown assignment varnode: "+*$1; delete $1; slgh->reportError(errmsg); YYERROR; } + | SUBTABLESYM { string errmsg = "Subtable not attached to operand: "+$1->getName(); slgh->reportError(errmsg); YYERROR; } ; label: '<' LABELSYM '>' { $$ = $2; } | '<' STRING '>' { $$ = slgh->pcode.defineLabel( $2 ); } @@ -489,8 +491,8 @@ exportvarnode: specificsymbol { $$ = $1->getVarnode(); } | '&' varnode { $$ = slgh->pcode.addressOf($2,0); } | '&' ':' INTEGER varnode { $$ = slgh->pcode.addressOf($4,*$3); delete $3; } | INTEGER ':' INTEGER { $$ = new VarnodeTpl(ConstTpl(slgh->getConstantSpace()),ConstTpl(ConstTpl::real,*$1),ConstTpl(ConstTpl::real,*$3)); delete $1; delete $3; } - | STRING { string errmsg="Unknown export varnode: "+*$1; delete $1; yyerror(errmsg.c_str()); YYERROR; } - | SUBTABLESYM { string errmsg = "Subtable not attached to operand: "+$1->getName(); yyerror(errmsg.c_str()); YYERROR; } + | STRING { string errmsg="Unknown export varnode: "+*$1; delete $1; slgh->reportError(errmsg); YYERROR; } + | SUBTABLESYM { string errmsg = "Subtable not attached to operand: "+$1->getName(); slgh->reportError(errmsg); YYERROR; } ; familysymbol: VALUESYM { $$ = $1; } | VALUEMAPSYM { $$ = $1; } @@ -514,11 +516,11 @@ intblist: '[' intbpart ']' { $$ = $2; } ; intbpart: INTEGER { $$ = new vector; $$->push_back(intb(*$1)); delete $1; } | '-' INTEGER { $$ = new vector; $$->push_back(-intb(*$2)); delete $2; } - | STRING { if (*$1!="_") { string errmsg = "Expecting integer but saw: "+*$1; delete $1; yyerror(errmsg.c_str()); YYERROR; } + | STRING { if (*$1!="_") { string errmsg = "Expecting integer but saw: "+*$1; delete $1; slgh->reportError(errmsg); YYERROR; } $$ = new vector; $$->push_back((intb)0xBADBEEF); delete $1; } | intbpart INTEGER { $$ = $1; $$->push_back(intb(*$2)); delete $2; } | intbpart '-' INTEGER { $$ = $1; $$->push_back(-intb(*$3)); delete $3; } - | intbpart STRING { if (*$2!="_") { string errmsg = "Expecting integer but saw: "+*$2; delete $2; yyerror(errmsg.c_str()); YYERROR; } + | intbpart STRING { if (*$2!="_") { string errmsg = "Expecting integer but saw: "+*$2; delete $2; slgh->reportError(errmsg); YYERROR; } $$ = $1; $$->push_back((intb)0xBADBEEF); delete $2; } ; stringlist: '[' stringpart ']' { $$ = $2; } @@ -526,7 +528,7 @@ stringlist: '[' stringpart ']' { $$ = $2; } ; stringpart: STRING { $$ = new vector; $$->push_back( *$1 ); delete $1; } | stringpart STRING { $$ = $1; $$->push_back(*$2); delete $2; } - | stringpart anysymbol { string errmsg = $2->getName()+": redefined"; yyerror(errmsg.c_str()); YYERROR; } + | stringpart anysymbol { string errmsg = $2->getName()+": redefined"; slgh->reportError(errmsg); YYERROR; } ; anystringlist: '[' anystringpart ']' { $$ = $2; } ; @@ -543,16 +545,16 @@ valuepart: VALUESYM { $$ = new vector; $$->push_back( $1 ); } | CONTEXTSYM { $$ = new vector; $$->push_back($1); } | valuepart VALUESYM { $$ = $1; $$->push_back($2); } | valuepart CONTEXTSYM { $$ = $1; $$->push_back($2); } - | valuepart STRING { string errmsg = *$2+": is not a value pattern"; delete $2; yyerror(errmsg.c_str()); YYERROR; } + | valuepart STRING { string errmsg = *$2+": is not a value pattern"; delete $2; slgh->reportError(errmsg); YYERROR; } ; varlist: '[' varpart ']' { $$ = $2; } | VARSYM { $$ = new vector; $$->push_back($1); } ; varpart: VARSYM { $$ = new vector; $$->push_back($1); } - | STRING { if (*$1!="_") { string errmsg = *$1+": is not a varnode symbol"; delete $1; yyerror(errmsg.c_str()); YYERROR; } + | STRING { if (*$1!="_") { string errmsg = *$1+": is not a varnode symbol"; delete $1; slgh->reportError(errmsg); YYERROR; } $$ = new vector; $$->push_back((SleighSymbol *)0); delete $1; } | varpart VARSYM { $$ = $1; $$->push_back($2); } - | varpart STRING { if (*$2!="_") { string errmsg = *$2+": is not a varnode symbol"; delete $2; yyerror(errmsg.c_str()); YYERROR; } + | varpart STRING { if (*$2!="_") { string errmsg = *$2+": is not a varnode symbol"; delete $2; slgh->reportError(errmsg); YYERROR; } $$ = $1; $$->push_back((SleighSymbol *)0); delete $2; } ; paramlist: /* EMPTY */ { $$ = new vector; } @@ -583,9 +585,11 @@ anysymbol: SPACESYM { $$ = $1; } ; %% -int yyerror(const char *s) +int sleigherror(const char *s) { slgh->reportError(s); return 0; } + +} // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/slghpatexpress.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/slghpatexpress.cc index 3b7534f091..5d6a2b9b48 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/slghpatexpress.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/slghpatexpress.cc @@ -16,6 +16,8 @@ #include "slghpatexpress.hh" #include "sleighbase.hh" +namespace ghidra { + int4 TokenPattern::resolveTokens(const TokenPattern &tok1,const TokenPattern &tok2) { // Use the token lists to decide how the two patterns @@ -1683,3 +1685,5 @@ void EquationRightEllipsis::operandOrder(Constructor *ct,vector { eq->operandOrder(ct,order); // List operands } + +} // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/slghpatexpress.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/slghpatexpress.hh index 8c748c2cee..c260fde829 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/slghpatexpress.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/slghpatexpress.hh @@ -13,11 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef __SLGHPATEXPRESS__ -#define __SLGHPATEXPRESS__ +#ifndef __SLGHPATEXPRESS_HH__ +#define __SLGHPATEXPRESS_HH__ #include "slghpattern.hh" +namespace ghidra { + class TokenPattern { Pattern *pattern; vector toklist; @@ -484,4 +486,5 @@ public: virtual void operandOrder(Constructor *ct,vector &order) const; }; +} // End namespace ghidra #endif diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/slghpattern.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/slghpattern.cc index 4ebeaa000c..755af9682c 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/slghpattern.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/slghpattern.cc @@ -15,6 +15,8 @@ */ #include "slghpattern.hh" +namespace ghidra { + uintm DisjointPattern::getMask(int4 startbit,int4 size,bool context) const { @@ -1014,3 +1016,5 @@ void OrPattern::restoreXml(const Element *el) ++iter; } } + +} // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/slghpattern.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/slghpattern.hh index 05b98e00ad..8d2f8d4376 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/slghpattern.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/slghpattern.hh @@ -13,11 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef __SLGHPATTERN__ -#define __SLGHPATTERN__ +#ifndef __SLGHPATTERN_HH__ +#define __SLGHPATTERN_HH__ #include "context.hh" +namespace ghidra { + // A mask/value pair viewed as two bitstreams class PatternBlock { int4 offset; // Offset to non-zero byte of mask @@ -168,4 +170,5 @@ public: virtual void restoreXml(const Element *el); }; +} // End namespace ghidra #endif diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/slghscan.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/slghscan.cc index 1144098b3b..9b3777e56d 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/slghscan.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/slghscan.cc @@ -13,14 +13,36 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#line 2 "slghscan.cc" - -#line 4 "slghscan.cc" #define YY_INT_ALIGNED short int /* A lexical scanner generated by flex */ +#define yy_create_buffer sleigh_create_buffer +#define yy_delete_buffer sleigh_delete_buffer +#define yy_scan_buffer sleigh_scan_buffer +#define yy_scan_string sleigh_scan_string +#define yy_scan_bytes sleigh_scan_bytes +#define yy_init_buffer sleigh_init_buffer +#define yy_flush_buffer sleigh_flush_buffer +#define yy_load_buffer_state sleigh_load_buffer_state +#define yy_switch_to_buffer sleigh_switch_to_buffer +#define yypush_buffer_state sleighpush_buffer_state +#define yypop_buffer_state sleighpop_buffer_state +#define yyensure_buffer_stack sleighensure_buffer_stack +#define yy_flex_debug sleigh_flex_debug +#define yyin sleighin +#define yyleng sleighleng +#define yylex sleighlex +#define yylineno sleighlineno +#define yyout sleighout +#define yyrestart sleighrestart +#define yytext sleightext +#define yywrap sleighwrap +#define yyalloc sleighalloc +#define yyrealloc sleighrealloc +#define yyfree sleighfree + #define FLEX_SCANNER #define YY_FLEX_MAJOR_VERSION 2 #define YY_FLEX_MINOR_VERSION 6 @@ -29,6 +51,240 @@ #define FLEX_BETA #endif +#ifdef yy_create_buffer +#define sleigh_create_buffer_ALREADY_DEFINED +#else +#define yy_create_buffer sleigh_create_buffer +#endif + +#ifdef yy_delete_buffer +#define sleigh_delete_buffer_ALREADY_DEFINED +#else +#define yy_delete_buffer sleigh_delete_buffer +#endif + +#ifdef yy_scan_buffer +#define sleigh_scan_buffer_ALREADY_DEFINED +#else +#define yy_scan_buffer sleigh_scan_buffer +#endif + +#ifdef yy_scan_string +#define sleigh_scan_string_ALREADY_DEFINED +#else +#define yy_scan_string sleigh_scan_string +#endif + +#ifdef yy_scan_bytes +#define sleigh_scan_bytes_ALREADY_DEFINED +#else +#define yy_scan_bytes sleigh_scan_bytes +#endif + +#ifdef yy_init_buffer +#define sleigh_init_buffer_ALREADY_DEFINED +#else +#define yy_init_buffer sleigh_init_buffer +#endif + +#ifdef yy_flush_buffer +#define sleigh_flush_buffer_ALREADY_DEFINED +#else +#define yy_flush_buffer sleigh_flush_buffer +#endif + +#ifdef yy_load_buffer_state +#define sleigh_load_buffer_state_ALREADY_DEFINED +#else +#define yy_load_buffer_state sleigh_load_buffer_state +#endif + +#ifdef yy_switch_to_buffer +#define sleigh_switch_to_buffer_ALREADY_DEFINED +#else +#define yy_switch_to_buffer sleigh_switch_to_buffer +#endif + +#ifdef yypush_buffer_state +#define sleighpush_buffer_state_ALREADY_DEFINED +#else +#define yypush_buffer_state sleighpush_buffer_state +#endif + +#ifdef yypop_buffer_state +#define sleighpop_buffer_state_ALREADY_DEFINED +#else +#define yypop_buffer_state sleighpop_buffer_state +#endif + +#ifdef yyensure_buffer_stack +#define sleighensure_buffer_stack_ALREADY_DEFINED +#else +#define yyensure_buffer_stack sleighensure_buffer_stack +#endif + +#ifdef yylex +#define sleighlex_ALREADY_DEFINED +#else +#define yylex sleighlex +#endif + +#ifdef yyrestart +#define sleighrestart_ALREADY_DEFINED +#else +#define yyrestart sleighrestart +#endif + +#ifdef yylex_init +#define sleighlex_init_ALREADY_DEFINED +#else +#define yylex_init sleighlex_init +#endif + +#ifdef yylex_init_extra +#define sleighlex_init_extra_ALREADY_DEFINED +#else +#define yylex_init_extra sleighlex_init_extra +#endif + +#ifdef yylex_destroy +#define sleighlex_destroy_ALREADY_DEFINED +#else +#define yylex_destroy sleighlex_destroy +#endif + +#ifdef yyget_debug +#define sleighget_debug_ALREADY_DEFINED +#else +#define yyget_debug sleighget_debug +#endif + +#ifdef yyset_debug +#define sleighset_debug_ALREADY_DEFINED +#else +#define yyset_debug sleighset_debug +#endif + +#ifdef yyget_extra +#define sleighget_extra_ALREADY_DEFINED +#else +#define yyget_extra sleighget_extra +#endif + +#ifdef yyset_extra +#define sleighset_extra_ALREADY_DEFINED +#else +#define yyset_extra sleighset_extra +#endif + +#ifdef yyget_in +#define sleighget_in_ALREADY_DEFINED +#else +#define yyget_in sleighget_in +#endif + +#ifdef yyset_in +#define sleighset_in_ALREADY_DEFINED +#else +#define yyset_in sleighset_in +#endif + +#ifdef yyget_out +#define sleighget_out_ALREADY_DEFINED +#else +#define yyget_out sleighget_out +#endif + +#ifdef yyset_out +#define sleighset_out_ALREADY_DEFINED +#else +#define yyset_out sleighset_out +#endif + +#ifdef yyget_leng +#define sleighget_leng_ALREADY_DEFINED +#else +#define yyget_leng sleighget_leng +#endif + +#ifdef yyget_text +#define sleighget_text_ALREADY_DEFINED +#else +#define yyget_text sleighget_text +#endif + +#ifdef yyget_lineno +#define sleighget_lineno_ALREADY_DEFINED +#else +#define yyget_lineno sleighget_lineno +#endif + +#ifdef yyset_lineno +#define sleighset_lineno_ALREADY_DEFINED +#else +#define yyset_lineno sleighset_lineno +#endif + +#ifdef yywrap +#define sleighwrap_ALREADY_DEFINED +#else +#define yywrap sleighwrap +#endif + +#ifdef yyalloc +#define sleighalloc_ALREADY_DEFINED +#else +#define yyalloc sleighalloc +#endif + +#ifdef yyrealloc +#define sleighrealloc_ALREADY_DEFINED +#else +#define yyrealloc sleighrealloc +#endif + +#ifdef yyfree +#define sleighfree_ALREADY_DEFINED +#else +#define yyfree sleighfree +#endif + +#ifdef yytext +#define sleightext_ALREADY_DEFINED +#else +#define yytext sleightext +#endif + +#ifdef yyleng +#define sleighleng_ALREADY_DEFINED +#else +#define yyleng sleighleng +#endif + +#ifdef yyin +#define sleighin_ALREADY_DEFINED +#else +#define yyin sleighin +#endif + +#ifdef yyout +#define sleighout_ALREADY_DEFINED +#else +#define yyout sleighout +#endif + +#ifdef yy_flex_debug +#define sleigh_flex_debug_ALREADY_DEFINED +#else +#define yy_flex_debug sleigh_flex_debug +#endif + +#ifdef yylineno +#define sleighlineno_ALREADY_DEFINED +#else +#define yylineno sleighlineno +#endif + /* First, we deal with platform-specific or compiler-specific issues. */ /* begin standard C headers. */ @@ -879,9 +1135,7 @@ char *yytext; * See the License for the specific language governing permissions and * limitations under the License. */ -#include "slgh_compile.hh" -#include "slghparse.hh" -#define yywrap() 1 +#define sleighwrap() 1 #define YY_SKIP_YYWRAP /* If we are building don't include unistd.h */ @@ -891,6 +1145,12 @@ char *yytext; static int isatty (int fildes) { return 0; } #endif +#include "slgh_compile.hh" + +namespace ghidra { + +#include "slghparse.hh" + struct FileStreamState { YY_BUFFER_STATE lastbuffer; // Last lex buffer corresponding to the stream FILE *file; // The NEW file stream @@ -1091,7 +1351,7 @@ void expand_preprocmacros(string &str) int4 preprocess(int4 cur_state,int4 blank_state) { - string str(yytext); + string str(sleightext); string::size_type pos = str.find('#'); if (pos != string::npos) str.erase(pos); @@ -1114,11 +1374,11 @@ int4 preprocess(int4 cur_state,int4 blank_state) expand_preprocmacros(fname); slgh->parseFromNewFile(fname); fname = slgh->grabCurrentFilePath(); - yyin = fopen(fname.c_str(),"r"); - if (yyin == (FILE *)0) + sleighin = fopen(fname.c_str(),"r"); + if (sleighin == (FILE *)0) preproc_error("Could not open included file "+fname); - filebuffers.back().file = yyin; - yy_switch_to_buffer( yy_create_buffer(yyin, YY_BUF_SIZE) ); + filebuffers.back().file = sleighin; + sleigh_switch_to_buffer( sleigh_create_buffer(sleighin, YY_BUF_SIZE) ); check_to_endofline(s); } } @@ -1235,81 +1495,81 @@ void preproc_macroexpand(void) filebuffers.push_back(FileStreamState()); filebuffers.back().lastbuffer = YY_CURRENT_BUFFER; filebuffers.back().file = (FILE *)0; - string macro(yytext); + string macro(sleightext); macro.erase(0,2); macro.erase(macro.size()-1,1); string value; if (!slgh->getPreprocValue(macro,value)) preproc_error("Unknown preprocessing macro "+macro); - yy_switch_to_buffer( yy_scan_string( value.c_str() ) ); + sleigh_switch_to_buffer( sleigh_scan_string( value.c_str() ) ); slgh->parsePreprocMacro(); } int4 find_symbol(void) { - string * newstring = new string(yytext); + string * newstring = new string(sleightext); SleighSymbol *sym = slgh->findSymbol(*newstring); if (sym == (SleighSymbol *)0) { - yylval.str = newstring; + sleighlval.str = newstring; return STRING; } delete newstring; switch(sym->getType()) { case SleighSymbol::section_symbol: - yylval.sectionsym = (SectionSymbol *)sym; + sleighlval.sectionsym = (SectionSymbol *)sym; return SECTIONSYM; case SleighSymbol::space_symbol: - yylval.spacesym = (SpaceSymbol *)sym; + sleighlval.spacesym = (SpaceSymbol *)sym; return SPACESYM; case SleighSymbol::token_symbol: - yylval.tokensym = (TokenSymbol *)sym; + sleighlval.tokensym = (TokenSymbol *)sym; return TOKENSYM; case SleighSymbol::userop_symbol: - yylval.useropsym = (UserOpSymbol *)sym; + sleighlval.useropsym = (UserOpSymbol *)sym; return USEROPSYM; case SleighSymbol::value_symbol: - yylval.valuesym = (ValueSymbol *)sym; + sleighlval.valuesym = (ValueSymbol *)sym; return VALUESYM; case SleighSymbol::valuemap_symbol: - yylval.valuemapsym = (ValueMapSymbol *)sym; + sleighlval.valuemapsym = (ValueMapSymbol *)sym; return VALUEMAPSYM; case SleighSymbol::name_symbol: - yylval.namesym = (NameSymbol *)sym; + sleighlval.namesym = (NameSymbol *)sym; return NAMESYM; case SleighSymbol::varnode_symbol: - yylval.varsym = (VarnodeSymbol *)sym; + sleighlval.varsym = (VarnodeSymbol *)sym; return VARSYM; case SleighSymbol::bitrange_symbol: - yylval.bitsym = (BitrangeSymbol *)sym; + sleighlval.bitsym = (BitrangeSymbol *)sym; return BITSYM; case SleighSymbol::varnodelist_symbol: - yylval.varlistsym = (VarnodeListSymbol *)sym; + sleighlval.varlistsym = (VarnodeListSymbol *)sym; return VARLISTSYM; case SleighSymbol::operand_symbol: - yylval.operandsym = (OperandSymbol *)sym; + sleighlval.operandsym = (OperandSymbol *)sym; return OPERANDSYM; case SleighSymbol::start_symbol: - yylval.startsym = (StartSymbol *)sym; + sleighlval.startsym = (StartSymbol *)sym; return STARTSYM; case SleighSymbol::end_symbol: - yylval.endsym = (EndSymbol *)sym; + sleighlval.endsym = (EndSymbol *)sym; return ENDSYM; case SleighSymbol::next2_symbol: - yylval.next2sym = (Next2Symbol *)sym; + sleighlval.next2sym = (Next2Symbol *)sym; return NEXT2SYM; case SleighSymbol::subtable_symbol: - yylval.subtablesym = (SubtableSymbol *)sym; + sleighlval.subtablesym = (SubtableSymbol *)sym; return SUBTABLESYM; case SleighSymbol::macro_symbol: - yylval.macrosym = (MacroSymbol *)sym; + sleighlval.macrosym = (MacroSymbol *)sym; return MACROSYM; case SleighSymbol::label_symbol: - yylval.labelsym = (LabelSymbol *)sym; + sleighlval.labelsym = (LabelSymbol *)sym; return LABELSYM; case SleighSymbol::epsilon_symbol: - yylval.specsym = (SpecificSymbol *)sym; + sleighlval.specsym = (SpecificSymbol *)sym; return SPECSYM; case SleighSymbol::context_symbol: - yylval.contextsym = (ContextSymbol *)sym; + sleighlval.contextsym = (ContextSymbol *)sym; return CONTEXTSYM; case SleighSymbol::dummy_symbol: break; @@ -1317,7 +1577,7 @@ int4 find_symbol(void) { return -1; // Should never reach here } -int4 scan_number(char *numtext,YYSTYPE *lval,bool signednum) +int4 scan_number(char *numtext,SLEIGHSTYPE *lval,bool signednum) { uintb val; @@ -1346,6 +1606,10 @@ int4 scan_number(char *numtext,YYSTYPE *lval,bool signednum) return INTEGER; } +} // End namespace ghidra + +using namespace ghidra; + #define INITIAL 0 #define defblock 1 #define macroblock 2 @@ -1638,15 +1902,15 @@ YY_RULE_SETUP YY_BREAK case 3: YY_RULE_SETUP -{ yylval.ch = yytext[0]; return yytext[0]; } +{ sleighlval.ch = sleightext[0]; return sleightext[0]; } YY_BREAK case 4: YY_RULE_SETUP -{ BEGIN(print); slgh->calcContextLayout(); yylval.ch = yytext[0]; return yytext[0]; } +{ BEGIN(print); slgh->calcContextLayout(); sleighlval.ch = sleightext[0]; return sleightext[0]; } YY_BREAK case 5: YY_RULE_SETUP -{ BEGIN(sem); yylval.ch = yytext[0]; return yytext[0]; } +{ BEGIN(sem); sleighlval.ch = sleightext[0]; return sleightext[0]; } YY_BREAK case 6: YY_RULE_SETUP @@ -1683,7 +1947,7 @@ YY_RULE_SETUP YY_BREAK case 14: YY_RULE_SETUP -{ return yytext[0]; } +{ return sleightext[0]; } YY_BREAK case 15: /* rule 15 can match eol */ @@ -1696,15 +1960,15 @@ YY_RULE_SETUP YY_BREAK case 17: YY_RULE_SETUP -{ yylval.ch = yytext[0]; return yytext[0]; } +{ sleighlval.ch = sleightext[0]; return sleightext[0]; } YY_BREAK case 18: YY_RULE_SETUP -{ BEGIN(sem); return yytext[0]; } +{ BEGIN(sem); return sleightext[0]; } YY_BREAK case 19: YY_RULE_SETUP -{ yylval.str = new string(yytext); return STRING; } +{ sleighlval.str = new string(sleightext); return STRING; } YY_BREAK case 20: YY_RULE_SETUP @@ -1717,7 +1981,7 @@ YY_RULE_SETUP YY_BREAK case 22: YY_RULE_SETUP -{ return yytext[0]; } +{ return sleightext[0]; } YY_BREAK case 23: /* rule 23 can match eol */ @@ -1730,11 +1994,11 @@ YY_RULE_SETUP YY_BREAK case 25: YY_RULE_SETUP -{ yylval.ch = yytext[0]; return yytext[0]; } +{ sleighlval.ch = sleightext[0]; return sleightext[0]; } YY_BREAK case 26: YY_RULE_SETUP -{ BEGIN(INITIAL); yylval.ch = yytext[0]; return yytext[0]; } +{ BEGIN(INITIAL); sleighlval.ch = sleightext[0]; return sleightext[0]; } YY_BREAK case 27: YY_RULE_SETUP @@ -1838,19 +2102,19 @@ YY_RULE_SETUP YY_BREAK case 52: YY_RULE_SETUP -{ return scan_number(yytext,&yylval,false); } +{ return scan_number(sleightext,&sleighlval,false); } YY_BREAK case 53: YY_RULE_SETUP -{ return scan_number(yytext,&yylval,false); } +{ return scan_number(sleightext,&sleighlval,false); } YY_BREAK case 54: YY_RULE_SETUP -{ return scan_number(yytext,&yylval,false); } +{ return scan_number(sleightext,&sleighlval,false); } YY_BREAK case 55: YY_RULE_SETUP -{ yylval.str = new string(yytext+1,strlen(yytext)-2); return STRING; } +{ sleighlval.str = new string(sleightext+1,strlen(sleightext)-2); return STRING; } YY_BREAK case 56: YY_RULE_SETUP @@ -1863,7 +2127,7 @@ YY_RULE_SETUP YY_BREAK case 58: YY_RULE_SETUP -{ return yytext[0]; } +{ return sleightext[0]; } YY_BREAK case 59: /* rule 59 can match eol */ @@ -1876,11 +2140,11 @@ YY_RULE_SETUP YY_BREAK case 61: YY_RULE_SETUP -{ yylval.ch = yytext[0]; return CHAR; } +{ sleighlval.ch = sleightext[0]; return CHAR; } YY_BREAK case 62: YY_RULE_SETUP -{ yylval.ch = '^'; return '^'; } +{ sleighlval.ch = '^'; return '^'; } YY_BREAK case 63: YY_RULE_SETUP @@ -1888,15 +2152,15 @@ YY_RULE_SETUP YY_BREAK case 64: YY_RULE_SETUP -{ yylval.str = new string(yytext); return SYMBOLSTRING; } +{ sleighlval.str = new string(sleightext); return SYMBOLSTRING; } YY_BREAK case 65: YY_RULE_SETUP -{ yylval.str = new string(yytext+1,strlen(yytext)-2); return STRING; } +{ sleighlval.str = new string(sleightext+1,strlen(sleightext)-2); return STRING; } YY_BREAK case 66: YY_RULE_SETUP -{ yylval.ch = ' '; return ' '; } +{ sleighlval.ch = ' '; return ' '; } YY_BREAK case 67: /* rule 67 can match eol */ @@ -1905,7 +2169,7 @@ YY_RULE_SETUP YY_BREAK case 68: YY_RULE_SETUP -{ return yytext[0]; } +{ return sleightext[0]; } YY_BREAK case 69: /* rule 69 can match eol */ @@ -1918,7 +2182,7 @@ YY_RULE_SETUP YY_BREAK case 71: YY_RULE_SETUP -{ BEGIN((withsection==1) ? INITIAL:sem); withsection=0; yylval.ch = yytext[0]; return yytext[0]; } +{ BEGIN((withsection==1) ? INITIAL:sem); withsection=0; sleighlval.ch = sleightext[0]; return sleightext[0]; } YY_BREAK case 72: YY_RULE_SETUP @@ -1966,19 +2230,19 @@ YY_RULE_SETUP YY_BREAK case 83: YY_RULE_SETUP -{ actionon = 1; yylval.ch = yytext[0]; return yytext[0]; } +{ actionon = 1; sleighlval.ch = sleightext[0]; return sleightext[0]; } YY_BREAK case 84: YY_RULE_SETUP -{ actionon = 0; yylval.ch = yytext[0]; return yytext[0]; } +{ actionon = 0; sleighlval.ch = sleightext[0]; return sleightext[0]; } YY_BREAK case 85: YY_RULE_SETUP -{ yylval.ch = yytext[0]; return (actionon==0) ? yytext[0] : OP_AND; } +{ sleighlval.ch = sleightext[0]; return (actionon==0) ? sleightext[0] : OP_AND; } YY_BREAK case 86: YY_RULE_SETUP -{ yylval.ch = yytext[0]; return (actionon==0) ? yytext[0] : OP_OR; } +{ sleighlval.ch = sleightext[0]; return (actionon==0) ? sleightext[0] : OP_OR; } YY_BREAK case 87: YY_RULE_SETUP @@ -1986,7 +2250,7 @@ YY_RULE_SETUP YY_BREAK case 88: YY_RULE_SETUP -{ yylval.ch = yytext[0]; return yytext[0]; } +{ sleighlval.ch = sleightext[0]; return sleightext[0]; } YY_BREAK case 89: YY_RULE_SETUP @@ -1998,15 +2262,15 @@ YY_RULE_SETUP YY_BREAK case 91: YY_RULE_SETUP -{ return scan_number(yytext,&yylval,true); } +{ return scan_number(sleightext,&sleighlval,true); } YY_BREAK case 92: YY_RULE_SETUP -{ return scan_number(yytext,&yylval,true); } +{ return scan_number(sleightext,&sleighlval,true); } YY_BREAK case 93: YY_RULE_SETUP -{ return scan_number(yytext,&yylval,true); } +{ return scan_number(sleightext,&sleighlval,true); } YY_BREAK case 94: YY_RULE_SETUP @@ -2019,7 +2283,7 @@ YY_RULE_SETUP YY_BREAK case 96: YY_RULE_SETUP -{ return yytext[0]; } +{ return sleightext[0]; } YY_BREAK case 97: /* rule 97 can match eol */ @@ -2032,7 +2296,7 @@ YY_RULE_SETUP YY_BREAK case 99: YY_RULE_SETUP -{ BEGIN(INITIAL); yylval.ch = yytext[0]; return yytext[0]; } +{ BEGIN(INITIAL); sleighlval.ch = sleightext[0]; return sleightext[0]; } YY_BREAK case 100: YY_RULE_SETUP @@ -2252,7 +2516,7 @@ YY_RULE_SETUP YY_BREAK case 154: YY_RULE_SETUP -{ yylval.ch = yytext[0]; return yytext[0]; } +{ sleighlval.ch = sleightext[0]; return sleightext[0]; } YY_BREAK case 155: YY_RULE_SETUP @@ -2264,15 +2528,15 @@ YY_RULE_SETUP YY_BREAK case 157: YY_RULE_SETUP -{ return scan_number(yytext,&yylval,false); } +{ return scan_number(sleightext,&sleighlval,false); } YY_BREAK case 158: YY_RULE_SETUP -{ return scan_number(yytext,&yylval,false); } +{ return scan_number(sleightext,&sleighlval,false); } YY_BREAK case 159: YY_RULE_SETUP -{ return scan_number(yytext,&yylval,false); } +{ return scan_number(sleightext,&sleighlval,false); } YY_BREAK case 160: YY_RULE_SETUP @@ -2285,7 +2549,7 @@ YY_RULE_SETUP YY_BREAK case 162: YY_RULE_SETUP -{ return yytext[0]; } +{ return sleightext[0]; } YY_BREAK case 163: /* rule 163 can match eol */ @@ -2304,10 +2568,10 @@ case YY_STATE_EOF(print): case YY_STATE_EOF(pattern): case YY_STATE_EOF(sem): case YY_STATE_EOF(preproc): -{ yy_delete_buffer( YY_CURRENT_BUFFER ); +{ sleigh_delete_buffer( YY_CURRENT_BUFFER ); if (filebuffers.empty()) yyterminate(); - yy_switch_to_buffer( filebuffers.back().lastbuffer ); + sleigh_switch_to_buffer( filebuffers.back().lastbuffer ); FILE *curfile = filebuffers.back().file; if (curfile != (FILE *)0) fclose(curfile); diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/slghscan.l b/Ghidra/Features/Decompiler/src/decompile/cpp/slghscan.l index 58e0a1dca3..32c7660970 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/slghscan.l +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/slghscan.l @@ -14,10 +14,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +%option prefix="sleigh" %{ -#include "slgh_compile.hh" -#include "slghparse.hh" -#define yywrap() 1 +#define sleighwrap() 1 #define YY_SKIP_YYWRAP /* If we are building don't include unistd.h */ @@ -27,6 +26,12 @@ static int isatty (int fildes) { return 0; } #endif +#include "slgh_compile.hh" + +namespace ghidra { + +#include "slghparse.hh" + struct FileStreamState { YY_BUFFER_STATE lastbuffer; // Last lex buffer corresponding to the stream FILE *file; // The NEW file stream @@ -227,7 +232,7 @@ void expand_preprocmacros(string &str) int4 preprocess(int4 cur_state,int4 blank_state) { - string str(yytext); + string str(sleightext); string::size_type pos = str.find('#'); if (pos != string::npos) str.erase(pos); @@ -250,11 +255,11 @@ int4 preprocess(int4 cur_state,int4 blank_state) expand_preprocmacros(fname); slgh->parseFromNewFile(fname); fname = slgh->grabCurrentFilePath(); - yyin = fopen(fname.c_str(),"r"); - if (yyin == (FILE *)0) + sleighin = fopen(fname.c_str(),"r"); + if (sleighin == (FILE *)0) preproc_error("Could not open included file "+fname); - filebuffers.back().file = yyin; - yy_switch_to_buffer( yy_create_buffer(yyin, YY_BUF_SIZE) ); + filebuffers.back().file = sleighin; + sleigh_switch_to_buffer( sleigh_create_buffer(sleighin, YY_BUF_SIZE) ); check_to_endofline(s); } } @@ -371,81 +376,81 @@ void preproc_macroexpand(void) filebuffers.push_back(FileStreamState()); filebuffers.back().lastbuffer = YY_CURRENT_BUFFER; filebuffers.back().file = (FILE *)0; - string macro(yytext); + string macro(sleightext); macro.erase(0,2); macro.erase(macro.size()-1,1); string value; if (!slgh->getPreprocValue(macro,value)) preproc_error("Unknown preprocessing macro "+macro); - yy_switch_to_buffer( yy_scan_string( value.c_str() ) ); + sleigh_switch_to_buffer( sleigh_scan_string( value.c_str() ) ); slgh->parsePreprocMacro(); } int4 find_symbol(void) { - string * newstring = new string(yytext); + string * newstring = new string(sleightext); SleighSymbol *sym = slgh->findSymbol(*newstring); if (sym == (SleighSymbol *)0) { - yylval.str = newstring; + sleighlval.str = newstring; return STRING; } delete newstring; switch(sym->getType()) { case SleighSymbol::section_symbol: - yylval.sectionsym = (SectionSymbol *)sym; + sleighlval.sectionsym = (SectionSymbol *)sym; return SECTIONSYM; case SleighSymbol::space_symbol: - yylval.spacesym = (SpaceSymbol *)sym; + sleighlval.spacesym = (SpaceSymbol *)sym; return SPACESYM; case SleighSymbol::token_symbol: - yylval.tokensym = (TokenSymbol *)sym; + sleighlval.tokensym = (TokenSymbol *)sym; return TOKENSYM; case SleighSymbol::userop_symbol: - yylval.useropsym = (UserOpSymbol *)sym; + sleighlval.useropsym = (UserOpSymbol *)sym; return USEROPSYM; case SleighSymbol::value_symbol: - yylval.valuesym = (ValueSymbol *)sym; + sleighlval.valuesym = (ValueSymbol *)sym; return VALUESYM; case SleighSymbol::valuemap_symbol: - yylval.valuemapsym = (ValueMapSymbol *)sym; + sleighlval.valuemapsym = (ValueMapSymbol *)sym; return VALUEMAPSYM; case SleighSymbol::name_symbol: - yylval.namesym = (NameSymbol *)sym; + sleighlval.namesym = (NameSymbol *)sym; return NAMESYM; case SleighSymbol::varnode_symbol: - yylval.varsym = (VarnodeSymbol *)sym; + sleighlval.varsym = (VarnodeSymbol *)sym; return VARSYM; case SleighSymbol::bitrange_symbol: - yylval.bitsym = (BitrangeSymbol *)sym; + sleighlval.bitsym = (BitrangeSymbol *)sym; return BITSYM; case SleighSymbol::varnodelist_symbol: - yylval.varlistsym = (VarnodeListSymbol *)sym; + sleighlval.varlistsym = (VarnodeListSymbol *)sym; return VARLISTSYM; case SleighSymbol::operand_symbol: - yylval.operandsym = (OperandSymbol *)sym; + sleighlval.operandsym = (OperandSymbol *)sym; return OPERANDSYM; case SleighSymbol::start_symbol: - yylval.startsym = (StartSymbol *)sym; + sleighlval.startsym = (StartSymbol *)sym; return STARTSYM; case SleighSymbol::end_symbol: - yylval.endsym = (EndSymbol *)sym; + sleighlval.endsym = (EndSymbol *)sym; return ENDSYM; case SleighSymbol::next2_symbol: - yylval.next2sym = (Next2Symbol *)sym; + sleighlval.next2sym = (Next2Symbol *)sym; return NEXT2SYM; case SleighSymbol::subtable_symbol: - yylval.subtablesym = (SubtableSymbol *)sym; + sleighlval.subtablesym = (SubtableSymbol *)sym; return SUBTABLESYM; case SleighSymbol::macro_symbol: - yylval.macrosym = (MacroSymbol *)sym; + sleighlval.macrosym = (MacroSymbol *)sym; return MACROSYM; case SleighSymbol::label_symbol: - yylval.labelsym = (LabelSymbol *)sym; + sleighlval.labelsym = (LabelSymbol *)sym; return LABELSYM; case SleighSymbol::epsilon_symbol: - yylval.specsym = (SpecificSymbol *)sym; + sleighlval.specsym = (SpecificSymbol *)sym; return SPECSYM; case SleighSymbol::context_symbol: - yylval.contextsym = (ContextSymbol *)sym; + sleighlval.contextsym = (ContextSymbol *)sym; return CONTEXTSYM; case SleighSymbol::dummy_symbol: break; @@ -453,7 +458,7 @@ int4 find_symbol(void) { return -1; // Should never reach here } -int4 scan_number(char *numtext,YYSTYPE *lval,bool signednum) +int4 scan_number(char *numtext,SLEIGHSTYPE *lval,bool signednum) { uintb val; @@ -482,6 +487,10 @@ int4 scan_number(char *numtext,YYSTYPE *lval,bool signednum) return INTEGER; } +} // End namespace ghidra + +using namespace ghidra; + %} %x defblock @@ -494,9 +503,9 @@ int4 scan_number(char *numtext,YYSTYPE *lval,bool signednum) ^@[^\n]*\n? { slgh->nextLine(); BEGIN( preprocess(INITIAL,preproc) ); } \$\([a-zA-Z0-9_.][a-zA-Z0-9_.]*\) { preproc_macroexpand(); } -[(),\-] { yylval.ch = yytext[0]; return yytext[0]; } -\: { BEGIN(print); slgh->calcContextLayout(); yylval.ch = yytext[0]; return yytext[0]; } -\{ { BEGIN(sem); yylval.ch = yytext[0]; return yytext[0]; } +[(),\-] { sleighlval.ch = sleightext[0]; return sleightext[0]; } +\: { BEGIN(print); slgh->calcContextLayout(); sleighlval.ch = sleightext[0]; return sleightext[0]; } +\{ { BEGIN(sem); sleighlval.ch = sleightext[0]; return sleightext[0]; } #.* [\r\ \t\v]+ \n { slgh->nextLine(); } @@ -505,21 +514,21 @@ define { BEGIN(defblock); return DEFINE_KEY; } attach { BEGIN(defblock); slgh->calcContextLayout(); return ATTACH_KEY; } with { BEGIN(pattern); withsection = 1; slgh->calcContextLayout(); return WITH_KEY; } [a-zA-Z_.][a-zA-Z0-9_.]* { return find_symbol(); } -. { return yytext[0]; } +. { return sleightext[0]; } ^@[^\n]*\n? { slgh->nextLine(); BEGIN( preprocess(macroblock,preproc) ); } \$\([a-zA-Z0-9_.][a-zA-Z0-9_.]*\) { preproc_macroexpand(); } -[(),] { yylval.ch = yytext[0]; return yytext[0]; } -\{ { BEGIN(sem); return yytext[0]; } -[a-zA-Z_.][a-zA-Z0-9_.]* { yylval.str = new string(yytext); return STRING; } +[(),] { sleighlval.ch = sleightext[0]; return sleightext[0]; } +\{ { BEGIN(sem); return sleightext[0]; } +[a-zA-Z_.][a-zA-Z0-9_.]* { sleighlval.str = new string(sleightext); return STRING; } [\r\ \t\v]+ \n { slgh->nextLine(); } -. { return yytext[0]; } +. { return sleightext[0]; } ^@[^\n]*\n? { slgh->nextLine(); BEGIN( preprocess(defblock,preproc) ); } \$\([a-zA-Z0-9_.][a-zA-Z0-9_.]*\) { preproc_macroexpand(); } -[(),=:\[\]] { yylval.ch = yytext[0]; return yytext[0]; } -\; { BEGIN(INITIAL); yylval.ch = yytext[0]; return yytext[0]; } +[(),=:\[\]] { sleighlval.ch = sleightext[0]; return sleightext[0]; } +\; { BEGIN(INITIAL); sleighlval.ch = sleightext[0]; return sleightext[0]; } space { return SPACE_KEY; } type { return TYPE_KEY; } ram_space { return RAM_KEY; } @@ -545,29 +554,29 @@ with { BEGIN(pattern); withsection = 1; slgh->calcContextLayout(); return WITH pcodeop { return PCODEOP_KEY; } #.* [a-zA-Z_.][a-zA-Z0-9_.]* { return find_symbol(); } -[0-9]|[1-9][0-9]+ { return scan_number(yytext,&yylval,false); } -0x[0-9a-fA-F]+ { return scan_number(yytext,&yylval,false); } -0b[01]+ { return scan_number(yytext,&yylval,false); } -\"([^\"[:cntrl:]]|\"\")*\" { yylval.str = new string(yytext+1,strlen(yytext)-2); return STRING; } +[0-9]|[1-9][0-9]+ { return scan_number(sleightext,&sleighlval,false); } +0x[0-9a-fA-F]+ { return scan_number(sleightext,&sleighlval,false); } +0b[01]+ { return scan_number(sleightext,&sleighlval,false); } +\"([^\"[:cntrl:]]|\"\")*\" { sleighlval.str = new string(sleightext+1,strlen(sleightext)-2); return STRING; } [\r\ \t\v]+ \n { slgh->nextLine(); } -. { return yytext[0]; } +. { return sleightext[0]; } ^@[^\n]*\n? { slgh->nextLine(); BEGIN( preprocess(print,preproc) ); } \$\([a-zA-Z0-9_.][a-zA-Z0-9_.]*\) { preproc_macroexpand(); } -[~!@#$%&*()\-=+\[\]{}|;:<>?,/0-9] { yylval.ch = yytext[0]; return CHAR; } -\^ { yylval.ch = '^'; return '^'; } +[~!@#$%&*()\-=+\[\]{}|;:<>?,/0-9] { sleighlval.ch = sleightext[0]; return CHAR; } +\^ { sleighlval.ch = '^'; return '^'; } is { BEGIN(pattern); actionon=0; return IS_KEY; } -[a-zA-Z_.][a-zA-Z0-9_.]* { yylval.str = new string(yytext); return SYMBOLSTRING; } -\"([^\"[:cntrl:]]|\"\")*\" { yylval.str = new string(yytext+1,strlen(yytext)-2); return STRING; } -[\r\ \t\v]+ { yylval.ch = ' '; return ' '; } +[a-zA-Z_.][a-zA-Z0-9_.]* { sleighlval.str = new string(sleightext); return SYMBOLSTRING; } +\"([^\"[:cntrl:]]|\"\")*\" { sleighlval.str = new string(sleightext+1,strlen(sleightext)-2); return STRING; } +[\r\ \t\v]+ { sleighlval.ch = ' '; return ' '; } \n { slgh->nextLine(); return ' '; } -. { return yytext[0]; } +. { return sleightext[0]; } ^@[^\n]*\n? { slgh->nextLine(); BEGIN( preprocess(pattern,preproc) ); } \$\([a-zA-Z0-9_.][a-zA-Z0-9_.]*\) { preproc_macroexpand(); } -\{ { BEGIN((withsection==1) ? INITIAL:sem); withsection=0; yylval.ch = yytext[0]; return yytext[0]; } +\{ { BEGIN((withsection==1) ? INITIAL:sem); withsection=0; sleighlval.ch = sleightext[0]; return sleightext[0]; } unimpl { BEGIN(INITIAL); return OP_UNIMPL; } globalset { return GLOBALSET_KEY; } \>\> { return OP_RIGHT; } @@ -579,24 +588,24 @@ with { BEGIN(pattern); withsection = 1; slgh->calcContextLayout(); return WITH \$or { return OP_OR; } \$xor { return OP_XOR; } \.\.\. { return ELLIPSIS_KEY; } -\[ { actionon = 1; yylval.ch = yytext[0]; return yytext[0]; } -\] { actionon = 0; yylval.ch = yytext[0]; return yytext[0]; } -\& { yylval.ch = yytext[0]; return (actionon==0) ? yytext[0] : OP_AND; } -\| { yylval.ch = yytext[0]; return (actionon==0) ? yytext[0] : OP_OR; } +\[ { actionon = 1; sleighlval.ch = sleightext[0]; return sleightext[0]; } +\] { actionon = 0; sleighlval.ch = sleightext[0]; return sleightext[0]; } +\& { sleighlval.ch = sleightext[0]; return (actionon==0) ? sleightext[0] : OP_AND; } +\| { sleighlval.ch = sleightext[0]; return (actionon==0) ? sleightext[0] : OP_OR; } \^ { return OP_XOR; } -[=(),:;+\-*/~<>] { yylval.ch = yytext[0]; return yytext[0]; } +[=(),:;+\-*/~<>] { sleighlval.ch = sleightext[0]; return sleightext[0]; } #.* [a-zA-Z_.][a-zA-Z0-9_.]* { return find_symbol(); } -[0-9]|[1-9][0-9]+ { return scan_number(yytext,&yylval,true); } -0x[0-9a-fA-F]+ { return scan_number(yytext,&yylval,true); } -0b[01]+ { return scan_number(yytext,&yylval,true); } +[0-9]|[1-9][0-9]+ { return scan_number(sleightext,&sleighlval,true); } +0x[0-9a-fA-F]+ { return scan_number(sleightext,&sleighlval,true); } +0b[01]+ { return scan_number(sleightext,&sleighlval,true); } [\r\ \t\v]+ \n { slgh->nextLine(); } -. { return yytext[0]; } +. { return sleightext[0]; } ^@[^\n]*\n? { slgh->nextLine(); BEGIN( preprocess(sem,preproc) ); } \$\([a-zA-Z0-9_.][a-zA-Z0-9_.]*\) { preproc_macroexpand(); } -\} { BEGIN(INITIAL); yylval.ch = yytext[0]; return yytext[0]; } +\} { BEGIN(INITIAL); sleighlval.ch = sleightext[0]; return sleightext[0]; } \|\| { return OP_BOOL_OR; } \&\& { return OP_BOOL_AND; } \^\^ { return OP_BOOL_XOR; } @@ -651,23 +660,23 @@ with { BEGIN(pattern); withsection = 1; slgh->calcContextLayout(); return WITH export { return EXPORT_KEY; } build { return BUILD_KEY; } local { return LOCAL_KEY; } -[=(),:\[\];!&|^+\-*/%~<>] { yylval.ch = yytext[0]; return yytext[0]; } +[=(),:\[\];!&|^+\-*/%~<>] { sleighlval.ch = sleightext[0]; return sleightext[0]; } #.* [a-zA-Z_.][a-zA-Z0-9_.]* { return find_symbol(); } -[0-9]|[1-9][0-9]+ { return scan_number(yytext,&yylval,false); } -0x[0-9a-fA-F]+ { return scan_number(yytext,&yylval,false); } -0b[01]+ { return scan_number(yytext,&yylval,false); } +[0-9]|[1-9][0-9]+ { return scan_number(sleightext,&sleighlval,false); } +0x[0-9a-fA-F]+ { return scan_number(sleightext,&sleighlval,false); } +0b[01]+ { return scan_number(sleightext,&sleighlval,false); } [\r\ \t\v]+ \n { slgh->nextLine(); } -. { return yytext[0]; } +. { return sleightext[0]; } ^@.*\n? { slgh->nextLine(); BEGIN( preprocess(preproc,preproc) ); } ^.*\n { slgh->nextLine(); } -<> { yy_delete_buffer( YY_CURRENT_BUFFER ); +<> { sleigh_delete_buffer( YY_CURRENT_BUFFER ); if (filebuffers.empty()) yyterminate(); - yy_switch_to_buffer( filebuffers.back().lastbuffer ); + sleigh_switch_to_buffer( filebuffers.back().lastbuffer ); FILE *curfile = filebuffers.back().file; if (curfile != (FILE *)0) fclose(curfile); diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/slghsymbol.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/slghsymbol.cc index 8516dbf107..b308e1b710 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/slghsymbol.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/slghsymbol.cc @@ -16,6 +16,9 @@ #include "slghsymbol.hh" #include "sleighbase.hh" #include + +namespace ghidra { + using std::log; SleighSymbol *SymbolScope::addSymbol(SleighSymbol *a) @@ -2644,3 +2647,5 @@ ContextChange *ContextCommit::clone(void) const res->num = num; return res; } + +} // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/slghsymbol.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/slghsymbol.hh index 82d95ffeff..2fc1e19216 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/slghsymbol.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/slghsymbol.hh @@ -13,12 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef __SLGHSYMBOL__ -#define __SLGHSYMBOL__ +#ifndef __SLGHSYMBOL_HH__ +#define __SLGHSYMBOL_HH__ #include "semantics.hh" #include "slghpatexpress.hh" +namespace ghidra { + class SleighBase; // Forward declaration class SleighSymbol { friend class SymbolTable; @@ -639,4 +641,5 @@ public: virtual symbol_type getType(void) const { return label_symbol; } }; +} // End namespace ghidra #endif diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/space.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/space.cc index b511f89194..bf4e1dc96b 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/space.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/space.cc @@ -16,6 +16,8 @@ #include "space.hh" #include "translate.hh" +namespace ghidra { + AttributeId ATTRIB_BASE = AttributeId("base",89); AttributeId ATTRIB_DEADCODEDELAY = AttributeId("deadcodedelay",90); AttributeId ATTRIB_DELAY = AttributeId("delay", 91); @@ -740,3 +742,5 @@ void OverlaySpace::decode(Decoder &decoder) if (baseSpace->hasPhysical()) setFlags(hasphysical); } + +} // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/space.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/space.hh index bf4913d413..23b1417248 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/space.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/space.hh @@ -16,12 +16,14 @@ /// \file space.hh /// \brief Classes for describing address spaces -#ifndef __CPUI_SPACE__ -#define __CPUI_SPACE__ +#ifndef __SPACE_HH__ +#define __SPACE_HH__ #include "error.hh" #include "marshal.hh" +namespace ghidra { + /// \brief Fundemental address space types /// /// Every address space must be one of the following core types @@ -554,4 +556,5 @@ inline bool AddrSpace::compareByIndex(const AddrSpace *a,const AddrSpace *b) { return (a->index < b->index); } +} // End namespace ghidra #endif diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/string_ghidra.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/string_ghidra.cc index 080f543cea..a13260cd6b 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/string_ghidra.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/string_ghidra.cc @@ -15,6 +15,8 @@ */ #include "string_ghidra.hh" +namespace ghidra { + GhidraStringManager::GhidraStringManager(ArchitectureGhidra *g,int4 max) : StringManager(max) { @@ -44,3 +46,5 @@ const vector &GhidraStringManager::getStringData(const Address &addr,Data isTrunc = stringData.isTruncated; return stringData.byteData; } + +} // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/string_ghidra.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/string_ghidra.hh index 884e7e6719..ec28b363df 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/string_ghidra.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/string_ghidra.hh @@ -16,11 +16,13 @@ /// \file string_ghidra.hh /// \brief Implementation of the StringManager through the ghidra client -#ifndef __STRING_GHIDRA__ -#define __STRING_GHIDRA__ +#ifndef __STRING_GHIDRA_HH__ +#define __STRING_GHIDRA_HH__ #include "ghidra_arch.hh" +namespace ghidra { + /// \brief Implementation of the StringManager that queries through the ghidra client /// /// This acts as a front end to Ghidra's string formats and encodings. @@ -36,4 +38,5 @@ public: virtual const vector &getStringData(const Address &addr,Datatype *charType,bool &isTrunc); }; +} // End namespace ghidra #endif diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/stringmanage.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/stringmanage.cc index 220210a1cf..e9aba5c799 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/stringmanage.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/stringmanage.cc @@ -16,6 +16,8 @@ #include "stringmanage.hh" #include "architecture.hh" +namespace ghidra { + AttributeId ATTRIB_TRUNC = AttributeId("trunc",69); ElementId ELEM_BYTES = ElementId("bytes",83); @@ -401,3 +403,5 @@ bool StringManagerUnicode::writeUnicode(ostream &s,uint1 *buffer,int4 size,int4 } return true; } + +} // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/stringmanage.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/stringmanage.hh index 8a227c69e7..92cd160614 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/stringmanage.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/stringmanage.hh @@ -16,11 +16,13 @@ /// \file stringmanage.hh /// \brief Classes for decoding and storing string data -#ifndef __STRING_MANAGE__ -#define __STRING_MANAGE__ +#ifndef __STRINGMANAGE_HH__ +#define __STRINGMANAGE_HH__ #include "type.hh" +namespace ghidra { + class Architecture; extern AttributeId ATTRIB_TRUNC; ///< Marshaling attribute "trunc" @@ -87,4 +89,5 @@ public: bool writeUnicode(ostream &s,uint1 *buffer,int4 size,int4 charsize); ///< Translate/copy unicode to UTF8 }; +} // End namespace ghidra #endif diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/subflow.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/subflow.cc index 8f6835b3ff..31037b912c 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/subflow.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/subflow.cc @@ -15,6 +15,8 @@ */ #include "subflow.hh" +namespace ghidra { + /// \brief Return \e slot of constant if INT_OR op sets all bits in mask, otherwise -1 /// /// \param orop is the given CPUI_INT_OR op @@ -2524,3 +2526,5 @@ bool LaneDivide::doTrace(void) if (!retval) return false; return true; } + +} // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/subflow.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/subflow.hh index d3c5983b8e..f4e15d82ef 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/subflow.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/subflow.hh @@ -15,11 +15,13 @@ */ /// \file subflow.hh /// \brief Classes for reducing/splitting Varnodes containing smaller logical values -#ifndef __SUBVARIABLE_FLOW__ -#define __SUBVARIABLE_FLOW__ +#ifndef __SUBFLOW_HH__ +#define __SUBFLOW_HH__ #include "funcdata.hh" +namespace ghidra { + /// \brief Class for shrinking big Varnodes carrying smaller logical values /// /// Given a root within the syntax tree and dimensions @@ -198,4 +200,5 @@ public: bool doTrace(void); ///< Trace lanes as far as possible from the root Varnode }; +} // End namespace ghidra #endif diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/test.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/test.cc index e1b6a04c7e..660f069400 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/test.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/test.cc @@ -16,6 +16,8 @@ #include "test.hh" #include "libdecomp.hh" +namespace ghidra { + vector UnitTest::tests; /// Run all the tests unless a non-empty set of names is passed in. @@ -95,7 +97,11 @@ int add_exit_code(int current, int add) { return ret; } +} // End namespace ghidra + int main(int argc, char **argv) { + using namespace ghidra; + bool runUnitTests = true; bool runDataTests = true; diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/test.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/test.hh index b593db91fc..27c27bc218 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/test.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/test.hh @@ -26,6 +26,8 @@ /// ASSERT(0.0 < 1.0); /// } /// +#ifndef __TEST_HH__ +#define __TEST_HH__ #include #include @@ -33,6 +35,8 @@ #include #include +namespace ghidra { + using std::vector; using std::set; using std::string; @@ -66,6 +70,7 @@ struct UnitTest { static int run(set &testNames); ///< Run all the instantiated tests }; +} // End namespace ghidra /// \brief Main unit test macro #define TEST(testname) \ @@ -101,3 +106,5 @@ struct UnitTest { << " != " << ssb.str() << "\"." << endl; \ throw 0; \ } + +#endif diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/testfunction.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/testfunction.cc index 38137ffd43..5f2cb69f97 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/testfunction.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/testfunction.cc @@ -15,6 +15,8 @@ */ #include "ifacedecomp.hh" +namespace ghidra { + void FunctionTestProperty::startTest(void) const { @@ -346,3 +348,5 @@ int FunctionTestCollection::runTestFiles(const vector &testFiles,ostream } return totalTestsApplied - totalTestsSucceeded; } + +} // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/testfunction.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/testfunction.hh index 43801047a4..26652355bf 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/testfunction.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/testfunction.hh @@ -15,14 +15,16 @@ */ /// \file testfunction.hh /// \brief Framework for decompiler data driven single function tests -#ifndef __TESTFUNCTION__ -#define __TESTFUNCTION__ +#ifndef __TESTFUNCTION_HH__ +#define __TESTFUNCTION_HH__ #include "ifaceterm.hh" #include "error.hh" #include "xml.hh" #include +namespace ghidra { + class IfaceDecompData; /// \brief A single property to be searched for in the output of a function decompilation @@ -94,4 +96,5 @@ public: static int runTestFiles(const vector &testFiles,ostream &s); ///< Run tests for each listed file }; +} // End namespace ghidra #endif diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/transform.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/transform.cc index 3c594169d4..009aa79cba 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/transform.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/transform.cc @@ -16,6 +16,8 @@ #include "transform.hh" #include "funcdata.hh" +namespace ghidra { + AttributeId ATTRIB_VECTOR_LANE_SIZES = AttributeId("vector_lane_sizes",130); /// \param op2 is the lane description to copy from @@ -756,3 +758,5 @@ void TransformManager::apply(void) transformInputVarnodes(inputList); placeInputs(); } + +} // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/transform.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/transform.hh index fa26f0bd10..e8cf9877a0 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/transform.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/transform.hh @@ -15,10 +15,13 @@ */ /// \file transform.hh /// \brief Classes for building large scale transforms of function data-flow -#ifndef __TRANSFORM__ -#define __TRANSFORM__ +#ifndef __TRANSFORM_HH__ +#define __TRANSFORM_HH__ #include "varnode.hh" + +namespace ghidra { + class Funcdata; // Forward declaration class TransformOp; @@ -248,4 +251,5 @@ inline bool TransformManager::preexistingGuard(int4 slot,TransformVar *rvn) return true; // The op was not (will not be) visited on slot 0, build now } +} // End namespace ghidra #endif diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/translate.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/translate.cc index 61b8cc108f..1675ad354f 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/translate.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/translate.cc @@ -15,6 +15,8 @@ */ #include "translate.hh" +namespace ghidra { + AttributeId ATTRIB_CODE = AttributeId("code",43); AttributeId ATTRIB_CONTAIN = AttributeId("contain",44); AttributeId ATTRIB_DEFAULTSPACE = AttributeId("defaultspace",45); @@ -977,3 +979,5 @@ void PcodeEmit::decodeOp(const Address &addr,Decoder &decoder) decoder.closeElement(elemId); dump(addr,(OpCode)opcode,outptr,invar,isize); } + +} // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/translate.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/translate.hh index 34a4709a85..83b87ee7d9 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/translate.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/translate.hh @@ -18,12 +18,14 @@ /// /// Classes for keeping track of spaces and registers (for a single architecture). -#ifndef __CPUI_TRANSLATE__ -#define __CPUI_TRANSLATE__ +#ifndef __TRANSLATE_HH__ +#define __TRANSLATE_HH__ #include "pcoderaw.hh" #include "float.hh" +namespace ghidra { + extern AttributeId ATTRIB_CODE; ///< Marshaling attribute "code" extern AttributeId ATTRIB_CONTAIN; ///< Marshaling attribute "contain" extern AttributeId ATTRIB_DEFAULTSPACE; ///< Marshaling attribute "defaultspace" @@ -602,4 +604,5 @@ inline uint4 Translate::getUniqueStart(UniqueLayout layout) const { return (layout != ANALYSIS) ? layout + unique_base : layout; } +} // End namespace ghidra #endif diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/type.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/type.cc index b35dcc3397..f1c0b6452a 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/type.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/type.cc @@ -16,6 +16,8 @@ #include "type.hh" #include "funcdata.hh" +namespace ghidra { + /// The base propagation ordering associated with each meta-type. /// The array elements correspond to the ordering of #type_metatype. sub_metatype Datatype::base2sub[15] = { @@ -4087,3 +4089,5 @@ void TypeFactory::parseEnumConfig(Decoder &decoder) enumtype = TYPE_UINT; decoder.closeElement(elemId); } + +} // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/type.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/type.hh index 89900734a0..5143d85b32 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/type.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/type.hh @@ -16,11 +16,13 @@ /// \file type.hh /// \brief Classes for describing and printing data-types -#ifndef __CPUI_TYPE__ -#define __CPUI_TYPE__ +#ifndef __TYPE_HH__ +#define __TYPE_HH__ #include "address.hh" +namespace ghidra { + extern AttributeId ATTRIB_ALIGNMENT; ///< Marshaling attribute "alignment" extern AttributeId ATTRIB_ARRAYSIZE; ///< Marshaling attribute "arraysize" extern AttributeId ATTRIB_CHAR; ///< Marshaling attribute "char" @@ -808,4 +810,5 @@ inline void TypePointerRel::markEphemeral(TypeFactory &typegrp) submeta = SUB_PTRREL_UNK; } +} // End namespace ghidra #endif diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/typegrp_ghidra.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/typegrp_ghidra.cc index 351e3df1a1..173890e1bf 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/typegrp_ghidra.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/typegrp_ghidra.cc @@ -15,6 +15,8 @@ */ #include "typegrp_ghidra.hh" +namespace ghidra { + Datatype *TypeFactoryGhidra::findById(const string &n,uint8 id,int4 sz) { @@ -32,3 +34,5 @@ Datatype *TypeFactoryGhidra::findById(const string &n,uint8 id,int4 sz) ct = decodeType(decoder); // Parse ghidra's type return ct; } + +} // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/typegrp_ghidra.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/typegrp_ghidra.hh index 847dec7dab..f29b88d1b3 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/typegrp_ghidra.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/typegrp_ghidra.hh @@ -16,12 +16,14 @@ /// \file typegrp_ghidra.hh /// \brief Interface for requesting data-type information from a Ghidra client -#ifndef __TYPEGRP_GHIDRA__ -#define __TYPEGRP_GHIDRA__ +#ifndef __TYPEGRP_GHIDRA_HH__ +#define __TYPEGRP_GHIDRA_HH__ #include "type.hh" #include "ghidra_arch.hh" +namespace ghidra { + /// \brief An implementation of the TypeFactory interface, query a Ghidra client for data-type information /// /// Requests for a specific data-type name and id are marshaled to the Ghidra client, @@ -35,4 +37,5 @@ public: virtual ~TypeFactoryGhidra(void) {} }; +} // End namespace ghidra #endif diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/typeop.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/typeop.cc index f71e96e293..2f9ebfc703 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/typeop.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/typeop.cc @@ -16,6 +16,8 @@ #include "typeop.hh" #include "funcdata.hh" +namespace ghidra { + /// \param inst will hold the array of TypeOp objects, indexed on op-code /// \param tlst is the corresponding TypeFactory for the Architecture /// \param trans is the Translate object for floating-point formats @@ -2343,3 +2345,5 @@ TypeOpLzcount::TypeOpLzcount(TypeFactory *t) opflags = PcodeOp::unary; behave = new OpBehaviorLzcount(); } + +} // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/typeop.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/typeop.hh index 4e8c143bc8..108350c66a 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/typeop.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/typeop.hh @@ -16,14 +16,16 @@ /// \file typeop.hh /// \brief Data-type and behavior information associated with specific p-code op-codes. -#ifndef __CPUI_TYPEOP__ -#define __CPUI_TYPEOP__ +#ifndef __TYPEOP_HH__ +#define __TYPEOP_HH__ #include "cpool.hh" #include "variable.hh" #include "opbehavior.hh" #include "printlanguage.hh" +namespace ghidra { + class PcodeOp; class Translate; @@ -864,4 +866,5 @@ public: virtual void push(PrintLanguage *lng,const PcodeOp *op,const PcodeOp *readOp) const { lng->opLzcountOp(op); } }; +} // End namespace ghidra #endif diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/types.h b/Ghidra/Features/Decompiler/src/decompile/cpp/types.h index c342f3d9a7..ddbff99431 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/types.h +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/types.h @@ -16,11 +16,13 @@ */ /* typedefs for getting specific word sizes */ -#ifndef __MYTYPES__ -#define __MYTYPES__ +#ifndef __TYPES_H__ +#define __TYPES_H__ #include +namespace ghidra { + // Use of uintm and intm is deprecated. They must currently be set to be 32-bit. typedef uint32_t uintm; typedef int32_t intm; @@ -94,4 +96,6 @@ CPUI_DEBUG -- This is the ONE debug switch that should be passed in //# define VARBANK_DEBUG #endif +} // End namespace ghidra + #endif diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/unify.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/unify.cc index d848cfc7dd..3c2f67dc83 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/unify.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/unify.cc @@ -16,6 +16,8 @@ #ifdef CPUI_RULECOMPILE #include "unify.hh" +namespace ghidra { + UnifyDatatype::UnifyDatatype(uint4 tp) { @@ -1641,4 +1643,5 @@ void UnifyCPrinter::print(ostream &s) } } +} // End namespace ghidra #endif diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/unify.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/unify.hh index 995f96b445..267af627b5 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/unify.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/unify.hh @@ -1,6 +1,5 @@ /* ### * IP: GHIDRA - * REVIEWED: YES * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,11 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef __CPUI_UNIFY__ -#define __CPUI_UNIFY__ +#ifndef __UNIFY_HH__ +#define __UNIFY_HH__ #include "funcdata.hh" +namespace ghidra { + class UnifyCPrinter; class UnifyDatatype { @@ -706,4 +707,5 @@ public: // vlo1 -> oloadd(+) <- vtmp( != vlo1)( == vlo2); // oloadd -> vreslo; +} // End namespace ghidra #endif diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/unionresolve.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/unionresolve.cc index 5f8a22c851..a99a9de891 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/unionresolve.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/unionresolve.cc @@ -16,6 +16,8 @@ #include "unionresolve.hh" #include "funcdata.hh" +namespace ghidra { + /// The original parent must either be a union, a pointer to a union, or a partial union. /// The object is set up initially to resolve to the parent. /// \param parent is the original parent data-type @@ -1106,3 +1108,4 @@ ScoreUnionFields::ScoreUnionFields(TypeFactory &tgrp,TypeUnion *unionType,int4 o computeBestIndex(); } +} // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/unionresolve.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/unionresolve.hh index c60c706014..8ceca302ba 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/unionresolve.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/unionresolve.hh @@ -13,11 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef __UNION_RESOLVE__ -#define __UNION_RESOLVE__ +#ifndef __UNIONRESOLVE_HH__ +#define __UNIONRESOLVE_HH__ #include "op.hh" +namespace ghidra { + /// \brief A data-type \e resolved from an associated TypeUnion or TypeStruct /// /// A \b parent refers to either: @@ -177,4 +179,5 @@ inline bool ResolveEdge::operator<(const ResolveEdge &op2) const return (opTime < op2.opTime); } +} // End namespace ghidra #endif diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/userop.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/userop.cc index e603539416..f83e8cb29d 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/userop.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/userop.cc @@ -16,6 +16,8 @@ #include "userop.hh" #include "funcdata.hh" +namespace ghidra { + AttributeId ATTRIB_FARPOINTER = AttributeId("farpointer",85); AttributeId ATTRIB_INPUTOP = AttributeId("inputop",86); AttributeId ATTRIB_OUTPUTOP = AttributeId("outputop",87); @@ -511,3 +513,5 @@ void UserOpManage::manualCallOtherFixup(const string &useropname,const string &o throw err; } } + +} // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/userop.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/userop.hh index 747a22d0f7..f182c3d383 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/userop.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/userop.hh @@ -16,11 +16,13 @@ /// \file userop.hh /// \brief Classes for more detailed definitions of user defined p-code operations -#ifndef __CPUI_USEROP__ -#define __CPUI_USEROP__ +#ifndef __USEROP_HH__ +#define __USEROP_HH__ #include "typeop.hh" +namespace ghidra { + extern AttributeId ATTRIB_FARPOINTER; ///< Marshaling attribute "farpointer" extern AttributeId ATTRIB_INPUTOP; ///< Marshaling attribute "inputop" extern AttributeId ATTRIB_OUTPUTOP; ///< Marshaling attribute "outputop" @@ -301,4 +303,5 @@ public: const vector &inname,const string &snippet,Architecture *glb); }; +} // End namespace ghidra #endif diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/variable.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/variable.cc index c8e3205afc..33cdebca0a 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/variable.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/variable.cc @@ -17,6 +17,8 @@ #include "op.hh" #include "database.hh" +namespace ghidra { + AttributeId ATTRIB_CLASS = AttributeId("class",66); AttributeId ATTRIB_REPREF = AttributeId("repref",67); AttributeId ATTRIB_SYMREF = AttributeId("symref",68); @@ -1122,3 +1124,4 @@ bool HighIntersectTest::intersection(HighVariable *a,HighVariable *b) return res; } +} // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/variable.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/variable.hh index 90daa50cb0..1f2dec817a 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/variable.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/variable.hh @@ -16,11 +16,13 @@ /// \file variable.hh /// \brief Definitions for high-level variables -#ifndef __CPUI_TYPEVAR__ -#define __CPUI_TYPEVAR__ +#ifndef __VARIABLE_HH__ +#define __VARIABLE_HH__ #include "varnode.hh" +namespace ghidra { + class Symbol; extern AttributeId ATTRIB_CLASS; ///< Marshaling attribute "class" @@ -291,4 +293,5 @@ inline const Cover &HighVariable::getCover(void) const return piece->getCover(); } +} // End namespace ghidra #endif diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/varmap.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/varmap.cc index a382431cb2..d5e779ec47 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/varmap.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/varmap.cc @@ -16,6 +16,8 @@ #include "varmap.hh" #include "funcdata.hh" +namespace ghidra { + AttributeId ATTRIB_LOCK = AttributeId("lock",133); AttributeId ATTRIB_MAIN = AttributeId("main",134); @@ -1450,3 +1452,5 @@ void ScopeLocal::addRecommendName(Symbol *sym) if (sym->getCategory() < 0) removeSymbol(sym); } + +} // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/varmap.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/varmap.hh index 5267b0a3a9..36f045da05 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/varmap.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/varmap.hh @@ -16,11 +16,13 @@ /// \file varmap.hh /// \brief Classes for keeping track of local variables and reconstructing stack layout -#ifndef __CPUI_VARMAP__ -#define __CPUI_VARMAP__ +#ifndef __VARMAP_HH__ +#define __VARMAP_HH__ #include "database.hh" +namespace ghidra { + extern AttributeId ATTRIB_LOCK; ///< Marshaling attribute "lock" extern AttributeId ATTRIB_MAIN; ///< Marshaling attribute "main" @@ -250,4 +252,5 @@ public: void addTypeRecommendation(const Address &addr,Datatype *dt); ///< Add a new data-type recommendation }; +} // End namespace ghidra #endif diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/varnode.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/varnode.cc index d22276613e..aa7c9399c9 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/varnode.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/varnode.cc @@ -16,6 +16,8 @@ #include "varnode.hh" #include "funcdata.hh" +namespace ghidra { + AttributeId ATTRIB_ADDRTIED = AttributeId("addrtied",30); AttributeId ATTRIB_GRP = AttributeId("grp",31); AttributeId ATTRIB_INPUT = AttributeId("input",32); @@ -1954,3 +1956,4 @@ Varnode *findContiguousWhole(Funcdata &data,Varnode *vn1,Varnode *vn2) return (Varnode *)0; } +} // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/varnode.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/varnode.hh index a76c21d428..2fb160392a 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/varnode.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/varnode.hh @@ -15,12 +15,14 @@ */ /// \file varnode.hh /// \brief The Varnode and VarnodeBank classes -#ifndef __CPUI_VARNODE__ -#define __CPUI_VARNODE__ +#ifndef __VARNODE_HH__ +#define __VARNODE_HH__ #include "pcoderaw.hh" #include "cover.hh" +namespace ghidra { + class HighVariable; class Varnode; // Forward declaration @@ -434,4 +436,5 @@ inline AddrSpace *Varnode::getSpaceFromConst(void) const { return (AddrSpace *)(uintp)loc.getOffset(); } +} // End namespace ghidra #endif diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/xml.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/xml.cc index 901e373487..76bdf4526a 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/xml.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/xml.cc @@ -99,6 +99,8 @@ #include #include +namespace ghidra { + string Attributes::bogus_uri("http://unused.uri"); /// \brief The XML character scanner @@ -190,6 +192,7 @@ static ContentHandler *handler; ///< Global reference to the content handler + # ifndef YY_NULLPTR # if defined __cplusplus && 201103L <= __cplusplus # define YY_NULLPTR nullptr @@ -567,14 +570,14 @@ static const yytype_uint8 yytranslate[] = /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */ static const yytype_uint8 yyrline[] = { - 0, 135, 135, 136, 137, 138, 139, 140, 141, 142, - 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, - 154, 155, 156, 157, 158, 160, 161, 162, 163, 164, - 165, 166, 168, 169, 170, 171, 172, 173, 174, 176, - 177, 178, 179, 180, 181, 182, 184, 185, 187, 188, - 189, 190, 192, 193, 194, 195, 196, 197, 199, 200, - 201, 202, 203, 204, 205, 207, 208, 210, 211, 212, - 213 + 0, 138, 138, 139, 140, 141, 142, 143, 144, 145, + 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, + 157, 158, 159, 160, 161, 163, 164, 165, 166, 167, + 168, 169, 171, 172, 173, 174, 175, 176, 177, 179, + 180, 181, 182, 183, 184, 185, 187, 188, 190, 191, + 192, 193, 195, 196, 197, 198, 199, 200, 202, 203, + 204, 205, 206, 207, 208, 210, 211, 213, 214, 215, + 216 }; #endif @@ -2372,3 +2375,5 @@ void xml_escape(ostream &s,const char *str) str++; } } + +} // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/xml.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/xml.hh index 21884553cd..72533012a1 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/xml.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/xml.hh @@ -15,8 +15,8 @@ */ /// \file xml.hh /// \brief Lightweight (and incomplete) XML parser for marshaling data to and from the decompiler -#ifndef __CPUI_XML__ -#define __CPUI_XML__ +#ifndef __XML_HH__ +#define __XML_HH__ #include "types.h" #include @@ -25,6 +25,8 @@ #include #include +namespace ghidra { + using std::string; using std::vector; using std::map; @@ -396,4 +398,6 @@ inline bool xml_readbool(const string &attr) if (firstc=='y') return true; // For backward compatibility return false; } + +} // End namespace ghidra #endif diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/xml.y b/Ghidra/Features/Decompiler/src/decompile/cpp/xml.y index 9a131710f8..30ed0acd5a 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/xml.y +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/xml.y @@ -26,6 +26,8 @@ #include #include +namespace ghidra { + string Attributes::bogus_uri("http://unused.uri"); /// \brief The XML character scanner @@ -114,6 +116,7 @@ extern int4 convertEntityRef(const string &ref); ///< Convert an XML entity to i extern int4 convertCharRef(const string &ref); ///< Convert an XML character reference to its equivalent character static XmlScan *global_scan; ///< Global reference to the scanner static ContentHandler *handler; ///< Global reference to the content handler + %} %union { @@ -642,3 +645,5 @@ void xml_escape(ostream &s,const char *str) str++; } } + +} // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/xml_arch.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/xml_arch.cc index c5c533ba94..ff76eac1a2 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/xml_arch.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/xml_arch.cc @@ -15,6 +15,8 @@ */ #include "xml_arch.hh" +namespace ghidra { + ElementId ELEM_XML_SAVEFILE = ElementId("xml_savefile",236); // Constructing the singleton registers the capability @@ -153,3 +155,5 @@ void XmlArchitecture::restoreXml(DocumentStorage &store) SleighArchitecture::restoreXml(store); } } + +} // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/xml_arch.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/xml_arch.hh index d395fb8a3c..92a72b8aea 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/xml_arch.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/xml_arch.hh @@ -15,9 +15,14 @@ */ /// \file xml_arch.hh /// \brief Extension to read executables based on an XML format +#ifndef __XML_ARCH_HH__ +#define __XML_ARCH_HH__ + #include "sleigh_arch.hh" #include "loadimage_xml.hh" +namespace ghidra { + extern ElementId ELEM_XML_SAVEFILE; ///< Marshaling element \ /// \brief Extension for building an XML format capable Architecture @@ -45,3 +50,6 @@ public: XmlArchitecture(const string &fname,const string &targ,ostream *estream); ///< Constructor virtual ~XmlArchitecture(void) {} }; + +} // End namespace ghidra +#endif diff --git a/Ghidra/Features/Decompiler/src/decompile/unittests/testcirclerange.cc b/Ghidra/Features/Decompiler/src/decompile/unittests/testcirclerange.cc index a8bf58ec5d..3c659468bc 100644 --- a/Ghidra/Features/Decompiler/src/decompile/unittests/testcirclerange.cc +++ b/Ghidra/Features/Decompiler/src/decompile/unittests/testcirclerange.cc @@ -16,6 +16,8 @@ #include "architecture.hh" #include "test.hh" +namespace ghidra { + class CircleRangeTestEnvironment { Architecture *g; public: @@ -794,3 +796,5 @@ TEST(circlerange_pushsext6) { TEST(circlerange_pushsext7) { ASSERT(CircleRangeTest::testPushUnary(0,0,4,1, CPUI_INT_SEXT, 2)); } + +} // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/unittests/testfloatemu.cc b/Ghidra/Features/Decompiler/src/decompile/unittests/testfloatemu.cc index f88b4d0002..c35bde8774 100644 --- a/Ghidra/Features/Decompiler/src/decompile/unittests/testfloatemu.cc +++ b/Ghidra/Features/Decompiler/src/decompile/unittests/testfloatemu.cc @@ -25,6 +25,9 @@ #include #include + +namespace ghidra { + using std::isnan; using std::sqrt; using std::floor; @@ -484,4 +487,5 @@ TEST(float_opSub) { } } +} // End namespace ghidra // end generated diff --git a/Ghidra/Features/Decompiler/src/decompile/unittests/testfuncproto.cc b/Ghidra/Features/Decompiler/src/decompile/unittests/testfuncproto.cc index 417f53e7b4..38eb5362c3 100644 --- a/Ghidra/Features/Decompiler/src/decompile/unittests/testfuncproto.cc +++ b/Ghidra/Features/Decompiler/src/decompile/unittests/testfuncproto.cc @@ -18,6 +18,8 @@ #include "test.hh" #include +namespace ghidra { + class FuncProtoTestEnvironment { Architecture *g; ProtoModel *mod1; @@ -684,3 +686,5 @@ TEST(funcproto_recovermixedmeta) ASSERT(!paramActive.getTrial(4).isUsed()); ASSERT(register_used(paramActive.getTrial(5),"r10")) } + +} // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/unittests/testmarshal.cc b/Ghidra/Features/Decompiler/src/decompile/unittests/testmarshal.cc index 26c7d62d76..44a31cc16f 100644 --- a/Ghidra/Features/Decompiler/src/decompile/unittests/testmarshal.cc +++ b/Ghidra/Features/Decompiler/src/decompile/unittests/testmarshal.cc @@ -16,6 +16,8 @@ #include "translate.hh" #include "test.hh" +namespace ghidra { + class TestAddrSpaceManager : public AddrSpaceManager { public: TestAddrSpaceManager(Translate *t); @@ -550,3 +552,5 @@ TEST(marshal_bufferpad) { ASSERT_EQUALS(nextel,0); decoder.closeElement(el); } + +} // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/unittests/testtypes.cc b/Ghidra/Features/Decompiler/src/decompile/unittests/testtypes.cc index 4ce7cdde65..a25b36c7ac 100644 --- a/Ghidra/Features/Decompiler/src/decompile/unittests/testtypes.cc +++ b/Ghidra/Features/Decompiler/src/decompile/unittests/testtypes.cc @@ -18,6 +18,8 @@ #include "test.hh" #include +namespace ghidra { + static Architecture *glb; static TypeFactory *types; static CastStrategy *strategy; @@ -209,3 +211,5 @@ TEST(cast_integertoken) { ASSERT(longPrinted(CPUI_INT_RIGHT,parse("uint8"),0xffffffff)); ASSERT(!longPrinted(CPUI_INT_RIGHT,parse("uint8"),0x100000000)); } + +} // End namespace ghidra