• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

nickg / nvc / 20645692657

01 Jan 2026 09:14PM UTC coverage: 92.653% (+0.08%) from 92.573%
20645692657

push

github

nickg
Allocate virtual registers in MIR

Fixes #1259

160 of 161 new or added lines in 9 files covered. (99.38%)

579 existing lines in 12 files now uncovered.

76033 of 82062 relevant lines covered (92.65%)

466822.97 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

98.46
/src/mir/mir-vcode.c
1
//
2
//  Copyright (C) 2024-2025  Nick Gasson
3
//
4
//  This program is free software: you can redistribute it and/or modify
5
//  it under the terms of the GNU General Public License as published by
6
//  the Free Software Foundation, either version 3 of the License, or
7
//  (at your option) any later version.
8
//
9
//  This program is distributed in the hope that it will be useful,
10
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
11
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
//  GNU General Public License for more details.
13
//
14
//  You should have received a copy of the GNU General Public License
15
//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
//
17

18
#include "util.h"
19
#include "hash.h"
20
#include "mir/mir-node.h"
21
#include "mir/mir-unit.h"
22
#include "vcode.h"
23

24
#include <stdlib.h>
25
#include <assert.h>
26
#include <float.h>
27

28
typedef struct {
29
   mir_block_t *blocks;
30
   mir_value_t *map;
31
   mir_value_t *vars;
32
   ihash_t     *types;
33
} mir_import_t;
34

35
static mir_type_t import_type(mir_unit_t *mu, mir_import_t *imp,
823,497✔
36
                              vcode_type_t vtype)
37
{
38
   void *ptr = ihash_get(imp->types, vtype);
823,497✔
39
   if (ptr != NULL)
823,497✔
40
      return (mir_type_t){ .bits = (uintptr_t)ptr };
632,553✔
41

42
   mir_type_t type;
190,944✔
43
   switch (vtype_kind(vtype)) {
190,944✔
44
   case VCODE_TYPE_INT:
82,798✔
45
      type = mir_int_type(mu, vtype_low(vtype), vtype_high(vtype));
82,798✔
46
      break;
82,798✔
47
   case VCODE_TYPE_REAL:
8,273✔
48
      type = mir_real_type(mu, -DBL_MAX, DBL_MAX);
8,273✔
49
      break;
8,273✔
50
   case VCODE_TYPE_OFFSET:
23,386✔
51
      type = mir_offset_type(mu);
23,386✔
52
      break;
23,386✔
53
   case VCODE_TYPE_SIGNAL:
9,088✔
54
      type = mir_signal_type(mu, import_type(mu, imp, vtype_base(vtype)));
9,088✔
55
      break;
9,088✔
56
   case VCODE_TYPE_UARRAY:
13,175✔
57
      type = mir_uarray_type(mu, vtype_dims(vtype),
13,175✔
58
                             import_type(mu, imp, vtype_elem(vtype)));
59
      break;
13,175✔
60
   case VCODE_TYPE_CARRAY:
22,270✔
61
      type = mir_carray_type(mu, vtype_size(vtype),
22,270✔
62
                             import_type(mu, imp, vtype_elem(vtype)));
63
      break;
22,270✔
64
   case VCODE_TYPE_CONTEXT:
12,862✔
65
      type = mir_context_type(mu, vtype_name(vtype));
12,862✔
66
      break;
12,862✔
67
   case VCODE_TYPE_ACCESS:
2,129✔
68
      type = mir_access_type(mu, import_type(mu, imp, vtype_pointed(vtype)));
2,129✔
69
      break;
2,129✔
70
   case VCODE_TYPE_OPAQUE:
685✔
71
      type = mir_opaque_type(mu);
685✔
72
      break;
685✔
73
   case VCODE_TYPE_CLOSURE:
×
74
      {
75
         mir_type_t atype = mir_opaque_type(mu);
×
76
         mir_type_t rtype = import_type(mu, imp, vtype_base(vtype));
×
77
         type = mir_closure_type(mu, atype, rtype);
×
78
      }
79
      break;
×
80
   case VCODE_TYPE_RECORD:
5,689✔
81
      {
82
         const int nfields = vtype_fields(vtype);
5,689✔
83
         mir_type_t *fields LOCAL = xmalloc_array(nfields, sizeof(mir_type_t));
11,378✔
84
         for (int i = 0; i < nfields; i++)
24,615✔
85
            fields[i] = import_type(mu, imp, vtype_field(vtype, i));
18,926✔
86

87
         type = mir_record_type(mu, vtype_name(vtype), fields, nfields);
5,689✔
88
      }
89
      break;
5,689✔
90
   case VCODE_TYPE_POINTER:
6,699✔
91
      type = mir_pointer_type(mu, import_type(mu, imp, vtype_pointed(vtype)));
6,699✔
92
      break;
6,699✔
93
   case VCODE_TYPE_FILE:
985✔
94
      type = mir_file_type(mu, import_type(mu, imp, vtype_base(vtype)));
985✔
95
      break;
985✔
96
   case VCODE_TYPE_CONVERSION:
222✔
97
      type = mir_conversion_type(mu);
222✔
98
      break;
222✔
99
   case VCODE_TYPE_TRIGGER:
84✔
100
      type = mir_trigger_type(mu);
84✔
101
      break;
84✔
102
   case VCODE_TYPE_DEBUG_LOCUS:
55✔
103
      type = mir_locus_type(mu);
55✔
104
      break;
55✔
105
   case VCODE_TYPE_RESOLUTION:
2,544✔
106
      type = mir_resolution_type(mu, import_type(mu, imp, vtype_base(vtype)));
2,544✔
107
      break;
2,544✔
108
   default:
×
109
      vcode_dump();
×
110
      fatal_trace("cannot import type kind %d", vtype_kind(vtype));
111
   }
112

113
   ihash_put(imp->types, vtype, (void *)(uintptr_t)type.bits);
190,944✔
114
   return type;
190,944✔
115
}
116

117
static void import_package_init(mir_unit_t *mu, mir_import_t *imp, int op)
21,787✔
118
{
119
   mir_value_t context = MIR_NULL_VALUE;
21,787✔
120
   if (vcode_count_args(op) > 0)
21,787✔
121
      context = imp->map[vcode_get_arg(op, 0)];
190✔
122

123
   ident_t name = vcode_get_func(op);
21,787✔
124
   imp->map[vcode_get_result(op)] = mir_build_package_init(mu, name, context);
21,787✔
125
}
21,787✔
126

127
static void import_link_package(mir_unit_t *mu, mir_import_t *imp, int op)
6,702✔
128
{
129
   mir_value_t context = mir_build_link_package(mu, vcode_get_ident(op));
6,702✔
130
   imp->map[vcode_get_result(op)] = context;
6,702✔
131
}
6,702✔
132

133
static void import_link_var(mir_unit_t *mu, mir_import_t *imp, int op)
4,851✔
134
{
135
   vcode_reg_t result = vcode_get_result(op);
4,851✔
136
   vcode_type_t vtype = vtype_pointed(vcode_reg_type(result));
4,851✔
137

138
   mir_value_t context = imp->map[vcode_get_arg(op, 0)];
4,851✔
139
   mir_type_t type = import_type(mu, imp, vtype);
4,851✔
140
   ident_t name = vcode_get_ident(op);
4,851✔
141

142
   imp->map[result] = mir_build_link_var(mu, context, name, type);
4,851✔
143
}
4,851✔
144

145
static void import_return(mir_unit_t *mu, mir_import_t *imp, int op)
55,139✔
146
{
147
   mir_value_t result = MIR_NULL_VALUE;
55,139✔
148
   if (vcode_count_args(op) > 0)
55,139✔
149
      result = imp->map[vcode_get_arg(op, 0)];
24,470✔
150

151
   mir_build_return(mu, result);
55,139✔
152
}
55,139✔
153

154
static void import_fcall(mir_unit_t *mu, mir_import_t *imp, int op)
34,176✔
155
{
156
   const int nargs = vcode_count_args(op);
34,176✔
157
   mir_value_t *args LOCAL = xmalloc_array(nargs, sizeof(mir_value_t));
68,352✔
158
   for (int i = 0; i < nargs; i++)
120,222✔
159
      args[i] = imp->map[vcode_get_arg(op, i)];
86,046✔
160

161
   ident_t func = vcode_get_func(op);
34,176✔
162
   vcode_reg_t result = vcode_get_result(op);
34,176✔
163
   if (result == VCODE_INVALID_REG)
34,176✔
164
      mir_build_fcall(mu, func, MIR_NULL_TYPE, MIR_NULL_STAMP, args, nargs);
5,535✔
165
   else {
166
      mir_type_t type = import_type(mu, imp, vcode_reg_type(result));
28,641✔
167
      imp->map[result] = mir_build_fcall(mu, func, type, MIR_NULL_STAMP,
28,641✔
168
                                         args, nargs);
169
   }
170
}
34,176✔
171

172
static void import_pcall(mir_unit_t *mu, mir_import_t *imp, int op)
843✔
173
{
174
   const int nargs = vcode_count_args(op);
843✔
175
   mir_value_t *args LOCAL = xmalloc_array(nargs, sizeof(mir_value_t));
1,686✔
176
   for (int i = 0; i < nargs; i++)
2,845✔
177
      args[i] = imp->map[vcode_get_arg(op, i)];
2,002✔
178

179
   ident_t func = vcode_get_func(op);
843✔
180
   mir_block_t resume = imp->blocks[vcode_get_target(op, 0)];
843✔
181

182
   mir_build_pcall(mu, func, resume, args, nargs);
843✔
183
}
843✔
184

185
static void import_resume(mir_unit_t *mu, mir_import_t *imp, int op)
843✔
186
{
187
   mir_build_resume(mu, vcode_get_func(op));
843✔
188
}
843✔
189

190
static void import_const(mir_unit_t *mu, mir_import_t *imp, int op)
366,915✔
191
{
192
   vcode_reg_t result = vcode_get_result(op);
366,915✔
193
   mir_type_t type = import_type(mu, imp, vcode_reg_type(result));
366,915✔
194
   imp->map[result] = mir_const(mu, type, vcode_get_value(op));
366,915✔
195
}
366,915✔
196

197
static void import_const_real(mir_unit_t *mu, mir_import_t *imp, int op)
22,249✔
198
{
199
   vcode_reg_t result = vcode_get_result(op);
22,249✔
200
   mir_type_t type = import_type(mu, imp, vcode_reg_type(result));
22,249✔
201
   imp->map[result] = mir_const_real(mu, type, vcode_get_real(op));
22,249✔
202
}
22,249✔
203

204
static void import_const_array(mir_unit_t *mu, mir_import_t *imp, int op)
29,890✔
205
{
206
   vcode_reg_t result = vcode_get_result(op);
29,890✔
207
   mir_type_t type = import_type(mu, imp, vcode_reg_type(result));
29,890✔
208

209
   const int nargs = vcode_count_args(op);
29,890✔
210
   mir_value_t *elts LOCAL = xmalloc_array(nargs, sizeof(mir_value_t));
59,780✔
211
   for (int i = 0; i < nargs; i++)
1,679,514✔
212
      elts[i] = imp->map[vcode_get_arg(op, i)];
1,649,624✔
213

214
   imp->map[result] = mir_const_array(mu, type, elts, nargs);
29,890✔
215
}
29,890✔
216

217
static void import_const_rep(mir_unit_t *mu, mir_import_t *imp, int op)
302✔
218
{
219
   vcode_reg_t result = vcode_get_result(op);
302✔
220
   mir_type_t type = import_type(mu, imp, vcode_reg_type(result));
302✔
221
   mir_value_t value = imp->map[vcode_get_arg(op, 0)];
302✔
222
   unsigned count = vcode_get_value(op);
302✔
223

224
   imp->map[result] = mir_build_const_rep(mu, type, value, count);
302✔
225
}
302✔
226

227
static void import_const_record(mir_unit_t *mu, mir_import_t *imp, int op)
2,050✔
228
{
229
   vcode_reg_t result = vcode_get_result(op);
2,050✔
230
   mir_type_t type = import_type(mu, imp, vcode_reg_type(result));
2,050✔
231

232
   const int nargs = vcode_count_args(op);
2,050✔
233
   mir_value_t *elts LOCAL = xmalloc_array(nargs, sizeof(mir_value_t));
4,100✔
234
   for (int i = 0; i < nargs; i++)
7,486✔
235
      elts[i] = imp->map[vcode_get_arg(op, i)];
5,436✔
236

237
   imp->map[result] = mir_const_record(mu, type, elts, nargs);
2,050✔
238
}
2,050✔
239

