File indexing completed on 2025-04-13 05:11:20
0001 /*************************************************************************** 0002 * Copyright (C) 2005 by David Saxton * 0003 * david@bluehaze.org * 0004 * * 0005 * This program is free software; you can redistribute it and/or modify * 0006 * it under the terms of the GNU General Public License as published by * 0007 * the Free Software Foundation; either version 2 of the License, or * 0008 * (at your option) any later version. * 0009 ***************************************************************************/ 0010 0011 #include "gpdasm.h" 0012 #include "docmanager.h" 0013 #include "languagemanager.h" 0014 #include "logview.h" 0015 0016 #include <KLocalizedString> 0017 #include <KMessageBox> 0018 #include <KProcess> 0019 0020 #include <QFile> 0021 #include <QRegExp> 0022 #include <QTextStream> 0023 0024 Gpdasm::Gpdasm(ProcessChain *processChain) 0025 : ExternalLanguage(processChain, "Gpdasm") 0026 { 0027 m_successfulMessage = i18n("*** Disassembly successful ***"); 0028 m_failedMessage = i18n("*** Disassembly failed ***"); 0029 } 0030 0031 Gpdasm::~Gpdasm() 0032 { 0033 } 0034 0035 void Gpdasm::processInput(ProcessOptions options) 0036 { 0037 resetLanguageProcess(); 0038 m_asmOutput = ""; 0039 m_processOptions = options; 0040 ; 0041 0042 *m_languageProcess << ("gpdasm"); 0043 0044 *m_languageProcess << ("--processor"); 0045 *m_languageProcess << (options.m_picID); 0046 *m_languageProcess << (options.inputFiles().first()); 0047 0048 if (!start()) { 0049 KMessageBox::error(LanguageManager::self()->logView(), i18n("Disassembly failed. Please check you have gputils installed.")); 0050 processInitFailed(); 0051 return; 0052 } 0053 } 0054 0055 void Gpdasm::outputtedMessage(const QString &message) 0056 { 0057 m_asmOutput += message + "\n"; 0058 } 0059 0060 bool Gpdasm::processExited(bool successfully) 0061 { 0062 if (!successfully) 0063 return false; 0064 0065 QFile file(m_processOptions.intermediaryOutput()); 0066 if (file.open(QIODevice::WriteOnly) == false) 0067 return false; 0068 0069 QTextStream stream(&file); 0070 stream << m_asmOutput; 0071 file.close(); 0072 return true; 0073 } 0074 0075 bool Gpdasm::isError(const QString &message) const 0076 { 0077 return (message.indexOf("error", -1, Qt::CaseInsensitive) != -1); 0078 } 0079 0080 bool Gpdasm::isWarning(const QString &message) const 0081 { 0082 return (message.indexOf("warning", -1, Qt::CaseInsensitive) != -1); 0083 } 0084 0085 MessageInfo Gpdasm::extractMessageInfo(const QString &text) 0086 { 0087 if (text.length() < 5 || !text.startsWith("/")) 0088 return MessageInfo(); 0089 0090 const int index = text.indexOf(".asm", 0, Qt::CaseInsensitive) + 4; 0091 if (index == -1 + 4) 0092 return MessageInfo(); 0093 const QString fileName = text.left(index); 0094 0095 // Extra line number 0096 const QString message = text.right(text.length() - index); 0097 const int linePos = message.indexOf(QRegExp(":[\\d]+")); 0098 int line = -1; 0099 if (linePos != -1) { 0100 const int linePosEnd = message.indexOf(':', linePos + 1); 0101 if (linePosEnd != -1) { 0102 const QString number = message.mid(linePos + 1, linePosEnd - linePos - 1).trimmed(); 0103 bool ok; 0104 line = number.toInt(&ok) - 1; 0105 if (!ok) 0106 line = -1; 0107 } 0108 } 0109 0110 return MessageInfo(fileName, line); 0111 } 0112 0113 ProcessOptions::ProcessPath::Path Gpdasm::outputPath(ProcessOptions::ProcessPath::Path inputPath) const 0114 { 0115 switch (inputPath) { 0116 case ProcessOptions::ProcessPath::Object_Disassembly: 0117 case ProcessOptions::ProcessPath::Program_Disassembly: 0118 return ProcessOptions::ProcessPath::None; 0119 0120 case ProcessOptions::ProcessPath::AssemblyAbsolute_PIC: 0121 case ProcessOptions::ProcessPath::AssemblyAbsolute_Program: 0122 case ProcessOptions::ProcessPath::AssemblyRelocatable_Library: 0123 case ProcessOptions::ProcessPath::AssemblyRelocatable_Object: 0124 case ProcessOptions::ProcessPath::AssemblyRelocatable_PIC: 0125 case ProcessOptions::ProcessPath::AssemblyRelocatable_Program: 0126 case ProcessOptions::ProcessPath::C_AssemblyRelocatable: 0127 case ProcessOptions::ProcessPath::C_Library: 0128 case ProcessOptions::ProcessPath::C_Object: 0129 case ProcessOptions::ProcessPath::C_PIC: 0130 case ProcessOptions::ProcessPath::C_Program: 0131 case ProcessOptions::ProcessPath::FlowCode_AssemblyAbsolute: 0132 case ProcessOptions::ProcessPath::FlowCode_Microbe: 0133 case ProcessOptions::ProcessPath::FlowCode_PIC: 0134 case ProcessOptions::ProcessPath::FlowCode_Program: 0135 case ProcessOptions::ProcessPath::Microbe_AssemblyAbsolute: 0136 case ProcessOptions::ProcessPath::Microbe_PIC: 0137 case ProcessOptions::ProcessPath::Microbe_Program: 0138 case ProcessOptions::ProcessPath::Object_Library: 0139 case ProcessOptions::ProcessPath::Object_PIC: 0140 case ProcessOptions::ProcessPath::Object_Program: 0141 case ProcessOptions::ProcessPath::PIC_AssemblyAbsolute: 0142 case ProcessOptions::ProcessPath::Program_PIC: 0143 case ProcessOptions::ProcessPath::Invalid: 0144 case ProcessOptions::ProcessPath::None: 0145 return ProcessOptions::ProcessPath::Invalid; 0146 } 0147 0148 return ProcessOptions::ProcessPath::Invalid; 0149 }