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

nickg / nvc / 15094290326

18 May 2025 08:51AM UTC coverage: 92.332% (-0.02%) from 92.354%
15094290326

push

github

nickg
Fix non-accelerated SHA1 writing to input buffer

Spotted by @Blebowski in #1184

69299 of 75054 relevant lines covered (92.33%)

387241.01 hits per line

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

98.97
/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,
709,490✔
36
                              vcode_type_t vtype)
37
{
38
   void *ptr = ihash_get(imp->types, vtype);
709,490✔
39
   if (ptr != NULL)
709,490✔
40
      return (mir_type_t){ .bits = (uintptr_t)ptr };
538,708✔
41

42
   mir_type_t type;
170,782✔
43
   switch (vtype_kind(vtype)) {
170,782✔
44
   case VCODE_TYPE_INT:
75,927✔
45
      type = mir_int_type(mu, vtype_low(vtype), vtype_high(vtype));
75,927✔
46
      break;
75,927✔
47
   case VCODE_TYPE_REAL:
8,394✔
48
      type = mir_real_type(mu, -DBL_MAX, DBL_MAX);
8,394✔
49
      break;
8,394✔
50
   case VCODE_TYPE_OFFSET:
21,317✔
51
      type = mir_offset_type(mu);
21,317✔
52
      break;
21,317✔
53
   case VCODE_TYPE_SIGNAL:
8,776✔
54
      type = mir_signal_type(mu, import_type(mu, imp, vtype_base(vtype)));
8,776✔
55
      break;
8,776✔
56
   case VCODE_TYPE_UARRAY:
13,558✔
57
      type = mir_uarray_type(mu, vtype_dims(vtype),
13,558✔
58
                             import_type(mu, imp, vtype_elem(vtype)));
59
      break;
13,558✔
60
   case VCODE_TYPE_CARRAY:
16,557✔
61
      type = mir_carray_type(mu, vtype_size(vtype),
16,557✔
62
                             import_type(mu, imp, vtype_elem(vtype)));
63
      break;
16,557✔
64
   case VCODE_TYPE_CONTEXT:
12,352✔
65
      type = mir_context_type(mu, vtype_name(vtype));
12,352✔
66
      break;
12,352✔
67
   case VCODE_TYPE_ACCESS:
1,150✔
68
      type = mir_access_type(mu, import_type(mu, imp, vtype_pointed(vtype)));
1,150✔
69
      break;
1,150✔
70
   case VCODE_TYPE_OPAQUE:
315✔
71
      type = mir_opaque_type(mu);
315✔
72
      break;
315✔
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,833✔
81
      {
82
         const int nfields = vtype_fields(vtype);
5,833✔
83
         mir_type_t *fields LOCAL = xmalloc_array(nfields, sizeof(mir_type_t));
11,666✔
84
         for (int i = 0; i < nfields; i++)
25,184✔
85
            fields[i] = import_type(mu, imp, vtype_field(vtype, i));
19,351✔
86

87
         type = mir_record_type(mu, vtype_name(vtype), fields, nfields);
5,833✔
88
      }
89
      break;
5,833✔
90
   case VCODE_TYPE_POINTER:
4,691✔
91
      type = mir_pointer_type(mu, import_type(mu, imp, vtype_pointed(vtype)));
4,691✔
92
      break;
4,691✔
93
   case VCODE_TYPE_FILE:
364✔
94
      type = mir_file_type(mu, import_type(mu, imp, vtype_base(vtype)));
364✔
95
      break;
364✔
96
   case VCODE_TYPE_CONVERSION:
300✔
97
      type = mir_conversion_type(mu);
300✔
98
      break;
300✔
99
   case VCODE_TYPE_TRIGGER:
75✔
100
      type = mir_trigger_type(mu);
75✔
101
      break;
75✔
102
   case VCODE_TYPE_DEBUG_LOCUS:
46✔
103
      type = mir_locus_type(mu);
46✔
104
      break;
46✔
105
   case VCODE_TYPE_RESOLUTION:
1,127✔
106
      type = mir_resolution_type(mu, import_type(mu, imp, vtype_base(vtype)));
1,127✔
107
      break;
1,127✔
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);
170,782✔
114
   return type;
170,782✔
115
}
116

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

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

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

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

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

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

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

152
   mir_build_return(mu, result);
53,315✔
153
}
53,315✔
154

155
static void import_fcall(mir_unit_t *mu, mir_import_t *imp, int op)
36,211✔
156
{
157
   const int nargs = vcode_count_args(op);
36,211✔
158
   mir_value_t *args LOCAL = xmalloc_array(nargs, sizeof(mir_value_t));
72,422✔
159
   for (int i = 0; i < nargs; i++)
141,535✔
160
      args[i] = imp->map[vcode_get_arg(op, i)];
105,324✔
161

162
   ident_t func = vcode_get_func(op);
36,211✔
163
   vcode_reg_t result = vcode_get_result(op);
36,211✔
164
   if (result == VCODE_INVALID_REG)
36,211✔
165
      mir_build_fcall(mu, func, MIR_NULL_TYPE, MIR_NULL_STAMP, args, nargs);
4,963✔
166
   else {
167
      mir_type_t type = import_type(mu, imp, vcode_reg_type(result));
31,248✔
168
      imp->map[result] = mir_build_fcall(mu, func, type, MIR_NULL_STAMP,
31,248✔
169
                                         args, nargs);
170
   }
171
}
36,211✔
172

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

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

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

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

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

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

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

210
   const int nargs = vcode_count_args(op);
21,775✔
211
   mir_value_t *elts LOCAL = xmalloc_array(nargs, sizeof(mir_value_t));
43,550✔
212
   for (int i = 0; i < nargs; i++)
1,179,493✔
213
      elts[i] = imp->map[vcode_get_arg(op, i)];
1,157,718✔
214

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

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

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

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

233
   const int nargs = vcode_count_args(op);
2,282✔
234
   mir_value_t *elts LOCAL = xmalloc_array(nargs, sizeof(mir_value_t));
4,564✔
235
   for (int i = 0; i < nargs; i++)
8,174✔
236
      elts[i] = imp->map[vcode_get_arg(op, i)];
5,892✔
237

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

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

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

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

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

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

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

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

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

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

293
   mir_value_t after = MIR_NULL_VALUE;
13,798✔
294
   vcode_reg_t after_reg = vcode_get_arg(op, 0);
13,798✔
295
   if (after_reg != VCODE_INVALID_REG)
13,798✔
296
      after = imp->map[after_reg];
5,368✔
297

298
   mir_build_wait(mu, btarget, after);
13,798✔
299
}
13,798✔
300

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

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

313
   mir_build_cond(mu, test, btrue, bfalse);
32,971✔
314
}
32,971✔
315

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

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

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

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

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

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

342
   mir_value_t offset = MIR_NULL_VALUE;
15,930✔
343
   if (vcode_count_args(op) > 5)
15,930✔
344
      offset = imp->map[vcode_get_arg(op, 5)];
5,607✔
345

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

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

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

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

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

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

374
   mir_build_drive_signal(mu, target, count);
9,371✔
375
}
9,371✔
376

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

628
   imp->map[vcode_get_result(op)] = mir_build_nor(mu, left, right);
63✔
629
}
63✔
630

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

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

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

644
   imp->map[vcode_get_result(op)] = mir_build_xnor(mu, left, right);