240
static void import_cmp(mir_unit_t *mu, mir_import_t *imp, int op)
33,658✔
241
{
242
   const mir_cmp_t cmp = (mir_cmp_t)vcode_get_cmp(op);
33,658✔
243
   mir_value_t left = imp->map[vcode_get_arg(op, 0)];
33,658✔
244
   mir_value_t right = imp->map[vcode_get_arg(op, 1)];
33,658✔
245

246
   imp->map[vcode_get_result(op)] = mir_build_cmp(mu, cmp, left, right);
33,658✔
247
}
33,658✔
248

249
static void import_debug_locus(mir_unit_t *mu, mir_import_t *imp, int op)
77,404✔
250
{
251
   object_t *obj = vcode_get_object(op);
77,404✔
252
   imp->map[vcode_get_result(op)] = mir_build_locus(mu, obj);
77,404✔
253
}
77,404✔
254

255
static void import_assert(mir_unit_t *mu, mir_import_t *imp, int op)
14,628✔
256
{
257
   mir_value_t value    = imp->map[vcode_get_arg(op, 0)];
14,628✔
258
   mir_value_t severity = imp->map[vcode_get_arg(op, 1)];
14,628✔
259
   mir_value_t locus    = imp->map[vcode_get_arg(op, 4)];
14,628✔
260

261
   // TODO: returning VCODE_INVALID_REG sucks - why not have optional args?
262
   mir_value_t msg = MIR_NULL_VALUE, length = MIR_NULL_VALUE;
14,628✔
263
   if (vcode_get_arg(op, 2) != VCODE_INVALID_REG) {
14,628✔
264
      msg    = imp->map[vcode_get_arg(op, 2)];
3,451✔
265
      length = imp->map[vcode_get_arg(op, 3)];
3,451✔
266
   }
267

268
   mir_value_t hint_left = MIR_NULL_VALUE, hint_right = MIR_NULL_VALUE;
14,628✔
269
   if (vcode_count_args(op) > 5) {
14,628✔
270
      hint_left  = imp->map[vcode_get_arg(op, 5)];
6,088✔
271
      hint_right = imp->map[vcode_get_arg(op, 6)];
6,088✔
272
   }
273

274
   mir_build_assert(mu, value, msg, length, severity, locus,
14,628✔
275
                    hint_left, hint_right);
276
}
14,628✔
277

278
static void import_report(mir_unit_t *mu, mir_import_t *imp, int op)
2,077✔
279
{
280
   mir_value_t severity = imp->map[vcode_get_arg(op, 0)];
2,077✔
281
   mir_value_t message  = imp->map[vcode_get_arg(op, 1)];
2,077✔
282
   mir_value_t length   = imp->map[vcode_get_arg(op, 2)];
2,077✔
283
   mir_value_t locus    = imp->map[vcode_get_arg(op, 3)];
2,077✔
284

285
   mir_build_report(mu, message, length, severity, locus);
2,077✔
286
}
2,077✔
287

288
static void import_wait(mir_unit_t *mu, mir_import_t *imp, int op)
12,821✔
289
{
290
   mir_block_t btarget = imp->blocks[vcode_get_target(op, 0)];
12,821✔
291
   mir_build_wait(mu, btarget);
12,821✔
292
}
12,821✔
293

294
static void import_jump(mir_unit_t *mu, mir_import_t *imp, int op)
36,086✔
295
{
296
   mir_block_t btarget = imp->blocks[vcode_get_target(op, 0)];
36,086✔
297
   mir_build_jump(mu, btarget);
36,086✔
298
}
36,086✔
299

300
static void import_cond(mir_unit_t *mu, mir_import_t *imp, int op)
30,759✔
301
{
302
   mir_value_t test   = imp->map[vcode_get_arg(op, 0)];
30,759✔
303
   mir_block_t btrue  = imp->blocks[vcode_get_target(op, 0)];
30,759✔
304
   mir_block_t bfalse = imp->blocks[vcode_get_target(op, 1)];
30,759✔
305

306
   mir_build_cond(mu, test, btrue, bfalse);
30,759✔
307
}
30,759✔
308

309
static void import_case(mir_unit_t *mu, mir_import_t *imp, int op)
647✔
310
{
311
   mir_value_t value = imp->map[vcode_get_arg(op, 0)];
647✔
312
   mir_block_t def   = imp->blocks[vcode_get_target(op, 0)];
647✔
313

314
   const int nargs = vcode_count_args(op);
647✔
315

316
   mir_value_t *cases LOCAL = xmalloc_array(nargs - 1, sizeof(mir_value_t));
1,294✔
317
   mir_block_t *blocks LOCAL = xmalloc_array(nargs - 1, sizeof(mir_block_t));
1,294✔
318

319
   for (int i = 1; i < nargs; i++) {
3,699✔
320
      cases[i - 1]  = imp->map[vcode_get_arg(op, i)];
3,052✔
321
      blocks[i - 1] = imp->blocks[vcode_get_target(op, i)];
3,052✔
322
   }
323

324
   mir_build_case(mu, value, def, cases, blocks, nargs - 1);
647✔
325
}
647✔
326

327
static void import_init_signal(mir_unit_t *mu, mir_import_t *imp, int op)
16,214✔
328
{
329
   mir_value_t count = imp->map[vcode_get_arg(op, 0)];
16,214✔
330
   mir_value_t size  = imp->map[vcode_get_arg(op, 1)];
16,214✔
331
   mir_value_t value = imp->map[vcode_get_arg(op, 2)];
16,214✔
332
   mir_value_t flags = imp->map[vcode_get_arg(op, 3)];
16,214✔
333
   mir_value_t locus = imp->map[vcode_get_arg(op, 4)];
16,214✔
334

335
   mir_value_t offset = MIR_NULL_VALUE;
16,214✔
336
   if (vcode_count_args(op) > 5)
16,214✔
337
      offset = imp->map[vcode_get_arg(op, 5)];
5,736✔
338

339
   vcode_reg_t result = vcode_get_result(op);
16,214✔
340
   mir_type_t type = import_type(mu, imp, vtype_base(vcode_reg_type(result)));
16,214✔
341

342
   imp->map[result] = mir_build_init_signal(mu, type, count, size,
16,214✔
343
                                            value, flags, locus, offset);
344
}
16,214✔
345

346
static void import_implicit_signal(mir_unit_t *mu, mir_import_t *imp, int op)
75✔
347
{
348
   mir_value_t count   = imp->map[vcode_get_arg(op, 0)];
75✔
349
   mir_value_t size    = imp->map[vcode_get_arg(op, 1)];
75✔
350
   mir_value_t locus   = imp->map[vcode_get_arg(op, 2)];
75✔
351
   mir_value_t kind    = imp->map[vcode_get_arg(op, 3)];
75✔
352
   mir_value_t closure = imp->map[vcode_get_arg(op, 4)];
75✔
353
   mir_value_t delay   = imp->map[vcode_get_arg(op, 5)];
75✔
354

355
   vcode_reg_t result = vcode_get_result(op);
75✔
356
   mir_type_t type = import_type(mu, imp, vtype_base(vcode_reg_type(result)));
75✔
357

358
   imp->map[result] = mir_build_implicit_signal(mu, type, count, size, locus,
75✔
359
                                                kind, closure, delay);
360
}
75✔
361

362
static void import_drive_signal(mir_unit_t *mu, mir_import_t *imp, int op)
7,236✔
363
{
364
   mir_value_t target = imp->map[vcode_get_arg(op, 0)];
7,236✔
365
   mir_value_t count  = imp->map[vcode_get_arg(op, 1)];
7,236✔
366

367
   mir_build_drive_signal(mu, target, count);
7,236✔
368
}
7,236✔
369

370
static void import_sched_waveform(mir_unit_t *mu, mir_import_t *imp, int op)
9,199✔
371
{
372
   mir_value_t target = imp->map[vcode_get_arg(op, 0)];
9,199✔
373
   mir_value_t count  = imp->map[vcode_get_arg(op, 1)];
9,199✔
374
   mir_value_t value  = imp->map[vcode_get_arg(op, 2)];
9,199✔
375
   mir_value_t reject = imp->map[vcode_get_arg(op, 3)];
9,199✔
376
   mir_value_t after  = imp->map[vcode_get_arg(op, 4)];
9,199✔
377

378
   mir_build_sched_waveform(mu, target, count, value, reject, after);
9,199✔
379
}
9,199✔
380

381
static void import_resolved(mir_unit_t *mu, mir_import_t *imp, int op)
12,910✔
382
{
383
   mir_value_t nets = imp->map[vcode_get_arg(op, 0)];
12,910✔
384
   imp->map[vcode_get_result(op)] = mir_build_resolved(mu, nets);
12,910✔
385
}
12,910✔
386

387
static void import_address_of(mir_unit_t *mu, mir_import_t *imp, int op)
31,180✔
388
{
389
   mir_value_t nets = imp->map[vcode_get_arg(op, 0)];
31,180✔
390
   imp->map[vcode_get_result(op)] = mir_build_address_of(mu, nets);
31,180✔
391
}
31,180✔
392

393
static void import_store(mir_unit_t *mu, mir_import_t *imp, int op)
75,152✔
394
{
395
   mir_value_t var = imp->vars[vcode_get_address(op)];
75,152✔
396
   mir_build_store(mu, var, imp->map[vcode_get_arg(op, 0)]);
75,152✔
397
}
75,152✔
398

399
static void import_store_indirect(mir_unit_t *mu, mir_import_t *imp, int op)
14,927✔
400
{
401
   mir_value_t value = imp->map[vcode_get_arg(op, 0)];
14,927✔
402
   mir_value_t var   = imp->map[vcode_get_arg(op, 1)];
14,927✔
403
   mir_build_store(mu, var, value);
14,927✔
404
}
14,927✔
405

406
static void import_load(mir_unit_t *mu, mir_import_t *imp, int op)
38,317✔
407
{
408
   mir_value_t var = imp->vars[vcode_get_address(op)];
38,317✔
409
   imp->map[vcode_get_result(op)] = mir_build_load(mu, var);
38,317✔
410
}
38,317✔
411

412
static void import_load_indirect(mir_unit_t *mu, mir_import_t *imp, int op)
82,909✔
413
{
414
   mir_value_t var = imp->map[vcode_get_arg(op, 0)];
82,909✔
415
   imp->map[vcode_get_result(op)] = mir_build_load(mu, var);
82,909✔
416
}
82,909✔
417

418
static void import_context_upref(mir_unit_t *mu, mir_import_t *imp, int op)
10,876✔
419
{
420
   const int hops = vcode_get_hops(op);
10,876✔
421
   imp->map[vcode_get_result(op)] = mir_build_context_upref(mu, hops);
10,876✔
422
}
10,876✔
423

424
static void import_var_upref(mir_unit_t *mu, mir_import_t *imp, int op)
43,277✔
425
{
426
   const int hops = vcode_get_hops(op);
43,277✔
427
   vcode_var_t var = vcode_get_address(op);
43,277✔
428
   imp->map[vcode_get_result(op)] = mir_build_var_upref(mu, hops, var);
43,277✔
429
}
43,277✔
430

431
static void import_wrap(mir_unit_t *mu, mir_import_t *imp, int op)
29,783✔
432
{
433
   mir_value_t data = imp->map[vcode_get_arg(op, 0)];
29,783✔
434

435
   const int nargs = vcode_count_args(op);
29,783✔
436
   assert((nargs - 1) % 3 == 0);
29,783✔
437

438
   const int ndims = (nargs - 1) / 3;
29,783✔
439
   mir_dim_t *dims LOCAL = xmalloc_array(ndims, sizeof(mir_dim_t));
59,566✔
440
   for (int i = 0, pos = 1; i < ndims; i++, pos += 3) {
60,099✔
441
      dims[i].left  = imp->map[vcode_get_arg(op, pos + 0)];
30,316✔
442
      dims[i].right = imp->map[vcode_get_arg(op, pos + 1)];
30,316✔
443
      dims[i].dir   = imp->map[vcode_get_arg(op, pos + 2)];
30,316✔
444
   }
445

446
   imp->map[vcode_get_result(op)] = mir_build_wrap(mu, data, dims, ndims);
29,783✔
447
}
29,783✔
448

449
static void import_unwrap(mir_unit_t *mu, mir_import_t *imp, int op)
25,205✔
450
{
451
   mir_value_t arg = imp->map[vcode_get_arg(op, 0)];
25,205✔
452
   imp->map[vcode_get_result(op)] = mir_build_unwrap(mu, arg);
25,205✔
453
}
25,205✔
454

455
static void import_uarray_len(mir_unit_t *mu, mir_import_t *imp, int op)
19,404✔
456
{
457
   mir_value_t arg = imp->map[vcode_get_arg(op, 0)];
19,404✔
458
   const int dim = vcode_get_dim(op);
19,404✔
459
   imp->map[vcode_get_result(op)] = mir_build_uarray_len(mu, arg, dim);
19,404✔
460
}
19,404✔
461

