]> git.cworth.org Git - apitrace/blob - trace_model.hpp
First stab at binary trace and retracing.
[apitrace] / trace_model.hpp
1 /**************************************************************************
2  *
3  * Copyright 2010 VMware, Inc.
4  * All Rights Reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22  * THE SOFTWARE.
23  *
24  **************************************************************************/
25
26 #ifndef _TRACE_MODEL_HPP_
27 #define _TRACE_MODEL_HPP_
28
29
30 #include <cassert>
31
32 #include <string>
33 #include <map>
34 #include <list>
35 #include <vector>
36 #include <iostream>
37
38
39 namespace Trace {
40
41
42 class Visitor;
43 class Dumper;
44 class UInt;
45
46
47 class Value
48 {
49 public:
50    virtual void visit(Visitor &visitor) = 0;
51 };
52
53
54 class Void : public Value
55 {
56 public:
57    void visit(Visitor &visitor);
58 };
59
60
61 class Bool : public Value
62 {
63 public:
64    Bool(bool _value) : value(_value) {}
65
66    void visit(Visitor &visitor);
67
68    bool value;
69 };
70
71
72 class SInt : public Value
73 {
74 public:
75    SInt(signed long long _value) : value(_value) {}
76
77    void visit(Visitor &visitor);
78
79    signed long long value;
80 };
81
82
83 class UInt : public Value
84 {
85 public:
86    UInt(unsigned long long _value) : value(_value) {}
87
88    void visit(Visitor &visitor);
89
90    unsigned long long value;
91 };
92
93
94 class Float : public Value
95 {
96 public:
97    Float(double _value) : value(_value) {}
98
99    void visit(Visitor &visitor);
100
101    double value;
102 };
103
104
105 class String : public Value
106 {
107 public:
108    String(std::string _value) : value(_value) {}
109
110    void visit(Visitor &visitor);
111
112    std::string value;
113 };
114
115
116 class Const : public Value
117 {
118 public:
119    Const(std::string _name, Value *_value) : name(_name), value(_value) {}
120
121    void visit(Visitor &visitor);
122
123    std::string name;
124    Value *value;
125 };
126
127
128 class Array : public Value
129 {
130 public:
131    Array(size_t len) : values(len) {}
132
133    void visit(Visitor &visitor);
134
135    std::vector<Value *> values;
136 };
137
138
139 class Visitor
140 {
141 public:
142    virtual void visit(Void *) {assert(0);}
143    virtual void visit(Bool *) {assert(0);}
144    virtual void visit(SInt *) {assert(0);}
145    virtual void visit(UInt *) {assert(0);}
146    virtual void visit(Float *) {assert(0);}
147    virtual void visit(String *) {assert(0);}
148    virtual void visit(Const *) {assert(0);}
149    virtual void visit(Array *) {assert(0);}
150 };
151
152
153 std::ostream & operator <<(std::ostream &os, Value *value);
154
155
156 signed long long asSInt(const Value *node);
157 unsigned long long asUInt(const Value *node);
158 double asFloat(const Value *node);
159
160
161 typedef std::pair<std::string, Value *> Arg;
162
163 class Call
164 {
165 public:
166    std::string name;
167    std::list<Arg> args;
168    Value *ret;
169
170    Call() : ret(0) { }
171
172    Value * get_arg(const char *name) {
173       for (std::list<Arg>::iterator it = args.begin(); it != args.end(); ++it) {
174          if (it->first == name) {
175             return it->second;
176          }
177       }
178       return NULL;
179    }
180 };
181
182
183
184 std::ostream & operator <<(std::ostream &os, Call &call);
185
186
187 } /* namespace Trace */
188
189 #endif /* _TRACE_MODEL_HPP_ */