1
/***************************************************************************
2
* Copyright (C) 2006 Nicolas Hadacek <hadacek@kde.org> *
4
* This program is free software; you can redistribute it and/or modify *
5
* it under the terms of the GNU General Public License as published by *
6
* the Free Software Foundation; either version 2 of the License, or *
7
* (at your option) any later version. *
8
***************************************************************************/
9
#include "object_view.h"
13
#include "devices/base/device_group.h"
14
#include "devices/pic/pic/pic_memory.h"
15
#include "tools/gputils/gputils.h"
16
#include "hex_editor.h"
17
#include "coff/base/text_coff.h"
18
#include "main_global.h"
19
#include "tools/list/compile.h"
20
#include "coff/base/disassembler.h"
21
#include "common/gui/misc_gui.h"
23
//-----------------------------------------------------------------------------
24
Coff::BaseEditor::BaseEditor(const PURL::Url &source, const Device::Data &data, Log::Base *log, QWidget *parent)
25
: SimpleTextEditor(true, parent), _source(source), _device(data), _log(log)
28
_view->setDynWordWrap(false);
29
setView(&Main::compileLog());
32
Coff::BaseEditor::BaseEditor(const Device::Data &data, QWidget *parent)
33
: SimpleTextEditor(true, parent), _device(data), _log(0)
36
_view->setDynWordWrap(false);
37
setView(&Main::compileLog());
40
//-----------------------------------------------------------------------------
41
Coff::Editor::Editor(const PURL::Url &source, const Device::Data &data, Log::Base &log, QWidget *parent)
42
: BaseEditor(source, data, &log, parent), _created(0), _provided(0)
45
Coff::Editor::Editor(const TextObject &object, QWidget *parent)
46
: BaseEditor(object.device(), parent), _created(0), _provided(&object)
49
Coff::Editor::~Editor()
54
bool Coff::Editor::open(const PURL::Url &url)
57
if (_provided) return setText(_provided->text());
58
if ( _created==0 ) _created = new TextObject(_device, _source, *_log, 0);
59
return setText(_created->text());
62
//-----------------------------------------------------------------------------
63
DisassemblyEditor::DisassemblyEditor(const PURL::Url &source, const Device::Data &data, QWidget *parent)
64
: Coff::BaseEditor(source, data, 0, parent), _editor(0)
67
DisassemblyEditor::DisassemblyEditor(const HexEditor &e, const Device::Data &data, QWidget *parent)
68
: Coff::BaseEditor(data, parent), _editor(&e)
71
bool DisassemblyEditor::open(const PURL::Url &url)
74
if ( Main::toolGroup().name()!="sdcc" && Main::toolGroup().name()!="gputils" ) {
75
MessageBox::sorry(i18n("Disassembly not supported for the selected toolchain."), Log::Show);
78
Pic::Architecture arch = (_device.group().name()=="pic" ? static_cast<const Pic::Data &>(_device).architecture() : Pic::Nb_Architectures);
79
if ( arch==Pic::Nb_Architectures ) {
80
MessageBox::sorry(i18n("Disassembly not supported for the selected device."), Log::Show);
84
Device::Memory *memory = 0;
86
log(Log::Information, i18n("Disassembling hex file: %1").arg(_source.pretty()));
87
PURL::File file(_source, &Main::compileLog());
88
if ( !file.openForRead() ) return false;
89
memory = _device.group().createMemory(_device);
90
QStringList errors, warnings;
91
Device::Memory::WarningTypes warningTypes;
92
if ( !memory->load(file.stream(), errors, warningTypes, warnings) ) {
94
log(Log::Error, errors[0]);
97
for (uint i=0; i<warnings.count(); i++) log(Log::Warning, warnings[i]);
99
log(Log::Information, i18n("Disassembling content of hex file editor."));
100
memory = const_cast<Device::Memory *>(_editor->memory());
102
SourceLine::List list = GPUtils::disassemble(static_cast<const Pic::Memory &>(*memory));
103
if ( _editor==0 ) delete memory;
104
return setText(SourceLine::text(PURL::Asm, list, 4));