class Template

Constants

FREE
RANDOM
TRY_FREE
TRY_USED
USED

Attributes

template[R]

Public Class Methods

BIASED(free_bias, used_bias) click to toggle source
# File template.rb, line 417
def self.BIASED(free_bias, used_bias)
  mode_allocator('BIASED', :"free-bias" => free_bias, :"used-bias" => used_bias)
end
inherited(subclass) click to toggle source

This method adds every subclass of Template to the list of templates to parse

# File template.rb, line 41
def self.inherited(subclass)
  subclass_file = parse_caller(caller[0])[0]
  puts "Loaded template #{subclass} defined in #{subclass_file}"
  @@template_classes.store subclass, subclass_file
end
mode_allocator(name, attrs = {}) click to toggle source

———————————————————————————————- # Register Allocation Facilities # ———————————————————————————————- #

# File template.rb, line 398
def self.mode_allocator(name, attrs = {})
  java_import Java::Ru.ispras.microtesk.test.engine.allocator.AllocatorBuilder
  builder = AllocatorBuilder.newInstance name

  attrs.each_pair do |key, value|
    builder.setAttribute key.to_s, value.to_s
  end

  builder.build
end
new() click to toggle source
Calls superclass method
# File template.rb, line 31
def initialize
  super
  @situation_manager = SituationManager.new(self)
end
parse_caller(at) click to toggle source

Parses the text of stack entries returned by the “caller” method, which have the following format: <file:line> or <file:line: in `method’>.

# File template.rb, line 49
def self.parse_caller(at)
  if /^(.+?):(\d+)(?::in `(.*)')?/ =~ at
    file   = Regexp.last_match[1]
    line   = Regexp.last_match[2].to_i
    method = Regexp.last_match[3]
    return [file, line, method]
  end
  raise "Failed to parse #{at}."
end
template_classes() click to toggle source
# File template.rb, line 36
def self.template_classes
  @@template_classes
end

Public Instance Methods

_(allocator = nil, attrs = {}) click to toggle source

Creates an object that specifies an unknown immediate value to be used as an argument of a mode or op. A corresponding concrete value must be produced as a result of test data generation for some test situation.

# File template.rb, line 368
def _(allocator = nil, attrs = {})
  if allocator.is_a? Hash and attrs.empty? then
    attrs = allocator
    allocator = nil
  end

  if !attrs.is_a?(Hash)
    raise "#{attrs} is not a Hash."
  end

  retain = attrs[:retain]
  exclude = attrs[:exclude]
  reserved = attrs.has_key?(:reserved) ? attrs[:reserved] : false

  allocator = @default_allocator if allocator.nil?
  @template.newUnknownImmediate(
    get_caller_location, allocator, retain, exclude, reserved)
end
_label() click to toggle source

Creates a placeholder for label to be updated in the process of generation.

# File template.rb, line 390
def _label
  @template.newLazyLabel
end
add_to_header(text) click to toggle source

Adds text to the header of generated files.

# File template.rb, line 570
def add_to_header(text)
  java_import Java::Ru.ispras.microtesk.test.Printer
  Printer.addToHeader text
end
address(*args) click to toggle source
# File template.rb, line 760
def address(*args)
  if args.count != 0 and args.count != 2
    raise "Wrong argument count: #{args.count}. Must be 0 or 2."
  end

  reference = AddressReference.new @template
  if args.count == 2
    reference.bits args[0], args[1]
  else
    reference
  end
end
align(value) click to toggle source
# File template.rb, line 891
def align(value)
  value_in_bytes = alignment_in_bytes(value)
  @template.setAlignment value, value_in_bytes, get_caller_location
end
alignment_in_bytes(n) click to toggle source

By default, align n is interpreted as alignment on 2**n byte border. This behavior can be overridden.

# File template.rb, line 900
def alignment_in_bytes(n)
  2 ** n
end
atomic(attributes = {}, &contents) click to toggle source
# File template.rb, line 134
def atomic(attributes = {}, &contents)
  blockBuilder = @template.beginBlock
  blockBuilder.setWhere get_caller_location

  blockBuilder.setAtomic true
  blockBuilder.setSequence false
  blockBuilder.setIterate false

  set_builder_attributes blockBuilder, attributes
  self.instance_eval &contents

  @template.endBlock
end
block(attributes = {}, &contents) click to toggle source

