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

nickg / nvc / 16099227452

06 Jul 2025 12:45PM UTC coverage: 92.335% (+0.05%) from 92.284%
16099227452

push

github

nickg
Handle underscores in Verilog decimal literals

Fixes #1230

18 of 20 new or added lines in 1 file covered. (90.0%)

598 existing lines in 16 files now uncovered.

71069 of 76969 relevant lines covered (92.33%)

564781.41 hits per line

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

96.83
/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,
1,094,076✔
36
                              vcode_type_t vtype)
37
{
38
   void *ptr = ihash_get(imp->types, vtype);
1,094,076✔
39
   if (ptr != NULL)
1,094,076✔
40
      return (mir_type_t){ .bits = (uintptr_t)ptr };
830,775✔
41

42
   mir_type_t type;
263,301✔
43
   switch (vtype_kind(vtype)) {
263,301✔
44
   case VCODE_TYPE_INT:
114,710✔
45
      type = mir_int_type(mu, vtype_low(vtype), vtype_high(vtype));
114,710✔
46
      break;
114,710✔
47
   case VCODE_TYPE_REAL:
10,390✔
48
      type = mir_real_type(mu, -DBL_MAX, DBL_MAX);
10,390✔
49
      break;
10,390✔
50
   case VCODE_TYPE_OFFSET:
34,864✔
51
      type = mir_offset_type(mu);
34,864✔
52
      break;
34,864✔
53
   case VCODE_TYPE_SIGNAL:
11,538✔
54
      type = mir_signal_type(mu, import_type(mu, imp, vtype_base(vtype)));
11,538✔
55
      break;
11,538✔
56
   case VCODE_TYPE_UARRAY:
18,482✔
57
      type = mir_uarray_type(mu, vtype_dims(vtype),
18,482✔
58
                             import_type(mu, imp, vtype_elem(vtype)));
59
      break;
18,482✔
60
   case VCODE_TYPE_CARRAY:
27,571✔
61
      type = mir_carray_type(mu, vtype_size(vtype),
27,571✔
62
                             import_type(mu, imp, vtype_elem(vtype)));
63
      break;
27,571✔
64
   case VCODE_TYPE_CONTEXT:
20,953✔
65
      type = mir_context_type(mu, vtype_name(vtype));
20,953✔
66
      break;
20,953✔
67
   case VCODE_TYPE_ACCESS:
2,824✔
68
      type = mir_access_type(mu, import_type(mu, imp, vtype_pointed(vtype)));
2,824✔
69
      break;
2,824✔
70
   case VCODE_TYPE_OPAQUE:
904✔
71
      type = mir_opaque_type(mu);
904✔
72
      break;
904✔
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:
7,287✔
81
      {
82
         const int nfields = vtype_fields(vtype);
7,287✔
83
         mir_type_t *fields LOCAL = xmalloc_array(nfields, sizeof(mir_type_t));
14,574✔
84
         for (int i = 0; i < nfields; i++)
32,270✔
85
            fields[i] = import_type(mu, imp, vtype_field(vtype, i));
24,983✔
86

87
         type = mir_record_type(mu, vtype_name(vtype), fields, nfields);
7,287✔
88
      }
89
      break;
7,287✔
90
   case VCODE_TYPE_POINTER:
9,135✔
91
      type = mir_pointer_type(mu, import_type(mu, imp, vtype_pointed(vtype)));
9,135✔
92
      break;
9,135✔
93
   case VCODE_TYPE_FILE:
1,252✔
94
      type = mir_file_type(mu, import_type(mu, imp, vtype_base(vtype)));
1,252✔
95
      break;
1,252✔
96
   case VCODE_TYPE_CONVERSION:
280✔
97
      type = mir_conversion_type(mu);
280✔
98
      break;
280✔
99
   case VCODE_TYPE_TRIGGER:
100✔
100
      type = mir_trigger_type(mu);
100✔
101
      break;
100✔
102
   case VCODE_TYPE_DEBUG_LOCUS:
61✔
103
      type = mir_locus_type(mu);
61✔
104
      break;
61✔
105
   case VCODE_TYPE_RESOLUTION:
2,950✔
106
      type = mir_resolution_type(mu, import_type(mu, imp, vtype_base(vtype)));
2,950✔
107
      break;
2,950✔
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);
263,301✔
114
   return type;
263,301✔
115
}
116

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

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

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

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

138
   mir_value_t context = imp->map[vcode_get_arg(op, 0)];
5,632✔
139
   mir_type_t type = import_type(mu, imp, vtype);
5,632✔
140
   ident_t unit_name = vtype_name(vcode_reg_type(vcode_get_arg(op, 0)));
5,632✔
141
   ident_t name = vcode_get_ident(op);
5,632✔
142

143
   imp->map[result] = mir_build_link_var(mu, unit_name, context, name, type);
5,632✔
144
}
5,632✔
145

146
static void import_return(mir_unit_t *mu, mir_import_t *imp, int op)
78,672✔
147
{
148
   mir_value_t result = MIR_NULL_VALUE;
78,672✔
149
   if (vcode_count_args(op) > 0)
78,672✔
150
      result = imp->map[vcode_get_arg(op, 0)];
36,895✔
151

152
   mir_build_return(mu, result);
78,672✔
153
}
78,672✔
154

155
static void import_fcall(mir_unit_t *mu, mir_import_t *imp, int op)
45,111✔
156
{
157
   const int nargs = vcode_count_args(op);
45,111✔
158
   mir_value_t *args LOCAL = xmalloc_array(nargs, sizeof(mir_value_t));
90,222✔
159
   for (int i = 0; i < nargs; i++)
170,747✔
160
      args[i] = imp->map[vcode_get_arg(op, i)];
125,636✔
161

162
   ident_t func = vcode_get_func(op);
45,111✔
163
   vcode_reg_t result = vcode_get_result(op);
45,111✔
164
   if (result == VCODE_INVALID_REG)
45,111✔
165
      mir_build_fcall(mu, func, MIR_NULL_TYPE, MIR_NULL_STAMP, args, nargs);
6,709✔
166
   else {
167
      mir_type_t type = import_type(mu, imp, vcode_reg_type(result));
38,402✔
168
      imp->map[result] = mir_build_fcall(mu, func, type, MIR_NULL_STAMP,
38,402✔
169
                                         args, nargs);
170
   }
171
}
45,111✔
172

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

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

183
   mir_build_pcall(mu, func, resume, args, nargs);
1,089✔
184
}
1,089✔
185

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

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

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

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

210
   const int nargs = vcode_count_args(op);
35,577✔
211
   mir_value_t *elts LOCAL = xmalloc_array(nargs, sizeof(mir_value_t));
71,154✔
212
   for (int i = 0; i < nargs; i++)
2,128,016✔
213
      elts[i] = imp->map[vcode_get_arg(op, i)];
2,092,439✔
214

215
   imp->map[result] = mir_const_array(mu, type, elts, nargs);
35,577✔
216
}
35,577✔
217

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

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

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

233
   const int nargs = vcode_count_args(op);
2,666✔
234
   mir_value_t *elts LOCAL = xmalloc_array(nargs, sizeof(mir_value_t));
5,332✔
235
   for (int i = 0; i < nargs; i++)
9,809✔
236
      elts[i] = imp->map[vcode_get_arg(op, i)];
7,143✔
237

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

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

247
   imp->map[vcode_get_result(op)] = mir_build_cmp(mu, cmp, left, right);
50,495✔
248
}
50,495✔
249

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

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

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

269
   mir_value_t hint_left = MIR_NULL_VALUE, hint_right = MIR_NULL_VALUE;
18,708✔
270
   if (vcode_count_args(op) > 5) {
18,708✔
271
      hint_left  = imp->map[vcode_get_arg(op, 5)];
7,914✔
272
      hint_right = imp->map[vcode_get_arg(op, 6)];
7,914✔
273
   }
274

275
   mir_build_assert(mu, value, msg, length, severity, locus,
18,708✔
276
                    hint_left, hint_right);
277
}
18,708✔
278

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

286
   mir_build_report(mu, message, length, severity, locus);
2,659✔
287
}
2,659✔
288

289
static void import_wait(mir_unit_t *mu, mir_import_t *imp, int op)
17,785✔
290
{
291
   mir_block_t btarget = imp->blocks[vcode_get_target(op, 0)];
17,785✔
292

293
   mir_value_t after = MIR_NULL_VALUE;
17,785✔
294
   vcode_reg_t after_reg = vcode_get_arg(op, 0);
17,785✔
295
   if (after_reg != VCODE_INVALID_REG)
17,785✔
296
      after = imp->map[after_reg];
6,724✔
297

298
   mir_build_wait(mu, btarget, after);
17,785✔
299
}
17,785✔
300

301
static void import_jump(mir_unit_t *mu, mir_import_t *imp, int op)
50,237✔
302
{
303
   mir_block_t btarget = imp->blocks[vcode_get_target(op, 0)];
50,237✔
304
   mir_build_jump(mu, btarget);
50,237✔
305
}
50,237✔
306

307
static void import_cond(mir_unit_t *mu, mir_import_t *imp, int op)
46,150✔
308
{
309
   mir_value_t test   = imp->map[vcode_get_arg(op, 0)];
46,150✔
310
   mir_block_t btrue  = imp->blocks[vcode_get_target(op, 0)];
46,150✔
311
   mir_block_t bfalse = imp->blocks[vcode_get_target(op, 1)];
46,150✔
312

313
   mir_build_cond(mu, test, btrue, bfalse);
46,150✔
314
}
46,150✔
315

316
static void import_case(mir_unit_t *mu, mir_import_t *imp, int op)
799✔
317
{
318
   mir_value_t value = imp->map[vcode_get_arg(op, 0)];
799✔
319
   mir_block_t def   = imp->blocks[vcode_get_target(op, 0)];
799✔
320

321
   const int nargs = vcode_count_args(op);
799✔
322

323
   mir_value_t *cases LOCAL = xmalloc_array(nargs - 1, sizeof(mir_value_t));
1,598✔
324
   mir_block_t *blocks LOCAL = xmalloc_array(nargs - 1, sizeof(mir_block_t));
1,598✔
325

326
   for (int i = 1; i < nargs; i++) {
4,571✔
327
      cases[i - 1]  = imp->map[vcode_get_arg(op, i)];
3,772✔
328
      blocks[i - 1] = imp->blocks[vcode_get_target(op, i)];
3,772✔
329
   }
330

331
   mir_build_case(mu, value, def, cases, blocks, nargs - 1);
799✔
332
}
799✔
333

334
static void import_init_signal(mir_unit_t *mu, mir_import_t *imp, int op)
20,853✔
335
{
336
   mir_value_t count = imp->map[vcode_get_arg(op, 0)];
20,853✔
337
   mir_value_t size  = imp->map[vcode_get_arg(op, 1)];
20,853✔
338
   mir_value_t value = imp->map[vcode_get_arg(op, 2)];
20,853✔
339
   mir_value_t flags = imp->map[vcode_get_arg(op, 3)];
20,853✔
340
   mir_value_t locus = imp->map[vcode_get_arg(op, 4)];
20,853✔
341

342
   mir_value_t offset = MIR_NULL_VALUE;
20,853✔
343
   if (vcode_count_args(op) > 5)
20,853✔
344
      offset = imp->map[vcode_get_arg(op, 5)];
7,495✔
345

346
   vcode_reg_t result = vcode_get_result(op);
20,853✔
347
   mir_type_t type = import_type(mu, imp, vtype_base(vcode_reg_type(result)));
20,853✔
348

349
   imp->map[result] = mir_build_init_signal(mu, type, count, size,
20,853✔
350
                                            value, flags, locus, offset);
351
}
20,853✔
352

