16145SN/A/*
26145SN/A * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
36145SN/A * All rights reserved.
46145SN/A *
56145SN/A * Redistribution and use in source and binary forms, with or without
66145SN/A * modification, are permitted provided that the following conditions are
76145SN/A * met: redistributions of source code must retain the above copyright
86145SN/A * notice, this list of conditions and the following disclaimer;
96145SN/A * redistributions in binary form must reproduce the above copyright
106145SN/A * notice, this list of conditions and the following disclaimer in the
116145SN/A * documentation and/or other materials provided with the distribution;
126145SN/A * neither the name of the copyright holders nor the names of its
136145SN/A * contributors may be used to endorse or promote products derived from
146145SN/A * this software without specific prior written permission.
156145SN/A *
166145SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
176145SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
186145SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
196145SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
206145SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
216145SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
226145SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
236145SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
246145SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
256145SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
266145SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
276145SN/A */
286145SN/A
2912492Sodanrc@yahoo.com.br#ifndef __MEM_RUBY_COMMON_MACHINEID_HH__
3012492Sodanrc@yahoo.com.br#define __MEM_RUBY_COMMON_MACHINEID_HH__
316145SN/A
327002SN/A#include <iostream>
337002SN/A#include <string>
347002SN/A
357056SN/A#include "base/cprintf.hh"
3614184Sgabeblack@google.com#include "mem/ruby/protocol/MachineType.hh"
376145SN/A
387039SN/Astruct MachineID
397039SN/A{
4011712Santhony.gutierrez@amd.com    MachineID() : type(MachineType_NULL), num(0) { }
4111712Santhony.gutierrez@amd.com    MachineID(MachineType mach_type, NodeID node_id)
4211712Santhony.gutierrez@amd.com        : type(mach_type), num(node_id) { }
4311712Santhony.gutierrez@amd.com
447039SN/A    MachineType type;
459496SN/A    //! range: 0 ... number of this machine's components in system - 1
469511SN/A    NodeID num;
479496SN/A
489496SN/A    MachineType getType() const { return type; }
499511SN/A    NodeID getNum() const { return num; }
506145SN/A};
516145SN/A
527039SN/Ainline std::string
537039SN/AMachineIDToString(MachineID machine)
547039SN/A{
557056SN/A    return csprintf("%s_%d", MachineType_to_string(machine.type), machine.num);
566145SN/A}
576145SN/A
587039SN/Ainline bool
597039SN/Aoperator==(const MachineID & obj1, const MachineID & obj2)
606145SN/A{
617039SN/A    return (obj1.type == obj2.type && obj1.num == obj2.num);
626145SN/A}
636145SN/A
647039SN/Ainline bool
657039SN/Aoperator!=(const MachineID & obj1, const MachineID & obj2)
666145SN/A{
677039SN/A    return (obj1.type != obj2.type || obj1.num != obj2.num);
686145SN/A}
696145SN/A
706145SN/A// Output operator declaration
717002SN/Astd::ostream& operator<<(std::ostream& out, const MachineID& obj);
726145SN/A
737039SN/Ainline std::ostream&
747039SN/Aoperator<<(std::ostream& out, const MachineID& obj)
756145SN/A{
767039SN/A    if ((obj.type < MachineType_NUM) && (obj.type >= MachineType_FIRST)) {
777039SN/A        out << MachineType_to_string(obj.type);
787039SN/A    } else {
797039SN/A        out << "NULL";
807039SN/A    }
817039SN/A    out << "-";
827039SN/A    out << obj.num;
837039SN/A    out << std::flush;
847039SN/A    return out;
856145SN/A}
866145SN/A
8712492Sodanrc@yahoo.com.br#endif // __MEM_RUBY_COMMON_MACHINEID_HH__
88