Help with creating a plugin that modifies a program

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Is it possible for GCC plugin to modify program (at AST level) so that program behavior changes?
For instance, how to write plugin to implicitly declare global variable "fake_var" in the following program?:

// fake.c
int main () {
  return fake_var;
}

When compiled with "gcc -fplugin=myplugin.so -o fake fake.c" there should be no syntax error messages.
GCC version used: 4.5.0

I tried the following plugin code from testsuite, but it does nothing:
tree fake_var = build_decl (UNKNOWN_LOCATION, VAR_DECL, get_identifier ("fake_var"), integer_type_node);
TREE_PUBLIC (fake_var) = 1;
DECL_ARTIFICIAL (fake_var) = 1;

(Event: PLUGIN_PRE_GENERICIZE, don't want to use gimple)


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux