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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
|
/***************************************************************************
* 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 "ktechlab.h"
#include "language.h"
#include "logview.h"
#include "outputmethoddlg.h"
#include "processchain.h"
#include "projectmanager.h"
#include "languagemanager.h"
#include "src/core/ktlconfig.h"
#include <kdebug.h>
#include <tdeio/netaccess.h>
#include <tdemessagebox.h>
#include <kprocess.h>
#include <tqregexp.h>
#include <tqtimer.h>
//BEGIN class Language
Language::Language( ProcessChain *processChain, KTechlab *parent, const TQString &name )
: TQObject(parent,name)
{
p_ktechlab = parent;
p_processChain = processChain;
}
Language::~Language()
{
}
void Language::outputMessage( const TQString &message )
{
LanguageManager::self()->slotMessage( message, extractMessageInfo(message) );
}
void Language::outputWarning( const TQString &message )
{
LanguageManager::self()->slotWarning( message, extractMessageInfo(message) );
}
void Language::outputError( const TQString &message )
{
LanguageManager::self()->slotError( message, extractMessageInfo(message) );
m_errorCount++;
}
void Language::finish( bool successful )
{
if (successful)
{
outputMessage(m_successfulMessage + "\n");
p_ktechlab->slotChangeStatusbar(m_successfulMessage);
ProcessOptions::ProcessPath::Path newPath = outputPath( m_processOptions.processPath() );
if ( newPath == ProcessOptions::ProcessPath::None )
emit processSucceeded(this);
else if (p_processChain)
{
m_processOptions.setInputFiles( m_processOptions.intermediaryOutput() );
m_processOptions.setIntermediaryOutput( m_processOptions.targetFile() );
m_processOptions.setProcessPath(newPath);
// p_processChain->compile(m_processOptions);
p_processChain->setProcessOptions(m_processOptions);
p_processChain->compile();
}
}
else
{
outputError(m_failedMessage + "\n");
p_ktechlab->slotChangeStatusbar(m_failedMessage);
emit processFailed(this);
return;
}
}
void Language::reset()
{
m_errorCount = 0;
}
MessageInfo Language::extractMessageInfo( const TQString &text )
{
if ( !text.startsWith("/") )
return MessageInfo();
const int index = text.find( ":", 0, false );
if ( index == -1 )
return MessageInfo();
const TQString fileName = text.left(index);
// Extra line number
const TQString message = text.right(text.length()-index);
const int linePos = message.find( TQRegExp(":[\\d]+") );
int line = -1;
if ( linePos != -1 )
{
const int linePosEnd = message.find( ':', linePos+1 );
if ( linePosEnd != -1 )
{
const TQString number = message.mid( linePos+1, linePosEnd-linePos-1 ).stripWhiteSpace();
bool ok;
line = number.toInt(&ok)-1;
if (!ok) line = -1;
}
}
return MessageInfo( fileName, line );
}
//END class Language
//BEGIN class ProcessOptionsSpecial
ProcessOptionsSpecial::ProcessOptionsSpecial()
{
m_bOutputMapFile = true;
b_forceList = true;
b_addToProject = ProjectManager::self()->currentProject();
p_flowCodeDocument = 0l;
switch ( KTLConfig::hexFormat() )
{
case KTLConfig::EnumHexFormat::inhx8m:
m_hexFormat = "inhx8m";
break;
case KTLConfig::EnumHexFormat::inhx8s:
m_hexFormat = "inhx8s";
break;
case KTLConfig::EnumHexFormat::inhx16:
m_hexFormat = "inhx16";
break;
case KTLConfig::EnumHexFormat::inhx32:
default:
m_hexFormat = "inhx32";
break;
}
}
//END class ProcessOptionsSpecial
//BEGIN class ProcessOptions
ProcessOptions::ProcessOptions()
{
m_pHelper = new ProcessOptionsHelper;
b_targetFileSet = false;
m_pTextOutputTarget = 0l;
}
ProcessOptions::ProcessOptions( OutputMethodInfo info )
{
m_pHelper = new ProcessOptionsHelper;
b_addToProject = info.addToProject();
m_picID = info.picID();
b_targetFileSet = false;
TQString target;
if ( !TDEIO::NetAccess::download( info.outputFile(), target, 0l ) )
{
// If the file could not be downloaded, for example does not
// exist on disk, NetAccess will tell us what error to use
KMessageBox::error( 0l, TDEIO::NetAccess::lastErrorString() );
return;
}
setTargetFile(target);
switch ( info.method() )
{
case OutputMethodInfo::Method::Direct:
m_method = Method::LoadAsNew;
break;
case OutputMethodInfo::Method::SaveAndForget:
m_method = Method::Forget;
break;
case OutputMethodInfo::Method::SaveAndLoad:
m_method = Method::Load;
break;
}
}
void ProcessOptions::setTextOutputTarget( TextDocument * target, TQObject * receiver, const char * slot )
{
m_pTextOutputTarget = target;
TQObject::connect( m_pHelper, TQT_SIGNAL(textOutputtedTo( TextDocument* )), receiver, slot );
}
void ProcessOptions::setTextOutputtedTo( TextDocument * outputtedTo )
{
m_pTextOutputTarget = outputtedTo;
emit m_pHelper->textOutputtedTo( m_pTextOutputTarget );
}
void ProcessOptions::setTargetFile( const TQString &file )
{
if (b_targetFileSet)
{
kdWarning() << "Trying to reset target file!"<<endl;
return;
}
m_targetFile = file;
m_intermediaryFile = file;
b_targetFileSet = true;
}
ProcessOptions::ProcessPath::MediaType ProcessOptions::guessMediaType( const TQString & url )
{
TQString extension = url.right( url.length() - url.findRev('.') - 1 );
extension = extension.lower();
if ( extension == "asm" )
{
// We'll have to look at the file contents to determine its type...
AsmParser p( url );
p.parse();
switch ( p.type() )
{
case AsmParser::Relocatable:
return ProcessPath::AssemblyRelocatable;
case AsmParser::Absolute:
return ProcessPath::AssemblyAbsolute;
}
}
if ( extension == "c" )
return ProcessPath::C;
if ( extension == "flowcode" )
return ProcessPath::FlowCode;
if ( extension == "a" || extension == "lib" )
return ProcessPath::Library;
if ( extension == "microbe" || extension == "basic" )
return ProcessPath::Microbe;
if ( extension == "o" )
return ProcessPath::Object;
if ( extension == "hex" )
return ProcessPath::Program;
return ProcessPath::Unknown;
}
ProcessOptions::ProcessPath::Path ProcessOptions::ProcessPath::path( MediaType from, MediaType to )
{
switch (from)
{
case AssemblyAbsolute:
switch (to)
{
case AssemblyAbsolute:
return None;
case Pic:
return AssemblyAbsolute_PIC;
case Program:
return AssemblyAbsolute_Program;
case AssemblyRelocatable:
case C:
case Disassembly:
case FlowCode:
case Library:
case Microbe:
case Object:
case Unknown:
return Invalid;
}
case AssemblyRelocatable:
switch (to)
{
case Library:
return AssemblyRelocatable_Library;
case Object:
return AssemblyRelocatable_Object;
case Pic:
return AssemblyRelocatable_PIC;
case Program:
return AssemblyRelocatable_Program;
case AssemblyAbsolute:
case AssemblyRelocatable:
case C:
case Disassembly:
case FlowCode:
case Microbe:
case Unknown:
return Invalid;
}
case C:
switch (to)
{
case AssemblyRelocatable:
return C_AssemblyRelocatable;
case Library:
return C_Library;
case Object:
return C_Object;
case Pic:
return C_PIC;
case Program:
return C_Program;
case AssemblyAbsolute:
case C:
case Disassembly:
case FlowCode:
case Microbe:
case Unknown:
return Invalid;
}
case Disassembly:
return Invalid;
case FlowCode:
switch (to)
{
case AssemblyAbsolute:
return FlowCode_AssemblyAbsolute;
case Microbe:
return FlowCode_Microbe;
case Pic:
return FlowCode_PIC;
case Program:
return FlowCode_Program;
case AssemblyRelocatable:
case C:
case Disassembly:
case FlowCode:
case Library:
case Object:
case Unknown:
return Invalid;
}
case Library:
return Invalid;
case Microbe:
switch (to)
{
case AssemblyAbsolute:
return Microbe_AssemblyAbsolute;
case Pic:
return Microbe_PIC;
case Program:
return Microbe_Program;
case AssemblyRelocatable:
case C:
case Disassembly:
case FlowCode:
case Library:
case Microbe:
case Object:
case Unknown:
return Invalid;
}
case Object:
switch (to)
{
case Disassembly:
return Object_Disassembly;
case Library:
return Object_Library;
case Pic:
return Object_PIC;
case Program:
return Object_Program;
case AssemblyAbsolute:
case AssemblyRelocatable:
case C:
case FlowCode:
case Microbe:
case Object:
case Unknown:
return Invalid;
}
case Pic:
return Invalid;
case Program:
switch (to)
{
case Disassembly:
return Program_Disassembly;
case Pic:
return Program_PIC;
case AssemblyAbsolute:
case AssemblyRelocatable:
case C:
case FlowCode:
case Library:
case Microbe:
case Object:
case Program:
case Unknown:
return Invalid;
}
case Unknown:
return Invalid;
}
return Invalid;
}
ProcessOptions::ProcessPath::MediaType ProcessOptions::ProcessPath::from( Path path )
{
switch (path)
{
case ProcessPath::AssemblyAbsolute_PIC:
case ProcessPath::AssemblyAbsolute_Program:
return AssemblyAbsolute;
case ProcessPath::AssemblyRelocatable_Library:
case ProcessPath::AssemblyRelocatable_Object:
case ProcessPath::AssemblyRelocatable_PIC:
case ProcessPath::AssemblyRelocatable_Program:
return AssemblyRelocatable;
case ProcessPath::C_AssemblyRelocatable:
case ProcessPath::C_Library:
case ProcessPath::C_Object:
case ProcessPath::C_PIC:
case ProcessPath::C_Program:
return C;
case ProcessPath::FlowCode_AssemblyAbsolute:
case ProcessPath::FlowCode_Microbe:
case ProcessPath::FlowCode_PIC:
case ProcessPath::FlowCode_Program:
return FlowCode;
case ProcessPath::Microbe_AssemblyAbsolute:
case ProcessPath::Microbe_PIC:
case ProcessPath::Microbe_Program:
return Microbe;
case ProcessPath::Object_Disassembly:
case ProcessPath::Object_Library:
case ProcessPath::Object_PIC:
case ProcessPath::Object_Program:
return Object;
case ProcessPath::PIC_AssemblyAbsolute:
return Pic;
case ProcessPath::Program_Disassembly:
case ProcessPath::Program_PIC:
return Program;
case ProcessPath::Invalid:
case ProcessPath::None:
return Unknown;
}
return Unknown;
}
ProcessOptions::ProcessPath::MediaType ProcessOptions::ProcessPath::to( Path path )
{
switch (path)
{
case ProcessPath::FlowCode_AssemblyAbsolute:
case ProcessPath::Microbe_AssemblyAbsolute:
case ProcessPath::PIC_AssemblyAbsolute:
return AssemblyAbsolute;
case ProcessPath::C_AssemblyRelocatable:
return AssemblyRelocatable;
case ProcessPath::Object_Disassembly:
case ProcessPath::Program_Disassembly:
return Disassembly;
case ProcessPath::AssemblyRelocatable_Library:
case ProcessPath::C_Library:
case ProcessPath::Object_Library:
return Library;
case ProcessPath::FlowCode_Microbe:
return Microbe;
case ProcessPath::AssemblyRelocatable_Object:
case ProcessPath::C_Object:
return Object;
case ProcessPath::AssemblyAbsolute_PIC:
case ProcessPath::AssemblyRelocatable_PIC:
case ProcessPath::C_PIC:
case ProcessPath::FlowCode_PIC:
case ProcessPath::Microbe_PIC:
case ProcessPath::Object_PIC:
case ProcessPath::Program_PIC:
return Pic;
case ProcessPath::AssemblyAbsolute_Program:
case ProcessPath::AssemblyRelocatable_Program:
case ProcessPath::C_Program:
case ProcessPath::FlowCode_Program:
case ProcessPath::Microbe_Program:
case ProcessPath::Object_Program:
return Program;
case ProcessPath::Invalid:
case ProcessPath::None:
return Unknown;
}
return Unknown;
}
//END class ProcessOptions
#include "language.moc"
|