summaryrefslogtreecommitdiffstats
path: root/src/languages/gpasm.cpp
blob: 1da7355535db8deda4c9ae27cb40dfdf9b9a910e (plain)
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
/***************************************************************************
 *   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 "asmparser.h"
#include "docmanager.h"
#include "gpasm.h"
#include "logview.h"
#include "languagemanager.h"
#include "src/core/ktlconfig.h"

#include <klocale.h>
#include <kmessagebox.h>
#include <kprocess.h>
#include <tqregexp.h>

Gpasm::Gpasm( ProcessChain *processChain, KTechlab * parent )
 : ExternalLanguage( processChain, parent, "Gpasm" )
{
	m_successfulMessage = i18n("*** Assembly successful ***");
	m_failedMessage = i18n("*** Assembly failed ***");
}


Gpasm::~Gpasm()
{
}


void Gpasm::processInput( ProcessOptions options )
{
	resetLanguageProcess();
	m_processOptions = options;
	
	AsmParser p( options.inputFiles().first() );
	p.parse();
	
	*m_languageProcess << ("gpasm");
	
	if ( ProcessOptions::ProcessPath::from( options.processPath() ) == ProcessOptions::ProcessPath::AssemblyRelocatable )
		*m_languageProcess << ("--object");
	
// 	*m_languageProcess << ("--debug-info"); // Debug info
	
	// Output filename
	*m_languageProcess << ("--output");
	*m_languageProcess << ( options.intermediaryOutput() );
	
	if ( !options.m_hexFormat.isEmpty() )
	{
		*m_languageProcess << ("--hex-format");
		*m_languageProcess << (options.m_hexFormat);
	}
	
	// Radix
	if ( !p.containsRadix() )
	{
		*m_languageProcess << ("--radix");
		switch( KTLConfig::radix() )
		{
			case KTLConfig::EnumRadix::Binary:
				*m_languageProcess << ("BIN");
				break;
			case KTLConfig::EnumRadix::Octal:
				*m_languageProcess << ("OCT");
				break;
			case KTLConfig::EnumRadix::Hexadecimal:
				*m_languageProcess << ("HEX");
				break;
			case KTLConfig::EnumRadix::Decimal:
			default:
				*m_languageProcess << ("DEC");
				break;
		}
	}
	
	// Warning Level
	*m_languageProcess << ("--warning");
	switch( KTLConfig::gpasmWarningLevel() )
	{
		case KTLConfig::EnumGpasmWarningLevel::Warnings:
			*m_languageProcess << ("1");
			break;
		case KTLConfig::EnumGpasmWarningLevel::Errors:
			*m_languageProcess << ("2");
			break;
		default:
		case KTLConfig::EnumGpasmWarningLevel::All:
			*m_languageProcess << ("0");
			break;
	}
	
	// Ignore case
	if ( KTLConfig::ignoreCase() )
		*m_languageProcess << ("--ignore-case");
	
	// Dos formatting
	if ( KTLConfig::dosFormat() )
		*m_languageProcess << ("--dos");
	
	// Force list
	if ( options.b_forceList )
		*m_languageProcess << ("--force-list");
	
	// Other options
	if ( !KTLConfig::miscGpasmOptions().isEmpty() )
		*m_languageProcess << ( KTLConfig::miscGpasmOptions() );
	
	// Input Asm file
	*m_languageProcess << ( options.inputFiles().first() );
	
	if ( !start() )
	{
		KMessageBox::sorry( LanguageManager::self()->logView(), i18n("Assembly failed. Please check you have gputils installed.") );
		processInitFailed();
		return;
	}
}


bool Gpasm::isError( const TQString &message ) const
{
	return message.contains( "Error", false );
}


bool Gpasm::isWarning( const TQString &message ) const
{
	return message.contains( "Warning", false );
}


ProcessOptions::ProcessPath::Path Gpasm::outputPath( ProcessOptions::ProcessPath::Path inputPath ) const
{
	switch (inputPath)
	{
		case ProcessOptions::ProcessPath::AssemblyAbsolute_PIC:
			return ProcessOptions::ProcessPath::Program_PIC;
			
		case ProcessOptions::ProcessPath::AssemblyAbsolute_Program:
			return ProcessOptions::ProcessPath::None;
			
		case ProcessOptions::ProcessPath::AssemblyRelocatable_Library:
			return ProcessOptions::ProcessPath::Object_Library;
			
		case ProcessOptions::ProcessPath::AssemblyRelocatable_Object:
			return ProcessOptions::ProcessPath::None;
			
		case ProcessOptions::ProcessPath::AssemblyRelocatable_PIC:
			return ProcessOptions::ProcessPath::Object_PIC;
			
		case ProcessOptions::ProcessPath::AssemblyRelocatable_Program:
			return ProcessOptions::ProcessPath::Object_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_Disassembly:
		case ProcessOptions::ProcessPath::Object_Library:
		case ProcessOptions::ProcessPath::Object_PIC:
		case ProcessOptions::ProcessPath::Object_Program:
		case ProcessOptions::ProcessPath::PIC_AssemblyAbsolute:
		case ProcessOptions::ProcessPath::Program_Disassembly:
		case ProcessOptions::ProcessPath::Program_PIC:
		case ProcessOptions::ProcessPath::Invalid:
		case ProcessOptions::ProcessPath::None:
			return ProcessOptions::ProcessPath::Invalid;
	}
	
	return ProcessOptions::ProcessPath::Invalid;
}