GCC Middle and Back End API Reference
gengtype-state.cc File Reference
#include "bconfig.h"
#include "system.h"
#include "errors.h"
#include "version.h"
#include "obstack.h"
#include "gengtype.h"
Include dependency graph for gengtype-state.cc:

Data Structures

struct  state_ident_st
 
struct  state_token_st
 
class  s_expr_writer
 
class  state_writer
 

Macros

#define NULL_STATE_TOKEN   (struct state_token_st*)0
 
#define fatal_reading_state_printf(Tok, Fmt, ...)
 

Enumerations

enum  state_token_en {
  STOK_NONE , STOK_INTEGER , STOK_STRING , STOK_LEFTPAR ,
  STOK_RIGHTPAR , STOK_NAME
}
 

Functions

static struct fileloctype_lineloc (const_type_p ty)
 
static void fatal_reading_state (struct state_token_st *tok, const char *msg)
 
static struct state_ident_ststate_ident_by_name (const char *name, enum insert_option optins)
 
static struct state_token_stread_a_state_token (void)
 
static struct state_token_stpeek_state_token (int depth)
 
static void next_state_tokens (int depth)
 
static enum state_token_en state_token_kind (struct state_token_st *p)
 
static bool state_token_is_name (struct state_token_st *p, const char *name)
 
static int pair_list_length (pair_p list)
 
static void write_state_trailer (void)
 
void write_state (const char *state_path)
 
static void read_state_fileloc (struct fileloc *line)
 
static void read_state_options (options_p *opt)
 
static void read_state_type (type_p *current)
 
static void read_state_pair (pair_p *pair)
 
static int read_state_pair_list (pair_p *list)
 
static void read_state_fields (pair_p *fields)
 
static void read_state_common_type_content (type_p current)
 
static void record_type (type_p type)
 
static void read_state_already_seen_type (type_p *type)
 
static void read_state_scalar_nonchar_type (type_p *type)
 
static void read_state_scalar_char_type (type_p *type)
 
static void read_state_string_type (type_p *type)
 
static void read_state_callback_type (type_p *type)
 
static void read_state_lang_bitmap (lang_bitmap *bitmap)
 
static void read_state_undefined_type (type_p type)
 
static void read_state_struct_type (type_p type)
 
static void read_state_user_struct_type (type_p type)
 
static void read_state_union_type (type_p type)
 
static void read_state_pointer_type (type_p type)
 
static void read_state_array_type (type_p type)
 
static void read_state_lang_struct_type (type_p type)
 
static void read_state_gc_used (enum gc_used_enum *pgus)
 
static void read_state_string_option (options_p opt)
 
static void read_state_type_option (options_p opt)
 
static void read_state_nested_option (options_p opt)
 
static void read_state_option (options_p *opt)
 
static void read_state_version (const char *ver_string)
 
static void read_state_typedefs (pair_p *typedefs)
 
static void read_state_structures (type_p *structures)
 
static void read_state_variables (pair_p *variables)
 
static void read_state_srcdir (void)
 
static void read_state_languages (void)
 
static void read_state_files_list (void)
 
static void read_state_trailer (void)
 
static unsigned hash_type_number (const void *ty)
 
static int equals_type_number (const void *ty1, const void *ty2)
 
void read_state (const char *path)
 

Variables

static htab_t state_ident_tab
 
struct state_token_ststate_token = NULL_STATE_TOKEN
 
static FILE * state_file
 
static const char * state_path = NULL
 
static int state_line = 0
 
static long state_bol = 0
 
static htab_t state_seen_types
 

Macro Definition Documentation

◆ fatal_reading_state_printf

#define fatal_reading_state_printf ( Tok,
Fmt,
... )
Value:
do { \
struct state_token_st* badtok = Tok; \
if (badtok) \
fatal ("%s:%d:%d: Invalid state file; " Fmt, \
badtok->stok_file, \
badtok->stok_line, \
badtok->stok_col, __VA_ARGS__); \
else \
fatal ("%s:%d: Invalid state file; " Fmt, \
state_path, state_line, __VA_ARGS__); \
} while (0)
static int state_line
Definition gengtype-state.cc:135
static const char * state_path
Definition gengtype-state.cc:134
Definition gengtype-state.cc:102
int stok_col
Definition gengtype-state.cc:107
int stok_line
Definition gengtype-state.cc:106
const char * stok_file
Definition gengtype-state.cc:108
Fatal printf-like message while reading state.  This can't be a
function, because there is no way to pass a va_arg to a variant of
fatal.   

Referenced by read_a_state_token(), read_state(), read_state_common_type_content(), read_state_fields(), read_state_pair(), read_state_structures(), read_state_typedefs(), read_state_variables(), and read_state_version().

