GCC Middle and Back End API Reference
godump.cc File Reference
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "tree.h"
#include "diagnostic-core.h"
#include "debug.h"
#include "stor-layout.h"
#include "gt-godump.h"
Include dependency graph for godump.cc:

Data Structures

struct  godump_str_hash
 
struct  macro_hash_value
 
class  godump_container
 

Functions

static unsigned int precision_to_units (unsigned int precision)
 
static hashval_t macro_hash_hashval (const void *val)
 
static int macro_hash_eq (const void *v1, const void *v2)
 
static void macro_hash_del (void *v)
 
static void go_define (unsigned int lineno, const char *buffer)
 
static void go_undef (unsigned int lineno, const char *buffer)
 
static void go_decl (tree decl)
 
static void go_function_decl (tree decl)
 
static void go_early_global_decl (tree decl)
 
static void go_late_global_decl (tree decl)
 
static void go_type_decl (tree decl, int local)
 
static void go_append_string (struct obstack *ob, tree id)
 
static const char * go_get_uinttype_for_precision (unsigned int precision, bool is_unsigned)
 
static unsigned int go_append_artificial_name (struct obstack *ob, unsigned int index)
 
static void go_append_decl_name (struct obstack *ob, tree decl, htab_t keyword_hash)
 
static unsigned int go_append_padding (struct obstack *ob, unsigned int from_offset, unsigned int to_offset, unsigned int align_units, unsigned int index, unsigned int *ret_offset)
 
static unsigned int go_force_record_alignment (struct obstack *ob, const char *type_string, unsigned int index, const char *error_string)
 
static bool go_format_type (class godump_container *container, tree type, bool use_type_name, bool is_func_ok, unsigned int *p_art_i, bool is_anon_record_or_union)
 
static void go_output_type (class godump_container *container)
 
static void go_output_fndecl (class godump_container *container, tree decl)
 
static void go_output_typedef (class godump_container *container, tree decl)
 
static void go_output_var (class godump_container *container, tree decl)
 
static int go_print_macro (void **slot, void *arg)
 
static void keyword_hash_init (class godump_container *container)
 
bool find_dummy_types (const char *const &ptr, godump_container *adata)
 
static void go_finish (const char *filename)
 
const struct gcc_debug_hooksdump_go_spec_init (const char *filename, const struct gcc_debug_hooks *hooks)
 

Variables

static struct gcc_debug_hooks go_debug_hooks
 
static const struct gcc_debug_hooksreal_debug_hooks
 
static FILE * go_dump_file
 
static vec< tree, va_gc > * queue
 
static htab_t macro_hash
 
static const char *const keywords []
 

Function Documentation

◆ dump_go_spec_init()

◆ find_dummy_types()

bool find_dummy_types ( const char *const & ptr,
godump_container * adata )
Traversing the pot_dummy_types and seeing which types are present
in the global types hash table and creating dummy definitions if
not found.  This function is invoked by hash_set::traverse.   

References go_dump_file, and NULL.

Referenced by go_finish().

◆ go_append_artificial_name()

static unsigned int go_append_artificial_name ( struct obstack * ob,
unsigned int index )
static
Append an artificial variable name with the suffix _INDEX to OB.  Returns
INDEX + 1.   

Referenced by go_append_padding(), and go_format_type().

◆ go_append_decl_name()

static void go_append_decl_name ( struct obstack * ob,
tree decl,
htab_t keyword_hash )
static
Append the variable name from DECL to OB.  If the name is in the
KEYWORD_HASH, prepend an '_'.   

References DECL_NAME, go_append_string(), IDENTIFIER_POINTER, and NULL.

Referenced by go_format_type().

◆ go_append_padding()

static unsigned int go_append_padding ( struct obstack * ob,
unsigned int from_offset,
unsigned int to_offset,
unsigned int align_units,
unsigned int index,
unsigned int * ret_offset )
static
Appends a byte array with the necessary number of elements and the name
"Godump_INDEX_pad" to pad from FROM_OFFSET to TO_OFFSET to OB assuming that
the next field is automatically aligned to ALIGN_UNITS.  Returns INDEX + 1,
or INDEX if no padding had to be appended.  The resulting offset where the
next field is allocated is returned through RET_OFFSET.   

