Skip to content
This repository
Newer
Older
100644 130 lines (105 sloc) 3.537 kb
16ff25d6 » jrfonseca
2011-05-28 Ability to write a new call to trace file.
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
b4a3d149 » jrfonseca
2011-10-27 Lower case namespaces.
30 namespace trace {
16ff25d6 » jrfonseca
2011-05-28 Ability to write a new call to trace file.
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
e935ee10 » cworth-gh
2011-11-17 Parse doubles to a new Double class rather than to the Float class.
63 void visit(Double *node) {
64 writer.writeDouble(node->value);
65 }
66
16ff25d6 » jrfonseca
2011-05-28 Ability to write a new call to trace file.
67 void visit(String *node) {
68 writer.writeString(node->value);
69 }
70
71 void visit(Enum *node) {
eb64451e » jrfonseca
2011-12-11 Trace enum signatures as a whole.
72 writer.writeEnum(node->sig, node->value);
16ff25d6 » jrfonseca
2011-05-28 Ability to write a new call to trace file.
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.writeOpaque((const void *) (size_t) node->value);
101 }
102
103 void visit(Call *call) {
0af9670e » jrfonseca
2011-12-22 First stab at tracing thread IDs.
104 unsigned call_no = writer.beginEnter(call->sig, call->thread_id);
16ff25d6 » jrfonseca
2011-05-28 Ability to write a new call to trace file.
105 for (unsigned i = 0; i < call->args.size(); ++i) {
a5b476eb » cworth-gh
2011-11-16 Correctly copy "out" arguments to the "leave" portion of the trace
106 if (call->args[i].value) {
16ff25d6 » jrfonseca
2011-05-28 Ability to write a new call to trace file.
107 writer.beginArg(i);
a5b476eb » cworth-gh
2011-11-16 Correctly copy "out" arguments to the "leave" portion of the trace
108 _visit(call->args[i].value);
16ff25d6 » jrfonseca
2011-05-28 Ability to write a new call to trace file.
109 writer.endArg();
110 }
111 }
112 writer.endEnter();
113 writer.beginLeave(call_no);
114 if (call->ret) {
115 writer.beginReturn();
116 _visit(call->ret);
117 writer.endReturn();
118 }
119 writer.endLeave();
120 }
121 };
122
123
124 void Writer::writeCall(Call *call) {
125 ModelWriter visitor(*this);
126 visitor.visit(call);
127 }
128
129
b4a3d149 » jrfonseca
2011-10-27 Lower case namespaces.
130 } /* namespace trace */
16ff25d6 » jrfonseca
2011-05-28 Ability to write a new call to trace file.
131
Something went wrong with that request. Please try again.