Skip to content

Commit

Permalink
Initial wrapping of the Register Transfer Language
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmalcolm committed Jul 28, 2011
1 parent 629182b commit fc4d7fa
Show file tree
Hide file tree
Showing 16 changed files with 813 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ PLUGIN_SOURCE_FILES= \
gcc-python-parameter.c \
gcc-python-pass.c \
gcc-python-pretty-printer.c \
gcc-python-rtl.c \
gcc-python-tree.c \
gcc-python-variable.c \
autogenerated-callgraph.c \
Expand All @@ -40,6 +41,7 @@ PLUGIN_SOURCE_FILES= \
autogenerated-parameter.c \
autogenerated-pass.c \
autogenerated-pretty-printer.c \
autogenerated-rtl.c \
autogenerated-tree.c \
autogenerated-variable.c

Expand Down Expand Up @@ -104,6 +106,9 @@ clean:
autogenerated-gimple-types.txt: gimple-types.txt.in
cpp $(CFLAGS) $^ -o $@

autogenerated-rtl-types.txt: rtl-types.txt.in
cpp $(CFLAGS) $^ -o $@

autogenerated-tree-types.txt: tree-types.txt.in
cpp $(CFLAGS) $^ -o $@

Expand Down Expand Up @@ -137,6 +142,9 @@ autogenerated-pretty-printer.c: cpybuilder.py generate-pretty-printer-c.py
autogenerated-tree.c: cpybuilder.py generate-tree-c.py autogenerated-tree-types.txt maketreetypes.py
$(PYTHON) generate-tree-c.py > $@

autogenerated-rtl.c: cpybuilder.py generate-rtl-c.py autogenerated-rtl-types.txt maketreetypes.py
python generate-rtl-c.py > $@

autogenerated-variable.c: cpybuilder.py generate-variable-c.py autogenerated-gimple-types.txt maketreetypes.py
$(PYTHON) generate-variable-c.py > $@

Expand Down
5 changes: 5 additions & 0 deletions docs/cfg.rst
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ You can get at the control flow graph of a :py:class:`gcc.Function` via its
The list of :py:class:`gcc.Gimple` instructions, if appropriate for this
pass, or None

.. py:attribute:: rtl
The list of :py:class:`gcc.Rtl` expressions, if appropriate for this
pass, or None


.. py:class:: gcc.Edge
Expand Down
1 change: 1 addition & 0 deletions docs/misc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ scripts.
parameters.rst
versions.rst
tables-of-passes.rst
rtl.rst
193 changes: 193 additions & 0 deletions docs/rtl.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
.. 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/>.
Register Transfer Language (RTL)
================================

.. py:class:: gcc.Rtl
A wrapper around GCC's `struct rtx_def` type: an expression within GCC's
Register Transfer Language

.. py:attribute:: loc
The :py:class:`gcc.Location` of this expression, or None

.. py:attribute:: operands
The operands of this expression, as a tuple. The precise type of the
operands will vary by subclass.

There are numerous subclasses. However, this part of the API is much less
polished than the rest of the plugin.