64✔
645
}
64✔
646

647
static void import_and(mir_unit_t *mu, mir_import_t *imp, int op)
3,752✔
648
{
649
   mir_value_t left  = imp->map[vcode_get_arg(op, 0)];
3,752✔
650
   mir_value_t right = imp->map[vcode_get_arg(op, 1)];
3,752✔
651

652
   imp->map[vcode_get_result(op)] = mir_build_and(mu, left, right);
3,752✔
653
}
3,752✔
654

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

660
   imp->map[vcode_get_result(op)] = mir_build_nand(mu, left, right);
62✔
661
}
62✔
662

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

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

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

684
static void import_not(mir_unit_t *mu, mir_import_t *imp, int op)
2,699✔
685
{
686
   mir_value_t arg = imp->map[vcode_get_arg(op, 0)];
2,699✔
687
   imp->map[vcode_get_result(op)] = mir_build_not(mu, arg);
2,699✔
688
}
2,699✔
689

690
static void import_cast(mir_unit_t *mu, mir_import_t *imp, int op)
48,193✔
691
{
692
   mir_value_t arg = imp->map[vcode_get_arg(op, 0)];
48,193✔
693
   mir_type_t type = import_type(mu, imp, vcode_get_type(op));
48,193✔
694
   imp->map[vcode_get_result(op)] = mir_build_cast(mu, type, arg);
48,193✔
695
}
48,193✔
696

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

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

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

722
static void import_index(mir_unit_t *mu, mir_import_t *imp, int op)
14,934✔
723
{
724
   mir_value_t var = imp->vars[vcode_get_address(op)];
14,934✔
725
   imp->map[vcode_get_result(op)] = var;
14,934✔
726
}
14,934✔
727

728
static void import_copy(mir_unit_t *mu, mir_import_t *imp, int op)
16,030✔
729
{
730
   mir_value_t dst = imp->map[vcode_get_arg(op, 0)];
16,030✔
731
   mir_value_t src = imp->map[vcode_get_arg(op, 1)];
16,030✔
732

733
   mir_value_t count = MIR_NULL_VALUE;
16,030✔
734
   if (vcode_count_args(op) > 2)
16,030✔
735
      count = imp->map[vcode_get_arg(op, 2)];
14,208✔
736

737
   mir_build_copy(mu, dst, src, count);
16,030✔
738
}
16,030✔
739

740
static void import_memset(mir_unit_t *mu, mir_import_t *imp, int op)
5,635✔
741
{
742
   mir_value_t dst   = imp->map[vcode_get_arg(op, 0)];
5,635✔
743
   mir_value_t value = imp->map[vcode_get_arg(op, 1)];
5,635✔
744
   mir_value_t count = imp->map[vcode_get_arg(op, 2)];
5,635✔
745

746
   mir_build_set(mu, dst, value, count);
5,635✔
747
}
5,635✔
748

749
static void import_array_ref(mir_unit_t *mu, mir_import_t *imp, int op)
32,970✔
750
{
751
   mir_value_t array  = imp->map[vcode_get_arg(op, 0)];
32,970✔
752
   mir_value_t offset = imp->map[vcode_get_arg(op, 1)];
32,970✔
753
   imp->map[vcode_get_result(op)] = mir_build_array_ref(mu, array, offset);
32,970✔
754
}
32,970✔
755

756
static void import_record_ref(mir_unit_t *mu, mir_import_t *imp, int op)
37,886✔
757
{
758
   mir_value_t record = imp->map[vcode_get_arg(op, 0)];
37,886✔
759
   const int field = vcode_get_field(op);
37,886✔
760
   imp->map[vcode_get_result(op)] = mir_build_record_ref(mu, record, field);
37,886✔
761
}
37,886✔
762

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

772
   mir_build_range_check(mu, value, left, right, dir, locus, hint);
2,754✔
773
}
2,754✔
774

775
static void import_sched_event(mir_unit_t *mu, mir_import_t *imp, int op)
5,944✔
776
{
777
   mir_value_t signal = imp->map[vcode_get_arg(op, 0)];
5,944✔
778
   mir_value_t count  = imp->map[vcode_get_arg(op, 1)];
5,944✔
779
   mir_build_sched_event(mu, signal, count);
5,944✔
780
}
5,944✔
781

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

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

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

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

815
static void import_null(mir_unit_t *mu, mir_import_t *imp, int op)
2,552✔
816
{
817
   vcode_reg_t result = vcode_get_result(op);
2,552✔
818
   mir_type_t type = import_type(mu, imp, vcode_reg_type(result));
2,552✔
819
   imp->map[result] = mir_build_null(mu, type);
2,552✔
820
}
2,552✔
821

822
static void import_new(mir_unit_t *mu, mir_import_t *imp, int op)
423✔
823
{
824
   vcode_reg_t result = vcode_get_result(op);
423✔
825
   vcode_type_t vtype = vtype_pointed(vcode_reg_type(result));
423✔
826
   mir_type_t type = import_type(mu, imp, vtype);
423✔
827

828
   mir_value_t count = MIR_NULL_VALUE;
423✔
829
   if (vcode_count_args(op) > 0)
423✔
830
      count = imp->map[vcode_get_arg(op, 0)];
332✔
831

832
   imp->map[result] = mir_build_new(mu, type, MIR_NULL_STAMP, count);
423✔
833
}
423✔
834

835
static void import_all(mir_unit_t *mu, mir_import_t *imp, int op)
1,535✔
836
{
837
   mir_value_t arg = imp->map[vcode_get_arg(op, 0)];
1,535✔
838
   imp->map[vcode_get_result(op)] = mir_build_all(mu, arg);
1,535✔
839
}
1,535✔
840

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

848
static void import_null_check(mir_unit_t *mu, mir_import_t *imp, int op)
1,112✔
849
{
850
   mir_value_t ptr = imp->map[vcode_get_arg(op, 0)];
1,112✔
851
   mir_value_t locus = imp->map[vcode_get_arg(op, 1)];
1,112✔
852
   mir_build_null_check(mu, ptr, locus);
1,112✔
853
}
1,112✔
854

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

862
static void import_length_check(mir_unit_t *mu, mir_import_t *imp, int op)
6,789✔
863
{
864
   mir_value_t llen = imp->map[vcode_get_arg(op, 0)];
6,789✔
865
   mir_value_t rlen = imp->map[vcode_get_arg(op, 1)];
6,789✔
866
   mir_value_t locus = imp->map[vcode_get_arg(op, 2)];
6,789✔
867

868
   mir_value_t dim = MIR_NULL_VALUE;
6,789✔
869
   if (vcode_count_args(op) > 3)
6,789✔
870
      dim = imp->map[vcode_get_arg(op, 3)];
27✔
871

872
   mir_build_length_check(mu, llen, rlen, locus, dim);
6,789✔
873
}
6,789✔
874

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

884
   mir_build_index_check(mu, value, left, right, dir, locus, hint);
12,678✔
885
}
12,678✔
886

887
static void import_alias_signal(mir_unit_t *mu, mir_import_t *imp, int op)
4,203✔
888
{
889
   mir_value_t signal = imp->map[vcode_get_arg(op, 0)];
4,203✔
890
   mir_value_t locus = imp->map[vcode_get_arg(op, 1)];
4,203✔
891

892
   mir_build_alias_signal(mu, signal, locus);
4,203✔
893
}
4,203✔
894

