xref: /netbsd-src/external/gpl3/gdb/dist/sim/igen/table.h (revision 71f621822dbfd5073a314948bec169b7bb05f7be)
14e98e3e1Schristos /* The IGEN simulator generator for GDB, the GNU Debugger.
24e98e3e1Schristos 
3*71f62182Schristos    Copyright 2002-2024 Free Software Foundation, Inc.
44e98e3e1Schristos 
54e98e3e1Schristos    Contributed by Andrew Cagney.
64e98e3e1Schristos 
74e98e3e1Schristos    This file is part of GDB.
84e98e3e1Schristos 
94e98e3e1Schristos    This program is free software; you can redistribute it and/or modify
104e98e3e1Schristos    it under the terms of the GNU General Public License as published by
114e98e3e1Schristos    the Free Software Foundation; either version 3 of the License, or
124e98e3e1Schristos    (at your option) any later version.
134e98e3e1Schristos 
144e98e3e1Schristos    This program is distributed in the hope that it will be useful,
154e98e3e1Schristos    but WITHOUT ANY WARRANTY; without even the implied warranty of
164e98e3e1Schristos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
174e98e3e1Schristos    GNU General Public License for more details.
184e98e3e1Schristos 
194e98e3e1Schristos    You should have received a copy of the GNU General Public License
204e98e3e1Schristos    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
214e98e3e1Schristos 
22*71f62182Schristos #ifndef IGEN_TABLE_H
23*71f62182Schristos #define IGEN_TABLE_H
244e98e3e1Schristos 
254e98e3e1Schristos /* Read a table, line by line, from a file.
264e98e3e1Schristos 
274e98e3e1Schristos    A table line has several forms:
284e98e3e1Schristos 
294e98e3e1Schristos    Field line:
304e98e3e1Schristos 
314e98e3e1Schristos        <text> { ":" <text> }
324e98e3e1Schristos        type == table_colon_entry
334e98e3e1Schristos 
344e98e3e1Schristos        Fields points to a NULL terminated list of pointers.
354e98e3e1Schristos 
364e98e3e1Schristos    Tab indented block:
374e98e3e1Schristos 
384e98e3e1Schristos      <tab> <text> <nl> { <tab> <text> <nl> }
394e98e3e1Schristos      type == table_code_entry
404e98e3e1Schristos 
414e98e3e1Schristos      The leading tab at the start of each line is discarded.
424e98e3e1Schristos      fields[i] is the i'th line with the <nl> discarded.
434e98e3e1Schristos 
444e98e3e1Schristos 
454e98e3e1Schristos    Code block:
464e98e3e1Schristos 
474e98e3e1Schristos      "{" <ignore-text> <nl> { <text> <nl> } "}" <ignore-text> <nl>
484e98e3e1Schristos      type == table_code_entry
494e98e3e1Schristos 
504e98e3e1Schristos      The leading/trailing {/} lines are discarded.
514e98e3e1Schristos      Lines containing two leading spaces have those spaces striped.
524e98e3e1Schristos      fields[i] is the i'th line with the <nl> discarded.
534e98e3e1Schristos 
544e98e3e1Schristos    In addition, the table parser reconises and handles internally the
554e98e3e1Schristos    following (when not in a code block):
564e98e3e1Schristos 
574e98e3e1Schristos      "#" <line-nr> '"' <file> '"'
584e98e3e1Schristos 
594e98e3e1Schristos      As per CPP/CC, treat following lines as if they were taken from
604e98e3e1Schristos      <file> starting at <line-nr>
614e98e3e1Schristos 
624e98e3e1Schristos    No support for CPP's "#if/#else/#endif" style conditions are
634e98e3e1Schristos    planned. */
644e98e3e1Schristos 
654e98e3e1Schristos typedef struct _table table;
664e98e3e1Schristos 
674e98e3e1Schristos typedef enum
684e98e3e1Schristos {
694e98e3e1Schristos   table_colon_entry,
704e98e3e1Schristos   table_code_entry,
714e98e3e1Schristos }
724e98e3e1Schristos table_entry_type;
734e98e3e1Schristos 
744e98e3e1Schristos 
754e98e3e1Schristos typedef struct _table_entry table_entry;
764e98e3e1Schristos struct _table_entry
774e98e3e1Schristos {
784e98e3e1Schristos   table *file;
794e98e3e1Schristos   line_ref *line;
804e98e3e1Schristos   table_entry_type type;
814e98e3e1Schristos   int nr_fields;
824e98e3e1Schristos   char **field;
834e98e3e1Schristos };
844e98e3e1Schristos 
854e98e3e1Schristos /* List of directories to search when opening a pushed file.  Current
864e98e3e1Schristos    directory is always searched first */
874e98e3e1Schristos typedef struct _table_include table_include;
884e98e3e1Schristos struct _table_include
894e98e3e1Schristos {
904e98e3e1Schristos   char *dir;
914e98e3e1Schristos   table_include *next;
924e98e3e1Schristos };
934e98e3e1Schristos 
944e98e3e1Schristos 
954e98e3e1Schristos /* Open/read a table file.  Since the file is read once during open
96b23b2582Schristos    (and then closed immediately) there is no close method. */
974e98e3e1Schristos 
984e98e3e1Schristos extern table *table_open (const char *file_name);
994e98e3e1Schristos 
1004e98e3e1Schristos extern table_entry *table_read (table *file);
1014e98e3e1Schristos 
1024e98e3e1Schristos 
1034e98e3e1Schristos /* Push the the state of the current file and open FILE_NAME.  When
1044e98e3e1Schristos    the end of FILE_NAME is reached, return to the pushed file */
1054e98e3e1Schristos 
1064e98e3e1Schristos extern void table_push
1074b169a6bSchristos   (table *file, const line_ref *line, table_include *search,
1084b169a6bSchristos    const char *file_name);
1094e98e3e1Schristos 
1104e98e3e1Schristos 
1114e98e3e1Schristos /* Expand the specified field_nr using the internal expansion table.
1124e98e3e1Schristos    A field is only expanded when explicitly specified.  */
1134e98e3e1Schristos 
1144e98e3e1Schristos extern void table_expand_field (table_entry *entry, int field_nr);
1154e98e3e1Schristos 
1164e98e3e1Schristos 
1174e98e3e1Schristos /* Given a code entry, write the code to FILE.  Since any
1184e98e3e1Schristos    leading/trailing braces were striped as part of the read, they are
1194e98e3e1Schristos    not written. */
1204e98e3e1Schristos 
1214b169a6bSchristos extern void table_print_code (lf *file, const table_entry *entry);
1224e98e3e1Schristos 
1234e98e3e1Schristos 
1244e98e3e1Schristos /* Debugging */
1254e98e3e1Schristos 
1264e98e3e1Schristos extern void dump_line_ref
1274b169a6bSchristos   (lf *file, const char *prefix, const line_ref *line, const char *suffix);
1284e98e3e1Schristos 
1294e98e3e1Schristos extern void dump_table_entry
1304b169a6bSchristos   (lf *file, const char *prefix, const table_entry *entry, const char *suffix);
1314e98e3e1Schristos 
1324e98e3e1Schristos 
1334e98e3e1Schristos 
1344e98e3e1Schristos /* Utilities for skipping around text */
1354e98e3e1Schristos 
1364e98e3e1Schristos extern char *skip_digits (char *chp);
1374e98e3e1Schristos 
1384e98e3e1Schristos extern char *skip_spaces (char *chp);
1394e98e3e1Schristos 
1404e98e3e1Schristos extern char *skip_to_separator (char *chp, char *separators);
1414e98e3e1Schristos 
1424e98e3e1Schristos extern char *back_spaces (char *start, char *chp);
143*71f62182Schristos 
144*71f62182Schristos #endif /* IGEN_TABLE_H */
145