Project

General

Profile

Template Description Language » History » Version 139

Andrei Tatarnikov, 06/22/2015 10:03 AM

1 5 Alexander Kamkin
h1. Template Description Language
2 4 Alexander Kamkin
3 97 Andrei Tatarnikov
_~By Artemiy Utekhin and Andrei Tatarnikov~_
4 1 Alexander Kamkin
5 21 Alexander Kamkin
*UNDER CONSTRUCTION*
6
7 6 Alexander Kamkin
{{toc}}
8
9 27 Andrei Tatarnikov
h2. Introduction
10
11 120 Andrei Tatarnikov
MicroTESK generates test programs on the basis of _test templates_ that provide an abstract description of scenarios to be reproduced by the generated programs. Test templates are created using the _test template description language_. It is a _Ruby_-based domain-specific language that provides facilities to describe test cases using symbolic names (that refer to a set of data satisfying certain conditions) instead of concrete input data and to manage the structure of the generated test programs. The language is implemented as a library that includes functionality for describing test templates and for further processing these test templates to produce a test program. MicroTESK uses the JRuby interpreter to process Ruby files. This allows Ruby libraries to interact with other components of MicroTESK written in Java.
12 1 Alexander Kamkin
13 45 Andrei Tatarnikov
h2. How It Works
14 1 Alexander Kamkin
15 121 Andrei Tatarnikov
A test template in Ruby describes a test program in terms of the model of the target microprocessor ISA. The structure of the test program is described using built-in features of Ruby (conditions, loops, etc.) and facilities provided by MicroTESK libraries (blocks that help organize instruction sequences). To provide access to elements of the model such as instructions and their addressing modes, corresponding Ruby methods are created at runtime on the basis on the meta-information provided by the model. The test template subsystem interacts with the model and the testing library of MicroTESK to create a symbolic test program, simulate it on the model and generate its textual representation. Generally speaking, processing of a test template is performed in the following steps:
16 46 Andrei Tatarnikov
17 101 Andrei Tatarnikov
* The model of the microprocessor is loaded;
18
* Runtime methods to access architecture-specific elements are created on the basis of the model''s meta-information;
19 121 Andrei Tatarnikov
* The code of the test template is executed to build the internal representation of the template described as a hierarchy of code blocks;
20
* Blocks are processed bottom-up to produce sequences of abstract instruction calls (at this step, their arguments can be described as a set of conditions instead of being assigned concrete values);
21 101 Andrei Tatarnikov
* A symbolic test program is built on the basis of the produced abstract instruction call sequences by applying corresponding algorithms to find values satisfying the specified conditions;
22
* The symbolic test program is simulated on the microprocessor model;
23
* The code of the test program is generated and saved to the output file.
24 1 Alexander Kamkin
25 3 Artemiy Utekhin
h2. Configuration
26 1 Alexander Kamkin
27 93 Andrei Tatarnikov
Global settings for the test template subsystem are specified in the <code>config.rb</code> file. These settings are related to the package structure and dependencies of the subsystem. They are predefined and rarely need to be modified. Also, there are local settings that control processing of individual test templates. They are specified as member variables of the <code>Template</code> class. Test templates can override them to customize the behavior of the subsystem. The settings will be discussed in more detail in the "Writing Test Templates" section.
28 1 Alexander Kamkin
29 35 Andrei Tatarnikov
h2. Running Test Program Generation
30 1 Alexander Kamkin
31 33 Andrei Tatarnikov
To start test program generation, a user needs to run the <code>generate.sh</code> script (Unix, Linux, OS X) or the <code>generate.bat</code> script (Windows) located in the <code>bin</code> folder. The script launches a Ruby program that processes the specified test template and produces a test program. The command to run the script has the following format: 
32 1 Alexander Kamkin
33
<pre>generate <model name> <template file.rb> [<output file.asm>]</pre>
34 7 Artemiy Utekhin
35 104 Andrei Tatarnikov
There are three parameters: (1) the name of the microprocessor model (generated by the [[Sim-nML Translator]] on the basis of Sim-nML specifications), (2) the name of the test template file to be processed and (3) the name of the test program file to be generated (optional, if it is skipped the program is printed to the console). For example, the following command processes the <code>example.rb</code> test template and saves the generated test program to the <code>test.asm</code> file:
36 7 Artemiy Utekhin
37 99 Andrei Tatarnikov
<pre>sh bin/generate.sh cpu arch/demo/cpu/templates/example.rb test.asm</pre>
38 1 Alexander Kamkin
39 56 Andrei Tatarnikov
h2. Writing Test Templates
40
41 57 Andrei Tatarnikov
h3. Test Template Structure
42
43 122 Andrei Tatarnikov
A test template is implemented as a class inherited from the <code>Template</code> library class that provides access to all features of the library. Information on the location of the <code>Template</code> class is stored in the <code>TEMPLATE</code> environment variable. So, the definition of a test template class looks like this:
44 57 Andrei Tatarnikov
45
<pre><code class="ruby">
46
require ENV[''TEMPLATE'']
47
48
class MyTemplate < Template</code></pre>
49 1 Alexander Kamkin
50 96 Andrei Tatarnikov
Test template classes should contain implementations of the following methods:
51 58 Andrei Tatarnikov
52 109 Andrei Tatarnikov
# <code>initialize</code> (optional) - specifies settings for the given test template;
53 105 Andrei Tatarnikov
# <code>pre</code> (optional) - specifies the initialization code for the test program;
54
# <code>post</code> (optional) - specifies the finalization code for the test program;
55
# <code>run</code> - specifies the main code of the test program (test cases).
56 58 Andrei Tatarnikov
57 63 Andrei Tatarnikov
The definitions of optional methods can be skipped. In this case, the default implementations provided by the parent class will be used. The default implementation of the <code>initialize</code> method initializes the settings with default values. The default implementations of the <code>pre</code> and <code>post</code> methods do nothing.
58
59 64 Andrei Tatarnikov
The full interface of a test template looks as follows:
60 60 Andrei Tatarnikov
61
<pre><code class="ruby">require ENV[''TEMPLATE'']
62
63
class MyTemplate < Template
64
65
  def initialize
