How to add a new rewriting option

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

How to add a new rewriting option

Vincent R.
Hi,

I would like to make some test about converting some objc code into C#
So I have started to locate the code responsible to handle objc-rewrite
and I tried to do the same for my case.
Presently I just want have something that compiles so I have duplicated
RewriteObjC.cpp and renamed it into RewriteObjC2Cs.cpp
and changed the class name (I didn't include it inside the diff below
because it makes things hard to read).
So now when I compile I get the following error :


Scanning dependencies of target clangFrontend
[ 84%] Building CXX object
tools/clang/lib/Frontend/CMakeFiles/clangFrontend.dir/CompilerInstance.cpp.o
/home/vincent/objc2cs/clang/llvm/tools/clang/lib/Frontend/CompilerInstance.cpp:
In member function ‘bool
clang::CompilerInstance::ExecuteAction(clang::FrontendAction&)’:
/home/vincent/objc2cs/clang/llvm/tools/clang/lib/Frontend/CompilerInstance.cpp:665:43:
error: ‘RewriteObjC2Cs’ is not a member of ‘clang::frontend’
make[2]: ***
[tools/clang/lib/Frontend/CMakeFiles/clangFrontend.dir/CompilerInstance.cpp.o]
Error 1
make[1]: ***
[tools/clang/lib/Frontend/CMakeFiles/clangFrontend.dir/all] Error 2
make: *** [all] Error 2

What am I missing ?




Index: lib/Frontend/InitPreprocessor.cpp
===================================================================
--- lib/Frontend/InitPreprocessor.cpp (revision 186145)
+++ lib/Frontend/InitPreprocessor.cpp (working copy)
@@ -624,7 +624,8 @@
    else if (LangOpts.getStackProtector() == LangOptions::SSPReq)
      Builder.defineMacro("__SSP_ALL__", "2");

-  if (FEOpts.ProgramAction == frontend::RewriteObjC)
+  if ((FEOpts.ProgramAction == frontend::RewriteObjC) ||
+      (FEOpts.ProgramAction == frontend::RewriteObjC2Cs))
      Builder.defineMacro("__weak", "__attribute__((objc_gc(weak)))");

    // Define a macro that exists only when using the static analyzer.
Index: lib/Frontend/CompilerInstance.cpp
===================================================================
--- lib/Frontend/CompilerInstance.cpp (revision 186145)
+++ lib/Frontend/CompilerInstance.cpp (working copy)
@@ -661,7 +661,8 @@
    getTarget().setForcedLangOptions(getLangOpts());

    // rewriter project will change target built-in bool type from its
default.
-  if (getFrontendOpts().ProgramAction == frontend::RewriteObjC)
+  if ((getFrontendOpts().ProgramAction == frontend::RewriteObjC) ||
+      (getFrontendOpts().ProgramAction == frontend::RewriteObjC2Cs))
      getTarget().noSignedCharForObjCBool();

    // Validate/process some options.
Index: lib/Frontend/CompilerInvocation.cpp
===================================================================
--- lib/Frontend/CompilerInvocation.cpp (revision 186145)
+++ lib/Frontend/CompilerInvocation.cpp (working copy)
@@ -661,6 +661,8 @@
        Opts.ProgramAction = frontend::RewriteMacros; break;
      case OPT_rewrite_objc:
        Opts.ProgramAction = frontend::RewriteObjC; break;
+    case OPT_rewrite_objc2cs:
+      Opts.ProgramAction = frontend::RewriteObjC2Cs; break;
      case OPT_rewrite_test:
        Opts.ProgramAction = frontend::RewriteTest; break;
      case OPT_analyze:
@@ -1473,6 +1475,7 @@
    case frontend::PluginAction:
    case frontend::PrintDeclContext:
    case frontend::RewriteObjC:
+  case frontend::RewriteObjC2Cs:
    case frontend::RewriteTest:
    case frontend::RunAnalysis:
    case frontend::MigrateSource:
@@ -1562,7 +1565,8 @@
    ParseHeaderSearchArgs(Res.getHeaderSearchOpts(), *Args);
    if (DashX != IK_AST && DashX != IK_LLVM_IR) {
      ParseLangArgs(*Res.getLangOpts(), *Args, DashX, Diags);
-    if (Res.getFrontendOpts().ProgramAction == frontend::RewriteObjC)
+    if ((Res.getFrontendOpts().ProgramAction == frontend::RewriteObjC)
||
+        (Res.getFrontendOpts().ProgramAction ==
frontend::RewriteObjC2Cs))
        Res.getLangOpts()->ObjCExceptions = 1;
    }
    // FIXME: ParsePreprocessorArgs uses the FileManager to read the
contents of
Index: lib/Rewrite/Frontend/CMakeLists.txt
===================================================================
--- lib/Rewrite/Frontend/CMakeLists.txt (revision 186145)
+++ lib/Rewrite/Frontend/CMakeLists.txt (working copy)
@@ -6,6 +6,7 @@
    RewriteMacros.cpp
    RewriteModernObjC.cpp
    RewriteObjC.cpp
+  RewriteObjC2Cs.cpp
    RewriteTest.cpp
    )

Index: lib/Driver/Driver.cpp
===================================================================
--- lib/Driver/Driver.cpp (revision 186145)
+++ lib/Driver/Driver.cpp (working copy)
@@ -129,6 +129,7 @@
               (PhaseArg =
DAL.getLastArg(options::OPT_module_file_info)) ||
               (PhaseArg = DAL.getLastArg(options::OPT_rewrite_objc)) ||
               (PhaseArg =
DAL.getLastArg(options::OPT_rewrite_legacy_objc)) ||
+             (PhaseArg = DAL.getLastArg(options::OPT_rewrite_objc2cs))
||
               (PhaseArg = DAL.getLastArg(options::OPT__migrate)) ||
               (PhaseArg = DAL.getLastArg(options::OPT__analyze,
                                          options::OPT__analyze_auto))
||
@@ -1153,6 +1154,8 @@
        return new CompileJobAction(Input, types::TY_RewrittenObjC);
      } else if (Args.hasArg(options::OPT_rewrite_legacy_objc)) {
        return new CompileJobAction(Input,
types::TY_RewrittenLegacyObjC);
+    } else if (Args.hasArg(options::OPT_rewrite_objc2cs)) {
+      return new CompileJobAction(Input, types::TY_RewrittenObjC2Cs);
      } else if (Args.hasArg(options::OPT__analyze,
options::OPT__analyze_auto)) {
        return new AnalyzeJobAction(Input, types::TY_Plist);
      } else if (Args.hasArg(options::OPT__migrate)) {
@@ -1326,6 +1329,7 @@
        !C.getArgs().hasArg(options::OPT_traditional_cpp) &&
        !C.getArgs().hasArg(options::OPT_save_temps) &&
        !C.getArgs().hasArg(options::OPT_rewrite_objc) &&
+      !C.getArgs().hasArg(options::OPT_rewrite_objc2cs) &&
        ToolForJob->hasIntegratedCPP())
      Inputs = &(*Inputs)[0]->getInputs();

Index: lib/Driver/Tools.cpp
===================================================================
--- lib/Driver/Tools.cpp (revision 186145)
+++ lib/Driver/Tools.cpp (working copy)
@@ -1961,7 +1961,10 @@
      } else if (JA.getType() == types::TY_RewrittenLegacyObjC) {
        CmdArgs.push_back("-rewrite-objc");
        rewriteKind = RK_Fragile;
-    } else {
+    } else if (JA.getType() == types::TY_RewrittenObjC2Cs) {
+      CmdArgs.push_back("-rewrite-objc2cs");
+    }
+      else {
        assert(JA.getType() == types::TY_PP_Asm &&
               "Unexpected output type!");
      }
Index: include/clang/Driver/Options.td
===================================================================
--- include/clang/Driver/Options.td (revision 186145)
+++ include/clang/Driver/Options.td (working copy)
@@ -1050,6 +1050,8 @@
    HelpText<"Rewrite Objective-C source to C++">, Group<Action_Group>;
  def rewrite_legacy_objc : Flag<["-"], "rewrite-legacy-objc">,