462
static void import_uarray_left(mir_unit_t *mu, mir_import_t *imp, int op)
15,827✔
463
{
464
   mir_value_t arg = imp->map[vcode_get_arg(op, 0)];
15,827✔
465
   const int dim = vcode_get_dim(op);
15,827✔
466
   imp->map[vcode_get_result(op)] = mir_build_uarray_left(mu, arg, dim);
15,827✔
467
}
15,827✔
468

469
static void import_uarray_right(mir_unit_t *mu, mir_import_t *imp, int op)
12,928✔
470
{
471
   mir_value_t arg = imp->map[vcode_get_arg(op, 0)];
12,928✔
472
   const int dim = vcode_get_dim(op);
12,928✔
473
   imp->map[vcode_get_result(op)] = mir_build_uarray_right(mu, arg, dim);
12,928✔
474
}
12,928✔
475

476
static void import_uarray_dir(mir_unit_t *mu, mir_import_t *imp, int op)
15,774✔
477
{
478
   mir_value_t arg = imp->map[vcode_get_arg(op, 0)];
15,774✔
479
   const int dim = vcode_get_dim(op);
15,774✔
480
   imp->map[vcode_get_result(op)] = mir_build_uarray_dir(mu, arg, dim);
15,774✔
481
}
15,774✔
482

483
static void import_add(mir_unit_t *mu, mir_import_t *imp, int op)
12,772✔
484
{
485
   vcode_reg_t result = vcode_get_result(op);
12,772✔
486

487
   mir_value_t left  = imp->map[vcode_get_arg(op, 0)];
12,772✔
488
   mir_value_t right = imp->map[vcode_get_arg(op, 1)];
12,772✔
489
   mir_type_t type = import_type(mu, imp, vcode_reg_type(result));
12,772✔
490

491
   imp->map[result] = mir_build_add(mu, type, left, right);
12,772✔
492
}
12,772✔
493

494
static void import_trap_add(mir_unit_t *mu, mir_import_t *imp, int op)
4,801✔
495
{
496
   vcode_reg_t result = vcode_get_result(op);
4,801✔
497

498
   mir_value_t left  = imp->map[vcode_get_arg(op, 0)];
4,801✔
499
   mir_value_t right = imp->map[vcode_get_arg(op, 1)];
4,801✔
500
   mir_value_t locus = imp->map[vcode_get_arg(op, 2)];
4,801✔
501
   mir_type_t type = import_type(mu, imp, vcode_reg_type(result));
4,801✔
502

503
   imp->map[result] = mir_build_trap_add(mu, type, left, right, locus);
4,801✔
504
}
4,801✔
505

506
static void import_sub(mir_unit_t *mu, mir_import_t *imp, int op)
27,594✔
507
{
508
   vcode_reg_t result = vcode_get_result(op);
27,594✔
509

510
   mir_value_t left  = imp->map[vcode_get_arg(op, 0)];
27,594✔
511
   mir_value_t right = imp->map[vcode_get_arg(op, 1)];
27,594✔
512
   mir_type_t type = import_type(mu, imp, vcode_reg_type(result));
27,594✔
513

514
   imp->map[result] = mir_build_sub(mu, type, left, right);
27,594✔
515
}
27,594✔
516

517
static void import_trap_sub(mir_unit_t *mu, mir_import_t *imp, int op)
1,671✔
518
{
519
   vcode_reg_t result = vcode_get_result(op);
1,671✔
520

521
   mir_value_t left  = imp->map[vcode_get_arg(op, 0)];
1,671✔
522
   mir_value_t right = imp->map[vcode_get_arg(op, 1)];
1,671✔
523
   mir_value_t locus = imp->map[vcode_get_arg(op, 2)];
1,671✔
524
   mir_type_t type = import_type(mu, imp, vcode_reg_type(result));
1,671✔
525

526
   imp->map[result] = mir_build_trap_sub(mu, type, left, right, locus);
1,671✔
527
}
1,671✔
528

529
static void import_mul(mir_unit_t *mu, mir_import_t *imp, int op)
2,921✔
530
{
531
   vcode_reg_t result = vcode_get_result(op);
2,921✔
532

533
   mir_value_t left  = imp->map[vcode_get_arg(op, 0)];
2,921✔
534
   mir_value_t right = imp->map[vcode_get_arg(op, 1)];
2,921✔
535
   mir_type_t type = import_type(mu, imp, vcode_reg_type(result));
2,921✔
536

537
   imp->map[result] = mir_build_mul(mu, type, left, right);
2,921✔
538
}
2,921✔
539

540
static void import_trap_mul(mir_unit_t *mu, mir_import_t *imp, int op)
908✔
541
{
542
   vcode_reg_t result = vcode_get_result(op);
908✔
543

544
   mir_value_t left  = imp->map[vcode_get_arg(op, 0)];
908✔
545
   mir_value_t right = imp->map[vcode_get_arg(op, 1)];
908✔
546
   mir_value_t locus = imp->map[vcode_get_arg(op, 2)];
908✔
547
   mir_type_t type = import_type(mu, imp, vcode_reg_type(result));
908✔
548

549
   imp->map[result] = mir_build_trap_mul(mu, type, left, right, locus);
908✔
550
}
908✔
551

552
static void import_div(mir_unit_t *mu, mir_import_t *imp, int op)
1,647✔
553
{
554
   vcode_reg_t result = vcode_get_result(op);
1,647✔
555

556
   mir_value_t left  = imp->map[vcode_get_arg(op, 0)];
1,647✔
557
   mir_value_t right = imp->map[vcode_get_arg(op, 1)];
1,647✔
558
   mir_type_t type = import_type(mu, imp, vcode_reg_type(result));
1,647✔
559

560
   imp->map[result] = mir_build_div(mu, type, left, right);
1,647✔
561
}
1,647✔
562

563
static void import_mod(mir_unit_t *mu, mir_import_t *imp, int op)
103✔
564
{
565
   vcode_reg_t result = vcode_get_result(op);
103✔
566

567
   mir_value_t left  = imp->map[vcode_get_arg(op, 0)];
103✔
568
   mir_value_t right = imp->map[vcode_get_arg(op, 1)];
103✔
569
   mir_type_t type = import_type(mu, imp, vcode_reg_type(result));
103✔
570

571
   imp->map[result] = mir_build_mod(mu, type, left, right);
103✔
572
}
103✔
573

574
static void import_rem(mir_unit_t *mu, mir_import_t *imp, int op)
937✔
575
{
576
   vcode_reg_t result = vcode_get_result(op);
937✔
577

578
   mir_value_t left  = imp->map[vcode_get_arg(op, 0)];
937✔
579
   mir_value_t right = imp->map[vcode_get_arg(op, 1)];
937✔
580
   mir_type_t type = import_type(mu, imp, vcode_reg_type(result));
937✔
581

582
   imp->map[result] = mir_build_rem(mu, type, left, right);
937✔
583
}
937✔
584

585
static void import_exp(mir_unit_t *mu, mir_import_t *imp, int op)
134✔
586
{
587
   vcode_reg_t result = vcode_get_result(op);
134✔
588

589
   mir_value_t left  = imp->map[vcode_get_arg(op, 0)];
134✔
590
   mir_value_t right = imp->map[vcode_get_arg(op, 1)];
134✔
591
   mir_type_t type = import_type(mu, imp, vcode_reg_type(result));
134✔
592

593
   imp->map[result] = mir_build_exp(mu, type, left, right);
134✔
594
}
134✔
595

596
static void import_trap_exp(mir_unit_t *mu, mir_import_t *imp, int op)
370✔
597
{
598
   vcode_reg_t result = vcode_get_result(op);
370✔
599

600
   mir_value_t left  = imp->map[vcode_get_arg(op, 0)];
370✔
601
   mir_value_t right = imp->map[vcode_get_arg(op, 1)];
370✔
602
   mir_value_t locus = imp->map[vcode_get_arg(op, 2)];
370✔
603
   mir_type_t type = import_type(mu, imp, vcode_reg_type(result));
370✔
604

605
   imp->map[result] = mir_build_trap_exp(mu, type, left, right, locus);
370✔
606
}
370✔
607

608
static void import_or(mir_unit_t *mu, mir_import_t *imp, int op)
2,066✔
609
{
610
   mir_value_t left  = imp->map[vcode_get_arg(op, 0)];
2,066✔
611
   mir_value_t right = imp->map[vcode_get_arg(op, 1)];
2,066✔
612

613
   imp->map[vcode_get_result(op)] = mir_build_or(mu, left, right);
2,066✔
614
}
2,066✔
615

616
static void import_nor(mir_unit_t *mu, mir_import_t *imp, int op)
38✔
617
{
618
   mir_value_t left  = imp->map[vcode_get_arg(op, 0)];
38✔
619
   mir_value_t right = imp->map[vcode_get_arg(op, 1)];
38✔
620

621
   mir_value_t or = mir_build_or(mu, left, right);
38✔
622
   imp->map[vcode_get_result(op)] = mir_build_not(mu, or);
38✔
623
}
38✔
624

625
static void import_xor(mir_unit_t *mu, mir_import_t *imp, int op)
58✔
626
{
627
   mir_value_t left  = imp->map[vcode_get_arg(op, 0)];
58✔
628
   mir_value_t right = imp->map[vcode_get_arg(op, 1)];
58✔
629

630
   imp->map[vcode_get_result(op)] = mir_build_xor(mu, left, right);
58✔
631
}
58✔
632

633
static void import_xnor(mir_unit_t *mu, mir_import_t *imp, int op)
40✔
634
{
635
   mir_value_t left  = imp->map[vcode_get_arg(op, 0)];
40✔
636
   mir_value_t right = imp->map[vcode_get_arg(op, 1)];
40✔
637

638
   mir_value_t xor = mir_build_xor(mu, left, right);
40✔
639
   imp->map[vcode_get_result(op)] = mir_build_not(mu, xor);
40✔
640
}
40✔
641

642
static void import_and(mir_unit_t *mu, mir_import_t *imp, int op)
4,683✔
643
{
644
   mir_value_t left  = imp->map[vcode_get_arg(op, 0)];
4,683✔
645
   mir_value_t right = imp->map[vcode_get_arg(op, 1)];
4,683✔
646

647
   imp->map[vcode_get_result(op)] = mir_build_and(mu, left, right);
4,683✔
648
}
4,683✔
649

650
static void import_nand(mir_unit_t *mu, mir_import_t *imp, int op)
37✔
651
{
652
   mir_value_t left  = imp->map[vcode_get_arg(op, 0)];
37✔
653
   mir_value_t right = imp->map[vcode_get_arg(op, 1)];
37✔
654

655
   mir_value_t and = mir_build_and(mu, left, right);
37✔
656
   imp->map[vcode_get_result(op)] = mir_build_not(mu, and);
37✔
657
}
37✔
658

659
static void import_event(mir_unit_t *mu, mir_import_t *imp, int op)
444✔
660
{
661
   mir_value_t signal = imp->map[vcode_get_arg(op, 0)];
444✔
662
   mir_value_t count  = imp->map[vcode_get_arg(op, 1)];
444✔
663
   imp->map[vcode_get_result(op)] = mir_build_event_flag(mu, signal, count);
444✔
664
}
444✔
665

666
static void import_active(mir_unit_t *mu, mir_import_t *imp, int op)
217✔
667
{
668
   mir_value_t signal = imp->map[vcode_get_arg(op, 0)];
217✔
669
   mir_value_t count  = imp->map[vcode_get_arg(op, 1)];
217✔
670
   imp->map[vcode_get_result(op)] = mir_build_active_flag(mu, signal, count);
217✔
671
}
217✔
672

673
static void import_driving(mir_unit_t *mu, mir_import_t *imp, int op)
36✔
674
{
675
   mir_value_t signal = imp->map[vcode_get_arg(op, 0)];
36✔
676
   mir_value_t count  = imp->map[vcode_get_arg(op, 1)];
36✔
677
   imp->map[vcode_get_result(op)] = mir_build_driving_flag(mu, signal, count);
36✔
678
}
36✔
679

680
static void import_not(mir_unit_t *mu, mir_import_t *imp, int op)
2,474✔
681
{
682
   mir_value_t arg = imp->map[vcode_get_arg(op, 0)];
2,474✔
683
   imp->map[vcode_get_result(op)] = mir_build_not(mu, arg);
2,474✔
684
}
2,474✔
685

686
static void import_cast(mir_unit_t *mu, mir_import_t *imp, int op)
53,558✔
687
{
688
   mir_value_t arg = imp->map[vcode_get_arg(op, 0)];
53,558✔
689
   mir_type_t type = import_type(mu, imp, vcode_get_type(op));
53,558✔
690
   imp->map[vcode_get_result(op)] = mir_build_cast(mu, type, arg);
53,558✔
691
}
53,558✔
692

