Exemplo n.º 1
0
/***************************************************************
* Function: CodeParser::parseXMLFile()
* Purpose : Parse a an XML IR file
* Initial : Maxime Chevalier-Boisvert on November 18, 2008
****************************************************************
Revisions and bug fixes:
*/
CompUnits CodeParser::parseXMLFile(const std::string& filePath)
{
	// Log that we are parsing this file
	std::cout << "Parsing XML IR file: \"" << filePath << "\"" << std::endl;

	// Create an XML parser object
	XML::Parser parser;

	// Setup a try block to catch any errors
	try
	{
		// Parse the IR code string
		XML::Document xmlIR = parser.parseFile(filePath);

		// If the verbose output flag is set
		if (ConfigManager::s_verboseVar.getBoolValue() == true)
		{
			// Output the parsed XML
			std::cout << std::endl;
			std::cout << "Parsed XML: " << std::endl;
			std::cout << xmlIR.toString() << std::endl;
			std::cout << std::endl;
		}

		// Get a pointer to the XML tree root
		const XML::Element* pTreeRoot = xmlIR.getTree();

		// Parse the XML tree
		return parseXMLRoot(pTreeRoot);
	}

	// If XML parsing error occur
	catch (XML::ParseError error)
	{
		// Log the error
		std::cout << "ERROR: XML parsing failed " + error.toString() << std::endl;

		// Exit this function
		return CompUnits();
	}
}