GCC Middle and Back End API Reference
read-md.c File Reference

Data Structures

struct  ptr_loc
struct  file_name_list


static void handle_file (directive_handler_t)
hashval_t leading_string_hash ()
int leading_string_eq_p ()
static hashval_t leading_ptr_hash ()
static int leading_ptr_eq_p ()
static void set_md_ptr_loc ()
static struct ptr_locget_md_ptr_loc ()
void copy_md_ptr_loc ()
void fprint_md_ptr_loc ()
void print_md_ptr_loc ()
const char * join_c_conditions ()
void fprint_c_condition ()
void print_c_condition ()
static void ATTRIBUTE_PRINTF (2, 0)
void message_with_line ()
void error_with_line ()
void fatal_with_file_and_line ()
void fatal_expected_char ()
int read_skip_spaces ()
void read_name ()
static void read_escape ()
char * read_quoted_string ()
static char * read_braced_string ()
char * read_string ()
void read_skip_construct ()
int n_comma_elts ()
const char * scan_comma_elt ()
void upcase_string ()
static struct md_constantadd_constant (htab_t defs, char *name, char *value, struct enum_type *parent_enum)
static void handle_constants ()
void traverse_md_constants ()
static char * decimal_string ()
static void handle_enum ()
struct enum_typelookup_enum_type ()
void traverse_enum_types ()
static void handle_include ()
static void handle_file ()
static void handle_toplevel_file ()
static void parse_include ()
bool read_md_files (int argc, char **argv, bool(*parse_opt)(const char *), directive_handler_t handle_directive)


struct obstack string_obstack
static htab_t ptr_locs
static struct obstack ptr_loc_obstack
static htab_t joined_conditions
static struct obstack joined_conditions_obstack
FILE * read_md_file
const char * read_md_filename
int read_md_lineno
const char * in_fname
static char * base_dir
static struct file_name_listfirst_dir_md_include
static struct file_name_list ** last_dir_md_include_ptr = &first_dir_md_include
void(* include_callback )(const char *)
static size_t max_include_len
static htab_t md_constants
static htab_t enum_types

Function Documentation

