visitors package¶
Program representations (ASTs) in Cnerator can be processed / modified before the final generation
of C source code. In order to do that, an introspective instance of the Visitor design pattern can be provided.
If so, the -V
or -Visitors
options should be passed, including and ordered collection of visitors.
In this package you can find different Visitor implementations.
Submodules¶
visitors.fix_ptr_literal module¶
This visitor replaces all the pointer literals with a valid memory address. At code generation, pointers literals are just a 0 memory address. Here, they are replaced with memory addresses of global variables.
-
visitors.fix_ptr_literal.
visit
(node, program=None, function=None, **kwargs)[source]¶ -
visitors.fix_ptr_literal.
visit
(program: core.ast.Program, **kwargs) → core.ast.Program -
visitors.fix_ptr_literal.
visit
(function: core.ast.Function, program: core.ast.Program, **kwargs) → core.ast.Function -
visitors.fix_ptr_literal.
visit
(invocation: core.ast.Invocation, program: core.ast.Program, function: core.ast.Function, **kwargs) → core.ast.Invocation -
visitors.fix_ptr_literal.
visit
(node: core.ast.CastExpression, program: core.ast.Program, function: core.ast.Function, **kwargs) → core.ast.ASTNode -
visitors.fix_ptr_literal.
visit
(node: core.ast.CastExpression, program: core.ast.Program, function: core.ast.Function, **kwargs) → core.ast.ASTNode -
visitors.fix_ptr_literal.
visit
(node: core.ast.CastExpression, program: core.ast.Program, function: core.ast.Function, **kwargs) → core.ast.ASTNode -
visitors.fix_ptr_literal.
visit
(node: core.ast.CastExpression, program: core.ast.Program, function: core.ast.Function, **kwargs) → core.ast.ASTNode -
visitors.fix_ptr_literal.
visit
(node: core.ast.CastExpression, program: core.ast.Program, function: core.ast.Function, **kwargs) → core.ast.ASTNode -
visitors.fix_ptr_literal.
visit
(node: core.ast.CastExpression, program: core.ast.Program, function: core.ast.Function, **kwargs) → core.ast.ASTNode -
visitors.fix_ptr_literal.
visit
(node: core.ast.CastExpression, program: core.ast.Program, function: core.ast.Function, **kwargs) → core.ast.ASTNode -
visitors.fix_ptr_literal.
visit
(node: core.ast.CastExpression, program: core.ast.Program, function: core.ast.Function, **kwargs) → core.ast.ASTNode -
visitors.fix_ptr_literal.
visit
(literal: core.ast.Literal, program: core.ast.Program, function: core.ast.Function, **kwargs) → core.ast.ASTNode -
visitors.fix_ptr_literal.
visit
(node: core.ast.Block, program: core.ast.Program, function: core.ast.Function, **kwargs) -
visitors.fix_ptr_literal.
visit
(node: core.ast.While, program: core.ast.Program, function: core.ast.Function, **kwargs) -
visitors.fix_ptr_literal.
visit
(node: core.ast.While, program: core.ast.Program, function: core.ast.Function, **kwargs) -
visitors.fix_ptr_literal.
visit
(node: core.ast.If, program: core.ast.Program, function: core.ast.Function, **kwargs) -
visitors.fix_ptr_literal.
visit
(node: core.ast.For, program: core.ast.Program, function: core.ast.Function, **kwargs) -
visitors.fix_ptr_literal.
visit
(node: core.ast.Switch, program: core.ast.Program, function: core.ast.Function, **kwargs) -
visitors.fix_ptr_literal.
visit
(node: core.ast.Break, program: core.ast.Program, function: core.ast.Function, **kwargs) → core.ast.ASTNode -
visitors.fix_ptr_literal.
visit
(node: core.ast.Break, program: core.ast.Program, function: core.ast.Function, **kwargs) → core.ast.ASTNode -
visitors.fix_ptr_literal.
visit
(node: core.ast.Break, program: core.ast.Program, function: core.ast.Function, **kwargs) → core.ast.ASTNode
visitors.func_to_proc module¶
Example visitor that replaces the name of functions returning void.
Its name prefix is changed from func
to proc
.
All the invocations are also renamed.
-
visitors.func_to_proc.
visit
(node)[source]¶ -
visitors.func_to_proc.
visit
(program: core.ast.Program) → None -
visitors.func_to_proc.
visit
(function: core.ast.Function) → None -
visitors.func_to_proc.
visit
(invocation: core.ast.Invocation) → None -
visitors.func_to_proc.
visit
(node: core.ast.Block) → None -
visitors.func_to_proc.
visit
(node: core.ast.While) → None -
visitors.func_to_proc.
visit
(node: core.ast.While) → None -
visitors.func_to_proc.
visit
(node: core.ast.If) → None -
visitors.func_to_proc.
visit
(node: core.ast.For) → None -
visitors.func_to_proc.
visit
(node: core.ast.Switch) → None -
visitors.func_to_proc.
visit
(_: core.ast.ASTNode) → None -
visitors.func_to_proc.
visit
(_: core.ast.ASTNode) → None -
visitors.func_to_proc.
visit
(_: core.ast.ASTNode) → None -
visitors.func_to_proc.
visit
(_: core.ast.ASTNode) → None -
visitors.func_to_proc.
visit
(_: core.ast.ASTNode) → None -
visitors.func_to_proc.
visit
(_: core.ast.ASTNode) → None -
visitors.func_to_proc.
visit
(_: core.ast.ASTNode) → None -
visitors.func_to_proc.
visit
(_: core.ast.ASTNode) → None
visitors.function_subs module¶
Visitor to replace the invocations to functions that have been removed with the controlled function
generation functionality (i.e., -f
or --functions
options).
-
visitors.function_subs.
visit
(node, targets: List[str], function: core.ast.Function, is_statement: bool)[source]¶ -
visitors.function_subs.
visit
(program: core.ast.Program, targets: List[str], function: Optional[core.ast.Function] = None, is_statement: bool = True) → core.ast.Program -
visitors.function_subs.
visit
(node: core.ast.Function, targets: List[str], function: core.ast.Function, is_statement: bool) → core.ast.Function -
visitors.function_subs.
visit
(invocation: core.ast.Invocation, targets: List[str], function: core.ast.Function, is_statement: bool) → Optional[core.ast.ASTNode] -
visitors.function_subs.
visit
(node: core.ast.TernaryExpression, targets: List[str], function: core.ast.Function, is_statement: bool) → core.ast.ASTNode -
visitors.function_subs.
visit
(node: core.ast.TernaryExpression, targets: List[str], function: core.ast.Function, is_statement: bool) → core.ast.ASTNode -
visitors.function_subs.
visit
(node: core.ast.TernaryExpression, targets: List[str], function: core.ast.Function, is_statement: bool) → core.ast.ASTNode -
visitors.function_subs.
visit
(node: core.ast.TernaryExpression, targets: List[str], function: core.ast.Function, is_statement: bool) → core.ast.ASTNode -
visitors.function_subs.
visit
(node: core.ast.TernaryExpression, targets: List[str], function: core.ast.Function, is_statement: bool) → core.ast.ASTNode -
visitors.function_subs.
visit
(node: core.ast.TernaryExpression, targets: List[str], function: core.ast.Function, is_statement: bool) → core.ast.ASTNode -
visitors.function_subs.
visit
(node: core.ast.TernaryExpression, targets: List[str], function: core.ast.Function, is_statement: bool) → core.ast.ASTNode -
visitors.function_subs.
visit
(node: core.ast.Block, targets: List[str], function: core.ast.Function, is_statement: bool) → core.ast.Block -
visitors.function_subs.
visit
(node: core.ast.While, targets: List[str], function: core.ast.Function, is_statement: bool) → core.ast.ASTNode -
visitors.function_subs.
visit
(node: core.ast.While, targets: List[str], function: core.ast.Function, is_statement: bool) → core.ast.ASTNode -
visitors.function_subs.
visit
(node: core.ast.If, targets: List[str], function: core.ast.Function, is_statement: bool) → core.ast.If -
visitors.function_subs.
visit
(node: core.ast.For, targets: List[str], function: core.ast.Function, is_statement: bool) → core.ast.For -
visitors.function_subs.
visit
(node: core.ast.Switch, targets: List[str], function: core.ast.Function, is_statement: bool) → core.ast.Switch -
visitors.function_subs.
visit
(node: core.ast.Label, targets: List[str], function: core.ast.Function, is_statement: bool) → core.ast.ASTNode -
visitors.function_subs.
visit
(node: core.ast.Label, targets: List[str], function: core.ast.Function, is_statement: bool) → core.ast.ASTNode -
visitors.function_subs.
visit
(node: core.ast.Label, targets: List[str], function: core.ast.Function, is_statement: bool) → core.ast.ASTNode -
visitors.function_subs.
visit
(node: core.ast.Label, targets: List[str], function: core.ast.Function, is_statement: bool) → core.ast.ASTNode
visitors.return_instrumentation module¶
Example visitor that adds a return label before every expression in a return statement.
The purpose is to identify the binary code used to return from a function.
If the function returns void
, a label and an explicit return function is added at the end of the function.
-
visitors.return_instrumentation.
visit
(node)[source]¶ -
visitors.return_instrumentation.
visit
(program: core.ast.Program) -
visitors.return_instrumentation.
visit
(function: core.ast.Function) -
visitors.return_instrumentation.
visit
(node: core.ast.For) -
visitors.return_instrumentation.
visit
(node: core.ast.For) -
visitors.return_instrumentation.
visit
(node: core.ast.For) -
visitors.return_instrumentation.
visit
(node: core.ast.For) -
visitors.return_instrumentation.
visit
(node: core.ast.If) -
visitors.return_instrumentation.
visit
(node: core.ast.Switch) -
visitors.return_instrumentation.
visit
(statement: core.ast.Label) -
visitors.return_instrumentation.
visit
(statement: core.ast.Label) -
visitors.return_instrumentation.
visit
(statement: core.ast.Label) -
visitors.return_instrumentation.
visit
(statement: core.ast.Label) -
visitors.return_instrumentation.
visit
(statement: core.ast.Label) -
visitors.return_instrumentation.
visit
(statement: core.ast.Label) -
visitors.return_instrumentation.
visit
(statement: core.ast.Label) -
visitors.return_instrumentation.
visit
(statement: core.ast.Label) -
visitors.return_instrumentation.
visit
(statement: core.ast.Label) -
visitors.return_instrumentation.
visit
(statement: core.ast.Label) -
visitors.return_instrumentation.
visit
(statement: core.ast.Label)