895
static void import_map_signal(mir_unit_t *mu, mir_import_t *imp, int op)
5,317✔
896
{
897
   mir_value_t src = imp->map[vcode_get_arg(op, 0)];
5,317✔
898
   mir_value_t dst = imp->map[vcode_get_arg(op, 1)];
5,317✔
899
   mir_value_t count = imp->map[vcode_get_arg(op, 2)];
5,317✔
900

901
   mir_build_map_signal(mu, src, dst, count);
5,317✔
902
}
5,317✔
903

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

910
   mir_build_map_const(mu, src, dst, count);
216✔
911
}
216✔
912

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

919
   mir_build_map_implicit(mu, src, dst, count);
63✔
920
}
63✔
921

922
static void import_bind_foreign(mir_unit_t *mu, mir_import_t *imp, int op)
270✔
923
{
924
   mir_value_t spec = imp->map[vcode_get_arg(op, 0)];
270✔
925
   mir_value_t length = imp->map[vcode_get_arg(op, 1)];
270✔
926

927
   mir_value_t locus = MIR_NULL_VALUE;
270✔
928
   if (vcode_count_args(op) > 2)
270✔
929
      locus = imp->map[vcode_get_arg(op, 2)];
142✔
930

931
   mir_build_bind_foreign(mu, spec, length, locus);
270✔
932
}
270✔
933

934
static void import_bind_external(mir_unit_t *mu, mir_import_t *imp, int op)
198✔
935
{
936
   mir_value_t locus = imp->map[vcode_get_arg(op, 0)];
198✔
937
   ident_t scope = vcode_get_ident(op);
198✔
938

939
   vcode_reg_t result = vcode_get_result(op);
198✔
940
   vcode_type_t vtype = vtype_pointed(vcode_reg_type(result));
198✔
941
   mir_type_t type = import_type(mu, imp, vtype);
198✔
942

943
   imp->map[result] = mir_build_bind_external(mu, locus, scope, type,
198✔
944
                                              MIR_NULL_STAMP);
198✔
945
}
198✔
946

947
static void import_unreachable(mir_unit_t *mu, mir_import_t *imp, int op)
618✔
948
{
949
   mir_value_t locus = MIR_NULL_VALUE;
618✔
950
   if (vcode_count_args(op) > 0)
618✔
951
      locus = imp->map[vcode_get_arg(op, 0)];
132✔
952

953
   mir_build_unreachable(mu, locus);
618✔
954
}
618✔
955

956
static void import_select(mir_unit_t *mu, mir_import_t *imp, int op)
12,614✔
957
{
958
   mir_value_t test = imp->map[vcode_get_arg(op, 0)];
12,614✔
959
   mir_value_t tval = imp->map[vcode_get_arg(op, 1)];
12,614✔
960
   mir_value_t fval = imp->map[vcode_get_arg(op, 2)];
12,614✔
961

962
   vcode_reg_t result = vcode_get_result(op);
12,614✔
963
   mir_type_t type = import_type(mu, imp, vcode_reg_type(result));
12,614✔
964

965
   imp->map[result] = mir_build_select(mu, type, test, tval, fval);
12,614✔
966
}
12,614✔
967

968
static void import_closure(mir_unit_t *mu, mir_import_t *imp, int op)
967✔
969
{
970
   mir_value_t context = imp->map[vcode_get_arg(op, 0)];
967✔
971
   ident_t func = vcode_get_func(op);
967✔
972

973
   mir_type_t atype = MIR_NULL_TYPE;
967✔
974
   vcode_reg_t result = vcode_get_result(op);
967✔
975
   mir_type_t rtype = import_type(mu, imp, vtype_base(vcode_reg_type(result)));
967✔
976

977
   imp->map[result] = mir_build_closure(mu, func, context, atype, rtype);
967✔
978
}
967✔
979

980
static void import_resolution_wrapper(mir_unit_t *mu, mir_import_t *imp, int op)
583✔
981
{
982
   mir_value_t closure = imp->map[vcode_get_arg(op, 0)];
583✔
983
   mir_value_t nlits = imp->map[vcode_get_arg(op, 1)];
583✔
984

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

988
   imp->map[result] = mir_build_resolution_wrapper(mu, type, closure, nlits);
583✔
989
}
583✔
990

991
static void import_resolve_signal(mir_unit_t *mu, mir_import_t *imp, int op)
3,320✔
992
{
993
   mir_value_t signal = imp->map[vcode_get_arg(op, 0)];
3,320✔
994
   mir_value_t resolution = imp->map[vcode_get_arg(op, 1)];
3,320✔
995
   mir_build_resolve_signal(mu, signal, resolution);
3,320✔
996
}
3,320✔
997

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

1006
   mir_build_transfer_signal(mu, target, source, count, reject, after);
1,209✔
1007
}
1,209✔
1008

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

1016
   mir_value_t status = MIR_NULL_VALUE;
268✔
1017
   if (vcode_count_args(op) > 4)
268✔
1018
      status = imp->map[vcode_get_arg(op, 4)];
26✔
1019

1020
   mir_build_file_open(mu, file, name, length, kind, status);
268✔
1021
}
268✔
1022

1023
static void import_file_read(mir_unit_t *mu, mir_import_t *imp, int op)
75✔
1024
{
1025
   mir_value_t file = imp->map[vcode_get_arg(op, 0)];
75✔
1026
   mir_value_t ptr = imp->map[vcode_get_arg(op, 1)];
75✔
1027

1028
   mir_value_t inlen = MIR_NULL_VALUE, outlen = MIR_NULL_VALUE;
75✔
1029
   if (vcode_count_args(op) > 2) {
75✔
1030
      inlen = imp->map[vcode_get_arg(op, 2)];
27✔
1031

1032
      if (vcode_count_args(op) > 3)
27✔
1033
         outlen = imp->map[vcode_get_arg(op, 3)];
18✔
1034
   }
1035

1036
   mir_build_file_read(mu, file, ptr, inlen, outlen);
75✔
1037
}
75✔
1038

1039
static void import_file_write(mir_unit_t *mu, mir_import_t *imp, int op)
123✔
1040
{
1041
   mir_value_t file = imp->map[vcode_get_arg(op, 0)];
123✔
1042
   mir_value_t value = imp->map[vcode_get_arg(op, 1)];
123✔
1043

1044
   mir_value_t length = MIR_NULL_VALUE;
123✔
1045
   if (vcode_count_args(op) > 2)
123✔
1046
      length = imp->map[vcode_get_arg(op, 2)];
66✔
1047

1048
   mir_build_file_write(mu, file, value, length);
123✔
1049
}
123✔
1050

1051
static void import_port_conversion(mir_unit_t *mu, mir_import_t *imp, int op)
285✔
1052
{
1053
   mir_value_t driving = imp->map[vcode_get_arg(op, 0)];
285✔
1054

1055
   mir_value_t effective = MIR_NULL_VALUE;
285✔
1056
   if (vcode_count_args(op) > 1)
285✔
1057
      effective = imp->map[vcode_get_arg(op, 1)];
18✔
1058

1059
   vcode_reg_t result = vcode_get_result(op);
285✔
1060
   imp->map[result] = mir_build_port_conversion(mu, driving, effective);
285✔
1061
}
285✔
1062

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

1069
   mir_build_convert_in(mu, conv, nets, count);
