~ubuntu-branches/ubuntu/karmic/piklab/karmic

« back to all changes in this revision

Viewing changes to src/libgui/object_view.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Miriam Ruiz
  • Date: 2007-09-01 22:37:44 UTC
  • Revision ID: james.westby@ubuntu.com-20070901223744-2r8t5kiqdurs5j8g
Tags: upstream-0.14.5
ImportĀ upstreamĀ versionĀ 0.14.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *   Copyright (C) 2006 Nicolas Hadacek <hadacek@kde.org>                  *
 
3
 *                                                                         *
 
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"
 
10
 
 
11
#include <klocale.h>
 
12
 
 
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"
 
22
 
 
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)
 
26
{
 
27
  setReadOnly(true);
 
28
  _view->setDynWordWrap(false);
 
29
  setView(&Main::compileLog());
 
30
}
 
31
 
 
32
Coff::BaseEditor::BaseEditor(const Device::Data &data, QWidget *parent)
 
33
  : SimpleTextEditor(true, parent), _device(data), _log(0)
 
34
{
 
35
  setReadOnly(true);
 
36
  _view->setDynWordWrap(false);
 
37
  setView(&Main::compileLog());
 
38
}
 
39
 
 
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)
 
43
{}
 
44
 
 
45
Coff::Editor::Editor(const TextObject &object, QWidget *parent)
 
46
  : BaseEditor(object.device(), parent), _created(0), _provided(&object)
 
47
{}
 
48
 
 
49
Coff::Editor::~Editor()
 
50
{
 
51
  delete _created;
 
52
}
 
53
 
 
54
bool Coff::Editor::open(const PURL::Url &url)
 
55
{
 
56
  _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());
 
60
}
 
61
 
 
62
//-----------------------------------------------------------------------------
 
63
DisassemblyEditor::DisassemblyEditor(const PURL::Url &source, const Device::Data &data, QWidget *parent)
 
64
  : Coff::BaseEditor(source, data, 0, parent), _editor(0)
 
65
{}
 
66
 
 
67
DisassemblyEditor::DisassemblyEditor(const HexEditor &e, const Device::Data &data, QWidget *parent)
 
68
  : Coff::BaseEditor(data, parent), _editor(&e)
 
69
{}
 
70
 
 
71
bool DisassemblyEditor::open(const PURL::Url &url)
 
72
{
 
73
  _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);
 
76
    return false;
 
77
  }
 
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);
 
81
    return false;
 
82
  }
 
83
 
 
84
  Device::Memory *memory = 0;
 
85
  if ( _editor==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) ) {
 
93
      delete memory;
 
94
      log(Log::Error, errors[0]);
 
95
      return false;
 
96
    }
 
97
    for (uint i=0; i<warnings.count(); i++) log(Log::Warning, warnings[i]);
 
98
  } else {
 
99
    log(Log::Information, i18n("Disassembling content of hex file editor."));
 
100
    memory = const_cast<Device::Memory *>(_editor->memory());
 
101
  }
 
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));
 
105
}