config:
[gem5.git] / test / paramtest.cc
1 /*
2 * Copyright (c) 2002-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
29 //
30 // This file is not part of the regular simulator. It is solely for
31 // testing the parameter code. Edit the Makefile to add param_test.cc
32 // to the sources list, then use configs/test.ini as the configuration
33 // file.
34 //
35 #include "sim/sim_object.hh"
36 #include "mem/cache/cache.hh"
37
38 class ParamTest : public SimObject
39 {
40 public:
41 ParamTest(string name)
42 : SimObject(name)
43 {
44 }
45
46 virtual ~ParamTest() {}
47 };
48
49 enum Enum1Type { Enum0 };
50 enum Enum2Type { Enum10 };
51
52 BEGIN_DECLARE_SIM_OBJECT_PARAMS(ParamTest)
53
54 Param<int> intparam;
55 VectorParam<int> vecint;
56 Param<string> stringparam;
57 VectorParam<string> vecstring;
58 Param<bool> boolparam;
59 VectorParam<bool> vecbool;
60 SimObjectParam<BaseMemory *> memobj;
61 SimObjectVectorParam<BaseMemory *> vecmemobj;
62 SimpleEnumParam<Enum1Type> enum1;
63 MappedEnumParam<Enum2Type> enum2;
64 SimpleEnumVectorParam<Enum1Type> vecenum1;
65 MappedEnumVectorParam<Enum2Type> vecenum2;
66
67 END_DECLARE_SIM_OBJECT_PARAMS(ParamTest)
68
69 const char *enum1_strings[] =
70 {
71 "zero", "one", "two", "three"
72 };
73
74 const EnumParamMap enum2_map[] =
75 {
76 { "ten", 10 },
77 { "twenty", 20 },
78 { "thirty", 30 },
79 { "forty", 40 }
80 };
81
82 BEGIN_INIT_SIM_OBJECT_PARAMS(ParamTest)
83
84 INIT_PARAM(intparam, "intparam"),
85 INIT_PARAM(vecint, "vecint"),
86 INIT_PARAM(stringparam, "stringparam"),
87 INIT_PARAM(vecstring, "vecstring"),
88 INIT_PARAM(boolparam, "boolparam"),
89 INIT_PARAM(vecbool, "vecbool"),
90 INIT_PARAM(memobj, "memobj"),
91 INIT_PARAM(vecmemobj, "vecmemobj"),
92 INIT_ENUM_PARAM(enum1, "enum1", enum1_strings),
93 INIT_ENUM_PARAM(enum2, "enum2", enum2_map),
94 INIT_ENUM_PARAM(vecenum1, "vecenum1", enum1_strings),
95 INIT_ENUM_PARAM(vecenum2, "vecenum2", enum2_map)
96
97 END_INIT_SIM_OBJECT_PARAMS(ParamTest)
98
99
100 CREATE_SIM_OBJECT(ParamTest)
101 {
102 return new ParamTest(getInstanceName());
103 }
104
105 REGISTER_SIM_OBJECT("ParamTest", ParamTest)