353
static void import_implicit_signal(mir_unit_t *mu, mir_import_t *imp, int op)
108✔
354
{
355
   mir_value_t count   = imp->map[vcode_get_arg(op, 0)];
108✔
356
   mir_value_t size    = imp->map[vcode_get_arg(op, 1)];
108✔
357
   mir_value_t locus   = imp->map[vcode_get_arg(op, 2)];
108✔
358
   mir_value_t kind    = imp->map[vcode_get_arg(op, 3)];
108✔
359
   mir_value_t closure = imp->map[vcode_get_arg(op, 4)];
108✔
360
   mir_value_t delay   = imp->map[vcode_get_arg(op, 5)];
108✔
361

362
   vcode_reg_t result = vcode_get_result(op);
108✔
363
   mir_type_t type = import_type(mu, imp, vtype_base(vcode_reg_type(result)));
108✔
364

365
   imp->map[result] = mir_build_implicit_signal(mu, type, count, size, locus,
108✔
366
                                                kind, closure, delay);
367
}
108✔
368

369
static void import_drive_signal(mir_unit_t *mu, mir_import_t *imp, int op)
12,350✔
370
{
371
   mir_value_t target = imp->map[vcode_get_arg(op, 0)];
12,350✔
372
   mir_value_t count  = imp->map[vcode_get_arg(op, 1)];
12,350✔
373

374
   mir_build_drive_signal(mu, target, count);
12,350✔
375
}
12,350✔
376

377
static void import_sched_waveform(mir_unit_t *mu, mir_import_t *imp, int op)
14,198✔
378
{
379
   mir_value_t target = imp->map[vcode_get_arg(op, 0)];
14,198✔
380
   mir_value_t count  = imp->map[vcode_get_arg(op, 1)];
14,198✔
381
   mir_value_t value  = imp->map[vcode_get_arg(op, 2)];
14,198✔
382
   mir_value_t reject = imp->map[vcode_get_arg(op, 3)];
14,198✔
383
   mir_value_t after  = imp->map[vcode_get_arg(op, 4)];
14,198✔
384

385
   mir_build_sched_waveform(mu, target, count, value, reject, after);
14,198✔
386
}
14,198✔
387

388
static void import_resolved(mir_unit_t *mu, mir_import_t *imp, int op)
18,654✔
389
{
390
   mir_value_t nets = imp->map[vcode_get_arg(op, 0)];
18,654✔
391
   imp->map[vcode_get_result(op)] = mir_build_resolved(mu, nets);
18,654✔
392
}
18,654✔
393

394
static void import_address_of(mir_unit_t *mu, mir_import_t *imp, int op)
37,213✔
395
{
396
   mir_value_t nets = imp->map[vcode_get_arg(op, 0)];
37,213✔
397
   imp->map[vcode_get_result(op)] = mir_build_address_of(mu, nets);
37,213✔
398
}
37,213✔
399

400
static void import_store(mir_unit_t *mu, mir_import_t *imp, int op)
99,985✔
401
{
402
   mir_value_t var = imp->vars[vcode_get_address(op)];
99,985✔
403
   mir_build_store(mu, var, imp->map[vcode_get_arg(op, 0)]);
99,985✔
404
}
99,985✔
405

406
static void import_store_indirect(mir_unit_t *mu, mir_import_t *imp, int op)
19,206✔
407
{
408
   mir_value_t value = imp->map[vcode_get_arg(op, 0)];
19,206✔
409
   mir_value_t var   = imp->map[vcode_get_arg(op, 1)];
19,206✔
410
   mir_build_store(mu, var, value);
19,206✔
411
}
19,206✔
412

413
static void import_load(mir_unit_t *mu, mir_import_t *imp, int op)
51,458✔
414
{
415
   mir_value_t var = imp->vars[vcode_get_address(op)];
51,458✔
416
   imp->map[vcode_get_result(op)] = mir_build_load(mu, var);
51,458✔
417
}
51,458✔
418

419
static void import_load_indirect(mir_unit_t *mu, mir_import_t *imp, int op)
120,931✔
420
{
421
   mir_value_t var = imp->map[vcode_get_arg(op, 0)];
120,931✔
422
   imp->map[vcode_get_result(op)] = mir_build_load(mu, var);
120,931✔
423
}
120,931✔
424

425
static void import_context_upref(mir_unit_t *mu, mir_import_t *imp, int op)
15,782✔
426
{
427
   const int hops = vcode_get_hops(op);
15,782✔
428
   imp->map[vcode_get_result(op)] = mir_build_context_upref(mu, hops);
15,782✔
429
}
15,782✔
430

431
static void import_var_upref(mir_unit_t *mu, mir_import_t *imp, int op)
61,335✔
432
{
433
   const int hops = vcode_get_hops(op);
61,335✔
434
   vcode_var_t var = vcode_get_address(op);
61,335✔
435
   imp->map[vcode_get_result(op)] = mir_build_var_upref(mu, hops, var);
61,335✔
436
}
61,335✔
437

438
static void import_wrap(mir_unit_t *mu, mir_import_t *imp, int op)
37,000✔
439
{
440
   mir_value_t data = imp->map[vcode_get_arg(op, 0)];
37,000✔
441

442
   const int nargs = vcode_count_args(op);
37,000✔
443
   assert((nargs - 1) % 3 == 0);
37,000✔
444

445
   const int ndims = (nargs - 1) / 3;
37,000✔
446
   mir_dim_t *dims LOCAL = xmalloc_array(ndims, sizeof(mir_dim_t));
74,000✔
447
   for (int i = 0, pos = 1; i < ndims; i++, pos += 3) {
74,570✔
448
      dims[i].left  = imp->map[vcode_get_arg(op, pos + 0)];
37,570✔
449
      dims[i].right = imp->map[vcode_get_arg(op, pos + 1)];
37,570✔
450
      dims[i].dir   = imp->map[vcode_get_arg(op, pos + 2)];
37,570✔
451
   }
452

453
   imp->map[vcode_get_result(op)] = mir_build_wrap(mu, data, dims, ndims);
37,000✔
454
}
37,000✔
455

456
static void import_unwrap(mir_unit_t *mu, mir_import_t *imp, int op)
37,008✔
457
{
458
   mir_value_t arg = imp->map[vcode_get_arg(op, 0)];
37,008✔
459
   imp->map[vcode_get_result(op)] = mir_build_unwrap(mu, arg);
37,008✔
460
}
37,008✔
461

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

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

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

483
static void import_uarray_dir(mir_unit_t *mu, mir_import_t *imp, int op)
22,590✔
484
{
485
   mir_value_t arg = imp->map[vcode_get_arg(op, 0)];
22,590✔
486
   const int dim = vcode_get_dim(op);
22,590✔
487
   imp->map[vcode_get_result(op)] = mir_build_uarray_dir(mu, arg, dim);
22,590✔
488
}
22,590✔
489

490
static void import_add(mir_unit_t *mu, mir_import_t *imp, int op)
19,055✔
491
{
492
   vcode_reg_t result = vcode_get_result(op);
19,055✔
493

494
   mir_value_t left  = imp->map[vcode_get_arg(op, 0)];
19,055✔
495
   mir_value_t right = imp->map[vcode_get_arg(op, 1)];
19,055✔
496
   mir_type_t type = import_type(mu, imp, vcode_reg_type(result));
19,055✔
497

498
   imp->map[result] = mir_build_add(mu, type, left, right);
19,055✔
499
}
19,055✔
500

501
static void import_trap_add(mir_unit_t *mu, mir_import_t *imp, int op)
5,319✔
502
{
503
   vcode_reg_t result = vcode_get_result(op);
5,319✔
504

505
   mir_value_t left  = imp->map[vcode_get_arg(op, 0)];
5,319✔
506
   mir_value_t right = imp->map[vcode_get_arg(op, 1)];
5,319✔
507
   mir_value_t locus = imp->map[vcode_get_arg(op, 2)];
5,319✔
508
   mir_type_t type = import_type(mu, imp, vcode_reg_type(result));
5,319✔
509

510
   imp->map[result] = mir_build_trap_add(mu, type, left, right, locus);
5,319✔
511
}
5,319✔
512

513
static void import_sub(mir_unit_t *mu, mir_import_t *imp, int op)
38,015✔
514
{
515
   vcode_reg_t result = vcode_get_result(op);
38,015✔
516

517
   mir_value_t left  = imp->map[vcode_get_arg(op, 0)];
38,015✔
518
   mir_value_t right = imp->map[vcode_get_arg(op, 1)];
38,015✔
519
   mir_type_t type = import_type(mu, imp, vcode_reg_type(result));
38,015✔
520

521
   imp->map[result] = mir_build_sub(mu, type, left, right);
38,015✔
522
}
38,015✔
523

524
static void import_trap_sub(mir_unit_t *mu, mir_import_t *imp, int op)
1,723✔
525
{
526
   vcode_reg_t result = vcode_get_result(op);
1,723✔
527

528
   mir_value_t left  = imp->map[vcode_get_arg(op, 0)];
1,723✔
529
   mir_value_t right = imp->map[vcode_get_arg(op, 1)];
1,723✔
530
   mir_value_t locus = imp->map[vcode_get_arg(op, 2)];
1,723✔
531
   mir_type_t type = import_type(mu, imp, vcode_reg_type(result));
1,723✔
532

533
   imp->map[result] = mir_build_trap_sub(mu, type, left, right, locus);
1,723✔
534
}
1,723✔
535

536
static void import_mul(mir_unit_t *mu, mir_import_t *imp, int op)
4,081✔
537
{
538
   vcode_reg_t result = vcode_get_result(op);
4,081✔
539

540
   mir_value_t left  = imp->map[vcode_get_arg(op, 0)];
4,081✔
541
   mir_value_t right = imp->map[vcode_get_arg(op, 1)];
4,081✔
542
   mir_type_t type = import_type(mu, imp, vcode_reg_type(result));
4,081✔
543

544
   imp->map[result] = mir_build_mul(mu, type, left, right);
4,081✔
545
}
4,081✔
546

547
static void import_trap_mul(mir_unit_t *mu, mir_import_t *imp, int op)
492✔
548
{
549
   vcode_reg_t result = vcode_get_result(op);
492✔
550

551
   mir_value_t left  = imp->map[vcode_get_arg(op, 0)];
492✔
552
   mir_value_t right = imp->map[vcode_get_arg(op, 1)];
492✔
553
   mir_value_t locus = imp->map[vcode_get_arg(op, 2)];
492✔
554
   mir_type_t type = import_type(mu, imp, vcode_reg_type(result));
492✔
555

556
   imp->map[result] = mir_build_trap_mul(mu, type, left, right, locus);
492✔
557
}
492✔
558

559
static void import_div(mir_unit_t *mu, mir_import_t *imp, int op)
2,027✔
560
{
561
   vcode_reg_t result = vcode_get_result(op);
2,027✔
562

563
   mir_value_t left  = imp->map[vcode_get_arg(op, 0)];
2,027✔
564
   mir_value_t right = imp->map[vcode_get_arg(op, 1)];
2,027✔
565
   mir_type_t type = import_type(mu, imp, vcode_reg_type(result));
2,027✔
566

567
   imp->map[result] = mir_build_div(mu, type, left, right);
2,027✔
568
}
2,027✔
569

