Skip to content
Browse files

Various pre-release cleanups

  • Loading branch information...
1 parent d5ba1a5 commit 4dee94f3cdd08ae41af0f6a01b82c48c1f7892b7 @davidmalcolm davidmalcolm committed Jun 21, 2011
Showing with 127 additions and 17 deletions.
  1. +5 −3 Makefile
  2. +7 −2 README.rst
  3. +55 −9 docs/basics.rst
  4. +21 −0 gcc-python-docs
  5. +17 −0 gcc-with-python
  6. +19 −0 show-docs.py
  7. +2 −2 testcpybuilder.py
  8. +1 −1 testcpychecker.py
View
8 Makefile
@@ -40,13 +40,15 @@ PLUGIN_SOURCE_FILES= \
PLUGIN_OBJECT_FILES= $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES))
GCCPLUGINS_DIR:= $(shell $(GCC) --print-file-name=plugin)
-PYTHON_CONFIG=python-debug-config
+PYTHON_CONFIG=python-config
+#PYTHON_CONFIG=python-debug-config
+
PYTHON_CFLAGS=$(shell $(PYTHON_CONFIG) --cflags)
PYTHON_LDFLAGS=$(shell $(PYTHON_CONFIG) --ldflags)
CFLAGS+= -I$(GCCPLUGINS_DIR)/include -fPIC -O2 -Wall -Werror -g $(PYTHON_CFLAGS) $(PYTHON_LDFLAGS)
-all: testcpychecker testcpybuilder test-suite demo test
+all: testcpybuilder test-suite testcpychecker
plugin: python.so
@@ -95,7 +97,7 @@ TEST_CFLAGS= \
-fplugin=$(shell pwd)/python.so \
-fplugin-arg-python-script=test.py
-# Catch-all test for experimentation with the API:
+# A catch-all test for quick experimentation with the API:
test: plugin
PYTHONPATH=$(shell pwd) gcc -v $(TEST_CFLAGS) $(shell pwd)/test.c
View
9 README.rst
@@ -30,8 +30,13 @@ I use::
make
-to run the tests, which finishes by running ``make demo``, which expects to
-fail, demonstrating the new compiler errors.
+to build the plugin and run the tests
+
+You can also use::
+
+ make demo
+
+to demonstrate the new compiler errors.
All of my coding so far has been on Fedora 15 x86_64, using::
View
64 docs/basics.rst
@@ -23,11 +23,29 @@
Basic usage of the plugin
=========================
-The process for building and installing the plugin is still a bit messy; you'll
-need to read the Makefile and use your own judgement. Some notes on GCC plugins
-can be seen at http://gcc.gnu.org/wiki/plugins and
-http://gcc.gnu.org/onlinedocs/gccint/Plugins.html
+To build the plugin, run:
+
+.. code-block:: bash
+
+ make plugin
+
+To build the plugin and run the selftests, run:
+
+.. code-block:: bash
+
+ make
+You can also use::
+
+ make demo
+
+to demonstrate the new compiler errors.
+
+There isn't a well-defined process yet for installing the plugin (though the
+rpm specfile in the source tree contains some work-in-progress towards this).
+
+Some notes on GCC plugins can be seen at http://gcc.gnu.org/wiki/plugins and
+http://gcc.gnu.org/onlinedocs/gccint/Plugins.html
Once you've built the plugin, you can invoke a Python script like this:
@@ -40,16 +58,44 @@ you have to supply absolute paths to the plugin, and to the script. (There's
also a gccutil.py, and you have to set PYTHONPATH for the plugin to be able to
find it).
-The exact API is still in flux; you can currently connect to events by
-registering callbacks e.g. to be called for each function in the source at
-different passes.
+There is also a helper script, `gcc-with-python`, which expects a python script
+as its first argument, then regular gcc arguments:
+
+.. code-block:: bash
-It exposes GCC's various types as Python objects, within a "gcc" module. You
-can see the API by running::
+ ./gcc-with-python PATH_TO_SCRIPT.py other args follow
+
+For example, this command will use graphviz to draw how GCC "sees" the
+internals of each function in `test.c` (within its SSA representation):
+
+.. code-block:: bash
+
+ ./gcc-with-python show-ssa.py test.c
+
+
+Most of the rest of this document describes the Python API visible for
+scripting.
+
+The plugin GCC's various types as Python objects, within a "gcc" module. You
+can see the API by running the following within a script::
import gcc
help(gcc)
+To make this easier, there's a script to do this for you:
+
+.. code-block:: bash
+
+ ./gcc-python-docs
+
+from where you can review the built-in documentation strings (this document
+may be easier to follow though).
+
+The exact API is still in flux: and may well change (this is an early version
+of the code; we may have to change things as GCC changes in future releases
+also).
+
+
Accessing parameters
--------------------
View
21 gcc-python-docs
@@ -0,0 +1,21 @@
+#!/bin/sh
+# Copyright 2011 David Malcolm <dmalcolm@redhat.com>
+# Copyright 2011 Red Hat, Inc.
+#
+# This is free software: you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see
+# <http://www.gnu.org/licenses/>.
+
+# Invoke "show-docs.py", with a dummy source file
+./gcc-with-python show-docs.py test.c
+
View
17 gcc-with-python
@@ -1,2 +1,19 @@
#!/bin/sh
+# Copyright 2011 David Malcolm <dmalcolm@redhat.com>
+# Copyright 2011 Red Hat, Inc.
+#
+# This is free software: you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see
+# <http://www.gnu.org/licenses/>.
+
PYTHONPATH=$(pwd) gcc -fplugin=$(pwd)/python.so -fplugin-arg-python-script=$@
View
19 show-docs.py
@@ -0,0 +1,19 @@
+# Copyright 2011 David Malcolm <dmalcolm@redhat.com>
+# Copyright 2011 Red Hat, Inc.
+#
+# This is free software: you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see
+# <http://www.gnu.org/licenses/>.
+
+import gcc
+help(gcc)
View
4 testcpybuilder.py
@@ -27,8 +27,8 @@
# FIXME: this will need tweaking:
pyruntimes = [PyRuntime('/usr/bin/python2.7', '/usr/bin/python2.7-config'),
- PyRuntime('/usr/bin/python2.7-debug', '/usr/bin/python2.7-debug-config'),
- PyRuntime('/usr/bin/python3.2mu', '/usr/bin/python3.2mu-config'),
+ #PyRuntime('/usr/bin/python2.7-debug', '/usr/bin/python2.7-debug-config'),
+ #PyRuntime('/usr/bin/python3.2mu', '/usr/bin/python3.2mu-config'),
#PyRuntime('/usr/bin/python3.2dmu', '/usr/bin/python3.2dmu-config')
]
View
2 testcpychecker.py
@@ -451,7 +451,7 @@ def make_src_for_incorrect_function(self, code, typenames):
'}\n') % locals()
return src, function_name
-#@unittest.skip("Refcount tracker doesn't yet work")
+@unittest.skip("Refcount tracker doesn't yet work")
class RefcountErrorTests(AnalyzerTests):
def add_method_table(self, cu, fn_name):
methods = PyMethodTable('test_methods',

0 comments on commit 4dee94f

Please sign in to comment.
Something went wrong with that request. Please try again.