Flags<[DriverOption]>,
    HelpText<"Rewrite Legacy Objective-C source to C++">;
+def rewrite_objc2cs : Flag<["-"], "rewrite-objc2cs">,
Flags<[DriverOption,CC1Option]>,
+  HelpText<"Rewrite Objective-C source to C#">, Group<Action_Group>;
  def rdynamic : Flag<["-"], "rdynamic">;
  def resource_dir : Separate<["-"], "resource-dir">,
    Flags<[DriverOption, CC1Option, HelpHidden]>,
Index: include/clang/Driver/Types.def
===================================================================
--- include/clang/Driver/Types.def (revision 186145)
+++ include/clang/Driver/Types.def (working copy)
@@ -84,6 +84,7 @@
  TYPE("plist",                    Plist,        INVALID,        
"plist", "")
  TYPE("rewritten-objc",           RewrittenObjC,INVALID,         "cpp",
  "")
  TYPE("rewritten-legacy-objc",    RewrittenLegacyObjC,INVALID,   "cpp",
  "")
+TYPE("rewritten-objc2cs",        RewrittenObjC2Cs,INVALID,        
"cs",   "")
  TYPE("remap",                    Remap,        INVALID,        
"remap", "")
  TYPE("precompiled-header",       PCH,          INVALID,         "gch",
  "A")
  TYPE("object",                   Object,       INVALID,         "o",  
  "")



_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: How to add a new rewriting option

Vincent R.
Le 28.07.2013 12:24, Vincent R. a écrit :

> Hi,
>
> I would like to make some test about converting some objc code into
> C#
> So I have started to locate the code responsible to handle
> objc-rewrite and I tried to do the same for my case.
> Presently I just want have something that compiles so I have
> duplicated RewriteObjC.cpp and renamed it into RewriteObjC2Cs.cpp
> and changed the class name (I didn't include it inside the diff below
> because it makes things hard to read).
> So now when I compile I get the following error :
>
>
> Scanning dependencies of target clangFrontend
> [ 84%] Building CXX object
>
> tools/clang/lib/Frontend/CMakeFiles/clangFrontend.dir/CompilerInstance.cpp.o
>
> /home/vincent/objc2cs/clang/llvm/tools/clang/lib/Frontend/CompilerInstance.cpp:
> In member function ‘bool
> clang::CompilerInstance::ExecuteAction(clang::FrontendAction&)’:
>
> /home/vincent/objc2cs/clang/llvm/tools/clang/lib/Frontend/CompilerInstance.cpp:665:43:
> error: ‘RewriteObjC2Cs’ is not a member of ‘clang::frontend’
> make[2]: ***
>
> [tools/clang/lib/Frontend/CMakeFiles/clangFrontend.dir/CompilerInstance.cpp.o]
> Error 1
> make[1]: ***
> [tools/clang/lib/Frontend/CMakeFiles/clangFrontend.dir/all] Error 2
> make: *** [all] Error 2
>
> What am I missing ?
>
Actually I think I found I forgot to add the corresponding enum inside
FrontendOptions.h :

Index: tools/clang/include/clang/Frontend/FrontendOptions.h
===================================================================
--- tools/clang/include/clang/Frontend/FrontendOptions.h (revision
186145)
+++ tools/clang/include/clang/Frontend/FrontendOptions.h (working copy)
@@ -51,6 +51,7 @@
      PrintPreprocessedInput, ///< -E mode.
      RewriteMacros,          ///< Expand macros but not \#includes.
      RewriteObjC,            ///< ObjC->C Rewriter.
+    RewriteObjC2Cs,         ///< ObjC->C# Rewriter.
      RewriteTest,            ///< Rewriter playground
      RunAnalysis,            ///< Run one or more source code analyses.
      MigrateSource,          ///< Run migrator.




_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: How to add a new rewriting option

Vincent R.
Le 28.07.2013 14:31, Vincent R. a écrit :

> Le 28.07.2013 12:24, Vincent R. a écrit :
>> Hi,
>>
>> I would like to make some test about converting some objc code into
>> C#
>> So I have started to locate the code responsible to handle
>> objc-rewrite and I tried to do the same for my case.
>> Presently I just want have something that compiles so I have
>> duplicated RewriteObjC.cpp and renamed it into RewriteObjC2Cs.cpp
>> and changed the class name (I didn't include it inside the diff
>> below
>> because it makes things hard to read).
>> So now when I compile I get the following error :
>>
>>
>> Scanning dependencies of target clangFrontend
>> [ 84%] Building CXX object
>>
>> tools/clang/lib/Frontend/CMakeFiles/clangFrontend.dir/CompilerInstance.cpp.o
>>
>> /home/vincent/objc2cs/clang/llvm/tools/clang/lib/Frontend/CompilerInstance.cpp:
>> In member function ‘bool
>> clang::CompilerInstance::ExecuteAction(clang::FrontendAction&)’:
>>
>> /home/vincent/objc2cs/clang/llvm/tools/clang/lib/Frontend/CompilerInstance.cpp:665:43:
>> error: ‘RewriteObjC2Cs’ is not a member of ‘clang::frontend’
>> make[2]: ***
>>
>> [tools/clang/lib/Frontend/CMakeFiles/clangFrontend.dir/CompilerInstance.cpp.o]
>> Error 1
>> make[1]: ***
>> [tools/clang/lib/Frontend/CMakeFiles/clangFrontend.dir/all] Error 2
>> make: *** [all] Error 2
>>
>> What am I missing ?
>>
> Actually I think I found I forgot to add the corresponding enum
> inside FrontendOptions.h :
>
> Index: tools/clang/include/clang/Frontend/FrontendOptions.h
> ===================================================================
> --- tools/clang/include/clang/Frontend/FrontendOptions.h (revision
> 186145)
> +++ tools/clang/include/clang/Frontend/FrontendOptions.h (working
> copy)
> @@ -51,6 +51,7 @@
>      PrintPreprocessedInput, ///< -E mode.
>      RewriteMacros,          ///< Expand macros but not \#includes.
>      RewriteObjC,            ///< ObjC->C Rewriter.
> +    RewriteObjC2Cs,         ///< ObjC->C# Rewriter.
>      RewriteTest,            ///< Rewriter playground
>      RunAnalysis,            ///< Run one or more source code
> analyses.
>      MigrateSource,          ///< Run migrator.
>

Hum still problem because when I try to use the new rewrite options
clang shows me the command usage (with the
new option) :

With the working rewrite-objc it works because I end up with a .cpp
file
  ~/objc2cs/gnustep/core/gui/Source $ clang -rewrite-objc NSButton.m -c
-MMD -MP -DGNUSTEP_TARGET_DIR=\".\" -DGNUSTEP_TARGET_CPU=\"x86_64\"
-DGNUSTEP_TARGET_OS=\"linux-gnu\" -DLIBRARY_COMBO=\"gnu-gnu-gnu\"
-DBACKEND_BUNDLE=1 -DGNUSTEP -DGNUSTEP_BASE_LIBRARY=1
-DGNU_GUI_LIBRARY=1 -DGNU_RUNTIME=1 -DGNUSTEP_BASE_LIBRARY=1
-fno-strict-aliasing -fexceptions -fobjc-exceptions
-D_NATIVE_OBJC_EXCEPTIONS -fobjc-nonfragile-abi -D_NONFRAGILE_ABI
-pthread -fPIC -DDEBUG -fno-omit-frame-pointer -Wall -DGSWARN
-DGSDIAGNOSE -Wno-import -g -fgnu-runtime -Wall
-fconstant-string-class=NSConstantString -I../Headers/Additions
-I../Headers -I./. -I. -I/home/vincent/GNUstep/Library/Headers
-I/GNUstep/Local/Library/Headers -I/GNUstep/System/Library/Headers
-I/usr/include/libpng12

