00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "docmanager.h"
00012 #include "gpdasm.h"
00013 #include "logview.h"
00014 #include "languagemanager.h"
00015
00016 #include <klocale.h>
00017 #include <kmessagebox.h>
00018 #include <kprocess.h>
00019 #include <qfile.h>
00020 #include <qregexp.h>
00021
00022 Gpdasm::Gpdasm( ProcessChain *processChain, KTechlab *parent )
00023 : ExternalLanguage( processChain, parent, "Gpdasm" )
00024 {
00025 m_successfulMessage = i18n("*** Disassembly successful ***");
00026 m_failedMessage = i18n("*** Disassembly failed ***");
00027 }
00028
00029
00030 Gpdasm::~Gpdasm()
00031 {
00032 }
00033
00034
00035 void Gpdasm::processInput( ProcessOptions options )
00036 {
00037 resetLanguageProcess();
00038 m_asmOutput = "";
00039 m_processOptions = options;;
00040
00041 *m_languageProcess << ("gpdasm");
00042
00043 *m_languageProcess << ("--processor");
00044 *m_languageProcess << ( options.m_picID );
00045 *m_languageProcess << ( options.inputFiles().first() );
00046
00047 if ( !start() )
00048 {
00049 KMessageBox::sorry( LanguageManager::self()->logView(), i18n("Disassembly failed. Please check you have gputils installed.") );
00050 processInitFailed();
00051 return;
00052 }
00053 }
00054
00055
00056 void Gpdasm::outputtedMessage( const QString &message )
00057 {
00058 m_asmOutput += message + "\n";
00059 }
00060
00061
00062 bool Gpdasm::processExited( bool successfully )
00063 {
00064 if (!successfully)
00065 return false;
00066
00067 QFile file(m_processOptions.intermediaryOutput());
00068 if ( file.open(IO_WriteOnly) == false )
00069 return false;
00070
00071 QTextStream stream(&file);
00072 stream << m_asmOutput;
00073 file.close();
00074 return true;
00075 }
00076
00077
00078 bool Gpdasm::isError( const QString &message ) const
00079 {
00080 return (message.find( "error", -1, false ) != -1);
00081 }
00082
00083
00084 bool Gpdasm::isWarning( const QString &message ) const
00085 {
00086 return (message.find( "warning", -1, false ) != -1);
00087 }
00088
00089
00090 MessageInfo Gpdasm::extractMessageInfo( const QString &text )
00091 {
00092 if ( text.length()<5 || !text.startsWith("/") )
00093 return MessageInfo();
00094
00095 const int index = text.find( ".asm", 0, false )+4;
00096 if ( index == -1+4 )
00097 return MessageInfo();
00098 const QString fileName = text.left(index);
00099
00100
00101 const QString message = text.right(text.length()-index);
00102 const int linePos = message.find( QRegExp(":[\\d]+") );
00103 int line = -1;
00104 if ( linePos != -1 )
00105 {
00106 const int linePosEnd = message.find( ':', linePos+1 );
00107 if ( linePosEnd != -1 )
00108 {
00109 const QString number = message.mid( linePos+1, linePosEnd-linePos-1 ).stripWhiteSpace();
00110 bool ok;
00111 line = number.toInt(&ok)-1;
00112 if (!ok) line = -1;
00113 }
00114 }
00115
00116 return MessageInfo( fileName, line );
00117 }
00118
00119
00120
00121 ProcessOptions::ProcessPath::Path Gpdasm::outputPath( ProcessOptions::ProcessPath::Path inputPath ) const
00122 {
00123 switch (inputPath)
00124 {
00125 case ProcessOptions::ProcessPath::Object_Disassembly:
00126 case ProcessOptions::ProcessPath::Program_Disassembly:
00127 return ProcessOptions::ProcessPath::None;
00128
00129 case ProcessOptions::ProcessPath::AssemblyAbsolute_PIC:
00130 case ProcessOptions::ProcessPath::AssemblyAbsolute_Program:
00131 case ProcessOptions::ProcessPath::AssemblyRelocatable_Library:
00132 case ProcessOptions::ProcessPath::AssemblyRelocatable_Object:
00133 case ProcessOptions::ProcessPath::AssemblyRelocatable_PIC:
00134 case ProcessOptions::ProcessPath::AssemblyRelocatable_Program:
00135 case ProcessOptions::ProcessPath::C_AssemblyRelocatable:
00136 case ProcessOptions::ProcessPath::C_Library:
00137 case ProcessOptions::ProcessPath::C_Object:
00138 case ProcessOptions::ProcessPath::C_PIC:
00139 case ProcessOptions::ProcessPath::C_Program:
00140 case ProcessOptions::ProcessPath::FlowCode_AssemblyAbsolute:
00141 case ProcessOptions::ProcessPath::FlowCode_Microbe:
00142 case ProcessOptions::ProcessPath::FlowCode_PIC:
00143 case ProcessOptions::ProcessPath::FlowCode_Program:
00144 case ProcessOptions::ProcessPath::Microbe_AssemblyAbsolute:
00145 case ProcessOptions::ProcessPath::Microbe_PIC:
00146 case ProcessOptions::ProcessPath::Microbe_Program:
00147 case ProcessOptions::ProcessPath::Object_Library:
00148 case ProcessOptions::ProcessPath::Object_PIC:
00149 case ProcessOptions::ProcessPath::Object_Program:
00150 case ProcessOptions::ProcessPath::PIC_AssemblyAbsolute:
00151 case ProcessOptions::ProcessPath::Program_PIC:
00152 case ProcessOptions::ProcessPath::Invalid:
00153 case ProcessOptions::ProcessPath::None:
00154 return ProcessOptions::ProcessPath::Invalid;
00155 }
00156
00157 return ProcessOptions::ProcessPath::Invalid;
00158 }