.. Here's a dump of the class hierarchy, from help(gcc):
.. Rtl
.. RtxAutoinc
.. RtlPostDec
.. RtlPostInc
.. RtlPostModify
.. RtlPreDec
.. RtlPreInc
.. RtlPreModify
.. RtxBinArith
.. RtlAshift
.. RtlAshiftrt
.. RtlCompare
.. RtlDiv
.. RtlLshiftrt
.. RtlMinus
.. RtlMod
.. RtlRotate
.. RtlRotatert
.. RtlSsAshift
.. RtlSsDiv
.. RtlSsMinus
.. RtlUdiv
.. RtlUmod
.. RtlUsAshift
.. RtlUsDiv
.. RtlUsMinus
.. RtlVecConcat
.. RtlVecSelect
.. RtxBitfieldOps
.. RtlSignExtract
.. RtlZeroExtract
.. RtxCommArith
.. RtlAnd
.. RtlIor
.. RtlMult
.. RtlPlus
.. RtlSmax
.. RtlSmin
.. RtlSsMult
.. RtlSsPlus
.. RtlUmax
.. RtlUmin
.. RtlUsMult
.. RtlUsPlus
.. RtlXor
.. RtxCommCompare
.. RtlEq
.. RtlLtgt
.. RtlNe
.. RtlOrdered
.. RtlUneq
.. RtlUnordered
.. RtxCompare
.. RtlGe
.. RtlGeu
.. RtlGt
.. RtlGtu
.. RtlLe
.. RtlLeu
.. RtlLt
.. RtlLtu
.. RtlUnge
.. RtlUngt
.. RtlUnle
.. RtlUnlt
.. RtxConstObj
.. RtlConst
.. RtlConstDouble
.. RtlConstFixed
.. RtlConstInt
.. RtlConstVector
.. RtlHigh
.. RtlLabelRef
.. RtlSymbolRef
.. RtxExtra
.. RtlAddrDiffVec
.. RtlAddrVec
.. RtlAsmInput
.. RtlAsmOperands
.. RtlBarrier
.. RtlCall
.. RtlClobber
.. RtlCodeLabel
.. RtlCondExec
.. RtlEhReturn
.. RtlExprList
.. RtlInsnList
.. RtlNote
.. RtlParallel
.. RtlPrefetch
.. RtlReturn
.. RtlSequence
.. RtlSet
.. RtlStrictLowPart
.. RtlSubreg
.. RtlTrapIf
.. RtlUnknown
.. RtlUnspec
.. RtlUnspecVolatile
.. RtlUse
.. RtlVarLocation
.. RtxInsn
.. RtlCallInsn
.. RtlDebugInsn
.. RtlInsn
.. RtlJumpInsn
.. RtxMatch
.. RtlAddress
.. RtxObj
.. RtlCc0
.. RtlConcat
.. RtlConcatn
.. RtlConstString
.. RtlDebugExpr
.. RtlDebugImplicitPtr
.. RtlLoSum
.. RtlMem
.. RtlPc
.. RtlReg
.. RtlScratch
.. RtlValue
.. RtxTernary
.. RtlFma
.. RtlIfThenElse
.. RtlVecMerge
.. RtxUnary
.. RtlAbs
.. RtlBswap
.. RtlClz
.. RtlCtz
.. RtlFfs
.. RtlFix
.. RtlFloat
.. RtlFloatExtend
.. RtlFloatTruncate
.. RtlFractConvert
.. RtlNeg
.. RtlNot
.. RtlParity
.. RtlPopcount
.. RtlSatFract
.. RtlSignExtend
.. RtlSqrt
.. RtlSsAbs
.. RtlSsNeg
.. RtlSsTruncate
.. RtlTruncate
.. RtlUnsignedFix
.. RtlUnsignedFloat
.. RtlUnsignedFractConvert
.. RtlUnsignedSatFract
.. RtlUsNeg
.. RtlUsTruncate
.. RtlVecDuplicate
.. RtlZeroExtend
49 changes: 49 additions & 0 deletions gcc-python-cfg.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "gcc-python-wrappers.h"

#include "basic-block.h"
#include "rtl.h"

/*
"struct edge_def" is declared in basic-block.h, c.f:
Expand Down Expand Up @@ -185,6 +186,54 @@ gcc_BasicBlock_get_phi_nodes(PyGccBasicBlock *self, void *closure)
return gcc_python_gimple_seq_to_list(self->bb->il.gimple->phi_nodes);
}

PyObject *
gcc_BasicBlock_get_rtl(PyGccBasicBlock *self, void *closure)
{
PyObject *result = NULL;

rtx insn;

if (!(self->bb->flags & BB_RTL)) {
Py_RETURN_NONE;
}

#if 0
/* Debugging help: */
{
fprintf(stderr, "--BEGIN--\n");
FOR_BB_INSNS(self->bb, insn) {
print_rtl_single (stderr, insn);
}
fprintf(stderr, "-- END --\n");
}
#endif

result = PyList_New(0);
if (!result) {
goto error;
}

FOR_BB_INSNS(self->bb, insn) {
PyObject *obj;

obj = gcc_python_make_wrapper_rtl(insn);
if (!obj) {
goto error;
}

if (PyList_Append(result, obj)) {
goto error;
}
}

return result;

error:
Py_XDECREF(result);
return NULL;
}


/*
Force a 1-1 mapping between pointer values and wrapper objects
*/
Expand Down
Loading

0 comments on commit fc4d7fa

Please sign in to comment.