◆ NULL_STATE_TOKEN

#define NULL_STATE_TOKEN   (struct state_token_st*)0

Enumeration Type Documentation

◆ state_token_en

The state file has simplistic lispy lexical tokens.  Its lexer gives
a linked list of struct state_token_st, through the peek_state_token
function.  Lexical tokens are consumed with next_state_tokens.   
The lexical kind of each lispy token.   
Enumerator
STOK_NONE 
STOK_INTEGER 
STOK_STRING 
STOK_LEFTPAR 
STOK_RIGHTPAR 
STOK_NAME 

Function Documentation

◆ equals_type_number()

static int equals_type_number ( const void * ty1,
const void * ty2 )
static

References type::state_number.

Referenced by read_state().

◆ fatal_reading_state()

◆ hash_type_number()

static unsigned hash_type_number ( const void * ty)
static
Utility functions for the state_seen_types hash table.   

References type::state_number, and ty.

Referenced by read_state().

◆ next_state_tokens()

◆ pair_list_length()

static int pair_list_length ( pair_p list)
static
Return the length of a linked list made of pairs.   
Compute the length of a list of pairs, starting from the first
one.   

References pair::next, and NULL.

Referenced by state_writer::write_state_fields(), state_writer::write_state_typedefs(), and state_writer::write_state_variables().

◆ peek_state_token()

◆ read_a_state_token()

static struct state_token_st * read_a_state_token ( void )
static
Our token lexer is heavily inspired by MELT's lexer, and share some
code with the file gcc/melt-runtime.c of the GCC MELT branch!  We
really want the gengtype state to be easily parsable by MELT.  This
is a usual lispy lexing routine, dealing with spaces and comments,
numbers, parenthesis, names, strings.   

References fatal_reading_state(), fatal_reading_state_printf, NULL, NULL_STATE_TOKEN, obstack, state_bol, state_file, state_ident_by_name(), state_line, state_path, state_token_st::stok_col, state_token_st::stok_file, state_token_st::stok_ident, STOK_INTEGER, state_token_st::stok_kind, STOK_LEFTPAR, state_token_st::stok_line, STOK_NAME, state_token_st::stok_next, state_token_st::stok_num, STOK_RIGHTPAR, STOK_STRING, state_token_st::stok_string, and state_token_st::stok_un.

Referenced by peek_state_token().

◆ read_state()

◆ read_state_already_seen_type()

◆ read_state_array_type()

◆ read_state_callback_type()

static void read_state_callback_type ( type_p * type)
static
Read the callback_type.   

References callback_type, and read_state_common_type_content().

Referenced by read_state_type().

◆ read_state_common_type_content()

◆ read_state_fields()

◆ read_state_fileloc()

void read_state_fileloc ( struct fileloc * floc)
static
End of writing routines!  The corresponding reading routines follow.  * 
Forward declarations, since some read_state_* functions are
recursive!  
Read a file location.  Files within the source directory are dealt
with specifically.   

References DIR_SEPARATOR, fatal_reading_state(), fileloc::file, free(), gcc_assert, input_file_by_name(), fileloc::line, next_state_tokens(), NULL, peek_state_token(), srcdir, state_token_is_name(), state_token_kind(), STOK_INTEGER, STOK_LEFTPAR, state_token_st::stok_num, STOK_RIGHTPAR, STOK_STRING, state_token_st::stok_string, and state_token_st::stok_un.

Referenced by read_state_lang_struct_type(), read_state_pair(), read_state_struct_type(), read_state_undefined_type(), read_state_union_type(), and read_state_user_struct_type().

◆ read_state_files_list()

◆ read_state_gc_used()

static void read_state_gc_used ( enum gc_used_enum * pgus)
static

◆ read_state_lang_bitmap()

static void read_state_lang_bitmap ( lang_bitmap * bitmap)
static

◆ read_state_lang_struct_type()

static void read_state_lang_struct_type ( type_p type)
static

◆ read_state_languages()

◆ read_state_nested_option()

◆ read_state_option()

◆ read_state_options()

◆ read_state_pair()

◆ read_state_pair_list()

int read_state_pair_list ( pair_p * list)
static

◆ read_state_pointer_type()

static void read_state_pointer_type ( type_p type)
static

◆ read_state_scalar_char_type()

static void read_state_scalar_char_type ( type_p * type)
static
Read the scalar_char type.   

References read_state_common_type_content(), and scalar_char.

Referenced by read_state_type().

◆ read_state_scalar_nonchar_type()

static void read_state_scalar_nonchar_type ( type_p * type)
static
Read the scalar_nonchar type.   

References read_state_common_type_content(), and scalar_nonchar.

Referenced by read_state_type().

