[PATCH] Implementation of #pragma (data|code|const|bss)_seg
Reid Kleckner
rnk at google.com
Wed Mar 26 16:15:49 PDT 2014
================
Comment at: lib/Parse/ParsePragma.cpp:449
@@ +448,3 @@
+ if (Parens.consumeOpen())
+ goto ERROR_RETURN;
+ Sema::PragmaMsStackAction Action = Sema::PSK_Reset;
----------------
gotos aren't common in LLVM, and there aren't any ALL_CAPS names, even for macros or enums.
I'd rather have a static helper like eatPastEOFToken() and do 'return eatPastEOFToken(PP)' for all of these gotos. Nevermind that we're returning void. :)
================
Comment at: lib/Parse/ParsePragma.cpp:441
@@ +440,3 @@
+ // because lex shouldn't emit the annotation token for unrecognized pragmas.
+ enum PragmaMSKind { DataSeg, BSSSeg, ConstSeg, CodeSeg } Kind =
+ llvm::StringSwitch<PragmaMSKind>(PragmaName)
----------------
Rather than making a new enum, how about using MSSegmentAttr::CodeSeg, etc? We should be able to include clang/AST/Attr.h from here.
================
Comment at: lib/Parse/ParsePragma.cpp:502-509
@@ +501,10 @@
+ PP.Lex(Tok); // eof
+ if (Kind == DataSeg)
+ Actions.ActOnPragmaMSDataSeg(PragmaLoc, Action, SlotLabel, SegmentName);
+ else if (Kind == BSSSeg)
+ Actions.ActOnPragmaMSBSSSeg(PragmaLoc, Action, SlotLabel, SegmentName);
+ else if (Kind == ConstSeg)
+ Actions.ActOnPragmaMSConstSeg(PragmaLoc, Action, SlotLabel, SegmentName);
+ else if (Kind == CodeSeg)
+ Actions.ActOnPragmaMSCodeSeg(PragmaLoc, Action, SlotLabel, SegmentName);
+ return;
----------------
Once we use MSSegmentAttr::Kind, we collapse these Sema actions down to ActOnPragmaMSSegment() and make the kind a parameter.
================
Comment at: include/clang/Sema/Sema.h:7066-7089
@@ -7032,2 +7065,26 @@
+ /// \brief Called on well formed \#pragma data_seg().
+ void ActOnPragmaMSDataSeg(SourceLocation PragmaLocation,
+ PragmaMsStackAction Action,
+ llvm::StringRef StackSlotLabel,
+ StringLiteral *SegmentName);
+
+ /// \brief Called on well formed \#pragma bss_seg().
+ void ActOnPragmaMSBSSSeg(SourceLocation PragmaLocation,
+ PragmaMsStackAction Action,
+ llvm::StringRef StackSlotLabel,
+ StringLiteral *SegmentName);
+
+ /// \brief Called on well formed \#pragma const_seg().
+ void ActOnPragmaMSConstSeg(SourceLocation PragmaLocation,
+ PragmaMsStackAction Action,
+ llvm::StringRef StackSlotLabel,
+ StringLiteral *SegmentName);
+
+ /// \brief Called on well formed \#pragma code_seg().
+ void ActOnPragmaMSCodeSeg(SourceLocation PragmaLocation,
+ PragmaMsStackAction Action,
+ llvm::StringRef StackSlotLabel,
+ StringLiteral *SegmentName);
+
/// ActOnPragmaDetectMismatch - Call on well-formed \#pragma detect_mismatch
----------------
IMO we should only have one action here, and make the attribute kind a parameter. We'll need to add one more for init_seg anyway.
http://llvm-reviews.chandlerc.com/D3065
More information about the cfe-commits
mailing list