My goal is to create a source to source translator that translates Objective-C header files into D files. From what I've read here in this list I should create a rewrite class, something like RewriteObjC.cpp.
I started by modifying RewriteObjC.cpp but then thought that it would be better to add a new rewrite class. I modified the source code for Clang and added a new file called RewriteObjCToD.cpp by copying the existing RewriteObjC.cpp then I added a new command line option to Clang to be able to use the new rewrite class. After compiling everything I tried to run Clang using "clang --help" and got this error:
<FlagClass Name:"-rewrite-objc">
<FlagClass Name:"-rewrite-objc-to-d">
Assertion failed: (0 && "Options are not in order!"), function OptTable,
file OptTable.cpp, line 119.
[...]
So how do I correctly add a new command line option to Clang
You just have to order them correctly [1]:
Options are stored in sorted order, with '\0' at the end of the
alphabet.o
So '-rewrite-objc-to-d' has to come *before* '-rewrite-objc'. The
ordering is necessary due to the way Clang parses its options.
or is there a better way to quickly get up and running with a new
rewrite class?
You could implement it as a plugin. There's an example in
'example/PrintFunctionNames'. Unfortunately the plugin infrastructure is
somewhat buggy/incomplete/?, so you have to add a minor change to llvm
before they work [2].
<FlagClass Name:"-rewrite-objc">
<FlagClass Name:"-rewrite-objc-to-d">
Assertion failed: (0 && "Options are not in order!"), function OptTable,
file OptTable.cpp, line 119.
[...]
So how do I correctly add a new command line option to Clang
You just have to order them correctly [1]:
> Options are stored in sorted order, with '\0' at the end of the
> alphabet.o
So '-rewrite-objc-to-d' has to come *before* '-rewrite-objc'. The
ordering is necessary due to the way Clang parses its options.
Note that this is no longer true, the option parser tblgen backend
handles the reordering now.
<FlagClass Name:"-rewrite-objc">
<FlagClass Name:"-rewrite-objc-to-d">
Assertion failed: (0&& "Options are not in order!"), function OptTable,
file OptTable.cpp, line 119.
[...]
So how do I correctly add a new command line option to Clang
You just have to order them correctly [1]:
> Options are stored in sorted order, with '\0' at the end of the
> alphabet.o
So '-rewrite-objc-to-d' has to come *before* '-rewrite-objc'. The
ordering is necessary due to the way Clang parses its options.
Note that this is no longer true, the option parser tblgen backend
handles the reordering now.
- Daniel
Ok, then I guess I used an older version of Clang.
<FlagClass Name:"-rewrite-objc">
<FlagClass Name:"-rewrite-objc-to-d">
Assertion failed: (0&& "Options are not in order!"), function OptTable,
file OptTable.cpp, line 119.
[...]
So how do I correctly add a new command line option to Clang
You just have to order them correctly [1]:
> Options are stored in sorted order, with '\0' at the end of the
> alphabet.o
So '-rewrite-objc-to-d' has to come *before* '-rewrite-objc'. The
ordering is necessary due to the way Clang parses its options.
Thanks that helped, but how could "-rewrite-objc-to-d" come before "-rewrite-objc" ?
<FlagClass Name:"-rewrite-objc">
<FlagClass Name:"-rewrite-objc-to-d">
Assertion failed: (0&& "Options are not in order!"), function OptTable,
file OptTable.cpp, line 119.
[...]
So how do I correctly add a new command line option to Clang
You just have to order them correctly [1]:
> Options are stored in sorted order, with '\0' at the end of the
> alphabet.o
So '-rewrite-objc-to-d' has to come *before* '-rewrite-objc'. The
ordering is necessary due to the way Clang parses its options.
Thanks that helped, but how could "-rewrite-objc-to-d" come before
"-rewrite-objc" ?
That is just the particular definition of the ordering we use. We
always match the first option in the list which is a prefix (more or
less), and we want "-rewrite-objc-to-d" to be matched instead of
"-rewrite-objc" (if it accepts suffixes).