예제 #1
0
// o+o+o+o+o+o+o+o+o+o+o+o+o+o+o+o+o+o+o+o+o+o+o+o+o+o+o+o+o+o+o+o
static void printPrototypes(std::ostream & out, std::string type) {
   int i;
   for (i=1;i<=2;++i) {
      std::string dimensionstring = getDimensionString (i);
      out << "extern int finiteValueProduced"<<dimensionstring ;
      out << type << " (brook::stream input);\n"      ;
      out <<"extern float shiftValues"<<dimensionstring;
      out << type << "(brook::stream list_stream,\n"
         "                         brook::stream *output_stream,\n"
         "                         int WIDTH, \n"
         "                         int LENGTH, \n"
         "                         int sign);\n"
         "void combineStreams"<<dimensionstring;
      out << type << "(brook::stream **streams,\n"
         "                     unsigned int num,\n"
         "                     unsigned int width, \n"
         "                     unsigned int length,\n"
         "                     brook::stream *output) ;\n";
      
   }
}
예제 #2
0
void BRTKernelDef::PrintVoutDimensionalShift(std::ostream &out, 
                                             Decl* decl,
                                             unsigned int dim) const {
   
      std::string type = undecoratedBase(decl);
      unsigned int i;
      std::string dimensionstring = getDimensionString(dim);
      out<< "    ::brook::stream "<<getDeclStream(decl,"_temp")<<"(&";
      std::string typevector = getDeclStream(decl,"_types");
      out<< typevector<<"[0],";
      for (i=0;i<dim;++i) {
         out << "1, ";
      }
      out << "-1);"<<std::endl;
      out<< "    combineStreams"<<dimensionstring;
      out << type <<" (&"<<getDeclStream(decl,"_outputs")<<"[0],";
      out<< std::endl;
      out<<"                   "<<getDeclStream(decl,"_outputs")<<".size()-1,";
      out<< std::endl;
      out<< "                   maxextents[0],";
      out<< std::endl;
      out<< "                   maxextents[1],";
      out<< std::endl;
      out<< "                   &"<<getDeclStream(decl,"_temp")<<");";
      out<< std::endl;
      out<< "    shiftValues"<<dimensionstring;
      out << type << "("<<getDeclStream(decl,"_temp")<<",";
      out<< std::endl;
      out<< "                &"<< decl->name->name<<",";
      out<< std::endl;
      for (i=0;i<dim;++i) {
         out<< "                "<<getDeclStream (decl,"_temp");
         out<< "->getExtents()["<<i<<"],";
         out<<std::endl;
      }
      for (;i<2;++i) out << "                 1,";
      out<< "                -1);"<<std::endl; 
}
예제 #3
0
파일: funcs.c 프로젝트: cmjonze/evlog_cvs
/*
 * For each non-const attribute in template t, print the appropriate args
 * in the call to evl_log_write().
 */
