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

nickg / nvc / 21458432965

28 Jan 2026 10:49PM UTC coverage: 92.632% (+0.02%) from 92.616%
21458432965

Pull #1384

github

web-flow
Merge a7f274965 into 71ebda0ca
Pull Request #1384: Random signal initialization plugin.

17 of 34 new or added lines in 1 file covered. (50.0%)

1096 existing lines in 29 files now uncovered.

76515 of 82601 relevant lines covered (92.63%)

444886.01 hits per line

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

98.47
/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,
826,643✔
36
                              vcode_type_t vtype)
37
{
38
   void *ptr = ihash_get(imp->types, vtype);
826,643✔
39
   if (ptr != NULL)
826,643✔
40
      return (mir_type_t){ .bits = (uintptr_t)ptr };
634,751✔
41

42
   mir_type_t type;
191,892✔
43
   switch (vtype_kind(vtype)) {
191,892✔
44
   case VCODE_TYPE_INT:
82,779✔
45
      type = mir_int_type(mu, vtype_low(vtype), vtype_high(vtype));
82,779✔
46
      break;
82,779✔
47
   case VCODE_TYPE_REAL:
8,271✔
48
      type = mir_real_type(mu, -DBL_MAX, DBL_MAX);
8,271✔
49
      break;
8,271✔
50
   case VCODE_TYPE_OFFSET:
23,280✔
51
      type = mir_offset_type(mu);
23,280✔
52
      break;
23,280✔
53
   case VCODE_TYPE_SIGNAL:
9,209✔
54
      type = mir_signal_type(mu, import_type(mu, imp, vtype_base(vtype)));
9,209✔
55
      break;
9,209✔
56
   case VCODE_TYPE_UARRAY:
13,036✔
57
      type = mir_uarray_type(mu, vtype_dims(vtype),
13,036✔
58
                             import_type(mu, imp, vtype_elem(vtype)));
59
      break;
13,036✔
60
   case VCODE_TYPE_CARRAY:
22,294✔
61
      type = mir_carray_type(mu, vtype_size(vtype),
22,294✔
62
                             import_type(mu, imp, vtype_elem(vtype)));
63
      break;
22,294✔
64
   case VCODE_TYPE_CONTEXT:
12,900✔
65
      type = mir_context_type(mu, vtype_name(vtype));
12,900✔
66
      break;
12,900✔
67
   case VCODE_TYPE_ACCESS:
2,137✔
68
      type = mir_access_type(mu, import_type(mu, imp, vtype_pointed(vtype)));
2,137✔
69
      break;
2,137✔
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,791✔
81
      {
82
         const int nfields = vtype_fields(vtype);
5,791✔
83
         mir_type_t *fields LOCAL = xmalloc_array(nfields, sizeof(mir_type_t));
11,582✔
84
         for (int i = 0; i < nfields; i++)
24,975✔
85
            fields[i] = import_type(mu, imp, vtype_field(vtype, i));
19,184✔
86

87
         type = mir_record_type(mu, vtype_name(vtype), fields, nfields);
5,791✔
88
      }
89
      break;
5,791✔
90
   case VCODE_TYPE_POINTER:
7,591✔
91
      type = mir_pointer_type(mu, import_type(mu, imp, vtype_pointed(vtype)));
7,591✔
92
      break;
7,591✔
93
   case VCODE_TYPE_FILE:
990✔
94
      type = mir_file_type(mu, import_type(mu, imp, vtype_base(vtype)));
990✔
95
      break;
990✔
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,568✔
106
      type = mir_resolution_type(mu, import_type(mu, imp, vtype_base(vtype)));
2,568✔
107
      break;
2,568✔
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);
191,892✔
114
   return type;
191,892✔
115
}
116

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

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

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

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

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

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

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

151
   mir_build_return(mu, result);
54,945✔
152
}
54,945✔
153

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

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

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

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

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

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

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

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

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

209
   const int nargs = vcode_count_args(op);
29,993✔
210
   mir_value_t *elts LOCAL = xmalloc_array(nargs, sizeof(mir_value_t));
59,986✔
211
   for (int i = 0; i < nargs; i++)
1,682,729✔
212
      elts[i] = imp->map[vcode_get_arg(op, i)];
1,652,736✔
213

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

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

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

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

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

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

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

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

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

