Improve sleigh compiler error messages

Signed-off-by: Klaus Kämpf <kkaempf@gmail.com>
This commit is contained in:
Klaus Kämpf 2022-09-12 19:57:33 +02:00 committed by James
parent 2758cbb40c
commit 23c1b63f55

View File

@ -1945,8 +1945,10 @@ void SleighCompile::buildPatterns(void)
errors += 1; errors += 1;
} }
for(int4 i=0;i<tables.size();++i) { for(int4 i=0;i<tables.size();++i) {
if (tables[i]->isError()) if (tables[i]->isError()) {
reportError(getLocation(tables[i]), "Problem in table '"+tables[i]->getName() + "':" + msg.str());
errors += 1; errors += 1;
}
if (tables[i]->getPattern() == (TokenPattern *)0) { if (tables[i]->getPattern() == (TokenPattern *)0) {
reportWarning(getLocation(tables[i]), "Unreferenced table '"+tables[i]->getName() + "'"); reportWarning(getLocation(tables[i]), "Unreferenced table '"+tables[i]->getName() + "'");
} }
@ -2192,7 +2194,11 @@ const Location *SleighCompile::getLocation(Constructor *ctor) const
const Location *SleighCompile::getLocation(SleighSymbol *sym) const const Location *SleighCompile::getLocation(SleighSymbol *sym) const
{ {
return &symbolLocationMap.at(sym); try {
return &symbolLocationMap.at(sym);
} catch (const std::exception &e) {
return NULL;
}
} }
/// The current filename and line number are placed into a Location object /// The current filename and line number are placed into a Location object
@ -2241,7 +2247,7 @@ void SleighCompile::reportError(const Location* loc, const string &msg)
void SleighCompile::reportError(const string &msg) void SleighCompile::reportError(const string &msg)
{ {
cerr << "ERROR " << msg << endl; cerr << filename.back() << ":" << lineno.back() << " - ERROR " << msg << endl;
errors += 1; errors += 1;
if (errors > 1000000) { if (errors > 1000000) {
cerr << "Too many errors: Aborting" << endl; cerr << "Too many errors: Aborting" << endl;
@ -2670,7 +2676,10 @@ void SleighCompile::attachValues(vector<SleighSymbol *> *symlist,vector<intb> *n
if (sym == (ValueSymbol *)0) continue; if (sym == (ValueSymbol *)0) continue;
PatternValue *patval = sym->getPatternValue(); PatternValue *patval = sym->getPatternValue();
if (patval->maxValue() + 1 != numlist->size()) { if (patval->maxValue() + 1 != numlist->size()) {
reportError(getCurrentLocation(), "Attach value '" + sym->getName() + "' is wrong size for list"); ostringstream msg;
msg << "Attach value '" + sym->getName();
msg << "' (range 0.." << patval->maxValue() << ") is wrong size for list (of " << numlist->size() << " entries";
reportError(getCurrentLocation(), msg.str());
} }
symtab.replaceSymbol(sym, new ValueMapSymbol(sym->getName(),patval,*numlist)); symtab.replaceSymbol(sym, new ValueMapSymbol(sym->getName(),patval,*numlist));
} }
@ -2695,7 +2704,10 @@ void SleighCompile::attachNames(vector<SleighSymbol *> *symlist,vector<string> *
if (sym == (ValueSymbol *)0) continue; if (sym == (ValueSymbol *)0) continue;
PatternValue *patval = sym->getPatternValue(); PatternValue *patval = sym->getPatternValue();
if (patval->maxValue() + 1 != names->size()) { if (patval->maxValue() + 1 != names->size()) {
reportError(getCurrentLocation(), "Attach name '" + sym->getName() + "' is wrong size for list"); ostringstream msg;
msg << "Attach name '" + sym->getName();
msg << "' (range 0.." << patval->maxValue() << ") is wrong size for list (of " << names->size() << " entries)";
reportError(getCurrentLocation(), msg.str());
} }
symtab.replaceSymbol(sym,new NameSymbol(sym->getName(),patval,*names)); symtab.replaceSymbol(sym,new NameSymbol(sym->getName(),patval,*names));
} }
@ -2720,7 +2732,10 @@ void SleighCompile::attachVarnodes(vector<SleighSymbol *> *symlist,vector<Sleigh
if (sym == (ValueSymbol *)0) continue; if (sym == (ValueSymbol *)0) continue;
PatternValue *patval = sym->getPatternValue(); PatternValue *patval = sym->getPatternValue();
if (patval->maxValue() + 1 != varlist->size()) { if (patval->maxValue() + 1 != varlist->size()) {
reportError(getCurrentLocation(), "Attach varnode '" + sym->getName() + "' is wrong size for list"); ostringstream msg;
msg << "Attach varnode '" + sym->getName();
msg << "' (range 0.." << patval->maxValue() << ") is wrong size for list (of " << varlist->size() << " entries)";
reportError(getCurrentLocation(), msg.str());
} }
int4 sz = 0; int4 sz = 0;
for(int4 j=0;j<varlist->size();++j) { for(int4 j=0;j<varlist->size();++j) {