00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "asmparser.h"
00012 #include "docmanager.h"
00013 #include "gpasm.h"
00014 #include "logview.h"
00015 #include "languagemanager.h"
00016 #include "src/core/ktlconfig.h"
00017
00018 #include <klocale.h>
00019 #include <kmessagebox.h>
00020 #include <kprocess.h>
00021 #include <qregexp.h>
00022
00023 Gpasm::Gpasm( ProcessChain *processChain, KTechlab * parent )
00024 : ExternalLanguage( processChain, parent, "Gpasm" )
00025 {
00026 m_successfulMessage = i18n("*** Assembly successful ***");
00027 m_failedMessage = i18n("*** Assembly failed ***");
00028 }
00029
00030
00031 Gpasm::~Gpasm()
00032 {
00033 }
00034
00035
00036 void Gpasm::processInput( ProcessOptions options )
00037 {
00038 resetLanguageProcess();
00039 m_processOptions = options;
00040
00041 AsmParser p( options.inputFiles().first() );
00042 p.parse();
00043
00044 *m_languageProcess << ("gpasm");
00045
00046 if ( ProcessOptions::ProcessPath::from( options.processPath() ) == ProcessOptions::ProcessPath::AssemblyRelocatable )
00047 *m_languageProcess << ("--object");
00048
00049
00050
00051
00052 *m_languageProcess << ("--output");
00053 *m_languageProcess << ( options.intermediaryOutput() );
00054
00055 if ( !options.m_hexFormat.isEmpty() )
00056 {
00057 *m_languageProcess << ("--hex-format");
00058 *m_languageProcess << (options.m_hexFormat);
00059 }
00060
00061
00062 if ( !p.containsRadix() )
00063 {
00064 *m_languageProcess << ("--radix");
00065 switch( KTLConfig::radix() )
00066 {
00067 case KTLConfig::EnumRadix::Binary:
00068 *m_languageProcess << ("BIN");
00069 break;
00070 case KTLConfig::EnumRadix::Octal:
00071 *m_languageProcess << ("OCT");
00072 break;
00073 case KTLConfig::EnumRadix::Hexadecimal:
00074 *m_languageProcess << ("HEX");
00075 break;
00076 case KTLConfig::EnumRadix::Decimal:
00077 default:
00078 *m_languageProcess << ("DEC");
00079 break;
00080 }
00081 }
00082
00083
00084 *m_languageProcess << ("--warning");
00085 switch( KTLConfig::gpasmWarningLevel() )
00086 {
00087 case KTLConfig::EnumGpasmWarningLevel::Warnings:
00088 *m_languageProcess << ("1");
00089 break;
00090 case KTLConfig::EnumGpasmWarningLevel::Errors:
00091 *m_languageProcess << ("2");
00092 break;
00093 default:
00094 case KTLConfig::EnumGpasmWarningLevel::All:
00095 *m_languageProcess << ("0");
00096 break;
00097 }
00098
00099
00100 if ( KTLConfig::ignoreCase() )
00101 *m_languageProcess << ("--ignore-case");
00102
00103
00104 if ( KTLConfig::dosFormat() )
00105 *m_languageProcess << ("--dos");
00106
00107
00108 if ( options.b_forceList )
00109 *m_languageProcess << ("--force-list");
00110
00111
00112 if ( !KTLConfig::miscGpasmOptions().isEmpty() )
00113 *m_languageProcess << ( KTLConfig::miscGpasmOptions() );
00114
00115
00116 *m_languageProcess << ( options.inputFiles().first() );
00117
00118 if ( !start() )
00119 {
00120 KMessageBox::sorry( LanguageManager::self()->logView(), i18n("Assembly failed. Please check you have gputils installed.") );
00121 processInitFailed();
00122 return;
00123 }
00124 }
00125
00126
00127 bool Gpasm::isError( const QString &message ) const
00128 {
00129 return message.contains( "Error", false );
00130 }
00131
00132
00133 bool Gpasm::isWarning( const QString &message ) const
00134 {
00135 return message.contains( "Warning", false );
00136 }
00137
00138
00139 ProcessOptions::ProcessPath::Path Gpasm::outputPath( ProcessOptions::ProcessPath::Path inputPath ) const
00140 {
00141 switch (inputPath)
00142 {
00143 case ProcessOptions::ProcessPath::AssemblyAbsolute_PIC:
00144 return ProcessOptions::ProcessPath::Program_PIC;
00145
00146 case ProcessOptions::ProcessPath::AssemblyAbsolute_Program:
00147 return ProcessOptions::ProcessPath::None;
00148
00149 case ProcessOptions::ProcessPath::AssemblyRelocatable_Library:
00150 return ProcessOptions::ProcessPath::Object_Library;
00151
00152 case ProcessOptions::ProcessPath::AssemblyRelocatable_Object:
00153 return ProcessOptions::ProcessPath::None;
00154
00155 case ProcessOptions::ProcessPath::AssemblyRelocatable_PIC:
00156 return ProcessOptions::ProcessPath::Object_PIC;
00157
00158 case ProcessOptions::ProcessPath::AssemblyRelocatable_Program:
00159 return ProcessOptions::ProcessPath::Object_Program;
00160
00161 case ProcessOptions::ProcessPath::C_AssemblyRelocatable:
00162 case ProcessOptions::ProcessPath::C_Library:
00163 case ProcessOptions::ProcessPath::C_Object:
00164 case ProcessOptions::ProcessPath::C_PIC:
00165 case ProcessOptions::ProcessPath::C_Program:
00166 case ProcessOptions::ProcessPath::FlowCode_AssemblyAbsolute:
00167 case ProcessOptions::ProcessPath::FlowCode_Microbe:
00168 case ProcessOptions::ProcessPath::FlowCode_PIC:
00169 case ProcessOptions::ProcessPath::FlowCode_Program:
00170 case ProcessOptions::ProcessPath::Microbe_AssemblyAbsolute:
00171 case ProcessOptions::ProcessPath::Microbe_PIC:
00172 case ProcessOptions::ProcessPath::Microbe_Program:
00173 case ProcessOptions::ProcessPath::Object_Disassembly:
00174 case ProcessOptions::ProcessPath::Object_Library:
00175 case ProcessOptions::ProcessPath::Object_PIC:
00176 case ProcessOptions::ProcessPath::Object_Program:
00177 case ProcessOptions::ProcessPath::PIC_AssemblyAbsolute:
00178 case ProcessOptions::ProcessPath::Program_Disassembly:
00179 case ProcessOptions::ProcessPath::Program_PIC:
00180 case ProcessOptions::ProcessPath::Invalid:
00181 case ProcessOptions::ProcessPath::None:
00182 return ProcessOptions::ProcessPath::Invalid;
00183 }
00184
00185 return ProcessOptions::ProcessPath::Invalid;
00186 }
00187