, it will lead to a GCC error:
/home/david/test.c:36:1: error: Unhandled Python exception raised calling 'execute' method Traceback (most recent call last): File "script.py", line 79, in execute dot = gccutils.tree_to_dot(fun) NameError: global name 'gccutils' is not defined
Given the name of another pass, register this
gcc.Passto occur immediately after that other pass.
If the other pass occurs multiple times, the pass will be inserted at the specified instance number, or at every instance, if supplied 0.
If they don’t match, GCC won’t be able to find the other pass, giving an error like this:
cc1: fatal error: pass 'ssa' not found but is referenced by new pass 'my-ipa-pass'
As above, but this pass is registered immediately before the referenced pass.
As above, but replace the given pass. This method is included for completeness; the result is unlikely to work well.
Dumping per-pass information¶
GCC has a logging framework which supports per-pass logging (“dump files”).
By default, no logging is done; dumping must be explicitly enabled.
Dumping of passes can be enabled from the command-line in groups:
For more information, see http://gcc.gnu.org/onlinedocs/gcc/Debugging-Options.html
It’s not possible to directly enable dumping for a custom pass from the command-line (it would require adding new GCC command-line options). However, your script can directly enable dumping for a custom pass by writing to the dump_enabled attribute (perhaps in response to the arguments passed to plugin, or a driver script).
If enabled for a pass, then a file is written to the same directory as the output file, with a name based on the input file and the pass number.
For example, given a custom
gcc.Pass with name ‘test-pass’, then
when input.c is compiled to build/output.o:
$ gcc -fdump-tree-all -o build/output.o src/input.c
then a dump file input.c.225t.test-pass will be written to the directory build. In this case, 225 is the static_pass_number field, “t” signifies a tree pass, with the pass name appearing as the suffix.
Write str() of the argument to the current dump file. No newlines or other whitespace are added.
Note that dumping is disabled by default; in this case, the call will do nothing.
Get the name of the current dump file.
If called from within a pass for which dumping is enabled, it will return the filename in string form.
If dumping is disabled for this pass, it will return None.
The typical output of a dump file will contain:
;; Function bar (bar) (dumped information when handling function bar goes here) ;; Function foo (foo) (dumped information when handling function foo goes here)
class TestPass(gcc.GimplePass): def execute(self, fun): # Dumping of strings: gcc.dump('hello world') # Dumping of other objects: gcc.dump(42) ps = TestPass(name='test-pass') ps.register_after('cfg') ps.dump_enabled = True
would have a dump file like this:
;; Function bar (bar) hello world42 ;; Function foo (foo) hello world42
Alternatively, it can be simpler to create your own logging system, given that one can simply open a file and write to it.
Get the base file path and name prefix for GCC’s dump files.
You can use this when creating non-standard logfiles and other output.
For example, the libcpychecker code can write HTML reports on reference-counting errors within a function, writing the output to a file named:
filename = '%s.%s-refcount-errors.html' % (gcc.get_dump_base_name(), fun.decl.name)
given fun, a
By default, this is the name of the input file, but within the output file’s directory. (It can be overridden using the -dumpbase command-line option).