/* ###
* 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 "sleighbase.hh"
const int4 SleighBase::SLA_FORMAT_VERSION = 3;
const uint4 SleighBase::MAX_UNIQUE_SIZE = 128;
int4 SourceFileIndexer::index(const string filename){
auto it = fileToIndex.find(filename);
if (fileToIndex.end() != it){
return it->second;
}
fileToIndex[filename] = leastUnusedIndex;
indexToFile[leastUnusedIndex] = filename;
return leastUnusedIndex++;
}
int4 SourceFileIndexer::getIndex(string filename){
return fileToIndex[filename];
}
string SourceFileIndexer::getFilename(int4 index){
return indexToFile[index];
}
void SourceFileIndexer::restoreXml(const Element *el){
const List &sourceFiles(el->getChildren());
List::const_iterator iter = sourceFiles.begin();
for (; iter != sourceFiles.end(); ++iter){
string filename = (*iter)->getAttributeValue("name");
int4 index = stoi((*iter)->getAttributeValue("index"),NULL,10);
fileToIndex[filename] = index;
indexToFile[index] = filename;
}
}
void SourceFileIndexer::saveXml(ostream& s) const {
s << "\n";
for (int4 i = 0; i < leastUnusedIndex; ++i){
s << ("\n";
}
s << "\n";
}
SleighBase::SleighBase(void)
{
root = (SubtableSymbol *)0;
maxdelayslotbytes = 0;
unique_allocatemask = 0;
numSections = 0;
}
/// Assuming the symbol table is populated, iterate through the table collecting
/// registers (for the map), user-op names, and context fields.
void SleighBase::buildXrefs(vector &errorPairs)
{
SymbolScope *glb = symtab.getGlobalScope();
SymbolTree::const_iterator iter;
SleighSymbol *sym;
ostringstream s;
for(iter=glb->begin();iter!=glb->end();++iter) {
sym = *iter;
if (sym->getType() == SleighSymbol::varnode_symbol) {
pair ins(((VarnodeSymbol *)sym)->getFixedVarnode(),sym->getName());
pair