gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
arguments.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2003-2005 The Regents of The University of Michigan
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met: redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer;
9  * redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution;
12  * neither the name of the copyright holders nor the names of its
13  * contributors may be used to endorse or promote products derived from
14  * this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  *
28  * Authors: Nathan Binkert
29  */
30 
31 #ifndef __SIM_ARGUMENTS_HH__
32 #define __SIM_ARGUMENTS_HH__
33 
34 #include <cassert>
35 #include <memory>
36 
38 
39 class ThreadContext;
40 
41 class Arguments
42 {
43  protected:
45  int number;
46  uint64_t getArg(uint16_t size = (uint16_t)(-1), bool fp = false);
47 
48  protected:
49  class Data
50  {
51  public:
52  Data(){}
53  ~Data();
54 
55  private:
57 
58  public:
59  char *alloc(size_t size);
60  };
61 
62  std::shared_ptr<Data> data;
63 
64  public:
65  Arguments(ThreadContext *ctx, int n = 0)
66  : tc(ctx), number(n), data(new Data())
67  { assert(number >= 0); }
68  Arguments(const Arguments &args)
69  : tc(args.tc), number(args.number), data(args.data) {}
71 
72  ThreadContext *getThreadContext() const { return tc; }
73 
74  const Arguments &operator=(const Arguments &args) {
75  if (this != &args) {
76  tc = args.tc;
77  number = args.number;
78  data = args.data;
79  }
80  return *this;
81  }
82 
83  // for checking if an argument is NULL
84  bool operator!() {
85  return getArg() == 0;
86  }
87 
89  ++number;
90  assert(number >= 0);
91  return *this;
92  }
93 
95  Arguments args = *this;
96  ++number;
97  assert(number >= 0);
98  return args;
99  }
100 
102  --number;
103  assert(number >= 0);
104  return *this;
105  }
106 
108  Arguments args = *this;
109  --number;
110  assert(number >= 0);
111  return args;
112  }
113 
114  const Arguments &operator+=(int index) {
115  number += index;
116  assert(number >= 0);
117  return *this;
118  }
119 
120  const Arguments &operator-=(int index) {
121  number -= index;
122  assert(number >= 0);
123  return *this;
124  }
125 
127  return Arguments(tc, index);
128  }
129 
130  template <class T>
131  operator T() {
132  assert(sizeof(T) <= sizeof(uint64_t));
133  T d = static_cast<T>(getArg(sizeof(T)));
134  return d;
135  }
136 
137  template <class T>
138  operator T *() {
139  T *buf = (T *)data->alloc(sizeof(T));
140  CopyOut(tc, buf, getArg(sizeof(T)), sizeof(T));
141  return buf;
142  }
143 
144  operator char *() {
145  char *buf = data->alloc(2048);
146  CopyStringOut(tc, buf, getArg(), 2048);
147  return buf;
148  }
149 };
150 
151 #endif // __SIM_ARGUMENTS_HH__
Bitfield< 30, 0 > index
Arguments operator[](int index)
Definition: arguments.hh:126
Bitfield< 0 > fp
int number
Definition: arguments.hh:45
~Arguments()
Definition: arguments.hh:70
void CopyOut(ThreadContext *tc, void *dest, Addr src, size_t cplen)
ThreadContext is the external interface to all thread state for anything outside of the CPU...
Bitfield< 31 > n
Definition: miscregs.hh:1636
Arguments operator++(int)
Definition: arguments.hh:94
Arguments(const Arguments &args)
Definition: arguments.hh:68
ThreadContext * getThreadContext() const
Definition: arguments.hh:72
char * alloc(size_t size)
Definition: arguments.cc:45
Arguments(ThreadContext *ctx, int n=0)
Definition: arguments.hh:65
void CopyStringOut(ThreadContext *tc, char *dst, Addr vaddr, size_t maxlen)
Bitfield< 9 > d
Definition: miscregs.hh:1375
Arguments operator--(int)
Definition: arguments.hh:107
std::shared_ptr< Data > data
Definition: arguments.hh:62
const Arguments & operator-=(int index)
Definition: arguments.hh:120
int size()
Definition: pagetable.hh:146
Arguments & operator--()
Definition: arguments.hh:101
std::list< char * > data
Definition: arguments.hh:56
TranslatingPortProxy Object Declaration for FS.
const Arguments & operator=(const Arguments &args)
Definition: arguments.hh:74
bool operator!()
Definition: arguments.hh:84
const Arguments & operator+=(int index)
Definition: arguments.hh:114
ThreadContext * tc
Definition: arguments.hh:44
uint64_t getArg(uint16_t size=(uint16_t)(-1), bool fp=false)
Definition: arguments.cc:53
Arguments & operator++()
Definition: arguments.hh:88

Generated on Fri Jun 9 2017 13:03:51 for gem5 by doxygen 1.8.6