Nemiver  0.3
nmv-asm-utils.h
Go to the documentation of this file.
1 // Author: Dodji Seketeli
2 /*
3  *This file is part of the Nemiver project
4  *
5  *Nemiver is free software; you can redistribute
6  *it and/or modify it under the terms of
7  *the GNU General Public License as published by the
8  *Free Software Foundation; either version 2,
9  *or (at your option) any later version.
10  *
11  *Nemiver is distributed in the hope that it will
12  *be useful, but WITHOUT ANY WARRANTY;
13  *without even the implied warranty of
14  *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15  *See the GNU General Public License for more details.
16  *
17  *You should have received a copy of the
18  *GNU General Public License along with Nemiver;
19  *see the file COPYING.
20  *If not, write to the Free Software Foundation,
21  *Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22  *
23  *See COPYRIGHT file copyright information.
24  */
25 #ifndef __NMV_ASM_UTILS_H__
26 #define __NMV_ASM_UTILS_H__
27 
28 #include "nmv-asm-instr.h"
29 
30 namespace Gtk {
31  class Window;
32 }
33 
35 
36 NEMIVER_BEGIN_NAMESPACE (nemiver)
37 NEMIVER_BEGIN_NAMESPACE (common)
38 
39 template<class Stream>
40 Stream&
41 operator<< (Stream &a_out, const AsmInstr &a_instr)
42 {
43  a_out << "<asm-instr>\n"
44  << " <addr>" << a_instr.address () << "</addr>\n"
45  << " <function-name>" << a_instr.function () << "</function-name>\n"
46  << " <offset>" << a_instr.offset () << "</offset>\n"
47  << " <instr>" << a_instr.instruction () << "</instr>\n"
48  << "</asm-instr>\n";
49  return a_out;
50 }
51 
52 template<class Stream>
53 Stream&
54 operator<< (Stream &a_out, const MixedAsmInstr &a_instr)
55 {
56  a_out << "<asm-mixed-instr>\n"
57  << " <line>" << a_instr.line_number () << "</line>\n"
58  << " <path>" << a_instr.file_path () << "</path>\n";
59 
60  list<AsmInstr>::const_iterator it;
61  a_out << " <asm-instr-list>";
62  for (it = a_instr.instrs ().begin ();
63  it != a_instr.instrs ().end ();
64  ++it) {
65  a_out << " <asm-instr>\n"
66  << " <addr>" << it->address () << "</addr>\n"
67  << " <function-name>" << it->function ()
68  << "</function-name>\n"
69  << " <offset>" << it->offset () << "</offset>\n"
70  << " <instr>" << it->instruction () << "</instr>\n"
71  << " </asm-instr>\n";
72  }
73  a_out << " </asm-instr-list>"
74  << "</asm-mixed-instr>\n";
75 
76  return a_out;
77 }
78 
79 template<class Stream>
80 Stream&
81 operator<< (Stream &a_out, const Asm &a_asm)
82 {
83  switch (a_asm.which ()) {
84  case Asm::TYPE_PURE:
85  a_out << a_asm.instr ();
86  break;
87  case Asm::TYPE_MIXED:
88  a_out << a_asm.mixed_instr ();
89  break;
90  default:
91  THROW ("reached unreachable");
92  }
93  return a_out;
94 }
95 
96 void log_asm_insns (const std::list<common::Asm> &a_asm);
97 
99 typedef bool (* FindFileAndReadLine) (Gtk::Window &a_parent_window,
100  const UString &a_file_path,
101  const std::list<UString> &a_where_to_look,
102  list<UString> &a_sess_dirs,
103  map<UString, bool> &a_ignore_paths,
104  int a_line_number,
105  std::string &a_line);
106 
114 class ReadLine
115 {
116  private:
117  ReadLine ();
118  ReadLine (const ReadLine &);
119 
120  protected:
121  Gtk::Window &m_parent;
122  const std::list<UString> &m_where_to_look;
123  list<UString> &m_session_dirs;
124  map<UString, bool> &m_ignore_paths;
126 
127  public:
128 
146  ReadLine (Gtk::Window& a_parent,
147  const std::list<UString> &where_to_look,
148  list<UString> &session_dirs,
149  map<UString, bool> &ignore_paths,
150  FindFileAndReadLine read_line_func) :
151  m_parent(a_parent),
152  m_where_to_look (where_to_look),
153  m_session_dirs (session_dirs),
154  m_ignore_paths (ignore_paths),
155  read_line (read_line_func)
156  {
157  }
158 
169  bool operator () (const UString &a_file_path,
170  int a_line_number,
171  std::string &a_line)
172  {
173  return read_line (m_parent, a_file_path,
174  m_where_to_look, m_session_dirs,
175  m_ignore_paths, a_line_number,
176  a_line);
177  }
178 };
179 
180 bool write_asm_instr (const common::Asm &a_asm,
181  ReadLine &a_read,
182  std::ostringstream &a_os);
183 
184 NEMIVER_END_NAMESPACE (common)
185 NEMIVER_END_NAMESPACE (nemiver)
186 
187 #endif // __NMV_ASM_UTILS_H__
nemiver::common::AsmInstr::offset
const string & offset() const
Definition: nmv-asm-instr.h:74
nemiver
Definition: nmv-address.h:31
nmv-asm-instr.h
THROW
#define THROW(a_reason)
Definition: nmv-exception.h:99
nemiver::common::MixedAsmInstr::file_path
const UString & file_path() const
Definition: nmv-asm-instr.h:110
nemiver::common::ReadLine::m_session_dirs
list< UString > & m_session_dirs
Definition: nmv-asm-utils.h:123
nemiver::common::Asm
Definition: nmv-asm-instr.h:127
nemiver::common::Asm::which
Type which() const
Definition: nmv-asm-instr.h:146
nemiver::common::ReadLine::m_parent
Gtk::Window & m_parent
Definition: nmv-asm-utils.h:121
nemiver::common::UString
Definition: nmv-ustring.h:45
nemiver::common::AsmInstr::function
const string & function() const
Definition: nmv-asm-instr.h:71
nemiver::common::Asm::mixed_instr
const MixedAsmInstr & mixed_instr() const
Definition: nmv-asm-instr.h:194
nemiver::common::MixedAsmInstr::instrs
const list< AsmInstr > & instrs() const
Definition: nmv-asm-instr.h:116
nemiver::common::MixedAsmInstr::line_number
int line_number() const
Definition: nmv-asm-instr.h:113
nemiver::common::log_asm_insns
void log_asm_insns(const std::list< common::Asm > &a_asm)
nemiver::common::ReadLine::m_ignore_paths
map< UString, bool > & m_ignore_paths
Definition: nmv-asm-utils.h:124
nemiver::common::AsmInstr::address
const string & address() const
Definition: nmv-asm-instr.h:68
nemiver::common::write_asm_instr
bool write_asm_instr(const common::Asm &a_asm, ReadLine &a_read, std::ostringstream &a_os)
nemiver::common::ReadLine::ReadLine
ReadLine(Gtk::Window &a_parent, const std::list< UString > &where_to_look, list< UString > &session_dirs, map< UString, bool > &ignore_paths, FindFileAndReadLine read_line_func)
Definition: nmv-asm-utils.h:146
nemiver::common::FindFileAndReadLine
bool(* FindFileAndReadLine)(Gtk::Window &a_parent_window, const UString &a_file_path, const std::list< UString > &a_where_to_look, list< UString > &a_sess_dirs, map< UString, bool > &a_ignore_paths, int a_line_number, std::string &a_line)
A pointer to ui_utils::find_file_and_read_line() function.
Definition: nmv-asm-utils.h:99
nemiver::common::AsmInstr
Definition: nmv-asm-instr.h:42
Gtk
Definition: nmv-asm-utils.h:30
nemiver::common::ReadLine
Definition: nmv-asm-utils.h:114
nemiver::common::operator<<
Stream & operator<<(Stream &a_out, const Asm &a_asm)
Definition: nmv-asm-utils.h:81
nemiver::common::ReadLine::read_line
FindFileAndReadLine read_line
Definition: nmv-asm-utils.h:125
nemiver::common::AsmInstr::instruction
const string & instruction() const
Definition: nmv-asm-instr.h:77
nemiver::common::Asm::instr
const AsmInstr & instr() const
Definition: nmv-asm-instr.h:170
nemiver::common::ReadLine::m_where_to_look
const std::list< UString > & m_where_to_look
Definition: nmv-asm-utils.h:122
common
Definition: nmv-proc-list-dialog.h:32
nemiver::common::MixedAsmInstr
Definition: nmv-asm-instr.h:81