[cfe-dev] How to add a new rewriting option
jahanian
fjahanian at apple.com
Tue Jul 30 08:47:22 PDT 2013
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. <forumer at smartmobili.com> 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
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130730/eecf1df0/attachment.html>
More information about the cfe-dev
mailing list