———————————————————————————————- # Template Description Facilities # ———————————————————————————————- #

# File template.rb, line 106
def block(attributes = {}, &contents)
  blockBuilder = @template.beginBlock
  blockBuilder.setWhere get_caller_location

  blockBuilder.setAtomic false
  blockBuilder.setSequence false
  blockBuilder.setIterate false

  set_builder_attributes blockBuilder, attributes
  self.instance_eval &contents

  @template.endBlock
end
branches(&contents) click to toggle source
# File template.rb, line 170
def branches(&contents)
  set_attributes(:branches => true, &contents)
end
buffer_preparator(attrs, &contents) click to toggle source

———————————————————————————————- # Creating Buffer Preparators # ———————————————————————————————- #

# File template.rb, line 748
def buffer_preparator(attrs, &contents)
  buffer_id = get_attribute attrs, :target
  builder = @template.beginBufferPreparator buffer_id

  if attrs.has_key?(:levels)
    builder.setLevels attrs[:levels]
  end

  self.instance_eval &contents
  @template.endBufferPreparator
end
comment(format, *args) click to toggle source

Adds a comment into the test program (uses sl_comment_starts_with).

# File template.rb, line 513
def comment(format, *args)
  print_format :COMMENT, format, *args
end
comparator(attrs, &contents) click to toggle source
# File template.rb, line 591
def comparator(attrs, &contents)
  create_preparator(true, attrs, &contents)
end
create_preparator(is_comparator, attrs, &contents) click to toggle source
# File template.rb, line 595
def create_preparator(is_comparator, attrs, &contents)
  target = get_attribute attrs, :target

  builder = @template.beginPreparator target.to_s, is_comparator
  builder.setWhere get_caller_location(2)

  name = attrs[:name]
  if !name.nil?
    builder.setName name.to_s
  end

  mask = attrs[:mask]
  if !mask.nil?
    if mask.is_a?(String)
      builder.setMaskValue mask
    elsif mask.is_a?(Array)
      builder.setMaskCollection mask
    else
      raise "Illegal mask type: #{mask}"
    end
  end

  arguments = attrs[:arguments]
  if !arguments.nil?
    if !arguments.is_a?(Hash)
      raise "#{arguments} is not a Hash."
    end

    arguments.each_pair do |name, value|
      if value.is_a?(Integer)
        builder.addArgumentValue name, value
      elsif value.is_a?(Range)
        builder.addArgumentRange name, value.min, value.max
      elsif value.is_a?(Array)
        builder.addArgumentCollection name, value
      else
        raise "Illegal value of #{name} argument: #{value}"
      end
    end
  end

  self.instance_eval &contents
  @template.endPreparator
end
data(attrs = {}, &contents) click to toggle source
# File template.rb, line 851
def data(attrs = {}, &contents)
  if nil == @data_manager
    raise "Data configuration is not defined"
  end

  if attrs.has_key?(:global)
    global = attrs[:global]
  else
    global = false
  end

  if attrs.has_key?(:separate_file)
    separate_file = attrs[:separate_file]
  else
    separate_file = false
  end

  @data_manager.beginData global, separate_file
  @data_manager.instance_eval &contents
  @data_manager.endData
end
data_config(attrs, &contents) click to toggle source

———————————————————————————————- # Data Definition Facilities # ———————————————————————————————- #

# File template.rb, line 830
def data_config(attrs, &contents)
  if nil != @data_manager
    raise "Data configuration is already defined"
  end

  target = get_attribute attrs, :target

  # Default value is 8 bits if other value is not explicitly specified
  addressableSize = attrs.has_key?(:item_size) ? attrs[:item_size] : 8

  @data_manager = new_data_manager self, @template.getDataManager
  @data_manager.beginConfig target, addressableSize

  @data_manager.instance_eval &contents
  @data_manager.endConfig
end
data_source() click to toggle source
# File template.rb, line 724
def data_source
  @template.getDataSource
end
define_method(method_name, &method_body) click to toggle source
# File template.rb, line 74
def define_method(method_name, &method_body)
  method_name = method_name.downcase
  if !Template.method_defined?(method_name)
    Template.send(:define_method, method_name, &method_body)
  else
    puts "Error: Failed to define the #{method_name} method."
  end
end
define_mode_group(name, distribution) click to toggle source

