]> git.cworth.org Git - apitrace/blob - common/trace_writer_model.cpp
Use skiplist-based FastCallSet within trace::CallSet
[apitrace] / common / trace_writer_model.cpp
1 /**************************************************************************
2  *
3  * Copyright 2011 Jose Fonseca
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
27 #include "trace_writer.hpp"
28
29
30 namespace trace {
31
32
33 class ModelWriter : public Visitor
34 {
35 protected:
36     Writer &writer;
37
38 public:
39     ModelWriter(Writer &_writer) :
40         writer(_writer) {
41     }
42
43     void visit(Null *) {
44         writer.writeNull();
45     }
46
47     void visit(Bool *node) {
48         writer.writeBool(node->value);
49     }
50
51     void visit(SInt *node) {
52         writer.writeSInt(node->value);
53     }
54
55     void visit(UInt *node) {
56         writer.writeUInt(node->value);
57     }
58
59     void visit(Float *node) {
60         writer.writeFloat(node->value);
61     }
62
63     void visit(Double *node) {
64         writer.writeDouble(node->value);
65     }
66
67     void visit(String *node) {
68         writer.writeString(node->value);
69     }
70
71     void visit(Enum *node) {
72         writer.writeEnum(node->sig, node->value);
73     }
74
75     void visit(Bitmask *node) {
76         writer.writeBitmask(node->sig, node->value);
77     }
78
79     void visit(Struct *node) {
80         writer.beginStruct(node->sig);
81         for (unsigned i = 0; i < node->sig->num_members; ++i) {
82             _visit(node->members[i]);
83         }
84         writer.endStruct();
85     }
86
87     void visit(Array *node) {
88         writer.beginArray(node->values.size());
89         for (std::vector<Value *>::iterator it = node->values.begin(); it != node->values.end(); ++it) {
90             _visit(*it);
91         }
92         writer.endArray();
93     }
94
95     void visit(Blob *node) {
96         writer.writeBlob(node->buf, node->size);
97     }
98
99     void visit(Pointer *node) {
100         writer.writePointer(node->value);
101     }
102
103     void visit(Repr *node) {
104         writer.beginRepr();
105         _visit(node->humanValue);
106         _visit(node->machineValue);
107         writer.endRepr();
108     }
109
110     void visit(Call *call) {
111         unsigned call_no = writer.beginEnter(call->sig, call->thread_id);
112         for (unsigned i = 0; i < call->args.size(); ++i) {
113             if (call->args[i].value) {
114                 writer.beginArg(i);
115                 _visit(call->args[i].value);
116                 writer.endArg();
117             }
118         }
119         writer.endEnter();
120         writer.beginLeave(call_no);
121         if (call->ret) {
122             writer.beginReturn();
123             _visit(call->ret);
124             writer.endReturn();
125         }
126         writer.endLeave();
127     }
128 };
129
130
131 void Writer::writeCall(Call *call) {
132     ModelWriter visitor(*this);
133     visitor.visit(call);
134 }
135
136
137 } /* namespace trace */
138