Documentation

LeanPool.MRiscX.AbstractSyntax.AbstractSyntax

AbstractSyntax #

This module provides core abstract-syntax types of the MRiscX assembly language.

@[reducible, inline]
abbrev Register :

Purpose of this file: This file establishes the syntax of the MRiscX assembly language, encompassing the definition of instructions, labels, registers, memory and machine states. Given that the instructionsMap, labels, registers, and memory are represented as maps, it may be beneficial to review the contents of the file Maps.lean beforehand.

Next we define some Datatypes for the map keys. This is because it makes it easier to understand which map is being processed. Firstly a register, which will hold a value

Equations
Instances For
    @[implicit_reducible]
    Equations
    @[reducible, inline]

    Next, the memory address. This address will point to a certain address in the memory which holds some value

    Equations
    Instances For
      @[reducible, inline]

      The InstructionIndex is a serial number which points to a instruction in the stack

      Equations
      Instances For
        @[reducible, inline]

        The program counter: the index of the instruction currently being executed.

        Equations
        Instances For

          A total map which holds the instructions of a program tied to a unsigned 64-bit integers as InstructionIndex. The default value of this map is the instruction Instr.Panic.

          IM := {uint64_1 ↦ instr_1, uint64_2 ↦ instr_2, ..., uint64_n ↦ instr_n} / default: Instr.IPanic

          Equations
          Instances For
            @[implicit_reducible]
            Equations

            Empty InstructionMap which serves as standard InstructionMap

            Equations
            Instances For

              A partial map LabelMap, which holds all the Labels as key and links these to an unsigned 64-bit integers.

              LM := {l_1 ↦ uint64_1, l_2 ↦ uint64_2, ..., l_n ↦ uint64_n}

              Equations
              Instances For
                @[implicit_reducible]
                Equations
                @[implicit_reducible]
                Equations

                Empty LabelMap which serves as standard LabelMap

                Equations
                Instances For
                  structure Code :

                  The InstructionMap and the LabelMap are combined into a single structure, which is refered as Code.

                  • instructionMap : InstructionMap

                    The instruction map, associating each instruction index with an instruction.

                  • labels : LabelMap

                    The label map, associating each label name with its target index.

                  Instances For

                    A default instance of Code, containing an empty InstructionMap and an empty LabelMap.

                    Equations
                    Instances For

                      Replace the instruction map of a Code with c.

                      Equations
                      Instances For
                        def Code.setLabels (m : Code) (l : LabelMap) :

                        Replace the label map of a Code with l.

                        Equations
                        Instances For

                          Add a list of (name, index) label bindings to a Code.

                          Equations
                          Instances For
                            def Code.addCMap (m : Code) (id : InstructionIndex) (v : Instr) :

                            Insert an instruction v at index id into the instruction map of a Code.

                            Equations
                            Instances For
                              def Code.addLabels (m : Code) (id : String) (v : UInt64) :

                              Insert a label id ↦ v into the label map of a Code.

                              Equations
                              Instances For
                                def Code.addMaps (m : Code) (id_c : InstructionIndex) (v_c : Instr) (id_l : String) (v_l : UInt64) :

                                Insert both an instruction and a label binding into a Code.

                                Equations
                                Instances For

                                  Replace both the instruction map and the label map of a Code.

                                  Equations
                                  Instances For

                                    Look up the target index of a label in a Code.

                                    Equations
                                    Instances For
                                      def Code.getInstrAt (m : Code) (l : UInt64) :

                                      Look up the instruction stored at index l in a Code.

                                      Equations
                                      Instances For

                                        Definiton of the registers R := {r_1 ↦ w_1, … , r_k ↦ w_k}

                                        Equations
                                        Instances For
                                          @[implicit_reducible]
                                          Equations

                                          RegisterMap with default value 0

                                          R := {r_1 ↦ w_1, … , r_k ↦ w_k; 0}

                                          Equations
                                          Instances For

                                            Definiton of the memory M := {m_1 ↦ w_1, … , m_k ↦ w_k}

                                            Equations
                                            Instances For
                                              @[implicit_reducible]
                                              Equations

                                              MemoryMap with default value 0

                                              M := {m_1 ↦ w_1, … , m_k ↦ w_k; 0}

                                              Equations
                                              Instances For