———————————————————————————————- # Defining Groups # ———————————————————————————————- #

# File template.rb, line 456
def define_mode_group(name, distribution)
  if !distribution.is_a?(Dist)
    raise "#{distribution} is not a distribution."
  end

  @template.defineGroup name, distribution.java_object
  TemplateBuilder.define_addressing_mode_group name
end
define_op_group(name, distribution) click to toggle source
# File template.rb, line 465
def define_op_group(name, distribution)
  if !distribution.is_a?(Dist)
    raise "#{distribution} is not a distribution."
  end

  @template.defineGroup name, distribution.java_object
  TemplateBuilder.define_operation_group name
end
dist(*ranges) click to toggle source

Creates an object describing the probability distribution for random generation (biased generation). Methods arguments specify ranges of values with corresponding biases.

# File template.rb, line 291
def dist(*ranges)
  if !ranges.is_a?(Array)
    raise "#{ranges} is not an Array."
  end

  builder = @template.newVariateBuilder
  ranges.each do |range_item|
    if !range_item.is_a?(ValueRange)
      raise "#{range_item} is not a ValueRange."
    end

    value = range_item.value
    bias = range_item.bias

    if value.is_a?(Range)
      min = [value.first, value.last].min
      max = [value.first, value.last].max
      if bias.nil? then
        builder.addInterval min, max
      else
        builder.addInterval min, max, bias
      end
    elsif value.is_a?(Array)
      if bias.nil? then
        builder.addCollection value
      else
        builder.addCollection value, bias
      end
    elsif value.is_a?(Dist)
      if bias.nil? then
        builder.addVariate value.java_object
      else
        builder.addVariate value.java_object, bias
      end
    else
      if bias.nil? then
        builder.addValue value
      else
        builder.addValue value, bias
      end
    end
  end

  Dist.new builder.build
end
end_comment() click to toggle source

Ends a multi-line comment (uses ml_comment_ends_with)

# File template.rb, line 528
def end_comment
  print_format :COMMENT_ML_END, ''
  @is_multiline_comment = false
end
entry(*args) click to toggle source
# File template.rb, line 773
def entry(*args)
  if args.count != 0 and args.count != 2
    raise "Wrong argument count: #{args.count}. Must be 0 or 2."
  end

  reference = BufferEntryReference.new @template
  if args.count == 2
    reference.bits args[0], args[1]
  else
    reference
  end
end
epilogue(&contents) click to toggle source
# File template.rb, line 956
def epilogue(&contents)
  @template.beginEpilogue
  self.instance_eval &contents
  @template.endEpilogue
end
exception_handler(attrs = {}, &contents) click to toggle source

———————————————————————————————- # Exception Handling # ———————————————————————————————- #

# File template.rb, line 800
def exception_handler(attrs = {}, &contents)
  if attrs.has_key?(:id)
    id = attrs[:id]
  else
    id = ''
  end

  builder = @template.beginExceptionHandler id
  if attrs.has_key?(:instance)
    instance = attrs[:instance]
  else
    instance = 0..(get_option_value('instance-number').to_i - 1)
  end

  if instance.is_a?(Range)
    builder.setInstances instance.min, instance.max
  else
    builder.setInstances instance
  end

  exception_handler_object = ExceptionHandler.new self, builder
  exception_handler_object.instance_eval &contents

  @template.endExceptionHandler
end
executed(&contents) click to toggle source
# File template.rb, line 162
def executed(&contents)
  set_attributes(:executed => true, &contents)
end
free_all_allocated_modes(mode) click to toggle source

TODO: Deprecated

# File template.rb, line 432
def free_all_allocated_modes(mode)
  set_free_all mode, true
end
free_allocated_mode(mode) click to toggle source

TODO: Deprecated

# File template.rb, line 427
def free_allocated_mode(mode)
  set_free mode, true
end
generate() click to toggle source

———————————————————————————————- # Generation (Execution and Printing) # ———————————————————————————————- #

# File template.rb, line 1039
def generate
  java_import Java::Ru.ispras.microtesk.test.TestEngine
  engine = TestEngine.getInstance()

  TemplateBuilder.define_runtime_methods engine.getModel.getMetaData
  @template = engine.newTemplate

  @template.beginPreSection
  pre
  @template.endPreSection

  @template.beginPostSection
  post
  @template.endPostSection

  @template.beginMainSection
  run
  @template.endMainSection
