12
12
#include " llvm/MC/MCAsmMacro.h"
13
13
#include " llvm/MC/MCContext.h"
14
14
#include " llvm/MC/MCParser/MCAsmLexer.h"
15
- #include " llvm/MC/MCParser/MCAsmParser.h"
16
15
#include " llvm/MC/MCParser/MCAsmParserExtension.h"
17
- #include " llvm/MC/MCParser/MCMasmParser.h"
18
16
#include " llvm/MC/MCParser/MCTargetAsmParser.h"
19
17
#include " llvm/MC/MCSectionCOFF.h"
20
18
#include " llvm/MC/MCStreamer.h"
@@ -43,7 +41,6 @@ class COFFMasmParser : public MCAsmParserExtension {
43
41
StringRef COMDATSymName, COFF::COMDATType Type,
44
42
Align Alignment);
45
43
46
- bool parseDirectiveModel (StringRef, SMLoc);
47
44
bool parseDirectiveProc (StringRef, SMLoc);
48
45
bool parseDirectiveEndProc (StringRef, SMLoc);
49
46
bool parseDirectiveSegment (StringRef, SMLoc);
@@ -170,7 +167,7 @@ class COFFMasmParser : public MCAsmParserExtension {
170
167
// .exit
171
168
// .fardata
172
169
// .fardata?
173
- addDirectiveHandler<&COFFMasmParser::parseDirectiveModel >(" .model" );
170
+ addDirectiveHandler<&COFFMasmParser::IgnoreDirective >(" .model" );
174
171
// .stack
175
172
// .startup
176
173
@@ -204,13 +201,8 @@ class COFFMasmParser : public MCAsmParserExtension {
204
201
}
205
202
206
203
// / 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;
214
206
215
207
public:
216
208
COFFMasmParser () = default ;
@@ -443,75 +435,48 @@ bool COFFMasmParser::parseDirectiveOption(StringRef Directive, SMLoc Loc) {
443
435
return false ;
444
436
}
445
437
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
-
463
438
// / parseDirectiveProc
464
439
// / TODO(epastor): Implement parameters and other attributes.
465
- // / ::= label "proc" [[distance]] [[frame]]
440
+ // / ::= label "proc" [[distance]]
466
441
// / statements
467
442
// / label "endproc"
468
443
bool COFFMasmParser::parseDirectiveProc (StringRef Directive, SMLoc Loc) {
469
444
if (!getStreamer ().getCurrentFragment ())
470
445
return Error (getTok ().getLoc (), " expected section directive" );
471
446
472
- ProcInfo Proc ;
473
- if (getParser ().parseIdentifier (Proc. Name ))
447
+ StringRef Label ;
448
+ if (getParser ().parseIdentifier (Label ))
474
449
return Error (Loc, " expected identifier for procedure" );
475
- while (getLexer ().is (AsmToken::Identifier)) {
450
+ if (getLexer ().is (AsmToken::Identifier)) {
476
451
StringRef nextVal = getTok ().getString ();
477
452
SMLoc nextLoc = getTok ().getLoc ();
478
453
if (nextVal.equals_insensitive (" far" )) {
454
+ // TODO(epastor): Handle far procedure definitions.
479
455
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" );
483
457
} else if (nextVal.equals_insensitive (" near" )) {
484
458
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 ;
491
459
nextVal = getTok ().getString ();
492
460
nextLoc = getTok ().getLoc ();
493
- } else {
494
- break ;
495
461
}
496
462
}
497
- MCSymbolCOFF *Sym =
498
- cast<MCSymbolCOFF>(getContext ().getOrCreateSymbol (Proc.Name ));
463
+ MCSymbolCOFF *Sym = cast<MCSymbolCOFF>(getContext ().getOrCreateSymbol (Label));
499
464
500
465
// Define symbol as simple external function
501
466
Sym->setExternal (true );
502
467
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);
508
468
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 ;
510
474
getStreamer ().emitWinCFIStartProc (Sym, Loc);
511
475
}
512
476
getStreamer ().emitLabel (Sym, Loc);
513
477
514
- CurrentProcedures.push_back (std::move (Proc));
478
+ CurrentProcedures.push_back (Label);
479
+ CurrentProceduresFramed.push_back (Framed);
515
480
return false ;
516
481
}
517
482
bool COFFMasmParser::parseDirectiveEndProc (StringRef Directive, SMLoc Loc) {
@@ -522,18 +487,15 @@ bool COFFMasmParser::parseDirectiveEndProc(StringRef Directive, SMLoc Loc) {
522
487
523
488
if (CurrentProcedures.empty ())
524
489
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))
526
491
return Error (LabelLoc, " endp does not match current procedure '" +
527
- CurrentProcedures.back (). Name + " '" );
492
+ CurrentProcedures.back () + " '" );
528
493
529
- if (CurrentProcedures .back (). IsFramed ) {
494
+ if (CurrentProceduresFramed .back ()) {
530
495
getStreamer ().emitWinCFIEndProc (Loc);
531
496
}
532
497
CurrentProcedures.pop_back ();
533
- cast<MCMasmParser>(getParser ())
534
- .setDefaultRetIsFar (!CurrentProcedures.empty () &&
535
- CurrentProcedures.back ().Distance ==
536
- PROC_DISTANCE_FAR);
498
+ CurrentProceduresFramed.pop_back ();
537
499
return false ;
538
500
}
539
501
0 commit comments