66
    super
67
    # Initialize settings here 
68
  end
69
70
  def pre
71
    # Place your initialization code here
72
  end
73
74
  def post
75
    # Place your finalization code here
76
  end
77
78
  def run
79
    # Place your test problem description here
80
  end
81
82 61 Andrei Tatarnikov
end</code></pre>
83 57 Andrei Tatarnikov
84 65 Andrei Tatarnikov
h3. Reusing Test Templates
85
86 70 Andrei Tatarnikov
It is possible to reuse code of existing test templates in other test templates. To do this, you need to subclass the template you want to reuse instead of the <code>Template</code> class. For example, the <code>MyTemplate</code> class below reuses code from the <code>MyPrepost</code> class that provides initialization and finalization code for similar test templates.
87 68 Andrei Tatarnikov
88
<pre><code class="ruby">require ENV[''TEMPLATE'']
89
require_relative ''MyPrepost''
90
91 71 Andrei Tatarnikov
class MyTemplate < MyPrepost
92
93
  def run
94
  ... 
95
  end
96
97
end</code></pre>
98 68 Andrei Tatarnikov
99 74 Andrei Tatarnikov
h3. Test Template Settings
100
101 78 Andrei Tatarnikov
Test templates use the following settings:
102
103
# Starting characters for single-line comments in the test program;
104 1 Alexander Kamkin
# Starting characters for multi-line comments in the test program;
105 107 Andrei Tatarnikov
# Terminating characters for multi-line comments in the test program;
106 137 Andrei Tatarnikov
# Indentation token;
107
# Token used in separator lines.
108 78 Andrei Tatarnikov
109 79 Andrei Tatarnikov
Here is how these settings are initialized with default values in the <code>Template</code> class:
110 75 Andrei Tatarnikov
111 106 Andrei Tatarnikov
<pre><code class="ruby">
112 138 Andrei Tatarnikov
@sl_comment_starts_with = "//"
113 1 Alexander Kamkin
@ml_comment_starts_with = "/*"
114 106 Andrei Tatarnikov
@ml_comment_ends_with   = "*/"
115 137 Andrei Tatarnikov
116
@indent_token    = "\t"
117
@separator_token = "="
118 106 Andrei Tatarnikov
</code></pre>
119 72 Andrei Tatarnikov
120 107 Andrei Tatarnikov
The settings can be overridden in the <code>initialize</code> method of a test template. For example:
121 80 Andrei Tatarnikov
122
<pre><code class="ruby">class MyTemplate < Template
123
124
  def initialize