References gcc_assert, and go_append_artificial_name().

Referenced by go_format_type().

◆ go_append_string()

static void go_append_string ( struct obstack * ob,
tree id )
static
Append an IDENTIFIER_NODE to OB.   

References IDENTIFIER_LENGTH, and IDENTIFIER_POINTER.

Referenced by go_append_decl_name(), go_format_type(), and go_output_var().

◆ go_decl()

static void go_decl ( tree decl)
static
A function or variable decl.   

References DECL_IS_UNDECLARED_BUILTIN, DECL_NAME, NULL_TREE, queue, TREE_PUBLIC, and vec_safe_push().

Referenced by go_early_global_decl(), and go_function_decl().

◆ go_define()

static void go_define ( unsigned int lineno,
const char * buffer )
static

◆ go_early_global_decl()

static void go_early_global_decl ( tree decl)
static

◆ go_finish()

◆ go_force_record_alignment()

static unsigned int go_force_record_alignment ( struct obstack * ob,
const char * type_string,
unsigned int index,
const char * error_string )
static
Appends an array of type TYPE_STRING with zero elements and the name
"_" to OB.  If TYPE_STRING is a null pointer, ERROR_STRING is appended
instead of the type.  Returns INDEX + 1.   

References NULL.

Referenced by go_format_type().

◆ go_format_type()

static bool go_format_type ( class godump_container * container,
tree type,
bool use_type_name,
bool is_func_ok,
unsigned int * p_art_i,
bool is_anon_record_or_union )
static
Write the Go version of TYPE to CONTAINER->TYPE_OBSTACK.
USE_TYPE_NAME is true if we can simply use a type name here without
needing to define it.  IS_FUNC_OK is true if we can output a func
type here; the "func" keyword will already have been added.
Return true if the type can be represented in Go, false otherwise.
P_ART_I is used for indexing artificial elements in nested structures and
should always be a NULL pointer when called, except by certain recursive
calls from go_format_type() itself.   

References hash_set< KeyId, Lazy, Traits >::add(), AGGREGATE_TYPE_P, arg_type, DECL_ALIGN_UNIT, DECL_BIT_FIELD, DECL_FIELD_BIT_OFFSET, DECL_FIELD_OFFSET, DECL_IS_UNDECLARED_BUILTIN, DECL_NAME, DECL_P, DECL_SIZE_UNIT, FOREACH_FUNCTION_ARGS, gcc_fallthrough, go_append_artificial_name(), go_append_decl_name(), go_append_padding(), go_append_string(), go_force_record_alignment(), go_format_type(), go_get_uinttype_for_precision(), HOST_WIDE_INT_PRINT_DEC, IDENTIFIER_POINTER, godump_container::invalid_hash, godump_container::keyword_hash, layout_type(), NULL, NULL_TREE, obstack, POINTER_TYPE_P, godump_container::pot_dummy_types, precision_to_units(), prototype_p(), RECORD_OR_UNION_TYPE_P, stdarg_p(), TREE_CHAIN, TREE_CODE, tree_fits_shwi_p(), TREE_INT_CST_LOW, tree_int_cst_sgn(), tree_to_shwi(), TREE_TYPE, TYPE_ALIGN, TYPE_ALIGN_UNIT, TYPE_DOMAIN, TYPE_FIELDS, TYPE_IDENTIFIER, TYPE_MAX_VALUE, TYPE_MIN_VALUE, TYPE_NAME, godump_container::type_obstack, TYPE_PRECISION, TYPE_SIZE_UNIT, TYPE_UNSIGNED, and VOID_TYPE_P.

Referenced by go_format_type(), go_output_fndecl(), go_output_typedef(), and go_output_var().

◆ go_function_decl()

static void go_function_decl ( tree decl)
static
A function decl.   

References gcc_debug_hooks::function_decl, go_decl(), and real_debug_hooks.

Referenced by dump_go_spec_init().

◆ go_get_uinttype_for_precision()

