aboutsummaryrefslogtreecommitdiff
path: root/sim/igen/table.c
diff options
context:
space:
mode:
authorAndrew Cagney <cagney@redhat.com>2002-11-22 04:20:49 +0000
committerAndrew Cagney <cagney@redhat.com>2002-11-22 04:20:49 +0000
commit4e0bf4c4d00096ac436378edaf7718dafec9ff82 (patch)
tree9a80850d7051a761dee6c6dd1aed8df337a1f92c /sim/igen/table.c
parentfeaee4bdbb06466822e886f5d1d30b9f1e04d985 (diff)
downloadgdb-4e0bf4c4d00096ac436378edaf7718dafec9ff82.zip
gdb-4e0bf4c4d00096ac436378edaf7718dafec9ff82.tar.gz
gdb-4e0bf4c4d00096ac436378edaf7718dafec9ff82.tar.bz2
2002-11-21 Andrew Cagney <ac131313@redhat.com>
* filter.c: Re-indent. * filter.h, filter_host.h, gen-engine.c, gen-engine.h: Ditto. * gen-icache.c, gen-icache.h, gen-idecode.c: Ditto. * gen-idecode.h, gen-itable.c, gen-itable.h: Ditto. * gen-model.c, gen-model.h, gen-semantics.c: Ditto. * gen-semantics.h, gen-support.c, gen-support.h: Ditto. * gen.c, gen.h, igen.c, igen.h, ld-cache.c, ld-cache.h: Ditto. * ld-decode.c, ld-decode.h, ld-insn.c, ld-insn.h, lf.c: Ditto. * lf.h, misc.c, misc.h, table.c, table.h: Ditto.
Diffstat (limited to 'sim/igen/table.c')
-rw-r--r--sim/igen/table.c131
1 files changed, 59 insertions, 72 deletions
diff --git a/sim/igen/table.c b/sim/igen/table.c
index 05e4ecc..29f7188 100644
--- a/sim/igen/table.c
+++ b/sim/igen/table.c
@@ -43,7 +43,8 @@
#endif
typedef struct _open_table open_table;
-struct _open_table {
+struct _open_table
+{
size_t size;
char *buffer;
char *pos;
@@ -52,13 +53,14 @@ struct _open_table {
open_table *parent;
table *root;
};
-struct _table {
+struct _table
+{
open_table *current;
};
static line_ref *
-current_line (open_table *file)
+current_line (open_table * file)
{
line_ref *entry = ZALLOC (line_ref);
*entry = file->pseudo_line;
@@ -66,8 +68,7 @@ current_line (open_table *file)
}
static table_entry *
-new_table_entry (open_table *file,
- table_entry_type type)
+new_table_entry (open_table * file, table_entry_type type)
{
table_entry *entry;
entry = ZALLOC (table_entry);
@@ -78,19 +79,16 @@ new_table_entry (open_table *file,
}
static void
-set_nr_table_entry_fields (table_entry *entry,
- int nr_fields)
+set_nr_table_entry_fields (table_entry *entry, int nr_fields)
{
- entry->field = NZALLOC (char*, nr_fields + 1);
+ entry->field = NZALLOC (char *, nr_fields + 1);
entry->nr_fields = nr_fields;
}
void
table_push (table *root,
- line_ref *line,
- table_include *includes,
- const char *file_name)
+ line_ref *line, table_include *includes, const char *file_name)
{
FILE *ff;
open_table *file;
@@ -115,7 +113,8 @@ table_push (table *root,
while (1)
{
/* save the file name */
- char *dup_name = NZALLOC (char, strlen (include->dir) + strlen (file_name) + 2);
+ char *dup_name =
+ NZALLOC (char, strlen (include->dir) + strlen (file_name) + 2);
if (dup_name == NULL)
{
perror (file_name);
@@ -143,7 +142,7 @@ table_push (table *root,
exit (1);
}
include = include->next;
- }
+ }
/* determine the size */
@@ -152,7 +151,7 @@ table_push (table *root,
fseek (ff, 0, SEEK_SET);
/* allocate this much memory */
- file->buffer = (char*) zalloc (file->size + 1);
+ file->buffer = (char *) zalloc (file->size + 1);
if (file->buffer == NULL)
{
perror (file_name);
@@ -161,15 +160,16 @@ table_push (table *root,
file->pos = file->buffer;
/* read it all in */
- if (fread (file->buffer, 1, file->size, ff) < file->size) {
- perror (file_name);
- exit (1);
- }
+ if (fread (file->buffer, 1, file->size, ff) < file->size)
+ {
+ perror (file_name);
+ exit (1);
+ }
file->buffer[file->size] = '\0';
/* set the initial line numbering */
- file->real_line.line_nr = 1; /* specifies current line */
- file->pseudo_line.line_nr = 1; /* specifies current line */
+ file->real_line.line_nr = 1; /* specifies current line */
+ file->pseudo_line.line_nr = 1; /* specifies current line */
/* done */
fclose (ff);
@@ -197,9 +197,7 @@ skip_spaces (char *chp)
{
while (1)
{
- if (*chp == '\0'
- || *chp == '\n'
- || !isspace (*chp))
+ if (*chp == '\0' || *chp == '\n' || !isspace (*chp))
return chp;
chp++;
}
@@ -211,8 +209,7 @@ back_spaces (char *start, char *chp)
{
while (1)
{
- if (chp <= start
- || !isspace (chp[-1]))
+ if (chp <= start || !isspace (chp[-1]))
return chp;
chp--;
}
@@ -223,17 +220,14 @@ skip_digits (char *chp)
{
while (1)
{
- if (*chp == '\0'
- || *chp == '\n'
- || !isdigit (*chp))
+ if (*chp == '\0' || *chp == '\n' || !isdigit (*chp))
return chp;
chp++;
}
}
char *
-skip_to_separator (char *chp,
- char *separators)
+skip_to_separator (char *chp, char *separators)
{
while (1)
{
@@ -258,14 +252,14 @@ skip_to_null (char *chp)
static char *
-skip_to_nl (char * chp)
+skip_to_nl (char *chp)
{
return skip_to_separator (chp, "\n");
}
static void
-next_line (open_table *file)
+next_line (open_table * file)
{
file->pos = skip_to_nl (file->pos);
if (*file->pos == '0')
@@ -282,7 +276,7 @@ table_read (table *root)
{
open_table *file = root->current;
table_entry *entry = NULL;
- while(1)
+ while (1)
{
/* end-of-file? */
@@ -301,7 +295,7 @@ table_read (table *root)
if (*file->pos == '{')
{
char *chp;
- next_line (file); /* discard leading brace */
+ next_line (file); /* discard leading brace */
entry = new_table_entry (file, table_code_entry);
chp = file->pos;
/* determine how many lines are involved - look for <nl> "}" */
@@ -368,7 +362,7 @@ table_read (table *root)
if (*chp == '\t')
entry->field[line_nr] = chp + 1;
else
- entry->field[line_nr] = ""; /* blank */
+ entry->field[line_nr] = ""; /* blank */
chp = skip_to_null (chp) + 1;
}
}
@@ -389,27 +383,28 @@ table_read (table *root)
char *file_name;
file->pos = chp;
/* parse the number */
- line_nr = atoi(file->pos) - 1;
+ line_nr = atoi (file->pos) - 1;
/* skip to the file name */
while (file->pos[0] != '0'
- && file->pos[0] != '"'
- && file->pos[0] != '\0')
+ && file->pos[0] != '"' && file->pos[0] != '\0')
file->pos++;
if (file->pos[0] != '"')
- error (&file->real_line, "Missing opening quote in cpp directive\n");
+ error (&file->real_line,
+ "Missing opening quote in cpp directive\n");
/* parse the file name */
file->pos++;
file_name = file->pos;
- while (file->pos[0] != '"'
- && file->pos[0] != '\0')
+ while (file->pos[0] != '"' && file->pos[0] != '\0')
file->pos++;
if (file->pos[0] != '"')
- error (&file->real_line, "Missing closing quote in cpp directive\n");
+ error (&file->real_line,
+ "Missing closing quote in cpp directive\n");
file->pos[0] = '\0';
file->pos++;
file->pos = skip_to_nl (file->pos);
if (file->pos[0] != '\n')
- error (&file->real_line, "Missing newline in cpp directive\n");
+ error (&file->real_line,
+ "Missing newline in cpp directive\n");
file->pseudo_line.file_name = file_name;
file->pseudo_line.line_nr = line_nr;
next_line (file);
@@ -498,40 +493,35 @@ table_read (table *root)
}
extern void
-table_print_code (lf *file,
- table_entry *entry)
+table_print_code (lf *file, table_entry *entry)
{
int field_nr;
int nr = 0;
- for (field_nr = 0;
- field_nr < entry->nr_fields;
- field_nr++)
+ for (field_nr = 0; field_nr < entry->nr_fields; field_nr++)
{
char *chp = entry->field[field_nr];
int in_bit_field = 0;
if (*chp == '#')
- lf_indent_suppress(file);
- while (*chp != '\0')
+ lf_indent_suppress (file);
+ while (*chp != '\0')
{
- if (chp[0] == '{'
- && !isspace(chp[1])
- && chp[1] != '\0')
+ if (chp[0] == '{' && !isspace (chp[1]) && chp[1] != '\0')
{
in_bit_field = 1;
- nr += lf_putchr(file, '_');
+ nr += lf_putchr (file, '_');
}
else if (in_bit_field && chp[0] == ':')
{
- nr += lf_putchr(file, '_');
+ nr += lf_putchr (file, '_');
}
else if (in_bit_field && *chp == '}')
{
- nr += lf_putchr(file, '_');
+ nr += lf_putchr (file, '_');
in_bit_field = 0;
}
- else
+ else
{
- nr += lf_putchr(file, *chp);
+ nr += lf_putchr (file, *chp);
}
chp++;
}
@@ -541,17 +531,14 @@ table_print_code (lf *file,
line.line_nr += field_nr;
error (&line, "Bit field brace miss match\n");
}
- nr += lf_putchr(file, '\n');
+ nr += lf_putchr (file, '\n');
}
}
void
-dump_line_ref (lf *file,
- char *prefix,
- const line_ref *line,
- char *suffix)
+dump_line_ref (lf *file, char *prefix, const line_ref *line, char *suffix)
{
lf_printf (file, "%s(line_ref*) 0x%lx", prefix, (long) line);
if (line != NULL)
@@ -570,17 +557,17 @@ table_entry_type_to_str (table_entry_type type)
{
switch (type)
{
- case table_code_entry: return "code-entry";
- case table_colon_entry: return "colon-entry";
+ case table_code_entry:
+ return "code-entry";
+ case table_colon_entry:
+ return "colon-entry";
}
return "*invalid*";
}
void
-dump_table_entry(lf *file,
- char *prefix,
- const table_entry *entry,
- char *suffix)
+dump_table_entry (lf *file,
+ char *prefix, const table_entry *entry, char *suffix)
{
lf_printf (file, "%s(table_entry*) 0x%lx", prefix, (long) entry);
if (entry != NULL)
@@ -604,7 +591,7 @@ dump_table_entry(lf *file,
#ifdef MAIN
int
-main(int argc, char **argv)
+main (int argc, char **argv)
{
table *t;
table_entry *entry;
@@ -613,7 +600,7 @@ main(int argc, char **argv)
if (argc != 2)
{
- printf("Usage: table <file>\n");
+ printf ("Usage: table <file>\n");
exit (1);
}
@@ -625,7 +612,7 @@ main(int argc, char **argv)
{
char line[10];
entry = table_read (t);
- line_nr ++;
+ line_nr++;
sprintf (line, "(%d ", line_nr);
dump_table_entry (l, line, entry, ")\n");
}