However if I try with the same command line and replace with
-rewrite-objc2cs it shows me the command usage ...

Any idea ?




_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: How to add a new rewriting option

Vincent R.
I have attached my latest patch(clang 3.3) below and I am wondering if
it wouldn't be easier to only modify the
RewriteObjc.cpp instead of trying to add a new rewriting option ...




Index: tools/clang/lib/Frontend/InitPreprocessor.cpp
===================================================================
--- tools/clang/lib/Frontend/InitPreprocessor.cpp (revision 186145)
+++ tools/clang/lib/Frontend/InitPreprocessor.cpp (working copy)
@@ -624,7 +624,8 @@
    else if (LangOpts.getStackProtector() == LangOptions::SSPReq)
      Builder.defineMacro("__SSP_ALL__", "2");

-  if (FEOpts.ProgramAction == frontend::RewriteObjC)
+  if ((FEOpts.ProgramAction == frontend::RewriteObjC) ||
+      (FEOpts.ProgramAction == frontend::RewriteObjC2Cs))
      Builder.defineMacro("__weak", "__attribute__((objc_gc(weak)))");

    // Define a macro that exists only when using the static analyzer.
Index: tools/clang/lib/Frontend/CompilerInstance.cpp
===================================================================
--- tools/clang/lib/Frontend/CompilerInstance.cpp (revision 186145)
+++ tools/clang/lib/Frontend/CompilerInstance.cpp (working copy)
@@ -661,7 +661,8 @@
    getTarget().setForcedLangOptions(getLangOpts());

    // rewriter project will change target built-in bool type from its
default.
-  if (getFrontendOpts().ProgramAction == frontend::RewriteObjC)
+  if ((getFrontendOpts().ProgramAction == frontend::RewriteObjC) ||
+      (getFrontendOpts().ProgramAction == frontend::RewriteObjC2Cs))
      getTarget().noSignedCharForObjCBool();

    // Validate/process some options.
Index: tools/clang/lib/Frontend/CompilerInvocation.cpp
===================================================================
--- tools/clang/lib/Frontend/CompilerInvocation.cpp (revision 186145)
+++ tools/clang/lib/Frontend/CompilerInvocation.cpp (working copy)
@@ -661,6 +661,8 @@
        Opts.ProgramAction = frontend::RewriteMacros; break;
      case OPT_rewrite_objc:
        Opts.ProgramAction = frontend::RewriteObjC; break;
+    case OPT_rewrite_objc2cs:
+      Opts.ProgramAction = frontend::RewriteObjC2Cs; break;
      case OPT_rewrite_test:
        Opts.ProgramAction = frontend::RewriteTest; break;
      case OPT_analyze:
@@ -1473,6 +1475,7 @@
    case frontend::PluginAction:
    case frontend::PrintDeclContext:
    case frontend::RewriteObjC:
+  case frontend::RewriteObjC2Cs:
    case frontend::RewriteTest:
    case frontend::RunAnalysis:
    case frontend::MigrateSource:
@@ -1562,7 +1565,8 @@
    ParseHeaderSearchArgs(Res.getHeaderSearchOpts(), *Args);
    if (DashX != IK_AST && DashX != IK_LLVM_IR) {
      ParseLangArgs(*Res.getLangOpts(), *Args, DashX, Diags);
-    if (Res.getFrontendOpts().ProgramAction == frontend::RewriteObjC)
+    if ((Res.getFrontendOpts().ProgramAction == frontend::RewriteObjC)
||
+        (Res.getFrontendOpts().ProgramAction ==
frontend::RewriteObjC2Cs))
        Res.getLangOpts()->ObjCExceptions = 1;
    }
    // FIXME: ParsePreprocessorArgs uses the FileManager to read the
contents of
Index: tools/clang/lib/Rewrite/Frontend/CMakeLists.txt
===================================================================
--- tools/clang/lib/Rewrite/Frontend/CMakeLists.txt (revision 186145)
+++ tools/clang/lib/Rewrite/Frontend/CMakeLists.txt (working copy)
@@ -6,6 +6,7 @@
    RewriteMacros.cpp
    RewriteModernObjC.cpp
    RewriteObjC.cpp
+  RewriteObjC2Cs.cpp
    RewriteTest.cpp
    )

Index: tools/clang/lib/Driver/Driver.cpp
===================================================================
--- tools/clang/lib/Driver/Driver.cpp (revision 186145)
+++ tools/clang/lib/Driver/Driver.cpp (working copy)
@@ -129,6 +129,7 @@
               (PhaseArg =
DAL.getLastArg(options::OPT_module_file_info)) ||
               (PhaseArg = DAL.getLastArg(options::OPT_rewrite_objc)) ||
               (PhaseArg =
DAL.getLastArg(options::OPT_rewrite_legacy_objc)) ||
+             (PhaseArg = DAL.getLastArg(options::OPT_rewrite_objc2cs))
||
               (PhaseArg = DAL.getLastArg(options::OPT__migrate)) ||
               (PhaseArg = DAL.getLastArg(options::OPT__analyze,
                                          options::OPT__analyze_auto))
||
@@ -1153,6 +1154,8 @@
        return new CompileJobAction(Input, types::TY_RewrittenObjC);
      } else if (Args.hasArg(options::OPT_rewrite_legacy_objc)) {
        return new CompileJobAction(Input,
types::TY_RewrittenLegacyObjC);
+    } else if (Args.hasArg(options::OPT_rewrite_objc2cs)) {
+      return new CompileJobAction(Input, types::TY_RewrittenObjC2Cs);
      } else if (Args.hasArg(options::OPT__analyze,
options::OPT__analyze_auto)) {
        return new AnalyzeJobAction(Input, types::TY_Plist);
      } else if (Args.hasArg(options::OPT__migrate)) {
@@ -1326,6 +1329,7 @@
        !C.getArgs().hasArg(options::OPT_traditional_cpp) &&
        !C.getArgs().hasArg(options::OPT_save_temps) &&
        !C.getArgs().hasArg(options::OPT_rewrite_objc) &&
+      !C.getArgs().hasArg(options::OPT_rewrite_objc2cs) &&
        ToolForJob->hasIntegratedCPP())
      Inputs = &(*Inputs)[0]->getInputs();

