#=========================================================================
# jal
#=========================================================================

import random

from pymtl import *
from inst_utils import *

#-------------------------------------------------------------------------
# gen_basic_test
#-------------------------------------------------------------------------

def gen_basic_test():
  return """
    # Use r3 to track the control flow pattern
    addi  x3, x0, 0     # 0x0200
                        #
    nop                 # 0x0204
    nop                 # 0x0208
    nop                 # 0x020c
    nop                 # 0x0210
    nop                 # 0x0214
    nop                 # 0x0218
    nop                 # 0x021c
    nop                 # 0x0220
                        #
    jal   x1, label_a   # 0x0224
    addi  x3, x3, 0b01  # 0x0228
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
  label_a:
    addi  x3, x3, 0b10
    # Check the link address
    csrw  proc2mngr, x1 > 0x0228 
    # Only the second bit should be set if jump was taken
    csrw  proc2mngr, x3 > 0b10
  """

def gen_dest_dep_test():
  return """
    # Use r3 to track the control flow pattern
    addi  x3, x0, 0           # 0x0200
                              #
    lui x1,      %hi[label_a] # 0x0204
    addi x1, x1, %lo[label_a] # 0x0208
                              #
    nop                       # 0x020c
    nop                       # 0x0210
    nop                       # 0x0214
    nop                       # 0x0224
    nop                       # 0x0228
                              #
    jalr  x31, x1, 0          # 0x022c
    addi  x3, x3, 1111        # 0x0230
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
  label_a:
    addi  x3, x3, 1111
    # Check the link address
    csrw  proc2mngr, x31 > 0x0224
    # Only the second bit should be set if jump was taken
    csrw  proc2mngr, x3  > 1111
  """


def gen_src_dep_test():
  return """
    # Use r3 to track the control flow pattern
    addi  x3, x0, 0           # 0x0200
                              #
    lui x1,      %hi[label_a] # 0x0204
    addi x1, x1, %lo[label_a] # 0x0208
    jalr  x31, x1, 0          # 0x022c
    addi  x3, x3, 0111        # 0x0230
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
  label_a:
    addi  x3, x3, 0333
    # Check the link address
    csrw  proc2mngr, x31 > 0x0210
    # Only the second bit should be set if jump was taken
    csrw  proc2mngr, x3  > 0333
  """