693
static void import_neg(mir_unit_t *mu, mir_import_t *imp, int op)
6,971✔
694
{
695
   vcode_reg_t result = vcode_get_result(op);
6,971✔
696
   mir_value_t arg = imp->map[vcode_get_arg(op, 0)];
6,971✔
697
   mir_type_t type = import_type(mu, imp, vcode_reg_type(result));
6,971✔
698
   imp->map[result] = mir_build_neg(mu, type, arg);
6,971✔
699
}
6,971✔
700

701
static void import_trap_neg(mir_unit_t *mu, mir_import_t *imp, int op)
257✔
702
{
703
   vcode_reg_t result = vcode_get_result(op);
257✔
704
   mir_value_t arg = imp->map[vcode_get_arg(op, 0)];
257✔
705
   mir_value_t locus = imp->map[vcode_get_arg(op, 1)];
257✔
706
   mir_type_t type = import_type(mu, imp, vcode_reg_type(result));
257✔
707
   imp->map[result] = mir_build_trap_neg(mu, type, arg, locus);
257✔
708
}
257✔
709

710
static void import_abs(mir_unit_t *mu, mir_import_t *imp, int op)
685✔
711
{
712
   vcode_reg_t result = vcode_get_result(op);
685✔
713
   mir_value_t arg = imp->map[vcode_get_arg(op, 0)];
685✔
714
   mir_type_t type = import_type(mu, imp, vcode_reg_type(result));
685✔
715
   imp->map[result] = mir_build_abs(mu, type, arg);
685✔
716
}
685✔
717

718
static void import_index(mir_unit_t *mu, mir_import_t *imp, int op)
25,641✔
719
{
720
   mir_value_t var = imp->vars[vcode_get_address(op)];
25,641✔
721
   imp->map[vcode_get_result(op)] = var;
25,641✔
722
}
25,641✔
723

724
static void import_copy(mir_unit_t *mu, mir_import_t *imp, int op)
24,936✔
725
{
726
   mir_value_t dst = imp->map[vcode_get_arg(op, 0)];
24,936✔
727
   mir_value_t src = imp->map[vcode_get_arg(op, 1)];
24,936✔
728

729
   mir_value_t count = MIR_NULL_VALUE;
24,936✔
730
   if (vcode_count_args(op) > 2)
24,936✔
731
      count = imp->map[vcode_get_arg(op, 2)];
23,360✔
732

733
   mir_build_copy(mu, dst, src, count);
24,936✔
734
}
24,936✔
735

736
static void import_memset(mir_unit_t *mu, mir_import_t *imp, int op)
5,480✔
737
{
738
   mir_value_t dst   = imp->map[vcode_get_arg(op, 0)];
5,480✔
739
   mir_value_t value = imp->map[vcode_get_arg(op, 1)];
5,480✔
740
   mir_value_t count = imp->map[vcode_get_arg(op, 2)];
5,480✔
741

742
   mir_build_set(mu, dst, value, count);
5,480✔
743
}
5,480✔
744

745
static void import_array_ref(mir_unit_t *mu, mir_import_t *imp, int op)
31,704✔
746
{
747
   mir_value_t array  = imp->map[vcode_get_arg(op, 0)];
31,704✔
748
   mir_value_t offset = imp->map[vcode_get_arg(op, 1)];
31,704✔
749
   imp->map[vcode_get_result(op)] = mir_build_array_ref(mu, array, offset);
31,704✔
750
}
31,704✔
751

752
static void import_table_ref(mir_unit_t *mu, mir_import_t *imp, int op)
699✔
753
{
754
   const int nargs = vcode_count_args(op);
699✔
755
   assert(nargs >= 2);
699✔
756

757
   mir_value_t *args LOCAL = xmalloc_array(nargs, sizeof(mir_value_t));
1,398✔
758
   for (int i = 0; i < nargs; i++)
3,143✔
759
      args[i] = imp->map[vcode_get_arg(op, i)];
2,444✔
760

761
   imp->map[vcode_get_result(op)] = mir_build_table_ref(mu, args[0], args[1],
699✔
762
                                                        args + 2, nargs - 2);
699✔
763
}
699✔
764

765
static void import_record_ref(mir_unit_t *mu, mir_import_t *imp, int op)
33,111✔
766
{
767
   mir_value_t record = imp->map[vcode_get_arg(op, 0)];
33,111✔
768
   const int field = vcode_get_field(op);
33,111✔
769
   imp->map[vcode_get_result(op)] = mir_build_record_ref(mu, record, field);
33,111✔
770
}
33,111✔
771

772
static void import_range_check(mir_unit_t *mu, mir_import_t *imp, int op)
3,785✔
773
{
774
   mir_value_t value = imp->map[vcode_get_arg(op, 0)];
3,785✔
775
   mir_value_t left  = imp->map[vcode_get_arg(op, 1)];
3,785✔
776
   mir_value_t right = imp->map[vcode_get_arg(op, 2)];
3,785✔
777
   mir_value_t dir   = imp->map[vcode_get_arg(op, 3)];
3,785✔
778
   mir_value_t locus = imp->map[vcode_get_arg(op, 4)];
3,785✔
779
   mir_value_t hint  = imp->map[vcode_get_arg(op, 5)];
3,785✔
780

781
   mir_build_range_check(mu, value, left, right, dir, locus, hint);
3,785✔
782
}
3,785✔
783

784
static void import_sched_event(mir_unit_t *mu, mir_import_t *imp, int op)
4,480✔
785
{
786
   mir_value_t signal = imp->map[vcode_get_arg(op, 0)];
4,480✔
787
   mir_value_t count  = imp->map[vcode_get_arg(op, 1)];
4,480✔
788
   mir_build_sched_event(mu, signal, count);
4,480✔
789
}
4,480✔
790

791
static void import_clear_event(mir_unit_t *mu, mir_import_t *imp, int op)
550✔
792
{
793
   mir_value_t signal = imp->map[vcode_get_arg(op, 0)];
550✔
794
   mir_value_t count  = imp->map[vcode_get_arg(op, 1)];
550✔
795
   mir_build_clear_event(mu, signal, count);
550✔
796
}
550✔
797

798
static void import_alloc(mir_unit_t *mu, mir_import_t *imp, int op)
7,270✔
799
{
800
   mir_value_t count  = imp->map[vcode_get_arg(op, 0)];
7,270✔
801
   mir_type_t type    = import_type(mu, imp, vcode_get_type(op));
7,270✔
802
   vcode_reg_t result = vcode_get_result(op);
7,270✔
803
   imp->map[result] = mir_build_alloc(mu, type, MIR_NULL_STAMP, count);
7,270✔
804
}
7,270✔
805

806
static void import_range_length(mir_unit_t *mu, mir_import_t *imp, int op)
7,035✔
807
{
808
   mir_value_t left   = imp->map[vcode_get_arg(op, 0)];
7,035✔
809
   mir_value_t right  = imp->map[vcode_get_arg(op, 1)];
7,035✔
810
   mir_value_t dir    = imp->map[vcode_get_arg(op, 2)];
7,035✔
811
   vcode_reg_t result = vcode_get_result(op);
7,035✔
812
   imp->map[result] = mir_build_range_length(mu, left, right, dir);
7,035✔
813
}
7,035✔
814

815
static void import_range_null(mir_unit_t *mu, mir_import_t *imp, int op)
2,997✔
816
{
817
   mir_value_t left   = imp->map[vcode_get_arg(op, 0)];
2,997✔
818
   mir_value_t right  = imp->map[vcode_get_arg(op, 1)];
2,997✔
819
   mir_value_t dir    = imp->map[vcode_get_arg(op, 2)];
2,997✔
820
   vcode_reg_t result = vcode_get_result(op);
2,997✔
821
   imp->map[result] = mir_build_range_null(mu, left, right, dir);
2,997✔
822
}
2,997✔
823

824
static void import_null(mir_unit_t *mu, mir_import_t *imp, int op)
3,859✔
825
{
826
   vcode_reg_t result = vcode_get_result(op);
3,859✔
827
   mir_type_t type = import_type(mu, imp, vcode_reg_type(result));
3,859✔
828
   imp->map[result] = mir_build_null(mu, type);
3,859✔
829
}
3,859✔
830

831
static void import_new(mir_unit_t *mu, mir_import_t *imp, int op)
645✔
832
{
833
   vcode_reg_t result = vcode_get_result(op);
645✔
834
   vcode_type_t vtype = vtype_pointed(vcode_reg_type(result));
645✔
835
   mir_type_t type = import_type(mu, imp, vtype);
645✔
836

837
   mir_value_t count = MIR_NULL_VALUE;
645✔
838
   if (vcode_count_args(op) > 0)
645✔
839
      count = imp->map[vcode_get_arg(op, 0)];
554✔
840

841
   imp->map[result] = mir_build_new(mu, type, MIR_NULL_STAMP, count);
645✔
842
}
645✔
843

844
static void import_all(mir_unit_t *mu, mir_import_t *imp, int op)
2,818✔
845
{
846
   mir_value_t arg = imp->map[vcode_get_arg(op, 0)];
2,818✔
847
   imp->map[vcode_get_result(op)] = mir_build_all(mu, arg);
2,818✔
848
}
2,818✔
849

850
static void import_deallocate(mir_unit_t *mu, mir_import_t *imp, int op)
341✔
851
{
852
   mir_value_t arg = imp->map[vcode_get_arg(op, 0)];
341✔
853
   mir_type_t type = mir_get_type(mu, arg);
341✔
854
   mir_build_store(mu, arg, mir_build_null(mu, mir_get_pointer(mu, type)));
341✔
855
}
341✔
856

857
static void import_null_check(mir_unit_t *mu, mir_import_t *imp, int op)
2,173✔
858
{
859
   mir_value_t ptr = imp->map[vcode_get_arg(op, 0)];
2,173✔
860
   mir_value_t locus = imp->map[vcode_get_arg(op, 1)];
2,173✔
861
   mir_build_null_check(mu, ptr, locus);
2,173✔
862
}
2,173✔
863

864
static void import_zero_check(mir_unit_t *mu, mir_import_t *imp, int op)
91✔
865
{
866
   mir_value_t value = imp->map[vcode_get_arg(op, 0)];
91✔
867
   mir_value_t locus = imp->map[vcode_get_arg(op, 1)];
91✔
868
   mir_build_zero_check(mu, value, locus);
91✔
869
}
91✔
870

871
static void import_length_check(mir_unit_t *mu, mir_import_t *imp, int op)
7,244✔
872
{
873
   mir_value_t llen = imp->map[vcode_get_arg(op, 0)];
7,244✔
874
   mir_value_t rlen = imp->map[vcode_get_arg(op, 1)];
7,244✔
875
   mir_value_t locus = imp->map[vcode_get_arg(op, 2)];
7,244✔
876

877
   mir_value_t dim = MIR_NULL_VALUE;
7,244✔
878
   if (vcode_count_args(op) > 3)
7,244✔
879
      dim = imp->map[vcode_get_arg(op, 3)];
27✔
880

881
   mir_build_length_check(mu, llen, rlen, locus, dim);
7,244✔
882
}
7,244✔
883

884
static void import_index_check(mir_unit_t *mu, mir_import_t *imp, int op)
14,919✔
885
{
886
   mir_value_t value = imp->map[vcode_get_arg(op, 0)];
14,919✔
887
   mir_value_t left  = imp->map[vcode_get_arg(op, 1)];
14,919✔
888
   mir_value_t right = imp->map[vcode_get_arg(op, 2)];
14,919✔
889
   mir_value_t dir   = imp->map[vcode_get_arg(op, 3)];
14,919✔
890
   mir_value_t locus = imp->map[vcode_get_arg(op, 4)];
14,919✔
891
   mir_value_t hint  = imp->map[vcode_get_arg(op, 5)];
14,919✔
892

893
   mir_build_index_check(mu, value, left, right, dir, locus, hint);
14,919✔
894
}
14,919✔
895

896
static void import_dir_check(mir_unit_t *mu, mir_import_t *imp, int op)
2,368✔
897
{
898
   mir_value_t value = imp->map[vcode_get_arg(op, 0)];
2,368✔
899
   mir_value_t dir   = imp->map[vcode_get_arg(op, 1)];
2,368✔
900
   mir_value_t locus = imp->map[vcode_get_arg(op, 2)];
2,368✔
901

902
   mir_build_dir_check(mu, value, dir, locus);
2,368✔
903
}
2,368✔
904

905
static void import_alias_signal(mir_unit_t *mu, mir_import_t *imp, int op)
4,296✔
906
{
907
   mir_value_t signal = imp->map[vcode_get_arg(op, 0)];
4,296✔
908
   mir_value_t locus = imp->map[vcode_get_arg(op, 1)];
4,296✔
909

910
   mir_build_alias_signal(mu, signal, locus);
4,296✔
911
}
4,296✔
912