125
    super
126
    @sl_comment_starts_with = ";" 
127 1 Alexander Kamkin
    @ml_comment_starts_with = "/="
128 137 Andrei Tatarnikov
    @ml_comment_ends_with   = "=/"
129
130
    @indent_token    = "  "
131
    @separator_token = "*" 
132 80 Andrei Tatarnikov
  end
133
  ...
134
end</code></pre>
135
136 111 Andrei Tatarnikov
h3. Data Definitions
137 1 Alexander Kamkin
138 119 Andrei Tatarnikov
Describing data requires the use of assembler-specific directives. Information of these directives in not included in ISA specifications and should be provided in test templates. It includes textual format of data directives and mappings between nML and assembler data types used by these directives. Configuration information on data directives is specified in the <code>data_config</code> block, which is usually placed in the <code>pre</code> method. Only one such block per template is allowed. Here is an example:
139 111 Andrei Tatarnikov
140 110 Andrei Tatarnikov
<pre><code class="ruby">
141
data_config(:text => ''.data'', :target => ''M'', :addressableSize => 8) {
142
  define_type :id => :byte, :text => ''.byte'', :type => type(''card'', 8)
143
  define_type :id => :half, :text => ''.half'', :type => type(''card'', 16)
144
  define_type :id => :word, :text => ''.word'', :type => type(''card'', 32)
145
146
  define_space :id => :space, :text => ''.space'', :fillWith => 0
147
  define_ascii_string :id => :ascii, :text => ''.ascii'', :zeroTerm => false
148
  define_ascii_string :id => :asciiz, :text => ''.asciiz'', :zeroTerm => true
149
}
150 1 Alexander Kamkin
</code></pre>
151 111 Andrei Tatarnikov
152 117 Andrei Tatarnikov
The block takes the following parameters (compulsory):
153 1 Alexander Kamkin
154 117 Andrei Tatarnikov
# _text_ - specifies the keyword that marks the beginning of the data section of the generated test program;
155
# _target_ - specifies the memory array defined in the nML specification to which data will be placed during simulation;
156
# _addressableSize_ - specifies the size (in bits) of addressable memory locations.
157
158 129 Andrei Tatarnikov
To set up particular directives, the language provides special methods that must be called inside the block. All the methods share two common parameters: _id_ and _text_. The first specifies the keyword to be used in a test template to address the directive and the second specifies how it will be printed in the test program. The current version of MicroTESK provides the following methods:
159 117 Andrei Tatarnikov
160 127 Andrei Tatarnikov
# _define_type_ - defines a directive to allocate memory for a data element of an nML data type specified by the _type_ parameter;
161 133 Andrei Tatarnikov
# _define_space_ - defines a directive to allocate memory (one or more addressable locations) filled with a default value specified by the _fillWith_ parameter;
162 127 Andrei Tatarnikov
# _define_ascii_string_ - defines a directive to allocate memory for an ASCII string terminated or not terminated with zero depending on the _zeroTerm_ parameter.
163 117 Andrei Tatarnikov
164 131 Andrei Tatarnikov
The above example defines the directives _byte_, _half_, _word_, _ascii_ (non-zero terminated string) and _asciiz_ (zero terminated string) that place data in the memory array _M_ (specified in nML using the <code>mem</code> keyword). The size of an addressable memory location is 8 bits (or 1 byte).
165 130 Andrei Tatarnikov
166 117 Andrei Tatarnikov
After all data directives are configured, data can be defined using the <code>data</code> block:
167 110 Andrei Tatarnikov
168
<pre><code class="ruby">
169
data {
170
  label :data1
171 134 Andrei Tatarnikov
  byte 1, 2, 3, 4
172 110 Andrei Tatarnikov
173
  label :data2
174
  half 0xDEAD, 0xBEEF
175 1 Alexander Kamkin
176 134 Andrei Tatarnikov
  label :data3
177
  word 0xDEADBEEF
178
179 110 Andrei Tatarnikov
  label :hello
180
  ascii  ''Hello''
181
182
  label :world
183 1 Alexander Kamkin
  asciiz ''World''
184 110 Andrei Tatarnikov
185 134 Andrei Tatarnikov
  space 6
186 110 Andrei Tatarnikov
}
187
</code></pre>
188
189 135 Andrei Tatarnikov
In this example, data is placed into memory. Data items are aligned by their size (1 byte, 2 bytes, 4 bytes). Strings are allocated at the byte border (addressable unit). For simplicity, in the current version of MicroTESK, memory is allocated starting from the address 0 (in the memory array of the executable model).
190 110 Andrei Tatarnikov
191 135 Andrei Tatarnikov
-----------------------
192 108 Andrei Tatarnikov
193 91 Andrei Tatarnikov
h3. Instruction Calls
194 1 Alexander Kamkin
195 86 Andrei Tatarnikov
The <code>pre</code>, <code>post</code> and <code>run</code> methods of a test template class contain specifications of instruction call sequences. Instruction calls are specified using the *_instruction_* and *_addressing mode_* abstractions. Instructions are self-explanatory, they simply represent target assembler instructions. Every instruction argument is a parameterized addressing mode that explains the meaning of the provided values. For example, an addressing mode can refer to a register, a memory location or hold an immediate value. In other words, an instruction call is an instruction that uses appropriate addressing modes initialized with appropriate values. The format of an instruction call description looks like this:
196 85 Andrei Tatarnikov
197 88 Andrei Tatarnikov
<pre><code class="ruby">instruction addr_mode1(:arg1_1 => value1_1, :arg1_2 => value1_2, ...), addr_mode2(:arg2_1 => value2_1, ...), ...</code></pre>
198 1 Alexander Kamkin
199 89 Andrei Tatarnikov
This format implies that addressing modes are parameterized with hash tables where they key is in the name of the addressing mode parameter and the value is the value to be assigned to this parameter. Also, there is a shorter format based on methods with a variable number of arguments. In this case, values are expected to come in the same order as corresponding parameter definitions. The shorter format looks like this:
200
201
<pre><code class="ruby">instruction addr_mode1(value1_1, value1_2, ...), addr_mode2(value2_1, ...), ...</code></pre>
202
203 90 Andrei Tatarnikov
The code below demonstrates both approaches:
204
205
<pre><code class="ruby">
206
mov reg(:i => 0), imm(:i => 0xFF) # The use of hash maps
207
mov reg(0), imm(0xFF)             # The use of variable numbers of arguments
208 1 Alexander Kamkin
</code></pre>
209 91 Andrei Tatarnikov
210
h3. Instruction Call Blocks
211
212
213 90 Andrei Tatarnikov
214 20 Alexander Kamkin
h2. *TODO: REWRITE*
215 1 Alexander Kamkin
216 20 Alexander Kamkin
h3. Basic features
217 1 Alexander Kamkin
218 11 Andrei Tatarnikov
The two core abstractions used by MicroTESK parser/simulator and Ruby-TDL are an *instruction* and an *addressing mode*. An instruction is rather self-explanatory, it simply represents a target assembler instruction. Every argument of an instruction is a parametrized *addressing mode* that explains the meaning of the provided values to the simulator. The mode could point to the registers, for instance, or to a specific memory location. It can also denote an immediate value - e.g. a simple integer or a string. Thus, a basic template is effectively a sequence of instructions with parametrized addressing modes as their arguments.
219 1 Alexander Kamkin
220 11 Andrei Tatarnikov
Each template is a class that inherits a basic Template class that provides most of the core Ruby-TDL functionality. So, to write a template you need to subclass Template first:
221 1 Alexander Kamkin
222 20 Alexander Kamkin
<pre><code class="ruby">require_relative "_path-to-the-rubymt-library_/mtruby"
223 1 Alexander Kamkin
224 3 Artemiy Utekhin
class MyTemplate < Template</code></pre>
225 1 Alexander Kamkin
226 10 Andrei Tatarnikov
While processing a template Ruby-TDL calls its %pre%, %run% and %post% methods, loosely meaning the pre-conditions, the main body and the post-conditions. The %pre% method is mostly useful for setup common to many templates, the %post% method will be more important once sequential testing is introduced. Most of the template code is supposed to be in the %run% method. Thus, a template needs to override one or more of these methods, most commonly %run%.
227 1 Alexander Kamkin
228 3 Artemiy Utekhin
To get %pre% and %post% over with, the most common usage of these is to make a special non-executable class and then subclass it with the actual templates:
229
230
<pre><code class="ruby">require_relative "_path-to-the-rubymt-library_/mtruby"
231
232
class MyPrepost < Template
233 1 Alexander Kamkin
  def initialize