570
static void import_mod(mir_unit_t *mu, mir_import_t *imp, int op)
169✔
571
{
572
   vcode_reg_t result = vcode_get_result(op);
169✔
573

574
   mir_value_t left  = imp->map[vcode_get_arg(op, 0)];
169✔
575
   mir_value_t right = imp->map[vcode_get_arg(op, 1)];
169✔
576
   mir_type_t type = import_type(mu, imp, vcode_reg_type(result));
169✔
577

578
   imp->map[result] = mir_build_mod(mu, type, left, right);
169✔
579
}
169✔
580

581
static void import_rem(mir_unit_t *mu, mir_import_t *imp, int op)
884✔
582
{
583
   vcode_reg_t result = vcode_get_result(op);
884✔
584

585
   mir_value_t left  = imp->map[vcode_get_arg(op, 0)];
884✔
586
   mir_value_t right = imp->map[vcode_get_arg(op, 1)];
884✔
587
   mir_type_t type = import_type(mu, imp, vcode_reg_type(result));
884✔
588

589
   imp->map[result] = mir_build_rem(mu, type, left, right);
884✔
590
}
884✔
591

592
static void import_exp(mir_unit_t *mu, mir_import_t *imp, int op)
175✔
593
{
594
   vcode_reg_t result = vcode_get_result(op);
175✔
595

596
   mir_value_t left  = imp->map[vcode_get_arg(op, 0)];
175✔
597
   mir_value_t right = imp->map[vcode_get_arg(op, 1)];
175✔
598
   mir_type_t type = import_type(mu, imp, vcode_reg_type(result));
175✔
599

600
   imp->map[result] = mir_build_exp(mu, type, left, right);
175✔
601
}
175✔
602

603
static void import_trap_exp(mir_unit_t *mu, mir_import_t *imp, int op)
684✔
604
{
605
   vcode_reg_t result = vcode_get_result(op);
684✔
606

607
   mir_value_t left  = imp->map[vcode_get_arg(op, 0)];
684✔
608
   mir_value_t right = imp->map[vcode_get_arg(op, 1)];
684✔
609
   mir_value_t locus = imp->map[vcode_get_arg(op, 2)];
684✔
610
   mir_type_t type = import_type(mu, imp, vcode_reg_type(result));
684✔
611

612
   imp->map[result] = mir_build_trap_exp(mu, type, left, right, locus);
684✔
613
}
684✔
614

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

620
   imp->map[vcode_get_result(op)] = mir_build_or(mu, left, right);
2,688✔
621
}
2,688✔
622

623
static void import_nor(mir_unit_t *mu, mir_import_t *imp, int op)
50✔
624
{
625
   mir_value_t left  = imp->map[vcode_get_arg(op, 0)];
50✔
626
   mir_value_t right = imp->map[vcode_get_arg(op, 1)];
50✔
627

628
   mir_value_t or = mir_build_or(mu, left, right);
50✔
629
   imp->map[vcode_get_result(op)] = mir_build_not(mu, or);
50✔
630
}
50✔
631

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

637
   imp->map[vcode_get_result(op)] = mir_build_xor(mu, left, right);
84✔
638
}
84✔
639

640
static void import_xnor(mir_unit_t *mu, mir_import_t *imp, int op)
53✔
641
{
642
   mir_value_t left  = imp->map[vcode_get_arg(op, 0)];
53✔
643
   mir_value_t right = imp->map[vcode_get_arg(op, 1)];
53✔
644

645
   mir_value_t xor = mir_build_xor(mu, left, right);
53✔
646
   imp->map[vcode_get_result(op)] = mir_build_not(mu, xor);
53✔
647
}
53✔
648

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

654
   imp->map[vcode_get_result(op)] = mir_build_and(mu, left, right);
5,654✔
655
}
5,654✔
656

657
static void import_nand(mir_unit_t *mu, mir_import_t *imp, int op)
49✔
658
{
659
   mir_value_t left  = imp->map[vcode_get_arg(op, 0)];
49✔
660
   mir_value_t right = imp->map[vcode_get_arg(op, 1)];
49✔
661

662
   mir_value_t and = mir_build_and(mu, left, right);
49✔
663
   imp->map[vcode_get_result(op)] = mir_build_not(mu, and);
49✔
664
}
49✔
665

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

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

680
static void import_driving(mir_unit_t *mu, mir_import_t *imp, int op)
48✔
681
{
682
   mir_value_t signal = imp->map[vcode_get_arg(op, 0)];
48✔
683
   mir_value_t count  = imp->map[vcode_get_arg(op, 1)];
48✔
684
   imp->map[vcode_get_result(op)] = mir_build_driving_flag(mu, signal, count);
48✔
685
}
48✔
686

687
static void import_not(mir_unit_t *mu, mir_import_t *imp, int op)
3,351✔
688
{
689
   mir_value_t arg = imp->map[vcode_get_arg(op, 0)];
3,351✔
690
   imp->map[vcode_get_result(op)] = mir_build_not(mu, arg);
3,351✔
691
}
3,351✔
692

693
static void import_cast(mir_unit_t *mu, mir_import_t *imp, int op)
74,105✔
694
{
695
   mir_value_t arg = imp->map[vcode_get_arg(op, 0)];
74,105✔
696
   mir_type_t type = import_type(mu, imp, vcode_get_type(op));
74,105✔
697
   imp->map[vcode_get_result(op)] = mir_build_cast(mu, type, arg);
74,105✔
698
}
74,105✔
699

700
static void import_neg(mir_unit_t *mu, mir_import_t *imp, int op)
9,182✔
701
{
702
   vcode_reg_t result = vcode_get_result(op);
9,182✔
703
   mir_value_t arg = imp->map[vcode_get_arg(op, 0)];
9,182✔
704
   mir_type_t type = import_type(mu, imp, vcode_reg_type(result));
9,182✔
705
   imp->map[result] = mir_build_neg(mu, type, arg);
9,182✔
706
}
9,182✔
707

708
static void import_trap_neg(mir_unit_t *mu, mir_import_t *imp, int op)
344✔
709
{
710
   vcode_reg_t result = vcode_get_result(op);
344✔
711
   mir_value_t arg = imp->map[vcode_get_arg(op, 0)];
344✔
712
   mir_value_t locus = imp->map[vcode_get_arg(op, 1)];
344✔
713
   mir_type_t type = import_type(mu, imp, vcode_reg_type(result));
344✔
714
   imp->map[result] = mir_build_trap_neg(mu, type, arg, locus);
344✔
715
}
344✔
716

717
static void import_abs(mir_unit_t *mu, mir_import_t *imp, int op)
987✔
718
{
719
   vcode_reg_t result = vcode_get_result(op);
987✔
720
   mir_value_t arg = imp->map[vcode_get_arg(op, 0)];
987✔
721
   mir_type_t type = import_type(mu, imp, vcode_reg_type(result));
987✔
722
   imp->map[result] = mir_build_abs(mu, type, arg);
987✔
723
}
987✔
724

725
static void import_index(mir_unit_t *mu, mir_import_t *imp, int op)
31,382✔
726
{
727
   mir_value_t var = imp->vars[vcode_get_address(op)];
31,382✔
728
   imp->map[vcode_get_result(op)] = var;
31,382✔
729
}
31,382✔
730

731
static void import_copy(mir_unit_t *mu, mir_import_t *imp, int op)
30,691✔
732
{
733
   mir_value_t dst = imp->map[vcode_get_arg(op, 0)];
30,691✔
734
   mir_value_t src = imp->map[vcode_get_arg(op, 1)];
30,691✔
735

736
   mir_value_t count = MIR_NULL_VALUE;
30,691✔
737
   if (vcode_count_args(op) > 2)
30,691✔
738
      count = imp->map[vcode_get_arg(op, 2)];
28,639✔
739

740
   mir_build_copy(mu, dst, src, count);
30,691✔
741
}
30,691✔
742

743
static void import_memset(mir_unit_t *mu, mir_import_t *imp, int op)
7,597✔
744
{
745
   mir_value_t dst   = imp->map[vcode_get_arg(op, 0)];
7,597✔
746
   mir_value_t value = imp->map[vcode_get_arg(op, 1)];
7,597✔
747
   mir_value_t count = imp->map[vcode_get_arg(op, 2)];
7,597✔
748

749
   mir_build_set(mu, dst, value, count);
7,597✔
750
}
7,597✔
751

752
static void import_array_ref(mir_unit_t *mu, mir_import_t *imp, int op)
48,859✔
753
{
754
   mir_value_t array  = imp->map[vcode_get_arg(op, 0)];
48,859✔
755
   mir_value_t offset = imp->map[vcode_get_arg(op, 1)];
48,859✔
756
   imp->map[vcode_get_result(op)] = mir_build_array_ref(mu, array, offset);
48,859✔
757
}
48,859✔
758

759
static void import_record_ref(mir_unit_t *mu, mir_import_t *imp, int op)
48,405✔
760
{
761
   mir_value_t record = imp->map[vcode_get_arg(op, 0)];
48,405✔
762
   const int field = vcode_get_field(op);
48,405✔
763
   imp->map[vcode_get_result(op)] = mir_build_record_ref(mu, record, field);
48,405✔
764
}
48,405✔
765

766
static void import_range_check(mir_unit_t *mu, mir_import_t *imp, int op)
5,695✔
767
{
768
   mir_value_t value = imp->map[vcode_get_arg(op, 0)];
5,695✔
769
   mir_value_t left  = imp->map[vcode_get_arg(op, 1)];
5,695✔
770
   mir_value_t right = imp->map[vcode_get_arg(op, 2)];
5,695✔
771
   mir_value_t dir   = imp->map[vcode_get_arg(op, 3)];
5,695✔
772
   mir_value_t locus = imp->map[vcode_get_arg(op, 4)];
5,695✔
773
   mir_value_t hint  = imp->map[vcode_get_arg(op, 5)];
5,695✔
774

775
   mir_build_range_check(mu, value, left, right, dir, locus, hint);
5,695✔
776
}
5,695✔
777

778
static void import_sched_event(mir_unit_t *mu, mir_import_t *imp, int op)
7,860✔
779
{
780
   mir_value_t signal = imp->map[vcode_get_arg(op, 0)];
7,860✔
781
   mir_value_t count  = imp->map[vcode_get_arg(op, 1)];
7,860✔
782
   mir_build_sched_event(mu, signal, count);
7,860✔
783
}
7,860✔
784

785
static void import_clear_event(mir_unit_t *mu, mir_import_t *imp, int op)
702✔
786
{
787
   mir_value_t signal = imp->map[vcode_get_arg(op, 0)];
702✔
788
   mir_value_t count  = imp->map[vcode_get_arg(op, 1)];
702✔
789
   mir_build_clear_event(mu, signal, count);
702✔
790
}
702✔
791

792
static void import_alloc(mir_unit_t *mu, mir_import_t *imp, int op)
9,200✔
793
{
794
   mir_value_t count  = imp->map[vcode_get_arg(op, 0)];
9,200✔
795
   mir_type_t type    = import_type(mu, imp, vcode_get_type(op));
9,200✔
796
   vcode_reg_t result = vcode_get_result(op);
9,200✔
797
   imp->map[result] = mir_build_alloc(mu, type, MIR_NULL_STAMP, count);
9,200✔
798
}
9,200✔
799

