debug.hh revision 8269
15882Snate@binkert.org/*
25882Snate@binkert.org * Copyright (c) 2003-2005 The Regents of The University of Michigan
38232Snate@binkert.org * Copyright (c) 2010 The Hewlett-Packard Development Company
45882Snate@binkert.org * All rights reserved.
55882Snate@binkert.org *
65882Snate@binkert.org * Redistribution and use in source and binary forms, with or without
75882Snate@binkert.org * modification, are permitted provided that the following conditions are
85882Snate@binkert.org * met: redistributions of source code must retain the above copyright
95882Snate@binkert.org * notice, this list of conditions and the following disclaimer;
105882Snate@binkert.org * redistributions in binary form must reproduce the above copyright
115882Snate@binkert.org * notice, this list of conditions and the following disclaimer in the
125882Snate@binkert.org * documentation and/or other materials provided with the distribution;
135882Snate@binkert.org * neither the name of the copyright holders nor the names of its
145882Snate@binkert.org * contributors may be used to endorse or promote products derived from
155882Snate@binkert.org * this software without specific prior written permission.
165882Snate@binkert.org *
175882Snate@binkert.org * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
185882Snate@binkert.org * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
195882Snate@binkert.org * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
205882Snate@binkert.org * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
215882Snate@binkert.org * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
225882Snate@binkert.org * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
235882Snate@binkert.org * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
245882Snate@binkert.org * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
255882Snate@binkert.org * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
265882Snate@binkert.org * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
275882Snate@binkert.org * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
285882Snate@binkert.org *
295882Snate@binkert.org * Authors: Nathan Binkert
305882Snate@binkert.org */
315882Snate@binkert.org
325882Snate@binkert.org#ifndef __BASE_DEBUG_HH__
335882Snate@binkert.org#define __BASE_DEBUG_HH__
345882Snate@binkert.org
358232Snate@binkert.org#include <string>
368232Snate@binkert.org#include <vector>
378232Snate@binkert.org
388231Snate@binkert.orgnamespace Debug {
398231Snate@binkert.org
408231Snate@binkert.orgvoid breakpoint();
418231Snate@binkert.org
428232Snate@binkert.orgclass Flag
438232Snate@binkert.org{
448232Snate@binkert.org  protected:
458232Snate@binkert.org    const char *_name;
468232Snate@binkert.org    const char *_desc;
478269Snate@binkert.org    std::vector<Flag *> _kids;
488232Snate@binkert.org
498232Snate@binkert.org  public:
508232Snate@binkert.org    Flag(const char *name, const char *desc);
518232Snate@binkert.org    virtual ~Flag();
528232Snate@binkert.org
538232Snate@binkert.org    std::string name() const { return _name; }
548232Snate@binkert.org    std::string desc() const { return _desc; }
558269Snate@binkert.org    std::vector<Flag *> kids() { return _kids; }
568232Snate@binkert.org
578232Snate@binkert.org    virtual void enable() = 0;
588232Snate@binkert.org    virtual void disable() = 0;
598232Snate@binkert.org};
608232Snate@binkert.org
618232Snate@binkert.orgclass SimpleFlag : public Flag
628232Snate@binkert.org{
638232Snate@binkert.org  protected:
648232Snate@binkert.org    bool _status;
658232Snate@binkert.org
668232Snate@binkert.org  public:
678232Snate@binkert.org    SimpleFlag(const char *name, const char *desc)
688232Snate@binkert.org        : Flag(name, desc)
698232Snate@binkert.org    { }
708232Snate@binkert.org
718232Snate@binkert.org    bool status() const { return _status; }
728232Snate@binkert.org    operator bool() const { return _status; }
738232Snate@binkert.org    bool operator!() const { return !_status; }
748232Snate@binkert.org
758232Snate@binkert.org    void enable() { _status = true; }
768232Snate@binkert.org    void disable() { _status = false; }
778232Snate@binkert.org};
788232Snate@binkert.org
798232Snate@binkert.orgclass CompoundFlag : public SimpleFlag
808232Snate@binkert.org{
818232Snate@binkert.org  protected:
828269Snate@binkert.org    void
838269Snate@binkert.org    addFlag(Flag &f)
848269Snate@binkert.org    {
858269Snate@binkert.org        if (&f != NULL)
868269Snate@binkert.org            _kids.push_back(&f);
878269Snate@binkert.org    }
888232Snate@binkert.org
898232Snate@binkert.org  public:
908232Snate@binkert.org    CompoundFlag(const char *name, const char *desc,
918232Snate@binkert.org        Flag &f00 = *(Flag *)0, Flag &f01 = *(Flag *)0,
928232Snate@binkert.org        Flag &f02 = *(Flag *)0, Flag &f03 = *(Flag *)0,
938232Snate@binkert.org        Flag &f04 = *(Flag *)0, Flag &f05 = *(Flag *)0,
948232Snate@binkert.org        Flag &f06 = *(Flag *)0, Flag &f07 = *(Flag *)0,
958232Snate@binkert.org        Flag &f08 = *(Flag *)0, Flag &f09 = *(Flag *)0,
968232Snate@binkert.org        Flag &f10 = *(Flag *)0, Flag &f11 = *(Flag *)0,
978232Snate@binkert.org        Flag &f12 = *(Flag *)0, Flag &f13 = *(Flag *)0,
988232Snate@binkert.org        Flag &f14 = *(Flag *)0, Flag &f15 = *(Flag *)0,
998232Snate@binkert.org        Flag &f16 = *(Flag *)0, Flag &f17 = *(Flag *)0,
1008232Snate@binkert.org        Flag &f18 = *(Flag *)0, Flag &f19 = *(Flag *)0)
1018232Snate@binkert.org        : SimpleFlag(name, desc)
1028232Snate@binkert.org    {
1038232Snate@binkert.org        addFlag(f00); addFlag(f01); addFlag(f02); addFlag(f03); addFlag(f04);
1048232Snate@binkert.org        addFlag(f05); addFlag(f06); addFlag(f07); addFlag(f08); addFlag(f09);
1058232Snate@binkert.org        addFlag(f10); addFlag(f11); addFlag(f12); addFlag(f13); addFlag(f14);
1068232Snate@binkert.org        addFlag(f15); addFlag(f16); addFlag(f17); addFlag(f18); addFlag(f19);
1078232Snate@binkert.org    }
1088232Snate@binkert.org
1098232Snate@binkert.org    void enable();
1108232Snate@binkert.org    void disable();
1118232Snate@binkert.org};
1128232Snate@binkert.org
1138231Snate@binkert.org} // namespace Debug
1145882Snate@binkert.org
1155882Snate@binkert.org#endif // __BASE_DEBUG_HH__
116