⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jsp_parser.cpp

📁 JAPAN RTOS TOPPERS/JSP kernel 1.4 PreRelease simulation environment JSP kernel Windows simulation
💻 CPP
📖 第 1 页 / 共 2 页
字号:


		//昁梫側忣曬偺嶌惉
	work = string(va_arg(vl, const char *));
	id["id"]  = work;
	for(i=0; i<(signed)work.size(); i++)
		work[i] = work[i] - 'a' + 'A';
	id["ID"]  = work;

	if((flag & SHORT_ID) != 0)
	{
		work = string(va_arg(vl, const char *));
		id["sid"]  = work;
		for(i=0; i<(signed)work.size(); i++)
			work[i] = work[i] - 'a' + 'A';
		id["SID"]  = work;
	}else
	{
		id["sid"] = id["id"].toString();
		id["SID"] = id["ID"].toString();
	}

	if(!backward_compatible)
		id["symbolprefix"] = "_kernel_";

	work = container.getKey();
	id["name"] = work;
	out->moveto(work);

		//僆僽僕僃僋僩弶婜壔娭悢傪捛壛
	if((flag & INIT) != 0 && container.size() != 0)
		container["/" OBJECT_INITIALIZER].addChild(new Directory(work));

	(*out) << "\n\t/* " << (Message("Object initializer [%]","僆僽僕僃僋僩弶婜壔僽儘僢僋 [%]") << work) << " */\n\n";

	if(((flag & HEADER) != 0) && backward_compatible)
	{
		(*out) << "#include ";
		if(libstyle_include)
			(*out) << '<' << work << ".h>\n\n";
		else
			(*out) << '\"' << work << ".h\"\n\n";
	}

	if((flag & TNUM) != 0)
	{
		(*out) << id.format("#define TNUM_$(ID)ID ") << container.size() << "\n\n";
		(*out) << id.format("const ID $(symbolprefix,)tmax_$(id)id = (TMIN_$(ID)ID + TNUM_$(ID)ID - 1);\n\n");
	}

	if((flag & TNUMNO) != 0)
	{
		(*out) << id.format("#define TNUM_$(ID)NO ") << container.size() << "\n\n";
		(*out) << id.format("const UINT $(symbolprefix,)tnum_$(id)no = TNUM_$(ID)NO;\n\n");
	}

		/* ID弴偵僜乕僩 (偙偺帪揰偱楢斣偑妋掕偟偰偄傞偼偢側偺偱丆僠僃僢僋偼偟側偄) */
	if((flag & (BUFFER|DEFINITION)) != 0)
	{
		const bool is_identifier = (flag & TNUMNO) == 0;

		i = 0;
		scope = container.getFirstChild();
		while(scope != 0)
		{
			if(is_identifier)
				sorter[scope->toInteger(i++)] = scope;
			else
				sorter[i++] = scope;

			scope = scope->getNext();
		}
	}

		//僾儘僩僞僀僾掕媊偺弌椡
	if((flag & PROTOTYPE) != 0)
	{
		buffer = va_arg(vl, const char *);

		if(def_prototype)
		{
			set<string> func;
			set<string>::iterator pfunc;

			scope = container.getFirstChild();
			while(scope != NULL)
			{
				func.insert(scope->format(buffer));
				scope = scope->getNext();
			}

			pfunc = func.begin();
			while(pfunc != func.end())
			{
				(*out) << (*pfunc) << endl;
				++ pfunc;
			}
		}
	}

		//僶僢僼傽偺嶌惉
	if((flag & BUFFER) != 0 && container.size() != 0)
	{
		buffer = va_arg(vl, const char *);
		psorter = sorter.begin();
		while(psorter != sorter.end())
		{
			(*out) << (*psorter).second->format(buffer) << '\n';
			++ psorter;
		}
		(*out) << '\n';
	}

		//掕媊僽儘僢僋(xINIB)偺弌椡
	if((flag & DEFINITION) != 0)
	{
		buffer = va_arg(vl, const char *);
		if(container.size() != 0)
		{
			(*out) << id.format("const $(SID)INIB $(symbolprefix,)$(sid)inib_table[TNUM_$(ID)") << ( (flag & TNUMNO) != 0  ? "NO" : "ID") << "] = {\n";
			psorter = sorter.begin();
			while(psorter != sorter.end())
			{
				(*out) << "\t{" << (*psorter).second->format(buffer) << '}';
				++ psorter;
				if(psorter != sorter.end())
					(*out) << ',';
				(*out) << '\n';
			}
			(*out) << "};\n\n";
		}else
			if( !restrict_zero )
				(*out) << id.format("__ZERO(const $(SID)INIB,$(symbolprefix,)$(sid)inib_table);\n");
	}

	if((flag & INITLIST) != 0)
	{
		Directory * node;

			/* 愰尵弴偱ID斣崋傪僜乕僩 */
		sorter.clear();
		node = container.getFirstChild();
		while(node != NULL)
		{
			sorter.insert(pair<int,Directory*>(node->findChild("#order")->toInteger(), node));
			node = node->getNext();
		}

		*out << id.format("const ID $(symbolprefix,)$(sid)order_table[TNUM_$(ID)ID] = {");
		psorter = sorter.begin();
		while(psorter != sorter.end())
		{
			*out << psorter->second->toInteger();
			++ psorter;
			if(psorter != sorter.end())
				*out << ',';
		}
		*out << "};\n\n";
	}

		//惂屼僽儘僢僋(xCB)偺弌椡
	if((flag & CONTROLBLOCK) != 0)
	{
		if(container.size() != 0)
			(*out) << id.format("$(SID)CB $(symbolprefix,)$(sid)cb_table[TNUM_$(ID)ID];\n\n");
		else
			if( !restrict_zero )
				(*out) << id.format("__ZERO($(SID)CB, $(symbolprefix,)$(sid)cb_table);\n\n");
	}
}

