]> git.cworth.org Git - apitrace/commitdiff
Refer args by index.
authorJosé Fonseca <jfonseca@vmware.com>
Wed, 24 Nov 2010 16:19:49 +0000 (16:19 +0000)
committerJosé Fonseca <jfonseca@vmware.com>
Wed, 24 Nov 2010 16:19:49 +0000 (16:19 +0000)
Argument names are not very reliable.

base.py
glretrace.py
log.cpp
log.hpp
trace.py
trace_model.cpp
trace_model.hpp
trace_parser.hpp

diff --git a/base.py b/base.py
index 1637128ddc77fa7a15cd923e16dc1db8ab525bab..8213403aafccc37043aedac98f4e9410cd0df9eb 100644 (file)
--- a/base.py
+++ b/base.py
@@ -332,6 +332,7 @@ class Arg:
         self.type = type
         self.name = name
         self.output = output
+        self.index = None
 
     def __str__(self):
         return '%s %s' % (self.type, self.name)
@@ -344,10 +345,13 @@ class Function:
         self.name = name
 
         self.args = []
+        index = 0
         for arg in args:
             if isinstance(arg, tuple):
                 arg_type, arg_name = arg
                 arg = Arg(arg_type, arg_name)
+            arg.index = index
+            index += 1
             self.args.append(arg)
 
         self.call = call
index 4b7ad7acdaa2205fc2afae474ed056b2f64cd66b..5cdcf24bf4cd973bb22c64ae5f1ce51d72a3655e 100644 (file)
@@ -137,7 +137,7 @@ def retrace_function(function):
         arg_type = ConstRemover().visit(arg.type)
         print '    // %s ->  %s' % (arg.type, arg_type)
         print '    %s %s;' % (arg_type, arg.name)
-        rvalue = 'call.arg("%s")' % (arg.name,)
+        rvalue = 'call.arg(%u)' % (arg.index,)
         lvalue = arg.name
         try:
             ValueExtractor().visit(arg_type, lvalue, rvalue)
@@ -156,7 +156,7 @@ def retrace_function(function):
     for arg in function.args:
         if arg.output:
             arg_type = ConstRemover().visit(arg.type)
-            rvalue = 'call.arg("%s")' % (arg.name,)
+            rvalue = 'call.arg(%u)' % (arg.index,)
             lvalue = arg.name
             try:
                 ValueWrapper().visit(arg_type, lvalue, rvalue)
diff --git a/log.cpp b/log.cpp
index 5236649ae5c62617454ac558552db72d8272a5a3..11d09934c5cb059b7a3cbfdc082f6ab1d84819c5 100644 (file)
--- a/log.cpp
+++ b/log.cpp
@@ -173,8 +173,9 @@ void EndCall(void) {
    OS::ReleaseMutex();
 }
 
-void BeginArg(const char *name) {
+void BeginArg(unsigned index, const char *name) {
    WriteByte(Trace::CALL_ARG);
+   WriteUInt(index);
    WriteString(name);
 }
 
diff --git a/log.hpp b/log.hpp
index fbc98469fc6b66306e8189e3d028afb24db649c9..b6fc2b35353a09f6cb8a769cfa929b42cf0966c9 100644 (file)
--- a/log.hpp
+++ b/log.hpp
@@ -34,7 +34,7 @@ namespace Log {
     void BeginCall(const char *function);
     void EndCall(void);
     
-    void BeginArg(const char *name);
+    void BeginArg(unsigned index, const char *name);
     inline void EndArg(void) {}
 
     void BeginReturn(void);
index 8e2e2af3e061cc41e6d9145d1b12d754947eadaf..b50d0a6734a5bbf5272b4e97310a6547e70999a4 100644 (file)
--- a/trace.py
+++ b/trace.py
@@ -340,7 +340,7 @@ class Tracer:
         print
 
     def dump_arg(self, function, arg):
-        print '    Log::BeginArg("%s");' % (arg.name,)
+        print '    Log::BeginArg(%u, "%s");' % (arg.index, arg.name,)
         dump_instance(arg.type, arg.name)
         print '    Log::EndArg();'
 
@@ -402,7 +402,7 @@ class Tracer:
             print '    %s __result;' % method.type
             result = '__result = '
         print '    Log::BeginCall("%s");' % (interface.name + '::' + method.name)
-        print '    Log::BeginArg("this");'
+        print '    Log::BeginArg(0, "this");'
         print '    Log::LiteralOpaque((const void *)m_pInstance);'
         print '    Log::EndArg();'
         for arg in method.args:
index f4e915d476aed87d5c27bf89ed56a8ada7b53d8d..098656fc05c37dee68c3b8591de13f5252abf4ca 100644 (file)
@@ -153,7 +153,7 @@ public:
    void visit(Call *call) {
       const char *sep = "";
       os << bold << call->name << normal << "(";
-      for (std::list<Arg>::iterator it = call->args.begin(); it != call->args.end(); ++it) {
+      for (std::vector<Arg>::iterator it = call->args.begin(); it != call->args.end(); ++it) {
          os << sep << italic << it->first << normal << " = ";
          _visit(it->second);
          sep = ", ";
@@ -245,15 +245,6 @@ const char * Value::string(void) const {
    return NULL;
 }
 
-Value & Call::arg(const char *name) {
-   for (std::list<Arg>::iterator it = args.begin(); it != args.end(); ++it) {
-      if (it->first == name) {
-         return *it->second;
-      }
-   }
-   return null;
-}
-
 std::ostream & operator <<(std::ostream &os, Call &call) {
    Dumper d(os);
    d.visit(&call);
index 659b165d54b3acab5215bf70e77b927f635bd13f..f50c6ac2c663161545b73804aefe9a40d1cb776d 100644 (file)
@@ -236,12 +236,14 @@ class Call
 {
 public:
    std::string name;
-   std::list<Arg> args;
+   std::vector<Arg> args;
    Value *ret;
 
    Call() : ret(0) { }
 
-   Value & arg(const char *name);
+   inline Value & arg(unsigned index) {
+       return *(args[index].second);
+   }
 };
 
 
index 2c5503751ee9c1c03247fd325a22825e1517cb76..97dcf657b71f30ad132bbd21bb3cd6f448bb9a72 100644 (file)
@@ -86,7 +86,7 @@ public:
          case Trace::CALL_END:
             return call;
          case Trace::CALL_ARG:
-            call->args.push_back(parse_arg());
+            parse_arg(call);
             break;
          case Trace::CALL_RET:
             call->ret = parse_value();
@@ -102,10 +102,14 @@ public:
       } while(true);
    }
    
-   Arg parse_arg(void) {
+   void parse_arg(Call *call) {
+      unsigned index = read_uint();
       std::string name = read_string();
       Value *value = parse_value();
-      return Arg(name, value);
+      if (index >= call->args.size()) {
+          call->args.resize(index + 1);
+      }
+      call->args[index] = Arg(name, value);
    }
    
    Value *parse_value(void) {