If I wanted to modify or add my own extensions to C, and add them to the GCC C compiler, what would I need to do? I do not want to propose changes to the language, I want to know how the C compiler actually works.
I've had a look at the source code to GCC and it looks as if Objective-C is implemented as a simple parser that generates code that makes references to a modified runtime library and then for everything that is C-based it uses the regular C compiler. I haven't studied it intensely so I'm probably not on the right track.
Say for example, I wanted to add my own keyword to Objective-C, just for fun. I want to add something that seems easy to implement, like maybe @assert
. All I want is for @assert
to call a function that I will add to the Objective-C runtime:
objc_runtime_assert (__FILE__, __LINE__, expression, "string version of expression");
Obviously I could just implement this as function call and macro anyway, but I want to gain an understanding of the parsing and compilation stages of C source code, and maybe so I could add my own extensions to a language for my own use.
The source code I have looked at consistently refers to "trees" and there are many, many macros that perform actions or obtain information from these trees.
Is there any documentation around that explains this sort of thing in-depth?