Пример #1
0
static PyObject *
PyGcc_get_global_namespace(PyObject *self, PyObject *args)
{
    /* (global_namespace will be NULL outside the C++ frontend, giving a
       result of None) */
    return PyGccTree_New(gcc_private_make_tree(global_namespace));
}
Пример #2
0
GCC_IMPLEMENT_PUBLIC_API (gcc_tree) gcc_variable_get_decl (gcc_variable var)
{
  /* gcc 4.8 eliminated the
       tree decl;
     field of varpool_node in favor of
       struct symtab_node_base symbol;

     gcc 4.9 made varpool_node be a derived class of symtab_node_base,
     renaming it to symtab_node.
  */
  tree decl;

#if (GCC_VERSION >= 4009)
  /* Get from base class */
  decl = var.inner->decl;
#else
#  if (GCC_VERSION >= 4008)
  decl = var.inner->symbol.decl;
#  else
  decl = var.inner->decl;
#  endif
#endif

  return gcc_private_make_tree (decl);
}
Пример #3
0
static PyObject *
PyGcc_maybe_get_identifier(PyObject *self, PyObject *args)
{
    const char *str;
    tree t;

    if (!PyArg_ParseTuple(args,
			  "s:maybe_get_identifier",
			  &str)) {
	return NULL;
    }

    t = maybe_get_identifier(str);
    return PyGccTree_New(gcc_private_make_tree(t));
}
/*
  Helper function when a custom attribute is encountered, for generating
  the arguments to the Python callback.

  The args to the function call will be the node, plus the args of the
  attribute:
    (node, arg0, arg1, ...)
*/
PyObject *
make_args_for_attribute_callback(tree node, tree args)
{
    PyObject *list_args = NULL;
    PyObject *py_args = NULL;
    PyObject *py_node = NULL;
    Py_ssize_t i;

    /* Walk "args" (a tree_list), converting to a python list of wrappers */
    list_args = PyGcc_TreeMakeListFromTreeList(args);
    if (!list_args) {
        goto error;
    }

    py_args = PyTuple_New(1 + PyList_Size(list_args));
    if (!py_args) {
        goto error;
    }

    py_node = PyGccTree_New(gcc_private_make_tree(node));
    if (!py_node) {
        goto error;
    }
    PyTuple_SET_ITEM(py_args, 0, py_node);

    for (i = 0; i < PyList_Size(list_args); i++) {
        PyObject *arg = PyList_GetItem(list_args, i);
        Py_INCREF(arg);
        PyTuple_SET_ITEM(py_args, i + 1, arg);
    }
    Py_DECREF(list_args);

    return py_args;

 error:
    Py_XDECREF(list_args);
    Py_XDECREF(py_args);
    Py_XDECREF(py_node);
    return NULL;
}
PyObject *
get_operand_as_object(const_rtx in_rtx, int idx, char fmt)
{
    const char *str;

    /* The operand types are described in gcc/rtl.c */
    switch (fmt) {

    case 'T': /* pointer to a string, with special meaning */
        str = XTMPL (in_rtx, idx);
        goto string;

    case 'S': /* optional pointer to a string */
    case 's': /* a pointer to a string */
        str = XSTR (in_rtx, idx);
    string:
        return PyGccStringOrNone(str);

    case '0': /* unused, or used in a phase-dependent manner */
        Py_RETURN_NONE; /* for now */

    case 'e': /* pointer to an rtl expression */
        /* Nested expression: */
        return PyGccRtl_New(
                   gcc_private_make_rtl_insn(XEXP (in_rtx, idx)));

    case 'E':
    case 'V':
        /* Nested list of expressions */
        {
            PyObject *list = PyList_New(XVECLEN (in_rtx, idx));
            int j;
            if (!list) {
                return NULL;
            }
            for (j = 0; j < XVECLEN (in_rtx, idx); j++) {
                PyObject *item = PyGccRtl_New(
                                     gcc_private_make_rtl_insn(XVECEXP (in_rtx, idx, j)));
                if (!item) {
                    Py_DECREF(list);
                    return NULL;
                }
                if (-1 == PyList_Append(list, item)) {
                    Py_DECREF(item);
                    Py_DECREF(list);
                    return NULL;
                }
                Py_DECREF(item);
            }
            return list;
        }

    case 'w':
        return PyGccInt_FromLong(XWINT (in_rtx, idx));

    case 'i':
        return PyGccInt_FromLong(XINT (in_rtx, idx));

    case 'n':
        /* Return NOTE_INSN names rather than integer codes.  */
        return PyGccStringOrNone(GET_NOTE_INSN_NAME (XINT (in_rtx, idx)));

    case 'u': /* a pointer to another insn */
        Py_RETURN_NONE; /* for now */

    case 't':
        return PyGccTree_New(gcc_private_make_tree(XTREE (in_rtx, idx)));

    case '*':
        Py_RETURN_NONE; /* for now */

    case 'B':
        return PyGccBasicBlock_New(
            gcc_private_make_cfg_block(XBBDEF (in_rtx, idx)));

    default:
        gcc_unreachable ();
    }
}
Пример #6
0
GCC_IMPLEMENT_PUBLIC_API (gcc_tree) gcc_type_get_name (gcc_type node)
{
    return gcc_private_make_tree (TYPE_NAME (node.inner));
}