ctree package
Submodules
ctree.analyses module
validation of ast trees
-
exception ctree.analyses.AstValidationError[source]
Bases: exceptions.Exception
Exception for non C nodes in an AST
-
class ctree.analyses.DeclFinder[source]
Bases: ast.NodeVisitor
Returns the first use of a particular symbol.
-
find(node)[source]
look for a declaration of a symbol ref
-
class ctree.analyses.VerifyOnlyCtreeNodes[source]
Bases: ast.NodeVisitor
Checks that every node in the tree is an instance of
ctree.nodes.common.CtreeNode. Raises an exception if a bad node
is found.
-
visit(node)[source]
ctree.codegen module
base class for generating code appropriate to the selected backend
-
class ctree.codegen.CodeGenVisitor(indent=0)[source]
Bases: ast.NodeVisitor
Return a string containing the program text.
ctree.frontend module
helper for getting properly formatted ast from arbitrary python object
-
ctree.frontend.get_ast(obj)[source]
Return the Python ast for the given object, which may
be anything that inspect.getsource accepts (incl.
a module, class, method, function, traceback, frame,
or code object).
ctree.jit module
Just-in-time compilation support.
-
class ctree.jit.ConcreteSpecializedFunction[source]
Bases: object
A function backed by generated code.
-
class ctree.jit.JitModule[source]
Bases: object
Manages compilation of multiple ASTs.
-
get_callable(entry_point_name, entry_point_typesig)[source]
Returns a python callable that dispatches to the requested C function.
-
class ctree.jit.LazySpecializedFunction(py_ast)[source]
Bases: object
A callable object that will produce executable
code just-in-time.
-
args_to_subconfig(args)[source]
Extract features from the arguments to define uniqueness of
this particular invocation. The return value must be a hashable
object, or a dictionary of hashable objects.
-
finalize(tree, program_config)[source]
This function will be passed the result of transform. The specializer
should return an ConcreteSpecializedFunction.
-
get_tuning_driver()[source]
Define the space of possible implementations.
-
report(*args, **kwargs)[source]
Records the performance of the most recent configuration.
-
transform(tree, program_config)[source]
Convert the AST ‘tree’ into a C AST, optionally taking advantage of the
actual runtime arguments.
ctree.precedence module
Utilities for determining precedence in C, with the goal of minimizing the
number of parentheses in the generated code.
-
ctree.precedence.get_precedence(node)[source]
-
ctree.precedence.is_left_associative(node)[source]
ctree.types module
-
ctree.types.codegen_type(ctype)[source]
Unparses the given ctype.
Parameters: | ctype – A ctype type instance to be unparsed. |
-
ctree.types.get_ctype(py_obj)[source]
Given a python object, this routine tries to return the
closest ctype type instance corresponding to that object.
Parameters: | py_obj – A python object. |
-
ctree.types.register_type_codegenerators(codegen_dict)[source]
Registers routines for generating code for types.
Parameters: | codegen_dict – Maps type classes to functions that |
take an instance of that class and return the corresponding
string.
-
ctree.types.register_type_recognizers(typerec_dict)[source]
Registers routines for getting ctypes objects from Python objects.
Parameters: | typerec_dict – Maps Python classes to functions that |
take an instance of that class and return the corresponding
ctypes object.
ctree.util module
-
class ctree.util.Timer[source]
-
ctree.util.enumerate_flatten(obj_or_list)[source]
Iterator for all objects arbitrarily nested in lists.
-
ctree.util.flatten(obj)[source]
Iterator for all objects arbitrarily nested in lists.
-
ctree.util.highlight(code, language='c')[source]
Syntax-highlight code using pygments, if installed.
-
ctree.util.lower_case_underscore_to_camel_case(string)[source]
Convert string or unicode from lower-case underscore to camel-case
-
ctree.util.singleton(cls)[source]
-
ctree.util.truncate(text)[source]
ctree.visitors module
For now, just use visitors defined by Python’s AST library.
Module contents
The ctree package
-
class ctree.Counter[source]
Bases: object
Tracks events, reports counts upon garbage collections.
-
log(event_str)[source]
record a single named event
-
report()[source]
send a counter report of all named events to the log
-
ctree.browser_show_ast(tree, file_name)[source]
convenience method to display an AST in ipython
converts tree in place to a dot format
then renders that into a png file
-
ctree.get_ast(func)[source]
convenience method for displaying a callable objects ast
-
ctree.ipython_show_ast(tree)[source]
convenience method to display an AST in ipython
converts tree in place to a dot format
then renders that into a png file