<?xml version="1.0" encoding="UTF-8"?>
<grammar xmlns="http://relaxng.org/ns/structure/1.0">

  <include href="language_common.rxg" />

  <!-- processor_spec files have extension .pspec -->

  <start>
    <element name="processor_spec">

      <!-- IMPORTANT NOTE:
           If a register is renamed in the register_data section, any
           subsequent reference to that register must use the NEW name.
           Likewise, references before the rename must refer to the OLD
           name.

           Also, references in compiler specs to the registers must use
           the new name, because the compiler specs for a given language
           are loaded after the language is completely loaded.
           -->

      <interleave>

        <optional>
          <ref name="properties_type"/>
        </optional>

        <optional>
          <element name="programcounter">
            <attribute name="register"/>
          </element>
        </optional>
        
        <optional>
          <element name="data_space">
            <attribute name="space"/>
            <optional>
              <attribute name="ptr_wordsize"/>
            </optional>
          </element>
        </optional>

		<zeroOrMore>
		  <element name="inferptrbounds">
		    <oneOrMore>
		      <ref name="range_type"/>
		    </oneOrMore>
		  </element>
		</zeroOrMore>

        <optional>
          <element name="segmented_address">
            <attribute name="space"/>
            <optional>
              <attribute name="type"/>
            </optional>
          </element>
        </optional>

        <zeroOrMore>
          <ref name="segmentop_type"/>
        </zeroOrMore>

        <!-- see language_common.rxg -->
        <optional>
          <element name="context_data">
            <ref name="context_data_type"/>
          </element>
        </optional>

        <optional>
          <element name="volatile">
            <attribute name="inputop"/>
            <attribute name="outputop"/>
            <optional>
              <attribute name="format"/>
              <!-- format="functional" forces functional operator synxtax-->
            </optional>
            <oneOrMore>
              <ref name="memory_tags_type"/>
            </oneOrMore>
          </element>
        </optional>

		<optional>
		  <element name="incidentalcopy">
		    <oneOrMore>
		      <ref name="varnode_tags_type"/>
		    </oneOrMore>
		  </element>
		</optional>

        <zeroOrMore>
          <element name="jumpassist"><ref name="jumpassist_type"/>
          </element>
        </zeroOrMore>
		
        <optional>
          <element name="register_data">
            <oneOrMore>
              <element name="register">
                <attribute name="name"/>
                <optional>
                  <attribute name="rename"/>
                </optional>
                <optional>
                  <attribute name="alias"/>
                </optional>
                <optional>
                  <attribute name="group"/>
                </optional>
                <optional>
                  <attribute name="hidden">
                    <ref name="boolean_type"/>
                  </attribute>
                </optional>
                <optional>
                  <attribute name="volatile">
                    <ref name="boolean_type"/>
                  </attribute>
                </optional>
                <optional>
                  <attribute name="vector_lane_sizes"/>
                </optional>
              </element>
            </oneOrMore>
          </element>
        </optional>

        <optional>
          <element name="default_symbols">
            <oneOrMore>
              <element name="symbol">
                <attribute name="name"/>
                <attribute name="address"/>
                <optional>
                  <attribute name="volatile">
                    <ref name="boolean_type"/>
                  </attribute>
                </optional>
                <optional>
                  <attribute name="size"/>
                </optional>
                <optional>
                  <attribute name="entry">
                    <ref name="boolean_type"/>
                  </attribute>
                </optional>
                <optional>
                  <attribute name="type">
                    <ref name="symbol_type"/>
                  </attribute>
                </optional>
                <optional>
                  <attribute name="description"/>
                </optional>
              </element>

            </oneOrMore>
          </element>
        </optional>

        <optional>
          <element name="default_memory_blocks">
            <oneOrMore>
              <element name="memory_block">
                <attribute name="name"/>
                <attribute name="start_address"/>
                <attribute name="length"/>
                <choice>
                  <attribute name="bit_mapped_address"/>
                  <!--
                     byte_mapped_address - mapped memory address and optional mapping ratio
                     Examples:
                        byte_mapped_address="rom:1000" - maps every byte starting at rom:1000
                        byte_mapped_address="rom:1000/1:2" - maps one byte for every two bytes 
                           starting at rom:1000.  Facilitates skip of padding bytes.
                  -->
                  <attribute name="byte_mapped_address"/>
                  <attribute name="initialized">
                    <ref name="boolean_type"/>
                  </attribute>
                 </choice>
                <optional> <attribute name="mode"/> </optional>
                <optional>
                  <attribute name="overlay">
                    <ref name="boolean_type"/>
                  </attribute>
                </optional>
              </element>
            </oneOrMore>
          </element>
        </optional>
      </interleave>
    </element>
  </start>
</grammar>
