Home | History | Annotate | Download | only in libabi
      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 
     25 abi_exception::abi_exception(string const d) : desc(d) {}
     26 
     27 
     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 
     38 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 
     47 bool abi::operator==(abi const & other) const
     48 {
     49 	return slots == other.slots;
     50 }
     51 
     52 
     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 
     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