[812dd5]: src / lib / simulator / src / languages / gpdasm.cpp Maximize Restore History

Download this file

gpdasm.cpp    162 lines (129 with data), 4.8 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/***************************************************************************
* Copyright (C) 2005 by David Saxton *
* david@bluehaze.org *
* *
* 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 "gpdasm.h"
#include "messageinfo.h"
#include "qprocesswitharguments.h"
#include <qfile.h>
#include <qregexp.h>
//Added by qt3to4:
#include <Q3TextStream>
#include <QDebug>
Gpdasm::Gpdasm( ProcessChain *processChain )
: ExternalLanguage( processChain, "Gpdasm" )
{
m_successfulMessage = tr("*** Disassembly successful ***");
m_failedMessage = tr("*** Disassembly failed ***");
}
Gpdasm::~Gpdasm()
{
}
void Gpdasm::processInput( ProcessOptions options )
{
resetLanguageProcess();
m_asmOutput = "";
m_processOptions = options;;
*m_languageProcess << ("gpdasm");
*m_languageProcess << ("--processor");
*m_languageProcess << ( options.m_picID );
*m_languageProcess << ( options.inputFiles().first() );
if ( !start() )
{
// QMessageBox::critical( LanguageManager::self()->logView(), tr("Disassembly failed. Please check you have gputils installed.") );
qDebug() << "disassembly failed";
processInitFailed();
return;
}
}
void Gpdasm::outputtedMessage( const QString &message )
{
m_asmOutput += message + "\n";
}
bool Gpdasm::processExited( bool successfully )
{
if (!successfully)
return false;
QFile file(m_processOptions.intermediaryOutput());
if ( file.open(QIODevice::WriteOnly) == false )
return false;
Q3TextStream stream(&file);
stream << m_asmOutput;
file.close();
return true;
}
bool Gpdasm::isError( const QString &message ) const
{
return (message.indexOf( "error", -1, Qt::CaseInsensitive ) != -1);
}
bool Gpdasm::isWarning( const QString &message ) const
{
return (message.indexOf( "warning", -1, Qt::CaseInsensitive ) != -1);
}
MessageInfo Gpdasm::extractMessageInfo( const QString &text )
{
if ( text.length()<5 || !text.startsWith("/") )
return MessageInfo();
const int index = text.indexOf( ".asm", 0, Qt::CaseInsensitive )+4;
if ( index == -1+4 )
return MessageInfo();
const QString fileName = text.left(index);
// Extra line number
const QString message = text.right(text.length()-index);
const int linePos = message.indexOf( QRegExp(":[\\d]+") );
int line = -1;
if ( linePos != -1 )
{
const int linePosEnd = message.indexOf( ':', linePos+1 );
if ( linePosEnd != -1 )
{
const QString number = message.mid( linePos+1, linePosEnd-linePos-1 )
.trimmed();
bool ok;
line = number.toInt(&ok)-1;
if (!ok) line = -1;
}
}
return MessageInfo( fileName, line );
}
ProcessOptions::ProcessPath::Path Gpdasm::outputPath( ProcessOptions::ProcessPath::Path inputPath ) const
{
switch (inputPath)
{
case ProcessOptions::ProcessPath::Object_Disassembly:
case ProcessOptions::ProcessPath::Program_Disassembly:
return ProcessOptions::ProcessPath::None;
case ProcessOptions::ProcessPath::AssemblyAbsolute_PIC:
case ProcessOptions::ProcessPath::AssemblyAbsolute_Program:
case ProcessOptions::ProcessPath::AssemblyRelocatable_Library:
case ProcessOptions::ProcessPath::AssemblyRelocatable_Object:
case ProcessOptions::ProcessPath::AssemblyRelocatable_PIC:
case ProcessOptions::ProcessPath::AssemblyRelocatable_Program:
case ProcessOptions::ProcessPath::C_AssemblyRelocatable:
case ProcessOptions::ProcessPath::C_Library:
case ProcessOptions::ProcessPath::C_Object:
case ProcessOptions::ProcessPath::C_PIC:
case ProcessOptions::ProcessPath::C_Program:
case ProcessOptions::ProcessPath::FlowCode_AssemblyAbsolute:
case ProcessOptions::ProcessPath::FlowCode_Microbe:
case ProcessOptions::ProcessPath::FlowCode_PIC:
case ProcessOptions::ProcessPath::FlowCode_Program:
case ProcessOptions::ProcessPath::Microbe_AssemblyAbsolute:
case ProcessOptions::ProcessPath::Microbe_PIC:
case ProcessOptions::ProcessPath::Microbe_Program:
case ProcessOptions::ProcessPath::Object_Library:
case ProcessOptions::ProcessPath::Object_PIC:
case ProcessOptions::ProcessPath::Object_Program:
case ProcessOptions::ProcessPath::PIC_AssemblyAbsolute:
case ProcessOptions::ProcessPath::Program_PIC:
case ProcessOptions::ProcessPath::Invalid:
case ProcessOptions::ProcessPath::None:
return ProcessOptions::ProcessPath::Invalid;
}
return ProcessOptions::ProcessPath::Invalid;
}