Commit bc0cbb97 by Ben Clayton

Reactor: Fix printing of strings with escape characters

Don't bake the string into the printf format, use a '%s' and pass the string as a parameter. Change-Id: I47be05383637caaa81a93d19623ff39c47988df3 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/31429Tested-by: 's avatarBen Clayton <bclayton@google.com> Kokoro-Presubmit: kokoro <noreply+kokoro@google.com> Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com>
parent 0dbe4ca0
...@@ -4092,6 +4092,7 @@ namespace rr ...@@ -4092,6 +4092,7 @@ namespace rr
std::vector<Value*> PrintValue::Ty<UShort4>::val(const RValue<UShort4>& v) { return extractAll(v.value, 4); } std::vector<Value*> PrintValue::Ty<UShort4>::val(const RValue<UShort4>& v) { return extractAll(v.value, 4); }
std::vector<Value*> PrintValue::Ty<Float>::val(const RValue<Float>& v) { return toDouble({v.value}); } std::vector<Value*> PrintValue::Ty<Float>::val(const RValue<Float>& v) { return toDouble({v.value}); }
std::vector<Value*> PrintValue::Ty<Float4>::val(const RValue<Float4>& v) { return toDouble(extractAll(v.value, 4)); } std::vector<Value*> PrintValue::Ty<Float4>::val(const RValue<Float4>& v) { return toDouble(extractAll(v.value, 4)); }
std::vector<Value*> PrintValue::Ty<const char*>::val(const char* v) { return {V(::builder->CreateGlobalStringPtr(v))}; }
void Printv(const char* function, const char* file, int line, const char* fmt, std::initializer_list<PrintValue> args) void Printv(const char* function, const char* file, int line, const char* fmt, std::initializer_list<PrintValue> args)
{ {
......
...@@ -3252,8 +3252,6 @@ namespace rr ...@@ -3252,8 +3252,6 @@ namespace rr
PrintValue(uint64_t v) : format(std::to_string(v)) {} PrintValue(uint64_t v) : format(std::to_string(v)) {}
PrintValue(float v) : format(std::to_string(v)) {} PrintValue(float v) : format(std::to_string(v)) {}
PrintValue(double v) : format(std::to_string(v)) {} PrintValue(double v) : format(std::to_string(v)) {}
PrintValue(const char* v) : format(v) {}
PrintValue(const std::string& v) : format(v) {}
template <typename T> template <typename T>
PrintValue(const T* v) : format(addr(v)) {} PrintValue(const T* v) : format(addr(v)) {}
...@@ -3295,6 +3293,18 @@ namespace rr ...@@ -3295,6 +3293,18 @@ namespace rr
} }
}; };
// PrintValue::Ty<T> specializations for basic types.
template <> struct PrintValue::Ty<const char*>
{
static constexpr const char* fmt = "%s";
static std::vector<Value*> val(const char* v);
};
template <> struct PrintValue::Ty<std::string>
{
static constexpr const char* fmt = PrintValue::Ty<const char*>::fmt;
static std::vector<Value*> val(const std::string& v) { return PrintValue::Ty<const char*>::val(v.c_str()); }
};
// PrintValue::Ty<T> specializations for standard Reactor types. // PrintValue::Ty<T> specializations for standard Reactor types.
template <> struct PrintValue::Ty<Bool> template <> struct PrintValue::Ty<Bool>
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment