# 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.

  add_comment(s: str) → None

    Add a comment in the program.

  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.

  add_instruction_PRINTLN_INT(reg: DataLocation) → None

    Print integer value, with newline. (see Expand)

  add_label(s: Label) → None

    Add a label in the program.

  fdata: FunctionData
  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.

  iter_statements(f) → None

    Iterate over instructions. For each real instruction (not label or comment), call f, which must return either None or a list of instruction. If it returns None, nothing happens. If it returns a list, then the instruction is replaced by this list.

  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.