Services and Modeling for Embedded Software Development
Embecosm divider strip
Prev  Next

4.6. Testing

Tests written for instruction encoding replace any tests written for assembly parsing with those that check for valid encoding. Assembly parsing is implicitly tested as the correct encoding is emitted only if the instruction was correctly parsed.

Each instruction in turn should have its instruction manually encoded based on the instruction set documentation and then tested with llvm-mc and the -show-encoding directive. An example of a test is shown below.

# RUN: llvm-mc -arch=or1k -mattr=mul,div,ror -show-encoding %s | FileCheck %s

    l.add r1, r2, r3
# CHECK: # encoding: [0xe0,0x22,0x18,0x00]
        

The -show-encoding flag will cause llvm-mc to output the encoded version of the provided instruction, which is in the format shown above. Tests can then be executed in the usual way.

To aid in writing these tests, a python function is specified below that takes an instruction encoding and prints out the CHECK line for a 32-bit big-endian processor.

def a(asm):
  asm=hex(asm)[2:].zfill(8)
  print '# CHECK: # encoding: [0x'+asm[-8:-6]+',0x'+asm[-6:-4]+',0x'+ \
  asm[-4:-2]+',0x'+asm[-2:]+']'
        

This function can then be simply used in the same way as this example for the OpenRISC 1000  l.add instruction when in a big endian mode.

a(0x38<<26|1<<21<2<<16|3<<11)
        
Embecosm divider strip