255
static void import_assert(mir_unit_t *mu, mir_import_t *imp, int op)
14,618✔
256
{
257
   mir_value_t value    = imp->map[vcode_get_arg(op, 0)];
14,618✔
258
   mir_value_t severity = imp->map[vcode_get_arg(op, 1)];
14,618✔
259
   mir_value_t locus    = imp->map[vcode_get_arg(op, 4)];
14,618✔
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,618✔
263
   if (vcode_get_arg(op, 2) != VCODE_INVALID_REG) {
14,618✔
264
      msg    = imp->map[vcode_get_arg(op, 2)];
3,456✔
265
      length = imp->map[vcode_get_arg(op, 3)];
3,456✔
266
   }
267

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

342
   imp->map[result] = mir_build_init_signal(mu, type, count, size,
16,314✔
343
                                            value, flags, locus, offset);
344
}
16,314✔
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,112✔
363
{
364
   mir_value_t target = imp->map[vcode_get_arg(op, 0)];
7,112✔
365
   mir_value_t count  = imp->map[vcode_get_arg(op, 1)];
7,112✔
366

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

560
   imp->map[result] = mir_build_div(mu, type, left, right);
1,659✔
561
}
1,659✔
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)
955✔
575
{
576
   vcode_reg_t result = vcode_get_result(op);
955✔
577

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

582
   imp->map[result] = mir_build_rem(mu, type, left, right);
955✔
583
}
955✔
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,078✔
609
{
610
   mir_value_t left  = imp->map[vcode_get_arg(op, 0)];
2,078✔
611
   mir_value_t right = imp->map[vcode_get_arg(op, 1)];
2,078✔
612

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

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

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

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

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

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

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

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

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

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

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

659
static void import_event(mir_unit_t *mu, mir_import_t *imp, int op)
438✔
660
{
661
   mir_value_t signal = imp->map[vcode_get_arg(op, 0)];
438✔
662
   mir_value_t count  = imp->map[vcode_get_arg(op, 1)];
438✔
663
   imp->map[vcode_get_result(op)] = mir_build_event_flag(mu, signal, count);
438✔
664
}
438✔
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,459✔
681
{
682
   mir_value_t arg = imp->map[vcode_get_arg(op, 0)];
2,459✔
683
   imp->map[vcode_get_result(op)] = mir_build_not(mu, arg);
2,459✔
684
}
2,459✔
685

686
static void import_cast(mir_unit_t *mu, mir_import_t *imp, int op)
53,650✔
687
{
688
   mir_value_t arg = imp->map[vcode_get_arg(op, 0)];
53,650✔
689
   mir_type_t type = import_type(mu, imp, vcode_get_type(op));
53,650✔
690
   imp->map[vcode_get_result(op)] = mir_build_cast(mu, type, arg);
53,650✔
691
}
53,650✔
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)
691✔
711
{
712
   vcode_reg_t result = vcode_get_result(op);
691✔
713
   mir_value_t arg = imp->map[vcode_get_arg(op, 0)];
691✔
714
   mir_type_t type = import_type(mu, imp, vcode_reg_type(result));
691✔
715
   imp->map[result] = mir_build_abs(mu, type, arg);
691✔
716
}
691✔
717

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

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

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

733
   mir_build_copy(mu, dst, src, count);
25,195✔
734
}
25,195✔
735

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

928
   mir_build_map_const(mu, src, dst, count);
201✔
929
}
201✔
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,029✔
941
{
942
   mir_value_t spec = imp->map[vcode_get_arg(op, 0)];
1,029✔
943
   mir_value_t length = imp->map[vcode_get_arg(op, 1)];
1,029✔
944

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

949
   mir_build_bind_foreign(mu, spec, length, locus);
1,029✔
950
}
1,029✔
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,381✔
971
{
972
   mir_value_t locus = MIR_NULL_VALUE;
1,381✔
973
   if (vcode_count_args(op) > 0)
1,381✔
974
      locus = imp->map[vcode_get_arg(op, 0)];
121✔
975

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

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

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

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

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

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

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

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

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

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

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

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

1029
   mir_build_transfer_signal(mu, target, source, count, reject, after);
497✔
1030
}
497✔
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)
267✔
1063
{
1064
   mir_value_t file = imp->map[vcode_get_arg(op, 0)];
267✔
1065
   mir_value_t value = imp->map[vcode_get_arg(op, 1)];
267✔
1066

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

1071
   mir_build_file_write(mu, file, value, length);
267✔
1072
}
267✔
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,195✔
1169
{
1170
   mir_value_t counters = imp->map[vcode_get_arg(op, 0)];
1,195✔
1171
   mir_build_cover_stmt(mu, counters, vcode_get_tag(op));
1,195✔
1172
}
1,195✔
1173

1174
static void import_cover_branch(mir_unit_t *mu, mir_import_t *imp, int op)
509✔
1175
{
1176
   mir_value_t counters = imp->map[vcode_get_arg(op, 0)];
509✔
1177
   mir_build_cover_branch(mu, counters, vcode_get_tag(op));
509✔
1178
}
509✔
1179

1180
static void import_cover_expr(mir_unit_t *mu, mir_import_t *imp, int op)
855✔
1181
{
1182
   mir_value_t counters = imp->map[vcode_get_arg(op, 0)];
855✔
1183
   mir_build_cover_expr(mu, counters, vcode_get_tag(op));
855✔
1184
}
855✔
1185

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

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

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

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

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

1219
static void import_pop_scope(mir_unit_t *mu, mir_import_t *imp, int op)
2,417✔
1220
{
1221
   mir_build_pop_scope(mu);
2,417✔
1222
}
2,417✔
1223

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

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

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

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

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