static void
printAttArgs(const evltemplate_t *t, const char *prefix)
{
	evl_listnode_t *head = t->tm_attributes, *end, *p;
	const evltemplate_t *st;	/* struct attribute's template */

	for (end=NULL, p=head; p!=end; end=head, p=p->li_next) {
		evlattribute_t *att = (evlattribute_t*) p->li_data;
		int ty;

		if (isConstAtt(att)) {
			continue;
		}
		if (isBitField(att)) {
			notSupported("bit-fields");
			continue;
		}

		ty = evlatt_gettype(att);
		if (isArray(att)) {
			char *dimString;

			dimString = getDimensionString(att, prefix);
			if (ty == TY_STRUCT) {
				/* Array of structs */
				st = att->ta_type->u.st_template;
				if ((st->tm_flags & TMPL_TF_ALIGNED) != 0) {
					/* Array of aligned structs */
					printf(
"\t\"char[]\",\t%s*sizeof(struct %s),\t%s%s,\n",
						dimString, st->tm_name, prefix,
						att->ta_name);
				} else {
					notSupported("arrays of unaligned structs");
				}
			} else {
				/* Array of scalars or strings */
				printf(
"\t\"%s[]\",\t%s,\t%s%s,\n",
					typeName(ty), dimString, prefix,
					att->ta_name);
			}

			free(dimString);
		} else {
			/* Not an array */
			if (ty == TY_STRUCT) {
				st = att->ta_type->u.st_template;
				if ((st->tm_flags & TMPL_TF_ALIGNED) != 0) {
					printf(
"\t\"char[]\",\tsizeof(struct %s),\t%s%s,\n",
						st->tm_name, prefix,
						att->ta_name);
				} else {
					/* Unaligned struct.  Print all its members. */
					size_t newPrefixSize = strlen(prefix)
						+ strlen(att->ta_name) + 1;
					char *newPrefix = (char*)
						malloc(newPrefixSize);
					assert(newPrefix != NULL);
					snprintf(newPrefix, newPrefixSize, "%s%s.", prefix,
						att->ta_name);
					printAttArgs(st, newPrefix);
					free(newPrefix);
				}
			} else {
				/* Not an array or struct */
				printf(
"\t\"%s\",\t%s%s,\n",
					typeName(ty), prefix, att->ta_name);
			}
		}
	}
}
예제 #4
0
void BRTKernelDef::PrintVoutPostfix(std::ostream & out) const{
   out << "    __vout_counter+=1.0f;"<<std::endl;
   FunctionType* ft = static_cast<FunctionType*>(decl->form);
   std::set<unsigned int >::iterator beginvout
      = voutFunctions[FunctionName()->name].begin();
   std::set<unsigned int >::iterator endvout
      = voutFunctions[FunctionName()->name].end();
   std::set<unsigned int >::iterator iter;
   std::set<unsigned int >::iterator inneriter;
   bool limited_vout=false;
   bool allone=true;
   unsigned int limited_vout_counter=0;
   unsigned int numlimits=0;
   for (iter = beginvout;iter!=endvout;++iter) {
      Decl * decl = ft->args[*iter];
      Expression * vout_limit = decl->form->getQualifiers().vout;
      if (vout_limit) {
        bool filter=isFilter(vout_limit);
        allone=(allone&&filter);
        
        if (limited_vout||beginvout==iter) {
          limited_vout=true;
          numlimits++;
        }
        else
          limited_vout=false;
      }
   }
   if (numlimits>1&&!allone){
     numlimits=0;
     limited_vout=false;
   }
   for (iter = beginvout;iter!=endvout;++iter) {
      Decl * decl = ft->args[*iter];
      Expression * vout_limit = decl->form->getQualifiers().vout;
      
      if (vout_limit&&limited_vout) {
        if (limited_vout_counter==0) out << "     if (";
        bool useparen=(vout_limit->precedence() < 
                       RelExpr(RO_Less,
                               NULL,
                               NULL,
                               vout_limit->location).precedence());
        // the above is a simple check for the common expressions.
        // no need to get fancy here for parens are ok in this case.
        out <<"(__vout_counter >= ";
        if (useparen) out << "(";
        vout_limit->print(out);
        if (useparen) out << ")";
        out << ")";
        limited_vout_counter++;
        if (limited_vout_counter==numlimits) {
           out <<") {"<<std::endl;
           for (inneriter = beginvout;inneriter!=endvout;++inneriter) {
              Decl * decl = ft->args[*inneriter];
              out <<"      ";
              out <<getDeclStream(decl,"_outputs")<<".push_back(0);"<<std::endl;
           }
           out <<"      ";              
           out <<"break;"<<std::endl;
           out <<"    }"<<std::endl;
        }else {
           out << "&&";
        }
      }else {
         out << "    "<<getDeclStream(decl,"_values")<< " = ";

         out << "(";
         out << decl->name->name<<"->getDimension()==2?";
         out << "finiteValueProduced"<<getDimensionString(2)<<undecoratedBase(decl);
         out << ":finiteValueProduced"<<getDimensionString(1);      
         out << undecoratedBase(decl)<<")(*"<<getDeclStream(decl,"_outputs");
         out << ".back())?1:0;"<<std::endl;
      }
   }
   out << "  }"<<std::endl;
   for (iter = beginvout;iter!=endvout;++iter) {
      
      Decl * decl = ft->args[*iter];
      out << "  if ("<<decl->name->name<<"->getDimension()==2) {"<<std::endl;
      PrintVoutDimensionalShift(out,decl,2);
      out << "  }else {"<<std::endl;
      PrintVoutDimensionalShift(out,decl,1);
      out << "  }"<<std::endl;
      out << "  while ("<<getDeclStream(decl,"_outputs")<<".size()) {";
      out << std::endl;
      out << "    if ("<<getDeclStream(decl,"_outputs")<<".back())"<<std::endl;
      out << "      delete "<<getDeclStream(decl,"_outputs")<<".back();";
      out << std::endl;
      out << "    "<<getDeclStream(decl,"_outputs")<<".pop_back();"<<std::endl;
      out << "  }"<<std::endl;
   }
}