diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/architecture.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/architecture.cc index e71bf7ad44..97c33cd9f8 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/architecture.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/architecture.cc @@ -624,8 +624,9 @@ void Architecture::postSpecFile(void) void Architecture::restoreFromSpec(DocumentStorage &store) { - Translate *newtrans = buildTranslator(store); // Once language is described we can build translator - newtrans->initialize(store); + unique_ptr utrans(buildTranslator(store)); // Once language is described we can build translator + utrans->initialize(store); + Translate *newtrans = utrans.release(); translate = newtrans; modifySpaces(newtrans); // Give architecture chance to modify spaces, before copying copySpaces(newtrans); @@ -741,23 +742,21 @@ void Architecture::decodeDynamicRule(Decoder &decoder) ProtoModel *Architecture::decodeProto(Decoder &decoder) { - ProtoModel *res; + unique_ptr model; uint4 elemId = decoder.peekElement(); if (elemId == ELEM_PROTOTYPE) - res = new ProtoModel(this); + model.reset(new ProtoModel(this)); else if (elemId == ELEM_RESOLVEPROTOTYPE) - res = new ProtoModelMerged(this); + model.reset(new ProtoModelMerged(this)); else throw LowlevelError("Expecting or tag"); - res->decode(decoder); + model->decode(decoder); - ProtoModel *other = getModel(res->getName()); - if (other != (ProtoModel *)0) { - string errMsg = "Duplicate ProtoModel name: " + res->getName(); - delete res; - throw LowlevelError(errMsg); - } + ProtoModel *other = getModel(model->getName()); + if (other != (ProtoModel *)0) + throw LowlevelError("Duplicate ProtoModel name: " + model->getName()); + ProtoModel *res = model.release(); protoModels[res->getName()] = res; return res; } diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/bfd_arch.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/bfd_arch.cc index a3f111f173..5a028a8864 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/bfd_arch.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/bfd_arch.cc @@ -5,9 +5,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -67,19 +67,19 @@ bool BfdArchitectureCapability::isXmlMatch(Document *doc) const void BfdArchitecture::buildLoader(DocumentStorage &store) { - LoadImageBfd *ldr; + unique_ptr ldr; collectSpecFiles(*errorstream); if (getTarget().find("binary")==0) - ldr = new LoadImageBfd(getFilename(),"binary"); + ldr.reset(new LoadImageBfd(getFilename(),"binary")); else if (getTarget().find("default")==0) - ldr = new LoadImageBfd(getFilename(),"default"); + ldr.reset(new LoadImageBfd(getFilename(),"default")); else - ldr = new LoadImageBfd(getFilename(),getTarget()); + ldr.reset(new LoadImageBfd(getFilename(),getTarget())); ldr->open(); if (adjustvma!=0) ldr->adjustVma(adjustvma); - loader = ldr; + loader = ldr.release(); } void BfdArchitecture::resolveArchitecture(void) diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/block.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/block.cc index bf7103d916..615057605d 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/block.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/block.cc @@ -1402,7 +1402,7 @@ void BlockGraph::decodeBody(Decoder &decoder) { BlockMap newresolver; - vector tmplist; + vector > tmplist; for(;;) { uint4 subId = decoder.peekElement(); @@ -1411,15 +1411,14 @@ void BlockGraph::decodeBody(Decoder &decoder) int4 newindex = decoder.readSignedInteger(ATTRIB_INDEX); FlowBlock *bl = newresolver.createBlock(decoder.readString(ATTRIB_TYPE)); bl->index = newindex; // Need to set index here for sort - tmplist.push_back(bl); + tmplist.push_back(unique_ptr(bl)); decoder.closeElement(subId); } newresolver.sortList(); for(int4 i=0;idecode(decoder,newresolver); - addBlock(bl); + tmplist[i]->decode(decoder,newresolver); + addBlock(tmplist[i].release()); } } @@ -1905,12 +1904,13 @@ BlockSwitch *BlockGraph::newBlockSwitch(const vector &cs,bool hasEx { FlowBlock *rootbl = cs[0]; - BlockSwitch *ret = new BlockSwitch(rootbl); + unique_ptr uret( new BlockSwitch(rootbl) ); const FlowBlock *leafbl = rootbl->getExitLeaf(); if ((leafbl == (const FlowBlock *)0)||(leafbl->getType() != FlowBlock::t_copy)) throw LowlevelError("Could not get switch leaf"); - ret->grabCaseBasic(leafbl->subBlock(0),cs); // Must be called before the identifyInternal - identifyInternal(ret,cs); + uret->grabCaseBasic(leafbl->subBlock(0),cs); // Must be called before the identifyInternal + identifyInternal(uret.get(),cs); + BlockSwitch *ret = uret.release(); addBlock(ret); if (hasExit) ret->forceOutputNum(1); // If there is an exit, there should be exactly 1 out edge diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/consolemain.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/consolemain.cc index d31e287580..87c13b8184 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/consolemain.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/consolemain.cc @@ -4,9 +4,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -206,43 +206,38 @@ int main(int argc,char **argv) startDecompilerLibrary(ghidraroot.c_str(), extrapaths); } - IfaceStatus *status; + int4 retval = 2; try { - status = new IfaceTerm("[decomp]> ",cin,cout); // Set up interface - } catch(IfaceError &err) { - cerr << "Interface error during setup: " << err.explain << endl; - exit(1); - } - IfaceCapability::registerAllCommands(status); // Register commands for decompiler and all modules + unique_ptr status(new IfaceTerm("[decomp]> ",cin,cout)); // Set up interface + IfaceCapability::registerAllCommands(status.get()); // Register commands for decompiler and all modules - // Extra commands specific to the console application - status->registerCom(new IfcLoadFile(),"load","file"); - status->registerCom(new IfcAddpath(),"addpath"); - status->registerCom(new IfcSave(),"save"); - status->registerCom(new IfcRestore(),"restore"); + // Extra commands specific to the console application + status->registerCom(new IfcLoadFile(),"load","file"); + status->registerCom(new IfcAddpath(),"addpath"); + status->registerCom(new IfcSave(),"save"); + status->registerCom(new IfcRestore(),"restore"); - if (initscript != (const char *)0) { - try { - status->pushScript(initscript,"init> "); - } catch(IfaceParseError &err) { - *status->optr << err.explain << endl; - status->done = true; + if (initscript != (const char *)0) { + try { + status->pushScript(initscript,"init> "); + } catch(IfaceParseError &err) { + *status->optr << err.explain << endl; + status->done = true; + } } - } - if (!status->done) - mainloop(status); - int4 retval = status->isInError() ? 1 : 0; + if (!status->done) + mainloop(status.get()); + retval = status->isInError() ? 1 : 0; #ifdef CPUI_STATISTICS - IfaceDecompData *decompdata = (IfaceDecompData *)status->getData("decompile"); - decompdata->conf->stats->printResults(cout); + IfaceDecompData *decompdata = (IfaceDecompData *)status->getData("decompile"); + decompdata->conf->stats->printResults(cout); #endif - try { - delete status; } catch(IfaceError &err) { - cerr << err.explain << endl; + cerr << "Interface error: " << err.explain << endl; + retval = 2; } shutdownDecompilerLibrary(); diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/cpool.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/cpool.cc index 59284ecbab..3b4fb14744 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/cpool.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/cpool.cc @@ -132,7 +132,10 @@ void CPoolRecord::decode(Decoder &decoder,TypeFactory &typegrp) if (subId == ELEM_TOKEN) token = decoder.readString(ATTRIB_CONTENT); else { - byteDataLen = decoder.readSignedInteger(ATTRIB_LENGTH); + int8 val = decoder.readSignedInteger(ATTRIB_LENGTH); + if (val < 0 || val >= MAX_STRING_SIZE) + throw LowlevelError("Bad constant pool record: bad size"); + byteDataLen = val; istringstream s3(decoder.readString(ATTRIB_CONTENT)); byteData = new uint1[byteDataLen]; for(int4 i=0;idecode(decoder); - } catch(RecovError &err) { + } catch(...) { delete sym; throw; } @@ -2950,12 +2950,13 @@ Database::~Database(void) void Database::attachScope(Scope *newscope,Scope *parent) { + unique_ptr owner(newscope); if (parent == (Scope *)0) { if (globalscope != (Scope *)0) throw LowlevelError("Multiple global scopes"); if (newscope->name.size() != 0) throw LowlevelError("Global scope does not have empty name"); - globalscope = newscope; + globalscope = owner.release(); idmap[globalscope->uniqueId] = globalscope; return; } @@ -2964,14 +2965,9 @@ void Database::attachScope(Scope *newscope,Scope *parent) pair value(newscope->uniqueId,newscope); pair res; res = idmap.insert(value); - if (res.second==false) { - ostringstream s; - s << "Duplicate scope id: "; - s << newscope->getFullName(); - delete newscope; - throw RecovError(s.str()); - } - parent->attachScope(newscope); + if (res.second==false) + throw RecovError("Duplicate scope id: " + newscope->getFullName()); + parent->attachScope(owner.release()); } /// Give \b this database the chance to inform existing scopes of any change to the @@ -3379,17 +3375,18 @@ void Database::decode(Decoder &decoder) void Database::decodeScope(Decoder &decoder,Scope *newScope) { + unique_ptr owner(newScope); uint4 elemId = decoder.openElement(); if (elemId == ELEM_SCOPE) { Scope *parentScope = parseParentTag(decoder); - attachScope(newScope,parentScope); + attachScope(owner.release(),parentScope); newScope->decode(decoder); } else { newScope->decodeWrappingAttributes(decoder); uint4 subId = decoder.openElement(ELEM_SCOPE); Scope *parentScope = parseParentTag(decoder); - attachScope(newScope,parentScope); + attachScope(owner.release(),parentScope); newScope->decode(decoder); decoder.closeElement(subId); } diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/error.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/error.hh index f61227fef0..d294a993a3 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/error.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/error.hh @@ -33,6 +33,7 @@ #include #include #include +#include namespace ghidra { @@ -65,6 +66,7 @@ using std::max; using std::to_string; using std::piecewise_construct; using std::forward_as_tuple; +using std::unique_ptr; /// \brief The lowest level error generated by the decompiler diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/flow.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/flow.cc index b16f794910..0add3cc173 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/flow.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/flow.cc @@ -682,8 +682,8 @@ bool FlowInfo::setupCallSpecs(PcodeOp *op,FuncCallSpecs *fc) { FuncCallSpecs *res; res = new FuncCallSpecs(op); - data.opSetInput(op,data.newVarnodeCallSpecs(res),0); qlst.push_back(res); + data.opSetInput(op,data.newVarnodeCallSpecs(res),0); data.getOverride().applyPrototype(data,*res); queryCall(*res); diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/funcdata.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/funcdata.cc index 6ec19de290..9fc8dbbc8a 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/funcdata.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/funcdata.cc @@ -615,9 +615,9 @@ void Funcdata::decodeJumpTable(Decoder &decoder) { uint4 elemId = decoder.openElement(ELEM_JUMPTABLELIST); while(decoder.peekElement() != 0) { - JumpTable *jt = new JumpTable(); + unique_ptr jt(new JumpTable()); jt->decode(decoder); - jumpvec.push_back(jt); + jumpvec.push_back(jt.release()); } decoder.closeElement(elemId); } diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/ghidra_arch.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/ghidra_arch.cc index 34226889c3..813d955051 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/ghidra_arch.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/ghidra_arch.cc @@ -47,14 +47,6 @@ ElementId ELEM_COMMAND_GETSTRINGDATA = ElementId("command_getstringdata",255); ElementId ELEM_COMMAND_GETTRACKEDREGISTERS = ElementId("command_gettrackedregisters",256); ElementId ELEM_COMMAND_GETUSEROPNAME = ElementId("command_getuseropname",257); -/// Catch the signal so the OS doesn't pop up a dialog -/// \param sig is the OS signal (should always be SIGSEGV) -void ArchitectureGhidra::segvHandler(int4 sig) - -{ - exit(1); // Just die - prevents OS from popping-up a dialog -} - /// All communications between the Ghidra client and the decompiler are surrounded /// by alignment bursts. A burst is 1 or more zero bytes followed by /// an 0x01 byte, then followed by a code byte. @@ -746,6 +738,8 @@ void ArchitectureGhidra::getBytes(uint1 *buf,int4 size,const Address &inaddr) if (type == 12) { uint1 *dblbuf = new uint1[size * 2]; sin.read((char *)dblbuf,size*2); + if (sin.gcount() != size*2) + throw JavaError("alignment","Could not read expected number of bytes"); for (int4 i=0; i < size; i++) { buf[i] = ((dblbuf[i*2]-'A') << 4) | (dblbuf[i*2 + 1]-'A'); } diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/ghidra_arch.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/ghidra_arch.hh index 27ee6cada7..529555a7f6 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/ghidra_arch.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/ghidra_arch.hh @@ -4,9 +4,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -155,7 +155,6 @@ public: void getStringData(vector &buffer,const Address &addr,Datatype *ct,int4 maxBytes,bool &isTrunc); virtual void printMessage(const string &message) const; - static void segvHandler(int4 sig); ///< Handler for a segment violation (SIGSEGV) signal static int4 readToAnyBurst(istream &s); ///< Read the next message protocol marker static bool readBoolStream(istream &s); ///< Read a boolean value from the client static void readStringStream(istream &s,string &res); ///< Receive a string from the client diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/ghidra_process.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/ghidra_process.cc index 9ec6788370..4c41f6bca7 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/ghidra_process.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/ghidra_process.cc @@ -4,9 +4,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -505,6 +505,14 @@ void GhidraDecompCapability::initialize(void) commandmap["setOptions"] = new SetOptions(); } +/// Catch the signal so the OS doesn't pop up a dialog +/// \param sig is the OS signal (should always be SIGSEGV) +static void segvHandler(int4 sig) + +{ + _exit(1); // Don't do any cleanup, just die - prevents OS from popping-up a dialog +} + } // End namespace ghidra int main(int argc,char **argv) @@ -512,7 +520,7 @@ int main(int argc,char **argv) { using namespace ghidra; - signal(SIGSEGV, &ArchitectureGhidra::segvHandler); // Exit on SEGV errors + signal(SIGSEGV, &segvHandler); // Exit on SEGV errors #ifdef _WINDOWS // Force i/o streams to be in binary mode _setmode(_fileno(stdin), _O_BINARY); diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/ifacedecomp.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/ifacedecomp.cc index 04bc55619c..e62ab6ab08 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/ifacedecomp.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/ifacedecomp.cc @@ -1856,12 +1856,12 @@ void IfcProtooverride::execute(istream &s) PrototypePieces pieces; parse_protopieces(pieces,s,dcp->conf); // Parse the prototype from stream - FuncProto *newproto = new FuncProto(); + unique_ptr newproto(new FuncProto()); // Make proto whose storage is internal, not backed by a real scope newproto->setInternal(pieces.model,dcp->conf->types->getTypeVoid()); newproto->setPieces(pieces); - dcp->fd->getOverride().insertProtoOverride(callpoint,newproto); + dcp->fd->getOverride().insertProtoOverride(callpoint,newproto.release()); dcp->fd->clear(); // Clear any analysis (this leaves overrides intact) } diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/ifaceterm.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/ifaceterm.cc index 20ca9f663a..3d84ebbf2d 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/ifaceterm.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/ifaceterm.cc @@ -4,9 +4,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -249,7 +249,7 @@ void IfaceTerm::pushScript(istream *iptr,const string &newprompt) { inputstack.push_back(sptr); sptr = iptr; - IfaceStatus::pushScript(iptr,newprompt); + IfaceStatus::pushScript((istream *)0,newprompt); } void IfaceTerm::popScript(void) diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/interface.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/interface.cc index 85f5f91df3..ab23a13cb7 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/interface.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/interface.cc @@ -4,9 +4,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -145,8 +145,10 @@ void IfaceStatus::pushScript(const string &filename,const string &newprompt) { ifstream *s = new ifstream(filename.c_str()); - if (!*s) + if (!*s) { + delete s; throw IfaceParseError("Unable to open script file: "+filename); + } pushScript(s,newprompt); } @@ -159,6 +161,10 @@ void IfaceStatus::pushScript(const string &filename,const string &newprompt) void IfaceStatus::pushScript(istream *iptr,const string &newprompt) { + if (iptr != (istream *)0) { + delete iptr; + throw IfaceExecutionError("Unable to read script from stream on this interface"); + } promptstack.push_back(prompt); uint4 flags = 0; if (errorisdone) diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/jumptable.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/jumptable.cc index 936bd5b8aa..42b10f0e99 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/jumptable.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/jumptable.cc @@ -2482,11 +2482,11 @@ void JumpTable::setOverride(const vector
&addrtable,const Address &nadd if (jmodel != (JumpModel *)0) delete jmodel; - JumpBasicOverride *override; - jmodel = override = new JumpBasicOverride(this); - override->setAddresses(addrtable); - override->setNorm(naddr,h); - override->setStartingValue(sv); + JumpBasicOverride *jumpOverride; + jmodel = jumpOverride = new JumpBasicOverride(this); + jumpOverride->setAddresses(addrtable); + jumpOverride->setNorm(naddr,h); + jumpOverride->setStartingValue(sv); } /// \brief Get the index of the i-th address table entry that corresponds to the given basic-block diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/loadimage.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/loadimage.cc index 87bcb5de89..558229946c 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/loadimage.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/loadimage.cc @@ -4,9 +4,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -30,8 +30,6 @@ uint1 *LoadImage::load(int4 size,const Address &addr) { uint1 *buf = new uint1[ size ]; - if (buf == (uint1 *)0) - throw LowlevelError("Out of memory"); loadFill(buf,size,addr); return buf; } @@ -62,6 +60,7 @@ void RawLoadImage::open(void) thefile = new ifstream(filename.c_str()); if (!(*thefile)) { string errmsg = "Unable to open raw image file: "+filename; + delete thefile; throw LowlevelError(errmsg); } thefile->seekg(0,ios::end); diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/marshal.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/marshal.cc index f1a43d865a..66b1562328 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/marshal.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/marshal.cc @@ -689,7 +689,10 @@ void PackedDecode::endIngest(int4 bufPos) } uint1 *buf = inStream.back().start; buf[bufPos] = ELEMENT_END; + } else { + throw DecoderError("Ended ingestion without any input"); } + } PackedDecode::~PackedDecode(void) @@ -961,11 +964,10 @@ string PackedDecode::readString(void) attributeRead = true; throw DecoderError("Expecting string attribute"); } - int4 length = readLengthCode(typeByte); - length = readInteger(length); + uint8 length = readInteger(readLengthCode(typeByte)); attributeRead = true; - int4 curLen = curPos.end - curPos.current; + uint8 curLen = curPos.end - curPos.current; if (curLen >= length) { string res((const char *)curPos.current,length); advancePosition(curPos, length); @@ -1002,10 +1004,12 @@ AddrSpace *PackedDecode::readSpace(void) getNextByte(curPos); uint1 typeByte = getNextByte(curPos); uint4 typeCode = typeByte >> TYPECODE_SHIFT; - int4 res; AddrSpace *spc; if (typeCode == TYPECODE_ADDRESSSPACE) { - res = readInteger(readLengthCode(typeByte)); + uint8 res = readInteger(readLengthCode(typeByte)); + if (res >= spcManager->numSpaces()) + throw DecoderError("Invalid address space index"); + spc = spcManager->getSpace(res); if (spc == (AddrSpace *)0) throw DecoderError("Unknown address space index"); diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/marshal.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/marshal.hh index 3b0ec0e4cc..9817f7b013 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/marshal.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/marshal.hh @@ -536,7 +536,7 @@ private: uint1 getByte(Position &pos) { return *pos.current; } ///< Get the byte at the current position, do not advance uint1 getBytePlus1(Position &pos); ///< Get the byte following the current byte, do not advance position uint1 getNextByte(Position &pos); ///< Get the byte at the current position and advance to the next byte - void advancePosition(Position &pos,int4 skip); ///< Advance the position by the given number of bytes + void advancePosition(Position &pos,uint4 skip); ///< Advance the position by the given number of bytes uint8 readInteger(int4 len); ///< Read an integer from the \e current position given its length in bytes uint4 readLengthCode(uint1 typeByte) { return ((uint4)typeByte & PackedFormat::LENGTHCODE_MASK); } ///< Extract length code from type byte void findMatchingAttribute(const AttributeId &attribId); ///< Find attribute matching the given id in open element @@ -631,7 +631,7 @@ inline uint1 PackedDecode::getNextByte(Position &pos) /// An exception is thrown of position is advanced past the end of the stream /// \param pos is the position being advanced /// \param skip is the number of bytes to advance -inline void PackedDecode::advancePosition(Position &pos,int4 skip) +inline void PackedDecode::advancePosition(Position &pos,uint4 skip) { while(pos.end - pos.current <= skip) { diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/modelrules.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/modelrules.cc index 2335bc012d..3f4bb8ef35 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/modelrules.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/modelrules.cc @@ -252,23 +252,23 @@ PrimitiveExtractor::PrimitiveExtractor(Datatype *dt,bool unionIllegal,int offset DatatypeFilter *DatatypeFilter::decodeFilter(Decoder &decoder) { - DatatypeFilter *filter; + unique_ptr filter; uint4 elemId = decoder.openElement(ELEM_DATATYPE); string nm = decoder.readString(ATTRIB_NAME); if (nm == "any") { - filter = new SizeRestrictedFilter(); + filter.reset(new SizeRestrictedFilter()); } else if (nm == "homogeneous-float-aggregate") { - filter = new HomogeneousAggregate(TYPE_FLOAT,4,0,0); + filter.reset(new HomogeneousAggregate(TYPE_FLOAT,4,0,0)); } else { // If no other name matches, assume this is a metatype type_metatype meta = string2metatype(nm); - filter = new MetaTypeFilter(meta); + filter.reset(new MetaTypeFilter(meta)); } filter->decode(decoder); decoder.closeElement(elemId); - return filter; + return filter.release(); } /// Parse the given string as a comma or space separated list of decimal integers, @@ -451,18 +451,18 @@ void HomogeneousAggregate::decode(Decoder &decoder) QualifierFilter *QualifierFilter::decodeFilter(Decoder &decoder) { - QualifierFilter *filter; + unique_ptr filter; uint4 elemId = decoder.peekElement(); if (elemId == ELEM_VARARGS) - filter = new VarargsFilter(); + filter.reset(new VarargsFilter()); else if (elemId == ELEM_POSITION) - filter = new PositionMatchFilter(-1); + filter.reset(new PositionMatchFilter(-1)); else if (elemId == ELEM_DATATYPE_AT) - filter = new DatatypeMatchFilter(); + filter.reset(new DatatypeMatchFilter()); else return (QualifierFilter *)0; filter->decode(decoder); - return filter; + return filter.release(); } /// The AndFilter assumes ownership of all the filters in the array and the original vector is cleared @@ -592,32 +592,32 @@ bool AssignAction::fillinOutputMap(ParamActive *active) const AssignAction *AssignAction::decodeAction(Decoder &decoder,const ParamListStandard *res) { - AssignAction *action; + unique_ptr action; uint4 elemId = decoder.peekElement(); if (elemId == ELEM_GOTO_STACK) - action = new GotoStack(res,0); + action.reset(new GotoStack(res,0)); else if (elemId == ELEM_JOIN) { - action = new MultiSlotAssign(res); + action.reset(new MultiSlotAssign(res)); } else if (elemId == ELEM_CONSUME) { - action = new ConsumeAs(TYPECLASS_GENERAL,res); + action.reset(new ConsumeAs(TYPECLASS_GENERAL,res)); } else if (elemId == ELEM_CONVERT_TO_PTR) { - action = new ConvertToPointer(res); + action.reset(new ConvertToPointer(res)); } else if (elemId == ELEM_HIDDEN_RETURN) { - action = new HiddenReturnAssign(res,hiddenret_specialreg); + action.reset(new HiddenReturnAssign(res,hiddenret_specialreg)); } else if (elemId == ELEM_JOIN_PER_PRIMITIVE) { - action = new MultiMemberAssign(TYPECLASS_GENERAL,false,res->isBigEndian(),res); + action.reset(new MultiMemberAssign(TYPECLASS_GENERAL,false,res->isBigEndian(),res)); } else if (elemId == ELEM_JOIN_DUAL_CLASS) { - action = new MultiSlotDualAssign(res); + action.reset(new MultiSlotDualAssign(res)); } else throw DecoderError("Expecting model rule action"); action->decode(decoder); - return action; + return action.release(); } /// \brief Read the next model rule precondition element from the stream @@ -629,18 +629,18 @@ AssignAction *AssignAction::decodeAction(Decoder &decoder,const ParamListStandar /// \return the new precondition, or null if no more preconditions are in the stream AssignAction *AssignAction::decodePrecondition(Decoder &decoder,const ParamListStandard *res) { - AssignAction *action; + unique_ptr action; uint4 elemId = decoder.peekElement(); if (elemId == ELEM_CONSUME_EXTRA) { - action = new ConsumeExtra(res); + action.reset(new ConsumeExtra(res)); } else { return (AssignAction *)0; } action->decode(decoder); - return action; + return action.release(); } /// \brief Read the next model rule sideeffect element from the stream @@ -653,22 +653,22 @@ AssignAction *AssignAction::decodePrecondition(Decoder &decoder,const ParamListS AssignAction *AssignAction::decodeSideeffect(Decoder &decoder,const ParamListStandard *res) { - AssignAction *action; + unique_ptr action; uint4 elemId = decoder.peekElement(); if (elemId == ELEM_CONSUME_EXTRA) { - action = new ConsumeExtra(res); + action.reset(new ConsumeExtra(res)); } else if (elemId == ELEM_EXTRA_STACK) { - action = new ExtraStack(res); + action.reset(new ExtraStack(res)); } else if (elemId == ELEM_CONSUME_REMAINING) { - action = new ConsumeRemaining(res); + action.reset(new ConsumeRemaining(res)); } else throw DecoderError("Expecting model rule sideeffect"); action->decode(decoder); - return action; + return action.release(); } /// \brief Truncate a tiling by a given number of bytes @@ -1695,9 +1695,9 @@ void ModelRule::decode(Decoder &decoder,const ParamListStandard *res) qualifier = new AndFilter(qualifiers); } for (;;) { - AssignAction *precond = AssignAction::decodePrecondition(decoder, res); - if (precond == (AssignAction *)0) - break; + AssignAction *precond = AssignAction::decodePrecondition(decoder, res); + if (precond == (AssignAction *)0) + break; preconditions.push_back(precond); } assign = AssignAction::decodeAction(decoder, res); diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/multiprecision.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/multiprecision.cc index 80623beb2e..81fd99f38f 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/multiprecision.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/multiprecision.cc @@ -4,9 +4,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -231,7 +231,7 @@ static void shift_right(uint4 *arr,int4 size,int4 sa) /// /// The numerator and denominator, expressed in 32-bit \e digits, are provided. /// The algorithm calculates the quotient and the remainder is left in the array originally -/// containing the numerator. +/// containing the numerator. We assume m > n > 0 and u[n-1] >= v[n-1] > 0. /// \param m is the number of 32-bit digits in the numerator /// \param n is the number of 32-bit digits in the denominator /// \param u is the numerator and will hold the remainder @@ -311,8 +311,6 @@ void udiv128(uint8 *numer,uint8 *denom,uint8 *quotient_res,uint8 *remainder_res) remainder_res[1] = numer[1]; return; } - u[m] = 0; - m += 1; // Extend u array by 1 to account for normalization if (n == 1) { uint4 d = v[0]; uint4 rem = 0; @@ -325,10 +323,13 @@ void udiv128(uint8 *numer,uint8 *denom,uint8 *quotient_res,uint8 *remainder_res) u[0] = rem; // Last carry is final remainder } else { + u[m] = 0; + m += 1; // Temporarily extend u array by 1 to allow for normalization knuth_algorithm_d(m,n,u,v,q); + m -= 1; // Remove the extension } - pack32_64(2,m-n,quotient_res,q); - pack32_64(2,m-1,remainder_res,u); + pack32_64(2,m-n+1,quotient_res,q); + pack32_64(2,m,remainder_res,u); } } // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/override.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/override.cc index f6fd0f5524..0c2b57342f 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/override.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/override.cc @@ -4,9 +4,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -367,10 +367,10 @@ void Override::decode(Decoder &decoder,Architecture *glb) } else if (subId == ELEM_PROTOOVERRIDE) { Address callpoint = Address::decode(decoder); - FuncProto *fp = new FuncProto(); + unique_ptr fp(new FuncProto()); fp->setInternal(glb->defaultfp,glb->types->getTypeVoid()); fp->decode(decoder,glb); - insertProtoOverride(callpoint,fp); + insertProtoOverride(callpoint,fp.release()); } else if (subId == ELEM_FORCEGOTO) { Address targetpc = Address::decode(decoder); diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/pcoderaw.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/pcoderaw.cc index 58d50ac8ea..dd589b62c2 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/pcoderaw.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/pcoderaw.cc @@ -96,7 +96,7 @@ bool VarnodeData::isContiguous(const VarnodeData &lo) const OpCode PcodeOpRaw::decode(Decoder &decoder,int4 isize,VarnodeData *invar,VarnodeData **outvar) { - OpCode opcode = (OpCode)decoder.readSignedInteger(ATTRIB_CODE); + OpCode opcode = decoder.readOpcode(ATTRIB_CODE); uint4 subId = decoder.peekElement(); if (subId == ELEM_VOID) { decoder.openElement(); diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/raw_arch.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/raw_arch.cc index 9e4169cc18..48dcc8b1b4 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/raw_arch.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/raw_arch.cc @@ -4,9 +4,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -55,14 +55,12 @@ bool RawBinaryArchitectureCapability::isXmlMatch(Document *doc) const void RawBinaryArchitecture::buildLoader(DocumentStorage &store) { - RawLoadImage *ldr; - collectSpecFiles(*errorstream); - ldr = new RawLoadImage(getFilename()); + unique_ptr ldr(new RawLoadImage(getFilename())); ldr->open(); if (adjustvma != 0) ldr->adjustVma(adjustvma); - loader = ldr; + loader = ldr.release(); } void RawBinaryArchitecture::resolveArchitecture(void) diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/semantics.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/semantics.cc index 18e2ff8ba1..7b06da8e0b 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/semantics.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/semantics.cc @@ -721,8 +721,8 @@ void OpTpl::decode(Decoder &decoder) } while(decoder.peekElement() != 0) { VarnodeTpl *vn = new VarnodeTpl(); - vn->decode(decoder); input.push_back(vn); + vn->decode(decoder); } decoder.closeElement(el); } @@ -915,8 +915,8 @@ int4 ConstructTpl::decode(Decoder &decoder) } while(decoder.peekElement() != 0) { OpTpl *op = new OpTpl(); - op->decode(decoder); vec.push_back(op); + op->decode(decoder); } decoder.closeElement(el); return sectionid; diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/semantics.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/semantics.hh index b53b18797d..2a768a7bef 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/semantics.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/semantics.hh @@ -142,7 +142,7 @@ class OpTpl { OpCode opc; vector input; public: - OpTpl(void) {} + OpTpl(void) : output(nullptr) {} OpTpl(OpCode oc) { opc = oc; output = (VarnodeTpl *)0; } ~OpTpl(void); VarnodeTpl *getOut(void) const { return output; } diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/sleigh.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/sleigh.cc index 29ba4c4926..f6b718d6e0 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/sleigh.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/sleigh.cc @@ -452,9 +452,9 @@ void DisassemblyCache::initialize(int4 min,int4 hashsize) nextfree = 0; hashtable = new ParserContext *[hashsize]; for(int4 i=0;iinitialize(constspace); - list[i] = pos; + ParserContext *pos = new ParserContext(contextcache,translate); + list[i] = pos; + pos->initialize(constspace); } ParserContext *pos = list[0]; for(int4 i=0;isetMainSection(vec->getMainSection()); + big->setMainSection(vec->releaseMainSection()); int4 max = vec->getMaxId(); for(int4 i=0;igetNamedSection(i); + ConstructTpl *section = vec->releaseNamedSection(i); if (section != (ConstructTpl *)0) big->setNamedSection(section,i); } @@ -3691,6 +3722,9 @@ void SleighCompile::buildConstructor(Constructor *big,PatternEquation *pateq,vec delete contvec; } } + else { + PatternEquation::release(pateq); + } symtab.popScope(); // In all cases pop scope } @@ -3751,6 +3785,7 @@ int4 SleighCompile::run_compilation(const string &filein,const string &fileout) try { int4 parseres = sleighparse(); // Try to parse fclose(sleighin); + sleighlex_destroy(); // Make sure lexer is reset so we can parse multiple files if (parseres==0) process(); // Do all the post-processing if ((parseres==0)&&(numErrors()==0)) { // If no errors @@ -3777,7 +3812,6 @@ int4 SleighCompile::run_compilation(const string &filein,const string &fileout) cerr << "No output produced" < named; ///< Named sections accessed by index public: - SectionVector(ConstructTpl *rtl,SymbolScope *scope); ///< Constructor - ConstructTpl *getMainSection(void) const { return main.section; } ///< Get the \e main section - ConstructTpl *getNamedSection(int4 index) const { return named[index].section; } ///< Get a \e named section by index - RtlPair getMainPair(void) const { return main; } ///< Get the \e main section/namespace pair - RtlPair getNamedPair(int4 i) const { return named[i]; } ///< Get a \e named section/namespace pair by index - void setNextIndex(int4 i) { nextindex = i; } ///< Set the index of the currently parsing \e named section - int4 getMaxId(void) const { return named.size(); } ///< Get the maximum (exclusive) named section index - void append(ConstructTpl *rtl,SymbolScope *scope); ///< Add a new \e named section + SectionVector(ConstructTpl *rtl,SymbolScope *scope); ///< Constructor + ~SectionVector(void); ///< Destructor + ConstructTpl *releaseMainSection(void); ///< Get the \e main section, giving up ownership + ConstructTpl *releaseNamedSection(int4 index); ///< Get a \e named section by index, giving up ownership + RtlPair getMainPair(void) const { return main; } ///< Get the \e main section/namespace pair + RtlPair getNamedPair(int4 i) const { return named[i]; } ///< Get a \e named section/namespace pair by index + void setNextIndex(int4 i) { nextindex = i; } ///< Set the index of the currently parsing \e named section + int4 getMaxId(void) const { return named.size(); } ///< Get the maximum (exclusive) named section index + void append(ConstructTpl *rtl,SymbolScope *scope); ///< Add a new \e named section }; /// \brief Qualities associated (via parsing) with an address space diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/slghparse.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/slghparse.cc index 741525a324..cf50b19372 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/slghparse.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/slghparse.cc @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -/* A Bison parser, made by GNU Bison 3.5.1. */ +/* A Bison parser, made by GNU Bison 3.7.4. */ /* Bison implementation for Yacc-like parsers in C @@ -49,6 +49,10 @@ /* C LALR(1) parser skeleton written by Richard Stallman, by simplifying the original so-called "semantic" parser. */ +/* DO NOT RELY ON FEATURES THAT ARE NOT DOCUMENTED in the manual, + especially those whose name start with YY_ or yy_. They are + private implementation details that can be changed or removed. */ + /* All symbols defined below should begin with yy or YY, to avoid infringing on user name space. This should be done even for local variables, as they might otherwise be expanded by user macros. @@ -56,14 +60,11 @@ define necessary library symbols; they are noted "INFRINGES ON USER NAME SPACE" below. */ -/* Undocumented macros, especially those whose name start with YY_, - are private implementation details. Do not rely on them. */ +/* Identify Bison output, and Bison version. */ +#define YYBISON 30704 -/* Identify Bison output. */ -#define YYBISON 1 - -/* Bison version. */ -#define YYBISON_VERSION "3.5.1" +/* Bison version string. */ +#define YYBISON_VERSION "3.7.4" /* Skeleton name. */ #define YYSKELETON_NAME "yacc.c" @@ -124,212 +125,223 @@ extern int sleigherror(const char *str ); # endif # endif -/* Enabling verbose error messages. */ -#ifdef YYERROR_VERBOSE -# undef YYERROR_VERBOSE -# define YYERROR_VERBOSE 1 -#else -# define YYERROR_VERBOSE 0 -#endif - -/* Use api.header.include to #include this header - instead of duplicating it here. */ -#ifndef YY_SLEIGH_SLGHPARSE_HH_INCLUDED -# define YY_SLEIGH_SLGHPARSE_HH_INCLUDED -/* Debug traces. */ -#ifndef SLEIGHDEBUG -# if defined YYDEBUG -#if 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 SLEIGHTOKENTYPE -# define SLEIGHTOKENTYPE - enum sleightokentype - { - OP_BOOL_OR = 258, - OP_BOOL_AND = 259, - OP_BOOL_XOR = 260, - OP_OR = 261, - OP_XOR = 262, - OP_AND = 263, - OP_EQUAL = 264, - OP_NOTEQUAL = 265, - OP_FEQUAL = 266, - OP_FNOTEQUAL = 267, - OP_GREATEQUAL = 268, - OP_LESSEQUAL = 269, - OP_SLESS = 270, - OP_SGREATEQUAL = 271, - OP_SLESSEQUAL = 272, - OP_SGREAT = 273, - OP_FLESS = 274, - OP_FGREAT = 275, - OP_FLESSEQUAL = 276, - OP_FGREATEQUAL = 277, - OP_LEFT = 278, - OP_RIGHT = 279, - OP_SRIGHT = 280, - OP_FADD = 281, - OP_FSUB = 282, - OP_SDIV = 283, - OP_SREM = 284, - OP_FMULT = 285, - OP_FDIV = 286, - OP_ZEXT = 287, - OP_CARRY = 288, - OP_BORROW = 289, - OP_SEXT = 290, - OP_SCARRY = 291, - OP_SBORROW = 292, - OP_NAN = 293, - OP_ABS = 294, - OP_SQRT = 295, - OP_CEIL = 296, - OP_FLOOR = 297, - OP_ROUND = 298, - OP_INT2FLOAT = 299, - OP_FLOAT2FLOAT = 300, - OP_TRUNC = 301, - OP_CPOOLREF = 302, - OP_NEW = 303, - OP_POPCOUNT = 304, - OP_LZCOUNT = 305, - BADINTEGER = 306, - GOTO_KEY = 307, - CALL_KEY = 308, - RETURN_KEY = 309, - IF_KEY = 310, - DEFINE_KEY = 311, - ATTACH_KEY = 312, - MACRO_KEY = 313, - SPACE_KEY = 314, - TYPE_KEY = 315, - RAM_KEY = 316, - DEFAULT_KEY = 317, - REGISTER_KEY = 318, - ENDIAN_KEY = 319, - WITH_KEY = 320, - ALIGN_KEY = 321, - OP_UNIMPL = 322, - TOKEN_KEY = 323, - SIGNED_KEY = 324, - NOFLOW_KEY = 325, - HEX_KEY = 326, - DEC_KEY = 327, - BIG_KEY = 328, - LITTLE_KEY = 329, - SIZE_KEY = 330, - WORDSIZE_KEY = 331, - OFFSET_KEY = 332, - NAMES_KEY = 333, - VALUES_KEY = 334, - VARIABLES_KEY = 335, - PCODEOP_KEY = 336, - IS_KEY = 337, - LOCAL_KEY = 338, - DELAYSLOT_KEY = 339, - CROSSBUILD_KEY = 340, - EXPORT_KEY = 341, - BUILD_KEY = 342, - CONTEXT_KEY = 343, - ELLIPSIS_KEY = 344, - GLOBALSET_KEY = 345, - BITRANGE_KEY = 346, - CHAR = 347, - INTEGER = 348, - INTB = 349, - STRING = 350, - SYMBOLSTRING = 351, - SPACESYM = 352, - SECTIONSYM = 353, - TOKENSYM = 354, - USEROPSYM = 355, - VALUESYM = 356, - VALUEMAPSYM = 357, - CONTEXTSYM = 358, - NAMESYM = 359, - VARSYM = 360, - BITSYM = 361, - SPECSYM = 362, - VARLISTSYM = 363, - OPERANDSYM = 364, - JUMPSYM = 365, - MACROSYM = 366, - LABELSYM = 367, - SUBTABLESYM = 368 - }; -#endif - -/* Value type. */ -#if ! defined SLEIGHSTYPE && ! defined SLEIGHSTYPE_IS_DECLARED -union SLEIGHSTYPE +#include "slghparse.hh" +/* Symbol kind. */ +enum yysymbol_kind_t { - - char ch; - uintb *i; - intb *big; - string *str; - vector *strlist; - vector *biglist; - vector *param; - SpaceQuality *spacequal; - FieldQuality *fieldqual; - StarQuality *starqual; - VarnodeTpl *varnode; - ExprTree *tree; - vector *stmt; - ConstructTpl *sem; - SectionVector *sectionstart; - Constructor *construct; - PatternEquation *pateq; - PatternExpression *patexp; - - vector *symlist; - vector *contop; - SleighSymbol *anysym; - SpaceSymbol *spacesym; - SectionSymbol *sectionsym; - TokenSymbol *tokensym; - UserOpSymbol *useropsym; - MacroSymbol *macrosym; - LabelSymbol *labelsym; - SubtableSymbol *subtablesym; - OperandSymbol *operandsym; - VarnodeListSymbol *varlistsym; - VarnodeSymbol *varsym; - BitrangeSymbol *bitsym; - NameSymbol *namesym; - ValueSymbol *valuesym; - ValueMapSymbol *valuemapsym; - ContextSymbol *contextsym; - FamilySymbol *famsym; - SpecificSymbol *specsym; - - + YYSYMBOL_YYEMPTY = -2, + YYSYMBOL_YYEOF = 0, /* "end of file" */ + YYSYMBOL_YYerror = 1, /* error */ + YYSYMBOL_YYUNDEF = 2, /* "invalid token" */ + YYSYMBOL_OP_BOOL_OR = 3, /* OP_BOOL_OR */ + YYSYMBOL_OP_BOOL_AND = 4, /* OP_BOOL_AND */ + YYSYMBOL_OP_BOOL_XOR = 5, /* OP_BOOL_XOR */ + YYSYMBOL_6_ = 6, /* '|' */ + YYSYMBOL_OP_OR = 7, /* OP_OR */ + YYSYMBOL_8_ = 8, /* ';' */ + YYSYMBOL_9_ = 9, /* '^' */ + YYSYMBOL_OP_XOR = 10, /* OP_XOR */ + YYSYMBOL_11_ = 11, /* '&' */ + YYSYMBOL_OP_AND = 12, /* OP_AND */ + YYSYMBOL_OP_EQUAL = 13, /* OP_EQUAL */ + YYSYMBOL_OP_NOTEQUAL = 14, /* OP_NOTEQUAL */ + YYSYMBOL_OP_FEQUAL = 15, /* OP_FEQUAL */ + YYSYMBOL_OP_FNOTEQUAL = 16, /* OP_FNOTEQUAL */ + YYSYMBOL_17_ = 17, /* '<' */ + YYSYMBOL_18_ = 18, /* '>' */ + YYSYMBOL_OP_GREATEQUAL = 19, /* OP_GREATEQUAL */ + YYSYMBOL_OP_LESSEQUAL = 20, /* OP_LESSEQUAL */ + YYSYMBOL_OP_SLESS = 21, /* OP_SLESS */ + YYSYMBOL_OP_SGREATEQUAL = 22, /* OP_SGREATEQUAL */ + YYSYMBOL_OP_SLESSEQUAL = 23, /* OP_SLESSEQUAL */ + YYSYMBOL_OP_SGREAT = 24, /* OP_SGREAT */ + YYSYMBOL_OP_FLESS = 25, /* OP_FLESS */ + YYSYMBOL_OP_FGREAT = 26, /* OP_FGREAT */ + YYSYMBOL_OP_FLESSEQUAL = 27, /* OP_FLESSEQUAL */ + YYSYMBOL_OP_FGREATEQUAL = 28, /* OP_FGREATEQUAL */ + YYSYMBOL_OP_LEFT = 29, /* OP_LEFT */ + YYSYMBOL_OP_RIGHT = 30, /* OP_RIGHT */ + YYSYMBOL_OP_SRIGHT = 31, /* OP_SRIGHT */ + YYSYMBOL_32_ = 32, /* '+' */ + YYSYMBOL_33_ = 33, /* '-' */ + YYSYMBOL_OP_FADD = 34, /* OP_FADD */ + YYSYMBOL_OP_FSUB = 35, /* OP_FSUB */ + YYSYMBOL_36_ = 36, /* '*' */ + YYSYMBOL_37_ = 37, /* '/' */ + YYSYMBOL_38_ = 38, /* '%' */ + YYSYMBOL_OP_SDIV = 39, /* OP_SDIV */ + YYSYMBOL_OP_SREM = 40, /* OP_SREM */ + YYSYMBOL_OP_FMULT = 41, /* OP_FMULT */ + YYSYMBOL_OP_FDIV = 42, /* OP_FDIV */ + YYSYMBOL_43_ = 43, /* '!' */ + YYSYMBOL_44_ = 44, /* '~' */ + YYSYMBOL_OP_ZEXT = 45, /* OP_ZEXT */ + YYSYMBOL_OP_CARRY = 46, /* OP_CARRY */ + YYSYMBOL_OP_BORROW = 47, /* OP_BORROW */ + YYSYMBOL_OP_SEXT = 48, /* OP_SEXT */ + YYSYMBOL_OP_SCARRY = 49, /* OP_SCARRY */ + YYSYMBOL_OP_SBORROW = 50, /* OP_SBORROW */ + YYSYMBOL_OP_NAN = 51, /* OP_NAN */ + YYSYMBOL_OP_ABS = 52, /* OP_ABS */ + YYSYMBOL_OP_SQRT = 53, /* OP_SQRT */ + YYSYMBOL_OP_CEIL = 54, /* OP_CEIL */ + YYSYMBOL_OP_FLOOR = 55, /* OP_FLOOR */ + YYSYMBOL_OP_ROUND = 56, /* OP_ROUND */ + YYSYMBOL_OP_INT2FLOAT = 57, /* OP_INT2FLOAT */ + YYSYMBOL_OP_FLOAT2FLOAT = 58, /* OP_FLOAT2FLOAT */ + YYSYMBOL_OP_TRUNC = 59, /* OP_TRUNC */ + YYSYMBOL_OP_CPOOLREF = 60, /* OP_CPOOLREF */ + YYSYMBOL_OP_NEW = 61, /* OP_NEW */ + YYSYMBOL_OP_POPCOUNT = 62, /* OP_POPCOUNT */ + YYSYMBOL_OP_LZCOUNT = 63, /* OP_LZCOUNT */ + YYSYMBOL_BADINTEGER = 64, /* BADINTEGER */ + YYSYMBOL_GOTO_KEY = 65, /* GOTO_KEY */ + YYSYMBOL_CALL_KEY = 66, /* CALL_KEY */ + YYSYMBOL_RETURN_KEY = 67, /* RETURN_KEY */ + YYSYMBOL_IF_KEY = 68, /* IF_KEY */ + YYSYMBOL_DEFINE_KEY = 69, /* DEFINE_KEY */ + YYSYMBOL_ATTACH_KEY = 70, /* ATTACH_KEY */ + YYSYMBOL_MACRO_KEY = 71, /* MACRO_KEY */ + YYSYMBOL_SPACE_KEY = 72, /* SPACE_KEY */ + YYSYMBOL_TYPE_KEY = 73, /* TYPE_KEY */ + YYSYMBOL_RAM_KEY = 74, /* RAM_KEY */ + YYSYMBOL_DEFAULT_KEY = 75, /* DEFAULT_KEY */ + YYSYMBOL_REGISTER_KEY = 76, /* REGISTER_KEY */ + YYSYMBOL_ENDIAN_KEY = 77, /* ENDIAN_KEY */ + YYSYMBOL_WITH_KEY = 78, /* WITH_KEY */ + YYSYMBOL_ALIGN_KEY = 79, /* ALIGN_KEY */ + YYSYMBOL_OP_UNIMPL = 80, /* OP_UNIMPL */ + YYSYMBOL_TOKEN_KEY = 81, /* TOKEN_KEY */ + YYSYMBOL_SIGNED_KEY = 82, /* SIGNED_KEY */ + YYSYMBOL_NOFLOW_KEY = 83, /* NOFLOW_KEY */ + YYSYMBOL_HEX_KEY = 84, /* HEX_KEY */ + YYSYMBOL_DEC_KEY = 85, /* DEC_KEY */ + YYSYMBOL_BIG_KEY = 86, /* BIG_KEY */ + YYSYMBOL_LITTLE_KEY = 87, /* LITTLE_KEY */ + YYSYMBOL_SIZE_KEY = 88, /* SIZE_KEY */ + YYSYMBOL_WORDSIZE_KEY = 89, /* WORDSIZE_KEY */ + YYSYMBOL_OFFSET_KEY = 90, /* OFFSET_KEY */ + YYSYMBOL_NAMES_KEY = 91, /* NAMES_KEY */ + YYSYMBOL_VALUES_KEY = 92, /* VALUES_KEY */ + YYSYMBOL_VARIABLES_KEY = 93, /* VARIABLES_KEY */ + YYSYMBOL_PCODEOP_KEY = 94, /* PCODEOP_KEY */ + YYSYMBOL_IS_KEY = 95, /* IS_KEY */ + YYSYMBOL_LOCAL_KEY = 96, /* LOCAL_KEY */ + YYSYMBOL_DELAYSLOT_KEY = 97, /* DELAYSLOT_KEY */ + YYSYMBOL_CROSSBUILD_KEY = 98, /* CROSSBUILD_KEY */ + YYSYMBOL_EXPORT_KEY = 99, /* EXPORT_KEY */ + YYSYMBOL_BUILD_KEY = 100, /* BUILD_KEY */ + YYSYMBOL_CONTEXT_KEY = 101, /* CONTEXT_KEY */ + YYSYMBOL_ELLIPSIS_KEY = 102, /* ELLIPSIS_KEY */ + YYSYMBOL_GLOBALSET_KEY = 103, /* GLOBALSET_KEY */ + YYSYMBOL_BITRANGE_KEY = 104, /* BITRANGE_KEY */ + YYSYMBOL_CHAR = 105, /* CHAR */ + YYSYMBOL_INTEGER = 106, /* INTEGER */ + YYSYMBOL_INTB = 107, /* INTB */ + YYSYMBOL_STRING = 108, /* STRING */ + YYSYMBOL_SYMBOLSTRING = 109, /* SYMBOLSTRING */ + YYSYMBOL_SPACESYM = 110, /* SPACESYM */ + YYSYMBOL_SECTIONSYM = 111, /* SECTIONSYM */ + YYSYMBOL_TOKENSYM = 112, /* TOKENSYM */ + YYSYMBOL_USEROPSYM = 113, /* USEROPSYM */ + YYSYMBOL_VALUESYM = 114, /* VALUESYM */ + YYSYMBOL_VALUEMAPSYM = 115, /* VALUEMAPSYM */ + YYSYMBOL_CONTEXTSYM = 116, /* CONTEXTSYM */ + YYSYMBOL_NAMESYM = 117, /* NAMESYM */ + YYSYMBOL_VARSYM = 118, /* VARSYM */ + YYSYMBOL_BITSYM = 119, /* BITSYM */ + YYSYMBOL_SPECSYM = 120, /* SPECSYM */ + YYSYMBOL_VARLISTSYM = 121, /* VARLISTSYM */ + YYSYMBOL_OPERANDSYM = 122, /* OPERANDSYM */ + YYSYMBOL_JUMPSYM = 123, /* JUMPSYM */ + YYSYMBOL_MACROSYM = 124, /* MACROSYM */ + YYSYMBOL_LABELSYM = 125, /* LABELSYM */ + YYSYMBOL_SUBTABLESYM = 126, /* SUBTABLESYM */ + YYSYMBOL_127_ = 127, /* '}' */ + YYSYMBOL_128_ = 128, /* '=' */ + YYSYMBOL_129_ = 129, /* '(' */ + YYSYMBOL_130_ = 130, /* ')' */ + YYSYMBOL_131_ = 131, /* ',' */ + YYSYMBOL_132_ = 132, /* '[' */ + YYSYMBOL_133_ = 133, /* ']' */ + YYSYMBOL_134_ = 134, /* '{' */ + YYSYMBOL_135_ = 135, /* ':' */ + YYSYMBOL_136_ = 136, /* ' ' */ + YYSYMBOL_YYACCEPT = 137, /* $accept */ + YYSYMBOL_spec = 138, /* spec */ + YYSYMBOL_definition = 139, /* definition */ + YYSYMBOL_constructorlike = 140, /* constructorlike */ + YYSYMBOL_endiandef = 141, /* endiandef */ + YYSYMBOL_aligndef = 142, /* aligndef */ + YYSYMBOL_tokendef = 143, /* tokendef */ + YYSYMBOL_tokenprop = 144, /* tokenprop */ + YYSYMBOL_contextdef = 145, /* contextdef */ + YYSYMBOL_contextprop = 146, /* contextprop */ + YYSYMBOL_fielddef = 147, /* fielddef */ + YYSYMBOL_contextfielddef = 148, /* contextfielddef */ + YYSYMBOL_spacedef = 149, /* spacedef */ + YYSYMBOL_spaceprop = 150, /* spaceprop */ + YYSYMBOL_varnodedef = 151, /* varnodedef */ + YYSYMBOL_bitrangedef = 152, /* bitrangedef */ + YYSYMBOL_bitrangelist = 153, /* bitrangelist */ + YYSYMBOL_bitrangesingle = 154, /* bitrangesingle */ + YYSYMBOL_pcodeopdef = 155, /* pcodeopdef */ + YYSYMBOL_valueattach = 156, /* valueattach */ + YYSYMBOL_nameattach = 157, /* nameattach */ + YYSYMBOL_varattach = 158, /* varattach */ + YYSYMBOL_macrodef = 159, /* macrodef */ + YYSYMBOL_withblockstart = 160, /* withblockstart */ + YYSYMBOL_withblockmid = 161, /* withblockmid */ + YYSYMBOL_withblock = 162, /* withblock */ + YYSYMBOL_id_or_nil = 163, /* id_or_nil */ + YYSYMBOL_bitpat_or_nil = 164, /* bitpat_or_nil */ + YYSYMBOL_macrostart = 165, /* macrostart */ + YYSYMBOL_rtlbody = 166, /* rtlbody */ + YYSYMBOL_constructor = 167, /* constructor */ + YYSYMBOL_constructprint = 168, /* constructprint */ + YYSYMBOL_subtablestart = 169, /* subtablestart */ + YYSYMBOL_pexpression = 170, /* pexpression */ + YYSYMBOL_pequation = 171, /* pequation */ + YYSYMBOL_elleq = 172, /* elleq */ + YYSYMBOL_ellrt = 173, /* ellrt */ + YYSYMBOL_atomic = 174, /* atomic */ + YYSYMBOL_constraint = 175, /* constraint */ + YYSYMBOL_contextblock = 176, /* contextblock */ + YYSYMBOL_contextlist = 177, /* contextlist */ + YYSYMBOL_section_def = 178, /* section_def */ + YYSYMBOL_rtlfirstsection = 179, /* rtlfirstsection */ + YYSYMBOL_rtlcontinue = 180, /* rtlcontinue */ + YYSYMBOL_rtl = 181, /* rtl */ + YYSYMBOL_rtlmid = 182, /* rtlmid */ + YYSYMBOL_statement = 183, /* statement */ + YYSYMBOL_expr = 184, /* expr */ + YYSYMBOL_sizedstar = 185, /* sizedstar */ + YYSYMBOL_jumpdest = 186, /* jumpdest */ + YYSYMBOL_varnode = 187, /* varnode */ + YYSYMBOL_integervarnode = 188, /* integervarnode */ + YYSYMBOL_lhsvarnode = 189, /* lhsvarnode */ + YYSYMBOL_label = 190, /* label */ + YYSYMBOL_exportvarnode = 191, /* exportvarnode */ + YYSYMBOL_familysymbol = 192, /* familysymbol */ + YYSYMBOL_specificsymbol = 193, /* specificsymbol */ + YYSYMBOL_charstring = 194, /* charstring */ + YYSYMBOL_intblist = 195, /* intblist */ + YYSYMBOL_intbpart = 196, /* intbpart */ + YYSYMBOL_stringlist = 197, /* stringlist */ + YYSYMBOL_stringpart = 198, /* stringpart */ + YYSYMBOL_anystringlist = 199, /* anystringlist */ + YYSYMBOL_anystringpart = 200, /* anystringpart */ + YYSYMBOL_valuelist = 201, /* valuelist */ + YYSYMBOL_valuepart = 202, /* valuepart */ + YYSYMBOL_varlist = 203, /* varlist */ + YYSYMBOL_varpart = 204, /* varpart */ + YYSYMBOL_paramlist = 205, /* paramlist */ + YYSYMBOL_oplist = 206, /* oplist */ + YYSYMBOL_anysymbol = 207 /* anysymbol */ }; -typedef union SLEIGHSTYPE SLEIGHSTYPE; -# define SLEIGHSTYPE_IS_TRIVIAL 1 -# define SLEIGHSTYPE_IS_DECLARED 1 -#endif +typedef enum yysymbol_kind_t yysymbol_kind_t; -extern SLEIGHSTYPE sleighlval; - -int sleighparse (void); - -#endif /* !YY_SLEIGH_SLGHPARSE_HH_INCLUDED */ - #ifdef short @@ -428,6 +440,7 @@ typedef int yytype_uint16; #define YYSIZEOF(X) YY_CAST (YYPTRDIFF_T, sizeof (X)) + /* Stored state numbers (used for stacks). */ typedef yytype_int16 yy_state_t; @@ -446,6 +459,7 @@ typedef int yy_state_fast_t; # endif #endif + #ifndef YY_ATTRIBUTE_PURE # if defined __GNUC__ && 2 < __GNUC__ + (96 <= __GNUC_MINOR__) # define YY_ATTRIBUTE_PURE __attribute__ ((__pure__)) @@ -503,7 +517,7 @@ typedef int yy_state_fast_t; #define YY_ASSERT(E) ((void) (0 && (E))) -#if ! defined yyoverflow || YYERROR_VERBOSE +#if !defined yyoverflow /* The parser invokes alloca or malloc; define the necessary symbols. */ @@ -568,8 +582,7 @@ void free (void *); /* INFRINGES ON USER NAME SPACE */ # endif # endif # endif -#endif /* ! defined yyoverflow || YYERROR_VERBOSE */ - +#endif /* !defined yyoverflow */ #if (! defined yyoverflow \ && (! defined __cplusplus \ @@ -645,14 +658,16 @@ union yyalloc /* YYNSTATES -- Number of states. */ #define YYNSTATES 714 -#define YYUNDEFTOK 2 +/* YYMAXUTOK -- Last valid token kind. */ #define YYMAXUTOK 368 /* YYTRANSLATE(TOKEN-NUM) -- Symbol number corresponding to TOKEN-NUM as returned by yylex, with out-of-bounds checking. */ -#define YYTRANSLATE(YYX) \ - (0 <= (YYX) && (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK) +#define YYTRANSLATE(YYX) \ + (0 <= (YYX) && (YYX) <= YYMAXUTOK \ + ? YY_CAST (yysymbol_kind_t, yytranslate[YYX]) \ + : YYSYMBOL_YYUNDEF) /* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM as returned by yylex. */ @@ -701,64 +716,71 @@ static const yytype_uint8 yytranslate[] = /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */ static const yytype_int16 yyrline[] = { - 0, 155, 155, 156, 157, 158, 160, 161, 162, 163, - 164, 165, 166, 167, 168, 169, 171, 172, 173, 174, - 176, 177, 179, 181, 183, 184, 185, 186, 187, 189, - 191, 192, 195, 196, 197, 198, 199, 201, 202, 203, - 204, 205, 206, 208, 210, 211, 212, 213, 214, 215, - 216, 218, 220, 222, 224, 225, 227, 230, 232, 234, - 236, 238, 241, 243, 244, 245, 247, 249, 250, 251, - 254, 255, 258, 260, 261, 262, 264, 265, 267, 268, - 269, 270, 271, 272, 273, 274, 275, 277, 278, 279, - 280, 282, 284, 287, 288, 289, 290, 291, 292, 293, - 294, 295, 296, 297, 298, 299, 301, 302, 303, 304, - 306, 307, 309, 310, 312, 313, 315, 316, 317, 318, - 319, 320, 321, 324, 325, 326, 327, 329, 330, 332, - 333, 334, 335, 336, 337, 339, 340, 342, 344, 345, - 347, 348, 349, 350, 351, 353, 354, 355, 356, 358, - 359, 360, 361, 362, 363, 364, 365, 366, 367, 368, - 369, 370, 371, 372, 373, 374, 375, 376, 377, 378, - 379, 380, 381, 382, 384, 385, 386, 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, 452, 453, 454, 455, 457, 458, 459, 460, 461, - 462, 463, 465, 466, 467, 468, 470, 471, 472, 473, - 474, 476, 477, 478, 480, 481, 483, 484, 485, 486, - 487, 488, 490, 491, 492, 493, 494, 496, 497, 498, - 499, 501, 502, 504, 505, 506, 508, 509, 510, 512, - 513, 514, 517, 518, 520, 521, 522, 524, 526, 527, - 528, 529, 531, 532, 533, 535, 536, 537, 538, 539, - 541, 542, 544, 545, 547, 548, 551, 552, 553, 555, - 556, 557, 559, 560, 561, 562, 563, 564, 565, 566, - 567, 568, 569, 570, 571, 572, 573 + 0, 163, 163, 164, 165, 166, 168, 169, 170, 171, + 172, 173, 174, 175, 176, 177, 179, 180, 181, 182, + 184, 185, 187, 189, 191, 192, 193, 194, 195, 197, + 199, 200, 203, 204, 205, 206, 207, 209, 210, 211, + 212, 213, 214, 216, 218, 219, 220, 221, 222, 223, + 224, 226, 228, 230, 232, 233, 235, 238, 240, 242, + 244, 246, 249, 251, 252, 253, 255, 257, 258, 259, + 262, 263, 266, 268, 269, 270, 272, 273, 275, 276, + 277, 278, 279, 280, 281, 282, 283, 285, 286, 287, + 288, 290, 292, 295, 296, 297, 298, 299, 300, 301, + 302, 303, 304, 305, 306, 307, 309, 310, 311, 312, + 314, 315, 317, 318, 320, 321, 323, 324, 325, 326, + 327, 328, 329, 332, 333, 334, 335, 337, 338, 340, + 341, 342, 343, 344, 345, 347, 348, 350, 352, 353, + 355, 356, 357, 358, 359, 361, 362, 363, 364, 366, + 367, 368, 369, 370, 371, 372, 373, 374, 375, 376, + 377, 378, 379, 380, 381, 382, 383, 384, 385, 386, + 387, 388, 389, 390, 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, 456, 457, + 458, 460, 461, 462, 463, 465, 466, 467, 468, 469, + 470, 471, 473, 474, 475, 476, 478, 479, 480, 481, + 482, 484, 485, 486, 488, 489, 491, 492, 493, 494, + 495, 496, 498, 499, 500, 501, 502, 504, 505, 506, + 507, 509, 510, 512, 513, 514, 516, 517, 518, 520, + 521, 522, 525, 526, 528, 529, 530, 532, 534, 535, + 536, 537, 539, 540, 541, 543, 544, 545, 546, 547, + 549, 550, 552, 553, 555, 556, 559, 560, 561, 563, + 564, 565, 567, 568, 569, 570, 571, 572, 573, 574, + 575, 576, 577, 578, 579, 580, 581 }; #endif -#if SLEIGHDEBUG || YYERROR_VERBOSE || 0 +/** Accessing symbol of state STATE. */ +#define YY_ACCESSING_SYMBOL(State) YY_CAST (yysymbol_kind_t, yystos[State]) + +#if SLEIGHDEBUG || 0 +/* The user-facing name of the symbol whose (internal) number is + YYSYMBOL. No bounds checking. */ +static const char *yysymbol_name (yysymbol_kind_t yysymbol) YY_ATTRIBUTE_UNUSED; + /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. First, the terminals, then, starting at YYNTOKENS, nonterminals. */ static const char *const yytname[] = { - "$end", "error", "$undefined", "OP_BOOL_OR", "OP_BOOL_AND", - "OP_BOOL_XOR", "'|'", "OP_OR", "';'", "'^'", "OP_XOR", "'&'", "OP_AND", - "OP_EQUAL", "OP_NOTEQUAL", "OP_FEQUAL", "OP_FNOTEQUAL", "'<'", "'>'", - "OP_GREATEQUAL", "OP_LESSEQUAL", "OP_SLESS", "OP_SGREATEQUAL", - "OP_SLESSEQUAL", "OP_SGREAT", "OP_FLESS", "OP_FGREAT", "OP_FLESSEQUAL", - "OP_FGREATEQUAL", "OP_LEFT", "OP_RIGHT", "OP_SRIGHT", "'+'", "'-'", - "OP_FADD", "OP_FSUB", "'*'", "'/'", "'%'", "OP_SDIV", "OP_SREM", - "OP_FMULT", "OP_FDIV", "'!'", "'~'", "OP_ZEXT", "OP_CARRY", "OP_BORROW", - "OP_SEXT", "OP_SCARRY", "OP_SBORROW", "OP_NAN", "OP_ABS", "OP_SQRT", - "OP_CEIL", "OP_FLOOR", "OP_ROUND", "OP_INT2FLOAT", "OP_FLOAT2FLOAT", - "OP_TRUNC", "OP_CPOOLREF", "OP_NEW", "OP_POPCOUNT", "OP_LZCOUNT", - "BADINTEGER", "GOTO_KEY", "CALL_KEY", "RETURN_KEY", "IF_KEY", - "DEFINE_KEY", "ATTACH_KEY", "MACRO_KEY", "SPACE_KEY", "TYPE_KEY", - "RAM_KEY", "DEFAULT_KEY", "REGISTER_KEY", "ENDIAN_KEY", "WITH_KEY", - "ALIGN_KEY", "OP_UNIMPL", "TOKEN_KEY", "SIGNED_KEY", "NOFLOW_KEY", - "HEX_KEY", "DEC_KEY", "BIG_KEY", "LITTLE_KEY", "SIZE_KEY", + "\"end of file\"", "error", "\"invalid token\"", "OP_BOOL_OR", + "OP_BOOL_AND", "OP_BOOL_XOR", "'|'", "OP_OR", "';'", "'^'", "OP_XOR", + "'&'", "OP_AND", "OP_EQUAL", "OP_NOTEQUAL", "OP_FEQUAL", "OP_FNOTEQUAL", + "'<'", "'>'", "OP_GREATEQUAL", "OP_LESSEQUAL", "OP_SLESS", + "OP_SGREATEQUAL", "OP_SLESSEQUAL", "OP_SGREAT", "OP_FLESS", "OP_FGREAT", + "OP_FLESSEQUAL", "OP_FGREATEQUAL", "OP_LEFT", "OP_RIGHT", "OP_SRIGHT", + "'+'", "'-'", "OP_FADD", "OP_FSUB", "'*'", "'/'", "'%'", "OP_SDIV", + "OP_SREM", "OP_FMULT", "OP_FDIV", "'!'", "'~'", "OP_ZEXT", "OP_CARRY", + "OP_BORROW", "OP_SEXT", "OP_SCARRY", "OP_SBORROW", "OP_NAN", "OP_ABS", + "OP_SQRT", "OP_CEIL", "OP_FLOOR", "OP_ROUND", "OP_INT2FLOAT", + "OP_FLOAT2FLOAT", "OP_TRUNC", "OP_CPOOLREF", "OP_NEW", "OP_POPCOUNT", + "OP_LZCOUNT", "BADINTEGER", "GOTO_KEY", "CALL_KEY", "RETURN_KEY", + "IF_KEY", "DEFINE_KEY", "ATTACH_KEY", "MACRO_KEY", "SPACE_KEY", + "TYPE_KEY", "RAM_KEY", "DEFAULT_KEY", "REGISTER_KEY", "ENDIAN_KEY", + "WITH_KEY", "ALIGN_KEY", "OP_UNIMPL", "TOKEN_KEY", "SIGNED_KEY", + "NOFLOW_KEY", "HEX_KEY", "DEC_KEY", "BIG_KEY", "LITTLE_KEY", "SIZE_KEY", "WORDSIZE_KEY", "OFFSET_KEY", "NAMES_KEY", "VALUES_KEY", "VARIABLES_KEY", "PCODEOP_KEY", "IS_KEY", "LOCAL_KEY", "DELAYSLOT_KEY", "CROSSBUILD_KEY", "EXPORT_KEY", "BUILD_KEY", "CONTEXT_KEY", "ELLIPSIS_KEY", @@ -783,9 +805,15 @@ static const char *const yytname[] = "stringpart", "anystringlist", "anystringpart", "valuelist", "valuepart", "varlist", "varpart", "paramlist", "oplist", "anysymbol", YY_NULLPTR }; + +static const char * +yysymbol_name (yysymbol_kind_t yysymbol) +{ + return yytname[yysymbol]; +} #endif -# ifdef YYPRINT +#ifdef YYPRINT /* YYTOKNUM[NUM] -- (External) token number corresponding to the (internal) symbol number NUM (which must be that of a token). */ static const yytype_int16 yytoknum[] = @@ -805,7 +833,7 @@ static const yytype_int16 yytoknum[] = 362, 363, 364, 365, 366, 367, 368, 125, 61, 40, 41, 44, 91, 93, 123, 58, 32 }; -# endif +#endif #define YYPACT_NINF (-293) @@ -1694,10 +1722,10 @@ static const yytype_int8 yyr2[] = }; +enum { YYENOMEM = -2 }; + #define yyerrok (yyerrstatus = 0) -#define yyclearin (yychar = YYEMPTY) -#define YYEMPTY (-2) -#define YYEOF 0 +#define yyclearin (yychar = SLEIGHEMPTY) #define YYACCEPT goto yyacceptlab #define YYABORT goto yyabortlab @@ -1708,7 +1736,7 @@ static const yytype_int8 yyr2[] = #define YYBACKUP(Token, Value) \ do \ - if (yychar == YYEMPTY) \ + if (yychar == SLEIGHEMPTY) \ { \ yychar = (Token); \ yylval = (Value); \ @@ -1723,10 +1751,9 @@ static const yytype_int8 yyr2[] = } \ while (0) -/* Error token number */ -#define YYTERROR 1 -#define YYERRCODE 256 - +/* Backward compatibility with an undocumented macro. + Use SLEIGHerror or SLEIGHUNDEF. */ +#define YYERRCODE SLEIGHUNDEF /* Enable debugging if requested. */ @@ -1744,18 +1771,18 @@ do { \ } while (0) /* This macro is provided for backward compatibility. */ -#ifndef YY_LOCATION_PRINT -# define YY_LOCATION_PRINT(File, Loc) ((void) 0) -#endif +# ifndef YY_LOCATION_PRINT +# define YY_LOCATION_PRINT(File, Loc) ((void) 0) +# endif -# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \ +# define YY_SYMBOL_PRINT(Title, Kind, Value, Location) \ do { \ if (yydebug) \ { \ YYFPRINTF (stderr, "%s ", Title); \ yy_symbol_print (stderr, \ - Type, Value); \ + Kind, Value); \ YYFPRINTF (stderr, "\n"); \ } \ } while (0) @@ -1766,18 +1793,19 @@ do { \ `-----------------------------------*/ static void -yy_symbol_value_print (FILE *yyo, int yytype, YYSTYPE const * const yyvaluep) +yy_symbol_value_print (FILE *yyo, + yysymbol_kind_t yykind, YYSTYPE const * const yyvaluep) { FILE *yyoutput = yyo; YYUSE (yyoutput); if (!yyvaluep) return; # ifdef YYPRINT - if (yytype < YYNTOKENS) - YYPRINT (yyo, yytoknum[yytype], *yyvaluep); + if (yykind < YYNTOKENS) + YYPRINT (yyo, yytoknum[yykind], *yyvaluep); # endif YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN - YYUSE (yytype); + YYUSE (yykind); YY_IGNORE_MAYBE_UNINITIALIZED_END } @@ -1787,12 +1815,13 @@ yy_symbol_value_print (FILE *yyo, int yytype, YYSTYPE const * const yyvaluep) `---------------------------*/ static void -yy_symbol_print (FILE *yyo, int yytype, YYSTYPE const * const yyvaluep) +yy_symbol_print (FILE *yyo, + yysymbol_kind_t yykind, YYSTYPE const * const yyvaluep) { YYFPRINTF (yyo, "%s %s (", - yytype < YYNTOKENS ? "token" : "nterm", yytname[yytype]); + yykind < YYNTOKENS ? "token" : "nterm", yysymbol_name (yykind)); - yy_symbol_value_print (yyo, yytype, yyvaluep); + yy_symbol_value_print (yyo, yykind, yyvaluep); YYFPRINTF (yyo, ")"); } @@ -1825,7 +1854,8 @@ do { \ `------------------------------------------------*/ static void -yy_reduce_print (yy_state_t *yyssp, YYSTYPE *yyvsp, int yyrule) +yy_reduce_print (yy_state_t *yyssp, YYSTYPE *yyvsp, + int yyrule) { int yylno = yyrline[yyrule]; int yynrhs = yyr2[yyrule]; @@ -1837,9 +1867,8 @@ yy_reduce_print (yy_state_t *yyssp, YYSTYPE *yyvsp, int yyrule) { YYFPRINTF (stderr, " $%d = ", yyi + 1); yy_symbol_print (stderr, - yystos[+yyssp[yyi + 1 - yynrhs]], - &yyvsp[(yyi + 1) - (yynrhs)] - ); + YY_ACCESSING_SYMBOL (+yyssp[yyi + 1 - yynrhs]), + &yyvsp[(yyi + 1) - (yynrhs)]); YYFPRINTF (stderr, "\n"); } } @@ -1854,8 +1883,8 @@ do { \ multiple parsers can coexist. */ int yydebug; #else /* !SLEIGHDEBUG */ -# define YYDPRINTF(Args) -# define YY_SYMBOL_PRINT(Title, Type, Value, Location) +# define YYDPRINTF(Args) ((void) 0) +# define YY_SYMBOL_PRINT(Title, Kind, Value, Location) # define YY_STACK_PRINT(Bottom, Top) # define YY_REDUCE_PRINT(Rule) #endif /* !SLEIGHDEBUG */ @@ -1878,259 +1907,202 @@ int yydebug; #endif -#if YYERROR_VERBOSE -# ifndef yystrlen -# if defined __GLIBC__ && defined _STRING_H -# define yystrlen(S) (YY_CAST (YYPTRDIFF_T, strlen (S))) -# else -/* Return the length of YYSTR. */ -static YYPTRDIFF_T -yystrlen (const char *yystr) -{ - YYPTRDIFF_T yylen; - for (yylen = 0; yystr[yylen]; yylen++) - continue; - return yylen; -} -# endif -# endif -# ifndef yystpcpy -# if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE -# define yystpcpy stpcpy -# else -/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in - YYDEST. */ -static char * -yystpcpy (char *yydest, const char *yysrc) -{ - char *yyd = yydest; - const char *yys = yysrc; - while ((*yyd++ = *yys++) != '\0') - continue; - - return yyd - 1; -} -# endif -# endif - -# ifndef yytnamerr -/* Copy to YYRES the contents of YYSTR after stripping away unnecessary - quotes and backslashes, so that it's suitable for yyerror. The - heuristic is that double-quoting is unnecessary unless the string - contains an apostrophe, a comma, or backslash (other than - backslash-backslash). YYSTR is taken from yytname. If YYRES is - null, do not copy; instead, return the length of what the result - would have been. */ -static YYPTRDIFF_T -yytnamerr (char *yyres, const char *yystr) -{ - if (*yystr == '"') - { - YYPTRDIFF_T yyn = 0; - char const *yyp = yystr; - - for (;;) - switch (*++yyp) - { - case '\'': - case ',': - goto do_not_strip_quotes; - - case '\\': - if (*++yyp != '\\') - goto do_not_strip_quotes; - else - goto append; - - append: - default: - if (yyres) - yyres[yyn] = *yyp; - yyn++; - break; - - case '"': - if (yyres) - yyres[yyn] = '\0'; - return yyn; - } - do_not_strip_quotes: ; - } - - if (yyres) - return yystpcpy (yyres, yystr) - yyres; - else - return yystrlen (yystr); -} -# endif - -/* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message - about the unexpected token YYTOKEN for the state stack whose top is - YYSSP. - - Return 0 if *YYMSG was successfully written. Return 1 if *YYMSG is - not large enough to hold the message. In that case, also set - *YYMSG_ALLOC to the required number of bytes. Return 2 if the - required number of bytes is too large to store. */ -static int -yysyntax_error (YYPTRDIFF_T *yymsg_alloc, char **yymsg, - yy_state_t *yyssp, int yytoken) -{ - enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 }; - /* Internationalized format string. */ - const char *yyformat = YY_NULLPTR; - /* Arguments of yyformat: reported tokens (one for the "unexpected", - one per "expected"). */ - char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM]; - /* Actual size of YYARG. */ - int yycount = 0; - /* Cumulated lengths of YYARG. */ - YYPTRDIFF_T yysize = 0; - - /* There are many possibilities here to consider: - - If this state is a consistent state with a default action, then - the only way this function was invoked is if the default action - is an error action. In that case, don't check for expected - tokens because there are none. - - The only way there can be no lookahead present (in yychar) is if - this state is a consistent state with a default action. Thus, - detecting the absence of a lookahead is sufficient to determine - that there is no unexpected or expected token to report. In that - case, just report a simple "syntax error". - - Don't assume there isn't a lookahead just because this state is a - consistent state with a default action. There might have been a - previous inconsistent state, consistent state with a non-default - action, or user semantic action that manipulated yychar. - - Of course, the expected token list depends on states to have - correct lookahead information, and it depends on the parser not - to perform extra reductions after fetching a lookahead from the - scanner and before detecting a syntax error. Thus, state merging - (from LALR or IELR) and default reductions corrupt the expected - token list. However, the list is correct for canonical LR with - one exception: it will still contain any token that will not be - accepted due to an error action in a later state. - */ - if (yytoken != YYEMPTY) - { - int yyn = yypact[+*yyssp]; - YYPTRDIFF_T yysize0 = yytnamerr (YY_NULLPTR, yytname[yytoken]); - yysize = yysize0; - yyarg[yycount++] = yytname[yytoken]; - if (!yypact_value_is_default (yyn)) - { - /* Start YYX at -YYN if negative to avoid negative indexes in - YYCHECK. In other words, skip the first -YYN actions for - this state because they are default actions. */ - int yyxbegin = yyn < 0 ? -yyn : 0; - /* Stay within bounds of both yycheck and yytname. */ - int yychecklim = YYLAST - yyn + 1; - int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; - int yyx; - - for (yyx = yyxbegin; yyx < yyxend; ++yyx) - if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR - && !yytable_value_is_error (yytable[yyx + yyn])) - { - if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM) - { - yycount = 1; - yysize = yysize0; - break; - } - yyarg[yycount++] = yytname[yyx]; - { - YYPTRDIFF_T yysize1 - = yysize + yytnamerr (YY_NULLPTR, yytname[yyx]); - if (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM) - yysize = yysize1; - else - return 2; - } - } - } - } - - switch (yycount) - { -# define YYCASE_(N, S) \ - case N: \ - yyformat = S; \ - break - default: /* Avoid compiler warnings. */ - YYCASE_(0, YY_("syntax error")); - YYCASE_(1, YY_("syntax error, unexpected %s")); - YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s")); - YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s")); - YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s")); - YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s")); -# undef YYCASE_ - } - - { - /* Don't count the "%s"s in the final size, but reserve room for - the terminator. */ - YYPTRDIFF_T yysize1 = yysize + (yystrlen (yyformat) - 2 * yycount) + 1; - if (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM) - yysize = yysize1; - else - return 2; - } - - if (*yymsg_alloc < yysize) - { - *yymsg_alloc = 2 * yysize; - if (! (yysize <= *yymsg_alloc - && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM)) - *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM; - return 1; - } - - /* Avoid sprintf, as that infringes on the user's name space. - Don't have undefined behavior even if the translation - produced a string with the wrong number of "%s"s. */ - { - char *yyp = *yymsg; - int yyi = 0; - while ((*yyp = *yyformat) != '\0') - if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount) - { - yyp += yytnamerr (yyp, yyarg[yyi++]); - yyformat += 2; - } - else - { - ++yyp; - ++yyformat; - } - } - return 0; -} -#endif /* YYERROR_VERBOSE */ /*-----------------------------------------------. | Release the memory associated to this symbol. | `-----------------------------------------------*/ static void -yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep) +yydestruct (const char *yymsg, + yysymbol_kind_t yykind, YYSTYPE *yyvaluep) { YYUSE (yyvaluep); if (!yymsg) yymsg = "Deleting"; - YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp); + YY_SYMBOL_PRINT (yymsg, yykind, yyvaluep, yylocationp); YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN - YYUSE (yytype); + switch (yykind) + { + case YYSYMBOL_INTEGER: /* INTEGER */ + { delete ((*yyvaluep).i); } + break; + + case YYSYMBOL_INTB: /* INTB */ + { delete ((*yyvaluep).big); } + break; + + case YYSYMBOL_STRING: /* STRING */ + { delete ((*yyvaluep).str); } + break; + + case YYSYMBOL_SYMBOLSTRING: /* SYMBOLSTRING */ + { delete ((*yyvaluep).str); } + break; + + case YYSYMBOL_fielddef: /* fielddef */ + { delete ((*yyvaluep).fieldqual); } + break; + + case YYSYMBOL_contextfielddef: /* contextfielddef */ + { delete ((*yyvaluep).fieldqual); } + break; + + case YYSYMBOL_spaceprop: /* spaceprop */ + { delete ((*yyvaluep).spacequal); } + break; + + case YYSYMBOL_bitpat_or_nil: /* bitpat_or_nil */ + { if (((*yyvaluep).pateq)) PatternEquation::release(((*yyvaluep).pateq)); } + break; + + case YYSYMBOL_rtlbody: /* rtlbody */ + { delete ((*yyvaluep).sectionstart); } + break; + + case YYSYMBOL_pexpression: /* pexpression */ + { PatternExpression::release(((*yyvaluep).patexp)); } + break; + + case YYSYMBOL_pequation: /* pequation */ + { if (((*yyvaluep).pateq)) PatternEquation::release(((*yyvaluep).pateq)); } + break; + + case YYSYMBOL_elleq: /* elleq */ + { if (((*yyvaluep).pateq)) PatternEquation::release(((*yyvaluep).pateq)); } + break; + + case YYSYMBOL_ellrt: /* ellrt */ + { if (((*yyvaluep).pateq)) PatternEquation::release(((*yyvaluep).pateq)); } + break; + + case YYSYMBOL_atomic: /* atomic */ + { if (((*yyvaluep).pateq)) PatternEquation::release(((*yyvaluep).pateq)); } + break; + + case YYSYMBOL_constraint: /* constraint */ + { if (((*yyvaluep).pateq)) PatternEquation::release(((*yyvaluep).pateq)); } + break; + + case YYSYMBOL_contextblock: /* contextblock */ + { delete ((*yyvaluep).contop); } + break; + + case YYSYMBOL_contextlist: /* contextlist */ + { delete ((*yyvaluep).contop); } + break; + + case YYSYMBOL_rtlfirstsection: /* rtlfirstsection */ + { delete ((*yyvaluep).sectionstart); } + break; + + case YYSYMBOL_rtlcontinue: /* rtlcontinue */ + { delete ((*yyvaluep).sectionstart); } + break; + + case YYSYMBOL_rtl: /* rtl */ + { delete ((*yyvaluep).sem); } + break; + + case YYSYMBOL_rtlmid: /* rtlmid */ + { delete ((*yyvaluep).sem); } + break; + + case YYSYMBOL_statement: /* statement */ + { delete ((*yyvaluep).stmt); } + break; + + case YYSYMBOL_expr: /* expr */ + { delete ((*yyvaluep).tree); } + break; + + case YYSYMBOL_sizedstar: /* sizedstar */ + { delete ((*yyvaluep).starqual); } + break; + + case YYSYMBOL_jumpdest: /* jumpdest */ + { delete ((*yyvaluep).varnode); } + break; + + case YYSYMBOL_varnode: /* varnode */ + { delete ((*yyvaluep).varnode); } + break; + + case YYSYMBOL_integervarnode: /* integervarnode */ + { delete ((*yyvaluep).varnode); } + break; + + case YYSYMBOL_lhsvarnode: /* lhsvarnode */ + { delete ((*yyvaluep).varnode); } + break; + + case YYSYMBOL_exportvarnode: /* exportvarnode */ + { delete ((*yyvaluep).varnode); } + break; + + case YYSYMBOL_charstring: /* charstring */ + { delete ((*yyvaluep).str); } + break; + + case YYSYMBOL_intblist: /* intblist */ + { delete ((*yyvaluep).biglist); } + break; + + case YYSYMBOL_intbpart: /* intbpart */ + { delete ((*yyvaluep).biglist); } + break; + + case YYSYMBOL_stringlist: /* stringlist */ + { delete ((*yyvaluep).strlist); } + break; + + case YYSYMBOL_stringpart: /* stringpart */ + { delete ((*yyvaluep).strlist); } + break; + + case YYSYMBOL_anystringlist: /* anystringlist */ + { delete ((*yyvaluep).strlist); } + break; + + case YYSYMBOL_anystringpart: /* anystringpart */ + { delete ((*yyvaluep).strlist); } + break; + + case YYSYMBOL_valuelist: /* valuelist */ + { delete ((*yyvaluep).symlist); } + break; + + case YYSYMBOL_valuepart: /* valuepart */ + { delete ((*yyvaluep).symlist); } + break; + + case YYSYMBOL_varlist: /* varlist */ + { delete ((*yyvaluep).symlist); } + break; + + case YYSYMBOL_varpart: /* varpart */ + { delete ((*yyvaluep).symlist); } + break; + + case YYSYMBOL_paramlist: /* paramlist */ + { delete ((*yyvaluep).param); } + break; + + case YYSYMBOL_oplist: /* oplist */ + { delete ((*yyvaluep).strlist); } + break; + + default: + break; + } YY_IGNORE_MAYBE_UNINITIALIZED_END } - - -/* The lookahead symbol. */ +/* Lookahead token kind. */ int yychar; /* The semantic value of the lookahead symbol. */ @@ -2139,6 +2111,8 @@ YYSTYPE yylval; int yynerrs; + + /*----------. | yyparse. | `----------*/ @@ -2146,43 +2120,36 @@ int yynerrs; int yyparse (void) { - yy_state_fast_t yystate; + yy_state_fast_t yystate = 0; /* Number of tokens to shift before error messages enabled. */ - int yyerrstatus; + int yyerrstatus = 0; - /* The stacks and their tools: - 'yyss': related to states. - 'yyvs': related to semantic values. - - Refer to the stacks through separate pointers, to allow yyoverflow + /* Refer to the stacks through separate pointers, to allow yyoverflow to reallocate them elsewhere. */ - /* The state stack. */ + /* Their size. */ + YYPTRDIFF_T yystacksize = YYINITDEPTH; + + /* The state stack: array, bottom, top. */ yy_state_t yyssa[YYINITDEPTH]; - yy_state_t *yyss; - yy_state_t *yyssp; + yy_state_t *yyss = yyssa; + yy_state_t *yyssp = yyss; - /* The semantic value stack. */ + /* The semantic value stack: array, bottom, top. */ YYSTYPE yyvsa[YYINITDEPTH]; - YYSTYPE *yyvs; - YYSTYPE *yyvsp; - - YYPTRDIFF_T yystacksize; + YYSTYPE *yyvs = yyvsa; + YYSTYPE *yyvsp = yyvs; int yyn; + /* The return value of yyparse. */ int yyresult; - /* Lookahead token as an internal (translated) token number. */ - int yytoken = 0; + /* Lookahead symbol kind. */ + yysymbol_kind_t yytoken = YYSYMBOL_YYEMPTY; /* The variables used to return semantic value and location from the action routines. */ YYSTYPE yyval; -#if YYERROR_VERBOSE - /* Buffer for error messages, and its allocated size. */ - char yymsgbuf[128]; - char *yymsg = yymsgbuf; - YYPTRDIFF_T yymsg_alloc = sizeof yymsgbuf; -#endif + #define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N)) @@ -2190,16 +2157,9 @@ yyparse (void) Keep to zero when no symbol should be popped. */ int yylen = 0; - yyssp = yyss = yyssa; - yyvsp = yyvs = yyvsa; - yystacksize = YYINITDEPTH; - YYDPRINTF ((stderr, "Starting parse\n")); - yystate = 0; - yyerrstatus = 0; - yynerrs = 0; - yychar = YYEMPTY; /* Cause a token to be read. */ + yychar = SLEIGHEMPTY; /* Cause a token to be read. */ goto yysetstate; @@ -2221,6 +2181,7 @@ yysetstate: YY_IGNORE_USELESS_CAST_BEGIN *yyssp = YY_CAST (yy_state_t, yystate); YY_IGNORE_USELESS_CAST_END + YY_STACK_PRINT (yyss, yyssp); if (yyss + yystacksize - 1 <= yyssp) #if !defined yyoverflow && !defined YYSTACK_RELOCATE @@ -2266,7 +2227,7 @@ yysetstate: goto yyexhaustedlab; YYSTACK_RELOCATE (yyss_alloc, yyss); YYSTACK_RELOCATE (yyvs_alloc, yyvs); -# undef YYSTACK_RELOCATE +# undef YYSTACK_RELOCATE if (yyss1 != yyssa) YYSTACK_FREE (yyss1); } @@ -2305,18 +2266,29 @@ yybackup: /* Not known => get a lookahead token if don't already have one. */ - /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */ - if (yychar == YYEMPTY) + /* YYCHAR is either empty, or end-of-input, or a valid lookahead. */ + if (yychar == SLEIGHEMPTY) { - YYDPRINTF ((stderr, "Reading a token: ")); + YYDPRINTF ((stderr, "Reading a token\n")); yychar = yylex (); } - if (yychar <= YYEOF) + if (yychar <= SLEIGHEOF) { - yychar = yytoken = YYEOF; + yychar = SLEIGHEOF; + yytoken = YYSYMBOL_YYEOF; YYDPRINTF ((stderr, "Now at end of input.\n")); } + else if (yychar == SLEIGHerror) + { + /* The scanner already issued an error message, process directly + to error recovery. But do not keep the error token as + lookahead, it is too special and may lead us to an endless + loop in error recovery. */ + yychar = SLEIGHUNDEF; + yytoken = YYSYMBOL_YYerror; + goto yyerrlab1; + } else { yytoken = YYTRANSLATE (yychar); @@ -2350,7 +2322,7 @@ yybackup: YY_IGNORE_MAYBE_UNINITIALIZED_END /* Discard the shifted token. */ - yychar = YYEMPTY; + yychar = SLEIGHEMPTY; goto yynewstate; @@ -2385,1245 +2357,1245 @@ yyreduce: YY_REDUCE_PRINT (yyn); switch (yyn) { - case 19: + case 19: /* constructorlike: error '}' */ { slgh->resetConstructors(); } break; - case 20: + case 20: /* endiandef: DEFINE_KEY ENDIAN_KEY '=' BIG_KEY ';' */ { slgh->setEndian(1); } break; - case 21: + case 21: /* endiandef: DEFINE_KEY ENDIAN_KEY '=' LITTLE_KEY ';' */ { slgh->setEndian(0); } break; - case 22: + case 22: /* aligndef: DEFINE_KEY ALIGN_KEY '=' INTEGER ';' */ { slgh->setAlignment(*(yyvsp[-1].i)); delete (yyvsp[-1].i); } break; - case 23: + case 23: /* tokendef: tokenprop ';' */ {} break; - case 24: + case 24: /* tokenprop: DEFINE_KEY TOKEN_KEY STRING '(' INTEGER ')' */ { (yyval.tokensym) = slgh->defineToken((yyvsp[-3].str),(yyvsp[-1].i),0); } break; - case 25: + case 25: /* tokenprop: DEFINE_KEY TOKEN_KEY STRING '(' INTEGER ')' ENDIAN_KEY '=' LITTLE_KEY */ { (yyval.tokensym) = slgh->defineToken((yyvsp[-6].str),(yyvsp[-4].i),-1); } break; - case 26: + case 26: /* tokenprop: DEFINE_KEY TOKEN_KEY STRING '(' INTEGER ')' ENDIAN_KEY '=' BIG_KEY */ { (yyval.tokensym) = slgh->defineToken((yyvsp[-6].str),(yyvsp[-4].i),1); } break; - case 27: + case 27: /* tokenprop: tokenprop fielddef */ { (yyval.tokensym) = (yyvsp[-1].tokensym); slgh->addTokenField((yyvsp[-1].tokensym),(yyvsp[0].fieldqual)); } break; - case 28: + case 28: /* tokenprop: DEFINE_KEY TOKEN_KEY anysymbol */ { string errmsg=(yyvsp[0].anysym)->getName()+": redefined as a token"; slgh->reportError(errmsg); YYERROR; } break; - case 29: + case 29: /* contextdef: contextprop ';' */ {} break; - case 30: + case 30: /* contextprop: DEFINE_KEY CONTEXT_KEY VARSYM */ { (yyval.varsym) = (yyvsp[0].varsym); } break; - case 31: + case 31: /* contextprop: contextprop contextfielddef */ { (yyval.varsym) = (yyvsp[-1].varsym); if (!slgh->addContextField( (yyvsp[-1].varsym), (yyvsp[0].fieldqual) )) { slgh->reportError("All context definitions must come before constructors"); YYERROR; } } break; - case 32: + case 32: /* fielddef: STRING '=' '(' INTEGER ',' INTEGER ')' */ { (yyval.fieldqual) = new FieldQuality((yyvsp[-6].str),(yyvsp[-3].i),(yyvsp[-1].i)); } break; - case 33: - { delete (yyvsp[-3].i); delete (yyvsp[-1].i); string errmsg = (yyvsp[-6].anysym)->getName()+": redefined as field"; slgh->reportError(errmsg); YYERROR; } + case 33: /* fielddef: anysymbol '=' '(' INTEGER ',' INTEGER ')' */ + { (yyval.fieldqual) = (FieldQuality *)0; delete (yyvsp[-3].i); delete (yyvsp[-1].i); string errmsg = (yyvsp[-6].anysym)->getName()+": redefined as field"; slgh->reportError(errmsg); YYERROR; } break; - case 34: + case 34: /* fielddef: fielddef SIGNED_KEY */ { (yyval.fieldqual) = (yyvsp[-1].fieldqual); (yyval.fieldqual)->signext = true; } break; - case 35: + case 35: /* fielddef: fielddef HEX_KEY */ { (yyval.fieldqual) = (yyvsp[-1].fieldqual); (yyval.fieldqual)->hex = true; } break; - case 36: + case 36: /* fielddef: fielddef DEC_KEY */ { (yyval.fieldqual) = (yyvsp[-1].fieldqual); (yyval.fieldqual)->hex = false; } break; - case 37: + case 37: /* contextfielddef: STRING '=' '(' INTEGER ',' INTEGER ')' */ { (yyval.fieldqual) = new FieldQuality((yyvsp[-6].str),(yyvsp[-3].i),(yyvsp[-1].i)); } break; - case 38: - { delete (yyvsp[-3].i); delete (yyvsp[-1].i); string errmsg = (yyvsp[-6].anysym)->getName()+": redefined as field"; slgh->reportError(errmsg); YYERROR; } + case 38: /* contextfielddef: anysymbol '=' '(' INTEGER ',' INTEGER ')' */ + { (yyval.fieldqual) = (FieldQuality *)0; delete (yyvsp[-3].i); delete (yyvsp[-1].i); string errmsg = (yyvsp[-6].anysym)->getName()+": redefined as field"; slgh->reportError(errmsg); YYERROR; } break; - case 39: + case 39: /* contextfielddef: contextfielddef SIGNED_KEY */ { (yyval.fieldqual) = (yyvsp[-1].fieldqual); (yyval.fieldqual)->signext = true; } break; - case 40: + case 40: /* contextfielddef: contextfielddef NOFLOW_KEY */ { (yyval.fieldqual) = (yyvsp[-1].fieldqual); (yyval.fieldqual)->flow = false; } break; - case 41: + case 41: /* contextfielddef: contextfielddef HEX_KEY */ { (yyval.fieldqual) = (yyvsp[-1].fieldqual); (yyval.fieldqual)->hex = true; } break; - case 42: + case 42: /* contextfielddef: contextfielddef DEC_KEY */ { (yyval.fieldqual) = (yyvsp[-1].fieldqual); (yyval.fieldqual)->hex = false; } break; - case 43: + case 43: /* spacedef: spaceprop ';' */ { slgh->newSpace((yyvsp[-1].spacequal)); } break; - case 44: + case 44: /* spaceprop: DEFINE_KEY SPACE_KEY STRING */ { (yyval.spacequal) = new SpaceQuality(*(yyvsp[0].str)); delete (yyvsp[0].str); } break; - case 45: - { string errmsg = (yyvsp[0].anysym)->getName()+": redefined as space"; slgh->reportError(errmsg); YYERROR; } + case 45: /* spaceprop: DEFINE_KEY SPACE_KEY anysymbol */ + { (yyval.spacequal) = (SpaceQuality *)0; string errmsg = (yyvsp[0].anysym)->getName()+": redefined as space"; slgh->reportError(errmsg); YYERROR; } break; - case 46: + case 46: /* spaceprop: spaceprop TYPE_KEY '=' RAM_KEY */ { (yyval.spacequal) = (yyvsp[-3].spacequal); (yyval.spacequal)->type = SpaceQuality::ramtype; } break; - case 47: + case 47: /* spaceprop: spaceprop TYPE_KEY '=' REGISTER_KEY */ { (yyval.spacequal) = (yyvsp[-3].spacequal); (yyval.spacequal)->type = SpaceQuality::registertype; } break; - case 48: + case 48: /* spaceprop: spaceprop SIZE_KEY '=' INTEGER */ { (yyval.spacequal) = (yyvsp[-3].spacequal); (yyval.spacequal)->size = *(yyvsp[0].i); delete (yyvsp[0].i); } break; - case 49: + case 49: /* spaceprop: spaceprop WORDSIZE_KEY '=' INTEGER */ { (yyval.spacequal) = (yyvsp[-3].spacequal); (yyval.spacequal)->wordsize = *(yyvsp[0].i); delete (yyvsp[0].i); } break; - case 50: + case 50: /* spaceprop: spaceprop DEFAULT_KEY */ { (yyval.spacequal) = (yyvsp[-1].spacequal); (yyval.spacequal)->isdefault = true; } break; - case 51: + case 51: /* varnodedef: DEFINE_KEY SPACESYM OFFSET_KEY '=' INTEGER SIZE_KEY '=' INTEGER stringlist ';' */ { slgh->defineVarnodes((yyvsp[-8].spacesym),(yyvsp[-5].i),(yyvsp[-2].i),(yyvsp[-1].strlist)); } break; - case 52: + case 52: /* varnodedef: DEFINE_KEY SPACESYM OFFSET_KEY '=' BADINTEGER */ { slgh->reportError("Parsed integer is too big (overflow)"); YYERROR; } break; - case 56: + case 56: /* bitrangesingle: STRING '=' VARSYM '[' INTEGER ',' INTEGER ']' */ { slgh->defineBitrange((yyvsp[-7].str),(yyvsp[-5].varsym),(uint4)*(yyvsp[-3].i),(uint4)*(yyvsp[-1].i)); delete (yyvsp[-3].i); delete (yyvsp[-1].i); } break; - case 57: + case 57: /* pcodeopdef: DEFINE_KEY PCODEOP_KEY stringlist ';' */ { slgh->addUserOp((yyvsp[-1].strlist)); } break; - case 58: + case 58: /* valueattach: ATTACH_KEY VALUES_KEY valuelist intblist ';' */ { slgh->attachValues((yyvsp[-2].symlist),(yyvsp[-1].biglist)); } break; - case 59: + case 59: /* nameattach: ATTACH_KEY NAMES_KEY valuelist anystringlist ';' */ { slgh->attachNames((yyvsp[-2].symlist),(yyvsp[-1].strlist)); } break; - case 60: + case 60: /* varattach: ATTACH_KEY VARIABLES_KEY valuelist varlist ';' */ { slgh->attachVarnodes((yyvsp[-2].symlist),(yyvsp[-1].symlist)); } break; - case 61: + case 61: /* macrodef: macrostart '{' rtl '}' */ { slgh->buildMacro((yyvsp[-3].macrosym),(yyvsp[-1].sem)); } break; - case 62: + case 62: /* withblockstart: WITH_KEY id_or_nil ':' bitpat_or_nil contextblock '{' */ { slgh->pushWith((yyvsp[-4].subtablesym),(yyvsp[-2].pateq),(yyvsp[-1].contop)); } break; - case 66: + case 66: /* withblock: withblockmid '}' */ { slgh->popWith(); } break; - case 67: + case 67: /* id_or_nil: %empty */ { (yyval.subtablesym) = (SubtableSymbol *)0; } break; - case 68: + case 68: /* id_or_nil: SUBTABLESYM */ { (yyval.subtablesym) = (yyvsp[0].subtablesym); } break; - case 69: + case 69: /* id_or_nil: STRING */ { (yyval.subtablesym) = slgh->newTable((yyvsp[0].str)); } break; - case 70: + case 70: /* bitpat_or_nil: %empty */ { (yyval.pateq) = (PatternEquation *)0; } break; - case 71: + case 71: /* bitpat_or_nil: pequation */ { (yyval.pateq) = (yyvsp[0].pateq); } break; - case 72: + case 72: /* macrostart: MACRO_KEY STRING '(' oplist ')' */ { (yyval.macrosym) = slgh->createMacro((yyvsp[-3].str),(yyvsp[-1].strlist)); } break; - case 73: + case 73: /* rtlbody: '{' rtl '}' */ { (yyval.sectionstart) = slgh->standaloneSection((yyvsp[-1].sem)); } break; - case 74: + case 74: /* rtlbody: '{' rtlcontinue rtlmid '}' */ { (yyval.sectionstart) = slgh->finalNamedSection((yyvsp[-2].sectionstart),(yyvsp[-1].sem)); } break; - case 75: + case 75: /* rtlbody: OP_UNIMPL */ { (yyval.sectionstart) = (SectionVector *)0; } break; - case 76: + case 76: /* constructor: constructprint IS_KEY pequation contextblock rtlbody */ { slgh->buildConstructor((yyvsp[-4].construct),(yyvsp[-2].pateq),(yyvsp[-1].contop),(yyvsp[0].sectionstart)); } break; - case 77: + case 77: /* constructor: subtablestart IS_KEY pequation contextblock rtlbody */ { slgh->buildConstructor((yyvsp[-4].construct),(yyvsp[-2].pateq),(yyvsp[-1].contop),(yyvsp[0].sectionstart)); } break; - case 78: + case 78: /* constructprint: subtablestart STRING */ { (yyval.construct) = (yyvsp[-1].construct); (yyval.construct)->addSyntax(*(yyvsp[0].str)); delete (yyvsp[0].str); } break; - case 79: + case 79: /* constructprint: subtablestart charstring */ { (yyval.construct) = (yyvsp[-1].construct); (yyval.construct)->addSyntax(*(yyvsp[0].str)); delete (yyvsp[0].str); } break; - case 80: + case 80: /* constructprint: subtablestart SYMBOLSTRING */ { (yyval.construct) = (yyvsp[-1].construct); if (slgh->isInRoot((yyvsp[-1].construct))) { (yyval.construct)->addSyntax(*(yyvsp[0].str)); delete (yyvsp[0].str); } else slgh->newOperand((yyvsp[-1].construct),(yyvsp[0].str)); } break; - case 81: + case 81: /* constructprint: subtablestart '^' */ { (yyval.construct) = (yyvsp[-1].construct); if (!slgh->isInRoot((yyvsp[-1].construct))) { slgh->reportError("Unexpected '^' at start of print pieces"); YYERROR; } } break; - case 82: + case 82: /* constructprint: constructprint '^' */ { (yyval.construct) = (yyvsp[-1].construct); } break; - case 83: + case 83: /* constructprint: constructprint STRING */ { (yyval.construct) = (yyvsp[-1].construct); (yyval.construct)->addSyntax(*(yyvsp[0].str)); delete (yyvsp[0].str); } break; - case 84: + case 84: /* constructprint: constructprint charstring */ { (yyval.construct) = (yyvsp[-1].construct); (yyval.construct)->addSyntax(*(yyvsp[0].str)); delete (yyvsp[0].str); } break; - case 85: + case 85: /* constructprint: constructprint ' ' */ { (yyval.construct) = (yyvsp[-1].construct); (yyval.construct)->addSyntax(string(" ")); } break; - case 86: + case 86: /* constructprint: constructprint SYMBOLSTRING */ { (yyval.construct) = (yyvsp[-1].construct); slgh->newOperand((yyvsp[-1].construct),(yyvsp[0].str)); } break; - case 87: + case 87: /* subtablestart: SUBTABLESYM ':' */ { (yyval.construct) = slgh->createConstructor((yyvsp[-1].subtablesym)); } break; - case 88: + case 88: /* subtablestart: STRING ':' */ { SubtableSymbol *sym=slgh->newTable((yyvsp[-1].str)); (yyval.construct) = slgh->createConstructor(sym); } break; - case 89: + case 89: /* subtablestart: ':' */ { (yyval.construct) = slgh->createConstructor((SubtableSymbol *)0); } break; - case 90: + case 90: /* subtablestart: subtablestart ' ' */ { (yyval.construct) = (yyvsp[-1].construct); } break; - case 91: + case 91: /* pexpression: INTB */ { (yyval.patexp) = new ConstantValue(*(yyvsp[0].big)); delete (yyvsp[0].big); } break; - case 92: + case 92: /* pexpression: familysymbol */ { 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"; slgh->reportError(errmsg); } (yyval.patexp) = (yyvsp[0].famsym)->getPatternValue(); } break; - case 93: + case 93: /* pexpression: specificsymbol */ { (yyval.patexp) = (yyvsp[0].specsym)->getPatternExpression(); } break; - case 94: + case 94: /* pexpression: '(' pexpression ')' */ { (yyval.patexp) = (yyvsp[-1].patexp); } break; - case 95: + case 95: /* pexpression: pexpression '+' pexpression */ { (yyval.patexp) = new PlusExpression((yyvsp[-2].patexp),(yyvsp[0].patexp)); } break; - case 96: + case 96: /* pexpression: pexpression '-' pexpression */ { (yyval.patexp) = new SubExpression((yyvsp[-2].patexp),(yyvsp[0].patexp)); } break; - case 97: + case 97: /* pexpression: pexpression '*' pexpression */ { (yyval.patexp) = new MultExpression((yyvsp[-2].patexp),(yyvsp[0].patexp)); } break; - case 98: + case 98: /* pexpression: pexpression OP_LEFT pexpression */ { (yyval.patexp) = new LeftShiftExpression((yyvsp[-2].patexp),(yyvsp[0].patexp)); } break; - case 99: + case 99: /* pexpression: pexpression OP_RIGHT pexpression */ { (yyval.patexp) = new RightShiftExpression((yyvsp[-2].patexp),(yyvsp[0].patexp)); } break; - case 100: + case 100: /* pexpression: pexpression OP_AND pexpression */ { (yyval.patexp) = new AndExpression((yyvsp[-2].patexp),(yyvsp[0].patexp)); } break; - case 101: + case 101: /* pexpression: pexpression OP_OR pexpression */ { (yyval.patexp) = new OrExpression((yyvsp[-2].patexp),(yyvsp[0].patexp)); } break; - case 102: + case 102: /* pexpression: pexpression OP_XOR pexpression */ { (yyval.patexp) = new XorExpression((yyvsp[-2].patexp),(yyvsp[0].patexp)); } break; - case 103: + case 103: /* pexpression: pexpression '/' pexpression */ { (yyval.patexp) = new DivExpression((yyvsp[-2].patexp),(yyvsp[0].patexp)); } break; - case 104: + case 104: /* pexpression: '-' pexpression */ { (yyval.patexp) = new MinusExpression((yyvsp[0].patexp)); } break; - case 105: + case 105: /* pexpression: '~' pexpression */ { (yyval.patexp) = new NotExpression((yyvsp[0].patexp)); } break; - case 107: + case 107: /* pequation: pequation '&' pequation */ { (yyval.pateq) = new EquationAnd((yyvsp[-2].pateq),(yyvsp[0].pateq)); } break; - case 108: + case 108: /* pequation: pequation '|' pequation */ { (yyval.pateq) = new EquationOr((yyvsp[-2].pateq),(yyvsp[0].pateq)); } break; - case 109: + case 109: /* pequation: pequation ';' pequation */ { (yyval.pateq) = new EquationCat((yyvsp[-2].pateq),(yyvsp[0].pateq)); } break; - case 110: + case 110: /* elleq: ELLIPSIS_KEY ellrt */ { (yyval.pateq) = new EquationLeftEllipsis((yyvsp[0].pateq)); } break; - case 112: + case 112: /* ellrt: atomic ELLIPSIS_KEY */ { (yyval.pateq) = new EquationRightEllipsis((yyvsp[-1].pateq)); } break; - case 115: + case 115: /* atomic: '(' pequation ')' */ { (yyval.pateq) = (yyvsp[-1].pateq); } break; - case 116: + case 116: /* constraint: familysymbol '=' pexpression */ { (yyval.pateq) = new EqualEquation((yyvsp[-2].famsym)->getPatternValue(),(yyvsp[0].patexp)); } break; - case 117: + case 117: /* constraint: familysymbol OP_NOTEQUAL pexpression */ { (yyval.pateq) = new NotEqualEquation((yyvsp[-2].famsym)->getPatternValue(),(yyvsp[0].patexp)); } break; - case 118: + case 118: /* constraint: familysymbol '<' pexpression */ { (yyval.pateq) = new LessEquation((yyvsp[-2].famsym)->getPatternValue(),(yyvsp[0].patexp)); } break; - case 119: + case 119: /* constraint: familysymbol OP_LESSEQUAL pexpression */ { (yyval.pateq) = new LessEqualEquation((yyvsp[-2].famsym)->getPatternValue(),(yyvsp[0].patexp)); } break; - case 120: + case 120: /* constraint: familysymbol '>' pexpression */ { (yyval.pateq) = new GreaterEquation((yyvsp[-2].famsym)->getPatternValue(),(yyvsp[0].patexp)); } break; - case 121: + case 121: /* constraint: familysymbol OP_GREATEQUAL pexpression */ { (yyval.pateq) = new GreaterEqualEquation((yyvsp[-2].famsym)->getPatternValue(),(yyvsp[0].patexp)); } break; - case 122: + case 122: /* constraint: OPERANDSYM '=' pexpression */ { (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(); slgh->reportError(errmsg); } } break; - case 123: + case 123: /* constraint: OPERANDSYM */ { (yyval.pateq) = new OperandEquation((yyvsp[0].operandsym)->getIndex()); slgh->selfDefine((yyvsp[0].operandsym)); } break; - case 124: + case 124: /* constraint: SPECSYM */ { (yyval.pateq) = new UnconstrainedEquation((yyvsp[0].specsym)->getPatternExpression()); } break; - case 125: + case 125: /* constraint: familysymbol */ { (yyval.pateq) = slgh->defineInvisibleOperand((yyvsp[0].famsym)); } break; - case 126: + case 126: /* constraint: SUBTABLESYM */ { (yyval.pateq) = slgh->defineInvisibleOperand((yyvsp[0].subtablesym)); } break; - case 127: + case 127: /* contextblock: %empty */ { (yyval.contop) = (vector *)0; } break; - case 128: + case 128: /* contextblock: '[' contextlist ']' */ { (yyval.contop) = (yyvsp[-1].contop); } break; - case 129: + case 129: /* contextlist: %empty */ { (yyval.contop) = new vector; } break; - 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(); slgh->reportError(errmsg); YYERROR; } } + case 130: /* contextlist: contextlist CONTEXTSYM '=' pexpression ';' */ + { (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); delete (yyvsp[-4].contop); (yyvsp[-1].patexp)->layClaim(); PatternExpression::release((yyvsp[-1].patexp)); YYERROR; } } break; - case 131: + case 131: /* contextlist: contextlist GLOBALSET_KEY '(' familysymbol ',' CONTEXTSYM ')' ';' */ { (yyval.contop) = (yyvsp[-7].contop); slgh->contextSet((yyvsp[-7].contop),(yyvsp[-4].famsym),(yyvsp[-2].contextsym)); } break; - case 132: + case 132: /* contextlist: contextlist GLOBALSET_KEY '(' specificsymbol ',' CONTEXTSYM ')' ';' */ { (yyval.contop) = (yyvsp[-7].contop); slgh->contextSet((yyvsp[-7].contop),(yyvsp[-4].specsym),(yyvsp[-2].contextsym)); } break; - case 133: + case 133: /* contextlist: contextlist OPERANDSYM '=' pexpression ';' */ { (yyval.contop) = (yyvsp[-4].contop); slgh->defineOperand((yyvsp[-3].operandsym),(yyvsp[-1].patexp)); } break; - case 134: - { string errmsg="Expecting context symbol, not "+*(yyvsp[0].str); delete (yyvsp[0].str); slgh->reportError(errmsg); YYERROR; } + case 134: /* contextlist: contextlist STRING */ + { (yyval.contop) = (vector *)0; delete (yyvsp[-1].contop); string errmsg="Expecting context symbol, not "+*(yyvsp[0].str); delete (yyvsp[0].str); slgh->reportError(errmsg); YYERROR; } break; - case 135: + case 135: /* section_def: OP_LEFT STRING OP_RIGHT */ { (yyval.sectionsym) = slgh->newSectionSymbol( *(yyvsp[-1].str) ); delete (yyvsp[-1].str); } break; - case 136: + case 136: /* section_def: OP_LEFT SECTIONSYM OP_RIGHT */ { (yyval.sectionsym) = (yyvsp[-1].sectionsym); } break; - case 137: + case 137: /* rtlfirstsection: rtl section_def */ { (yyval.sectionstart) = slgh->firstNamedSection((yyvsp[-1].sem),(yyvsp[0].sectionsym)); } break; - case 138: + case 138: /* rtlcontinue: rtlfirstsection */ { (yyval.sectionstart) = (yyvsp[0].sectionstart); } break; - case 139: + case 139: /* rtlcontinue: rtlcontinue rtlmid section_def */ { (yyval.sectionstart) = slgh->nextNamedSection((yyvsp[-2].sectionstart),(yyvsp[-1].sem),(yyvsp[0].sectionsym)); } break; - case 140: + case 140: /* rtl: rtlmid */ { (yyval.sem) = (yyvsp[0].sem); if ((yyval.sem)->getOpvec().empty() && ((yyval.sem)->getResult() == (HandleTpl *)0)) slgh->recordNop(); } break; - case 141: + case 141: /* rtl: rtlmid EXPORT_KEY exportvarnode ';' */ { (yyval.sem) = slgh->setResultVarnode((yyvsp[-3].sem),(yyvsp[-1].varnode)); } break; - case 142: + case 142: /* rtl: rtlmid EXPORT_KEY sizedstar lhsvarnode ';' */ { (yyval.sem) = slgh->setResultStarVarnode((yyvsp[-4].sem),(yyvsp[-2].starqual),(yyvsp[-1].varnode)); } break; - case 143: - { string errmsg="Unknown export varnode: "+*(yyvsp[0].str); delete (yyvsp[0].str); slgh->reportError(errmsg); YYERROR; } + case 143: /* rtl: rtlmid EXPORT_KEY STRING */ + { (yyval.sem) = (ConstructTpl *)0; delete (yyvsp[-2].sem); 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); slgh->reportError(errmsg); YYERROR; } + case 144: /* rtl: rtlmid EXPORT_KEY sizedstar STRING */ + { (yyval.sem) = (ConstructTpl *)0; delete (yyvsp[-3].sem); string errmsg="Unknown pointer varnode: "+*(yyvsp[0].str); delete (yyvsp[-1].starqual); delete (yyvsp[0].str); slgh->reportError(errmsg); YYERROR; } break; - case 145: + case 145: /* rtlmid: %empty */ { (yyval.sem) = slgh->enterSection(); } break; - case 146: - { (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); } + case 146: /* rtlmid: rtlmid statement */ + { (yyval.sem) = (yyvsp[-1].sem); if (!(yyval.sem)->addOpList(*(yyvsp[0].stmt))) { delete (yyvsp[-1].sem); delete (yyvsp[0].stmt); slgh->reportError("Multiple delayslot declarations"); YYERROR; } delete (yyvsp[0].stmt); } break; - case 147: + case 147: /* rtlmid: rtlmid LOCAL_KEY STRING ';' */ { (yyval.sem) = (yyvsp[-3].sem); slgh->pcode.newLocalDefinition((yyvsp[-1].str)); } break; - case 148: + case 148: /* rtlmid: rtlmid LOCAL_KEY STRING ':' INTEGER ';' */ { (yyval.sem) = (yyvsp[-5].sem); slgh->pcode.newLocalDefinition((yyvsp[-3].str),*(yyvsp[-1].i)); delete (yyvsp[-1].i); } break; - case 149: + case 149: /* statement: lhsvarnode '=' expr ';' */ { (yyvsp[-1].tree)->setOutput((yyvsp[-3].varnode)); (yyval.stmt) = ExprTree::toVector((yyvsp[-1].tree)); } break; - case 150: + case 150: /* statement: LOCAL_KEY STRING '=' expr ';' */ { (yyval.stmt) = slgh->pcode.newOutput(true,(yyvsp[-1].tree),(yyvsp[-3].str)); } break; - case 151: + case 151: /* statement: STRING '=' expr ';' */ { (yyval.stmt) = slgh->pcode.newOutput(false,(yyvsp[-1].tree),(yyvsp[-3].str)); } break; - case 152: + case 152: /* statement: LOCAL_KEY STRING ':' INTEGER '=' expr ';' */ { (yyval.stmt) = slgh->pcode.newOutput(true,(yyvsp[-1].tree),(yyvsp[-5].str),*(yyvsp[-3].i)); delete (yyvsp[-3].i); } break; - case 153: + case 153: /* statement: STRING ':' INTEGER '=' expr ';' */ { (yyval.stmt) = slgh->pcode.newOutput(true,(yyvsp[-1].tree),(yyvsp[-5].str),*(yyvsp[-3].i)); delete (yyvsp[-3].i); } break; - case 154: + case 154: /* statement: LOCAL_KEY specificsymbol '=' */ { (yyval.stmt) = (vector *)0; string errmsg = "Redefinition of symbol: "+(yyvsp[-1].specsym)->getName(); slgh->reportError(errmsg); YYERROR; } break; - case 155: + case 155: /* statement: sizedstar expr '=' expr ';' */ { (yyval.stmt) = slgh->pcode.createStore((yyvsp[-4].starqual),(yyvsp[-3].tree),(yyvsp[-1].tree)); } break; - case 156: + case 156: /* statement: USEROPSYM '(' paramlist ')' ';' */ { (yyval.stmt) = slgh->pcode.createUserOpNoOut((yyvsp[-4].useropsym),(yyvsp[-2].param)); } break; - case 157: + case 157: /* statement: lhsvarnode '[' INTEGER ',' INTEGER ']' '=' expr ';' */ { (yyval.stmt) = slgh->pcode.assignBitRange((yyvsp[-8].varnode),(uint4)*(yyvsp[-6].i),(uint4)*(yyvsp[-4].i),(yyvsp[-1].tree)); delete (yyvsp[-6].i), delete (yyvsp[-4].i); } break; - case 158: + case 158: /* statement: BITSYM '=' expr ';' */ { (yyval.stmt)=slgh->pcode.assignBitRange((yyvsp[-3].bitsym)->getParentSymbol()->getVarnode(),(yyvsp[-3].bitsym)->getBitOffset(),(yyvsp[-3].bitsym)->numBits(),(yyvsp[-1].tree)); } break; - case 159: - { delete (yyvsp[-3].varnode); delete (yyvsp[-1].i); slgh->reportError("Illegal truncation on left-hand side of assignment"); YYERROR; } + case 159: /* statement: varnode ':' INTEGER '=' */ + { (yyval.stmt) = (vector *)0; 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); slgh->reportError("Illegal subpiece on left-hand side of assignment"); YYERROR; } + case 160: /* statement: varnode '(' INTEGER ')' */ + { (yyval.stmt) = (vector *)0; delete (yyvsp[-3].varnode); delete (yyvsp[-1].i); slgh->reportError("Illegal subpiece on left-hand side of assignment"); YYERROR; } break; - case 161: + case 161: /* statement: BUILD_KEY OPERANDSYM ';' */ { (yyval.stmt) = slgh->pcode.createOpConst(BUILD,(yyvsp[-1].operandsym)->getIndex()); } break; - case 162: + case 162: /* statement: CROSSBUILD_KEY varnode ',' SECTIONSYM ';' */ { (yyval.stmt) = slgh->createCrossBuild((yyvsp[-3].varnode),(yyvsp[-1].sectionsym)); } break; - case 163: + case 163: /* statement: CROSSBUILD_KEY varnode ',' STRING ';' */ { (yyval.stmt) = slgh->createCrossBuild((yyvsp[-3].varnode),slgh->newSectionSymbol(*(yyvsp[-1].str))); delete (yyvsp[-1].str); } break; - case 164: + case 164: /* statement: DELAYSLOT_KEY '(' INTEGER ')' ';' */ { (yyval.stmt) = slgh->pcode.createOpConst(DELAY_SLOT,*(yyvsp[-2].i)); delete (yyvsp[-2].i); } break; - case 165: + case 165: /* statement: GOTO_KEY jumpdest ';' */ { (yyval.stmt) = slgh->pcode.createOpNoOut(CPUI_BRANCH,new ExprTree((yyvsp[-1].varnode))); } break; - case 166: + case 166: /* statement: IF_KEY expr GOTO_KEY jumpdest ';' */ { (yyval.stmt) = slgh->pcode.createOpNoOut(CPUI_CBRANCH,new ExprTree((yyvsp[-1].varnode)),(yyvsp[-3].tree)); } break; - case 167: + case 167: /* statement: GOTO_KEY '[' expr ']' ';' */ { (yyval.stmt) = slgh->pcode.createOpNoOut(CPUI_BRANCHIND,(yyvsp[-2].tree)); } break; - case 168: + case 168: /* statement: CALL_KEY jumpdest ';' */ { (yyval.stmt) = slgh->pcode.createOpNoOut(CPUI_CALL,new ExprTree((yyvsp[-1].varnode))); } break; - case 169: + case 169: /* statement: CALL_KEY '[' expr ']' ';' */ { (yyval.stmt) = slgh->pcode.createOpNoOut(CPUI_CALLIND,(yyvsp[-2].tree)); } break; - case 170: - { slgh->reportError("Must specify an indirect parameter for return"); YYERROR; } + case 170: /* statement: RETURN_KEY ';' */ + { (yyval.stmt) = (vector *)0; slgh->reportError("Must specify an indirect parameter for return"); YYERROR; } break; - case 171: + case 171: /* statement: RETURN_KEY '[' expr ']' ';' */ { (yyval.stmt) = slgh->pcode.createOpNoOut(CPUI_RETURN,(yyvsp[-2].tree)); } break; - case 172: + case 172: /* statement: MACROSYM '(' paramlist ')' ';' */ { (yyval.stmt) = slgh->createMacroUse((yyvsp[-4].macrosym),(yyvsp[-2].param)); } break; - case 173: + case 173: /* statement: label */ { (yyval.stmt) = slgh->pcode.placeLabel( (yyvsp[0].labelsym) ); } break; - case 174: + case 174: /* expr: varnode */ { (yyval.tree) = new ExprTree((yyvsp[0].varnode)); } break; - case 175: + case 175: /* expr: sizedstar expr */ { (yyval.tree) = slgh->pcode.createLoad((yyvsp[-1].starqual),(yyvsp[0].tree)); } break; - case 176: + case 176: /* expr: '(' expr ')' */ { (yyval.tree) = (yyvsp[-1].tree); } break; - case 177: + case 177: /* expr: expr '+' expr */ { (yyval.tree) = slgh->pcode.createOp(CPUI_INT_ADD,(yyvsp[-2].tree),(yyvsp[0].tree)); } break; - case 178: + case 178: /* expr: expr '-' expr */ { (yyval.tree) = slgh->pcode.createOp(CPUI_INT_SUB,(yyvsp[-2].tree),(yyvsp[0].tree)); } break; - case 179: + case 179: /* expr: expr OP_EQUAL expr */ { (yyval.tree) = slgh->pcode.createOp(CPUI_INT_EQUAL,(yyvsp[-2].tree),(yyvsp[0].tree)); } break; - case 180: + case 180: /* expr: expr OP_NOTEQUAL expr */ { (yyval.tree) = slgh->pcode.createOp(CPUI_INT_NOTEQUAL,(yyvsp[-2].tree),(yyvsp[0].tree)); } break; - case 181: + case 181: /* expr: expr '<' expr */ { (yyval.tree) = slgh->pcode.createOp(CPUI_INT_LESS,(yyvsp[-2].tree),(yyvsp[0].tree)); } break; - case 182: + case 182: /* expr: expr OP_GREATEQUAL expr */ { (yyval.tree) = slgh->pcode.createOp(CPUI_INT_LESSEQUAL,(yyvsp[0].tree),(yyvsp[-2].tree)); } break; - case 183: + case 183: /* expr: expr OP_LESSEQUAL expr */ { (yyval.tree) = slgh->pcode.createOp(CPUI_INT_LESSEQUAL,(yyvsp[-2].tree),(yyvsp[0].tree)); } break; - case 184: + case 184: /* expr: expr '>' expr */ { (yyval.tree) = slgh->pcode.createOp(CPUI_INT_LESS,(yyvsp[0].tree),(yyvsp[-2].tree)); } break; - case 185: + case 185: /* expr: expr OP_SLESS expr */ { (yyval.tree) = slgh->pcode.createOp(CPUI_INT_SLESS,(yyvsp[-2].tree),(yyvsp[0].tree)); } break; - case 186: + case 186: /* expr: expr OP_SGREATEQUAL expr */ { (yyval.tree) = slgh->pcode.createOp(CPUI_INT_SLESSEQUAL,(yyvsp[0].tree),(yyvsp[-2].tree)); } break; - case 187: + case 187: /* expr: expr OP_SLESSEQUAL expr */ { (yyval.tree) = slgh->pcode.createOp(CPUI_INT_SLESSEQUAL,(yyvsp[-2].tree),(yyvsp[0].tree)); } break; - case 188: + case 188: /* expr: expr OP_SGREAT expr */ { (yyval.tree) = slgh->pcode.createOp(CPUI_INT_SLESS,(yyvsp[0].tree),(yyvsp[-2].tree)); } break; - case 189: + case 189: /* expr: '-' expr */ { (yyval.tree) = slgh->pcode.createOp(CPUI_INT_2COMP,(yyvsp[0].tree)); } break; - case 190: + case 190: /* expr: '~' expr */ { (yyval.tree) = slgh->pcode.createOp(CPUI_INT_NEGATE,(yyvsp[0].tree)); } break; - case 191: + case 191: /* expr: expr '^' expr */ { (yyval.tree) = slgh->pcode.createOp(CPUI_INT_XOR,(yyvsp[-2].tree),(yyvsp[0].tree)); } break; - case 192: + case 192: /* expr: expr '&' expr */ { (yyval.tree) = slgh->pcode.createOp(CPUI_INT_AND,(yyvsp[-2].tree),(yyvsp[0].tree)); } break; - case 193: + case 193: /* expr: expr '|' expr */ { (yyval.tree) = slgh->pcode.createOp(CPUI_INT_OR,(yyvsp[-2].tree),(yyvsp[0].tree)); } break; - case 194: + case 194: /* expr: expr OP_LEFT expr */ { (yyval.tree) = slgh->pcode.createOp(CPUI_INT_LEFT,(yyvsp[-2].tree),(yyvsp[0].tree)); } break; - case 195: + case 195: /* expr: expr OP_RIGHT expr */ { (yyval.tree) = slgh->pcode.createOp(CPUI_INT_RIGHT,(yyvsp[-2].tree),(yyvsp[0].tree)); } break; - case 196: + case 196: /* expr: expr OP_SRIGHT expr */ { (yyval.tree) = slgh->pcode.createOp(CPUI_INT_SRIGHT,(yyvsp[-2].tree),(yyvsp[0].tree)); } break; - case 197: + case 197: /* expr: expr '*' expr */ { (yyval.tree) = slgh->pcode.createOp(CPUI_INT_MULT,(yyvsp[-2].tree),(yyvsp[0].tree)); } break; - case 198: + case 198: /* expr: expr '/' expr */ { (yyval.tree) = slgh->pcode.createOp(CPUI_INT_DIV,(yyvsp[-2].tree),(yyvsp[0].tree)); } break; - case 199: + case 199: /* expr: expr OP_SDIV expr */ { (yyval.tree) = slgh->pcode.createOp(CPUI_INT_SDIV,(yyvsp[-2].tree),(yyvsp[0].tree)); } break; - case 200: + case 200: /* expr: expr '%' expr */ { (yyval.tree) = slgh->pcode.createOp(CPUI_INT_REM,(yyvsp[-2].tree),(yyvsp[0].tree)); } break; - case 201: + case 201: /* expr: expr OP_SREM expr */ { (yyval.tree) = slgh->pcode.createOp(CPUI_INT_SREM,(yyvsp[-2].tree),(yyvsp[0].tree)); } break; - case 202: + case 202: /* expr: '!' expr */ { (yyval.tree) = slgh->pcode.createOp(CPUI_BOOL_NEGATE,(yyvsp[0].tree)); } break; - case 203: + case 203: /* expr: expr OP_BOOL_XOR expr */ { (yyval.tree) = slgh->pcode.createOp(CPUI_BOOL_XOR,(yyvsp[-2].tree),(yyvsp[0].tree)); } break; - case 204: + case 204: /* expr: expr OP_BOOL_AND expr */ { (yyval.tree) = slgh->pcode.createOp(CPUI_BOOL_AND,(yyvsp[-2].tree),(yyvsp[0].tree)); } break; - case 205: + case 205: /* expr: expr OP_BOOL_OR expr */ { (yyval.tree) = slgh->pcode.createOp(CPUI_BOOL_OR,(yyvsp[-2].tree),(yyvsp[0].tree)); } break; - case 206: + case 206: /* expr: expr OP_FEQUAL expr */ { (yyval.tree) = slgh->pcode.createOp(CPUI_FLOAT_EQUAL,(yyvsp[-2].tree),(yyvsp[0].tree)); } break; - case 207: + case 207: /* expr: expr OP_FNOTEQUAL expr */ { (yyval.tree) = slgh->pcode.createOp(CPUI_FLOAT_NOTEQUAL,(yyvsp[-2].tree),(yyvsp[0].tree)); } break; - case 208: + case 208: /* expr: expr OP_FLESS expr */ { (yyval.tree) = slgh->pcode.createOp(CPUI_FLOAT_LESS,(yyvsp[-2].tree),(yyvsp[0].tree)); } break; - case 209: + case 209: /* expr: expr OP_FGREAT expr */ { (yyval.tree) = slgh->pcode.createOp(CPUI_FLOAT_LESS,(yyvsp[0].tree),(yyvsp[-2].tree)); } break; - case 210: + case 210: /* expr: expr OP_FLESSEQUAL expr */ { (yyval.tree) = slgh->pcode.createOp(CPUI_FLOAT_LESSEQUAL,(yyvsp[-2].tree),(yyvsp[0].tree)); } break; - case 211: + case 211: /* expr: expr OP_FGREATEQUAL expr */ { (yyval.tree) = slgh->pcode.createOp(CPUI_FLOAT_LESSEQUAL,(yyvsp[0].tree),(yyvsp[-2].tree)); } break; - case 212: + case 212: /* expr: expr OP_FADD expr */ { (yyval.tree) = slgh->pcode.createOp(CPUI_FLOAT_ADD,(yyvsp[-2].tree),(yyvsp[0].tree)); } break; - case 213: + case 213: /* expr: expr OP_FSUB expr */ { (yyval.tree) = slgh->pcode.createOp(CPUI_FLOAT_SUB,(yyvsp[-2].tree),(yyvsp[0].tree)); } break; - case 214: + case 214: /* expr: expr OP_FMULT expr */ { (yyval.tree) = slgh->pcode.createOp(CPUI_FLOAT_MULT,(yyvsp[-2].tree),(yyvsp[0].tree)); } break; - case 215: + case 215: /* expr: expr OP_FDIV expr */ { (yyval.tree) = slgh->pcode.createOp(CPUI_FLOAT_DIV,(yyvsp[-2].tree),(yyvsp[0].tree)); } break; - case 216: + case 216: /* expr: OP_FSUB expr */ { (yyval.tree) = slgh->pcode.createOp(CPUI_FLOAT_NEG,(yyvsp[0].tree)); } break; - case 217: + case 217: /* expr: OP_ABS '(' expr ')' */ { (yyval.tree) = slgh->pcode.createOp(CPUI_FLOAT_ABS,(yyvsp[-1].tree)); } break; - case 218: + case 218: /* expr: OP_SQRT '(' expr ')' */ { (yyval.tree) = slgh->pcode.createOp(CPUI_FLOAT_SQRT,(yyvsp[-1].tree)); } break; - case 219: + case 219: /* expr: OP_SEXT '(' expr ')' */ { (yyval.tree) = slgh->pcode.createOp(CPUI_INT_SEXT,(yyvsp[-1].tree)); } break; - case 220: + case 220: /* expr: OP_ZEXT '(' expr ')' */ { (yyval.tree) = slgh->pcode.createOp(CPUI_INT_ZEXT,(yyvsp[-1].tree)); } break; - case 221: + case 221: /* expr: OP_CARRY '(' expr ',' expr ')' */ { (yyval.tree) = slgh->pcode.createOp(CPUI_INT_CARRY,(yyvsp[-3].tree),(yyvsp[-1].tree)); } break; - case 222: + case 222: /* expr: OP_SCARRY '(' expr ',' expr ')' */ { (yyval.tree) = slgh->pcode.createOp(CPUI_INT_SCARRY,(yyvsp[-3].tree),(yyvsp[-1].tree)); } break; - case 223: + case 223: /* expr: OP_SBORROW '(' expr ',' expr ')' */ { (yyval.tree) = slgh->pcode.createOp(CPUI_INT_SBORROW,(yyvsp[-3].tree),(yyvsp[-1].tree)); } break; - case 224: + case 224: /* expr: OP_FLOAT2FLOAT '(' expr ')' */ { (yyval.tree) = slgh->pcode.createOp(CPUI_FLOAT_FLOAT2FLOAT,(yyvsp[-1].tree)); } break; - case 225: + case 225: /* expr: OP_INT2FLOAT '(' expr ')' */ { (yyval.tree) = slgh->pcode.createOp(CPUI_FLOAT_INT2FLOAT,(yyvsp[-1].tree)); } break; - case 226: + case 226: /* expr: OP_NAN '(' expr ')' */ { (yyval.tree) = slgh->pcode.createOp(CPUI_FLOAT_NAN,(yyvsp[-1].tree)); } break; - case 227: + case 227: /* expr: OP_TRUNC '(' expr ')' */ { (yyval.tree) = slgh->pcode.createOp(CPUI_FLOAT_TRUNC,(yyvsp[-1].tree)); } break; - case 228: + case 228: /* expr: OP_CEIL '(' expr ')' */ { (yyval.tree) = slgh->pcode.createOp(CPUI_FLOAT_CEIL,(yyvsp[-1].tree)); } break; - case 229: + case 229: /* expr: OP_FLOOR '(' expr ')' */ { (yyval.tree) = slgh->pcode.createOp(CPUI_FLOAT_FLOOR,(yyvsp[-1].tree)); } break; - case 230: + case 230: /* expr: OP_ROUND '(' expr ')' */ { (yyval.tree) = slgh->pcode.createOp(CPUI_FLOAT_ROUND,(yyvsp[-1].tree)); } break; - case 231: + case 231: /* expr: OP_NEW '(' expr ')' */ { (yyval.tree) = slgh->pcode.createOp(CPUI_NEW,(yyvsp[-1].tree)); } break; - case 232: + case 232: /* expr: OP_NEW '(' expr ',' expr ')' */ { (yyval.tree) = slgh->pcode.createOp(CPUI_NEW,(yyvsp[-3].tree),(yyvsp[-1].tree)); } break; - case 233: + case 233: /* expr: OP_POPCOUNT '(' expr ')' */ { (yyval.tree) = slgh->pcode.createOp(CPUI_POPCOUNT,(yyvsp[-1].tree)); } break; - case 234: + case 234: /* expr: OP_LZCOUNT '(' expr ')' */ { (yyval.tree) = slgh->pcode.createOp(CPUI_LZCOUNT,(yyvsp[-1].tree)); } break; - case 235: + case 235: /* expr: specificsymbol '(' integervarnode ')' */ { (yyval.tree) = slgh->pcode.createOp(CPUI_SUBPIECE,new ExprTree((yyvsp[-3].specsym)->getVarnode()),new ExprTree((yyvsp[-1].varnode))); } break; - case 236: + case 236: /* expr: specificsymbol ':' INTEGER */ { (yyval.tree) = slgh->pcode.createBitRange((yyvsp[-2].specsym),0,(uint4)(*(yyvsp[0].i) * 8)); delete (yyvsp[0].i); } break; - case 237: + case 237: /* expr: specificsymbol '[' INTEGER ',' INTEGER ']' */ { (yyval.tree) = slgh->pcode.createBitRange((yyvsp[-5].specsym),(uint4)*(yyvsp[-3].i),(uint4)*(yyvsp[-1].i)); delete (yyvsp[-3].i), delete (yyvsp[-1].i); } break; - case 238: + case 238: /* expr: BITSYM */ { (yyval.tree)=slgh->pcode.createBitRange((yyvsp[0].bitsym)->getParentSymbol(),(yyvsp[0].bitsym)->getBitOffset(),(yyvsp[0].bitsym)->numBits()); } break; - case 239: + case 239: /* expr: USEROPSYM '(' paramlist ')' */ { (yyval.tree) = slgh->pcode.createUserOp((yyvsp[-3].useropsym),(yyvsp[-1].param)); } break; - case 240: - { 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)); } + case 240: /* expr: OP_CPOOLREF '(' paramlist ')' */ + { if ((*(yyvsp[-1].param)).size() < 2) { string errmsg = "Must be at least two inputs to cpool"; slgh->reportError(errmsg); delete (yyvsp[-1].param); YYERROR; } (yyval.tree) = slgh->pcode.createVariadic(CPUI_CPOOLREF,(yyvsp[-1].param)); } break; - case 241: + case 241: /* sizedstar: '*' '[' SPACESYM ']' ':' INTEGER */ { (yyval.starqual) = new StarQuality; (yyval.starqual)->size = *(yyvsp[0].i); delete (yyvsp[0].i); (yyval.starqual)->id=ConstTpl((yyvsp[-3].spacesym)->getSpace()); } break; - case 242: + case 242: /* sizedstar: '*' '[' SPACESYM ']' */ { (yyval.starqual) = new StarQuality; (yyval.starqual)->size = 0; (yyval.starqual)->id=ConstTpl((yyvsp[-1].spacesym)->getSpace()); } break; - case 243: + case 243: /* sizedstar: '*' ':' INTEGER */ { (yyval.starqual) = new StarQuality; (yyval.starqual)->size = *(yyvsp[0].i); delete (yyvsp[0].i); (yyval.starqual)->id=ConstTpl(slgh->getDefaultCodeSpace()); } break; - case 244: + case 244: /* sizedstar: '*' */ { (yyval.starqual) = new StarQuality; (yyval.starqual)->size = 0; (yyval.starqual)->id=ConstTpl(slgh->getDefaultCodeSpace()); } break; - case 245: + case 245: /* jumpdest: JUMPSYM */ { VarnodeTpl *sym = (yyvsp[0].specsym)->getVarnode(); (yyval.varnode) = new VarnodeTpl(ConstTpl(ConstTpl::j_curspace),sym->getOffset(),ConstTpl(ConstTpl::j_curspace_size)); delete sym; } break; - case 246: + case 246: /* jumpdest: INTEGER */ { (yyval.varnode) = new VarnodeTpl(ConstTpl(ConstTpl::j_curspace),ConstTpl(ConstTpl::real,*(yyvsp[0].i)),ConstTpl(ConstTpl::j_curspace_size)); delete (yyvsp[0].i); } break; - case 247: + case 247: /* jumpdest: BADINTEGER */ { (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; - case 248: + case 248: /* jumpdest: OPERANDSYM */ { (yyval.varnode) = (yyvsp[0].operandsym)->getVarnode(); (yyvsp[0].operandsym)->setCodeAddress(); } break; - case 249: + case 249: /* jumpdest: INTEGER '[' SPACESYM ']' */ { AddrSpace *spc = (yyvsp[-1].spacesym)->getSpace(); (yyval.varnode) = new VarnodeTpl(ConstTpl(spc),ConstTpl(ConstTpl::real,*(yyvsp[-3].i)),ConstTpl(ConstTpl::real,spc->getAddrSize())); delete (yyvsp[-3].i); } break; - case 250: + case 250: /* jumpdest: label */ { (yyval.varnode) = new VarnodeTpl(ConstTpl(slgh->getConstantSpace()),ConstTpl(ConstTpl::j_relative,(yyvsp[0].labelsym)->getIndex()),ConstTpl(ConstTpl::real,sizeof(uintm))); (yyvsp[0].labelsym)->incrementRefCount(); } break; - case 251: - { string errmsg = "Unknown jump destination: "+*(yyvsp[0].str); delete (yyvsp[0].str); slgh->reportError(errmsg); YYERROR; } + case 251: /* jumpdest: STRING */ + { (yyval.varnode) = (VarnodeTpl *)0; string errmsg = "Unknown jump destination: "+*(yyvsp[0].str); delete (yyvsp[0].str); slgh->reportError(errmsg); YYERROR; } break; - case 252: + case 252: /* varnode: specificsymbol */ { (yyval.varnode) = (yyvsp[0].specsym)->getVarnode(); } break; - case 253: + case 253: /* varnode: integervarnode */ { (yyval.varnode) = (yyvsp[0].varnode); } break; - case 254: - { string errmsg = "Unknown varnode parameter: "+*(yyvsp[0].str); delete (yyvsp[0].str); slgh->reportError(errmsg); YYERROR; } + case 254: /* varnode: STRING */ + { (yyval.varnode) = (VarnodeTpl *)0; string errmsg = "Unknown varnode parameter: "+*(yyvsp[0].str); delete (yyvsp[0].str); slgh->reportError(errmsg); YYERROR; } break; - case 255: - { string errmsg = "Subtable not attached to operand: "+(yyvsp[0].subtablesym)->getName(); slgh->reportError(errmsg); YYERROR; } + case 255: /* varnode: SUBTABLESYM */ + { (yyval.varnode) = (VarnodeTpl *)0; string errmsg = "Subtable not attached to operand: "+(yyvsp[0].subtablesym)->getName(); slgh->reportError(errmsg); YYERROR; } break; - case 256: + case 256: /* integervarnode: INTEGER */ { (yyval.varnode) = new VarnodeTpl(ConstTpl(slgh->getConstantSpace()),ConstTpl(ConstTpl::real,*(yyvsp[0].i)),ConstTpl(ConstTpl::real,0)); delete (yyvsp[0].i); } break; - case 257: + case 257: /* integervarnode: BADINTEGER */ { (yyval.varnode) = new VarnodeTpl(ConstTpl(slgh->getConstantSpace()),ConstTpl(ConstTpl::real,0),ConstTpl(ConstTpl::real,0)); slgh->reportError("Parsed integer is too big (overflow)"); } break; - case 258: + case 258: /* integervarnode: INTEGER ':' INTEGER */ { (yyval.varnode) = new VarnodeTpl(ConstTpl(slgh->getConstantSpace()),ConstTpl(ConstTpl::real,*(yyvsp[-2].i)),ConstTpl(ConstTpl::real,*(yyvsp[0].i))); delete (yyvsp[-2].i); delete (yyvsp[0].i); } break; - case 259: + case 259: /* integervarnode: '&' varnode */ { (yyval.varnode) = slgh->pcode.addressOf((yyvsp[0].varnode),0); } break; - case 260: + case 260: /* integervarnode: '&' ':' INTEGER varnode */ { (yyval.varnode) = slgh->pcode.addressOf((yyvsp[0].varnode),*(yyvsp[-1].i)); delete (yyvsp[-1].i); } break; - case 261: + case 261: /* lhsvarnode: specificsymbol */ { (yyval.varnode) = (yyvsp[0].specsym)->getVarnode(); } break; - case 262: - { string errmsg = "Unknown assignment varnode: "+*(yyvsp[0].str); delete (yyvsp[0].str); slgh->reportError(errmsg); YYERROR; } + case 262: /* lhsvarnode: STRING */ + { (yyval.varnode) = (VarnodeTpl *)0; string errmsg = "Unknown assignment varnode: "+*(yyvsp[0].str); delete (yyvsp[0].str); slgh->reportError(errmsg); YYERROR; } break; - case 263: - { string errmsg = "Subtable not attached to operand: "+(yyvsp[0].subtablesym)->getName(); slgh->reportError(errmsg); YYERROR; } + case 263: /* lhsvarnode: SUBTABLESYM */ + { (yyval.varnode) = (VarnodeTpl *)0; string errmsg = "Subtable not attached to operand: "+(yyvsp[0].subtablesym)->getName(); slgh->reportError(errmsg); YYERROR; } break; - case 264: + case 264: /* label: '<' LABELSYM '>' */ { (yyval.labelsym) = (yyvsp[-1].labelsym); } break; - case 265: + case 265: /* label: '<' STRING '>' */ { (yyval.labelsym) = slgh->pcode.defineLabel( (yyvsp[-1].str) ); } break; - case 266: + case 266: /* exportvarnode: specificsymbol */ { (yyval.varnode) = (yyvsp[0].specsym)->getVarnode(); } break; - case 267: + case 267: /* exportvarnode: '&' varnode */ { (yyval.varnode) = slgh->pcode.addressOf((yyvsp[0].varnode),0); } break; - case 268: + case 268: /* exportvarnode: '&' ':' INTEGER varnode */ { (yyval.varnode) = slgh->pcode.addressOf((yyvsp[0].varnode),*(yyvsp[-1].i)); delete (yyvsp[-1].i); } break; - case 269: + case 269: /* exportvarnode: INTEGER ':' INTEGER */ { (yyval.varnode) = new VarnodeTpl(ConstTpl(slgh->getConstantSpace()),ConstTpl(ConstTpl::real,*(yyvsp[-2].i)),ConstTpl(ConstTpl::real,*(yyvsp[0].i))); delete (yyvsp[-2].i); delete (yyvsp[0].i); } break; - case 270: - { string errmsg="Unknown export varnode: "+*(yyvsp[0].str); delete (yyvsp[0].str); slgh->reportError(errmsg); YYERROR; } + case 270: /* exportvarnode: STRING */ + { (yyval.varnode) = (VarnodeTpl *)0; string errmsg="Unknown export varnode: "+*(yyvsp[0].str); delete (yyvsp[0].str); slgh->reportError(errmsg); YYERROR; } break; - case 271: - { string errmsg = "Subtable not attached to operand: "+(yyvsp[0].subtablesym)->getName(); slgh->reportError(errmsg); YYERROR; } + case 271: /* exportvarnode: SUBTABLESYM */ + { (yyval.varnode) = (VarnodeTpl *)0; string errmsg = "Subtable not attached to operand: "+(yyvsp[0].subtablesym)->getName(); slgh->reportError(errmsg); YYERROR; } break; - case 272: + case 272: /* familysymbol: VALUESYM */ { (yyval.famsym) = (yyvsp[0].valuesym); } break; - case 273: + case 273: /* familysymbol: VALUEMAPSYM */ { (yyval.famsym) = (yyvsp[0].valuemapsym); } break; - case 274: + case 274: /* familysymbol: CONTEXTSYM */ { (yyval.famsym) = (yyvsp[0].contextsym); } break; - case 275: + case 275: /* familysymbol: NAMESYM */ { (yyval.famsym) = (yyvsp[0].namesym); } break; - case 276: + case 276: /* familysymbol: VARLISTSYM */ { (yyval.famsym) = (yyvsp[0].varlistsym); } break; - case 277: + case 277: /* specificsymbol: VARSYM */ { (yyval.specsym) = (yyvsp[0].varsym); } break; - case 278: + case 278: /* specificsymbol: SPECSYM */ { (yyval.specsym) = (yyvsp[0].specsym); } break; - case 279: + case 279: /* specificsymbol: OPERANDSYM */ { (yyval.specsym) = (yyvsp[0].operandsym); } break; - case 280: + case 280: /* specificsymbol: JUMPSYM */ { (yyval.specsym) = (yyvsp[0].specsym); } break; - case 281: + case 281: /* charstring: CHAR */ { (yyval.str) = new string; (*(yyval.str)) += (yyvsp[0].ch); } break; - case 282: + case 282: /* charstring: charstring CHAR */ { (yyval.str) = (yyvsp[-1].str); (*(yyval.str)) += (yyvsp[0].ch); } break; - case 283: + case 283: /* intblist: '[' intbpart ']' */ { (yyval.biglist) = (yyvsp[-1].biglist); } break; - case 284: + case 284: /* intblist: INTEGER */ { (yyval.biglist) = new vector; (yyval.biglist)->push_back(intb(*(yyvsp[0].i))); delete (yyvsp[0].i); } break; - case 285: + case 285: /* intblist: '-' INTEGER */ { (yyval.biglist) = new vector; (yyval.biglist)->push_back(-intb(*(yyvsp[0].i))); delete (yyvsp[0].i); } break; - case 286: + case 286: /* intbpart: INTEGER */ { (yyval.biglist) = new vector; (yyval.biglist)->push_back(intb(*(yyvsp[0].i))); delete (yyvsp[0].i); } break; - case 287: + case 287: /* intbpart: '-' INTEGER */ { (yyval.biglist) = new vector; (yyval.biglist)->push_back(-intb(*(yyvsp[0].i))); delete (yyvsp[0].i); } break; - case 288: + case 288: /* intbpart: STRING */ { 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; - case 289: + case 289: /* intbpart: intbpart INTEGER */ { (yyval.biglist) = (yyvsp[-1].biglist); (yyval.biglist)->push_back(intb(*(yyvsp[0].i))); delete (yyvsp[0].i); } break; - case 290: + case 290: /* intbpart: intbpart '-' INTEGER */ { (yyval.biglist) = (yyvsp[-2].biglist); (yyval.biglist)->push_back(-intb(*(yyvsp[0].i))); delete (yyvsp[0].i); } break; - case 291: - { if (*(yyvsp[0].str)!="_") { string errmsg = "Expecting integer but saw: "+*(yyvsp[0].str); delete (yyvsp[0].str); slgh->reportError(errmsg); YYERROR; } + case 291: /* intbpart: intbpart STRING */ + { if (*(yyvsp[0].str)!="_") { string errmsg = "Expecting integer but saw: "+*(yyvsp[0].str); delete (yyvsp[-1].biglist); delete (yyvsp[0].str); slgh->reportError(errmsg); YYERROR; } (yyval.biglist) = (yyvsp[-1].biglist); (yyval.biglist)->push_back((intb)0xBADBEEF); delete (yyvsp[0].str); } break; - case 292: + case 292: /* stringlist: '[' stringpart ']' */ { (yyval.strlist) = (yyvsp[-1].strlist); } break; - case 293: + case 293: /* stringlist: STRING */ { (yyval.strlist) = new vector; (yyval.strlist)->push_back(*(yyvsp[0].str)); delete (yyvsp[0].str); } break; - case 294: + case 294: /* stringpart: STRING */ { (yyval.strlist) = new vector; (yyval.strlist)->push_back( *(yyvsp[0].str) ); delete (yyvsp[0].str); } break; - case 295: + case 295: /* stringpart: stringpart STRING */ { (yyval.strlist) = (yyvsp[-1].strlist); (yyval.strlist)->push_back(*(yyvsp[0].str)); delete (yyvsp[0].str); } break; - case 296: - { string errmsg = (yyvsp[0].anysym)->getName()+": redefined"; slgh->reportError(errmsg); YYERROR; } + case 296: /* stringpart: stringpart anysymbol */ + { (yyval.strlist) = (vector *)0; delete (yyvsp[-1].strlist); string errmsg = (yyvsp[0].anysym)->getName()+": redefined"; slgh->reportError(errmsg); YYERROR; } break; - case 297: + case 297: /* anystringlist: '[' anystringpart ']' */ { (yyval.strlist) = (yyvsp[-1].strlist); } break; - case 298: + case 298: /* anystringpart: STRING */ { (yyval.strlist) = new vector; (yyval.strlist)->push_back( *(yyvsp[0].str) ); delete (yyvsp[0].str); } break; - case 299: + case 299: /* anystringpart: anysymbol */ { (yyval.strlist) = new vector; (yyval.strlist)->push_back( (yyvsp[0].anysym)->getName() ); } break; - case 300: + case 300: /* anystringpart: anystringpart STRING */ { (yyval.strlist) = (yyvsp[-1].strlist); (yyval.strlist)->push_back(*(yyvsp[0].str)); delete (yyvsp[0].str); } break; - case 301: + case 301: /* anystringpart: anystringpart anysymbol */ { (yyval.strlist) = (yyvsp[-1].strlist); (yyval.strlist)->push_back((yyvsp[0].anysym)->getName()); } break; - case 302: + case 302: /* valuelist: '[' valuepart ']' */ { (yyval.symlist) = (yyvsp[-1].symlist); } break; - case 303: + case 303: /* valuelist: VALUESYM */ { (yyval.symlist) = new vector; (yyval.symlist)->push_back((yyvsp[0].valuesym)); } break; - case 304: + case 304: /* valuelist: CONTEXTSYM */ { (yyval.symlist) = new vector; (yyval.symlist)->push_back((yyvsp[0].contextsym)); } break; - case 305: + case 305: /* valuepart: VALUESYM */ { (yyval.symlist) = new vector; (yyval.symlist)->push_back( (yyvsp[0].valuesym) ); } break; - case 306: + case 306: /* valuepart: CONTEXTSYM */ { (yyval.symlist) = new vector; (yyval.symlist)->push_back((yyvsp[0].contextsym)); } break; - case 307: + case 307: /* valuepart: valuepart VALUESYM */ { (yyval.symlist) = (yyvsp[-1].symlist); (yyval.symlist)->push_back((yyvsp[0].valuesym)); } break; - case 308: + case 308: /* valuepart: valuepart CONTEXTSYM */ { (yyval.symlist) = (yyvsp[-1].symlist); (yyval.symlist)->push_back((yyvsp[0].contextsym)); } break; - case 309: - { string errmsg = *(yyvsp[0].str)+": is not a value pattern"; delete (yyvsp[0].str); slgh->reportError(errmsg); YYERROR; } + case 309: /* valuepart: valuepart STRING */ + { (yyval.symlist) = (vector *)0; delete (yyvsp[-1].symlist); string errmsg = *(yyvsp[0].str)+": is not a value pattern"; delete (yyvsp[0].str); slgh->reportError(errmsg); YYERROR; } break; - case 310: + case 310: /* varlist: '[' varpart ']' */ { (yyval.symlist) = (yyvsp[-1].symlist); } break; - case 311: + case 311: /* varlist: VARSYM */ { (yyval.symlist) = new vector; (yyval.symlist)->push_back((yyvsp[0].varsym)); } break; - case 312: + case 312: /* varpart: VARSYM */ { (yyval.symlist) = new vector; (yyval.symlist)->push_back((yyvsp[0].varsym)); } break; - case 313: + case 313: /* varpart: STRING */ { 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; - case 314: + case 314: /* varpart: varpart VARSYM */ { (yyval.symlist) = (yyvsp[-1].symlist); (yyval.symlist)->push_back((yyvsp[0].varsym)); } break; - case 315: - { if (*(yyvsp[0].str)!="_") { string errmsg = *(yyvsp[0].str)+": is not a varnode symbol"; delete (yyvsp[0].str); slgh->reportError(errmsg); YYERROR; } + case 315: /* varpart: varpart STRING */ + { if (*(yyvsp[0].str)!="_") { string errmsg = *(yyvsp[0].str)+": is not a varnode symbol"; delete (yyvsp[-1].symlist); delete (yyvsp[0].str); slgh->reportError(errmsg); YYERROR; } (yyval.symlist) = (yyvsp[-1].symlist); (yyval.symlist)->push_back((SleighSymbol *)0); delete (yyvsp[0].str); } break; - case 316: + case 316: /* paramlist: %empty */ { (yyval.param) = new vector; } break; - case 317: + case 317: /* paramlist: expr */ { (yyval.param) = new vector; (yyval.param)->push_back((yyvsp[0].tree)); } break; - case 318: + case 318: /* paramlist: paramlist ',' expr */ { (yyval.param) = (yyvsp[-2].param); (yyval.param)->push_back((yyvsp[0].tree)); } break; - case 319: + case 319: /* oplist: %empty */ { (yyval.strlist) = new vector; } break; - case 320: + case 320: /* oplist: STRING */ { (yyval.strlist) = new vector; (yyval.strlist)->push_back(*(yyvsp[0].str)); delete (yyvsp[0].str); } break; - case 321: + case 321: /* oplist: oplist ',' STRING */ { (yyval.strlist) = (yyvsp[-2].strlist); (yyval.strlist)->push_back(*(yyvsp[0].str)); delete (yyvsp[0].str); } break; - case 322: + case 322: /* anysymbol: SPACESYM */ { (yyval.anysym) = (yyvsp[0].spacesym); } break; - case 323: + case 323: /* anysymbol: SECTIONSYM */ { (yyval.anysym) = (yyvsp[0].sectionsym); } break; - case 324: + case 324: /* anysymbol: TOKENSYM */ { (yyval.anysym) = (yyvsp[0].tokensym); } break; - case 325: + case 325: /* anysymbol: USEROPSYM */ { (yyval.anysym) = (yyvsp[0].useropsym); } break; - case 326: + case 326: /* anysymbol: MACROSYM */ { (yyval.anysym) = (yyvsp[0].macrosym); } break; - case 327: + case 327: /* anysymbol: SUBTABLESYM */ { (yyval.anysym) = (yyvsp[0].subtablesym); } break; - case 328: + case 328: /* anysymbol: VALUESYM */ { (yyval.anysym) = (yyvsp[0].valuesym); } break; - case 329: + case 329: /* anysymbol: VALUEMAPSYM */ { (yyval.anysym) = (yyvsp[0].valuemapsym); } break; - case 330: + case 330: /* anysymbol: CONTEXTSYM */ { (yyval.anysym) = (yyvsp[0].contextsym); } break; - case 331: + case 331: /* anysymbol: NAMESYM */ { (yyval.anysym) = (yyvsp[0].namesym); } break; - case 332: + case 332: /* anysymbol: VARSYM */ { (yyval.anysym) = (yyvsp[0].varsym); } break; - case 333: + case 333: /* anysymbol: VARLISTSYM */ { (yyval.anysym) = (yyvsp[0].varlistsym); } break; - case 334: + case 334: /* anysymbol: OPERANDSYM */ { (yyval.anysym) = (yyvsp[0].operandsym); } break; - case 335: + case 335: /* anysymbol: JUMPSYM */ { (yyval.anysym) = (yyvsp[0].specsym); } break; - case 336: + case 336: /* anysymbol: BITSYM */ { (yyval.anysym) = (yyvsp[0].bitsym); } break; @@ -3642,11 +3614,10 @@ yyreduce: case of YYERROR or YYBACKUP, subsequent parser actions might lead to an incorrect destructor call or verbose syntax error message before the lookahead is translated. */ - YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc); + YY_SYMBOL_PRINT ("-> $$ =", YY_CAST (yysymbol_kind_t, yyr1[yyn]), &yyval, &yyloc); YYPOPSTACK (yylen); yylen = 0; - YY_STACK_PRINT (yyss, yyssp); *++yyvsp = yyval; @@ -3670,66 +3641,30 @@ yyreduce: yyerrlab: /* Make sure we have latest lookahead translation. See comments at user semantic actions for why this is necessary. */ - yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar); - + yytoken = yychar == SLEIGHEMPTY ? YYSYMBOL_YYEMPTY : YYTRANSLATE (yychar); /* If not already recovering from an error, report this error. */ if (!yyerrstatus) { ++yynerrs; -#if ! YYERROR_VERBOSE yyerror (YY_("syntax error")); -#else -# define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \ - yyssp, yytoken) - { - char const *yymsgp = YY_("syntax error"); - int yysyntax_error_status; - yysyntax_error_status = YYSYNTAX_ERROR; - if (yysyntax_error_status == 0) - yymsgp = yymsg; - else if (yysyntax_error_status == 1) - { - if (yymsg != yymsgbuf) - YYSTACK_FREE (yymsg); - yymsg = YY_CAST (char *, YYSTACK_ALLOC (YY_CAST (YYSIZE_T, yymsg_alloc))); - if (!yymsg) - { - yymsg = yymsgbuf; - yymsg_alloc = sizeof yymsgbuf; - yysyntax_error_status = 2; - } - else - { - yysyntax_error_status = YYSYNTAX_ERROR; - yymsgp = yymsg; - } - } - yyerror (yymsgp); - if (yysyntax_error_status == 2) - goto yyexhaustedlab; - } -# undef YYSYNTAX_ERROR -#endif } - - if (yyerrstatus == 3) { /* If just tried and failed to reuse lookahead token after an error, discard it. */ - if (yychar <= YYEOF) + if (yychar <= SLEIGHEOF) { /* Return failure if at end of input. */ - if (yychar == YYEOF) + if (yychar == SLEIGHEOF) YYABORT; } else { yydestruct ("Error: discarding", yytoken, &yylval); - yychar = YYEMPTY; + yychar = SLEIGHEMPTY; } } @@ -3762,13 +3697,14 @@ yyerrorlab: yyerrlab1: yyerrstatus = 3; /* Each real token shifted decrements this. */ + /* Pop stack until we find a state that shifts the error token. */ for (;;) { yyn = yypact[yystate]; if (!yypact_value_is_default (yyn)) { - yyn += YYTERROR; - if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR) + yyn += YYSYMBOL_YYerror; + if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYSYMBOL_YYerror) { yyn = yytable[yyn]; if (0 < yyn) @@ -3782,7 +3718,7 @@ yyerrlab1: yydestruct ("Error: popping", - yystos[yystate], yyvsp); + YY_ACCESSING_SYMBOL (yystate), yyvsp); YYPOPSTACK (1); yystate = *yyssp; YY_STACK_PRINT (yyss, yyssp); @@ -3794,7 +3730,7 @@ yyerrlab1: /* Shift the error token. */ - YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp); + YY_SYMBOL_PRINT ("Shifting", YY_ACCESSING_SYMBOL (yyn), yyvsp, yylsp); yystate = yyn; goto yynewstate; @@ -3816,22 +3752,22 @@ yyabortlab: goto yyreturn; -#if !defined yyoverflow || YYERROR_VERBOSE +#if !defined yyoverflow /*-------------------------------------------------. | yyexhaustedlab -- memory exhaustion comes here. | `-------------------------------------------------*/ yyexhaustedlab: yyerror (YY_("memory exhausted")); yyresult = 2; - /* Fall through. */ + goto yyreturn; #endif -/*-----------------------------------------------------. -| yyreturn -- parsing is finished, return the result. | -`-----------------------------------------------------*/ +/*-------------------------------------------------------. +| yyreturn -- parsing is finished, clean up and return. | +`-------------------------------------------------------*/ yyreturn: - if (yychar != YYEMPTY) + if (yychar != SLEIGHEMPTY) { /* Make sure we have latest lookahead translation. See comments at user semantic actions for why this is necessary. */ @@ -3846,21 +3782,19 @@ yyreturn: while (yyssp != yyss) { yydestruct ("Cleanup: popping", - yystos[+*yyssp], yyvsp); + YY_ACCESSING_SYMBOL (+*yyssp), yyvsp); YYPOPSTACK (1); } #ifndef yyoverflow if (yyss != yyssa) YYSTACK_FREE (yyss); #endif -#if YYERROR_VERBOSE - if (yymsg != yymsgbuf) - YYSTACK_FREE (yymsg); -#endif + return yyresult; } + int sleigherror(const char *s) { diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/slghparse.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/slghparse.hh index 3d615cc319..5d72496c6b 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/slghparse.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/slghparse.hh @@ -4,16 +4,16 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ -/* A Bison parser, made by GNU Bison 3.5.1. */ +/* A Bison parser, made by GNU Bison 3.7.4. */ /* Bison interface for Yacc-like parsers in C @@ -46,8 +46,9 @@ This special exception was added by the Free Software Foundation in version 2.2 of Bison. */ -/* Undocumented macros, especially those whose name start with YY_, - are private implementation details. Do not rely on them. */ +/* DO NOT RELY ON FEATURES THAT ARE NOT DOCUMENTED in the manual, + especially those whose name start with YY_ or yy_. They are + private implementation details that can be changed or removed. */ #ifndef YY_SLEIGH_SLGHPARSE_HH_INCLUDED # define YY_SLEIGH_SLGHPARSE_HH_INCLUDED @@ -67,123 +68,128 @@ extern int sleighdebug; #endif -/* Token type. */ +/* Token kinds. */ #ifndef SLEIGHTOKENTYPE # define SLEIGHTOKENTYPE enum sleightokentype { - OP_BOOL_OR = 258, - OP_BOOL_AND = 259, - OP_BOOL_XOR = 260, - OP_OR = 261, - OP_XOR = 262, - OP_AND = 263, - OP_EQUAL = 264, - OP_NOTEQUAL = 265, - OP_FEQUAL = 266, - OP_FNOTEQUAL = 267, - OP_GREATEQUAL = 268, - OP_LESSEQUAL = 269, - OP_SLESS = 270, - OP_SGREATEQUAL = 271, - OP_SLESSEQUAL = 272, - OP_SGREAT = 273, - OP_FLESS = 274, - OP_FGREAT = 275, - OP_FLESSEQUAL = 276, - OP_FGREATEQUAL = 277, - OP_LEFT = 278, - OP_RIGHT = 279, - OP_SRIGHT = 280, - OP_FADD = 281, - OP_FSUB = 282, - OP_SDIV = 283, - OP_SREM = 284, - OP_FMULT = 285, - OP_FDIV = 286, - OP_ZEXT = 287, - OP_CARRY = 288, - OP_BORROW = 289, - OP_SEXT = 290, - OP_SCARRY = 291, - OP_SBORROW = 292, - OP_NAN = 293, - OP_ABS = 294, - OP_SQRT = 295, - OP_CEIL = 296, - OP_FLOOR = 297, - OP_ROUND = 298, - OP_INT2FLOAT = 299, - OP_FLOAT2FLOAT = 300, - OP_TRUNC = 301, - OP_CPOOLREF = 302, - OP_NEW = 303, - OP_POPCOUNT = 304, - OP_LZCOUNT = 305, - BADINTEGER = 306, - GOTO_KEY = 307, - CALL_KEY = 308, - RETURN_KEY = 309, - IF_KEY = 310, - DEFINE_KEY = 311, - ATTACH_KEY = 312, - MACRO_KEY = 313, - SPACE_KEY = 314, - TYPE_KEY = 315, - RAM_KEY = 316, - DEFAULT_KEY = 317, - REGISTER_KEY = 318, - ENDIAN_KEY = 319, - WITH_KEY = 320, - ALIGN_KEY = 321, - OP_UNIMPL = 322, - TOKEN_KEY = 323, - SIGNED_KEY = 324, - NOFLOW_KEY = 325, - HEX_KEY = 326, - DEC_KEY = 327, - BIG_KEY = 328, - LITTLE_KEY = 329, - SIZE_KEY = 330, - WORDSIZE_KEY = 331, - OFFSET_KEY = 332, - NAMES_KEY = 333, - VALUES_KEY = 334, - VARIABLES_KEY = 335, - PCODEOP_KEY = 336, - IS_KEY = 337, - LOCAL_KEY = 338, - DELAYSLOT_KEY = 339, - CROSSBUILD_KEY = 340, - EXPORT_KEY = 341, - BUILD_KEY = 342, - CONTEXT_KEY = 343, - ELLIPSIS_KEY = 344, - GLOBALSET_KEY = 345, - BITRANGE_KEY = 346, - CHAR = 347, - INTEGER = 348, - INTB = 349, - STRING = 350, - SYMBOLSTRING = 351, - SPACESYM = 352, - SECTIONSYM = 353, - TOKENSYM = 354, - USEROPSYM = 355, - VALUESYM = 356, - VALUEMAPSYM = 357, - CONTEXTSYM = 358, - NAMESYM = 359, - VARSYM = 360, - BITSYM = 361, - SPECSYM = 362, - VARLISTSYM = 363, - OPERANDSYM = 364, - JUMPSYM = 365, - MACROSYM = 366, - LABELSYM = 367, - SUBTABLESYM = 368 + SLEIGHEMPTY = -2, + SLEIGHEOF = 0, /* "end of file" */ + SLEIGHerror = 256, /* error */ + SLEIGHUNDEF = 257, /* "invalid token" */ + OP_BOOL_OR = 258, /* OP_BOOL_OR */ + OP_BOOL_AND = 259, /* OP_BOOL_AND */ + OP_BOOL_XOR = 260, /* OP_BOOL_XOR */ + OP_OR = 261, /* OP_OR */ + OP_XOR = 262, /* OP_XOR */ + OP_AND = 263, /* OP_AND */ + OP_EQUAL = 264, /* OP_EQUAL */ + OP_NOTEQUAL = 265, /* OP_NOTEQUAL */ + OP_FEQUAL = 266, /* OP_FEQUAL */ + OP_FNOTEQUAL = 267, /* OP_FNOTEQUAL */ + OP_GREATEQUAL = 268, /* OP_GREATEQUAL */ + OP_LESSEQUAL = 269, /* OP_LESSEQUAL */ + OP_SLESS = 270, /* OP_SLESS */ + OP_SGREATEQUAL = 271, /* OP_SGREATEQUAL */ + OP_SLESSEQUAL = 272, /* OP_SLESSEQUAL */ + OP_SGREAT = 273, /* OP_SGREAT */ + OP_FLESS = 274, /* OP_FLESS */ + OP_FGREAT = 275, /* OP_FGREAT */ + OP_FLESSEQUAL = 276, /* OP_FLESSEQUAL */ + OP_FGREATEQUAL = 277, /* OP_FGREATEQUAL */ + OP_LEFT = 278, /* OP_LEFT */ + OP_RIGHT = 279, /* OP_RIGHT */ + OP_SRIGHT = 280, /* OP_SRIGHT */ + OP_FADD = 281, /* OP_FADD */ + OP_FSUB = 282, /* OP_FSUB */ + OP_SDIV = 283, /* OP_SDIV */ + OP_SREM = 284, /* OP_SREM */ + OP_FMULT = 285, /* OP_FMULT */ + OP_FDIV = 286, /* OP_FDIV */ + OP_ZEXT = 287, /* OP_ZEXT */ + OP_CARRY = 288, /* OP_CARRY */ + OP_BORROW = 289, /* OP_BORROW */ + OP_SEXT = 290, /* OP_SEXT */ + OP_SCARRY = 291, /* OP_SCARRY */ + OP_SBORROW = 292, /* OP_SBORROW */ + OP_NAN = 293, /* OP_NAN */ + OP_ABS = 294, /* OP_ABS */ + OP_SQRT = 295, /* OP_SQRT */ + OP_CEIL = 296, /* OP_CEIL */ + OP_FLOOR = 297, /* OP_FLOOR */ + OP_ROUND = 298, /* OP_ROUND */ + OP_INT2FLOAT = 299, /* OP_INT2FLOAT */ + OP_FLOAT2FLOAT = 300, /* OP_FLOAT2FLOAT */ + OP_TRUNC = 301, /* OP_TRUNC */ + OP_CPOOLREF = 302, /* OP_CPOOLREF */ + OP_NEW = 303, /* OP_NEW */ + OP_POPCOUNT = 304, /* OP_POPCOUNT */ + OP_LZCOUNT = 305, /* OP_LZCOUNT */ + BADINTEGER = 306, /* BADINTEGER */ + GOTO_KEY = 307, /* GOTO_KEY */ + CALL_KEY = 308, /* CALL_KEY */ + RETURN_KEY = 309, /* RETURN_KEY */ + IF_KEY = 310, /* IF_KEY */ + DEFINE_KEY = 311, /* DEFINE_KEY */ + ATTACH_KEY = 312, /* ATTACH_KEY */ + MACRO_KEY = 313, /* MACRO_KEY */ + SPACE_KEY = 314, /* SPACE_KEY */ + TYPE_KEY = 315, /* TYPE_KEY */ + RAM_KEY = 316, /* RAM_KEY */ + DEFAULT_KEY = 317, /* DEFAULT_KEY */ + REGISTER_KEY = 318, /* REGISTER_KEY */ + ENDIAN_KEY = 319, /* ENDIAN_KEY */ + WITH_KEY = 320, /* WITH_KEY */ + ALIGN_KEY = 321, /* ALIGN_KEY */ + OP_UNIMPL = 322, /* OP_UNIMPL */ + TOKEN_KEY = 323, /* TOKEN_KEY */ + SIGNED_KEY = 324, /* SIGNED_KEY */ + NOFLOW_KEY = 325, /* NOFLOW_KEY */ + HEX_KEY = 326, /* HEX_KEY */ + DEC_KEY = 327, /* DEC_KEY */ + BIG_KEY = 328, /* BIG_KEY */ + LITTLE_KEY = 329, /* LITTLE_KEY */ + SIZE_KEY = 330, /* SIZE_KEY */ + WORDSIZE_KEY = 331, /* WORDSIZE_KEY */ + OFFSET_KEY = 332, /* OFFSET_KEY */ + NAMES_KEY = 333, /* NAMES_KEY */ + VALUES_KEY = 334, /* VALUES_KEY */ + VARIABLES_KEY = 335, /* VARIABLES_KEY */ + PCODEOP_KEY = 336, /* PCODEOP_KEY */ + IS_KEY = 337, /* IS_KEY */ + LOCAL_KEY = 338, /* LOCAL_KEY */ + DELAYSLOT_KEY = 339, /* DELAYSLOT_KEY */ + CROSSBUILD_KEY = 340, /* CROSSBUILD_KEY */ + EXPORT_KEY = 341, /* EXPORT_KEY */ + BUILD_KEY = 342, /* BUILD_KEY */ + CONTEXT_KEY = 343, /* CONTEXT_KEY */ + ELLIPSIS_KEY = 344, /* ELLIPSIS_KEY */ + GLOBALSET_KEY = 345, /* GLOBALSET_KEY */ + BITRANGE_KEY = 346, /* BITRANGE_KEY */ + CHAR = 347, /* CHAR */ + INTEGER = 348, /* INTEGER */ + INTB = 349, /* INTB */ + STRING = 350, /* STRING */ + SYMBOLSTRING = 351, /* SYMBOLSTRING */ + SPACESYM = 352, /* SPACESYM */ + SECTIONSYM = 353, /* SECTIONSYM */ + TOKENSYM = 354, /* TOKENSYM */ + USEROPSYM = 355, /* USEROPSYM */ + VALUESYM = 356, /* VALUESYM */ + VALUEMAPSYM = 357, /* VALUEMAPSYM */ + CONTEXTSYM = 358, /* CONTEXTSYM */ + NAMESYM = 359, /* NAMESYM */ + VARSYM = 360, /* VARSYM */ + BITSYM = 361, /* BITSYM */ + SPECSYM = 362, /* SPECSYM */ + VARLISTSYM = 363, /* VARLISTSYM */ + OPERANDSYM = 364, /* OPERANDSYM */ + JUMPSYM = 365, /* JUMPSYM */ + MACROSYM = 366, /* MACROSYM */ + LABELSYM = 367, /* LABELSYM */ + SUBTABLESYM = 368 /* SUBTABLESYM */ }; + typedef enum sleightokentype sleightoken_kind_t; #endif /* Value type. */ diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/slghparse.y b/Ghidra/Features/Decompiler/src/decompile/cpp/slghparse.y index cddc09f5cb..27c326b202 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/slghparse.y +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/slghparse.y @@ -151,6 +151,14 @@ extern int sleigherror(const char *str ); %type specificsymbol %type id_or_nil +%destructor { delete $$; } INTEGER INTB STRING SYMBOLSTRING +%destructor { delete $$; } paramlist rtl rtlmid rtlbody rtlfirstsection rtlcontinue statement expr +%destructor { delete $$; } varnode integervarnode exportvarnode lhsvarnode jumpdest charstring +%destructor { if ($$) PatternEquation::release($$); } pequation elleq ellrt atomic constraint bitpat_or_nil +%destructor { PatternExpression::release($$); } pexpression +%destructor { delete $$; } spaceprop fielddef contextfielddef sizedstar stringlist stringpart anystringlist anystringpart +%destructor { delete $$; } oplist intblist intbpart valuelist valuepart varlist varpart contextlist contextblock + %% spec: endiandef | spec aligndef @@ -193,13 +201,13 @@ contextprop: DEFINE_KEY CONTEXT_KEY VARSYM { $$ = $3; } { 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"; slgh->reportError(errmsg); YYERROR; } + | anysymbol '=' '(' INTEGER ',' INTEGER ')' { $$ = (FieldQuality *)0; 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"; slgh->reportError(errmsg); YYERROR; } + | anysymbol '=' '(' INTEGER ',' INTEGER ')' { $$ = (FieldQuality *)0; 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; } @@ -208,7 +216,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"; slgh->reportError(errmsg); YYERROR; } + | DEFINE_KEY SPACE_KEY anysymbol { $$ = (SpaceQuality *)0; 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; } @@ -330,11 +338,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(); slgh->reportError(errmsg); 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); delete $1; $4->layClaim(); PatternExpression::release($4); 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; slgh->reportError(errmsg); YYERROR; } + | contextlist STRING { $$ = (vector *)0; delete $1; 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; } @@ -347,11 +355,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; slgh->reportError(errmsg); YYERROR; } - | rtlmid EXPORT_KEY sizedstar STRING { string errmsg="Unknown pointer varnode: "+*$4; delete $3; delete $4; slgh->reportError(errmsg); YYERROR; } + | rtlmid EXPORT_KEY STRING { $$ = (ConstructTpl *)0; delete $1; string errmsg="Unknown export varnode: "+*$3; delete $3; slgh->reportError(errmsg); YYERROR; } + | rtlmid EXPORT_KEY sizedstar STRING { $$ = (ConstructTpl *)0; delete $1; string errmsg="Unknown pointer varnode: "+*$4; delete $3; delete $4; slgh->reportError(errmsg); YYERROR; } ; rtlmid: /* EMPTY */ { $$ = slgh->enterSection(); } - | rtlmid statement { $$ = $1; if (!$$->addOpList(*$2)) { delete $2; slgh->reportError("Multiple delayslot declarations"); YYERROR; } delete $2; } + | rtlmid statement { $$ = $1; if (!$$->addOpList(*$2)) { delete $1; 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; } ; @@ -365,8 +373,8 @@ statement: lhsvarnode '=' expr ';' { $3->setOutput($1); $$ = ExprTree::toVector( | 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; 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; } + | varnode ':' INTEGER '=' { $$ = (vector *)0; delete $1; delete $3; slgh->reportError("Illegal truncation on left-hand side of assignment"); YYERROR; } + | varnode '(' INTEGER ')' { $$ = (vector *)0; 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; } @@ -376,7 +384,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 ';' { slgh->reportError("Must specify an indirect parameter for return"); YYERROR; } + | RETURN_KEY ';' { $$ = (vector *)0; 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 ); } @@ -447,7 +455,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"; slgh->reportError(errmsg); YYERROR; } $$ = slgh->pcode.createVariadic(CPUI_CPOOLREF,$3); } + | OP_CPOOLREF '(' paramlist ')' { if ((*$3).size() < 2) { string errmsg = "Must be at least two inputs to cpool"; slgh->reportError(errmsg); delete $3; 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()); } @@ -460,12 +468,12 @@ jumpdest: JUMPSYM { VarnodeTpl *sym = $1->getVarnode(); $$ = new VarnodeTpl(Con | 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; slgh->reportError(errmsg); YYERROR; } + | STRING { $$ = (VarnodeTpl *)0; 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; slgh->reportError(errmsg); YYERROR; } - | SUBTABLESYM { string errmsg = "Subtable not attached to operand: "+$1->getName(); slgh->reportError(errmsg); YYERROR; } + | STRING { $$ = (VarnodeTpl *)0; string errmsg = "Unknown varnode parameter: "+*$1; delete $1; slgh->reportError(errmsg); YYERROR; } + | SUBTABLESYM { $$ = (VarnodeTpl *)0; 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)); slgh->reportError("Parsed integer is too big (overflow)"); } @@ -474,8 +482,8 @@ integervarnode: INTEGER { $$ = new VarnodeTpl(ConstTpl(slgh->getConstantSpace() | '&' ':' INTEGER varnode { $$ = slgh->pcode.addressOf($4,*$3); delete $3; } ; lhsvarnode: specificsymbol { $$ = $1->getVarnode(); } - | 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; } + | STRING { $$ = (VarnodeTpl *)0; string errmsg = "Unknown assignment varnode: "+*$1; delete $1; slgh->reportError(errmsg); YYERROR; } + | SUBTABLESYM { $$ = (VarnodeTpl *)0; string errmsg = "Subtable not attached to operand: "+$1->getName(); slgh->reportError(errmsg); YYERROR; } ; label: '<' LABELSYM '>' { $$ = $2; } | '<' STRING '>' { $$ = slgh->pcode.defineLabel( $2 ); } @@ -484,8 +492,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; slgh->reportError(errmsg); YYERROR; } - | SUBTABLESYM { string errmsg = "Subtable not attached to operand: "+$1->getName(); slgh->reportError(errmsg); YYERROR; } + | STRING { $$ = (VarnodeTpl *)0; string errmsg="Unknown export varnode: "+*$1; delete $1; slgh->reportError(errmsg); YYERROR; } + | SUBTABLESYM { $$ = (VarnodeTpl *)0; string errmsg = "Subtable not attached to operand: "+$1->getName(); slgh->reportError(errmsg); YYERROR; } ; familysymbol: VALUESYM { $$ = $1; } | VALUEMAPSYM { $$ = $1; } @@ -511,7 +519,7 @@ intbpart: INTEGER { $$ = new vector; $$->push_back(intb(*$1)); delete $1; $$ = 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; slgh->reportError(errmsg); YYERROR; } + | intbpart STRING { if (*$2!="_") { string errmsg = "Expecting integer but saw: "+*$2; delete $1; delete $2; slgh->reportError(errmsg); YYERROR; } $$ = $1; $$->push_back((intb)0xBADBEEF); delete $2; } ; stringlist: '[' stringpart ']' { $$ = $2; } @@ -519,7 +527,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"; slgh->reportError(errmsg); YYERROR; } + | stringpart anysymbol { $$ = (vector *)0; delete $1; string errmsg = $2->getName()+": redefined"; slgh->reportError(errmsg); YYERROR; } ; anystringlist: '[' anystringpart ']' { $$ = $2; } ; @@ -536,7 +544,7 @@ 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; slgh->reportError(errmsg); YYERROR; } + | valuepart STRING { $$ = (vector *)0; delete $1; string errmsg = *$2+": is not a value pattern"; delete $2; slgh->reportError(errmsg); YYERROR; } ; varlist: '[' varpart ']' { $$ = $2; } | VARSYM { $$ = new vector; $$->push_back($1); } @@ -545,7 +553,7 @@ varpart: VARSYM { $$ = new vector; $$->push_back($1); } | 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; slgh->reportError(errmsg); YYERROR; } + | varpart STRING { if (*$2!="_") { string errmsg = *$2+": is not a varnode symbol"; delete $1; delete $2; slgh->reportError(errmsg); YYERROR; } $$ = $1; $$->push_back((SleighSymbol *)0); delete $2; } ; paramlist: /* EMPTY */ { $$ = new vector; } diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/slghpatexpress.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/slghpatexpress.cc index 9410978595..a724f3013f 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/slghpatexpress.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/slghpatexpress.cc @@ -4,9 +4,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -503,9 +503,13 @@ PatternExpression *PatternExpression::decodeExpression(Decoder &decoder,Translat else if (el == sla::ELEM_NOT_EXP) res = new NotExpression(); else - return (PatternExpression *)0; - - res->decode(decoder,trans); + throw DecoderError("Invalid pattern expression element"); + try { + res->decode(decoder,trans); + } catch(...) { + delete res; + throw; + } return res; } @@ -826,6 +830,9 @@ void OperandValue::decode(Decoder &decoder,Translate *trans) uintm ctid = decoder.readUnsignedInteger(sla::ATTRIB_CT); SleighBase *sleigh = (SleighBase *)trans; SubtableSymbol *tab = dynamic_cast(sleigh->findSymbol(tabid)); + if (ctid >= tab->getNumConstructors()) { + throw DecoderError("Invalid constructor id"); + } ct = tab->getConstructor(ctid); decoder.closeElement(el); } diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/slghpattern.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/slghpattern.cc index fc993930b4..6253ca118d 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/slghpattern.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/slghpattern.cc @@ -4,9 +4,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -141,16 +141,16 @@ bool DisjointPattern::resolvesIntersect(const DisjointPattern *op1,const Disjoin DisjointPattern *DisjointPattern::decodeDisjoint(Decoder &decoder) { // DisjointPattern factory - DisjointPattern *res; + unique_ptr res; uint4 el = decoder.peekElement(); if (el == sla::ELEM_INSTRUCT_PAT) - res = new InstructionPattern(); + res.reset(new InstructionPattern()); else if (el == sla::ELEM_CONTEXT_PAT) - res = new ContextPattern(); + res.reset(new ContextPattern()); else - res = new CombinePattern(); + res.reset(new CombinePattern()); res->decode(decoder); - return res; + return res.release(); } void PatternBlock::normalize(void) diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/slghscan.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/slghscan.cc index f3c1e361a8..a8545a5f3d 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/slghscan.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/slghscan.cc @@ -1128,9 +1128,9 @@ char *yytext; * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/slghsymbol.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/slghsymbol.cc index e62c4708b2..deadf3b532 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/slghsymbol.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/slghsymbol.cc @@ -49,10 +49,12 @@ SymbolTable::~SymbolTable(void) { vector::iterator iter; for(iter=table.begin();iter!=table.end();++iter) - delete *iter; + if (*iter) + delete *iter; vector::iterator siter; for(siter=symbollist.begin();siter!=symbollist.end();++siter) - delete *siter; + if (*siter) + delete *siter; } void SymbolTable::addScope(void) @@ -170,13 +172,33 @@ void SymbolTable::decode(Decoder &decoder,SleighBase *trans) { int4 el = decoder.openElement(sla::ELEM_SYMBOL_TABLE); - table.resize(decoder.readSignedInteger(sla::ATTRIB_SCOPESIZE), (SymbolScope *)0); - symbollist.resize(decoder.readSignedInteger(sla::ATTRIB_SYMBOLSIZE), (SleighSymbol *)0); + int8 tableSize = decoder.readSignedInteger(sla::ATTRIB_SCOPESIZE); + int8 symbolSize = decoder.readSignedInteger(sla::ATTRIB_SYMBOLSIZE); + if (tableSize < 0 || symbolSize < 0) + throw SleighError("Bad symbol table size"); + if (tableSize > MAX_TABLES) + throw SleighError("Maximum scopes exceeded"); + if (symbolSize > MAX_SYMBOLS) + throw SleighError("Maximum symbols exceeded"); + table.resize(tableSize, (SymbolScope *)0); + symbollist.resize(symbolSize, (SleighSymbol *)0); for(int4 i=0;i= table.size()) { + throw SleighError("Bad symbol scope id: exceeds symbol scope table size"); + } + uintm parent = decoder.readUnsignedInteger(sla::ATTRIB_PARENT); + if (parent >= table.size()) { + throw SleighError("Bad symbol scope parent id: exceeds symbol scope table size"); + } + SymbolScope *parscope = (parent==id) ? (SymbolScope *)0 : table[parent]; + if (table[id]) { + throw SleighError("Bad symbol scope parent id: not unique"); + } + table[id] = new SymbolScope( parscope, id ); decoder.closeElement(subel); } @@ -202,39 +224,58 @@ void SymbolTable::decodeSymbolHeader(Decoder &decoder) { // Put the shell of a symbol in the symbol table // in order to allow recursion - SleighSymbol *sym; + unique_ptr sym; uint4 el = decoder.peekElement(); if (el == sla::ELEM_USEROP_HEAD) - sym = new UserOpSymbol(); + sym.reset(new UserOpSymbol()); else if (el == sla::ELEM_EPSILON_SYM_HEAD) - sym = new EpsilonSymbol(); + sym.reset(new EpsilonSymbol()); else if (el == sla::ELEM_VALUE_SYM_HEAD) - sym = new ValueSymbol(); + sym.reset(new ValueSymbol()); else if (el == sla::ELEM_VALUEMAP_SYM_HEAD) - sym = new ValueMapSymbol(); + sym.reset(new ValueMapSymbol()); else if (el == sla::ELEM_NAME_SYM_HEAD) - sym = new NameSymbol(); + sym.reset(new NameSymbol()); else if (el == sla::ELEM_VARNODE_SYM_HEAD) - sym = new VarnodeSymbol(); + sym.reset(new VarnodeSymbol()); else if (el == sla::ELEM_CONTEXT_SYM_HEAD) - sym = new ContextSymbol(); + sym.reset(new ContextSymbol()); else if (el == sla::ELEM_VARLIST_SYM_HEAD) - sym = new VarnodeListSymbol(); + sym.reset(new VarnodeListSymbol()); else if (el == sla::ELEM_OPERAND_SYM_HEAD) - sym = new OperandSymbol(); + sym.reset(new OperandSymbol()); else if (el == sla::ELEM_START_SYM_HEAD) - sym = new StartSymbol(); + sym.reset(new StartSymbol()); else if (el == sla::ELEM_END_SYM_HEAD) - sym = new EndSymbol(); + sym.reset(new EndSymbol()); else if (el == sla::ELEM_NEXT2_SYM_HEAD) - sym = new Next2Symbol(); + sym.reset(new Next2Symbol()); else if (el == sla::ELEM_SUBTABLE_SYM_HEAD) - sym = new SubtableSymbol(); + sym.reset(new SubtableSymbol()); else throw SleighError("Bad symbol xml"); + sym->decodeHeader(decoder); // Restore basic elements of symbol - symbollist[sym->id] = sym; // Put the basic symbol in the table - table[sym->scopeid]->addSymbol(sym); // to allow recursion + + if (sym->id >= symbollist.size()) { + throw SleighError("Bad symbol id: exceeds symbollist size"); + } + + if (symbollist[sym->id] != (SleighSymbol *)0) { + throw SleighError("Bad symbol id: not unique"); + } + + if (sym->scopeid >= table.size()) { + throw SleighError("Bad symbol scope id: too large"); + } + + if (table[sym->scopeid] == (SymbolScope *)0) { + throw SleighError("Bad symbol scope id: undefined"); + } + + SleighSymbol *res = sym.release(); + symbollist[res->id] = res; // Put the basic symbol in the table + table[res->scopeid]->addSymbol(res); // to allow recursion } void SymbolTable::purge(void) @@ -500,6 +541,9 @@ void ValueSymbol::encodeHeader(Encoder &encoder) const void ValueSymbol::decode(Decoder &decoder,SleighBase *trans) { + if (patval) + throw DecoderError("Already decoded symbol"); + patval = (PatternValue *) PatternExpression::decodeExpression(decoder,trans); patval->layClaim(); decoder.closeElement(sla::ELEM_VALUE_SYM.getId()); @@ -581,6 +625,9 @@ void ValueMapSymbol::encodeHeader(Encoder &encoder) const void ValueMapSymbol::decode(Decoder &decoder,SleighBase *trans) { + if (patval) + throw DecoderError("Already decoded symbol"); + patval = (PatternValue *) PatternExpression::decodeExpression(decoder,trans); patval->layClaim(); while(decoder.peekElement() != 0) { @@ -660,6 +707,9 @@ void NameSymbol::encodeHeader(Encoder &encoder) const void NameSymbol::decode(Decoder &decoder,SleighBase *trans) { + if (patval) + throw DecoderError("Already decoded symbol"); + patval = (PatternValue *) PatternExpression::decodeExpression(decoder,trans); patval->layClaim(); while(decoder.peekElement() != 0) { @@ -794,6 +844,10 @@ void ContextSymbol::decode(Decoder &decoder,SleighBase *trans) if (lowMissing || highMissing) { throw DecoderError("Missing high/low attributes"); } + + if (patval) + throw DecoderError("Already decoded symbol"); + patval = (PatternValue *) PatternExpression::decodeExpression(decoder,trans); patval->layClaim(); decoder.closeElement(sla::ELEM_CONTEXT_SYM.getId()); @@ -898,6 +952,9 @@ void VarnodeListSymbol::encodeHeader(Encoder &encoder) const void VarnodeListSymbol::decode(Decoder &decoder,SleighBase *trans) { + if (patval) + throw DecoderError("Already decoded symbol"); + patval = (PatternValue *) PatternExpression::decodeExpression(decoder,trans); patval->layClaim(); while(decoder.peekElement() != 0) { @@ -945,7 +1002,9 @@ void OperandSymbol::defineOperand(TripleSymbol *tri) OperandSymbol::~OperandSymbol(void) { - PatternExpression::release(localexp); + if (localexp != (PatternExpression *)0) + PatternExpression::release(localexp); + if (defexp != (PatternExpression *)0) PatternExpression::release(defexp); } @@ -1040,6 +1099,9 @@ void OperandSymbol::encodeHeader(Encoder &encoder) const void OperandSymbol::decode(Decoder &decoder,SleighBase *trans) { + if (defexp || localexp) + throw DecoderError("Already decoded symbol"); + defexp = (PatternExpression *)0; triple = (TripleSymbol *)0; flags = 0; @@ -1631,28 +1693,28 @@ void Constructor::decode(Decoder &decoder,SleighBase *trans) } else if (subel == sla::ELEM_CONTEXT_OP) { ContextOp *c_op = new ContextOp(); - c_op->decode(decoder,trans); context.push_back(c_op); + c_op->decode(decoder,trans); } else if (subel == sla::ELEM_COMMIT) { ContextCommit *c_op = new ContextCommit(); - c_op->decode(decoder,trans); context.push_back(c_op); + c_op->decode(decoder,trans); } else { - ConstructTpl *cur = new ConstructTpl(); + unique_ptr cur(new ConstructTpl()); int4 sectionid = cur->decode(decoder); if (sectionid < 0) { if (templ != (ConstructTpl *)0) throw LowlevelError("Duplicate main section"); - templ = cur; + templ = cur.release(); } else { while(namedtempl.size() <= sectionid) namedtempl.push_back((ConstructTpl *)0); if (namedtempl[sectionid] != (ConstructTpl *)0) throw LowlevelError("Duplicate named section"); - namedtempl[sectionid] = cur; + namedtempl[sectionid] = cur.release(); } } subel = decoder.peekElement(); @@ -2334,6 +2396,9 @@ void DecisionNode::decode(Decoder &decoder,DecisionNode *par,SubtableSymbol *sub if (subel == sla::ELEM_PAIR) { decoder.openElement(); uintm id = decoder.readSignedInteger(sla::ATTRIB_ID); + if (id >= sub->getNumConstructors()) { + throw DecoderError("Invalid constructor id"); + } Constructor *ct = sub->getConstructor(id); DisjointPattern *pat = DisjointPattern::decodeDisjoint(decoder); list.push_back(pair(pat,ct)); @@ -2341,8 +2406,8 @@ void DecisionNode::decode(Decoder &decoder,DecisionNode *par,SubtableSymbol *sub } else if (subel == sla::ELEM_DECISION) { DecisionNode *subnode = new DecisionNode(); - subnode->decode(decoder,this,sub); children.push_back(subnode); + subnode->decode(decoder,this,sub); } subel = decoder.peekElement(); } diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/slghsymbol.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/slghsymbol.hh index 5e8b4d3dfd..e3be244b3b 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/slghsymbol.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/slghsymbol.hh @@ -4,9 +4,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -76,6 +76,8 @@ class SymbolTable { SymbolScope *skipScope(int4 i) const; SleighSymbol *findSymbolInternal(SymbolScope *scope,const string &nm) const; void renumber(void); + static constexpr int8 MAX_TABLES = 0x100000; + static constexpr int8 MAX_SYMBOLS = 0x1000000; public: SymbolTable(void) { curscope = (SymbolScope *)0; } ~SymbolTable(void); @@ -326,7 +328,7 @@ private: void setVariableLength(void) { flags |= variable_len; } bool isVariableLength(void) const { return ((flags&variable_len)!=0); } public: - OperandSymbol(void) {} // For use with decode + OperandSymbol(void) : localexp(nullptr), defexp(nullptr) {} // For use with decode OperandSymbol(const string &nm,int4 index,Constructor *ct); uint4 getRelativeOffset(void) const { return reloffset; } int4 getOffsetBase(void) const { return offsetbase; } @@ -448,8 +450,8 @@ class ContextOp : public ContextChange { int4 shift; // Number of bits to shift value into place public: ContextOp(int4 startbit,int4 endbit,PatternExpression *pe); - ContextOp(void) {} // For use with decode - virtual ~ContextOp(void) { PatternExpression::release(patexp); } + ContextOp(void) : patexp(nullptr) {} // For use with decode + virtual ~ContextOp(void) { if (patexp) PatternExpression::release(patexp); } virtual void validate(void) const; virtual void encode(Encoder &encoder) const; virtual void decode(Decoder &decoder,SleighBase *trans); diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/translate.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/translate.cc index 98060c2b96..8cca59a574 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/translate.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/translate.cc @@ -258,20 +258,20 @@ AddrSpace *AddrSpaceManager::decodeSpace(Decoder &decoder,const Translate *trans { uint4 elemId = decoder.peekElement(); - AddrSpace *res; + unique_ptr res; if (elemId == ELEM_SPACE_BASE) - res = new SpacebaseSpace(this,trans); + res.reset(new SpacebaseSpace(this,trans)); else if (elemId == ELEM_SPACE_UNIQUE) - res = new UniqueSpace(this,trans); + res.reset(new UniqueSpace(this,trans)); else if (elemId == ELEM_SPACE_OTHER) - res = new OtherSpace(this,trans); + res.reset(new OtherSpace(this,trans)); else if (elemId == ELEM_SPACE_OVERLAY) - res = new OverlaySpace(this,trans); + res.reset(new OverlaySpace(this,trans)); else - res = new AddrSpace(this,trans,IPTR_PROCESSOR); + res.reset(new AddrSpace(this,trans,IPTR_PROCESSOR)); res->decode(decoder); - return res; + return res.release(); } /// This routine initializes (almost) all the address spaces used @@ -352,49 +352,49 @@ void AddrSpaceManager::setReverseJustified(AddrSpace *spc) void AddrSpaceManager::insertSpace(AddrSpace *spc) { - bool nameTypeMismatch = false; - bool duplicateName = false; - bool duplicateId = false; + unique_ptr owner; + if (spc->refcount == 0) + owner.reset(spc); // Take ownership if this is the first reference switch(spc->getType()) { case IPTR_CONSTANT: if (spc->getName() != ConstantSpace::NAME) - nameTypeMismatch = true; + throw LowlevelError("Space " + spc->getName() + " was initialized with wrong type"); if (spc->index != ConstantSpace::INDEX) throw LowlevelError("const space must be assigned index 0"); constantspace = spc; break; case IPTR_INTERNAL: if (spc->getName() != UniqueSpace::NAME) - nameTypeMismatch = true; + throw LowlevelError("Space " + spc->getName() + " was initialized with wrong type"); if (uniqspace != (AddrSpace *)0) - duplicateName = true; + throw LowlevelError("Space " + spc->getName() + " was initialized more than once"); uniqspace = spc; break; case IPTR_FSPEC: if (spc->getName() != "fspec") - nameTypeMismatch = true; + throw LowlevelError("Space " + spc->getName() + " was initialized with wrong type"); if (fspecspace != (AddrSpace *)0) - duplicateName = true; + throw LowlevelError("Space " + spc->getName() + " was initialized more than once"); fspecspace = spc; break; case IPTR_JOIN: if (spc->getName() != JoinSpace::NAME) - nameTypeMismatch = true; + throw LowlevelError("Space " + spc->getName() + " was initialized with wrong type"); if (joinspace != (AddrSpace *)0) - duplicateName = true; + throw LowlevelError("Space " + spc->getName() + " was initialized more than once"); joinspace = spc; break; case IPTR_IOP: if (spc->getName() != "iop") - nameTypeMismatch = true; + throw LowlevelError("Space " + spc->getName() + " was initialized with wrong type"); if (iopspace != (AddrSpace *)0) - duplicateName = true; + throw LowlevelError("Space " + spc->getName() + " was initialized more than once"); iopspace = spc; break; case IPTR_SPACEBASE: if (spc->getName() == "stack") { if (stackspace != (AddrSpace *)0) - duplicateName = true; + throw LowlevelError("Space " + spc->getName() + " was initialized more than once"); stackspace = spc; } // fallthru @@ -412,26 +412,14 @@ void AddrSpaceManager::insertSpace(AddrSpace *spc) if (baselist.size() <= spc->index) baselist.resize(spc->index+1, (AddrSpace *)0); - duplicateId = baselist[spc->index] != (AddrSpace *)0; + if (baselist[spc->index] != (AddrSpace *)0) + throw LowlevelError("Space " + spc->getName() + " was assigned id duplicating: "+baselist[spc->index]->getName()); - if (!nameTypeMismatch && !duplicateName && !duplicateId) { - duplicateName = !name2Space.insert(pair(spc->getName(),spc)).second; - } + if (!name2Space.insert(pair(spc->getName(),spc)).second) + throw LowlevelError("Space " + spc->getName() + " was initialized more than once"); - if (nameTypeMismatch || duplicateName || duplicateId) { - string errMsg = "Space " + spc->getName(); - if (nameTypeMismatch) - errMsg = errMsg + " was initialized with wrong type"; - if (duplicateName) - errMsg = errMsg + " was initialized more than once"; - if (duplicateId) - errMsg = errMsg + " was assigned as id duplicating: "+baselist[spc->index]->getName(); - if (spc->refcount == 0) - delete spc; - spc = (AddrSpace *)0; - throw LowlevelError(errMsg); - } baselist[spc->index] = spc; + owner.release(); spc->refcount += 1; assignShortcut(spc); } @@ -1024,7 +1012,7 @@ const FloatFormat *Translate::getFloatFormat(int4 size) const void PcodeEmit::decodeOp(const Address &addr,Decoder &decoder) { - int4 opcode; + OpCode opcode; int4 isize; VarnodeData outvar; VarnodeData invar[16]; @@ -1033,14 +1021,19 @@ void PcodeEmit::decodeOp(const Address &addr,Decoder &decoder) uint4 elemId = decoder.openElement(ELEM_OP); isize = decoder.readSignedInteger(ATTRIB_SIZE); outptr = &outvar; - if (isize <= 16) + if (isize <= 16) { + if (isize < 0) + throw DecoderError("Bad size attribute"); opcode = PcodeOpRaw::decode(decoder, isize, invar, &outptr); + decoder.closeElement(elemId); + dump(addr,opcode,outptr,invar,isize); + } else { vector varStorage(isize,VarnodeData()); opcode = PcodeOpRaw::decode(decoder, isize, varStorage.data(), &outptr); + decoder.closeElement(elemId); + dump(addr,opcode,outptr,varStorage.data(),isize); } - decoder.closeElement(elemId); - dump(addr,(OpCode)opcode,outptr,invar,isize); } } // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/userop.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/userop.cc index 9fe8b78d03..c9074bfa6c 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/userop.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/userop.cc @@ -4,9 +4,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -490,6 +490,7 @@ UserPcodeOp *UserOpManage::registerBuiltin(uint4 i) void UserOpManage::registerOp(UserPcodeOp *op) { + unique_ptr owner(op); // Take ownership int4 ind = op->getIndex(); if (ind < 0) throw LowlevelError("UserOp not assigned an index"); @@ -509,7 +510,7 @@ void UserOpManage::registerOp(UserPcodeOp *op) // We assume this registration customizes an existing userop delete useroplist[ind]; // Delete the old spec } - useroplist[ind] = op; // Index crossref + useroplist[ind] = owner.release(); // Index crossref useropmap[op->getName()] = op; // Name crossref SegmentOp *s_op = dynamic_cast(op); @@ -533,15 +534,9 @@ void UserOpManage::registerOp(UserPcodeOp *op) void UserOpManage::decodeSegmentOp(Decoder &decoder,Architecture *glb) { - SegmentOp *s_op; - s_op = new SegmentOp("",glb,useroplist.size()); - try { - s_op->decode(decoder); - registerOp(s_op); - } catch(LowlevelError &err) { - delete s_op; - throw err; - } + unique_ptr s_op(new SegmentOp("",glb,useroplist.size())); + s_op->decode(decoder); + registerOp(s_op.release()); } /// Create either a VolatileReadOp or VolatileWriteOp description object based on @@ -589,14 +584,9 @@ void UserOpManage::decodeVolatile(Decoder &decoder,Architecture *glb) void UserOpManage::decodeCallOtherFixup(Decoder &decoder,Architecture *glb) { - InjectedUserOp *op = new InjectedUserOp("",glb,0,0); - try { - op->decode(decoder); - registerOp(op); - } catch(LowlevelError &err) { - delete op; - throw err; - } + unique_ptr op(new InjectedUserOp("",glb,0,0)); + op->decode(decoder); + registerOp(op.release()); } /// Create a JumpAssistOp description object based on the element @@ -606,14 +596,9 @@ void UserOpManage::decodeCallOtherFixup(Decoder &decoder,Architecture *glb) void UserOpManage::decodeJumpAssist(Decoder &decoder,Architecture *glb) { - JumpAssistOp *op = new JumpAssistOp(glb); - try { - op->decode(decoder); - registerOp(op); - } catch(LowlevelError &err) { - delete op; - throw err; - } + unique_ptr op(new JumpAssistOp(glb)); + op->decode(decoder); + registerOp(op.release()); } /// \brief Manually install an InjectedUserOp given just names of the user defined op and the p-code snippet @@ -637,12 +622,7 @@ void UserOpManage::manualCallOtherFixup(const string &useropname,const string &o int4 injectid = glb->pcodeinjectlib->manualCallOtherFixup(useropname,outname,inname,snippet); InjectedUserOp *op = new InjectedUserOp(useropname,glb,userop->getIndex(),injectid); - try { - registerOp(op); - } catch(LowlevelError &err) { - delete op; - throw err; - } + registerOp(op); } } // End namespace ghidra diff --git a/Ghidra/Features/Decompiler/src/decompile/unittests/testmultiprec.cc b/Ghidra/Features/Decompiler/src/decompile/unittests/testmultiprec.cc new file mode 100644 index 0000000000..529b8c8158 --- /dev/null +++ b/Ghidra/Features/Decompiler/src/decompile/unittests/testmultiprec.cc @@ -0,0 +1,89 @@ +/* ### + * IP: GHIDRA + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "test.hh" +#include "multiprecision.hh" + +namespace ghidra { + +static uint8 num1[2] = { 0xffffffffffffffff, 0xffffffffffffffff }; +static uint8 denom1[2] = { 1, 0 }; +static uint8 num2[2] = { 0x89a732a9fb157c4d, 0x4eada2039e48443e }; +static uint8 denom2[2] = { 0xbabf3b71, 0 }; +static uint8 num3[2] = { 0xf7df0315d584ad8d, 0xb9d55c0d1d5cfbbd }; +static uint8 denom3[2] = { 0x8aa797dbccee6e96, 0x646be9 }; +static uint8 a[2] = { 0x1a309a9df2ce836a, 0xd66f2248906d1bdf }; +static uint8 b[2] = { 0xf6c190704eb1763e, 0xa05c42212dfba7c6 }; + +TEST(multiprec_udiv) { + uint8 q[2]; + uint8 r[2]; + + udiv128(num1, denom1, q, r); + ASSERT_EQUALS(q[0],0xffffffffffffffff); + ASSERT_EQUALS(q[1],0xffffffffffffffff); + ASSERT_EQUALS(r[0],0); + ASSERT_EQUALS(r[1],0); + + udiv128(num2, denom2, q, r); + ASSERT_EQUALS(q[0], 0x2a21eef2058d7e9a); + ASSERT_EQUALS(q[1], 0x6bdaed99); + ASSERT_EQUALS(r[0], 0x928d1c53); + ASSERT_EQUALS(r[1], 0); + + udiv128(num2,num1,q,r); + ASSERT_EQUALS(q[0], 0); + ASSERT_EQUALS(q[1], 0); + ASSERT_EQUALS(r[0],num2[0]); + ASSERT_EQUALS(r[1],num2[1]); + + udiv128(num3,denom3,q,r); + ASSERT_EQUALS(q[0], 0x1d9bc949e24); + ASSERT_EQUALS(q[1], 0); + ASSERT_EQUALS(r[0], 0x2e78197dc5048c75); + ASSERT_EQUALS(r[1], 0x24d9cc); +} + +TEST(multiprec_add) { + uint8 res[2]; + add128(a,b,res); + ASSERT_EQUALS(res[0], 0x10f22b0e417ff9a8); + ASSERT_EQUALS(res[1], 0x76cb6469be68c3a6); +} + +TEST(multiprec_sub) { + uint8 res[2]; + subtract128(a,b,res); + ASSERT_EQUALS(res[0], 0x236F0A2DA41D0D2C); + ASSERT_EQUALS(res[1], 0x3612E02762717418); +} + +TEST(multiprec_left) { + uint8 res[2]; + leftshift128(num2, res, 51); + ASSERT_EQUALS(res[0], 0xe268000000000000); + ASSERT_EQUALS(res[1], 0x21f44d39954fd8ab); +} + +TEST(multiprec_less) { + ASSERT(!uless128(a,a)); + ASSERT(uless128(num2,num3)); + ASSERT(uless128(denom1,denom2)); + ASSERT(ulessequal128(a,a)); + ASSERT(ulessequal128(num2,num3)); + ASSERT(ulessequal128(denom2,denom2)); +} + +} // End namespace ghidra