end
generate_data(address, label, type, length, method, *flags) click to toggle source

———————————————————————————————- # Generating Data Files # ———————————————————————————————- #

# File template.rb, line 790
def generate_data(address, label, type, length, method, *flags)
  # puts "Generating data file"
  separate_file = if flags.empty? then true else flags[0] end
  @template.generateData address, label, type, length, method, separate_file
end
get_address_of(label) click to toggle source
# File template.rb, line 208
def get_address_of(label)
  @template.getAddressForLabel label.to_s
end
get_caller_location(caller_index = 1) click to toggle source
# File template.rb, line 68
def get_caller_location(caller_index = 1)
  # Parses the caller of this method's caller, so the default index is 1
  caller_info = Template.parse_caller(caller[caller_index])
  @template.where File.basename(caller_info[0]), caller_info[1]
end
get_new_situation(name, attrs, testdata_provider) click to toggle source
# File template.rb, line 220
def get_new_situation(name, attrs, testdata_provider)
  if !attrs.is_a?(Hash)
    raise "attrs (#{attrs}) must be a Hash."
  end

  builder = @template.newSituation name, testdata_provider
  attrs.each_pair do |name, value|
    if value.is_a?(Dist) then
      attr_value = value.java_object
    elsif value.is_a?(Symbol) then
      attr_value = value.to_s
    else
      attr_value = value
    end
    builder.setAttribute name.to_s, attr_value
  end

  builder.build
end
get_option_value(name) click to toggle source
# File template.rb, line 1065
def get_option_value(name)
  java_import Java::Ru.ispras.microtesk.test.TestEngine
  engine = TestEngine.getInstance
  engine.getOptionValue name
end
global_label(name) click to toggle source
# File template.rb, line 192
def global_label(name)
  @template.addLabel name, true
end
index_source() click to toggle source
# File template.rb, line 728
def index_source
  @template.getIndexSource
end
is_rev(id) click to toggle source
# File template.rb, line 1077
def is_rev(id)
  java_import Java::Ru.ispras.microtesk.test.TestEngine
  engine = TestEngine.getInstance
  engine.isRevision id
end
iterate(attributes = {}, &contents) click to toggle source
# File template.rb, line 148
def iterate(attributes = {}, &contents)
  blockBuilder = @template.beginBlock
  blockBuilder.setWhere get_caller_location

  blockBuilder.setAtomic false
  blockBuilder.setSequence false
  blockBuilder.setIterate true

  set_builder_attributes blockBuilder, attributes
  self.instance_eval &contents

  @template.endBlock
end
label(name) click to toggle source
# File template.rb, line 181
def label(name)
  if name.is_a?(Integer)
    if !name.between?(0, 9)
      raise "#{name} is must be within the range 0..9."
    end
    @template.addNumericLabel name
  else
    @template.addLabel name.to_s, false
  end
end
label_b(index) click to toggle source
# File template.rb, line 200
def label_b(index)
  numeric_label_ref index, false
end
label_f(index) click to toggle source
# File template.rb, line 204
def label_f(index)
  numeric_label_ref index, true
end
location(name, index) click to toggle source

Creates a location-based format argument for format-like output methods.

# File template.rb, line 481
def location(name, index)
  Location.new name, index
end
memory_object(attrs) click to toggle source

———————————————————————————————- # Memory Objects # ———————————————————————————————- #

# File template.rb, line 966
def memory_object(attrs)
  size = get_attribute attrs, :size
  builder = @template.newMemoryObjectBuilder size

  va = get_attribute attrs, :va
  is_va_label = false

  if va.is_a?(Integer)
    builder.setVa va
  elsif va.is_a?(Range)
    builder.setVa va.min, va.max
  elsif va.is_a?(String) or va.is_a?(Symbol)
    builder.setVa va.to_s
    is_va_label = true
  else
    raise "The 'va' attribute has unsupported type #{va.class}."
  end

  if !is_va_label
    pa = get_attribute attrs, :pa
    if pa.is_a?(Integer)
      builder.setPa pa
    elsif pa.is_a?(Range)
      builder.setPa pa.min, pa.max
    elsif pa.is_a?(String) or pa.is_a?(Symbol)
      builder.setPa pa.to_s
    else
      raise "The 'pa' attribute has unsupported type #{pa.class}."
    end
  end

  if attrs.has_key?(:name)
    builder.setName attrs[:name].to_s
  end

  if attrs.has_key?(:mode)
    builder.setMode attrs[:mode].to_s
  end

  if attrs.has_key?(:data)
    builder.setData attrs[:data]
  end

  builder.build
