File indexing completed on 2024-07-21 05:07:53

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 "gpasm.h"
0012 #include "asmparser.h"
0013 #include "docmanager.h"
0014 #include "languagemanager.h"
0015 #include "logview.h"
0016 
0017 #include <KLocalizedString>
0018 #include <KMessageBox>
0019 #include <KProcess>
0020 #include <QRegExp>
0021 
0022 #include <ktlconfig.h>
0023 
0024 Gpasm::Gpasm(ProcessChain *processChain)
0025     : ExternalLanguage(processChain, "Gpasm")
0026 {
0027     m_successfulMessage = i18n("*** Assembly successful ***");
0028     m_failedMessage = i18n("*** Assembly failed ***");
0029 }
0030 
0031 Gpasm::~Gpasm()
0032 {
0033 }
0034 
0035 void Gpasm::processInput(ProcessOptions options)
0036 {
0037     resetLanguageProcess();
0038     m_processOptions = options;
0039 
0040     AsmParser p(options.inputFiles().first());
0041     p.parse();
0042 
0043     *m_languageProcess << ("gpasm");
0044 
0045     if (ProcessOptions::ProcessPath::from(options.processPath()) == ProcessOptions::ProcessPath::AssemblyRelocatable)
0046         *m_languageProcess << ("--object");
0047 
0048     //  *m_languageProcess << ("--debug-info"); // Debug info
0049 
0050     // Output filename
0051     *m_languageProcess << ("--output");
0052     *m_languageProcess << (options.intermediaryOutput());
0053 
0054     if (!options.m_hexFormat.isEmpty()) {
0055         *m_languageProcess << ("--hex-format");
0056         *m_languageProcess << (options.m_hexFormat);
0057     }
0058 
0059     // Radix
0060     if (!p.containsRadix()) {
0061         *m_languageProcess << ("--radix");
0062         switch (KTLConfig::radix()) {
0063         case KTLConfig::EnumRadix::Binary:
0064             *m_languageProcess << ("BIN");
0065             break;
0066         case KTLConfig::EnumRadix::Octal:
0067             *m_languageProcess << ("OCT");
0068             break;
0069         case KTLConfig::EnumRadix::Hexadecimal:
0070             *m_languageProcess << ("HEX");
0071             break;
0072         case KTLConfig::EnumRadix::Decimal:
0073         default:
0074             *m_languageProcess << ("DEC");
0075             break;
0076         }
0077     }
0078 
0079     // Warning Level
0080     *m_languageProcess << ("--warning");
0081     switch (KTLConfig::gpasmWarningLevel()) {
0082     case KTLConfig::EnumGpasmWarningLevel::Warnings:
0083         *m_languageProcess << ("1");
0084         break;
0085     case KTLConfig::EnumGpasmWarningLevel::Errors:
0086         *m_languageProcess << ("2");
0087         break;
0088     default:
0089     case KTLConfig::EnumGpasmWarningLevel::All:
0090         *m_languageProcess << ("0");
0091         break;
0092     }
0093 
0094     // Ignore case
0095     if (KTLConfig::ignoreCase())
0096         *m_languageProcess << ("--ignore-case");
0097 
0098     // Dos formatting
0099     if (KTLConfig::dosFormat())
0100         *m_languageProcess << ("--dos");
0101 
0102     // Force list
0103     if (options.b_forceList)
0104         *m_languageProcess << ("--force-list");
0105 
0106     // Other options
0107     if (!KTLConfig::miscGpasmOptions().isEmpty())
0108         *m_languageProcess << (KTLConfig::miscGpasmOptions());
0109 
0110     // Input Asm file
0111     *m_languageProcess << (options.inputFiles().first());
0112 
0113     if (!start()) {
0114         KMessageBox::error(LanguageManager::self()->logView(), i18n("Assembly failed. Please check you have gputils installed."));
0115         processInitFailed();
0116         return;
0117     }
0118 }
0119 
0120 bool Gpasm::isError(const QString &message) const
0121 {
0122     return message.contains("Error", Qt::CaseInsensitive);
0123 }
0124 
0125 bool Gpasm::isWarning(const QString &message) const
0126 {
0127     return message.contains("Warning", Qt::CaseInsensitive);
0128 }
0129 
0130 ProcessOptions::ProcessPath::Path Gpasm::outputPath(ProcessOptions::ProcessPath::Path inputPath) const
0131 {
0132     switch (inputPath) {
0133     case ProcessOptions::ProcessPath::AssemblyAbsolute_PIC:
0134         return ProcessOptions::ProcessPath::Program_PIC;
0135 
0136     case ProcessOptions::ProcessPath::AssemblyAbsolute_Program:
0137         return ProcessOptions::ProcessPath::None;
0138 
0139     case ProcessOptions::ProcessPath::AssemblyRelocatable_Library:
0140         return ProcessOptions::ProcessPath::Object_Library;
0141 
0142     case ProcessOptions::ProcessPath::AssemblyRelocatable_Object:
0143         return ProcessOptions::ProcessPath::None;
0144 
0145     case ProcessOptions::ProcessPath::AssemblyRelocatable_PIC:
0146         return ProcessOptions::ProcessPath::Object_PIC;
0147 
0148     case ProcessOptions::ProcessPath::AssemblyRelocatable_Program:
0149         return ProcessOptions::ProcessPath::Object_Program;
0150 
0151     case ProcessOptions::ProcessPath::C_AssemblyRelocatable:
0152     case ProcessOptions::ProcessPath::C_Library:
0153     case ProcessOptions::ProcessPath::C_Object:
0154     case ProcessOptions::ProcessPath::C_PIC:
0155     case ProcessOptions::ProcessPath::C_Program:
0156     case ProcessOptions::ProcessPath::FlowCode_AssemblyAbsolute:
0157     case ProcessOptions::ProcessPath::FlowCode_Microbe:
0158     case ProcessOptions::ProcessPath::FlowCode_PIC:
0159     case ProcessOptions::ProcessPath::FlowCode_Program:
0160     case ProcessOptions::ProcessPath::Microbe_AssemblyAbsolute:
0161     case ProcessOptions::ProcessPath::Microbe_PIC:
0162     case ProcessOptions::ProcessPath::Microbe_Program:
0163     case ProcessOptions::ProcessPath::Object_Disassembly:
0164     case ProcessOptions::ProcessPath::Object_Library:
0165     case ProcessOptions::ProcessPath::Object_PIC:
0166     case ProcessOptions::ProcessPath::Object_Program:
0167     case ProcessOptions::ProcessPath::PIC_AssemblyAbsolute:
0168     case ProcessOptions::ProcessPath::Program_Disassembly:
0169     case ProcessOptions::ProcessPath::Program_PIC:
0170     case ProcessOptions::ProcessPath::Invalid:
0171     case ProcessOptions::ProcessPath::None:
0172         return ProcessOptions::ProcessPath::Invalid;
0173     }
0174 
0175     return ProcessOptions::ProcessPath::Invalid;
0176 }