363✔
1070
}
363✔
1071

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

1078
   mir_build_convert_out(mu, conv, nets, count);
405✔
1079
}
405✔
1080

1081
static void import_driving_value(mir_unit_t *mu, mir_import_t *imp, int op)
172✔
1082
{
1083
   mir_value_t signal = imp->map[vcode_get_arg(op, 0)];
172✔
1084

1085
   mir_value_t count = MIR_NULL_VALUE;
172✔
1086
   if (vcode_count_args(op) > 1)
172✔
1087
      count = imp->map[vcode_get_arg(op, 1)];
33✔
1088

1089
   imp->map[vcode_get_result(op)] = mir_build_driving_value(mu, signal, count);
172✔
1090
}
172✔
1091

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

1099
   mir_build_put_conversion(mu, cf, target, count, values);
420✔
1100
}
420✔
1101

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

1108
   mir_build_force(mu, target, count, values);
63✔
1109
}
63✔
1110

1111
static void import_release(mir_unit_t *mu, mir_import_t *imp, int op)
30✔
1112
{
1113
   mir_value_t target = imp->map[vcode_get_arg(op, 0)];
30✔
1114
   mir_value_t count = imp->map[vcode_get_arg(op, 1)];
30✔
1115

1116
   mir_build_release(mu, target, count);
30✔
1117
}
30✔
1118

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

1126
   mir_build_disconnect(mu, target, count, reject, after);
24✔
1127
}
24✔
1128

1129
static void import_exponent_check(mir_unit_t *mu, mir_import_t *imp, int op)
514✔
1130
{
1131
   mir_value_t exp = imp->map[vcode_get_arg(op, 0)];
514✔
1132
   mir_value_t locus = imp->map[vcode_get_arg(op, 1)];
514✔
1133

1134
   mir_build_exponent_check(mu, exp, locus);
514✔
1135
}
514✔
1136

1137
static void import_process_init(mir_unit_t *mu, mir_import_t *imp, int op)
110✔
1138
{
1139
   ident_t name = vcode_get_func(op);
110✔
1140
   mir_value_t locus = imp->map[vcode_get_arg(op, 0)];
110✔
1141

1142
   mir_build_process_init(mu, name, locus);
110✔
1143
}
110✔
1144

1145
static void import_cover_stmt(mir_unit_t *mu, mir_import_t *imp, int op)
1,006✔
1146
{
1147
   mir_build_cover_stmt(mu, vcode_get_tag(op));
1,006✔
1148
}
1,006✔
1149

1150
static void import_cover_branch(mir_unit_t *mu, mir_import_t *imp, int op)
495✔
1151
{
1152
   mir_build_cover_branch(mu, vcode_get_tag(op));
495✔
1153
}
495✔
1154

1155
static void import_cover_expr(mir_unit_t *mu, mir_import_t *imp, int op)
859✔
1156
{
1157
   mir_build_cover_expr(mu, vcode_get_tag(op));
859✔
1158
}
859✔
1159

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

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

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

1180
static void import_package_scope(mir_unit_t *mu, mir_import_t *imp, int op)
45✔
1181
{
1182
   mir_value_t locus = imp->map[vcode_get_arg(op, 0)];
45✔
1183
   mir_build_package_scope(mu, locus);
45✔
1184
}
45✔
1185

1186
static void import_record_scope(mir_unit_t *mu, mir_import_t *imp, int op)
1,605✔
1187
{
1188
   mir_value_t locus = imp->map[vcode_get_arg(op, 0)];
1,605✔
1189
   mir_type_t type = import_type(mu, imp, vcode_get_type(op));
1,605✔
1190
   mir_build_record_scope(mu, locus, type);
1,605✔
1191
}
1,605✔
1192

1193
static void import_pop_scope(mir_unit_t *mu, mir_import_t *imp, int op)
2,282✔
1194
{
1195
   mir_build_pop_scope(mu);
2,282✔
1196
}
2,282✔
1197

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

1205
static void import_function_trigger(mir_unit_t *mu, mir_import_t *imp, int op)
217✔
1206
{
1207
   const int nargs = vcode_count_args(op);
217✔
1208
   mir_value_t *args LOCAL = xmalloc_array(nargs, sizeof(mir_value_t));
434✔
1209
   for (int i = 0; i < nargs; i++)
573✔
1210
      args[i] = imp->map[vcode_get_arg(op, i)];
356✔
1211

1212
   ident_t func = vcode_get_func(op);
217✔
1213
   vcode_reg_t result = vcode_get_result(op);
217✔
1214
   imp->map[result] = mir_build_function_trigger(mu, func, args, nargs);
217✔
1215
}
217✔
1216

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

1224
static void import_add_trigger(mir_unit_t *mu, mir_import_t *imp, int op)
377✔
1225
{
1226
   mir_value_t trigger = imp->map[vcode_get_arg(op, 0)];
377✔
1227
   mir_build_add_trigger(mu, trigger);
377✔
1228
}
377✔
1229

1230
static void import_protected_init(mir_unit_t *mu, mir_import_t *imp, int op)
167✔
1231
{
1232
   mir_value_t context = imp->map[vcode_get_arg(op, 0)];
167✔
1233

1234
   mir_value_t path_name = MIR_NULL_VALUE, inst_name = MIR_NULL_VALUE;
167✔
1235
   if (vcode_count_args(op) > 1) {
167✔
1236
      path_name = imp->map[vcode_get_arg(op, 1)];
38✔
1237
      inst_name = imp->map[vcode_get_arg(op, 2)];
38✔
1238
   }
1239

1240
   vcode_reg_t result = vcode_get_result(op);
167✔
1241
   mir_type_t type = import_type(mu, imp, vcode_reg_type(result));
167✔
1242

1243
   imp->map[result] = mir_build_protected_init(mu, type, context,
167✔
1244
                                               path_name, inst_name);
1245
}
167✔
1246

1247
static void import_instance_name(mir_unit_t *mu, mir_import_t *imp, int op)
812✔
1248
{
1249
   mir_value_t kind = imp->map[vcode_get_arg(op, 0)];
812✔
1250
   imp->map[vcode_get_result(op)] = mir_build_instance_name(mu, kind);
812✔
1251
}
812✔
1252

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

1257
   mir_value_t count = MIR_NULL_VALUE;
66✔
1258
   if (vcode_count_args(op) > 1)
66✔
1259
      count = imp->map[vcode_get_arg(op, 1)];
9✔
1260

1261
   imp->map[vcode_get_result(op)] = mir_build_last_event(mu, signal, count);
66✔
1262
}
66✔
1263

1264
static void import_last_active(mir_unit_t *mu, mir_import_t *imp, int op)
69✔
1265
{
1266
   mir_value_t signal = imp->map[vcode_get_arg(op, 0)];
69✔
1267

1268
   mir_value_t count = MIR_NULL_VALUE;
69✔
1269
   if (vcode_count_args(op) > 1)
69✔
1270
      count = imp->map[vcode_get_arg(op, 1)];
6✔
1271

1272
   imp->map[vcode_get_result(op)] = mir_build_last_active(mu, signal, count);
69✔
1273
}
69✔
1274

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

