|
|
@@ -237,14 +237,14 @@ static int global_map_ir_post(const struct func *func, struct node *n,
|
|
237
|
237
|
arg = arg->next;
|
|
238
|
238
|
}
|
|
239
|
239
|
|
|
|
240
|
+ n->sym->irs.hint.stack = 1;
|
|
|
241
|
+ ir_init_sym(prog->ir, n->sym);
|
|
|
242
|
+
|
|
240
|
243
|
if (n->sym->irs.hint.lval)
|
|
241
|
244
|
/* map[key] = val, whatever is in our storage now it
|
|
242
|
245
|
will be overwritten, so skip the load. */
|
|
243
|
246
|
return 0;
|
|
244
|
247
|
|
|
245
|
|
- n->sym->irs.hint.stack = 1;
|
|
246
|
|
- ir_init_sym(prog->ir, n->sym);
|
|
247
|
|
-
|
|
248
|
248
|
ir_emit_ldmap(prog->ir, BPF_REG_1, map->sym);
|
|
249
|
249
|
ir_emit_insn(prog->ir, MOV, BPF_REG_2, BPF_REG_BP);
|
|
250
|
250
|
ir_emit_insn(prog->ir, ALU_IMM(BPF_ADD, stack), BPF_REG_BP, 0);
|
|
|
@@ -324,6 +324,51 @@ static int global_map_static_validate(const struct func *func, struct node *n)
|
|
324
|
324
|
|
|
325
|
325
|
/* :assign */
|
|
326
|
326
|
|
|
|
327
|
+static int global_assign_ir_pre(const struct func *func, struct node *n,
|
|
|
328
|
+ struct prog *prog)
|
|
|
329
|
+{
|
|
|
330
|
+ struct node *lval, *rval;
|
|
|
331
|
+
|
|
|
332
|
+ lval = n->expr.args;
|
|
|
333
|
+ rval = lval->next;
|
|
|
334
|
+
|
|
|
335
|
+ n->sym->irs.hint.stack = 1;
|
|
|
336
|
+ ir_init_irs(prog->ir, &n->sym->irs, lval->sym->type);
|
|
|
337
|
+
|
|
|
338
|
+ lval->sym->irs.hint.lval = 1;
|
|
|
339
|
+ lval->sym->irs.hint.stack = 1;
|
|
|
340
|
+ lval->sym->irs.stack = n->sym->irs.stack;
|
|
|
341
|
+
|
|
|
342
|
+ rval->sym->irs.hint.stack = 1;
|
|
|
343
|
+ rval->sym->irs.stack = n->sym->irs.stack;
|
|
|
344
|
+ return 0;
|
|
|
345
|
+}
|
|
|
346
|
+
|
|
|
347
|
+static int global_assign_ir_post(const struct func *func, struct node *n,
|
|
|
348
|
+ struct prog *prog)
|
|
|
349
|
+{
|
|
|
350
|
+ struct node *lval, *rval, *map;
|
|
|
351
|
+
|
|
|
352
|
+ lval = n->expr.args;
|
|
|
353
|
+ rval = lval->next;
|
|
|
354
|
+
|
|
|
355
|
+ ir_emit_sym_to_sym(prog->ir, lval->sym, rval->sym);
|
|
|
356
|
+ if (!node_is(lval, "{}"))
|
|
|
357
|
+ return 0;
|
|
|
358
|
+
|
|
|
359
|
+ map = lval->expr.args;
|
|
|
360
|
+
|
|
|
361
|
+ ir_emit_ldmap(prog->ir, BPF_REG_1, map->sym);
|
|
|
362
|
+ ir_emit_insn(prog->ir, MOV, BPF_REG_2, BPF_REG_BP);
|
|
|
363
|
+ ir_emit_insn(prog->ir, ALU_IMM(BPF_ADD, map->sym->irs.stack), BPF_REG_2, 0);
|
|
|
364
|
+ ir_emit_insn(prog->ir, MOV, BPF_REG_3, BPF_REG_BP);
|
|
|
365
|
+ ir_emit_insn(prog->ir, ALU_IMM(BPF_ADD, lval->sym->irs.stack), BPF_REG_3, 0);
|
|
|
366
|
+ ir_emit_insn(prog->ir, MOV_IMM(0), BPF_REG_4, 0);
|
|
|
367
|
+ ir_emit_insn(prog->ir, CALL(BPF_FUNC_map_update_elem), 0, 0);
|
|
|
368
|
+ /* TODO: if (r0) exit(r0); */
|
|
|
369
|
+ return 0;
|
|
|
370
|
+}
|
|
|
371
|
+
|
|
327
|
372
|
static int global_assign_type_infer_map(struct node *n)
|
|
328
|
373
|
{
|
|
329
|
374
|
struct node *map, *key;
|
|
|
@@ -588,6 +633,9 @@ static const struct func global_funcs[] = {
|
|
588
|
633
|
.type = &t_2args_func,
|
|
589
|
634
|
.type_infer = global_assign_type_infer,
|
|
590
|
635
|
.static_validate = global_assign_static_validate,
|
|
|
636
|
+
|
|
|
637
|
+ .ir_pre = global_assign_ir_pre,
|
|
|
638
|
+ .ir_post = global_assign_ir_post,
|
|
591
|
639
|
},
|
|
592
|
640
|
{
|
|
593
|
641
|
.name = "{}",
|