end
memory_preparator(attrs, &contents) click to toggle source

uses address and data

# File template.rb, line 701
def memory_preparator(attrs, &contents)
  size = get_attribute attrs, :size
  builder = @template.beginMemoryPreparator size
  self.instance_eval &contents
  @template.endMemoryPreparator
end
method_missing(meth, *args, &block) click to toggle source

Hack to allow limited use of capslocked characters

Calls superclass method
# File template.rb, line 60
def method_missing(meth, *args, &block)
  if self.respond_to?(meth.to_s.downcase)
    self.send meth.to_s.downcase.to_sym, *args, &block
  else
    super
  end
end
new_data_manager(template, manager) click to toggle source
# File template.rb, line 847
def new_data_manager(template, manager)
  DataManager.new(self, @template.getDataManager)
end
newline() click to toggle source

Adds the new line character into the test program

# File template.rb, line 495
def newline
  text ''
end
nonexecuted(&contents) click to toggle source
# File template.rb, line 166
def nonexecuted(&contents)
  set_attributes(:executed => false, &contents)
end
org(origin) click to toggle source

———————————————————————————————- # Code Allocation Facilities # ———————————————————————————————- #

# File template.rb, line 877
def org(origin)
  if origin.is_a?(Integer)
    @template.setOrigin origin, get_caller_location
  elsif origin.is_a?(Hash)
    delta = get_attribute origin, :delta
    if !delta.is_a?(Integer)
      raise "delta (#{delta}) must be an Integer."
    end
    @template.setRelativeOrigin delta, get_caller_location
  else
    raise "origin (#{origin}) must be an Integer or a Hash."
  end
end
page_table(attrs = {}, &contents) click to toggle source
# File template.rb, line 1012
def page_table(attrs = {}, &contents)
  if nil == @data_manager
    raise "Data configuration is not defined"
  end

  if attrs.has_key?(:global)
    global = attrs[:global]
  else
    global = false
  end

  if attrs.has_key?(:separate_file)
    separate_file = attrs[:separate_file]
  else
    separate_file = false
  end

  @data_manager.beginData global, separate_file
  page_table = PageTable.new self, @data_manager
  page_table.instance_eval &contents
  @data_manager.endData
end
post() click to toggle source

Post-condition instructions template

# File template.rb, line 98
def post

end
pre() click to toggle source

Pre-condition instructions template

# File template.rb, line 88
def pre

end
preparator(attrs, &contents) click to toggle source

———————————————————————————————- # Creating Preparators and Comparators # ———————————————————————————————- #

# File template.rb, line 587
def preparator(attrs, &contents)
  create_preparator(false, attrs, &contents)
end
prepare(target_mode, value_object, attrs = {}) click to toggle source
# File template.rb, line 681
def prepare(target_mode, value_object, attrs = {})
  preparator_name = attrs[:name]
  if !preparator_name.nil?
    preparator_name = preparator_name.to_s
  end

  variant_name = attrs[:variant]
  if !variant_name.nil?
    variant_name = variant_name.to_s
  end

  value_object = value_object.java_object if value_object.is_a? WrappedObject
  @template.addPreparatorCall target_mode, value_object, preparator_name, variant_name
end
print_format(kind, format, *args) click to toggle source

Prints a format-based output to the simulator log or to the test program depending of the is_runtime flag.

prologue(&contents) click to toggle source

———————————————————————————————- # Test-Case-Level Prologue and Epilogue # ———————————————————————————————- #

# File template.rb, line 950
def prologue(&contents)
  @template.beginPrologue
  self.instance_eval &contents
  @template.endPrologue
end
pseudo(text) click to toggle source

Creates a pseudo instruction call that prints user-specified text.

# File template.rb, line 562
def pseudo(text)
  @template.setCallText text
  @template.endBuildingCall
end
rand(*args) click to toggle source

Creates an object for generating a random integer (to be used as an argument of a mode or op) selected from the specified range or according to the specified distribution.