◆ read_state_srcdir()

◆ read_state_string_option()

◆ read_state_string_type()

static void read_state_string_type ( type_p * type)
static
Read the string_type.   

References read_state_common_type_content(), and string_type.

Referenced by read_state_type().

◆ read_state_struct_type()

◆ read_state_structures()

◆ read_state_trailer()

static void read_state_trailer ( void )
static

◆ read_state_type()

◆ read_state_type_option()

static void read_state_type_option ( options_p opt)
static
Read a type option.   

References options::info, options::kind, OPTION_TYPE, read_state_type(), and options::type.

Referenced by read_state_option().

◆ read_state_typedefs()

◆ read_state_undefined_type()

◆ read_state_union_type()

◆ read_state_user_struct_type()

◆ read_state_variables()

◆ read_state_version()

static void read_state_version ( const char * ver_string)
static

◆ record_type()

static void record_type ( type_p type)
static
Record into the state_seen_types hash-table a type which we are
reading, to enable recursive or circular references to it.   

References gcc_assert, state_seen_types, and type().

Referenced by create_task_copyfn(), install_var_field(), lower_omp_task_reductions(), lower_send_shared_vars(), neuter_worker_single(), oacc_do_neutering(), read_state_common_type_content(), and worker_single_copy().

◆ state_ident_by_name()

static struct state_ident_st * state_ident_by_name ( const char * name,
enum insert_option optins )
static
Find or allocate an identifier in our name hash table.   

References NULL, state_ident_tab, and state_ident_st::stid_name.

Referenced by read_a_state_token().

◆ state_token_is_name()

◆ state_token_kind()

◆ type_lineloc()

static struct fileloc * type_lineloc ( const_type_p ty)
inlinestatic
Gengtype persistent state serialization & de-serialization.
  Useful for gengtype in plugin mode.

  Copyright (C) 2010-2024 Free Software Foundation, Inc.

  This file is part of GCC.

  GCC is free software; you can redistribute it and/or modify it under
  the terms of the GNU General Public License as published by the Free
  Software Foundation; either version 3, or (at your option) any later
  version.

  GCC is distributed in the hope that it will be useful, but WITHOUT ANY
  WARRANTY; without even the implied warranty of MERCHANTABILITY or
  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  for more details.

  You should have received a copy of the GNU General Public License
  along with GCC; see the file COPYING3.  If not see
  <http://www.gnu.org/licenses/>.

  Contributed by Jeremie Salvucci <jeremie.salvucci@free.fr>
  and Basile Starynkevitch <basile@starynkevitch.net>
Gives the file location of a type, if any.   

References CONST_CAST, gcc_unreachable, fileloc::line, NULL, ty, TYPE_ARRAY, TYPE_CALLBACK, TYPE_LANG_STRUCT, TYPE_NONE, TYPE_POINTER, TYPE_SCALAR, TYPE_STRING, TYPE_STRUCT, TYPE_UNDEFINED, TYPE_UNION, and TYPE_USER_STRUCT.

Referenced by state_writer::write_state_struct_union_type(), state_writer::write_state_undefined_type(), and state_writer::write_state_user_struct_type().

◆ write_state()

void write_state ( const char * state_path)
The write_state routine is the only writing routine called by main
in gengtype.cc.  To avoid messing the state if gengtype is
interrupted or aborted, we write a temporary file and rename it
after having written it in totality.   

◆ write_state_trailer()

static void write_state_trailer ( void )
static
Write the trailer.   

References errno, fatal(), and state_file.

Variable Documentation

◆ state_bol

long state_bol = 0
static

Referenced by read_a_state_token().

◆ state_file

◆ state_ident_tab

htab_t state_ident_tab
static

Referenced by read_state(), and state_ident_by_name().

◆ state_line

◆ state_path

const char* state_path = NULL
static

◆ state_seen_types

htab_t state_seen_types
static
Following routines are useful for serializing datas.
*
* We want to serialize :
*          - typedefs list
*          - structures list
*          - variables list
*
* So, we have one routine for each kind of data.  The main writing
* routine is write_state.  The main reading routine is
* read_state.  Most writing routines write_state_FOO have a
* corresponding reading routine read_state_FOO.  Reading is done in a
* recursive descending way, and any read error is fatal.
When reading the state, we need to remember the previously seen
types by their state_number, since GTY-ed types are usually
shared.   

Referenced by read_state(), read_state_already_seen_type(), and record_type().

◆ state_token

struct state_token_st* state_token = NULL_STATE_TOKEN
the state_token pointer contains the leftmost current token.  The
tokens are organized in a linked queue, using stok_next, for token
look-ahead.   

Referenced by next_state_tokens(), peek_state_token(), and read_state_pair().