# Lib.LinearCode module

CAP, CodeGeneration, LinearCode API Classes for a RiscV linear code.

class Lib.LinearCode.LinearCode(name: str)

  Bases: `object`

  Representation of a RiscV program as a list of instructions.

  `add_instruction()` is repeatedly called in the codegen visitor to build a complete list of RiscV instructions for the source program.

  The `fdata` member variable contains some meta-information on the program, for instance to allocate a new temporary. See `Lib.FunctionData.FunctionData`.

  For debugging purposes, `print_code()` allows to print the RiscV program to a file.

  fdata: FunctionData
  add_instruction(i: Lib.Statement.Comment | Lib.Statement.Label | Lib.Statement.Instru3A | Lib.Statement.AbsoluteJump | Lib.Statement.ConditionalJump ) → None

    Utility function to add an instruction in the program.

    See also `Lib.RiscV` to generate relevant instructions.

  iter_statements(f) → None

    Iterate over instructions. For each real instruction i (not label or comment), replace it with the list of instructions given by f(i).

  get_instructions() → List[ Lib.Statement.Comment | Lib.Statement.Label | Lib.Statement.Instru3A | Lib.Statement.AbsoluteJump | Lib.Statement.ConditionalJump ]

    Return the list of instructions of the program.

  add_label(s: Label ) → None

    Add a label in the program.

  add_comment(s: str) → None

    Add a comment in the program.

  add_instruction_PRINTLN_INT(reg: DataLocation ) → None

    Print integer value, with newline. (see Expand)

  print_code(output, comment=None) → None

    Outputs the RiscV program as text to a file at the given path.

  print_dot(filename: str, DF=None, view=False) → None

    Outputs the RiscV program as graph to a file at the given path.