1256
static void import_protected_init(mir_unit_t *mu, mir_import_t *imp, int op)
550✔
1257
{
1258
   mir_value_t context = imp->map[vcode_get_arg(op, 0)];
550✔
1259

1260
   mir_value_t path_name = MIR_NULL_VALUE, inst_name = MIR_NULL_VALUE;
550✔
1261
   if (vcode_count_args(op) > 1) {
550✔
1262
      path_name = imp->map[vcode_get_arg(op, 1)];
420✔
1263
      inst_name = imp->map[vcode_get_arg(op, 2)];
420✔
1264
   }
1265

1266
   vcode_reg_t result = vcode_get_result(op);
550✔
1267
   mir_type_t type = import_type(mu, imp, vcode_reg_type(result));
550✔
1268

1269
   imp->map[result] = mir_build_protected_init(mu, type, context,
550✔
1270
                                               path_name, inst_name);
1271
}
550✔
1272

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

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

1283
   mir_value_t count = MIR_NULL_VALUE;
42✔
1284
   if (vcode_count_args(op) > 1)
42✔
1285
      count = imp->map[vcode_get_arg(op, 1)];
9✔
1286

1287
   imp->map[vcode_get_result(op)] = mir_build_last_event(mu, signal, count);
42✔
1288
}
42✔
1289

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

1294
   mir_value_t count = MIR_NULL_VALUE;
45✔
1295
   if (vcode_count_args(op) > 1)
45✔
1296
      count = imp->map[vcode_get_arg(op, 1)];
6✔
1297

1298
   imp->map[vcode_get_result(op)] = mir_build_last_active(mu, signal, count);
45✔
1299
}
45✔
1300

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

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

1311
   mir_value_t strong = MIR_NULL_VALUE;
849✔
1312
   if (vcode_count_args(op) > 1)
849✔
1313
      strong = imp->map[vcode_get_arg(op, 1)];
36✔
1314

1315
   mir_build_enter_state(mu, state, strong);
849✔
1316
}
849✔
1317

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

1324
   mir_value_t bounds = MIR_NULL_VALUE;
48✔
1325
   if (vcode_count_args(op) > 3)
48✔
1326
      bounds = imp->map[vcode_get_arg(op, 3)];
6✔
1327

1328
   imp->map[vcode_get_result(op)] =
48✔
1329
      mir_build_reflect_value(mu, value, context, locus, bounds);
48✔
1330
}
48✔
1331

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

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

1341
   imp->map[vcode_get_result(op)] =
42✔
1342
      mir_build_reflect_subtype(mu, context, locus, bounds);
42✔
1343
}
42✔
1344

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

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

1357
static void import_get_counters(mir_unit_t *mu, mir_import_t *imp, int op)
679✔
1358
{
1359
   ident_t block = vcode_get_ident(op);
679✔
1360
   imp->map[vcode_get_result(op)] = mir_build_get_counters(mu, block);
679✔
1361
}
679✔
1362

