/*************************************************************************** * Copyright (C) 2006-2007 Nicolas Hadacek * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * ***************************************************************************/ #include "disassembler.h" #include #include "devices/base/device_group.h" #include "devices/pic/pic/pic_memory.h" #include "coff_object.h" //----------------------------------------------------------------------------- QString SourceLine::comment(PURL::SourceFamily family, const QString &text) { switch (family.type()) { case PURL::SourceFamily::Asm: return "; " + text; case PURL::SourceFamily::C: return "/* " + text + " */"; case PURL::SourceFamily::JAL: return "-- " + text; case PURL::SourceFamily::Cpp: return "// " + text; case PURL::SourceFamily::Basic: return "' " + text; case PURL::SourceFamily::Nb_Types: break; } Q_ASSERT(false); return QString::null; } namespace SourceLine { class LineData { public: LineData() : group(-1) {} QString text, comment; int group; }; } // namespace QStringList SourceLine::lines(PURL::SourceFamily family, const List &list, uint nbSpaces) { QValueList lines; QValueList groupCommentColumn; groupCommentColumn.append(0); List::const_iterator it; for (it=list.begin(); it!=list.end(); ++it) { LineData data; switch((*it).type) { case Indented: data.text = repeat(" ", nbSpaces); case NotIndented: if ( (*it).code.isEmpty() && !(*it).comment.isEmpty() ) data.text += comment(family, (*it).comment); else { data.text += (*it).code; data.comment = (*it).comment; data.group = groupCommentColumn.count() - 1; groupCommentColumn[data.group] = qMax(groupCommentColumn[data.group], uint(data.text.length())); } break; case Separator: data.text = comment(family, "-----------------------------------------------------------------------"); groupCommentColumn.append(0); break; case Empty: break; case Title: data.text = comment(family, (*it).comment); break; } lines += data; } QStringList slines; QValueList::const_iterator lit; for (lit=lines.begin(); lit!=lines.end(); ++lit) { if ( (*lit).group==-1 || (*lit).comment.isEmpty() ) slines += (*lit).text; else { uint col = groupCommentColumn[(*lit).group] + 1; slines += (*lit).text.leftJustify(col, ' ') + comment(family, (*lit).comment); } } return slines; } QString SourceLine::text(PURL::SourceFamily family, const List &list, uint nbSpaces) { return lines(family, list, nbSpaces).join("\n") + "\n"; } QString SourceLine::transformConfigName(const Pic::Data &data, uint wordIndex, const QString &name) { if ( !data.is18Family() ) return name; bool ok; (void)fromHexLabel(name, &ok); if (ok) return name; QString s = name + '_'; if ( data.name()=="18C601" || data.name()=="18C801" || data.name().startsWith("18F" ) ) s += QString::number(wordIndex/2+1) + (wordIndex%2==0 ? 'L' : 'H'); else s += QString::number(wordIndex); return s; } QStringList SourceLine::ignoredConfigNames(const Pic::Data &data, uint wordIndex) { QStringList cnames; const QStringList &names = data.config()._words[wordIndex].ignoredCNames; for (uint i=0; i=0; l--) { const Pic::Config::Value &cvalue = cmask.values[l]; if ( !cvalue.value.isInside(v) ) continue; QStringList vcnames = cvalue.configNames[type]; if ( vcnames.isEmpty() && type!=Pic::ConfigNameType::Default ) vcnames = cvalue.configNames[Pic::ConfigNameType::Default]; for (uint i=0; i"); return lines; } SourceLine::List GPUtils::generateConfigLines(const Pic::Memory &memory, bool &ok) { SourceLine::List lines; const Pic::Data &data = memory.device(); const Pic::Config &config = data.config(); for (uint i=0; i