800
static void import_range_length(mir_unit_t *mu, mir_import_t *imp, int op)
9,038✔
801
{
802
   mir_value_t left   = imp->map[vcode_get_arg(op, 0)];
9,038✔
803
   mir_value_t right  = imp->map[vcode_get_arg(op, 1)];
9,038✔
804
   mir_value_t dir    = imp->map[vcode_get_arg(op, 2)];
9,038✔
805
   vcode_reg_t result = vcode_get_result(op);
9,038✔
806
   imp->map[result] = mir_build_range_length(mu, left, right, dir);
9,038✔
807
}
9,038✔
808

809
static void import_range_null(mir_unit_t *mu, mir_import_t *imp, int op)
4,321✔
810
{
811
   mir_value_t left   = imp->map[vcode_get_arg(op, 0)];
4,321✔
812
   mir_value_t right  = imp->map[vcode_get_arg(op, 1)];
4,321✔
813
   mir_value_t dir    = imp->map[vcode_get_arg(op, 2)];
4,321✔
814
   vcode_reg_t result = vcode_get_result(op);
4,321✔
815
   imp->map[result] = mir_build_range_null(mu, left, right, dir);
4,321✔
816
}
4,321✔
817

818
static void import_null(mir_unit_t *mu, mir_import_t *imp, int op)
5,239✔
819
{
820
   vcode_reg_t result = vcode_get_result(op);
5,239✔
821
   mir_type_t type = import_type(mu, imp, vcode_reg_type(result));
5,239✔
822
   imp->map[result] = mir_build_null(mu, type);
5,239✔
823
}
5,239✔
824

825
static void import_new(mir_unit_t *mu, mir_import_t *imp, int op)
854✔
826
{
827
   vcode_reg_t result = vcode_get_result(op);
854✔
828
   vcode_type_t vtype = vtype_pointed(vcode_reg_type(result));
854✔
829
   mir_type_t type = import_type(mu, imp, vtype);
854✔
830

831
   mir_value_t count = MIR_NULL_VALUE;
854✔
832
   if (vcode_count_args(op) > 0)
854✔
833
      count = imp->map[vcode_get_arg(op, 0)];
736✔
834

835
   imp->map[result] = mir_build_new(mu, type, MIR_NULL_STAMP, count);
854✔
836
}
854✔
837

838
static void import_all(mir_unit_t *mu, mir_import_t *imp, int op)
3,755✔
839
{
840
   mir_value_t arg = imp->map[vcode_get_arg(op, 0)];
3,755✔
841
   imp->map[vcode_get_result(op)] = mir_build_all(mu, arg);
3,755✔
842
}
3,755✔
843

844
static void import_deallocate(mir_unit_t *mu, mir_import_t *imp, int op)
459✔
845
{
846
   mir_value_t arg = imp->map[vcode_get_arg(op, 0)];
459✔
847
   mir_type_t type = mir_get_type(mu, arg);
459✔
848
   mir_build_store(mu, arg, mir_build_null(mu, mir_get_pointer(mu, type)));
459✔
849
}
459✔
850

851
static void import_null_check(mir_unit_t *mu, mir_import_t *imp, int op)
2,901✔
852
{
853
   mir_value_t ptr = imp->map[vcode_get_arg(op, 0)];
2,901✔
854
   mir_value_t locus = imp->map[vcode_get_arg(op, 1)];
2,901✔
855
   mir_build_null_check(mu, ptr, locus);
2,901✔
856
}
2,901✔
857

858
static void import_zero_check(mir_unit_t *mu, mir_import_t *imp, int op)
119✔
859
{
860
   mir_value_t value = imp->map[vcode_get_arg(op, 0)];
119✔
861
   mir_value_t locus = imp->map[vcode_get_arg(op, 1)];
119✔
862
   mir_build_zero_check(mu, value, locus);
119✔
863
}
119✔
864

865
static void import_length_check(mir_unit_t *mu, mir_import_t *imp, int op)
9,538✔
866
{
867
   mir_value_t llen = imp->map[vcode_get_arg(op, 0)];
9,538✔
868
   mir_value_t rlen = imp->map[vcode_get_arg(op, 1)];
9,538✔
869
   mir_value_t locus = imp->map[vcode_get_arg(op, 2)];
9,538✔
870

871
   mir_value_t dim = MIR_NULL_VALUE;
9,538✔
872
   if (vcode_count_args(op) > 3)
9,538✔
873
      dim = imp->map[vcode_get_arg(op, 3)];
36✔
874

875
   mir_build_length_check(mu, llen, rlen, locus, dim);
9,538✔
876
}
9,538✔
877

878
static void import_index_check(mir_unit_t *mu, mir_import_t *imp, int op)
21,043✔
879
{
880
   mir_value_t value = imp->map[vcode_get_arg(op, 0)];
21,043✔
881
   mir_value_t left  = imp->map[vcode_get_arg(op, 1)];
21,043✔
882
   mir_value_t right = imp->map[vcode_get_arg(op, 2)];
21,043✔
883
   mir_value_t dir   = imp->map[vcode_get_arg(op, 3)];
21,043✔
884
   mir_value_t locus = imp->map[vcode_get_arg(op, 4)];
21,043✔
885
   mir_value_t hint  = imp->map[vcode_get_arg(op, 5)];;
21,043✔
886

887
   mir_build_index_check(mu, value, left, right, dir, locus, hint);
21,043✔
888
}
21,043✔
889

890
static void import_alias_signal(mir_unit_t *mu, mir_import_t *imp, int op)
5,570✔
891
{
892
   mir_value_t signal = imp->map[vcode_get_arg(op, 0)];
5,570✔
893
   mir_value_t locus = imp->map[vcode_get_arg(op, 1)];
5,570✔
894

895
   mir_build_alias_signal(mu, signal, locus);
5,570✔
896
}
5,570✔
897

898
static void import_map_signal(mir_unit_t *mu, mir_import_t *imp, int op)
7,078✔
899
{
900
   mir_value_t src = imp->map[vcode_get_arg(op, 0)];
7,078✔
901
   mir_value_t dst = imp->map[vcode_get_arg(op, 1)];
7,078✔
902
   mir_value_t count = imp->map[vcode_get_arg(op, 2)];
7,078✔
903

904
   mir_build_map_signal(mu, src, dst, count);
7,078✔
905
}
7,078✔
906

907
static void import_map_const(mir_unit_t *mu, mir_import_t *imp, int op)
248✔
908
{
909
   mir_value_t src = imp->map[vcode_get_arg(op, 0)];
248✔
910
   mir_value_t dst = imp->map[vcode_get_arg(op, 1)];
248✔
911
   mir_value_t count = imp->map[vcode_get_arg(op, 2)];
248✔
912

913
   mir_build_map_const(mu, src, dst, count);
248✔
914
}
248✔
915

916
static void import_map_implicit(mir_unit_t *mu, mir_import_t *imp, int op)
84✔
917
{
918
   mir_value_t src = imp->map[vcode_get_arg(op, 0)];
84✔
919
   mir_value_t dst = imp->map[vcode_get_arg(op, 1)];
84✔
920
   mir_value_t count = imp->map[vcode_get_arg(op, 2)];
84✔
921

922
   mir_build_map_implicit(mu, src, dst, count);
84✔
923
}
84✔
924

925
static void import_bind_foreign(mir_unit_t *mu, mir_import_t *imp, int op)
1,294✔
926
{
927
   mir_value_t spec = imp->map[vcode_get_arg(op, 0)];
1,294✔
928
   mir_value_t length = imp->map[vcode_get_arg(op, 1)];
1,294✔
929

930
   mir_value_t locus = MIR_NULL_VALUE;
1,294✔
931
   if (vcode_count_args(op) > 2)
1,294✔
932
      locus = imp->map[vcode_get_arg(op, 2)];
1,062✔
933

934
   mir_build_bind_foreign(mu, spec, length, locus);
1,294✔
935
}
1,294✔
936

937
static void import_bind_external(mir_unit_t *mu, mir_import_t *imp, int op)
261✔
938
{
939
   mir_value_t locus = imp->map[vcode_get_arg(op, 0)];
261✔
940
   ident_t scope = vcode_get_ident(op);
261✔
941

942
   vcode_reg_t result = vcode_get_result(op);
261✔
943
   vcode_type_t vtype = vtype_pointed(vcode_reg_type(result));
261✔
944
   mir_type_t type = import_type(mu, imp, vtype);
261✔
945

946
   imp->map[result] = mir_build_bind_external(mu, locus, scope, type,
261✔
947
                                              MIR_NULL_STAMP);
261✔
948
}
261✔
949

950
static void import_unreachable(mir_unit_t *mu, mir_import_t *imp, int op)
1,707✔
951
{
952
   mir_value_t locus = MIR_NULL_VALUE;
1,707✔
953
   if (vcode_count_args(op) > 0)
1,707✔
954
      locus = imp->map[vcode_get_arg(op, 0)];
125✔
955

956
   mir_build_unreachable(mu, locus);
1,707✔
957
}
1,707✔
958

959
static void import_select(mir_unit_t *mu, mir_import_t *imp, int op)
18,147✔
960
{
961
   mir_value_t test = imp->map[vcode_get_arg(op, 0)];
18,147✔
962
   mir_value_t tval = imp->map[vcode_get_arg(op, 1)];
18,147✔
963
   mir_value_t fval = imp->map[vcode_get_arg(op, 2)];
18,147✔
964

965
   vcode_reg_t result = vcode_get_result(op);
18,147✔
966
   mir_type_t type = import_type(mu, imp, vcode_reg_type(result));
18,147✔
967

968
   imp->map[result] = mir_build_select(mu, type, test, tval, fval);
18,147✔
969
}
18,147✔
970

971
static void import_closure(mir_unit_t *mu, mir_import_t *imp, int op)
6,290✔
972
{
973
   mir_value_t context = imp->map[vcode_get_arg(op, 0)];
6,290✔
974
   ident_t func = vcode_get_func(op);
6,290✔
975

976
   mir_type_t atype = MIR_NULL_TYPE;
6,290✔
977
   vcode_reg_t result = vcode_get_result(op);
6,290✔
978
   mir_type_t rtype = import_type(mu, imp, vtype_base(vcode_reg_type(result)));
6,290✔
979

980
   imp->map[result] = mir_build_closure(mu, func, context, atype, rtype);
6,290✔
981
}
6,290✔
982

983
static void import_resolution_wrapper(mir_unit_t *mu, mir_import_t *imp, int op)
5,902✔
984
{
985
   mir_value_t closure = imp->map[vcode_get_arg(op, 0)];
5,902✔
986
   mir_value_t nlits = imp->map[vcode_get_arg(op, 1)];
5,902✔
987

988
   vcode_reg_t result = vcode_get_result(op);
5,902✔
989
   mir_type_t type = import_type(mu, imp, vtype_base(vcode_reg_type(result)));
5,902✔
990

991
   imp->map[result] = mir_build_resolution_wrapper(mu, type, closure, nlits);
5,902✔
992
}
5,902✔
993