1363
static void import_block(mir_unit_t *mu, mir_import_t *imp)
137,230✔
1364
{
1365
   const int nops = vcode_count_ops();
137,230✔
1366
   for (int i = 0; i < nops; i++) {
1,921,673✔
1367
      mir_set_loc(mu, vcode_get_loc(i));
1,784,443✔
1368

1369
      switch (vcode_get_op(i)) {
1,784,443✔
1370
      case VCODE_OP_COMMENT:
1371
         break;
1372
      case VCODE_OP_PACKAGE_INIT:
21,911✔
1373
         import_package_init(mu, imp, i);
21,911✔
1374
         break;
21,911✔
1375
      case VCODE_OP_LINK_PACKAGE:
6,734✔
1376
         import_link_package(mu, imp, i);
6,734✔
1377
         break;
6,734✔
1378
      case VCODE_OP_LINK_VAR:
4,854✔
1379
         import_link_var(mu, imp, i);
4,854✔
1380
         break;
4,854✔
1381
      case VCODE_OP_RETURN:
54,945✔
1382
         import_return(mu, imp, i);
54,945✔
1383
         break;
54,945✔
1384
      case VCODE_OP_FCALL:
34,227✔
1385
         import_fcall(mu, imp, i);
34,227✔
1386
         break;
34,227✔
1387
      case VCODE_OP_PCALL:
847✔
1388
         import_pcall(mu, imp, i);
847✔
1389
         break;
847✔
1390
      case VCODE_OP_RESUME:
847✔
1391
         import_resume(mu, imp, i);
847✔
1392
         break;
847✔
1393
      case VCODE_OP_CONST:
367,186✔
1394
         import_const(mu, imp, i);
367,186✔
1395
         break;
367,186✔
1396
      case VCODE_OP_CONST_REAL:
22,257✔
1397
         import_const_real(mu, imp, i);
22,257✔
1398
         break;
22,257✔
1399
      case VCODE_OP_CONST_ARRAY:
29,993✔
1400
         import_const_array(mu, imp, i);
29,993✔
1401
         break;
29,993✔
1402
      case VCODE_OP_CONST_REP:
272✔
1403
         import_const_rep(mu, imp, i);
272✔
1404
         break;
272✔
1405
      case VCODE_OP_CONST_RECORD:
2,026✔
1406
         import_const_record(mu, imp, i);
2,026✔
1407
         break;
2,026✔
1408
      case VCODE_OP_CMP:
33,576✔
1409
         import_cmp(mu, imp, i);
33,576✔
1410
         break;
33,576✔
1411
      case VCODE_OP_DEBUG_LOCUS:
77,875✔
1412
         import_debug_locus(mu, imp, i);
77,875✔
1413
         break;
77,875✔
1414
      case VCODE_OP_ASSERT:
14,618✔
1415
         import_assert(mu, imp, i);
14,618✔
1416
         break;
14,618✔
1417
      case VCODE_OP_REPORT:
2,101✔
1418
         import_report(mu, imp, i);
2,101✔
1419
         break;
2,101✔
1420
      case VCODE_OP_WAIT:
12,733✔
1421
         import_wait(mu, imp, i);
12,733✔
1422
         break;
12,733✔
1423
      case VCODE_OP_JUMP:
36,007✔
1424
         import_jump(mu, imp, i);
36,007✔
1425
         break;
36,007✔
1426
      case VCODE_OP_COND:
30,666✔
1427
         import_cond(mu, imp, i);
30,666✔
1428
         break;
30,666✔
1429
      case VCODE_OP_INIT_SIGNAL:
16,314✔
1430
         import_init_signal(mu, imp, i);
16,314✔
1431
         break;
16,314✔
1432
      case VCODE_OP_IMPLICIT_SIGNAL:
75✔
1433
         import_implicit_signal(mu, imp, i);
75✔
1434
         break;
75✔
1435
      case VCODE_OP_DRIVE_SIGNAL:
7,112✔
1436
         import_drive_signal(mu, imp, i);
7,112✔
1437
         break;
7,112✔
1438
      case VCODE_OP_SCHED_WAVEFORM:
9,049✔
1439
         import_sched_waveform(mu, imp, i);
9,049✔
1440
         break;
9,049✔
1441
      case VCODE_OP_RESOLVED:
12,824✔
1442
         import_resolved(mu, imp, i);
12,824✔
1443
         break;
12,824✔
1444
      case VCODE_OP_ADDRESS_OF:
31,288✔
1445
         import_address_of(mu, imp, i);
31,288✔
1446
         break;
31,288✔
1447
      case VCODE_OP_STORE:
76,290✔
1448
         import_store(mu, imp, i);
76,290✔
1449
         break;
76,290✔
1450
      case VCODE_OP_STORE_INDIRECT:
14,998✔
1451
         import_store_indirect(mu, imp, i);
14,998✔
1452
         break;
14,998✔
1453
      case VCODE_OP_LOAD:
38,525✔
1454
         import_load(mu, imp, i);
38,525✔
1455
         break;
38,525✔
1456
      case VCODE_OP_LOAD_INDIRECT:
83,490✔
1457
         import_load_indirect(mu, imp, i);
83,490✔
1458
         break;
83,490✔
1459
      case VCODE_OP_CONTEXT_UPREF:
10,914✔
1460
         import_context_upref(mu, imp, i);
10,914✔
1461
         break;
10,914✔
1462
      case VCODE_OP_VAR_UPREF:
43,907✔
1463
         import_var_upref(mu, imp, i);
43,907✔
1464
         break;
43,907✔
1465
      case VCODE_OP_WRAP:
29,811✔
1466
         import_wrap(mu, imp, i);
29,811✔
1467
         break;
29,811✔
1468
      case VCODE_OP_UNWRAP:
25,279✔
1469
         import_unwrap(mu, imp, i);
25,279✔
1470
         break;
25,279✔
1471
      case VCODE_OP_UARRAY_LEN:
19,487✔
1472
         import_uarray_len(mu, imp, i);
19,487✔
1473
         break;
19,487✔
1474
      case VCODE_OP_UARRAY_LEFT:
15,892✔
1475
         import_uarray_left(mu, imp, i);
15,892✔
1476
         break;
15,892✔
1477
      case VCODE_OP_UARRAY_RIGHT:
13,020✔
1478
         import_uarray_right(mu, imp, i);
13,020✔
1479
         break;
13,020✔
1480
      case VCODE_OP_UARRAY_DIR:
15,845✔
1481
         import_uarray_dir(mu, imp, i);
15,845✔
1482
         break;
15,845✔
1483
      case VCODE_OP_ADD:
12,816✔
1484
         import_add(mu, imp, i);
12,816✔
1485
         break;
12,816✔
1486
      case VCODE_OP_TRAP_ADD:
4,861✔
1487
         import_trap_add(mu, imp, i);
4,861✔
1488
         break;
4,861✔
1489
      case VCODE_OP_SUB:
27,534✔
1490
         import_sub(mu, imp, i);
27,534✔
1491
         break;
27,534✔
1492
      case VCODE_OP_TRAP_SUB:
1,681✔
1493
         import_trap_sub(mu, imp, i);
1,681✔
1494
         break;
1,681✔
1495
      case VCODE_OP_MUL:
2,854✔
1496
         import_mul(mu, imp, i);
2,854✔
1497
         break;
2,854✔
1498
      case VCODE_OP_TRAP_MUL:
913✔
1499
         import_trap_mul(mu, imp, i);
913✔
1500
         break;
913✔
1501
      case VCODE_OP_DIV:
1,659✔
1502
         import_div(mu, imp, i);
1,659✔
1503
         break;
1,659✔
1504
      case VCODE_OP_MOD:
103✔
1505
         import_mod(mu, imp, i);
103✔
1506
         break;
103✔
1507
      case VCODE_OP_REM:
955✔
1508
         import_rem(mu, imp, i);
955✔
1509
         break;
955✔
1510
      case VCODE_OP_EXP:
134✔
1511
         import_exp(mu, imp, i);
134✔
1512
         break;
134✔
1513
      case VCODE_OP_TRAP_EXP:
370✔
1514
         import_trap_exp(mu, imp, i);
370✔
1515
         break;
370✔
1516
      case VCODE_OP_OR:
2,078✔
1517
         import_or(mu, imp, i);
2,078✔
1518
         break;
2,078✔
1519
      case VCODE_OP_NOR:
35✔
1520
         import_nor(mu, imp, i);
35✔
1521
         break;
35✔
1522
      case VCODE_OP_XOR:
55✔
1523
         import_xor(mu, imp, i);
55✔
1524
         break;
55✔
1525
      case VCODE_OP_XNOR:
37✔
1526
         import_xnor(mu, imp, i);
37✔
1527
         break;
37✔
1528
      case VCODE_OP_AND:
4,690✔
1529
         import_and(mu, imp, i);
4,690✔
1530
         break;
4,690✔
1531
      case VCODE_OP_NAND:
34✔
1532
         import_nand(mu, imp, i);
34✔
1533
         break;
34✔
1534
      case VCODE_OP_EVENT:
438✔
1535
         import_event(mu, imp, i);
438✔
1536
         break;
438✔
1537
      case VCODE_OP_ACTIVE:
217✔
1538
         import_active(mu, imp, i);
217✔
1539
         break;
217✔
1540
      case VCODE_OP_DRIVING:
36✔
1541
         import_driving(mu, imp, i);
36✔
1542
         break;
36✔
1543
      case VCODE_OP_NOT:
2,459✔
1544
         import_not(mu, imp, i);
2,459✔
1545
         break;
2,459✔
1546
      case VCODE_OP_CAST:
53,650✔
1547
         import_cast(mu, imp, i);
53,650✔
1548
         break;
53,650✔
1549
      case VCODE_OP_NEG:
6,971✔
1550
         import_neg(mu, imp, i);
6,971✔
1551
         break;
6,971✔
1552
      case VCODE_OP_TRAP_NEG:
257✔
1553
         import_trap_neg(mu, imp, i);
257✔
1554
         break;
257✔
1555
      case VCODE_OP_ABS:
691✔
1556
         import_abs(mu, imp, i);
691✔
1557
         break;
691✔
1558
      case VCODE_OP_INDEX:
25,890✔
1559
         import_index(mu, imp, i);
25,890✔
1560
         break;
25,890✔
1561
      case VCODE_OP_COPY:
25,195✔
1562
         import_copy(mu, imp, i);
25,195✔
1563
         break;
25,195✔
1564
      case VCODE_OP_MEMSET:
5,487✔
1565
         import_memset(mu, imp, i);
5,487✔
1566
         break;
5,487✔
1567
      case VCODE_OP_ARRAY_REF:
31,493✔
1568
         import_array_ref(mu, imp, i);
31,493✔
1569
         break;
31,493✔
1570
      case VCODE_OP_TABLE_REF:
694✔
1571
         import_table_ref(mu, imp, i);
694✔
1572
         break;
694✔
1573
      case VCODE_OP_RECORD_REF:
33,243✔
1574
         import_record_ref(mu, imp, i);
33,243✔
1575
         break;
33,243✔
1576
      case VCODE_OP_RANGE_CHECK:
3,825✔
1577
         import_range_check(mu, imp, i);
3,825✔
1578
         break;
3,825✔
1579
      case VCODE_OP_SCHED_EVENT:
4,322✔
1580
         import_sched_event(mu, imp, i);
4,322✔
1581
         break;
4,322✔
1582
      case VCODE_OP_CLEAR_EVENT:
548✔
1583
         import_clear_event(mu, imp, i);
548✔
1584
         break;
548✔
1585
      case VCODE_OP_ALLOC:
7,241✔
1586
         import_alloc(mu, imp, i);
7,241✔
1587
         break;
7,241✔
1588
      case VCODE_OP_RANGE_LENGTH:
7,097✔
1589
         import_range_length(mu, imp, i);
7,097✔
1590
         break;
7,097✔
1591
      case VCODE_OP_RANGE_NULL:
3,023✔
1592
         import_range_null(mu, imp, i);
3,023✔
1593
         break;
3,023✔
1594
      case VCODE_OP_NULL:
4,012✔
1595
         import_null(mu, imp, i);
4,012✔
1596
         break;
4,012✔
1597
      case VCODE_OP_NEW:
654✔
1598
         import_new(mu, imp, i);
654✔
1599
         break;
654✔
1600
      case VCODE_OP_ALL:
2,853✔
1601
         import_all(mu, imp, i);
2,853✔
1602
         break;
2,853✔
1603
      case VCODE_OP_DEALLOCATE:
347✔
1604
         import_deallocate(mu, imp, i);
347✔
1605
         break;
347✔
1606
      case VCODE_OP_ZERO_CHECK:
88✔
1607
         import_zero_check(mu, imp, i);
88✔
1608
         break;
88✔
1609
      case VCODE_OP_NULL_CHECK:
2,199✔
1610
         import_null_check(mu, imp, i);
2,199✔
1611
         break;
2,199✔
1612
      case VCODE_OP_LENGTH_CHECK:
7,299✔
1613
         import_length_check(mu, imp, i);
7,299✔
1614
         break;
7,299✔
1615
      case VCODE_OP_INDEX_CHECK:
14,990✔
1616
         import_index_check(mu, imp, i);
14,990✔
1617
         break;
14,990✔
1618
      case VCODE_OP_DIR_CHECK:
2,380✔
1619
         import_dir_check(mu, imp, i);
2,380✔
1620
         break;
2,380✔
1621
      case VCODE_OP_ALIAS_SIGNAL:
4,302✔
1622
         import_alias_signal(mu, imp, i);
4,302✔
1623
         break;
4,302✔
1624
      case VCODE_OP_MAP_SIGNAL:
5,456✔
1625
         import_map_signal(mu, imp, i);
5,456✔
1626
         break;
5,456✔
1627
      case VCODE_OP_MAP_CONST:
201✔
1628
         import_map_const(mu, imp, i);
201✔
1629
         break;
201✔
1630
      case VCODE_OP_MAP_IMPLICIT:
57✔
1631
         import_map_implicit(mu, imp, i);
57✔
1632
         break;
57✔
1633
      case VCODE_OP_CASE:
651✔
1634
         import_case(mu, imp, i);
651✔
1635
         break;
651✔
1636
      case VCODE_OP_BIND_FOREIGN:
1,029✔
1637
         import_bind_foreign(mu, imp, i);
1,029✔
1638
         break;
1,029✔
1639
      case VCODE_OP_BIND_EXTERNAL:
180✔
1640
         import_bind_external(mu, imp, i);
180✔
1641
         break;
180✔
1642
      case VCODE_OP_UNREACHABLE:
1,381✔
1643
         import_unreachable(mu, imp, i);
1,381✔
1644
         break;
1,381✔
1645
      case VCODE_OP_SELECT:
12,559✔
1646
         import_select(mu, imp, i);
12,559✔
1647
         break;
12,559✔
1648
      case VCODE_OP_CLOSURE:
5,510✔
1649
         import_closure(mu, imp, i);
5,510✔
1650
         break;
5,510✔
1651
      case VCODE_OP_RESOLUTION_WRAPPER:
5,213✔
1652
         import_resolution_wrapper(mu, imp, i);
5,213✔
1653
         break;
5,213✔
1654
      case VCODE_OP_RESOLVE_SIGNAL:
3,406✔
1655
         import_resolve_signal(mu, imp, i);
3,406✔
1656
         break;
3,406✔
1657
      case VCODE_OP_TRANSFER_SIGNAL:
497✔
1658
         import_transfer_signal(mu, imp, i);
497✔
1659
         break;
497✔
1660
      case VCODE_OP_FILE_OPEN:
1,236✔
1661
         import_file_open(mu, imp, i);
1,236✔
1662
         break;
1,236✔
1663
      case VCODE_OP_FILE_READ:
90✔
1664
         import_file_read(mu, imp, i);
90✔
1665
         break;
90✔
1666
      case VCODE_OP_FILE_WRITE:
267✔
1667
         import_file_write(mu, imp, i);
267✔
1668
         break;
267✔
1669
      case VCODE_OP_PORT_CONVERSION:
204✔
1670
         import_port_conversion(mu, imp, i);
204✔
1671
         break;
204✔
1672
      case VCODE_OP_CONVERT_IN:
282✔
1673
         import_convert_in(mu, imp, i);
282✔
1674
         break;
282✔
1675
      case VCODE_OP_CONVERT_OUT:
324✔
1676
         import_convert_out(mu, imp, i);
324✔
1677
         break;
324✔
1678
      case VCODE_OP_DRIVING_VALUE:
120✔
1679
         import_driving_value(mu, imp, i);
120✔
1680
         break;
120✔
1681
      case VCODE_OP_PUT_CONVERSION:
342✔
1682
         import_put_conversion(mu, imp, i);
342✔
1683
         break;
342✔
1684
      case VCODE_OP_FORCE:
70✔
1685
         import_force(mu, imp, i);
70✔
1686
         break;
70✔
1687
      case VCODE_OP_RELEASE:
42✔
1688
         import_release(mu, imp, i);
42✔
1689
         break;
42✔
1690
      case VCODE_OP_DISCONNECT:
24✔
1691
         import_disconnect(mu, imp, i);
24✔
1692
         break;
24✔
1693
      case VCODE_OP_EXPONENT_CHECK:
364✔
1694
         import_exponent_check(mu, imp, i);
364✔
1695
         break;
364✔
1696
      case VCODE_OP_PROCESS_INIT:
117✔
1697
         import_process_init(mu, imp, i);
117✔
1698
         break;
117✔
1699
      case VCODE_OP_COVER_STMT:
1,195✔
1700
         import_cover_stmt(mu, imp, i);
1,195✔
1701
         break;
1,195✔
1702
      case VCODE_OP_COVER_BRANCH:
509✔
1703
         import_cover_branch(mu, imp, i);
509✔
1704
         break;
509✔
1705
      case VCODE_OP_COVER_EXPR:
855✔
1706
         import_cover_expr(mu, imp, i);
855✔
1707
         break;
855✔
1708
      case VCODE_OP_COVER_TOGGLE:
321✔
1709
         import_cover_toggle(mu, imp, i);
321✔
1710
         break;
321✔
1711
      case VCODE_OP_COVER_STATE:
12✔
1712
         import_cover_state(mu, imp, i);
12✔
1713
         break;
12✔
1714
      case VCODE_OP_ARRAY_SCOPE:
654✔
1715
         import_array_scope(mu, imp, i);
654✔
1716
         break;
654✔
1717
      case VCODE_OP_PACKAGE_SCOPE:
45✔
1718
         import_package_scope(mu, imp, i);
45✔
1719
         break;
45✔
1720
      case VCODE_OP_RECORD_SCOPE:
1,718✔
1721
         import_record_scope(mu, imp, i);
1,718✔
1722
         break;
1,718✔
1723
      case VCODE_OP_POP_SCOPE:
2,417✔
1724
         import_pop_scope(mu, imp, i);
2,417✔
1725
         break;
2,417✔
1726
      case VCODE_OP_CMP_TRIGGER:
47✔
1727
         import_cmp_trigger(mu, imp, i);
47✔
1728
         break;
47✔
1729
      case VCODE_OP_FUNCTION_TRIGGER:
199✔
1730
         import_function_trigger(mu, imp, i);
199✔
1731
         break;
199✔
1732
      case VCODE_OP_OR_TRIGGER:
34✔
1733
         import_or_trigger(mu, imp, i);
34✔
1734
         break;
34✔
1735
      case VCODE_OP_ADD_TRIGGER:
368✔
1736
         import_add_trigger(mu, imp, i);
368✔
1737
         break;
368✔
1738
      case VCODE_OP_PROTECTED_INIT:
550✔
1739
         import_protected_init(mu, imp, i);
550✔
1740
         break;
550✔
1741
      case VCODE_OP_PROTECTED_FREE:
1742
         break;   // No-op
1743
      case VCODE_OP_INSTANCE_NAME:
767✔
1744
         import_instance_name(mu, imp, i);
767✔
1745
         break;
767✔
1746
      case VCODE_OP_LAST_EVENT:
42✔
1747
         import_last_event(mu, imp, i);
42✔
1748
         break;
42✔
1749
      case VCODE_OP_LAST_ACTIVE:
45✔
1750
         import_last_active(mu, imp, i);
45✔
1751
         break;
45✔
1752
      case VCODE_OP_LAST_VALUE:
184✔
1753
         import_last_value(mu, imp, i);
184✔
1754
         break;
184✔
1755
      case VCODE_OP_ENTER_STATE:
849✔
1756
         import_enter_state(mu, imp, i);
849✔
1757
         break;
849✔
1758
      case VCODE_OP_REFLECT_SUBTYPE:
42✔
1759
         import_reflect_subtype(mu, imp, i);
42✔
1760
         break;
42✔
1761
      case VCODE_OP_REFLECT_VALUE:
48✔
1762
         import_reflect_value(mu, imp, i);
48✔
1763
         break;
48✔
UNCOV
1764
      case VCODE_OP_DEBUG_OUT:
×
UNCOV
1765
         import_debug_out(mu, imp, i);
×
UNCOV
1766
         break;
×
1767
      case VCODE_OP_SCHED_PROCESS:
5,305✔
1768
         import_sched_process(mu, imp, i);
5,305✔
1769
         break;
5,305✔
1770
      case VCODE_OP_GET_COUNTERS:
679✔
1771
         import_get_counters(mu, imp, i);
679✔
1772
         break;
679✔
UNCOV
1773
      default:
×
UNCOV
1774
         vcode_dump_with_mark(i, NULL, NULL);
×
1775
         fatal_trace("cannot import vcode op %s",
1776
                     vcode_op_string(vcode_get_op(i)));
1777
      }
1778
   }
1779
}
137,230✔
1780

