1 /*********************************************************************
3 * Copyright 2010 VMware, Inc.
4 * Copyright 2011 Intel Corporation
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:
15 * The above copyright notice and this permission notice shall be
16 * included in all copies or substantial portions of the Software.
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
27 *********************************************************************/
29 #include "trace_copier.hpp"
33 Copier::Copier(const char *filename) : writer() {
34 writer.open(filename);
41 void Copier::visit(Null *) {
45 void Copier::visit(Bool *node) {
46 writer.writeBool(node->value);
49 void Copier::visit(SInt *node) {
50 writer.writeSInt(node->value);
53 void Copier::visit(UInt *node) {
54 writer.writeUInt(node->value);
57 void Copier::visit(Float *node) {
58 writer.writeFloat(node->value);
61 void Copier::visit(Double *node) {
62 writer.writeDouble(node->value);
65 void Copier::visit(String *node) {
66 writer.writeString(node->value);
69 void Copier::visit(Enum *node) {
70 writer.writeEnum(node->sig);
73 void Copier::visit(Bitmask *bitmask) {
74 writer.writeBitmask(bitmask->sig, bitmask->value);
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]);
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) {
96 void Copier::visit(Blob *blob) {
97 writer.writeBlob(blob->buf, blob->size);
100 void Copier::visit(Pointer *p) {
101 writer.writeOpaque((void *)p->value);
104 void Copier::visit(Call *call) {
105 unsigned __call = writer.beginEnter(call->sig);
106 for (unsigned i = 0; i < call->args.size(); ++i) {
108 _visit(call->args[i]);
112 writer.beginLeave(__call);
114 writer.beginReturn();