Commit bb77a611 bb77a611f868027d03af44c69c2e471bbabbd29f by Sergey Poznyakoff

Rework emitting source locations in sieve code

* include/mailutils/locus.h (mu_locus_point_eq): New function.
* libmu_sieve/prog.c (mu_i_sv_code): Emit the _mu_i_sv_instr_locus
if locus changed.
(mu_i_sv_locus): Raise the changeloc flag and set the locus, instead
of immediately emitting location change code.
* libmu_sieve/runtime.c (_mu_i_sv_instr_locus): New function.
(_mu_i_sv_instr_source,_mu_i_sv_instr_line)
(_mu_i_sv_instr_col): Remove.
* libmu_sieve/sieve-priv.h (mu_sieve_machine) <changeloc>: New member.
1 parent 618c1e17
...@@ -78,6 +78,13 @@ mu_locus_point_same_line (struct mu_locus_point const *a, ...@@ -78,6 +78,13 @@ mu_locus_point_same_line (struct mu_locus_point const *a,
78 return mu_locus_point_same_file (a, b) && a->mu_line == b->mu_line; 78 return mu_locus_point_same_file (a, b) && a->mu_line == b->mu_line;
79 } 79 }
80 80
81 static inline int
82 mu_locus_point_eq (struct mu_locus_point const *a,
83 struct mu_locus_point const *b)
84 {
85 return mu_locus_point_same_line (a, b) && a->mu_col == b->mu_col;
86 }
87
81 int mu_linetrack_create (mu_linetrack_t *ret, 88 int mu_linetrack_create (mu_linetrack_t *ret,
82 char const *file_name, size_t max_lines); 89 char const *file_name, size_t max_lines);
83 int mu_linetrack_origin (mu_linetrack_t trk, struct mu_locus_point const *pt); 90 int mu_linetrack_origin (mu_linetrack_t trk, struct mu_locus_point const *pt);
......
...@@ -27,6 +27,22 @@ ...@@ -27,6 +27,22 @@
27 void 27 void
28 mu_i_sv_code (struct mu_sieve_machine *mach, sieve_op_t op) 28 mu_i_sv_code (struct mu_sieve_machine *mach, sieve_op_t op)
29 { 29 {
30 if (mach->changeloc)
31 {
32 mach->changeloc = 0;
33 mu_i_sv_code (mach, (sieve_op_t) _mu_i_sv_instr_locus);
34 mu_i_sv_code (mach,
35 (sieve_op_t) mu_i_sv_id_num (mach,
36 mach->locus.beg.mu_file));
37 mu_i_sv_code (mach, (sieve_op_t) mach->locus.beg.mu_line);
38 mu_i_sv_code (mach, (sieve_op_t) mach->locus.beg.mu_col);
39 mu_i_sv_code (mach,
40 (sieve_op_t) mu_i_sv_id_num (mach,
41 mach->locus.end.mu_file));
42 mu_i_sv_code (mach, (sieve_op_t) mach->locus.end.mu_line);
43 mu_i_sv_code (mach, (sieve_op_t) mach->locus.end.mu_col);
44 }
45
30 if (mach->pc >= mach->progsize) 46 if (mach->pc >= mach->progsize)
31 { 47 {
32 mu_i_sv_2nrealloc (mach, (void**) &mach->prog, &mach->progsize, 48 mu_i_sv_2nrealloc (mach, (void**) &mach->prog, &mach->progsize,
...@@ -38,45 +54,11 @@ mu_i_sv_code (struct mu_sieve_machine *mach, sieve_op_t op) ...@@ -38,45 +54,11 @@ mu_i_sv_code (struct mu_sieve_machine *mach, sieve_op_t op)
38 int 54 int
39 mu_i_sv_locus (struct mu_sieve_machine *mach, struct mu_locus_range *lr) 55 mu_i_sv_locus (struct mu_sieve_machine *mach, struct mu_locus_range *lr)
40 { 56 {
41 if (!mu_locus_point_same_file (&mach->locus.beg, &lr->beg)) 57 if (!mu_locus_point_eq (&mach->locus.beg, &lr->beg))
42 {
43 mu_i_sv_code (mach, (sieve_op_t) _mu_i_sv_instr_source);
44 mu_i_sv_code (mach, (sieve_op_t) mu_i_sv_id_num (mach, lr->beg.mu_file));
45 mu_i_sv_code (mach, (sieve_op_t) (int) 0);
46 }
47 if (mach->locus.beg.mu_line != lr->beg.mu_line)
48 {
49 mu_i_sv_code (mach, (sieve_op_t) _mu_i_sv_instr_line);
50 mu_i_sv_code (mach, (sieve_op_t) lr->beg.mu_line);
51 mu_i_sv_code (mach, (sieve_op_t) (int) 0);
52 }
53 if (mach->locus.beg.mu_col != lr->beg.mu_col)
54 {
55 mu_i_sv_code (mach, (sieve_op_t) _mu_i_sv_instr_col);
56 mu_i_sv_code (mach, (sieve_op_t) lr->beg.mu_col);
57 mu_i_sv_code (mach, (sieve_op_t) (int) 0);
58 }
59
60 if (!mu_locus_point_same_file (&mach->locus.end, &lr->end))
61 {
62 mu_i_sv_code (mach, (sieve_op_t) _mu_i_sv_instr_source);
63 mu_i_sv_code (mach, (sieve_op_t) mu_i_sv_id_num (mach, lr->end.mu_file));
64 mu_i_sv_code (mach, (sieve_op_t) (int) 1);
65 }
66 if (mach->locus.end.mu_line != lr->end.mu_line)
67 {
68 mu_i_sv_code (mach, (sieve_op_t) _mu_i_sv_instr_line);
69 mu_i_sv_code (mach, (sieve_op_t) lr->end.mu_line);
70 mu_i_sv_code (mach, (sieve_op_t) (int) 1);
71 }
72 if (mach->locus.end.mu_col != lr->end.mu_col)
73 { 58 {
74 mu_i_sv_code (mach, (sieve_op_t) _mu_i_sv_instr_col); 59 mach->changeloc = 1;
75 mu_i_sv_code (mach, (sieve_op_t) lr->end.mu_col);
76 mu_i_sv_code (mach, (sieve_op_t) (int) 1);
77 }
78
79 mu_locus_range_copy (&mach->locus, lr); 60 mu_locus_range_copy (&mach->locus, lr);
61 }
80 return 0; 62 return 0;
81 } 63 }
82 64
......
...@@ -32,48 +32,22 @@ ...@@ -32,48 +32,22 @@
32 (INSTR_DISASS(m) || mu_debug_level_p (mu_sieve_debug_handle, MU_DEBUG_TRACE9)) 32 (INSTR_DISASS(m) || mu_debug_level_p (mu_sieve_debug_handle, MU_DEBUG_TRACE9))
33 33
34 void 34 void
35 _mu_i_sv_instr_source (mu_sieve_machine_t mach) 35 _mu_i_sv_instr_locus (mu_sieve_machine_t mach)
36 { 36 {
37 char const *file = mu_i_sv_id_str (mach, SIEVE_RT_ARG (mach, 0, pc)); 37 mu_locus_point_set_file (&mach->locus.beg,
38 int what = SIEVE_RT_ARG (mach, 1, inum); 38 mu_i_sv_id_str (mach, SIEVE_RT_ARG (mach, 0, pc)));
39 mu_locus_point_set_file (what ? &mach->locus.beg : &mach->locus.end, file); 39 mach->locus.beg.mu_line = SIEVE_RT_ARG (mach, 1, unum);
40 if (INSTR_DEBUG (mach)) 40 mach->locus.beg.mu_col = SIEVE_RT_ARG (mach, 2, unum);
41 mu_i_sv_debug (mach, mach->pc - 2, "SOURCE %s %d", file, what); 41
42 SIEVE_RT_ADJUST (mach, 2); 42 mu_locus_point_set_file (&mach->locus.end,
43 mu_i_sv_id_str (mach, SIEVE_RT_ARG (mach, 3, pc)));
44 mach->locus.end.mu_line = SIEVE_RT_ARG (mach, 4, unum);
45 mach->locus.end.mu_col = SIEVE_RT_ARG (mach, 5, unum);
43 mu_stream_ioctl (mach->errstream, MU_IOCTL_LOGSTREAM, 46 mu_stream_ioctl (mach->errstream, MU_IOCTL_LOGSTREAM,
44 MU_IOCTL_LOGSTREAM_SET_LOCUS_RANGE, &mach->locus); 47 MU_IOCTL_LOGSTREAM_SET_LOCUS_RANGE, &mach->locus);
45 }
46
47 void
48 _mu_i_sv_instr_line (mu_sieve_machine_t mach)
49 {
50 unsigned line = SIEVE_RT_ARG (mach, 0, line);
51 int what = SIEVE_RT_ARG (mach, 1, inum);
52 if (what == 0)
53 mach->locus.beg.mu_line = line;
54 else
55 mach->locus.end.mu_line = line;
56 if (INSTR_DEBUG (mach)) 48 if (INSTR_DEBUG (mach))
57 mu_i_sv_debug (mach, mach->pc - 1, "LINE %u %d", line, what); 49 mu_i_sv_debug (mach, mach->pc - 1, "LOCUS");
58 SIEVE_RT_ADJUST (mach, 2); 50 SIEVE_RT_ADJUST (mach, 6);
59 mu_stream_ioctl (mach->errstream, MU_IOCTL_LOGSTREAM,
60 MU_IOCTL_LOGSTREAM_SET_LOCUS_RANGE, &mach->locus);
61 }
62
63 void
64 _mu_i_sv_instr_col (mu_sieve_machine_t mach)
65 {
66 unsigned col = SIEVE_RT_ARG (mach, 0, line);
67 int what = SIEVE_RT_ARG (mach, 1, inum);
68 if (what == 0)
69 mach->locus.beg.mu_col = col;
70 else
71 mach->locus.end.mu_col = col;
72 if (INSTR_DEBUG (mach))
73 mu_i_sv_debug (mach, mach->pc - 2, "COLUMN %u %d", col, what);
74 SIEVE_RT_ADJUST (mach, 2);
75 mu_stream_ioctl (mach->errstream, MU_IOCTL_LOGSTREAM,
76 MU_IOCTL_LOGSTREAM_SET_LOCUS_RANGE, &mach->locus);
77 } 51 }
78 52
79 static int 53 static int
......
...@@ -58,6 +58,9 @@ struct mu_sieve_machine ...@@ -58,6 +58,9 @@ struct mu_sieve_machine
58 { 58 {
59 /* Static data */ 59 /* Static data */
60 struct mu_locus_range locus; /* Approximate location in the code */ 60 struct mu_locus_range locus; /* Approximate location in the code */
61 int changeloc:1; /* If set during code generation phase, the
62 _mu_i_sv_instr_locus will be emitted before
63 next instruction */
61 64
62 mu_list_t memory_pool; /* Pool of allocated memory objects */ 65 mu_list_t memory_pool; /* Pool of allocated memory objects */
63 mu_list_t destr_list; /* List of destructor functions */ 66 mu_list_t destr_list; /* List of destructor functions */
...@@ -197,9 +200,7 @@ void _mu_i_sv_instr_not (mu_sieve_machine_t mach); ...@@ -197,9 +200,7 @@ void _mu_i_sv_instr_not (mu_sieve_machine_t mach);
197 void _mu_i_sv_instr_branch (mu_sieve_machine_t mach); 200 void _mu_i_sv_instr_branch (mu_sieve_machine_t mach);
198 void _mu_i_sv_instr_brz (mu_sieve_machine_t mach); 201 void _mu_i_sv_instr_brz (mu_sieve_machine_t mach);
199 void _mu_i_sv_instr_brnz (mu_sieve_machine_t mach); 202 void _mu_i_sv_instr_brnz (mu_sieve_machine_t mach);
200 void _mu_i_sv_instr_source (mu_sieve_machine_t mach); 203 void _mu_i_sv_instr_locus (mu_sieve_machine_t mach);
201 void _mu_i_sv_instr_line (mu_sieve_machine_t mach);
202 void _mu_i_sv_instr_col (mu_sieve_machine_t mach);
203 204
204 int mu_i_sv_load_add_dir (mu_sieve_machine_t mach, const char *name); 205 int mu_i_sv_load_add_dir (mu_sieve_machine_t mach, const char *name);
205 206
......