913
static void import_map_signal(mir_unit_t *mu, mir_import_t *imp, int op)
5,440✔
914
{
915
   mir_value_t src = imp->map[vcode_get_arg(op, 0)];
5,440✔
916
   mir_value_t dst = imp->map[vcode_get_arg(op, 1)];
5,440✔
917
   mir_value_t count = imp->map[vcode_get_arg(op, 2)];
5,440✔
918

919
   mir_build_map_signal(mu, src, dst, count);
5,440✔
920
}
5,440✔
921

922
static void import_map_const(mir_unit_t *mu, mir_import_t *imp, int op)
200✔
923
{
924
   mir_value_t src = imp->map[vcode_get_arg(op, 0)];
200✔
925
   mir_value_t dst = imp->map[vcode_get_arg(op, 1)];
200✔
926
   mir_value_t count = imp->map[vcode_get_arg(op, 2)];
200✔
927

928
   mir_build_map_const(mu, src, dst, count);
200✔
929
}
200✔
930

931
static void import_map_implicit(mir_unit_t *mu, mir_import_t *imp, int op)
57✔
932
{
933
   mir_value_t src = imp->map[vcode_get_arg(op, 0)];
57✔
934
   mir_value_t dst = imp->map[vcode_get_arg(op, 1)];
57✔
935
   mir_value_t count = imp->map[vcode_get_arg(op, 2)];
57✔
936

937
   mir_build_map_implicit(mu, src, dst, count);
57✔
938
}
57✔
939

940
static void import_bind_foreign(mir_unit_t *mu, mir_import_t *imp, int op)
1,011✔
941
{
942
   mir_value_t spec = imp->map[vcode_get_arg(op, 0)];
1,011✔
943
   mir_value_t length = imp->map[vcode_get_arg(op, 1)];
1,011✔
944

945
   mir_value_t locus = MIR_NULL_VALUE;
1,011✔
946
   if (vcode_count_args(op) > 2)
1,011✔
947
      locus = imp->map[vcode_get_arg(op, 2)];
834✔
948

949
   mir_build_bind_foreign(mu, spec, length, locus);
1,011✔
950
}
1,011✔
951

952
static void import_bind_external(mir_unit_t *mu, mir_import_t *imp, int op)
180✔
953
{
954
   mir_value_t locus = imp->map[vcode_get_arg(op, 0)];
180✔
955
   ident_t scope = vcode_get_ident(op);
180✔
956

957
   vcode_reg_t result = vcode_get_result(op);
180✔
958
   vcode_type_t vtype = vtype_pointed(vcode_reg_type(result));
180✔
959
   mir_type_t type = import_type(mu, imp, vtype);
180✔
960

961
   const int nargs = vcode_count_args(op) - 1;
180✔
962
   mir_value_t *args LOCAL = xmalloc_array(nargs, sizeof(mir_value_t));
360✔
963
   for (int i = 0; i < nargs; i++)
210✔
964
      args[i] = imp->map[vcode_get_arg(op, i + 1)];
30✔
965

966
   imp->map[result] = mir_build_bind_external(mu, locus, scope, type,
180✔
967
                                              MIR_NULL_STAMP, args, nargs);
180✔
968
}
180✔
969

970
static void import_unreachable(mir_unit_t *mu, mir_import_t *imp, int op)
1,360✔
971
{
972
   mir_value_t locus = MIR_NULL_VALUE;
1,360✔
973
   if (vcode_count_args(op) > 0)
1,360✔
974
      locus = imp->map[vcode_get_arg(op, 0)];
118✔
975

976
   mir_build_unreachable(mu, locus);
1,360✔
977
}
1,360✔
978

979
static void import_select(mir_unit_t *mu, mir_import_t *imp, int op)
12,506✔
980
{
981
   mir_value_t test = imp->map[vcode_get_arg(op, 0)];
12,506✔
982
   mir_value_t tval = imp->map[vcode_get_arg(op, 1)];
12,506✔
983
   mir_value_t fval = imp->map[vcode_get_arg(op, 2)];
12,506✔
984

985
   vcode_reg_t result = vcode_get_result(op);
12,506✔
986
   mir_type_t type = import_type(mu, imp, vcode_reg_type(result));
12,506✔
987

988
   imp->map[result] = mir_build_select(mu, type, test, tval, fval);
12,506✔
989
}
12,506✔
990

991
static void import_closure(mir_unit_t *mu, mir_import_t *imp, int op)
5,448✔
992
{
993
   mir_value_t context = imp->map[vcode_get_arg(op, 0)];
5,448✔
994
   ident_t func = vcode_get_func(op);
5,448✔
995

996
   mir_type_t atype = MIR_NULL_TYPE;
5,448✔
997
   vcode_reg_t result = vcode_get_result(op);
5,448✔
998
   mir_type_t rtype = import_type(mu, imp, vtype_base(vcode_reg_type(result)));
5,448✔
999

1000
   imp->map[result] = mir_build_closure(mu, func, context, atype, rtype);
5,448✔
1001
}
5,448✔
1002

1003
static void import_resolution_wrapper(mir_unit_t *mu, mir_import_t *imp, int op)
5,151✔
1004
{
1005
   mir_value_t closure = imp->map[vcode_get_arg(op, 0)];
5,151✔
1006
   mir_value_t nlits = imp->map[vcode_get_arg(op, 1)];
5,151✔
1007

1008
   vcode_reg_t result = vcode_get_result(op);
5,151✔
1009
   mir_type_t type = import_type(mu, imp, vtype_base(vcode_reg_type(result)));
5,151✔
1010

1011
   imp->map[result] = mir_build_resolution_wrapper(mu, type, closure, nlits);
5,151✔
1012
}
5,151✔
1013

1014
static void import_resolve_signal(mir_unit_t *mu, mir_import_t *imp, int op)
3,388✔
1015
{
1016
   mir_value_t signal = imp->map[vcode_get_arg(op, 0)];
3,388✔
1017
   mir_value_t resolution = imp->map[vcode_get_arg(op, 1)];
3,388✔
1018
   mir_build_resolve_signal(mu, signal, resolution);
3,388✔
1019
}
3,388✔
1020

1021
static void import_transfer_signal(mir_unit_t *mu, mir_import_t *imp, int op)
530✔
1022
{
1023
   mir_value_t target = imp->map[vcode_get_arg(op, 0)];
530✔
1024
   mir_value_t source = imp->map[vcode_get_arg(op, 1)];
530✔
1025
   mir_value_t count = imp->map[vcode_get_arg(op, 2)];
530✔
1026
   mir_value_t reject = imp->map[vcode_get_arg(op, 3)];
530✔
1027
   mir_value_t after = imp->map[vcode_get_arg(op, 4)];
530✔
1028

1029
   mir_build_transfer_signal(mu, target, source, count, reject, after);
530✔
1030
}
530✔
1031

1032
static void import_file_open(mir_unit_t *mu, mir_import_t *imp, int op)
1,236✔
1033
{
1034
   mir_value_t file = imp->map[vcode_get_arg(op, 0)];
1,236✔
1035
   mir_value_t name = imp->map[vcode_get_arg(op, 1)];
1,236✔
1036
   mir_value_t length = imp->map[vcode_get_arg(op, 2)];
1,236✔
1037
   mir_value_t kind = imp->map[vcode_get_arg(op, 3)];
1,236✔
1038

1039
   mir_value_t status = MIR_NULL_VALUE;
1,236✔
1040
   if (vcode_count_args(op) > 4)
1,236✔
1041
      status = imp->map[vcode_get_arg(op, 4)];
25✔
1042

1043
   mir_build_file_open(mu, file, name, length, kind, status);
1,236✔
1044
}
1,236✔
1045

1046
static void import_file_read(mir_unit_t *mu, mir_import_t *imp, int op)
90✔
1047
{
1048
   mir_value_t file = imp->map[vcode_get_arg(op, 0)];
90✔
1049
   mir_value_t ptr = imp->map[vcode_get_arg(op, 1)];
90✔
1050

1051
   mir_value_t inlen = MIR_NULL_VALUE, outlen = MIR_NULL_VALUE;
90✔
1052
   if (vcode_count_args(op) > 2) {
90✔
1053
      inlen = imp->map[vcode_get_arg(op, 2)];
42✔
1054

1055
      if (vcode_count_args(op) > 3)
42✔
1056
         outlen = imp->map[vcode_get_arg(op, 3)];
33✔
1057
   }
1058

1059
   mir_build_file_read(mu, file, ptr, inlen, outlen);
90✔
1060
}
90✔
1061

1062
static void import_file_write(mir_unit_t *mu, mir_import_t *imp, int op)
261✔
1063
{
1064
   mir_value_t file = imp->map[vcode_get_arg(op, 0)];
261✔
1065
   mir_value_t value = imp->map[vcode_get_arg(op, 1)];
261✔
1066

1067
   mir_value_t length = MIR_NULL_VALUE;
261✔
1068
   if (vcode_count_args(op) > 2)
261✔
1069
      length = imp->map[vcode_get_arg(op, 2)];
204✔
1070

1071
   mir_build_file_write(mu, file, value, length);
261✔
1072
}
261✔
1073

1074
static void import_port_conversion(mir_unit_t *mu, mir_import_t *imp, int op)
204✔
1075
{
1076
   mir_value_t driving = imp->map[vcode_get_arg(op, 0)];
204✔
1077

1078
   mir_value_t effective = MIR_NULL_VALUE;
204✔
1079
   if (vcode_count_args(op) > 1)
204✔
1080
      effective = imp->map[vcode_get_arg(op, 1)];
18✔
1081

1082
   vcode_reg_t result = vcode_get_result(op);
204✔
1083
   imp->map[result] = mir_build_port_conversion(mu, driving, effective);
204✔
1084
}
204✔
1085

1086
static void import_convert_in(mir_unit_t *mu, mir_import_t *imp, int op)
282✔
1087
{
1088
   mir_value_t conv = imp->map[vcode_get_arg(op, 0)];
282✔
1089
   mir_value_t nets = imp->map[vcode_get_arg(op, 1)];
282✔
1090
   mir_value_t count = imp->map[vcode_get_arg(op, 2)];
282✔
1091

1092
   mir_build_convert_in(mu, conv, nets, count);
282✔
1093
}
282✔
1094

1095
static void import_convert_out(mir_unit_t *mu, mir_import_t *imp, int op)
324✔
1096
{
1097
   mir_value_t conv = imp->map[vcode_get_arg(op, 0)];
324✔
1098
   mir_value_t nets = imp->map[vcode_get_arg(op, 1)];
324✔
1099
   mir_value_t count = imp->map[vcode_get_arg(op, 2)];
324✔
1100

1101
   mir_build_convert_out(mu, conv, nets, count);
324✔
1102
}
324✔
1103

1104
static void import_driving_value(mir_unit_t *mu, mir_import_t *imp, int op)
120✔
1105
{
1106
   mir_value_t signal = imp->map[vcode_get_arg(op, 0)];
120✔
1107

1108
   mir_value_t count = MIR_NULL_VALUE;
120✔
1109
   if (vcode_count_args(op) > 1)
120✔
1110
      count = imp->map[vcode_get_arg(op, 1)];
36✔
1111

1112
   imp->map[vcode_get_result(op)] = mir_build_driving_value(mu, signal, count);
120✔
1113
}
120✔
1114

1115
static void import_put_conversion(mir_unit_t *mu, mir_import_t *imp, int op)
342✔
1116
{
1117
   mir_value_t cf = imp->map[vcode_get_arg(op, 0)];
342✔
1118
   mir_value_t target = imp->map[vcode_get_arg(op, 1)];
342✔
1119
   mir_value_t count = imp->map[vcode_get_arg(op, 2)];
342✔
1120
   mir_value_t values = imp->map[vcode_get_arg(op, 3)];
342✔
1121

1122
   mir_build_put_conversion(mu, cf, target, count, values);
342✔
1123
}
342✔
1124

1125
static void import_force(mir_unit_t *mu, mir_import_t *imp, int op)
70✔
1126
{
1127
   mir_value_t target = imp->map[vcode_get_arg(op, 0)];
70✔
1128
   mir_value_t count = imp->map[vcode_get_arg(op, 1)];
70✔
1129
   mir_value_t values = imp->map[vcode_get_arg(op, 2)];
70✔
1130

1131
   mir_build_force(mu, target, count, values);
70✔
1132
}
70✔
1133

1134
static void import_release(mir_unit_t *mu, mir_import_t *imp, int op)
42✔
1135
{
1136
   mir_value_t target = imp->map[vcode_get_arg(op, 0)];
42✔
1137
   mir_value_t count = imp->map[vcode_get_arg(op, 1)];
42✔
1138

1139
   mir_build_release(mu, target, count);
42✔
1140
}
42✔
1141