static struct md_constant* add_constant ( htab_t  defs,
char *  name,
char *  value,
struct enum_type parent_enum 
   Add a NAME = VALUE definition to md_constants-style hash table DEFS,
   where both NAME and VALUE are malloc()ed strings.  PARENT_ENUM is the
   enum to which NAME belongs, or null if NAME is a stand-alone constant.  
static void ATTRIBUTE_PRINTF ( ,
   A vfprintf-like function for reporting an error against line LINENO
   of the current MD file.  
void copy_md_ptr_loc ( )
   Associate NEW_PTR with the same file position as OLD_PTR.  
static char* decimal_string ( )
   Return a malloc()ed decimal string that represents number NUMBER.  
     A safe overestimate.  +1 for sign, +1 for null terminator.  
void error_with_line ( )
   Like message_with_line, but treat the condition as an error.  

References unread_char().

Referenced by handle_constants(), lookup_enum_type(), n_occurrences(), nodes_identical_1(), process_template(), read_string(), traverse_md_constants(), and valid_predicate_name_p().

void fatal_expected_char ( )
   Report that we found character ACTUAL when we expected to find
   character EXPECTED.  

References fatal_with_file_and_line(), and unread_char().

Referenced by handle_constants(), and read_rtx_code().

void fatal_with_file_and_line ( )
   A printf-like function for reporting an error against the current
   position in the MD file.  
     Gather some following context.  

Referenced by fatal_expected_char().

void fprint_c_condition ( )
   Print condition COND to OUTF, wrapped in brackets.  If COND was created
   by join_c_conditions, recursively invoke this function for the original
   conditions and join the result with "&&".  Otherwise print a #line
   directive for COND if its original file position is known.  

References read_md_filename.

Referenced by join_c_conditions().

void fprint_md_ptr_loc ( )
   If PTR is associated with a known file position, print a #line
   directive for it to OUTF.  

Referenced by get_md_ptr_loc(), and join_c_conditions().

static struct ptr_loc* get_md_ptr_loc ( )
   Return the position associated with pointer PTR.  Return null if no
   position was set.  

References fprint_md_ptr_loc().

Referenced by set_md_ptr_loc().

static void handle_constants ( )
   Process a define_constants directive, starting with the optional space
   after the "define_constants".  
     Disable constant expansion during definition processing.  

References enum_types, error_with_line(), fatal_expected_char(), enum_type::md_p, enum_type::name, enum_type::num_values, read_skip_spaces(), read_string(), enum_type::tail_ptr, and enum_type::values.

static void handle_enum ( )
   Process a define_enum or define_c_enum directive, starting with
   the optional space after the "define_enum".  LINENO is the line
   number on which the directive started and MD_P is true if the
   directive is a define_enum rather than a define_c_enum.  
static void handle_file ( directive_handler_t  )
static void handle_file ( )
   Process the current file, assuming that read_md_file and
   read_md_filename are valid.  Use HANDLE_DIRECTIVE to handle
   unknown directives.  

References enum_types, joined_conditions, joined_conditions_obstack, leading_ptr_eq_p(), leading_ptr_hash(), leading_string_eq_p(), leading_string_hash(), md_constants, ptr_loc_obstack, ptr_locs, and string_obstack.

static void handle_include ( )
   Process an "include" directive, starting with the optional space
   after the "include".  Read in the file and use HANDLE_DIRECTIVE
   to process each unknown directive.  LINENO is the line number on
   which the "include" occurred.  
     If the specified file name is absolute, skip the include stack.  
         Search the directory path, trying to open the file.  
     If we haven't managed to open the file yet, try combining the
     filename with BASE_DIR.  
     Save the old cursor.  Note that the LINENO argument to this
     function is the beginning of the include statement, while
     read_md_lineno has already been advanced.  
     Restore the old cursor.  
     Do not free the pathname.  It is attached to the various rtx
     queue elements.  
static void handle_toplevel_file ( )
   Like handle_file, but for top-level files.  Set up in_fname and
   base_dir accordingly.  

References fatal(), and parse_include().

const char* join_c_conditions ( )
   Return a condition that satisfies both COND1 and COND2.  Either string
   may be null or empty.  

References fprint_c_condition(), fprint_md_ptr_loc(), and joined_conditions.

Referenced by add_current_iterators(), and alter_constraints().

static int leading_ptr_eq_p ( )
   Return true if DEF1 and DEF2 are pointers to the same pointer.  

References ptr_locs.

Referenced by handle_file().

static hashval_t leading_ptr_hash ( )
   Return a hash value for the pointer pointed to by DEF.  

Referenced by handle_file().

int leading_string_eq_p ( )
   Given two objects that start with char * name fields, return true if
   they have the same name.  

References ptr_loc_obstack.

Referenced by handle_file().

hashval_t leading_string_hash ( )
   Given an object that starts with a char * name field, return a hash
   code for its name.  

Referenced by handle_file().

struct enum_type* lookup_enum_type ( )
   Try to find the definition of the given enum.  Return null on failure.  

References error_with_line(), and free().

void message_with_line ( )
   A printf-like function for reporting an error against line LINENO
   in the current MD file.  

Referenced by gen_insn(), nodes_identical_1(), process_template(), and validate_exp().

int n_comma_elts ( )
   Given a string, return the number of comma-separated elements in it.
   Return 0 for the null string.  
static void parse_include ( )
   Parse a -I option with argument ARG.  

Referenced by handle_toplevel_file().

void print_c_condition ( )
   Special fprint_c_condition for writing to STDOUT.  

References have_error.

void print_md_ptr_loc ( )
   Special fprint_md_ptr_loc for writing to STDOUT.  
static char* read_braced_string ( )
   Read a braced string (a la Tcl) onto the string obstack.  Caller
   has scanned the leading brace.  Note that unlike quoted strings,
   the outermost braces _are_ included in the string constant.  
static void read_escape ( )
   Subroutine of the string readers.  Handles backslash escapes.
   Caller has read the backslash, but not placed it into the obstack.  
         Backslash-newline is replaced by nothing, as in C.  
         \" \' \\ are replaced by the second character.  
         Standard C string escapes:
         \a \b \f \n \r \t \v
         \[0-7] \x
         all are passed through to the output string unmolested.
         In normal use these wind up in a string constant processed
         by the C compiler, which will translate them appropriately.
         We do not bother checking that \[0-7] are followed by up to
         two octal digits, or that \x is followed by N hex digits.
         \? \u \U are left out because they are not in traditional C.  
         \; makes stuff for a C string constant containing
         newline and tab.  
         pass anything else through, but issue a warning.  
bool read_md_files ( int  argc,
char **  argv,
bool(*)(const char *)  parse_opt,
directive_handler_t  handle_directive 
   The main routine for reading .md files.  Try to process all the .md
   files specified on the command line and return true if no error occurred.

   ARGC and ARGV are the arguments to main.

   PARSE_OPT, if nonnull, is passed all unknown command-line arguments.
   It should return true if it recognizes the argument or false if a
   generic error should be reported.

   If HANDLE_DIRECTIVE is nonnull, the parser calls it for each
   unknown directive, otherwise it just skips such directives.
   See the comment above the directive_handler_t definition for
   details about the callback's interface.  
     Initialize global data.  
     Unlock the stdio streams.  
     First we loop over all the options.  
           An argument consisting of exactly one dash is a request to
           read stdin.  This will be handled in the second loop.  
           An argument consisting of just two dashes causes option
           parsing to cease.  
           The program may have provided a callback so it can
           accept its own options.  
     Now loop over all input files.  
                 Read stdin.  
                 No further arguments are to be treated as options.  
         If we get here we are looking at a non-option argument, i.e.
         a file to be processed.  
     If we get to this point without having seen any files to process,
     read the standard input now.  

Referenced by gen_mnemonic_attr(), and main().

void read_name ( )
   Read an rtx code name into NAME.  It is terminated by any of the
   punctuation chars of rtx printed syntax.  
         Do constant expansion.  

References md_constants, md_constant::name, md_name::string, and md_constant::value.

Referenced by traverse_md_constants().

char* read_quoted_string ( void  )
   Read a double-quoted string onto the obstack.  Caller has scanned
   the leading quote.  
void read_skip_construct ( )
   Skip the rest of a construct that started at line LINENO and that
   is currently nested by DEPTH levels of parentheses.  
int read_skip_spaces ( void  )
   Read chars from the MD file until a non-whitespace char and return that.
   Comments, both Lisp style and C style, are treated as whitespace.  

Referenced by handle_constants().

char* read_string ( )
   Read some kind of string constant.  This is the high-level routine
   used by read_rtx.  It handles surrounding parentheses, leading star,
   and dispatch to the appropriate string constant reader.  

References error_with_line().

Referenced by handle_constants().

const char* scan_comma_elt ( )
   Given a pointer to a (char *), return a pointer to the beginning of the
   next comma-separated element in the string.  Advance the pointer given
   to the end of that element.  Return NULL if at end of string.  Caller
   is responsible for copying the string if necessary.  White space between
   a comma and an element is ignored.  

Referenced by gen_attr(), gen_mnemonic_setattr(), and write_extract_subexp().

static void set_md_ptr_loc ( )
   Associate PTR with the file position given by FILENAME and LINENO.  

References ptr_loc::filename, get_md_ptr_loc(), and ptr_loc::lineno.

void traverse_enum_types ( )
   For every enum definition, call CALLBACK with two arguments:
   a pointer to the constant definition and INFO.  Stop when CALLBACK
   returns zero.  
void traverse_md_constants ( )
   For every constant definition, call CALLBACK with two arguments:
   a pointer a pointer to the constant definition and INFO.
   Stop when CALLBACK returns zero.  

References error_with_line(), read_name(), and unread_char().

void upcase_string ( )
   Convert STRING to uppercase.  

Variable Documentation

char* base_dir
   The directory part of IN_FNAME.  NULL if IN_FNAME is a bare filename.  
htab_t enum_types
   A table of enum_type structures, hashed by name.  

Referenced by handle_constants(), and handle_file().

struct file_name_list* first_dir_md_include
   The first directory to search.  
const char* in_fname
   The name of the toplevel file that indirectly included READ_MD_FILE.  

Referenced by write_insn_constraint_len().

void(* include_callback)(const char *)
   This callback will be invoked whenever an md include directive is
   processed.  To be used for creation of the dependency file.  

Referenced by main().

htab_t joined_conditions
   A hash table of triples (A, B, C), where each of A, B and C is a condition
   and A is equivalent to "B && C".  This is used to keep track of the source
   of conditions that are made up of separate MD strings (such as the split
   condition of a define_insn_and_split).  

Referenced by handle_file(), and join_c_conditions().

struct obstack joined_conditions_obstack
   An obstack for allocating joined_conditions entries.  

Referenced by handle_file().

struct file_name_list** last_dir_md_include_ptr = &first_dir_md_include
   A pointer to the null terminator of the md include chain.  
size_t max_include_len
   The current maximum length of directory names in the search path
   for include files.  (Altered as we get more of them.)  
htab_t md_constants
   A table of md_constant structures, hashed by name.  Null if no
   constant expansion should occur.  

Referenced by handle_file(), and read_name().

struct obstack ptr_loc_obstack
   An obstack for the above.  Plain xmalloc is a bit heavyweight for a
   small structure like ptr_loc.  

Referenced by handle_file(), and leading_string_eq_p().

htab_t ptr_locs
   A table of ptr_locs, hashed on the PTR field.  

Referenced by handle_file(), and leading_ptr_eq_p().

FILE* read_md_file
   The file we are reading.  
const char* read_md_filename
   The filename of READ_MD_FILE.  

Referenced by fprint_c_condition(), and main().

int read_md_lineno
   The current line number in READ_MD_FILE.  
struct obstack string_obstack
   Obstack used for allocating MD strings.  

Referenced by gen_mnemonic_setattr(), handle_file(), and process_define_subst().