234 3 Artemiy Utekhin
    super
235
    @is_executable = no
236
  end
237 1 Alexander Kamkin
238 3 Artemiy Utekhin
  def pre
239
    # Your ''startup'' code goes here
240
  end
241 9 Andrei Tatarnikov
242 1 Alexander Kamkin
  def post
243 11 Andrei Tatarnikov
    # Your ''cleanup'' code goes here
244 1 Alexander Kamkin
  end
245 3 Artemiy Utekhin
end</code></pre>
246
247
<pre><code class="ruby">require_relative "_path-to-the-rubymt-library_/mtruby"
248
249
class MyTemplate < MyPrepost
250
  def initialize
251
    super
252
    @is_executable = yes
253
  end
254 11 Andrei Tatarnikov
  
255 1 Alexander Kamkin
  def run
256 3 Artemiy Utekhin
    # Your template code goes here
257 1 Alexander Kamkin
  end
258 16 Andrei Tatarnikov
end</code></pre>
259 1 Alexander Kamkin
260 3 Artemiy Utekhin
These methods essentially contain the instructions. The general instruction format is slightly more intimidating than the native assembler and looks like this:
261 1 Alexander Kamkin
262 16 Andrei Tatarnikov
<pre><code class="ruby">instruction_name addr_mode1(:arg1_1 => value, :arg1_2 => value, ...), addr_mode2(:arg2_1 => value, ...), ...</code></pre>
263 1 Alexander Kamkin
264 3 Artemiy Utekhin
So, for instance, if the simulator has an ADD(MEM(i), MEM(i)|IMM(i)) instruction, it would look like:
265 1 Alexander Kamkin
266 16 Andrei Tatarnikov
<pre><code class="ruby">add mem(:i => 42), imm(:i => 128)</code></pre>
267 3 Artemiy Utekhin
268 8 Artemiy Utekhin
Thankfully, there are shortcuts. If there''s only one argument expected in the addressing mode, you can simply write its value and never have to worry about the argument name. And, by convention, the immediate values are always denoted in the simulator as the IMM addressing mode, so the template parser automatically accepts numbers and strings as such. Thus, in this case, the instruction can be simplified to:
269
270 16 Andrei Tatarnikov
<pre><code class="ruby">add mem(42), 128</code></pre>
271 8 Artemiy Utekhin
272 3 Artemiy Utekhin
As a matter of fact, if you''re sure about the order of addressing mode arguments, you can omit the names altogether and simply provide the values:
273
274
<pre><code class="ruby">instruction_name addr_mode1(value1, value2, ...) ...</code></pre>
275
276
If the name of the instruction conflicts with an already existing Ruby method, the instruction will be available with an %op_% prefix before its name.
277
278
h3. Test situations
279
280
_This section is to be taken with a grain of salt because the logic and the interface behind the situations is not yet finalized and mostly missing from the templates and shouldn''t be used yet_
281
282 17 Andrei Tatarnikov
_Big TODO: define what is a test situation_
283 3 Artemiy Utekhin
284
To denote a test situation, add a Ruby block that describes situations to an instruction, this will loosely look like this (likely similar to the way the addressing modes are denoted):
285
286
<pre><code class="ruby">sub mem(42), mem(21) do overflow(:op1 => 123, :op2 => 456) end</code></pre>
287
288 12 Andrei Tatarnikov
h3. Instruction blocks
289 3 Artemiy Utekhin
290
Sometimes a certain test situation should influence more than just one instruction. In that case, you can pass the instructions in an atomic block that can optionally accept a Proc of situations as its argument (because Ruby doesn''t want to be nice and allow multiple blocks for a method, and passing a Hash of Proc can hardly be called comfortable).
291
292
<pre><code class="ruby">p = lambda { overflow(:op1 => 123, :op2 => 456) }
293
294 12 Andrei Tatarnikov
atomic p {
295 3 Artemiy Utekhin
  mov mem(25), mem(26)
296 25 Andrei Tatarnikov
  add mem(27), 28
297 3 Artemiy Utekhin
  sub mem(29), 30
298 24 Andrei Tatarnikov
}</code></pre>
299
300
h3. Groups and random selections _(N.B. REMOVED in r1923. The implementation does not work in the current build and, therefore, was removed. The described features must be reviewed and reimplemented if required.)_
301
302
From source code comments:
303
304
<pre>
305
# VERY UNTESTED leftovers from the previous version ("V2", this is V3)
306
# Should work with the applied fixes but I''d be very careful to use these
307
308 3 Artemiy Utekhin
# As things stand this is just a little discrete probability utility that
309
# may or may not find its way into the potential ruby part of the test engine
310
</pre>
311
312 17 Andrei Tatarnikov
There are certain ways to group together or randomize addressing modes and instructions.
313 3 Artemiy Utekhin
314
To group several addressing modes together (this only works if they have similar arguments) create a mode group like this:
315
316 17 Andrei Tatarnikov
<pre><code class="ruby">mode_group "my_group" [:mem, :imm]</code></pre>
317 3 Artemiy Utekhin
318
You can also set weights to each of the modes in the group like this:
319
320 17 Andrei Tatarnikov
<pre><code class="ruby">mode_group "my_group" {:mem => 1.5, :imm => 2.5}</code></pre>
321 3 Artemiy Utekhin
322
The name of the group is converted into a method in the Template class. To select a random mode from a group, use %sample% on this generated method:
323
324
<pre><code class="ruby">add mem(42), my_group.sample(21)</code></pre>
325
326 17 Andrei Tatarnikov
_TODO: sampling already parametrized modes_
327 3 Artemiy Utekhin
328 17 Andrei Tatarnikov
The first method of grouping instructions works in a similar manner with the same restrictions on arguments:
329 3 Artemiy Utekhin
330 17 Andrei Tatarnikov
<pre><code class="ruby">group "i_group" [:add, :sub]</code></pre>
331 3 Artemiy Utekhin
332
<pre><code class="ruby">group "i_group" {:add => 0.3, :sub => 0.7]</code></pre>
333
334 17 Andrei Tatarnikov
<pre><code class="ruby">i_group.sample mem(42), 21</code></pre>
335 3 Artemiy Utekhin
336
You can also run all of the instructions in a group at once by using the %all% method:
337
338 17 Andrei Tatarnikov
<pre><code class="ruby">i_group.all mem(42), 21</code></pre>
339 3 Artemiy Utekhin
340
The second one allows you to create a normal block of instructions, setting their arguments separately. 
341
342 17 Andrei Tatarnikov
<pre><code class="ruby">block_group "b_group" do
343 3 Artemiy Utekhin
  mov mem(25), mem(26)