Index: tools/clang/lib/Driver/Tools.cpp
===================================================================
--- tools/clang/lib/Driver/Tools.cpp (revision 186145)
+++ tools/clang/lib/Driver/Tools.cpp (working copy)
@@ -1889,7 +1889,8 @@
        CmdArgs.push_back("-Eonly");
      else {
        CmdArgs.push_back("-E");
-      if (Args.hasArg(options::OPT_rewrite_objc) &&
+      if ((Args.hasArg(options::OPT_rewrite_objc)  ||
+           Args.hasArg(options::OPT_rewrite_objc2cs)) &&
            !Args.hasArg(options::OPT_g_Group))
          CmdArgs.push_back("-P");
      }
@@ -1961,6 +1962,9 @@
      } else if (JA.getType() == types::TY_RewrittenLegacyObjC) {
        CmdArgs.push_back("-rewrite-objc");
        rewriteKind = RK_Fragile;
+    } else if (JA.getType() == types::TY_RewrittenObjC2Cs) {
+      CmdArgs.push_back("-rewrite-objc2cs");
+      rewriteKind = RK_NonFragile;
      } else {
        assert(JA.getType() == types::TY_PP_Asm &&
               "Unexpected output type!");
@@ -3421,7 +3425,8 @@
           it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) {
      const InputInfo &II = *it;
      CmdArgs.push_back("-x");
-    if (Args.hasArg(options::OPT_rewrite_objc))
+    if ((Args.hasArg(options::OPT_rewrite_objc)) ||
+ (Args.hasArg(options::OPT_rewrite_objc2cs)))
        CmdArgs.push_back(types::getTypeName(types::TY_PP_ObjCXX));
      else
        CmdArgs.push_back(types::getTypeName(II.getType()));
Index: tools/clang/include/clang/Frontend/FrontendOptions.h
===================================================================
--- tools/clang/include/clang/Frontend/FrontendOptions.h (revision
186145)
+++ tools/clang/include/clang/Frontend/FrontendOptions.h (working copy)
@@ -51,6 +51,7 @@
      PrintPreprocessedInput, ///< -E mode.
      RewriteMacros,          ///< Expand macros but not \#includes.
      RewriteObjC,            ///< ObjC->C Rewriter.
+    RewriteObjC2Cs,         ///< ObjC->C# Rewriter.
      RewriteTest,            ///< Rewriter playground
      RunAnalysis,            ///< Run one or more source code analyses.
      MigrateSource,          ///< Run migrator.
Index: tools/clang/include/clang/Driver/Options.td
===================================================================
--- tools/clang/include/clang/Driver/Options.td (revision 186145)
+++ tools/clang/include/clang/Driver/Options.td (working copy)
@@ -1050,6 +1050,8 @@
    HelpText<"Rewrite Objective-C source to C++">, Group<Action_Group>;
  def rewrite_legacy_objc : Flag<["-"], "rewrite-legacy-objc">,
Flags<[DriverOption]>,
    HelpText<"Rewrite Legacy Objective-C source to C++">;
+def rewrite_objc2cs : Flag<["-"], "rewrite-objc2cs">,
Flags<[DriverOption,CC1Option]>,
+  HelpText<"Rewrite Objective-C source to C#">, Group<Action_Group>;
  def rdynamic : Flag<["-"], "rdynamic">;
  def resource_dir : Separate<["-"], "resource-dir">,
    Flags<[DriverOption, CC1Option, HelpHidden]>,
Index: tools/clang/include/clang/Driver/Types.def
===================================================================
--- tools/clang/include/clang/Driver/Types.def (revision 186145)
+++ tools/clang/include/clang/Driver/Types.def (working copy)
@@ -84,6 +84,7 @@
  TYPE("plist",                    Plist,        INVALID,        
"plist", "")
  TYPE("rewritten-objc",           RewrittenObjC,INVALID,         "cpp",
  "")
  TYPE("rewritten-legacy-objc",    RewrittenLegacyObjC,INVALID,   "cpp",
  "")
+TYPE("rewritten-objc2cs",        RewrittenObjC2Cs,INVALID,      "cs",  
"")
  TYPE("remap",                    Remap,        INVALID,        
"remap", "")
  TYPE("precompiled-header",       PCH,          INVALID,         "gch",
  "A")
  TYPE("object",                   Object,       INVALID,         "o",  
  "")
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: How to add a new rewriting option

Vincent R.
Le 28.07.2013 15:44, Vincent R. a écrit :
> I have attached my latest patch(clang 3.3) below and I am wondering
> if it wouldn't be easier to only modify the
> RewriteObjc.cpp instead of trying to add a new rewriting option ...
>

Ok I found the last missing part.
Sorry for the noise.
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: How to add a new rewriting option

Vincent R.
Le 28.07.2013 19:31, Vincent R. a écrit :
> Le 28.07.2013 15:44, Vincent R. a écrit :
>> I have attached my latest patch(clang 3.3) below and I am wondering
>> if it wouldn't be easier to only modify the
>> RewriteObjc.cpp instead of trying to add a new rewriting option ...
>>


Ok so last question, actually I have noticed a big difference between
-rewrite-legacy-objc and -rewrite-objc because
when I try the two differents flags on the same file I get respectively
a file of 40.8 kB and another of 392.4 kB.
The difference seems to be because when using -rewrite-objc flag the
file is first preprocessed :

1) -rewrite-legacy-objc

clang -v -v -rewrite-legacy-objc NSButton.m -c -MMD -MP
-DGNUSTEP_TARGET_DIR=\".\" -DGNUSTEP_TARGET_CPU=\"x86_64\"
-DGNUSTEP_TARGET_OS=\"linux-gnu\" -DLIBRARY_COMBO=\"gnu-gnu-gnu\"
-DBACKEND_BUNDLE=1 -DGNUSTEP -DGNUSTEP_BASE_LIBRARY=1
-DGNU_GUI_LIBRARY=1 -DGNU_RUNTIME=1 -DGNUSTEP_BASE_LIBRARY=1
-fno-strict-aliasing -fexceptions -fobjc-exceptions
-D_NATIVE_OBJC_EXCEPTIONS -fobjc-nonfragile-abi -D_NONFRAGILE_ABI
-pthread -fPIC -DDEBUG -fno-omit-frame-pointer -Wall -DGSWARN
-DGSDIAGNOSE -Wno-import -g -fgnu-runtime -Wall
-fconstant-string-class=NSConstantString -I../Headers/Additions
-I../Headers -I./. -I. -I/home/vincent/GNUstep/Library/Headers
-I/GNUstep/Local/Library/Headers -I/GNUstep/System/Library/Headers
-I/usr/include/libpng12
clang version 3.3 (186145)
Target: x86_64-unknown-linux-gnu
Thread model: posix

**** File is transformed (-rewrite-objc)

  "/opt/bin/clang-3.3" -cc1 -triple x86_64-unknown-linux-gnu
-rewrite-objc -disable-free -main-file-name NSButton.m
-mrelocation-model pic -pic-level 2 -mdisable-fp-elim -relaxed-aliasing
-fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables
-fuse-init-array -target-cpu x86-64 -v -v -g -coverage-file
/home/vincent/objc2cs/gnustep/core/gui/Source/NSButton.cpp -resource-dir
/opt/bin/../lib/clang/3.3 -dependency-file NSButton.d -MT NSButton.o -MP
-D "GNUSTEP_TARGET_DIR=\".\"" -D "GNUSTEP_TARGET_CPU=\"x86_64\"" -D
"GNUSTEP_TARGET_OS=\"linux-gnu\"" -D "LIBRARY_COMBO=\"gnu-gnu-gnu\"" -D
BACKEND_BUNDLE=1 -D GNUSTEP -D GNUSTEP_BASE_LIBRARY=1 -D
GNU_GUI_LIBRARY=1 -D GNU_RUNTIME=1 -D GNUSTEP_BASE_LIBRARY=1 -D
_NATIVE_OBJC_EXCEPTIONS -D _NONFRAGILE_ABI -D DEBUG -D GSWARN -D
GSDIAGNOSE -I ../Headers/Additions -I ../Headers -I ./. -I . -I
/home/vincent/GNUstep/Library/Headers -I /GNUstep/Local/Library/Headers
-I /GNUstep/System/Library/Headers -I /usr/include/libpng12
-internal-isystem /usr/local/include -internal-isystem
/opt/bin/../lib/clang/3.3/include -internal-externc-isystem
/usr/include/x86_64-linux-gnu -internal-externc-isystem /include
-internal-externc-isystem /usr/include -Wall -Wno-import -Wall
-fdebug-compilation-dir /home/vincent/objc2cs/gnustep/core/gui/Source
-fconstant-string-class NSConstantString -ferror-limit 19
-fmessage-length 232 -pthread -mstackrealign -fblocks
-fobjc-runtime=gnustep-1.6 -fobjc-dispatch-method=non-legacy
-fobjc-default-synthesize-properties -fno-objc-infer-related-result-type
-fobjc-exceptions -fexceptions -fdiagnostics-show-option
-fcolor-diagnostics -backend-option -vectorize-loops -o NSButton.cpp -x
objective-c NSButton.m

2)-rewrite-objc

