[cfe-commits] [LLVMdev] [cfe-dev] OpenMP support in CLANG: A proposal

Eli Friedman eli.friedman at gmail.com
Thu Oct 18 15:33:35 PDT 2012


On Thu, Oct 18, 2012 at 6:34 AM, Mahesha HS <mahesha.llvm at gmail.com> wrote:
> Sorry, in my previous mail,  I had missed to attach changes to
> "clang/include/clang/Basic/TokenKinds.def" in the patch 2. Please
> refer to the patch (2) attached in *this* mail, instead of the one
> sent in the previous mail. Patch 1 is fine.

+//--------------------------------
+// OpenMP directives
+//--------------------------------
+// \#pragam omp parallel ...
+TOK(pragma_omp_parallel)
+// \#pragam omp for ...
+TOK(pragma_omp_for)

Please use ANNOTATION(pragma_omp_parallel) etc. instead.

+/// PragmaOmpHandler - "\#pragma omp ...".
+template<class T, tok::TokenKind TKind>
+struct PragmaOmpHandler : public PragmaHandler {
+  PragmaOmpHandler() : PragmaHandler(T::Name) {}
+  virtual void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer,
+                            Token &OmpTok) {
+    PP.HandlePragmaOmp(OmpTok, TKind);
+  }
+};

Something like following would make your patch substantially shorter:

struct PragmaOmpHandler : public PragmaHandler {
  tok::TokenKind TKind;
  PragmaOmpHandler(tok::TokenKind Kind, StringRef Name)
    : PragmaHandler(Name), TKind(Kind) {}
  virtual void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer,
                            Token &OmpTok) {
    PP.HandlePragmaOmp(OmpTok, TKind);
  }
};


Please add a test that the pragmas round-trip correctly through clang -E.

-Eli



More information about the cfe-commits mailing list