Template Description Language » History » Revision 5

« Previous | Revision 5/139 (diff) | Next »
Alexander Kamkin, 03/07/2013 08:11 AM

Template Description Language

By Artemiy Utekhin

Ruby-MT (Ruby for MicroTESK) is a Ruby-based domain specific language geared towards writing compact and reusable tests for microprocessors and other programmable devices. The language intends to look similar to the assembler of the target CPU (TL, Target Language) complemented by higher level features consisting of both standard Ruby and features specific to the Ruby-MT implementation (ML, Meta Language). Ruby-MT, in a sense, is similar to a macro processor - it generates code in the target language based on the provided meta language.

Since Ruby-MT is built as a Ruby library providing an internal DSL no additional parsers are required. Currently, because of the extensive use of Java, Ruby-MT templates can only be executed by the JRuby interpreter. CRuby will probably be supported at a later stage.

The translation process


  1. Receiving model metadata from the simulator;
  2. Template pre-processing;
  3. Constructing commands in the simulator;
  4. Executing commands in the simulator;
  6. Writing the TL output to target files.





Right now there is a simple execution script that requires a template file and an optional output file (if it''s not provided the library uses the standard output to print out the results). To run a template, execute the following command:

jruby parse_templates.rb <template file.rb> [<output file.asm>]

Writing templates

Basic features


Each template is a class that inherits a basic Template class that provides most of the core Ruby-MT functionality. So, to write a template you need to subclass Template first:


class MyTemplate < Template




class MyPrepost < Template
  def initialize
    @is_executable = no

  def pre
    # Your ''startup'' code goes here

  def post
    # Your ''cleanup'' code goes here

class MyTemplate < MyPrepost
  def initialize
    @is_executable = yes

  def run
    # Your template code goes here






 add mem(42), 128 


Test situations


Big TODO: define what is a test situation



Instruction blocks



atomic p {
  mov mem(25), mem(26)
  add mem(27), 28
  sub mem(29), 30

Groups and random selections



 mode_group "my_group" [:mem, :imm] 




 add mem(42), my_group.sample(21) 

TODO: sampling already parametrized modes


 group "i_group" [:add, :sub]
i_group.sample mem(42), 21


i_group.all mem(42), 21


 block_group "b_group" do
  mov mem(25), mem(26)
  add mem(27), 28
  sub mem(29), 30


 block_group "b_group" do
  prob 0.1
  mov mem(25), mem(26)
  prob 0.7
  add mem(27), 28
  prob 0.4
  sub mem(29), 30




TODO: Permutations


Updated by Alexander Kamkin over 6 years ago · 5 revisions