Exemplo n.º 1
0
void FB_TP::executeEvent(int pa_nEIID){
  if(pa_nEIID == scm_nEventREQID){
      if (edgeFlag) {
        if(ET() >= PT()){
          Q() = false;
          edgeFlag = false;
          DEVLOG_DEBUG("top\n");
        }else{
          ET() = TIME() - start;
          DEVLOG_DEBUG("rising\n");
        }
      }
      else {
        if(IN() == true && ET() == 0){
          Q() = true;
          edgeFlag = true;
          start = TIME();
          DEVLOG_DEBUG("start\n");
        }
        else
          if((false == IN()) && (ET()>0)) {
            ET() = 0;
            DEVLOG_DEBUG("reset\n");
          }
      }
      sendOutputEvent(scm_nEventCNFID);
  }
}
Exemplo n.º 2
0
void FB_TOF::executeEvent(int pa_nEIID){
  if(scm_nEventREQID == pa_nEIID){
    if(IN() == true){
      Q() = true;
      ET() = 0;
      fallingEdge = false;
      notFirstRisingEdge = true;
      start = 0;
    }
    else{
      if(true == notFirstRisingEdge){
        if(fallingEdge == false){
          fallingEdge = true;
          start = TIME();
        }
        else{
          count = TIME() - start;
          if(PT() <= count){
            Q() = false;
            ET() = PT();
          }else{
            ET() = count;
          }
        }
      }
    }
    sendOutputEvent(scm_nEventCNFID);
  }
}
Exemplo n.º 3
0
typename QP_solver<Rep_>::ET  QP_solver<Rep_>::
multiply__A_ixO(int row) const
{
  ET value = et0;

  for (int i = 0; i < qp_n; ++i)
    // Note: the following computes
    //
    //   value += original_variable_value(i) * qp_A[i][row];
    //
    // but for efficiency, we only add summands that are known to be
    // nonzero.
    switch (x_O_v_i[i]) {
    case UPPER:
      value += ET(qp_u[i]) * qp_A[i][row];
      break;
    case LOWER:
    case FIXED:
      value += ET(qp_l[i]) * qp_A[i][row];
      break;
    case BASIC:
      CGAL_qpe_assertion(false);
    default:
      break;
    }

  return value;
}
Exemplo n.º 4
0
void FB_TON::executeEvent(int pa_nEIID){
  if(scm_nEventREQID == pa_nEIID){
    if(IN() == false){
      Q() = false;
      ET() = 0;
      risingEdge = false;
      start = 0;
    }
    else{
      if(risingEdge == false){
        risingEdge = true;
        start = TIME();
      }else{
        count = TIME() - start;
        if(PT() <= count){
          Q() = true;
          ET() = PT();
        }else{
          ET() = count;
        }
      }
    }
    sendOutputEvent(scm_nEventCNFID);
  }
}
Exemplo n.º 5
0
int
rumpuser_iovwrite(int fd, const struct rumpuser_iovec *ruiov, size_t iovlen,
	int64_t roff, size_t *retp)
{
	const struct iovec *iov = (const struct iovec *)ruiov;
	off_t off = (off_t)roff;
	ssize_t nn;
	int rv;

	if (off == RUMPUSER_IOV_NOSEEK) {
		KLOCK_WRAP(nn = writev(fd, iov, iovlen));
	} else {
		int nlocks;

		rumpkern_unsched(&nlocks, NULL);
		if (lseek(fd, off, SEEK_SET) == off) {
			nn = writev(fd, iov, iovlen);
		} else {
			nn = -1;
		}
		rumpkern_sched(nlocks, NULL);
	}

	if (nn == -1) {
		rv = errno;
	} else {
		*retp = (size_t)nn;
		rv = 0;
	}

	ET(rv);
}
Exemplo n.º 6
0
int
rumpuser_clock_gettime(int enum_rumpclock, int64_t *sec, long *nsec)
{
	enum rumpclock rclk = enum_rumpclock;
	struct timespec ts;
	clockid_t clk;
	int rv;

	switch (rclk) {
	case RUMPUSER_CLOCK_RELWALL:
		clk = CLOCK_REALTIME;
		break;
	case RUMPUSER_CLOCK_ABSMONO:
#ifdef HAVE_CLOCK_NANOSLEEP
		clk = CLOCK_MONOTONIC;
#else
		clk = CLOCK_REALTIME;
#endif
		break;
	default:
		abort();
	}

	if (clock_gettime(clk, &ts) == -1) {
		rv = errno;
	} else {
		*sec = ts.tv_sec;
		*nsec = ts.tv_nsec;
		rv = 0;
	}

	ET(rv);
}
Exemplo n.º 7
0
int
rumpuser_clock_sleep(int enum_rumpclock, int64_t sec, long nsec)
{
	enum rumpclock rclk = enum_rumpclock;
	struct timespec rqt, rmt;
	int nlocks;
	int rv;

	rumpkern_unsched(&nlocks, NULL);

	/*LINTED*/
	rqt.tv_sec = sec;
	/*LINTED*/
	rqt.tv_nsec = nsec;

	switch (rclk) {
	case RUMPUSER_CLOCK_RELWALL:
		do {
			rv = nanosleep(&rqt, &rmt);
			rqt = rmt;
		} while (rv == -1 && errno == EINTR);
		if (rv == -1) {
			rv = errno;
		}
		break;
	case RUMPUSER_CLOCK_ABSMONO:
		do {
#ifdef HAVE_CLOCK_NANOSLEEP
			rv = clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME,
			    &rqt, NULL);
#else
			/* le/la/der/die/das sigh. timevalspec tailspin */
			struct timespec ts, tsr;
			clock_gettime(CLOCK_REALTIME, &ts);
			if (ts.tv_sec == rqt.tv_sec ?
			    ts.tv_nsec > rqt.tv_nsec : ts.tv_sec > rqt.tv_sec) {
				rv = 0;
			} else {
				tsr.tv_sec = rqt.tv_sec - ts.tv_sec;
				tsr.tv_nsec = rqt.tv_nsec - ts.tv_nsec;
				if (tsr.tv_nsec < 0) {
					tsr.tv_sec--;
					tsr.tv_nsec += 1000*1000*1000;
				}
				rv = nanosleep(&tsr, NULL);
			}
#endif
		} while (rv == -1 && errno == EINTR);
		if (rv == -1) {
			rv = errno;
		}
		break;
	default:
		abort();
	}

	rumpkern_sched(nlocks, NULL);

	ET(rv);
}
Exemplo n.º 8
0
void testUtf8String(std::string const & fn)
{
	::libmaus::util::Utf8String::shared_ptr_type us = ::libmaus::util::Utf8String::constructRaw(fn);
	::libmaus::util::Utf8StringPairAdapter usp(us);
	
	::libmaus::util::Utf8DecoderWrapper decwr(fn);
	uint64_t const numsyms = ::libmaus::util::GetFileSize::getFileSize(decwr);
	assert ( us->size() == numsyms );

	for ( uint64_t i = 0; i < numsyms; ++i )
	{
		assert ( static_cast<wchar_t>(decwr.get()) == us->get(i) );
		assert ( 
			us->get(i) ==
			((usp[2*i] << 12) | (usp[2*i+1]))
		);
	}
	
	::std::map<int64_t,uint64_t> const chist = us->getHistogramAsMap();
	::libmaus::huffman::HuffmanTreeNode::shared_ptr_type htree = ::libmaus::huffman::HuffmanBase::createTree(chist);
	::libmaus::huffman::EncodeTable<1> ET(htree.get());
	
	for ( ::std::map<int64_t,uint64_t>::const_iterator ita = chist.begin(); ita != chist.end(); ++ita )
	{
		::libmaus::util::UTF8::encodeUTF8(ita->first,std::cerr);
		std::cerr << "\t" << ita->second << "\t" << ET.printCode(ita->first) << std::endl;
	}
}
Exemplo n.º 9
0
void CGAL_Solver::solve(const hough_min_max::P3 points[]) {
  for(int i=0; i<n; i++) {
    A[0][i] = points[i].x;
    A[1][i] = points[i].y;
    A[2][i] = -1;
    b[i] = points[i].z;
  }
  A[0][n] = 1;
  A[1][n] = 1;
  A[2][n] = 0;
  b[n] = 1;
  
  timeval t1, t2;
  gettimeofday(&t1, NULL);
  Solution s = CGAL::solve_nonnegative_linear_program(*lp, ET());
  gettimeofday(&t2, NULL);
  time += (t2.tv_sec - t1.tv_sec) * 1000.0;      // sec to ms
  time += (t2.tv_usec - t1.tv_usec) / 1000.0;   // us to ms

  release_assert(!s.is_infeasible());
  bounded = !s.is_unbounded();
  
  value = CGAL::to_double(s.objective_value());
  u = CGAL::to_double(*s.variable_values_begin());
  v = CGAL::to_double(*(s.variable_values_begin()+1));
}
Exemplo n.º 10
0
int
rumpuser_sp_anonmmap(void *arg, size_t howmuch, void **addr)
{
	struct spclient *spc = arg;
	void *resp, *rdata = NULL; /* XXXuninit */
	int nlocks, rv;

	rumpkern_unsched(&nlocks, NULL);

	rv = anonmmap_req(spc, howmuch, &rdata);
	if (rv) {
		rv = EFAULT;
		goto out;
	}

	resp = *(void **)rdata;
	free(rdata);

	if (resp == NULL) {
		rv = ENOMEM;
	}

	*addr = resp;

 out:
	rumpkern_sched(nlocks, NULL);
	ET(rv);
}
Exemplo n.º 11
0
int
rumpuser_sp_copyin(void *arg, const void *raddr, void *laddr, size_t len)
{
	int rv;

	rv = sp_copyin(arg, raddr, laddr, &len, 0);
	ET(rv);
}
Exemplo n.º 12
0
int main()
{
    srand(int(time(NULL)));

    MLP ET(2,1,2,1);
    QVector<double> sortie = ET.valeur(*new QVector<double>(2,1));
    std::cout << sortie.at(0) << std::endl;
}
Exemplo n.º 13
0
int
rumpuser_sp_copyoutstr(void *arg, const void *laddr, void *raddr, size_t *dlen)
{
	int rv;

	rv = sp_copyout(arg, laddr, raddr, *dlen);
	ET(rv);
}
Exemplo n.º 14
0
int
rumpuser_sp_copyinstr(void *arg, const void *raddr, void *laddr, size_t *len)
{
	int rv;

	rv = sp_copyin(arg, raddr, laddr, len, 1);
	ET(rv);
}
int
rumpuser_daemonize_begin(void)
{
	ssize_t n;
	int error;
	int rv;

	if (isdaemonizing) {
		rv = EINPROGRESS;
		goto out;
	}
	isdaemonizing = 1;

	/*
	 * For daemons we need to fork.  However, since we can't fork
	 * after rump_init (which creates threads), do it now.  Add
	 * a little pipe trickery to make sure we don't exit until the
	 * service is fully inited (i.e. interlocked daemonization).
	 * Actually, use sucketpair since that allows to easily steer
	 * clear of the dreaded sigpipe.
	 *
	 * Note: We do *NOT* host chdir("/").  It's up to the caller to
	 * take care of that or not.
	 */
	if (socketpair(PF_LOCAL, SOCK_STREAM, 0, daemonpipe) == -1) {
		rv = errno;
		goto out;
	}

	switch (fork()) {
	case 0:
		if (setsid() == -1) {
			rumpuser_daemonize_done(errno);
		}
		rv = 0;
		break;
	case -1:
		rv = errno;
		break;
	default:
		close(daemonpipe[1]);
		n = recv(daemonpipe[0], &error, sizeof(error), MSG_NOSIGNAL);
		if (n == -1)
			error = errno;
		else if (n != sizeof(error))
			error = ESRCH;
		_exit(error);
		/*NOTREACHED*/
	}

 out:
	ET(rv);
}
Exemplo n.º 16
0
int
rumpuser_close(int fd)
{
	int nlocks;

	rumpkern_unsched(&nlocks, NULL);
	fsync(fd);
	close(fd);
	rumpkern_sched(nlocks, NULL);

	ET(0);
}
Exemplo n.º 17
0
int main()
{
  Toy toto;
  Toy ET(Toy::ALIEN, "green", "./alien.txt");
  toto.setName("TOTO !");
  if (toto.getType() == Toy::BASIC_TOY)
  std::cout << "basic toy: " << toto.getName() << std::endl
	    << toto.getAscii() << std::endl;
  if (ET.getType() == Toy::ALIEN)
  std::cout << "this alien is: " << ET.getName() << std::endl
	    << ET.getAscii() << std::endl;
  return 1337;
  }
