diff options
author | Alex Lorenz <arphaman@gmail.com> | 2015-08-21 21:32:39 +0000 |
---|---|---|
committer | Alex Lorenz <arphaman@gmail.com> | 2015-08-21 21:32:39 +0000 |
commit | 1de2acd3c2d94f424d2e8a1b366159c2578754e1 (patch) | |
tree | a15f088b2266db894cdba1fb85b3e62d3dceb24c /llvm/lib/AsmParser/LLParser.cpp | |
parent | 7a1483e7d1dceb9b9b59bc8d26a1418800d08e73 (diff) | |
download | bcm5719-llvm-1de2acd3c2d94f424d2e8a1b366159c2578754e1.tar.gz bcm5719-llvm-1de2acd3c2d94f424d2e8a1b366159c2578754e1.zip |
AsmParser: Save and restore the parsing state for types using SlotMapping.
This commit extends the 'SlotMapping' structure and includes mappings for named
and numbered types in it. The LLParser is extended accordingly to fill out
those mappings at the end of module parsing.
This information is useful when we want to parse standalone constant values
at a later stage using the 'parseConstantValue' method. The constant values
can be constant expressions, which can contain references to types. In order
to parse such constant values, we have to restore the internal named and
numbered mappings for the types in LLParser, otherwise the parser will report
a parsing error. Therefore, this commit also introduces a new method called
'restoreParsingState' to LLParser, which uses the slot mappings to restore
some of its internal parsing state.
This commit is required to serialize constant value pointers in the machine
memory operands for the MIR format.
Reviewers: Duncan P. N. Exon Smith
llvm-svn: 245740
Diffstat (limited to 'llvm/lib/AsmParser/LLParser.cpp')
-rw-r--r-- | llvm/lib/AsmParser/LLParser.cpp | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp index 83bc33d0e6c..fc7fceb2a26 100644 --- a/llvm/lib/AsmParser/LLParser.cpp +++ b/llvm/lib/AsmParser/LLParser.cpp @@ -49,7 +49,9 @@ bool LLParser::Run() { ValidateEndOfModule(); } -bool LLParser::parseStandaloneConstantValue(Constant *&C) { +bool LLParser::parseStandaloneConstantValue(Constant *&C, + const SlotMapping *Slots) { + restoreParsingState(Slots); Lex.Lex(); Type *Ty = nullptr; @@ -60,6 +62,19 @@ bool LLParser::parseStandaloneConstantValue(Constant *&C) { return false; } +void LLParser::restoreParsingState(const SlotMapping *Slots) { + if (!Slots) + return; + NumberedVals = Slots->GlobalValues; + NumberedMetadata = Slots->MetadataNodes; + for (const auto &I : Slots->NamedTypes) + NamedTypes.insert( + std::make_pair(I.getKey(), std::make_pair(I.second, LocTy()))); + for (const auto &I : Slots->Types) + NumberedTypes.insert( + std::make_pair(I.first, std::make_pair(I.second, LocTy()))); +} + /// ValidateEndOfModule - Do final validity and sanity checks at the end of the /// module. bool LLParser::ValidateEndOfModule() { @@ -181,6 +196,10 @@ bool LLParser::ValidateEndOfModule() { // the mapping from LLParser as it doesn't need it anymore. Slots->GlobalValues = std::move(NumberedVals); Slots->MetadataNodes = std::move(NumberedMetadata); + for (const auto &I : NamedTypes) + Slots->NamedTypes.insert(std::make_pair(I.getKey(), I.second.first)); + for (const auto &I : NumberedTypes) + Slots->Types.insert(std::make_pair(I.first, I.second.first)); return false; } |