static struct parsed_op ops[MAX_OPS];
static struct parsed_equ *g_eqs;
static int g_eqcnt;
-static char g_labels[MAX_OPS][48];
+static char *g_labels[MAX_OPS];
static struct label_ref g_label_refs[MAX_OPS];
static const struct parsed_proto *g_func_pp;
static struct parsed_data *g_func_pd;
break;
}
- if (g_labels[j][0] != 0)
+ if (g_labels[j] != NULL)
return -1;
}
}
}
ops[i].cc_scratch = magic;
- if (g_labels[i][0] != 0) {
+ if (g_labels[i] != NULL) {
*branched = 1;
lr = &g_label_refs[i];
static int scan_for_cdq_edx(int i)
{
while (i >= 0) {
- if (g_labels[i][0] != 0) {
+ if (g_labels[i] != NULL) {
if (g_label_refs[i].next != NULL)
return -1;
if (i > 0 && LAST_OP(i - 1)) {
static int scan_for_reg_clear(int i, int reg)
{
while (i >= 0) {
- if (g_labels[i][0] != 0) {
+ if (g_labels[i] != NULL) {
if (g_label_refs[i].next != NULL)
return -1;
if (i > 0 && LAST_OP(i - 1)) {
for (; i < opcnt; i++) {
po = &ops[i];
- if (g_labels[i][0] != 0)
+ if (g_labels[i] != NULL)
*multipath = 1;
if (po->op == OP_ADD && po->operand[0].reg == xSP) {
ops[i].cc_scratch = magic;
while (1) {
- if (g_labels[i][0] != 0) {
+ if (g_labels[i] != NULL) {
lr = &g_label_refs[i];
for (; lr != NULL; lr = lr->next) {
check_i(&ops[i], lr->i);
ops[i].cc_scratch = magic;
while (1) {
- if (g_labels[i][0] != 0) {
+ if (g_labels[i] != NULL) {
lr = &g_label_refs[i];
for (; lr != NULL; lr = lr->next) {
check_i(&ops[i], lr->i);
}
ops[j].cc_scratch = magic;
- if (g_labels[j][0] != 0 && g_label_refs[j].i != -1) {
+ if (g_labels[j] != NULL && g_label_refs[j].i != -1) {
lr = &g_label_refs[j];
if (lr->next != NULL)
need_op_saving = 1;
// find all labels, link
for (j = 0; j < pd->count; j++) {
for (l = 0; l < opcnt; l++) {
- if (g_labels[l][0] && IS(g_labels[l], pd->d[j].u.label)) {
+ if (g_labels[l] != NULL && IS(g_labels[l], pd->d[j].u.label)) {
add_label_ref(&g_label_refs[l], i);
pd->d[j].bt_i = l;
break;
return pd;
}
+static void clear_labels(int count)
+{
+ int i;
+
+ for (i = 0; i < count; i++) {
+ if (g_labels[i] != NULL) {
+ free(g_labels[i]);
+ g_labels[i] = NULL;
+ }
+ }
+}
+
static void output_std_flags(FILE *fout, struct parsed_op *po,
int *pfomask, const char *dst_opr_text)
{
}
for (l = 0; l < opcnt; l++) {
- if (g_labels[l][0] && IS(po->operand[0].name, g_labels[l])) {
+ if (g_labels[l] != NULL
+ && IS(po->operand[0].name, g_labels[l]))
+ {
if (l == i + 1 && po->op == OP_JMP) {
// yet another alignment type..
po->flags |= OPF_RMD;
// - process calls
for (i = 0; i < opcnt; i++)
{
- if (g_labels[i][0] != 0 && g_label_refs[i].i == -1)
- g_labels[i][0] = 0;
+ if (g_labels[i] != NULL && g_label_refs[i].i == -1) {
+ free(g_labels[i]);
+ g_labels[i] = NULL;
+ }
po = &ops[i];
if (po->flags & OPF_RMD)
else if (po->operand[0].type == OPT_CONST) {
for (j = i + 1; j < opcnt; j++) {
if ((ops[j].flags & (OPF_JMP|OPF_TAIL|OPF_RSAVE))
- || ops[j].op == OP_PUSH || g_labels[i][0] != 0)
+ || ops[j].op == OP_PUSH || g_labels[i] != NULL)
{
break;
}
// output ops
for (i = 0; i < opcnt; i++)
{
- if (g_labels[i][0] != 0) {
+ if (g_labels[i] != NULL) {
fprintf(fout, "\n%s:\n", g_labels[i]);
label_pending = 1;
}
for (l = 0; l < opcnt; l++) {
- if (g_labels[l][0] && IS(po->operand[0].name, g_labels[l])) {
+ if (g_labels[l] != NULL
+ && IS(po->operand[0].name, g_labels[l]))
+ {
add_label_ref(&g_label_refs[l], i);
po->bt_i = l;
break;
// - remove dead labels
for (i = 0; i < opcnt; i++)
{
- if (g_labels[i][0] != 0 && g_label_refs[i].i == -1)
- g_labels[i][0] = 0;
+ if (g_labels[i] != NULL && g_label_refs[i].i == -1) {
+ free(g_labels[i]);
+ g_labels[i] = NULL;
+ }
}
// pass3:
else if (po->op == OP_PUSH && po->operand[0].type == OPT_CONST) {
for (j = i + 1; j < opcnt; j++) {
if ((ops[j].flags & (OPF_JMP|OPF_TAIL|OPF_RSAVE))
- || ops[j].op == OP_PUSH || g_labels[i][0] != 0)
+ || ops[j].op == OP_PUSH || g_labels[i] != NULL)
{
break;
}
if (p != NULL)
len = p - name;
- if (len > sizeof(g_labels[0]) - 1)
- aerr("label '%s' too long: %d\n", name, len);
- if (g_labels[i][0] != 0 && !IS_START(g_labels[i], "algn_"))
+ if (g_labels[i] != NULL && !IS_START(g_labels[i], "algn_"))
aerr("dupe label '%s' vs '%s'?\n", name, g_labels[i]);
+ g_labels[i] = realloc(g_labels[i], len + 1);
+ my_assert_not(g_labels[i], NULL);
memcpy(g_labels[i], name, len);
g_labels[i][len] = 0;
}
func_chunk_i = -1;
if (pi != 0) {
memset(&ops, 0, pi * sizeof(ops[0]));
- memset(g_labels, 0, pi * sizeof(g_labels[0]));
+ clear_labels(pi);
pi = 0;
}
g_eqcnt = 0;
}
if (!in_func || skip_func) {
- if (!skip_warned && !skip_func && g_labels[pi][0] != 0) {
+ if (!skip_warned && !skip_func && g_labels[pi] != NULL) {
if (verbose)
anote("skipping from '%s'\n", g_labels[pi]);
skip_warned = 1;
}
- g_labels[pi][0] = 0;
+ free(g_labels[pi]);
+ g_labels[pi] = NULL;
continue;
}