Пример #1
0
int unmarshallGraph(const std::string& file, char delimiter) {
	Graphs graphs;
	graphs.unmarshall(file, delimiter);

	if(Env::verbose()) {
		std::cout << "Graphs: " << graphs.size() << std::endl;
		for (Graphs::Graph_map::iterator it = graphs.begin(); it != graphs.end(); it++) {
			std::cout << it->first << it->second << std::endl;
		}
	}

	std::shared_ptr<Graph> g = graphs.find("main");
	if (g == nullptr)
		return -9;

	if(Env::verbose()) {
		std::cout << "Name: " << g->name() << "Size: " << g->nodeCount() << std::endl;
	}
	std::shared_ptr<Node> n = g->start();
	printNode(n);

	g = graphs.find("Hello");
	if (g == nullptr)
		return -9;

	if(Env::verbose()) {
		std::cout << "Name: " << g->name() << "Size: " << g->nodeCount() << std::endl;
	}

	n = g->start();
	printNode(n);
	return 0;
}
Пример #2
0
int main(int argc, char *argv[]) {

	try {
		Env::parseParams(argc, argv);


		if(Env::verbose()) {
			std::cout << std::endl;
			std::cout << "          __      _ __          " << std::endl;
			std::cout << "         / /___ _(_) / __    __ " << std::endl;
			std::cout << "    __  / / __ `/ / /_/ /___/ /_" << std::endl;
			std::cout << "   / /_/ / /_/ / / /_  __/_  __/" << std::endl;
			std::cout << "   \\____/\\__,_/_/_/ /_/   /_/   " << std::endl;
			std::cout << std::endl;
		}

		Env::initTimer();


		//Env::initIoDirectory();		// produces io folders from the callers location - not intended
		Env::showStatus();

		Graphs graphs;


		// ------------------------------------------------------------------------
		// FRONTEND
		// ------------------------------------------------------------------------

		if(Env::hasSrcFile()) {

			Env::printCaption("Frontend - Lexer");

			// Lexer
			Lexer lexer;
			lexer.lex(Env::getSrcFile());
			Env::showStatus();
			if(!lexer.hasFunctions()) {
				throw EnvException(FRONTEND_LEXER, "No rail functions found in " + Env::getSrcFile());
			}

			// Parser
			Env::printCaption("Frontend - Parser");
			Parser p(lexer.functions);
			graphs = p.parseGraphs(graphs);
			Env::showStatus();
		}
		else if(Env::hasSrcDeserialize()) {
			// Deserialize
			Env::printCaption("ASG - Deserialize");
			graphs.unmarshall(Env::getSrcDeserialize(), ';');
			Env::showStatus();
		}
		else {
			// handled within Env.h
		}

		// ------------------------------------------------------------------------
		// ASG
		// ------------------------------------------------------------------------

		// Serialize
		if(Env::hasDstSerialize()) {
			Env::printCaption("ASG - Serialize");
			graphs.marshall(Env::getDstSerialize(), ';');
		}
		Env::showStatus();

		// GraphViz
		if(Env::hasDstGraphviz()) {
			Env::printCaption("ASG - GraphViz");
			graphs.writeGraphViz(Env::getDstGraphviz());
		}
		Env::showStatus();




		// ------------------------------------------------------------------------
		// BACKEND
		// ------------------------------------------------------------------------
		if(Env::hasDstClassfile()) {
			Env::printCaption("Backend");

			// TODO #118
			ofstream outFile(Env::getDstClassfile(), std::ofstream::binary);
			Backend::Generate(graphs, &outFile);
			Env::showStatus();
			if(Env::verbose()) {
				std::cout << "done..." << std::endl;
			}
		}



		Env::printCaption("Finished");

		Env::printBuildStatus(!Env::hasErrors());
		return Env::hasErrors();

	}
	catch(EnvException &ee) {
		Env::showStatus();
		ee.showMessage();
		Env::printBuildStatus(false);
		return 1;
	}
	catch(...) {
		Env::addError(UNKNOWN, "An unhandled exception occurred");
		Env::showStatus();
		Env::printBuildStatus(false);
		return 1;
	}

}