]> git.cworth.org Git - apitrace/commitdiff
Ability to write a new call to trace file.
authorJosé Fonseca <jose.r.fonseca@gmail.com>
Sat, 28 May 2011 17:13:39 +0000 (18:13 +0100)
committerJosé Fonseca <jose.r.fonseca@gmail.com>
Sat, 28 May 2011 17:13:39 +0000 (18:13 +0100)
CMakeLists.txt
trace_model_writer.cpp [new file with mode: 0644]
trace_writer.hpp

index 96967462a69741ed6943d6194d82569b1f9c3bbf..7fd53c792ddf8c01d1638818b4a776391c8ff477 100755 (executable)
@@ -163,7 +163,7 @@ else (WIN32)
     set (glws glws_glx.cpp)
 endif (WIN32)
 
-add_library (trace trace_model.cpp trace_parser.cpp trace_writer.cpp ${os})
+add_library (trace trace_model.cpp trace_parser.cpp trace_writer.cpp trace_model_writer.cpp ${os})
 
 add_executable (tracedump tracedump.cpp)
 target_link_libraries (tracedump trace)
diff --git a/trace_model_writer.cpp b/trace_model_writer.cpp
new file mode 100644 (file)
index 0000000..dcfcf86
--- /dev/null
@@ -0,0 +1,127 @@
+/**************************************************************************
+ *
+ * Copyright 2011 Jose Fonseca
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ **************************************************************************/
+
+
+#include "trace_writer.hpp"
+
+
+namespace Trace {
+
+
+class ModelWriter : public Visitor
+{
+protected:
+    Writer &writer;
+
+public:
+    ModelWriter(Writer &_writer) :
+        writer(_writer) {
+    }
+
+    void visit(Null *) {
+        writer.writeNull();
+    }
+
+    void visit(Bool *node) {
+        writer.writeBool(node->value);
+    }
+
+    void visit(SInt *node) {
+        writer.writeSInt(node->value);
+    }
+
+    void visit(UInt *node) {
+        writer.writeUInt(node->value);
+    }
+
+    void visit(Float *node) {
+        writer.writeFloat(node->value);
+    }
+
+    void visit(String *node) {
+        writer.writeString(node->value);
+    }
+
+    void visit(Enum *node) {
+        writer.writeEnum(node->sig);
+    }
+
+    void visit(Bitmask *node) {
+        writer.writeBitmask(node->sig, node->value);
+    }
+
+    void visit(Struct *node) {
+        writer.beginStruct(node->sig);
+        for (unsigned i = 0; i < node->sig->num_members; ++i) {
+            _visit(node->members[i]);
+        }
+        writer.endStruct();
+    }
+
+    void visit(Array *node) {
+        writer.beginArray(node->values.size());
+        for (std::vector<Value *>::iterator it = node->values.begin(); it != node->values.end(); ++it) {
+            _visit(*it);
+        }
+        writer.endArray();
+    }
+
+    void visit(Blob *node) {
+        writer.writeBlob(node->buf, node->size);
+    }
+
+    void visit(Pointer *node) {
+        writer.writeOpaque((const void *) (size_t) node->value);
+    }
+
+    void visit(Call *call) {
+        unsigned call_no = writer.beginEnter(call->sig);
+        for (unsigned i = 0; i < call->args.size(); ++i) {
+            if (call->args[i]) {
+                writer.beginArg(i);
+                _visit(call->args[i]);
+                writer.endArg();
+            }
+        }
+        writer.endEnter();
+        writer.beginLeave(call_no);
+        if (call->ret) {
+            writer.beginReturn();
+            _visit(call->ret);
+            writer.endReturn();
+        }
+        writer.endLeave();
+    }
+};
+
+
+void Writer::writeCall(Call *call) {
+    ModelWriter visitor(*this);
+    visitor.visit(call);
+}
+
+
+} /* namespace Trace */
+
index 9d07150055140bb941333bd2a4d05bdb8a4f0171..4f9cd2b27a32e913bad5889fe32c750afa099a6f 100644 (file)
@@ -93,6 +93,8 @@ namespace Trace {
         void writeNull(void);
         void writeOpaque(const void *ptr);
 
+        void writeCall(Call *call);
+
     protected:
         void inline _write(const void *sBuffer, size_t dwBytesToWrite);
         void inline _writeByte(char c);