1281
static void import_enter_state(mir_unit_t *mu, mir_import_t *imp, int op)
780✔
1282
{
1283
   mir_value_t state = imp->map[vcode_get_arg(op, 0)];
780✔
1284

1285
   mir_value_t strong = MIR_NULL_VALUE;
780✔
1286
   if (vcode_count_args(op) > 1)
780✔
1287
      strong = imp->map[vcode_get_arg(op, 1)];
18✔
1288

1289
   mir_build_enter_state(mu, state, strong);
780✔
1290
}
780✔
1291

1292
static void import_deposit_signal(mir_unit_t *mu, mir_import_t *imp, int op)
177✔
1293
{
1294
   mir_value_t target = imp->map[vcode_get_arg(op, 0)];
177✔
1295
   mir_value_t count = imp->map[vcode_get_arg(op, 1)];
177✔
1296
   mir_value_t values = imp->map[vcode_get_arg(op, 2)];
177✔
1297

1298
   mir_build_deposit_signal(mu, target, count, values);
177✔
1299
}
177✔
1300

1301
static void import_syscall(mir_unit_t *mu, mir_import_t *imp, int op)
423✔
1302
{
1303
   mir_value_t locus = imp->map[vcode_get_arg(op, 0)];
423✔
1304
   ident_t func = vcode_get_func(op);
423✔
1305

1306
   mir_type_t type = MIR_NULL_TYPE;
423✔
1307
   vcode_type_t vtype = vcode_get_type(op);
423✔
1308
   if (vtype != VCODE_INVALID_TYPE)
423✔
1309
      type = import_type(mu, imp, vtype);
39✔
1310

1311
   const int nargs = vcode_count_args(op) - 1;
423✔
1312
   mir_value_t *args LOCAL = xmalloc_array(nargs, sizeof(mir_value_t));
846✔
1313
   for (int i = 0; i < nargs; i++)
498✔
1314
      args[i] = imp->map[vcode_get_arg(op, i + 1)];
75✔
1315

1316
   vcode_reg_t result = vcode_get_result(op);
423✔
1317
   if (result == VCODE_INVALID_REG)
423✔
1318
      mir_build_syscall(mu, func, type, MIR_NULL_STAMP, locus, args, nargs);
384✔
1319
   else {
1320
      mir_type_t type = import_type(mu, imp, vcode_reg_type(result));
39✔
1321
      imp->map[result] =  mir_build_syscall(mu, func, type, MIR_NULL_STAMP,
39✔
1322
                                            locus, args, nargs);
1323
   }
1324
}
423✔
1325

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

1332
   mir_value_t bounds = MIR_NULL_VALUE;
48✔
1333
   if (vcode_count_args(op) > 3)
48✔
1334
      bounds = imp->map[vcode_get_arg(op, 3)];
6✔
1335

1336
   imp->map[vcode_get_result(op)] =
48✔
1337
      mir_build_reflect_value(mu, value, context, locus, bounds);
48✔
1338
}
48✔
1339

1340
static void import_reflect_subtype(mir_unit_t *mu, mir_import_t *imp, int op)
42✔
1341
{
1342
   mir_value_t context = imp->map[vcode_get_arg(op, 0)];
42✔
1343
   mir_value_t locus = imp->map[vcode_get_arg(op, 1)];
42✔
1344

1345
   mir_value_t bounds = MIR_NULL_VALUE;
42✔
1346
   if (vcode_count_args(op) > 2)
42✔
1347
      bounds = imp->map[vcode_get_arg(op, 2)];
×
1348

1349
   imp->map[vcode_get_result(op)] =
42✔
1350
      mir_build_reflect_subtype(mu, context, locus, bounds);
42✔
1351
}
42✔
1352

