Reputation: 9110
So basically I am using CIL (writing some CIL extension) to simplify some C code, and what I am trying to do is eliminate the usage of pointer(Because the usage of pointer could cause a lot of troubles in our next step analysis)
Here is the code:
void foo()
{
int a = 1;
int* p = &a;
int c = *p;
*p = 3;
}
I am thinking that to maintain a map of pointer reference relation in my CIL extension, and the simplified C code could be:
void foo()
{
int a = 1;
// int *p = &a; // map: {p : a} just eliminate this code, and create new entry in map
int c = a; // substitute based on map
a = 3; // substitute based on map
}
This is the most easy situation, and it looks promising.
But things could turn to complicated, for example return a pointer(then have to change the type of this function, of course it is also straightforward in CIL)
So my questions are :
Is it universally doable to eliminate pointer in this way?
Is there any undecidable situation?
Upvotes: 2
Views: 82
Reputation: 40614
I'm not sure about what you are actually trying to achieve, but eliminating all pointer uses is next to impossible. You may be able to eliminate some uses (like the rather trivial code in your example), but you will most likely not be able to eliminate all, simply because indirection is used in so many interesting ways.
Take for example a linked list. If you try to eliminate the pointers linking the list, you would need to give a name to each list node that is ever created by the program. Of course, you can replace the list by an array (which involves pointer arithmetic of its own), but that won't help you with a binary tree. And that is not the end of it, there are hash tables, virtually arbitrary linking between objects that results from object oriented programming, etc.
Upvotes: 2