# File template.rb, line 263
def rand(*args)
  if args.count == 1
    distribution = args.at(0)

    if !distribution.is_a?(Dist)
      raise "the argument must be a distribution."
    end

    @template.newRandom distribution.java_object
  elsif args.count == 2
    from = args.at(0)
    to = args.at(1)

    if !from.is_a?(Integer) or !to.is_a?(Integer)
      raise "the arguments must be integers."
    end

    @template.newRandom from, to
  else
    raise "Wrong argument count: #{args.count}. Must be 1 or 2."
  end
end
random_situation(dist) click to toggle source
# File template.rb, line 240
def random_situation(dist)
  dist.java_object
end
range(attrs = {}) click to toggle source

Creates an object describing a value range (with corresponding bias) used in random generation. If the bias attribute is not specified, it will be set to nil, which means the default bias.

# File template.rb, line 342
def range(attrs = {})
  if !attrs.is_a?(Hash)
    raise "#{attrs} is not a Hash."
  end

  if !attrs.has_key?(:value)
    raise "The :value attribute is not specified in #{attrs}."
  end
  value = attrs[:value]

  bias = nil
  if attrs.has_key?(:bias)
    bias = attrs[:bias]
    if !bias.is_a?(Integer)
      raise "#{bias} is not an Integer."
    end
  end

  ValueRange.new value, bias
end
rev_id() click to toggle source
# File template.rb, line 1071
def rev_id
  java_import Java::Ru.ispras.microtesk.test.TestEngine
  engine = TestEngine.getInstance
  engine.getModel.getRevisionId
end
run() click to toggle source

Main instructions template

# File template.rb, line 93
def run
  puts "MTRuby: warning: Trying to execute the original Template#run."
end
section(attrs, &contents) click to toggle source

———————————————————————————————- # Sections # ———————————————————————————————- #

# File template.rb, line 908
def section(attrs, &contents)
  name = get_attribute attrs, :name
  prefix = attrs.has_key?(:prefix) ? attrs[:prefix] : ''

  pa   = attrs[:pa]
  va   = attrs[:va]
  args = attrs.has_key?(:args) ? attrs[:args] : ''
  file = attrs.has_key?(:file) ? attrs[:file] : false

  @template.beginSection name, prefix, pa, va, args, file
  self.instance_eval &contents
  @template.endSection
end
section_data(attrs = {}, &contents) click to toggle source
# File template.rb, line 934
def section_data(attrs = {}, &contents)
  prefix = attrs.has_key?(:prefix) ? attrs[:prefix] : ''

  pa   = attrs[:pa]
  va   = attrs[:va]
  args = attrs.has_key?(:args) ? attrs[:args] : ''

  @template.beginSectionData prefix, pa, va, args
  self.instance_eval &contents
  @template.endSection
end
section_text(attrs = {}, &contents) click to toggle source
# File template.rb, line 922
def section_text(attrs = {}, &contents)
  prefix = attrs.has_key?(:prefix) ? attrs[:prefix] : ''

  pa   = attrs[:pa]
  va   = attrs[:va]
  args = attrs.has_key?(:args) ? attrs[:args] : ''

  @template.beginSectionText prefix, pa, va, args
  self.instance_eval &contents
  @template.endSection
end
sequence(attributes = {}, &contents) click to toggle source
# File template.rb, line 120
def sequence(attributes = {}, &contents)
  blockBuilder = @template.beginBlock
  blockBuilder.setWhere get_caller_location

  blockBuilder.setAtomic false
  blockBuilder.setSequence true
  blockBuilder.setIterate false

  set_builder_attributes blockBuilder, attributes
  self.instance_eval &contents

  @template.endBlock
end
set_attributes(attributes, &contents) click to toggle source
# File template.rb, line 174
def set_attributes(attributes, &contents)
  mapBuilder = set_builder_attributes @template.newMapBuilder, attributes
  @template.beginAttibutes mapBuilder
  self.instance_eval &contents
  @template.endAttibutes
end
set_default_allocator(allocator) click to toggle source
# File template.rb, line 436
def set_default_allocator(allocator)
  @default_allocator = allocator
end
set_default_mode_allocator(allocator) click to toggle source

TODO: Deprecated

# File template.rb, line 422
def set_default_mode_allocator(allocator)
  set_default_allocator(allocator)