994
static void import_resolve_signal(mir_unit_t *mu, mir_import_t *imp, int op)
4,272✔
995
{
996
   mir_value_t signal = imp->map[vcode_get_arg(op, 0)];
4,272✔
997
   mir_value_t resolution = imp->map[vcode_get_arg(op, 1)];
4,272✔
998
   mir_build_resolve_signal(mu, signal, resolution);
4,272✔
999
}
4,272✔
1000

1001
static void import_transfer_signal(mir_unit_t *mu, mir_import_t *imp, int op)
1,606✔
1002
{
1003
   mir_value_t target = imp->map[vcode_get_arg(op, 0)];
1,606✔
1004
   mir_value_t source = imp->map[vcode_get_arg(op, 1)];
1,606✔
1005
   mir_value_t count = imp->map[vcode_get_arg(op, 2)];
1,606✔
1006
   mir_value_t reject = imp->map[vcode_get_arg(op, 3)];
1,606✔
1007
   mir_value_t after = imp->map[vcode_get_arg(op, 4)];
1,606✔
1008

1009
   mir_build_transfer_signal(mu, target, source, count, reject, after);
1,606✔
1010
}
1,606✔
1011

1012
static void import_file_open(mir_unit_t *mu, mir_import_t *imp, int op)
1,550✔
1013
{
1014
   mir_value_t file = imp->map[vcode_get_arg(op, 0)];
1,550✔
1015
   mir_value_t name = imp->map[vcode_get_arg(op, 1)];
1,550✔
1016
   mir_value_t length = imp->map[vcode_get_arg(op, 2)];
1,550✔
1017
   mir_value_t kind = imp->map[vcode_get_arg(op, 3)];
1,550✔
1018

1019
   mir_value_t status = MIR_NULL_VALUE;
1,550✔
1020
   if (vcode_count_args(op) > 4)
1,550✔
1021
      status = imp->map[vcode_get_arg(op, 4)];
33✔
1022

1023
   mir_build_file_open(mu, file, name, length, kind, status);
1,550✔
1024
}
1,550✔
1025

1026
static void import_file_read(mir_unit_t *mu, mir_import_t *imp, int op)
120✔
1027
{
1028
   mir_value_t file = imp->map[vcode_get_arg(op, 0)];
120✔
1029
   mir_value_t ptr = imp->map[vcode_get_arg(op, 1)];
120✔
1030

1031
   mir_value_t inlen = MIR_NULL_VALUE, outlen = MIR_NULL_VALUE;
120✔
1032
   if (vcode_count_args(op) > 2) {
120✔
1033
      inlen = imp->map[vcode_get_arg(op, 2)];
56✔
1034

1035
      if (vcode_count_args(op) > 3)
56✔
1036
         outlen = imp->map[vcode_get_arg(op, 3)];
44✔
1037
   }
1038

1039
   mir_build_file_read(mu, file, ptr, inlen, outlen);
120✔
1040
}
120✔
1041

1042
static void import_file_write(mir_unit_t *mu, mir_import_t *imp, int op)
339✔
1043
{
1044
   mir_value_t file = imp->map[vcode_get_arg(op, 0)];
339✔
1045
   mir_value_t value = imp->map[vcode_get_arg(op, 1)];
339✔
1046

1047
   mir_value_t length = MIR_NULL_VALUE;
339✔
1048
   if (vcode_count_args(op) > 2)
339✔
1049
      length = imp->map[vcode_get_arg(op, 2)];
263✔
1050

1051
   mir_build_file_write(mu, file, value, length);
339✔
1052
}
339✔
1053

1054
static void import_port_conversion(mir_unit_t *mu, mir_import_t *imp, int op)
256✔
1055
{
1056
   mir_value_t driving = imp->map[vcode_get_arg(op, 0)];
256✔
1057

1058
   mir_value_t effective = MIR_NULL_VALUE;
256✔
1059
   if (vcode_count_args(op) > 1)
256✔
1060
      effective = imp->map[vcode_get_arg(op, 1)];
24✔
1061

1062
   vcode_reg_t result = vcode_get_result(op);
256✔
1063
   imp->map[result] = mir_build_port_conversion(mu, driving, effective);
256✔
1064
}
256✔
1065

1066
static void import_convert_in(mir_unit_t *mu, mir_import_t *imp, int op)
360✔
1067
{
1068
   mir_value_t conv = imp->map[vcode_get_arg(op, 0)];
360✔
1069
   mir_value_t nets = imp->map[vcode_get_arg(op, 1)];
360✔
1070
   mir_value_t count = imp->map[vcode_get_arg(op, 2)];
360✔
1071

1072
   mir_build_convert_in(mu, conv, nets, count);
360✔
1073
}
360✔
1074

1075
static void import_convert_out(mir_unit_t *mu, mir_import_t *imp, int op)
416✔
1076
{
1077
   mir_value_t conv = imp->map[vcode_get_arg(op, 0)];
416✔
1078
   mir_value_t nets = imp->map[vcode_get_arg(op, 1)];
416✔
1079
   mir_value_t count = imp->map[vcode_get_arg(op, 2)];
416✔
1080

1081
   mir_build_convert_out(mu, conv, nets, count);
416✔
1082
}
416✔
1083

1084
static void import_driving_value(mir_unit_t *mu, mir_import_t *imp, int op)
152✔
1085
{
1086
   mir_value_t signal = imp->map[vcode_get_arg(op, 0)];
152✔
1087

1088
   mir_value_t count = MIR_NULL_VALUE;
152✔
1089
   if (vcode_count_args(op) > 1)
152✔
1090
      count = imp->map[vcode_get_arg(op, 1)];
40✔
1091

1092
   imp->map[vcode_get_result(op)] = mir_build_driving_value(mu, signal, count);
152✔
1093
}
152✔
1094

1095
static void import_put_conversion(mir_unit_t *mu, mir_import_t *imp, int op)
440✔
1096
{
1097
   mir_value_t cf = imp->map[vcode_get_arg(op, 0)];
440✔
1098
   mir_value_t target = imp->map[vcode_get_arg(op, 1)];
440✔
1099
   mir_value_t count = imp->map[vcode_get_arg(op, 2)];
440✔
1100
   mir_value_t values = imp->map[vcode_get_arg(op, 3)];
440✔
1101

1102
   mir_build_put_conversion(mu, cf, target, count, values);
440✔
1103
}
440✔
1104

1105
static void import_force(mir_unit_t *mu, mir_import_t *imp, int op)
84✔
1106
{
1107
   mir_value_t target = imp->map[vcode_get_arg(op, 0)];
84✔
1108
   mir_value_t count = imp->map[vcode_get_arg(op, 1)];
84✔
1109
   mir_value_t values = imp->map[vcode_get_arg(op, 2)];
84✔
1110

1111
   mir_build_force(mu, target, count, values);
84✔
1112
}
84✔
1113

1114
static void import_release(mir_unit_t *mu, mir_import_t *imp, int op)
40✔
1115
{
1116
   mir_value_t target = imp->map[vcode_get_arg(op, 0)];
40✔
1117
   mir_value_t count = imp->map[vcode_get_arg(op, 1)];
40✔
1118

1119
   mir_build_release(mu, target, count);
40✔
1120
}
40✔
1121

1122
static void import_disconnect(mir_unit_t *mu, mir_import_t *imp, int op)
32✔
1123
{
1124
   mir_value_t target = imp->map[vcode_get_arg(op, 0)];
32✔
1125
   mir_value_t count = imp->map[vcode_get_arg(op, 1)];
32✔
1126
   mir_value_t reject = imp->map[vcode_get_arg(op, 2)];
32✔
1127
   mir_value_t after = imp->map[vcode_get_arg(op, 3)];
32✔
1128

1129
   mir_build_disconnect(mu, target, count, reject, after);
32✔
1130
}
32✔
1131

1132
static void import_exponent_check(mir_unit_t *mu, mir_import_t *imp, int op)
660✔
1133
{
1134
   mir_value_t exp = imp->map[vcode_get_arg(op, 0)];
660✔
1135
   mir_value_t locus = imp->map[vcode_get_arg(op, 1)];
660✔
1136

1137
   mir_build_exponent_check(mu, exp, locus);
660✔
1138
}
660✔
1139

1140
static void import_process_init(mir_unit_t *mu, mir_import_t *imp, int op)
154✔
1141
{
1142
   ident_t name = vcode_get_func(op);
154✔
1143
   mir_value_t locus = imp->map[vcode_get_arg(op, 0)];
154✔
1144

1145
   mir_build_process_init(mu, name, locus);
154✔
1146
}
154✔
1147

1148
static void import_cover_stmt(mir_unit_t *mu, mir_import_t *imp, int op)
1,374✔
1149
{
1150
   mir_build_cover_stmt(mu, vcode_get_tag(op));
1,374✔
1151
}
1,374✔
1152

1153
static void import_cover_branch(mir_unit_t *mu, mir_import_t *imp, int op)
657✔
1154
{
1155
   mir_build_cover_branch(mu, vcode_get_tag(op));
657✔
1156
}
657✔
1157

1158
static void import_cover_expr(mir_unit_t *mu, mir_import_t *imp, int op)
1,142✔
1159
{
1160
   mir_build_cover_expr(mu, vcode_get_tag(op));
1,142✔
1161
}
1,142✔
1162

1163
static void import_cover_toggle(mir_unit_t *mu, mir_import_t *imp, int op)
416✔
1164
{
1165
   mir_value_t signal = imp->map[vcode_get_arg(op, 0)];
416✔
1166
   mir_build_cover_toggle(mu, signal, vcode_get_tag(op));
416✔
1167
}
416✔
1168

1169
static void import_cover_state(mir_unit_t *mu, mir_import_t *imp, int op)
16✔
1170
{
1171
   mir_value_t signal = imp->map[vcode_get_arg(op, 0)];
16✔
1172
   mir_value_t low = imp->map[vcode_get_arg(op, 1)];
16✔
1173
   mir_build_cover_state(mu, signal, low, vcode_get_tag(op));
16✔
1174
}
16✔
1175

1176
static void import_array_scope(mir_unit_t *mu, mir_import_t *imp, int op)
839✔
1177
{
1178
   mir_value_t locus = imp->map[vcode_get_arg(op, 0)];
839✔
1179
   mir_type_t type = import_type(mu, imp, vcode_get_type(op));
839✔
1180
   mir_build_array_scope(mu, locus, type);
839✔
1181
}
839✔
1182

1183
static void import_package_scope(mir_unit_t *mu, mir_import_t *imp, int op)
59✔
1184
{
1185
   mir_value_t locus = imp->map[vcode_get_arg(op, 0)];
59✔
1186
   mir_build_package_scope(mu, locus);
59✔
1187
}
59✔
1188

1189
static void import_record_scope(mir_unit_t *mu, mir_import_t *imp, int op)
2,153✔
1190
{
1191
   mir_value_t locus = imp->map[vcode_get_arg(op, 0)];
2,153✔
1192
   mir_type_t type = import_type(mu, imp, vcode_get_type(op));
2,153✔
1193
   mir_build_record_scope(mu, locus, type);
2,153✔
1194
}
2,153✔
1195

1196
static void import_pop_scope(mir_unit_t *mu, mir_import_t *imp, int op)
3,051✔
1197
{
1198
   mir_build_pop_scope(mu);
3,051✔
1199
}
3,051✔
1200

1201
static void import_cmp_trigger(mir_unit_t *mu, mir_import_t *imp, int op)
62✔
1202
{
1203
   mir_value_t left = imp->map[vcode_get_arg(op, 0)];
62✔
1204
   mir_value_t right = imp->map[vcode_get_arg(op, 1)];
62✔
1205
   imp->map[vcode_get_result(op)] = mir_build_cmp_trigger(mu, left, right);
62✔
1206
}
62✔
1207

