Exemplo n.º 1
0
Arquivo: var.cpp Projeto: Aspenka/SSD
void Var::importFromJsonString(QString json)
{
        QJsonDocument parser = QJsonDocument::fromJson(json.toUtf8());
        Var var = fromQVariant(parser.toVariant());
        setType(var.getType());
        if(var.getType()=="list")
            List=var.List;
        if(var.getType()=="map")
            Map=var.Map;
        if(var.getType()=="string")
            String=var.String;
}
Exemplo n.º 2
0
Arquivo: var.cpp Projeto: Aspenka/SSD
bool Var::operator == (Var var) const
{
	if(Type==var.getType())
    {
		if(Type=="string")
			if(String==var.getString())
				return true;
		if(Type=="list")
			if(List.size()==var.getList().size())
            {
				for(int i=0;i<List.size();i++)
					if(List[i]!=var.getList()[i])
						return false;
				return true;
            }
		if(Type=="map")
			if(Map.size()==var.getMap().size())
            {
                for(QMap<QString, Var>::const_iterator i = Map.constBegin();i != Map.constEnd();i++)
					if(i.value()!=var.getMap().value(i.key()))
						return false;
				return true;
            }
    }
	return false;
}
Exemplo n.º 3
0
Arquivo: var.cpp Projeto: Aspenka/SSD
void Var::importFromJsonFile(QString filePath)
{
	QFile* file = new QFile(filePath);
	if(!file->open(QIODevice::ReadOnly))
    {
        qDebug()<<"Var::Var(QString filePath) - path is incorrect"<<filePath;
    }
	QString json = file->readAll();
	QJsonDocument parser = QJsonDocument::fromJson(json.toUtf8());
	Var var = fromQVariant(parser.toVariant());
	setType(var.getType());
	if(var.getType()=="list")
		List=var.List;		
	if(var.getType()=="map")
		Map=var.Map;		
	if(var.getType()=="string")
		String=var.String;		
}
Exemplo n.º 4
0
void bi::InputNetCDFBuffer::readMask0(const VarType type,
    Mask<ON_HOST>& mask) {
  typedef temp_host_matrix<real>::type temp_matrix_type;
  mask.resize(m.getNumVars(type), false);

  Var* var;
  int r;
  long start, len;

  /* sparse masks */
  for (r = 0; r < int(recDims.size()); ++r) {
    if (timeVars[r] < 0) {
      BOOST_AUTO(range, modelVars.equal_range(r));
      BOOST_AUTO(iter, range.first);
      BOOST_AUTO(end, range.second);

      start = 0;
      len = nc_inq_dimlen(ncid, recDims[r]);

      temp_matrix_type C(iter->second->getNumDims(), len);
      readCoords(coordVars[r], start, len, C);
      for (; iter != end; ++iter) {
        var = iter->second;
        if (var->getType() == type) {
          mask.addSparseMask(var->getId(), C.size2());
          serialiseCoords(var, C, mask.getIndices(var->getId()));
        }
      }
    }
  }

  /* dense masks */
  r = -1;  // for those vars not associated with a record dimension
  BOOST_AUTO(range, modelVars.equal_range(r));
  BOOST_AUTO(iter, range.first);
  BOOST_AUTO(end, range.second);

  for (; iter != end; ++iter) {
    var = iter->second;
    if (var->getType() == type) {
      mask.addDenseMask(var->getId(), var->getSize());
    }
  }
}
Exemplo n.º 5
0
void bi::InputNetCDFBuffer::readMask(const size_t k, const VarType type,
    Mask<ON_HOST>& mask) {
  typedef temp_host_matrix<real>::type temp_matrix_type;

  mask.resize(m.getNumVars(type), false);

  Var* var;
  int r;
  long start, len;
  for (r = 0; r < int(recDims.size()); ++r) {
    if (timeVars[r] >= 0) {
      start = recStarts[k][r];
      len = recLens[k][r];

      if (len > 0) {
        BOOST_AUTO(range, modelVars.equal_range(r));
        BOOST_AUTO(iter, range.first);
        BOOST_AUTO(end, range.second);

        if (coordVars[r] >= 0) {
          /* sparse mask */
          temp_matrix_type C(iter->second->getNumDims(), len);
          readCoords(coordVars[r], start, len, C);
          for (; iter != end; ++iter) {
            var = iter->second;
            if (var->getType() == type) {
              mask.addSparseMask(var->getId(), len);
              serialiseCoords(var, C, mask.getIndices(var->getId()));
            }
          }
        } else {
          /* dense mask */
          for (; iter != end; ++iter) {
            var = iter->second;
            if (var->getType() == type) {
              mask.addDenseMask(var->getId(), var->getSize());
            }
          }
        }
      }
    }
  }
}
Exemplo n.º 6
0
Arquivo: var.cpp Projeto: Aspenka/SSD
void Var::unite(Var var)
{
	if(getType()!="map")
    {
        qDebug()<<"Var::unite current var is not a map!";
		return;
    }
	if(var.getType()!="map")
    {
        qDebug()<<"Var::unite passed var is not a map!";
		return;
    }
	Map.unite(var.Map);
}
Exemplo n.º 7
0
Stmt lowerTranspose(Var target, const IndexExpr* iexpr,
                    Environment* env, Storage* storage) {
  simit_iassert(isa<IndexedTensor>(iexpr->value));
  simit_iassert(isa<VarExpr>(to<IndexedTensor>(iexpr->value)->tensor));

  Var source = to<VarExpr>(to<IndexedTensor>(iexpr->value)->tensor)->var;
  auto sourceIndex = storage->getStorage(source).getTensorIndex();
  auto targetIndex = storage->getStorage(target).getTensorIndex();

  auto sourceType = source.getType().toTensor();
  auto iRange   = sourceType->getOuterDimensions()[0];

  Var  i("i",  Int);
  Var ij("ij", Int);
  Var  j("j",  Int);

  Var locVar(INTERNAL_PREFIX("locVar"), Int);
  Stmt locStmt = CallStmt::make({locVar}, intrinsics::loc(),
                                {Load::make(sourceIndex.getColidxArray(),ij), i,
                                 targetIndex.getRowptrArray(),
                                 targetIndex.getColidxArray()});
  Stmt body;
  auto blockType = *sourceType->getBlockType().toTensor();
  if (blockType.order() == 0) {  // Not blocked
    body = Store::make(target, locVar, Load::make(source, ij));
  }
  else {  // Blocked
    simit_iassert(blockType.order() == 2);
    Var ii("ii", Int);
    Var jj("jj", Int);
    auto d1 = blockType.getOuterDimensions()[0];
    auto d2 = blockType.getOuterDimensions()[1];
    Expr l1 = Length::make(d1);
    Expr l2 = Length::make(d2);

    body = Store::make(target, locVar*l1*l2 + ii*l2 + jj,
                       Load::make(source, ij*l1*l2 + ii*l2 + jj));

    body = For::make(jj, ForDomain(d2), body);
    body = For::make(ii, ForDomain(d1), body);
  }
  simit_iassert(body.defined());

  Expr start = Load::make(sourceIndex.getRowptrArray(), i);
  Expr stop  = Load::make(sourceIndex.getRowptrArray(), i+1);
  Stmt innerLoop  = ForRange::make(ij, start, stop, Block::make(locStmt, body));
  return For::make(i, iRange, innerLoop);
}
Exemplo n.º 8
0
Arquivo: var.cpp Projeto: Aspenka/SSD
void Var::append(Var var)
{
	if(Type=="list")
    {
		if(var.getType()=="list")
        {
			for(int i=0;i<var.size();i++)
				List.append(var[i]);
        }
		else
        {
			List.append(var);
        }
    }
	else
		qDebug()<<"Var::append - type is not list; Name = "<<Name<<"Type = "<<Type;
}
Exemplo n.º 9
0
void Engine::blockCurrentSol() {
	if (outputs.size() == 0) NOT_SUPPORTED;
	Clause& c = *Reason_new(outputs.size());
	bool root_failure = true;
	for (int i = 0; i < outputs.size(); i++) {
		Var *v = (Var*) outputs[i];
		if (v->getType() == BOOL_VAR) {
			c[i] = ((BoolView*) outputs[i])->getValLit();
		} else {
			c[i] = ((IntVar*) outputs[i])->getValLit();
		}
		if (!sat.isRootLevel(var(c[i]))) root_failure = false;
		assert(sat.value(c[i]) == l_False);
	}
	if (root_failure) sat.btToLevel(0);
	sat.confl = &c;
}
Exemplo n.º 10
0
// When this function returns, tree must point to the last node in the SUB
// header (the return type).
bool Component::paramListsEqual(Token *&tree, Sub *sub) const {
    
    unsigned int index = 0;
    Var *var = sub->getVar(0);
    
    // Can't use an early return because of pre-requirement (see above).
    bool iseq = true;
    
    while (tree->id == DEF) {
        // Check if the pre-existing list is shorter
        if (!var) {
            iseq = false;
            tree = tree->next;
            continue;
        }
        
        const Type *type = getType(tree->child);
        std::string newname;
        
        if (!type)
            iseq = false;
        else if (*type != *var->getType())
            iseq = false;
        else if (!strEqualIdLookup(var->getName(),
                newname = tree->child->next->text)) {
        
            printf("warning: param names differ from DECLARE to SUB, "
                "using '%s' instead of '%s' (line %d)\n",
                tree->child->next->text, var->getName().c_str(),
                tree->child->next->loc.first_line);
            
            // MUST NOT call var->setName, otherwise sub's var map won't
            // get updated.
            if (!sub->setVarName(var->getName(), newname)) {
                printf("Just kidding; there was a conflict with that "
                    "name. I'm still gonna try to compile this, but you "
                    "should really consider synchronizing the names.\n");
            }
        }
        
        var = sub->getVar(++index);
        tree = tree->next;
    }
    
    SubType *subty = const_cast<SubType *>(
        static_cast<const SubType *>(sub->getType())
    );
    
    // Does it have var-args?
    if (tree->id == ELLIPSIS) {
        if ((subty->getFlags() & SubType::VARARGS) == 0)
            iseq = false;
        else if (tree->child) {
            // Is it an implicit len or null?
            if (tree->child->id == LEN &&
                    ((subty->getFlags() & SubType::VA_IMPLICIT_LEN) == 0))
                iseq = false;
            else if (tree->child->id == INTCONST &&
                    ((subty->getFlags() & SubType::VA_IMPLICIT_NULL) == 0))
                iseq = false;
        }
            
        tree = tree->next;
    } else {
        if ((subty->getFlags() & SubType::VARARGS) != 0)
            iseq = false;
    }
    
    assert(tree->id == AS && "no return type for sub");
    
    // If any of the params were not equal, it doesn't matter what the return
    // type is, and we can just return false here. Also make sure the
    // pre-existing list is the same length.
    if (!iseq || var)
        return false;
    
    // Make sure the return types are equal also.
    const Type *other_rettype = subty->getReturnType();
    
    // If you left off the return type from the SUB, it is carried over from
    // the declare, but a warning is shown.
    if (tree->child == 0) {
        if (*other_rettype != *void_type) {
            printf("warning: omitted return type, using '%s' (line %d)\n",
                other_rettype->getName().c_str(), tree->loc.first_line);
        }
        return true;
    }
    
    const Type *rettype = getType(tree->child);
    return rettype && *rettype == *other_rettype;
}
Exemplo n.º 11
0
void print_controller_C(ostream& out, string component, const StateMachine& machine)
{
  out << "// Auto generated C++ code started by "<<__FILE__<<":"<<__LINE__<< endl;
  out << "// " << machine.getIdent() << ": " << machine.getShorthand() << endl;
  out << endl;
  out << "#include \"Global.h\"" << endl;
  out << "#include \"slicc_util.h\"" << endl;
  out << "#include \"" << component << "_Controller.h\"" << endl;
  out << "#include \"" << component << "_State.h\"" << endl;
  out << "#include \"" << component << "_Event.h\"" << endl;
  out << "#include \"Types.h\"" << endl;
  out << "#include \"Profiler.h\"" << endl;
  out << "#include \"Network.h\"" << endl;
  out << endl;

  out << "// static profiler defn" << endl;
  out << component << "_Profiler " << component << "_Controller::s_profiler;" << endl;
  out << endl;

  out << "// constructor" << endl;
  out << component << "_Controller::" << component << "_Controller(NodeID id, Network* network_ptr)" << endl;
  out << "{" << endl;
  out << "  m_id = id;" << endl;

  // Initialize member variables
  const Vector<Symbol*>& symbols = g_sym_table.getAllSymbols();
  for (int i=0; i < symbols.size(); i++) {
    Var* var = dynamic_cast<Var*>(symbols[i]);
    if (var == NULL || var->getMachine() != &machine) {
      continue;
    }
    out << "  // " << var->cIdent() << endl;
    if (var->existPair("network")) {
      // Network port object
      string network = var->lookupPair("network");
      string ordered =  var->lookupPair("ordered");
      string vnet =  var->lookupPair("virtual_network");
      
      out << "  m_" << var->cIdent() << "_ptr = network_ptr->get" 
          << network << "NetQueue(MachineType_" << var->getMachine()->getIdent() << ", m_id, " 
          << ordered << ", " << vnet << ");\n";
    } else if (var->getType()->existPair("primitive") || (dynamic_cast<Enum*>(var->getType()) != NULL)) {
      // Normal non-object
      out << "  m_" << var->cIdent() << "_ptr = new " << var->getType()->cIdent() << ";\n";
    } else {
      // Normal Object
      out << "  m_" << var->cIdent() << "_ptr = new " << var->getType()->cIdent();
      if (!var->getType()->existPair("non_obj")) {
        if (var->existPair("constructor_hack")) {
          string constructor_hack = var->lookupPair("constructor_hack");
          out << "(m_id, " << constructor_hack << ")";
        } else {
          out << "(m_id)";
        }
        out << ";\n";
      }
    }
    out << "  assert(m_" << var->cIdent() << "_ptr != NULL);" << endl;

    // Set to the default value
    if (var->existPair("default")) {
      out << "  (*m_" << var->cIdent() << "_ptr) = " << var->lookupPair("default") 
          << "; // Object default" << endl;
    } else if (var->getType()->hasDefault()) {
      out << "  (*m_" << var->cIdent() << "_ptr) = " << var->getType()->getDefault() 
          << "; // Type " << var->getType()->getIdent() << " default" << endl;
    }
    
    // Set ordering
    if (var->existPair("ordered")) {
      // A buffer
      string ordered =  var->lookupPair("ordered");
      out << "  m_" << var->cIdent() << "_ptr->setOrdering(" << ordered << ");\n";
    }
    
    // Set randomization
    if (var->existPair("random")) {
      // A buffer
      string value =  var->lookupPair("random");
      out << "  m_" << var->cIdent() << "_ptr->setRandomization(" << value << ");\n";
    }
    out << endl;
  }

  // Set the queue consumers
  for(int i=0; i < machine.numInPorts(); i++) {
    out << "  " << machine.getInPort(i).getCode() << ".setConsumer(this);" << endl;
  }

  out << endl;
  // Set the queue descriptions
  for(int i=0; i < machine.numInPorts(); i++) {
    out << "  " << machine.getInPort(i).getCode() 
        << ".setDescription(\"[Node \" + int_to_string(m_id) + \", " 
        << component << ", " << machine.getInPort(i).toString() << "]\");" << endl;
  }

  // Initialize the transition profiling
  out << endl;
  for(int i=0; i<machine.numTransitions(); i++) {
    const Transition& t = machine.getTransition(i);
    const Vector<Action*>& action_vec = t.getActions();
    int numActions = action_vec.size();

    // Figure out if we stall
    bool stall = false;
    for (int i=0; i<numActions; i++) {
      if(action_vec[i]->getIdent() == "z_stall") {
        stall = true;
      }
    }

    // Only possible if it is not a 'z' case
    if (!stall) {
      out << "  s_profiler.possibleTransition(" << component << "_State_"
          << t.getStatePtr()->getIdent() << ", " << component << "_Event_"
          << t.getEventPtr()->getIdent() << ");" << endl;
    }
  }

  out << "}" << endl;

  out << endl;

  {
    out << component << "_Controller::~" << component << "_Controller()" << endl;
    out << "{" << endl;
    const Vector<Symbol*>& symbols = g_sym_table.getAllSymbols();
    for (int i=0; i < symbols.size(); i++) {
      Var* var_ptr = dynamic_cast<Var*>(symbols[i]);
      if (var_ptr == NULL || var_ptr->getMachine() != &machine) {
        continue;
      }
      if (!var_ptr->existPair("network")) {
        // Normal Object
        out << "  delete m_" << var_ptr->cIdent() << "_ptr;\n";
      }
    }
    out << "}" << endl;
  }

  {  
    out << endl;
    out << "void " << component << "_Controller::printConfig(ostream& out)\n";
    out << "{\n";
    out << "  out << heading(\"" << component << " Config\");\n";
    
    const Vector<Symbol*>& symbols = g_sym_table.getAllSymbols();
    for (int i=0; i < symbols.size(); i++) {
      Var* var_ptr = dynamic_cast<Var*>(symbols[i]);
      if (var_ptr == NULL || var_ptr->getMachine() != &machine) {
        continue;
      }
      if (!var_ptr->existPair("network") && (!var_ptr->getType()->existPair("primitive"))) {
        // Normal Object
        out << "  m_" << var_ptr->cIdent() << "_ptr->printConfig(out);\n";
      }

    }
    out << "  out << endl;\n";
    out << "}" << endl;
  }
  
  out << endl;
  out << "void " << component << "_Controller::print(ostream& out) const { out << \"[" << component 
      << "_Controller \" << m_id << \"]\"; }" << endl;

  out << endl;
  out << "// Actions" << endl;
  out << endl;

  for(int i=0; i < machine.numActions(); i++) {
    const Action& action = machine.getAction(i);
    if (action.existPair("c_code")) {
      out << "//" << action.getDescription() << endl;
      out << "void " << component << "_Controller::" 
          << action.getIdent() << "(const Address& addr)" << endl;
      out << "{" << endl;
      out << "  DEBUG_MSG(GENERATED_COMP, HighPrio,\"executing\");" << endl;
      out << action.lookupPair("c_code");
      out << "}" << endl;
    }
    out << endl;
  }

  // Function definitions
  {
    const Vector<Symbol*>& symbols = g_sym_table.getAllSymbols();
    for (int i=0; i < symbols.size(); i++) {
      Func* func_ptr = dynamic_cast<Func*>(symbols[i]);
      if (func_ptr == NULL || func_ptr->getMachine() != &machine) {
        continue;
      }
      string code;
      func_ptr->funcDefinition(code);
      out << code;
    }
  }
}