344
  add mem(27), 28
345
  sub mem(29), 30
346 17 Andrei Tatarnikov
end</code></pre>
347 3 Artemiy Utekhin
348
In this case to set weights you should call a %prob% method before every instruction:
349
350
<pre><code class="ruby">block_group "b_group" do
351
  prob 0.1
352
  mov mem(25), mem(26)
353 17 Andrei Tatarnikov
  prob 0.7
354 3 Artemiy Utekhin
  add mem(27), 28
355
  prob 0.4
356
  sub mem(29), 30
357 18 Andrei Tatarnikov
end</code></pre>
358
359 3 Artemiy Utekhin
The usage is almost identical, but without providing the arguments as they are already set:
360
361
<pre><code class="ruby">b_group.sample
362
b_group.all</code></pre>
363
364
_Not sure how does it work inside atomics when the group is defined outside, needs more consideration_
365 8 Artemiy Utekhin
366
_TODO: Permutations_
367
368
Any normal Ruby code is allowed inside the blocks as well as the %run%-type methods, letting you write more complex or inter-dependent templates.
369
370 18 Andrei Tatarnikov
h3. TODO: Labels
371 8 Artemiy Utekhin
372
To set a label write:
373
374 18 Andrei Tatarnikov
<pre><code class="ruby">label :label_name</code></pre>
375 8 Artemiy Utekhin
376
To use a label in an instruction that accepts one (under the hood it''s just a simple immediate #IMM value - just not a pre-defined one until it''s actually defined):
377
378
<pre><code class="ruby">b greaterThan, :label_name</code></pre>
379
380 15 Andrei Tatarnikov
h3. TODO: Debug
381 8 Artemiy Utekhin
382
To get a value from registers use:
383
384
<pre><code class="ruby">get_reg_value("register_name", index)</code></pre>
385
386 15 Andrei Tatarnikov
Right now the pre-processing and the execution of instructions are separated due to ambiguous logic regarding labels and various blocks and atomics. This may be changed later, so these special debugging blocks might become unnecessary. By default what''s written in the template is run during pre-processing so you have to use special blocks if you want to run some Ruby code during the execution stage, most likely some debugging.
387 8 Artemiy Utekhin
388 15 Andrei Tatarnikov
To print some debug in the console during the execution of the instructions use the exec_debug block:
389 8 Artemiy Utekhin
390
<pre><code class="ruby">exec_debug {
391
  puts "R0: " + get_reg_value("GPR", 0).to_s + ", R1: " + get_reg_value("GPR", 1).to_s# + ", label code: " + self.send("cycle" + ind.to_s).to_s
392 14 Andrei Tatarnikov
}</code></pre>
393 8 Artemiy Utekhin
394 13 Andrei Tatarnikov
To save something that depends on the current state of the simulator to the resulting assembler code use exec_output that should return a string:
395 1 Alexander Kamkin
396
<pre><code class="ruby">exec_output {
397
  "// The result should be " + self.get_reg_value("GPR", 0).to_s
398
}</code></pre>