Use std::vector in compile-loc2c.c

This changes compile-loc2c.c to use std::vector, removing some
cleanups.

gdb/ChangeLog
2017-11-04  Tom Tromey  <tom@tromey.com>

	* compile/compile-loc2c.c (compute_stack_depth_worker): Change
	type of "info".
	(compute_stack_depth): Likewise.
	(do_compile_dwarf_expr_to_c): Use std::vector.
This commit is contained in:
Tom Tromey
2017-10-25 15:46:31 -06:00
parent 20dcd8cae7
commit c6bcad5ffc
2 changed files with 24 additions and 25 deletions

View File

@ -1,3 +1,10 @@
2017-11-04 Tom Tromey <tom@tromey.com>
* compile/compile-loc2c.c (compute_stack_depth_worker): Change
type of "info".
(compute_stack_depth): Likewise.
(do_compile_dwarf_expr_to_c): Use std::vector.
2017-11-04 Tom Tromey <tom@tromey.com> 2017-11-04 Tom Tromey <tom@tromey.com>
* compile/compile-object-load.c (link_callbacks_einfo): Use * compile/compile-object-load.c (link_callbacks_einfo): Use

View File

@ -62,7 +62,7 @@ struct insn_info
NEED_TEMPVAR is an out parameter which is set if this expression NEED_TEMPVAR is an out parameter which is set if this expression
needs a special temporary variable to be emitted (see the code needs a special temporary variable to be emitted (see the code
generator). generator).
INFO is an array of insn_info objects, indexed by offset from the INFO is a vector of insn_info objects, indexed by offset from the
start of the DWARF expression. start of the DWARF expression.
TO_DO is a list of bytecodes which must be examined; it may be TO_DO is a list of bytecodes which must be examined; it may be
added to by this function. added to by this function.
@ -71,7 +71,7 @@ struct insn_info
static void static void
compute_stack_depth_worker (int start, int *need_tempvar, compute_stack_depth_worker (int start, int *need_tempvar,
struct insn_info *info, std::vector<struct insn_info> *info,
std::vector<int> *to_do, std::vector<int> *to_do,
enum bfd_endian byte_order, unsigned int addr_size, enum bfd_endian byte_order, unsigned int addr_size,
const gdb_byte *op_ptr, const gdb_byte *op_end) const gdb_byte *op_ptr, const gdb_byte *op_end)
@ -80,8 +80,8 @@ compute_stack_depth_worker (int start, int *need_tempvar,
int stack_depth; int stack_depth;
op_ptr += start; op_ptr += start;
gdb_assert (info[start].visited); gdb_assert ((*info)[start].visited);
stack_depth = info[start].depth; stack_depth = (*info)[start].depth;
while (op_ptr < op_end) while (op_ptr < op_end)
{ {
@ -91,16 +91,16 @@ compute_stack_depth_worker (int start, int *need_tempvar,
int ndx = op_ptr - base; int ndx = op_ptr - base;
#define SET_CHECK_DEPTH(WHERE) \ #define SET_CHECK_DEPTH(WHERE) \
if (info[WHERE].visited) \ if ((*info)[WHERE].visited) \
{ \ { \
if (info[WHERE].depth != stack_depth) \ if ((*info)[WHERE].depth != stack_depth) \
error (_("inconsistent stack depths")); \ error (_("inconsistent stack depths")); \
} \ } \
else \ else \
{ \ { \
/* Stack depth not set, so set it. */ \ /* Stack depth not set, so set it. */ \
info[WHERE].visited = 1; \ (*info)[WHERE].visited = 1; \
info[WHERE].depth = stack_depth; \ (*info)[WHERE].depth = stack_depth; \
} }
SET_CHECK_DEPTH (ndx); SET_CHECK_DEPTH (ndx);
@ -324,7 +324,7 @@ compute_stack_depth_worker (int start, int *need_tempvar,
case DW_OP_GNU_push_tls_address: case DW_OP_GNU_push_tls_address:
case DW_OP_form_tls_address: case DW_OP_form_tls_address:
info[ndx].is_tls = 1; (*info)[ndx].is_tls = 1;
break; break;
case DW_OP_skip: case DW_OP_skip:
@ -333,10 +333,10 @@ compute_stack_depth_worker (int start, int *need_tempvar,
offset = op_ptr + offset - base; offset = op_ptr + offset - base;
/* If the destination has not been seen yet, add it to the /* If the destination has not been seen yet, add it to the
to-do list. */ to-do list. */
if (!info[offset].visited) if (!(*info)[offset].visited)
to_do->push_back (offset); to_do->push_back (offset);
SET_CHECK_DEPTH (offset); SET_CHECK_DEPTH (offset);
info[offset].label = 1; (*info)[offset].label = 1;
/* We're done with this line of code. */ /* We're done with this line of code. */
return; return;
@ -347,10 +347,10 @@ compute_stack_depth_worker (int start, int *need_tempvar,
--stack_depth; --stack_depth;
/* If the destination has not been seen yet, add it to the /* If the destination has not been seen yet, add it to the
to-do list. */ to-do list. */
if (!info[offset].visited) if (!(*info)[offset].visited)
to_do->push_back (offset); to_do->push_back (offset);
SET_CHECK_DEPTH (offset); SET_CHECK_DEPTH (offset);
info[offset].label = 1; (*info)[offset].label = 1;
break; break;
case DW_OP_nop: case DW_OP_nop:
@ -387,15 +387,13 @@ compute_stack_depth (enum bfd_endian byte_order, unsigned int addr_size,
int *need_tempvar, int *is_tls, int *need_tempvar, int *is_tls,
const gdb_byte *op_ptr, const gdb_byte *op_end, const gdb_byte *op_ptr, const gdb_byte *op_end,
int initial_depth, int initial_depth,
struct insn_info **info) std::vector<struct insn_info> *info)
{ {
unsigned char *set; unsigned char *set;
struct cleanup *outer_cleanup;
std::vector<int> to_do; std::vector<int> to_do;
int stack_depth, i; int stack_depth, i;
*info = XCNEWVEC (struct insn_info, op_end - op_ptr); info->resize (op_end - op_ptr);
outer_cleanup = make_cleanup (xfree, *info);
to_do.push_back (0); to_do.push_back (0);
(*info)[0].depth = initial_depth; (*info)[0].depth = initial_depth;
@ -406,7 +404,7 @@ compute_stack_depth (enum bfd_endian byte_order, unsigned int addr_size,
int ndx = to_do.back (); int ndx = to_do.back ();
to_do.pop_back (); to_do.pop_back ();
compute_stack_depth_worker (ndx, need_tempvar, *info, &to_do, compute_stack_depth_worker (ndx, need_tempvar, info, &to_do,
byte_order, addr_size, byte_order, addr_size,
op_ptr, op_end); op_ptr, op_end);
} }
@ -421,7 +419,6 @@ compute_stack_depth (enum bfd_endian byte_order, unsigned int addr_size,
*is_tls = 1; *is_tls = 1;
} }
discard_cleanups (outer_cleanup);
return stack_depth + 1; return stack_depth + 1;
} }
@ -594,8 +591,7 @@ do_compile_dwarf_expr_to_c (int indent, string_file &stream,
const gdb_byte * const base = op_ptr; const gdb_byte * const base = op_ptr;
int need_tempvar = 0; int need_tempvar = 0;
int is_tls = 0; int is_tls = 0;
struct cleanup *cleanup; std::vector<struct insn_info> info;
struct insn_info *info;
int stack_depth; int stack_depth;
++scope; ++scope;
@ -609,7 +605,6 @@ do_compile_dwarf_expr_to_c (int indent, string_file &stream,
&need_tempvar, &is_tls, &need_tempvar, &is_tls,
op_ptr, op_end, initial != NULL, op_ptr, op_end, initial != NULL,
&info); &info);
cleanup = make_cleanup (xfree, info);
/* This is a hack until we can add a feature to glibc to let us /* This is a hack until we can add a feature to glibc to let us
properly generate code for TLS. You might think we could emit properly generate code for TLS. You might think we could emit
@ -643,7 +638,6 @@ do_compile_dwarf_expr_to_c (int indent, string_file &stream,
result_name, result_name,
core_addr_to_string (value_address (val))); core_addr_to_string (value_address (val)));
fprintfi_filtered (indent - 2, &stream, "}\n"); fprintfi_filtered (indent - 2, &stream, "}\n");
do_cleanups (cleanup);
return; return;
} }
@ -1117,8 +1111,6 @@ do_compile_dwarf_expr_to_c (int indent, string_file &stream,
fprintfi_filtered (indent, &stream, "%s = __gdb_stack[__gdb_tos];\n", fprintfi_filtered (indent, &stream, "%s = __gdb_stack[__gdb_tos];\n",
result_name); result_name);
fprintfi_filtered (indent - 2, &stream, "}\n"); fprintfi_filtered (indent - 2, &stream, "}\n");
do_cleanups (cleanup);
} }
/* See compile.h. */ /* See compile.h. */