• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * @file abi.cpp
3  *
4  * @remark Copyright 2002 OProfile authors
5  * @remark Read the file COPYING
6  *
7  * @author Graydon Hoare
8  * @author John Levon
9  * @author Philippe Elie
10  */
11 
12 #include "abi.h"
13 #include "op_abi.h"
14 #include "odb.h"
15 #include "op_sample_file.h"
16 
17 #include <iostream>
18 #include <cassert>
19 
20 using namespace std;
21 
22 typedef map<string, int> abi_map;
23 typedef abi_map::const_iterator abi_iter;
24 
abi_exception(string const d)25 abi_exception::abi_exception(string const d) : desc(d) {}
26 
27 
abi()28 abi::abi()
29 {
30 	op_abi_entry const * entry = get_abi();
31 	for ( ; entry->name != 0; ++entry)
32 		slots[entry->name] = entry->offset;
33 
34 	slots["little_endian"] = op_little_endian();
35 }
36 
37 
need(string const key) const38 int abi::need(string const key) const throw (abi_exception)
39 {
40 	if (slots.find(key) != slots.end())
41 		return slots.find(key)->second;
42 	else
43 		throw abi_exception(string("missing ABI key: ") + key);
44 }
45 
46 
operator ==(abi const & other) const47 bool abi::operator==(abi const & other) const
48 {
49 	return slots == other.slots;
50 }
51 
52 
operator <<(ostream & o,abi const & abi)53 ostream & operator<<(ostream & o, abi const & abi)
54 {
55 	abi_iter i = abi.slots.begin();
56 	abi_iter e = abi.slots.end();
57 
58 	for (; i != e; ++i)
59 		o << i->first << " " << i->second << endl;
60 
61 	return o;
62 }
63 
64 
operator >>(istream & i,abi & abi)65 istream & operator>>(istream & i, abi & abi)
66 {
67 	string key;
68 	int val;
69 	abi.slots.clear();
70 
71 	while(i >> key >> val)
72 		abi.slots[key] = val;
73 
74 	return i;
75 }
76