clang -v -v -rewrite-objc NSButton.m -c -MMD -MP
-DGNUSTEP_TARGET_DIR=\".\" -DGNUSTEP_TARGET_CPU=\"x86_64\"
-DGNUSTEP_TARGET_OS=\"linux-gnu\" -DLIBRARY_COMBO=\"gnu-gnu-gnu\"
-DBACKEND_BUNDLE=1 -DGNUSTEP -DGNUSTEP_BASE_LIBRARY=1
-DGNU_GUI_LIBRARY=1 -DGNU_RUNTIME=1 -DGNUSTEP_BASE_LIBRARY=1
-fno-strict-aliasing -fexceptions -fobjc-exceptions
-D_NATIVE_OBJC_EXCEPTIONS -fobjc-nonfragile-abi -D_NONFRAGILE_ABI
-pthread -fPIC -DDEBUG -fno-omit-frame-pointer -Wall -DGSWARN
-DGSDIAGNOSE -Wno-import -g -fgnu-runtime -Wall
-fconstant-string-class=NSConstantString -I../Headers/Additions
-I../Headers -I./. -I. -I/home/vincent/GNUstep/Library/Headers
-I/GNUstep/Local/Library/Headers -I/GNUstep/System/Library/Headers
-I/usr/include/libpng12

**** FIRST file is preprocessed(-E flag) :

"/opt/bin/clang-3.3" -cc1 -triple x86_64-unknown-linux-gnu -E
-disable-free -main-file-name NSButton.m -mrelocation-model pic
-pic-level 2 -mdisable-fp-elim -relaxed-aliasing -fmath-errno
-masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array
-target-cpu x86-64 -v -v -g -coverage-file /tmp/NSButton-sxcmia.mi
-resource-dir /opt/bin/../lib/clang/3.3 -dependency-file NSButton.d -MT
NSButton.o -MP -D "GNUSTEP_TARGET_DIR=\".\"" -D
"GNUSTEP_TARGET_CPU=\"x86_64\"" -D "GNUSTEP_TARGET_OS=\"linux-gnu\"" -D
"LIBRARY_COMBO=\"gnu-gnu-gnu\"" -D BACKEND_BUNDLE=1 -D GNUSTEP -D
GNUSTEP_BASE_LIBRARY=1 -D GNU_GUI_LIBRARY=1 -D GNU_RUNTIME=1 -D
GNUSTEP_BASE_LIBRARY=1 -D _NATIVE_OBJC_EXCEPTIONS -D _NONFRAGILE_ABI -D
DEBUG -D GSWARN -D GSDIAGNOSE -I ../Headers/Additions -I ../Headers -I
./. -I . -I /home/vincent/GNUstep/Library/Headers -I
/GNUstep/Local/Library/Headers -I /GNUstep/System/Library/Headers -I
/usr/include/libpng12 -internal-isystem /usr/local/include
-internal-isystem /opt/bin/../lib/clang/3.3/include
-internal-externc-isystem /usr/include/x86_64-linux-gnu
-internal-externc-isystem /include -internal-externc-isystem
/usr/include -Wall -Wno-import -Wall -fdebug-compilation-dir
/home/vincent/objc2cs/gnustep/core/gui/Source -fconstant-string-class
NSConstantString -ferror-limit 19 -fmessage-length 232 -pthread
-mstackrealign -fblocks -fobjc-runtime=gnustep-1.6
-fobjc-dispatch-method=non-legacy -fobjc-default-synthesize-properties
-fobjc-exceptions -fexceptions -fdiagnostics-show-option
-fcolor-diagnostics -backend-option -vectorize-loops -o
/tmp/NSButton-sxcmia.mi -x objective-c++-cpp-output NSButton.m

**** THEN file is transformed (-rewrite-objc)

"/opt/bin/clang-3.3" -cc1 -triple x86_64-unknown-linux-gnu
-rewrite-objc -disable-free -main-file-name NSButton.m
-mrelocation-model pic -pic-level 2 -mdisable-fp-elim -relaxed-aliasing
-fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables
-fuse-init-array -target-cpu x86-64 -v -v -g -coverage-file
/home/vincent/objc2cs/gnustep/core/gui/Source/NSButton.cpp -resource-dir
/opt/bin/../lib/clang/3.3 -Wall -Wno-import -Wall
-fdebug-compilation-dir /home/vincent/objc2cs/gnustep/core/gui/Source
-fconstant-string-class NSConstantString -ferror-limit 19
-fmessage-length 232 -pthread -mstackrealign -fblocks
-fobjc-runtime=gnustep-1.6 -fobjc-dispatch-method=non-legacy
-fobjc-default-synthesize-properties -fno-objc-infer-related-result-type
-fobjc-exceptions -fexceptions -fdiagnostics-show-option
-fcolor-diagnostics -backend-option -vectorize-loops -o NSButton.cpp -x
objective-c++-cpp-output /tmp/NSButton-sxcmia.mi


Is is a normal behavior to have a difference in preprocessing between
-rewrite-legacy-objc and -rewrite-objc or is it one of my change that
could explain it ?
What part of code is responsible for that ?
With my new flag -rewrite-objc2cs I don't want to have a preprocessing
stage but I don't know how to do it ?
If you have any pointers about this part, it would help a lot.

Pleas note that for the moment the RewriteObjC2Cs.cpp is a copy of
RewriteObjC.cpp and I am calling a method called CreateObjC2CsRewriter
that actually corresponds to the CreateObjCRewriter (fragile runtime)
of the RewriteObjC.cpp


ASTConsumer *RewriteObjCAction::CreateASTConsumer(CompilerInstance &CI,
                                                   StringRef InFile) {
   if (raw_ostream *OS = CI.createDefaultOutputFile(false, InFile,
"cpp")) {
     if (CI.getLangOpts().ObjCRuntime.isNonFragile())
       return CreateModernObjCRewriter(InFile, OS,
                                 CI.getDiagnostics(), CI.getLangOpts(),
                                 CI.getDiagnosticOpts().NoRewriteMacros,
                                 (CI.getCodeGenOpts().getDebugInfo() !=
                                  CodeGenOptions::NoDebugInfo));
     return CreateObjCRewriter(InFile, OS,
                               CI.getDiagnostics(), CI.getLangOpts(),
                               CI.getDiagnosticOpts().NoRewriteMacros);
   }
   return 0;
}

ASTConsumer *RewriteObjC2CsAction::CreateASTConsumer(CompilerInstance
&CI,
                                                   StringRef InFile) {
   if (raw_ostream *OS = CI.createDefaultOutputFile(false, InFile,
"cs")) {
    return CreateObjC2CsRewriter(InFile, OS,
                               CI.getDiagnostics(), CI.getLangOpts(),
                               CI.getDiagnosticOpts().NoRewriteMacros);
   }
   return 0;
}




Thanks

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: How to add a new rewriting option

jahanian
Hi Vincent,

-rewrite-legacy-objc is out of date. For up to date support for ObjectiveC features and translation of its
modern ABI, you may want to look into -rewrite-objc. -rewrite-objc has simplified the workflow by pre-processing
user program and translating it into C++. -rewrite-legacy-objc requires user to do the pre-processing step manually.

- Fariborz

On Jul 28, 2013, at 1:22 PM, Vincent R. <[hidden email]> wrote:

Le 28.07.2013 19:31, Vincent R. a écrit :
Le 28.07.2013 15:44, Vincent R. a écrit :
I have attached my latest patch(clang 3.3) below and I am wondering
if it wouldn't be easier to only modify the
RewriteObjc.cpp instead of trying to add a new rewriting option ...



Ok so last question, actually I have noticed a big difference between -rewrite-legacy-objc and -rewrite-objc because
when I try the two differents flags on the same file I get respectively a file of 40.8 kB and another of 392.4 kB.
The difference seems to be because when using -rewrite-objc flag the file is first preprocessed :

1) -rewrite-legacy-objc

