Exemplo n.º 1
0
Arquivo: if.c Projeto: Bunzo/nop
Uint if_ins(Uint pid)
{
	if (if_full(pid)) {
		return 1;
	}

	PE(pid).plif.ins[PE(pid).plif.bot] = PE(pid).imem.mem[PE(pid).plia.pc];
	return 0;
}
Exemplo n.º 2
0
int main()
{
	int res;

	res = linkat(0, "in", 0, "in_link", 0);	// error
	PE(res, "maomao get a error!");
	res = linkat(0, "~/codes/basic/c/file/in", 0, "~/codes/basic/c/file/in_link", 0);	// error
	PE(res, "maomao get a error!");
	res = linkat(0, "/Users/xichen/codes/basic/c/file/in", 0, "/Users/xichen/codes/basic/c/file/in_link", 0);  // ok for me
	PE(res, "maomao get a error!");

    return 0;
}
Exemplo n.º 3
0
Arquivo: if.c Projeto: Bunzo/nop
void if_init()
{
	int i, j;
	for (i=0; i<PENUM; i++) {
		for (j=0; j<IFQSIZE; j++) {
			PE(i).plif.ins[j] = 0x0;
		}

		PE(i).plif.full  = 0x0;
		PE(i).plif.empty = 0x0;
		PE(i).plif.top   = 0x0;
		PE(i).plif.bot   = 0x0;
	}
}
Exemplo n.º 4
0
static void usage(void)
{
#define FMT "  %-25s %s\n"
#define PE(a, b) fprintf(stderr, FMT, a, b)
    fprintf(stderr, "Usage: test_rbtree [options] [filename]\n");
    fprintf(stderr, "Read data from [filename] or via stdin and build a Red-Black Tree.\n");
    fprintf(stderr, "\nOptions:\n");
    PE("-h, --help", "Print this help message.");
    PE("-e, --export=EXPORT", "Export tree in .dot file format.");
    PE("-i, --interactive", "Interact with the tree in a simple CLI.");
    fprintf(stderr, "\nReport bugs to [email protected]\n");
#undef PE
#undef FMT
}
Exemplo n.º 5
0
static int __init at32_init_ide_or_cf(struct platform_device *pdev,
		unsigned int cs, unsigned int extint)
{
	static unsigned int extint_pin_map[4] __initdata = {
		GPIO_PIN_PB(25),
		GPIO_PIN_PB(26),
		GPIO_PIN_PB(27),
		GPIO_PIN_PB(28),
	};
	static bool common_pins_initialized __initdata = false;
	unsigned int extint_pin;
	int ret;

	if (extint >= ARRAY_SIZE(extint_pin_map))
		return -EINVAL;
	extint_pin = extint_pin_map[extint];

	switch (cs) {
	case 4:
		ret = platform_device_add_resources(pdev,
				at32_smc_cs4_resource,
				ARRAY_SIZE(at32_smc_cs4_resource));
		if (ret)
			return ret;

		select_peripheral(PE(21), PERIPH_A, 0); /* NCS4   -> OE_N  */
		set_ebi_sfr_bits(HMATRIX_BIT(CS4A));
		break;
	case 5:
		ret = platform_device_add_resources(pdev,
				at32_smc_cs5_resource,
				ARRAY_SIZE(at32_smc_cs5_resource));
		if (ret)
			return ret;

		select_peripheral(PE(22), PERIPH_A, 0); /* NCS5   -> OE_N  */
		set_ebi_sfr_bits(HMATRIX_BIT(CS5A));
		break;
	default:
		return -EINVAL;
	}

	if (!common_pins_initialized) {
		select_peripheral(PE(19), PERIPH_A, 0);	/* CFCE1  -> CS0_N */
		select_peripheral(PE(20), PERIPH_A, 0);	/* CFCE2  -> CS1_N */
		select_peripheral(PE(23), PERIPH_A, 0); /* CFRNW  -> DIR   */
		select_peripheral(PE(24), PERIPH_A, 0); /* NWAIT  <- IORDY */
		common_pins_initialized = true;
	}

	at32_select_periph(extint_pin, GPIO_PERIPH_A, AT32_GPIOF_DEGLITCH);

	pdev->resource[1].start = EIM_IRQ_BASE + extint;
	pdev->resource[1].end = pdev->resource[1].start;

	return 0;
}
Exemplo n.º 6
0
int main(int argc, char *argv[])
{
	int fd;
	off_t ofset;
	int res;
	struct dirent *ent;
	DIR *dir;
	struct stat buf;
	int complete = 1;

	if(argc != 2)
		return -1;

	dir = opendir(argv[1]);	
	assert(dir);

	res = chdir(argv[1]);
	assert(res == 0);
	while(ent = readdir(dir)) {
		res = stat(ent->d_name, &buf);
		if(res != 0) {
			PE(res, "");
			complete = 0;	
			continue;	
		}
		printf("ent:%s\n", ent->d_name);
		if(!strcmp(ent->d_name, ".") || !strcmp(ent->d_name, ".."))
			continue;
		if(S_ISDIR(buf.st_mode))
			continue;	
		if(S_ISCHR(buf.st_mode))
			printf("\tChar Device: dev:%d/%d, rdev:%d/%d\n", major(buf.st_dev), minor(buf.st_dev), major(buf.st_rdev), minor(buf.st_rdev));
		if(S_ISBLK(buf.st_mode))
			printf("\tBlock Device: dev:%d/%d, rdev:%d/%d\n", major(buf.st_dev), minor(buf.st_dev), major(buf.st_rdev), minor(buf.st_rdev));
	}

	assert(closedir(dir) == 0);

    return 0;
}
Exemplo n.º 7
0
Arquivo: utlib.c Projeto: AZed/uvcdat
    UtFactor    factor;		/* corresponding multiplying factor */
    short       nchar;		/* size of prefix string excluding EOS */
} PrefixEntry;

