summaryrefslogtreecommitdiff
path: root/backend/src/ir
diff options
context:
space:
mode:
authorJunyan He <junyan.he@linux.intel.com>2014-06-23 16:38:56 +0800
committerZhigang Gong <zhigang.gong@intel.com>2014-06-23 17:14:40 +0800
commit64e719d98f68147ee1fdc95aac53885f29a8a077 (patch)
tree66d58af25705c0c2e03507a9c3321e8789e2a622 /backend/src/ir
parent6bd3f96e41983c7189c967bde007c4e26c7c44a7 (diff)
Add the format and flag support for printf.
The format and flag such as -+# and precision request has been added into the output. Signed-off-by: Junyan He <junyan.he@linux.intel.com> Reviewed-by: Zhigang Gong <zhigang.gong@linux.intel.com>
Diffstat (limited to 'backend/src/ir')
-rw-r--r--backend/src/ir/printf.cpp104
-rw-r--r--backend/src/ir/printf.hpp13
2 files changed, 108 insertions, 9 deletions
diff --git a/backend/src/ir/printf.cpp b/backend/src/ir/printf.cpp
index d919f78a..58711e29 100644
--- a/backend/src/ir/printf.cpp
+++ b/backend/src/ir/printf.cpp
@@ -50,6 +50,60 @@ namespace gbe
return (uint32_t)fmts.size();
}
+ static void generatePrintfFmtString(PrintfState& state, std::string& str)
+ {
+ char num_str[16];
+ str += "%";
+
+ if (state.left_justified) {
+ str += "-";
+ }
+
+ if (state.sign_symbol == 1) {
+ str += "+";
+ } else if (state.sign_symbol == 2) {
+ str += " ";
+ }
+
+ if (state.alter_form) {
+ str += "#";
+ }
+
+ if (state.zero_padding) {
+ str += "0";
+ }
+
+ if (state.min_width >= 0) {
+ snprintf(num_str, 16, "%d", state.min_width);
+ str += num_str;
+ }
+
+ if (state.precision >= 0) {
+ str += ".";
+ snprintf(num_str, 16, "%d", state.precision);
+ str += num_str;
+ }
+
+ // TODO: Handle the vector here.
+
+ switch (state.length_modifier) {
+ case PRINTF_LM_HH:
+ str += "hh";
+ break;
+ case PRINTF_LM_H:
+ str += "h";
+ break;
+ case PRINTF_LM_L:
+ str += "l";
+ break;
+ case PRINTF_LM_HL:
+ str += "hl";
+ break;
+ default:
+ assert(state.length_modifier == PRINTF_LM_NONE);
+ }
+ }
+
#define PRINT_SOMETHING(target_ty, conv) do { \
pf_str = pf_str + std::string(#conv); \
printf(pf_str.c_str(), \
@@ -59,6 +113,7 @@ namespace gbe
pf_str = ""; \
} while (0)
+
void PrintfSet::outputPrintf(void* index_addr, void* buf_addr, size_t global_wk_sz0,
size_t global_wk_sz1, size_t global_wk_sz2)
{
@@ -81,26 +136,59 @@ namespace gbe
}
assert(slot.type == PRINTF_SLOT_TYPE_STATE);
+ generatePrintfFmtString(*slot.state, pf_str);
+
switch (slot.state->conversion_specifier) {
case PRINTF_CONVERSION_D:
case PRINTF_CONVERSION_I:
- PRINT_SOMETHING(int, %d);
+ PRINT_SOMETHING(int, d);
+ break;
+
+ case PRINTF_CONVERSION_O:
+ PRINT_SOMETHING(int, o);
+ break;
+ case PRINTF_CONVERSION_U:
+ PRINT_SOMETHING(int, u);
+ break;
+ case PRINTF_CONVERSION_X:
+ PRINT_SOMETHING(int, X);
+ break;
+ case PRINTF_CONVERSION_x:
+ PRINT_SOMETHING(int, x);
break;
+
case PRINTF_CONVERSION_C:
- PRINT_SOMETHING(char, %c);
+ PRINT_SOMETHING(char, c);
break;
case PRINTF_CONVERSION_F:
+ PRINT_SOMETHING(float, F);
+ break;
case PRINTF_CONVERSION_f:
- if (slot.state->conversion_specifier == PRINTF_CONVERSION_F)
- PRINT_SOMETHING(float, %F);
- else
- PRINT_SOMETHING(float, %f);
+ PRINT_SOMETHING(float, f);
+ break;
+ case PRINTF_CONVERSION_E:
+ PRINT_SOMETHING(float, E);
+ break;
+ case PRINTF_CONVERSION_e:
+ PRINT_SOMETHING(float, e);
+ break;
+ case PRINTF_CONVERSION_G:
+ PRINT_SOMETHING(float, G);
+ break;
+ case PRINTF_CONVERSION_g:
+ PRINT_SOMETHING(float, g);
+ break;
+ case PRINTF_CONVERSION_A:
+ PRINT_SOMETHING(float, A);
+ break;
+ case PRINTF_CONVERSION_a:
+ PRINT_SOMETHING(float, a);
break;
case PRINTF_CONVERSION_S:
- pf_str = pf_str + "%s";
- printf("%s%s", pf_str.c_str(), slot.state->str.c_str());
+ pf_str = pf_str + "s";
+ printf(pf_str.c_str(), slot.state->str.c_str());
pf_str = "";
break;
diff --git a/backend/src/ir/printf.hpp b/backend/src/ir/printf.hpp
index 18bdd6e3..8b759d47 100644
--- a/backend/src/ir/printf.hpp
+++ b/backend/src/ir/printf.hpp
@@ -35,6 +35,7 @@ namespace gbe
/* Things about printf info. */
enum {
+ PRINTF_LM_NONE,
PRINTF_LM_HH,
PRINTF_LM_H,
PRINTF_LM_L,
@@ -184,11 +185,21 @@ namespace gbe
switch (slot->state->conversion_specifier) {
case PRINTF_CONVERSION_I:
case PRINTF_CONVERSION_D:
- /* Char will be aligned to sizeof(int) here. */
+ case PRINTF_CONVERSION_O:
+ case PRINTF_CONVERSION_U:
+ case PRINTF_CONVERSION_X:
+ case PRINTF_CONVERSION_x:
+ /* Char will be aligned to sizeof(int) here. */
case PRINTF_CONVERSION_C:
return (uint32_t)sizeof(int);
+ case PRINTF_CONVERSION_E:
+ case PRINTF_CONVERSION_e:
case PRINTF_CONVERSION_F:
case PRINTF_CONVERSION_f:
+ case PRINTF_CONVERSION_G:
+ case PRINTF_CONVERSION_g:
+ case PRINTF_CONVERSION_A:
+ case PRINTF_CONVERSION_a:
return (uint32_t)sizeof(float);
case PRINTF_CONVERSION_S:
return (uint32_t)0;