clang -v -v -rewrite-legacy-objc NSButton.m -c -MMD -MP -DGNUSTEP_TARGET_DIR=\".\" -DGNUSTEP_TARGET_CPU=\"x86_64\" -DGNUSTEP_TARGET_OS=\"linux-gnu\" -DLIBRARY_COMBO=\"gnu-gnu-gnu\" -DBACKEND_BUNDLE=1 -DGNUSTEP -DGNUSTEP_BASE_LIBRARY=1 -DGNU_GUI_LIBRARY=1 -DGNU_RUNTIME=1 -DGNUSTEP_BASE_LIBRARY=1 -fno-strict-aliasing -fexceptions -fobjc-exceptions -D_NATIVE_OBJC_EXCEPTIONS -fobjc-nonfragile-abi -D_NONFRAGILE_ABI -pthread -fPIC -DDEBUG -fno-omit-frame-pointer -Wall -DGSWARN -DGSDIAGNOSE -Wno-import -g -fgnu-runtime -Wall -fconstant-string-class=NSConstantString -I../Headers/Additions -I../Headers -I./. -I. -I/home/vincent/GNUstep/Library/Headers -I/GNUstep/Local/Library/Headers -I/GNUstep/System/Library/Headers -I/usr/include/libpng12
clang version 3.3 (186145)
Target: x86_64-unknown-linux-gnu
Thread model: posix

**** File is transformed (-rewrite-objc)

"/opt/bin/clang-3.3" -cc1 -triple x86_64-unknown-linux-gnu -rewrite-objc -disable-free -main-file-name NSButton.m -mrelocation-model pic -pic-level 2 -mdisable-fp-elim -relaxed-aliasing -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -v -v -g -coverage-file /home/vincent/objc2cs/gnustep/core/gui/Source/NSButton.cpp -resource-dir /opt/bin/../lib/clang/3.3 -dependency-file NSButton.d -MT NSButton.o -MP -D "GNUSTEP_TARGET_DIR=\".\"" -D "GNUSTEP_TARGET_CPU=\"x86_64\"" -D "GNUSTEP_TARGET_OS=\"linux-gnu\"" -D "LIBRARY_COMBO=\"gnu-gnu-gnu\"" -D BACKEND_BUNDLE=1 -D GNUSTEP -D GNUSTEP_BASE_LIBRARY=1 -D GNU_GUI_LIBRARY=1 -D GNU_RUNTIME=1 -D GNUSTEP_BASE_LIBRARY=1 -D _NATIVE_OBJC_EXCEPTIONS -D _NONFRAGILE_ABI -D DEBUG -D GSWARN -D GSDIAGNOSE -I ../Headers/Additions -I ../Headers -I ./. -I . -I /home/vincent/GNUstep/Library/Headers -I /GNUstep/Local/Library/Headers -I /GNUstep/System/Library/Headers -I /usr/include/libpng12 -internal-isystem /usr/local/include -internal-isystem /opt/bin/../lib/clang/3.3/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -Wall -Wno-import -Wall -fdebug-compilation-dir /home/vincent/objc2cs/gnustep/core/gui/Source -fconstant-string-class NSConstantString -ferror-limit 19 -fmessage-length 232 -pthread -mstackrealign -fblocks -fobjc-runtime=gnustep-1.6 -fobjc-dispatch-method=non-legacy -fobjc-default-synthesize-properties -fno-objc-infer-related-result-type -fobjc-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -backend-option -vectorize-loops -o NSButton.cpp -x objective-c NSButton.m

2)-rewrite-objc

clang -v -v -rewrite-objc NSButton.m -c -MMD -MP -DGNUSTEP_TARGET_DIR=\".\" -DGNUSTEP_TARGET_CPU=\"x86_64\" -DGNUSTEP_TARGET_OS=\"linux-gnu\" -DLIBRARY_COMBO=\"gnu-gnu-gnu\" -DBACKEND_BUNDLE=1 -DGNUSTEP -DGNUSTEP_BASE_LIBRARY=1 -DGNU_GUI_LIBRARY=1 -DGNU_RUNTIME=1 -DGNUSTEP_BASE_LIBRARY=1 -fno-strict-aliasing -fexceptions -fobjc-exceptions -D_NATIVE_OBJC_EXCEPTIONS -fobjc-nonfragile-abi -D_NONFRAGILE_ABI -pthread -fPIC -DDEBUG -fno-omit-frame-pointer -Wall -DGSWARN -DGSDIAGNOSE -Wno-import -g -fgnu-runtime -Wall -fconstant-string-class=NSConstantString -I../Headers/Additions -I../Headers -I./. -I. -I/home/vincent/GNUstep/Library/Headers -I/GNUstep/Local/Library/Headers -I/GNUstep/System/Library/Headers -I/usr/include/libpng12

**** FIRST file is preprocessed(-E flag) :

"/opt/bin/clang-3.3" -cc1 -triple x86_64-unknown-linux-gnu -E -disable-free -main-file-name NSButton.m -mrelocation-model pic -pic-level 2 -mdisable-fp-elim -relaxed-aliasing -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -v -v -g -coverage-file /tmp/NSButton-sxcmia.mi -resource-dir /opt/bin/../lib/clang/3.3 -dependency-file NSButton.d -MT NSButton.o -MP -D "GNUSTEP_TARGET_DIR=\".\"" -D "GNUSTEP_TARGET_CPU=\"x86_64\"" -D "GNUSTEP_TARGET_OS=\"linux-gnu\"" -D "LIBRARY_COMBO=\"gnu-gnu-gnu\"" -D BACKEND_BUNDLE=1 -D GNUSTEP -D GNUSTEP_BASE_LIBRARY=1 -D GNU_GUI_LIBRARY=1 -D GNU_RUNTIME=1 -D GNUSTEP_BASE_LIBRARY=1 -D _NATIVE_OBJC_EXCEPTIONS -D _NONFRAGILE_ABI -D DEBUG -D GSWARN -D GSDIAGNOSE -I ../Headers/Additions -I ../Headers -I ./. -I . -I /home/vincent/GNUstep/Library/Headers -I /GNUstep/Local/Library/Headers -I /GNUstep/System/Library/Headers -I /usr/include/libpng12 -internal-isystem /usr/local/include -internal-isystem /opt/bin/../lib/clang/3.3/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -Wall -Wno-import -Wall -fdebug-compilation-dir /home/vincent/objc2cs/gnustep/core/gui/Source -fconstant-string-class NSConstantString -ferror-limit 19 -fmessage-length 232 -pthread -mstackrealign -fblocks -fobjc-runtime=gnustep-1.6 -fobjc-dispatch-method=non-legacy -fobjc-default-synthesize-properties -fobjc-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -backend-option -vectorize-loops -o /tmp/NSButton-sxcmia.mi -x objective-c++-cpp-output NSButton.m

**** THEN file is transformed (-rewrite-objc)

"/opt/bin/clang-3.3" -cc1 -triple x86_64-unknown-linux-gnu -rewrite-objc -disable-free -main-file-name NSButton.m -mrelocation-model pic -pic-level 2 -mdisable-fp-elim -relaxed-aliasing -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -v -v -g -coverage-file /home/vincent/objc2cs/gnustep/core/gui/Source/NSButton.cpp -resource-dir /opt/bin/../lib/clang/3.3 -Wall -Wno-import -Wall -fdebug-compilation-dir /home/vincent/objc2cs/gnustep/core/gui/Source -fconstant-string-class NSConstantString -ferror-limit 19 -fmessage-length 232 -pthread -mstackrealign -fblocks -fobjc-runtime=gnustep-1.6 -fobjc-dispatch-method=non-legacy -fobjc-default-synthesize-properties -fno-objc-infer-related-result-type -fobjc-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -backend-option -vectorize-loops -o NSButton.cpp -x objective-c++-cpp-output /tmp/NSButton-sxcmia.mi


Is is a normal behavior to have a difference in preprocessing between -rewrite-legacy-objc and -rewrite-objc or is it one of my change that could explain it ?
What part of code is responsible for that ?
With my new flag -rewrite-objc2cs I don't want to have a preprocessing stage but I don't know how to do it ?
If you have any pointers about this part, it would help a lot.

Pleas note that for the moment the RewriteObjC2Cs.cpp is a copy of RewriteObjC.cpp and I am calling a method called CreateObjC2CsRewriter
that actually corresponds to the CreateObjCRewriter (fragile runtime) of the RewriteObjC.cpp


