From 077e8cd949c1fcfa48413df3f0a4ca6bdb8ca944 Mon Sep 17 00:00:00 2001
From: David 'Digit' Turner <digit@google.com>
Date: Wed, 17 Sep 2014 19:12:24 +0200
Subject: emulator/opengl/emgen: Fix debug output of floating point values.

When calling printf() with a "%f", the value passed must be a double,
not a float, which means we can't just pass a 32-bit value in the stack
and assume printf() will cast it to a float properly. This results in
bogus values printed whenever a GLfloat is used in a function signature,
due to invalid stack offsets used by the printf().

Fix the problem by using Unpack<>() template.

Change-Id: I282d9c07af68457f32af477435e5dc1999267d39
---
 emulator/opengl/host/tools/emugen/ApiGen.cpp | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)

(limited to 'emulator')

diff --git a/emulator/opengl/host/tools/emugen/ApiGen.cpp b/emulator/opengl/host/tools/emugen/ApiGen.cpp
index a92ad39..78c15e4 100644
--- a/emulator/opengl/host/tools/emugen/ApiGen.cpp
+++ b/emulator/opengl/host/tools/emugen/ApiGen.cpp
@@ -854,19 +854,14 @@ int ApiGen::genDecoderImpl(const std::string &filename)
                 }
 
                 if (!v->isPointer()) {
-                    if (pass == PASS_FunctionCall) {
+                    if (pass == PASS_FunctionCall ||
+                        pass == PASS_DebugPrint) {
                         fprintf(fp,
                                 "Unpack<%s,uint%d_t>(ptr + %s)",
                                 v->type()->name().c_str(),
                                 v->type()->bytes() * 8,
                                 varoffset.c_str());
                     }
-                    if (pass == PASS_DebugPrint) {
-                        fprintf(fp,
-                                "*(uint%d_t *)(ptr + %s)",
-                                v->type()->bytes() * 8,
-                                varoffset.c_str());
-                    }
                     varoffset += " + " + toString(v->type()->bytes());
                     continue;
                 }
-- 
cgit v1.1