Example #1
0
POETCode* EvaluatePOET::
eval_readInput_nosyntax(POETCode* inputFiles, POETCode* codeType, POETCode* inputInline)
{ 
  inputFiles = eval_AST(inputFiles);
  std::cerr << "Using ROSE Parser for " << inputFiles->toString() << "\n";
  std::vector<std::string> argvList;
  argvList.push_back("pcg_rose");

  for (std::list<std::string>::const_iterator p_lib = lib_dir.begin();
        p_lib != lib_dir.end(); ++p_lib) {
     std::string cur_dir=(*p_lib);
     argvList.push_back("-I"+cur_dir);
  }
  for (POETCode* p = inputFiles; p != 0; p = get_tail(p))
  {
     std::string curname = p->toString(OUTPUT_NO_DEBUG);
     assert(curname != "");
     if (curname.find("/") == curname.npos) {
        for (std::list<std::string>::const_iterator p_lib = lib_dir.begin();
             p_lib != lib_dir.end(); ++p_lib) {
            std::string cur_dir=(*p_lib) + "/" + curname;
            if (access(cur_dir.c_str(), R_OK) == 0) 
               { curname = cur_dir; break;}
        }
     }
     argvList.push_back(curname);
  }
  assert(argvList.size() > 1);
  SgProject *sageProject = new SgProject ( argvList);

/*TODO: must add support for inserting trace handles. optimization won't work otherwise*/

  return POETAstInterface::Ast2POET(sageProject);
}
Example #2
0
std::string POETTuple :: toString(ASTOutputEnum config)
{ 
    std:: stringstream r;
    r << "(";
    for (unsigned i = 0; i < impl.size(); ++i) {
       POETCode* cur = impl[i];
       if (cur == 0) r << "NULL,";
       else if (cur->get_enum() == SRC_LIST) 
           r << "(" << cur->toString(config) << "),";
       else
           r << cur->toString(config) << ",";
    }
    std::string str = r.str();
    str[str.size()-1] = ')' ; 
    return str;
  }
Example #3
0
LocalVar* POETProgram::
set_local_static(LvarSymbolTable* local, POETCode* id, 
                 LocalVarType t, POETCode* code, POETCode * restr, bool insert)
{
  assert(local != 0);
  LocalVar* lvar = local->find(id);
  POETCode* orig = 0;
  if (lvar == 0) {
     if (insert) {
       lvar = local->insert(id, t);
       lvar->get_entry().set_code(code);
       lvar->get_entry().set_restr(restr);
     }
     else SYM_UNDEFINED(id->toString()+"="+code->toString());
  }
  else if (code != 0 && (orig = lvar->get_entry().get_code()) != 0 && orig != code && !match_AST(orig, code, MATCH_AST_EQ)) {
       SYM_DIFF_DEFINED(id->toString()+"="+code->toString(), orig->toString());
   }
  else {
      if (code != 0)
         lvar->get_entry().set_code(code);
      if (restr != 0)
          lvar->get_entry().set_restr(restr);
  }
  return lvar;
}
void ReadFiles(POETCode* _files, LexState _lexStateStart, std::list<POETProgram*>& resultFiles)
{
   POETCode* files = eval_AST(_files);
   POETCode* p_files=files;
   while (p_files != 0) {
       POETList* fileList = dynamic_cast<POETList*>(p_files);
       POETCode* fileCur = p_files;
       if (fileList != 0) {
              fileCur = fileList->get_first();
              p_files=fileList->get_rest();
        }
       else  p_files = 0;
       
       std::string fname= fileCur->toString(OUTPUT_NO_DEBUG); 
       if (fname == "") {
          std::cerr << "Empty file name: " << fileCur->toString() << " from list " << files->toString() << "\n";
       } 
       lexState = _lexStateStart;
       POETProgram* programFile =  process_file(fname.c_str());
       resultFiles.push_back(programFile);
       lexState=LEX_DEFAULT;
    }
}
Example #5
0
std::string LocalVar:: toString(ASTOutputEnum config)
      { 
        std::string str = entry.get_name()->toString(OUTPUT_NO_DEBUG) ;
        if ((config & OUTPUT_VAR_VAL) 
            || ((config & OUTPUT_TRACE_VAL) && entry.get_entry_type() == LVAR_TRACE)) {
              POETCode* res = entry.get_code(); 
              if (res != 0 && res != this) {
                 entry.set_code(0);
                 str = str + "={" + res->toString(config) + "}";
                 entry.set_code(res);
              }
        }
        if (config & OUTPUT_VAR_RESTR && entry.get_restr() != 0) {
           str = "(" + str + ":" + entry.get_restr()->toString() + ")";
        }
        return str;
      }
 virtual void visitTupleAccess(TupleAccess* fc) 
    { 
     try {
      POETCode* tuple = apply(fc->get_tuple());
      POETCode* tuple1 = EvalTrace(tuple);
      if (tuple1 == 0) SYM_UNDEFINED(tuple->toString())
      else tuple = tuple1;
      POETCode* access= EvalTrace(fc->get_access()); 
      switch (tuple->get_enum()) {
        case SRC_TUPLE: {
           access= apply(access);
           if (access->get_enum() == SRC_LVAR) {
             LvarSymbolTable::Entry e = static_cast<LocalVar*>(access)->get_entry();
             if (e.get_entry_type() == LVAR_OUTPUT) access = e.get_code(); 
             else TUPLE_ACC_MISMATCH(fc, tuple,access);
           }
           res = eval_tuple_access(tuple,access);
           if (res == 0) { TUPLE_ACC_MISMATCH(fc, tuple,access); }
           return;
         }
        case SRC_MAP: {
           POETMap* m = static_cast<POETMap*>(tuple);
           access= apply(access);
           res = m->find(access);
           if (res == 0) 
               res = EMPTY;
           return;
        }
        case SRC_CVAR: {
           CodeVar* cv = static_cast<CodeVar*>(tuple);
           CvarSymbolTable::Entry cv_e = cv->get_entry();
           LvarSymbolTable* symTable = cv_e.get_symTable();
           res = eval_cvar_access(cv, access);
           return;
        }
        default: { 
           res = eval_tuple_access(tuple,access);
           if (res == 0)
            TUPLE_ACC_MISMATCH( fc, tuple, access); 
          }
       }
     }
     catch (Error err) { std::cerr << "From invoking " << SHORT(fc->toString(),500) << "\n"; throw err; }
    } 