end
set_default_situation(names, &situations) click to toggle source
# File template.rb, line 244
def set_default_situation(names, &situations)
  if !names.is_a?(String) and !names.is_a?(Array)
    raise "#{names} must be String or Array."
  end

  default_situation = @situation_manager.instance_eval &situations
  if names.is_a?(Array)
    names.each do |name|
      @template.setDefaultSituation name, default_situation
    end
  else
    @template.setDefaultSituation names, default_situation
  end
end
set_free(mode, flag) click to toggle source
# File template.rb, line 440
def set_free(mode, flag)
  @template.addAllocatorAction mode, 'FREE', flag, false
end
set_free_all(mode, flag) click to toggle source
# File template.rb, line 444
def set_free_all(mode, flag)
  @template.addAllocatorAction mode, 'FREE', flag, true
end
set_option_value(name, value) click to toggle source
# File template.rb, line 1059
def set_option_value(name, value)
  java_import Java::Ru.ispras.microtesk.test.TestEngine
  engine = TestEngine.getInstance
  engine.setOptionValue name, value
end
set_reserved(mode, flag) click to toggle source
# File template.rb, line 448
def set_reserved(mode, flag)
  @template.addAllocatorAction mode, 'RESERVED', flag, false
end
sign_extend(value_object, bit_size) click to toggle source

Sign-extends the specified value (currently, supports only LazyValue objects).

# File template.rb, line 668
def sign_extend(value_object, bit_size)
  value_object = value_object.java_object if value_object.is_a? WrappedObject
  value_object.signExtend bit_size
end
situation(name, attrs = {}) click to toggle source
# File template.rb, line 216
def situation(name, attrs = {})
  get_new_situation name, attrs, false
end
start_comment() click to toggle source

Starts a multi-line comment (uses sl_comment_starts_with)

# File template.rb, line 520
def start_comment
  @is_multiline_comment = true
  print_format :COMMENT_ML_START, ''
end
start_label() click to toggle source
# File template.rb, line 732
def start_label
  @template.getStartLabel
end
stream(label, data, index, length) click to toggle source

———————————————————————————————- # Creating Streams # ———————————————————————————————- #

# File template.rb, line 740
def stream(label, data, index, length)
  @template.addStream label.to_s, data, index, length
end
stream_preparator(attrs, &contents) click to toggle source

———————————————————————————————- # Creating Stream Preparators # ———————————————————————————————- #

# File template.rb, line 712
def stream_preparator(attrs, &contents)
  data  = get_attribute attrs, :data_source
  index = get_attribute attrs, :index_source

  @template.beginStreamPreparator data.to_s, index.to_s

  data_stream_object = StreamPreparator.new self, @template
  data_stream_object.instance_eval &contents

  @template.endStreamPreparator
end
target() click to toggle source
# File template.rb, line 649
def target
  @template.getPreparatorTarget
end
testdata(name, attrs = {}) click to toggle source
# File template.rb, line 212
def testdata(name, attrs = {})
  get_new_situation name, attrs, true
end
text(format, *args) click to toggle source

Adds text into the test program.

# File template.rb, line 502
def text(format, *args)
  if @is_multiline_comment
    print_format :COMMENT_ML_BODY, format, *args
  else
    print_format :TEXT, format, *args
  end
end
trace(format, *args) click to toggle source

Prints text into the simulator execution log.

# File template.rb, line 488
def trace(format, *args)
  print_format :TRACE, format, *args
end
value(*args) click to toggle source
# File template.rb, line 653
def value(*args)
  if args.count != 0 and args.count != 2
    raise "Wrong argument count: #{args.count}. Must be 0 or 2."
  end

  if args.count == 2
    @template.newLazy args.at(0), args.at(1)
  else
    @template.newLazy
  end
end
variant(attrs = {}, &contents) click to toggle source
# File template.rb, line 640
def variant(attrs = {}, &contents)
  name = attrs[:name]
  bias = attrs[:bias]

  @template.beginPreparatorVariant name, bias
  self.instance_eval &contents
  @template.endPreparatorVariant
end
weak(name) click to toggle source
# File template.rb, line 196
def weak(name)
  @template.addWeakLabel name
end
zero_extend(value_object, bit_size) click to toggle source

Zero-extends the specified value (currently, supports only LazyValue objects).

# File template.rb, line 676
def zero_extend(value_object, bit_size)
  value_object = value_object.java_object if value_object.is_a? WrappedObject
  value_object.zeroExtend bit_size
end