1353
static void import_block(mir_unit_t *mu, mir_import_t *imp)
137,099✔
1354
{
1355
   const int nops = vcode_count_ops();
137,099✔
1356
   for (int i = 0; i < nops; i++) {
1,757,594✔
1357
      mir_set_loc(mu, vcode_get_loc(i));
1,620,495✔
1358

1359
      switch (vcode_get_op(i)) {
1,620,495✔
1360
      case VCODE_OP_COMMENT:
1361
         break;
1362
      case VCODE_OP_PACKAGE_INIT:
20,891✔
1363
         import_package_init(mu, imp, i);
20,891✔
1364
         break;
20,891✔
1365
      case VCODE_OP_LINK_PACKAGE:
11,399✔
1366
         import_link_package(mu, imp, i);
11,399✔
1367
         break;
11,399✔
1368
      case VCODE_OP_LINK_VAR:
3,508✔
1369
         import_link_var(mu, imp, i);
3,508✔
1370
         break;
3,508✔
1371
      case VCODE_OP_RETURN:
53,315✔
1372
         import_return(mu, imp, i);
53,315✔
1373
         break;
53,315✔
1374
      case VCODE_OP_FCALL:
36,211✔
1375
         import_fcall(mu, imp, i);
36,211✔
1376
         break;
36,211✔
1377
      case VCODE_OP_PCALL:
892✔
1378
         import_pcall(mu, imp, i);
892✔
1379
         break;
892✔
1380
      case VCODE_OP_RESUME:
892✔
1381
         import_resume(mu, imp, i);
892✔
1382
         break;
892✔
1383
      case VCODE_OP_CONST:
321,922✔
1384
         import_const(mu, imp, i);
321,922✔
1385
         break;
321,922✔
1386
      case VCODE_OP_CONST_REAL:
20,985✔
1387
         import_const_real(mu, imp, i);
20,985✔
1388
         break;
20,985✔
1389
      case VCODE_OP_CONST_ARRAY:
21,775✔
1390
         import_const_array(mu, imp, i);
21,775✔
1391
         break;
21,775✔
1392
      case VCODE_OP_CONST_REP:
357✔
1393
         import_const_rep(mu, imp, i);
357✔
1394
         break;
357✔
1395
      case VCODE_OP_CONST_RECORD:
2,282✔
1396
         import_const_record(mu, imp, i);
2,282✔
1397
         break;
2,282✔
1398
      case VCODE_OP_CMP:
34,044✔
1399
         import_cmp(mu, imp, i);
34,044✔
1400
         break;
34,044✔
1401
      case VCODE_OP_DEBUG_LOCUS:
66,663✔
1402
         import_debug_locus(mu, imp, i);
66,663✔
1403
         break;
66,663✔
1404
      case VCODE_OP_ASSERT:
14,011✔
1405
         import_assert(mu, imp, i);
14,011✔
1406
         break;
14,011✔
1407
      case VCODE_OP_REPORT:
2,245✔
1408
         import_report(mu, imp, i);
2,245✔
1409
         break;
2,245✔
1410
      case VCODE_OP_WAIT:
13,798✔
1411
         import_wait(mu, imp, i);
13,798✔
1412
         break;
13,798✔
1413
      case VCODE_OP_JUMP:
34,865✔
1414
         import_jump(mu, imp, i);
34,865✔
1415
         break;
34,865✔
1416
      case VCODE_OP_COND:
32,971✔
1417
         import_cond(mu, imp, i);
32,971✔
1418
         break;
32,971✔
1419
      case VCODE_OP_INIT_SIGNAL:
15,930✔
1420
         import_init_signal(mu, imp, i);
15,930✔
1421
         break;
15,930✔
1422
      case VCODE_OP_IMPLICIT_SIGNAL:
81✔
1423
         import_implicit_signal(mu, imp, i);
81✔
1424
         break;
81✔
1425
      case VCODE_OP_DRIVE_SIGNAL:
9,371✔
1426
         import_drive_signal(mu, imp, i);
9,371✔
1427
         break;
9,371✔
1428
      case VCODE_OP_SCHED_WAVEFORM:
10,771✔
1429
         import_sched_waveform(mu, imp, i);
10,771✔
1430
         break;
10,771✔
1431
      case VCODE_OP_RESOLVED:
14,279✔
1432
         import_resolved(mu, imp, i);
14,279✔
1433
         break;
14,279✔
1434
      case VCODE_OP_ADDRESS_OF:
23,301✔
1435
         import_address_of(mu, imp, i);
23,301✔
1436
         break;
23,301✔
1437
      case VCODE_OP_STORE:
57,940✔
1438
         import_store(mu, imp, i);
57,940✔
1439
         break;
57,940✔
1440
      case VCODE_OP_STORE_INDIRECT:
13,601✔
1441
         import_store_indirect(mu, imp, i);
13,601✔
1442
         break;
13,601✔
1443
      case VCODE_OP_LOAD:
31,166✔
1444
         import_load(mu, imp, i);
31,166✔
1445
         break;
31,166✔
1446
      case VCODE_OP_LOAD_INDIRECT:
90,093✔
1447
         import_load_indirect(mu, imp, i);
90,093✔
1448
         break;
90,093✔
1449
      case VCODE_OP_CONTEXT_UPREF:
9,101✔
1450
         import_context_upref(mu, imp, i);
9,101✔
1451
         break;
9,101✔
1452
      case VCODE_OP_VAR_UPREF:
46,298✔
1453
         import_var_upref(mu, imp, i);
46,298✔
1454
         break;
46,298✔
1455
      case VCODE_OP_WRAP:
29,364✔
1456
         import_wrap(mu, imp, i);
29,364✔
1457
         break;
29,364✔
1458
      case VCODE_OP_UNWRAP:
26,849✔
1459
         import_unwrap(mu, imp, i);
26,849✔
1460
         break;
26,849✔
1461
      case VCODE_OP_UARRAY_LEN:
21,328✔
1462
         import_uarray_len(mu, imp, i);
21,328✔
1463
         break;
21,328✔
1464
      case VCODE_OP_UARRAY_LEFT:
17,296✔
1465
         import_uarray_left(mu, imp, i);
17,296✔
1466
         break;
17,296✔
1467
      case VCODE_OP_UARRAY_RIGHT:
14,931✔
1468
         import_uarray_right(mu, imp, i);
14,931✔
1469
         break;
14,931✔
1470
      case VCODE_OP_UARRAY_DIR:
17,253✔
1471
         import_uarray_dir(mu, imp, i);
17,253✔
1472
         break;
17,253✔
1473
      case VCODE_OP_ADD:
12,659✔
1474
         import_add(mu, imp, i);
12,659✔
1475
         break;
12,659✔
1476
      case VCODE_OP_TRAP_ADD:
1,928✔
1477
         import_trap_add(mu, imp, i);
1,928✔
1478
         break;
1,928✔
1479
      case VCODE_OP_SUB:
20,395✔
1480
         import_sub(mu, imp, i);
20,395✔
1481
         break;
20,395✔
1482
      case VCODE_OP_TRAP_SUB:
1,168✔
1483
         import_trap_sub(mu, imp, i);
1,168✔
1484
         break;
1,168✔
1485
      case VCODE_OP_MUL:
2,334✔
1486
         import_mul(mu, imp, i);
2,334✔
1487
         break;
2,334✔
1488
      case VCODE_OP_TRAP_MUL:
326✔
1489
         import_trap_mul(mu, imp, i);
326✔
1490
         break;
326✔
1491
      case VCODE_OP_DIV:
898✔
1492
         import_div(mu, imp, i);
898✔
1493
         break;
898✔
1494
      case VCODE_OP_MOD:
124✔
1495
         import_mod(mu, imp, i);
124✔
1496
         break;
124✔
1497
      case VCODE_OP_REM:
106✔
1498
         import_rem(mu, imp, i);
106✔
1499
         break;
106✔
1500
      case VCODE_OP_EXP:
72✔
1501
         import_exp(mu, imp, i);
72✔
1502
         break;
72✔
1503
      case VCODE_OP_TRAP_EXP:
532✔
1504
         import_trap_exp(mu, imp, i);
532✔
1505
         break;
532✔
1506
      case VCODE_OP_OR:
1,795✔
1507
         import_or(mu, imp, i);
1,795✔
1508
         break;
1,795✔
1509
      case VCODE_OP_NOR:
63✔
1510
         import_nor(mu, imp, i);
63✔
1511
         break;
63✔
1512
      case VCODE_OP_XOR:
104✔
1513
         import_xor(mu, imp, i);
104✔
1514
         break;
104✔
1515
      case VCODE_OP_XNOR:
64✔
1516
         import_xnor(mu, imp, i);
64✔
1517
         break;
64✔
1518
      case VCODE_OP_AND:
3,752✔
1519
         import_and(mu, imp, i);
3,752✔
1520
         break;
3,752✔
1521
      case VCODE_OP_NAND:
62✔
1522
         import_nand(mu, imp, i);
62✔
1523
         break;
62✔
1524
      case VCODE_OP_EVENT:
375✔
1525
         import_event(mu, imp, i);
375✔
1526
         break;
375✔
1527
      case VCODE_OP_ACTIVE:
220✔
1528
         import_active(mu, imp, i);
220✔
1529
         break;
220✔
1530
      case VCODE_OP_DRIVING:
36✔
1531
         import_driving(mu, imp, i);
36✔
1532
         break;
36✔
1533
      case VCODE_OP_NOT:
2,699✔
1534
         import_not(mu, imp, i);
2,699✔
1535
         break;
2,699✔
1536
      case VCODE_OP_CAST:
48,193✔
1537
         import_cast(mu, imp, i);
48,193✔
1538
         break;
48,193✔
1539
      case VCODE_OP_NEG:
7,338✔
1540
         import_neg(mu, imp, i);
7,338✔
1541
         break;
7,338✔
1542
      case VCODE_OP_TRAP_NEG:
553✔
1543
         import_trap_neg(mu, imp, i);
553✔
1544
         break;
553✔
1545
      case VCODE_OP_ABS:
235✔
1546
         import_abs(mu, imp, i);
235✔
1547
         break;
235✔
1548
      case VCODE_OP_INDEX:
14,934✔
1549
         import_index(mu, imp, i);
14,934✔
1550
         break;
14,934✔
1551
      case VCODE_OP_COPY:
16,030✔
1552
         import_copy(mu, imp, i);
16,030✔
1553
         break;
16,030✔
1554
      case VCODE_OP_MEMSET:
5,635✔
1555
         import_memset(mu, imp, i);
5,635✔
1556
         break;
5,635✔
1557
      case VCODE_OP_ARRAY_REF:
32,970✔
1558
         import_array_ref(mu, imp, i);
32,970✔
1559
         break;
32,970✔
1560
      case VCODE_OP_RECORD_REF:
37,886✔
1561
         import_record_ref(mu, imp, i);
37,886✔
1562
         break;
37,886✔
1563
      case VCODE_OP_RANGE_CHECK:
2,754✔
1564
         import_range_check(mu, imp, i);
2,754✔
1565
         break;
2,754✔
1566
      case VCODE_OP_SCHED_EVENT:
5,944✔
1567
         import_sched_event(mu, imp, i);
5,944✔
1568
         break;
5,944✔
1569
      case VCODE_OP_CLEAR_EVENT:
528✔
1570
         import_clear_event(mu, imp, i);
528✔
1571
         break;
528✔
1572
      case VCODE_OP_ALLOC:
7,193✔
1573
         import_alloc(mu, imp, i);
7,193✔
1574
         break;
7,193✔
1575
      case VCODE_OP_RANGE_LENGTH:
6,346✔
1576
         import_range_length(mu, imp, i);
6,346✔
1577
         break;
6,346✔
1578
      case VCODE_OP_RANGE_NULL:
4,583✔
1579
         import_range_null(mu, imp, i);
4,583✔
1580
         break;
4,583✔
1581
      case VCODE_OP_NULL:
2,552✔
1582
         import_null(mu, imp, i);
2,552✔
1583
         break;
2,552✔
1584
      case VCODE_OP_NEW:
423✔
1585
         import_new(mu, imp, i);
423✔
1586
         break;
423✔
1587
      case VCODE_OP_ALL:
1,535✔
1588
         import_all(mu, imp, i);
1,535✔
1589
         break;
1,535✔
1590
      case VCODE_OP_DEALLOCATE:
203✔
1591
         import_deallocate(mu, imp, i);
203✔
1592
         break;
203✔
1593
      case VCODE_OP_ZERO_CHECK:
111✔
1594
         import_zero_check(mu, imp, i);
111✔
1595
         break;
111✔
1596
      case VCODE_OP_NULL_CHECK:
1,112✔
1597
         import_null_check(mu, imp, i);
1,112✔
1598
         break;
1,112✔
1599
      case VCODE_OP_LENGTH_CHECK:
6,789✔
1600
         import_length_check(mu, imp, i);
6,789✔
1601
         break;
6,789✔
1602
      case VCODE_OP_INDEX_CHECK:
12,678✔
1603
         import_index_check(mu, imp, i);
12,678✔
1604
         break;
12,678✔
1605
      case VCODE_OP_ALIAS_SIGNAL:
4,203✔
1606
         import_alias_signal(mu, imp, i);
4,203✔
1607
         break;
4,203✔
1608
      case VCODE_OP_MAP_SIGNAL:
5,317✔
1609
         import_map_signal(mu, imp, i);
5,317✔
1610
         break;
5,317✔
1611
      case VCODE_OP_MAP_CONST:
216✔
1612
         import_map_const(mu, imp, i);
216✔
1613
         break;
216✔
1614
      case VCODE_OP_MAP_IMPLICIT:
63✔
1615
         import_map_implicit(mu, imp, i);
63✔
1616
         break;
63✔
1617
      case VCODE_OP_CASE:
640✔
1618
         import_case(mu, imp, i);
640✔
1619
         break;
640✔
1620
      case VCODE_OP_BIND_FOREIGN:
270✔
1621
         import_bind_foreign(mu, imp, i);
270✔
1622
         break;
270✔
1623
      case VCODE_OP_BIND_EXTERNAL:
198✔
1624
         import_bind_external(mu, imp, i);
198✔
1625
         break;
198✔
1626
      case VCODE_OP_UNREACHABLE:
618✔
1627
         import_unreachable(mu, imp, i);
618✔
1628
         break;
618✔
1629
      case VCODE_OP_SELECT:
12,614✔
1630
         import_select(mu, imp, i);
12,614✔
1631
         break;
12,614✔
1632
      case VCODE_OP_CLOSURE:
967✔
1633
         import_closure(mu, imp, i);
967✔
1634
         break;
967✔
1635
      case VCODE_OP_RESOLUTION_WRAPPER:
583✔
1636
         import_resolution_wrapper(mu, imp, i);
583✔
1637
         break;
583✔
1638
      case VCODE_OP_RESOLVE_SIGNAL:
3,320✔
1639
         import_resolve_signal(mu, imp, i);
3,320✔
1640
         break;
3,320✔
1641
      case VCODE_OP_TRANSFER_SIGNAL:
1,209✔
1642
         import_transfer_signal(mu, imp, i);
1,209✔
1643
         break;
1,209✔
1644
      case VCODE_OP_FILE_OPEN:
268✔
1645
         import_file_open(mu, imp, i);
268✔
1646
         break;
268✔
1647
      case VCODE_OP_FILE_READ:
75✔
1648
         import_file_read(mu, imp, i);
75✔
1649
         break;
75✔
1650
      case VCODE_OP_FILE_WRITE:
123✔
1651
         import_file_write(mu, imp, i);
123✔
1652
         break;
123✔
1653
      case VCODE_OP_PORT_CONVERSION:
285✔
1654
         import_port_conversion(mu, imp, i);
285✔
1655
         break;
285✔
1656
      case VCODE_OP_CONVERT_IN:
363✔
1657
         import_convert_in(mu, imp, i);
363✔
1658
         break;
363✔
1659
      case VCODE_OP_CONVERT_OUT:
405✔
1660
         import_convert_out(mu, imp, i);
405✔
1661
         break;
405✔
1662
      case VCODE_OP_DRIVING_VALUE:
172✔
1663
         import_driving_value(mu, imp, i);
172✔
1664
         break;
172✔
1665
      case VCODE_OP_PUT_CONVERSION:
420✔
1666
         import_put_conversion(mu, imp, i);
420✔
1667
         break;
420✔
1668
      case VCODE_OP_FORCE:
63✔
1669
         import_force(mu, imp, i);
63✔
1670
         break;
63✔
1671
      case VCODE_OP_RELEASE:
30✔
1672
         import_release(mu, imp, i);
30✔
1673
         break;
30✔
1674
      case VCODE_OP_DISCONNECT:
24✔
1675
         import_disconnect(mu, imp, i);
24✔
1676
         break;
24✔
1677
      case VCODE_OP_EXPONENT_CHECK:
514✔
1678
         import_exponent_check(mu, imp, i);
514✔
1679
         break;
514✔
1680
      case VCODE_OP_PROCESS_INIT:
110✔
1681
         import_process_init(mu, imp, i);
110✔
1682
         break;
110✔
1683
      case VCODE_OP_COVER_STMT:
1,006✔
1684
         import_cover_stmt(mu, imp, i);
1,006✔
1685
         break;
1,006✔
1686
      case VCODE_OP_COVER_BRANCH:
495✔
1687
         import_cover_branch(mu, imp, i);
495✔
1688
         break;
495✔
1689
      case VCODE_OP_COVER_EXPR:
859✔
1690
         import_cover_expr(mu, imp, i);
859✔
1691
         break;
859✔
1692
      case VCODE_OP_COVER_TOGGLE:
312✔
1693
         import_cover_toggle(mu, imp, i);
312✔
1694
         break;
312✔
1695
      case VCODE_OP_COVER_STATE:
12✔
1696
         import_cover_state(mu, imp, i);
12✔
1697
         break;
12✔
1698
      case VCODE_OP_ARRAY_SCOPE:
632✔
1699
         import_array_scope(mu, imp, i);
632✔
1700
         break;
632✔
1701
      case VCODE_OP_PACKAGE_SCOPE:
45✔
1702
         import_package_scope(mu, imp, i);
45✔
1703
         break;
45✔
1704
      case VCODE_OP_RECORD_SCOPE:
1,605✔
1705
         import_record_scope(mu, imp, i);
1,605✔
1706
         break;
1,605✔
1707
      case VCODE_OP_POP_SCOPE:
2,282✔
1708
         import_pop_scope(mu, imp, i);
2,282✔
1709
         break;
2,282✔
1710
      case VCODE_OP_CMP_TRIGGER:
47✔
1711
         import_cmp_trigger(mu, imp, i);
47✔
1712
         break;
47✔
1713
      case VCODE_OP_FUNCTION_TRIGGER:
217✔
1714
         import_function_trigger(mu, imp, i);
217✔
1715
         break;
217✔
1716
      case VCODE_OP_OR_TRIGGER:
34✔
1717
         import_or_trigger(mu, imp, i);
34✔
1718
         break;
34✔
1719
      case VCODE_OP_ADD_TRIGGER:
377✔
1720
         import_add_trigger(mu, imp, i);
377✔
1721
         break;
377✔
1722
      case VCODE_OP_PROTECTED_INIT:
167✔
1723
         import_protected_init(mu, imp, i);
167✔
1724
         break;
167✔
1725
      case VCODE_OP_PROTECTED_FREE:
1726
         break;   // No-op
1727
      case VCODE_OP_INSTANCE_NAME:
812✔
1728
         import_instance_name(mu, imp, i);
812✔
1729
         break;
812✔
1730
      case VCODE_OP_LAST_EVENT:
66✔
1731
         import_last_event(mu, imp, i);
66✔
1732
         break;
66✔
1733
      case VCODE_OP_LAST_ACTIVE:
69✔
1734
         import_last_active(mu, imp, i);
69✔
1735
         break;
69✔
1736
      case VCODE_OP_LAST_VALUE:
83✔
1737
         import_last_value(mu, imp, i);
83✔
1738
         break;
83✔
1739
      case VCODE_OP_ENTER_STATE:
780✔
1740
         import_enter_state(mu, imp, i);
780✔
1741
         break;
780✔
1742
      case VCODE_OP_DEPOSIT_SIGNAL:
177✔
1743
         import_deposit_signal(mu, imp, i);
177✔
1744
         break;
177✔
1745
      case VCODE_OP_SYSCALL:
423✔
1746
         import_syscall(mu, imp, i);
423✔
1747
         break;
423✔
1748
      case VCODE_OP_REFLECT_SUBTYPE:
42✔
1749
         import_reflect_subtype(mu, imp, i);
42✔
1750
         break;
42✔
1751
      case VCODE_OP_REFLECT_VALUE:
48✔
1752
         import_reflect_value(mu, imp, i);
48✔
1753
         break;
48✔
1754
      default:
×
1755
         vcode_dump_with_mark(i, NULL, NULL);
×
1756
         fatal_trace("cannot import vcode op %s",
1757
                     vcode_op_string(vcode_get_op(i)));
1758
      }
1759
   }
1760
}
137,099✔
1761

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