1781
mir_unit_t *mir_import(mir_context_t *mc, vcode_unit_t vu)
50,607✔
1782
{
1783
   static const mir_unit_kind_t kind_map[] = {
50,607✔
1784
      [VCODE_UNIT_FUNCTION] = MIR_UNIT_FUNCTION,
1785
      [VCODE_UNIT_INSTANCE] = MIR_UNIT_INSTANCE,
1786
      [VCODE_UNIT_PROCEDURE] = MIR_UNIT_PROCEDURE,
1787
      [VCODE_UNIT_PROCESS] = MIR_UNIT_PROCESS,
1788
      [VCODE_UNIT_PACKAGE] = MIR_UNIT_PACKAGE,
1789
      [VCODE_UNIT_THUNK] = MIR_UNIT_THUNK,
1790
      [VCODE_UNIT_PROTECTED] = MIR_UNIT_PROTECTED,
1791
      [VCODE_UNIT_PROPERTY] = MIR_UNIT_PROPERTY,
1792
   };
1793

1794
   const mir_unit_kind_t kind = kind_map[vcode_unit_kind(vu)];
50,607✔
1795

1796
   mir_shape_t *parent = NULL;
50,607✔
1797
   vcode_unit_t context = vcode_unit_context(vu);
50,607✔
1798
   if (context != NULL) {
50,607✔
1799
      ident_t name = vcode_unit_name(context);
27,399✔
1800
      if ((parent = mir_get_shape(mc, name)) == NULL) {
27,399✔
UNCOV
1801
         mir_unit_t *parent_mu = mir_import(mc, context);
×
UNCOV
1802
         mir_put_unit(mc, parent_mu);
×
1803

UNCOV
1804
         parent = mir_get_shape(mc, name);
×
UNCOV
1805
         assert(parent != NULL);
×
1806
      }
1807
   }
1808

1809
   ident_t name = vcode_unit_name(vu);
50,607✔
1810
   object_t *obj = vcode_unit_object(vu);
50,607✔
1811

1812
   mir_unit_t *mu = mir_unit_new(mc, name, obj, kind, parent);
50,607✔
1813

1814
   vcode_select_unit(vu);
50,607✔
1815

1816
   const int nblocks = vcode_count_blocks();
50,607✔
1817
   const int nregs = vcode_count_regs();
50,607✔
1818
   const int nvars = vcode_count_vars();
50,607✔
1819

1820
   mir_import_t imp = {};
50,607✔
1821
   imp.blocks = xcalloc_array(nblocks, sizeof(mir_block_t));
50,607✔
1822
   imp.map    = xcalloc_array(nregs, sizeof(mir_value_t));
50,607✔
1823
   imp.vars   = xcalloc_array(nvars, sizeof(mir_value_t));
50,607✔
1824
   imp.types  = ihash_new(64);
50,607✔
1825

1826
   switch (kind) {
50,607✔
1827
   case MIR_UNIT_FUNCTION:
12,171✔
1828
      {
1829
         vcode_type_t vresult = vcode_unit_result(vu);
12,171✔
1830
         if (vresult != VCODE_INVALID_TYPE)
12,171✔
1831
            mir_set_result(mu, import_type(mu, &imp, vresult));
9,877✔
1832
      }
1833
      // Fall-through
1834
   case MIR_UNIT_PROCEDURE:
1835
   case MIR_UNIT_PROTECTED:
1836
   case MIR_UNIT_PROPERTY:
1837
      {
1838
         const int nparams = vcode_count_params();
13,166✔
1839
         for (int i = 0; i < nparams; i++) {
44,534✔
1840
            vcode_reg_t preg = vcode_param_reg(i);
31,368✔
1841
            mir_type_t type = import_type(mu, &imp, vcode_param_type(i));
31,368✔
1842
            ident_t name = vcode_param_name(i);
31,368✔
1843
            imp.map[preg] = mir_add_param(mu, type, MIR_NULL_STAMP, name);
31,368✔
1844
         }
1845
      }
1846
      break;
1847
   case MIR_UNIT_THUNK:
11,118✔
1848
      mir_set_result(mu, import_type(mu, &imp, vcode_unit_result(vu)));
11,118✔
1849
      break;
11,118✔
1850
   default:
1851
      break;
1852
   }
1853

1854
   for (int i = 0; i < nvars; i++) {
122,513✔
1855
      mir_type_t type = import_type(mu, &imp, vcode_var_type(i));
71,906✔
1856
      imp.vars[i] = mir_add_var(mu, type, MIR_NULL_STAMP, vcode_var_name(i),
71,906✔
1857
                                (mir_var_flags_t)vcode_var_flags(i));
71,906✔
1858
   }
1859

1860
   imp.blocks[0] = mir_get_cursor(mu, NULL);
50,607✔
1861
   for (int i = 1; i < nblocks; i++)
137,230✔
1862
      imp.blocks[i] = mir_add_block(mu);
86,623✔
1863

1864
   for (int i = 0; i < nblocks; i++) {
187,837✔
1865
      vcode_select_block(i);
137,230✔
1866
      mir_set_cursor(mu, imp.blocks[i], MIR_APPEND);
137,230✔
1867
      import_block(mu, &imp);
137,230✔
1868
   }
1869

1870
   ihash_free(imp.types);
50,607✔
1871
   free(imp.blocks);
50,607✔
1872
   free(imp.map);
50,607✔
1873
   free(imp.vars);
50,607✔
1874

1875
   mir_optimise(mu, MIR_PASS_O0);
50,607✔
1876
   return mu;
50,607✔
1877
}
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