ASTConsumer *RewriteObjCAction::CreateASTConsumer(CompilerInstance &CI,
                                                 StringRef InFile) {
 if (raw_ostream *OS = CI.createDefaultOutputFile(false, InFile, "cpp")) {
   if (CI.getLangOpts().ObjCRuntime.isNonFragile())
     return CreateModernObjCRewriter(InFile, OS,
                               CI.getDiagnostics(), CI.getLangOpts(),
                               CI.getDiagnosticOpts().NoRewriteMacros,
                               (CI.getCodeGenOpts().getDebugInfo() !=
                                CodeGenOptions::NoDebugInfo));
   return CreateObjCRewriter(InFile, OS,
                             CI.getDiagnostics(), CI.getLangOpts(),
                             CI.getDiagnosticOpts().NoRewriteMacros);
 }
 return 0;
}

ASTConsumer *RewriteObjC2CsAction::CreateASTConsumer(CompilerInstance &CI,
                                                 StringRef InFile) {
 if (raw_ostream *OS = CI.createDefaultOutputFile(false, InFile, "cs")) {
  return CreateObjC2CsRewriter(InFile, OS,
                             CI.getDiagnostics(), CI.getLangOpts(),
                             CI.getDiagnosticOpts().NoRewriteMacros);
 }
 return 0;
}




Thanks

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev


_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: How to add a new rewriting option

Vincent R.
Le 30.07.2013 17:47, jahanian a écrit :

> Hi Vincent,
>
> -rewrite-legacy-objc is out of date. For up to date support for
> ObjectiveC features and translation of its
> modern ABI, you may want to look into -rewrite-objc. -rewrite-objc
> has
> simplified the workflow by pre-processing
> user program and translating it into C++. -rewrite-legacy-objc
> requires user to do the pre-processing step manually.
>

Ok but what I would like to achieve is closer to rewrite-legacy-objc
than rewrite-objc
because I don't want to compile the code after transformation and I
don't want preprocessing stage.


So now I have modified the Options.td for my new flag -rewrite-objc2cs
and used the same parameters
as rewrite-legacy-objc but now the driver tells me : unrecognized

clang -rewrite-objc2cs NSButton.m -c -MMD -MP
-DGNUSTEP_TARGET_DIR=\".\" -DGNUSTEP_TARGET_CPU=\"x86_64\"
-DGNUSTEP_TARGET_OS=\"linux-gnu\" -DLIBRARY_COMBO=\"gnu-gnu-gnu\"
-DBACKEND_BUNDLE=1 -DGNUSTEP -DGNUSTEP_BASE_LIBRARY=1
-DGNU_GUI_LIBRARY=1 -DGNU_RUNTIME=1 -DGNUSTEP_BASE_LIBRARY=1
-fno-strict-aliasing -fexceptions -fobjc-exceptions
-D_NATIVE_OBJC_EXCEPTIONS -fobjc-nonfragile-abi -D_NONFRAGILE_ABI
-pthread -fPIC -DDEBUG -fno-omit-frame-pointer -Wall -DGSWARN
-DGSDIAGNOSE -Wno-import -g -fgnu-runtime -Wall
-fconstant-string-class=NSConstantString -I../Headers/Additions
-I../Headers -I./. -I. -I/home/vincent/GNUstep/Library/Headers
-I/GNUstep/Local/Library/Headers -I/GNUstep/System/Library/Headers
-I/usr/include/libpng12


vincent@vincent-virtual-machine ~/objc2cs/gnustep/core/gui/Source $
clang -v -v -rewrite-objc2cs NSButton.m -c -MMD -MP
-DGNUSTEP_TARGET_DIR=\".\" -DGNUSTEP_TARGET_CPU=\"x86_64\"
-DGNUSTEP_TARGET_OS=\"linux-gnu\" -DLIBRARY_COMBO=\"gnu-gnu-gnu\"
-DBACKEND_BUNDLE=1 -DGNUSTEP -DGNUSTEP_BASE_LIBRARY=1
-DGNU_GUI_LIBRARY=1 -DGNU_RUNTIME=1 -DGNUSTEP_BASE_LIBRARY=1
-fno-strict-aliasing -fexceptions -fobjc-exceptions
-D_NATIVE_OBJC_EXCEPTIONS -fobjc-nonfragile-abi -D_NONFRAGILE_ABI
-pthread -fPIC -DDEBUG -fno-omit-frame-pointer -Wall -DGSWARN
-DGSDIAGNOSE -Wno-import -g -fgnu-runtime -Wall
-fconstant-string-class=NSConstantString -I../Headers/Additions
-I../Headers -I./. -I. -I/home/vincent/GNUstep/Library/Headers
-I/GNUstep/Local/Library/Headers -I/GNUstep/System/Library/Headers
-I/usr/include/libpng12
clang version 3.3 (186145)
Target: x86_64-unknown-linux-gnu
Thread model: posix
  "/opt/bin/clang-3.3" -cc1 -triple x86_64-unknown-linux-gnu
-rewrite-objc2cs -disable-free -main-file-name NSButton.m
-mrelocation-model pic -pic-level 2 -mdisable-fp-elim -relaxed-aliasing
-fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables
-fuse-init-array -target-cpu x86-64 -v -v -g -coverage-file
/home/vincent/objc2cs/gnustep/core/gui/Source/NSButton.cs -resource-dir
/opt/bin/../lib/clang/3.3 -dependency-file NSButton.d -MT NSButton.o -MP
-D "GNUSTEP_TARGET_DIR=\".\"" -D "GNUSTEP_TARGET_CPU=\"x86_64\"" -D
"GNUSTEP_TARGET_OS=\"linux-gnu\"" -D "LIBRARY_COMBO=\"gnu-gnu-gnu\"" -D
BACKEND_BUNDLE=1 -D GNUSTEP -D GNUSTEP_BASE_LIBRARY=1 -D
GNU_GUI_LIBRARY=1 -D GNU_RUNTIME=1 -D GNUSTEP_BASE_LIBRARY=1 -D
_NATIVE_OBJC_EXCEPTIONS -D _NONFRAGILE_ABI -D DEBUG -D GSWARN -D
GSDIAGNOSE -I ../Headers/Additions -I ../Headers -I ./. -I . -I
/home/vincent/GNUstep/Library/Headers -I /GNUstep/Local/Library/Headers
-I /GNUstep/System/Library/Headers -I /usr/include/libpng12
-internal-isystem /usr/local/include -internal-isystem
/opt/bin/../lib/clang/3.3/include -internal-externc-isystem
/usr/include/x86_64-linux-gnu -internal-externc-isystem /include
-internal-externc-isystem /usr/include -Wall -Wno-import -Wall
-fdebug-compilation-dir /home/vincent/objc2cs/gnustep/core/gui/Source
-fconstant-string-class NSConstantString -ferror-limit 19
-fmessage-length 159 -pthread -mstackrealign -fblocks
-fobjc-runtime=gnustep-1.6 -fobjc-dispatch-method=non-legacy
-fobjc-default-synthesize-properties -fno-objc-infer-related-result-type
-fobjc-exceptions -fexceptions -fdiagnostics-show-option
-fcolor-diagnostics -backend-option -vectorize-loops -o NSButton.cs -x
objective-c NSButton.m
error: unknown argument: '-rewrite-objc2cs'

Before I use the same arguments as rewrite-legacy-objc, the command was
working even if the result wasn't what I wanted to (non processed file).
So I suppose I forgot to add my new option somewhere in the code but I
don't know where ...




_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: How to add a new rewriting option

Vincent R.
Le 30.07.2013 18:30, Vincent R. a écrit :