1142
static void import_disconnect(mir_unit_t *mu, mir_import_t *imp, int op)
24✔
1143
{
1144
   mir_value_t target = imp->map[vcode_get_arg(op, 0)];
24✔
1145
   mir_value_t count = imp->map[vcode_get_arg(op, 1)];
24✔
1146
   mir_value_t reject = imp->map[vcode_get_arg(op, 2)];
24✔
1147
   mir_value_t after = imp->map[vcode_get_arg(op, 3)];
24✔
1148

1149
   mir_build_disconnect(mu, target, count, reject, after);
24✔
1150
}
24✔
1151

1152
static void import_exponent_check(mir_unit_t *mu, mir_import_t *imp, int op)
364✔
1153
{
1154
   mir_value_t exp = imp->map[vcode_get_arg(op, 0)];
364✔
1155
   mir_value_t locus = imp->map[vcode_get_arg(op, 1)];
364✔
1156

1157
   mir_build_exponent_check(mu, exp, locus);
364✔
1158
}
364✔
1159

1160
static void import_process_init(mir_unit_t *mu, mir_import_t *imp, int op)
117✔
1161
{
1162
   ident_t name = vcode_get_func(op);
117✔
1163
   mir_value_t locus = imp->map[vcode_get_arg(op, 0)];
117✔
1164

1165
   mir_build_process_init(mu, name, locus);
117✔
1166
}
117✔
1167

1168
static void import_cover_stmt(mir_unit_t *mu, mir_import_t *imp, int op)
1,300✔
1169
{
1170
   mir_build_cover_stmt(mu, vcode_get_tag(op));
1,300✔
1171
}
1,300✔
1172

1173
static void import_cover_branch(mir_unit_t *mu, mir_import_t *imp, int op)
499✔
1174
{
1175
   mir_build_cover_branch(mu, vcode_get_tag(op));
499✔
1176
}
499✔
1177

1178
static void import_cover_expr(mir_unit_t *mu, mir_import_t *imp, int op)
887✔
1179
{
1180
   mir_build_cover_expr(mu, vcode_get_tag(op));
887✔
1181
}
887✔
1182

1183
static void import_cover_toggle(mir_unit_t *mu, mir_import_t *imp, int op)
312✔
1184
{
1185
   mir_value_t signal = imp->map[vcode_get_arg(op, 0)];
312✔
1186
   mir_build_cover_toggle(mu, signal, vcode_get_tag(op));
312✔
1187
}
312✔
1188

1189
static void import_cover_state(mir_unit_t *mu, mir_import_t *imp, int op)
12✔
1190
{
1191
   mir_value_t signal = imp->map[vcode_get_arg(op, 0)];
12✔
1192
   mir_value_t low = imp->map[vcode_get_arg(op, 1)];
12✔
1193
   mir_build_cover_state(mu, signal, low, vcode_get_tag(op));
12✔
1194
}
12✔
1195

1196
static void import_array_scope(mir_unit_t *mu, mir_import_t *imp, int op)
654✔
1197
{
1198
   mir_value_t locus = imp->map[vcode_get_arg(op, 0)];
654✔
1199
   mir_type_t type = import_type(mu, imp, vcode_get_type(op));
654✔
1200
   mir_build_array_scope(mu, locus, type);
654✔
1201
}
654✔
1202

1203
static void import_package_scope(mir_unit_t *mu, mir_import_t *imp, int op)
45✔
1204
{
1205
   mir_value_t locus = imp->map[vcode_get_arg(op, 0)];
45✔
1206
   mir_build_package_scope(mu, locus);
45✔
1207
}
45✔
1208

1209
static void import_record_scope(mir_unit_t *mu, mir_import_t *imp, int op)
1,690✔
1210
{
1211
   mir_value_t locus = imp->map[vcode_get_arg(op, 0)];
1,690✔
1212
   mir_type_t type = import_type(mu, imp, vcode_get_type(op));
1,690✔
1213
   mir_build_record_scope(mu, locus, type);
1,690✔
1214
}
1,690✔
1215

1216
static void import_pop_scope(mir_unit_t *mu, mir_import_t *imp, int op)
2,389✔
1217
{
1218
   mir_build_pop_scope(mu);
2,389✔
1219
}
2,389✔
1220

1221
static void import_cmp_trigger(mir_unit_t *mu, mir_import_t *imp, int op)
47✔
1222
{
1223
   mir_value_t left = imp->map[vcode_get_arg(op, 0)];
47✔
1224
   mir_value_t right = imp->map[vcode_get_arg(op, 1)];
47✔
1225
   imp->map[vcode_get_result(op)] = mir_build_cmp_trigger(mu, left, right);
47✔
1226
}
47✔
1227

1228
static void import_function_trigger(mir_unit_t *mu, mir_import_t *imp, int op)
199✔
1229
{
1230
   const int nargs = vcode_count_args(op);
199✔
1231
   mir_value_t *args LOCAL = xmalloc_array(nargs, sizeof(mir_value_t));
398✔
1232
   for (int i = 0; i < nargs; i++)
480✔
1233
      args[i] = imp->map[vcode_get_arg(op, i)];
281✔
1234

1235
   ident_t func = vcode_get_func(op);
199✔
1236
   vcode_reg_t result = vcode_get_result(op);
199✔
1237
   imp->map[result] = mir_build_function_trigger(mu, func, args, nargs);
199✔
1238
}
199✔
1239

1240
static void import_or_trigger(mir_unit_t *mu, mir_import_t *imp, int op)
34✔
1241
{
1242
   mir_value_t left = imp->map[vcode_get_arg(op, 0)];
34✔
1243
   mir_value_t right = imp->map[vcode_get_arg(op, 1)];
34✔
1244
   imp->map[vcode_get_result(op)] = mir_build_or_trigger(mu, left, right);
34✔
1245
}
34✔
1246

1247
static void import_add_trigger(mir_unit_t *mu, mir_import_t *imp, int op)
368✔
1248
{
1249
   mir_value_t trigger = imp->map[vcode_get_arg(op, 0)];
368✔
1250
   mir_build_add_trigger(mu, trigger);
368✔
1251
}
368✔
1252

1253
static void import_protected_init(mir_unit_t *mu, mir_import_t *imp, int op)
544✔
1254
{
1255
   mir_value_t context = imp->map[vcode_get_arg(op, 0)];
544✔
1256

1257
   mir_value_t path_name = MIR_NULL_VALUE, inst_name = MIR_NULL_VALUE;
544✔
1258
   if (vcode_count_args(op) > 1) {
544✔
1259
      path_name = imp->map[vcode_get_arg(op, 1)];
414✔
1260
      inst_name = imp->map[vcode_get_arg(op, 2)];
414✔
1261
   }
1262

1263
   vcode_reg_t result = vcode_get_result(op);
544✔
1264
   mir_type_t type = import_type(mu, imp, vcode_reg_type(result));
544✔
1265

1266
   imp->map[result] = mir_build_protected_init(mu, type, context,
544✔
1267
                                               path_name, inst_name);
1268
}
544✔
1269

1270
static void import_instance_name(mir_unit_t *mu, mir_import_t *imp, int op)
767✔
1271
{
1272
   mir_value_t kind = imp->map[vcode_get_arg(op, 0)];
767✔
1273
   imp->map[vcode_get_result(op)] = mir_build_instance_name(mu, kind);
767✔
1274
}
767✔
1275

1276
static void import_last_event(mir_unit_t *mu, mir_import_t *imp, int op)
42✔
1277
{
1278
   mir_value_t signal = imp->map[vcode_get_arg(op, 0)];
42✔
1279

1280
   mir_value_t count = MIR_NULL_VALUE;
42✔
1281
   if (vcode_count_args(op) > 1)
42✔
1282
      count = imp->map[vcode_get_arg(op, 1)];
9✔
1283

1284
   imp->map[vcode_get_result(op)] = mir_build_last_event(mu, signal, count);
42✔
1285
}
42✔
1286

1287
static void import_last_active(mir_unit_t *mu, mir_import_t *imp, int op)
45✔
1288
{
1289
   mir_value_t signal = imp->map[vcode_get_arg(op, 0)];
45✔
1290

1291
   mir_value_t count = MIR_NULL_VALUE;
45✔
1292
   if (vcode_count_args(op) > 1)
45✔
1293
      count = imp->map[vcode_get_arg(op, 1)];
6✔
1294

1295
   imp->map[vcode_get_result(op)] = mir_build_last_active(mu, signal, count);
45✔
1296
}
45✔
1297

1298
static void import_last_value(mir_unit_t *mu, mir_import_t *imp, int op)
186✔
1299
{
1300
   mir_value_t signal = imp->map[vcode_get_arg(op, 0)];
186✔
1301
   imp->map[vcode_get_result(op)] = mir_build_last_value(mu, signal);
186✔
1302
}
186✔
1303

1304
static void import_enter_state(mir_unit_t *mu, mir_import_t *imp, int op)
849✔
1305
{
1306
   mir_value_t state = imp->map[vcode_get_arg(op, 0)];
849✔
1307

1308
   mir_value_t strong = MIR_NULL_VALUE;
849✔
1309
   if (vcode_count_args(op) > 1)
849✔
1310
      strong = imp->map[vcode_get_arg(op, 1)];
36✔
1311

1312
   mir_build_enter_state(mu, state, strong);
849✔
1313
}
849✔
1314

1315
static void import_reflect_value(mir_unit_t *mu, mir_import_t *imp, int op)
48✔
1316
{
1317
   mir_value_t value = imp->map[vcode_get_arg(op, 0)];
48✔
1318
   mir_value_t context = imp->map[vcode_get_arg(op, 1)];
48✔
1319
   mir_value_t locus = imp->map[vcode_get_arg(op, 2)];
48✔
1320

1321
   mir_value_t bounds = MIR_NULL_VALUE;
48✔
1322
   if (vcode_count_args(op) > 3)
48✔
1323
      bounds = imp->map[vcode_get_arg(op, 3)];
6✔
1324

1325
   imp->map[vcode_get_result(op)] =
48✔
1326
      mir_build_reflect_value(mu, value, context, locus, bounds);
48✔
1327
}
48✔
1328

1329
static void import_reflect_subtype(mir_unit_t *mu, mir_import_t *imp, int op)
42✔
1330
{
1331
   mir_value_t context = imp->map[vcode_get_arg(op, 0)];
42✔
1332
   mir_value_t locus = imp->map[vcode_get_arg(op, 1)];
42✔
1333

1334
   mir_value_t bounds = MIR_NULL_VALUE;
42✔
1335
   if (vcode_count_args(op) > 2)
42✔
UNCOV
1336
      bounds = imp->map[vcode_get_arg(op, 2)];
×
1337

1338
   imp->map[vcode_get_result(op)] =
42✔
1339
      mir_build_reflect_subtype(mu, context, locus, bounds);
42✔
1340
}
42✔
1341

UNCOV
1342
static void import_debug_out(mir_unit_t *mu, mir_import_t *imp, int op)
×
1343
{
UNCOV
1344
   mir_value_t value = imp->map[vcode_get_arg(op, 0)];
×
UNCOV
1345
   mir_build_debug_out(mu, value);
×
UNCOV
1346
}
×
1347

1348
static void import_sched_process(mir_unit_t *mu, mir_import_t *imp, int op)
5,267✔
1349
{
1350
   mir_value_t delay = imp->map[vcode_get_arg(op, 0)];
5,267✔
1351
   mir_build_sched_process(mu, delay);
5,267✔
1352
}
5,267✔
1353

