]> git.cworth.org Git - apitrace/blob - common/trace_copier.cpp
Add "apitrace trim" command.
[apitrace] / common / trace_copier.cpp
1 /*********************************************************************
2  *
3  * Copyright 2010 VMware, Inc.
4  * Copyright 2011 Intel Corporation
5  * All Rights Reserved.
6  *
7  * Permission is hereby granted, free of charge, to any person
8  * obtaining a copy of this software and associated documentation
9  * files (the "Software"), to deal in the Software without
10  * restriction, including without limitation the rights to use, copy,
11  * modify, merge, publish, distribute, sublicense, and/or sell copies
12  * of the Software, and to permit persons to whom the Software is
13  * furnished to do so, subject to the following conditions:
14  *
15  * The above copyright notice and this permission notice shall be
16  * included in all copies or substantial portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
22  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
23  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25  * SOFTWARE.
26  *
27  *********************************************************************/
28
29 #include "trace_copier.hpp"
30
31 namespace trace {
32
33 Copier::Copier(const char *filename) : writer() {
34     writer.open(filename);
35 }
36
37 Copier::~Copier() {
38     writer.close();
39 }
40
41 void Copier::visit(Null *) {
42     writer.writeNull();
43 }
44
45 void Copier::visit(Bool *node) {
46     writer.writeBool(node->value);
47 }
48
49 void Copier::visit(SInt *node) {
50     writer.writeSInt(node->value);
51 }
52
53 void Copier::visit(UInt *node) {
54     writer.writeUInt(node->value);
55 }
56
57 void Copier::visit(Float *node) {
58     writer.writeFloat(node->value);
59 }
60
61 void Copier::visit(Double *node) {
62     writer.writeDouble(node->value);
63 }
64
65 void Copier::visit(String *node) {
66     writer.writeString(node->value);
67 }
68
69 void Copier::visit(Enum *node) {
70     writer.writeEnum(node->sig);
71 }
72
73 void Copier::visit(Bitmask *bitmask) {
74     writer.writeBitmask(bitmask->sig, bitmask->value);
75 }
76
77 void Copier::visit(Struct *s) {
78     writer.beginStruct(s->sig);
79     for (unsigned i = 0; i < s->members.size(); ++i) {
80         _visit(s->members[i]);
81     }
82 }
83
84 void Copier::visit(Array *array) {
85     if (array->values.size()) {
86         writer.beginArray(array->values.size());
87         for (std::vector<Value *>::iterator it = array->values.begin(); it != array->values.end(); ++it) {
88             _visit(*it);
89         }
90         writer.endArray();
91     } else {
92         writer.writeNull();
93     }
94 }
95
96 void Copier::visit(Blob *blob) {
97     writer.writeBlob(blob->buf, blob->size);
98 }
99
100 void Copier::visit(Pointer *p) {
101     writer.writeOpaque((void *)p->value);
102 }
103
104 void Copier::visit(Call *call) {
105     unsigned __call = writer.beginEnter(call->sig);
106     for (unsigned i = 0; i < call->args.size(); ++i) {
107         writer.beginArg(i);
108         _visit(call->args[i]);
109         writer.endArg();
110     }
111     writer.endEnter();
112     writer.beginLeave(__call);
113     if (call->ret) {
114         writer.beginReturn();
115         _visit(call->ret);
116         writer.endReturn();
117     }
118     writer.endLeave();
119 }
120
121 }