void ConfigurationFileGenerator::body(Directory & container)
{
	Directory * scope;
	mpstrstream * out;
	string work;

		/* kernel_id.h偺弌椡 */
	out = reinterpret_cast<mpstrstream *>(container(KERNEL_ID)->toPointer());
	out->moveto("body");
	scope = container("/identifier")->getFirstChild();
	while(scope != 0)
	{
		(*out) << "#define " << scope->getKey() << " " << scope->toInteger() << endl;
		scope = scope->getNext();
	}

		/* kernel_cfg.c偺弌椡 */
	out = reinterpret_cast<mpstrstream *>(container(KERNEL_CFG)->toPointer());
	out->moveto("header");
	(*out) << "/* Configured by [" << container["/Parameter/#cmdline"].toString() << "] */\n\n";

	if(!backward_compatible)
	{
		if(libstyle_include)
			(*out) <<	"#include <kernel_cfg.h>\n";
		else
			(*out) <<	"#include \"kernel_cfg.h\"\n";
	}

	if(!findOption(container,"id","kernel_id",&work))
		work.assign("kernel_id.h");
	(*out) << "#include \"" << work << "\"\n\n";

	if(backward_compatible)
		(*out) <<	"#if TKERNEL_PRVER >= 0x1011\n\n";


	(*out) <<	"#define CFG_INTHDR_ENTRY(inthdr) INTHDR_ENTRY(inthdr)\n"
				"#define CFG_EXCHDR_ENTRY(exchdr) EXCHDR_ENTRY(exchdr)\n"
				"#define CFG_INT_ENTRY(inthdr) INT_ENTRY(inthdr)\n"
				"#define CFG_EXC_ENTRY(exchdr) EXC_ENTRY(exchdr)\n";

	if(backward_compatible)
		(*out) <<	"\n#else\n\n"
					"#define CFG_INTHDR_ENTRY(inthdr) INTHDR_ENTRY(ENTRY(inthdr), inthdr)\n"
					"#define CFG_EXCHDR_ENTRY(exchdr) EXCHDR_ENTRY(ENTRY(exchdr), exchdr)\n"
					"#define CFG_INT_ENTRY(inthdr) ENTRY(inthdr)\n"
					"#define CFG_EXC_ENTRY(exchdr) ENTRY(exchdr)\n"
					"\n#endif\n";

	(*out) << "\n";

	if( !restrict_zero )
	{
		if(!findOption(container, "ZERO","ZERO",&work))
			work.assign("x y[0]");
		(*out) << "#if defined(_MSC_VER) || defined(__BORLANDC__)\n  #define __ZERO(x,y) _declspec(naked) void y(void){}\n#else\n  #define __ZERO(x,y) " << work << "\n#endif\n\n";
	}

		/* INCLUDE */
	out->moveto(INCLUDEFILE);
	scope = container(OBJECTTREE "/" INCLUDEFILE)->getFirstChild();
	(*out) << "\t/* " << Message("User specified include files","儐乕僓掕媊偺僀儞僋儖乕僪僼傽僀儖") << "*/\n";
	while(scope != 0)
	{
		(*out) << "#include " << scope->toString() << endl;
		scope = scope->getNext();
	}
	(*out) << '\n';

		/* TASK */
    work.assign("$(tskatr), (VP_INT)($(exinf)), (FP)($(task)), INT_PRIORITY($(itskpri)), TROUND_VP($(stksz)), __stack_$@, $(texatr), (FP)($(texrtn))");
    if(container["/cpu"].toString().compare("nios32") == 0)
        work += ", $(hi_limit), $(lo_limit)";
	createObjectDefinition(out, container[OBJECTTREE "/" TASK], HEADER|TNUM|SHORT_ID|BUFFER|DEFINITION|CONTROLBLOCK|INIT|PROTOTYPE|INITLIST,"tsk", "t", "void $(task)(VP_INT exinf);", "static VP __stack_$@[TCOUNT_VP($(stksz))];",work.c_str());

		/* SEMAPHORE */
	createObjectDefinition(out, container[OBJECTTREE "/" SEMAPHORE], HEADER|TNUM|DEFINITION|CONTROLBLOCK|INIT,"sem", "$(sematr), $(isemcnt), $(maxsem)");

		/* EVENTFLAG */
	createObjectDefinition(out, container[OBJECTTREE "/" EVENTFLAG], HEADER|TNUM|DEFINITION|CONTROLBLOCK|INIT,"flg", "$(flgatr), $(iflgptn)");

		/* DATAQUEUE */
	createObjectDefinition(out, container[OBJECTTREE "/" DATAQUEUE], HEADER|TNUM|BUFFER|DEFINITION|CONTROLBLOCK|INIT,"dtq", "#if ($(dtqcnt)) > 0\n  static VP_INT __dataqueue_$@[$(dtqcnt)];\n#else\n  #define __dataqueue_$@ NULL\n#endif","$(dtqatr), $(dtqcnt), __dataqueue_$@");

		/* MAILBOX */
	createObjectDefinition(out, container[OBJECTTREE "/" MAILBOX], HEADER|TNUM|DEFINITION|CONTROLBLOCK|INIT,"mbx","$(mbxatr), $(maxmpri)");

		/* FIXEDSIZEMEMORYPOOL */
	createObjectDefinition(out, container[OBJECTTREE "/" FIXEDSIZEMEMORYPOOL], HEADER|TNUM|BUFFER|DEFINITION|CONTROLBLOCK|INIT,"mpf","static VP __fixedsize_memorypool_$@[TCOUNT_VP($(blksz)) * (($(blkcnt)))];","$(mpfatr), TROUND_VP($(blksz)), __fixedsize_memorypool_$@, (VP)((VB *)__fixedsize_memorypool_$@ + sizeof(__fixedsize_memorypool_$@))");

		/* CYCLICHANDLER */
	createObjectDefinition(out, container[OBJECTTREE "/" CYCLICHANDLER], HEADER|TNUM|DEFINITION|CONTROLBLOCK|INIT|PROTOTYPE,"cyc","void $(cychdr)(VP_INT exinf);","$(cycatr),$(exinf),(FP)($(cychdr)),$(cyctim),$(cycphs)");

		/* INTERRUPTHANDLER */
	createObjectDefinition(out, container[OBJECTTREE "/" INTERRUPTHANDLER], HEADER|BUFFER|TNUMNO|DEFINITION|INIT|PROTOTYPE,"inh","void $(inthdr)(void);","CFG_INTHDR_ENTRY($(inthdr));","$@,$(inhatr),(FP)CFG_INT_ENTRY($(inthdr))");

		/* EXCEPTIONHANDLER */
	createObjectDefinition(out, container[OBJECTTREE "/" EXCEPTIONHANDLER], HEADER|BUFFER|TNUMNO|DEFINITION|INIT|PROTOTYPE,"exc","void $(exchdr)(VP p_excinf);","CFG_EXCHDR_ENTRY($(exchdr));","$@,$(excatr),(FP)CFG_EXC_ENTRY($(exchdr))");


	if(!backward_compatible)
		work.assign("_kernel_");
	else
		work.assign("");


		/* 僆僽僕僃僋僩弶婜壔儖乕僠儞 */
	out->moveto(OBJECT_INITIALIZER);
	(*out) << "\t/* " << Message("Object initialization routine","僆僽僕僃僋僩弶婜壔儖乕僠儞") << " */\n\n";
	(*out) << "void\n" << work << "object_initialize(void)\n{\n";
	scope = container["/" OBJECT_INITIALIZER].getFirstChild();
	while(scope != 0)
	{
		(*out) << '\t' << work << scope->toString() << "_initialize();\n";
		scope = scope->getNext();
	}
	(*out) << "}\n\n";


		/* 弶婜壔僴儞僪儔 */
	out->moveto(INITIALIZER);
	(*out) << "\t/* " << Message("Initialization handler","弶婜壔僴儞僪儔婲摦儖乕僠儞") << " */\n\n";
	(*out) << "void\n" << work << "call_inirtn(void)\n{\n";
	scope = container[OBJECTTREE "/" INITIALIZER].getFirstChild();
	while(scope != 0)
	{
		(*out) << scope->format("\t$(inirtn)( (VP_INT)($(exinf)) );\n");
		scope = scope->getNext();
	}
	(*out) << "}\n\n";

		/* 廔椆僴儞僪儔 */
	scope = container[OBJECTTREE "/"  TERMINATOR].getLastChild();
	if(!backward_compatible) {
		(*out) << "void\n" << work << "call_terrtn(void)\n{\n";
		while(scope != 0)
		{
			(*out) << scope->format("\t$(terrtn)( (VP_INT)($(exinf)) );\n");
			scope = scope->getPrev();
		}
		(*out) << "}\n\n";
	}
	else {
		if(scope->size() != 0)
			ExceptionMessage("VATT_TER is not supported for TOPPERS/JSP rel 1.3 or earlier.",
							 "VATT_TER偼TOPPERS/JSP rel 1.3埲慜偱偼僒億乕僩偝傟傑偣傫").throwException();
	}

	out->moveto("others");
	(*out) << "TMEVTN	" << work << "tmevt_heap[TNUM_TSKID + TNUM_CYCID];\n\n";

	container["/object_initializer"].erase();

	string filename;
	if(findOption(container,"obj","dump-object",&filename))
	{
		if(filename.empty())
			filename.assign("kernel_obj.dat");

		fstream f(filename.c_str(),ios::out|ios::binary);
		if(f.is_open())
		{
			container[OBJECTTREE].Store(&f);
			f.close();
		}else
			ExceptionMessage(" Failed to open the file % for storing object definitions"," 僆僽僕僃僋僩忣曬傪奿擺偡傞偨傔偺僼傽僀儖(%)偑奐偗傑偣傫") << filename << throwException;
	}
}


/* ======================================================================== */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -