Permalink
Browse files

proper support for checksums

  • Loading branch information...
jbangert committed Aug 11, 2015
1 parent bd09eaf commit d861b8d5cbe0066373a102b299cfbbeae5c7b549
Showing with 33 additions and 7 deletions.
  1. +1 −1 generator/mk_directparser.cc
  2. +12 −2 generator/mk_gen.cc
  3. +1 −1 generator/mk_parser.cc
  4. +18 −2 generator/nailtool.h
  5. +1 −1 generator/util.cc
@@ -164,7 +164,7 @@ class CDirectParser {
ValExpr lval(std::string ("dep_") + name);
out << type << " dep_" << name << ";\n";
parser(field->dependency.parser->pr,lval,fail,newscope);
newscope.add_dependency_definition(name,type);
newscope.add_dependency_definition(name,type, 0);
break;
}
case TRANSFORM:{
View
@@ -104,7 +104,7 @@ class GenGenerator{
}
int width = boost::lexical_cast<int>(mk_str(p.pr.integer.parser.unsign));
out << type << " dep_"<< name << ";";
newscope.add_dependency_definition(name,type);
newscope.add_dependency_definition(name,type, width);
assert(post == "");
out << "NailOutStreamPos rewind_"<< name << "=NailOutStream_getpos(str_current);";
out << "NailOutStream_write(str_current,0,"<<width<<");";
@@ -149,15 +149,25 @@ class GenGenerator{
FOREACH(stream, field->transform.left){
newscope.add_stream_definition(mk_str(*stream));
}
invocation << "{ NailOutStreamPos t_rewind_eot =NailOutStream_getpos(str_current);\n";
FOREACH(param, field->transform.right){
if(param->N_type != PDEPENDENCY) continue;
std::string name (mk_str(param->pdependency));
if(!newscope.is_local_dependency(name)) continue;
invocation << "NailOutStream_reposition(str_current, rewind_"<<name<<");";
invocation << "NailOutStream_write(str_current,dep_"<<name<<","<<newscope.dependency_width(name)<<");";
}
invocation << " NailOutStream_reposition(str_current, t_rewind_eot);\n }";
transform_invocations.push_front(invocation.str());
}
break;
}
}
fixup << "NailOutStream_reposition(str_current, end_of_struct);";
for(auto &transform: transform_invocations){
out << transform;
}
fixup << "NailOutStream_reposition(str_current, end_of_struct);";
//TODO: We need to properly interleave APPLY and TRANSFORM when generating! Transform at the
//end is wrong in some cases (when the applied parser relies on a context from the transform)
out << fixup.str();
View
@@ -514,7 +514,7 @@ class CPrimitiveParser{
out << "NailStream *stream = &tmpstream;"; //TODO: parametrize this on action
dependency_action.action(field->dependency.parser->pr,lval,end);
out << "}";
newscope.add_dependency_definition(name,type);
newscope.add_dependency_definition(name,type, 0);
out << "n_tr_setpos(trace,trace_"<<name<<");\n";
out << "n_tr_const(trace,str_current);\n";
}
View
@@ -44,6 +44,7 @@ NailException(const std::string &message) : std::logic_error(message){}
struct Dependency{
std::string name;
std::string typedef_type;
uint64_t width; // XXX: Replace by a line that should be inserted to output this Dependency
};
class Scope{
std::map<std::string,Dependency> dependencies;
@@ -57,10 +58,11 @@ class Scope{
throw NailException("Duplicate stream "+value);
}
}
void add_dependency_parameter(std::string value, std::string type){
void add_dependency_parameter(std::string value, std::string type,uint64_t width){
Dependency dep;
dep.name = std::string("dep_")+value;
dep.typedef_type = type;
dep.width = width;
if(!dependencies.emplace(value,dep).second){
throw NailException("Duplicate dependency "+value);
}
@@ -70,10 +72,11 @@ class Scope{
throw NailException("Duplicate dependency "+value);
}
}
void add_dependency_definition(std::string value,std::string type){
void add_dependency_definition(std::string value,std::string type,uint64_t width ){
Dependency dep;
dep.name = std::string("&dep_")+value;
dep.typedef_type = type;
dep.width = width;
if(!dependencies.emplace(value,dep).second){
throw NailException("Duplicate dependency "+value);
}
@@ -108,6 +111,19 @@ class Scope{
}
return i->second;
}
bool is_local_dependency(std::string name){
return dependencies.count(name)>0;
}
uint64_t dependency_width(std::string name){
auto i = dependencies.find(name);
if(i==dependencies.end()){
if(!parent)
throw NailException(std::string("Undefined reference to ") + name);
else
return parent->dependency_width(name);
}
return i->second.width;
}
};
std::string int_type(const intp &intp );
View
@@ -154,7 +154,7 @@ std::string parameter_definition(const definition &def, Scope &scope){
std::string name = mk_str(param->ddependency.name);
assert(post == "");
params << ","<< type << "* dep_" << name << post;
scope.add_dependency_parameter(name,type);
scope.add_dependency_parameter(name,type, 0);
}
break;
}

0 comments on commit d861b8d

Please sign in to comment.