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,
return mu_locus_point_same_file (a, b) && a->mu_line == b->mu_line;
}
static inline int
mu_locus_point_eq (struct mu_locus_point const *a,
struct mu_locus_point const *b)
{
return mu_locus_point_same_line (a, b) && a->mu_col == b->mu_col;
}
int mu_linetrack_create (mu_linetrack_t *ret,
char const *file_name, size_t max_lines);
int mu_linetrack_origin (mu_linetrack_t trk, struct mu_locus_point const *pt);
......
......@@ -27,6 +27,22 @@
void
mu_i_sv_code (struct mu_sieve_machine *mach, sieve_op_t op)
{
if (mach->changeloc)
{
mach->changeloc = 0;
mu_i_sv_code (mach, (sieve_op_t) _mu_i_sv_instr_locus);
mu_i_sv_code (mach,
(sieve_op_t) mu_i_sv_id_num (mach,
mach->locus.beg.mu_file));
mu_i_sv_code (mach, (sieve_op_t) mach->locus.beg.mu_line);
mu_i_sv_code (mach, (sieve_op_t) mach->locus.beg.mu_col);
mu_i_sv_code (mach,
(sieve_op_t) mu_i_sv_id_num (mach,
mach->locus.end.mu_file));
mu_i_sv_code (mach, (sieve_op_t) mach->locus.end.mu_line);
mu_i_sv_code (mach, (sieve_op_t) mach->locus.end.mu_col);
}
if (mach->pc >= mach->progsize)
{
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)
int
mu_i_sv_locus (struct mu_sieve_machine *mach, struct mu_locus_range *lr)
{
if (!mu_locus_point_same_file (&mach->locus.beg, &lr->beg))
{
mu_i_sv_code (mach, (sieve_op_t) _mu_i_sv_instr_source);
mu_i_sv_code (mach, (sieve_op_t) mu_i_sv_id_num (mach, lr->beg.mu_file));
mu_i_sv_code (mach, (sieve_op_t) (int) 0);
}
if (mach->locus.beg.mu_line != lr->beg.mu_line)
{
mu_i_sv_code (mach, (sieve_op_t) _mu_i_sv_instr_line);
mu_i_sv_code (mach, (sieve_op_t) lr->beg.mu_line);
mu_i_sv_code (mach, (sieve_op_t) (int) 0);
}
if (mach->locus.beg.mu_col != lr->beg.mu_col)
if (!mu_locus_point_eq (&mach->locus.beg, &lr->beg))
{
mu_i_sv_code (mach, (sieve_op_t) _mu_i_sv_instr_col);
mu_i_sv_code (mach, (sieve_op_t) lr->beg.mu_col);
mu_i_sv_code (mach, (sieve_op_t) (int) 0);
mach->changeloc = 1;
mu_locus_range_copy (&mach->locus, lr);
}
if (!mu_locus_point_same_file (&mach->locus.end, &lr->end))
{
mu_i_sv_code (mach, (sieve_op_t) _mu_i_sv_instr_source);
mu_i_sv_code (mach, (sieve_op_t) mu_i_sv_id_num (mach, lr->end.mu_file));
mu_i_sv_code (mach, (sieve_op_t) (int) 1);
}
if (mach->locus.end.mu_line != lr->end.mu_line)
{
mu_i_sv_code (mach, (sieve_op_t) _mu_i_sv_instr_line);
mu_i_sv_code (mach, (sieve_op_t) lr->end.mu_line);
mu_i_sv_code (mach, (sieve_op_t) (int) 1);
}
if (mach->locus.end.mu_col != lr->end.mu_col)
{
mu_i_sv_code (mach, (sieve_op_t) _mu_i_sv_instr_col);
mu_i_sv_code (mach, (sieve_op_t) lr->end.mu_col);
mu_i_sv_code (mach, (sieve_op_t) (int) 1);
}
mu_locus_range_copy (&mach->locus, lr);
return 0;
}
......
......@@ -32,48 +32,22 @@
(INSTR_DISASS(m) || mu_debug_level_p (mu_sieve_debug_handle, MU_DEBUG_TRACE9))
void
_mu_i_sv_instr_source (mu_sieve_machine_t mach)
_mu_i_sv_instr_locus (mu_sieve_machine_t mach)
{
char const *file = mu_i_sv_id_str (mach, SIEVE_RT_ARG (mach, 0, pc));
int what = SIEVE_RT_ARG (mach, 1, inum);
mu_locus_point_set_file (what ? &mach->locus.beg : &mach->locus.end, file);
if (INSTR_DEBUG (mach))
mu_i_sv_debug (mach, mach->pc - 2, "SOURCE %s %d", file, what);
SIEVE_RT_ADJUST (mach, 2);
mu_locus_point_set_file (&mach->locus.beg,
mu_i_sv_id_str (mach, SIEVE_RT_ARG (mach, 0, pc)));
mach->locus.beg.mu_line = SIEVE_RT_ARG (mach, 1, unum);
mach->locus.beg.mu_col = SIEVE_RT_ARG (mach, 2, unum);
mu_locus_point_set_file (&mach->locus.end,
mu_i_sv_id_str (mach, SIEVE_RT_ARG (mach, 3, pc)));
mach->locus.end.mu_line = SIEVE_RT_ARG (mach, 4, unum);
mach->locus.end.mu_col = SIEVE_RT_ARG (mach, 5, unum);
mu_stream_ioctl (mach->errstream, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_LOCUS_RANGE, &mach->locus);
}
void
_mu_i_sv_instr_line (mu_sieve_machine_t mach)
{
unsigned line = SIEVE_RT_ARG (mach, 0, line);
int what = SIEVE_RT_ARG (mach, 1, inum);
if (what == 0)
mach->locus.beg.mu_line = line;
else
mach->locus.end.mu_line = line;
if (INSTR_DEBUG (mach))
mu_i_sv_debug (mach, mach->pc - 1, "LINE %u %d", line, what);
SIEVE_RT_ADJUST (mach, 2);
mu_stream_ioctl (mach->errstream, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_LOCUS_RANGE, &mach->locus);
}
void
_mu_i_sv_instr_col (mu_sieve_machine_t mach)
{
unsigned col = SIEVE_RT_ARG (mach, 0, line);
int what = SIEVE_RT_ARG (mach, 1, inum);
if (what == 0)
mach->locus.beg.mu_col = col;
else
mach->locus.end.mu_col = col;
if (INSTR_DEBUG (mach))
mu_i_sv_debug (mach, mach->pc - 2, "COLUMN %u %d", col, what);
SIEVE_RT_ADJUST (mach, 2);
mu_stream_ioctl (mach->errstream, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_LOCUS_RANGE, &mach->locus);
mu_i_sv_debug (mach, mach->pc - 1, "LOCUS");
SIEVE_RT_ADJUST (mach, 6);
}
static int
......
......@@ -58,7 +58,10 @@ struct mu_sieve_machine
{
/* Static data */
struct mu_locus_range locus; /* Approximate location in the code */
int changeloc:1; /* If set during code generation phase, the
_mu_i_sv_instr_locus will be emitted before
next instruction */
mu_list_t memory_pool; /* Pool of allocated memory objects */
mu_list_t destr_list; /* List of destructor functions */
......@@ -197,9 +200,7 @@ void _mu_i_sv_instr_not (mu_sieve_machine_t mach);
void _mu_i_sv_instr_branch (mu_sieve_machine_t mach);
void _mu_i_sv_instr_brz (mu_sieve_machine_t mach);
void _mu_i_sv_instr_brnz (mu_sieve_machine_t mach);
void _mu_i_sv_instr_source (mu_sieve_machine_t mach);
void _mu_i_sv_instr_line (mu_sieve_machine_t mach);
void _mu_i_sv_instr_col (mu_sieve_machine_t mach);
void _mu_i_sv_instr_locus (mu_sieve_machine_t mach);
int mu_i_sv_load_add_dir (mu_sieve_machine_t mach, const char *name);
......