diff options
author | Lingfeng Yang <lfy@google.com> | 2017-05-04 09:20:01 -0700 |
---|---|---|
committer | Greg Hartman <ghartman@google.com> | 2018-08-23 17:30:51 -0700 |
commit | 88a596779a40644e59ebe46d24cb665f9402e603 (patch) | |
tree | 44b13827bda7f40532c7fc2941b42068f379b8d0 /host | |
parent | cc7d4f0dd74f3b2db0ff7f95869c1e8e81a2197f (diff) | |
download | opengl-transport-88a596779a40644e59ebe46d24cb665f9402e603.tar.gz |
[gl] Allow custom unpack in decoder
Encoder has custom pack, why not custom unpack as well?
Change-Id: I955e0967dad6ee6e1c46bda51774463b67774744
Diffstat (limited to 'host')
-rw-r--r-- | host/commands/emugen/ApiGen.cpp | 23 | ||||
-rw-r--r-- | host/commands/emugen/EntryPoint.cpp | 20 | ||||
-rw-r--r-- | host/commands/emugen/Var.h | 7 |
3 files changed, 45 insertions, 5 deletions
diff --git a/host/commands/emugen/ApiGen.cpp b/host/commands/emugen/ApiGen.cpp index 5d8851dd0..e343b83ab 100644 --- a/host/commands/emugen/ApiGen.cpp +++ b/host/commands/emugen/ApiGen.cpp @@ -1163,6 +1163,14 @@ R"( // Do this on every iteration, as some commands may change the checks var_name, varoffset.c_str(), var_name); + if (v->unpackExpression().size() > 0) { + fprintf(fp, + "\t\t\tvoid* inptr_%s_unpacked;\n" + "\t\t\t%s;\n", + var_name, + v->unpackExpression().c_str()); + } + } if (pass == PASS_FunctionCall) { if (v->nullAllowed()) { @@ -1172,10 +1180,17 @@ R"( // Do this on every iteration, as some commands may change the checks var_type_name, var_name); } else { - fprintf(fp, - "(%s)(inptr_%s.get())", - var_type_name, - var_name); + if (v->unpackExpression().size() > 0) { + fprintf(fp, + "(%s)(inptr_%s_unpacked)", + var_type_name, + var_name); + } else { + fprintf(fp, + "(%s)(inptr_%s.get())", + var_type_name, + var_name); + } } } else if (pass == PASS_DebugPrint) { fprintf(fp, diff --git a/host/commands/emugen/EntryPoint.cpp b/host/commands/emugen/EntryPoint.cpp index 20ba8f2f7..6aecac16c 100644 --- a/host/commands/emugen/EntryPoint.cpp +++ b/host/commands/emugen/EntryPoint.cpp @@ -81,6 +81,7 @@ bool EntryPoint::parse(unsigned int lc, const std::string & str) std::string(""), Var::POINTER_OUT, std::string(""), + std::string(""), std::string("")); // function name @@ -117,7 +118,7 @@ bool EntryPoint::parse(unsigned int lc, const std::string & str) varname = oss.str(); } - m_vars.push_back(Var(varname, v, std::string(""), Var::POINTER_IN, "", "")); + m_vars.push_back(Var(varname, v, std::string(""), Var::POINTER_IN, "", "", "")); } pos = last + 1; } @@ -307,6 +308,23 @@ int EntryPoint::setAttribute(const std::string &line, size_t lc) // set the size expression into var pos = last; v->setPackExpression(line.substr(pos)); + } else if (token == "custom_unpack") { + pos = last; + std::string varname = getNextToken(line, pos, &last, WHITESPACE); + + if (varname.size() == 0) { + fprintf(stderr, "ERROR: %u: Missing variable name in 'custom_unpack' attribute\n", (unsigned int)lc); + return -1; + } + Var * v = var(varname); + if (v == NULL) { + fprintf(stderr, "ERROR: %u: variable %s is not a parameter of %s\n", + (unsigned int)lc, varname.c_str(), name().c_str()); + return -2; + } + // set the size expression into var + pos = last; + v->setUnpackExpression(line.substr(pos)); } else if (token == "custom_write") { pos = last; std::string varname = getNextToken(line, pos, &last, WHITESPACE); diff --git a/host/commands/emugen/Var.h b/host/commands/emugen/Var.h index 0266c1392..d20afb167 100644 --- a/host/commands/emugen/Var.h +++ b/host/commands/emugen/Var.h @@ -31,12 +31,14 @@ public: const std::string & lenExpression, PointerDir dir, const std::string &packExpression, + const std::string &unpackExpression, const std::string &writeExpression) : m_name(name), m_type(const_cast<VarType *>(vartype)), m_lenExpression(lenExpression), m_pointerDir(dir), m_packExpression(packExpression), + m_unpackExpression(unpackExpression), m_writeExpression(writeExpression) { } @@ -45,11 +47,13 @@ public: std::string lenExpression, PointerDir dir, std::string packExpression, + std::string unpackExpression, std::string writeExpression) { m_name = name; m_type = vartype; m_lenExpression = lenExpression; m_packExpression = packExpression; + m_unpackExpression = unpackExpression; m_writeExpression = writeExpression; m_pointerDir = dir; m_nullAllowed = false; @@ -63,10 +67,12 @@ public: bool isVoid() const { return ((m_type->bytes() == 0) && (!m_type->isPointer())); } const std::string & lenExpression() const { return m_lenExpression; } const std::string & packExpression() const { return(m_packExpression); } + const std::string & unpackExpression() const { return(m_unpackExpression); } const std::string & writeExpression() const { return(m_writeExpression); } const std::string & paramCheckExpression() const { return m_paramCheckExpression; } void setLenExpression(const std::string & lenExpression) { m_lenExpression = lenExpression; } void setPackExpression(const std::string & packExpression) { m_packExpression = packExpression; } + void setUnpackExpression(const std::string & unpackExpression) { m_unpackExpression = unpackExpression; } void setWriteExpression(const std::string & writeExpression) { m_writeExpression = writeExpression; } void setParamCheckExpression(const std::string & paramCheckExpression) { m_paramCheckExpression = paramCheckExpression; } void setPointerDir(PointerDir dir) { m_pointerDir = dir; } @@ -90,6 +96,7 @@ private: bool m_isLarge = false; bool m_isDMA = false; std::string m_packExpression; // an expression to pack data into the stream + std::string m_unpackExpression; // an expression to unpack data that has arrived from the stream std::string m_writeExpression; // an expression to write data into the stream std::string m_paramCheckExpression; //an expression to check parameter value }; |