/*
 *  Prefix table in the order required by the prefix-entry comparison function.
 *  The names are Based on ANSI/IEEE Std 260-1978 (a.k.a. ANSI Y10.19-1969) -- 
 *  reaffirmed 1985.  The names must be unique.
 *
 *  NB: The short-prefix symbol corresponding to the prefix "micro" has been 
 *  changed here from the standard one (the Greek letter "mu") to the symbol 
 *  "u".
 */
#define PE(name, factor)    {name, factor, sizeof(name)-1}
static PrefixEntry	PrefixTable[]   = {
    PE("E",     1e18),
    PE("G",     1e9),
    PE("M",     1e6),
    PE("P",     1e15),
    PE("T",     1e12),
    PE("Y",	1e24),
    PE("Z",	1e21),
    PE("a",     1e-18),
    PE("atto",  1e-18),
    PE("c",     1e-2),
    PE("centi", 1e-2),
    PE("d",     1e-1),
    PE("da",    1e1),
    PE("deca",  1e1),	/* Spelling according to "ISO 2955: Information
			 * processing -- Representation of SI and other units
			 * in systems with limited character sets". */
Exemplo n.º 8
0
Arquivo: if.c Projeto: Bunzo/nop
Uint if_empty(Uint pid)
{
	return PE(pid).plif.top == PE(pid).plif.bot;
}
Exemplo n.º 9
0
Arquivo: if.c Projeto: Bunzo/nop
Uint if_full(Uint pid)
{
	return PE(pid).plif.top-1 == PE(pid).plif.bot;
}
Exemplo n.º 10
0
void FFlatCodeGen::writeExec()
{
	testEofUsed = false;
	outLabelUsed = false;

	out << 
		L"	{\n"
		L"	int _slen";

	if ( redFsm->anyRegCurStateRef() )
		out << L", _ps";
	
	out << L";\n";
	out << L"	int _trans";

	if ( redFsm->anyConditions() )
		out << L", _cond";

	out << L";\n";

	out <<
		L"	" << PTR_CONST() << WIDE_ALPH_TYPE() << PTR_CONST_END() << POINTER() << L"_keys;\n"
		L"	" << PTR_CONST() << ARRAY_TYPE(redFsm->maxIndex) << PTR_CONST_END() << POINTER() << L"_inds;\n";

	if ( redFsm->anyConditions() ) {
		out << 
			L"	" << PTR_CONST() << ARRAY_TYPE(redFsm->maxCond) << PTR_CONST_END() << POINTER() << L"_conds;\n"
			L"	" << WIDE_ALPH_TYPE() << L" _widec;\n";
	}

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

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

	out << L"_resume:\n";

	if ( redFsm->anyFromStateActions() ) {
		out <<
			L"	switch ( " << FSA() << L"[" << vCS() << L"] ) {\n";
			FROM_STATE_ACTION_SWITCH();
			SWITCH_DEFAULT() <<
			L"	}\n"
			L"\n";
	}

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

	LOCATE_TRANS();

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

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

	if ( redFsm->anyRegActions() ) {
		out << 
			L"	if ( " << TA() << L"[_trans] == 0 )\n"
			L"		goto _again;\n"
			L"\n"
			L"	switch ( " << TA() << L"[_trans] ) {\n";
			ACTION_SWITCH();
			SWITCH_DEFAULT() <<
			L"	}\n"
			L"\n";
	}

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

	if ( redFsm->anyToStateActions() ) {
		out <<
			L"	switch ( " << TSA() << L"[" << vCS() << L"] ) {\n";
			TO_STATE_ACTION_SWITCH();
			SWITCH_DEFAULT() <<
			L"	}\n"
			L"\n";
	}

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

	if ( !noEnd ) {
		out << 
			L"	if ( ++" << P() << L" != " << PE() << L" )\n"
			L"		goto _resume;\n";
	}
	else {
		out << 
			L"	" << P() << L" += 1;\n"
			L"	goto _resume;\n";
	}

	if ( testEofUsed )
		out << L"	_test_eof: {}\n";

	if ( redFsm->anyEofTrans() || redFsm->anyEofActions() ) {
		out <<
			L"	if ( " << P() << L" == " << vEOF() << L" )\n"
			L"	{\n";

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

		if ( redFsm->anyEofActions() ) {
			out <<
				L"	switch ( " << EA() << L"[" << vCS() << L"] ) {\n";
				EOF_ACTION_SWITCH();
				SWITCH_DEFAULT() <<
				L"	}\n";
		}

		out <<
			L"	}\n"
			L"\n";
	}

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

	out << L"	}\n";
}
Exemplo n.º 11
0
QList<fugio::NodeControlInterface::AvailablePinEntry> NamespacePin::oscPins( const QStringList &pCurDir ) const
{
	QList<fugio::NodeControlInterface::AvailablePinEntry>		PinLst;

	for( QHash<QString,QVariant>::const_iterator it = mDataNames.begin() ; it != mDataNames.end() ; it++ )
	{
		QSharedPointer<fugio::PinInterface>		CurPin;

		QStringList		CurLst = it.key().split( '/', QString::SkipEmptyParts );

		if( !pCurDir.isEmpty() )
		{
			if( CurLst.size() <= pCurDir.size() )
			{
				continue;
			}

			bool			CurFnd = true;

			for( int i = 0 ; i < pCurDir.size() ; i++ )
			{
				if( CurLst.first() != pCurDir.at( i ) )
				{
					CurFnd = false;

					break;
				}

				CurLst.removeFirst();
			}

			if( !CurFnd )
			{
				continue;
			}
		}

		QStringList		NewLst = QStringList( CurLst.takeFirst() );

		while( true )
		{
			QString		CurNam = NewLst.join( '/' ).prepend( '/' );

			CurPin = mPin->node()->findOutputPinByName( CurNam );

			if( CurPin )
			{
				break;
			}

			fugio::NodeControlInterface::AvailablePinEntry		PE( "" );

			if( CurLst.isEmpty() )
			{
				QUuid		PinUid = PID_FLOAT;

				switch( QMetaType::Type( it.value().type() ) )
				{
					case QMetaType::Float:
					case QMetaType::Double:
						PinUid = PID_FLOAT;
						break;

					case QMetaType::Bool:
						PinUid = PID_BOOL;
						break;

					case QMetaType::Int:
					case QMetaType::Long:
						PinUid = PID_INTEGER;
						break;

					case QMetaType::QByteArray:
						PinUid = PID_BYTEARRAY;
						break;

					case QMetaType::QColor:
						PinUid = PID_COLOUR;
						break;

					case QMetaType::QString:
						PinUid = PID_STRING;
						break;

					case QMetaType::QVariantList:
						PinUid = PID_LIST;
						break;

					default:
						break;
				}

				PE = fugio::NodeControlInterface::AvailablePinEntry( CurNam, PinUid );
			}
			else
			{
				PE = fugio::NodeControlInterface::AvailablePinEntry( CurNam, PID_OSC_SPLIT );
			}

			if( !PinLst.contains( PE ) )
			{
				PinLst << PE;
			}

			if( CurLst.isEmpty() )
			{
				break;
			}

			NewLst.push_back( CurLst.takeFirst() );
		}
	}

	std::sort( PinLst.begin(), PinLst.end() );

	return( PinLst );
}
Exemplo n.º 12
0
void OCamlFGotoCodeGen::writeExec()
{
	testEofUsed = false;
	outLabelUsed = false;

	out << "	begin\n";

	if ( redFsm->anyRegCurStateRef() )
		out << "	let _ps = ref 0 in\n";

	if ( redFsm->anyConditions() )
		out << "	let _widec : " << WIDE_ALPH_TYPE() << " = ref 0 in\n";

	out << "\n";
  out << "\tlet rec do_start () =\n";
	if ( !noEnd ) {
		testEofUsed = true;
		out << 
			"	if " << P() << " = " << PE() << " then\n"
			"		do_test_eof ()\n"
      "\telse\n";
	}

	if ( redFsm->errState != 0 ) {
		outLabelUsed = true;
		out << 
			"	if " << vCS() << " = " << redFsm->errState->id << " then\n"
			"		do_out ()\n"
      "\telse\n";
	}
  out << "\tdo_resume ()\n";

	out << "and do_resume () =\n";

	if ( redFsm->anyFromStateActions() ) {
		out <<
			"	begin match " << AT(FSA(),vCS()) << " with\n";
			FROM_STATE_ACTION_SWITCH();
			SWITCH_DEFAULT() <<
			"	end;\n"
			"\n";
	}

	out << 
		"	begin match " << vCS() << " with\n";
		STATE_GOTOS();
		SWITCH_DEFAULT() <<
		"	end\n"
		"\n";
		TRANSITIONS() << 
		"\n";

	if ( redFsm->anyRegActions() )
		EXEC_ACTIONS() << "\n";

	out << "\tand do_again () =\n";

	if ( redFsm->anyToStateActions() ) {
		out <<
			" begin match " << AT(TSA(), vCS()) << " with\n";
			TO_STATE_ACTION_SWITCH();
			SWITCH_DEFAULT() <<
			"	end;\n"
			"\n";
	}

	if ( redFsm->errState != 0 ) {
		outLabelUsed = true;
		out << 
			"	match " << vCS() << " with\n" <<
      "	| " << redFsm->errState->id << " -> do_out ()\n"
      "	| _ ->\n";
	}

	out << "\t" << P() << " <- " << P() << " + 1;\n";

	if ( !noEnd ) {
		out << 
			"	if " << P() << " <> " << PE() << " then\n"
			"		do_resume ()\n"
      "\telse do_test_eof ()\n";
	}
	else {
		out << 
			"	do_resume ()\n";
	}

//	if ( testEofUsed )
  out << "and do_test_eof () =\n";

	if ( redFsm->anyEofTrans() || redFsm->anyEofActions() ) {
		out <<
			"	if " << P() << " = " << vEOF() << " then\n"
			"	begin\n";

		if ( redFsm->anyEofTrans() ) {
			out <<
				"	match " << vCS() << " with\n";

			for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
				if ( st->eofTrans != 0 )
					out << "	| " << st->id << " -> tr" << st->eofTrans->id << " ()\n";
			}

			SWITCH_DEFAULT() << ";\n"; // fall through
		}

		if ( redFsm->anyEofActions() ) {
			out <<
				"	try match " << AT(EA(), vCS()) << " with\n";
				EOF_ACTION_SWITCH();
				SWITCH_DEFAULT() <<
				"	\n"
				"	with Goto_again -> do_again () \n";
		}

		out <<
			"	end\n"
			"\n";
	}
  else
    out << "\t()\n";

	if ( outLabelUsed )
		out << "\tand do_out () = ()\n";

  out << "\tin do_start ()\n";
	out << "	end;\n";
}
Exemplo n.º 13
0
void OCamlFFlatCodeGen::writeExec()
{
	testEofUsed = false;
	outLabelUsed = false;
	initVarTypes();

	out << 
		L"	begin\n";
//		L"	" << slenType << L" _slen";

//	if ( redFsm->anyRegCurStateRef() )
//		out << L", _ps";
	
//	out << L";\n";
//	out << L"	" << transType << L" _trans";

//	if ( redFsm->anyConditions() )
//		out << L", _cond";

//	out << L";\n";

//	out <<
//		L"	" << L"int _keys;\n"
//		L"	" << indsType << L" _inds;\n";
		/*
		L"	" << PTR_CONST() << WIDE_ALPH_TYPE() << POINTER() << L"_keys;\n"
		L"	" << PTR_CONST() << ARRAY_TYPE(redFsm->maxIndex) << POINTER() << L"_inds;\n";*/

  out <<
    L"	let state = { keys = 0; trans = 0; } in\n"
    L"	let rec do_start () =\n";

//	if ( redFsm->anyConditions() ) {
//		out << 
//			L"	" << condsType << L" _conds;\n"
//			L"	" << WIDE_ALPH_TYPE() << L" _widec;\n";
//	}

	if ( !noEnd ) {
		testEofUsed = true;
		out << 
			L"	if " << P() << L" = " << PE() << L" then\n"
			L"		do_test_eof ()\n"
      L"\telse\n";
	}

	if ( redFsm->errState != 0 ) {
		outLabelUsed = true;
		out << 
			L"	if " << vCS() << L" = " << redFsm->errState->id << L" then\n"
			L"		do_out ()\n"
      L"\telse\n";
	}
  out << L"\tdo_resume ()\n";

	out << L"and do_resume () =\n";

	if ( redFsm->anyFromStateActions() ) {
		out <<
			L"	begin match " << AT( FSA(), vCS() ) << L" with\n";
			FROM_STATE_ACTION_SWITCH();
			SWITCH_DEFAULT() <<
			L"	end;\n"
			L"\n";
	}

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

  out << L"\tbegin try\n";
	LOCATE_TRANS();
  out << L"\twith Goto_match -> () end;\n";

  out << L"\tdo_eof_trans ()\n";
	
//	if ( redFsm->anyEofTrans() )
  out << L"and do_eof_trans () =\n";

	if ( redFsm->anyRegCurStateRef() )
		out << L"	let ps = " << vCS() << L" in\n";

	out <<
		L"	" << vCS() << L" <- " << AT( TT() ,L"state.trans" ) << L";\n"
		L"\n";

	if ( redFsm->anyRegActions() ) {
		out << 
			L"	begin try if " << AT( TA() , L"state.trans" ) << L" = 0 then\n"
			L"		raise Goto_again;\n"
			L"\n"
			L"	match " << AT( TA(), L"state.trans" ) << L" with\n";
			ACTION_SWITCH();
			SWITCH_DEFAULT() <<
			L"	with Goto_again -> () end;\n"
			L"\n";
	}
  out << L"\tdo_again ()\n";

//	if ( redFsm->anyRegActions() || redFsm->anyActionGotos() || 
//			redFsm->anyActionCalls() || redFsm->anyActionRets() )
  out << L"\tand do_again () =\n";

	if ( redFsm->anyToStateActions() ) {
		out <<
			L"	begin match " << AT( TSA(), vCS() ) << L" with\n";
			TO_STATE_ACTION_SWITCH();
			SWITCH_DEFAULT() <<
			L"	end;\n"
			L"\n";
	}

	if ( redFsm->errState != 0 ) {
		outLabelUsed = true;
		out << 
			L"	match " << vCS() << L" with\n"
      L"\t| " << redFsm->errState->id << L" -> do_out ()\n"
      L"\t| _ ->\n";
	}

  out << L"\t" << P() << L" <- " << P() << L" + 1;\n";

	if ( !noEnd ) {
		out << 
			L"	if " << P() << L" <> " << PE() << L" then\n"
			L"		do_resume ()\n"
      L"\telse do_test_eof ()\n";
	}
	else {
		out << 
			L"	do_resume ()\n";
	}

//	if ( testEofUsed )
	out << L"and do_test_eof () =\n";
	
	if ( redFsm->anyEofTrans() || redFsm->anyEofActions() ) {
		out << 
			L"	if " << P() << L" = " << vEOF() << L" then\n"
			L"	begin try\n";

		if ( redFsm->anyEofTrans() ) {
			out <<
				L"	if " << AT( ET(), vCS() ) << L" > 0 then\n"
				L"	begin\n"
        L"   state.trans <- " << CAST(transType) << L"(" << AT( ET(), vCS() ) << L" - 1);\n"
				L"		raise Goto_eof_trans;\n"
				L"	end;\n";
		}

		if ( redFsm->anyEofActions() ) {
			out <<
				L"	begin match " << AT( EA(), vCS() ) << L" with\n";
				EOF_ACTION_SWITCH();
				SWITCH_DEFAULT() <<
				L"	end\n";
		}

		out << 
			L"	with Goto_again -> do_again ()\n"
			L"	| Goto_eof_trans -> do_eof_trans () end\n"
			L"\n";
	}
  else
  {
    out << L"\t()\n";
  }

	if ( outLabelUsed )
		out << L"	and do_out () = ()\n";

  out << L"\tin do_start ()\n";
	out << L"	end;\n";
}
Exemplo n.º 14
0
void CSharpTabCodeGen::writeExec()
{
	testEofUsed = false;
	outLabelUsed = false;
	initVarTypes();

	out <<
		L"	{\n"
		L"	" << klenType << L" _klen";

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

	out << 
		L";\n"
		L"	" << transType << L" _trans;\n";

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

	if ( redFsm->anyToStateActions() || redFsm->anyRegActions() 
			|| redFsm->anyFromStateActions() )
	{
		out << 
			L"	int _acts;\n"
			L"	int _nacts;\n";
	}

	out <<
		L"	" << keysType << L" _keys;\n"
		L"\n";
//		L"	" << PTR_CONST() << WIDE_ALPH_TYPE() << POINTER() << L"_keys;\n"

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

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

	out << L"_resume:\n";

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

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

	LOCATE_TRANS();

	out << L"_match:\n";

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

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

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

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

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

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

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

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

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

		if ( redFsm->anyEofActions() ) {
			out <<
				L"	int __acts = " << 
						EA() << L"[" << vCS() << L"]" << L";\n"
				L"	int __nacts = " << 
				A() << L"[__acts++];\n"
				L"	while ( __nacts-- > 0 ) {\n"
				L"		switch ( " << A() << L"[__acts++] ) {\n";
				EOF_ACTION_SWITCH();
				SWITCH_DEFAULT() <<
				L"		}\n"
				L"	}\n";
		}
		
		out << 
			L"	}\n"
			L"\n";
	}

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

	out << L"	}\n";
}
Exemplo n.º 15
0
void OCamlTabCodeGen::writeExec()
{
	testEofUsed = false;
	outLabelUsed = false;
	initVarTypes();

	out <<
		"	begin\n";
//		"	" << klenType << " _klen";

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

/*
	out << "	" << transType << " _trans;\n";

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

	if ( redFsm->anyToStateActions() || redFsm->anyRegActions() 
			|| redFsm->anyFromStateActions() )
	{
		out << 
			"	int _acts;\n"
			"	int _nacts;\n";
	}

	out <<
		"	" << keysType << " _keys;\n"
		"\n";
//		"	" << PTR_CONST() << WIDE_ALPH_TYPE() << POINTER() << "_keys;\n"
*/

  out <<
    "	let state = { keys = 0; trans = 0; acts = 0; nacts = 0; } in\n"
    "	let rec do_start () =\n";
	if ( !noEnd ) {
		testEofUsed = true;
		out << 
			"	if " << P() << " = " << PE() << " then\n"
			"		do_test_eof ()\n"
      "\telse\n";
	}

	if ( redFsm->errState != 0 ) {
		outLabelUsed = true;
		out << 
			"	if " << vCS() << " = " << redFsm->errState->id << " then\n"
			"		do_out ()\n"
      "\telse\n";
	}
  out << "\tdo_resume ()\n";

	out << "and do_resume () =\n";

	if ( redFsm->anyFromStateActions() ) {
		out <<
			"	state.acts <- " << AT( FSA(), vCS() ) << ";\n"
			"	state.nacts <- " << AT( A(), POST_INCR("state.acts") ) << ";\n"
			"	while " << POST_DECR("state.nacts") << " > 0 do\n"
			"		begin match " << AT( A(), POST_INCR("state.acts") ) << " with\n";
			FROM_STATE_ACTION_SWITCH();
			SWITCH_DEFAULT() <<
			"		end\n"
			"	done;\n"
			"\n";
	}

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

  out << "\tbegin try\n";
	LOCATE_TRANS();
  out << "\twith Goto_match -> () end;\n";

  out << 
    "\tdo_match ()\n";

	out << "and do_match () =\n";

	if ( useIndicies )
		out << "	state.trans <- " << CAST(transType) << AT( I(), "state.trans" ) << ";\n";

  out << "\tdo_eof_trans ()\n";
	
//	if ( redFsm->anyEofTrans() )
  out << "and do_eof_trans () =\n";

	if ( redFsm->anyRegCurStateRef() )
		out << "	let ps = " << vCS() << " in\n";

	out <<
		"	" << vCS() << " <- " << AT( TT() ,"state.trans" ) << ";\n"
		"\n";

	if ( redFsm->anyRegActions() ) {
		out <<
			"\tbegin try\n"
      "	match " << AT( TA(), "state.trans" ) << " with\n"
			"\t| 0 -> raise Goto_again\n"
      "\t| _ ->\n"
			"	state.acts <- " << AT( TA(), "state.trans" ) << ";\n"
			"	state.nacts <- " << AT( A(), POST_INCR("state.acts") ) << ";\n"
			"	while " << POST_DECR("state.nacts") << " > 0 do\n"
			"		begin match " << AT( A(), POST_INCR("state.acts") ) << " with\n";
			ACTION_SWITCH();
			SWITCH_DEFAULT() <<
			"		end;\n"
			"	done\n"
      "\twith Goto_again -> () end;\n";
	}
  out << "\tdo_again ()\n";

//	if ( redFsm->anyRegActions() || redFsm->anyActionGotos() || 
//			redFsm->anyActionCalls() || redFsm->anyActionRets() )
  out << "\tand do_again () =\n";

	if ( redFsm->anyToStateActions() ) {
		out <<
			"	state.acts <- " << AT( TSA(), vCS() ) << ";\n"
			"	state.nacts <- " << AT( A(), POST_INCR("state.acts") ) << ";\n"
			"	while " << POST_DECR("state.nacts") << " > 0 do\n"
			"		begin match " << AT( A(), POST_INCR("state.acts") ) << " with\n";
			TO_STATE_ACTION_SWITCH();
			SWITCH_DEFAULT() <<
			"		end\n"
			"	done;\n"
			"\n";
	}

	if ( redFsm->errState != 0 ) {
		outLabelUsed = true;
		out << 
			"	match " << vCS() << " with\n"
      "\t| " << redFsm->errState->id << " -> do_out ()\n"
      "\t| _ ->\n";
	}

  out << "\t" << P() << " <- " << P() << " + 1;\n";

	if ( !noEnd ) {
		out << 
			"	if " << P() << " <> " << PE() << " then\n"
			"		do_resume ()\n"
      "\telse do_test_eof ()\n";
	}
	else {
		out << 
			"	do_resume ()\n";
	}

//	if ( testEofUsed )
	out << "and do_test_eof () =\n";
	
	if ( redFsm->anyEofTrans() || redFsm->anyEofActions() ) {
		out << 
			"	if " << P() << " = " << vEOF() << " then\n"
			"	begin try\n";

		if ( redFsm->anyEofTrans() ) {
			out <<
				"	if " << AT( ET(), vCS() ) << " > 0 then\n"
				"	begin\n"
        "   state.trans <- " << CAST(transType) << "(" << AT( ET(), vCS() ) << " - 1);\n"
				"		raise Goto_eof_trans;\n"
				"	end\n";
		}

		if ( redFsm->anyEofActions() ) {
			out <<
				"	let __acts = ref " << AT( EA(), vCS() ) << " in\n"
				"	let __nacts = ref " << AT( A(), "!__acts" ) << " in\n"
        " incr __acts;\n"
				"	while !__nacts > 0 do\n"
        "   decr __nacts;\n"
				"		begin match " << AT( A(), POST_INCR("__acts.contents") ) << " with\n";
				EOF_ACTION_SWITCH();
				SWITCH_DEFAULT() <<
				"		end;\n"
				"	done\n";
		}

		out << 
			"	with Goto_again -> do_again ()\n"
			"	| Goto_eof_trans -> do_eof_trans () end\n"
			"\n";
	}
  else
  {
    out << "\t()\n";
  }

	if ( outLabelUsed )
		out << "	and do_out () = ()\n";

  out << "\tin do_start ()\n";
	out << "	end;\n";
}
Exemplo n.º 16
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.º 17
0
void FGotoCodeGen::writeExec()
{
	testEofUsed = false;
	outLabelUsed = false;

	out << L"	{\n";

	if ( redFsm->anyRegCurStateRef() )
		out << L"	int _ps = 0;\n";

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

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

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

	out << L"_resume:\n";

	if ( redFsm->anyFromStateActions() ) {
		out <<
			L"	switch ( " << FSA() << L"[" << vCS() << L"] ) {\n";
			FROM_STATE_ACTION_SWITCH();
			SWITCH_DEFAULT() <<
			L"	}\n"
			L"\n";
	}

	out << 
		L"	switch ( " << vCS() << L" ) {\n";
		STATE_GOTOS();
		SWITCH_DEFAULT() <<
		L"	}\n"
		L"\n";
		TRANSITIONS() << 
		L"\n";

	if ( redFsm->anyRegActions() )
		EXEC_ACTIONS() << L"\n";

	out << L"_again:\n";

	if ( redFsm->anyToStateActions() ) {
		out <<
			L"	switch ( " << TSA() << L"[" << vCS() << L"] ) {\n";
			TO_STATE_ACTION_SWITCH();
			SWITCH_DEFAULT() <<
			L"	}\n"
			L"\n";
	}

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

	if ( !noEnd ) {
		out << 
			L"	if ( ++" << P() << L" != " << PE() << L" )\n"
			L"		goto _resume;\n";
	}
	else {
		out << 
			L"	" << P() << L" += 1;\n"
			L"	goto _resume;\n";
	}

	if ( testEofUsed )
		out << L"	_test_eof: {}\n";

	if ( redFsm->anyEofTrans() || redFsm->anyEofActions() ) {
		out <<
			L"	if ( " << P() << L" == " << vEOF() << L" )\n"
			L"	{\n";

		if ( redFsm->anyEofTrans() ) {
			out <<
				L"	switch ( " << vCS() << L" ) {\n";

			for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
				if ( st->eofTrans != 0 )
					out << L"	case " << st->id << L": goto tr" << st->eofTrans->id << L";\n";
			}

			SWITCH_DEFAULT() <<
				L"	}\n";
		}

		if ( redFsm->anyEofActions() ) {
			out <<
				L"	switch ( " << EA() << L"[" << vCS() << L"] ) {\n";
				EOF_ACTION_SWITCH();
				SWITCH_DEFAULT() <<
				L"	}\n";
		}

		out <<
			L"	}\n"
			L"\n";
	}

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

	out << L"	}\n";
}
Exemplo n.º 18
0
void CSharpFlatCodeGen::writeExec()
{
	testEofUsed = false;
	outLabelUsed = false;
	initVarTypes();

	out << 
		"	{\n"
		"	" << slenType << " _slen";

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

	out << 
		";\n"
		"	" << transType << " _trans";

	if ( redFsm->anyConditions() )
		out << ", _cond";
	out << ";\n";

	if ( redFsm->anyToStateActions() || 
			redFsm->anyRegActions() || redFsm->anyFromStateActions() )
	{
		out << 
			"	" << actsType << " _acts;\n"
			"	" << nactsType << " _nacts;\n"; 
	}

	out <<
		"	" << "int _keys;\n"
		"	" << indsType << " _inds;\n";
		/*
		"	" << PTR_CONST() << WIDE_ALPH_TYPE() << POINTER() << "_keys;\n"
		"	" << PTR_CONST() << ARRAY_TYPE(redFsm->maxIndex) << POINTER() << "_inds;\n";*/

	if ( redFsm->anyConditions() ) {
		out << 
			"	" << condsType << " _conds;\n"
			"	" << WIDE_ALPH_TYPE() << " _widec;\n";
	}

	out << "\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 = " << FSA() << "[" << vCS() << "];\n"
			"	_nacts = " << A() << "[_acts++];\n"
			"	while ( _nacts-- > 0 ) {\n"
			"		switch ( " << A() << "[_acts++] ) {\n";
			FROM_STATE_ACTION_SWITCH();
			SWITCH_DEFAULT() <<
			"		}\n"
			"	}\n"
			"\n";
	}

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

	LOCATE_TRANS();

	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 = " << TA() << "[_trans];\n"
			"	_nacts = " << A() << "[_acts++];\n"
			"	while ( _nacts-- > 0 ) {\n"
			"		switch ( " << A() << "[_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 = " << TSA() << "[" << vCS() << "];\n"
			"	_nacts = " << A() << "[_acts++];\n"
			"	while ( _nacts-- > 0 ) {\n"
			"		switch ( " << A() << "[_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 = " << CAST(transType) << " (" << ET() << 
					"[" << vCS() << "] - 1);\n"
				"		goto _eof_trans;\n"
				"	}\n";
		}

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

		out <<
			"	}\n"
			"\n";
	}

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

	out << "	}\n";
}