Example #7
0
 void output(POETString* s) {  
       ASTFactory* fac = ASTFactory::inst();
       std::string r = s->get_content();
       if (r == "\n") {
           for (int i = 0; i < align; ++i) r = r + " ";
           s = fac->new_string(r);
       }
       if (output_xform == 0) 
            output_content(r,r); 
       else {
          POETCode* args = fac->new_pair(s, fac->new_iconst(cur_pos));
          if (!match_parameters(output_xform->get_entry().get_param(), args,
                        MATCH_PAR_MOD_CODE))
               INCORRECT_XFORM_DEF("output(string,cur_pos)", output_xform->toString()); 
          XformVarInvoke invoke(output_xform->get_entry(), output_xform->get_config(), args);
          POETCode* res = invoke.eval(0);
          output_content(res->toString(OUTPUT_NO_DEBUG),r);
       }
    }
POETCode* TraceEval(POETCode* vars, POETCode* res)
{
  std::vector<LocalVar*> vec;
  switch (vars->get_enum()) {
  case SRC_LVAR: {
     LocalVar* lvar = static_cast<LocalVar*>(vars);
     vec.push_back(lvar);
     break;
  }
 case SRC_LIST: {
   POETList* l = static_cast<POETList*>(vars);
   while (l != 0) {
     POETCode* cur = l->get_first();
     if (cur->get_enum() != SRC_LVAR) INCORRECT_TRACE_HANDLE(cur->toString());
     vec.push_back(static_cast<LocalVar*>(cur));
     l = dynamic_cast<POETList*>(l->get_rest());
   }
  } 
   break;
 default: INCORRECT_TRACE_HANDLE(vars->toString()); 
 }
 for (int i = vec.size()-1; i >= 0; --i) {
    LocalVar* lvar = vec[i];
    LvarSymbolTable::Entry entry = lvar->get_entry();
    entry.push(true);
    entry.set_entry_type(LVAR_TRACE);
 }
 res = eval_AST(res);
 for (int i = vec.size()-1; i >= 0; --i) {
    LocalVar* lvar = dynamic_cast<LocalVar*>(vec[i]);
    assert(lvar != 0);
    LvarSymbolTable::Entry entry = lvar->get_entry();
    POETCode* val = entry.get_code();
    entry.pop();
    entry.set_code(val);
 }
 return res;
}
Example #9
0
void POETProgram:: write_to_file(std::ostream& out)
{  
  int lineNo=0;
  for (std::list<POETProgram*>::const_iterator 
           pincludeFiles = includeFiles.begin();
           pincludeFiles!=includeFiles.end(); ++pincludeFiles) {
        POETProgram* cur = (*pincludeFiles);
        out << "include " << cur->get_filename() << "\n";
        ++lineNo;
  }
  for (const_iterator pdef = define.begin(); pdef != define.end(); ++pdef) {
       POETCode* cur = *pdef;
       const FileInfo* curFile = cur->get_fileinfo();
       if (curFile != 0) {
           while (lineNo < curFile->get_lineno()) {
               out << "\n"; ++lineNo;
           }
       }
       switch (cur->get_enum())
       {
       case SRC_WRITE_OUTPUT: case SRC_READ_INPUT: case SRC_PARAM_DECL:
       case SRC_TRACE_DECL:
          out << cur->toString(DEBUG_NO_VAR) << "\n"; ++lineNo; break;
       case SRC_CVAR: 
         {
          CodeVar* cvar = static_cast<CodeVar*>(cur);
          out << "<code " << cvar->toString();
          const CodeDefSave& def = codeDef[cvar];
          unsigned par_size = def.par_type.size();
          if (par_size > 0) {
             out << " pars=(";
             for (unsigned i = 0; i < par_size; ++i) 
             {
               const LocalVarSave& par_save = def.par_type[i];
               assert(par_save.lvar != 0); 
               out << par_save.lvar->get_entry().get_name();
               if (par_save.restr != 0)
                   out << ":" << par_save.restr->toString(DEBUG_NO_VAR);
               if (i < par_size) out << ",";
             } 
             out << ")";
          }
          CvarSymbolTable::Entry cvar_entry = cvar->get_entry();
          for (unsigned i = 0; i < cvar_entry.attr_size(); ++i) {
             LocalVar* v = cvar_entry.get_attr(i); 
             out << " " << v->get_entry().get_name()->toString(OUTPUT_NO_DEBUG) << "=" << v->get_entry().get_code()->toString(DEBUG_NO_VAR);
          } 
          out << "/>\n";++lineNo;  
          break;
         } 
       case SRC_LVAR:
         {
          LocalVar* cur_var = static_cast<LocalVar*>(cur);
          switch (cur_var->get_entry().get_entry_type())
          {
           case LVAR_TUNE:
              out << "<define " << cur->toString(OUTPUT_NO_DEBUG) << "/>\n";
              ++lineNo;  
              break;
           default:
                std::cerr << "Something is wrong. Unexpected var decl at global scope: " << cur->toString(DEBUG_OUTPUT) << "\n"; 
               assert(0);
          }
          break;
         }
       case SRC_EVAL: // eval command
          if (dynamic_cast<POETCondExp*>(cur) != 0)
               out << "<cond ";
          else out << "<eval ";
          Write_POET_Exp write(out,6);
          lineNo += write(cur);
          out << "/>\n"; ++lineNo;
      }
   }
}
Example #10
0
void set_code_xform_parameters( Entry e, POETCode* par) 
{
   POETCode* p = e.get_param();
   if (p == 0) 
      e.set_param(par); 
   else {
     if (p != par && !match_AST(p, par, MATCH_AST_EQ))  {
       std::cerr << "par=" << par << "; p = " << p << "\n";
        SYM_DIFF_DEFINED(par->get_className() + ":" + par->toString(OUTPUT_VAR_VAL), p->get_className() + ":" + p->toString(OUTPUT_VAR_VAL)); 
     }
     return;
   }
   switch (par->get_enum()) {
   case SRC_LVAR:  
      static_cast<LocalVar*>(par)->get_entry().set_code(ASTFactory::inst()->new_iconst(0));
      break;
   case SRC_TUPLE: {
      POETTuple* vec = static_cast<POETTuple*>(par);
      for (unsigned i = 0; i < vec->size(); ++i)
       {
         LocalVar* cur_par = dynamic_cast<LocalVar*>(vec->get_entry(i));
         assert (cur_par != 0);
         cur_par->get_entry().set_code(ASTFactory::inst()->new_iconst(i) );
       }
      break;
   }
   default:
      assert(false);
   }
}