1208
static void import_function_trigger(mir_unit_t *mu, mir_import_t *imp, int op)
288✔
1209
{
1210
   const int nargs = vcode_count_args(op);
288✔
1211
   mir_value_t *args LOCAL = xmalloc_array(nargs, sizeof(mir_value_t));
576✔
1212
   for (int i = 0; i < nargs; i++)
760✔
1213
      args[i] = imp->map[vcode_get_arg(op, i)];
472✔
1214

1215
   ident_t func = vcode_get_func(op);
288✔
1216
   vcode_reg_t result = vcode_get_result(op);
288✔
1217
   imp->map[result] = mir_build_function_trigger(mu, func, args, nargs);
288✔
1218
}
288✔
1219

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

1227
static void import_add_trigger(mir_unit_t *mu, mir_import_t *imp, int op)
501✔
1228
{
1229
   mir_value_t trigger = imp->map[vcode_get_arg(op, 0)];
501✔
1230
   mir_build_add_trigger(mu, trigger);
501✔
1231
}
501✔
1232

1233
static void import_protected_init(mir_unit_t *mu, mir_import_t *imp, int op)
719✔
1234
{
1235
   mir_value_t context = imp->map[vcode_get_arg(op, 0)];
719✔
1236

1237
   mir_value_t path_name = MIR_NULL_VALUE, inst_name = MIR_NULL_VALUE;
719✔
1238
   if (vcode_count_args(op) > 1) {
719✔
1239
      path_name = imp->map[vcode_get_arg(op, 1)];
548✔
1240
      inst_name = imp->map[vcode_get_arg(op, 2)];
548✔
1241
   }
1242

1243
   vcode_reg_t result = vcode_get_result(op);
719✔
1244
   mir_type_t type = import_type(mu, imp, vcode_reg_type(result));
719✔
1245

1246
   imp->map[result] = mir_build_protected_init(mu, type, context,
719✔
1247
                                               path_name, inst_name);
1248
}
719✔
1249

1250
static void import_instance_name(mir_unit_t *mu, mir_import_t *imp, int op)
1,018✔
1251
{
1252
   mir_value_t kind = imp->map[vcode_get_arg(op, 0)];
1,018✔
1253
   imp->map[vcode_get_result(op)] = mir_build_instance_name(mu, kind);
1,018✔
1254
}
1,018✔
1255

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

1260
   mir_value_t count = MIR_NULL_VALUE;
44✔
1261
   if (vcode_count_args(op) > 1)
44✔
1262
      count = imp->map[vcode_get_arg(op, 1)];
12✔
1263

1264
   imp->map[vcode_get_result(op)] = mir_build_last_event(mu, signal, count);
44✔
1265
}
44✔
1266

1267
static void import_last_active(mir_unit_t *mu, mir_import_t *imp, int op)
48✔
1268
{
1269
   mir_value_t signal = imp->map[vcode_get_arg(op, 0)];
48✔
1270

1271
   mir_value_t count = MIR_NULL_VALUE;
48✔
1272
   if (vcode_count_args(op) > 1)
48✔
1273
      count = imp->map[vcode_get_arg(op, 1)];
8✔
1274

1275
   imp->map[vcode_get_result(op)] = mir_build_last_active(mu, signal, count);
48✔
1276
}
48✔
1277

1278
static void import_last_value(mir_unit_t *mu, mir_import_t *imp, int op)
221✔
1279
{
1280
   mir_value_t signal = imp->map[vcode_get_arg(op, 0)];
221✔
1281
   imp->map[vcode_get_result(op)] = mir_build_last_value(mu, signal);
221✔
1282
}
221✔
1283

1284
static void import_enter_state(mir_unit_t *mu, mir_import_t *imp, int op)
1,040✔
1285
{
1286
   mir_value_t state = imp->map[vcode_get_arg(op, 0)];
1,040✔
1287

1288
   mir_value_t strong = MIR_NULL_VALUE;
1,040✔
1289
   if (vcode_count_args(op) > 1)
1,040✔
1290
      strong = imp->map[vcode_get_arg(op, 1)];
24✔
1291

1292
   mir_build_enter_state(mu, state, strong);
1,040✔
1293
}
1,040✔
1294

1295
static void import_deposit_signal(mir_unit_t *mu, mir_import_t *imp, int op)
×
1296
{
1297
   mir_value_t target = imp->map[vcode_get_arg(op, 0)];
×
1298
   mir_value_t count = imp->map[vcode_get_arg(op, 1)];
×
1299
   mir_value_t values = imp->map[vcode_get_arg(op, 2)];
×
1300

1301
   mir_build_deposit_signal(mu, target, count, values);
×
1302
}
×
1303

1304
static void import_syscall(mir_unit_t *mu, mir_import_t *imp, int op)
×
1305
{
1306
   mir_value_t locus = imp->map[vcode_get_arg(op, 0)];
×
1307
   ident_t func = vcode_get_func(op);
×
1308

1309
   mir_type_t type = MIR_NULL_TYPE;
×
1310
   vcode_type_t vtype = vcode_get_type(op);
×
1311
   if (vtype != VCODE_INVALID_TYPE)
×
1312
      type = import_type(mu, imp, vtype);
×
1313

1314
   const int nargs = vcode_count_args(op) - 1;
×
1315
   mir_value_t *args LOCAL = xmalloc_array(nargs, sizeof(mir_value_t));
×
1316
   for (int i = 0; i < nargs; i++)
×
1317
      args[i] = imp->map[vcode_get_arg(op, i + 1)];
×
1318

1319
   vcode_reg_t result = vcode_get_result(op);
×
1320
   if (result == VCODE_INVALID_REG)
×
1321
      mir_build_syscall(mu, func, type, MIR_NULL_STAMP, locus, args, nargs);
×
1322
   else {
1323
      mir_type_t type = import_type(mu, imp, vcode_reg_type(result));
×
1324
      imp->map[result] =  mir_build_syscall(mu, func, type, MIR_NULL_STAMP,
×
1325
                                            locus, args, nargs);
1326
   }
1327
}
×
1328

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

1335
   mir_value_t bounds = MIR_NULL_VALUE;
64✔
1336
   if (vcode_count_args(op) > 3)
64✔
1337
      bounds = imp->map[vcode_get_arg(op, 3)];
8✔
1338

1339
   imp->map[vcode_get_result(op)] =
64✔
1340
      mir_build_reflect_value(mu, value, context, locus, bounds);
64✔
1341
}
64✔
1342

1343
static void import_reflect_subtype(mir_unit_t *mu, mir_import_t *imp, int op)
56✔
1344
{
1345
   mir_value_t context = imp->map[vcode_get_arg(op, 0)];
56✔
1346
   mir_value_t locus = imp->map[vcode_get_arg(op, 1)];
56✔
1347

1348
   mir_value_t bounds = MIR_NULL_VALUE;
56✔
1349
   if (vcode_count_args(op) > 2)
56✔
1350
      bounds = imp->map[vcode_get_arg(op, 2)];
×
1351

1352
   imp->map[vcode_get_result(op)] =
56✔
1353
      mir_build_reflect_subtype(mu, context, locus, bounds);
56✔
1354
}
56✔
1355