Exemplo n.º 18
0
static int
sp_copyout(void *arg, const void *laddr, void *raddr, size_t dlen)
{
	struct spclient *spc = arg;
	int nlocks, rv;

	rumpkern_unsched(&nlocks, NULL);
	rv = send_copyout_req(spc, raddr, laddr, dlen);
	rumpkern_sched(nlocks, NULL);

	if (rv)
		rv = EFAULT;
	ET(rv);
}
Exemplo n.º 19
0
double SVMachine::predict(Sample input){
//	std::cout << "I'm predicting with the SVMachine" << std::endl;
	if(C_executionMode == 1)
		loadParams();

    ET aux(0.0);
    // Hago esto provisional para escalar
    std::vector<double> entradaScalada;
    std::vector<Sample> sInput;

    sInput.push_back(input);
//    Utils::scalation(sInput);

    arma::Col<double> Input(input.getNFeatures());

    for(int i=0; i<input.getNFeatures(); i++)
        Input(i)=sInput[0].getInput()[i];

    for(int i=0; i<C_trainingSet.size(); i++){
        if(C_SupportVectors.at(i) > 0.0){
            aux += ET(C_SupportVectors.at(i))*ET(C_y.at(i))*C_kernel->K(C_X.row(i).t(), Input);
//            std::cout << "La suma auxiliar vale: " << aux+b << std::endl;
        }
    }

    double p = CGAL::to_double(aux + C_b);

    std::cout << "Predigo p=" << p << std::endl;

    double treshold = 0.0;

    if(p > treshold){
    	return 1.0;
    } else if(p <= treshold){
    	return -1.0;
    }
}
Exemplo n.º 20
0
int
rumpuser_getrandom(void *buf, size_t buflen, int flags, size_t *retp)
{
	size_t origlen = buflen;
	uint32_t *p = buf;
	uint32_t tmp;
	int chunk;

	do {
		chunk = buflen < 4 ? buflen : 4; /* portable MIN ... */
		tmp = RUMPUSER_RANDOM();
		memcpy(p, &tmp, chunk);
		p++;
		buflen -= chunk;
	} while (chunk);

	*retp = origlen;
	ET(0);
}
Exemplo n.º 21
0
static int
sp_copyin(void *arg, const void *raddr, void *laddr, size_t *len, int wantstr)
{
	struct spclient *spc = arg;
	void *rdata = NULL; /* XXXuninit */
	int rv, nlocks;

	rumpkern_unsched(&nlocks, NULL);

	rv = copyin_req(spc, raddr, len, wantstr, &rdata);
	if (rv)
		goto out;

	memcpy(laddr, rdata, *len);
	free(rdata);

 out:
	rumpkern_sched(nlocks, NULL);
	if (rv)
		rv = EFAULT;
	ET(rv);
}
Exemplo n.º 22
0
void
EigenGraspInterface::computeProjectionMatrices()
{
	if (mP) delete mP;
	if (mPInv) delete mPInv;

	//first build the E matrix that just contains the (potentially non-orthonormal) bases
	Matrix E(eSize, dSize);
	for (int e=0; e<eSize; e++) {
		for (int d=0; d<dSize; d++) {
			E.elem(e,d) = mGrasps[e]->getAxisValue(d);
		}
	}

	//the trivial case (assumes ortho-normal E)
	//mP = new Matrix(E);
	//mPInv = new Matrix(E.transposed());

	//general case
	//remember: P(PInv(a)) = a (always)
	//		    PInv(P(x)) != x (usually)
	// P = (E*ET)'*E
	// P' = ET
	Matrix ET(E.transposed());
	Matrix EET(eSize, eSize);
	matrixMultiply(E, ET, EET);
	Matrix EETInv(eSize, eSize);
	int result = matrixInverse(EET, EETInv);
	if (result) {
		DBGA("Projection matrix is rank deficient!");
		mP = new Matrix(Matrix::ZEROES<Matrix>(eSize, dSize));
		mPInv = new Matrix(Matrix::ZEROES<Matrix>(dSize, eSize));
		return;
	}
	mP = new Matrix(eSize, dSize);
	matrixMultiply(EETInv, E, *mP);
	mPInv = new Matrix(ET);
}
int
rumpuser_daemonize_done(int error)
{
	ssize_t n;
	int fd, rv = 0;

	if (!isdaemonizing) {
		rv = ENOENT;
		goto outout;
	}

	if (error == 0) {
		fd = open(_PATH_DEVNULL, O_RDWR);
		if (fd == -1) {
			error = errno;
			goto out;
		}
		dup2(fd, STDIN_FILENO);
		dup2(fd, STDOUT_FILENO);
		dup2(fd, STDERR_FILENO);
		if (fd > STDERR_FILENO)
			close(fd);
	}

 out:
	n = send(daemonpipe[1], &error, sizeof(error), MSG_NOSIGNAL);
	if (n != sizeof(error)) {
		rv = EPIPE;
	} else if (n == -1) {
		rv = errno;
	} else {
		close(daemonpipe[0]);
		close(daemonpipe[1]);
	}

 outout:
	ET(rv);
}
Exemplo n.º 24
0
int
rumpuser_open(const char *path, int ruflags, int *fdp)
{
	int fd, flags, rv;

	switch (ruflags & RUMPUSER_OPEN_ACCMODE) {
	case RUMPUSER_OPEN_RDONLY:
		flags = O_RDONLY;
		break;
	case RUMPUSER_OPEN_WRONLY:
		flags = O_WRONLY;
		break;
	case RUMPUSER_OPEN_RDWR:
		flags = O_RDWR;
		break;
	default:
		rv = EINVAL;
		goto out;
	}

#define TESTSET(_ru_, _h_) if (ruflags & _ru_) flags |= _h_;
	TESTSET(RUMPUSER_OPEN_CREATE, O_CREAT);
	TESTSET(RUMPUSER_OPEN_EXCL, O_EXCL);
#undef TESTSET

	KLOCK_WRAP(fd = open(path, flags, 0644));
	if (fd == -1) {
		rv = errno;
	} else {
		*fdp = fd;
		rv = 0;
	}

 out:
	ET(rv);
}
Exemplo n.º 25
0
int
rumpuser_syncfd(int fd, int flags, uint64_t start, uint64_t len)
{
	int rv = 0;
	
	/*
	 * For now, assume fd is regular file and does not care
	 * about read syncing
	 */
	if ((flags & RUMPUSER_SYNCFD_BOTH) == 0) {
		rv = EINVAL;
		goto out;
	}
	if ((flags & RUMPUSER_SYNCFD_WRITE) == 0) {
		rv = 0;
		goto out;
	}

#ifdef __NetBSD__
	{
	int fsflags = FDATASYNC;

	if (fsflags & RUMPUSER_SYNCFD_SYNC)
		fsflags |= FDISKSYNC;
	if (fsync_range(fd, fsflags, start, len) == -1)
		rv = errno;
	}
#else
	/* el-simplo */
	if (fsync(fd) == -1)
		rv = errno;
#endif

 out:
	ET(rv);
}
Exemplo n.º 26
0
int
rumpuser_getparam(const char *name, void *buf, size_t blen)
{
	int rv;

	if (strcmp(name, RUMPUSER_PARAM_NCPU) == 0) {
		int ncpu;

		if (getenv_r("RUMP_NCPU", buf, blen) == -1) {
			sprintf(buf, "2"); /* default */
		} else if (strcmp(buf, "host") == 0) {
			ncpu = gethostncpu();
			snprintf(buf, blen, "%d", ncpu);
		}
		rv = 0;
	} else if (strcmp(name, RUMPUSER_PARAM_HOSTNAME) == 0) {
		char tmp[MAXHOSTNAMELEN];

		if (gethostname(tmp, sizeof(tmp)) == -1) {
			snprintf(buf, blen, "rump-%05d", (int)getpid());
		} else {
			snprintf(buf, blen, "rump-%05d.%s",
			    (int)getpid(), tmp);
		}
		rv = 0;
	} else if (*name == '_') {
		rv = EINVAL;
	} else {
		if (getenv_r(name, buf, blen) == -1)
			rv = errno;
		else
			rv = 0;
	}

	ET(rv);
}
Exemplo n.º 27
0
// revised from RTKLIB by T.TAKASU, Japan 
int CLAMBDA::lambda(int n, int m,  std::vector<double> a, std::vector< std::vector<double> > Q, std::vector< std::vector<double> >& F,	 std::vector<double>& s)
{
	//
	//SYNTAX:
	//            ======================================
	//            | [zn,  s]=search( n, m, L, D, zs) |
	//            ======================================
	//      Search m best integer vectors zn and correspondent quadratic residual error was given by s
	//INPUTS:
	//      n: dimension of ambiguity vectors
	//      m: how many ambiguity vectors one want to output, when m=2, zn could given the best and the second best solution  
	//      Q: (co)variance matrices of float ambiguities
	//      a: float  ambiguities
	//OUTPUT:
	//      F: m integer ambiguity vectors
	//      s:   quadratic residual error of m sets ambiguity vectors
	//	revised by D. Xiang on 2014/05/06 in Tongji Univ
	//	email: [email protected]
	//	School.of Surveying and Geoinformatics Engineering,Tongji Univ.,China
	//	Originally written by D. Xiang on 2012 in CASM, Beijing 
	//////////////////////////////////////////////////////////////////////////
	if (n<=0||m<=0) return -1;
	if(F.size()==0)
	{
		F.resize(n);
		for(int i=0;i<n;i++)
			F[i].resize(m);
	}
	if(s.size()==0)
		s.resize(m);

	int info;
	CMatrix mymat;
	std::vector< std::vector<double> > L(n),Z,E(m),ET(n),ZT,Q1;
	std::vector< double > D(n),z(n);
	mymat.zeros(L,n,n); mymat.zeros(Z,n,n);
	mymat.zeros(L,n,n); mymat.eye(Z,n,n);ZT=Z; Q1=Z;
	for(int i=0; i<n; i++) { ET[i].resize(m);} for(int i=0;i<m;i++)E[i].resize(n);
	/* LD factorization 下*对*上*/
	if ((info=LTDLFactorization(n,Q,L,D))) {

		/* lambda reduction */
		reduction(n,L,D,Z);
		//matmul("TN",n,1,n,1.0,Z,a,0.0,z); /* z=Z*a */
		mymat.multip(Z,a,z,n,n);
		/* mlambda search */
		if (!(info=search(n,m,L,D,z,E,s))) 
		{

			//info=solve("T",Z,E,n,m,F); /* F=Z'\E */
			mymat.MatT(E,ET,m,n);
			if(mymat.MatrixSovleDong(Z,ET,F,n,m)==false)
			{
//				AfxMessageBox("Error");
				return -1;
			}

		}
	}
	return info;
}
Exemplo n.º 28
0
void TabCodeGen::writeExec()
{
	testEofUsed = false;
	outLabelUsed = false;

	out <<
		"	{\n"
		"	int _klen";

	if ( redFsm->anyRegCurStateRef() )
		out << ", _ps";

	out << 
		";\n"
		"	" << UINT() << " _trans;\n";

	if ( redFsm->anyConditions() )
		out << "	" << WIDE_ALPH_TYPE() << " _widec;\n";

	if ( redFsm->anyToStateActions() || redFsm->anyRegActions() 
			|| redFsm->anyFromStateActions() )
	{
		out << 
			"	" << PTR_CONST() << ARRAY_TYPE(redFsm->maxActArrItem) << PTR_CONST_END() << 
					POINTER() << "_acts;\n"
			"	" << UINT() << " _nacts;\n";
	}

	out <<
		"	" << PTR_CONST() << WIDE_ALPH_TYPE() << PTR_CONST_END() << POINTER() << "_keys;\n"
		"\n";

	if ( !noEnd ) {
		testEofUsed = true;
		out << 
			"	if ( " << P() << " == " << PE() << " )\n"
			"		goto _test_eof;\n";
	}

	if ( redFsm->errState != 0 ) {
		outLabelUsed = true;
		out << 
			"	if ( " << vCS() << " == " << redFsm->errState->id << " )\n"
			"		goto _out;\n";
	}

	out << "_resume:\n";

	if ( redFsm->anyFromStateActions() ) {
		out <<
			"	_acts = " << ARR_OFF( A(),  FSA() + "[" + vCS() + "]" ) << ";\n"
			"	_nacts = " << CAST(UINT()) << " *_acts++;\n"
			"	while ( _nacts-- > 0 ) {\n"
			"		switch ( *_acts++ ) {\n";
			FROM_STATE_ACTION_SWITCH();
			SWITCH_DEFAULT() <<
			"		}\n"
			"	}\n"
			"\n";
	}

	if ( redFsm->anyConditions() )
		COND_TRANSLATE();

	LOCATE_TRANS();

	out << "_match:\n";

	if ( useIndicies )
		out << "	_trans = " << I() << "[_trans];\n";
	
	if ( redFsm->anyEofTrans() )
		out << "_eof_trans:\n";

	if ( redFsm->anyRegCurStateRef() )
		out << "	_ps = " << vCS() << ";\n";

	out <<
		"	" << vCS() << " = " << TT() << "[_trans];\n"
		"\n";

	if ( redFsm->anyRegActions() ) {
		out <<
			"	if ( " << TA() << "[_trans] == 0 )\n"
			"		goto _again;\n"
			"\n"
			"	_acts = " << ARR_OFF( A(), TA() + "[_trans]" ) << ";\n"
			"	_nacts = " << CAST(UINT()) << " *_acts++;\n"
			"	while ( _nacts-- > 0 )\n	{\n"
			"		switch ( *_acts++ )\n		{\n";
			ACTION_SWITCH();
			SWITCH_DEFAULT() <<
			"		}\n"
			"	}\n"
			"\n";
	}

	if ( redFsm->anyRegActions() || redFsm->anyActionGotos() || 
			redFsm->anyActionCalls() || redFsm->anyActionRets() )
		out << "_again:\n";

	if ( redFsm->anyToStateActions() ) {
		out <<
			"	_acts = " << ARR_OFF( A(), TSA() + "[" + vCS() + "]" ) << ";\n"
			"	_nacts = " << CAST(UINT()) << " *_acts++;\n"
			"	while ( _nacts-- > 0 ) {\n"
			"		switch ( *_acts++ ) {\n";
			TO_STATE_ACTION_SWITCH();
			SWITCH_DEFAULT() <<
			"		}\n"
			"	}\n"
			"\n";
	}

	if ( redFsm->errState != 0 ) {
		outLabelUsed = true;
		out << 
			"	if ( " << vCS() << " == " << redFsm->errState->id << " )\n"
			"		goto _out;\n";
	}

	if ( !noEnd ) {
		out << 
			"	if ( ++" << P() << " != " << PE() << " )\n"
			"		goto _resume;\n";
	}
	else {
		out << 
			"	" << P() << " += 1;\n"
			"	goto _resume;\n";
	}
	
	if ( testEofUsed )
		out << "	_test_eof: {}\n";
	
	if ( redFsm->anyEofTrans() || redFsm->anyEofActions() ) {
		out << 
			"	if ( " << P() << " == " << vEOF() << " )\n"
			"	{\n";

		if ( redFsm->anyEofTrans() ) {
			out <<
				"	if ( " << ET() << "[" << vCS() << "] > 0 ) {\n"
				"		_trans = " << ET() << "[" << vCS() << "] - 1;\n"
				"		goto _eof_trans;\n"
				"	}\n";
		}

		if ( redFsm->anyEofActions() ) {
			out <<
				"	" << PTR_CONST() << ARRAY_TYPE(redFsm->maxActArrItem) << PTR_CONST_END() << 
						POINTER() << "__acts = " << 
						ARR_OFF( A(), EA() + "[" + vCS() + "]" ) << ";\n"
				"	" << UINT() << " __nacts = " << CAST(UINT()) << " *__acts++;\n"
				"	while ( __nacts-- > 0 ) {\n"
				"		switch ( *__acts++ ) {\n";
				EOF_ACTION_SWITCH();
				SWITCH_DEFAULT() <<
				"		}\n"
				"	}\n";
		}
		
		out << 
			"	}\n"
			"\n";
	}

	if ( outLabelUsed )
		out << "	_out: {}\n";

	out << "	}\n";
}
Exemplo n.º 29
0
void TabCodeGen::writeData()
{
	/* If there are any transtion functions then output the array. If there
	 * are none, don't bother emitting an empty array that won't be used. */
	if ( redFsm->anyActions() ) {
		OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActArrItem), A() );
		ACTIONS_ARRAY();
		CLOSE_ARRAY() <<
		"\n";
	}

	if ( redFsm->anyConditions() ) {
		OPEN_ARRAY( ARRAY_TYPE(redFsm->maxCondOffset), CO() );
		COND_OFFSETS();
		CLOSE_ARRAY() <<
		"\n";

		OPEN_ARRAY( ARRAY_TYPE(redFsm->maxCondLen), CL() );
		COND_LENS();
		CLOSE_ARRAY() <<
		"\n";

		OPEN_ARRAY( WIDE_ALPH_TYPE(), CK() );
		COND_KEYS();
		CLOSE_ARRAY() <<
		"\n";

		OPEN_ARRAY( ARRAY_TYPE(redFsm->maxCondSpaceId), C() );
		COND_SPACES();
		CLOSE_ARRAY() <<
		"\n";
	}

	OPEN_ARRAY( ARRAY_TYPE(redFsm->maxKeyOffset), KO() );
	KEY_OFFSETS();
	CLOSE_ARRAY() <<
	"\n";

	OPEN_ARRAY( WIDE_ALPH_TYPE(), K() );
	KEYS();
	CLOSE_ARRAY() <<
	"\n";

	OPEN_ARRAY( ARRAY_TYPE(redFsm->maxSingleLen), SL() );
	SINGLE_LENS();
	CLOSE_ARRAY() <<
	"\n";

	OPEN_ARRAY( ARRAY_TYPE(redFsm->maxRangeLen), RL() );
	RANGE_LENS();
	CLOSE_ARRAY() <<
	"\n";

	OPEN_ARRAY( ARRAY_TYPE(redFsm->maxIndexOffset), IO() );
	INDEX_OFFSETS();
	CLOSE_ARRAY() <<
	"\n";

	if ( useIndicies ) {
		OPEN_ARRAY( ARRAY_TYPE(redFsm->maxIndex), I() );
		INDICIES();
		CLOSE_ARRAY() <<
		"\n";

		OPEN_ARRAY( ARRAY_TYPE(redFsm->maxState), TT() );
		TRANS_TARGS_WI();
		CLOSE_ARRAY() <<
		"\n";

		if ( redFsm->anyActions() ) {
			OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), TA() );
			TRANS_ACTIONS_WI();
			CLOSE_ARRAY() <<
			"\n";
		}
	}
	else {
		OPEN_ARRAY( ARRAY_TYPE(redFsm->maxState), TT() );
		TRANS_TARGS();
		CLOSE_ARRAY() <<
		"\n";

		if ( redFsm->anyActions() ) {
			OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), TA() );
			TRANS_ACTIONS();
			CLOSE_ARRAY() <<
			"\n";
		}
	}

	if ( redFsm->anyToStateActions() ) {
		OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), TSA() );
		TO_STATE_ACTIONS();
		CLOSE_ARRAY() <<
		"\n";
	}

	if ( redFsm->anyFromStateActions() ) {
		OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), FSA() );
		FROM_STATE_ACTIONS();
		CLOSE_ARRAY() <<
		"\n";
	}

	if ( redFsm->anyEofActions() ) {
		OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), EA() );
		EOF_ACTIONS();
		CLOSE_ARRAY() <<
		"\n";
	}

	if ( redFsm->anyEofTrans() ) {
		OPEN_ARRAY( ARRAY_TYPE(redFsm->maxIndexOffset+1), ET() );
		EOF_TRANS();
		CLOSE_ARRAY() <<
		"\n";
	}

	STATE_IDS();
}
Exemplo n.º 30
0
void seissol::model::initializeSpecificLocalData( seissol::model::Material const& material,
                                                  seissol::model::LocalData* localData )
{
  for (unsigned mech = 0; mech < NUMBER_OF_RELAXATION_MECHANISMS; ++mech) {
    MatrixView ET(&localData->ET[mech * seissol::model::ET::reals], seissol::model::ET::reals, seissol::model::ET::index);
    ET.setZero();
    real const* theta = material.theta[mech];
    ET(0, 0) = theta[0];
    ET(1, 0) = theta[1];
    ET(2, 0) = theta[1];
    ET(0, 1) = theta[1];
    ET(1, 1) = theta[0];
    ET(2, 1) = theta[1];  
    ET(0, 2) = theta[1];
    ET(1, 2) = theta[1];
    ET(2, 2) = theta[0];  
    ET(3, 3) = theta[2];
    ET(4, 4) = theta[2];
    ET(5, 5) = theta[2];
  }
  
  for (unsigned mech = 0; mech < NUMBER_OF_RELAXATION_MECHANISMS; ++mech) {
    localData->omega[mech] = material.omega[mech];
  }
}