static const char * go_get_uinttype_for_precision ( unsigned int precision,
bool is_unsigned )
static
Given an integer PRECISION in bits, returns a constant string that is the
matching go int or uint type (depending on the IS_UNSIGNED flag).  Returns a
NULL pointer if there is no matching go type.   

References NULL.

Referenced by go_format_type().

◆ go_late_global_decl()

static void go_late_global_decl ( tree decl)
static
A global variable decl.   

References gcc_debug_hooks::late_global_decl, and real_debug_hooks.

Referenced by dump_go_spec_init().

◆ go_output_fndecl()

static void go_output_fndecl ( class godump_container * container,
tree decl )
static
Output a function declaration.   

References DECL_ASSEMBLER_NAME, DECL_NAME, go_dump_file, go_format_type(), go_output_type(), IDENTIFIER_POINTER, NULL, and TREE_TYPE.

Referenced by go_finish().

◆ go_output_type()

static void go_output_type ( class godump_container * container)
static
Output the type which was built on the type obstack, and then free
it.   

References go_dump_file, obstack, and godump_container::type_obstack.

Referenced by go_output_fndecl(), go_output_typedef(), and go_output_var().

◆ go_output_typedef()

◆ go_output_var()

◆ go_print_macro()

static int go_print_macro ( void ** slot,
void * arg )
static
Output the final value of a preprocessor macro or enum constant.
This is called via htab_traverse_noresize.   

References go_dump_file, macro_hash_value::name, and macro_hash_value::value.

Referenced by go_finish().

◆ go_type_decl()

static void go_type_decl ( tree decl,
int local )
static

◆ go_undef()

static void go_undef ( unsigned int lineno,
const char * buffer )
static

◆ keyword_hash_init()

static void keyword_hash_init ( class godump_container * container)
static

◆ macro_hash_del()

static void macro_hash_del ( void * v)
static
Free values deleted from the macro hash table.   

References macro_hash_value::name, and macro_hash_value::value.

Referenced by dump_go_spec_init(), go_define(), and go_output_typedef().

◆ macro_hash_eq()

static int macro_hash_eq ( const void * v1,
const void * v2 )
static
Compare values in the macro hash table for equality.   

References macro_hash_value::name.

Referenced by dump_go_spec_init().

◆ macro_hash_hashval()

static hashval_t macro_hash_hashval ( const void * val)
static
Calculate the hash value for an entry in the macro hash table.   

References macro_hash_value::name.

Referenced by dump_go_spec_init().

◆ precision_to_units()

static unsigned int precision_to_units ( unsigned int precision)
inlinestatic
Returns the number of units necessary to represent an integer with the given
PRECISION (in bits).   

Referenced by go_format_type().

Variable Documentation

◆ go_debug_hooks

struct gcc_debug_hooks go_debug_hooks
static
Output Go language descriptions of types.
   Copyright (C) 2008-2024 Free Software Foundation, Inc.
   Written by Ian Lance Taylor <iant@google.com>.

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/>.   
This file is used during the build process to emit Go language
descriptions of declarations from C header files.  It uses the
debug info hooks to emit the descriptions.  The Go language
descriptions then become part of the Go runtime support
library.

All global names are output with a leading underscore, so that they
are all hidden in Go.   
We dump this information from the debug hooks.  This gives us a
stable and maintainable API to hook into.  In order to work
correctly when -g is used, we build our own hooks structure which
wraps the hooks we need to change.   
Our debug hooks.  This is initialized by dump_go_spec_init.   

Referenced by dump_go_spec_init().

◆ go_dump_file

FILE* go_dump_file
static

◆ keywords

const char* const keywords[]
static
Initial value:
= {
"__asm__", "break", "case", "chan", "const", "continue", "default",
"defer", "else", "fallthrough", "for", "func", "go", "goto", "if",
"import", "interface", "map", "package", "range", "return", "select",
"struct", "switch", "type", "var"
}
Build a hash table with the Go keywords.   

Referenced by keyword_hash_init().

◆ macro_hash

htab_t macro_hash
static
A hash table of macros we have seen.   

Referenced by dump_go_spec_init(), go_define(), go_finish(), go_output_typedef(), and go_undef().

◆ queue

◆ real_debug_hooks

const struct gcc_debug_hooks* real_debug_hooks
static