1212#include " llvm/MC/MCAsmMacro.h"
1313#include " llvm/MC/MCContext.h"
1414#include " llvm/MC/MCParser/MCAsmLexer.h"
15- #include " llvm/MC/MCParser/MCAsmParser.h"
1615#include " llvm/MC/MCParser/MCAsmParserExtension.h"
17- #include " llvm/MC/MCParser/MCMasmParser.h"
1816#include " llvm/MC/MCParser/MCTargetAsmParser.h"
1917#include " llvm/MC/MCSectionCOFF.h"
2018#include " llvm/MC/MCStreamer.h"
@@ -43,7 +41,6 @@ class COFFMasmParser : public MCAsmParserExtension {
4341 StringRef COMDATSymName, COFF::COMDATType Type,
4442 Align Alignment);
4543
46- bool parseDirectiveModel (StringRef, SMLoc);
4744 bool parseDirectiveProc (StringRef, SMLoc);
4845 bool parseDirectiveEndProc (StringRef, SMLoc);
4946 bool parseDirectiveSegment (StringRef, SMLoc);
@@ -170,7 +167,7 @@ class COFFMasmParser : public MCAsmParserExtension {
170167 // .exit
171168 // .fardata
172169 // .fardata?
173- addDirectiveHandler<&COFFMasmParser::parseDirectiveModel >(" .model" );
170+ addDirectiveHandler<&COFFMasmParser::IgnoreDirective >(" .model" );
174171 // .stack
175172 // .startup
176173
@@ -204,13 +201,8 @@ class COFFMasmParser : public MCAsmParserExtension {
204201 }
205202
206203 // / Stack of active procedure definitions.
207- enum ProcDistance { PROC_DISTANCE_NEAR = 0 , PROC_DISTANCE_FAR = 1 };
208- struct ProcInfo {
209- StringRef Name;
210- ProcDistance Distance = PROC_DISTANCE_NEAR;
211- bool IsFramed = false ;
212- };
213- SmallVector<ProcInfo, 1 > CurrentProcedures;
204+ SmallVector<StringRef, 1 > CurrentProcedures;
205+ SmallVector<bool , 1 > CurrentProceduresFramed;
214206
215207public:
216208 COFFMasmParser () = default ;
@@ -443,75 +435,48 @@ bool COFFMasmParser::parseDirectiveOption(StringRef Directive, SMLoc Loc) {
443435 return false ;
444436}
445437
446- // / parseDirectiveModel
447- // / ::= ".model" "flat"
448- bool COFFMasmParser::parseDirectiveModel (StringRef Directive, SMLoc Loc) {
449- if (!getLexer ().is (AsmToken::Identifier))
450- return TokError (" expected identifier in directive" );
451-
452- StringRef ModelType = getTok ().getIdentifier ();
453- if (!ModelType.equals_insensitive (" flat" )) {
454- return TokError (
455- " expected 'flat' for memory model; no other models supported" );
456- }
457-
458- // Ignore; no action necessary.
459- Lex ();
460- return false ;
461- }
462-
463438// / parseDirectiveProc
464439// / TODO(epastor): Implement parameters and other attributes.
465- // / ::= label "proc" [[distance]] [[frame]]
440+ // / ::= label "proc" [[distance]]
466441// / statements
467442// / label "endproc"
468443bool COFFMasmParser::parseDirectiveProc (StringRef Directive, SMLoc Loc) {
469444 if (!getStreamer ().getCurrentFragment ())
470445 return Error (getTok ().getLoc (), " expected section directive" );
471446
472- ProcInfo Proc ;
473- if (getParser ().parseIdentifier (Proc. Name ))
447+ StringRef Label ;
448+ if (getParser ().parseIdentifier (Label ))
474449 return Error (Loc, " expected identifier for procedure" );
475- while (getLexer ().is (AsmToken::Identifier)) {
450+ if (getLexer ().is (AsmToken::Identifier)) {
476451 StringRef nextVal = getTok ().getString ();
477452 SMLoc nextLoc = getTok ().getLoc ();
478453 if (nextVal.equals_insensitive (" far" )) {
454+ // TODO(epastor): Handle far procedure definitions.
479455 Lex ();
480- Proc.Distance = PROC_DISTANCE_FAR;
481- nextVal = getTok ().getString ();
482- nextLoc = getTok ().getLoc ();
456+ return Error (nextLoc, " far procedure definitions not yet supported" );
483457 } else if (nextVal.equals_insensitive (" near" )) {
484458 Lex ();
485- Proc.Distance = PROC_DISTANCE_NEAR;
486- nextVal = getTok ().getString ();
487- nextLoc = getTok ().getLoc ();
488- } else if (nextVal.equals_insensitive (" frame" )) {
489- Lex ();
490- Proc.IsFramed = true ;
491459 nextVal = getTok ().getString ();
492460 nextLoc = getTok ().getLoc ();
493- } else {
494- break ;
495461 }
496462 }
497- MCSymbolCOFF *Sym =
498- cast<MCSymbolCOFF>(getContext ().getOrCreateSymbol (Proc.Name ));
463+ MCSymbolCOFF *Sym = cast<MCSymbolCOFF>(getContext ().getOrCreateSymbol (Label));
499464
500465 // Define symbol as simple external function
501466 Sym->setExternal (true );
502467 Sym->setType (COFF::IMAGE_SYM_DTYPE_FUNCTION << COFF::SCT_COMPLEX_TYPE_SHIFT);
503- if (Proc.Distance == PROC_DISTANCE_FAR)
504- Sym->setIsFarProc ();
505-
506- cast<MCMasmParser>(getParser ())
507- .setDefaultRetIsFar (Proc.Distance == PROC_DISTANCE_FAR);
508468
509- if (Proc.IsFramed ) {
469+ bool Framed = false ;
470+ if (getLexer ().is (AsmToken::Identifier) &&
471+ getTok ().getString ().equals_insensitive (" frame" )) {
472+ Lex ();
473+ Framed = true ;
510474 getStreamer ().emitWinCFIStartProc (Sym, Loc);
511475 }
512476 getStreamer ().emitLabel (Sym, Loc);
513477
514- CurrentProcedures.push_back (std::move (Proc));
478+ CurrentProcedures.push_back (Label);
479+ CurrentProceduresFramed.push_back (Framed);
515480 return false ;
516481}
517482bool COFFMasmParser::parseDirectiveEndProc (StringRef Directive, SMLoc Loc) {
@@ -522,18 +487,15 @@ bool COFFMasmParser::parseDirectiveEndProc(StringRef Directive, SMLoc Loc) {
522487
523488 if (CurrentProcedures.empty ())
524489 return Error (Loc, " endp outside of procedure block" );
525- else if (!CurrentProcedures.back ().Name . equals_insensitive (Label))
490+ else if (!CurrentProcedures.back ().equals_insensitive (Label))
526491 return Error (LabelLoc, " endp does not match current procedure '" +
527- CurrentProcedures.back (). Name + " '" );
492+ CurrentProcedures.back () + " '" );
528493
529- if (CurrentProcedures .back (). IsFramed ) {
494+ if (CurrentProceduresFramed .back ()) {
530495 getStreamer ().emitWinCFIEndProc (Loc);
531496 }
532497 CurrentProcedures.pop_back ();
533- cast<MCMasmParser>(getParser ())
534- .setDefaultRetIsFar (!CurrentProcedures.empty () &&
535- CurrentProcedures.back ().Distance ==
536- PROC_DISTANCE_FAR);
498+ CurrentProceduresFramed.pop_back ();
537499 return false ;
538500}
539501
0 commit comments