1776
   const mir_unit_kind_t kind = kind_map[vcode_unit_kind(vu)];
44,556✔
1777

1778
   mir_shape_t *parent = NULL;
44,556✔
1779
   vcode_unit_t context = vcode_unit_context(vu);
44,556✔
1780
   if (context != NULL) {
44,556✔
1781
      ident_t name = vcode_unit_name(context);
28,107✔
1782
      if ((parent = mir_get_shape(mc, name)) == NULL) {
28,107✔
1783
         mir_unit_t *parent_mu = mir_import(mc, context);
×
1784
         mir_put_unit(mc, parent_mu);
×
1785

1786
         parent = mir_get_shape(mc, name);
×
1787
         assert(parent != NULL);
×
1788
      }
1789
   }
1790

1791
   ident_t name = vcode_unit_name(vu);
44,556✔
1792
   object_t *obj = vcode_unit_object(vu);
44,556✔
1793

1794
   mir_unit_t *mu = mir_unit_new(mc, name, obj, kind, parent);
44,556✔
1795

1796
   vcode_select_unit(vu);
44,556✔
1797

1798
   const int nblocks = vcode_count_blocks();
44,556✔
1799
   const int nregs = vcode_count_regs();
44,556✔
1800
   const int nvars = vcode_count_vars();
