result.py¶
from pymwp import Result
Result defines all information collected about an analyzed program.
FuncLoops
¶
FuncLoops(name: str = None)
Bases: Timeable
, Serializable
Analysis result for a function with loops, when running
loop analysis mode. FuncLoops
captures the results for all loops
inside their parent function.
Attributes:
Name | Type | Description |
---|---|---|
name |
str
|
Containing function name. |
loops |
Dict[str, LoopResult]
|
Function loop analysis results. |
FuncResult
¶
FuncResult(
name: str,
infinite: bool = False,
variables: Optional[List[str]] = None,
relation: Optional[Relation] = None,
choices: Optional[Choices] = None,
bound: Optional[Bound] = None,
inf_flows: Optional[str] = None,
index: int = -1,
func_code: str = None,
)
Bases: Timeable
, Serializable
Analysis results for one function of the input program.
Attributes:
Name | Type | Description |
---|---|---|
name |
str
|
Function name. |
infinite |
bool
|
True if no valid derivation exists. |
variables |
List[str]
|
List of program variables. |
relation |
Relation
|
Relation object; does not |
choices |
Choices
|
A choice vector-object. |
bound |
Bound
|
A bound of mwp-bounds. |
inf_flows |
str
|
Description of problematic flows. |
index |
int
|
Degree of derivation choice. |
func_code |
str
|
Function source code. |
from_dict
staticmethod
¶
from_dict(name: str = None, **kwargs) -> FuncResult
Deserialize a function result.
LoopResult
¶
LoopResult(loop_code: str = None)
Bases: Timeable
, Serializable
Analysis result for one loop.
Attributes:
Name | Type | Description |
---|---|---|
loop_code |
str
|
The analyzed loop. |
variables |
Dict[str, VResult]
|
Results by variable. |
Program
¶
Program(
program_path: str = None,
n_lines: int = -1,
n_func: int = 0,
n_loops: int = 0,
n_func_vars: int = 0,
n_loop_vars: int = 0,
)
Bases: Serializable
Details about analyzed C-language input file.
Attributes:
Name | Type | Description |
---|---|---|
program_path |
str
|
Path to program file. |
n_lines |
int
|
Lines of code in input program. |
n_func |
int
|
Total functions (incl. un-analyzed). |
n_loops |
int
|
Total loops (incl. un-analyzed). |
n_func_vars |
int
|
Total function variables (incl. un-analyzed). |
n_loop_vars |
int
|
Total loop variables (incl. un-analyzed). |
Result
¶
Result()
Bases: Timeable
, Serializable
Captures analysis result and details about the analysis process.
Attributes:
Name | Type | Description |
---|---|---|
program |
Program
|
Information about analyzed C File. |
relations |
Dict[str, FuncResult]
|
Dictionary of function results. |
loops |
Dict[str, FuncLoops]
|
Dictionary of function loop results. |
get_func
¶
get_func(
name: Optional[str] = None,
) -> Union[FuncResult, FuncLoops, Dict[str, FuncResult], Dict[str, FuncLoops]]
Returns analysis result for function(s).
Here "analysis" means either whole-function analysis, or loop analysis, based on executed analysis mode; they cannot co-exist in the same result.
- If
name
argument is provided and key exists, returns a result for exact value match. - If program contained exactly 1 function, returns result for that function.
- Otherwise, returns a dictionary of results for each analyzed
function, as in:
<function_name, analysis_result>
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
Optional[str]
|
Name of function. |
None
|
Returns:
Type | Description |
---|---|
Union[FuncResult, FuncLoops, Dict[str, FuncResult], Dict[str, FuncLoops]]
|
A function analysis result, or a dictionary of results. |
pretty_print
staticmethod
¶
pretty_print(
txt: str, line_w: int = 50, hb: str = "─", color: bool = False
) -> str
Draws a colored box around text before display.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
txt |
str
|
Some text to display. |
required |
line_w |
int
|
Formatted text line width. |
50
|
hb |
str
|
Horizontal bar box-drawing character |
'─'
|
color |
bool
|
Apply color to output |
False
|
Returns:
Type | Description |
---|---|
str
|
Formatted text. |
Serializable
¶
Bases: ABC
General utilities for converting results to JSON-writable objects and vice versa.
from_dict
abstractmethod
staticmethod
¶
from_dict(**kwargs) -> Serializable
Restore object from a dictionary; reverses to_dict()
.
Timeable
¶
Timeable()
Represents an entity whose runtime can be measured.
Attributes:
Name | Type | Description |
---|---|---|
start_time |
int
|
recorded start time. |
end_time |
int
|
recorded end time. |
VResult
¶
VResult(
name: str = None,
is_m: bool = False,
is_w: bool = False,
is_p: bool = False,
bound: MwpBound = None,
choices: Choices = None,
)
Bases: Serializable
Analysis result for a single variable.
Attributes:
Name | Type | Description |
---|---|---|
name |
str
|
Variable name. |
is_m |
bool
|
Has maximal linear bound. |
is_w |
bool
|
Has weak polynomial bound. |
is_p |
bool
|
Has polynomial bound. |
bound |
Optional[MwpBound]
|
A bound (if exists). |
choices |
Optional[Choice]
|
Bound choices. |