1 /**************************************************************************
3 * Copyright 2011 Jose Fonseca
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:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
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
24 **************************************************************************/
27 #include "trace_writer.hpp"
33 class ModelWriter : public Visitor
39 ModelWriter(Writer &_writer) :
47 void visit(Bool *node) {
48 writer.writeBool(node->value);
51 void visit(SInt *node) {
52 writer.writeSInt(node->value);
55 void visit(UInt *node) {
56 writer.writeUInt(node->value);
59 void visit(Float *node) {
60 writer.writeFloat(node->value);
63 void visit(Double *node) {
64 writer.writeDouble(node->value);
67 void visit(String *node) {
68 writer.writeString(node->value);
71 void visit(Enum *node) {
72 writer.writeEnum(node->sig, node->value);
75 void visit(Bitmask *node) {
76 writer.writeBitmask(node->sig, node->value);
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]);
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) {
95 void visit(Blob *node) {
96 writer.writeBlob(node->buf, node->size);
99 void visit(Pointer *node) {
100 writer.writePointer(node->value);
103 void visit(Repr *node) {
105 _visit(node->humanValue);
106 _visit(node->machineValue);
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) {
115 _visit(call->args[i].value);
120 writer.beginLeave(call_no);
122 writer.beginReturn();
131 void Writer::writeCall(Call *call) {
132 ModelWriter visitor(*this);
137 } /* namespace trace */