1356
static void import_block(mir_unit_t *mu, mir_import_t *imp)
196,439✔
1357
{
1358
   const int nops = vcode_count_ops();
196,439✔
1359
   for (int i = 0; i < nops; i++) {
2,604,993✔
1360
      mir_set_loc(mu, vcode_get_loc(i));
2,408,554✔
1361

1362
      switch (vcode_get_op(i)) {
2,408,554✔
1363
      case VCODE_OP_COMMENT:
1364
         break;
1365
      case VCODE_OP_PACKAGE_INIT:
34,135✔
1366
         import_package_init(mu, imp, i);
34,135✔
1367
         break;
34,135✔
1368
      case VCODE_OP_LINK_PACKAGE:
13,577✔
1369
         import_link_package(mu, imp, i);
13,577✔
1370
         break;
13,577✔
1371
      case VCODE_OP_LINK_VAR:
5,632✔
1372
         import_link_var(mu, imp, i);
5,632✔
1373
         break;
5,632✔
1374
      case VCODE_OP_RETURN:
78,672✔
1375
         import_return(mu, imp, i);
78,672✔
1376
         break;
78,672✔
1377
      case VCODE_OP_FCALL:
45,111✔
1378
         import_fcall(mu, imp, i);
45,111✔
1379
         break;
45,111✔
1380
      case VCODE_OP_PCALL:
1,089✔
1381
         import_pcall(mu, imp, i);
1,089✔
1382
         break;
1,089✔
1383
      case VCODE_OP_RESUME:
1,089✔
1384
         import_resume(mu, imp, i);
1,089✔
1385
         break;
1,089✔
1386
      case VCODE_OP_CONST:
482,463✔
1387
         import_const(mu, imp, i);
482,463✔
1388
         break;
482,463✔
1389
      case VCODE_OP_CONST_REAL:
29,604✔
1390
         import_const_real(mu, imp, i);
29,604✔
1391
         break;
29,604✔
1392
      case VCODE_OP_CONST_ARRAY:
35,577✔
1393
         import_const_array(mu, imp, i);
35,577✔
1394
         break;
35,577✔
1395
      case VCODE_OP_CONST_REP:
423✔
1396
         import_const_rep(mu, imp, i);
423✔
1397
         break;
423✔
1398
      case VCODE_OP_CONST_RECORD:
2,666✔
1399
         import_const_record(mu, imp, i);
2,666✔
1400
         break;
2,666✔
1401
      case VCODE_OP_CMP:
50,495✔
1402
         import_cmp(mu, imp, i);
50,495✔
1403
         break;
50,495✔
1404
      case VCODE_OP_DEBUG_LOCUS:
100,423✔
1405
         import_debug_locus(mu, imp, i);
100,423✔
1406
         break;
100,423✔
1407
      case VCODE_OP_ASSERT:
18,708✔
1408
         import_assert(mu, imp, i);
18,708✔
1409
         break;
18,708✔
1410
      case VCODE_OP_REPORT:
2,659✔
1411
         import_report(mu, imp, i);
2,659✔
1412
         break;
2,659✔
1413
      case VCODE_OP_WAIT:
17,785✔
1414
         import_wait(mu, imp, i);
17,785✔
1415
         break;
17,785✔
1416
      case VCODE_OP_JUMP:
50,237✔
1417
         import_jump(mu, imp, i);
50,237✔
1418
         break;
50,237✔
1419
      case VCODE_OP_COND:
46,150✔
1420
         import_cond(mu, imp, i);
46,150✔
1421
         break;
46,150✔
1422
      case VCODE_OP_INIT_SIGNAL:
20,853✔
1423
         import_init_signal(mu, imp, i);
20,853✔
1424
         break;
20,853✔
1425
      case VCODE_OP_IMPLICIT_SIGNAL:
108✔
1426
         import_implicit_signal(mu, imp, i);
108✔
1427
         break;
108✔
1428
      case VCODE_OP_DRIVE_SIGNAL:
12,350✔
1429
         import_drive_signal(mu, imp, i);
12,350✔
1430
         break;
12,350✔
1431
      case VCODE_OP_SCHED_WAVEFORM:
14,198✔
1432
         import_sched_waveform(mu, imp, i);
14,198✔
1433
         break;
14,198✔
1434
      case VCODE_OP_RESOLVED:
18,654✔
1435
         import_resolved(mu, imp, i);
18,654✔
1436
         break;
18,654✔
1437
      case VCODE_OP_ADDRESS_OF:
37,213✔
1438
         import_address_of(mu, imp, i);
37,213✔
1439
         break;
37,213✔
1440
      case VCODE_OP_STORE:
99,985✔
1441
         import_store(mu, imp, i);
99,985✔
1442
         break;
99,985✔
1443
      case VCODE_OP_STORE_INDIRECT:
19,206✔
1444
         import_store_indirect(mu, imp, i);
19,206✔
1445
         break;
19,206✔
1446
      case VCODE_OP_LOAD:
51,458✔
1447
         import_load(mu, imp, i);
51,458✔
1448
         break;
51,458✔
1449
      case VCODE_OP_LOAD_INDIRECT:
120,931✔
1450
         import_load_indirect(mu, imp, i);
120,931✔
1451
         break;
120,931✔
1452
      case VCODE_OP_CONTEXT_UPREF:
15,782✔
1453
         import_context_upref(mu, imp, i);
15,782✔
1454
         break;
15,782✔
1455
      case VCODE_OP_VAR_UPREF:
61,335✔
1456
         import_var_upref(mu, imp, i);
61,335✔
1457
         break;
61,335✔
1458
      case VCODE_OP_WRAP:
37,000✔
1459
         import_wrap(mu, imp, i);
37,000✔
1460
         break;
37,000✔
1461
      case VCODE_OP_UNWRAP:
37,008✔
1462
         import_unwrap(mu, imp, i);
37,008✔
1463
         break;
37,008✔
1464
      case VCODE_OP_UARRAY_LEN:
28,626✔
1465
         import_uarray_len(mu, imp, i);
28,626✔
1466
         break;
28,626✔
1467
      case VCODE_OP_UARRAY_LEFT:
22,676✔
1468
         import_uarray_left(mu, imp, i);
22,676✔
1469
         break;
22,676✔
1470
      case VCODE_OP_UARRAY_RIGHT:
18,576✔
1471
         import_uarray_right(mu, imp, i);
18,576✔
1472
         break;
18,576✔
1473
      case VCODE_OP_UARRAY_DIR:
22,590✔
1474
         import_uarray_dir(mu, imp, i);
22,590✔
1475
         break;
22,590✔
1476
      case VCODE_OP_ADD:
19,055✔
1477
         import_add(mu, imp, i);
19,055✔
1478
         break;
19,055✔
1479
      case VCODE_OP_TRAP_ADD:
5,319✔
1480
         import_trap_add(mu, imp, i);
5,319✔
1481
         break;
5,319✔
1482
      case VCODE_OP_SUB:
38,015✔
1483
         import_sub(mu, imp, i);
38,015✔
1484
         break;
38,015✔
1485
      case VCODE_OP_TRAP_SUB:
1,723✔
1486
         import_trap_sub(mu, imp, i);
1,723✔
1487
         break;
1,723✔
1488
      case VCODE_OP_MUL:
4,081✔
1489
         import_mul(mu, imp, i);
4,081✔
1490
         break;
4,081✔
1491
      case VCODE_OP_TRAP_MUL:
492✔
1492
         import_trap_mul(mu, imp, i);
492✔
1493
         break;
492✔
1494
      case VCODE_OP_DIV:
2,027✔
1495
         import_div(mu, imp, i);
2,027✔
1496
         break;
2,027✔
1497
      case VCODE_OP_MOD:
169✔
1498
         import_mod(mu, imp, i);
169✔
1499
         break;
169✔
1500
      case VCODE_OP_REM:
884✔
1501
         import_rem(mu, imp, i);
884✔
1502
         break;
884✔
1503
      case VCODE_OP_EXP:
175✔
1504
         import_exp(mu, imp, i);
175✔
1505
         break;
175✔
1506
      case VCODE_OP_TRAP_EXP:
684✔
1507
         import_trap_exp(mu, imp, i);
684✔
1508
         break;
684✔
1509
      case VCODE_OP_OR:
2,688✔
1510
         import_or(mu, imp, i);
2,688✔
1511
         break;
2,688✔
1512
      case VCODE_OP_NOR:
50✔
1513
         import_nor(mu, imp, i);
50✔
1514
         break;
50✔
1515
      case VCODE_OP_XOR:
84✔
1516
         import_xor(mu, imp, i);
84✔
1517
         break;
84✔
1518
      case VCODE_OP_XNOR:
53✔
1519
         import_xnor(mu, imp, i);
53✔
1520
         break;
53✔
1521
      case VCODE_OP_AND:
5,654✔
1522
         import_and(mu, imp, i);
5,654✔
1523
         break;
5,654✔
1524
      case VCODE_OP_NAND:
49✔
1525
         import_nand(mu, imp, i);
49✔
1526
         break;
49✔
1527
      case VCODE_OP_EVENT:
530✔
1528
         import_event(mu, imp, i);
530✔
1529
         break;
530✔
1530
      case VCODE_OP_ACTIVE:
293✔
1531
         import_active(mu, imp, i);
293✔
1532
         break;
293✔
1533
      case VCODE_OP_DRIVING:
48✔
1534
         import_driving(mu, imp, i);
48✔
1535
         break;
48✔
1536
      case VCODE_OP_NOT:
3,351✔
1537
         import_not(mu, imp, i);
3,351✔
1538
         break;
3,351✔
1539
      case VCODE_OP_CAST:
74,105✔
1540
         import_cast(mu, imp, i);
74,105✔
1541
         break;
74,105✔
1542
      case VCODE_OP_NEG:
9,182✔
1543
         import_neg(mu, imp, i);
9,182✔
1544
         break;
9,182✔
1545
      case VCODE_OP_TRAP_NEG:
344✔
1546
         import_trap_neg(mu, imp, i);
344✔
1547
         break;
344✔
1548
      case VCODE_OP_ABS:
987✔
1549
         import_abs(mu, imp, i);
987✔
1550
         break;
987✔
1551
      case VCODE_OP_INDEX:
31,382✔
1552
         import_index(mu, imp, i);
31,382✔
1553
         break;
31,382✔
1554
      case VCODE_OP_COPY:
30,691✔
1555
         import_copy(mu, imp, i);
30,691✔
1556
         break;
30,691✔
1557
      case VCODE_OP_MEMSET:
7,597✔
1558
         import_memset(mu, imp, i);
7,597✔
1559
         break;
7,597✔
1560
      case VCODE_OP_ARRAY_REF:
48,859✔
1561
         import_array_ref(mu, imp, i);
48,859✔
1562
         break;
48,859✔
1563
      case VCODE_OP_RECORD_REF:
48,405✔
1564
         import_record_ref(mu, imp, i);
48,405✔
1565
         break;
48,405✔
1566
      case VCODE_OP_RANGE_CHECK:
5,695✔
1567
         import_range_check(mu, imp, i);
5,695✔
1568
         break;
5,695✔
1569
      case VCODE_OP_SCHED_EVENT:
7,860✔
1570
         import_sched_event(mu, imp, i);
7,860✔
1571
         break;
7,860✔
1572
      case VCODE_OP_CLEAR_EVENT:
702✔
1573
         import_clear_event(mu, imp, i);
702✔
1574
         break;
702✔
1575
      case VCODE_OP_ALLOC:
9,200✔
1576
         import_alloc(mu, imp, i);
9,200✔
1577
         break;
9,200✔
1578
      case VCODE_OP_RANGE_LENGTH:
9,038✔
1579
         import_range_length(mu, imp, i);
9,038✔
1580
         break;
9,038✔
1581
      case VCODE_OP_RANGE_NULL:
4,321✔
1582
         import_range_null(mu, imp, i);
4,321✔
1583
         break;
4,321✔
1584
      case VCODE_OP_NULL:
5,239✔
1585
         import_null(mu, imp, i);
5,239✔
1586
         break;
5,239✔
1587
      case VCODE_OP_NEW:
854✔
1588
         import_new(mu, imp, i);
854✔
1589
         break;
854✔
1590
      case VCODE_OP_ALL:
3,755✔
1591
         import_all(mu, imp, i);
3,755✔
1592
         break;
3,755✔
1593
      case VCODE_OP_DEALLOCATE:
459✔
1594
         import_deallocate(mu, imp, i);
459✔
1595
         break;
459✔
1596
      case VCODE_OP_ZERO_CHECK:
119✔
1597
         import_zero_check(mu, imp, i);
119✔
1598
         break;
119✔
1599
      case VCODE_OP_NULL_CHECK:
2,901✔
1600
         import_null_check(mu, imp, i);
2,901✔
1601
         break;
2,901✔
1602
      case VCODE_OP_LENGTH_CHECK:
9,538✔
1603
         import_length_check(mu, imp, i);
9,538✔
1604
         break;
9,538✔
1605
      case VCODE_OP_INDEX_CHECK:
21,043✔
1606
         import_index_check(mu, imp, i);
21,043✔
1607
         break;
21,043✔
1608
      case VCODE_OP_ALIAS_SIGNAL:
5,570✔
1609
         import_alias_signal(mu, imp, i);
5,570✔
1610
         break;
5,570✔
1611
      case VCODE_OP_MAP_SIGNAL:
7,078✔
1612
         import_map_signal(mu, imp, i);
7,078✔
1613
         break;
7,078✔
1614
      case VCODE_OP_MAP_CONST:
248✔
1615
         import_map_const(mu, imp, i);
248✔
1616
         break;
248✔
1617
      case VCODE_OP_MAP_IMPLICIT:
84✔
1618
         import_map_implicit(mu, imp, i);
84✔
1619
         break;
84✔
1620
      case VCODE_OP_CASE:
799✔
1621
         import_case(mu, imp, i);
799✔
1622
         break;
799✔
1623
      case VCODE_OP_BIND_FOREIGN:
1,294✔
1624
         import_bind_foreign(mu, imp, i);
1,294✔
1625
         break;
1,294✔
1626
      case VCODE_OP_BIND_EXTERNAL:
261✔
1627
         import_bind_external(mu, imp, i);
261✔
1628
         break;
261✔
1629
      case VCODE_OP_UNREACHABLE:
1,707✔
1630
         import_unreachable(mu, imp, i);
1,707✔
1631
         break;
1,707✔
1632
      case VCODE_OP_SELECT:
18,147✔
1633
         import_select(mu, imp, i);
18,147✔
1634
         break;
18,147✔
1635
      case VCODE_OP_CLOSURE:
6,290✔
1636
         import_closure(mu, imp, i);
6,290✔
1637
         break;
6,290✔
1638
      case VCODE_OP_RESOLUTION_WRAPPER:
5,902✔
1639
         import_resolution_wrapper(mu, imp, i);
5,902✔
1640
         break;
5,902✔
1641
      case VCODE_OP_RESOLVE_SIGNAL:
4,272✔
1642
         import_resolve_signal(mu, imp, i);
4,272✔
1643
         break;
4,272✔
1644
      case VCODE_OP_TRANSFER_SIGNAL:
1,606✔
1645
         import_transfer_signal(mu, imp, i);
1,606✔
1646
         break;
1,606✔
1647
      case VCODE_OP_FILE_OPEN:
1,550✔
1648
         import_file_open(mu, imp, i);
1,550✔
1649
         break;
1,550✔
1650
      case VCODE_OP_FILE_READ:
120✔
1651
         import_file_read(mu, imp, i);
120✔
1652
         break;
120✔
1653
      case VCODE_OP_FILE_WRITE:
339✔
1654
         import_file_write(mu, imp, i);
339✔
1655
         break;
339✔
1656
      case VCODE_OP_PORT_CONVERSION:
256✔
1657
         import_port_conversion(mu, imp, i);
256✔
1658
         break;
256✔
1659
      case VCODE_OP_CONVERT_IN:
360✔
1660
         import_convert_in(mu, imp, i);
360✔
1661
         break;
360✔
1662
      case VCODE_OP_CONVERT_OUT:
416✔
1663
         import_convert_out(mu, imp, i);
416✔
1664
         break;
416✔
1665
      case VCODE_OP_DRIVING_VALUE:
152✔
1666
         import_driving_value(mu, imp, i);
152✔
1667
         break;
152✔
1668
      case VCODE_OP_PUT_CONVERSION:
440✔
1669
         import_put_conversion(mu, imp, i);
440✔
1670
         break;
440✔
1671
      case VCODE_OP_FORCE:
84✔
1672
         import_force(mu, imp, i);
84✔
1673
         break;
84✔
1674
      case VCODE_OP_RELEASE:
40✔
1675
         import_release(mu, imp, i);
40✔
1676
         break;
40✔
1677
      case VCODE_OP_DISCONNECT:
32✔
1678
         import_disconnect(mu, imp, i);
32✔
1679
         break;
32✔
1680
      case VCODE_OP_EXPONENT_CHECK:
660✔
1681
         import_exponent_check(mu, imp, i);
660✔
1682
         break;
660✔
1683
      case VCODE_OP_PROCESS_INIT:
154✔
1684
         import_process_init(mu, imp, i);
154✔
1685
         break;
154✔
1686
      case VCODE_OP_COVER_STMT:
1,374✔
1687
         import_cover_stmt(mu, imp, i);
1,374✔
1688
         break;
1,374✔
1689
      case VCODE_OP_COVER_BRANCH:
657✔
1690
         import_cover_branch(mu, imp, i);
657✔
1691
         break;
657✔
1692
      case VCODE_OP_COVER_EXPR:
1,142✔
1693
         import_cover_expr(mu, imp, i);
1,142✔
1694
         break;
1,142✔
1695
      case VCODE_OP_COVER_TOGGLE:
416✔
1696
         import_cover_toggle(mu, imp, i);
416✔
1697
         break;
416✔
1698
      case VCODE_OP_COVER_STATE:
16✔
1699
         import_cover_state(mu, imp, i);
16✔
1700
         break;
16✔
1701
      case VCODE_OP_ARRAY_SCOPE:
839✔
1702
         import_array_scope(mu, imp, i);
839✔
1703
         break;
839✔
1704
      case VCODE_OP_PACKAGE_SCOPE:
59✔
1705
         import_package_scope(mu, imp, i);
59✔
1706
         break;
59✔
1707
      case VCODE_OP_RECORD_SCOPE:
2,153✔
1708
         import_record_scope(mu, imp, i);
2,153✔
1709
         break;
2,153✔
1710
      case VCODE_OP_POP_SCOPE:
3,051✔
1711
         import_pop_scope(mu, imp, i);
3,051✔
1712
         break;
3,051✔
1713
      case VCODE_OP_CMP_TRIGGER:
62✔
1714
         import_cmp_trigger(mu, imp, i);
62✔
1715
         break;
62✔
1716
      case VCODE_OP_FUNCTION_TRIGGER:
288✔
1717
         import_function_trigger(mu, imp, i);
288✔
1718
         break;
288✔
1719
      case VCODE_OP_OR_TRIGGER:
45✔
1720
         import_or_trigger(mu, imp, i);
45✔
1721
         break;
45✔
1722
      case VCODE_OP_ADD_TRIGGER:
501✔
1723
         import_add_trigger(mu, imp, i);
501✔
1724
         break;
501✔
1725
      case VCODE_OP_PROTECTED_INIT:
719✔
1726
         import_protected_init(mu, imp, i);
719✔
1727
         break;
719✔
1728
      case VCODE_OP_PROTECTED_FREE:
1729
         break;   // No-op
1730
      case VCODE_OP_INSTANCE_NAME:
1,018✔
1731
         import_instance_name(mu, imp, i);
1,018✔
1732
         break;
1,018✔
1733
      case VCODE_OP_LAST_EVENT:
44✔
1734
         import_last_event(mu, imp, i);
44✔
1735
         break;
44✔
1736
      case VCODE_OP_LAST_ACTIVE:
48✔
1737
         import_last_active(mu, imp, i);
48✔
1738
         break;
48✔
1739
      case VCODE_OP_LAST_VALUE:
221✔
1740
         import_last_value(mu, imp, i);
221✔
1741
         break;
221✔
1742
      case VCODE_OP_ENTER_STATE:
1,040✔
1743
         import_enter_state(mu, imp, i);
1,040✔
1744
         break;
1,040✔
1745
      case VCODE_OP_DEPOSIT_SIGNAL:
×
1746
         import_deposit_signal(mu, imp, i);
×
1747
         break;
×
1748
      case VCODE_OP_SYSCALL:
×
1749
         import_syscall(mu, imp, i);
×
1750
         break;
×
1751
      case VCODE_OP_REFLECT_SUBTYPE:
56✔
1752
         import_reflect_subtype(mu, imp, i);
56✔
1753
         break;
56✔
1754
      case VCODE_OP_REFLECT_VALUE:
64✔
1755
         import_reflect_value(mu, imp, i);
64✔
1756
         break;
64✔
1757
      default:
×
1758
         vcode_dump_with_mark(i, NULL, NULL);
×
1759
         fatal_trace("cannot import vcode op %s",
1760
                     vcode_op_string(vcode_get_op(i)));
1761
      }
1762
   }
1763
}
196,439✔
1764