1354
static void import_block(mir_unit_t *mu, mir_import_t *imp)
137,655✔
1355
{
1356
   const int nops = vcode_count_ops();
137,655✔
1357
   for (int i = 0; i < nops; i++) {
1,916,431✔
1358
      mir_set_loc(mu, vcode_get_loc(i));
1,778,776✔
1359

1360
      switch (vcode_get_op(i)) {
1,778,776✔
1361
      case VCODE_OP_COMMENT:
1362
         break;
1363
      case VCODE_OP_PACKAGE_INIT:
21,787✔
1364
         import_package_init(mu, imp, i);
21,787✔
1365
         break;
21,787✔
1366
      case VCODE_OP_LINK_PACKAGE:
6,702✔
1367
         import_link_package(mu, imp, i);
6,702✔
1368
         break;
6,702✔
1369
      case VCODE_OP_LINK_VAR:
4,851✔
1370
         import_link_var(mu, imp, i);
4,851✔
1371
         break;
4,851✔
1372
      case VCODE_OP_RETURN:
55,139✔
1373
         import_return(mu, imp, i);
55,139✔
1374
         break;
55,139✔
1375
      case VCODE_OP_FCALL:
34,176✔
1376
         import_fcall(mu, imp, i);
34,176✔
1377
         break;
34,176✔
1378
      case VCODE_OP_PCALL:
843✔
1379
         import_pcall(mu, imp, i);
843✔
1380
         break;
843✔
1381
      case VCODE_OP_RESUME:
843✔
1382
         import_resume(mu, imp, i);
843✔
1383
         break;
843✔
1384
      case VCODE_OP_CONST:
366,915✔
1385
         import_const(mu, imp, i);
366,915✔
1386
         break;
366,915✔
1387
      case VCODE_OP_CONST_REAL:
22,249✔
1388
         import_const_real(mu, imp, i);
22,249✔
1389
         break;
22,249✔
1390
      case VCODE_OP_CONST_ARRAY:
29,890✔
1391
         import_const_array(mu, imp, i);
29,890✔
1392
         break;
29,890✔
1393
      case VCODE_OP_CONST_REP:
302✔
1394
         import_const_rep(mu, imp, i);
302✔
1395
         break;
302✔
1396
      case VCODE_OP_CONST_RECORD:
2,050✔
1397
         import_const_record(mu, imp, i);
2,050✔
1398
         break;
2,050✔
1399
      case VCODE_OP_CMP:
33,658✔
1400
         import_cmp(mu, imp, i);
33,658✔
1401
         break;
33,658✔
1402
      case VCODE_OP_DEBUG_LOCUS:
77,404✔
1403
         import_debug_locus(mu, imp, i);
77,404✔
1404
         break;
77,404✔
1405
      case VCODE_OP_ASSERT:
14,628✔
1406
         import_assert(mu, imp, i);
14,628✔
1407
         break;
14,628✔
1408
      case VCODE_OP_REPORT:
2,077✔
1409
         import_report(mu, imp, i);
2,077✔
1410
         break;
2,077✔
1411
      case VCODE_OP_WAIT:
12,821✔
1412
         import_wait(mu, imp, i);
12,821✔
1413
         break;
12,821✔
1414
      case VCODE_OP_JUMP:
36,086✔
1415
         import_jump(mu, imp, i);
36,086✔
1416
         break;
36,086✔
1417
      case VCODE_OP_COND:
30,759✔
1418
         import_cond(mu, imp, i);
30,759✔
1419
         break;
30,759✔
1420
      case VCODE_OP_INIT_SIGNAL:
16,214✔
1421
         import_init_signal(mu, imp, i);
16,214✔
1422
         break;
16,214✔
1423
      case VCODE_OP_IMPLICIT_SIGNAL:
75✔
1424
         import_implicit_signal(mu, imp, i);
75✔
1425
         break;
75✔
1426
      case VCODE_OP_DRIVE_SIGNAL:
7,236✔
1427
         import_drive_signal(mu, imp, i);
7,236✔
1428
         break;
7,236✔
1429
      case VCODE_OP_SCHED_WAVEFORM:
9,199✔
1430
         import_sched_waveform(mu, imp, i);
9,199✔
1431
         break;
9,199✔
1432
      case VCODE_OP_RESOLVED:
12,910✔
1433
         import_resolved(mu, imp, i);
12,910✔
1434
         break;
12,910✔
1435
      case VCODE_OP_ADDRESS_OF:
31,180✔
1436
         import_address_of(mu, imp, i);
31,180✔
1437
         break;
31,180✔
1438
      case VCODE_OP_STORE:
75,152✔
1439
         import_store(mu, imp, i);
75,152✔
1440
         break;
75,152✔
1441
      case VCODE_OP_STORE_INDIRECT:
14,927✔
1442
         import_store_indirect(mu, imp, i);
14,927✔
1443
         break;
14,927✔
1444
      case VCODE_OP_LOAD:
38,317✔
1445
         import_load(mu, imp, i);
38,317✔
1446
         break;
38,317✔
1447
      case VCODE_OP_LOAD_INDIRECT:
82,909✔
1448
         import_load_indirect(mu, imp, i);
82,909✔
1449
         break;
82,909✔
1450
      case VCODE_OP_CONTEXT_UPREF:
10,876✔
1451
         import_context_upref(mu, imp, i);
10,876✔
1452
         break;
10,876✔
1453
      case VCODE_OP_VAR_UPREF:
43,277✔
1454
         import_var_upref(mu, imp, i);
43,277✔
1455
         break;
43,277✔
1456
      case VCODE_OP_WRAP:
29,783✔
1457
         import_wrap(mu, imp, i);
29,783✔
1458
         break;
29,783✔
1459
      case VCODE_OP_UNWRAP:
25,205✔
1460
         import_unwrap(mu, imp, i);
25,205✔
1461
         break;
25,205✔
1462
      case VCODE_OP_UARRAY_LEN:
19,404✔
1463
         import_uarray_len(mu, imp, i);
19,404✔
1464
         break;
19,404✔
1465
      case VCODE_OP_UARRAY_LEFT:
15,827✔
1466
         import_uarray_left(mu, imp, i);
15,827✔
1467
         break;
15,827✔
1468
      case VCODE_OP_UARRAY_RIGHT:
12,928✔
1469
         import_uarray_right(mu, imp, i);
12,928✔
1470
         break;
12,928✔
1471
      case VCODE_OP_UARRAY_DIR:
15,774✔
1472
         import_uarray_dir(mu, imp, i);
15,774✔
1473
         break;
15,774✔
1474
      case VCODE_OP_ADD:
12,772✔
1475
         import_add(mu, imp, i);
12,772✔
1476
         break;
12,772✔
1477
      case VCODE_OP_TRAP_ADD:
4,801✔
1478
         import_trap_add(mu, imp, i);
4,801✔
1479
         break;
4,801✔
1480
      case VCODE_OP_SUB:
27,594✔
1481
         import_sub(mu, imp, i);
27,594✔
1482
         break;
27,594✔
1483
      case VCODE_OP_TRAP_SUB:
1,671✔
1484
         import_trap_sub(mu, imp, i);
1,671✔
1485
         break;
1,671✔
1486
      case VCODE_OP_MUL:
2,921✔
1487
         import_mul(mu, imp, i);
2,921✔
1488
         break;
2,921✔
1489
      case VCODE_OP_TRAP_MUL:
908✔
1490
         import_trap_mul(mu, imp, i);
908✔
1491
         break;
908✔
1492
      case VCODE_OP_DIV:
1,647✔
1493
         import_div(mu, imp, i);
1,647✔
1494
         break;
1,647✔
1495
      case VCODE_OP_MOD:
103✔
1496
         import_mod(mu, imp, i);
103✔
1497
         break;
103✔
1498
      case VCODE_OP_REM:
937✔
1499
         import_rem(mu, imp, i);
937✔
1500
         break;
937✔
1501
      case VCODE_OP_EXP:
134✔
1502
         import_exp(mu, imp, i);
134✔
1503
         break;
134✔
1504
      case VCODE_OP_TRAP_EXP:
370✔
1505
         import_trap_exp(mu, imp, i);
370✔
1506
         break;
370✔
1507
      case VCODE_OP_OR:
2,066✔
1508
         import_or(mu, imp, i);
2,066✔
1509
         break;
2,066✔
1510
      case VCODE_OP_NOR:
38✔
1511
         import_nor(mu, imp, i);
38✔
1512
         break;
38✔
1513
      case VCODE_OP_XOR:
58✔
1514
         import_xor(mu, imp, i);
58✔
1515
         break;
58✔
1516
      case VCODE_OP_XNOR:
40✔
1517
         import_xnor(mu, imp, i);
40✔
1518
         break;
40✔
1519
      case VCODE_OP_AND:
4,683✔
1520
         import_and(mu, imp, i);
4,683✔
1521
         break;
4,683✔
1522
      case VCODE_OP_NAND:
37✔
1523
         import_nand(mu, imp, i);
37✔
1524
         break;
37✔
1525
      case VCODE_OP_EVENT:
444✔
1526
         import_event(mu, imp, i);
444✔
1527
         break;
444✔
1528
      case VCODE_OP_ACTIVE:
217✔
1529
         import_active(mu, imp, i);
217✔
1530
         break;
217✔
1531
      case VCODE_OP_DRIVING:
36✔
1532
         import_driving(mu, imp, i);
36✔
1533
         break;
36✔
1534
      case VCODE_OP_NOT:
2,474✔
1535
         import_not(mu, imp, i);
2,474✔
1536
         break;
2,474✔
1537
      case VCODE_OP_CAST:
53,558✔
1538
         import_cast(mu, imp, i);
53,558✔
1539
         break;
53,558✔
1540
      case VCODE_OP_NEG:
6,971✔
1541
         import_neg(mu, imp, i);
6,971✔
1542
         break;
6,971✔
1543
      case VCODE_OP_TRAP_NEG:
257✔
1544
         import_trap_neg(mu, imp, i);
257✔
1545
         break;
257✔
1546
      case VCODE_OP_ABS:
685✔
1547
         import_abs(mu, imp, i);
685✔
1548
         break;
685✔
1549
      case VCODE_OP_INDEX:
25,641✔
1550
         import_index(mu, imp, i);
25,641✔
1551
         break;
25,641✔
1552
      case VCODE_OP_COPY:
24,936✔
1553
         import_copy(mu, imp, i);
24,936✔
1554
         break;
24,936✔
1555
      case VCODE_OP_MEMSET:
5,480✔
1556
         import_memset(mu, imp, i);
5,480✔
1557
         break;
5,480✔
1558
      case VCODE_OP_ARRAY_REF:
31,704✔
1559
         import_array_ref(mu, imp, i);
31,704✔
1560
         break;
31,704✔
1561
      case VCODE_OP_TABLE_REF:
699✔
1562
         import_table_ref(mu, imp, i);
699✔
1563
         break;
699✔
1564
      case VCODE_OP_RECORD_REF:
33,111✔
1565
         import_record_ref(mu, imp, i);
33,111✔
1566
         break;
33,111✔
1567
      case VCODE_OP_RANGE_CHECK:
3,785✔
1568
         import_range_check(mu, imp, i);
3,785✔
1569
         break;
3,785✔
1570
      case VCODE_OP_SCHED_EVENT:
4,480✔
1571
         import_sched_event(mu, imp, i);
4,480✔
1572
         break;
4,480✔
1573
      case VCODE_OP_CLEAR_EVENT:
550✔
1574
         import_clear_event(mu, imp, i);
550✔
1575
         break;
550✔
1576
      case VCODE_OP_ALLOC:
7,270✔
1577
         import_alloc(mu, imp, i);
7,270✔
1578
         break;
7,270✔
1579
      case VCODE_OP_RANGE_LENGTH:
7,035✔
1580
         import_range_length(mu, imp, i);
7,035✔
1581
         break;
7,035✔
1582
      case VCODE_OP_RANGE_NULL:
2,997✔
1583
         import_range_null(mu, imp, i);
2,997✔
1584
         break;
2,997✔
1585
      case VCODE_OP_NULL:
3,859✔
1586
         import_null(mu, imp, i);
3,859✔
1587
         break;
3,859✔
1588
      case VCODE_OP_NEW:
645✔
1589
         import_new(mu, imp, i);
645✔
1590
         break;
645✔
1591
      case VCODE_OP_ALL:
2,818✔
1592
         import_all(mu, imp, i);
2,818✔
1593
         break;
2,818✔
1594
      case VCODE_OP_DEALLOCATE:
341✔
1595
         import_deallocate(mu, imp, i);
341✔
1596
         break;
341✔
1597
      case VCODE_OP_ZERO_CHECK:
91✔
1598
         import_zero_check(mu, imp, i);
91✔
1599
         break;
91✔
1600
      case VCODE_OP_NULL_CHECK:
2,173✔
1601
         import_null_check(mu, imp, i);
2,173✔
1602
         break;
2,173✔
1603
      case VCODE_OP_LENGTH_CHECK:
7,244✔
1604
         import_length_check(mu, imp, i);
7,244✔
1605
         break;
7,244✔
1606
      case VCODE_OP_INDEX_CHECK:
14,919✔
1607
         import_index_check(mu, imp, i);
14,919✔
1608
         break;
14,919✔
1609
      case VCODE_OP_DIR_CHECK:
2,368✔
1610
         import_dir_check(mu, imp, i);
2,368✔
1611
         break;
2,368✔
1612
      case VCODE_OP_ALIAS_SIGNAL:
4,296✔
1613
         import_alias_signal(mu, imp, i);
4,296✔
1614
         break;
4,296✔
1615
      case VCODE_OP_MAP_SIGNAL:
5,440✔
1616
         import_map_signal(mu, imp, i);
5,440✔
1617
         break;
5,440✔
1618
      case VCODE_OP_MAP_CONST:
200✔
1619
         import_map_const(mu, imp, i);
200✔
1620
         break;
200✔
1621
      case VCODE_OP_MAP_IMPLICIT:
57✔
1622
         import_map_implicit(mu, imp, i);
57✔
1623
         break;
57✔
1624
      case VCODE_OP_CASE:
647✔
1625
         import_case(mu, imp, i);
647✔
1626
         break;
647✔
1627
      case VCODE_OP_BIND_FOREIGN:
1,011✔
1628
         import_bind_foreign(mu, imp, i);
1,011✔
1629
         break;
1,011✔
1630
      case VCODE_OP_BIND_EXTERNAL:
180✔
1631
         import_bind_external(mu, imp, i);
180✔
1632
         break;
180✔
1633
      case VCODE_OP_UNREACHABLE:
1,360✔
1634
         import_unreachable(mu, imp, i);
1,360✔
1635
         break;
1,360✔
1636
      case VCODE_OP_SELECT:
12,506✔
1637
         import_select(mu, imp, i);
12,506✔
1638
         break;
12,506✔
1639
      case VCODE_OP_CLOSURE:
5,448✔
1640
         import_closure(mu, imp, i);
5,448✔
1641
         break;
5,448✔
1642
      case VCODE_OP_RESOLUTION_WRAPPER:
5,151✔
1643
         import_resolution_wrapper(mu, imp, i);
5,151✔
1644
         break;
5,151✔
1645
      case VCODE_OP_RESOLVE_SIGNAL:
3,388✔
1646
         import_resolve_signal(mu, imp, i);
3,388✔
1647
         break;
3,388✔
1648
      case VCODE_OP_TRANSFER_SIGNAL:
530✔
1649
         import_transfer_signal(mu, imp, i);
530✔
1650
         break;
530✔
1651
      case VCODE_OP_FILE_OPEN:
1,236✔
1652
         import_file_open(mu, imp, i);
1,236✔
1653
         break;
1,236✔
1654
      case VCODE_OP_FILE_READ:
90✔
1655
         import_file_read(mu, imp, i);
90✔
1656
         break;
90✔
1657
      case VCODE_OP_FILE_WRITE:
261✔
1658
         import_file_write(mu, imp, i);
261✔
1659
         break;
261✔
1660
      case VCODE_OP_PORT_CONVERSION:
204✔
1661
         import_port_conversion(mu, imp, i);
204✔
1662
         break;
204✔
1663
      case VCODE_OP_CONVERT_IN:
282✔
1664
         import_convert_in(mu, imp, i);
282✔
1665
         break;
282✔
1666
      case VCODE_OP_CONVERT_OUT:
324✔
1667
         import_convert_out(mu, imp, i);
324✔
1668
         break;
324✔
1669
      case VCODE_OP_DRIVING_VALUE:
120✔
1670
         import_driving_value(mu, imp, i);
120✔
1671
         break;
120✔
1672
      case VCODE_OP_PUT_CONVERSION:
342✔
1673
         import_put_conversion(mu, imp, i);
342✔
1674
         break;
342✔
1675
      case VCODE_OP_FORCE:
70✔
1676
         import_force(mu, imp, i);
70✔
1677
         break;
70✔
1678
      case VCODE_OP_RELEASE:
42✔
1679
         import_release(mu, imp, i);
42✔
1680
         break;
42✔
1681
      case VCODE_OP_DISCONNECT:
24✔
1682
         import_disconnect(mu, imp, i);
24✔
1683
         break;
24✔
1684
      case VCODE_OP_EXPONENT_CHECK:
364✔
1685
         import_exponent_check(mu, imp, i);
364✔
1686
         break;
364✔
1687
      case VCODE_OP_PROCESS_INIT:
117✔
1688
         import_process_init(mu, imp, i);
117✔
1689
         break;
117✔
1690
      case VCODE_OP_COVER_STMT:
1,300✔
1691
         import_cover_stmt(mu, imp, i);
1,300✔
1692
         break;
1,300✔
1693
      case VCODE_OP_COVER_BRANCH:
499✔
1694
         import_cover_branch(mu, imp, i);
499✔
1695
         break;
499✔
1696
      case VCODE_OP_COVER_EXPR:
887✔
1697
         import_cover_expr(mu, imp, i);
887✔
1698
         break;
887✔
1699
      case VCODE_OP_COVER_TOGGLE:
312✔
1700
         import_cover_toggle(mu, imp, i);
312✔
1701
         break;
312✔
1702
      case VCODE_OP_COVER_STATE:
12✔
1703
         import_cover_state(mu, imp, i);
12✔
1704
         break;
12✔
1705
      case VCODE_OP_ARRAY_SCOPE:
654✔
1706
         import_array_scope(mu, imp, i);
654✔
1707
         break;
654✔
1708
      case VCODE_OP_PACKAGE_SCOPE:
45✔
1709
         import_package_scope(mu, imp, i);
45✔
1710
         break;
45✔
1711
      case VCODE_OP_RECORD_SCOPE:
1,690✔
1712
         import_record_scope(mu, imp, i);
1,690✔
1713
         break;
1,690✔
1714
      case VCODE_OP_POP_SCOPE:
2,389✔
1715
         import_pop_scope(mu, imp, i);
2,389✔
1716
         break;
2,389✔
1717
      case VCODE_OP_CMP_TRIGGER:
47✔
1718
         import_cmp_trigger(mu, imp, i);
47✔
1719
         break;
47✔
1720
      case VCODE_OP_FUNCTION_TRIGGER:
199✔
1721
         import_function_trigger(mu, imp, i);
199✔
1722
         break;
199✔
1723
      case VCODE_OP_OR_TRIGGER:
34✔
1724
         import_or_trigger(mu, imp, i);
34✔
1725
         break;
34✔
1726
      case VCODE_OP_ADD_TRIGGER:
368✔
1727
         import_add_trigger(mu, imp, i);
368✔
1728
         break;
368✔
1729
      case VCODE_OP_PROTECTED_INIT:
544✔
1730
         import_protected_init(mu, imp, i);
544✔
1731
         break;
544✔
1732
      case VCODE_OP_PROTECTED_FREE:
1733
         break;   // No-op
1734
      case VCODE_OP_INSTANCE_NAME:
767✔
1735
         import_instance_name(mu, imp, i);
767✔
1736
         break;
767✔
1737
      case VCODE_OP_LAST_EVENT:
42✔
1738
         import_last_event(mu, imp, i);
42✔
1739
         break;
42✔
1740
      case VCODE_OP_LAST_ACTIVE:
45✔
1741
         import_last_active(mu, imp, i);
45✔
1742
         break;
45✔
1743
      case VCODE_OP_LAST_VALUE:
186✔
1744
         import_last_value(mu, imp, i);
186✔
1745
         break;
186✔
1746
      case VCODE_OP_ENTER_STATE:
849✔
1747
         import_enter_state(mu, imp, i);
849✔
1748
         break;
849✔
1749
      case VCODE_OP_REFLECT_SUBTYPE:
42✔
1750
         import_reflect_subtype(mu, imp, i);
42✔
1751
         break;
42✔
1752
      case VCODE_OP_REFLECT_VALUE:
48✔
1753
         import_reflect_value(mu, imp, i);
48✔
1754
         break;
48✔
UNCOV
1755
      case VCODE_OP_DEBUG_OUT:
×
UNCOV
1756
         import_debug_out(mu, imp, i);
×
UNCOV
1757
         break;
×
1758
      case VCODE_OP_SCHED_PROCESS:
5,267✔
1759
         import_sched_process(mu, imp, i);
5,267✔
1760
         break;
5,267✔
UNCOV
1761
      default:
×
UNCOV
1762
         vcode_dump_with_mark(i, NULL, NULL);
×
1763
         fatal_trace("cannot import vcode op %s",
1764
                     vcode_op_string(vcode_get_op(i)));
1765
      }
1766
   }
1767
}
137,655✔
1768

