epsilon-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Question/Bug report


From: Mohammad-Reza Nabipoor
Subject: Question/Bug report
Date: Thu, 9 Dec 2021 19:49:06 +0330

Hi, Luca.

It seems `vmprefix_mutable_routine_print` should be called after
`vmprefix_make_executable_routine` to print the labels correctly.

So, why not `vmprefix_executable_routine_print` instead of
`vmprefix_mutable_routine_print`?


Reproducer:


```jitter
vm
  set prefix "pr"
end

state-struct-runtime-c
  code
  end
end

stack s
  long-name "stack"
  c-element-type "uintptr_t"
  c-initial-value "0"
  element-no 4096
  tos-optimized
  guard-underflow
  guard-overflow
end

early-header-c
  code
#include <stdint.h>
  end
end

wrapped-functions
end

instruction push (?n)
  code
    PR_PUSH_STACK (JITTER_ARGN0);
  end
end

instruction b (?f)
  code
    JITTER_BRANCH_FAST (JITTER_ARGF0);
  end
end
```


```c
#include "pr-vm.h"

int
main ()
{
  pr_initialize ();

  struct pr_mutable_routine *r = pr_make_mutable_routine ();
  pr_label l1 = pr_fresh_label (r);
  pr_label l2 = pr_fresh_label (r);

#define push(x)                                                               \
  do                                                                          \
    {                                                                         \
      PR_MUTABLE_ROUTINE_APPEND_INSTRUCTION (r, push);                        \
      pr_mutable_routine_append_unsigned_literal_parameter (r, x);            \
    }                                                                         \
  while (0)
#define b(x)                                                                  \
  do                                                                          \
    {                                                                         \
      PR_MUTABLE_ROUTINE_APPEND_INSTRUCTION (r, b);                           \
      pr_mutable_routine_append_label_parameter (r, x);                       \
    }                                                                         \
  while (0)
#define lbl(x) pr_mutable_routine_append_label (r, x)

  push (1);
  push (2);
  push (3);
  b (l2);
  lbl (l1);
  push (4);
  push (5);
  lbl (l2);
  b (l1);

#undef lbl
#undef b
#undef push

  jitter_print_context pctx = jitter_print_context_make_file_star (stdout);

  puts ("\nBefore:");
  pr_mutable_routine_print (pctx, r);

  struct pr_executable_routine *rx = pr_make_executable_routine (r);

  puts ("\nAfter:");
  pr_mutable_routine_print (pctx, r);

  pr_destroy_mutable_routine (r);
  pr_finalize ();
  return 0;
}
```

Ouput:

```text
Before:
$L0: push 0x1
$L1: push 0x2
     push 0x3
     b    $L1
     push 0x4
     push 0x5
     b    $L0

After:
     push   0x1
     push   0x2
     push   0x3
     b      $L6
$L4: push   0x4
     push   0x5
$L6: b      $L4
     exitvm
```


Regards,
Mohammad-Reza



reply via email to

[Prev in Thread] Current Thread [Next in Thread]