RubyRequest.cc revision 8092
113521Sgabeblack@google.com#include <iostream>
213521Sgabeblack@google.com
313521Sgabeblack@google.com#include "mem/ruby/slicc_interface/RubyRequest.hh"
413521Sgabeblack@google.com
513521Sgabeblack@google.comusing namespace std;
613521Sgabeblack@google.com
713521Sgabeblack@google.comstring
813521Sgabeblack@google.comRubyRequestType_to_string(const RubyRequestType& obj)
913521Sgabeblack@google.com{
1013521Sgabeblack@google.com    switch(obj) {
1113521Sgabeblack@google.com      case RubyRequestType_IFETCH:
1213521Sgabeblack@google.com        return "IFETCH";
1313521Sgabeblack@google.com      case RubyRequestType_LD:
1413521Sgabeblack@google.com        return "LD";
1513521Sgabeblack@google.com      case RubyRequestType_ST:
1613521Sgabeblack@google.com        return "ST";
1713521Sgabeblack@google.com      case RubyRequestType_Load_Linked:
1813521Sgabeblack@google.com        return "Load_Linked";
1913521Sgabeblack@google.com      case RubyRequestType_Store_Conditional:
2013521Sgabeblack@google.com        return "Store_Conditional";
2113521Sgabeblack@google.com      case RubyRequestType_RMW_Read:
2213521Sgabeblack@google.com        return "RMW_Read";
2313521Sgabeblack@google.com      case RubyRequestType_RMW_Write:
2413521Sgabeblack@google.com        return "RMW_Write";
2513521Sgabeblack@google.com      case RubyRequestType_Locked_RMW_Read:
2613521Sgabeblack@google.com        return "Locked_RMW_Read";
2713521Sgabeblack@google.com      case RubyRequestType_Locked_RMW_Write:
2813521Sgabeblack@google.com        return "Locked_RMW_Write";
2913521Sgabeblack@google.com      case RubyRequestType_NULL:
3013521Sgabeblack@google.com      default:
3113521Sgabeblack@google.com        assert(0);
3213521Sgabeblack@google.com        return "";
3313521Sgabeblack@google.com    }
3413521Sgabeblack@google.com}
3513521Sgabeblack@google.com
3613521Sgabeblack@google.comRubyRequestType
3713521Sgabeblack@google.comstring_to_RubyRequestType(string str)
3813521Sgabeblack@google.com{
3913521Sgabeblack@google.com    if (str == "IFETCH")
4013521Sgabeblack@google.com        return RubyRequestType_IFETCH;
4113521Sgabeblack@google.com    else if (str == "LD")
4213521Sgabeblack@google.com        return RubyRequestType_LD;
4313521Sgabeblack@google.com    else if (str == "ST")
4413521Sgabeblack@google.com        return RubyRequestType_ST;
4513521Sgabeblack@google.com    else if (str == "Locked_Read")
4613521Sgabeblack@google.com        return RubyRequestType_Load_Linked;
4713521Sgabeblack@google.com    else if (str == "Locked_Write")
4813521Sgabeblack@google.com        return RubyRequestType_Store_Conditional;
4913521Sgabeblack@google.com    else if (str == "RMW_Read")
5013521Sgabeblack@google.com        return RubyRequestType_RMW_Read;
5113521Sgabeblack@google.com    else if (str == "RMW_Write")
5213521Sgabeblack@google.com        return RubyRequestType_RMW_Write;
5313521Sgabeblack@google.com    else if (str == "Locked_RMW_Read")
5413521Sgabeblack@google.com        return RubyRequestType_Locked_RMW_Read;
5513521Sgabeblack@google.com    else if (str == "Locked_RMW_Write")
5613521Sgabeblack@google.com        return RubyRequestType_Locked_RMW_Write;
5713521Sgabeblack@google.com    else
5813521Sgabeblack@google.com        assert(0);
5913521Sgabeblack@google.com    return RubyRequestType_NULL;
6013521Sgabeblack@google.com}
6113521Sgabeblack@google.com
6213521Sgabeblack@google.comostream&
6313521Sgabeblack@google.comoperator<<(ostream& out, const RubyRequestType& obj)
6413521Sgabeblack@google.com{
6513521Sgabeblack@google.com    out << RubyRequestType_to_string(obj);
6613521Sgabeblack@google.com    out << flush;
6713521Sgabeblack@google.com    return out;
6813521Sgabeblack@google.com}
6913521Sgabeblack@google.com
7013521Sgabeblack@google.comostream&
71operator<<(ostream& out, const RubyRequest& obj)
72{
73    out << hex << "0x" << obj.paddr << " data: 0x" << flush;
74    for (int i = 0; i < obj.len; i++) {
75        out << (int)obj.data[i];
76    }
77    out << dec << " type: " << RubyRequestType_to_string(obj.type) << endl;
78    return out;
79}
80
81vector<string>
82tokenizeString(string str, string delims)
83{
84    vector<string> tokens;
85    char* pch;
86    char* tmp;
87    const char* c_delims = delims.c_str();
88    tmp = new char[str.length()+1];
89    strcpy(tmp, str.c_str());
90    pch = strtok(tmp, c_delims);
91    while (pch != NULL) {
92        string tmp_str(pch);
93        if (tmp_str == "null") tmp_str = "";
94        tokens.push_back(tmp_str);
95
96        pch = strtok(NULL, c_delims);
97    }
98    delete [] tmp;
99    return tokens;
100}
101