diff options
Diffstat (limited to 'elftosb2')
-rw-r--r-- | elftosb2/BootImageGenerator.cpp | 80 | ||||
-rw-r--r-- | elftosb2/BootImageGenerator.h | 69 | ||||
-rw-r--r-- | elftosb2/ConversionController.cpp | 1428 | ||||
-rw-r--r-- | elftosb2/ConversionController.h | 153 | ||||
-rw-r--r-- | elftosb2/Doxyfile | 250 | ||||
-rw-r--r-- | elftosb2/ElftosbAST.cpp | 1352 | ||||
-rw-r--r-- | elftosb2/ElftosbAST.h | 1227 | ||||
-rw-r--r-- | elftosb2/ElftosbErrors.h | 29 | ||||
-rw-r--r-- | elftosb2/ElftosbLexer.cpp | 149 | ||||
-rw-r--r-- | elftosb2/ElftosbLexer.h | 97 | ||||
-rw-r--r-- | elftosb2/EncoreBootImageGenerator.cpp | 297 | ||||
-rw-r--r-- | elftosb2/EncoreBootImageGenerator.h | 57 | ||||
-rw-r--r-- | elftosb2/FlexLexer.h | 208 | ||||
-rw-r--r-- | elftosb2/elftosb.cpp | 700 | ||||
-rw-r--r-- | elftosb2/elftosb_lexer.cpp | 2241 | ||||
-rw-r--r-- | elftosb2/elftosb_lexer.l | 299 | ||||
-rw-r--r-- | elftosb2/elftosb_parser.tab.cpp | 2955 | ||||
-rw-r--r-- | elftosb2/elftosb_parser.tab.hpp | 152 | ||||
-rw-r--r-- | elftosb2/elftosb_parser.y | 978 |
19 files changed, 12721 insertions, 0 deletions
diff --git a/elftosb2/BootImageGenerator.cpp b/elftosb2/BootImageGenerator.cpp new file mode 100644 index 0000000..63daf26 --- /dev/null +++ b/elftosb2/BootImageGenerator.cpp @@ -0,0 +1,80 @@ +/* + * BootImageGenerator.cpp + * elftosb + * + * Copyright (c) Freescale Semiconductor, Inc. All rights reserved. + * See included license file for license details. + */ + +#include "BootImageGenerator.h" +#include "Logging.h" + +//! Name of product version option. +#define kProductVersionOption "productVersion" + +//! Name of component version option. +#define kComponentVersionOption "componentVersion" + +//! Name of option that specifies the drive tag for this .sb file. +#define kDriveTagOption "driveTag" + +using namespace elftosb; + +void BootImageGenerator::processVersionOptions(BootImage * image) +{ + // bail if no option context was set + if (!m_options) + { + return; + } + + const StringValue * stringValue; + version_t version; + + // productVersion + if (m_options->hasOption(kProductVersionOption)) + { + stringValue = dynamic_cast<const StringValue *>(m_options->getOption(kProductVersionOption)); + if (stringValue) + { + version.set(*stringValue); + image->setProductVersion(version); + } + else + { + Log::log(Logger::WARNING, "warning: productVersion option is an unexpected type\n"); + } + } + + // componentVersion + if (m_options->hasOption(kComponentVersionOption)) + { + stringValue = dynamic_cast<const StringValue *>(m_options->getOption(kComponentVersionOption)); + if (stringValue) + { + version.set(*stringValue); + image->setComponentVersion(version); + } + else + { + Log::log(Logger::WARNING, "warning: componentVersion option is an unexpected type\n"); + } + } +} + +void BootImageGenerator::processDriveTagOption(BootImage * image) +{ + if (m_options->hasOption(kDriveTagOption)) + { + const IntegerValue * intValue = dynamic_cast<const IntegerValue *>(m_options->getOption(kDriveTagOption)); + if (intValue) + { + image->setDriveTag(intValue->getValue()); + } + else + { + Log::log(Logger::WARNING, "warning: driveTag option is an unexpected type\n"); + } + } +} + diff --git a/elftosb2/BootImageGenerator.h b/elftosb2/BootImageGenerator.h new file mode 100644 index 0000000..3d50fbb --- /dev/null +++ b/elftosb2/BootImageGenerator.h @@ -0,0 +1,69 @@ +/* + * File: BootImageGenerator.h + * + * Copyright (c) Freescale Semiconductor, Inc. All rights reserved. + * See included license file for license details. + */ +#if !defined(_BootImageGenerator_h_) +#define _BootImageGenerator_h_ + +#include "OutputSection.h" +#include "BootImage.h" +#include "OptionContext.h" + +namespace elftosb +{ + +/*! + * \brief Abstract base class for generators of specific boot image formats. + * + * Subclasses implement a concrete generator for a certain boot image format, but + * they all have the same interface. + * + * After creating an instance of a subclass the user adds OutputSection objects + * to the generator. These objects describe discrete sections within the resulting + * boot image file. If the format does not support multiple sections then only + * the first will be used. + * + * Options that are common to all boot image formats are handled by methods + * defined in this class. These are the current common options: + * - productVersion + * - componentVersion + * - driveTag + */ +class BootImageGenerator +{ +public: + //! \brief Constructor. + BootImageGenerator() {} + + //! \brief Destructor. + virtual ~BootImageGenerator() {} + + //! \brief Add another section to the output. + void addOutputSection(OutputSection * section) { m_sections.push_back(section); } + + //! \brief Set the global option context. + void setOptionContext(OptionContext * context) { m_options = context; } + + //! \brief Pure virtual method to generate the output BootImage from input sections. + virtual BootImage * generate()=0; + +protected: + //! Type for a list of model output sections. + typedef std::vector<OutputSection*> section_vector_t; + + section_vector_t m_sections; //!< Requested output sections. + OptionContext * m_options; //!< Global option context. + + //! \brief Handle common product and component version options. + void processVersionOptions(BootImage * image); + + //! \brief Handle the common option which sets the system drive tag. + void processDriveTagOption(BootImage * image); +}; + +}; // namespace elftosb + +#endif // _BootImageGenerator_h_ + diff --git a/elftosb2/ConversionController.cpp b/elftosb2/ConversionController.cpp new file mode 100644 index 0000000..dd3341c --- /dev/null +++ b/elftosb2/ConversionController.cpp @@ -0,0 +1,1428 @@ +/* + * File: ConversionController.cpp + * + * Copyright (c) Freescale Semiconductor, Inc. All rights reserved. + * See included license file for license details. + */ + +#include "ConversionController.h" +#include <stdexcept> +#include "EvalContext.h" +#include "ElftosbErrors.h" +#include "GlobMatcher.h" +#include "ExcludesListMatcher.h" +#include "BootImageGenerator.h" +#include "EncoreBootImageGenerator.h" +#include "Logging.h" +#include "OptionDictionary.h" +#include "format_string.h" +#include "SearchPath.h" +#include "DataSourceImager.h" +#include "IVTDataSource.h" +#include <algorithm> + +//! Set to 1 to cause the ConversionController to print information about +//! the values that it processes (options, constants, etc.). +#define PRINT_VALUES 1 + +using namespace elftosb; + +// Define the parser function prototype; +extern int yyparse(ElftosbLexer * lexer, CommandFileASTNode ** resultAST); + +bool elftosb::g_enableHABSupport = false; + +ConversionController::ConversionController() +: OptionDictionary(), + m_commandFilePath(), + m_ast(), + m_defaultSource(0) +{ + m_context.setSourceFileManager(this); +} + +ConversionController::~ConversionController() +{ + // clean up sources + source_map_t::iterator it = m_sources.begin(); + for (; it != m_sources.end(); ++it) + { + if (it->second) + { + delete it->second; + } + } +} + +void ConversionController::setCommandFilePath(const std::string & path) +{ + m_commandFilePath = new std::string(path); +} + +//! The paths provided to this method are added to an array and accessed with the +//! "extern(N)" notation in the command file. So the path provided in the third +//! call to addExternalFilePath() will be found with N=2 in the source definition. +void ConversionController::addExternalFilePath(const std::string & path) +{ + m_externPaths.push_back(path); +} + +bool ConversionController::hasSourceFile(const std::string & name) +{ + return m_sources.find(name) != m_sources.end(); +} + +SourceFile * ConversionController::getSourceFile(const std::string & name) +{ + if (!hasSourceFile(name)) + { + return NULL; + } + + return m_sources[name]; +} + +SourceFile * ConversionController::getDefaultSourceFile() +{ + return m_defaultSource; +} + +//! These steps are executed while running this method: +//! - The command file is parsed into an abstract syntax tree. +//! - The list of options is extracted. +//! - Constant expressions are evaluated. +//! - The list of source files is extracted and source file objects created. +//! - Section definitions are extracted. +//! +//! This method does not produce any output. It processes the input files and +//! builds a representation of the output in memory. Use the generateOutput() method +//! to produce a BootImage object after this method returns. +//! +//! \note This method is \e not reentrant. And in fact, the whole class is not designed +//! to be reentrant. +//! +//! \exception std::runtime_error Any number of problems will cause this exception to +//! be thrown. +//! +//! \see parseCommandFile() +//! \see processOptions() +//! \see processConstants() +//! \see processSources() +//! \see processSections() +void ConversionController::run() +{ +#if PRINT_VALUES + Log::SetOutputLevel debugLevel(Logger::DEBUG2); +#endif + + parseCommandFile(); + assert(m_ast); + + ListASTNode * blocks = m_ast->getBlocks(); + if (!blocks) + { + throw std::runtime_error("command file has no blocks"); + } + + ListASTNode::iterator it = blocks->begin(); + for (; it != blocks->end(); ++it) + { + ASTNode * node = *it; + + // Handle an options block. + OptionsBlockASTNode * options = dynamic_cast<OptionsBlockASTNode *>(node); + if (options) + { + processOptions(options->getOptions()); + continue; + } + + // Handle a constants block. + ConstantsBlockASTNode * constants = dynamic_cast<ConstantsBlockASTNode *>(node); + if (constants) + { + processConstants(constants->getConstants()); + continue; + } + + // Handle a sources block. + SourcesBlockASTNode * sources = dynamic_cast<SourcesBlockASTNode *>(node); + if (sources) + { + processSources(sources->getSources()); + } + } + + processSections(m_ast->getSections()); +} + +//! Opens the command file and runs it through the lexer and parser. The resulting +//! abstract syntax tree is held in the m_ast member variable. After parsing, the +//! command file is closed. +//! +//! \exception std::runtime_error Several problems will cause this exception to be +//! raised, including an unspecified command file path or an error opening the +//! file. +void ConversionController::parseCommandFile() +{ + if (!m_commandFilePath) + { + throw std::runtime_error("no command file path was provided"); + } + + // Search for command file + std::string actualPath; + bool found = PathSearcher::getGlobalSearcher().search(*m_commandFilePath, PathSearcher::kFindFile, true, actualPath); + if (!found) + { + throw runtime_error(format_string("unable to find command file %s\n", m_commandFilePath->c_str())); + } + + // open command file + std::ifstream commandFile(actualPath.c_str(), ios_base::in | ios_base::binary); + if (!commandFile.is_open()) + { + throw std::runtime_error("could not open command file"); + } + + try + { + // create lexer instance + ElftosbLexer lexer(commandFile); +// testLexer(lexer); + + CommandFileASTNode * ast = NULL; + int result = yyparse(&lexer, &ast); + m_ast = ast; + + // check results + if (result || !m_ast) + { + throw std::runtime_error("failed to parse command file"); + } + + // dump AST +// m_ast->printTree(0); + + // close command file + commandFile.close(); + } + catch (...) + { + // close command file + commandFile.close(); + + // rethrow exception + throw; + } +} + +//! Iterates over the option definition AST nodes. elftosb::Value objects are created for +//! each option value and added to the option dictionary. +//! +//! \exception std::runtime_error Various errors will cause this exception to be thrown. These +//! include AST nodes being an unexpected type or expression not evaluating to integers. +void ConversionController::processOptions(ListASTNode * options) +{ + if (!options) + { + return; + } + + ListASTNode::iterator it = options->begin(); + for (; it != options->end(); ++it) + { + std::string ident; + Value * value = convertAssignmentNodeToValue(*it, ident); + + // check if this option has already been set + if (hasOption(ident)) + { + throw semantic_error(format_string("line %d: option already set", (*it)->getFirstLine())); + } + + // now save the option value in our map + if (value) + { + setOption(ident, value); + } + } +} + +//! Scans the constant definition AST nodes, evaluates expression nodes by calling their +//! elftosb::ExprASTNode::reduce() method, and updates the evaluation context member so +//! those constant values can be used in other expressions. +//! +//! \exception std::runtime_error Various errors will cause this exception to be thrown. These +//! include AST nodes being an unexpected type or expression not evaluating to integers. +void ConversionController::processConstants(ListASTNode * constants) +{ + if (!constants) + { + return; + } + + ListASTNode::iterator it = constants->begin(); + for (; it != constants->end(); ++it) + { + std::string ident; + Value * value = convertAssignmentNodeToValue(*it, ident); + + SizedIntegerValue * intValue = dynamic_cast<SizedIntegerValue*>(value); + if (!intValue) + { + throw semantic_error(format_string("line %d: constant value is an invalid type", (*it)->getFirstLine())); + } + +//#if PRINT_VALUES +// Log::log("constant "); +// printIntConstExpr(ident, intValue); +//#endif + + // record this constant's value in the evaluation context + m_context.setVariable(ident, intValue->getValue(), intValue->getWordSize()); + } +} + +//! \exception std::runtime_error Various errors will cause this exception to be thrown. These +//! include AST nodes being an unexpected type or expression not evaluating to integers. +//! +//! \todo Handle freeing of dict if an exception occurs. +void ConversionController::processSources(ListASTNode * sources) +{ + if (!sources) + { + return; + } + + ListASTNode::iterator it = sources->begin(); + for (; it != sources->end(); ++it) + { + SourceDefASTNode * node = dynamic_cast<SourceDefASTNode*>(*it); + if (!node) + { + throw semantic_error(format_string("line %d: source definition node is an unexpected type", node->getFirstLine())); + } + + // get source name and check if it has already been defined + std::string * name = node->getName(); + if (m_sources.find(*name) != m_sources.end()) + { + // can't define a source multiple times + throw semantic_error(format_string("line %d: source already defined", node->getFirstLine())); + } + + // convert attributes into an option dict + OptionDictionary * dict = new OptionDictionary(this); + ListASTNode * attrsNode = node->getAttributes(); + if (attrsNode) + { + ListASTNode::iterator attrIt = attrsNode->begin(); + for (; attrIt != attrsNode->end(); ++attrIt) + { + std::string ident; + Value * value = convertAssignmentNodeToValue(*attrIt, ident); + dict->setOption(ident, value); + } + } + + // figure out which type of source definition this is + PathSourceDefASTNode * pathNode = dynamic_cast<PathSourceDefASTNode*>(node); + ExternSourceDefASTNode * externNode = dynamic_cast<ExternSourceDefASTNode*>(node); + SourceFile * file = NULL; + + if (pathNode) + { + // explicit path + std::string * path = pathNode->getPath(); + +#if PRINT_VALUES + Log::log("source %s => path(%s)\n", name->c_str(), path->c_str()); +#endif + + try + { + file = SourceFile::openFile(*path); + } + catch (...) + { + // file doesn't exist + Log::log(Logger::INFO2, "failed to open source file: %s (ignoring for now)\n", path->c_str()); + m_failedSources.push_back(*name); + } + } + else if (externNode) + { + // externally provided path + ExprASTNode * expr = externNode->getSourceNumberExpr()->reduce(m_context); + IntConstExprASTNode * intConst = dynamic_cast<IntConstExprASTNode*>(expr); + if (!intConst) + { + throw semantic_error(format_string("line %d: expression didn't evaluate to an integer", expr->getFirstLine())); + } + + uint32_t externalFileNumber = static_cast<uint32_t>(intConst->getValue()); + + // make sure the extern number is valid + if (externalFileNumber >= 0 && externalFileNumber < m_externPaths.size()) + { + +#if PRINT_VALUES + Log::log("source %s => extern(%d=%s)\n", name->c_str(), externalFileNumber, m_externPaths[externalFileNumber].c_str()); +#endif + + try + { + file = SourceFile::openFile(m_externPaths[externalFileNumber]); + } + catch (...) + { + Log::log(Logger::INFO2, "failed to open source file: %s (ignoring for now)\n", m_externPaths[externalFileNumber].c_str()); + m_failedSources.push_back(*name); + } + } + } + else + { + throw semantic_error(format_string("line %d: unexpected source definition node type", node->getFirstLine())); + } + + if (file) + { + // set options + file->setOptions(dict); + + // stick the file object in the source map + m_sources[*name] = file; + } + } +} + +void ConversionController::processSections(ListASTNode * sections) +{ + if (!sections) + { + Log::log(Logger::WARNING, "warning: no sections were defined in command file"); + return; + } + + ListASTNode::iterator it = sections->begin(); + for (; it != sections->end(); ++it) + { + SectionContentsASTNode * node = dynamic_cast<SectionContentsASTNode*>(*it); + if (!node) + { + throw semantic_error(format_string("line %d: section definition is unexpected type", node->getFirstLine())); + } + + // evaluate section number + ExprASTNode * idExpr = node->getSectionNumberExpr()->reduce(m_context); + IntConstExprASTNode * idConst = dynamic_cast<IntConstExprASTNode*>(idExpr); + if (!idConst) + { + throw semantic_error(format_string("line %d: section number did not evaluate to an integer", idExpr->getFirstLine())); + } + uint32_t sectionID = idConst->getValue(); + + // Create options context for this section. The options context has the + // conversion controller as its parent context so it will inherit global options. + // The context will be set in the section after the section is created below. + OptionDictionary * optionsDict = new OptionDictionary(this); + ListASTNode * attrsNode = node->getOptions(); + if (attrsNode) + { + ListASTNode::iterator attrIt = attrsNode->begin(); + for (; attrIt != attrsNode->end(); ++attrIt) + { + std::string ident; + Value * value = convertAssignmentNodeToValue(*attrIt, ident); + optionsDict->setOption(ident, value); + } + } + + // Now create the actual section object based on its type. + OutputSection * outputSection = NULL; + BootableSectionContentsASTNode * bootableSection; + DataSectionContentsASTNode * dataSection; + if (bootableSection = dynamic_cast<BootableSectionContentsASTNode*>(node)) + { + // process statements into a sequence of operations + ListASTNode * statements = bootableSection->getStatements(); + OperationSequence * sequence = convertStatementList(statements); + +#if 0 + Log::log("section ID = %d\n", sectionID); + statements->printTree(0); + + Log::log("sequence has %d operations\n", sequence->getCount()); + OperationSequence::iterator_t it = sequence->begin(); + for (; it != sequence->end(); ++it) + { + Operation * op = *it; + Log::log("op = %p\n", op); + } +#endif + + // create the output section and add it to the list + OperationSequenceSection * opSection = new OperationSequenceSection(sectionID); + opSection->setOptions(optionsDict); + opSection->getSequence() += sequence; + outputSection = opSection; + } + else if (dataSection = dynamic_cast<DataSectionContentsASTNode*>(node)) + { + outputSection = convertDataSection(dataSection, sectionID, optionsDict); + } + else + { + throw semantic_error(format_string("line %d: unexpected section contents type", node->getFirstLine())); + } + + if (outputSection) + { + m_outputSections.push_back(outputSection); + } + } +} + +//! Creates an instance of BinaryDataSection from the AST node passed in the +//! \a dataSection parameter. The section-specific options for this node will +//! have already been converted into an OptionDictionary, the one passed in +//! the \a optionsDict parameter. +//! +//! The \a dataSection node will have as its contents one of the AST node +//! classes that represents a source of data. The member function +//! createSourceFromNode() is used to convert this AST node into an +//! instance of a DataSource subclass. Then the method imageDataSource() +//! converts the segments of the DataSource into a raw binary buffer that +//! becomes the contents of the BinaryDataSection this is returned. +//! +//! \param dataSection The AST node for the data section. +//! \param sectionID Unique tag value the user has assigned to this section. +//! \param optionsDict Options that apply only to this section. This dictionary +//! will be assigned as the options dictionary for the resulting section +//! object. Its parent is the conversion controller itself. +//! \return An instance of BinaryDataSection. Its contents are a contiguous +//! binary representation of the contents of \a dataSection. +OutputSection * ConversionController::convertDataSection(DataSectionContentsASTNode * dataSection, uint32_t sectionID, OptionDictionary * optionsDict) +{ + // Create a data source from the section contents AST node. + ASTNode * contents = dataSection->getContents(); + DataSource * dataSource = createSourceFromNode(contents); + + // Convert the data source to a raw buffer. + DataSourceImager imager; + imager.addDataSource(dataSource); + + // Then make a data section from the buffer. + BinaryDataSection * resultSection = new BinaryDataSection(sectionID); + resultSection->setOptions(optionsDict); + if (imager.getLength()) + { + resultSection->setData(imager.getData(), imager.getLength()); + } + + return resultSection; +} + +//! @param node The AST node instance for the assignment expression. +//! @param[out] ident Upon exit this string will be set the the left hand side of the +//! assignment expression, the identifier name. +//! +//! @return An object that is a subclass of Value is returned. The specific subclass will +//! depend on the type of the right hand side of the assignment expression whose AST +//! node was provided in the @a node argument. +//! +//! @exception semantic_error Thrown for any error where an AST node is an unexpected type. +//! This may be the @a node argument itself, if it is not an AssignmentASTNode. Or it +//! may be an unexpected type for either the right or left hand side of the assignment. +//! The message for the exception will contain a description of the error. +Value * ConversionController::convertAssignmentNodeToValue(ASTNode * node, std::string & ident) +{ + Value * resultValue = NULL; + + // each item of the options list should be an assignment node + AssignmentASTNode * assignmentNode = dynamic_cast<AssignmentASTNode*>(node); + if (!node) + { + throw semantic_error(format_string("line %d: node is wrong type", assignmentNode->getFirstLine())); + } + + // save the left hand side (the identifier) into ident + ident = *assignmentNode->getIdent(); + + // get the right hand side and convert it to a Value instance + ASTNode * valueNode = assignmentNode->getValue(); + StringConstASTNode * str; + ExprASTNode * expr; + if (str = dynamic_cast<StringConstASTNode*>(valueNode)) + { + // the option value is a string constant + resultValue = new StringValue(str->getString()); + +//#if PRINT_VALUES +// Log::log("option %s => \'%s\'\n", ident->c_str(), str->getString()->c_str()); +//#endif + } + else if (expr = dynamic_cast<ExprASTNode*>(valueNode)) + { + ExprASTNode * reducedExpr = expr->reduce(m_context); + IntConstExprASTNode * intConst = dynamic_cast<IntConstExprASTNode*>(reducedExpr); + if (!intConst) + { + throw semantic_error(format_string("line %d: expression didn't evaluate to an integer", expr->getFirstLine())); + } + +//#if PRINT_VALUES +// Log::log("option "); +// printIntConstExpr(*ident, intConst); +//#endif + + resultValue = new SizedIntegerValue(intConst->getValue(), intConst->getSize()); + } + else + { + throw semantic_error(format_string("line %d: right hand side node is an unexpected type", valueNode->getFirstLine())); + } + + return resultValue; +} + +//! Builds up a sequence of Operation objects that are equivalent to the +//! statements in the \a statements list. The statement list is simply iterated +//! over and the results of convertOneStatement() are used to build up +//! the final result sequence. +//! +//! \see convertOneStatement() +OperationSequence * ConversionController::convertStatementList(ListASTNode * statements) +{ + OperationSequence * resultSequence = new OperationSequence(); + ListASTNode::iterator it = statements->begin(); + for (; it != statements->end(); ++it) + { + StatementASTNode * statement = dynamic_cast<StatementASTNode*>(*it); + if (!statement) + { + throw semantic_error(format_string("line %d: statement node is unexpected type", (*it)->getFirstLine())); + } + + // convert this statement and append it to the result + OperationSequence * sequence = convertOneStatement(statement); + if (sequence) + { + *resultSequence += sequence; + } + } + + return resultSequence; +} + +//! Uses C++ RTTI to identify the particular subclass of StatementASTNode that +//! the \a statement argument matches. Then the appropriate conversion method +//! is called. +//! +//! \see convertLoadStatement() +//! \see convertCallStatement() +//! \see convertFromStatement() +OperationSequence * ConversionController::convertOneStatement(StatementASTNode * statement) +{ + // see if it's a load statement + LoadStatementASTNode * load = dynamic_cast<LoadStatementASTNode*>(statement); + if (load) + { + return convertLoadStatement(load); + } + + // see if it's a call statement + CallStatementASTNode * call = dynamic_cast<CallStatementASTNode*>(statement); + if (call) + { + return convertCallStatement(call); + } + + // see if it's a from statement + FromStatementASTNode * from = dynamic_cast<FromStatementASTNode*>(statement); + if (from) + { + return convertFromStatement(from); + } + + // see if it's a mode statement + ModeStatementASTNode * mode = dynamic_cast<ModeStatementASTNode*>(statement); + if (mode) + { + return convertModeStatement(mode); + } + + // see if it's an if statement + IfStatementASTNode * ifStmt = dynamic_cast<IfStatementASTNode*>(statement); + if (ifStmt) + { + return convertIfStatement(ifStmt); + } + + // see if it's a message statement + MessageStatementASTNode * messageStmt = dynamic_cast<MessageStatementASTNode*>(statement); + if (messageStmt) + { + // Message statements don't produce operation sequences. + handleMessageStatement(messageStmt); + return NULL; + } + + // didn't match any of the expected statement types + throw semantic_error(format_string("line %d: unexpected statement type", statement->getFirstLine())); + return NULL; +} + +//! Possible load data node types: +//! - StringConstASTNode +//! - ExprASTNode +//! - SourceASTNode +//! - SectionMatchListASTNode +//! +//! Possible load target node types: +//! - SymbolASTNode +//! - NaturalLocationASTNode +//! - AddressRangeASTNode +OperationSequence * ConversionController::convertLoadStatement(LoadStatementASTNode * statement) +{ + LoadOperation * op = NULL; + + try + { + // build load operation from source and target + op = new LoadOperation(); + op->setSource(createSourceFromNode(statement->getData())); + op->setTarget(createTargetFromNode(statement->getTarget())); + op->setDCDLoad(statement->isDCDLoad()); + + return new OperationSequence(op); + } + catch (...) + { + if (op) + { + delete op; + } + throw; + } +} + +//! Possible call target node types: +//! - SymbolASTNode +//! - ExprASTNode +//! +//! Possible call argument node types: +//! - ExprASTNode +//! - NULL +OperationSequence * ConversionController::convertCallStatement(CallStatementASTNode * statement) +{ + ExecuteOperation * op = NULL; + + try + { + // create operation from AST nodes + op = new ExecuteOperation(); + + bool isHAB = statement->isHAB(); + + op->setTarget(createTargetFromNode(statement->getTarget())); + + // set argument value, which defaults to 0 if no expression was provided + uint32_t arg = 0; + ASTNode * argNode = statement->getArgument(); + if (argNode) + { + ExprASTNode * argExprNode = dynamic_cast<ExprASTNode*>(argNode); + if (!argExprNode) + { + throw semantic_error(format_string("line %d: call argument is unexpected type", argNode->getFirstLine())); + } + argExprNode = argExprNode->reduce(m_context); + IntConstExprASTNode * intNode = dynamic_cast<IntConstExprASTNode*>(argExprNode); + if (!intNode) + { + throw semantic_error(format_string("line %d: call argument did not evaluate to an integer", argExprNode->getFirstLine())); + } + + arg = intNode->getValue(); + } + op->setArgument(arg); + + // set call type + switch (statement->getCallType()) + { + case CallStatementASTNode::kCallType: + op->setExecuteType(ExecuteOperation::kCall); + break; + case CallStatementASTNode::kJumpType: + op->setExecuteType(ExecuteOperation::kJump); + break; + } + + // Set the HAB mode flag. + op->setIsHAB(isHAB); + + return new OperationSequence(op); + } + catch (...) + { + // delete op and rethrow exception + if (op) + { + delete op; + } + throw; + } +} + +//! First this method sets the default source to the source identified in +//! the from statement. Then the statements within the from block are +//! processed recursively by calling convertStatementList(). The resulting +//! operation sequence is returned. +OperationSequence * ConversionController::convertFromStatement(FromStatementASTNode * statement) +{ + if (m_defaultSource) + { + throw semantic_error(format_string("line %d: from statements cannot be nested", statement->getFirstLine())); + } + + // look up source file instance + std::string * fromSourceName = statement->getSourceName(); + assert(fromSourceName); + + // make sure it's a valid source name + source_map_t::iterator sourceIt = m_sources.find(*fromSourceName); + if (sourceIt == m_sources.end()) + { + throw semantic_error(format_string("line %d: bad source name", statement->getFirstLine())); + } + + // set default source + m_defaultSource = sourceIt->second; + assert(m_defaultSource); + + // get statements inside the from block + ListASTNode * fromStatements = statement->getStatements(); + assert(fromStatements); + + // produce resulting operation sequence + OperationSequence * result = convertStatementList(fromStatements); + + // restore default source to NULL + m_defaultSource = NULL; + + return result; +} + +//! Evaluates the expression to get the new boot mode value. Then creates a +//! BootModeOperation object and returns an OperationSequence containing it. +//! +//! \exception elftosb::semantic_error Thrown if a semantic problem is found with +//! the boot mode expression. +OperationSequence * ConversionController::convertModeStatement(ModeStatementASTNode * statement) +{ + BootModeOperation * op = NULL; + + try + { + op = new BootModeOperation(); + + // evaluate the boot mode expression + ExprASTNode * modeExprNode = statement->getModeExpr(); + if (!modeExprNode) + { + throw semantic_error(format_string("line %d: mode statement has invalid boot mode expression", statement->getFirstLine())); + } + modeExprNode = modeExprNode->reduce(m_context); + IntConstExprASTNode * intNode = dynamic_cast<IntConstExprASTNode*>(modeExprNode); + if (!intNode) + { + throw semantic_error(format_string("line %d: boot mode did not evaluate to an integer", statement->getFirstLine())); + } + + op->setBootMode(intNode->getValue()); + + return new OperationSequence(op); + } + catch (...) + { + if (op) + { + delete op; + } + + // rethrow exception + throw; + } +} + +//! Else branches, including else-if, are handled recursively, so there is a limit +//! on the number of them based on the stack size. +//! +//! \return Returns the operation sequence for the branch of the if statement that +//! evaluated to true. If the statement did not have an else branch and the +//! condition expression evaluated to false, then NULL will be returned. +//! +//! \todo Handle else branches without recursion. +OperationSequence * ConversionController::convertIfStatement(IfStatementASTNode * statement) +{ + // Get the if's conditional expression. + ExprASTNode * conditionalExpr = statement->getConditionExpr(); + if (!conditionalExpr) + { + throw semantic_error(format_string("line %d: missing or invalid conditional expression", statement->getFirstLine())); + } + + // Reduce the conditional to a single integer. + conditionalExpr = conditionalExpr->reduce(m_context); + IntConstExprASTNode * intNode = dynamic_cast<IntConstExprASTNode*>(conditionalExpr); + if (!intNode) + { + throw semantic_error(format_string("line %d: if statement conditional expression did not evaluate to an integer", statement->getFirstLine())); + } + + // Decide which statements to further process by the conditional's boolean value. + if (intNode->getValue() && statement->getIfStatements()) + { + return convertStatementList(statement->getIfStatements()); + } + else if (statement->getElseStatements()) + { + return convertStatementList(statement->getElseStatements()); + } + else + { + // No else branch and the conditional was false, so there are no operations to return. + return NULL; + } +} + +//! Message statements are executed immediately, by this method. They are +//! not converted into an abstract operation. All messages are passed through +//! substituteVariables() before being output. +//! +//! \param statement The message statement AST node object. +void ConversionController::handleMessageStatement(MessageStatementASTNode * statement) +{ + string * message = statement->getMessage(); + if (!message) + { + throw runtime_error("message statement had no message"); + } + + smart_ptr<string> finalMessage = substituteVariables(message); + + switch (statement->getType()) + { + case MessageStatementASTNode::kInfo: + Log::log(Logger::INFO, "%s\n", finalMessage->c_str()); + break; + + case MessageStatementASTNode::kWarning: + Log::log(Logger::WARNING, "warning: %s\n", finalMessage->c_str()); + break; + + case MessageStatementASTNode::kError: + throw runtime_error(*finalMessage); + break; + } +} + +//! Performs shell-like variable substitution on the string passed into it. +//! Both sources and constants can be substituted. Sources will be replaced +//! with their path and constants with their integer value. The syntax allows +//! for some simple formatting for constants. +//! +//! The syntax is mostly standard. A substitution begins with a dollar-sign +//! and is followed by the source or constant name in parentheses. For instance, +//! "$(mysource)" or "$(myconst)". The parentheses are always required. +//! +//! Constant names can be prefixed by a single formatting character followed +//! by a colon. The only formatting characters currently supported are 'd' for +//! decimal and 'x' for hex. For example, "$(x:myconst)" will be replaced with +//! the value of the constant named "myconst" formatted as hexadecimal. The +//! default is decimal, so the 'd' formatting character isn't really ever +//! needed. +//! +//! \param message The string to perform substitution on. +//! \return Returns a newly allocated std::string object that has all +//! substitutions replaced with the associated value. The caller is +//! responsible for freeing the string object using the delete operator. +std::string * ConversionController::substituteVariables(const std::string * message) +{ + string * result = new string(); + int i; + int state = 0; + string name; + + for (i=0; i < message->size(); ++i) + { + char c = (*message)[i]; + switch (state) + { + case 0: + if (c == '$') + { + state = 1; + } + else + { + (*result) += c; + } + break; + + case 1: + if (c == '(') + { + state = 2; + } + else + { + // Wasn't a variable substitution, so revert to initial state after + // inserting the original characters. + (*result) += '$'; + (*result) += c; + state = 0; + } + break; + + case 2: + if (c == ')') + { + // Try the name as a source name first. + if (m_sources.find(name) != m_sources.end()) + { + (*result) += m_sources[name]->getPath(); + } + // Otherwise try it as a variable. + else + { + // Select format. + const char * fmt = "%d"; + if (name[1] == ':' && (name[0] == 'd' || name[0] == 'x')) + { + if (name[0] == 'x') + { + fmt = "0x%x"; + } + + // Delete the format characters. + name.erase(0, 2); + } + + // Now insert the formatted variable if it exists. + if (m_context.isVariableDefined(name)) + { + (*result) += format_string(fmt, m_context.getVariableValue(name)); + } + } + + // Switch back to initial state and clear name. + state = 0; + name.clear(); + } + else + { + // Just keep building up the variable name. + name += c; + } + break; + } + } + + return result; +} + +//! +//! \param generator The generator to use. +BootImage * ConversionController::generateOutput(BootImageGenerator * generator) +{ + // set the generator's option context + generator->setOptionContext(this); + + // add output sections to the generator in sequence + section_vector_t::iterator it = m_outputSections.begin(); + for (; it != m_outputSections.end(); ++it) + { + generator->addOutputSection(*it); + } + + // and produce the output + BootImage * image = generator->generate(); +// Log::log("boot image = %p\n", image); + return image; +} + +//! Takes an AST node that is one of the following subclasses and creates the corresponding +//! type of DataSource object from it. +//! - StringConstASTNode +//! - ExprASTNode +//! - SourceASTNode +//! - SectionASTNode +//! - SectionMatchListASTNode +//! - BlobConstASTNode +//! - IVTConstASTNode +//! +//! \exception elftosb::semantic_error Thrown if a semantic problem is found with +//! the data node. +//! \exception std::runtime_error Thrown if an error occurs that shouldn't be possible +//! based on the grammar. +DataSource * ConversionController::createSourceFromNode(ASTNode * dataNode) +{ + assert(dataNode); + + DataSource * source = NULL; + StringConstASTNode * stringNode; + BlobConstASTNode * blobNode; + ExprASTNode * exprNode; + SourceASTNode * sourceNode; + SectionASTNode * sectionNode; + SectionMatchListASTNode * matchListNode; + IVTConstASTNode * ivtNode; + + if (stringNode = dynamic_cast<StringConstASTNode*>(dataNode)) + { + // create a data source with the string contents + std::string * stringData = stringNode->getString(); + const uint8_t * stringContents = reinterpret_cast<const uint8_t *>(stringData->c_str()); + source = new UnmappedDataSource(stringContents, static_cast<unsigned>(stringData->size())); + } + else if (blobNode = dynamic_cast<BlobConstASTNode*>(dataNode)) + { + // create a data source with the raw binary data + Blob * blob = blobNode->getBlob(); + source = new UnmappedDataSource(blob->getData(), blob->getLength()); + } + else if (exprNode = dynamic_cast<ExprASTNode*>(dataNode)) + { + // reduce the expression first + exprNode = exprNode->reduce(m_context); + IntConstExprASTNode * intNode = dynamic_cast<IntConstExprASTNode*>(exprNode); + if (!intNode) + { + throw semantic_error("load pattern expression did not evaluate to an integer"); + } + + SizedIntegerValue intValue(intNode->getValue(), intNode->getSize()); + source = new PatternSource(intValue); + } + else if (sourceNode = dynamic_cast<SourceASTNode*>(dataNode)) + { + // load the entire source contents + SourceFile * sourceFile = getSourceFromName(sourceNode->getSourceName(), sourceNode->getFirstLine()); + source = sourceFile->createDataSource(); + } + else if (sectionNode = dynamic_cast<SectionASTNode*>(dataNode)) + { + // load some subset of the source + SourceFile * sourceFile = getSourceFromName(sectionNode->getSourceName(), sectionNode->getFirstLine()); + if (!sourceFile->supportsNamedSections()) + { + throw semantic_error(format_string("line %d: source does not support sections", sectionNode->getFirstLine())); + } + + // create data source from the section name + std::string * sectionName = sectionNode->getSectionName(); + GlobMatcher globber(*sectionName); + source = sourceFile->createDataSource(globber); + if (!source) + { + throw semantic_error(format_string("line %d: no sections match the pattern", sectionNode->getFirstLine())); + } + } + else if (matchListNode = dynamic_cast<SectionMatchListASTNode*>(dataNode)) + { + SourceFile * sourceFile = getSourceFromName(matchListNode->getSourceName(), matchListNode->getFirstLine()); + if (!sourceFile->supportsNamedSections()) + { + throw semantic_error(format_string("line %d: source type does not support sections", matchListNode->getFirstLine())); + } + + // create string matcher + ExcludesListMatcher matcher; + + // add each pattern to the matcher + ListASTNode * matchList = matchListNode->getSections(); + ListASTNode::iterator it = matchList->begin(); + for (; it != matchList->end(); ++it) + { + ASTNode * node = *it; + sectionNode = dynamic_cast<SectionASTNode*>(node); + if (!sectionNode) + { + throw std::runtime_error(format_string("line %d: unexpected node type in section pattern list", (*it)->getFirstLine())); + } + bool isInclude = sectionNode->getAction() == SectionASTNode::kInclude; + matcher.addPattern(isInclude, *(sectionNode->getSectionName())); + } + + // create data source from the section match list + source = sourceFile->createDataSource(matcher); + if (!source) + { + throw semantic_error(format_string("line %d: no sections match the section pattern list", matchListNode->getFirstLine())); + } + } + else if (ivtNode = dynamic_cast<IVTConstASTNode*>(dataNode)) + { + source = createIVTDataSource(ivtNode); + } + else + { + throw semantic_error(format_string("line %d: unexpected load data node type", dataNode->getFirstLine())); + } + + return source; +} + +DataSource * ConversionController::createIVTDataSource(IVTConstASTNode * ivtNode) +{ + IVTDataSource * source = new IVTDataSource; + + // Iterate over the assignment statements in the IVT definition. + ListASTNode * fieldList = ivtNode->getFieldAssignments(); + + if (fieldList) + { + ListASTNode::iterator it = fieldList->begin(); + for (; it != fieldList->end(); ++it) + { + AssignmentASTNode * assignmentNode = dynamic_cast<AssignmentASTNode*>(*it); + if (!assignmentNode) + { + throw std::runtime_error(format_string("line %d: unexpected node type in IVT definition", (*it)->getFirstLine())); + } + + // Get the IVT field name. + std::string * fieldName = assignmentNode->getIdent(); + + // Reduce the field expression and get the integer result. + ASTNode * valueNode = assignmentNode->getValue(); + ExprASTNode * valueExpr = dynamic_cast<ExprASTNode*>(valueNode); + if (!valueExpr) + { + throw semantic_error("IVT field must have a valid expression"); + } + IntConstExprASTNode * valueIntExpr = dynamic_cast<IntConstExprASTNode*>(valueExpr->reduce(m_context)); + if (!valueIntExpr) + { + throw semantic_error(format_string("line %d: IVT field '%s' does not evaluate to an integer", valueNode->getFirstLine(), fieldName->c_str())); + } + uint32_t value = static_cast<uint32_t>(valueIntExpr->getValue()); + + // Set the field in the IVT data source. + if (!source->setFieldByName(*fieldName, value)) + { + throw semantic_error(format_string("line %d: unknown IVT field '%s'", assignmentNode->getFirstLine(), fieldName->c_str())); + } + } + } + + return source; +} + +//! Takes an AST node subclass and returns an appropriate DataTarget object that contains +//! the same information. Supported AST node types are: +//! - SymbolASTNode +//! - NaturalLocationASTNode +//! - AddressRangeASTNode +//! +//! \exception elftosb::semantic_error Thrown if a semantic problem is found with +//! the target node. +DataTarget * ConversionController::createTargetFromNode(ASTNode * targetNode) +{ + assert(targetNode); + + DataTarget * target = NULL; + SymbolASTNode * symbolNode; + NaturalLocationASTNode * naturalNode; + AddressRangeASTNode * addressNode; + + if (symbolNode = dynamic_cast<SymbolASTNode*>(targetNode)) + { + SourceFile * sourceFile = getSourceFromName(symbolNode->getSource(), symbolNode->getFirstLine()); + std::string * symbolName = symbolNode->getSymbolName(); + + // symbol name is optional + if (symbolName) + { + if (!sourceFile->supportsNamedSymbols()) + { + throw std::runtime_error(format_string("line %d: source does not support symbols", symbolNode->getFirstLine())); + } + + target = sourceFile->createDataTargetForSymbol(*symbolName); + if (!target) + { + throw std::runtime_error(format_string("line %d: source does not have a symbol with that name", symbolNode->getFirstLine())); + } + } + else + { + // no symbol name was specified so use entry point + target = sourceFile->createDataTargetForEntryPoint(); + if (!target) + { + throw std::runtime_error(format_string("line %d: source does not have an entry point", symbolNode->getFirstLine())); + } + } + } + else if (naturalNode = dynamic_cast<NaturalLocationASTNode*>(targetNode)) + { + // the target is the source's natural location + target = new NaturalDataTarget(); + } + else if (addressNode = dynamic_cast<AddressRangeASTNode*>(targetNode)) + { + // evaluate begin address + ExprASTNode * beginExpr = dynamic_cast<ExprASTNode*>(addressNode->getBegin()); + if (!beginExpr) + { + throw semantic_error("address range must always have a beginning expression"); + } + IntConstExprASTNode * beginIntExpr = dynamic_cast<IntConstExprASTNode*>(beginExpr->reduce(m_context)); + if (!beginIntExpr) + { + throw semantic_error("address range begin did not evaluate to an integer"); + } + uint32_t beginAddress = static_cast<uint32_t>(beginIntExpr->getValue()); + + // evaluate end address + ExprASTNode * endExpr = dynamic_cast<ExprASTNode*>(addressNode->getEnd()); + uint32_t endAddress = 0; + bool hasEndAddress = false; + if (endExpr) + { + IntConstExprASTNode * endIntExpr = dynamic_cast<IntConstExprASTNode*>(endExpr->reduce(m_context)); + if (!endIntExpr) + { + throw semantic_error("address range end did not evaluate to an integer"); + } + endAddress = static_cast<uint32_t>(endIntExpr->getValue()); + hasEndAddress = true; + } + + // create target + if (hasEndAddress) + { + target = new ConstantDataTarget(beginAddress, endAddress); + } + else + { + target = new ConstantDataTarget(beginAddress); + } + } + else + { + throw semantic_error("unexpected load target node type"); + } + + return target; +} + +//! \param sourceName Pointer to string containing the name of the source to look up. +//! May be NULL, in which case the default source is used. +//! \param line The line number on which the source name was located. +//! +//! \result A source file object that was previously created in the processSources() +//! stage. +//! +//! \exception std::runtime_error Thrown if the source name is invalid, or if it +//! was NULL and there is no default source (i.e., we're not inside a from +//! statement). +SourceFile * ConversionController::getSourceFromName(std::string * sourceName, int line) +{ + SourceFile * sourceFile = NULL; + if (sourceName) + { + // look up source in map + source_map_t::iterator it = m_sources.find(*sourceName); + if (it == m_sources.end()) + { + source_name_vector_t::const_iterator findIt = std::find<source_name_vector_t::const_iterator, std::string>(m_failedSources.begin(), m_failedSources.end(), *sourceName); + if (findIt != m_failedSources.end()) + { + throw semantic_error(format_string("line %d: error opening source '%s'", line, sourceName->c_str())); + } + else + { + throw semantic_error(format_string("line %d: invalid source name '%s'", line, sourceName->c_str())); + } + } + sourceFile = it->second; + } + else + { + // no name provided - use default source + sourceFile = m_defaultSource; + if (!sourceFile) + { + throw semantic_error(format_string("line %d: source required but no default source is available", line)); + } + } + + // open the file if it hasn't already been + if (!sourceFile->isOpen()) + { + sourceFile->open(); + } + return sourceFile; +} + +//! Exercises the lexer by printing out the value of every token produced by the +//! lexer. It is assumed that the lexer object has already be configured to read +//! from some input file. The method will return when the lexer has exhausted all +//! tokens, or an error occurs. +void ConversionController::testLexer(ElftosbLexer & lexer) +{ + // test lexer + while (1) + { + YYSTYPE value; + int lexresult = lexer.yylex(); + if (lexresult == 0) + break; + lexer.getSymbolValue(&value); + Log::log("%d -> int:%d, ast:%p", lexresult, value.m_int, value.m_str, value.m_ast); + if (lexresult == TOK_IDENT || lexresult == TOK_SOURCE_NAME || lexresult == TOK_STRING_LITERAL) + { + if (value.m_str) + { + Log::log(", str:%s\n", value.m_str->c_str()); + } + else + { + Log::log("str:NULL\n"); + } + } + else + { + Log::log("\n"); + } + } +} + +//! Prints out the value of an integer constant expression AST node. Also prints +//! the name of the identifier associated with that node, as well as the integer +//! size. +void ConversionController::printIntConstExpr(const std::string & ident, IntConstExprASTNode * expr) +{ + // print constant value + char sizeChar; + switch (expr->getSize()) + { + case kWordSize: + sizeChar = 'w'; + break; + case kHalfWordSize: + sizeChar = 'h'; + break; + case kByteSize: + sizeChar = 'b'; + break; + } + Log::log("%s => %d:%c\n", ident.c_str(), expr->getValue(), sizeChar); +} + diff --git a/elftosb2/ConversionController.h b/elftosb2/ConversionController.h new file mode 100644 index 0000000..16ae247 --- /dev/null +++ b/elftosb2/ConversionController.h @@ -0,0 +1,153 @@ +/* + * File: ConversionController.h + * + * Copyright (c) Freescale Semiconductor, Inc. All rights reserved. + * See included license file for license details. + */ +#if !defined(_ConversionController_h_) +#define _ConversionController_h_ + +#include <iostream> +#include <fstream> +#include <string> +#include <stdexcept> +#include <smart_ptr.h> +#include <ElftosbLexer.h> +#include <ElftosbAST.h> +#include "EvalContext.h" +#include "Value.h" +#include "SourceFile.h" +#include "Operation.h" +#include "DataSource.h" +#include "DataTarget.h" +#include "OutputSection.h" +#include "BootImage.h" +#include "OptionDictionary.h" +#include "BootImageGenerator.h" + +namespace elftosb +{ + +/*! + * \brief Manages the entire elftosb file conversion process. + * + * Instances of this class are intended to be used only once. There is no + * way to reset an instance once it has started or completed a conversion. + * Thus the run() method is not reentrant. State information is stored in + * the object during the conversion process. + * + * Two things need to be done before the conversion can be started. The + * command file path has to be set with the setCommandFilePath() method, + * and the paths of any externally provided (i.e., from the command line) + * files need to be added with addExternalFilePath(). Once these tasks + * are completed, the run() method can be called to parse and execute the + * command file. After run() returns, pass an instance of + * BootImageGenerator to the generateOutput() method in order to get + * an instance of BootImage that can be written to the output file. + */ +class ConversionController : public OptionDictionary, public EvalContext::SourceFileManager +{ +public: + //! \brief Default constructor. + ConversionController(); + + //! \brief Destructor. + virtual ~ConversionController(); + + //! \name Paths + //@{ + //! \brief Specify the command file that controls the conversion process. + void setCommandFilePath(const std::string & path); + + //! \brief Specify the path of a file provided by the user from outside the command file. + void addExternalFilePath(const std::string & path); + //@} + + //! \name Conversion + //@{ + //! \brief Process input files. + void run(); + + //! \brief Uses a BootImageGenerator object to create the final output boot image. + BootImage * generateOutput(BootImageGenerator * generator); + //@} + + //! \name SourceFileManager interface + //@{ + //! \brief Returns true if a source file with the name \a name exists. + virtual bool hasSourceFile(const std::string & name); + + //! \brief Gets the requested source file. + virtual SourceFile * getSourceFile(const std::string & name); + + //! \brief Returns the default source file, or NULL if none is set. + virtual SourceFile * getDefaultSourceFile(); + //@} + + //! \brief Returns a reference to the context used for expression evaluation. + inline EvalContext & getEvalContext() { return m_context; } + +protected: + //! \name AST processing + //@{ + void parseCommandFile(); + void processOptions(ListASTNode * options); + void processConstants(ListASTNode * constants); + void processSources(ListASTNode * sources); + void processSections(ListASTNode * sections); + OutputSection * convertDataSection(DataSectionContentsASTNode * dataSection, uint32_t sectionID, OptionDictionary * optionsDict); + //@} + + //! \name Statement conversion + //@{ + OperationSequence * convertStatementList(ListASTNode * statements); + OperationSequence * convertOneStatement(StatementASTNode * statement); + OperationSequence * convertLoadStatement(LoadStatementASTNode * statement); + OperationSequence * convertCallStatement(CallStatementASTNode * statement); + OperationSequence * convertFromStatement(FromStatementASTNode * statement); + OperationSequence * convertModeStatement(ModeStatementASTNode * statement); + OperationSequence * convertIfStatement(IfStatementASTNode * statement); + void handleMessageStatement(MessageStatementASTNode * statement); + //@} + + //! \name Utilities + //@{ + Value * convertAssignmentNodeToValue(ASTNode * node, std::string & ident); + SourceFile * getSourceFromName(std::string * sourceName, int line); + DataSource * createSourceFromNode(ASTNode * dataNode); + DataTarget * createTargetFromNode(ASTNode * targetNode); + std::string * substituteVariables(const std::string * message); + DataSource * createIVTDataSource(IVTConstASTNode * ivtNode); + //@} + + //! \name Debugging + //@{ + void testLexer(ElftosbLexer & lexer); + void printIntConstExpr(const std::string & ident, IntConstExprASTNode * expr); + //@} + +protected: + typedef std::map<std::string, SourceFile*> source_map_t; //!< Map from source name to object. + typedef std::vector<std::string> path_vector_t; //!< List of file paths. + typedef std::vector<OutputSection*> section_vector_t; //!< List of output sections. + typedef std::vector<std::string> source_name_vector_t; //!< List of source names. + + smart_ptr<std::string> m_commandFilePath; //!< Path to command file. + smart_ptr<CommandFileASTNode> m_ast; //!< Root of the abstract syntax tree. + EvalContext m_context; //!< Evaluation context for expressions. + source_map_t m_sources; //!< Map of source names to file objects. + path_vector_t m_externPaths; //!< Paths provided on the command line by the user. + SourceFile * m_defaultSource; //!< Source to use when one isn't provided. + section_vector_t m_outputSections; //!< List of output sections the user wants. + source_name_vector_t m_failedSources; //!< List of sources that failed to open successfully. +}; + +//! \brief Whether to support HAB keywords during parsing. +//! +//! This is a standalone global solely so that the bison-generated parser code can get to it +//! as simply as possible. +extern bool g_enableHABSupport; + +}; // namespace elftosb + +#endif // _ConversionController_h_ diff --git a/elftosb2/Doxyfile b/elftosb2/Doxyfile new file mode 100644 index 0000000..6e7f239 --- /dev/null +++ b/elftosb2/Doxyfile @@ -0,0 +1,250 @@ +# Doxyfile 1.3.9 + +#--------------------------------------------------------------------------- +# Project related configuration options +#--------------------------------------------------------------------------- +PROJECT_NAME = elftosb +PROJECT_NUMBER = 2.0 +OUTPUT_DIRECTORY = . +CREATE_SUBDIRS = YES +OUTPUT_LANGUAGE = English +USE_WINDOWS_ENCODING = YES +BRIEF_MEMBER_DESC = YES +REPEAT_BRIEF = YES +ABBREVIATE_BRIEF = "The $name class" \ + "The $name widget" \ + "The $name file" \ + is \ + provides \ + specifies \ + contains \ + represents \ + a \ + an \ + the +ALWAYS_DETAILED_SEC = NO +INLINE_INHERITED_MEMB = NO +FULL_PATH_NAMES = NO +STRIP_FROM_PATH = "/Users/creed/projects/elftosb/elftosb2" \ + "/Users/creed/projects/sgtl/elftosb/sbtool" \ + "/Users/creed/projects/elftosb/common" \ + "/Users/creed/projects/sgtl/elftosb/common" +STRIP_FROM_INC_PATH = +SHORT_NAMES = NO +JAVADOC_AUTOBRIEF = NO +MULTILINE_CPP_IS_BRIEF = NO +DETAILS_AT_TOP = YES +INHERIT_DOCS = YES +DISTRIBUTE_GROUP_DOC = NO +TAB_SIZE = 4 +ALIASES = +OPTIMIZE_OUTPUT_FOR_C = NO +OPTIMIZE_OUTPUT_JAVA = NO +SUBGROUPING = YES +#--------------------------------------------------------------------------- +# Build related configuration options +#--------------------------------------------------------------------------- +EXTRACT_ALL = YES +EXTRACT_PRIVATE = YES +EXTRACT_STATIC = YES +EXTRACT_LOCAL_CLASSES = YES +EXTRACT_LOCAL_METHODS = NO +HIDE_UNDOC_MEMBERS = NO +HIDE_UNDOC_CLASSES = NO +HIDE_FRIEND_COMPOUNDS = NO +HIDE_IN_BODY_DOCS = NO +INTERNAL_DOCS = NO +CASE_SENSE_NAMES = NO +HIDE_SCOPE_NAMES = NO +SHOW_INCLUDE_FILES = YES +INLINE_INFO = YES +SORT_MEMBER_DOCS = YES +SORT_BRIEF_DOCS = NO +SORT_BY_SCOPE_NAME = NO +GENERATE_TODOLIST = YES +GENERATE_TESTLIST = YES +GENERATE_BUGLIST = YES +GENERATE_DEPRECATEDLIST= YES +ENABLED_SECTIONS = +MAX_INITIALIZER_LINES = 30 +SHOW_USED_FILES = YES +SHOW_DIRECTORIES = YES +#--------------------------------------------------------------------------- +# configuration options related to warning and progress messages +#--------------------------------------------------------------------------- +QUIET = NO +WARNINGS = YES +WARN_IF_UNDOCUMENTED = YES +WARN_IF_DOC_ERROR = YES +WARN_FORMAT = "$file:$line: $text" +WARN_LOGFILE = +#--------------------------------------------------------------------------- +# configuration options related to the input files +#--------------------------------------------------------------------------- +INPUT = . ../common +FILE_PATTERNS = *.c \ + *.cc \ + *.cxx \ + *.cpp \ + *.c++ \ + *.java \ + *.ii \ + *.ixx \ + *.ipp \ + *.i++ \ + *.inl \ + *.h \ + *.hh \ + *.hxx \ + *.hpp \ + *.h++ \ + *.idl \ + *.odl \ + *.cs \ + *.php \ + *.php3 \ + *.inc \ + *.m \ + *.mm +RECURSIVE = NO +EXCLUDE = +EXCLUDE_SYMLINKS = NO +EXCLUDE_PATTERNS = +EXAMPLE_PATH = +EXAMPLE_PATTERNS = * +EXAMPLE_RECURSIVE = NO +IMAGE_PATH = +INPUT_FILTER = +FILTER_PATTERNS = +FILTER_SOURCE_FILES = NO +#--------------------------------------------------------------------------- +# configuration options related to source browsing +#--------------------------------------------------------------------------- +SOURCE_BROWSER = NO +INLINE_SOURCES = NO +STRIP_CODE_COMMENTS = YES +REFERENCED_BY_RELATION = NO +REFERENCES_RELATION = NO +VERBATIM_HEADERS = NO +#--------------------------------------------------------------------------- +# configuration options related to the alphabetical class index +#--------------------------------------------------------------------------- +ALPHABETICAL_INDEX = NO +COLS_IN_ALPHA_INDEX = 5 +IGNORE_PREFIX = +#--------------------------------------------------------------------------- +# configuration options related to the HTML output +#--------------------------------------------------------------------------- +GENERATE_HTML = YES +HTML_OUTPUT = html +HTML_FILE_EXTENSION = .html +HTML_HEADER = +HTML_FOOTER = +HTML_STYLESHEET = +HTML_ALIGN_MEMBERS = YES +GENERATE_HTMLHELP = NO +CHM_FILE = +HHC_LOCATION = +GENERATE_CHI = NO +BINARY_TOC = NO +TOC_EXPAND = NO +DISABLE_INDEX = NO +ENUM_VALUES_PER_LINE = 4 +GENERATE_TREEVIEW = YES +TREEVIEW_WIDTH = 250 +#--------------------------------------------------------------------------- +# configuration options related to the LaTeX output +#--------------------------------------------------------------------------- +GENERATE_LATEX = NO +LATEX_OUTPUT = latex +LATEX_CMD_NAME = latex +MAKEINDEX_CMD_NAME = makeindex +COMPACT_LATEX = NO +PAPER_TYPE = a4wide +EXTRA_PACKAGES = +LATEX_HEADER = +PDF_HYPERLINKS = NO +USE_PDFLATEX = NO +LATEX_BATCHMODE = NO +LATEX_HIDE_INDICES = NO +#--------------------------------------------------------------------------- +# configuration options related to the RTF output +#--------------------------------------------------------------------------- +GENERATE_RTF = NO +RTF_OUTPUT = rtf +COMPACT_RTF = NO +RTF_HYPERLINKS = NO +RTF_STYLESHEET_FILE = +RTF_EXTENSIONS_FILE = +#--------------------------------------------------------------------------- +# configuration options related to the man page output +#--------------------------------------------------------------------------- +GENERATE_MAN = NO +MAN_OUTPUT = man +MAN_EXTENSION = .3 +MAN_LINKS = NO +#--------------------------------------------------------------------------- +# configuration options related to the XML output +#--------------------------------------------------------------------------- +GENERATE_XML = NO +XML_OUTPUT = xml +XML_SCHEMA = +XML_DTD = +XML_PROGRAMLISTING = YES +#--------------------------------------------------------------------------- +# configuration options for the AutoGen Definitions output +#--------------------------------------------------------------------------- +GENERATE_AUTOGEN_DEF = NO +#--------------------------------------------------------------------------- +# configuration options related to the Perl module output +#--------------------------------------------------------------------------- +GENERATE_PERLMOD = NO +PERLMOD_LATEX = NO +PERLMOD_PRETTY = YES +PERLMOD_MAKEVAR_PREFIX = +#--------------------------------------------------------------------------- +# Configuration options related to the preprocessor +#--------------------------------------------------------------------------- +ENABLE_PREPROCESSING = YES +MACRO_EXPANSION = NO +EXPAND_ONLY_PREDEF = NO +SEARCH_INCLUDES = YES +INCLUDE_PATH = +INCLUDE_FILE_PATTERNS = +PREDEFINED = +EXPAND_AS_DEFINED = +SKIP_FUNCTION_MACROS = YES +#--------------------------------------------------------------------------- +# Configuration::additions related to external references +#--------------------------------------------------------------------------- +TAGFILES = +GENERATE_TAGFILE = +ALLEXTERNALS = NO +EXTERNAL_GROUPS = YES +PERL_PATH = /usr/bin/perl +#--------------------------------------------------------------------------- +# Configuration options related to the dot tool +#--------------------------------------------------------------------------- +CLASS_DIAGRAMS = NO +HIDE_UNDOC_RELATIONS = YES +HAVE_DOT = NO +CLASS_GRAPH = YES +COLLABORATION_GRAPH = YES +UML_LOOK = NO +TEMPLATE_RELATIONS = NO +INCLUDE_GRAPH = YES +INCLUDED_BY_GRAPH = YES +CALL_GRAPH = NO +GRAPHICAL_HIERARCHY = YES +DOT_IMAGE_FORMAT = png +DOT_PATH = +DOTFILE_DIRS = +MAX_DOT_GRAPH_WIDTH = 1024 +MAX_DOT_GRAPH_HEIGHT = 1024 +MAX_DOT_GRAPH_DEPTH = 1000 +GENERATE_LEGEND = YES +DOT_CLEANUP = YES +#--------------------------------------------------------------------------- +# Configuration::additions related to the search engine +#--------------------------------------------------------------------------- +SEARCHENGINE = NO diff --git a/elftosb2/ElftosbAST.cpp b/elftosb2/ElftosbAST.cpp new file mode 100644 index 0000000..ab7732b --- /dev/null +++ b/elftosb2/ElftosbAST.cpp @@ -0,0 +1,1352 @@ +/* + * File: ElftosbAST.cpp + * + * Copyright (c) Freescale Semiconductor, Inc. All rights reserved. + * See included license file for license details. + */ + +#include "ElftosbAST.h" +#include <stdexcept> +#include <math.h> +#include <assert.h> +#include "ElftosbErrors.h" +#include "format_string.h" + +using namespace elftosb; + +#pragma mark = ASTNode = + +void ASTNode::printTree(int indent) const +{ + printIndent(indent); + printf("%s\n", nodeName().c_str()); +} + +void ASTNode::printIndent(int indent) const +{ + int i; + for (i=0; i<indent; ++i) + { + printf(" "); + } +} + +void ASTNode::setLocation(token_loc_t & first, token_loc_t & last) +{ + m_location.m_firstLine = first.m_firstLine; + m_location.m_lastLine = last.m_lastLine; +} + +void ASTNode::setLocation(ASTNode * first, ASTNode * last) +{ + m_location.m_firstLine = first->getLocation().m_firstLine; + m_location.m_lastLine = last->getLocation().m_lastLine; +} + +#pragma mark = ListASTNode = + +ListASTNode::ListASTNode(const ListASTNode & other) +: ASTNode(other), m_list() +{ + // deep copy each item of the original's list + const_iterator it = other.begin(); + for (; it != other.end(); ++it) + { + m_list.push_back((*it)->clone()); + } +} + +//! Deletes child node in the list. +//! +ListASTNode::~ListASTNode() +{ + iterator it = begin(); + for (; it != end(); it++) + { + delete *it; + } +} + +//! If \a node is NULL then the list is left unmodified. +//! +//! The list node's location is automatically updated after the node is added by a call +//! to updateLocation(). +void ListASTNode::appendNode(ASTNode * node) +{ + if (node) + { + m_list.push_back(node); + updateLocation(); + } +} + +void ListASTNode::printTree(int indent) const +{ + ASTNode::printTree(indent); + + int n = 0; + const_iterator it = begin(); + for (; it != end(); it++, n++) + { + printIndent(indent + 1); + printf("%d:\n", n); + (*it)->printTree(indent + 2); + } +} + +void ListASTNode::updateLocation() +{ + token_loc_t current = { 0 }; + const_iterator it = begin(); + for (; it != end(); it++) + { + const ASTNode * node = *it; + const token_loc_t & loc = node->getLocation(); + + // handle first node + if (current.m_firstLine == 0) + { + current = loc; + continue; + } + + if (loc.m_firstLine < current.m_firstLine) + { + current.m_firstLine = loc.m_firstLine; + } + + if (loc.m_lastLine > current.m_lastLine) + { + current.m_lastLine = loc.m_lastLine; + } + } + + setLocation(current); +} + +#pragma mark = CommandFileASTNode = + +CommandFileASTNode::CommandFileASTNode() +: ASTNode(), m_options(), m_constants(), m_sources(), m_sections() +{ +} + +CommandFileASTNode::CommandFileASTNode(const CommandFileASTNode & other) +: ASTNode(other), m_options(), m_constants(), m_sources(), m_sections() +{ + m_options = dynamic_cast<ListASTNode*>(other.m_options->clone()); + m_constants = dynamic_cast<ListASTNode*>(other.m_constants->clone()); + m_sources = dynamic_cast<ListASTNode*>(other.m_sources->clone()); + m_sections = dynamic_cast<ListASTNode*>(other.m_sections->clone()); +} + +void CommandFileASTNode::printTree(int indent) const +{ + ASTNode::printTree(indent); + + printIndent(indent + 1); + printf("options:\n"); + if (m_options) m_options->printTree(indent + 2); + + printIndent(indent + 1); + printf("constants:\n"); + if (m_constants) m_constants->printTree(indent + 2); + + printIndent(indent + 1); + printf("sources:\n"); + if (m_sources) m_sources->printTree(indent + 2); + + printIndent(indent + 1); + printf("sections:\n"); + if (m_sections) m_sections->printTree(indent + 2); +} + +#pragma mark = ExprASTNode = + +int_size_t ExprASTNode::resultIntSize(int_size_t a, int_size_t b) +{ + int_size_t result; + switch (a) + { + case kWordSize: + result = kWordSize; + break; + case kHalfWordSize: + if (b == kWordSize) + { + result = kWordSize; + } + else + { + result = kHalfWordSize; + } + break; + case kByteSize: + if (b == kWordSize) + { + result = kWordSize; + } + else if (b == kHalfWordSize) + { + result = kHalfWordSize; + } + else + { + result = kByteSize; + } + break; + } + + return result; +} + +#pragma mark = IntConstExprASTNode = + +IntConstExprASTNode::IntConstExprASTNode(const IntConstExprASTNode & other) +: ExprASTNode(other), m_value(other.m_value), m_size(other.m_size) +{ +} + +void IntConstExprASTNode::printTree(int indent) const +{ + printIndent(indent); + char sizeChar='?'; + switch (m_size) + { + case kWordSize: + sizeChar = 'w'; + break; + case kHalfWordSize: + sizeChar = 'h'; + break; + case kByteSize: + sizeChar = 'b'; + break; + } + printf("%s(%d:%c)\n", nodeName().c_str(), m_value, sizeChar); +} + +#pragma mark = VariableExprASTNode = + +VariableExprASTNode::VariableExprASTNode(const VariableExprASTNode & other) +: ExprASTNode(other), m_variable() +{ + m_variable = new std::string(*other.m_variable); +} + +void VariableExprASTNode::printTree(int indent) const +{ + printIndent(indent); + printf("%s(%s)\n", nodeName().c_str(), m_variable->c_str()); +} + +ExprASTNode * VariableExprASTNode::reduce(EvalContext & context) +{ + if (!context.isVariableDefined(*m_variable)) + { + throw std::runtime_error(format_string("line %d: undefined variable '%s'", getFirstLine(), m_variable->c_str())); + } + + uint32_t value = context.getVariableValue(*m_variable); + int_size_t size = context.getVariableSize(*m_variable); + return new IntConstExprASTNode(value, size); +} + +#pragma mark = SymbolRefExprASTNode = + +SymbolRefExprASTNode::SymbolRefExprASTNode(const SymbolRefExprASTNode & other) +: ExprASTNode(other), m_symbol(NULL) +{ + if (other.m_symbol) + { + m_symbol = dynamic_cast<SymbolASTNode*>(other.m_symbol->clone()); + } +} + +void SymbolRefExprASTNode::printTree(int indent) const +{ +} + +ExprASTNode * SymbolRefExprASTNode::reduce(EvalContext & context) +{ + EvalContext::SourceFileManager * manager = context.getSourceFileManager(); + if (!manager) + { + throw std::runtime_error("no source manager available"); + } + + if (!m_symbol) + { + throw semantic_error("no symbol provided"); + } + + // Get the name of the symbol + std::string * symbolName = m_symbol->getSymbolName(); +// if (!symbolName) +// { +// throw semantic_error(format_string("line %d: no symbol name provided", getFirstLine())); +// } + + // Get the source file. + std::string * sourceName = m_symbol->getSource(); + SourceFile * sourceFile; + + if (sourceName) + { + sourceFile = manager->getSourceFile(*sourceName); + if (!sourceFile) + { + throw semantic_error(format_string("line %d: no source file named %s", getFirstLine(), sourceName->c_str())); + } + } + else + { + sourceFile = manager->getDefaultSourceFile(); + if (!sourceFile) + { + throw semantic_error(format_string("line %d: no default source file is set", getFirstLine())); + } + } + + // open the file if it hasn't already been + if (!sourceFile->isOpen()) + { + sourceFile->open(); + } + + // Make sure the source file supports symbols before going any further + if (symbolName && !sourceFile->supportsNamedSymbols()) + { + throw semantic_error(format_string("line %d: source file %s does not support symbols", getFirstLine(), sourceFile->getPath().c_str())); + } + + if (!symbolName && !sourceFile->hasEntryPoint()) + { + throw semantic_error(format_string("line %d: source file %s does not have an entry point", getFirstLine(), sourceFile->getPath().c_str())); + } + + // Returns a const expr node with the symbol's value. + uint32_t value; + if (symbolName) + { + value = sourceFile->getSymbolValue(*symbolName); + } + else + { + value = sourceFile->getEntryPointAddress(); + } + return new IntConstExprASTNode(value); +} + +#pragma mark = NegativeExprASTNode = + +NegativeExprASTNode::NegativeExprASTNode(const NegativeExprASTNode & other) +: ExprASTNode(other), m_expr() +{ + m_expr = dynamic_cast<ExprASTNode*>(other.m_expr->clone()); +} + +void NegativeExprASTNode::printTree(int indent) const +{ + ExprASTNode::printTree(indent); + if (m_expr) m_expr->printTree(indent + 1); +} + +ExprASTNode * NegativeExprASTNode::reduce(EvalContext & context) +{ + if (!m_expr) + { + return this; + } + + m_expr = m_expr->reduce(context); + IntConstExprASTNode * intConst = dynamic_cast<IntConstExprASTNode*>(m_expr.get()); + if (intConst) + { + int32_t value = -(int32_t)intConst->getValue(); + return new IntConstExprASTNode((uint32_t)value, intConst->getSize()); + } + else + { + return this; + } +} + +#pragma mark = BooleanNotExprASTNode = + +BooleanNotExprASTNode::BooleanNotExprASTNode(const BooleanNotExprASTNode & other) +: ExprASTNode(other), m_expr() +{ + m_expr = dynamic_cast<ExprASTNode*>(other.m_expr->clone()); +} + +void BooleanNotExprASTNode::printTree(int indent) const +{ + ExprASTNode::printTree(indent); + if (m_expr) m_expr->printTree(indent + 1); +} + +ExprASTNode * BooleanNotExprASTNode::reduce(EvalContext & context) +{ + if (!m_expr) + { + return this; + } + + m_expr = m_expr->reduce(context); + IntConstExprASTNode * intConst = dynamic_cast<IntConstExprASTNode*>(m_expr.get()); + if (intConst) + { + int32_t value = !((int32_t)intConst->getValue()); + return new IntConstExprASTNode((uint32_t)value, intConst->getSize()); + } + else + { + throw semantic_error(format_string("line %d: expression did not evaluate to an integer", m_expr->getFirstLine())); + } +} + +#pragma mark = SourceFileFunctionASTNode = + +SourceFileFunctionASTNode::SourceFileFunctionASTNode(const SourceFileFunctionASTNode & other) +: ExprASTNode(other), m_functionName(), m_sourceFile() +{ + m_functionName = new std::string(*other.m_functionName); + m_sourceFile = new std::string(*other.m_sourceFile); +} + +void SourceFileFunctionASTNode::printTree(int indent) const +{ + ExprASTNode::printTree(indent); + printIndent(indent+1); + + // for some stupid reason the msft C++ compiler barfs on the following line if the ".get()" parts are remove, + // even though the first line of reduce() below has the same expression, just in parentheses. stupid compiler. + if (m_functionName.get() && m_sourceFile.get()) + { + printf("%s ( %s )\n", m_functionName->c_str(), m_sourceFile->c_str()); + } +} + +ExprASTNode * SourceFileFunctionASTNode::reduce(EvalContext & context) +{ + if (!(m_functionName && m_sourceFile)) + { + throw std::runtime_error("unset function name or source file"); + } + + // Get source file manager from evaluation context. This will be the + // conversion controller itself. + EvalContext::SourceFileManager * mgr = context.getSourceFileManager(); + if (!mgr) + { + throw std::runtime_error("source file manager is not set"); + } + + // Perform function + uint32_t functionResult = 0; + if (*m_functionName == "exists") + { + functionResult = static_cast<uint32_t>(mgr->hasSourceFile(*m_sourceFile)); + } + + // Return function result as an expression node + return new IntConstExprASTNode(functionResult); +} + +#pragma mark = DefinedOperatorASTNode = + +DefinedOperatorASTNode::DefinedOperatorASTNode(const DefinedOperatorASTNode & other) +: ExprASTNode(other), m_constantName() +{ + m_constantName = new std::string(*other.m_constantName); +} + +void DefinedOperatorASTNode::printTree(int indent) const +{ + ExprASTNode::printTree(indent); + printIndent(indent+1); + + if (m_constantName) + { + printf("defined ( %s )\n", m_constantName->c_str()); + } +} + +ExprASTNode * DefinedOperatorASTNode::reduce(EvalContext & context) +{ + assert(m_constantName); + + // Return function result as an expression node + return new IntConstExprASTNode(context.isVariableDefined(m_constantName) ? 1 : 0); +} + +#pragma mark = SizeofOperatorASTNode = + +SizeofOperatorASTNode::SizeofOperatorASTNode(const SizeofOperatorASTNode & other) +: ExprASTNode(other), m_constantName(), m_symbol() +{ + m_constantName = new std::string(*other.m_constantName); + m_symbol = dynamic_cast<SymbolASTNode*>(other.m_symbol->clone()); +} + +void SizeofOperatorASTNode::printTree(int indent) const +{ + ExprASTNode::printTree(indent); + + printIndent(indent+1); + + if (m_constantName) + { + printf("sizeof: %s\n", m_constantName->c_str()); + } + else if (m_symbol) + { + printf("sizeof:\n"); + m_symbol->printTree(indent + 2); + } +} + +ExprASTNode * SizeofOperatorASTNode::reduce(EvalContext & context) +{ + // One or the other must be defined. + assert(m_constantName || m_symbol); + + EvalContext::SourceFileManager * manager = context.getSourceFileManager(); + assert(manager); + + unsigned sizeInBytes = 0; + SourceFile * sourceFile; + + if (m_symbol) + { + // Get the symbol name. + std::string * symbolName = m_symbol->getSymbolName(); + assert(symbolName); + + // Get the source file, using the default if one is not specified. + std::string * sourceName = m_symbol->getSource(); + if (sourceName) + { + sourceFile = manager->getSourceFile(*sourceName); + if (!sourceFile) + { + throw semantic_error(format_string("line %d: invalid source file: %s", getFirstLine(), sourceName->c_str())); + } + } + else + { + sourceFile = manager->getDefaultSourceFile(); + if (!sourceFile) + { + throw semantic_error(format_string("line %d: no default source file is set", getFirstLine())); + } + } + + // Get the size of the symbol. + if (sourceFile->hasSymbol(*symbolName)) + { + sizeInBytes = sourceFile->getSymbolSize(*symbolName); + } + } + else if (m_constantName) + { + // See if the "constant" is really a constant or if it's a source name. + if (manager->hasSourceFile(m_constantName)) + { + sourceFile = manager->getSourceFile(m_constantName); + if (sourceFile) + { + sizeInBytes = sourceFile->getSize(); + } + } + else + { + // Regular constant. + if (!context.isVariableDefined(*m_constantName)) + { + throw semantic_error(format_string("line %d: cannot get size of undefined constant %s", getFirstLine(), m_constantName->c_str())); + } + + int_size_t intSize = context.getVariableSize(*m_constantName); + switch (intSize) + { + case kWordSize: + sizeInBytes = sizeof(uint32_t); + break; + case kHalfWordSize: + sizeInBytes = sizeof(uint16_t); + break; + case kByteSize: + sizeInBytes = sizeof(uint8_t); + break; + } + } + } + + // Return function result as an expression node + return new IntConstExprASTNode(sizeInBytes); +} + +#pragma mark = BinaryOpExprASTNode = + +BinaryOpExprASTNode::BinaryOpExprASTNode(const BinaryOpExprASTNode & other) +: ExprASTNode(other), m_left(), m_op(other.m_op), m_right() +{ + m_left = dynamic_cast<ExprASTNode*>(other.m_left->clone()); + m_right = dynamic_cast<ExprASTNode*>(other.m_right->clone()); +} + +void BinaryOpExprASTNode::printTree(int indent) const +{ + ExprASTNode::printTree(indent); + + printIndent(indent + 1); + printf("left:\n"); + if (m_left) m_left->printTree(indent + 2); + + printIndent(indent + 1); + printf("op: %s\n", getOperatorName().c_str()); + + printIndent(indent + 1); + printf("right:\n"); + if (m_right) m_right->printTree(indent + 2); +} + +std::string BinaryOpExprASTNode::getOperatorName() const +{ + switch (m_op) + { + case kAdd: + return "+"; + case kSubtract: + return "-"; + case kMultiply: + return "*"; + case kDivide: + return "/"; + case kModulus: + return "%"; + case kPower: + return "**"; + case kBitwiseAnd: + return "&"; + case kBitwiseOr: + return "|"; + case kBitwiseXor: + return "^"; + case kShiftLeft: + return "<<"; + case kShiftRight: + return ">>"; + case kLessThan: + return "<"; + case kGreaterThan: + return ">"; + case kLessThanEqual: + return "<="; + case kGreaterThanEqual: + return ">"; + case kEqual: + return "=="; + case kNotEqual: + return "!="; + case kBooleanAnd: + return "&&"; + case kBooleanOr: + return "||"; + } + + return "???"; +} + +//! \todo Fix power operator under windows!!! +//! +ExprASTNode * BinaryOpExprASTNode::reduce(EvalContext & context) +{ + if (!m_left || !m_right) + { + return this; + } + + IntConstExprASTNode * leftIntConst = NULL; + IntConstExprASTNode * rightIntConst = NULL; + uint32_t leftValue; + uint32_t rightValue; + uint32_t result = 0; + + // Always reduce the left hand side. + m_left = m_left->reduce(context); + leftIntConst = dynamic_cast<IntConstExprASTNode*>(m_left.get()); + if (!leftIntConst) + { + throw semantic_error(format_string("left hand side of %s operator failed to evaluate to an integer", getOperatorName().c_str())); + } + leftValue = leftIntConst->getValue(); + + // Boolean && and || operators are handled separately so that we can perform + // short-circuit evaluation. + if (m_op == kBooleanAnd || m_op == kBooleanOr) + { + // Reduce right hand side only if required to evaluate the boolean operator. + if ((m_op == kBooleanAnd && leftValue != 0) || (m_op == kBooleanOr && leftValue == 0)) + { + m_right = m_right->reduce(context); + rightIntConst = dynamic_cast<IntConstExprASTNode*>(m_right.get()); + if (!rightIntConst) + { + throw semantic_error(format_string("right hand side of %s operator failed to evaluate to an integer", getOperatorName().c_str())); + } + rightValue = rightIntConst->getValue(); + + // Perform the boolean operation. + switch (m_op) + { + case kBooleanAnd: + result = leftValue && rightValue; + break; + + case kBooleanOr: + result = leftValue && rightValue; + break; + } + } + else if (m_op == kBooleanAnd) + { + // The left hand side is false, so the && operator's result must be false + // without regard to the right hand side. + result = 0; + } + else if (m_op == kBooleanOr) + { + // The left hand value is true so the || result is automatically true. + result = 1; + } + } + else + { + // Reduce right hand side always for most operators. + m_right = m_right->reduce(context); + rightIntConst = dynamic_cast<IntConstExprASTNode*>(m_right.get()); + if (!rightIntConst) + { + throw semantic_error(format_string("right hand side of %s operator failed to evaluate to an integer", getOperatorName().c_str())); + } + rightValue = rightIntConst->getValue(); + + switch (m_op) + { + case kAdd: + result = leftValue + rightValue; + break; + case kSubtract: + result = leftValue - rightValue; + break; + case kMultiply: + result = leftValue * rightValue; + break; + case kDivide: + result = leftValue / rightValue; + break; + case kModulus: + result = leftValue % rightValue; + break; + case kPower: + #ifdef WIN32 + result = 0; + #else + result = lroundf(powf(float(leftValue), float(rightValue))); + #endif + break; + case kBitwiseAnd: + result = leftValue & rightValue; + break; + case kBitwiseOr: + result = leftValue | rightValue; + break; + case kBitwiseXor: + result = leftValue ^ rightValue; + break; + case kShiftLeft: + result = leftValue << rightValue; + break; + case kShiftRight: + result = leftValue >> rightValue; + break; + case kLessThan: + result = leftValue < rightValue; + break; + case kGreaterThan: + result = leftValue > rightValue; + break; + case kLessThanEqual: + result = leftValue <= rightValue; + break; + case kGreaterThanEqual: + result = leftValue >= rightValue; + break; + case kEqual: + result = leftValue == rightValue; + break; + case kNotEqual: + result = leftValue != rightValue; + break; + } + } + + // Create the result value. + int_size_t resultSize; + if (leftIntConst && rightIntConst) + { + resultSize = resultIntSize(leftIntConst->getSize(), rightIntConst->getSize()); + } + else if (leftIntConst) + { + resultSize = leftIntConst->getSize(); + } + else + { + // This shouldn't really be possible, but just in case. + resultSize = kWordSize; + } + return new IntConstExprASTNode(result, resultSize); +} + +#pragma mark = IntSizeExprASTNode = + +IntSizeExprASTNode::IntSizeExprASTNode(const IntSizeExprASTNode & other) +: ExprASTNode(other), m_expr(), m_size(other.m_size) +{ + m_expr = dynamic_cast<ExprASTNode*>(other.m_expr->clone()); +} + +void IntSizeExprASTNode::printTree(int indent) const +{ + ExprASTNode::printTree(indent); + + char sizeChar='?'; + switch (m_size) + { + case kWordSize: + sizeChar = 'w'; + break; + case kHalfWordSize: + sizeChar = 'h'; + break; + case kByteSize: + sizeChar = 'b'; + break; + } + printIndent(indent + 1); + printf("size: %c\n", sizeChar); + + printIndent(indent + 1); + printf("expr:\n"); + if (m_expr) m_expr->printTree(indent + 2); +} + +ExprASTNode * IntSizeExprASTNode::reduce(EvalContext & context) +{ + if (!m_expr) + { + return this; + } + + m_expr = m_expr->reduce(context); + IntConstExprASTNode * intConst = dynamic_cast<IntConstExprASTNode*>(m_expr.get()); + if (!intConst) + { + return this; + } + + return new IntConstExprASTNode(intConst->getValue(), m_size); +} + +#pragma mark = ExprConstASTNode = + +ExprConstASTNode::ExprConstASTNode(const ExprConstASTNode & other) +: ConstASTNode(other), m_expr() +{ + m_expr = dynamic_cast<ExprASTNode*>(other.m_expr->clone()); +} + +void ExprConstASTNode::printTree(int indent) const +{ + ConstASTNode::printTree(indent); + if (m_expr) m_expr->printTree(indent + 1); +} + +#pragma mark = StringConstASTNode = + +StringConstASTNode::StringConstASTNode(const StringConstASTNode & other) +: ConstASTNode(other), m_value() +{ + m_value = new std::string(other.m_value); +} + +void StringConstASTNode::printTree(int indent) const +{ + printIndent(indent); + printf("%s(%s)\n", nodeName().c_str(), m_value->c_str()); +} + +#pragma mark = BlobConstASTNode = + +BlobConstASTNode::BlobConstASTNode(const BlobConstASTNode & other) +: ConstASTNode(other), m_blob() +{ + m_blob = new Blob(*other.m_blob); +} + +void BlobConstASTNode::printTree(int indent) const +{ + printIndent(indent); + + const uint8_t * dataPtr = m_blob->getData(); + unsigned dataLen = m_blob->getLength(); + printf("%s(%p:%d)\n", nodeName().c_str(), dataPtr, dataLen); +} + +#pragma mark = IVTConstASTNode = + +IVTConstASTNode::IVTConstASTNode(const IVTConstASTNode & other) +: ConstASTNode(other), m_fields() +{ + m_fields = dynamic_cast<ListASTNode*>(other.m_fields->clone()); +} + +void IVTConstASTNode::printTree(int indent) const +{ + printIndent(indent); + printf("%s:\n", nodeName().c_str()); + if (m_fields) + { + m_fields->printTree(indent + 1); + } +} + +#pragma mark = AssignmentASTNode = + +AssignmentASTNode::AssignmentASTNode(const AssignmentASTNode & other) +: ASTNode(other), m_ident(), m_value() +{ + m_ident = new std::string(*other.m_ident); + m_value = dynamic_cast<ConstASTNode*>(other.m_value->clone()); +} + +void AssignmentASTNode::printTree(int indent) const +{ + printIndent(indent); + printf("%s(%s)\n", nodeName().c_str(), m_ident->c_str()); + + if (m_value) m_value->printTree(indent + 1); +} + +#pragma mark = SourceDefASTNode = + +SourceDefASTNode::SourceDefASTNode(const SourceDefASTNode & other) +: ASTNode(other), m_name() +{ + m_name = new std::string(*other.m_name); +} + +#pragma mark = PathSourceDefASTNode = + +PathSourceDefASTNode::PathSourceDefASTNode(const PathSourceDefASTNode & other) +: SourceDefASTNode(other), m_path() +{ + m_path = new std::string(*other.m_path); +} + +void PathSourceDefASTNode::printTree(int indent) const +{ + SourceDefASTNode::printTree(indent); + + printIndent(indent+1); + printf("path: %s\n", m_path->c_str()); + + printIndent(indent+1); + printf("attributes:\n"); + if (m_attributes) + { + m_attributes->printTree(indent+2); + } +} + +#pragma mark = ExternSourceDefASTNode = + +ExternSourceDefASTNode::ExternSourceDefASTNode(const ExternSourceDefASTNode & other) +: SourceDefASTNode(other), m_expr() +{ + m_expr = dynamic_cast<ExprASTNode*>(other.m_expr->clone()); +} + +void ExternSourceDefASTNode::printTree(int indent) const +{ + SourceDefASTNode::printTree(indent); + + printIndent(indent+1); + printf("expr:\n"); + if (m_expr) m_expr->printTree(indent + 2); + + printIndent(indent+1); + printf("attributes:\n"); + if (m_attributes) + { + m_attributes->printTree(indent+2); + } +} + +#pragma mark = SectionContentsASTNode = + +SectionContentsASTNode::SectionContentsASTNode(const SectionContentsASTNode & other) +: ASTNode(other), m_sectionExpr() +{ + m_sectionExpr = dynamic_cast<ExprASTNode*>(other.m_sectionExpr->clone()); +} + +void SectionContentsASTNode::printTree(int indent) const +{ + ASTNode::printTree(indent); + + printIndent(indent + 1); + printf("section#:\n"); + if (m_sectionExpr) m_sectionExpr->printTree(indent + 2); +} + +#pragma mark = DataSectionContentsASTNode = + +DataSectionContentsASTNode::DataSectionContentsASTNode(const DataSectionContentsASTNode & other) +: SectionContentsASTNode(other), m_contents() +{ + m_contents = dynamic_cast<ASTNode*>(other.m_contents->clone()); +} + +void DataSectionContentsASTNode::printTree(int indent) const +{ + SectionContentsASTNode::printTree(indent); + + if (m_contents) + { + m_contents->printTree(indent + 1); + } +} + +#pragma mark = BootableSectionContentsASTNode = + +BootableSectionContentsASTNode::BootableSectionContentsASTNode(const BootableSectionContentsASTNode & other) +: SectionContentsASTNode(other), m_statements() +{ + m_statements = dynamic_cast<ListASTNode*>(other.m_statements->clone()); +} + +void BootableSectionContentsASTNode::printTree(int indent) const +{ + SectionContentsASTNode::printTree(indent); + + printIndent(indent + 1); + printf("statements:\n"); + if (m_statements) m_statements->printTree(indent + 2); +} + +#pragma mark = IfStatementASTNode = + +//! \warning Be careful; this method could enter an infinite loop if m_nextIf feeds +//! back onto itself. m_nextIf must be NULL at some point down the next if list. +IfStatementASTNode::IfStatementASTNode(const IfStatementASTNode & other) +: StatementASTNode(), + m_conditionExpr(), + m_ifStatements(), + m_nextIf(), + m_elseStatements() +{ + m_conditionExpr = dynamic_cast<ExprASTNode*>(other.m_conditionExpr->clone()); + m_ifStatements = dynamic_cast<ListASTNode*>(other.m_ifStatements->clone()); + m_nextIf = dynamic_cast<IfStatementASTNode*>(other.m_nextIf->clone()); + m_elseStatements = dynamic_cast<ListASTNode*>(other.m_elseStatements->clone()); +} + +#pragma mark = ModeStatementASTNode = + +ModeStatementASTNode::ModeStatementASTNode(const ModeStatementASTNode & other) +: StatementASTNode(other), m_modeExpr() +{ + m_modeExpr = dynamic_cast<ExprASTNode*>(other.m_modeExpr->clone()); +} + +void ModeStatementASTNode::printTree(int indent) const +{ + StatementASTNode::printTree(indent); + printIndent(indent + 1); + printf("mode:\n"); + if (m_modeExpr) m_modeExpr->printTree(indent + 2); +} + +#pragma mark = MessageStatementASTNode = + +MessageStatementASTNode::MessageStatementASTNode(const MessageStatementASTNode & other) +: StatementASTNode(other), m_type(other.m_type), m_message() +{ + m_message = new std::string(*other.m_message); +} + +void MessageStatementASTNode::printTree(int indent) const +{ + StatementASTNode::printTree(indent); + printIndent(indent + 1); + printf("%s: %s\n", getTypeName(), m_message->c_str()); +} + +const char * MessageStatementASTNode::getTypeName() const +{ + switch (m_type) + { + case kInfo: + return "info"; + + case kWarning: + return "warning"; + + case kError: + return "error"; + } + + return "unknown"; +} + +#pragma mark = LoadStatementASTNode = + +LoadStatementASTNode::LoadStatementASTNode(const LoadStatementASTNode & other) +: StatementASTNode(other), m_data(), m_target(), m_isDCDLoad(other.m_isDCDLoad) +{ + m_data = other.m_data->clone(); + m_target = other.m_target->clone(); +} + +void LoadStatementASTNode::printTree(int indent) const +{ + StatementASTNode::printTree(indent); + + printIndent(indent + 1); + printf("data:\n"); + if (m_data) m_data->printTree(indent + 2); + + printIndent(indent + 1); + printf("target:\n"); + if (m_target) m_target->printTree(indent + 2); +} + +#pragma mark = CallStatementASTNode = + +CallStatementASTNode::CallStatementASTNode(const CallStatementASTNode & other) +: StatementASTNode(other), m_type(other.m_type), m_target(), m_arg() +{ + m_target = other.m_target->clone(); + m_arg = other.m_arg->clone(); +} + +void CallStatementASTNode::printTree(int indent) const +{ + printIndent(indent); + printf("%s(%s)%s\n", nodeName().c_str(), (m_type == kCallType ? "call" : "jump"), (m_isHAB ? "/HAB" : "")); + + printIndent(indent + 1); + printf("target:\n"); + if (m_target) m_target->printTree(indent + 2); + + printIndent(indent + 1); + printf("arg:\n"); + if (m_arg) m_arg->printTree(indent + 2); +} + +#pragma mark = SourceASTNode = + +SourceASTNode::SourceASTNode(const SourceASTNode & other) +: ASTNode(other), m_name() +{ + m_name = new std::string(*other.m_name); +} + +void SourceASTNode::printTree(int indent) const +{ + printIndent(indent); + printf("%s(%s)\n", nodeName().c_str(), m_name->c_str()); +} + +#pragma mark = SectionMatchListASTNode = + +SectionMatchListASTNode::SectionMatchListASTNode(const SectionMatchListASTNode & other) +: ASTNode(other), m_sections(), m_source() +{ + if (other.m_sections) + { + m_sections = dynamic_cast<ListASTNode *>(other.m_sections->clone()); + } + + if (other.m_source) + { + m_source = new std::string(*other.m_source); + } +} + +void SectionMatchListASTNode::printTree(int indent) const +{ + ASTNode::printTree(indent); + + printIndent(indent+1); + printf("sections:\n"); + if (m_sections) + { + m_sections->printTree(indent+2); + } + + printIndent(indent+1); + printf("source: ", m_source->c_str()); + if (m_source) + { + printf("%s\n", m_source->c_str()); + } + else + { + printf("\n"); + } +} + +#pragma mark = SectionASTNode = + +SectionASTNode::SectionASTNode(const SectionASTNode & other) +: ASTNode(other), m_name(), m_source() +{ + m_action = other.m_action; + + if (other.m_name) + { + m_name = new std::string(*other.m_name); + } + + if (other.m_source) + { + m_source = new std::string(*other.m_source); + } +} + +void SectionASTNode::printTree(int indent) const +{ + printIndent(indent); + + const char * actionName; + switch (m_action) + { + case kInclude: + actionName = "include"; + break; + case kExclude: + actionName = "exclude"; + break; + } + + if (m_source) + { + printf("%s(%s:%s:%s)\n", nodeName().c_str(), actionName, m_name->c_str(), m_source->c_str()); + } + else + { + printf("%s(%s:%s)\n", nodeName().c_str(), actionName, m_name->c_str()); + } +} + +#pragma mark = SymbolASTNode = + +SymbolASTNode::SymbolASTNode(const SymbolASTNode & other) +: ASTNode(other), m_symbol(), m_source() +{ + m_symbol = new std::string(*other.m_symbol); + m_source = new std::string(*other.m_source); +} + +void SymbolASTNode::printTree(int indent) const +{ + printIndent(indent); + + const char * symbol = NULL; + if (m_symbol) + { + symbol = m_symbol->c_str(); + } + + const char * source = NULL; + if (m_source) + { + source = m_source->c_str(); + } + + printf("%s(", nodeName().c_str()); + if (source) + { + printf(source); + } + else + { + printf("."); + } + printf(":"); + if (symbol) + { + printf(symbol); + } + else + { + printf("."); + } + printf(")\n"); +} + +#pragma mark = AddressRangeASTNode = + +AddressRangeASTNode::AddressRangeASTNode(const AddressRangeASTNode & other) +: ASTNode(other), m_begin(), m_end() +{ + m_begin = other.m_begin->clone(); + m_end = other.m_end->clone(); +} + +void AddressRangeASTNode::printTree(int indent) const +{ + ASTNode::printTree(indent); + + printIndent(indent + 1); + printf("begin:\n"); + if (m_begin) m_begin->printTree(indent + 2); + + printIndent(indent + 1); + printf("end:\n"); + if (m_end) m_end->printTree(indent + 2); +} + +#pragma mark = FromStatementASTNode = + +FromStatementASTNode::FromStatementASTNode(std::string * source, ListASTNode * statements) +: StatementASTNode(), m_source(source), m_statements(statements) +{ +} + +FromStatementASTNode::FromStatementASTNode(const FromStatementASTNode & other) +: StatementASTNode(), m_source(), m_statements() +{ + m_source = new std::string(*other.m_source); + m_statements = dynamic_cast<ListASTNode*>(other.m_statements->clone()); +} + +void FromStatementASTNode::printTree(int indent) const +{ + ASTNode::printTree(indent); + + printIndent(indent + 1); + printf("source: "); + if (m_source) printf("%s\n", m_source->c_str()); + + printIndent(indent + 1); + printf("statements:\n"); + if (m_statements) m_statements->printTree(indent + 2); +} + diff --git a/elftosb2/ElftosbAST.h b/elftosb2/ElftosbAST.h new file mode 100644 index 0000000..cb70f49 --- /dev/null +++ b/elftosb2/ElftosbAST.h @@ -0,0 +1,1227 @@ +/* + * File: ElftosbAST.h + * + * Copyright (c) Freescale Semiconductor, Inc. All rights reserved. + * See included license file for license details. + */ +#if !defined(_ElftosbAST_h_) +#define _ElftosbAST_h_ + +#include "stdafx.h" +#include <string> +#include <list> +#include "smart_ptr.h" +#include "EvalContext.h" + +namespace elftosb +{ + +// forward reference +class SymbolASTNode; + +/*! + * \brief Token location in the source file. + */ +struct token_loc_t +{ + int m_firstLine; //!< Starting line of the token. + int m_lastLine; //!< Ending line of the token. +}; + +/*! + * \brief The base class for all AST node classes. + */ +class ASTNode +{ +public: + //! \brief Default constructor. + ASTNode() : m_parent(0) {} + + //! \brief Constructor taking a parent node. + ASTNode(ASTNode * parent) : m_parent(parent) {} + + //! \brief Copy constructor. + ASTNode(const ASTNode & other) : m_parent(other.m_parent) {} + + //! \brief Destructor. + virtual ~ASTNode() {} + + //! \brief Returns an exact duplicate of this object. + virtual ASTNode * clone() const = 0; + + //! \brief Returns the name of the object's class. + virtual std::string nodeName() const { return "ASTNode"; } + + //! \name Parents + //@{ + virtual ASTNode * getParent() const { return m_parent; } + virtual void setParent(ASTNode * newParent) { m_parent = newParent; } + //@} + + //! \name Tree printing + //@{ + virtual void printTree() const { printTree(0); } + virtual void printTree(int indent) const; + //@} + + //! \name Location + //@{ + virtual void setLocation(token_loc_t & loc) { m_location = loc; } + virtual void setLocation(token_loc_t & first, token_loc_t & last); + virtual void setLocation(ASTNode * loc) { setLocation(loc->getLocation()); } + virtual void setLocation(ASTNode * first, ASTNode * last); + + virtual token_loc_t & getLocation() { return m_location; } + virtual const token_loc_t & getLocation() const { return m_location; } + + virtual int getFirstLine() { return m_location.m_firstLine; } + virtual int getLastLine() { return m_location.m_lastLine; } + //@} + +protected: + ASTNode * m_parent; //!< Pointer to parent node of this object. May be NULL. + token_loc_t m_location; //!< Location of this node in the source file. + + //! \brief Prints \a indent number of spaces. + void printIndent(int indent) const; +}; + +/*! + * \brief AST node that contains other AST nodes. + * + * Unlike other AST nodes, the location of a ListASTNode is computed dynamically + * based on the nodes in its list. Or mostly dynamic at least. The updateLocation() + * method is used to force the list object to recalculate its beginning and ending + * line numbers. + * + * \todo Figure out why it crashes in the destructor when the + * ast_list_t type is a list of smart_ptr<ASTNode>. + */ +class ListASTNode : public ASTNode +{ +public: + typedef std::list< /*smart_ptr<ASTNode>*/ ASTNode * > ast_list_t; + typedef ast_list_t::iterator iterator; + typedef ast_list_t::const_iterator const_iterator; + +public: + ListASTNode() {} + + ListASTNode(const ListASTNode & other); + + virtual ~ListASTNode(); + + virtual ASTNode * clone() const { return new ListASTNode(*this); } + + virtual std::string nodeName() const { return "ListASTNode"; } + + virtual void printTree(int indent) const; + + //! \name List operations + //@{ + //! \brief Adds \a node to the end of the ordered list of child nodes. + virtual void appendNode(ASTNode * node); + + //! \brief Returns the number of nodes in this list. + virtual unsigned nodeCount() const { return static_cast<unsigned>(m_list.size()); } + //@} + + //! \name Node iterators + //@{ + inline iterator begin() { return m_list.begin(); } + inline iterator end() { return m_list.end(); } + + inline const_iterator begin() const { return m_list.begin(); } + inline const_iterator end() const { return m_list.end(); } + //@} + + //! \name Location + //@{ + virtual void updateLocation(); + //@} + +protected: + ast_list_t m_list; //!< Ordered list of child nodes. +}; + +/*! + * + */ +class OptionsBlockASTNode : public ASTNode +{ +public: + OptionsBlockASTNode(ListASTNode * options) : ASTNode(), m_options(options) {} + + inline ListASTNode * getOptions() { return m_options; } + + virtual ASTNode * clone() const { return NULL; } + +protected: + smart_ptr<ListASTNode> m_options; +}; + +/*! + * + */ +class ConstantsBlockASTNode : public ASTNode +{ +public: + ConstantsBlockASTNode(ListASTNode * constants) : ASTNode(), m_constants(constants) {} + + inline ListASTNode * getConstants() { return m_constants; } + + virtual ASTNode * clone() const { return NULL; } + +protected: + smart_ptr<ListASTNode> m_constants; +}; + +/*! + * + */ +class SourcesBlockASTNode : public ASTNode +{ +public: + SourcesBlockASTNode(ListASTNode * sources) : ASTNode(), m_sources(sources) {} + + inline ListASTNode * getSources() { return m_sources; } + + virtual ASTNode * clone() const { return NULL; } + +protected: + smart_ptr<ListASTNode> m_sources; +}; + +/*! + * \brief Root node for the entire file. + */ +class CommandFileASTNode : public ASTNode +{ +public: + CommandFileASTNode(); + CommandFileASTNode(const CommandFileASTNode & other); + + virtual std::string nodeName() const { return "CommandFileASTNode"; } + + virtual ASTNode * clone() const { return new CommandFileASTNode(*this); } + + virtual void printTree(int indent) const; + + inline void setBlocks(ListASTNode * blocks) { m_blocks = blocks; } + inline void setOptions(ListASTNode * options) { m_options = options; } + inline void setConstants(ListASTNode * constants) { m_constants = constants; } + inline void setSources(ListASTNode * sources) { m_sources = sources; } + inline void setSections(ListASTNode * sections) { m_sections = sections; } + + inline ListASTNode * getBlocks() { return m_blocks; } + inline ListASTNode * getOptions() { return m_options; } + inline ListASTNode * getConstants() { return m_constants; } + inline ListASTNode * getSources() { return m_sources; } + inline ListASTNode * getSections() { return m_sections; } + +protected: + smart_ptr<ListASTNode> m_blocks; + smart_ptr<ListASTNode> m_options; + smart_ptr<ListASTNode> m_constants; + smart_ptr<ListASTNode> m_sources; + smart_ptr<ListASTNode> m_sections; +}; + +/*! + * \brief Abstract base class for all expression AST nodes. + */ +class ExprASTNode : public ASTNode +{ +public: + ExprASTNode() : ASTNode() {} + ExprASTNode(const ExprASTNode & other) : ASTNode(other) {} + + virtual std::string nodeName() const { return "ExprASTNode"; } + + //! \brief Evaluate the expression and produce a result node to replace this one. + //! + //! The default implementation simply return this node unmodified. This + //! method is responsible for deleting any nodes that are no longer needed. + //! (?) how to delete this? + virtual ExprASTNode * reduce(EvalContext & context) { return this; } + + int_size_t resultIntSize(int_size_t a, int_size_t b); +}; + +/*! + * + */ +class IntConstExprASTNode : public ExprASTNode +{ +public: + IntConstExprASTNode(uint32_t value, int_size_t size=kWordSize) + : ExprASTNode(), m_value(value), m_size(size) + { + } + + IntConstExprASTNode(const IntConstExprASTNode & other); + + virtual std::string nodeName() const { return "IntConstExprASTNode"; } + + virtual ASTNode * clone() const { return new IntConstExprASTNode(*this); } + + virtual void printTree(int indent) const; + + uint32_t getValue() const { return m_value; } + int_size_t getSize() const { return m_size; } + +protected: + uint32_t m_value; + int_size_t m_size; +}; + +/*! + * + */ +class VariableExprASTNode : public ExprASTNode +{ +public: + VariableExprASTNode(std::string * name) : ExprASTNode(), m_variable(name) {} + VariableExprASTNode(const VariableExprASTNode & other); + + inline std::string * getVariableName() { return m_variable; } + + virtual ASTNode * clone() const { return new VariableExprASTNode(*this); } + + virtual std::string nodeName() const { return "VariableExprASTNode"; } + + virtual void printTree(int indent) const; + + virtual ExprASTNode * reduce(EvalContext & context); + +protected: + smart_ptr<std::string> m_variable; +}; + +/*! + * \brief Expression node for a symbol reference. + * + * The symbol evaluates to its address. + */ +class SymbolRefExprASTNode : public ExprASTNode +{ +public: + SymbolRefExprASTNode(SymbolASTNode * sym) : ExprASTNode(), m_symbol(sym) {} + SymbolRefExprASTNode(const SymbolRefExprASTNode & other); + + virtual ASTNode * clone() const { return new SymbolRefExprASTNode(*this); } + + virtual std::string nodeName() const { return "SymbolRefExprASTNode"; } + + virtual void printTree(int indent) const; + + virtual ExprASTNode * reduce(EvalContext & context); + +protected: + SymbolASTNode * m_symbol; +}; + +/*! + * \brief Negates an expression. + */ +class NegativeExprASTNode : public ExprASTNode +{ +public: + NegativeExprASTNode(ExprASTNode * expr) : ExprASTNode(), m_expr(expr) {} + NegativeExprASTNode(const NegativeExprASTNode & other); + + virtual ASTNode * clone() const { return new NegativeExprASTNode(*this); } + + virtual std::string nodeName() const { return "NegativeExprASTNode"; } + + virtual void printTree(int indent) const; + + virtual ExprASTNode * reduce(EvalContext & context); + + ExprASTNode * getExpr() { return m_expr; } + +protected: + smart_ptr<ExprASTNode> m_expr; +}; + +/*! + * \brief Performa a boolean inversion. + */ +class BooleanNotExprASTNode : public ExprASTNode +{ +public: + BooleanNotExprASTNode(ExprASTNode * expr) : ExprASTNode(), m_expr(expr) {} + BooleanNotExprASTNode(const BooleanNotExprASTNode & other); + + virtual ASTNode * clone() const { return new BooleanNotExprASTNode(*this); } + + virtual std::string nodeName() const { return "BooleanNotExprASTNode"; } + + virtual void printTree(int indent) const; + + virtual ExprASTNode * reduce(EvalContext & context); + + ExprASTNode * getExpr() { return m_expr; } + +protected: + smart_ptr<ExprASTNode> m_expr; +}; + +/*! + * \brief Calls a built-in function with a source as the parameter. + */ +class SourceFileFunctionASTNode : public ExprASTNode +{ +public: + SourceFileFunctionASTNode(std::string * functionName, std::string * sourceFileName) : ExprASTNode(), m_functionName(functionName), m_sourceFile(sourceFileName) {} + SourceFileFunctionASTNode(const SourceFileFunctionASTNode & other); + + virtual ASTNode * clone() const { return new SourceFileFunctionASTNode(*this); } + + virtual std::string nodeName() const { return "SourceFileFunctionASTNode"; } + + virtual void printTree(int indent) const; + + virtual ExprASTNode * reduce(EvalContext & context); + + std::string * getFunctionName() { return m_functionName; } + std::string * getSourceFile() { return m_sourceFile; } + +protected: + smart_ptr<std::string> m_functionName; + smart_ptr<std::string> m_sourceFile; +}; + +/*! + * \brief Returns true or false depending on whether a constant is defined. + */ +class DefinedOperatorASTNode : public ExprASTNode +{ +public: + DefinedOperatorASTNode(std::string * constantName) : ExprASTNode(), m_constantName(constantName) {} + DefinedOperatorASTNode(const DefinedOperatorASTNode & other); + + virtual ASTNode * clone() const { return new DefinedOperatorASTNode(*this); } + + virtual std::string nodeName() const { return "DefinedOperatorASTNode"; } + + virtual void printTree(int indent) const; + + virtual ExprASTNode * reduce(EvalContext & context); + + std::string * getConstantName() { return m_constantName; } + +protected: + smart_ptr<std::string> m_constantName; //!< Name of the constant. +}; + +class SymbolASTNode; + +/*! + * \brief Returns an integer that is the size in bytes of the operand. + */ +class SizeofOperatorASTNode : public ExprASTNode +{ +public: + SizeofOperatorASTNode(std::string * constantName) : ExprASTNode(), m_constantName(constantName), m_symbol() {} + SizeofOperatorASTNode(SymbolASTNode * symbol) : ExprASTNode(), m_constantName(), m_symbol(symbol) {} + SizeofOperatorASTNode(const SizeofOperatorASTNode & other); + + virtual ASTNode * clone() const { return new SizeofOperatorASTNode(*this); } + + virtual std::string nodeName() const { return "SizeofOperatorASTNode"; } + + virtual void printTree(int indent) const; + + virtual ExprASTNode * reduce(EvalContext & context); + + std::string * getConstantName() { return m_constantName; } + SymbolASTNode * getSymbol() { return m_symbol; } + +protected: + smart_ptr<std::string> m_constantName; //!< Name of the constant. + smart_ptr<SymbolASTNode> m_symbol; //!< Symbol reference. If this is non-NULL then the constant name is used instead. +}; + +/*! + * + */ +class BinaryOpExprASTNode : public ExprASTNode +{ +public: + enum operator_t + { + kAdd, + kSubtract, + kMultiply, + kDivide, + kModulus, + kPower, + kBitwiseAnd, + kBitwiseOr, + kBitwiseXor, + kShiftLeft, + kShiftRight, + kLessThan, + kGreaterThan, + kLessThanEqual, + kGreaterThanEqual, + kEqual, + kNotEqual, + kBooleanAnd, + kBooleanOr + }; + + BinaryOpExprASTNode(ExprASTNode * left, operator_t op, ExprASTNode * right) + : ExprASTNode(), m_left(left), m_op(op), m_right(right) + { + } + + BinaryOpExprASTNode(const BinaryOpExprASTNode & other); + + virtual ASTNode * clone() const { return new BinaryOpExprASTNode(*this); } + + virtual std::string nodeName() const { return "BinaryOpExprASTNode"; } + + virtual void printTree(int indent) const; + + virtual ExprASTNode * reduce(EvalContext & context); + + ExprASTNode * getLeftExpr() { return m_left; } + ExprASTNode * getRightExpr() { return m_right; } + operator_t getOp() const { return m_op; } + +protected: + smart_ptr<ExprASTNode> m_left; + smart_ptr<ExprASTNode> m_right; + operator_t m_op; + + std::string getOperatorName() const; +}; + +/*! + * \brief Negates an expression. + */ +class IntSizeExprASTNode : public ExprASTNode +{ +public: + IntSizeExprASTNode(ExprASTNode * expr, int_size_t intSize) : ExprASTNode(), m_expr(expr), m_size(intSize) {} + IntSizeExprASTNode(const IntSizeExprASTNode & other); + + virtual ASTNode * clone() const { return new IntSizeExprASTNode(*this); } + + virtual std::string nodeName() const { return "IntSizeExprASTNode"; } + + virtual void printTree(int indent) const; + + virtual ExprASTNode * reduce(EvalContext & context); + + ExprASTNode * getExpr() { return m_expr; } + int_size_t getIntSize() { return m_size; } + +protected: + smart_ptr<ExprASTNode> m_expr; + int_size_t m_size; +}; + +/*! + * Base class for const AST nodes. + */ +class ConstASTNode : public ASTNode +{ +public: + ConstASTNode() : ASTNode() {} + ConstASTNode(const ConstASTNode & other) : ASTNode(other) {} + +protected: +}; + +/*! + * + */ +class ExprConstASTNode : public ConstASTNode +{ +public: + ExprConstASTNode(ExprASTNode * expr) : ConstASTNode(), m_expr(expr) {} + ExprConstASTNode(const ExprConstASTNode & other); + + virtual ASTNode * clone() const { return new ExprConstASTNode(*this); } + + virtual std::string nodeName() const { return "ExprConstASTNode"; } + + virtual void printTree(int indent) const; + + ExprASTNode * getExpr() { return m_expr; } + +protected: + smart_ptr<ExprASTNode> m_expr; +}; + +/*! + * + */ +class StringConstASTNode : public ConstASTNode +{ +public: + StringConstASTNode(std::string * value) : ConstASTNode(), m_value(value) {} + StringConstASTNode(const StringConstASTNode & other); + + virtual ASTNode * clone() const { return new StringConstASTNode(*this); } + + virtual std::string nodeName() const { return "StringConstASTNode"; } + + virtual void printTree(int indent) const; + + std::string * getString() { return m_value; } + +protected: + smart_ptr<std::string> m_value; +}; + +/*! + * + */ +class BlobConstASTNode : public ConstASTNode +{ +public: + BlobConstASTNode(Blob * value) : ConstASTNode(), m_blob(value) {} + BlobConstASTNode(const BlobConstASTNode & other); + + virtual ASTNode * clone() const { return new BlobConstASTNode(*this); } + + virtual std::string nodeName() const { return "BlobConstASTNode"; } + + virtual void printTree(int indent) const; + + Blob * getBlob() { return m_blob; } + +protected: + smart_ptr<Blob> m_blob; +}; + +// Forward declaration. +struct hab_ivt; + +/*! + * \brief Node for a constant IVT structure as used by HAB4. + */ +class IVTConstASTNode : public ConstASTNode +{ +public: + IVTConstASTNode() : ConstASTNode(), m_fields() {} + IVTConstASTNode(const IVTConstASTNode & other); + + virtual ASTNode * clone() const { return new IVTConstASTNode(*this); } + + virtual std::string nodeName() const { return "IVTConstASTNode"; } + + virtual void printTree(int indent) const; + + void setFieldAssignments(ListASTNode * fields) { m_fields = fields; } + ListASTNode * getFieldAssignments() { return m_fields; } + +protected: + //! Fields of the IVT are set through assignment statements. + smart_ptr<ListASTNode> m_fields; +}; + +/*! + * + */ +class AssignmentASTNode : public ASTNode +{ +public: + AssignmentASTNode(std::string * ident, ASTNode * value) + : ASTNode(), m_ident(ident), m_value(value) + { + } + + AssignmentASTNode(const AssignmentASTNode & other); + + virtual ASTNode * clone() const { return new AssignmentASTNode(*this); } + + virtual std::string nodeName() const { return "AssignmentASTNode"; } + + virtual void printTree(int indent) const; + + inline std::string * getIdent() { return m_ident; } + inline ASTNode * getValue() { return m_value; } + +protected: + smart_ptr<std::string> m_ident; + smart_ptr<ASTNode> m_value; +}; + +/*! + * Base class for PathSourceDefASTNode and ExternSourceDefASTNode. + */ +class SourceDefASTNode : public ASTNode +{ +public: + SourceDefASTNode(std::string * name) : m_name(name) {} + SourceDefASTNode(const SourceDefASTNode & other); + + inline std::string * getName() { return m_name; } + + inline void setAttributes(ListASTNode * attributes) { m_attributes = attributes; } + inline ListASTNode * getAttributes() { return m_attributes; } + +protected: + smart_ptr<std::string> m_name; + smart_ptr<ListASTNode> m_attributes; +}; + +/*! + * + */ +class PathSourceDefASTNode : public SourceDefASTNode +{ +public: + PathSourceDefASTNode(std::string * name, std::string * path) + : SourceDefASTNode(name), m_path(path) + { + } + + PathSourceDefASTNode(const PathSourceDefASTNode & other); + + virtual PathSourceDefASTNode * clone() const { return new PathSourceDefASTNode(*this); } + + virtual std::string nodeName() const { return "PathSourceDefASTNode"; } + + virtual void printTree(int indent) const; + + std::string * getPath() { return m_path; } + +protected: + smart_ptr<std::string> m_path; +}; + +/*! + * + */ +class ExternSourceDefASTNode : public SourceDefASTNode +{ +public: + ExternSourceDefASTNode(std::string * name, ExprASTNode * expr) + : SourceDefASTNode(name), m_expr(expr) + { + } + + ExternSourceDefASTNode(const ExternSourceDefASTNode & other); + + virtual ASTNode * clone() const { return new ExternSourceDefASTNode(*this); } + + virtual std::string nodeName() const { return "ExternSourceDefASTNode"; } + + virtual void printTree(int indent) const; + + ExprASTNode * getSourceNumberExpr() { return m_expr; } + +protected: + smart_ptr<ExprASTNode> m_expr; +}; + +/*! + * + */ +class SectionContentsASTNode : public ASTNode +{ +public: + SectionContentsASTNode() : m_sectionExpr() {} + SectionContentsASTNode(ExprASTNode * section) : m_sectionExpr(section) {} + SectionContentsASTNode(const SectionContentsASTNode & other); + + virtual ASTNode * clone() const { return new SectionContentsASTNode(*this); } + + virtual std::string nodeName() const { return "SectionContentsASTNode"; } + + virtual void printTree(int indent) const; + + inline void setSectionNumberExpr(ExprASTNode * section) + { + m_sectionExpr = section; + } + + inline ExprASTNode * getSectionNumberExpr() + { + return m_sectionExpr; + } + + inline void setOptions(ListASTNode * options) + { + m_options = options; + } + + inline ListASTNode * getOptions() + { + return m_options; + } + +protected: + smart_ptr<ExprASTNode> m_sectionExpr; + smart_ptr<ListASTNode> m_options; +}; + +/*! + * @brief Node representing a raw binary section definition. + */ +class DataSectionContentsASTNode : public SectionContentsASTNode +{ +public: + DataSectionContentsASTNode(ASTNode * contents) + : SectionContentsASTNode(), m_contents(contents) + { + } + + DataSectionContentsASTNode(const DataSectionContentsASTNode & other); + + virtual ASTNode * clone() const { return new DataSectionContentsASTNode(*this); } + + virtual std::string nodeName() const { return "DataSectionContentsASTNode"; } + + virtual void printTree(int indent) const; + + ASTNode * getContents() { return m_contents; } + +protected: + smart_ptr<ASTNode> m_contents; +}; + +/*! + * + */ +class BootableSectionContentsASTNode : public SectionContentsASTNode +{ +public: + BootableSectionContentsASTNode(ListASTNode * statements) + : SectionContentsASTNode(), m_statements(statements) + { + } + + BootableSectionContentsASTNode(const BootableSectionContentsASTNode & other); + + virtual ASTNode * clone() const { return new BootableSectionContentsASTNode(*this); } + + virtual std::string nodeName() const { return "BootableSectionContentsASTNode"; } + + virtual void printTree(int indent) const; + + ListASTNode * getStatements() { return m_statements; } + +protected: + smart_ptr<ListASTNode> m_statements; +}; + +/*! + * + */ +class StatementASTNode : public ASTNode +{ +public: + StatementASTNode() : ASTNode() {} + StatementASTNode(const StatementASTNode & other) : ASTNode(other) {} + +protected: +}; + +/*! + * + */ +class IfStatementASTNode : public StatementASTNode +{ +public: + IfStatementASTNode() : StatementASTNode(), m_ifStatements(), m_nextIf(), m_elseStatements() {} + IfStatementASTNode(const IfStatementASTNode & other); + + virtual ASTNode * clone() const { return new IfStatementASTNode(*this); } + + void setConditionExpr(ExprASTNode * expr) { m_conditionExpr = expr; } + ExprASTNode * getConditionExpr() { return m_conditionExpr; } + + void setIfStatements(ListASTNode * statements) { m_ifStatements = statements; } + ListASTNode * getIfStatements() { return m_ifStatements; } + + void setNextIf(IfStatementASTNode * nextIf) { m_nextIf = nextIf; } + IfStatementASTNode * getNextIf() { return m_nextIf; } + + void setElseStatements(ListASTNode * statements) { m_elseStatements = statements; } + ListASTNode * getElseStatements() { return m_elseStatements; } + +protected: + smart_ptr<ExprASTNode> m_conditionExpr; //!< Boolean expression. + smart_ptr<ListASTNode> m_ifStatements; //!< List of "if" section statements. + smart_ptr<IfStatementASTNode> m_nextIf; //!< Link to next "else if". If this is non-NULL then #m_elseStatements must be NULL and vice-versa. + smart_ptr<ListASTNode> m_elseStatements; //!< Statements for the "else" part of the statements. +}; + +/*! + * \brief Statement to insert a ROM_MODE_CMD command. + */ +class ModeStatementASTNode : public StatementASTNode +{ +public: + ModeStatementASTNode() : StatementASTNode(), m_modeExpr() {} + ModeStatementASTNode(ExprASTNode * modeExpr) : StatementASTNode(), m_modeExpr(modeExpr) {} + ModeStatementASTNode(const ModeStatementASTNode & other); + + virtual ASTNode * clone() const { return new ModeStatementASTNode(*this); } + + virtual std::string nodeName() const { return "ModeStatementASTNode"; } + + virtual void printTree(int indent) const; + + inline void setModeExpr(ExprASTNode * modeExpr) { m_modeExpr = modeExpr; } + inline ExprASTNode * getModeExpr() { return m_modeExpr; } + +protected: + smart_ptr<ExprASTNode> m_modeExpr; //!< Expression that evaluates to the new boot mode. +}; + +/*! + * \brief Statement to print a message to the elftosb user. + */ +class MessageStatementASTNode : public StatementASTNode +{ +public: + enum _message_type + { + kInfo, //!< Prints an informational messag to the user. + kWarning, //!< Prints a warning to the user. + kError //!< Throws an error exception. + }; + + typedef enum _message_type message_type_t; + +public: + MessageStatementASTNode(message_type_t messageType, std::string * message) : StatementASTNode(), m_type(messageType), m_message(message) {} + MessageStatementASTNode(const MessageStatementASTNode & other); + + virtual ASTNode * clone() const { return new MessageStatementASTNode(*this); } + + virtual std::string nodeName() const { return "MessageStatementASTNode"; } + + virtual void printTree(int indent) const; + + inline message_type_t getType() { return m_type; } + inline std::string * getMessage() { return m_message; } + + const char * getTypeName() const; + +protected: + message_type_t m_type; + smart_ptr<std::string> m_message; //!< Message to report. +}; + +/*! + * \brief AST node for a load statement. + */ +class LoadStatementASTNode : public StatementASTNode +{ +public: + LoadStatementASTNode() + : StatementASTNode(), m_data(), m_target(), m_isDCDLoad(false) + { + } + + LoadStatementASTNode(ASTNode * data, ASTNode * target) + : StatementASTNode(), m_data(data), m_target(), m_isDCDLoad(false) + { + } + + LoadStatementASTNode(const LoadStatementASTNode & other); + + virtual ASTNode * clone() const { return new LoadStatementASTNode(*this); } + + virtual std::string nodeName() const { return "LoadStatementASTNode"; } + + virtual void printTree(int indent) const; + + inline void setData(ASTNode * data) { m_data = data; } + inline ASTNode * getData() { return m_data; } + + inline void setTarget(ASTNode * target) { m_target = target; } + inline ASTNode * getTarget() { return m_target; } + + inline void setDCDLoad(bool isDCD) { m_isDCDLoad = isDCD; } + inline bool isDCDLoad() const { return m_isDCDLoad; } + +protected: + smart_ptr<ASTNode> m_data; + smart_ptr<ASTNode> m_target; + bool m_isDCDLoad; +}; + +/*! + * \brief AST node for a call statement. + */ +class CallStatementASTNode : public StatementASTNode +{ +public: + //! Possible sub-types of call statements. + typedef enum { + kCallType, + kJumpType + } call_type_t; + +public: + CallStatementASTNode(call_type_t callType=kCallType) + : StatementASTNode(), m_type(callType), m_target(), m_arg(), m_isHAB(false) + { + } + + CallStatementASTNode(call_type_t callType, ASTNode * target, ASTNode * arg) + : StatementASTNode(), m_type(callType), m_target(target), m_arg(arg), m_isHAB(false) + { + } + + CallStatementASTNode(const CallStatementASTNode & other); + + virtual ASTNode * clone() const { return new CallStatementASTNode(*this); } + + virtual std::string nodeName() const { return "CallStatementASTNode"; } + + virtual void printTree(int indent) const; + + inline void setCallType(call_type_t callType) { m_type = callType; } + inline call_type_t getCallType() { return m_type; } + + inline void setTarget(ASTNode * target) { m_target = target; } + inline ASTNode * getTarget() { return m_target; } + + inline void setArgument(ASTNode * arg) { m_arg = arg; } + inline ASTNode * getArgument() { return m_arg; } + + inline void setIsHAB(bool isHAB) { m_isHAB = isHAB; } + inline bool isHAB() const { return m_isHAB; } + +protected: + call_type_t m_type; + smart_ptr<ASTNode> m_target; //!< This becomes the IVT address in HAB mode. + smart_ptr<ASTNode> m_arg; + bool m_isHAB; +}; + +/*! + * + */ +class SourceASTNode : public ASTNode +{ +public: + SourceASTNode(std::string * name) : ASTNode(), m_name(name) {} + SourceASTNode(const SourceASTNode & other); + + virtual ASTNode * clone() const { return new SourceASTNode(*this); } + + virtual std::string nodeName() const { return "SourceASTNode"; } + + virtual void printTree(int indent) const; + + inline std::string * getSourceName() { return m_name; } + +protected: + smart_ptr<std::string> m_name; +}; + +/*! + * \brief List of section matches for a particular source name. + */ +class SectionMatchListASTNode : public ASTNode +{ +public: + SectionMatchListASTNode(ListASTNode * sections) + : ASTNode(), m_sections(sections), m_source() + { + } + + SectionMatchListASTNode(ListASTNode * sections, std::string * source) + : ASTNode(), m_sections(sections), m_source(source) + { + } + + SectionMatchListASTNode(const SectionMatchListASTNode & other); + + virtual ASTNode * clone() const { return new SectionMatchListASTNode(*this); } + + virtual std::string nodeName() const { return "SectionMatchListASTNode"; } + + virtual void printTree(int indent) const; + + inline ListASTNode * getSections() { return m_sections; } + inline std::string * getSourceName() { return m_source; } + +protected: + smart_ptr<ListASTNode> m_sections; + smart_ptr<std::string> m_source; +}; + +/*! + * \brief AST node for a section glob. + * + * Can be assigned an include or exclude action for when this node is part of a + * SectionMatchListASTNode. + */ +class SectionASTNode : public ASTNode +{ +public: + //! Possible actions for a section match list. + typedef enum + { + kInclude, //!< Include sections matched by this node. + kExclude //!< Exclude sections matched by this node. + } match_action_t; + +public: + SectionASTNode(std::string * name) + : ASTNode(), m_action(kInclude), m_name(name), m_source() + { + } + + SectionASTNode(std::string * name, match_action_t action) + : ASTNode(), m_action(action), m_name(name), m_source() + { + } + + SectionASTNode(std::string * name, std::string * source) + : ASTNode(), m_action(kInclude), m_name(name), m_source(source) + { + } + + SectionASTNode(const SectionASTNode & other); + + virtual ASTNode * clone() const { return new SectionASTNode(*this); } + + virtual std::string nodeName() const { return "SectionASTNode"; } + + virtual void printTree(int indent) const; + + inline match_action_t getAction() { return m_action; } + inline std::string * getSectionName() { return m_name; } + inline std::string * getSourceName() { return m_source; } + +protected: + match_action_t m_action; + smart_ptr<std::string> m_name; + smart_ptr<std::string> m_source; +}; + +/*! + * + */ +class SymbolASTNode : public ASTNode +{ +public: + SymbolASTNode() + : ASTNode(), m_symbol(), m_source() + { + } + + SymbolASTNode(std::string * symbol, std::string * source=0) + : ASTNode(), m_symbol(symbol), m_source(source) + { + } + + SymbolASTNode(const SymbolASTNode & other); + + virtual ASTNode * clone() const { return new SymbolASTNode(*this); } + + virtual std::string nodeName() const { return "SymbolASTNode"; } + + virtual void printTree(int indent) const; + + inline void setSymbolName(std::string * symbol) { m_symbol = symbol; } + inline std::string * getSymbolName() { return m_symbol; } + + inline void setSource(std::string * source) { m_source = source; } + inline std::string * getSource() { return m_source; } + +protected: + smart_ptr<std::string> m_symbol; //!< Required. + smart_ptr<std::string> m_source; //!< Optional, may be NULL; +}; + +/*! + * If the end of the range is NULL, then only a single address was specified. + */ +class AddressRangeASTNode : public ASTNode +{ +public: + AddressRangeASTNode() + : ASTNode(), m_begin(), m_end() + { + } + + AddressRangeASTNode(ASTNode * begin, ASTNode * end) + : ASTNode(), m_begin(begin), m_end(end) + { + } + + AddressRangeASTNode(const AddressRangeASTNode & other); + + virtual ASTNode * clone() const { return new AddressRangeASTNode(*this); } + + virtual std::string nodeName() const { return "AddressRangeASTNode"; } + + virtual void printTree(int indent) const; + + inline void setBegin(ASTNode * begin) { m_begin = begin; } + inline ASTNode * getBegin() { return m_begin; } + + inline void setEnd(ASTNode * end) { m_end = end; } + inline ASTNode * getEnd() { return m_end; } + +protected: + smart_ptr<ASTNode> m_begin; + smart_ptr<ASTNode> m_end; +}; + +/*! + * + */ +class NaturalLocationASTNode : public ASTNode +{ +public: + NaturalLocationASTNode() + : ASTNode() + { + } + + NaturalLocationASTNode(const NaturalLocationASTNode & other) + : ASTNode(other) + { + } + + virtual ASTNode * clone() const { return new NaturalLocationASTNode(*this); } + + virtual std::string nodeName() const { return "NaturalLocationASTNode"; } +}; + +/*! + * + */ +class FromStatementASTNode : public StatementASTNode +{ +public: + FromStatementASTNode() : StatementASTNode() {} + FromStatementASTNode(std::string * source, ListASTNode * statements); + FromStatementASTNode(const FromStatementASTNode & other); + + virtual ASTNode * clone() const { return new FromStatementASTNode(*this); } + + virtual std::string nodeName() const { return "FromStatementASTNode"; } + + virtual void printTree(int indent) const; + + inline void setSourceName(std::string * source) { m_source = source; } + inline std::string * getSourceName() { return m_source; } + + inline void setStatements(ListASTNode * statements) { m_statements = statements; } + inline ListASTNode * getStatements() { return m_statements; } + +protected: + smart_ptr<std::string> m_source; + smart_ptr<ListASTNode> m_statements; +}; + +}; // namespace elftosb + +#endif // _ElftosbAST_h_ diff --git a/elftosb2/ElftosbErrors.h b/elftosb2/ElftosbErrors.h new file mode 100644 index 0000000..abb546a --- /dev/null +++ b/elftosb2/ElftosbErrors.h @@ -0,0 +1,29 @@ +/* + * File: ConversionController.h + * + * Copyright (c) Freescale Semiconductor, Inc. All rights reserved. + * See included license file for license details. + */ +#if !defined(_ElftosbErrors_h_) +#define _ElftosbErrors_h_ + +#include <string> +#include <stdexcept> + +namespace elftosb +{ + +/*! + * \brief A semantic error discovered while processing the command file AST. + */ +class semantic_error : public std::runtime_error +{ +public: + explicit semantic_error(const std::string & msg) + : std::runtime_error(msg) + {} +}; + +}; // namespace elftosb + +#endif // _ElftosbErrors_h_ diff --git a/elftosb2/ElftosbLexer.cpp b/elftosb2/ElftosbLexer.cpp new file mode 100644 index 0000000..b1ba327 --- /dev/null +++ b/elftosb2/ElftosbLexer.cpp @@ -0,0 +1,149 @@ +/* + * File: ElftosbLexer.cpp + * + * Copyright (c) Freescale Semiconductor, Inc. All rights reserved. + * See included license file for license details. + */ +#include "ElftosbLexer.h" +#include <algorithm> +#include "HexValues.h" + +using namespace elftosb; + +ElftosbLexer::ElftosbLexer(istream & inputStream) +: yyFlexLexer(&inputStream), m_line(1), m_blob(0), m_blobFirstLine(0) +{ +} + +void ElftosbLexer::getSymbolValue(YYSTYPE * value) +{ + if (!value) + { + return; + } + *value = m_symbolValue; +} + +void ElftosbLexer::addSourceName(std::string * ident) +{ + m_sources.push_back(*ident); +} + +bool ElftosbLexer::isSourceName(std::string * ident) +{ + string_vector_t::iterator it = find(m_sources.begin(), m_sources.end(), *ident); + return it != m_sources.end(); +} + +void ElftosbLexer::LexerError(const char * msg) +{ + throw elftosb::lexical_error(msg); +} + +//! Reads the \a in string and writes to the \a out string. These strings can be the same +//! string since the read head is always in front of the write head. +//! +//! \param[in] in Input string containing C-style escape sequences. +//! \param[out] out Output string. All escape sequences in the input string have been converted +//! to the actual characters. May point to the same string as \a in. +//! \return The length of the resulting \a out string. This length is necessary because +//! the string may have contained escape sequences that inserted null characters. +int ElftosbLexer::processStringEscapes(const char * in, char * out) +{ + int count = 0; + while (*in) + { + switch (*in) + { + case '\\': + { + // start of an escape sequence + char c = *++in; + switch (c) + { + case 0: // end of the string, bail + break; + case 'x': + { + // start of a hex char escape sequence + + // read high and low nibbles, checking for end of string + char hi = *++in; + if (hi == 0) break; + char lo = *++in; + if (lo == 0) break; + + if (isHexDigit(hi) && isHexDigit(lo)) + { + if (hi >= '0' && hi <= '9') + c = (hi - '0') << 4; + else if (hi >= 'A' && hi <= 'F') + c = (hi - 'A' + 10) << 4; + else if (hi >= 'a' && hi <= 'f') + c = (hi - 'a' + 10) << 4; + + if (lo >= '0' && lo <= '9') + c |= lo - '0'; + else if (lo >= 'A' && lo <= 'F') + c |= lo - 'A' + 10; + else if (lo >= 'a' && lo <= 'f') + c |= lo - 'a' + 10; + + *out++ = c; + count++; + } + else + { + // not hex digits, the \x must have wanted an 'x' char + *out++ = 'x'; + *out++ = hi; + *out++ = lo; + count += 3; + } + break; + } + case 'n': + *out++ = '\n'; + count++; + break; + case 't': + *out++ = '\t'; + count++; + break; + case 'r': + *out++ = '\r'; + count++; + break; + case 'b': + *out++ = '\b'; + count++; + break; + case 'f': + *out++ = '\f'; + count++; + break; + case '0': + *out++ = '\0'; + count++; + break; + default: + *out++ = c; + count++; + break; + } + break; + } + + default: + // copy all other chars directly + *out++ = *in++; + count++; + } + } + + // place terminating null char on output + *out = 0; + return count; +} + + diff --git a/elftosb2/ElftosbLexer.h b/elftosb2/ElftosbLexer.h new file mode 100644 index 0000000..04a16f9 --- /dev/null +++ b/elftosb2/ElftosbLexer.h @@ -0,0 +1,97 @@ +/* + * File: ElftosbLexer.h + * + * Copyright (c) Freescale Semiconductor, Inc. All rights reserved. + * See included license file for license details. + */ + +// This header just wraps the standard flex C++ header to make it easier to include +// without having to worry about redefinitions of the class name every time. + +#if !defined(_ElftosbLexer_h_) +#define _ElftosbLexer_h_ + +#include "ElftosbAST.h" +#include "FlexLexer.h" +#include "elftosb_parser.tab.hpp" +#include <vector> +#include <string> +#include <stdexcept> +#include "Blob.h" + +using namespace std; + +namespace elftosb +{ + +/*! + * \brief Exception class for syntax errors. + */ +class syntax_error : public std::runtime_error +{ +public: + explicit syntax_error(const std::string & __arg) : std::runtime_error(__arg) {} +}; + +/*! + * \brief Exception class for lexical errors. + */ +class lexical_error : public std::runtime_error +{ +public: + explicit lexical_error(const std::string & __arg) : std::runtime_error(__arg) {} +}; + +/*! + * \brief Lexical scanner class for elftosb command files. + * + * This class is a subclass of the standard C++ lexer class produced by + * Flex. It's primary purpose is to provide a clean way to report values + * for symbols, without using the yylval global. This is necessary because + * the parser produced by Bison is a "pure" parser. + * + * In addition, this class manages a list of source names generated by + * parsing. The lexer uses this list to determine if an identifier is + * a source name or a constant identifier. + */ +class ElftosbLexer : public yyFlexLexer +{ +public: + //! \brief Constructor. + ElftosbLexer(istream & inputStream); + + //! \brief Lexer interface. Returns one token. + virtual int yylex(); + + //! \brief Returns the value for the most recently produced token in \a value. + virtual void getSymbolValue(YYSTYPE * value); + + //! \brief Returns the current token's location in \a loc. + inline token_loc_t & getLocation() { return m_location; } + + //! \name Source names + //@{ + void addSourceName(std::string * ident); + bool isSourceName(std::string * ident); + //@} + +protected: + YYSTYPE m_symbolValue; //!< Value for the current token. + int m_line; //!< Current line number. + token_loc_t m_location; //!< Location for the current token. + Blob * m_blob; //!< The binary object value as its being constructed. + int m_blobFirstLine; //!< Line number for the first character of a blob. + + typedef std::vector<std::string> string_vector_t; + string_vector_t m_sources; //!< Vector of source identifiers; + + //! \brief Throw an elftosb::lexical_error exception. + virtual void LexerError(const char * msg); + + //! \brief Process a string containing escape sequences. + int processStringEscapes(const char * in, char * out); +}; + +}; // namespace elftosb + +#endif // _ElftosbLexer_h_ diff --git a/elftosb2/EncoreBootImageGenerator.cpp b/elftosb2/EncoreBootImageGenerator.cpp new file mode 100644 index 0000000..9bb65c2 --- /dev/null +++ b/elftosb2/EncoreBootImageGenerator.cpp @@ -0,0 +1,297 @@ +/* + * File: EncoreBootImageGenerator.cpp + * + * Copyright (c) Freescale Semiconductor, Inc. All rights reserved. + * See included license file for license details. + */ + +#include "EncoreBootImageGenerator.h" +#include "Logging.h" + +#define kFlagsOption "flags" +#define kSectionFlagsOption "sectionFlags" +#define kProductVersionOption "productVersion" +#define kComponentVersionOption "componentVersion" +#define kAlignmentOption "alignment" +#define kCleartextOption "cleartext" + +using namespace elftosb; + +BootImage * EncoreBootImageGenerator::generate() +{ + EncoreBootImage * image = new EncoreBootImage(); + + // process each output section + section_vector_t::iterator it = m_sections.begin(); + for (; it != m_sections.end(); ++it) + { + OutputSection * section = *it; + + OperationSequenceSection * opSection = dynamic_cast<OperationSequenceSection*>(section); + if (opSection) + { + processOperationSection(opSection, image); + continue; + } + + BinaryDataSection * dataSection = dynamic_cast<BinaryDataSection*>(section); + if (dataSection) + { + processDataSection(dataSection, image); + continue; + } + + Log::log(Logger::WARNING, "warning: unexpected output section type\n"); + } + + // handle global options that affect the image + processOptions(image); + + return image; +} + +void EncoreBootImageGenerator::processOptions(EncoreBootImage * image) +{ + // bail if no option context was set + if (!m_options) + { + return; + } + + if (m_options->hasOption(kFlagsOption)) + { + const IntegerValue * intValue = dynamic_cast<const IntegerValue *>(m_options->getOption(kFlagsOption)); + if (intValue) + { + image->setFlags(intValue->getValue()); + } + else + { + Log::log(Logger::WARNING, "warning: flags option is an unexpected type\n"); + } + } + + // handle common options + processVersionOptions(image); + processDriveTagOption(image); +} + +void EncoreBootImageGenerator::processSectionOptions(EncoreBootImage::Section * imageSection, OutputSection * modelSection) +{ + // Get options context for this output section. + const OptionContext * context = modelSection->getOptions(); + if (!context) + { + return; + } + + // Check for and handle "sectionFlags" option. + if (context->hasOption(kSectionFlagsOption)) + { + const Value * value = context->getOption(kSectionFlagsOption); + const IntegerValue * intValue = dynamic_cast<const IntegerValue *>(value); + if (intValue) + { + // set explicit flags for this section + imageSection->setFlags(intValue->getValue()); + } + else + { + Log::log(Logger::WARNING, "warning: sectionFlags option is an unexpected type\n"); + } + } + + // Check for and handle "alignment" option. + if (context->hasOption(kAlignmentOption)) + { + const Value * value = context->getOption(kAlignmentOption); + const IntegerValue * intValue = dynamic_cast<const IntegerValue *>(value); + if (intValue) + { + // verify alignment value + if (intValue->getValue() < EncoreBootImage::BOOT_IMAGE_MINIMUM_SECTION_ALIGNMENT) + { + Log::log(Logger::WARNING, "warning: alignment option value must be 16 or greater\n"); + } + + imageSection->setAlignment(intValue->getValue()); + } + else + { + Log::log(Logger::WARNING, "warning: alignment option is an unexpected type\n"); + } + } + + // Check for and handle "cleartext" option. + if (context->hasOption(kCleartextOption)) + { + const Value * value = context->getOption(kCleartextOption); + const IntegerValue * intValue = dynamic_cast<const IntegerValue *>(value); + if (intValue) + { + bool leaveUnencrypted = intValue->getValue() != 0; + imageSection->setLeaveUnencrypted(leaveUnencrypted); + } + else + { + Log::log(Logger::WARNING, "warning: cleartext option is an unexpected type\n"); + } + } +} + +void EncoreBootImageGenerator::processOperationSection(OperationSequenceSection * section, EncoreBootImage * image) +{ + EncoreBootImage::BootSection * newSection = new EncoreBootImage::BootSection(section->getIdentifier()); + + OperationSequence & sequence = section->getSequence(); + OperationSequence::iterator_t it = sequence.begin(); + for (; it != sequence.end(); ++it) + { + Operation * op = *it; + + LoadOperation * loadOp = dynamic_cast<LoadOperation*>(op); + if (loadOp) + { + processLoadOperation(loadOp, newSection); + continue; + } + + ExecuteOperation * execOp = dynamic_cast<ExecuteOperation*>(op); + if (execOp) + { + processExecuteOperation(execOp, newSection); + continue; + } + + BootModeOperation * modeOp = dynamic_cast<BootModeOperation*>(op); + if (modeOp) + { + processBootModeOperation(modeOp, newSection); + continue; + } + + Log::log(Logger::WARNING, "warning: unexpected operation type\n"); + } + + // Deal with options that apply to sections. + processSectionOptions(newSection, section); + + // add the boot section to the image + image->addSection(newSection); +} + +void EncoreBootImageGenerator::processLoadOperation(LoadOperation * op, EncoreBootImage::BootSection * section) +{ + DataSource * source = op->getSource(); + DataTarget * target = op->getTarget(); + + // other sources get handled the same way + unsigned segmentCount = source->getSegmentCount(); + unsigned index = 0; + for (; index < segmentCount; ++index) + { + DataSource::Segment * segment = source->getSegmentAt(index); + DataTarget::AddressRange range = target->getRangeForSegment(*source, *segment); + unsigned rangeLength = range.m_end - range.m_begin; + + // handle a pattern segment as a special case to create a fill command + DataSource::PatternSegment * patternSegment = dynamic_cast<DataSource::PatternSegment*>(segment); + if (patternSegment) + { + SizedIntegerValue & pattern = patternSegment->getPattern(); + + EncoreBootImage::FillCommand * command = new EncoreBootImage::FillCommand(); + command->setAddress(range.m_begin); + command->setFillCount(rangeLength); + setFillPatternFromValue(*command, pattern); + + section->addCommand(command); + continue; + } + + // get the data from the segment + uint8_t * data = new uint8_t[rangeLength]; + segment->getData(0, rangeLength, data); + + // create the boot command + EncoreBootImage::LoadCommand * command = new EncoreBootImage::LoadCommand(); + command->setData(data, rangeLength); // Makes a copy of the data buffer. + command->setLoadAddress(range.m_begin); + command->setDCD(op->isDCDLoad()); + + section->addCommand(command); + + // Free the segment buffer. + delete [] data; + } +} + +void EncoreBootImageGenerator::setFillPatternFromValue(EncoreBootImage::FillCommand & command, SizedIntegerValue & pattern) +{ + uint32_t u32PatternValue = pattern.getValue() & pattern.getWordSizeMask(); + switch (pattern.getWordSize()) + { + case kWordSize: + { + command.setPattern(u32PatternValue); + break; + } + + case kHalfWordSize: + { + uint16_t u16PatternValue = static_cast<uint16_t>(u32PatternValue); + command.setPattern(u16PatternValue); + break; + } + + case kByteSize: + { + uint8_t u8PatternValue = static_cast<uint8_t>(u32PatternValue); + command.setPattern(u8PatternValue); + } + } +} + +void EncoreBootImageGenerator::processExecuteOperation(ExecuteOperation * op, EncoreBootImage::BootSection * section) +{ + DataTarget * target = op->getTarget(); + uint32_t arg = static_cast<uint32_t>(op->getArgument()); + + EncoreBootImage::JumpCommand * command; + switch (op->getExecuteType()) + { + case ExecuteOperation::kJump: + command = new EncoreBootImage::JumpCommand(); + break; + + case ExecuteOperation::kCall: + command = new EncoreBootImage::CallCommand(); + break; + } + + command->setAddress(target->getBeginAddress()); + command->setArgument(arg); + command->setIsHAB(op->isHAB()); + + section->addCommand(command); +} + +void EncoreBootImageGenerator::processBootModeOperation(BootModeOperation * op, EncoreBootImage::BootSection * section) +{ + EncoreBootImage::ModeCommand * command = new EncoreBootImage::ModeCommand(); + command->setBootMode(op->getBootMode()); + + section->addCommand(command); +} + +void EncoreBootImageGenerator::processDataSection(BinaryDataSection * section, EncoreBootImage * image) +{ + EncoreBootImage::DataSection * dataSection = new EncoreBootImage::DataSection(section->getIdentifier()); + dataSection->setData(section->getData(), section->getLength()); + + // Handle alignment option. + processSectionOptions(dataSection, section); + + image->addSection(dataSection); +} + diff --git a/elftosb2/EncoreBootImageGenerator.h b/elftosb2/EncoreBootImageGenerator.h new file mode 100644 index 0000000..f0466bb --- /dev/null +++ b/elftosb2/EncoreBootImageGenerator.h @@ -0,0 +1,57 @@ +/* + * File: EncoreBootImageGenerator.h + * + * Copyright (c) Freescale Semiconductor, Inc. All rights reserved. + * See included license file for license details. + */ +#if !defined(_EncoreBootImageGenerator_h_) +#define _EncoreBootImageGenerator_h_ + +#include "BootImageGenerator.h" +#include "EncoreBootImage.h" + +namespace elftosb +{ + +/*! + * \brief Generator for Encore boot images. + * + * Takes the abstract model of the output file and processes it into a + * concrete boot image for the STMP37xx. + * + * In order to enable full i.mx28 support, you must call the setSupportHAB() method and + * pass true. + */ +class EncoreBootImageGenerator : public BootImageGenerator +{ +public: + //! \brief Default constructor. + EncoreBootImageGenerator() : BootImageGenerator() {} + + //! \brief Builds the resulting boot image from previously added output sections. + virtual BootImage * generate(); + + //! \brief Enable or disable HAB support. + void setSupportHAB(bool supportHAB) { m_supportHAB = supportHAB; } + +protected: + + bool m_supportHAB; //!< True if HAB features are enabled. + + void processOptions(EncoreBootImage * image); + void processSectionOptions(EncoreBootImage::Section * imageSection, OutputSection * modelSection); + + void processOperationSection(OperationSequenceSection * section, EncoreBootImage * image); + void processDataSection(BinaryDataSection * section, EncoreBootImage * image); + + void processLoadOperation(LoadOperation * op, EncoreBootImage::BootSection * section); + void processExecuteOperation(ExecuteOperation * op, EncoreBootImage::BootSection * section); + void processBootModeOperation(BootModeOperation * op, EncoreBootImage::BootSection * section); + + void setFillPatternFromValue(EncoreBootImage::FillCommand & command, SizedIntegerValue & pattern); +}; + +}; // namespace elftosb + +#endif // _EncoreBootImageGenerator_h_ + diff --git a/elftosb2/FlexLexer.h b/elftosb2/FlexLexer.h new file mode 100644 index 0000000..8b26ef2 --- /dev/null +++ b/elftosb2/FlexLexer.h @@ -0,0 +1,208 @@ +// -*-C++-*- +// FlexLexer.h -- define interfaces for lexical analyzer classes generated +// by flex + +// Copyright (c) 1993 The Regents of the University of California. +// All rights reserved. +// +// This code is derived from software contributed to Berkeley by +// Kent Williams and Tom Epperly. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: + +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. + +// Neither the name of the University nor the names of its contributors +// may be used to endorse or promote products derived from this software +// without specific prior written permission. + +// THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR +// IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +// PURPOSE. + +// This file defines FlexLexer, an abstract class which specifies the +// external interface provided to flex C++ lexer objects, and yyFlexLexer, +// which defines a particular lexer class. +// +// If you want to create multiple lexer classes, you use the -P flag +// to rename each yyFlexLexer to some other xxFlexLexer. You then +// include <FlexLexer.h> in your other sources once per lexer class: +// +// #undef yyFlexLexer +// #define yyFlexLexer xxFlexLexer +// #include <FlexLexer.h> +// +// #undef yyFlexLexer +// #define yyFlexLexer zzFlexLexer +// #include <FlexLexer.h> +// ... + +#ifndef __FLEX_LEXER_H +// Never included before - need to define base class. +#define __FLEX_LEXER_H + +#include <iostream> +# ifndef FLEX_STD +# define FLEX_STD std:: +# endif + +extern "C++" { + +struct yy_buffer_state; +typedef int yy_state_type; + +class FlexLexer { +public: + virtual ~FlexLexer() { } + + const char* YYText() const { return yytext; } + int YYLeng() const { return yyleng; } + + virtual void + yy_switch_to_buffer( struct yy_buffer_state* new_buffer ) = 0; + virtual struct yy_buffer_state* + yy_create_buffer( FLEX_STD istream* s, int size ) = 0; + virtual void yy_delete_buffer( struct yy_buffer_state* b ) = 0; + virtual void yyrestart( FLEX_STD istream* s ) = 0; + + virtual int yylex() = 0; + + // Call yylex with new input/output sources. + int yylex( FLEX_STD istream* new_in, FLEX_STD ostream* new_out = 0 ) + { + switch_streams( new_in, new_out ); + return yylex(); + } + + // Switch to new input/output streams. A nil stream pointer + // indicates "keep the current one". + virtual void switch_streams( FLEX_STD istream* new_in = 0, + FLEX_STD ostream* new_out = 0 ) = 0; + + int lineno() const { return yylineno; } + + int debug() const { return yy_flex_debug; } + void set_debug( int flag ) { yy_flex_debug = flag; } + +protected: + char* yytext; + int yyleng; + int yylineno; // only maintained if you use %option yylineno + int yy_flex_debug; // only has effect with -d or "%option debug" +}; + +} +#endif // FLEXLEXER_H + +//#if defined(yyFlexLexer) || ! defined(yyFlexLexerOnce) +// had to disable the 'defined(yyFlexLexer)' part because it was causing duplicate class defs +#if ! defined(yyFlexLexerOnce) +// Either this is the first time through (yyFlexLexerOnce not defined), +// or this is a repeated include to define a different flavor of +// yyFlexLexer, as discussed in the flex manual. +#define yyFlexLexerOnce + +extern "C++" { + +class yyFlexLexer : public FlexLexer { +public: + // arg_yyin and arg_yyout default to the cin and cout, but we + // only make that assignment when initializing in yylex(). + yyFlexLexer( FLEX_STD istream* arg_yyin = 0, FLEX_STD ostream* arg_yyout = 0 ); + + virtual ~yyFlexLexer(); + + void yy_switch_to_buffer( struct yy_buffer_state* new_buffer ); + struct yy_buffer_state* yy_create_buffer( FLEX_STD istream* s, int size ); + void yy_delete_buffer( struct yy_buffer_state* b ); + void yyrestart( FLEX_STD istream* s ); + + void yypush_buffer_state( struct yy_buffer_state* new_buffer ); + void yypop_buffer_state(); + + virtual int yylex(); + virtual void switch_streams( FLEX_STD istream* new_in, FLEX_STD ostream* new_out = 0 ); + virtual int yywrap(); + +protected: + virtual int LexerInput( char* buf, int max_size ); + virtual void LexerOutput( const char* buf, int size ); + virtual void LexerError( const char* msg ); + + void yyunput( int c, char* buf_ptr ); + int yyinput(); + + void yy_load_buffer_state(); + void yy_init_buffer( struct yy_buffer_state* b, FLEX_STD istream* s ); + void yy_flush_buffer( struct yy_buffer_state* b ); + + int yy_start_stack_ptr; + int yy_start_stack_depth; + int* yy_start_stack; + + void yy_push_state( int new_state ); + void yy_pop_state(); + int yy_top_state(); + + yy_state_type yy_get_previous_state(); + yy_state_type yy_try_NUL_trans( yy_state_type current_state ); + int yy_get_next_buffer(); + + FLEX_STD istream* yyin; // input source for default LexerInput + FLEX_STD ostream* yyout; // output sink for default LexerOutput + + // yy_hold_char holds the character lost when yytext is formed. + char yy_hold_char; + + // Number of characters read into yy_ch_buf. + int yy_n_chars; + + // Points to current character in buffer. + char* yy_c_buf_p; + + int yy_init; // whether we need to initialize + int yy_start; // start state number + + // Flag which is used to allow yywrap()'s to do buffer switches + // instead of setting up a fresh yyin. A bit of a hack ... + int yy_did_buffer_switch_on_eof; + + + size_t yy_buffer_stack_top; /**< index of top of stack. */ + size_t yy_buffer_stack_max; /**< capacity of stack. */ + struct yy_buffer_state ** yy_buffer_stack; /**< Stack as an array. */ + void yyensure_buffer_stack(void); + + // The following are not always needed, but may be depending + // on use of certain flex features (like REJECT or yymore()). + + yy_state_type yy_last_accepting_state; + char* yy_last_accepting_cpos; + + yy_state_type* yy_state_buf; + yy_state_type* yy_state_ptr; + + char* yy_full_match; + int* yy_full_state; + int yy_full_lp; + + int yy_lp; + int yy_looking_for_trail_begin; + + int yy_more_flag; + int yy_more_len; + int yy_more_offset; + int yy_prev_more_offset; +}; + +} + +#endif // yyFlexLexer || ! yyFlexLexerOnce + diff --git a/elftosb2/elftosb.cpp b/elftosb2/elftosb.cpp new file mode 100644 index 0000000..f358bd9 --- /dev/null +++ b/elftosb2/elftosb.cpp @@ -0,0 +1,700 @@ +/* + * File: elftosb.cpp + * + * Copyright (c) Freescale Semiconductor, Inc. All rights reserved. + * See included license file for license details. + */ + +#include "stdafx.h" +#include <iostream> +#include <fstream> +#include <sstream> +#include <stdlib.h> +#include <stdexcept> +#include "ConversionController.h" +#include "options.h" +#include "Version.h" +#include "EncoreBootImage.h" +#include "smart_ptr.h" +#include "Logging.h" +#include "EncoreBootImageGenerator.h" +#include "SearchPath.h" +#include "format_string.h" + +//! An array of strings. +typedef std::vector<std::string> string_vector_t; + +//! The tool's name. +const char k_toolName[] = "elftosb"; + +//! Current version number for the tool. +const char k_version[] = "2.6.1"; + +//! Copyright string. +const char k_copyright[] = "Copyright (c) 2004-2010 Freescale Semiconductor, Inc.\nAll rights reserved."; + +static const char * k_optionsDefinition[] = { + "?|help", + "v|version", + "f:chip-family <family>", + "c:command <file>", + "o:output <file>", + "P:product <version>", + "C:component <version>", + "k:key <file>", + "z|zero-key", + "D:define <const>", + "O:option <option>", + "d|debug", + "q|quiet", + "V|verbose", + "p:search-path <path>", + NULL +}; + +//! Help string. +const char k_usageText[] = "\nOptions:\n\ + -?/--help Show this help\n\ + -v/--version Display tool version\n\ + -f/--chip-family <family> Select the chip family (default is 37xx)\n\ + -c/--command <file> Use this command file\n\ + -o/--output <file> Write output to this file\n\ + -p/--search-path <path> Add a search path used to find input files\n\ + -P/--product <version Set product version\n\ + -C/--component <version> Set component version\n\ + -k/--key <file> Add OTP key, enable encryption\n\ + -z/--zero-key Add default key of all zeroes\n\ + -D/--define <const>=<int> Define or override a constant value\n\ + -O/--option <name>=<value> Set or override a processing option\n\ + -d/--debug Enable debug output\n\ + -q/--quiet Output only warnings and errors\n\ + -V/--verbose Print extra detailed log information\n\n"; + +// prototypes +int main(int argc, char* argv[], char* envp[]); + +/*! + * \brief Class that encapsulates the elftosb tool. + * + * A single global logger instance is created during object construction. It is + * never freed because we need it up to the last possible minute, when an + * exception could be thrown. + */ +class elftosbTool +{ +protected: + //! Supported chip families. + enum chip_family_t + { + k37xxFamily, //!< 37xx series. + kMX28Family, //!< Catskills series. + }; + + /*! + * \brief A structure describing an entry in the table of chip family names. + */ + struct FamilyNameTableEntry + { + const char * const name; + chip_family_t family; + }; + + //! \brief Table that maps from family name strings to chip family constants. + static const FamilyNameTableEntry kFamilyNameTable[]; + + int m_argc; //!< Number of command line arguments. + char ** m_argv; //!< String value for each command line argument. + StdoutLogger * m_logger; //!< Singleton logger instance. + string_vector_t m_keyFilePaths; //!< Paths to OTP key files. + string_vector_t m_positionalArgs; //!< Arguments coming after explicit options. + bool m_isVerbose; //!< Whether the verbose flag was turned on. + bool m_useDefaultKey; //!< Include a default (zero) crypto key. + const char * m_commandFilePath; //!< Path to the elftosb command file. + const char * m_outputFilePath; //!< Path to the output .sb file. + const char * m_searchPath; //!< Optional search path for input files. + elftosb::version_t m_productVersion; //!< Product version specified on command line. + elftosb::version_t m_componentVersion; //!< Component version specified on command line. + bool m_productVersionSpecified; //!< True if the product version was specified on the command line. + bool m_componentVersionSpecified; //!< True if the component version was specified on the command line. + chip_family_t m_family; //!< Chip family that the output file is formatted for. + elftosb::ConversionController m_controller; //!< Our conversion controller instance. + +public: + /*! + * Constructor. + * + * Creates the singleton logger instance. + */ + elftosbTool(int argc, char * argv[]) + : m_argc(argc), + m_argv(argv), + m_logger(0), + m_keyFilePaths(), + m_positionalArgs(), + m_isVerbose(false), + m_useDefaultKey(false), + m_commandFilePath(NULL), + m_outputFilePath(NULL), + m_searchPath(NULL), + m_productVersion(), + m_componentVersion(), + m_productVersionSpecified(false), + m_componentVersionSpecified(false), + m_family(k37xxFamily), + m_controller() + { + // create logger instance + m_logger = new StdoutLogger(); + m_logger->setFilterLevel(Logger::INFO); + Log::setLogger(m_logger); + } + + /*! + * Destructor. + */ + ~elftosbTool() + { + } + + /*! + * \brief Searches the family name table. + * + * \retval true The \a name was found in the table, and \a family is valid. + * \retval false No matching family name was found. The \a family argument is not modified. + */ + bool lookupFamilyName(const char * name, chip_family_t * family) + { + // Create a local read-write copy of the argument string. + std::string familyName(name); + + // Convert the argument string to lower case for case-insensitive comparison. + for (int n=0; n < familyName.length(); n++) + { + familyName[n] = tolower(familyName[n]); + } + + // Exit the loop if we hit the NULL terminator entry. + const FamilyNameTableEntry * entry = &kFamilyNameTable[0]; + for (; entry->name; entry++) + { + // Compare lowercased name with the table entry. + if (familyName == entry->name) + { + *family = entry->family; + return true; + } + } + + // Failed to find a matching name. + return false; + } + + /*! + * Reads the command line options passed into the constructor. + * + * This method can return a return code to its caller, which will cause the + * tool to exit immediately with that return code value. Normally, though, it + * will return -1 to signal that the tool should continue to execute and + * all options were processed successfully. + * + * The Options class is used to parse command line options. See + * #k_optionsDefinition for the list of options and #k_usageText for the + * descriptive help for each option. + * + * \retval -1 The options were processed successfully. Let the tool run normally. + * \return A zero or positive result is a return code value that should be + * returned from the tool as it exits immediately. + */ + int processOptions() + { + Options options(*m_argv, k_optionsDefinition); + OptArgvIter iter(--m_argc, ++m_argv); + + // process command line options + int optchar; + const char * optarg; + while (optchar = options(iter, optarg)) + { + switch (optchar) + { + case '?': + printUsage(options); + return 0; + + case 'v': + printf("%s %s\n%s\n", k_toolName, k_version, k_copyright); + return 0; + + case 'f': + if (!lookupFamilyName(optarg, &m_family)) + { + Log::log(Logger::ERROR, "error: unknown chip family '%s'\n", optarg); + printUsage(options); + return 0; + } + break; + + case 'c': + m_commandFilePath = optarg; + break; + + case 'o': + m_outputFilePath = optarg; + break; + + case 'P': + m_productVersion.set(optarg); + m_productVersionSpecified = true; + break; + + case 'C': + m_componentVersion.set(optarg); + m_componentVersionSpecified = true; + break; + + case 'k': + m_keyFilePaths.push_back(optarg); + break; + + case 'z': + m_useDefaultKey = true; + break; + + case 'D': + overrideVariable(optarg); + break; + + case 'O': + overrideOption(optarg); + break; + + case 'd': + Log::getLogger()->setFilterLevel(Logger::DEBUG); + break; + + case 'q': + Log::getLogger()->setFilterLevel(Logger::WARNING); + break; + + case 'V': + m_isVerbose = true; + break; + + case 'p': + { + std::string newSearchPath(optarg); + PathSearcher::getGlobalSearcher().addSearchPath(newSearchPath); + break; + } + + default: + Log::log(Logger::ERROR, "error: unrecognized option\n\n"); + printUsage(options); + return 0; + } + } + + // handle positional args + if (iter.index() < m_argc) + { + Log::SetOutputLevel leveler(Logger::DEBUG); + Log::log("positional args:\n"); + int i; + for (i = iter.index(); i < m_argc; ++i) + { + Log::log("%d: %s\n", i - iter.index(), m_argv[i]); + m_positionalArgs.push_back(m_argv[i]); + } + } + + // all is well + return -1; + } + + /*! + * Prints help for the tool. + */ + void printUsage(Options & options) + { + options.usage(std::cout, "files..."); + printf(k_usageText, k_toolName); + } + + /*! + * \brief Core of the tool. + * + * Calls processOptions() to handle command line options before performing the + * real work the tool does. + */ + int run() + { + try + { + // read command line options + int result; + if ((result = processOptions()) != -1) + { + return result; + } + + // set verbose logging + setVerboseLogging(); + + // check argument values + checkArguments(); + + // set up the controller + m_controller.setCommandFilePath(m_commandFilePath); + + // add external paths to controller + string_vector_t::iterator it = m_positionalArgs.begin(); + for (; it != m_positionalArgs.end(); ++it) + { + m_controller.addExternalFilePath(*it); + } + + // run conversion + convert(); + } + catch (std::exception & e) + { + Log::log(Logger::ERROR, "error: %s\n", e.what()); + return 1; + } + catch (...) + { + Log::log(Logger::ERROR, "error: unexpected exception\n"); + return 1; + } + + return 0; + } + + /*! + * \brief Validate arguments that can be checked. + * \exception std::runtime_error Thrown if an argument value fails to pass validation. + */ + void checkArguments() + { + if (m_commandFilePath == NULL) + { + throw std::runtime_error("no command file was specified"); + } + if (m_outputFilePath == NULL) + { + throw std::runtime_error("no output file was specified"); + } + } + + /*! + * \brief Turns on verbose logging. + */ + void setVerboseLogging() + { + if (m_isVerbose) + { + // verbose only affects the INFO and DEBUG filter levels + // if the user has selected quiet mode, it overrides verbose + switch (Log::getLogger()->getFilterLevel()) + { + case Logger::INFO: + Log::getLogger()->setFilterLevel(Logger::INFO2); + break; + case Logger::DEBUG: + Log::getLogger()->setFilterLevel(Logger::DEBUG2); + break; + } + } + } + + /*! + * \brief Returns the integer value for a string. + * + * Metric multiplier prefixes are supported. + */ + uint32_t parseIntValue(const char * value) + { + // Accept 'true'/'yes' and 'false'/'no' as integer values. + if ((strcmp(value, "true") == 0) || (strcmp(value, "yes") == 0)) + { + return 1; + } + else if ((strcmp(value, "false") == 0) || (strcmp(value, "no") == 0)) + { + return 0; + } + + uint32_t intValue = strtoul(value, NULL, 0); + unsigned multiplier; + switch (value[strlen(value) - 1]) + { + case 'G': + multiplier = 1024 * 1024 * 1024; + break; + case 'M': + multiplier = 1024 * 1024; + break; + case 'K': + multiplier = 1024; + break; + default: + multiplier = 1; + } + intValue *= multiplier; + return intValue; + } + + /*! + * \brief Parses the -D option to override a constant value. + */ + void overrideVariable(const char * optarg) + { + // split optarg into two strings + std::string constName(optarg); + int i; + for (i=0; i < strlen(optarg); ++i) + { + if (optarg[i] == '=') + { + constName.resize(i++); + break; + } + } + + uint32_t constValue = parseIntValue(&optarg[i]); + + elftosb::EvalContext & context = m_controller.getEvalContext(); + context.setVariable(constName, constValue); + context.lockVariable(constName); + } + + /*! + * \brief + */ + void overrideOption(const char * optarg) + { + // split optarg into two strings + std::string optionName(optarg); + int i; + for (i=0; i < strlen(optarg); ++i) + { + if (optarg[i] == '=') + { + optionName.resize(i++); + break; + } + } + + // handle quotes for option value + const char * valuePtr = &optarg[i]; + bool isString = false; + int len; + if (valuePtr[0] == '"') + { + // remember that the value is a string and get rid of the opening quote + isString = true; + valuePtr++; + + // remove trailing quote if present + len = strlen(valuePtr); + if (valuePtr[len] == '"') + { + len--; + } + } + + elftosb::Value * value; + if (isString) + { + std::string stringValue(valuePtr); + stringValue.resize(len); // remove trailing quote + value = new elftosb::StringValue(stringValue); + } + else + { + value = new elftosb::IntegerValue(parseIntValue(valuePtr)); + } + + // Set and lock the option in the controller + m_controller.setOption(optionName, value); + m_controller.lockOption(optionName); + } + + /*! + * \brief Do the conversion. + * \exception std::runtime_error This exception is thrown if the conversion controller does + * not produce a boot image, or if the output file cannot be opened. Other errors + * internal to the conversion controller may also produce this exception. + */ + void convert() + { + // create a generator for the chosen chip family + smart_ptr<elftosb::BootImageGenerator> generator; + switch (m_family) + { + case k37xxFamily: + generator = new elftosb::EncoreBootImageGenerator; + elftosb::g_enableHABSupport = false; + break; + + case kMX28Family: + generator = new elftosb::EncoreBootImageGenerator; + elftosb::g_enableHABSupport = true; + break; + } + + // process input and get a boot image + m_controller.run(); + smart_ptr<elftosb::BootImage> image = m_controller.generateOutput(generator); + if (!image) + { + throw std::runtime_error("failed to produce output!"); + } + + // set version numbers if they were provided on the command line + if (m_productVersionSpecified) + { + image->setProductVersion(m_productVersion); + } + if (m_componentVersionSpecified) + { + image->setComponentVersion(m_componentVersion); + } + + // special handling for each family + switch (m_family) + { + case k37xxFamily: + case kMX28Family: + { + // add OTP keys + elftosb::EncoreBootImage * encoreImage = dynamic_cast<elftosb::EncoreBootImage*>(image.get()); + if (encoreImage) + { + // add keys + addCryptoKeys(encoreImage); + + // print debug image + encoreImage->debugPrint(); + } + break; + } + } + + // write output + std::ofstream outputStream(m_outputFilePath, std::ios_base::binary | std::ios_base::out | std::ios_base::trunc); + if (outputStream.is_open()) + { + image->writeToStream(outputStream); + } + else + { + throw std::runtime_error(format_string("could not open output file %s", m_outputFilePath)); + } + } + + /*! + * \brief + */ + void addCryptoKeys(elftosb::EncoreBootImage * encoreImage) + { + string_vector_t::iterator it = m_keyFilePaths.begin(); + for (; it != m_keyFilePaths.end(); ++it) + { + std::string & keyPath = *it; + + std::string actualPath; + bool found = PathSearcher::getGlobalSearcher().search(keyPath, PathSearcher::kFindFile, true, actualPath); + if (!found) + { + throw std::runtime_error(format_string("unable to find key file %s\n", keyPath.c_str())); + } + + std::ifstream keyStream(actualPath.c_str(), std::ios_base::in); + if (!keyStream.is_open()) + { + throw std::runtime_error(format_string("unable to read key file %s\n", keyPath.c_str())); + } + keyStream.seekg(0); + + try + { + // read as many keys as possible from the stream + while (true) + { + AESKey<128> key(keyStream); + encoreImage->addKey(key); + + // dump key bytes + dumpKey(key); + } + } + catch (...) + { + // ignore the exception -- there are just no more keys in the stream + } + } + + // add the default key of all zero bytes if requested + if (m_useDefaultKey) + { + AESKey<128> defaultKey; + encoreImage->addKey(defaultKey); + } + } + + /*! + * \brief Write the value of each byte of the \a key to the log. + */ + void dumpKey(const AESKey<128> & key) + { + // dump key bytes + Log::log(Logger::DEBUG, "key bytes: "); + AESKey<128>::key_t the_key; + key.getKey(&the_key); + int q; + for (q=0; q<16; q++) + { + Log::log(Logger::DEBUG, "%02x ", the_key[q]); + } + Log::log(Logger::DEBUG, "\n"); + } + +}; + +const elftosbTool::FamilyNameTableEntry elftosbTool::kFamilyNameTable[] = + { + { "37xx", k37xxFamily }, + { "377x", k37xxFamily }, + { "378x", k37xxFamily }, + { "mx23", k37xxFamily }, + { "imx23", k37xxFamily }, + { "i.mx23", k37xxFamily }, + { "mx28", kMX28Family }, + { "imx28", kMX28Family }, + { "i.mx28", kMX28Family }, + + // Null terminator entry. + { NULL, k37xxFamily } + }; + +/*! + * Main application entry point. Creates an sbtool instance and lets it take over. + */ +int main(int argc, char* argv[], char* envp[]) +{ + try + { + return elftosbTool(argc, argv).run(); + } + catch (...) + { + Log::log(Logger::ERROR, "error: unexpected exception\n"); + return 1; + } + + return 0; +} + + + diff --git a/elftosb2/elftosb_lexer.cpp b/elftosb2/elftosb_lexer.cpp new file mode 100644 index 0000000..3b87842 --- /dev/null +++ b/elftosb2/elftosb_lexer.cpp @@ -0,0 +1,2241 @@ +#line 2 "/Users/creed/projects/fsl/fromsvr/elftosb/build/elftosb.build/Debug/elftosb.build/DerivedSources/elftosb_lexer.cpp" + +#line 4 "/Users/creed/projects/fsl/fromsvr/elftosb/build/elftosb.build/Debug/elftosb.build/DerivedSources/elftosb_lexer.cpp" + +#define YY_INT_ALIGNED short int + +/* A lexical scanner generated by flex */ + +#define FLEX_SCANNER +#define YY_FLEX_MAJOR_VERSION 2 +#define YY_FLEX_MINOR_VERSION 5 +#define YY_FLEX_SUBMINOR_VERSION 35 +#if YY_FLEX_SUBMINOR_VERSION > 0 +#define FLEX_BETA +#endif + + /* The c++ scanner is a mess. The FlexLexer.h header file relies on the + * following macro. This is required in order to pass the c++-multiple-scanners + * test in the regression suite. We get reports that it breaks inheritance. + * We will address this in a future release of flex, or omit the C++ scanner + * altogether. + */ + #define yyFlexLexer yyFlexLexer + +/* First, we deal with platform-specific or compiler-specific issues. */ + +/* begin standard C headers. */ + +/* end standard C headers. */ + +/* flex integer type definitions */ + +#ifndef FLEXINT_H +#define FLEXINT_H + +/* C99 systems have <inttypes.h>. Non-C99 systems may or may not. */ + +#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L + +/* C99 says to define __STDC_LIMIT_MACROS before including stdint.h, + * if you want the limit (max/min) macros for int types. + */ +#ifndef __STDC_LIMIT_MACROS +#define __STDC_LIMIT_MACROS 1 +#endif + +#include <inttypes.h> +typedef int8_t flex_int8_t; +typedef uint8_t flex_uint8_t; +typedef int16_t flex_int16_t; +typedef uint16_t flex_uint16_t; +typedef int32_t flex_int32_t; +typedef uint32_t flex_uint32_t; +#else +typedef signed char flex_int8_t; +typedef short int flex_int16_t; +typedef int flex_int32_t; +typedef unsigned char flex_uint8_t; +typedef unsigned short int flex_uint16_t; +typedef unsigned int flex_uint32_t; +#endif /* ! C99 */ + +/* Limits of integral types. */ +#ifndef INT8_MIN +#define INT8_MIN (-128) +#endif +#ifndef INT16_MIN +#define INT16_MIN (-32767-1) +#endif +#ifndef INT32_MIN +#define INT32_MIN (-2147483647-1) +#endif +#ifndef INT8_MAX +#define INT8_MAX (127) +#endif +#ifndef INT16_MAX +#define INT16_MAX (32767) +#endif +#ifndef INT32_MAX +#define INT32_MAX (2147483647) +#endif +#ifndef UINT8_MAX +#define UINT8_MAX (255U) +#endif +#ifndef UINT16_MAX +#define UINT16_MAX (65535U) +#endif +#ifndef UINT32_MAX +#define UINT32_MAX (4294967295U) +#endif + +#endif /* ! FLEXINT_H */ + +/* begin standard C++ headers. */ +#include <iostream> +#include <errno.h> +#include <cstdlib> +#include <cstring> +/* end standard C++ headers. */ + +#ifdef __cplusplus + +/* The "const" storage-class-modifier is valid. */ +#define YY_USE_CONST + +#else /* ! __cplusplus */ + +/* C99 requires __STDC__ to be defined as 1. */ +#if defined (__STDC__) + +#define YY_USE_CONST + +#endif /* defined (__STDC__) */ +#endif /* ! __cplusplus */ + +#ifdef YY_USE_CONST +#define yyconst const +#else +#define yyconst +#endif + +/* Returned upon end-of-file. */ +#define YY_NULL 0 + +/* Promotes a possibly negative, possibly signed char to an unsigned + * integer for use as an array index. If the signed char is negative, + * we want to instead treat it as an 8-bit unsigned char, hence the + * double cast. + */ +#define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c) + +/* Enter a start condition. This macro really ought to take a parameter, + * but we do it the disgusting crufty way forced on us by the ()-less + * definition of BEGIN. + */ +#define BEGIN (yy_start) = 1 + 2 * + +/* Translate the current start state into a value that can be later handed + * to BEGIN to return to the state. The YYSTATE alias is for lex + * compatibility. + */ +#define YY_START (((yy_start) - 1) / 2) +#define YYSTATE YY_START + +/* Action number for EOF rule of a given start state. */ +#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1) + +/* Special action meaning "start processing a new file". */ +#define YY_NEW_FILE yyrestart( yyin ) + +#define YY_END_OF_BUFFER_CHAR 0 + +/* Size of default input buffer. */ +#ifndef YY_BUF_SIZE +#define YY_BUF_SIZE 16384 +#endif + +/* The state buf must be large enough to hold one state per character in the main buffer. + */ +#define YY_STATE_BUF_SIZE ((YY_BUF_SIZE + 2) * sizeof(yy_state_type)) + +#ifndef YY_TYPEDEF_YY_BUFFER_STATE +#define YY_TYPEDEF_YY_BUFFER_STATE +typedef struct yy_buffer_state *YY_BUFFER_STATE; +#endif + +#ifndef YY_TYPEDEF_YY_SIZE_T +#define YY_TYPEDEF_YY_SIZE_T +typedef size_t yy_size_t; +#endif + +extern yy_size_t yyleng; + +#define EOB_ACT_CONTINUE_SCAN 0 +#define EOB_ACT_END_OF_FILE 1 +#define EOB_ACT_LAST_MATCH 2 + + /* Note: We specifically omit the test for yy_rule_can_match_eol because it requires + * access to the local variable yy_act. Since yyless() is a macro, it would break + * existing scanners that call yyless() from OUTSIDE yylex. + * One obvious solution it to make yy_act a global. I tried that, and saw + * a 5% performance hit in a non-yylineno scanner, because yy_act is + * normally declared as a register variable-- so it is not worth it. + */ + #define YY_LESS_LINENO(n) \ + do { \ + int yyl;\ + for ( yyl = n; yyl < yyleng; ++yyl )\ + if ( yytext[yyl] == '\n' )\ + --yylineno;\ + }while(0) + +/* Return all but the first "n" matched characters back to the input stream. */ +#define yyless(n) \ + do \ + { \ + /* Undo effects of setting up yytext. */ \ + int yyless_macro_arg = (n); \ + YY_LESS_LINENO(yyless_macro_arg);\ + *yy_cp = (yy_hold_char); \ + YY_RESTORE_YY_MORE_OFFSET \ + (yy_c_buf_p) = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \ + YY_DO_BEFORE_ACTION; /* set up yytext again */ \ + } \ + while ( 0 ) + +#define unput(c) yyunput( c, (yytext_ptr) ) + +#ifndef YY_STRUCT_YY_BUFFER_STATE +#define YY_STRUCT_YY_BUFFER_STATE +struct yy_buffer_state + { + + std::istream* yy_input_file; + + char *yy_ch_buf; /* input buffer */ + char *yy_buf_pos; /* current position in input buffer */ + + /* Size of input buffer in bytes, not including room for EOB + * characters. + */ + yy_size_t yy_buf_size; + + /* Number of characters read into yy_ch_buf, not including EOB + * characters. + */ + yy_size_t yy_n_chars; + + /* Whether we "own" the buffer - i.e., we know we created it, + * and can realloc() it to grow it, and should free() it to + * delete it. + */ + int yy_is_our_buffer; + + /* Whether this is an "interactive" input source; if so, and + * if we're using stdio for input, then we want to use getc() + * instead of fread(), to make sure we stop fetching input after + * each newline. + */ + int yy_is_interactive; + + /* Whether we're considered to be at the beginning of a line. + * If so, '^' rules will be active on the next match, otherwise + * not. + */ + int yy_at_bol; + + int yy_bs_lineno; /**< The line count. */ + int yy_bs_column; /**< The column count. */ + + /* Whether to try to fill the input buffer when we reach the + * end of it. + */ + int yy_fill_buffer; + + int yy_buffer_status; + +#define YY_BUFFER_NEW 0 +#define YY_BUFFER_NORMAL 1 + /* When an EOF's been seen but there's still some text to process + * then we mark the buffer as YY_EOF_PENDING, to indicate that we + * shouldn't try reading from the input source any more. We might + * still have a bunch of tokens to match, though, because of + * possible backing-up. + * + * When we actually see the EOF, we change the status to "new" + * (via yyrestart()), so that the user can continue scanning by + * just pointing yyin at a new input file. + */ +#define YY_BUFFER_EOF_PENDING 2 + + }; +#endif /* !YY_STRUCT_YY_BUFFER_STATE */ + +/* We provide macros for accessing buffer states in case in the + * future we want to put the buffer states in a more general + * "scanner state". + * + * Returns the top of the stack, or NULL. + */ +#define YY_CURRENT_BUFFER ( (yy_buffer_stack) \ + ? (yy_buffer_stack)[(yy_buffer_stack_top)] \ + : NULL) + +/* Same as previous macro, but useful when we know that the buffer stack is not + * NULL or when we need an lvalue. For internal use only. + */ +#define YY_CURRENT_BUFFER_LVALUE (yy_buffer_stack)[(yy_buffer_stack_top)] + +void *yyalloc (yy_size_t ); +void *yyrealloc (void *,yy_size_t ); +void yyfree (void * ); + +#define yy_new_buffer yy_create_buffer + +#define yy_set_interactive(is_interactive) \ + { \ + if ( ! YY_CURRENT_BUFFER ){ \ + yyensure_buffer_stack (); \ + YY_CURRENT_BUFFER_LVALUE = \ + yy_create_buffer( yyin, YY_BUF_SIZE ); \ + } \ + YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \ + } + +#define yy_set_bol(at_bol) \ + { \ + if ( ! YY_CURRENT_BUFFER ){\ + yyensure_buffer_stack (); \ + YY_CURRENT_BUFFER_LVALUE = \ + yy_create_buffer( yyin, YY_BUF_SIZE ); \ + } \ + YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \ + } + +#define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol) + +/* Begin user sect3 */ +#define YY_SKIP_YYWRAP + +typedef unsigned char YY_CHAR; + +#define yytext_ptr yytext + +#include <FlexLexer.h> + +int yyFlexLexer::yywrap() { return 1; } +int yyFlexLexer::yylex() + { + LexerError( "yyFlexLexer::yylex invoked but %option yyclass used" ); + return 0; + } + +#define YY_DECL int ElftosbLexer::yylex() + +/* Done after the current pattern has been matched and before the + * corresponding action - sets up yytext. + */ +#define YY_DO_BEFORE_ACTION \ + (yytext_ptr) = yy_bp; \ + yyleng = (size_t) (yy_cp - yy_bp); \ + (yy_hold_char) = *yy_cp; \ + *yy_cp = '\0'; \ + (yy_c_buf_p) = yy_cp; + +#define YY_NUM_RULES 74 +#define YY_END_OF_BUFFER 75 +/* This struct is not used in this scanner, + but its presence is necessary. */ +struct yy_trans_info + { + flex_int32_t yy_verify; + flex_int32_t yy_nxt; + }; +static yyconst flex_int16_t yy_accept[218] = + { 0, + 0, 0, 0, 0, 0, 0, 75, 73, 70, 71, + 71, 64, 73, 73, 73, 49, 54, 73, 34, 35, + 47, 45, 39, 46, 42, 48, 27, 27, 40, 41, + 57, 38, 43, 26, 36, 37, 51, 26, 26, 26, + 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, + 26, 26, 26, 26, 32, 55, 33, 50, 73, 73, + 72, 70, 71, 72, 71, 61, 0, 65, 0, 0, + 69, 29, 62, 0, 0, 56, 44, 30, 0, 0, + 27, 27, 0, 0, 52, 59, 60, 58, 53, 26, + 23, 26, 26, 26, 26, 26, 26, 26, 26, 26, + + 26, 26, 13, 26, 26, 26, 26, 26, 25, 26, + 26, 26, 26, 26, 26, 26, 26, 31, 63, 66, + 67, 68, 0, 0, 28, 0, 0, 27, 27, 26, + 26, 20, 26, 26, 26, 26, 26, 26, 26, 21, + 26, 22, 26, 26, 26, 26, 8, 26, 26, 26, + 26, 26, 24, 0, 0, 28, 0, 0, 0, 11, + 26, 26, 14, 26, 26, 26, 26, 7, 16, 10, + 9, 12, 26, 26, 26, 26, 26, 0, 0, 0, + 0, 28, 0, 26, 26, 18, 26, 26, 26, 26, + 26, 26, 26, 28, 0, 28, 0, 26, 26, 6, + + 26, 26, 26, 19, 26, 26, 0, 26, 15, 4, + 1, 5, 3, 17, 26, 2, 0 + } ; + +static yyconst flex_int32_t yy_ec[256] = + { 0, + 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, + 1, 1, 4, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 2, 5, 6, 7, 8, 9, 10, 11, 12, + 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, + 22, 22, 22, 22, 22, 22, 22, 23, 24, 25, + 26, 27, 28, 1, 29, 29, 30, 29, 31, 29, + 32, 33, 33, 33, 32, 33, 32, 33, 33, 33, + 33, 33, 34, 33, 33, 33, 33, 33, 33, 33, + 35, 1, 36, 37, 33, 1, 38, 39, 40, 41, + + 42, 43, 44, 45, 46, 47, 33, 48, 49, 50, + 51, 52, 33, 53, 54, 55, 56, 57, 58, 59, + 60, 61, 62, 63, 64, 65, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1 + } ; + +static yyconst flex_int32_t yy_meta[66] = + { 0, + 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 3, 1, 1, 3, 3, 1, 4, + 4, 4, 1, 1, 1, 1, 1, 3, 4, 4, + 4, 5, 5, 5, 3, 3, 3, 4, 4, 4, + 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 1, 1, 1, 1 + } ; + +static yyconst flex_int16_t yy_base[231] = + { 0, + 0, 0, 64, 127, 67, 73, 384, 385, 385, 385, + 380, 356, 66, 378, 0, 385, 370, 348, 385, 385, + 364, 385, 385, 385, 359, 59, 78, 94, 385, 385, + 57, 350, 62, 0, 385, 385, 385, 191, 41, 69, + 60, 74, 337, 75, 318, 322, 321, 320, 318, 331, + 92, 315, 329, 324, 303, 301, 385, 385, 0, 299, + 385, 385, 359, 342, 385, 385, 115, 385, 129, 357, + 385, 0, 385, 111, 128, 385, 385, 385, 356, 121, + 152, 385, 70, 0, 385, 385, 385, 385, 385, 0, + 385, 310, 307, 315, 312, 300, 300, 297, 303, 302, + + 298, 309, 0, 304, 291, 296, 306, 302, 0, 287, + 283, 300, 278, 282, 281, 283, 281, 385, 385, 385, + 385, 385, 145, 113, 130, 200, 202, 218, 148, 286, + 279, 0, 286, 289, 279, 287, 274, 272, 277, 0, + 274, 0, 272, 282, 280, 275, 0, 265, 277, 265, + 275, 266, 0, 146, 284, 283, 102, 148, 210, 0, + 258, 262, 0, 258, 257, 267, 266, 0, 0, 0, + 0, 0, 256, 257, 247, 253, 242, 270, 153, 160, + 211, 212, 213, 214, 209, 0, 199, 195, 196, 189, + 194, 194, 185, 385, 200, 198, 151, 162, 148, 0, + + 134, 132, 135, 0, 129, 111, 214, 90, 0, 0, + 0, 0, 0, 0, 86, 0, 385, 256, 261, 266, + 271, 274, 279, 281, 97, 286, 70, 291, 296, 301 + } ; + +static yyconst flex_int16_t yy_def[231] = + { 0, + 217, 1, 218, 218, 219, 219, 217, 217, 217, 217, + 217, 217, 220, 221, 222, 217, 217, 223, 217, 217, + 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, + 217, 217, 217, 224, 217, 217, 217, 224, 224, 224, + 224, 224, 38, 224, 224, 224, 224, 224, 224, 224, + 224, 224, 38, 224, 217, 217, 217, 217, 225, 217, + 217, 217, 217, 217, 217, 217, 220, 217, 220, 221, + 217, 222, 217, 226, 226, 217, 217, 217, 221, 217, + 217, 217, 217, 227, 217, 217, 217, 217, 217, 224, + 217, 224, 224, 224, 224, 224, 224, 224, 224, 224, + + 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, + 224, 224, 224, 224, 224, 224, 224, 217, 217, 217, + 217, 217, 220, 228, 228, 228, 228, 217, 227, 224, + 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, + 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, + 224, 224, 224, 220, 229, 229, 229, 229, 230, 224, + 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, + 224, 224, 224, 224, 224, 224, 224, 217, 217, 217, + 228, 228, 228, 224, 224, 224, 224, 224, 224, 224, + 224, 224, 224, 217, 217, 229, 229, 224, 224, 224, + + 224, 224, 224, 224, 224, 224, 228, 224, 224, 224, + 224, 224, 224, 224, 224, 224, 0, 217, 217, 217, + 217, 217, 217, 217, 217, 217, 217, 217, 217, 217 + } ; + +static yyconst flex_int16_t yy_nxt[451] = + { 0, + 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, + 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, + 28, 28, 29, 30, 31, 32, 33, 8, 34, 34, + 34, 34, 34, 34, 35, 36, 37, 34, 38, 39, + 40, 41, 42, 34, 43, 44, 45, 46, 47, 48, + 49, 34, 50, 51, 52, 34, 34, 53, 34, 54, + 34, 55, 56, 57, 58, 9, 10, 11, 62, 10, + 63, 68, 78, 129, 62, 10, 63, 79, 92, 80, + 64, 85, 86, 59, 59, 59, 64, 88, 89, 128, + 128, 93, 59, 59, 59, 80, 69, 81, 81, 81, + + 120, 59, 59, 59, 59, 59, 59, 96, 94, 82, + 95, 99, 97, 81, 81, 81, 83, 103, 98, 100, + 68, 125, 80, 156, 104, 82, 101, 60, 9, 10, + 11, 105, 179, 112, 68, 180, 84, 113, 125, 216, + 156, 126, 114, 157, 215, 69, 59, 59, 59, 80, + 68, 68, 82, 80, 214, 59, 59, 59, 126, 69, + 157, 127, 123, 194, 59, 59, 59, 59, 59, 59, + 194, 81, 81, 81, 154, 69, 69, 181, 179, 82, + 207, 179, 213, 82, 212, 211, 195, 210, 209, 155, + 60, 91, 91, 91, 91, 91, 91, 91, 91, 91, + + 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, + 156, 208, 156, 91, 91, 91, 91, 91, 91, 80, + 182, 196, 196, 196, 196, 91, 91, 91, 179, 178, + 157, 159, 157, 158, 206, 205, 204, 128, 128, 203, + 183, 157, 157, 157, 157, 202, 197, 201, 200, 82, + 199, 198, 91, 91, 91, 91, 8, 8, 8, 8, + 8, 61, 61, 61, 61, 61, 67, 67, 67, 67, + 67, 70, 70, 70, 70, 70, 72, 72, 72, 74, + 194, 74, 74, 74, 90, 90, 124, 193, 124, 124, + 124, 155, 192, 155, 155, 155, 178, 191, 178, 178, + + 178, 181, 190, 181, 181, 181, 189, 188, 109, 187, + 186, 185, 184, 179, 179, 177, 153, 176, 175, 174, + 173, 172, 171, 170, 169, 168, 167, 166, 165, 164, + 163, 162, 161, 160, 153, 152, 151, 150, 149, 148, + 147, 146, 145, 144, 143, 142, 141, 140, 139, 138, + 137, 136, 135, 134, 133, 132, 131, 130, 71, 71, + 122, 65, 121, 119, 118, 117, 116, 115, 111, 110, + 109, 108, 107, 106, 102, 87, 77, 76, 75, 73, + 71, 66, 65, 217, 7, 217, 217, 217, 217, 217, + 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, + + 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, + 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, + 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, + 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, + 217, 217, 217, 217, 217, 217, 217, 217, 217, 217 + } ; + +static yyconst flex_int16_t yy_chk[451] = + { 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 3, 3, 3, 5, 5, + 5, 13, 26, 227, 6, 6, 6, 26, 39, 27, + 5, 31, 31, 3, 3, 3, 6, 33, 33, 83, + 83, 39, 3, 3, 3, 28, 13, 27, 27, 27, + + 225, 3, 3, 3, 3, 3, 3, 41, 40, 27, + 40, 42, 41, 28, 28, 28, 27, 44, 41, 42, + 67, 74, 80, 124, 44, 28, 42, 3, 4, 4, + 4, 44, 157, 51, 69, 157, 27, 51, 75, 215, + 125, 74, 51, 124, 208, 67, 4, 4, 4, 129, + 123, 154, 80, 81, 206, 4, 4, 4, 75, 69, + 125, 75, 69, 179, 4, 4, 4, 4, 4, 4, + 180, 81, 81, 81, 123, 123, 154, 158, 158, 129, + 197, 197, 205, 81, 203, 202, 179, 201, 199, 180, + 4, 38, 38, 38, 38, 38, 38, 38, 38, 38, + + 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, + 126, 198, 127, 38, 38, 38, 38, 38, 38, 128, + 159, 181, 182, 183, 207, 38, 38, 38, 196, 195, + 126, 127, 127, 126, 193, 192, 191, 128, 128, 190, + 159, 181, 182, 183, 207, 189, 183, 188, 187, 128, + 185, 184, 38, 38, 38, 38, 218, 218, 218, 218, + 218, 219, 219, 219, 219, 219, 220, 220, 220, 220, + 220, 221, 221, 221, 221, 221, 222, 222, 222, 223, + 178, 223, 223, 223, 224, 224, 226, 177, 226, 226, + 226, 228, 176, 228, 228, 228, 229, 175, 229, 229, + + 229, 230, 174, 230, 230, 230, 173, 167, 166, 165, + 164, 162, 161, 156, 155, 152, 151, 150, 149, 148, + 146, 145, 144, 143, 141, 139, 138, 137, 136, 135, + 134, 133, 131, 130, 117, 116, 115, 114, 113, 112, + 111, 110, 108, 107, 106, 105, 104, 102, 101, 100, + 99, 98, 97, 96, 95, 94, 93, 92, 79, 70, + 64, 63, 60, 56, 55, 54, 53, 52, 50, 49, + 48, 47, 46, 45, 43, 32, 25, 21, 18, 17, + 14, 12, 11, 7, 217, 217, 217, 217, 217, 217, + 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, + + 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, + 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, + 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, + 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, + 217, 217, 217, 217, 217, 217, 217, 217, 217, 217 + } ; + +/* Table of booleans, true if rule could match eol. */ +static yyconst flex_int32_t yy_rule_can_match_eol[75] = + { 0, +0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, }; + +/* The intent behind this definition is that it'll catch + * any uses of REJECT which flex missed. + */ +#define REJECT reject_used_but_not_detected +#define yymore() yymore_used_but_not_detected +#define YY_MORE_ADJ 0 +#define YY_RESTORE_YY_MORE_OFFSET +#line 1 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_lexer.l" +/* %option prefix="Elftosb" */ +#line 10 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_lexer.l" +#include "ElftosbLexer.h" +#include <stdlib.h> +#include <limits.h> +#include <string> +#include "HexValues.h" +#include "Value.h" + +using namespace elftosb; + +//! Always executed before all other actions when a token is matched. +//! This action just assign the first and last lines of the token to +//! the current line. In most cases this is correct. +#define YY_USER_ACTION do { \ + m_location.m_firstLine = m_line; \ + m_location.m_lastLine = m_line; \ + } while (0); + +/* start conditions */ + +#line 628 "/Users/creed/projects/fsl/fromsvr/elftosb/build/elftosb.build/Debug/elftosb.build/DerivedSources/elftosb_lexer.cpp" + +#define INITIAL 0 +#define blob 1 +#define mlcmt 2 + +#ifndef YY_NO_UNISTD_H +/* Special case for "unistd.h", since it is non-ANSI. We include it way + * down here because we want the user's section 1 to have been scanned first. + * The user has a chance to override it with an option. + */ +#include <unistd.h> +#endif + +#ifndef YY_EXTRA_TYPE +#define YY_EXTRA_TYPE void * +#endif + +#ifndef yytext_ptr +static void yy_flex_strncpy (char *,yyconst char *,int ); +#endif + +#ifdef YY_NEED_STRLEN +static int yy_flex_strlen (yyconst char * ); +#endif + +#ifndef YY_NO_INPUT + +#endif + +/* Amount of stuff to slurp up with each read. */ +#ifndef YY_READ_BUF_SIZE +#define YY_READ_BUF_SIZE 8192 +#endif + +/* Copy whatever the last rule matched to the standard output. */ +#ifndef ECHO +#define ECHO LexerOutput( yytext, yyleng ) +#endif + +/* Gets input and stuffs it into "buf". number of characters read, or YY_NULL, + * is returned in "result". + */ +#ifndef YY_INPUT +#define YY_INPUT(buf,result,max_size) \ +\ + if ( (result = LexerInput( (char *) buf, max_size )) < 0 ) \ + YY_FATAL_ERROR( "input in flex scanner failed" ); + +#endif + +/* No semi-colon after return; correct usage is to write "yyterminate();" - + * we don't want an extra ';' after the "return" because that will cause + * some compilers to complain about unreachable statements. + */ +#ifndef yyterminate +#define yyterminate() return YY_NULL +#endif + +/* Number of entries by which start-condition stack grows. */ +#ifndef YY_START_STACK_INCR +#define YY_START_STACK_INCR 25 +#endif + +/* Report a fatal error. */ +#ifndef YY_FATAL_ERROR +#define YY_FATAL_ERROR(msg) LexerError( msg ) +#endif + +/* end tables serialization structures and prototypes */ + +/* Default declaration of generated scanner - a define so the user can + * easily add parameters. + */ +#ifndef YY_DECL +#define YY_DECL_IS_OURS 1 +#define YY_DECL int yyFlexLexer::yylex() +#endif /* !YY_DECL */ + +/* Code executed at the beginning of each rule, after yytext and yyleng + * have been set up. + */ +#ifndef YY_USER_ACTION +#define YY_USER_ACTION +#endif + +/* Code executed at the end of each rule. */ +#ifndef YY_BREAK +#define YY_BREAK break; +#endif + +#define YY_RULE_SETUP \ + YY_USER_ACTION + +/** The main scanner function which does all the work. + */ +YY_DECL +{ + register yy_state_type yy_current_state; + register char *yy_cp, *yy_bp; + register int yy_act; + +#line 38 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_lexer.l" + + +#line 733 "/Users/creed/projects/fsl/fromsvr/elftosb/build/elftosb.build/Debug/elftosb.build/DerivedSources/elftosb_lexer.cpp" + + if ( !(yy_init) ) + { + (yy_init) = 1; + +#ifdef YY_USER_INIT + YY_USER_INIT; +#endif + + if ( ! (yy_start) ) + (yy_start) = 1; /* first start state */ + + if ( ! yyin ) + yyin = & std::cin; + + if ( ! yyout ) + yyout = & std::cout; + + if ( ! YY_CURRENT_BUFFER ) { + yyensure_buffer_stack (); + YY_CURRENT_BUFFER_LVALUE = + yy_create_buffer( yyin, YY_BUF_SIZE ); + } + + yy_load_buffer_state( ); + } + + while ( 1 ) /* loops until end-of-file is reached */ + { + yy_cp = (yy_c_buf_p); + + /* Support of yytext. */ + *yy_cp = (yy_hold_char); + + /* yy_bp points to the position in yy_ch_buf of the start of + * the current run. + */ + yy_bp = yy_cp; + + yy_current_state = (yy_start); +yy_match: + do + { + register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)]; + if ( yy_accept[yy_current_state] ) + { + (yy_last_accepting_state) = yy_current_state; + (yy_last_accepting_cpos) = yy_cp; + } + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = (int) yy_def[yy_current_state]; + if ( yy_current_state >= 218 ) + yy_c = yy_meta[(unsigned int) yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; + ++yy_cp; + } + while ( yy_current_state != 217 ); + yy_cp = (yy_last_accepting_cpos); + yy_current_state = (yy_last_accepting_state); + +yy_find_action: + yy_act = yy_accept[yy_current_state]; + + YY_DO_BEFORE_ACTION; + + if ( yy_act != YY_END_OF_BUFFER && yy_rule_can_match_eol[yy_act] ) + { + int yyl; + for ( yyl = 0; yyl < yyleng; ++yyl ) + if ( yytext[yyl] == '\n' ) + + yylineno++; +; + } + +do_action: /* This label is used only to access EOF actions. */ + + switch ( yy_act ) + { /* beginning of action switch */ + case 0: /* must back up */ + /* undo the effects of YY_DO_BEFORE_ACTION */ + *yy_cp = (yy_hold_char); + yy_cp = (yy_last_accepting_cpos); + yy_current_state = (yy_last_accepting_state); + goto yy_find_action; + +case 1: +YY_RULE_SETUP +#line 40 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_lexer.l" +{ return TOK_OPTIONS; } + YY_BREAK +case 2: +YY_RULE_SETUP +#line 41 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_lexer.l" +{ return TOK_CONSTANTS; } + YY_BREAK +case 3: +YY_RULE_SETUP +#line 42 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_lexer.l" +{ return TOK_SOURCES; } + YY_BREAK +case 4: +YY_RULE_SETUP +#line 43 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_lexer.l" +{ return TOK_FILTERS; } + YY_BREAK +case 5: +YY_RULE_SETUP +#line 44 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_lexer.l" +{ return TOK_SECTION; } + YY_BREAK +case 6: +YY_RULE_SETUP +#line 45 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_lexer.l" +{ return TOK_EXTERN; } + YY_BREAK +case 7: +YY_RULE_SETUP +#line 46 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_lexer.l" +{ return TOK_FROM; } + YY_BREAK +case 8: +YY_RULE_SETUP +#line 47 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_lexer.l" +{ return TOK_RAW; } + YY_BREAK +case 9: +YY_RULE_SETUP +#line 48 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_lexer.l" +{ return TOK_LOAD; } + YY_BREAK +case 10: +YY_RULE_SETUP +#line 49 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_lexer.l" +{ return TOK_JUMP; } + YY_BREAK +case 11: +YY_RULE_SETUP +#line 50 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_lexer.l" +{ return TOK_CALL; } + YY_BREAK +case 12: +YY_RULE_SETUP +#line 51 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_lexer.l" +{ return TOK_MODE; } + YY_BREAK +case 13: +YY_RULE_SETUP +#line 52 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_lexer.l" +{ return TOK_IF; } + YY_BREAK +case 14: +YY_RULE_SETUP +#line 53 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_lexer.l" +{ return TOK_ELSE; } + YY_BREAK +case 15: +YY_RULE_SETUP +#line 54 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_lexer.l" +{ return TOK_DEFINED; } + YY_BREAK +case 16: +YY_RULE_SETUP +#line 55 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_lexer.l" +{ return TOK_INFO; } + YY_BREAK +case 17: +YY_RULE_SETUP +#line 56 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_lexer.l" +{ return TOK_WARNING; } + YY_BREAK +case 18: +YY_RULE_SETUP +#line 57 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_lexer.l" +{ return TOK_ERROR; } + YY_BREAK +case 19: +YY_RULE_SETUP +#line 58 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_lexer.l" +{ return TOK_SIZEOF; } + YY_BREAK +case 20: +YY_RULE_SETUP +#line 59 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_lexer.l" +{ return TOK_DCD; } + YY_BREAK +case 21: +YY_RULE_SETUP +#line 60 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_lexer.l" +{ return TOK_HAB; } + YY_BREAK +case 22: +YY_RULE_SETUP +#line 61 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_lexer.l" +{ return TOK_IVT; } + YY_BREAK +case 23: +/* rule 23 can match eol */ +*yy_cp = (yy_hold_char); /* undo effects of setting up yytext */ +(yy_c_buf_p) = yy_cp = yy_bp + 1; +YY_DO_BEFORE_ACTION; /* set up yytext again */ +YY_RULE_SETUP +#line 63 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_lexer.l" +{ // must be followed by any non-ident char + int_size_t theSize; + switch (yytext[0]) + { + case 'w': + theSize = kWordSize; + break; + case 'h': + theSize = kHalfWordSize; + break; + case 'b': + theSize = kByteSize; + break; + } + m_symbolValue.m_int = new elftosb::SizedIntegerValue(0, theSize); + return TOK_INT_SIZE; + } + YY_BREAK +case 24: +YY_RULE_SETUP +#line 81 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_lexer.l" +{ + m_symbolValue.m_int = new elftosb::SizedIntegerValue(1, kWordSize); + return TOK_INT_LITERAL; + } + YY_BREAK +case 25: +YY_RULE_SETUP +#line 86 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_lexer.l" +{ + m_symbolValue.m_int = new elftosb::SizedIntegerValue(0, kWordSize); + return TOK_INT_LITERAL; + } + YY_BREAK +case 26: +YY_RULE_SETUP +#line 91 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_lexer.l" +{ + m_symbolValue.m_str = new std::string(yytext); + if (isSourceName(m_symbolValue.m_str)) + { + return TOK_SOURCE_NAME; + } + else + { + return TOK_IDENT; + } + } + YY_BREAK +case 27: +YY_RULE_SETUP +#line 103 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_lexer.l" +{ + int base = 0; + uint32_t value; + int mult; + + // check for binary number + if (yytext[0] == '0' && yytext[1] == 'b') + { + base = 2; // this is a binary number + yytext += 2; // skip over the "0b" + } + + // convert value + value = (uint32_t)strtoul(yytext, NULL, base); + + // find multiplier + switch (yytext[strlen(yytext) - 1]) + { + case 'G': + mult = 1024 * 1024 * 1024; + break; + case 'M': + mult = 1024 * 1024; + break; + case 'K': + mult = 1024; + break; + default: + mult = 1; + break; + } + + // set resulting symbol value + m_symbolValue.m_int = new elftosb::SizedIntegerValue(value * mult, kWordSize); + return TOK_INT_LITERAL; + } + YY_BREAK +case 28: +YY_RULE_SETUP +#line 140 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_lexer.l" +{ + uint32_t value = 0; + int_size_t theSize; + int len = strlen(yytext); + if (len >= 3) + { + value = yytext[1]; + theSize = kByteSize; + } + if (len >= 4) + { + value = (value << 8) | yytext[2]; + theSize = kHalfWordSize; + } + if (len >= 6) + { + value = (value << 8) | yytext[3]; + value = (value << 8) | yytext[4]; + theSize = kWordSize; + } + m_symbolValue.m_int = new elftosb::SizedIntegerValue(value, theSize); + return TOK_INT_LITERAL; + } + YY_BREAK +case 29: +YY_RULE_SETUP +#line 164 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_lexer.l" +{ + // remove $ from string + m_symbolValue.m_str = new std::string(&yytext[1]); + return TOK_SECTION_NAME; + } + YY_BREAK +case 30: +YY_RULE_SETUP +#line 171 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_lexer.l" +{ BEGIN(mlcmt); } + YY_BREAK +case 31: +YY_RULE_SETUP +#line 173 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_lexer.l" +{ + m_blob = new Blob(); + m_blobFirstLine = yylineno; + BEGIN(blob); + } + YY_BREAK +case 32: +YY_RULE_SETUP +#line 179 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_lexer.l" +{ return '{'; } + YY_BREAK +case 33: +YY_RULE_SETUP +#line 181 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_lexer.l" +{ return '}'; } + YY_BREAK +case 34: +YY_RULE_SETUP +#line 183 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_lexer.l" +{ return '('; } + YY_BREAK +case 35: +YY_RULE_SETUP +#line 185 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_lexer.l" +{ return ')'; } + YY_BREAK +case 36: +YY_RULE_SETUP +#line 187 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_lexer.l" +{ return '['; } + YY_BREAK +case 37: +YY_RULE_SETUP +#line 189 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_lexer.l" +{ return ']'; } + YY_BREAK +case 38: +YY_RULE_SETUP +#line 191 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_lexer.l" +{ return '='; } + YY_BREAK +case 39: +YY_RULE_SETUP +#line 193 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_lexer.l" +{ return ','; } + YY_BREAK +case 40: +YY_RULE_SETUP +#line 195 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_lexer.l" +{ return ':'; } + YY_BREAK +case 41: +YY_RULE_SETUP +#line 197 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_lexer.l" +{ return ';'; } + YY_BREAK +case 42: +YY_RULE_SETUP +#line 199 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_lexer.l" +{ return '.'; } + YY_BREAK +case 43: +YY_RULE_SETUP +#line 201 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_lexer.l" +{ return '>'; } + YY_BREAK +case 44: +YY_RULE_SETUP +#line 203 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_lexer.l" +{ return TOK_DOT_DOT; } + YY_BREAK +case 45: +YY_RULE_SETUP +#line 205 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_lexer.l" +{ return '+'; } + YY_BREAK +case 46: +YY_RULE_SETUP +#line 207 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_lexer.l" +{ return '-'; } + YY_BREAK +case 47: +YY_RULE_SETUP +#line 209 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_lexer.l" +{ return '*'; } + YY_BREAK +case 48: +YY_RULE_SETUP +#line 211 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_lexer.l" +{ return '/'; } + YY_BREAK +case 49: +YY_RULE_SETUP +#line 213 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_lexer.l" +{ return '%'; } + YY_BREAK +case 50: +YY_RULE_SETUP +#line 215 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_lexer.l" +{ return '~'; } + YY_BREAK +case 51: +YY_RULE_SETUP +#line 217 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_lexer.l" +{ return '^'; } + YY_BREAK +case 52: +YY_RULE_SETUP +#line 219 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_lexer.l" +{ return TOK_LSHIFT; } + YY_BREAK +case 53: +YY_RULE_SETUP +#line 221 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_lexer.l" +{ return TOK_RSHIFT; } + YY_BREAK +case 54: +YY_RULE_SETUP +#line 223 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_lexer.l" +{ return '&'; } + YY_BREAK +case 55: +YY_RULE_SETUP +#line 225 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_lexer.l" +{ return '|'; } + YY_BREAK +case 56: +YY_RULE_SETUP +#line 227 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_lexer.l" +{ return TOK_POWER; } + YY_BREAK +case 57: +YY_RULE_SETUP +#line 229 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_lexer.l" +{ return '<'; } + YY_BREAK +case 58: +YY_RULE_SETUP +#line 231 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_lexer.l" +{ return TOK_GEQ; } + YY_BREAK +case 59: +YY_RULE_SETUP +#line 233 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_lexer.l" +{ return TOK_LEQ; } + YY_BREAK +case 60: +YY_RULE_SETUP +#line 235 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_lexer.l" +{ return TOK_EQ; } + YY_BREAK +case 61: +YY_RULE_SETUP +#line 237 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_lexer.l" +{ return TOK_NEQ; } + YY_BREAK +case 62: +YY_RULE_SETUP +#line 239 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_lexer.l" +{ return TOK_AND; } + YY_BREAK +case 63: +YY_RULE_SETUP +#line 241 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_lexer.l" +{ return TOK_OR; } + YY_BREAK +case 64: +YY_RULE_SETUP +#line 243 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_lexer.l" +{ return '!'; } + YY_BREAK +case 65: +/* rule 65 can match eol */ +YY_RULE_SETUP +#line 245 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_lexer.l" +{ + // get rid of quotes + yytext++; + yytext[strlen(yytext) - 1] = 0; +// processStringEscapes(yytext, yytext); + m_symbolValue.m_str = new std::string(yytext); + return TOK_STRING_LITERAL; + } + YY_BREAK +case 66: +YY_RULE_SETUP +#line 254 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_lexer.l" +{ + uint8_t x = (hexCharToInt(yytext[0]) << 4) | hexCharToInt(yytext[1]); + m_blob->append(&x, 1); + } + YY_BREAK +case 67: +YY_RULE_SETUP +#line 259 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_lexer.l" +{ + BEGIN(INITIAL); + m_symbolValue.m_blob = m_blob; + m_blob = NULL; + m_location.m_firstLine = m_blobFirstLine; + return TOK_BLOB; + } + YY_BREAK +case 68: +YY_RULE_SETUP +#line 267 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_lexer.l" +{ + // end of multi-line comment, return to initial state + BEGIN(INITIAL); + } + YY_BREAK +case 69: +*yy_cp = (yy_hold_char); /* undo effects of setting up yytext */ +(yy_c_buf_p) = yy_cp -= 1; +YY_DO_BEFORE_ACTION; /* set up yytext again */ +YY_RULE_SETUP +#line 273 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_lexer.l" +/* absorb single-line comment */ + YY_BREAK +case 70: +YY_RULE_SETUP +#line 275 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_lexer.l" +/* eat up whitespace in all states */ + YY_BREAK +case 71: +/* rule 71 can match eol */ +YY_RULE_SETUP +#line 277 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_lexer.l" +{ + /* eat up whitespace and count lines in all states */ + m_line++; + } + YY_BREAK +case 72: +YY_RULE_SETUP +#line 282 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_lexer.l" +/* ignore all other chars in a multi-line comment */ + YY_BREAK +case 73: +YY_RULE_SETUP +#line 284 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_lexer.l" +{ + /* all other chars produce errors */ + char msg[50]; + sprintf(msg, "unexpected character '%c' on line %d", yytext[0], m_line); + LexerError(msg); + } + YY_BREAK +case 74: +YY_RULE_SETUP +#line 291 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_lexer.l" +ECHO; + YY_BREAK +#line 1325 "/Users/creed/projects/fsl/fromsvr/elftosb/build/elftosb.build/Debug/elftosb.build/DerivedSources/elftosb_lexer.cpp" +case YY_STATE_EOF(INITIAL): +case YY_STATE_EOF(blob): +case YY_STATE_EOF(mlcmt): + yyterminate(); + + case YY_END_OF_BUFFER: + { + /* Amount of text matched not including the EOB char. */ + int yy_amount_of_matched_text = (int) (yy_cp - (yytext_ptr)) - 1; + + /* Undo the effects of YY_DO_BEFORE_ACTION. */ + *yy_cp = (yy_hold_char); + YY_RESTORE_YY_MORE_OFFSET + + if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW ) + { + /* We're scanning a new file or input source. It's + * possible that this happened because the user + * just pointed yyin at a new source and called + * yylex(). If so, then we have to assure + * consistency between YY_CURRENT_BUFFER and our + * globals. Here is the right place to do so, because + * this is the first action (other than possibly a + * back-up) that will match for the new input source. + */ + (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; + YY_CURRENT_BUFFER_LVALUE->yy_input_file = yyin; + YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL; + } + + /* Note that here we test for yy_c_buf_p "<=" to the position + * of the first EOB in the buffer, since yy_c_buf_p will + * already have been incremented past the NUL character + * (since all states make transitions on EOB to the + * end-of-buffer state). Contrast this with the test + * in input(). + */ + if ( (yy_c_buf_p) <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) + { /* This was really a NUL. */ + yy_state_type yy_next_state; + + (yy_c_buf_p) = (yytext_ptr) + yy_amount_of_matched_text; + + yy_current_state = yy_get_previous_state( ); + + /* Okay, we're now positioned to make the NUL + * transition. We couldn't have + * yy_get_previous_state() go ahead and do it + * for us because it doesn't know how to deal + * with the possibility of jamming (and we don't + * want to build jamming into it because then it + * will run more slowly). + */ + + yy_next_state = yy_try_NUL_trans( yy_current_state ); + + yy_bp = (yytext_ptr) + YY_MORE_ADJ; + + if ( yy_next_state ) + { + /* Consume the NUL. */ + yy_cp = ++(yy_c_buf_p); + yy_current_state = yy_next_state; + goto yy_match; + } + + else + { + yy_cp = (yy_last_accepting_cpos); + yy_current_state = (yy_last_accepting_state); + goto yy_find_action; + } + } + + else switch ( yy_get_next_buffer( ) ) + { + case EOB_ACT_END_OF_FILE: + { + (yy_did_buffer_switch_on_eof) = 0; + + if ( yywrap( ) ) + { + /* Note: because we've taken care in + * yy_get_next_buffer() to have set up + * yytext, we can now set up + * yy_c_buf_p so that if some total + * hoser (like flex itself) wants to + * call the scanner after we return the + * YY_NULL, it'll still work - another + * YY_NULL will get returned. + */ + (yy_c_buf_p) = (yytext_ptr) + YY_MORE_ADJ; + + yy_act = YY_STATE_EOF(YY_START); + goto do_action; + } + + else + { + if ( ! (yy_did_buffer_switch_on_eof) ) + YY_NEW_FILE; + } + break; + } + + case EOB_ACT_CONTINUE_SCAN: + (yy_c_buf_p) = + (yytext_ptr) + yy_amount_of_matched_text; + + yy_current_state = yy_get_previous_state( ); + + yy_cp = (yy_c_buf_p); + yy_bp = (yytext_ptr) + YY_MORE_ADJ; + goto yy_match; + + case EOB_ACT_LAST_MATCH: + (yy_c_buf_p) = + &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)]; + + yy_current_state = yy_get_previous_state( ); + + yy_cp = (yy_c_buf_p); + yy_bp = (yytext_ptr) + YY_MORE_ADJ; + goto yy_find_action; + } + break; + } + + default: + YY_FATAL_ERROR( + "fatal flex scanner internal error--no action found" ); + } /* end of action switch */ + } /* end of scanning one token */ +} /* end of yylex */ + +/* The contents of this function are C++ specific, so the () macro is not used. + */ +yyFlexLexer::yyFlexLexer( std::istream* arg_yyin, std::ostream* arg_yyout ) +{ + yyin = arg_yyin; + yyout = arg_yyout; + yy_c_buf_p = 0; + yy_init = 0; + yy_start = 0; + yy_flex_debug = 0; + yylineno = 1; // this will only get updated if %option yylineno + + yy_did_buffer_switch_on_eof = 0; + + yy_looking_for_trail_begin = 0; + yy_more_flag = 0; + yy_more_len = 0; + yy_more_offset = yy_prev_more_offset = 0; + + yy_start_stack_ptr = yy_start_stack_depth = 0; + yy_start_stack = NULL; + + yy_buffer_stack = 0; + yy_buffer_stack_top = 0; + yy_buffer_stack_max = 0; + + yy_state_buf = 0; + +} + +/* The contents of this function are C++ specific, so the () macro is not used. + */ +yyFlexLexer::~yyFlexLexer() +{ + delete [] yy_state_buf; + yyfree(yy_start_stack ); + yy_delete_buffer( YY_CURRENT_BUFFER ); + yyfree(yy_buffer_stack ); +} + +/* The contents of this function are C++ specific, so the () macro is not used. + */ +void yyFlexLexer::switch_streams( std::istream* new_in, std::ostream* new_out ) +{ + if ( new_in ) + { + yy_delete_buffer( YY_CURRENT_BUFFER ); + yy_switch_to_buffer( yy_create_buffer( new_in, YY_BUF_SIZE ) ); + } + + if ( new_out ) + yyout = new_out; +} + +#ifdef YY_INTERACTIVE +int yyFlexLexer::LexerInput( char* buf, int /* max_size */ ) +#else +int yyFlexLexer::LexerInput( char* buf, int max_size ) +#endif +{ + if ( yyin->eof() || yyin->fail() ) + return 0; + +#ifdef YY_INTERACTIVE + yyin->get( buf[0] ); + + if ( yyin->eof() ) + return 0; + + if ( yyin->bad() ) + return -1; + + return 1; + +#else + (void) yyin->read( buf, max_size ); + + if ( yyin->bad() ) + return -1; + else + return yyin->gcount(); +#endif +} + +void yyFlexLexer::LexerOutput( const char* buf, int size ) +{ + (void) yyout->write( buf, size ); +} + +/* yy_get_next_buffer - try to read in a new buffer + * + * Returns a code representing an action: + * EOB_ACT_LAST_MATCH - + * EOB_ACT_CONTINUE_SCAN - continue scanning from current position + * EOB_ACT_END_OF_FILE - end of file + */ +int yyFlexLexer::yy_get_next_buffer() +{ + register char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf; + register char *source = (yytext_ptr); + register int number_to_move, i; + int ret_val; + + if ( (yy_c_buf_p) > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] ) + YY_FATAL_ERROR( + "fatal flex scanner internal error--end of buffer missed" ); + + if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 ) + { /* Don't try to fill the buffer, so this is an EOF. */ + if ( (yy_c_buf_p) - (yytext_ptr) - YY_MORE_ADJ == 1 ) + { + /* We matched a single character, the EOB, so + * treat this as a final EOF. + */ + return EOB_ACT_END_OF_FILE; + } + + else + { + /* We matched some text prior to the EOB, first + * process it. + */ + return EOB_ACT_LAST_MATCH; + } + } + + /* Try to read more data. */ + + /* First move last chars to start of buffer. */ + number_to_move = (int) ((yy_c_buf_p) - (yytext_ptr)) - 1; + + for ( i = 0; i < number_to_move; ++i ) + *(dest++) = *(source++); + + if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING ) + /* don't do the read, it's not guaranteed to return an EOF, + * just force an EOF + */ + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars) = 0; + + else + { + yy_size_t num_to_read = + YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1; + + while ( num_to_read <= 0 ) + { /* Not enough room in the buffer - grow it. */ + + /* just a shorter name for the current buffer */ + YY_BUFFER_STATE b = YY_CURRENT_BUFFER; + + int yy_c_buf_p_offset = + (int) ((yy_c_buf_p) - b->yy_ch_buf); + + if ( b->yy_is_our_buffer ) + { + yy_size_t new_size = b->yy_buf_size * 2; + + if ( new_size <= 0 ) + b->yy_buf_size += b->yy_buf_size / 8; + else + b->yy_buf_size *= 2; + + b->yy_ch_buf = (char *) + /* Include room in for 2 EOB chars. */ + yyrealloc((void *) b->yy_ch_buf,b->yy_buf_size + 2 ); + } + else + /* Can't grow it, we don't own it. */ + b->yy_ch_buf = 0; + + if ( ! b->yy_ch_buf ) + YY_FATAL_ERROR( + "fatal error - scanner input buffer overflow" ); + + (yy_c_buf_p) = &b->yy_ch_buf[yy_c_buf_p_offset]; + + num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size - + number_to_move - 1; + + } + + if ( num_to_read > YY_READ_BUF_SIZE ) + num_to_read = YY_READ_BUF_SIZE; + + /* Read in more data. */ + YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]), + (yy_n_chars), num_to_read ); + + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); + } + + if ( (yy_n_chars) == 0 ) + { + if ( number_to_move == YY_MORE_ADJ ) + { + ret_val = EOB_ACT_END_OF_FILE; + yyrestart( yyin ); + } + + else + { + ret_val = EOB_ACT_LAST_MATCH; + YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = + YY_BUFFER_EOF_PENDING; + } + } + + else + ret_val = EOB_ACT_CONTINUE_SCAN; + + if ((yy_size_t) ((yy_n_chars) + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) { + /* Extend the array by 50%, plus the number we really need. */ + yy_size_t new_size = (yy_n_chars) + number_to_move + ((yy_n_chars) >> 1); + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) yyrealloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,new_size ); + if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) + YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" ); + } + + (yy_n_chars) += number_to_move; + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] = YY_END_OF_BUFFER_CHAR; + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] = YY_END_OF_BUFFER_CHAR; + + (yytext_ptr) = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0]; + + return ret_val; +} + +/* yy_get_previous_state - get the state just before the EOB char was reached */ + + yy_state_type yyFlexLexer::yy_get_previous_state() +{ + register yy_state_type yy_current_state; + register char *yy_cp; + + yy_current_state = (yy_start); + + for ( yy_cp = (yytext_ptr) + YY_MORE_ADJ; yy_cp < (yy_c_buf_p); ++yy_cp ) + { + register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1); + if ( yy_accept[yy_current_state] ) + { + (yy_last_accepting_state) = yy_current_state; + (yy_last_accepting_cpos) = yy_cp; + } + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = (int) yy_def[yy_current_state]; + if ( yy_current_state >= 218 ) + yy_c = yy_meta[(unsigned int) yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; + } + + return yy_current_state; +} + +/* yy_try_NUL_trans - try to make a transition on the NUL character + * + * synopsis + * next_state = yy_try_NUL_trans( current_state ); + */ + yy_state_type yyFlexLexer::yy_try_NUL_trans( yy_state_type yy_current_state ) +{ + register int yy_is_jam; + register char *yy_cp = (yy_c_buf_p); + + register YY_CHAR yy_c = 1; + if ( yy_accept[yy_current_state] ) + { + (yy_last_accepting_state) = yy_current_state; + (yy_last_accepting_cpos) = yy_cp; + } + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = (int) yy_def[yy_current_state]; + if ( yy_current_state >= 218 ) + yy_c = yy_meta[(unsigned int) yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; + yy_is_jam = (yy_current_state == 217); + + return yy_is_jam ? 0 : yy_current_state; +} + + void yyFlexLexer::yyunput( int c, register char* yy_bp) +{ + register char *yy_cp; + + yy_cp = (yy_c_buf_p); + + /* undo effects of setting up yytext */ + *yy_cp = (yy_hold_char); + + if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 ) + { /* need to shift things up to make room */ + /* +2 for EOB chars. */ + register yy_size_t number_to_move = (yy_n_chars) + 2; + register char *dest = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[ + YY_CURRENT_BUFFER_LVALUE->yy_buf_size + 2]; + register char *source = + &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]; + + while ( source > YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) + *--dest = *--source; + + yy_cp += (int) (dest - source); + yy_bp += (int) (dest - source); + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = + (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_buf_size; + + if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 ) + YY_FATAL_ERROR( "flex scanner push-back overflow" ); + } + + *--yy_cp = (char) c; + + if ( c == '\n' ){ + --yylineno; + } + + (yytext_ptr) = yy_bp; + (yy_hold_char) = *yy_cp; + (yy_c_buf_p) = yy_cp; +} + + int yyFlexLexer::yyinput() +{ + int c; + + *(yy_c_buf_p) = (yy_hold_char); + + if ( *(yy_c_buf_p) == YY_END_OF_BUFFER_CHAR ) + { + /* yy_c_buf_p now points to the character we want to return. + * If this occurs *before* the EOB characters, then it's a + * valid NUL; if not, then we've hit the end of the buffer. + */ + if ( (yy_c_buf_p) < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) + /* This was really a NUL. */ + *(yy_c_buf_p) = '\0'; + + else + { /* need more input */ + yy_size_t offset = (yy_c_buf_p) - (yytext_ptr); + ++(yy_c_buf_p); + + switch ( yy_get_next_buffer( ) ) + { + case EOB_ACT_LAST_MATCH: + /* This happens because yy_g_n_b() + * sees that we've accumulated a + * token and flags that we need to + * try matching the token before + * proceeding. But for input(), + * there's no matching to consider. + * So convert the EOB_ACT_LAST_MATCH + * to EOB_ACT_END_OF_FILE. + */ + + /* Reset buffer status. */ + yyrestart( yyin ); + + /*FALLTHROUGH*/ + + case EOB_ACT_END_OF_FILE: + { + if ( yywrap( ) ) + return 0; + + if ( ! (yy_did_buffer_switch_on_eof) ) + YY_NEW_FILE; +#ifdef __cplusplus + return yyinput(); +#else + return input(); +#endif + } + + case EOB_ACT_CONTINUE_SCAN: + (yy_c_buf_p) = (yytext_ptr) + offset; + break; + } + } + } + + c = *(unsigned char *) (yy_c_buf_p); /* cast for 8-bit char's */ + *(yy_c_buf_p) = '\0'; /* preserve yytext */ + (yy_hold_char) = *++(yy_c_buf_p); + + if ( c == '\n' ) + + yylineno++; +; + + return c; +} + +/** Immediately switch to a different input stream. + * @param input_file A readable stream. + * + * @note This function does not reset the start condition to @c INITIAL . + */ + void yyFlexLexer::yyrestart( std::istream* input_file ) +{ + + if ( ! YY_CURRENT_BUFFER ){ + yyensure_buffer_stack (); + YY_CURRENT_BUFFER_LVALUE = + yy_create_buffer( yyin, YY_BUF_SIZE ); + } + + yy_init_buffer( YY_CURRENT_BUFFER, input_file ); + yy_load_buffer_state( ); +} + +/** Switch to a different input buffer. + * @param new_buffer The new input buffer. + * + */ + void yyFlexLexer::yy_switch_to_buffer( YY_BUFFER_STATE new_buffer ) +{ + + /* TODO. We should be able to replace this entire function body + * with + * yypop_buffer_state(); + * yypush_buffer_state(new_buffer); + */ + yyensure_buffer_stack (); + if ( YY_CURRENT_BUFFER == new_buffer ) + return; + + if ( YY_CURRENT_BUFFER ) + { + /* Flush out information for old buffer. */ + *(yy_c_buf_p) = (yy_hold_char); + YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); + } + + YY_CURRENT_BUFFER_LVALUE = new_buffer; + yy_load_buffer_state( ); + + /* We don't actually know whether we did this switch during + * EOF (yywrap()) processing, but the only time this flag + * is looked at is after yywrap() is called, so it's safe + * to go ahead and always set it. + */ + (yy_did_buffer_switch_on_eof) = 1; +} + + void yyFlexLexer::yy_load_buffer_state() +{ + (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; + (yytext_ptr) = (yy_c_buf_p) = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos; + yyin = YY_CURRENT_BUFFER_LVALUE->yy_input_file; + (yy_hold_char) = *(yy_c_buf_p); +} + +/** Allocate and initialize an input buffer state. + * @param file A readable stream. + * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE. + * + * @return the allocated buffer state. + */ + YY_BUFFER_STATE yyFlexLexer::yy_create_buffer( std::istream* file, int size ) +{ + YY_BUFFER_STATE b; + + b = (YY_BUFFER_STATE) yyalloc(sizeof( struct yy_buffer_state ) ); + if ( ! b ) + YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); + + b->yy_buf_size = size; + + /* yy_ch_buf has to be 2 characters longer than the size given because + * we need to put in 2 end-of-buffer characters. + */ + b->yy_ch_buf = (char *) yyalloc(b->yy_buf_size + 2 ); + if ( ! b->yy_ch_buf ) + YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); + + b->yy_is_our_buffer = 1; + + yy_init_buffer( b, file ); + + return b; +} + +/** Destroy the buffer. + * @param b a buffer created with yy_create_buffer() + * + */ + void yyFlexLexer::yy_delete_buffer( YY_BUFFER_STATE b ) +{ + + if ( ! b ) + return; + + if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */ + YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0; + + if ( b->yy_is_our_buffer ) + yyfree((void *) b->yy_ch_buf ); + + yyfree((void *) b ); +} + +/* Initializes or reinitializes a buffer. + * This function is sometimes called more than once on the same buffer, + * such as during a yyrestart() or at EOF. + */ + void yyFlexLexer::yy_init_buffer( YY_BUFFER_STATE b, std::istream* file ) + +{ + int oerrno = errno; + + yy_flush_buffer( b ); + + b->yy_input_file = file; + b->yy_fill_buffer = 1; + + /* If b is the current buffer, then yy_init_buffer was _probably_ + * called from yyrestart() or through yy_get_next_buffer. + * In that case, we don't want to reset the lineno or column. + */ + if (b != YY_CURRENT_BUFFER){ + b->yy_bs_lineno = 1; + b->yy_bs_column = 0; + } + + b->yy_is_interactive = 0; + errno = oerrno; +} + +/** Discard all buffered characters. On the next scan, YY_INPUT will be called. + * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER. + * + */ + void yyFlexLexer::yy_flush_buffer( YY_BUFFER_STATE b ) +{ + if ( ! b ) + return; + + b->yy_n_chars = 0; + + /* We always need two end-of-buffer characters. The first causes + * a transition to the end-of-buffer state. The second causes + * a jam in that state. + */ + b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR; + b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR; + + b->yy_buf_pos = &b->yy_ch_buf[0]; + + b->yy_at_bol = 1; + b->yy_buffer_status = YY_BUFFER_NEW; + + if ( b == YY_CURRENT_BUFFER ) + yy_load_buffer_state( ); +} + +/** Pushes the new state onto the stack. The new state becomes + * the current state. This function will allocate the stack + * if necessary. + * @param new_buffer The new state. + * + */ +void yyFlexLexer::yypush_buffer_state (YY_BUFFER_STATE new_buffer) +{ + if (new_buffer == NULL) + return; + + yyensure_buffer_stack(); + + /* This block is copied from yy_switch_to_buffer. */ + if ( YY_CURRENT_BUFFER ) + { + /* Flush out information for old buffer. */ + *(yy_c_buf_p) = (yy_hold_char); + YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); + } + + /* Only push if top exists. Otherwise, replace top. */ + if (YY_CURRENT_BUFFER) + (yy_buffer_stack_top)++; + YY_CURRENT_BUFFER_LVALUE = new_buffer; + + /* copied from yy_switch_to_buffer. */ + yy_load_buffer_state( ); + (yy_did_buffer_switch_on_eof) = 1; +} + +/** Removes and deletes the top of the stack, if present. + * The next element becomes the new top. + * + */ +void yyFlexLexer::yypop_buffer_state (void) +{ + if (!YY_CURRENT_BUFFER) + return; + + yy_delete_buffer(YY_CURRENT_BUFFER ); + YY_CURRENT_BUFFER_LVALUE = NULL; + if ((yy_buffer_stack_top) > 0) + --(yy_buffer_stack_top); + + if (YY_CURRENT_BUFFER) { + yy_load_buffer_state( ); + (yy_did_buffer_switch_on_eof) = 1; + } +} + +/* Allocates the stack if it does not exist. + * Guarantees space for at least one push. + */ +void yyFlexLexer::yyensure_buffer_stack(void) +{ + yy_size_t num_to_alloc; + + if (!(yy_buffer_stack)) { + + /* First allocation is just for 2 elements, since we don't know if this + * scanner will even need a stack. We use 2 instead of 1 to avoid an + * immediate realloc on the next call. + */ + num_to_alloc = 1; + (yy_buffer_stack) = (struct yy_buffer_state**)yyalloc + (num_to_alloc * sizeof(struct yy_buffer_state*) + ); + if ( ! (yy_buffer_stack) ) + YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" ); + + memset((yy_buffer_stack), 0, num_to_alloc * sizeof(struct yy_buffer_state*)); + + (yy_buffer_stack_max) = num_to_alloc; + (yy_buffer_stack_top) = 0; + return; + } + + if ((yy_buffer_stack_top) >= ((yy_buffer_stack_max)) - 1){ + + /* Increase the buffer to prepare for a possible push. */ + int grow_size = 8 /* arbitrary grow size */; + + num_to_alloc = (yy_buffer_stack_max) + grow_size; + (yy_buffer_stack) = (struct yy_buffer_state**)yyrealloc + ((yy_buffer_stack), + num_to_alloc * sizeof(struct yy_buffer_state*) + ); + if ( ! (yy_buffer_stack) ) + YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" ); + + /* zero only the new slots.*/ + memset((yy_buffer_stack) + (yy_buffer_stack_max), 0, grow_size * sizeof(struct yy_buffer_state*)); + (yy_buffer_stack_max) = num_to_alloc; + } +} + + void yyFlexLexer::yy_push_state( int new_state ) +{ + if ( (yy_start_stack_ptr) >= (yy_start_stack_depth) ) + { + yy_size_t new_size; + + (yy_start_stack_depth) += YY_START_STACK_INCR; + new_size = (yy_start_stack_depth) * sizeof( int ); + + if ( ! (yy_start_stack) ) + (yy_start_stack) = (int *) yyalloc(new_size ); + + else + (yy_start_stack) = (int *) yyrealloc((void *) (yy_start_stack),new_size ); + + if ( ! (yy_start_stack) ) + YY_FATAL_ERROR( "out of memory expanding start-condition stack" ); + } + + (yy_start_stack)[(yy_start_stack_ptr)++] = YY_START; + + BEGIN(new_state); +} + + void yyFlexLexer::yy_pop_state() +{ + if ( --(yy_start_stack_ptr) < 0 ) + YY_FATAL_ERROR( "start-condition stack underflow" ); + + BEGIN((yy_start_stack)[(yy_start_stack_ptr)]); +} + + int yyFlexLexer::yy_top_state() +{ + return (yy_start_stack)[(yy_start_stack_ptr) - 1]; +} + +#ifndef YY_EXIT_FAILURE +#define YY_EXIT_FAILURE 2 +#endif + +void yyFlexLexer::LexerError( yyconst char msg[] ) +{ + std::cerr << msg << std::endl; + exit( YY_EXIT_FAILURE ); +} + +/* Redefine yyless() so it works in section 3 code. */ + +#undef yyless +#define yyless(n) \ + do \ + { \ + /* Undo effects of setting up yytext. */ \ + int yyless_macro_arg = (n); \ + YY_LESS_LINENO(yyless_macro_arg);\ + yytext[yyleng] = (yy_hold_char); \ + (yy_c_buf_p) = yytext + yyless_macro_arg; \ + (yy_hold_char) = *(yy_c_buf_p); \ + *(yy_c_buf_p) = '\0'; \ + yyleng = yyless_macro_arg; \ + } \ + while ( 0 ) + +/* Accessor methods (get/set functions) to struct members. */ + +/* + * Internal utility routines. + */ + +#ifndef yytext_ptr +static void yy_flex_strncpy (char* s1, yyconst char * s2, int n ) +{ + register int i; + for ( i = 0; i < n; ++i ) + s1[i] = s2[i]; +} +#endif + +#ifdef YY_NEED_STRLEN +static int yy_flex_strlen (yyconst char * s ) +{ + register int n; + for ( n = 0; s[n]; ++n ) + ; + + return n; +} +#endif + +void *yyalloc (yy_size_t size ) +{ + return (void *) malloc( size ); +} + +void *yyrealloc (void * ptr, yy_size_t size ) +{ + /* The cast to (char *) in the following accommodates both + * implementations that use char* generic pointers, and those + * that use void* generic pointers. It works with the latter + * because both ANSI C and C++ allow castless assignment from + * any pointer type to void*, and deal with argument conversions + * as though doing an assignment. + */ + return (void *) realloc( (char *) ptr, size ); +} + +void yyfree (void * ptr ) +{ + free( (char *) ptr ); /* see yyrealloc() for (char *) cast */ +} + +#define YYTABLES_NAME "yytables" + +#line 291 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_lexer.l" + + + +// verbatim code copied to the bottom of the output + + + diff --git a/elftosb2/elftosb_lexer.l b/elftosb2/elftosb_lexer.l new file mode 100644 index 0000000..23272b7 --- /dev/null +++ b/elftosb2/elftosb_lexer.l @@ -0,0 +1,299 @@ +/* + * Copyright (c) Freescale Semiconductor, Inc. All rights reserved. + * See included license file for license details. + */ + +%option c++ +/* %option prefix="Elftosb" */ +%option yylineno +%option never-interactive +%option yyclass="ElftosbLexer" +%option noyywrap + +%{ +#include "ElftosbLexer.h" +#include <stdlib.h> +#include <limits.h> +#include <string> +#include "HexValues.h" +#include "Value.h" + +using namespace elftosb; + +//! Always executed before all other actions when a token is matched. +//! This action just assign the first and last lines of the token to +//! the current line. In most cases this is correct. +#define YY_USER_ACTION do { \ + m_location.m_firstLine = m_line; \ + m_location.m_lastLine = m_line; \ + } while (0); + +%} + +DIGIT [0-9] +HEXDIGIT [0-9a-fA-F] +BINDIGIT [0-1] +IDENT [a-zA-Z_][a-zA-Z0-9_]* +ESC \\(x{HEXDIGIT}{2}|.) + +/* start conditions */ +%x blob mlcmt + +%% + +options { return TOK_OPTIONS; } +constants { return TOK_CONSTANTS; } +sources { return TOK_SOURCES; } +filters { return TOK_FILTERS; } +section { return TOK_SECTION; } +extern { return TOK_EXTERN; } +from { return TOK_FROM; } +raw { return TOK_RAW; } +load { return TOK_LOAD; } +jump { return TOK_JUMP; } +call { return TOK_CALL; } +mode { return TOK_MODE; } +if { return TOK_IF; } +else { return TOK_ELSE; } +defined { return TOK_DEFINED; } +info { return TOK_INFO; } +warning { return TOK_WARNING; } +error { return TOK_ERROR; } +sizeof { return TOK_SIZEOF; } +dcd { return TOK_DCD; } +hab { return TOK_HAB; } +ivt { return TOK_IVT; } + +[whb]/[^a-zA-Z_0-9] { // must be followed by any non-ident char + int_size_t theSize; + switch (yytext[0]) + { + case 'w': + theSize = kWordSize; + break; + case 'h': + theSize = kHalfWordSize; + break; + case 'b': + theSize = kByteSize; + break; + } + m_symbolValue.m_int = new elftosb::SizedIntegerValue(0, theSize); + return TOK_INT_SIZE; + } + +true|yes { + m_symbolValue.m_int = new elftosb::SizedIntegerValue(1, kWordSize); + return TOK_INT_LITERAL; + } + +false|no { + m_symbolValue.m_int = new elftosb::SizedIntegerValue(0, kWordSize); + return TOK_INT_LITERAL; + } + +{IDENT} { + m_symbolValue.m_str = new std::string(yytext); + if (isSourceName(m_symbolValue.m_str)) + { + return TOK_SOURCE_NAME; + } + else + { + return TOK_IDENT; + } + } + +({DIGIT}+|0x{HEXDIGIT}+|0b{BINDIGIT}+)([ \t]*[GMK])? { + int base = 0; + uint32_t value; + int mult; + + // check for binary number + if (yytext[0] == '0' && yytext[1] == 'b') + { + base = 2; // this is a binary number + yytext += 2; // skip over the "0b" + } + + // convert value + value = (uint32_t)strtoul(yytext, NULL, base); + + // find multiplier + switch (yytext[strlen(yytext) - 1]) + { + case 'G': + mult = 1024 * 1024 * 1024; + break; + case 'M': + mult = 1024 * 1024; + break; + case 'K': + mult = 1024; + break; + default: + mult = 1; + break; + } + + // set resulting symbol value + m_symbolValue.m_int = new elftosb::SizedIntegerValue(value * mult, kWordSize); + return TOK_INT_LITERAL; + } + +\'(.|ESC)\'|\'(.|ESC){2}\'|\'(.|ESC){4}\' { + uint32_t value = 0; + int_size_t theSize; + int len = strlen(yytext); + if (len >= 3) + { + value = yytext[1]; + theSize = kByteSize; + } + if (len >= 4) + { + value = (value << 8) | yytext[2]; + theSize = kHalfWordSize; + } + if (len >= 6) + { + value = (value << 8) | yytext[3]; + value = (value << 8) | yytext[4]; + theSize = kWordSize; + } + m_symbolValue.m_int = new elftosb::SizedIntegerValue(value, theSize); + return TOK_INT_LITERAL; + } + +\$[\.\*a-zA-Z0-9_\[\]\^\?\-]+ { + // remove $ from string + m_symbolValue.m_str = new std::string(&yytext[1]); + return TOK_SECTION_NAME; + } + + +"/*" { BEGIN(mlcmt); } + +"{{" { + m_blob = new Blob(); + m_blobFirstLine = yylineno; + BEGIN(blob); + } + +"{" { return '{'; } + +"}" { return '}'; } + +"(" { return '('; } + +")" { return ')'; } + +"[" { return '['; } + +"]" { return ']'; } + +"=" { return '='; } + +"," { return ','; } + +":" { return ':'; } + +";" { return ';'; } + +"." { return '.'; } + +">" { return '>'; } + +".." { return TOK_DOT_DOT; } + +"+" { return '+'; } + +"-" { return '-'; } + +"*" { return '*'; } + +"/" { return '/'; } + +"%" { return '%'; } + +"~" { return '~'; } + +"^" { return '^'; } + +"<<" { return TOK_LSHIFT; } + +">>" { return TOK_RSHIFT; } + +"&" { return '&'; } + +"|" { return '|'; } + +"**" { return TOK_POWER; } + +"<" { return '<'; } + +">=" { return TOK_GEQ; } + +"<=" { return TOK_LEQ; } + +"==" { return TOK_EQ; } + +"!=" { return TOK_NEQ; } + +"&&" { return TOK_AND; } + +"||" { return TOK_OR; } + +"!" { return '!'; } + +\"(ESC|[^\"])*\" { + // get rid of quotes + yytext++; + yytext[strlen(yytext) - 1] = 0; +// processStringEscapes(yytext, yytext); + m_symbolValue.m_str = new std::string(yytext); + return TOK_STRING_LITERAL; + } + +<blob>{HEXDIGIT}{2} { + uint8_t x = (hexCharToInt(yytext[0]) << 4) | hexCharToInt(yytext[1]); + m_blob->append(&x, 1); + } + +<blob>"}}" { + BEGIN(INITIAL); + m_symbolValue.m_blob = m_blob; + m_blob = NULL; + m_location.m_firstLine = m_blobFirstLine; + return TOK_BLOB; + } + +<mlcmt>\*\/ { + // end of multi-line comment, return to initial state + BEGIN(INITIAL); + } + + +(#|\/\/).*$ /* absorb single-line comment */ + +<*>[ \t] /* eat up whitespace in all states */ + +<*>(\r\n|\r|\n) { + /* eat up whitespace and count lines in all states */ + m_line++; + } + +<mlcmt>. /* ignore all other chars in a multi-line comment */ + +<*>. { + /* all other chars produce errors */ + char msg[50]; + sprintf(msg, "unexpected character '%c' on line %d", yytext[0], m_line); + LexerError(msg); + } + +%% + +// verbatim code copied to the bottom of the output + + diff --git a/elftosb2/elftosb_parser.tab.cpp b/elftosb2/elftosb_parser.tab.cpp new file mode 100644 index 0000000..731ca45 --- /dev/null +++ b/elftosb2/elftosb_parser.tab.cpp @@ -0,0 +1,2955 @@ +/* A Bison parser, made by GNU Bison 2.1. */ + +/* Skeleton parser for Yacc-like parsing with Bison, + Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. */ + +/* As a special exception, when this file is copied by Bison into a + Bison output file, you may use that output file without restriction. + This special exception was added by the Free Software Foundation + in version 1.24 of Bison. */ + +/* Written by Richard Stallman by simplifying the original so called + ``semantic'' parser. */ + +/* All symbols defined below should begin with yy or YY, to avoid + infringing on user name space. This should be done even for local + variables, as they might otherwise be expanded by user macros. + There are some unavoidable exceptions within include files to + define necessary library symbols; they are noted "INFRINGES ON + USER NAME SPACE" below. */ + +/* Identify Bison output. */ +#define YYBISON 1 + +/* Bison version. */ +#define YYBISON_VERSION "2.1" + +/* Skeleton name. */ +#define YYSKELETON_NAME "yacc.c" + +/* Pure parsers. */ +#define YYPURE 1 + +/* Using locations. */ +#define YYLSP_NEEDED 1 + + + +/* Tokens. */ +#ifndef YYTOKENTYPE +# define YYTOKENTYPE + /* Put the tokens into the symbol table, so that GDB and other debuggers + know about them. */ + enum yytokentype { + TOK_IDENT = 258, + TOK_STRING_LITERAL = 259, + TOK_INT_LITERAL = 260, + TOK_SECTION_NAME = 261, + TOK_SOURCE_NAME = 262, + TOK_BLOB = 263, + TOK_DOT_DOT = 264, + TOK_AND = 265, + TOK_OR = 266, + TOK_GEQ = 267, + TOK_LEQ = 268, + TOK_EQ = 269, + TOK_NEQ = 270, + TOK_POWER = 271, + TOK_LSHIFT = 272, + TOK_RSHIFT = 273, + TOK_INT_SIZE = 274, + TOK_OPTIONS = 275, + TOK_CONSTANTS = 276, + TOK_SOURCES = 277, + TOK_FILTERS = 278, + TOK_SECTION = 279, + TOK_EXTERN = 280, + TOK_FROM = 281, + TOK_RAW = 282, + TOK_LOAD = 283, + TOK_JUMP = 284, + TOK_CALL = 285, + TOK_MODE = 286, + TOK_IF = 287, + TOK_ELSE = 288, + TOK_DEFINED = 289, + TOK_INFO = 290, + TOK_WARNING = 291, + TOK_ERROR = 292, + TOK_SIZEOF = 293, + TOK_DCD = 294, + TOK_HAB = 295, + TOK_IVT = 296, + UNARY_OP = 297 + }; +#endif +/* Tokens. */ +#define TOK_IDENT 258 +#define TOK_STRING_LITERAL 259 +#define TOK_INT_LITERAL 260 +#define TOK_SECTION_NAME 261 +#define TOK_SOURCE_NAME 262 +#define TOK_BLOB 263 +#define TOK_DOT_DOT 264 +#define TOK_AND 265 +#define TOK_OR 266 +#define TOK_GEQ 267 +#define TOK_LEQ 268 +#define TOK_EQ 269 +#define TOK_NEQ 270 +#define TOK_POWER 271 +#define TOK_LSHIFT 272 +#define TOK_RSHIFT 273 +#define TOK_INT_SIZE 274 +#define TOK_OPTIONS 275 +#define TOK_CONSTANTS 276 +#define TOK_SOURCES 277 +#define TOK_FILTERS 278 +#define TOK_SECTION 279 +#define TOK_EXTERN 280 +#define TOK_FROM 281 +#define TOK_RAW 282 +#define TOK_LOAD 283 +#define TOK_JUMP 284 +#define TOK_CALL 285 +#define TOK_MODE 286 +#define TOK_IF 287 +#define TOK_ELSE 288 +#define TOK_DEFINED 289 +#define TOK_INFO 290 +#define TOK_WARNING 291 +#define TOK_ERROR 292 +#define TOK_SIZEOF 293 +#define TOK_DCD 294 +#define TOK_HAB 295 +#define TOK_IVT 296 +#define UNARY_OP 297 + + + + +/* Copy the first part of user declarations. */ +#line 14 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + +#include "ElftosbLexer.h" +#include "ElftosbAST.h" +#include "Logging.h" +#include "Blob.h" +#include "format_string.h" +#include "Value.h" +#include "ConversionController.h" + +using namespace elftosb; + +//! Our special location type. +#define YYLTYPE token_loc_t + +// this indicates that we're using our own type. it should be unset automatically +// but that's not working for some reason with the .hpp file. +#if defined(YYLTYPE_IS_TRIVIAL) + #undef YYLTYPE_IS_TRIVIAL + #define YYLTYPE_IS_TRIVIAL 0 +#endif + +//! Default location action +#define YYLLOC_DEFAULT(Current, Rhs, N) \ + do { \ + if (N) \ + { \ + (Current).m_firstLine = YYRHSLOC(Rhs, 1).m_firstLine; \ + (Current).m_lastLine = YYRHSLOC(Rhs, N).m_lastLine; \ + } \ + else \ + { \ + (Current).m_firstLine = (Current).m_lastLine = YYRHSLOC(Rhs, 0).m_lastLine; \ + } \ + } while (0) + +//! Forward declaration of yylex(). +static int yylex(YYSTYPE * lvalp, YYLTYPE * yylloc, ElftosbLexer * lexer); + +// Forward declaration of error handling function. +static void yyerror(YYLTYPE * yylloc, ElftosbLexer * lexer, CommandFileASTNode ** resultAST, const char * error); + + + +/* Enabling traces. */ +#ifndef YYDEBUG +# define YYDEBUG 0 +#endif + +/* Enabling verbose error messages. */ +#ifdef YYERROR_VERBOSE +# undef YYERROR_VERBOSE +# define YYERROR_VERBOSE 1 +#else +# define YYERROR_VERBOSE 1 +#endif + +/* Enabling the token table. */ +#ifndef YYTOKEN_TABLE +# define YYTOKEN_TABLE 0 +#endif + +#if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED) +#line 58 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" +typedef union YYSTYPE { + int m_num; + elftosb::SizedIntegerValue * m_int; + Blob * m_blob; + std::string * m_str; + elftosb::ASTNode * m_ast; // must use full name here because this is put into *.tab.hpp +} YYSTYPE; +/* Line 196 of yacc.c. */ +#line 220 "/Users/creed/projects/fsl/fromsvr/elftosb/build/elftosb.build/Debug/elftosb.build/DerivedSources/elftosb_parser.tab.cpp" +# define yystype YYSTYPE /* obsolescent; will be withdrawn */ +# define YYSTYPE_IS_DECLARED 1 +# define YYSTYPE_IS_TRIVIAL 1 +#endif + +#if ! defined (YYLTYPE) && ! defined (YYLTYPE_IS_DECLARED) +typedef struct YYLTYPE +{ + int first_line; + int first_column; + int last_line; + int last_column; +} YYLTYPE; +# define yyltype YYLTYPE /* obsolescent; will be withdrawn */ +# define YYLTYPE_IS_DECLARED 1 +# define YYLTYPE_IS_TRIVIAL 1 +#endif + + +/* Copy the second part of user declarations. */ + + +/* Line 219 of yacc.c. */ +#line 244 "/Users/creed/projects/fsl/fromsvr/elftosb/build/elftosb.build/Debug/elftosb.build/DerivedSources/elftosb_parser.tab.cpp" + +#if ! defined (YYSIZE_T) && defined (__SIZE_TYPE__) +# define YYSIZE_T __SIZE_TYPE__ +#endif +#if ! defined (YYSIZE_T) && defined (size_t) +# define YYSIZE_T size_t +#endif +#if ! defined (YYSIZE_T) && (defined (__STDC__) || defined (__cplusplus)) +# include <stddef.h> /* INFRINGES ON USER NAME SPACE */ +# define YYSIZE_T size_t +#endif +#if ! defined (YYSIZE_T) +# define YYSIZE_T unsigned int +#endif + +#ifndef YY_ +# if YYENABLE_NLS +# if ENABLE_NLS +# include <libintl.h> /* INFRINGES ON USER NAME SPACE */ +# define YY_(msgid) dgettext ("bison-runtime", msgid) +# endif +# endif +# ifndef YY_ +# define YY_(msgid) msgid +# endif +#endif + +#if ! defined (yyoverflow) || YYERROR_VERBOSE + +/* The parser invokes alloca or malloc; define the necessary symbols. */ + +# ifdef YYSTACK_USE_ALLOCA +# if YYSTACK_USE_ALLOCA +# ifdef __GNUC__ +# define YYSTACK_ALLOC __builtin_alloca +# else +# define YYSTACK_ALLOC alloca +# if defined (__STDC__) || defined (__cplusplus) +# include <stdlib.h> /* INFRINGES ON USER NAME SPACE */ +# define YYINCLUDED_STDLIB_H +# endif +# endif +# endif +# endif + +# ifdef YYSTACK_ALLOC + /* Pacify GCC's `empty if-body' warning. */ +# define YYSTACK_FREE(Ptr) do { /* empty */; } while (0) +# ifndef YYSTACK_ALLOC_MAXIMUM + /* The OS might guarantee only one guard page at the bottom of the stack, + and a page size can be as small as 4096 bytes. So we cannot safely + invoke alloca (N) if N exceeds 4096. Use a slightly smaller number + to allow for a few compiler-allocated temporary stack slots. */ +# define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2005 */ +# endif +# else +# define YYSTACK_ALLOC YYMALLOC +# define YYSTACK_FREE YYFREE +# ifndef YYSTACK_ALLOC_MAXIMUM +# define YYSTACK_ALLOC_MAXIMUM ((YYSIZE_T) -1) +# endif +# ifdef __cplusplus +extern "C" { +# endif +# ifndef YYMALLOC +# define YYMALLOC malloc +# if (! defined (malloc) && ! defined (YYINCLUDED_STDLIB_H) \ + && (defined (__STDC__) || defined (__cplusplus))) +void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */ +# endif +# endif +# ifndef YYFREE +# define YYFREE free +# if (! defined (free) && ! defined (YYINCLUDED_STDLIB_H) \ + && (defined (__STDC__) || defined (__cplusplus))) +void free (void *); /* INFRINGES ON USER NAME SPACE */ +# endif +# endif +# ifdef __cplusplus +} +# endif +# endif +#endif /* ! defined (yyoverflow) || YYERROR_VERBOSE */ + + +#if (! defined (yyoverflow) \ + && (! defined (__cplusplus) \ + || (defined (YYLTYPE_IS_TRIVIAL) && YYLTYPE_IS_TRIVIAL \ + && defined (YYSTYPE_IS_TRIVIAL) && YYSTYPE_IS_TRIVIAL))) + +/* A type that is properly aligned for any stack member. */ +union yyalloc +{ + short int yyss; + YYSTYPE yyvs; + YYLTYPE yyls; +}; + +/* The size of the maximum gap between one aligned stack and the next. */ +# define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1) + +/* The size of an array large to enough to hold all stacks, each with + N elements. */ +# define YYSTACK_BYTES(N) \ + ((N) * (sizeof (short int) + sizeof (YYSTYPE) + sizeof (YYLTYPE)) \ + + 2 * YYSTACK_GAP_MAXIMUM) + +/* Copy COUNT objects from FROM to TO. The source and destination do + not overlap. */ +# ifndef YYCOPY +# if defined (__GNUC__) && 1 < __GNUC__ +# define YYCOPY(To, From, Count) \ + __builtin_memcpy (To, From, (Count) * sizeof (*(From))) +# else +# define YYCOPY(To, From, Count) \ + do \ + { \ + YYSIZE_T yyi; \ + for (yyi = 0; yyi < (Count); yyi++) \ + (To)[yyi] = (From)[yyi]; \ + } \ + while (0) +# endif +# endif + +/* Relocate STACK from its old location to the new one. The + local variables YYSIZE and YYSTACKSIZE give the old and new number of + elements in the stack, and YYPTR gives the new location of the + stack. Advance YYPTR to a properly aligned location for the next + stack. */ +# define YYSTACK_RELOCATE(Stack) \ + do \ + { \ + YYSIZE_T yynewbytes; \ + YYCOPY (&yyptr->Stack, Stack, yysize); \ + Stack = &yyptr->Stack; \ + yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \ + yyptr += yynewbytes / sizeof (*yyptr); \ + } \ + while (0) + +#endif + +#if defined (__STDC__) || defined (__cplusplus) + typedef signed char yysigned_char; +#else + typedef short int yysigned_char; +#endif + +/* YYFINAL -- State number of the termination state. */ +#define YYFINAL 13 +/* YYLAST -- Last index in YYTABLE. */ +#define YYLAST 418 + +/* YYNTOKENS -- Number of terminals. */ +#define YYNTOKENS 66 +/* YYNNTS -- Number of nonterminals. */ +#define YYNNTS 52 +/* YYNRULES -- Number of rules. */ +#define YYNRULES 133 +/* YYNRULES -- Number of states. */ +#define YYNSTATES 238 + +/* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */ +#define YYUNDEFTOK 2 +#define YYMAXUTOK 297 + +#define YYTRANSLATE(YYX) \ + ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK) + +/* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */ +static const unsigned char yytranslate[] = +{ + 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 26, 2, 2, 2, 64, 23, 2, + 9, 10, 62, 60, 16, 61, 20, 63, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 18, 17, + 25, 15, 19, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 13, 2, 14, 59, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 11, 24, 12, 22, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 1, 2, 3, 4, + 5, 6, 7, 8, 21, 27, 28, 29, 30, 31, + 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, + 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, + 52, 53, 54, 55, 56, 57, 58, 65 +}; + +#if YYDEBUG +/* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in + YYRHS. */ +static const unsigned short int yyprhs[] = +{ + 0, 0, 3, 6, 8, 11, 13, 15, 17, 22, + 27, 29, 32, 35, 36, 40, 45, 47, 50, 54, + 55, 59, 66, 70, 71, 73, 77, 81, 83, 86, + 93, 96, 97, 99, 100, 104, 108, 110, 113, 116, + 118, 120, 121, 123, 126, 129, 131, 132, 134, 136, + 138, 140, 145, 147, 148, 150, 152, 154, 156, 160, + 165, 167, 169, 171, 175, 177, 180, 183, 184, 186, + 188, 193, 195, 196, 200, 205, 207, 209, 211, 213, + 217, 220, 221, 227, 230, 233, 236, 239, 246, 251, + 254, 255, 257, 261, 263, 265, 267, 271, 275, 279, + 283, 287, 291, 295, 299, 302, 307, 311, 316, 318, + 322, 325, 327, 329, 331, 335, 339, 343, 347, 351, + 355, 359, 363, 367, 371, 375, 377, 381, 385, 390, + 395, 400, 403, 406 +}; + +/* YYRHS -- A `-1'-separated list of the rules' RHS. */ +static const yysigned_char yyrhs[] = +{ + 67, 0, -1, 68, 82, -1, 69, -1, 68, 69, + -1, 70, -1, 71, -1, 75, -1, 37, 11, 72, + 12, -1, 38, 11, 72, 12, -1, 73, -1, 72, + 73, -1, 74, 17, -1, -1, 3, 15, 111, -1, + 39, 11, 76, 12, -1, 77, -1, 76, 77, -1, + 78, 79, 17, -1, -1, 3, 15, 4, -1, 3, + 15, 42, 9, 113, 10, -1, 9, 80, 10, -1, + -1, 81, -1, 80, 16, 81, -1, 3, 15, 111, + -1, 83, -1, 82, 83, -1, 41, 9, 113, 84, + 10, 86, -1, 17, 85, -1, -1, 80, -1, -1, + 30, 94, 17, -1, 11, 87, 12, -1, 88, -1, + 87, 88, -1, 91, 17, -1, 105, -1, 108, -1, + -1, 90, -1, 89, 90, -1, 91, 17, -1, 108, + -1, -1, 92, -1, 101, -1, 106, -1, 107, -1, + 45, 93, 94, 97, -1, 56, -1, -1, 113, -1, + 4, -1, 7, -1, 95, -1, 95, 43, 7, -1, + 7, 13, 95, 14, -1, 8, -1, 99, -1, 96, + -1, 95, 16, 96, -1, 6, -1, 22, 6, -1, + 19, 98, -1, -1, 20, -1, 110, -1, 58, 9, + 100, 10, -1, 80, -1, -1, 102, 103, 104, -1, + 57, 102, 110, 104, -1, 47, -1, 46, -1, 7, + -1, 113, -1, 9, 113, 10, -1, 9, 10, -1, + -1, 43, 7, 11, 89, 12, -1, 48, 113, -1, + 52, 4, -1, 53, 4, -1, 54, 4, -1, 49, + 112, 11, 87, 12, 109, -1, 50, 11, 87, 12, + -1, 50, 108, -1, -1, 113, -1, 113, 21, 113, + -1, 112, -1, 4, -1, 113, -1, 112, 25, 112, + -1, 112, 19, 112, -1, 112, 29, 112, -1, 112, + 30, 112, -1, 112, 31, 112, -1, 112, 32, 112, + -1, 112, 27, 112, -1, 112, 28, 112, -1, 26, + 112, -1, 3, 9, 7, 10, -1, 9, 112, 10, + -1, 51, 9, 3, 10, -1, 115, -1, 7, 18, + 3, -1, 18, 3, -1, 117, -1, 3, -1, 114, + -1, 115, 60, 115, -1, 115, 61, 115, -1, 115, + 62, 115, -1, 115, 63, 115, -1, 115, 64, 115, + -1, 115, 33, 115, -1, 115, 23, 115, -1, 115, + 24, 115, -1, 115, 59, 115, -1, 115, 34, 115, + -1, 115, 35, 115, -1, 116, -1, 115, 20, 36, + -1, 9, 115, 10, -1, 55, 9, 114, 10, -1, + 55, 9, 3, 10, -1, 55, 9, 7, 10, -1, + 60, 115, -1, 61, 115, -1, 5, -1 +}; + +/* YYRLINE[YYN] -- source line where rule number YYN was defined. */ +static const unsigned short int yyrline[] = +{ + 0, 162, 162, 172, 178, 186, 187, 188, 191, 197, + 203, 209, 216, 217, 220, 227, 233, 239, 247, 259, + 262, 267, 275, 276, 280, 286, 294, 301, 307, 314, + 329, 334, 340, 345, 351, 357, 365, 371, 379, 380, + 381, 382, 385, 391, 399, 400, 401, 404, 405, 406, + 407, 410, 433, 443, 445, 449, 454, 459, 464, 469, + 474, 479, 484, 490, 498, 503, 510, 515, 521, 526, + 532, 544, 545, 548, 577, 614, 615, 618, 623, 630, + 631, 632, 635, 642, 649, 654, 659, 666, 677, 681, + 688, 691, 696, 703, 707, 714, 718, 725, 732, 739, + 746, 753, 760, 767, 774, 779, 784, 789, 796, 799, + 804, 812, 816, 821, 832, 839, 846, 853, 860, 867, + 874, 881, 888, 895, 902, 909, 913, 918, 923, 928, + 933, 940, 944, 951 +}; +#endif + +#if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE +/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. + First, the terminals, then, starting at YYNTOKENS, nonterminals. */ +static const char *const yytname[] = +{ + "$end", "error", "$undefined", "\"identifier\"", "\"string\"", + "\"integer\"", "\"section name\"", "\"source name\"", + "\"binary object\"", "'('", "')'", "'{'", "'}'", "'['", "']'", "'='", + "','", "';'", "':'", "'>'", "'.'", "\"..\"", "'~'", "'&'", "'|'", "'<'", + "'!'", "\"&&\"", "\"||\"", "\">=\"", "\"<=\"", "\"==\"", "\"!=\"", + "\"**\"", "\"<<\"", "\">>\"", "\"integer size\"", "\"options\"", + "\"constants\"", "\"sources\"", "\"filters\"", "\"section\"", + "\"extern\"", "\"from\"", "\"raw\"", "\"load\"", "\"jump\"", "\"call\"", + "\"mode\"", "\"if\"", "\"else\"", "\"defined\"", "\"info\"", + "\"warning\"", "\"error\"", "\"sizeof\"", "\"dcd\"", "\"hab\"", + "\"ivt\"", "'^'", "'+'", "'-'", "'*'", "'/'", "'%'", "UNARY_OP", + "$accept", "command_file", "blocks_list", "pre_section_block", + "options_block", "constants_block", "const_def_list", + "const_def_list_elem", "const_def", "sources_block", "source_def_list", + "source_def_list_elem", "source_def", "source_attrs_opt", + "source_attr_list", "source_attr_list_elem", "section_defs", + "section_def", "section_options_opt", "source_attr_list_opt", + "section_contents", "full_stmt_list", "full_stmt_list_elem", + "basic_stmt_list", "basic_stmt_list_elem", "basic_stmt", "load_stmt", + "dcd_opt", "load_data", "section_list", "section_list_elem", + "load_target_opt", "load_target", "ivt_def", "assignment_list_opt", + "call_stmt", "call_or_jump", "call_target", "call_arg_opt", "from_stmt", + "mode_stmt", "message_stmt", "if_stmt", "else_opt", "address_or_range", + "const_expr", "bool_expr", "int_const_expr", "symbol_ref", "expr", + "unary_expr", "int_value", 0 +}; +#endif + +# ifdef YYPRINT +/* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to + token YYLEX-NUM. */ +static const unsigned short int yytoknum[] = +{ + 0, 256, 257, 258, 259, 260, 261, 262, 263, 40, + 41, 123, 125, 91, 93, 61, 44, 59, 58, 62, + 46, 264, 126, 38, 124, 60, 33, 265, 266, 267, + 268, 269, 270, 271, 272, 273, 274, 275, 276, 277, + 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, + 288, 289, 290, 291, 292, 293, 294, 295, 296, 94, + 43, 45, 42, 47, 37, 297 +}; +# endif + +/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ +static const unsigned char yyr1[] = +{ + 0, 66, 67, 68, 68, 69, 69, 69, 70, 71, + 72, 72, 73, 73, 74, 75, 76, 76, 77, 77, + 78, 78, 79, 79, 80, 80, 81, 82, 82, 83, + 84, 84, 85, 85, 86, 86, 87, 87, 88, 88, + 88, 88, 89, 89, 90, 90, 90, 91, 91, 91, + 91, 92, 93, 93, 94, 94, 94, 94, 94, 94, + 94, 94, 95, 95, 96, 96, 97, 97, 98, 98, + 99, 100, 100, 101, 101, 102, 102, 103, 103, 104, + 104, 104, 105, 106, 107, 107, 107, 108, 109, 109, + 109, 110, 110, 111, 111, 112, 112, 112, 112, 112, + 112, 112, 112, 112, 112, 112, 112, 112, 113, 114, + 114, 115, 115, 115, 115, 115, 115, 115, 115, 115, + 115, 115, 115, 115, 115, 115, 115, 115, 115, 115, + 115, 116, 116, 117 +}; + +/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */ +static const unsigned char yyr2[] = +{ + 0, 2, 2, 1, 2, 1, 1, 1, 4, 4, + 1, 2, 2, 0, 3, 4, 1, 2, 3, 0, + 3, 6, 3, 0, 1, 3, 3, 1, 2, 6, + 2, 0, 1, 0, 3, 3, 1, 2, 2, 1, + 1, 0, 1, 2, 2, 1, 0, 1, 1, 1, + 1, 4, 1, 0, 1, 1, 1, 1, 3, 4, + 1, 1, 1, 3, 1, 2, 2, 0, 1, 1, + 4, 1, 0, 3, 4, 1, 1, 1, 1, 3, + 2, 0, 5, 2, 2, 2, 2, 6, 4, 2, + 0, 1, 3, 1, 1, 1, 3, 3, 3, 3, + 3, 3, 3, 3, 2, 4, 3, 4, 1, 3, + 2, 1, 1, 1, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 1, 3, 3, 4, 4, + 4, 2, 2, 1 +}; + +/* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state + STATE-NUM when YYTABLE doesn't specify something else to do. Zero + means the default is an error. */ +static const unsigned char yydefact[] = +{ + 0, 0, 0, 0, 0, 0, 3, 5, 6, 7, + 13, 13, 19, 1, 0, 4, 2, 27, 0, 0, + 10, 0, 0, 0, 0, 16, 23, 0, 28, 0, + 8, 11, 12, 9, 0, 15, 17, 0, 0, 112, + 133, 0, 0, 0, 0, 0, 0, 31, 113, 108, + 125, 111, 112, 94, 0, 0, 0, 14, 93, 95, + 20, 0, 0, 0, 24, 18, 0, 0, 110, 0, + 131, 132, 33, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 108, 104, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 22, 0, 109, 127, 0, 0, 0, 32, 30, + 0, 126, 120, 121, 119, 123, 124, 122, 114, 115, + 116, 117, 118, 0, 106, 0, 97, 96, 102, 103, + 98, 99, 100, 101, 0, 26, 25, 129, 130, 128, + 41, 0, 29, 105, 107, 21, 0, 53, 76, 75, + 0, 0, 0, 0, 0, 0, 0, 36, 0, 47, + 48, 0, 39, 49, 50, 40, 55, 64, 56, 60, + 0, 0, 0, 57, 62, 61, 54, 0, 52, 0, + 83, 0, 84, 85, 86, 0, 35, 37, 38, 77, + 81, 78, 0, 65, 72, 34, 0, 0, 46, 67, + 41, 81, 91, 0, 73, 0, 71, 0, 63, 58, + 0, 42, 0, 45, 0, 51, 0, 74, 0, 80, + 0, 59, 70, 82, 43, 44, 68, 66, 69, 90, + 92, 79, 0, 87, 41, 89, 0, 88 +}; + +/* YYDEFGOTO[NTERM-NUM]. */ +static const short int yydefgoto[] = +{ + -1, 4, 5, 6, 7, 8, 19, 20, 21, 9, + 24, 25, 26, 38, 63, 64, 16, 17, 73, 109, + 142, 156, 157, 210, 211, 158, 159, 179, 172, 173, + 174, 215, 227, 175, 207, 160, 161, 190, 204, 162, + 163, 164, 165, 233, 201, 57, 58, 59, 48, 49, + 50, 51 +}; + +/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing + STATE-NUM. */ +#define YYPACT_NINF -181 +static const short int yypact[] = +{ + 128, 17, 25, 48, 69, 123, -181, -181, -181, -181, + 96, 96, 101, -181, 80, -181, 68, -181, 112, 85, + -181, 115, 89, 114, 91, -181, 124, 30, -181, 47, + -181, -181, -181, -181, 11, -181, -181, 134, 125, -181, + -181, 133, 30, 140, 144, 30, 30, 153, -181, 225, + -181, -181, 148, -181, 61, 61, 162, -181, 359, -181, + -181, 164, 159, 22, -181, -181, 172, 121, -181, 9, + -181, -181, 134, 168, 143, 30, 30, 30, 30, 30, + 30, 30, 30, 30, 30, 30, 179, 303, 121, -181, + 194, 61, 61, 61, 61, 61, 61, 61, 61, 30, + 47, -181, 134, -181, -181, 188, 4, 200, 199, -181, + 56, -181, 241, 231, 236, 86, 86, 247, 76, 76, + 196, 196, 196, 208, -181, 210, -181, -181, 373, 373, + -181, -181, -181, -181, 216, -181, -181, -181, -181, -181, + 314, 2, -181, -181, -181, -181, 220, 175, -181, -181, + 30, 61, 228, 230, 237, 28, 147, -181, 223, -181, + -181, 108, -181, -181, -181, -181, -181, -181, 92, -181, + 240, 243, 233, 15, -181, -181, -181, 242, -181, 2, + -181, 345, -181, -181, -181, 30, -181, -181, -181, 133, + 246, -181, 7, -181, 134, -181, 7, 250, 361, 244, + 314, 246, 248, 16, -181, 104, 199, 252, -181, -181, + 190, -181, 251, -181, 75, -181, 160, -181, 30, -181, + 261, -181, -181, -181, -181, -181, -181, -181, -181, 222, + -181, -181, 6, -181, 314, -181, 176, -181 +}; + +/* YYPGOTO[NTERM-NUM]. */ +static const short int yypgoto[] = +{ + -181, -181, -181, 268, -181, -181, 266, 106, -181, -181, + -181, 254, -181, -181, -70, 177, -181, 267, -181, -181, + -181, -151, -155, -181, 107, -180, -181, -181, 127, 122, + 129, -181, -181, -181, -181, -181, 163, -181, 118, -181, + -181, -181, -21, -181, 109, 221, -51, -27, 257, 270, + -181, -181 +}; + +/* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If + positive, shift that token. If negative, reduce the rule which + number is the opposite. If zero, do what YYDEFACT says. + If YYTABLE_NINF, syntax error. */ +#define YYTABLE_NINF -1 +static const unsigned char yytable[] = +{ + 47, 187, 108, 87, 89, 39, 166, 40, 167, 168, + 169, 42, 105, 167, 138, 60, 106, 234, 212, 39, + 43, 40, 66, 41, 170, 42, 219, 43, 10, 170, + 212, 196, 101, 39, 43, 40, 11, 41, 102, 42, + 126, 127, 128, 129, 130, 131, 132, 133, 43, 216, + 52, 53, 40, 61, 41, 151, 54, 44, 197, 12, + 171, 187, 45, 46, 52, 43, 40, 140, 41, 13, + 54, 44, 134, 55, 148, 149, 45, 46, 39, 43, + 40, 187, 41, 236, 42, 44, 141, 55, 18, 27, + 45, 46, 18, 43, 23, 226, 74, 30, 56, 18, + 181, 33, 44, 35, 23, 192, 74, 45, 46, 14, + 66, 39, 56, 40, 176, 189, 44, 42, 221, 77, + 196, 45, 46, 180, 206, 31, 43, 29, 31, 34, + 44, 104, 32, 37, 191, 45, 46, 62, 83, 84, + 85, 74, 65, 68, 75, 76, 81, 82, 83, 84, + 85, 66, 176, 69, 77, 78, 79, 86, 202, 186, + 1, 2, 3, 44, 14, 1, 2, 3, 45, 46, + 72, 90, 229, 99, 100, 103, 220, 213, 110, 111, + 80, 81, 82, 83, 84, 85, 123, 202, 237, 213, + 146, 230, 147, 148, 149, 150, 151, 125, 137, 152, + 153, 154, 223, 146, 155, 147, 148, 149, 150, 151, + 139, 235, 152, 153, 154, 102, 74, 155, 143, 146, + 144, 147, 148, 149, 150, 151, 145, 177, 152, 153, + 154, 178, 182, 155, 183, 147, 148, 149, 150, 151, + 188, 184, 152, 153, 154, 74, 193, 155, 75, 76, + 195, 74, 194, 198, 75, 203, 74, 209, 77, 78, + 79, 74, 222, 214, 77, 78, 79, 74, 225, 218, + 75, 231, 232, 15, 77, 78, 79, 22, 36, 136, + 77, 78, 79, 28, 80, 81, 82, 83, 84, 85, + 80, 81, 82, 83, 84, 85, 81, 82, 83, 84, + 85, 81, 82, 83, 84, 85, 199, 81, 82, 83, + 84, 85, 67, 124, 205, 70, 71, 224, 185, 217, + 0, 135, 91, 228, 88, 208, 107, 0, 92, 0, + 93, 94, 95, 96, 97, 98, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 112, 113, 114, 115, 116, + 117, 118, 119, 120, 121, 122, 200, 146, 0, 147, + 148, 149, 150, 151, 91, 0, 152, 153, 154, 0, + 92, 155, 93, 94, 95, 96, 97, 98, 91, 0, + 0, 0, 0, 0, 92, 0, 93, 94, 95, 96, + 97, 98, 91, 0, 0, 0, 0, 0, 92, 0, + 0, 0, 95, 96, 97, 98, 147, 148, 149, 150, + 151, 0, 0, 152, 153, 154, 0, 0, 155 +}; + +static const short int yycheck[] = +{ + 27, 156, 72, 54, 55, 3, 4, 5, 6, 7, + 8, 9, 3, 6, 10, 4, 7, 11, 198, 3, + 18, 5, 18, 7, 22, 9, 10, 18, 11, 22, + 210, 16, 10, 3, 18, 5, 11, 7, 16, 9, + 91, 92, 93, 94, 95, 96, 97, 98, 18, 200, + 3, 4, 5, 42, 7, 49, 9, 55, 43, 11, + 58, 216, 60, 61, 3, 18, 5, 11, 7, 0, + 9, 55, 99, 26, 46, 47, 60, 61, 3, 18, + 5, 236, 7, 234, 9, 55, 30, 26, 3, 9, + 60, 61, 3, 18, 3, 20, 20, 12, 51, 3, + 151, 12, 55, 12, 3, 13, 20, 60, 61, 41, + 18, 3, 51, 5, 141, 7, 55, 9, 14, 33, + 16, 60, 61, 150, 194, 19, 18, 15, 22, 15, + 55, 10, 17, 9, 161, 60, 61, 3, 62, 63, + 64, 20, 17, 3, 23, 24, 60, 61, 62, 63, + 64, 18, 179, 9, 33, 34, 35, 9, 185, 12, + 37, 38, 39, 55, 41, 37, 38, 39, 60, 61, + 17, 9, 12, 9, 15, 3, 203, 198, 10, 36, + 59, 60, 61, 62, 63, 64, 7, 214, 12, 210, + 43, 218, 45, 46, 47, 48, 49, 3, 10, 52, + 53, 54, 12, 43, 57, 45, 46, 47, 48, 49, + 10, 232, 52, 53, 54, 16, 20, 57, 10, 43, + 10, 45, 46, 47, 48, 49, 10, 7, 52, 53, + 54, 56, 4, 57, 4, 45, 46, 47, 48, 49, + 17, 4, 52, 53, 54, 20, 6, 57, 23, 24, + 17, 20, 9, 11, 23, 9, 20, 7, 33, 34, + 35, 20, 10, 19, 33, 34, 35, 20, 17, 21, + 23, 10, 50, 5, 33, 34, 35, 11, 24, 102, + 33, 34, 35, 16, 59, 60, 61, 62, 63, 64, + 59, 60, 61, 62, 63, 64, 60, 61, 62, 63, + 64, 60, 61, 62, 63, 64, 179, 60, 61, 62, + 63, 64, 42, 10, 192, 45, 46, 210, 155, 201, + -1, 100, 19, 214, 54, 196, 69, -1, 25, -1, + 27, 28, 29, 30, 31, 32, -1, -1, -1, -1, + -1, -1, -1, -1, -1, 75, 76, 77, 78, 79, + 80, 81, 82, 83, 84, 85, 11, 43, -1, 45, + 46, 47, 48, 49, 19, -1, 52, 53, 54, -1, + 25, 57, 27, 28, 29, 30, 31, 32, 19, -1, + -1, -1, -1, -1, 25, -1, 27, 28, 29, 30, + 31, 32, 19, -1, -1, -1, -1, -1, 25, -1, + -1, -1, 29, 30, 31, 32, 45, 46, 47, 48, + 49, -1, -1, 52, 53, 54, -1, -1, 57 +}; + +/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing + symbol of state STATE-NUM. */ +static const unsigned char yystos[] = +{ + 0, 37, 38, 39, 67, 68, 69, 70, 71, 75, + 11, 11, 11, 0, 41, 69, 82, 83, 3, 72, + 73, 74, 72, 3, 76, 77, 78, 9, 83, 15, + 12, 73, 17, 12, 15, 12, 77, 9, 79, 3, + 5, 7, 9, 18, 55, 60, 61, 113, 114, 115, + 116, 117, 3, 4, 9, 26, 51, 111, 112, 113, + 4, 42, 3, 80, 81, 17, 18, 115, 3, 9, + 115, 115, 17, 84, 20, 23, 24, 33, 34, 35, + 59, 60, 61, 62, 63, 64, 9, 112, 115, 112, + 9, 19, 25, 27, 28, 29, 30, 31, 32, 9, + 15, 10, 16, 3, 10, 3, 7, 114, 80, 85, + 10, 36, 115, 115, 115, 115, 115, 115, 115, 115, + 115, 115, 115, 7, 10, 3, 112, 112, 112, 112, + 112, 112, 112, 112, 113, 111, 81, 10, 10, 10, + 11, 30, 86, 10, 10, 10, 43, 45, 46, 47, + 48, 49, 52, 53, 54, 57, 87, 88, 91, 92, + 101, 102, 105, 106, 107, 108, 4, 6, 7, 8, + 22, 58, 94, 95, 96, 99, 113, 7, 56, 93, + 113, 112, 4, 4, 4, 102, 12, 88, 17, 7, + 103, 113, 13, 6, 9, 17, 16, 43, 11, 94, + 11, 110, 113, 9, 104, 95, 80, 100, 96, 7, + 89, 90, 91, 108, 19, 97, 87, 104, 21, 10, + 113, 14, 10, 12, 90, 17, 20, 98, 110, 12, + 113, 10, 50, 109, 11, 108, 87, 12 +}; + +#define yyerrok (yyerrstatus = 0) +#define yyclearin (yychar = YYEMPTY) +#define YYEMPTY (-2) +#define YYEOF 0 + +#define YYACCEPT goto yyacceptlab +#define YYABORT goto yyabortlab +#define YYERROR goto yyerrorlab + + +/* Like YYERROR except do call yyerror. This remains here temporarily + to ease the transition to the new meaning of YYERROR, for GCC. + Once GCC version 2 has supplanted version 1, this can go. */ + +#define YYFAIL goto yyerrlab + +#define YYRECOVERING() (!!yyerrstatus) + +#define YYBACKUP(Token, Value) \ +do \ + if (yychar == YYEMPTY && yylen == 1) \ + { \ + yychar = (Token); \ + yylval = (Value); \ + yytoken = YYTRANSLATE (yychar); \ + YYPOPSTACK; \ + goto yybackup; \ + } \ + else \ + { \ + yyerror (&yylloc, lexer, resultAST, YY_("syntax error: cannot back up")); \ + YYERROR; \ + } \ +while (0) + + +#define YYTERROR 1 +#define YYERRCODE 256 + + +/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N]. + If N is 0, then set CURRENT to the empty location which ends + the previous symbol: RHS[0] (always defined). */ + +#define YYRHSLOC(Rhs, K) ((Rhs)[K]) +#ifndef YYLLOC_DEFAULT +# define YYLLOC_DEFAULT(Current, Rhs, N) \ + do \ + if (N) \ + { \ + (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \ + (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \ + (Current).last_line = YYRHSLOC (Rhs, N).last_line; \ + (Current).last_column = YYRHSLOC (Rhs, N).last_column; \ + } \ + else \ + { \ + (Current).first_line = (Current).last_line = \ + YYRHSLOC (Rhs, 0).last_line; \ + (Current).first_column = (Current).last_column = \ + YYRHSLOC (Rhs, 0).last_column; \ + } \ + while (0) +#endif + + +/* YY_LOCATION_PRINT -- Print the location on the stream. + This macro was not mandated originally: define only if we know + we won't break user code: when these are the locations we know. */ + +#ifndef YY_LOCATION_PRINT +# if YYLTYPE_IS_TRIVIAL +# define YY_LOCATION_PRINT(File, Loc) \ + fprintf (File, "%d.%d-%d.%d", \ + (Loc).first_line, (Loc).first_column, \ + (Loc).last_line, (Loc).last_column) +# else +# define YY_LOCATION_PRINT(File, Loc) ((void) 0) +# endif +#endif + + +/* YYLEX -- calling `yylex' with the right arguments. */ + +#ifdef YYLEX_PARAM +# define YYLEX yylex (&yylval, &yylloc, YYLEX_PARAM) +#else +# define YYLEX yylex (&yylval, &yylloc, lexer) +#endif + +/* Enable debugging if requested. */ +#if YYDEBUG + +# ifndef YYFPRINTF +# include <stdio.h> /* INFRINGES ON USER NAME SPACE */ +# define YYFPRINTF fprintf +# endif + +# define YYDPRINTF(Args) \ +do { \ + if (yydebug) \ + YYFPRINTF Args; \ +} while (0) + +# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \ +do { \ + if (yydebug) \ + { \ + YYFPRINTF (stderr, "%s ", Title); \ + yysymprint (stderr, \ + Type, Value, Location); \ + YYFPRINTF (stderr, "\n"); \ + } \ +} while (0) + +/*------------------------------------------------------------------. +| yy_stack_print -- Print the state stack from its BOTTOM up to its | +| TOP (included). | +`------------------------------------------------------------------*/ + +#if defined (__STDC__) || defined (__cplusplus) +static void +yy_stack_print (short int *bottom, short int *top) +#else +static void +yy_stack_print (bottom, top) + short int *bottom; + short int *top; +#endif +{ + YYFPRINTF (stderr, "Stack now"); + for (/* Nothing. */; bottom <= top; ++bottom) + YYFPRINTF (stderr, " %d", *bottom); + YYFPRINTF (stderr, "\n"); +} + +# define YY_STACK_PRINT(Bottom, Top) \ +do { \ + if (yydebug) \ + yy_stack_print ((Bottom), (Top)); \ +} while (0) + + +/*------------------------------------------------. +| Report that the YYRULE is going to be reduced. | +`------------------------------------------------*/ + +#if defined (__STDC__) || defined (__cplusplus) +static void +yy_reduce_print (int yyrule) +#else +static void +yy_reduce_print (yyrule) + int yyrule; +#endif +{ + int yyi; + unsigned long int yylno = yyrline[yyrule]; + YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu), ", + yyrule - 1, yylno); + /* Print the symbols being reduced, and their result. */ + for (yyi = yyprhs[yyrule]; 0 <= yyrhs[yyi]; yyi++) + YYFPRINTF (stderr, "%s ", yytname[yyrhs[yyi]]); + YYFPRINTF (stderr, "-> %s\n", yytname[yyr1[yyrule]]); +} + +# define YY_REDUCE_PRINT(Rule) \ +do { \ + if (yydebug) \ + yy_reduce_print (Rule); \ +} while (0) + +/* Nonzero means print parse trace. It is left uninitialized so that + multiple parsers can coexist. */ +int yydebug; +#else /* !YYDEBUG */ +# define YYDPRINTF(Args) +# define YY_SYMBOL_PRINT(Title, Type, Value, Location) +# define YY_STACK_PRINT(Bottom, Top) +# define YY_REDUCE_PRINT(Rule) +#endif /* !YYDEBUG */ + + +/* YYINITDEPTH -- initial size of the parser's stacks. */ +#ifndef YYINITDEPTH +# define YYINITDEPTH 200 +#endif + +/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only + if the built-in stack extension method is used). + + Do not make this value too large; the results are undefined if + YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH) + evaluated with infinite-precision integer arithmetic. */ + +#ifndef YYMAXDEPTH +# define YYMAXDEPTH 10000 +#endif + + + +#if YYERROR_VERBOSE + +# ifndef yystrlen +# if defined (__GLIBC__) && defined (_STRING_H) +# define yystrlen strlen +# else +/* Return the length of YYSTR. */ +static YYSIZE_T +# if defined (__STDC__) || defined (__cplusplus) +yystrlen (const char *yystr) +# else +yystrlen (yystr) + const char *yystr; +# endif +{ + const char *yys = yystr; + + while (*yys++ != '\0') + continue; + + return yys - yystr - 1; +} +# endif +# endif + +# ifndef yystpcpy +# if defined (__GLIBC__) && defined (_STRING_H) && defined (_GNU_SOURCE) +# define yystpcpy stpcpy +# else +/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in + YYDEST. */ +static char * +# if defined (__STDC__) || defined (__cplusplus) +yystpcpy (char *yydest, const char *yysrc) +# else +yystpcpy (yydest, yysrc) + char *yydest; + const char *yysrc; +# endif +{ + char *yyd = yydest; + const char *yys = yysrc; + + while ((*yyd++ = *yys++) != '\0') + continue; + + return yyd - 1; +} +# endif +# endif + +# ifndef yytnamerr +/* Copy to YYRES the contents of YYSTR after stripping away unnecessary + quotes and backslashes, so that it's suitable for yyerror. The + heuristic is that double-quoting is unnecessary unless the string + contains an apostrophe, a comma, or backslash (other than + backslash-backslash). YYSTR is taken from yytname. If YYRES is + null, do not copy; instead, return the length of what the result + would have been. */ +static YYSIZE_T +yytnamerr (char *yyres, const char *yystr) +{ + if (*yystr == '"') + { + size_t yyn = 0; + char const *yyp = yystr; + + for (;;) + switch (*++yyp) + { + case '\'': + case ',': + goto do_not_strip_quotes; + + case '\\': + if (*++yyp != '\\') + goto do_not_strip_quotes; + /* Fall through. */ + default: + if (yyres) + yyres[yyn] = *yyp; + yyn++; + break; + + case '"': + if (yyres) + yyres[yyn] = '\0'; + return yyn; + } + do_not_strip_quotes: ; + } + + if (! yyres) + return yystrlen (yystr); + + return yystpcpy (yyres, yystr) - yyres; +} +# endif + +#endif /* YYERROR_VERBOSE */ + + + +#if YYDEBUG +/*--------------------------------. +| Print this symbol on YYOUTPUT. | +`--------------------------------*/ + +#if defined (__STDC__) || defined (__cplusplus) +static void +yysymprint (FILE *yyoutput, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocationp) +#else +static void +yysymprint (yyoutput, yytype, yyvaluep, yylocationp) + FILE *yyoutput; + int yytype; + YYSTYPE *yyvaluep; + YYLTYPE *yylocationp; +#endif +{ + /* Pacify ``unused variable'' warnings. */ + (void) yyvaluep; + (void) yylocationp; + + if (yytype < YYNTOKENS) + YYFPRINTF (yyoutput, "token %s (", yytname[yytype]); + else + YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]); + + YY_LOCATION_PRINT (yyoutput, *yylocationp); + YYFPRINTF (yyoutput, ": "); + +# ifdef YYPRINT + if (yytype < YYNTOKENS) + YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep); +# endif + switch (yytype) + { + default: + break; + } + YYFPRINTF (yyoutput, ")"); +} + +#endif /* ! YYDEBUG */ +/*-----------------------------------------------. +| Release the memory associated to this symbol. | +`-----------------------------------------------*/ + +#if defined (__STDC__) || defined (__cplusplus) +static void +yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocationp) +#else +static void +yydestruct (yymsg, yytype, yyvaluep, yylocationp) + const char *yymsg; + int yytype; + YYSTYPE *yyvaluep; + YYLTYPE *yylocationp; +#endif +{ + /* Pacify ``unused variable'' warnings. */ + (void) yyvaluep; + (void) yylocationp; + + if (!yymsg) + yymsg = "Deleting"; + YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp); + + switch (yytype) + { + case 3: /* "\"identifier\"" */ +#line 158 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { delete (yyvaluep->m_str); }; +#line 1209 "/Users/creed/projects/fsl/fromsvr/elftosb/build/elftosb.build/Debug/elftosb.build/DerivedSources/elftosb_parser.tab.cpp" + break; + case 4: /* "\"string\"" */ +#line 158 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { delete (yyvaluep->m_str); }; +#line 1214 "/Users/creed/projects/fsl/fromsvr/elftosb/build/elftosb.build/Debug/elftosb.build/DerivedSources/elftosb_parser.tab.cpp" + break; + case 5: /* "\"integer\"" */ +#line 158 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { delete (yyvaluep->m_int); }; +#line 1219 "/Users/creed/projects/fsl/fromsvr/elftosb/build/elftosb.build/Debug/elftosb.build/DerivedSources/elftosb_parser.tab.cpp" + break; + case 6: /* "\"section name\"" */ +#line 158 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { delete (yyvaluep->m_str); }; +#line 1224 "/Users/creed/projects/fsl/fromsvr/elftosb/build/elftosb.build/Debug/elftosb.build/DerivedSources/elftosb_parser.tab.cpp" + break; + case 7: /* "\"source name\"" */ +#line 158 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { delete (yyvaluep->m_str); }; +#line 1229 "/Users/creed/projects/fsl/fromsvr/elftosb/build/elftosb.build/Debug/elftosb.build/DerivedSources/elftosb_parser.tab.cpp" + break; + case 8: /* "\"binary object\"" */ +#line 158 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { delete (yyvaluep->m_blob); }; +#line 1234 "/Users/creed/projects/fsl/fromsvr/elftosb/build/elftosb.build/Debug/elftosb.build/DerivedSources/elftosb_parser.tab.cpp" + break; + case 36: /* "\"integer size\"" */ +#line 158 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { delete (yyvaluep->m_int); }; +#line 1239 "/Users/creed/projects/fsl/fromsvr/elftosb/build/elftosb.build/Debug/elftosb.build/DerivedSources/elftosb_parser.tab.cpp" + break; + + default: + break; + } +} + + +/* Prevent warnings from -Wmissing-prototypes. */ + +#ifdef YYPARSE_PARAM +# if defined (__STDC__) || defined (__cplusplus) +int yyparse (void *YYPARSE_PARAM); +# else +int yyparse (); +# endif +#else /* ! YYPARSE_PARAM */ +#if defined (__STDC__) || defined (__cplusplus) +int yyparse (ElftosbLexer * lexer, CommandFileASTNode ** resultAST); +#else +int yyparse (); +#endif +#endif /* ! YYPARSE_PARAM */ + + + + + + +/*----------. +| yyparse. | +`----------*/ + +#ifdef YYPARSE_PARAM +# if defined (__STDC__) || defined (__cplusplus) +int yyparse (void *YYPARSE_PARAM) +# else +int yyparse (YYPARSE_PARAM) + void *YYPARSE_PARAM; +# endif +#else /* ! YYPARSE_PARAM */ +#if defined (__STDC__) || defined (__cplusplus) +int +yyparse (ElftosbLexer * lexer, CommandFileASTNode ** resultAST) +#else +int +yyparse (lexer, resultAST) + ElftosbLexer * lexer; + CommandFileASTNode ** resultAST; +#endif +#endif +{ + /* The look-ahead symbol. */ +int yychar; + +/* The semantic value of the look-ahead symbol. */ +YYSTYPE yylval; + +/* Number of syntax errors so far. */ +int yynerrs; +/* Location data for the look-ahead symbol. */ +YYLTYPE yylloc; + + int yystate; + int yyn; + int yyresult; + /* Number of tokens to shift before error messages enabled. */ + int yyerrstatus; + /* Look-ahead token as an internal (translated) token number. */ + int yytoken = 0; + + /* Three stacks and their tools: + `yyss': related to states, + `yyvs': related to semantic values, + `yyls': related to locations. + + Refer to the stacks thru separate pointers, to allow yyoverflow + to reallocate them elsewhere. */ + + /* The state stack. */ + short int yyssa[YYINITDEPTH]; + short int *yyss = yyssa; + short int *yyssp; + + /* The semantic value stack. */ + YYSTYPE yyvsa[YYINITDEPTH]; + YYSTYPE *yyvs = yyvsa; + YYSTYPE *yyvsp; + + /* The location stack. */ + YYLTYPE yylsa[YYINITDEPTH]; + YYLTYPE *yyls = yylsa; + YYLTYPE *yylsp; + /* The locations where the error started and ended. */ + YYLTYPE yyerror_range[2]; + +#define YYPOPSTACK (yyvsp--, yyssp--, yylsp--) + + YYSIZE_T yystacksize = YYINITDEPTH; + + /* The variables used to return semantic value and location from the + action routines. */ + YYSTYPE yyval; + YYLTYPE yyloc; + + /* When reducing, the number of symbols on the RHS of the reduced + rule. */ + int yylen; + + YYDPRINTF ((stderr, "Starting parse\n")); + + yystate = 0; + yyerrstatus = 0; + yynerrs = 0; + yychar = YYEMPTY; /* Cause a token to be read. */ + + /* Initialize stack pointers. + Waste one element of value and location stack + so that they stay on the same level as the state stack. + The wasted elements are never initialized. */ + + yyssp = yyss; + yyvsp = yyvs; + yylsp = yyls; +#if YYLTYPE_IS_TRIVIAL + /* Initialize the default location before parsing starts. */ + yylloc.first_line = yylloc.last_line = 1; + yylloc.first_column = yylloc.last_column = 0; +#endif + + goto yysetstate; + +/*------------------------------------------------------------. +| yynewstate -- Push a new state, which is found in yystate. | +`------------------------------------------------------------*/ + yynewstate: + /* In all cases, when you get here, the value and location stacks + have just been pushed. so pushing a state here evens the stacks. + */ + yyssp++; + + yysetstate: + *yyssp = yystate; + + if (yyss + yystacksize - 1 <= yyssp) + { + /* Get the current used size of the three stacks, in elements. */ + YYSIZE_T yysize = yyssp - yyss + 1; + +#ifdef yyoverflow + { + /* Give user a chance to reallocate the stack. Use copies of + these so that the &'s don't force the real ones into + memory. */ + YYSTYPE *yyvs1 = yyvs; + short int *yyss1 = yyss; + YYLTYPE *yyls1 = yyls; + + /* Each stack pointer address is followed by the size of the + data in use in that stack, in bytes. This used to be a + conditional around just the two extra args, but that might + be undefined if yyoverflow is a macro. */ + yyoverflow (YY_("memory exhausted"), + &yyss1, yysize * sizeof (*yyssp), + &yyvs1, yysize * sizeof (*yyvsp), + &yyls1, yysize * sizeof (*yylsp), + &yystacksize); + yyls = yyls1; + yyss = yyss1; + yyvs = yyvs1; + } +#else /* no yyoverflow */ +# ifndef YYSTACK_RELOCATE + goto yyexhaustedlab; +# else + /* Extend the stack our own way. */ + if (YYMAXDEPTH <= yystacksize) + goto yyexhaustedlab; + yystacksize *= 2; + if (YYMAXDEPTH < yystacksize) + yystacksize = YYMAXDEPTH; + + { + short int *yyss1 = yyss; + union yyalloc *yyptr = + (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize)); + if (! yyptr) + goto yyexhaustedlab; + YYSTACK_RELOCATE (yyss); + YYSTACK_RELOCATE (yyvs); + YYSTACK_RELOCATE (yyls); +# undef YYSTACK_RELOCATE + if (yyss1 != yyssa) + YYSTACK_FREE (yyss1); + } +# endif +#endif /* no yyoverflow */ + + yyssp = yyss + yysize - 1; + yyvsp = yyvs + yysize - 1; + yylsp = yyls + yysize - 1; + + YYDPRINTF ((stderr, "Stack size increased to %lu\n", + (unsigned long int) yystacksize)); + + if (yyss + yystacksize - 1 <= yyssp) + YYABORT; + } + + YYDPRINTF ((stderr, "Entering state %d\n", yystate)); + + goto yybackup; + +/*-----------. +| yybackup. | +`-----------*/ +yybackup: + +/* Do appropriate processing given the current state. */ +/* Read a look-ahead token if we need one and don't already have one. */ +/* yyresume: */ + + /* First try to decide what to do without reference to look-ahead token. */ + + yyn = yypact[yystate]; + if (yyn == YYPACT_NINF) + goto yydefault; + + /* Not known => get a look-ahead token if don't already have one. */ + + /* YYCHAR is either YYEMPTY or YYEOF or a valid look-ahead symbol. */ + if (yychar == YYEMPTY) + { + YYDPRINTF ((stderr, "Reading a token: ")); + yychar = YYLEX; + } + + if (yychar <= YYEOF) + { + yychar = yytoken = YYEOF; + YYDPRINTF ((stderr, "Now at end of input.\n")); + } + else + { + yytoken = YYTRANSLATE (yychar); + YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc); + } + + /* If the proper action on seeing token YYTOKEN is to reduce or to + detect an error, take that action. */ + yyn += yytoken; + if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken) + goto yydefault; + yyn = yytable[yyn]; + if (yyn <= 0) + { + if (yyn == 0 || yyn == YYTABLE_NINF) + goto yyerrlab; + yyn = -yyn; + goto yyreduce; + } + + if (yyn == YYFINAL) + YYACCEPT; + + /* Shift the look-ahead token. */ + YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc); + + /* Discard the token being shifted unless it is eof. */ + if (yychar != YYEOF) + yychar = YYEMPTY; + + *++yyvsp = yylval; + *++yylsp = yylloc; + + /* Count tokens shifted since error; after three, turn off error + status. */ + if (yyerrstatus) + yyerrstatus--; + + yystate = yyn; + goto yynewstate; + + +/*-----------------------------------------------------------. +| yydefault -- do the default action for the current state. | +`-----------------------------------------------------------*/ +yydefault: + yyn = yydefact[yystate]; + if (yyn == 0) + goto yyerrlab; + goto yyreduce; + + +/*-----------------------------. +| yyreduce -- Do a reduction. | +`-----------------------------*/ +yyreduce: + /* yyn is the number of a rule to reduce with. */ + yylen = yyr2[yyn]; + + /* If YYLEN is nonzero, implement the default value of the action: + `$$ = $1'. + + Otherwise, the following line sets YYVAL to garbage. + This behavior is undocumented and Bison + users should not rely upon it. Assigning to YYVAL + unconditionally makes the parser a bit smaller, and it avoids a + GCC warning that YYVAL may be used uninitialized. */ + yyval = yyvsp[1-yylen]; + + /* Default location. */ + YYLLOC_DEFAULT (yyloc, yylsp - yylen, yylen); + YY_REDUCE_PRINT (yyn); + switch (yyn) + { + case 2: +#line 163 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + CommandFileASTNode * commandFile = new CommandFileASTNode(); + commandFile->setBlocks(dynamic_cast<ListASTNode*>((yyvsp[-1].m_ast))); + commandFile->setSections(dynamic_cast<ListASTNode*>((yyvsp[0].m_ast))); + commandFile->setLocation((yylsp[-1]), (yylsp[0])); + *resultAST = commandFile; + ;} + break; + + case 3: +#line 173 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + ListASTNode * list = new ListASTNode(); + list->appendNode((yyvsp[0].m_ast)); + (yyval.m_ast) = list; + ;} + break; + + case 4: +#line 179 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + dynamic_cast<ListASTNode*>((yyvsp[-1].m_ast))->appendNode((yyvsp[0].m_ast)); + (yyval.m_ast) = (yyvsp[-1].m_ast); + ;} + break; + + case 5: +#line 186 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { (yyval.m_ast) = (yyvsp[0].m_ast); ;} + break; + + case 6: +#line 187 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { (yyval.m_ast) = (yyvsp[0].m_ast); ;} + break; + + case 7: +#line 188 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { (yyval.m_ast) = (yyvsp[0].m_ast); ;} + break; + + case 8: +#line 192 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + (yyval.m_ast) = new OptionsBlockASTNode(dynamic_cast<ListASTNode *>((yyvsp[-1].m_ast))); + ;} + break; + + case 9: +#line 198 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + (yyval.m_ast) = new ConstantsBlockASTNode(dynamic_cast<ListASTNode *>((yyvsp[-1].m_ast))); + ;} + break; + + case 10: +#line 204 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + ListASTNode * list = new ListASTNode(); + list->appendNode((yyvsp[0].m_ast)); + (yyval.m_ast) = list; + ;} + break; + + case 11: +#line 210 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + dynamic_cast<ListASTNode*>((yyvsp[-1].m_ast))->appendNode((yyvsp[0].m_ast)); + (yyval.m_ast) = (yyvsp[-1].m_ast); + ;} + break; + + case 12: +#line 216 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { (yyval.m_ast) = (yyvsp[-1].m_ast); ;} + break; + + case 13: +#line 217 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { (yyval.m_ast) = NULL; ;} + break; + + case 14: +#line 221 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + (yyval.m_ast) = new AssignmentASTNode((yyvsp[-2].m_str), (yyvsp[0].m_ast)); + (yyval.m_ast)->setLocation((yylsp[-2]), (yylsp[0])); + ;} + break; + + case 15: +#line 228 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + (yyval.m_ast) = new SourcesBlockASTNode(dynamic_cast<ListASTNode *>((yyvsp[-1].m_ast))); + ;} + break; + + case 16: +#line 234 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + ListASTNode * list = new ListASTNode(); + list->appendNode((yyvsp[0].m_ast)); + (yyval.m_ast) = list; + ;} + break; + + case 17: +#line 240 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + dynamic_cast<ListASTNode*>((yyvsp[-1].m_ast))->appendNode((yyvsp[0].m_ast)); + (yyval.m_ast) = (yyvsp[-1].m_ast); + ;} + break; + + case 18: +#line 248 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + // tell the lexer that this is the name of a source file + SourceDefASTNode * node = dynamic_cast<SourceDefASTNode*>((yyvsp[-2].m_ast)); + if ((yyvsp[-1].m_ast)) + { + node->setAttributes(dynamic_cast<ListASTNode*>((yyvsp[-1].m_ast))); + } + node->setLocation(node->getLocation(), (yylsp[0])); + lexer->addSourceName(node->getName()); + (yyval.m_ast) = (yyvsp[-2].m_ast); + ;} + break; + + case 19: +#line 259 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { (yyval.m_ast) = NULL; ;} + break; + + case 20: +#line 263 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + (yyval.m_ast) = new PathSourceDefASTNode((yyvsp[-2].m_str), (yyvsp[0].m_str)); + (yyval.m_ast)->setLocation((yylsp[-2]), (yylsp[0])); + ;} + break; + + case 21: +#line 268 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + (yyval.m_ast) = new ExternSourceDefASTNode((yyvsp[-5].m_str), dynamic_cast<ExprASTNode*>((yyvsp[-1].m_ast))); + (yyval.m_ast)->setLocation((yylsp[-5]), (yylsp[0])); + ;} + break; + + case 22: +#line 275 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { (yyval.m_ast) = (yyvsp[-1].m_ast); ;} + break; + + case 23: +#line 276 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { (yyval.m_ast) = NULL; ;} + break; + + case 24: +#line 281 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + ListASTNode * list = new ListASTNode(); + list->appendNode((yyvsp[0].m_ast)); + (yyval.m_ast) = list; + ;} + break; + + case 25: +#line 287 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + dynamic_cast<ListASTNode*>((yyvsp[-2].m_ast))->appendNode((yyvsp[0].m_ast)); + (yyval.m_ast) = (yyvsp[-2].m_ast); + ;} + break; + + case 26: +#line 295 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + (yyval.m_ast) = new AssignmentASTNode((yyvsp[-2].m_str), (yyvsp[0].m_ast)); + (yyval.m_ast)->setLocation((yylsp[-2]), (yylsp[0])); + ;} + break; + + case 27: +#line 302 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + ListASTNode * list = new ListASTNode(); + list->appendNode((yyvsp[0].m_ast)); + (yyval.m_ast) = list; + ;} + break; + + case 28: +#line 308 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + dynamic_cast<ListASTNode*>((yyvsp[-1].m_ast))->appendNode((yyvsp[0].m_ast)); + (yyval.m_ast) = (yyvsp[-1].m_ast); + ;} + break; + + case 29: +#line 315 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + SectionContentsASTNode * sectionNode = dynamic_cast<SectionContentsASTNode*>((yyvsp[0].m_ast)); + if (sectionNode) + { + ExprASTNode * exprNode = dynamic_cast<ExprASTNode*>((yyvsp[-3].m_ast)); + sectionNode->setSectionNumberExpr(exprNode); + sectionNode->setOptions(dynamic_cast<ListASTNode*>((yyvsp[-2].m_ast))); + sectionNode->setLocation((yylsp[-5]), sectionNode->getLocation()); + } + (yyval.m_ast) = (yyvsp[0].m_ast); + ;} + break; + + case 30: +#line 330 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + (yyval.m_ast) = (yyvsp[0].m_ast); + ;} + break; + + case 31: +#line 334 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + (yyval.m_ast) = NULL; + ;} + break; + + case 32: +#line 341 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + (yyval.m_ast) = (yyvsp[0].m_ast); + ;} + break; + + case 33: +#line 345 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + (yyval.m_ast) = NULL; + ;} + break; + + case 34: +#line 352 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + DataSectionContentsASTNode * dataSection = new DataSectionContentsASTNode((yyvsp[-1].m_ast)); + dataSection->setLocation((yylsp[-2]), (yylsp[0])); + (yyval.m_ast) = dataSection; + ;} + break; + + case 35: +#line 358 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + ListASTNode * listNode = dynamic_cast<ListASTNode*>((yyvsp[-1].m_ast)); + (yyval.m_ast) = new BootableSectionContentsASTNode(listNode); + (yyval.m_ast)->setLocation((yylsp[-2]), (yylsp[0])); + ;} + break; + + case 36: +#line 366 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + ListASTNode * list = new ListASTNode(); + list->appendNode((yyvsp[0].m_ast)); + (yyval.m_ast) = list; + ;} + break; + + case 37: +#line 372 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + dynamic_cast<ListASTNode*>((yyvsp[-1].m_ast))->appendNode((yyvsp[0].m_ast)); + (yyval.m_ast) = (yyvsp[-1].m_ast); + ;} + break; + + case 38: +#line 379 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { (yyval.m_ast) = (yyvsp[-1].m_ast); ;} + break; + + case 39: +#line 380 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { (yyval.m_ast) = (yyvsp[0].m_ast); ;} + break; + + case 40: +#line 381 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { (yyval.m_ast) = (yyvsp[0].m_ast); ;} + break; + + case 41: +#line 382 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { (yyval.m_ast) = NULL; ;} + break; + + case 42: +#line 386 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + ListASTNode * list = new ListASTNode(); + list->appendNode((yyvsp[0].m_ast)); + (yyval.m_ast) = list; + ;} + break; + + case 43: +#line 392 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + dynamic_cast<ListASTNode*>((yyvsp[-1].m_ast))->appendNode((yyvsp[0].m_ast)); + (yyval.m_ast) = (yyvsp[-1].m_ast); + ;} + break; + + case 44: +#line 399 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { (yyval.m_ast) = (yyvsp[-1].m_ast); ;} + break; + + case 45: +#line 400 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { (yyval.m_ast) = (yyvsp[0].m_ast); ;} + break; + + case 46: +#line 401 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { (yyval.m_ast) = NULL; ;} + break; + + case 47: +#line 404 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { (yyval.m_ast) = (yyvsp[0].m_ast); ;} + break; + + case 48: +#line 405 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { (yyval.m_ast) = (yyvsp[0].m_ast); ;} + break; + + case 49: +#line 406 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { (yyval.m_ast) = (yyvsp[0].m_ast); ;} + break; + + case 50: +#line 407 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { (yyval.m_ast) = (yyvsp[0].m_ast); ;} + break; + + case 51: +#line 411 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + LoadStatementASTNode * stmt = new LoadStatementASTNode(); + stmt->setData((yyvsp[-1].m_ast)); + stmt->setTarget((yyvsp[0].m_ast)); + // set dcd load flag if the "dcd" keyword was present. + if ((yyvsp[-2].m_num)) + { + stmt->setDCDLoad(true); + } + // set char locations for the statement + if ((yyvsp[0].m_ast)) + { + stmt->setLocation((yylsp[-3]), (yylsp[0])); + } + else + { + stmt->setLocation((yylsp[-3]), (yylsp[-1])); + } + (yyval.m_ast) = stmt; + ;} + break; + + case 52: +#line 434 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + if (!elftosb::g_enableHABSupport) + { + yyerror(&yylloc, lexer, resultAST, "HAB features not supported with the selected family"); + YYABORT; + } + + (yyval.m_num) = 1; + ;} + break; + + case 53: +#line 443 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { (yyval.m_num) = 0; ;} + break; + + case 54: +#line 446 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + (yyval.m_ast) = (yyvsp[0].m_ast); + ;} + break; + + case 55: +#line 450 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + (yyval.m_ast) = new StringConstASTNode((yyvsp[0].m_str)); + (yyval.m_ast)->setLocation((yylsp[0])); + ;} + break; + + case 56: +#line 455 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + (yyval.m_ast) = new SourceASTNode((yyvsp[0].m_str)); + (yyval.m_ast)->setLocation((yylsp[0])); + ;} + break; + + case 57: +#line 460 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + (yyval.m_ast) = new SectionMatchListASTNode(dynamic_cast<ListASTNode*>((yyvsp[0].m_ast))); + (yyval.m_ast)->setLocation((yylsp[0])); + ;} + break; + + case 58: +#line 465 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + (yyval.m_ast) = new SectionMatchListASTNode(dynamic_cast<ListASTNode*>((yyvsp[-2].m_ast)), (yyvsp[0].m_str)); + (yyval.m_ast)->setLocation((yylsp[-2]), (yylsp[0])); + ;} + break; + + case 59: +#line 470 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + (yyval.m_ast) = new SectionMatchListASTNode(dynamic_cast<ListASTNode*>((yyvsp[-1].m_ast)), (yyvsp[-3].m_str)); + (yyval.m_ast)->setLocation((yylsp[-3]), (yylsp[0])); + ;} + break; + + case 60: +#line 475 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + (yyval.m_ast) = new BlobConstASTNode((yyvsp[0].m_blob)); + (yyval.m_ast)->setLocation((yylsp[0])); + ;} + break; + + case 61: +#line 480 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + ;} + break; + + case 62: +#line 485 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + ListASTNode * list = new ListASTNode(); + list->appendNode((yyvsp[0].m_ast)); + (yyval.m_ast) = list; + ;} + break; + + case 63: +#line 491 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + dynamic_cast<ListASTNode*>((yyvsp[-2].m_ast))->appendNode((yyvsp[0].m_ast)); + (yyval.m_ast) = (yyvsp[-2].m_ast); + ;} + break; + + case 64: +#line 499 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + (yyval.m_ast) = new SectionASTNode((yyvsp[0].m_str), SectionASTNode::kInclude); + (yyval.m_ast)->setLocation((yylsp[0])); + ;} + break; + + case 65: +#line 504 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + (yyval.m_ast) = new SectionASTNode((yyvsp[0].m_str), SectionASTNode::kExclude); + (yyval.m_ast)->setLocation((yylsp[-1]), (yylsp[0])); + ;} + break; + + case 66: +#line 511 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + (yyval.m_ast) = (yyvsp[0].m_ast); + ;} + break; + + case 67: +#line 515 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + (yyval.m_ast) = new NaturalLocationASTNode(); +// $$->setLocation(); + ;} + break; + + case 68: +#line 522 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + (yyval.m_ast) = new NaturalLocationASTNode(); + (yyval.m_ast)->setLocation((yylsp[0])); + ;} + break; + + case 69: +#line 527 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + (yyval.m_ast) = (yyvsp[0].m_ast); + ;} + break; + + case 70: +#line 533 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + IVTConstASTNode * ivt = new IVTConstASTNode(); + if ((yyvsp[-1].m_ast)) + { + ivt->setFieldAssignments(dynamic_cast<ListASTNode*>((yyvsp[-1].m_ast))); + } + ivt->setLocation((yylsp[-3]), (yylsp[0])); + (yyval.m_ast) = ivt; + ;} + break; + + case 71: +#line 544 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { (yyval.m_ast) = (yyvsp[0].m_ast); ;} + break; + + case 72: +#line 545 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { (yyval.m_ast) = NULL; ;} + break; + + case 73: +#line 549 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + CallStatementASTNode * stmt = new CallStatementASTNode(); + switch ((yyvsp[-2].m_num)) + { + case 1: + stmt->setCallType(CallStatementASTNode::kCallType); + break; + case 2: + stmt->setCallType(CallStatementASTNode::kJumpType); + break; + default: + yyerror(&yylloc, lexer, resultAST, "invalid call_or_jump value"); + YYABORT; + break; + } + stmt->setTarget((yyvsp[-1].m_ast)); + stmt->setArgument((yyvsp[0].m_ast)); + stmt->setIsHAB(false); + if ((yyvsp[0].m_ast)) + { + stmt->setLocation((yylsp[-2]), (yylsp[0])); + } + else + { + stmt->setLocation((yylsp[-2]), (yylsp[-1])); + } + (yyval.m_ast) = stmt; + ;} + break; + + case 74: +#line 578 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + if (!elftosb::g_enableHABSupport) + { + yyerror(&yylloc, lexer, resultAST, "HAB features not supported with the selected family"); + YYABORT; + } + + CallStatementASTNode * stmt = new CallStatementASTNode(); + switch ((yyvsp[-2].m_num)) + { + case 1: + stmt->setCallType(CallStatementASTNode::kCallType); + break; + case 2: + stmt->setCallType(CallStatementASTNode::kJumpType); + break; + default: + yyerror(&yylloc, lexer, resultAST, "invalid call_or_jump value"); + YYABORT; + break; + } + stmt->setTarget((yyvsp[-1].m_ast)); + stmt->setArgument((yyvsp[0].m_ast)); + stmt->setIsHAB(true); + if ((yyvsp[0].m_ast)) + { + stmt->setLocation((yylsp[-3]), (yylsp[0])); + } + else + { + stmt->setLocation((yylsp[-3]), (yylsp[-1])); + } + (yyval.m_ast) = stmt; + ;} + break; + + case 75: +#line 614 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { (yyval.m_num) = 1; ;} + break; + + case 76: +#line 615 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { (yyval.m_num) = 2; ;} + break; + + case 77: +#line 619 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + (yyval.m_ast) = new SymbolASTNode(NULL, (yyvsp[0].m_str)); + (yyval.m_ast)->setLocation((yylsp[0])); + ;} + break; + + case 78: +#line 624 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + (yyval.m_ast) = new AddressRangeASTNode((yyvsp[0].m_ast), NULL); + (yyval.m_ast)->setLocation((yyvsp[0].m_ast)); + ;} + break; + + case 79: +#line 630 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { (yyval.m_ast) = (yyvsp[-1].m_ast); ;} + break; + + case 80: +#line 631 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { (yyval.m_ast) = NULL; ;} + break; + + case 81: +#line 632 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { (yyval.m_ast) = NULL; ;} + break; + + case 82: +#line 636 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + (yyval.m_ast) = new FromStatementASTNode((yyvsp[-3].m_str), dynamic_cast<ListASTNode*>((yyvsp[-1].m_ast))); + (yyval.m_ast)->setLocation((yylsp[-4]), (yylsp[0])); + ;} + break; + + case 83: +#line 643 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + (yyval.m_ast) = new ModeStatementASTNode(dynamic_cast<ExprASTNode*>((yyvsp[0].m_ast))); + (yyval.m_ast)->setLocation((yylsp[-1]), (yylsp[0])); + ;} + break; + + case 84: +#line 650 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + (yyval.m_ast) = new MessageStatementASTNode(MessageStatementASTNode::kInfo, (yyvsp[0].m_str)); + (yyval.m_ast)->setLocation((yylsp[-1]), (yylsp[0])); + ;} + break; + + case 85: +#line 655 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + (yyval.m_ast) = new MessageStatementASTNode(MessageStatementASTNode::kWarning, (yyvsp[0].m_str)); + (yyval.m_ast)->setLocation((yylsp[-1]), (yylsp[0])); + ;} + break; + + case 86: +#line 660 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + (yyval.m_ast) = new MessageStatementASTNode(MessageStatementASTNode::kError, (yyvsp[0].m_str)); + (yyval.m_ast)->setLocation((yylsp[-1]), (yylsp[0])); + ;} + break; + + case 87: +#line 667 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + IfStatementASTNode * ifStmt = new IfStatementASTNode(); + ifStmt->setConditionExpr(dynamic_cast<ExprASTNode*>((yyvsp[-4].m_ast))); + ifStmt->setIfStatements(dynamic_cast<ListASTNode*>((yyvsp[-2].m_ast))); + ifStmt->setElseStatements(dynamic_cast<ListASTNode*>((yyvsp[0].m_ast))); + ifStmt->setLocation((yylsp[-5]), (yylsp[0])); + (yyval.m_ast) = ifStmt; + ;} + break; + + case 88: +#line 678 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + (yyval.m_ast) = (yyvsp[-1].m_ast); + ;} + break; + + case 89: +#line 682 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + ListASTNode * list = new ListASTNode(); + list->appendNode((yyvsp[0].m_ast)); + (yyval.m_ast) = list; + (yyval.m_ast)->setLocation((yylsp[-1]), (yylsp[0])); + ;} + break; + + case 90: +#line 688 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { (yyval.m_ast) = NULL; ;} + break; + + case 91: +#line 692 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + (yyval.m_ast) = new AddressRangeASTNode((yyvsp[0].m_ast), NULL); + (yyval.m_ast)->setLocation((yyvsp[0].m_ast)); + ;} + break; + + case 92: +#line 697 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + (yyval.m_ast) = new AddressRangeASTNode((yyvsp[-2].m_ast), (yyvsp[0].m_ast)); + (yyval.m_ast)->setLocation((yylsp[-2]), (yylsp[0])); + ;} + break; + + case 93: +#line 704 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + (yyval.m_ast) = (yyvsp[0].m_ast); + ;} + break; + + case 94: +#line 708 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + (yyval.m_ast) = new StringConstASTNode((yyvsp[0].m_str)); + (yyval.m_ast)->setLocation((yylsp[0])); + ;} + break; + + case 95: +#line 715 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + (yyval.m_ast) = (yyvsp[0].m_ast); + ;} + break; + + case 96: +#line 719 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + ExprASTNode * left = dynamic_cast<ExprASTNode*>((yyvsp[-2].m_ast)); + ExprASTNode * right = dynamic_cast<ExprASTNode*>((yyvsp[0].m_ast)); + (yyval.m_ast) = new BinaryOpExprASTNode(left, BinaryOpExprASTNode::kLessThan, right); + (yyval.m_ast)->setLocation((yylsp[-2]), (yylsp[0])); + ;} + break; + + case 97: +#line 726 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + ExprASTNode * left = dynamic_cast<ExprASTNode*>((yyvsp[-2].m_ast)); + ExprASTNode * right = dynamic_cast<ExprASTNode*>((yyvsp[0].m_ast)); + (yyval.m_ast) = new BinaryOpExprASTNode(left, BinaryOpExprASTNode::kGreaterThan, right); + (yyval.m_ast)->setLocation((yylsp[-2]), (yylsp[0])); + ;} + break; + + case 98: +#line 733 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + ExprASTNode * left = dynamic_cast<ExprASTNode*>((yyvsp[-2].m_ast)); + ExprASTNode * right = dynamic_cast<ExprASTNode*>((yyvsp[0].m_ast)); + (yyval.m_ast) = new BinaryOpExprASTNode(left, BinaryOpExprASTNode::kGreaterThanEqual, right); + (yyval.m_ast)->setLocation((yylsp[-2]), (yylsp[0])); + ;} + break; + + case 99: +#line 740 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + ExprASTNode * left = dynamic_cast<ExprASTNode*>((yyvsp[-2].m_ast)); + ExprASTNode * right = dynamic_cast<ExprASTNode*>((yyvsp[0].m_ast)); + (yyval.m_ast) = new BinaryOpExprASTNode(left, BinaryOpExprASTNode::kLessThanEqual, right); + (yyval.m_ast)->setLocation((yylsp[-2]), (yylsp[0])); + ;} + break; + + case 100: +#line 747 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + ExprASTNode * left = dynamic_cast<ExprASTNode*>((yyvsp[-2].m_ast)); + ExprASTNode * right = dynamic_cast<ExprASTNode*>((yyvsp[0].m_ast)); + (yyval.m_ast) = new BinaryOpExprASTNode(left, BinaryOpExprASTNode::kEqual, right); + (yyval.m_ast)->setLocation((yylsp[-2]), (yylsp[0])); + ;} + break; + + case 101: +#line 754 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + ExprASTNode * left = dynamic_cast<ExprASTNode*>((yyvsp[-2].m_ast)); + ExprASTNode * right = dynamic_cast<ExprASTNode*>((yyvsp[0].m_ast)); + (yyval.m_ast) = new BinaryOpExprASTNode(left, BinaryOpExprASTNode::kNotEqual, right); + (yyval.m_ast)->setLocation((yylsp[-2]), (yylsp[0])); + ;} + break; + + case 102: +#line 761 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + ExprASTNode * left = dynamic_cast<ExprASTNode*>((yyvsp[-2].m_ast)); + ExprASTNode * right = dynamic_cast<ExprASTNode*>((yyvsp[0].m_ast)); + (yyval.m_ast) = new BinaryOpExprASTNode(left, BinaryOpExprASTNode::kBooleanAnd, right); + (yyval.m_ast)->setLocation((yylsp[-2]), (yylsp[0])); + ;} + break; + + case 103: +#line 768 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + ExprASTNode * left = dynamic_cast<ExprASTNode*>((yyvsp[-2].m_ast)); + ExprASTNode * right = dynamic_cast<ExprASTNode*>((yyvsp[0].m_ast)); + (yyval.m_ast) = new BinaryOpExprASTNode(left, BinaryOpExprASTNode::kBooleanOr, right); + (yyval.m_ast)->setLocation((yylsp[-2]), (yylsp[0])); + ;} + break; + + case 104: +#line 775 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + (yyval.m_ast) = new BooleanNotExprASTNode(dynamic_cast<ExprASTNode*>((yyvsp[0].m_ast))); + (yyval.m_ast)->setLocation((yylsp[-1]), (yylsp[0])); + ;} + break; + + case 105: +#line 780 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + (yyval.m_ast) = new SourceFileFunctionASTNode((yyvsp[-3].m_str), (yyvsp[-1].m_str)); + (yyval.m_ast)->setLocation((yylsp[-3]), (yylsp[0])); + ;} + break; + + case 106: +#line 785 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + (yyval.m_ast) = (yyvsp[-1].m_ast); + (yyval.m_ast)->setLocation((yylsp[-2]), (yylsp[0])); + ;} + break; + + case 107: +#line 790 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + (yyval.m_ast) = new DefinedOperatorASTNode((yyvsp[-1].m_str)); + (yyval.m_ast)->setLocation((yylsp[-3]), (yylsp[0])); + ;} + break; + + case 108: +#line 796 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { (yyval.m_ast) = (yyvsp[0].m_ast); ;} + break; + + case 109: +#line 800 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + (yyval.m_ast) = new SymbolASTNode((yyvsp[0].m_str), (yyvsp[-2].m_str)); + (yyval.m_ast)->setLocation((yylsp[-2]), (yylsp[0])); + ;} + break; + + case 110: +#line 805 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + (yyval.m_ast) = new SymbolASTNode((yyvsp[0].m_str)); + (yyval.m_ast)->setLocation((yylsp[-1]), (yylsp[0])); + ;} + break; + + case 111: +#line 813 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + (yyval.m_ast) = (yyvsp[0].m_ast); + ;} + break; + + case 112: +#line 817 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + (yyval.m_ast) = new VariableExprASTNode((yyvsp[0].m_str)); + (yyval.m_ast)->setLocation((yylsp[0])); + ;} + break; + + case 113: +#line 822 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + (yyval.m_ast) = new SymbolRefExprASTNode(dynamic_cast<SymbolASTNode*>((yyvsp[0].m_ast))); + (yyval.m_ast)->setLocation((yylsp[0])); + ;} + break; + + case 114: +#line 833 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + ExprASTNode * left = dynamic_cast<ExprASTNode*>((yyvsp[-2].m_ast)); + ExprASTNode * right = dynamic_cast<ExprASTNode*>((yyvsp[0].m_ast)); + (yyval.m_ast) = new BinaryOpExprASTNode(left, BinaryOpExprASTNode::kAdd, right); + (yyval.m_ast)->setLocation((yylsp[-2]), (yylsp[0])); + ;} + break; + + case 115: +#line 840 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + ExprASTNode * left = dynamic_cast<ExprASTNode*>((yyvsp[-2].m_ast)); + ExprASTNode * right = dynamic_cast<ExprASTNode*>((yyvsp[0].m_ast)); + (yyval.m_ast) = new BinaryOpExprASTNode(left, BinaryOpExprASTNode::kSubtract, right); + (yyval.m_ast)->setLocation((yylsp[-2]), (yylsp[0])); + ;} + break; + + case 116: +#line 847 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + ExprASTNode * left = dynamic_cast<ExprASTNode*>((yyvsp[-2].m_ast)); + ExprASTNode * right = dynamic_cast<ExprASTNode*>((yyvsp[0].m_ast)); + (yyval.m_ast) = new BinaryOpExprASTNode(left, BinaryOpExprASTNode::kMultiply, right); + (yyval.m_ast)->setLocation((yylsp[-2]), (yylsp[0])); + ;} + break; + + case 117: +#line 854 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + ExprASTNode * left = dynamic_cast<ExprASTNode*>((yyvsp[-2].m_ast)); + ExprASTNode * right = dynamic_cast<ExprASTNode*>((yyvsp[0].m_ast)); + (yyval.m_ast) = new BinaryOpExprASTNode(left, BinaryOpExprASTNode::kDivide, right); + (yyval.m_ast)->setLocation((yylsp[-2]), (yylsp[0])); + ;} + break; + + case 118: +#line 861 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + ExprASTNode * left = dynamic_cast<ExprASTNode*>((yyvsp[-2].m_ast)); + ExprASTNode * right = dynamic_cast<ExprASTNode*>((yyvsp[0].m_ast)); + (yyval.m_ast) = new BinaryOpExprASTNode(left, BinaryOpExprASTNode::kModulus, right); + (yyval.m_ast)->setLocation((yylsp[-2]), (yylsp[0])); + ;} + break; + + case 119: +#line 868 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + ExprASTNode * left = dynamic_cast<ExprASTNode*>((yyvsp[-2].m_ast)); + ExprASTNode * right = dynamic_cast<ExprASTNode*>((yyvsp[0].m_ast)); + (yyval.m_ast) = new BinaryOpExprASTNode(left, BinaryOpExprASTNode::kPower, right); + (yyval.m_ast)->setLocation((yylsp[-2]), (yylsp[0])); + ;} + break; + + case 120: +#line 875 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + ExprASTNode * left = dynamic_cast<ExprASTNode*>((yyvsp[-2].m_ast)); + ExprASTNode * right = dynamic_cast<ExprASTNode*>((yyvsp[0].m_ast)); + (yyval.m_ast) = new BinaryOpExprASTNode(left, BinaryOpExprASTNode::kBitwiseAnd, right); + (yyval.m_ast)->setLocation((yylsp[-2]), (yylsp[0])); + ;} + break; + + case 121: +#line 882 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + ExprASTNode * left = dynamic_cast<ExprASTNode*>((yyvsp[-2].m_ast)); + ExprASTNode * right = dynamic_cast<ExprASTNode*>((yyvsp[0].m_ast)); + (yyval.m_ast) = new BinaryOpExprASTNode(left, BinaryOpExprASTNode::kBitwiseOr, right); + (yyval.m_ast)->setLocation((yylsp[-2]), (yylsp[0])); + ;} + break; + + case 122: +#line 889 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + ExprASTNode * left = dynamic_cast<ExprASTNode*>((yyvsp[-2].m_ast)); + ExprASTNode * right = dynamic_cast<ExprASTNode*>((yyvsp[0].m_ast)); + (yyval.m_ast) = new BinaryOpExprASTNode(left, BinaryOpExprASTNode::kBitwiseXor, right); + (yyval.m_ast)->setLocation((yylsp[-2]), (yylsp[0])); + ;} + break; + + case 123: +#line 896 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + ExprASTNode * left = dynamic_cast<ExprASTNode*>((yyvsp[-2].m_ast)); + ExprASTNode * right = dynamic_cast<ExprASTNode*>((yyvsp[0].m_ast)); + (yyval.m_ast) = new BinaryOpExprASTNode(left, BinaryOpExprASTNode::kShiftLeft, right); + (yyval.m_ast)->setLocation((yylsp[-2]), (yylsp[0])); + ;} + break; + + case 124: +#line 903 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + ExprASTNode * left = dynamic_cast<ExprASTNode*>((yyvsp[-2].m_ast)); + ExprASTNode * right = dynamic_cast<ExprASTNode*>((yyvsp[0].m_ast)); + (yyval.m_ast) = new BinaryOpExprASTNode(left, BinaryOpExprASTNode::kShiftRight, right); + (yyval.m_ast)->setLocation((yylsp[-2]), (yylsp[0])); + ;} + break; + + case 125: +#line 910 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + (yyval.m_ast) = (yyvsp[0].m_ast); + ;} + break; + + case 126: +#line 914 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + (yyval.m_ast) = new IntSizeExprASTNode(dynamic_cast<ExprASTNode*>((yyvsp[-2].m_ast)), (yyvsp[0].m_int)->getWordSize()); + (yyval.m_ast)->setLocation((yylsp[-2]), (yylsp[0])); + ;} + break; + + case 127: +#line 919 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + (yyval.m_ast) = (yyvsp[-1].m_ast); + (yyval.m_ast)->setLocation((yylsp[-2]), (yylsp[0])); + ;} + break; + + case 128: +#line 924 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + (yyval.m_ast) = new SizeofOperatorASTNode(dynamic_cast<SymbolASTNode*>((yyvsp[-1].m_ast))); + (yyval.m_ast)->setLocation((yylsp[-3]), (yylsp[0])); + ;} + break; + + case 129: +#line 929 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + (yyval.m_ast) = new SizeofOperatorASTNode((yyvsp[-1].m_str)); + (yyval.m_ast)->setLocation((yylsp[-3]), (yylsp[0])); + ;} + break; + + case 130: +#line 934 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + (yyval.m_ast) = new SizeofOperatorASTNode((yyvsp[-1].m_str)); + (yyval.m_ast)->setLocation((yylsp[-3]), (yylsp[0])); + ;} + break; + + case 131: +#line 941 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + (yyval.m_ast) = (yyvsp[0].m_ast); + ;} + break; + + case 132: +#line 945 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + (yyval.m_ast) = new NegativeExprASTNode(dynamic_cast<ExprASTNode*>((yyvsp[0].m_ast))); + (yyval.m_ast)->setLocation((yylsp[-1]), (yylsp[0])); + ;} + break; + + case 133: +#line 952 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + { + (yyval.m_ast) = new IntConstExprASTNode((yyvsp[0].m_int)->getValue(), (yyvsp[0].m_int)->getWordSize()); + (yyval.m_ast)->setLocation((yylsp[0])); + ;} + break; + + + default: break; + } + +/* Line 1126 of yacc.c. */ +#line 2663 "/Users/creed/projects/fsl/fromsvr/elftosb/build/elftosb.build/Debug/elftosb.build/DerivedSources/elftosb_parser.tab.cpp" + + yyvsp -= yylen; + yyssp -= yylen; + yylsp -= yylen; + + YY_STACK_PRINT (yyss, yyssp); + + *++yyvsp = yyval; + *++yylsp = yyloc; + + /* Now `shift' the result of the reduction. Determine what state + that goes to, based on the state we popped back to and the rule + number reduced by. */ + + yyn = yyr1[yyn]; + + yystate = yypgoto[yyn - YYNTOKENS] + *yyssp; + if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp) + yystate = yytable[yystate]; + else + yystate = yydefgoto[yyn - YYNTOKENS]; + + goto yynewstate; + + +/*------------------------------------. +| yyerrlab -- here on detecting error | +`------------------------------------*/ +yyerrlab: + /* If not already recovering from an error, report this error. */ + if (!yyerrstatus) + { + ++yynerrs; +#if YYERROR_VERBOSE + yyn = yypact[yystate]; + + if (YYPACT_NINF < yyn && yyn < YYLAST) + { + int yytype = YYTRANSLATE (yychar); + YYSIZE_T yysize0 = yytnamerr (0, yytname[yytype]); + YYSIZE_T yysize = yysize0; + YYSIZE_T yysize1; + int yysize_overflow = 0; + char *yymsg = 0; +# define YYERROR_VERBOSE_ARGS_MAXIMUM 5 + char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM]; + int yyx; + +#if 0 + /* This is so xgettext sees the translatable formats that are + constructed on the fly. */ + YY_("syntax error, unexpected %s"); + YY_("syntax error, unexpected %s, expecting %s"); + YY_("syntax error, unexpected %s, expecting %s or %s"); + YY_("syntax error, unexpected %s, expecting %s or %s or %s"); + YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"); +#endif + char *yyfmt; + char const *yyf; + static char const yyunexpected[] = "syntax error, unexpected %s"; + static char const yyexpecting[] = ", expecting %s"; + static char const yyor[] = " or %s"; + char yyformat[sizeof yyunexpected + + sizeof yyexpecting - 1 + + ((YYERROR_VERBOSE_ARGS_MAXIMUM - 2) + * (sizeof yyor - 1))]; + char const *yyprefix = yyexpecting; + + /* Start YYX at -YYN if negative to avoid negative indexes in + YYCHECK. */ + int yyxbegin = yyn < 0 ? -yyn : 0; + + /* Stay within bounds of both yycheck and yytname. */ + int yychecklim = YYLAST - yyn; + int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; + int yycount = 1; + + yyarg[0] = yytname[yytype]; + yyfmt = yystpcpy (yyformat, yyunexpected); + + for (yyx = yyxbegin; yyx < yyxend; ++yyx) + if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR) + { + if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM) + { + yycount = 1; + yysize = yysize0; + yyformat[sizeof yyunexpected - 1] = '\0'; + break; + } + yyarg[yycount++] = yytname[yyx]; + yysize1 = yysize + yytnamerr (0, yytname[yyx]); + yysize_overflow |= yysize1 < yysize; + yysize = yysize1; + yyfmt = yystpcpy (yyfmt, yyprefix); + yyprefix = yyor; + } + + yyf = YY_(yyformat); + yysize1 = yysize + yystrlen (yyf); + yysize_overflow |= yysize1 < yysize; + yysize = yysize1; + + if (!yysize_overflow && yysize <= YYSTACK_ALLOC_MAXIMUM) + yymsg = (char *) YYSTACK_ALLOC (yysize); + if (yymsg) + { + /* Avoid sprintf, as that infringes on the user's name space. + Don't have undefined behavior even if the translation + produced a string with the wrong number of "%s"s. */ + char *yyp = yymsg; + int yyi = 0; + while ((*yyp = *yyf)) + { + if (*yyp == '%' && yyf[1] == 's' && yyi < yycount) + { + yyp += yytnamerr (yyp, yyarg[yyi++]); + yyf += 2; + } + else + { + yyp++; + yyf++; + } + } + yyerror (&yylloc, lexer, resultAST, yymsg); + YYSTACK_FREE (yymsg); + } + else + { + yyerror (&yylloc, lexer, resultAST, YY_("syntax error")); + goto yyexhaustedlab; + } + } + else +#endif /* YYERROR_VERBOSE */ + yyerror (&yylloc, lexer, resultAST, YY_("syntax error")); + } + + yyerror_range[0] = yylloc; + + if (yyerrstatus == 3) + { + /* If just tried and failed to reuse look-ahead token after an + error, discard it. */ + + if (yychar <= YYEOF) + { + /* Return failure if at end of input. */ + if (yychar == YYEOF) + YYABORT; + } + else + { + yydestruct ("Error: discarding", yytoken, &yylval, &yylloc); + yychar = YYEMPTY; + } + } + + /* Else will try to reuse look-ahead token after shifting the error + token. */ + goto yyerrlab1; + + +/*---------------------------------------------------. +| yyerrorlab -- error raised explicitly by YYERROR. | +`---------------------------------------------------*/ +yyerrorlab: + + /* Pacify compilers like GCC when the user code never invokes + YYERROR and the label yyerrorlab therefore never appears in user + code. */ + if (0) + goto yyerrorlab; + + yyerror_range[0] = yylsp[1-yylen]; + yylsp -= yylen; + yyvsp -= yylen; + yyssp -= yylen; + yystate = *yyssp; + goto yyerrlab1; + + +/*-------------------------------------------------------------. +| yyerrlab1 -- common code for both syntax error and YYERROR. | +`-------------------------------------------------------------*/ +yyerrlab1: + yyerrstatus = 3; /* Each real token shifted decrements this. */ + + for (;;) + { + yyn = yypact[yystate]; + if (yyn != YYPACT_NINF) + { + yyn += YYTERROR; + if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR) + { + yyn = yytable[yyn]; + if (0 < yyn) + break; + } + } + + /* Pop the current state because it cannot handle the error token. */ + if (yyssp == yyss) + YYABORT; + + yyerror_range[0] = *yylsp; + yydestruct ("Error: popping", yystos[yystate], yyvsp, yylsp); + YYPOPSTACK; + yystate = *yyssp; + YY_STACK_PRINT (yyss, yyssp); + } + + if (yyn == YYFINAL) + YYACCEPT; + + *++yyvsp = yylval; + + yyerror_range[1] = yylloc; + /* Using YYLLOC is tempting, but would change the location of + the look-ahead. YYLOC is available though. */ + YYLLOC_DEFAULT (yyloc, yyerror_range - 1, 2); + *++yylsp = yyloc; + + /* Shift the error token. */ + YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp); + + yystate = yyn; + goto yynewstate; + + +/*-------------------------------------. +| yyacceptlab -- YYACCEPT comes here. | +`-------------------------------------*/ +yyacceptlab: + yyresult = 0; + goto yyreturn; + +/*-----------------------------------. +| yyabortlab -- YYABORT comes here. | +`-----------------------------------*/ +yyabortlab: + yyresult = 1; + goto yyreturn; + +#ifndef yyoverflow +/*-------------------------------------------------. +| yyexhaustedlab -- memory exhaustion comes here. | +`-------------------------------------------------*/ +yyexhaustedlab: + yyerror (&yylloc, lexer, resultAST, YY_("memory exhausted")); + yyresult = 2; + /* Fall through. */ +#endif + +yyreturn: + if (yychar != YYEOF && yychar != YYEMPTY) + yydestruct ("Cleanup: discarding lookahead", + yytoken, &yylval, &yylloc); + while (yyssp != yyss) + { + yydestruct ("Cleanup: popping", + yystos[*yyssp], yyvsp, yylsp); + YYPOPSTACK; + } +#ifndef yyoverflow + if (yyss != yyssa) + YYSTACK_FREE (yyss); +#endif + return yyresult; +} + + +#line 958 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" + + +/* code goes here */ + +static int yylex(YYSTYPE * lvalp, YYLTYPE * yylloc, ElftosbLexer * lexer) +{ + int token = lexer->yylex(); + *yylloc = lexer->getLocation(); + lexer->getSymbolValue(lvalp); + return token; +} + +static void yyerror(YYLTYPE * yylloc, ElftosbLexer * lexer, CommandFileASTNode ** resultAST, const char * error) +{ + throw syntax_error(format_string("line %d: %s\n", yylloc->m_firstLine, error)); +} + + diff --git a/elftosb2/elftosb_parser.tab.hpp b/elftosb2/elftosb_parser.tab.hpp new file mode 100644 index 0000000..4ee45c4 --- /dev/null +++ b/elftosb2/elftosb_parser.tab.hpp @@ -0,0 +1,152 @@ +/* A Bison parser, made by GNU Bison 2.1. */ + +/* Skeleton parser for Yacc-like parsing with Bison, + Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. */ + +/* As a special exception, when this file is copied by Bison into a + Bison output file, you may use that output file without restriction. + This special exception was added by the Free Software Foundation + in version 1.24 of Bison. */ + +/* Tokens. */ +#ifndef YYTOKENTYPE +# define YYTOKENTYPE + /* Put the tokens into the symbol table, so that GDB and other debuggers + know about them. */ + enum yytokentype { + TOK_IDENT = 258, + TOK_STRING_LITERAL = 259, + TOK_INT_LITERAL = 260, + TOK_SECTION_NAME = 261, + TOK_SOURCE_NAME = 262, + TOK_BLOB = 263, + TOK_DOT_DOT = 264, + TOK_AND = 265, + TOK_OR = 266, + TOK_GEQ = 267, + TOK_LEQ = 268, + TOK_EQ = 269, + TOK_NEQ = 270, + TOK_POWER = 271, + TOK_LSHIFT = 272, + TOK_RSHIFT = 273, + TOK_INT_SIZE = 274, + TOK_OPTIONS = 275, + TOK_CONSTANTS = 276, + TOK_SOURCES = 277, + TOK_FILTERS = 278, + TOK_SECTION = 279, + TOK_EXTERN = 280, + TOK_FROM = 281, + TOK_RAW = 282, + TOK_LOAD = 283, + TOK_JUMP = 284, + TOK_CALL = 285, + TOK_MODE = 286, + TOK_IF = 287, + TOK_ELSE = 288, + TOK_DEFINED = 289, + TOK_INFO = 290, + TOK_WARNING = 291, + TOK_ERROR = 292, + TOK_SIZEOF = 293, + TOK_DCD = 294, + TOK_HAB = 295, + TOK_IVT = 296, + UNARY_OP = 297 + }; +#endif +/* Tokens. */ +#define TOK_IDENT 258 +#define TOK_STRING_LITERAL 259 +#define TOK_INT_LITERAL 260 +#define TOK_SECTION_NAME 261 +#define TOK_SOURCE_NAME 262 +#define TOK_BLOB 263 +#define TOK_DOT_DOT 264 +#define TOK_AND 265 +#define TOK_OR 266 +#define TOK_GEQ 267 +#define TOK_LEQ 268 +#define TOK_EQ 269 +#define TOK_NEQ 270 +#define TOK_POWER 271 +#define TOK_LSHIFT 272 +#define TOK_RSHIFT 273 +#define TOK_INT_SIZE 274 +#define TOK_OPTIONS 275 +#define TOK_CONSTANTS 276 +#define TOK_SOURCES 277 +#define TOK_FILTERS 278 +#define TOK_SECTION 279 +#define TOK_EXTERN 280 +#define TOK_FROM 281 +#define TOK_RAW 282 +#define TOK_LOAD 283 +#define TOK_JUMP 284 +#define TOK_CALL 285 +#define TOK_MODE 286 +#define TOK_IF 287 +#define TOK_ELSE 288 +#define TOK_DEFINED 289 +#define TOK_INFO 290 +#define TOK_WARNING 291 +#define TOK_ERROR 292 +#define TOK_SIZEOF 293 +#define TOK_DCD 294 +#define TOK_HAB 295 +#define TOK_IVT 296 +#define UNARY_OP 297 + + + + +#if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED) +#line 58 "/Users/creed/projects/fsl/fromsvr/elftosb/elftosb2/elftosb_parser.y" +typedef union YYSTYPE { + int m_num; + elftosb::SizedIntegerValue * m_int; + Blob * m_blob; + std::string * m_str; + elftosb::ASTNode * m_ast; // must use full name here because this is put into *.tab.hpp +} YYSTYPE; +/* Line 1447 of yacc.c. */ +#line 130 "/Users/creed/projects/fsl/fromsvr/elftosb/build/elftosb.build/Debug/elftosb.build/DerivedSources/elftosb_parser.tab.hpp" +# define yystype YYSTYPE /* obsolescent; will be withdrawn */ +# define YYSTYPE_IS_DECLARED 1 +# define YYSTYPE_IS_TRIVIAL 1 +#endif + + + +#if ! defined (YYLTYPE) && ! defined (YYLTYPE_IS_DECLARED) +typedef struct YYLTYPE +{ + int first_line; + int first_column; + int last_line; + int last_column; +} YYLTYPE; +# define yyltype YYLTYPE /* obsolescent; will be withdrawn */ +# define YYLTYPE_IS_DECLARED 1 +# define YYLTYPE_IS_TRIVIAL 1 +#endif + + + + diff --git a/elftosb2/elftosb_parser.y b/elftosb2/elftosb_parser.y new file mode 100644 index 0000000..7c33652 --- /dev/null +++ b/elftosb2/elftosb_parser.y @@ -0,0 +1,978 @@ +/* + * Copyright (c) Freescale Semiconductor, Inc. All rights reserved. + * See included license file for license details. + */ + +/* write header with token defines */ +%defines + +/* make it reentrant */ +%pure-parser + +/* put more info in error messages */ +%error-verbose + +/* enable location processing */ +%locations + +%{ +#include "ElftosbLexer.h" +#include "ElftosbAST.h" +#include "Logging.h" +#include "Blob.h" +#include "format_string.h" +#include "Value.h" +#include "ConversionController.h" + +using namespace elftosb; + +//! Our special location type. +#define YYLTYPE token_loc_t + +// this indicates that we're using our own type. it should be unset automatically +// but that's not working for some reason with the .hpp file. +#if defined(YYLTYPE_IS_TRIVIAL) + #undef YYLTYPE_IS_TRIVIAL + #define YYLTYPE_IS_TRIVIAL 0 +#endif + +//! Default location action +#define YYLLOC_DEFAULT(Current, Rhs, N) \ + do { \ + if (N) \ + { \ + (Current).m_firstLine = YYRHSLOC(Rhs, 1).m_firstLine; \ + (Current).m_lastLine = YYRHSLOC(Rhs, N).m_lastLine; \ + } \ + else \ + { \ + (Current).m_firstLine = (Current).m_lastLine = YYRHSLOC(Rhs, 0).m_lastLine; \ + } \ + } while (0) + +//! Forward declaration of yylex(). +static int yylex(YYSTYPE * lvalp, YYLTYPE * yylloc, ElftosbLexer * lexer); + +// Forward declaration of error handling function. +static void yyerror(YYLTYPE * yylloc, ElftosbLexer * lexer, CommandFileASTNode ** resultAST, const char * error); + +%} + +/* symbol types */ +%union { + int m_num; + elftosb::SizedIntegerValue * m_int; + Blob * m_blob; + std::string * m_str; + elftosb::ASTNode * m_ast; // must use full name here because this is put into *.tab.hpp +} + +/* extra parameters for the parser and lexer */ +%parse-param {ElftosbLexer * lexer} +%parse-param {CommandFileASTNode ** resultAST} +%lex-param {ElftosbLexer * lexer} + +/* token definitions */ +%token <m_str> TOK_IDENT "identifier" +%token <m_str> TOK_STRING_LITERAL "string" +%token <m_int> TOK_INT_LITERAL "integer" +%token <m_str> TOK_SECTION_NAME "section name" +%token <m_str> TOK_SOURCE_NAME "source name" +%token <m_blob> TOK_BLOB "binary object" +%token '(' +%token ')' +%token '{' +%token '}' +%token '[' +%token ']' +%token '=' +%token ',' +%token ';' +%token ':' +%token '>' +%token '.' +%token TOK_DOT_DOT ".." +%token '~' +%token '&' +%token '|' +%token '<' +%token '>' +%token '!' +%token TOK_AND "&&" +%token TOK_OR "||" +%token TOK_GEQ ">=" +%token TOK_LEQ "<=" +%token TOK_EQ "==" +%token TOK_NEQ "!=" +%token TOK_POWER "**" +%token TOK_LSHIFT "<<" +%token TOK_RSHIFT ">>" +%token <m_int> TOK_INT_SIZE "integer size" +%token TOK_OPTIONS "options" +%token TOK_CONSTANTS "constants" +%token TOK_SOURCES "sources" +%token TOK_FILTERS "filters" +%token TOK_SECTION "section" +%token TOK_EXTERN "extern" +%token TOK_FROM "from" +%token TOK_RAW "raw" +%token TOK_LOAD "load" +%token TOK_JUMP "jump" +%token TOK_CALL "call" +%token TOK_MODE "mode" +%token TOK_IF "if" +%token TOK_ELSE "else" +%token TOK_DEFINED "defined" +%token TOK_INFO "info" +%token TOK_WARNING "warning" +%token TOK_ERROR "error" +%token TOK_SIZEOF "sizeof" +%token TOK_DCD "dcd" +%token TOK_HAB "hab" +%token TOK_IVT "ivt" + +/* operator precedence */ +%left "&&" "||" +%left '>' '<' ">=" "<=" "==" "!=" +%left '|' +%left '^' +%left '&' +%left "<<" ">>" +%left "**" +%left '+' '-' +%left '*' '/' '%' +%left '.' +%right UNARY_OP + +/* nonterminal types - most nonterminal symbols are subclasses of ASTNode */ +%type <m_ast> command_file blocks_list pre_section_block options_block const_def_list const_def_list_elem +%type <m_ast> const_def const_expr expr int_const_expr unary_expr int_value constants_block +%type <m_ast> sources_block source_def_list source_def_list_elem source_def +%type <m_ast> section_defs section_def section_contents full_stmt_list full_stmt_list_elem +%type <m_ast> basic_stmt load_stmt call_stmt from_stmt load_data load_target call_target +%type <m_ast> address_or_range load_target_opt call_arg_opt basic_stmt_list basic_stmt_list_elem +%type <m_ast> source_attr_list source_attr_list_elem source_attrs_opt +%type <m_ast> section_list section_list_elem symbol_ref mode_stmt +%type <m_ast> section_options_opt source_attr_list_opt +%type <m_ast> if_stmt else_opt message_stmt +%type <m_ast> bool_expr ivt_def assignment_list_opt + +%type <m_num> call_or_jump dcd_opt + +%destructor { delete $$; } TOK_IDENT TOK_STRING_LITERAL TOK_SECTION_NAME TOK_SOURCE_NAME TOK_BLOB TOK_INT_SIZE TOK_INT_LITERAL + +%% + +command_file : blocks_list section_defs + { + CommandFileASTNode * commandFile = new CommandFileASTNode(); + commandFile->setBlocks(dynamic_cast<ListASTNode*>($1)); + commandFile->setSections(dynamic_cast<ListASTNode*>($2)); + commandFile->setLocation(@1, @2); + *resultAST = commandFile; + } + ; + +blocks_list : pre_section_block + { + ListASTNode * list = new ListASTNode(); + list->appendNode($1); + $$ = list; + } + | blocks_list pre_section_block + { + dynamic_cast<ListASTNode*>($1)->appendNode($2); + $$ = $1; + } + ; + +pre_section_block + : options_block { $$ = $1; } + | constants_block { $$ = $1; } + | sources_block { $$ = $1; } + ; + +options_block : "options" '{' const_def_list '}' + { + $$ = new OptionsBlockASTNode(dynamic_cast<ListASTNode *>($3)); + } + ; + +constants_block : "constants" '{' const_def_list '}' + { + $$ = new ConstantsBlockASTNode(dynamic_cast<ListASTNode *>($3)); + } + ; + +const_def_list : const_def_list_elem + { + ListASTNode * list = new ListASTNode(); + list->appendNode($1); + $$ = list; + } + | const_def_list const_def_list_elem + { + dynamic_cast<ListASTNode*>($1)->appendNode($2); + $$ = $1; + } + ; + +const_def_list_elem : const_def ';' { $$ = $1; } + | /* empty */ { $$ = NULL; } + ; + +const_def : TOK_IDENT '=' const_expr + { + $$ = new AssignmentASTNode($1, $3); + $$->setLocation(@1, @3); + } + ; + +sources_block : "sources" '{' source_def_list '}' + { + $$ = new SourcesBlockASTNode(dynamic_cast<ListASTNode *>($3)); + } + ; + +source_def_list : source_def_list_elem + { + ListASTNode * list = new ListASTNode(); + list->appendNode($1); + $$ = list; + } + | source_def_list source_def_list_elem + { + dynamic_cast<ListASTNode*>($1)->appendNode($2); + $$ = $1; + } + ; + +source_def_list_elem + : source_def source_attrs_opt ';' + { + // tell the lexer that this is the name of a source file + SourceDefASTNode * node = dynamic_cast<SourceDefASTNode*>($1); + if ($2) + { + node->setAttributes(dynamic_cast<ListASTNode*>($2)); + } + node->setLocation(node->getLocation(), @3); + lexer->addSourceName(node->getName()); + $$ = $1; + } + | /* empty */ { $$ = NULL; } + ; + +source_def : TOK_IDENT '=' TOK_STRING_LITERAL + { + $$ = new PathSourceDefASTNode($1, $3); + $$->setLocation(@1, @3); + } + | TOK_IDENT '=' "extern" '(' int_const_expr ')' + { + $$ = new ExternSourceDefASTNode($1, dynamic_cast<ExprASTNode*>($5)); + $$->setLocation(@1, @6); + } + ; + +source_attrs_opt + : '(' source_attr_list ')' { $$ = $2; } + | /* empty */ { $$ = NULL; } + ; + +source_attr_list + : source_attr_list_elem + { + ListASTNode * list = new ListASTNode(); + list->appendNode($1); + $$ = list; + } + | source_attr_list ',' source_attr_list_elem + { + dynamic_cast<ListASTNode*>($1)->appendNode($3); + $$ = $1; + } + ; + +source_attr_list_elem + : TOK_IDENT '=' const_expr + { + $$ = new AssignmentASTNode($1, $3); + $$->setLocation(@1, @3); + } + ; + +section_defs : section_def + { + ListASTNode * list = new ListASTNode(); + list->appendNode($1); + $$ = list; + } + | section_defs section_def + { + dynamic_cast<ListASTNode*>($1)->appendNode($2); + $$ = $1; + } + ; + +section_def : "section" '(' int_const_expr section_options_opt ')' section_contents + { + SectionContentsASTNode * sectionNode = dynamic_cast<SectionContentsASTNode*>($6); + if (sectionNode) + { + ExprASTNode * exprNode = dynamic_cast<ExprASTNode*>($3); + sectionNode->setSectionNumberExpr(exprNode); + sectionNode->setOptions(dynamic_cast<ListASTNode*>($4)); + sectionNode->setLocation(@1, sectionNode->getLocation()); + } + $$ = $6; + } + ; + +section_options_opt + : ';' source_attr_list_opt + { + $$ = $2; + } + | /* empty */ + { + $$ = NULL; + } + ; + +source_attr_list_opt + : source_attr_list + { + $$ = $1; + } + | /* empty */ + { + $$ = NULL; + } + ; + +section_contents + : "<=" load_data ';' + { + DataSectionContentsASTNode * dataSection = new DataSectionContentsASTNode($2); + dataSection->setLocation(@1, @3); + $$ = dataSection; + } + | '{' full_stmt_list '}' + { + ListASTNode * listNode = dynamic_cast<ListASTNode*>($2); + $$ = new BootableSectionContentsASTNode(listNode); + $$->setLocation(@1, @3); + } + ; + +full_stmt_list : full_stmt_list_elem + { + ListASTNode * list = new ListASTNode(); + list->appendNode($1); + $$ = list; + } + | full_stmt_list full_stmt_list_elem + { + dynamic_cast<ListASTNode*>($1)->appendNode($2); + $$ = $1; + } + ; + +full_stmt_list_elem + : basic_stmt ';' { $$ = $1; } + | from_stmt { $$ = $1; } + | if_stmt { $$ = $1; } + | /* empty */ { $$ = NULL; } + ; + +basic_stmt_list : basic_stmt_list_elem + { + ListASTNode * list = new ListASTNode(); + list->appendNode($1); + $$ = list; + } + | basic_stmt_list basic_stmt_list_elem + { + dynamic_cast<ListASTNode*>($1)->appendNode($2); + $$ = $1; + } + ; + +basic_stmt_list_elem + : basic_stmt ';' { $$ = $1; } + | if_stmt { $$ = $1; } + | /* empty */ { $$ = NULL; } + ; + +basic_stmt : load_stmt { $$ = $1; } + | call_stmt { $$ = $1; } + | mode_stmt { $$ = $1; } + | message_stmt { $$ = $1; } + ; + +load_stmt : "load" dcd_opt load_data load_target_opt + { + LoadStatementASTNode * stmt = new LoadStatementASTNode(); + stmt->setData($3); + stmt->setTarget($4); + // set dcd load flag if the "dcd" keyword was present. + if ($2) + { + stmt->setDCDLoad(true); + } + // set char locations for the statement + if ($4) + { + stmt->setLocation(@1, @4); + } + else + { + stmt->setLocation(@1, @3); + } + $$ = stmt; + } + ; + +dcd_opt : "dcd" + { + if (!elftosb::g_enableHABSupport) + { + yyerror(&yylloc, lexer, resultAST, "HAB features not supported with the selected family"); + YYABORT; + } + + $$ = 1; + } + | /* empty */ { $$ = 0; } + +load_data : int_const_expr + { + $$ = $1; + } + | TOK_STRING_LITERAL + { + $$ = new StringConstASTNode($1); + $$->setLocation(@1); + } + | TOK_SOURCE_NAME + { + $$ = new SourceASTNode($1); + $$->setLocation(@1); + } + | section_list + { + $$ = new SectionMatchListASTNode(dynamic_cast<ListASTNode*>($1)); + $$->setLocation(@1); + } + | section_list "from" TOK_SOURCE_NAME + { + $$ = new SectionMatchListASTNode(dynamic_cast<ListASTNode*>($1), $3); + $$->setLocation(@1, @3); + } + | TOK_SOURCE_NAME '[' section_list ']' + { + $$ = new SectionMatchListASTNode(dynamic_cast<ListASTNode*>($3), $1); + $$->setLocation(@1, @4); + } + | TOK_BLOB + { + $$ = new BlobConstASTNode($1); + $$->setLocation(@1); + } + | ivt_def + { + } + ; + +section_list : section_list_elem + { + ListASTNode * list = new ListASTNode(); + list->appendNode($1); + $$ = list; + } + | section_list ',' section_list_elem + { + dynamic_cast<ListASTNode*>($1)->appendNode($3); + $$ = $1; + } + ; + +section_list_elem + : TOK_SECTION_NAME + { + $$ = new SectionASTNode($1, SectionASTNode::kInclude); + $$->setLocation(@1); + } + | '~' TOK_SECTION_NAME + { + $$ = new SectionASTNode($2, SectionASTNode::kExclude); + $$->setLocation(@1, @2); + } + ; + +load_target_opt : '>' load_target + { + $$ = $2; + } + | /* empty */ + { + $$ = new NaturalLocationASTNode(); +// $$->setLocation(); + } + ; + +load_target : '.' + { + $$ = new NaturalLocationASTNode(); + $$->setLocation(@1); + } + | address_or_range + { + $$ = $1; + } + ; + +ivt_def : "ivt" '(' assignment_list_opt ')' + { + IVTConstASTNode * ivt = new IVTConstASTNode(); + if ($3) + { + ivt->setFieldAssignments(dynamic_cast<ListASTNode*>($3)); + } + ivt->setLocation(@1, @4); + $$ = ivt; + } + ; + +assignment_list_opt : source_attr_list { $$ = $1; } + | /* empty */ { $$ = NULL; } + ; + +call_stmt : call_or_jump call_target call_arg_opt + { + CallStatementASTNode * stmt = new CallStatementASTNode(); + switch ($1) + { + case 1: + stmt->setCallType(CallStatementASTNode::kCallType); + break; + case 2: + stmt->setCallType(CallStatementASTNode::kJumpType); + break; + default: + yyerror(&yylloc, lexer, resultAST, "invalid call_or_jump value"); + YYABORT; + break; + } + stmt->setTarget($2); + stmt->setArgument($3); + stmt->setIsHAB(false); + if ($3) + { + stmt->setLocation(@1, @3); + } + else + { + stmt->setLocation(@1, @2); + } + $$ = stmt; + } + | "hab" call_or_jump address_or_range call_arg_opt + { + if (!elftosb::g_enableHABSupport) + { + yyerror(&yylloc, lexer, resultAST, "HAB features not supported with the selected family"); + YYABORT; + } + + CallStatementASTNode * stmt = new CallStatementASTNode(); + switch ($2) + { + case 1: + stmt->setCallType(CallStatementASTNode::kCallType); + break; + case 2: + stmt->setCallType(CallStatementASTNode::kJumpType); + break; + default: + yyerror(&yylloc, lexer, resultAST, "invalid call_or_jump value"); + YYABORT; + break; + } + stmt->setTarget($3); + stmt->setArgument($4); + stmt->setIsHAB(true); + if ($4) + { + stmt->setLocation(@1, @4); + } + else + { + stmt->setLocation(@1, @3); + } + $$ = stmt; + } + ; + +call_or_jump : "call" { $$ = 1; } + | "jump" { $$ = 2; } + ; + +call_target : TOK_SOURCE_NAME + { + $$ = new SymbolASTNode(NULL, $1); + $$->setLocation(@1); + } + | int_const_expr + { + $$ = new AddressRangeASTNode($1, NULL); + $$->setLocation($1); + } + ; + +call_arg_opt : '(' int_const_expr ')' { $$ = $2; } + | '(' ')' { $$ = NULL; } + | /* empty */ { $$ = NULL; } + ; + +from_stmt : "from" TOK_SOURCE_NAME '{' basic_stmt_list '}' + { + $$ = new FromStatementASTNode($2, dynamic_cast<ListASTNode*>($4)); + $$->setLocation(@1, @5); + } + ; + +mode_stmt : "mode" int_const_expr + { + $$ = new ModeStatementASTNode(dynamic_cast<ExprASTNode*>($2)); + $$->setLocation(@1, @2); + } + ; + +message_stmt : "info" TOK_STRING_LITERAL + { + $$ = new MessageStatementASTNode(MessageStatementASTNode::kInfo, $2); + $$->setLocation(@1, @2); + } + | "warning" TOK_STRING_LITERAL + { + $$ = new MessageStatementASTNode(MessageStatementASTNode::kWarning, $2); + $$->setLocation(@1, @2); + } + | "error" TOK_STRING_LITERAL + { + $$ = new MessageStatementASTNode(MessageStatementASTNode::kError, $2); + $$->setLocation(@1, @2); + } + ; + +if_stmt : "if" bool_expr '{' full_stmt_list '}' else_opt + { + IfStatementASTNode * ifStmt = new IfStatementASTNode(); + ifStmt->setConditionExpr(dynamic_cast<ExprASTNode*>($2)); + ifStmt->setIfStatements(dynamic_cast<ListASTNode*>($4)); + ifStmt->setElseStatements(dynamic_cast<ListASTNode*>($6)); + ifStmt->setLocation(@1, @6); + $$ = ifStmt; + } + ; + +else_opt : "else" '{' full_stmt_list '}' + { + $$ = $3; + } + | "else" if_stmt + { + ListASTNode * list = new ListASTNode(); + list->appendNode($2); + $$ = list; + $$->setLocation(@1, @2); + } + | /* empty */ { $$ = NULL; } + ; + +address_or_range : int_const_expr + { + $$ = new AddressRangeASTNode($1, NULL); + $$->setLocation($1); + } + | int_const_expr ".." int_const_expr + { + $$ = new AddressRangeASTNode($1, $3); + $$->setLocation(@1, @3); + } + ; + +const_expr : bool_expr + { + $$ = $1; + } + | TOK_STRING_LITERAL + { + $$ = new StringConstASTNode($1); + $$->setLocation(@1); + } + ; + +bool_expr : int_const_expr + { + $$ = $1; + } + | bool_expr '<' bool_expr + { + ExprASTNode * left = dynamic_cast<ExprASTNode*>($1); + ExprASTNode * right = dynamic_cast<ExprASTNode*>($3); + $$ = new BinaryOpExprASTNode(left, BinaryOpExprASTNode::kLessThan, right); + $$->setLocation(@1, @3); + } + | bool_expr '>' bool_expr + { + ExprASTNode * left = dynamic_cast<ExprASTNode*>($1); + ExprASTNode * right = dynamic_cast<ExprASTNode*>($3); + $$ = new BinaryOpExprASTNode(left, BinaryOpExprASTNode::kGreaterThan, right); + $$->setLocation(@1, @3); + } + | bool_expr ">=" bool_expr + { + ExprASTNode * left = dynamic_cast<ExprASTNode*>($1); + ExprASTNode * right = dynamic_cast<ExprASTNode*>($3); + $$ = new BinaryOpExprASTNode(left, BinaryOpExprASTNode::kGreaterThanEqual, right); + $$->setLocation(@1, @3); + } + | bool_expr "<=" bool_expr + { + ExprASTNode * left = dynamic_cast<ExprASTNode*>($1); + ExprASTNode * right = dynamic_cast<ExprASTNode*>($3); + $$ = new BinaryOpExprASTNode(left, BinaryOpExprASTNode::kLessThanEqual, right); + $$->setLocation(@1, @3); + } + | bool_expr "==" bool_expr + { + ExprASTNode * left = dynamic_cast<ExprASTNode*>($1); + ExprASTNode * right = dynamic_cast<ExprASTNode*>($3); + $$ = new BinaryOpExprASTNode(left, BinaryOpExprASTNode::kEqual, right); + $$->setLocation(@1, @3); + } + | bool_expr "!=" bool_expr + { + ExprASTNode * left = dynamic_cast<ExprASTNode*>($1); + ExprASTNode * right = dynamic_cast<ExprASTNode*>($3); + $$ = new BinaryOpExprASTNode(left, BinaryOpExprASTNode::kNotEqual, right); + $$->setLocation(@1, @3); + } + | bool_expr "&&" bool_expr + { + ExprASTNode * left = dynamic_cast<ExprASTNode*>($1); + ExprASTNode * right = dynamic_cast<ExprASTNode*>($3); + $$ = new BinaryOpExprASTNode(left, BinaryOpExprASTNode::kBooleanAnd, right); + $$->setLocation(@1, @3); + } + | bool_expr "||" bool_expr + { + ExprASTNode * left = dynamic_cast<ExprASTNode*>($1); + ExprASTNode * right = dynamic_cast<ExprASTNode*>($3); + $$ = new BinaryOpExprASTNode(left, BinaryOpExprASTNode::kBooleanOr, right); + $$->setLocation(@1, @3); + } + | '!' bool_expr %prec UNARY_OP + { + $$ = new BooleanNotExprASTNode(dynamic_cast<ExprASTNode*>($2)); + $$->setLocation(@1, @2); + } + | TOK_IDENT '(' TOK_SOURCE_NAME ')' + { + $$ = new SourceFileFunctionASTNode($1, $3); + $$->setLocation(@1, @4); + } + | '(' bool_expr ')' + { + $$ = $2; + $$->setLocation(@1, @3); + } + | "defined" '(' TOK_IDENT ')' + { + $$ = new DefinedOperatorASTNode($3); + $$->setLocation(@1, @4); + } + ; + +int_const_expr : expr { $$ = $1; } + ; + +symbol_ref : TOK_SOURCE_NAME ':' TOK_IDENT + { + $$ = new SymbolASTNode($3, $1); + $$->setLocation(@1, @3); + } + | ':' TOK_IDENT + { + $$ = new SymbolASTNode($2); + $$->setLocation(@1, @2); + } + ; + + +expr : int_value + { + $$ = $1; + } + | TOK_IDENT + { + $$ = new VariableExprASTNode($1); + $$->setLocation(@1); + } + | symbol_ref + { + $$ = new SymbolRefExprASTNode(dynamic_cast<SymbolASTNode*>($1)); + $$->setLocation(@1); + } +/* | expr '..' expr + { + ExprASTNode * left = dynamic_cast<ExprASTNode*>($1); + ExprASTNode * right = dynamic_cast<ExprASTNode*>($3); + $$ = new RangeExprASTNode(left, right); + } +*/ | expr '+' expr + { + ExprASTNode * left = dynamic_cast<ExprASTNode*>($1); + ExprASTNode * right = dynamic_cast<ExprASTNode*>($3); + $$ = new BinaryOpExprASTNode(left, BinaryOpExprASTNode::kAdd, right); + $$->setLocation(@1, @3); + } + | expr '-' expr + { + ExprASTNode * left = dynamic_cast<ExprASTNode*>($1); + ExprASTNode * right = dynamic_cast<ExprASTNode*>($3); + $$ = new BinaryOpExprASTNode(left, BinaryOpExprASTNode::kSubtract, right); + $$->setLocation(@1, @3); + } + | expr '*' expr + { + ExprASTNode * left = dynamic_cast<ExprASTNode*>($1); + ExprASTNode * right = dynamic_cast<ExprASTNode*>($3); + $$ = new BinaryOpExprASTNode(left, BinaryOpExprASTNode::kMultiply, right); + $$->setLocation(@1, @3); + } + | expr '/' expr + { + ExprASTNode * left = dynamic_cast<ExprASTNode*>($1); + ExprASTNode * right = dynamic_cast<ExprASTNode*>($3); + $$ = new BinaryOpExprASTNode(left, BinaryOpExprASTNode::kDivide, right); + $$->setLocation(@1, @3); + } + | expr '%' expr + { + ExprASTNode * left = dynamic_cast<ExprASTNode*>($1); + ExprASTNode * right = dynamic_cast<ExprASTNode*>($3); + $$ = new BinaryOpExprASTNode(left, BinaryOpExprASTNode::kModulus, right); + $$->setLocation(@1, @3); + } + | expr "**" expr + { + ExprASTNode * left = dynamic_cast<ExprASTNode*>($1); + ExprASTNode * right = dynamic_cast<ExprASTNode*>($3); + $$ = new BinaryOpExprASTNode(left, BinaryOpExprASTNode::kPower, right); + $$->setLocation(@1, @3); + } + | expr '&' expr + { + ExprASTNode * left = dynamic_cast<ExprASTNode*>($1); + ExprASTNode * right = dynamic_cast<ExprASTNode*>($3); + $$ = new BinaryOpExprASTNode(left, BinaryOpExprASTNode::kBitwiseAnd, right); + $$->setLocation(@1, @3); + } + | expr '|' expr + { + ExprASTNode * left = dynamic_cast<ExprASTNode*>($1); + ExprASTNode * right = dynamic_cast<ExprASTNode*>($3); + $$ = new BinaryOpExprASTNode(left, BinaryOpExprASTNode::kBitwiseOr, right); + $$->setLocation(@1, @3); + } + | expr '^' expr + { + ExprASTNode * left = dynamic_cast<ExprASTNode*>($1); + ExprASTNode * right = dynamic_cast<ExprASTNode*>($3); + $$ = new BinaryOpExprASTNode(left, BinaryOpExprASTNode::kBitwiseXor, right); + $$->setLocation(@1, @3); + } + | expr "<<" expr + { + ExprASTNode * left = dynamic_cast<ExprASTNode*>($1); + ExprASTNode * right = dynamic_cast<ExprASTNode*>($3); + $$ = new BinaryOpExprASTNode(left, BinaryOpExprASTNode::kShiftLeft, right); + $$->setLocation(@1, @3); + } + | expr ">>" expr + { + ExprASTNode * left = dynamic_cast<ExprASTNode*>($1); + ExprASTNode * right = dynamic_cast<ExprASTNode*>($3); + $$ = new BinaryOpExprASTNode(left, BinaryOpExprASTNode::kShiftRight, right); + $$->setLocation(@1, @3); + } + | unary_expr + { + $$ = $1; + } + | expr '.' TOK_INT_SIZE + { + $$ = new IntSizeExprASTNode(dynamic_cast<ExprASTNode*>($1), $3->getWordSize()); + $$->setLocation(@1, @3); + } + | '(' expr ')' + { + $$ = $2; + $$->setLocation(@1, @3); + } + | "sizeof" '(' symbol_ref ')' + { + $$ = new SizeofOperatorASTNode(dynamic_cast<SymbolASTNode*>($3)); + $$->setLocation(@1, @4); + } + | "sizeof" '(' TOK_IDENT ')' + { + $$ = new SizeofOperatorASTNode($3); + $$->setLocation(@1, @4); + } + | "sizeof" '(' TOK_SOURCE_NAME ')' + { + $$ = new SizeofOperatorASTNode($3); + $$->setLocation(@1, @4); + } + ; + +unary_expr : '+' expr %prec UNARY_OP + { + $$ = $2; + } + | '-' expr %prec UNARY_OP + { + $$ = new NegativeExprASTNode(dynamic_cast<ExprASTNode*>($2)); + $$->setLocation(@1, @2); + } + ; + +int_value : TOK_INT_LITERAL + { + $$ = new IntConstExprASTNode($1->getValue(), $1->getWordSize()); + $$->setLocation(@1); + } + ; + +%% + +/* code goes here */ + +static int yylex(YYSTYPE * lvalp, YYLTYPE * yylloc, ElftosbLexer * lexer) +{ + int token = lexer->yylex(); + *yylloc = lexer->getLocation(); + lexer->getSymbolValue(lvalp); + return token; +} + +static void yyerror(YYLTYPE * yylloc, ElftosbLexer * lexer, CommandFileASTNode ** resultAST, const char * error) +{ + throw syntax_error(format_string("line %d: %s\n", yylloc->m_firstLine, error)); +} + |