29 template <
bool (COFFMasmParser::*HandlerMethod)(StringRef, SMLoc)>
32 std::make_pair(
this, HandleDirective<COFFMasmParser, HandlerMethod>);
33 getParser().addDirectiveHandler(
Directive, Handler);
66 addDirectiveHandler<&COFFMasmParser::ParseSEHDirectiveAllocStack>(
68 addDirectiveHandler<&COFFMasmParser::ParseSEHDirectiveEndProlog>(
97 addDirectiveHandler<&COFFMasmParser::IgnoreDirective>(
".cref");
98 addDirectiveHandler<&COFFMasmParser::IgnoreDirective>(
".list");
99 addDirectiveHandler<&COFFMasmParser::IgnoreDirective>(
".listall");
100 addDirectiveHandler<&COFFMasmParser::IgnoreDirective>(
".listif");
101 addDirectiveHandler<&COFFMasmParser::IgnoreDirective>(
".listmacro");
102 addDirectiveHandler<&COFFMasmParser::IgnoreDirective>(
".listmacroall");
103 addDirectiveHandler<&COFFMasmParser::IgnoreDirective>(
".nocref");
104 addDirectiveHandler<&COFFMasmParser::IgnoreDirective>(
".nolist");
105 addDirectiveHandler<&COFFMasmParser::IgnoreDirective>(
".nolistif");
106 addDirectiveHandler<&COFFMasmParser::IgnoreDirective>(
".nolistmacro");
107 addDirectiveHandler<&COFFMasmParser::IgnoreDirective>(
"page");
108 addDirectiveHandler<&COFFMasmParser::IgnoreDirective>(
"subtitle");
109 addDirectiveHandler<&COFFMasmParser::IgnoreDirective>(
".tfcond");
110 addDirectiveHandler<&COFFMasmParser::IgnoreDirective>(
"title");
116 addDirectiveHandler<&COFFMasmParser::ParseDirectiveAlias>(
"alias");
119 addDirectiveHandler<&COFFMasmParser::ParseDirectiveIncludelib>(
127 addDirectiveHandler<&COFFMasmParser::ParseDirectiveEndProc>(
"endp");
129 addDirectiveHandler<&COFFMasmParser::ParseDirectiveProc>(
"proc");
133 addDirectiveHandler<&COFFMasmParser::IgnoreDirective>(
".386");
134 addDirectiveHandler<&COFFMasmParser::IgnoreDirective>(
".386p");
135 addDirectiveHandler<&COFFMasmParser::IgnoreDirective>(
".387");
136 addDirectiveHandler<&COFFMasmParser::IgnoreDirective>(
".486");
137 addDirectiveHandler<&COFFMasmParser::IgnoreDirective>(
".486p");
138 addDirectiveHandler<&COFFMasmParser::IgnoreDirective>(
".586");
139 addDirectiveHandler<&COFFMasmParser::IgnoreDirective>(
".586p");
140 addDirectiveHandler<&COFFMasmParser::IgnoreDirective>(
".686");
141 addDirectiveHandler<&COFFMasmParser::IgnoreDirective>(
".686p");
142 addDirectiveHandler<&COFFMasmParser::IgnoreDirective>(
".k3d");
143 addDirectiveHandler<&COFFMasmParser::IgnoreDirective>(
".mmx");
144 addDirectiveHandler<&COFFMasmParser::IgnoreDirective>(
".xmm");
154 addDirectiveHandler<&COFFMasmParser::ParseDirectiveSegmentEnd>(
"ends");
156 addDirectiveHandler<&COFFMasmParser::ParseDirectiveSegment>(
"segment");
159 addDirectiveHandler<&COFFMasmParser::ParseSectionDirectiveCode>(
".code");
162 &COFFMasmParser::ParseSectionDirectiveInitializedData>(
".data");
164 &COFFMasmParser::ParseSectionDirectiveUninitializedData>(
".data?");
168 addDirectiveHandler<&COFFMasmParser::IgnoreDirective>(
".model");
184 return ParseSectionSwitch(
".text",
192 return ParseSectionSwitch(
".data",
200 return ParseSectionSwitch(
".bss",
208 bool CurrentProcedureFramed;
211 COFFMasmParser() =
default;
225 bool COFFMasmParser::ParseSectionSwitch(
StringRef Section,
232 bool COFFMasmParser::ParseSectionSwitch(
StringRef Section,
238 return TokError(
"unexpected token in section switching directive");
241 getStreamer().SwitchSection(getContext().getCOFFSection(
250 return TokError(
"expected identifier in directive");
251 SegmentName = getTok().getIdentifier();
258 if (SegmentName ==
"_TEXT" || SegmentName.
startswith(
"_TEXT$")) {
259 if (SegmentName.
size() == 5) {
269 getStreamer().SwitchSection(getContext().getCOFFSection(
279 return TokError(
"expected identifier in directive");
280 SegmentName = getTok().getIdentifier();
291 if (getParser().parseIdentifier(Lib))
292 return TokError(
"expected identifier in includelib directive");
296 getStreamer().PushSection();
297 getStreamer().SwitchSection(getContext().getCOFFSection(
299 getStreamer().emitBytes(
"/DEFAULTLIB:");
300 getStreamer().emitBytes(Lib);
301 getStreamer().emitBytes(
" ");
302 getStreamer().PopSection();
313 if (getParser().parseIdentifier(Label))
314 return Error(Loc,
"expected identifier for procedure");
316 StringRef nextVal = getTok().getString();
317 SMLoc nextLoc = getTok().getLoc();
321 return Error(nextLoc,
"far procedure definitions not yet supported");
324 nextVal = getTok().getString();
325 nextLoc = getTok().getLoc();
328 MCSymbolCOFF *Sym = cast<MCSymbolCOFF>(getContext().getOrCreateSymbol(Label));
336 getTok().getString().equals_insensitive(
"frame")) {
339 getStreamer().EmitWinCFIStartProc(Sym, Loc);
341 getStreamer().emitLabel(Sym, Loc);
343 CurrentProcedure =
Label;
344 CurrentProcedureFramed = Framed;
349 SMLoc LabelLoc = getTok().getLoc();
350 if (getParser().parseIdentifier(Label))
351 return Error(LabelLoc,
"expected identifier for procedure end");
353 if (CurrentProcedure.empty())
354 return Error(Loc,
"endp outside of procedure block");
355 else if (CurrentProcedure != Label)
356 return Error(LabelLoc,
"endp does not match current procedure '" +
357 CurrentProcedure +
"'");
359 if (CurrentProcedureFramed) {
360 getStreamer().EmitWinCFIEndProc(Loc);
362 CurrentProcedure =
"";
363 CurrentProcedureFramed =
false;
368 std::string AliasName, ActualName;
370 getParser().parseAngleBracketString(AliasName))
371 return Error(getTok().getLoc(),
"expected <aliasName>");
373 return addErrorSuffix(
" in " +
Directive +
" directive");
375 getParser().parseAngleBracketString(ActualName))
376 return Error(getTok().getLoc(),
"expected <actualName>");
378 MCSymbol *Alias = getContext().getOrCreateSymbol(AliasName);
379 MCSymbol *Actual = getContext().getOrCreateSymbol(ActualName);
381 getStreamer().emitWeakReference(Alias, Actual);
389 SMLoc SizeLoc = getTok().getLoc();
390 if (getParser().parseAbsoluteExpression(Size))
391 return Error(SizeLoc,
"expected integer size");
393 return Error(SizeLoc,
"stack size must be a multiple of 8");
394 getStreamer().EmitWinCFIAllocStack(
static_cast<unsigned>(Size), Loc);
400 getStreamer().EmitWinCFIEndProlog(Loc);