qat.experimental.frontend.importer.environment module

class EnvironmentTracker

Bases: Generic[_AttributeType]

Models an environment to track named variables and their current SSA values.

This is not designed to support stacked environments or deal with phi nodes; it is intended to support simple linear programs that translate a linear list of operations, but has scope for generalisations in the future.

This is a simple wrapper around a bidict that provides a more convenient interface for looking up and setting variables by name. It encapsulates the responsibility of tracking SSA values without exposing the underlying implementation.

get_by_name(name, default=None)

Get the current SSA value for a variable by name.

Parameters:
  • name (str) – The name of the variable to look up.

  • default (Optional[SSAValue[TypeVar(_AttributeType, bound= Attribute)]]) – The default value to return if the variable is not found.

Return type:

Optional[SSAValue[TypeVar(_AttributeType, bound= Attribute)]]

Returns:

The current SSA value for the variable, or default when the name is not present.

items()

Returns name and value pairs.

set_by_name(name, value)

Set the current SSA value for a variable by name.

Parameters:
  • name (str) – The name of the variable to set.

  • value (SSAValue[TypeVar(_AttributeType, bound= Attribute)]) – The SSA value to associate with the variable.

Return type:

None

set_by_value(value, new_value)

Set the current SSA value for a variable by value.

Parameters:
  • value (SSAValue[TypeVar(_AttributeType, bound= Attribute)]) – The SSA value to associate with the variable.

  • new_value (SSAValue[TypeVar(_AttributeType, bound= Attribute)]) – The new SSA value to associate with the variable.

Return type:

None