1769
mir_unit_t *mir_import(mir_context_t *mc, vcode_unit_t vu)
50,752✔
1770
{
1771
   static const mir_unit_kind_t kind_map[] = {
50,752✔
1772
      [VCODE_UNIT_FUNCTION] = MIR_UNIT_FUNCTION,
1773
      [VCODE_UNIT_INSTANCE] = MIR_UNIT_INSTANCE,
1774
      [VCODE_UNIT_PROCEDURE] = MIR_UNIT_PROCEDURE,
1775
      [VCODE_UNIT_PROCESS] = MIR_UNIT_PROCESS,
1776
      [VCODE_UNIT_PACKAGE] = MIR_UNIT_PACKAGE,
1777
      [VCODE_UNIT_THUNK] = MIR_UNIT_THUNK,
1778
      [VCODE_UNIT_PROTECTED] = MIR_UNIT_PROTECTED,
1779
      [VCODE_UNIT_PROPERTY] = MIR_UNIT_PROPERTY,
1780
   };
1781

1782
   const mir_unit_kind_t kind = kind_map[vcode_unit_kind(vu)];
50,752✔
1783

1784
   mir_shape_t *parent = NULL;
50,752✔
1785
   vcode_unit_t context = vcode_unit_context(vu);
50,752✔
1786
   if (context != NULL) {
50,752✔
1787
      ident_t name = vcode_unit_name(context);
27,648✔
1788
      if ((parent = mir_get_shape(mc, name)) == NULL) {
27,648✔
1789
         mir_unit_t *parent_mu = mir_import(mc, context);
×
1790
         mir_put_unit(mc, parent_mu);
×
1791

UNCOV
1792
         parent = mir_get_shape(mc, name);
×
UNCOV
1793
         assert(parent != NULL);
×
1794
      }
1795
   }
1796

1797
   ident_t name = vcode_unit_name(vu);
50,752✔
1798
   object_t *obj = vcode_unit_object(vu);
50,752✔
1799

1800
   mir_unit_t *mu = mir_unit_new(mc, name, obj, kind, parent);
50,752✔
1801

1802
   vcode_select_unit(vu);
50,752✔
1803

1804
   const int nblocks = vcode_count_blocks();
50,752✔
1805
   const int nregs = vcode_count_regs();
50,752✔
1806
   const int nvars = vcode_count_vars();
50,752✔
1807

1808
   mir_import_t imp = {};
50,752✔
1809
   imp.blocks = xcalloc_array(nblocks, sizeof(mir_block_t));
50,752✔
1810
   imp.map    = xcalloc_array(nregs, sizeof(mir_value_t));
50,752✔
1811
   imp.vars   = xcalloc_array(nvars, sizeof(mir_value_t));
50,752✔
1812
   imp.types  = ihash_new(64);
50,752✔
1813

1814
   switch (kind) {
50,752✔
1815
   case MIR_UNIT_FUNCTION:
12,293✔
1816
      {
1817
         vcode_type_t vresult = vcode_unit_result(vu);
12,293✔
1818
         if (vresult != VCODE_INVALID_TYPE)
12,293✔
1819
            mir_set_result(mu, import_type(mu, &imp, vresult));
10,023✔
1820
      }
1821
      // Fall-through
1822
   case MIR_UNIT_PROCEDURE:
1823
   case MIR_UNIT_PROTECTED:
1824
   case MIR_UNIT_PROPERTY:
1825
      {
1826
         const int nparams = vcode_count_params();
13,283✔
1827
         for (int i = 0; i < nparams; i++) {
44,707✔
1828
            vcode_reg_t preg = vcode_param_reg(i);
31,424✔
1829
            mir_type_t type = import_type(mu, &imp, vcode_param_type(i));
31,424✔
1830
            ident_t name = vcode_param_name(i);
31,424✔
1831
            imp.map[preg] = mir_add_param(mu, type, MIR_NULL_STAMP, name);
31,424✔
1832
         }
1833
      }
1834
      break;
1835
   case MIR_UNIT_THUNK:
11,106✔
1836
      mir_set_result(mu, import_type(mu, &imp, vcode_unit_result(vu)));
11,106✔
1837
      break;
11,106✔
1838
   default:
1839
      break;
1840
   }
1841

1842
   for (int i = 0; i < nvars; i++) {
121,417✔
1843
      mir_type_t type = import_type(mu, &imp, vcode_var_type(i));
70,665✔
1844
      imp.vars[i] = mir_add_var(mu, type, MIR_NULL_STAMP, vcode_var_name(i),
70,665✔
1845
                                (mir_var_flags_t)vcode_var_flags(i));
70,665✔
1846
   }
1847

1848
   imp.blocks[0] = mir_get_cursor(mu, NULL);
50,752✔
1849
   for (int i = 1; i < nblocks; i++)
137,655✔
1850
      imp.blocks[i] = mir_add_block(mu);
86,903✔
1851

1852
   for (int i = 0; i < nblocks; i++) {
188,407✔
1853
      vcode_select_block(i);
137,655✔
1854
      mir_set_cursor(mu, imp.blocks[i], MIR_APPEND);
137,655✔
1855
      import_block(mu, &imp);
137,655✔
1856
   }
1857

1858
   ihash_free(imp.types);
50,752✔
1859
   free(imp.blocks);
50,752✔
1860
   free(imp.map);
50,752✔
1861
   free(imp.vars);
50,752✔
1862

1863
   mir_optimise(mu, MIR_PASS_O0);
50,752✔
1864
   return mu;
50,752✔
1865
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc