mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-15 04:30:12 +00:00
MCParser: Modernize memory handling.
NFC. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@218998 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
83e571e7ba
commit
3c5eaffc07
@ -69,8 +69,8 @@ struct MCAsmMacro {
|
||||
MCAsmMacroParameters Parameters;
|
||||
|
||||
public:
|
||||
MCAsmMacro(StringRef N, StringRef B, ArrayRef<MCAsmMacroParameter> P) :
|
||||
Name(N), Body(B), Parameters(P) {}
|
||||
MCAsmMacro(StringRef N, StringRef B, MCAsmMacroParameters P)
|
||||
: Name(N), Body(B), Parameters(std::move(P)) {}
|
||||
};
|
||||
|
||||
/// \brief Helper class for storing information about an active macro
|
||||
@ -121,7 +121,7 @@ private:
|
||||
SourceMgr &SrcMgr;
|
||||
SourceMgr::DiagHandlerTy SavedDiagHandler;
|
||||
void *SavedDiagContext;
|
||||
MCAsmParserExtension *PlatformParser;
|
||||
std::unique_ptr<MCAsmParserExtension> PlatformParser;
|
||||
|
||||
/// This is the current buffer index we're lexing from as managed by the
|
||||
/// SourceMgr object.
|
||||
@ -136,7 +136,7 @@ private:
|
||||
StringMap<ExtensionDirectiveHandler> ExtensionDirectiveMap;
|
||||
|
||||
/// \brief Map of currently defined macros.
|
||||
StringMap<MCAsmMacro*> MacroMap;
|
||||
StringMap<MCAsmMacro> MacroMap;
|
||||
|
||||
/// \brief Stack of active macro instantiations.
|
||||
std::vector<MacroInstantiation*> ActiveMacros;
|
||||
@ -262,7 +262,7 @@ private:
|
||||
const MCAsmMacro* lookupMacro(StringRef Name);
|
||||
|
||||
/// \brief Define a new macro with the given name and information.
|
||||
void defineMacro(StringRef Name, const MCAsmMacro& Macro);
|
||||
void defineMacro(StringRef Name, MCAsmMacro Macro);
|
||||
|
||||
/// \brief Undefine a macro. If no such macro was defined, it's a no-op.
|
||||
void undefineMacro(StringRef Name);
|
||||
@ -502,34 +502,24 @@ AsmParser::AsmParser(SourceMgr &_SM, MCContext &_Ctx, MCStreamer &_Out,
|
||||
// Initialize the platform / file format parser.
|
||||
switch (_Ctx.getObjectFileInfo()->getObjectFileType()) {
|
||||
case MCObjectFileInfo::IsCOFF:
|
||||
PlatformParser = createCOFFAsmParser();
|
||||
PlatformParser->Initialize(*this);
|
||||
PlatformParser.reset(createCOFFAsmParser());
|
||||
break;
|
||||
case MCObjectFileInfo::IsMachO:
|
||||
PlatformParser = createDarwinAsmParser();
|
||||
PlatformParser->Initialize(*this);
|
||||
PlatformParser.reset(createDarwinAsmParser());
|
||||
IsDarwin = true;
|
||||
break;
|
||||
case MCObjectFileInfo::IsELF:
|
||||
PlatformParser = createELFAsmParser();
|
||||
PlatformParser->Initialize(*this);
|
||||
PlatformParser.reset(createELFAsmParser());
|
||||
break;
|
||||
}
|
||||
|
||||
PlatformParser->Initialize(*this);
|
||||
initializeDirectiveKindMap();
|
||||
}
|
||||
|
||||
AsmParser::~AsmParser() {
|
||||
assert((HadError || ActiveMacros.empty()) &&
|
||||
"Unexpected active macro instantiation!");
|
||||
|
||||
// Destroy any macros.
|
||||
for (StringMap<MCAsmMacro *>::iterator it = MacroMap.begin(),
|
||||
ie = MacroMap.end();
|
||||
it != ie; ++it)
|
||||
delete it->getValue();
|
||||
|
||||
delete PlatformParser;
|
||||
}
|
||||
|
||||
void AsmParser::printMacroInstantiations() {
|
||||
@ -2088,21 +2078,15 @@ bool AsmParser::parseMacroArguments(const MCAsmMacro *M,
|
||||
}
|
||||
|
||||
const MCAsmMacro *AsmParser::lookupMacro(StringRef Name) {
|
||||
StringMap<MCAsmMacro *>::iterator I = MacroMap.find(Name);
|
||||
return (I == MacroMap.end()) ? nullptr : I->getValue();
|
||||
StringMap<MCAsmMacro>::iterator I = MacroMap.find(Name);
|
||||
return (I == MacroMap.end()) ? nullptr : &I->getValue();
|
||||
}
|
||||
|
||||
void AsmParser::defineMacro(StringRef Name, const MCAsmMacro &Macro) {
|
||||
MacroMap[Name] = new MCAsmMacro(Macro);
|
||||
void AsmParser::defineMacro(StringRef Name, MCAsmMacro Macro) {
|
||||
MacroMap.insert(std::make_pair(Name, std::move(Macro)));
|
||||
}
|
||||
|
||||
void AsmParser::undefineMacro(StringRef Name) {
|
||||
StringMap<MCAsmMacro *>::iterator I = MacroMap.find(Name);
|
||||
if (I != MacroMap.end()) {
|
||||
delete I->getValue();
|
||||
MacroMap.erase(I);
|
||||
}
|
||||
}
|
||||
void AsmParser::undefineMacro(StringRef Name) { MacroMap.erase(Name); }
|
||||
|
||||
bool AsmParser::handleMacroEntry(const MCAsmMacro *M, SMLoc NameLoc) {
|
||||
// Arbitrarily limit macro nesting depth, to match 'as'. We can eliminate
|
||||
@ -3325,7 +3309,7 @@ bool AsmParser::parseDirectiveMacro(SMLoc DirectiveLoc) {
|
||||
"'" + Parameter.Name + "' in macro '" + Name + "'");
|
||||
}
|
||||
|
||||
Parameters.push_back(Parameter);
|
||||
Parameters.push_back(std::move(Parameter));
|
||||
|
||||
if (getLexer().is(AsmToken::Comma))
|
||||
Lex();
|
||||
@ -3377,7 +3361,7 @@ bool AsmParser::parseDirectiveMacro(SMLoc DirectiveLoc) {
|
||||
const char *BodyEnd = EndToken.getLoc().getPointer();
|
||||
StringRef Body = StringRef(BodyStart, BodyEnd - BodyStart);
|
||||
checkForBadMacro(DirectiveLoc, Name, Body, Parameters);
|
||||
defineMacro(Name, MCAsmMacro(Name, Body, Parameters));
|
||||
defineMacro(Name, MCAsmMacro(Name, Body, std::move(Parameters)));
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -4306,7 +4290,8 @@ MCAsmMacro *AsmParser::parseMacroLikeBody(SMLoc DirectiveLoc) {
|
||||
StringRef Body = StringRef(BodyStart, BodyEnd - BodyStart);
|
||||
|
||||
// We Are Anonymous.
|
||||
MacroLikeBodies.push_back(MCAsmMacro(StringRef(), Body, None));
|
||||
MacroLikeBodies.push_back(
|
||||
MCAsmMacro(StringRef(), Body, MCAsmMacroParameters()));
|
||||
return &MacroLikeBodies.back();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user