1765
mir_unit_t *mir_import(mir_context_t *mc, vcode_unit_t vu)
70,505✔
1766
{
1767
   static const mir_unit_kind_t kind_map[] = {
70,505✔
1768
      [VCODE_UNIT_FUNCTION] = MIR_UNIT_FUNCTION,
1769
      [VCODE_UNIT_INSTANCE] = MIR_UNIT_INSTANCE,
1770
      [VCODE_UNIT_PROCEDURE] = MIR_UNIT_PROCEDURE,
1771
      [VCODE_UNIT_PROCESS] = MIR_UNIT_PROCESS,
1772
      [VCODE_UNIT_PACKAGE] = MIR_UNIT_PACKAGE,
1773
      [VCODE_UNIT_THUNK] = MIR_UNIT_THUNK,
1774
      [VCODE_UNIT_PROTECTED] = MIR_UNIT_PROTECTED,
1775
      [VCODE_UNIT_PROPERTY] = MIR_UNIT_PROPERTY,
1776
   };
1777

1778
   const mir_unit_kind_t kind = kind_map[vcode_unit_kind(vu)];
70,505✔
1779

1780
   mir_shape_t *parent = NULL;
70,505✔
1781
   vcode_unit_t context = vcode_unit_context(vu);
70,505✔
1782
   if (context != NULL) {
70,505✔
1783
      ident_t name = vcode_unit_name(context);
41,495✔
1784
      if ((parent = mir_get_shape(mc, name)) == NULL) {
41,495✔
UNCOV
1785
         mir_unit_t *parent_mu = mir_import(mc, context);
×
1786
         mir_put_unit(mc, parent_mu);
×
1787

UNCOV
1788
         parent = mir_get_shape(mc, name);
×
1789
         assert(parent != NULL);
×
1790
      }
1791
   }
1792

1793
   ident_t name = vcode_unit_name(vu);
70,505✔
1794
   object_t *obj = vcode_unit_object(vu);
70,505✔
1795

1796
   mir_unit_t *mu = mir_unit_new(mc, name, obj, kind, parent);
70,505✔
1797

1798
   vcode_select_unit(vu);
70,505✔
1799

1800
   const int nblocks = vcode_count_blocks();
70,505✔
1801
   const int nregs = vcode_count_regs();
70,505✔
1802
   const int nvars = vcode_count_vars();
70,505✔
1803

1804
   mir_import_t imp = {};
70,505✔
1805
   imp.blocks = xcalloc_array(nblocks, sizeof(mir_block_t));
70,505✔
1806
   imp.map    = xcalloc_array(nregs, sizeof(mir_value_t));
70,505✔
1807
   imp.vars   = xcalloc_array(nvars, sizeof(mir_value_t));
70,505✔
1808
   imp.types  = ihash_new(64);
70,505✔
1809

1810
   switch (kind) {
70,505✔
1811
   case MIR_UNIT_FUNCTION:
18,671✔
1812
      {
1813
         vcode_type_t vresult = vcode_unit_result(vu);
18,671✔
1814
         if (vresult != VCODE_INVALID_TYPE)
18,671✔
1815
            mir_set_result(mu, import_type(mu, &imp, vresult));
15,950✔
1816
      }
1817
      // Fall-through
1818
   case MIR_UNIT_PROCEDURE:
1819
   case MIR_UNIT_PROTECTED:
1820
   case MIR_UNIT_PROPERTY:
1821
      {
1822
         const int nparams = vcode_count_params();
19,946✔
1823
         for (int i = 0; i < nparams; i++) {
69,766✔
1824
            vcode_reg_t preg = vcode_param_reg(i);
49,820✔
1825
            mir_type_t type = import_type(mu, &imp, vcode_param_type(i));
49,820✔
1826
            ident_t name = vcode_param_name(i);
49,820✔
1827
            imp.map[preg] = mir_add_param(mu, type, MIR_NULL_STAMP, name);
49,820✔
1828
         }
1829
      }
1830
      break;
1831
   case MIR_UNIT_THUNK:
15,037✔
1832
      mir_set_result(mu, import_type(mu, &imp, vcode_unit_result(vu)));
15,037✔
1833
      break;
15,037✔
1834
   default:
1835
      break;
1836
   }
1837

1838
   for (int i = 0; i < nvars; i++) {
162,465✔
1839
      mir_type_t type = import_type(mu, &imp, vcode_var_type(i));
91,960✔
1840
      imp.vars[i] = mir_add_var(mu, type, MIR_NULL_STAMP, vcode_var_name(i),
91,960✔
1841
                                (mir_var_flags_t)vcode_var_flags(i));
91,960✔
1842
   }
1843

1844
   imp.blocks[0] = mir_get_cursor(mu, NULL);
70,505✔
1845
   for (int i = 1; i < nblocks; i++)
196,439✔
1846
      imp.blocks[i] = mir_add_block(mu);
125,934✔
1847

1848
   for (int i = 0; i < nblocks; i++) {
266,944✔
1849
      vcode_select_block(i);
196,439✔
1850
      mir_set_cursor(mu, imp.blocks[i], MIR_APPEND);
196,439✔
1851
      import_block(mu, &imp);
196,439✔
1852
   }
1853

1854
   ihash_free(imp.types);
70,505✔
1855
   free(imp.blocks);
70,505✔
1856
   free(imp.map);
70,505✔
1857
   free(imp.vars);
70,505✔
1858

1859
   return mu;
70,505✔
1860
}
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