44,556✔
1801

1802
   mir_import_t imp = {};
44,556✔
1803
   imp.blocks = xcalloc_array(nblocks, sizeof(mir_block_t));
44,556✔
1804
   imp.map    = xcalloc_array(nregs, sizeof(mir_value_t));
44,556✔
1805
   imp.vars   = xcalloc_array(nvars, sizeof(mir_value_t));
44,556✔
1806
   imp.types  = ihash_new(64);
44,556✔
1807

1808
   switch (kind) {
44,556✔
1809
   case MIR_UNIT_FUNCTION:
11,264✔
1810
      {
1811
         vcode_type_t vresult = vcode_unit_result(vu);
11,264✔
1812
         if (vresult != VCODE_INVALID_TYPE)
11,264✔
1813
            mir_set_result(mu, import_type(mu, &imp, vresult));
9,842✔
1814
      }
1815
      // Fall-through
1816
   case MIR_UNIT_PROCEDURE:
1817
   case MIR_UNIT_PROTECTED:
1818
   case MIR_UNIT_PROPERTY:
1819
      {
1820
         const int nparams = vcode_count_params();
11,920✔
1821
         for (int i = 0; i < nparams; i++) {
42,727✔
1822
            vcode_reg_t preg = vcode_param_reg(i);
30,807✔
1823
            mir_type_t type = import_type(mu, &imp, vcode_param_type(i));
30,807✔
1824
            ident_t name = vcode_param_name(i);
30,807✔
1825
            imp.map[preg] = mir_add_param(mu, type, MIR_NULL_STAMP, name);
30,807✔
1826
         }
1827
      }
1828
      break;
1829
   case MIR_UNIT_THUNK:
12,096✔
1830
      mir_set_result(mu, import_type(mu, &imp, vcode_unit_result(vu)));
12,096✔
1831
      break;
12,096✔
1832
   default:
1833
      break;
1834
   }
1835

1836
   for (int i = 0; i < nvars; i++) {
93,766✔
1837
      mir_type_t type = import_type(mu, &imp, vcode_var_type(i));
49,210✔
1838
      imp.vars[i] = mir_add_var(mu, type, MIR_NULL_STAMP, vcode_var_name(i),
49,210✔
1839
                                (mir_var_flags_t)vcode_var_flags(i));
49,210✔
1840
   }
1841

1842
   imp.blocks[0] = mir_get_cursor(mu, NULL);
44,556✔
1843
   for (int i = 1; i < nblocks; i++)
137,099✔
1844
      imp.blocks[i] = mir_add_block(mu);
92,543✔
1845

1846
   for (int i = 0; i < nblocks; i++) {
181,655✔
1847
      vcode_select_block(i);
137,099✔
1848
      mir_set_cursor(mu, imp.blocks[i], MIR_APPEND);
137,099✔
1849
      import_block(mu, &imp);
137,099✔
1850
   }
1851

1852
   ihash_free(imp.types);
44,556✔
1853
   free(imp.blocks);
44,556✔
1854
   free(imp.map);
44,556✔
1855
   free(imp.vars);
44,556✔
1856

1857
   return mu;
44,556✔
1858
}
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