> Le 30.07.2013 17:47, jahanian a écrit :
>> Hi Vincent,
>>
>> -rewrite-legacy-objc is out of date. For up to date support for
>> ObjectiveC features and translation of its
>> modern ABI, you may want to look into -rewrite-objc. -rewrite-objc
>> has
>> simplified the workflow by pre-processing
>> user program and translating it into C++. -rewrite-legacy-objc
>> requires user to do the pre-processing step manually.
>>
>
> Ok but what I would like to achieve is closer to rewrite-legacy-objc
> than rewrite-objc
> because I don't want to compile the code after transformation and I
> don't want preprocessing stage.
>
>
> So now I have modified the Options.td for my new flag
> -rewrite-objc2cs and used the same parameters
> as rewrite-legacy-objc but now the driver tells me : unrecognized
>
> clang -rewrite-objc2cs NSButton.m -c -MMD -MP
> -DGNUSTEP_TARGET_DIR=\".\" -DGNUSTEP_TARGET_CPU=\"x86_64\"
> -DGNUSTEP_TARGET_OS=\"linux-gnu\" -DLIBRARY_COMBO=\"gnu-gnu-gnu\"
> -DBACKEND_BUNDLE=1 -DGNUSTEP -DGNUSTEP_BASE_LIBRARY=1
> -DGNU_GUI_LIBRARY=1 -DGNU_RUNTIME=1 -DGNUSTEP_BASE_LIBRARY=1
> -fno-strict-aliasing -fexceptions -fobjc-exceptions
> -D_NATIVE_OBJC_EXCEPTIONS -fobjc-nonfragile-abi -D_NONFRAGILE_ABI
> -pthread -fPIC -DDEBUG -fno-omit-frame-pointer -Wall -DGSWARN
> -DGSDIAGNOSE -Wno-import -g -fgnu-runtime -Wall
> -fconstant-string-class=NSConstantString -I../Headers/Additions
> -I../Headers -I./. -I. -I/home/vincent/GNUstep/Library/Headers
> -I/GNUstep/Local/Library/Headers -I/GNUstep/System/Library/Headers
> -I/usr/include/libpng12
>
>
> vincent@vincent-virtual-machine ~/objc2cs/gnustep/core/gui/Source $
> clang -v -v -rewrite-objc2cs NSButton.m -c -MMD -MP
> -DGNUSTEP_TARGET_DIR=\".\" -DGNUSTEP_TARGET_CPU=\"x86_64\"
> -DGNUSTEP_TARGET_OS=\"linux-gnu\" -DLIBRARY_COMBO=\"gnu-gnu-gnu\"
> -DBACKEND_BUNDLE=1 -DGNUSTEP -DGNUSTEP_BASE_LIBRARY=1
> -DGNU_GUI_LIBRARY=1 -DGNU_RUNTIME=1 -DGNUSTEP_BASE_LIBRARY=1
> -fno-strict-aliasing -fexceptions -fobjc-exceptions
> -D_NATIVE_OBJC_EXCEPTIONS -fobjc-nonfragile-abi -D_NONFRAGILE_ABI
> -pthread -fPIC -DDEBUG -fno-omit-frame-pointer -Wall -DGSWARN
> -DGSDIAGNOSE -Wno-import -g -fgnu-runtime -Wall
> -fconstant-string-class=NSConstantString -I../Headers/Additions
> -I../Headers -I./. -I. -I/home/vincent/GNUstep/Library/Headers
> -I/GNUstep/Local/Library/Headers -I/GNUstep/System/Library/Headers
> -I/usr/include/libpng12
> clang version 3.3 (186145)
> Target: x86_64-unknown-linux-gnu
> Thread model: posix
>  "/opt/bin/clang-3.3" -cc1 -triple x86_64-unknown-linux-gnu
> -rewrite-objc2cs -disable-free -main-file-name NSButton.m
> -mrelocation-model pic -pic-level 2 -mdisable-fp-elim
> -relaxed-aliasing -fmath-errno -masm-verbose -mconstructor-aliases
> -munwind-tables -fuse-init-array -target-cpu x86-64 -v -v -g
> -coverage-file
> /home/vincent/objc2cs/gnustep/core/gui/Source/NSButton.cs
> -resource-dir /opt/bin/../lib/clang/3.3 -dependency-file NSButton.d
> -MT NSButton.o -MP -D "GNUSTEP_TARGET_DIR=\".\"" -D
> "GNUSTEP_TARGET_CPU=\"x86_64\"" -D "GNUSTEP_TARGET_OS=\"linux-gnu\""
> -D "LIBRARY_COMBO=\"gnu-gnu-gnu\"" -D BACKEND_BUNDLE=1 -D GNUSTEP -D
> GNUSTEP_BASE_LIBRARY=1 -D GNU_GUI_LIBRARY=1 -D GNU_RUNTIME=1 -D
> GNUSTEP_BASE_LIBRARY=1 -D _NATIVE_OBJC_EXCEPTIONS -D _NONFRAGILE_ABI
> -D DEBUG -D GSWARN -D GSDIAGNOSE -I ../Headers/Additions -I
> ../Headers
> -I ./. -I . -I /home/vincent/GNUstep/Library/Headers -I
> /GNUstep/Local/Library/Headers -I /GNUstep/System/Library/Headers -I
> /usr/include/libpng12 -internal-isystem /usr/local/include
> -internal-isystem /opt/bin/../lib/clang/3.3/include
> -internal-externc-isystem /usr/include/x86_64-linux-gnu
> -internal-externc-isystem /include -internal-externc-isystem
> /usr/include -Wall -Wno-import -Wall -fdebug-compilation-dir
> /home/vincent/objc2cs/gnustep/core/gui/Source -fconstant-string-class
> NSConstantString -ferror-limit 19 -fmessage-length 159 -pthread
> -mstackrealign -fblocks -fobjc-runtime=gnustep-1.6
> -fobjc-dispatch-method=non-legacy
> -fobjc-default-synthesize-properties
> -fno-objc-infer-related-result-type -fobjc-exceptions -fexceptions
> -fdiagnostics-show-option -fcolor-diagnostics -backend-option
> -vectorize-loops -o NSButton.cs -x objective-c NSButton.m
> error: unknown argument: '-rewrite-objc2cs'
>
> Before I use the same arguments as rewrite-legacy-objc, the command
> was working even if the result wasn't what I wanted to (non processed
> file).
> So I suppose I forgot to add my new option somewhere in the code but
> I don't know where ...


And another thing I don't understand because when looking at generated
code when using -rewrite-legacy-objc
it seems the rewriter used is the one implemented inside
RewriteModernObjC.cpp.

I don't understand why because if I look int Tools.cpp :

} else if (JA.getType() == types::TY_RewrittenObjC) {
       CmdArgs.push_back("-rewrite-objc");
       rewriteKind = RK_NonFragile;
     } else if (JA.getType() == types::TY_RewrittenLegacyObjC) {
       CmdArgs.push_back("-rewrite-objc");
       rewriteKind = RK_Fragile;
     } else if (JA.getType() == types::TY_RewrittenObjC2Cs) {
       CmdArgs.push_back("-rewrite-objc2cs");
       rewriteKind = RK_Fragile;
     } else {
       assert(JA.getType() == types::TY_PP_Asm &&
              "Unexpected output type!");
     }

the associated rewriteKind of TY_RewrittenLegacyObjC is RK_Fragile BUT
the code that use RewriteModernObjC is the following :

if (CI.getLangOpts().ObjCRuntime.isNonFragile())
       return CreateModernObjCRewriter(InFile, OS,
                                 CI.getDiagnostics(), CI.getLangOpts(),
                                 CI.getDiagnosticOpts().NoRewriteMacros,
                                 (CI.getCodeGenOpts().getDebugInfo() !=
                                  CodeGenOptions::NoDebugInfo));
     return CreateObjCRewriter(InFile, OS,
                               CI.getDiagnostics(), CI.getLangOpts(),
                               CI.getDiagnosticOpts().NoRewriteMacros);

so does it mean that the fragile meaning of ObjCRuntime.isNonFragile()
is different from the rewriteKind meaning ?
Because let's say I cannot debug clang and just by reading the code I
would have thought than when using -rewrite-legacy-objc (RK_Fragile)
it would call the fragile branch ie CreateObjCRewriter() ...


And another question about debugging I tried to put some breakpoints
inside CreateModernObjCRewriter and CreateObjCRewriter and inside
some other methods inside RewriteModernObjC.cpp but they are never
triggered. Any idea why ?













_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev