id
int64
1
722k
file_path
stringlengths
8
177
funcs
stringlengths
1
35.8M
722,001
./hicuda/src/osprey/libdwarf/libdwarf/pro_funcs.c
/* * Copyright 2005, 2006 PathScale, Inc. All Rights Reserved. */ /* Copyright (C) 2000,2004 Silicon Graphics, Inc. All Rights Reserved. This program is free software; you can redistribute it and/or modify it under the terms of version 2.1 of the GNU Lesser General Public License as published by the Free Software Foundation. This program is distributed in the hope that it would be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Further, this software is distributed without any warranty that it is free of the rightful claim of any third person regarding infringement or the like. Any license provided herein, whether implied or otherwise, applies only to this software file. Patent licenses, if any, provided herein do not apply to combinations of this program with other software, or any other product whatsoever. You should have received a copy of the GNU Lesser General Public License along with this program; if not, write the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA. Contact information: Silicon Graphics, Inc., 1500 Crittenden Lane, Mountain View, CA 94043, or: http://www.sgi.com For further information regarding this notice, see: http://oss.sgi.com/projects/GenInfo/NoticeExplan */ #include "config.h" #include "libdwarfdefs.h" #include <stdio.h> #include <string.h> #ifdef HAVE_ELFACCESS_H #include <elfaccess.h> #endif #include "pro_incl.h" #include "pro_section.h" /* This function adds another function name to the list of function names for the given Dwarf_P_Debug. It returns 0 on error, and 1 otherwise. */ Dwarf_Unsigned dwarf_add_funcname(Dwarf_P_Debug dbg, Dwarf_P_Die die, char *function_name, Dwarf_Error * error) { return _dwarf_add_simple_name_entry(dbg, die, function_name, dwarf_snk_funcname, error); }
722,002
./hicuda/src/osprey/libdwarf/libdwarf/dwarf_types.c
/* * Copyright 2005, 2006 PathScale, Inc. All Rights Reserved. */ /* Copyright (C) 2000,2002,2004 Silicon Graphics, Inc. All Rights Reserved. This program is free software; you can redistribute it and/or modify it under the terms of version 2.1 of the GNU Lesser General Public License as published by the Free Software Foundation. This program is distributed in the hope that it would be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Further, this software is distributed without any warranty that it is free of the rightful claim of any third person regarding infringement or the like. Any license provided herein, whether implied or otherwise, applies only to this software file. Patent licenses, if any, provided herein do not apply to combinations of this program with other software, or any other product whatsoever. You should have received a copy of the GNU Lesser General Public License along with this program; if not, write the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA. Contact information: Silicon Graphics, Inc., 1500 Crittenden Lane, Mountain View, CA 94043, or: http://www.sgi.com For further information regarding this notice, see: http://oss.sgi.com/projects/GenInfo/NoticeExplan */ #include "config.h" #include "dwarf_incl.h" #include <stdio.h> #include "dwarf_types.h" #include "dwarf_global.h" int dwarf_get_types(Dwarf_Debug dbg, Dwarf_Type ** types, Dwarf_Signed * ret_type_count, Dwarf_Error * error) { int res; res = _dwarf_load_section(dbg, dbg->de_debug_typenames_index, &dbg->de_debug_typenames, error); if (res != DW_DLV_OK) { return res; } return _dwarf_internal_get_pubnames_like_data(dbg, dbg->de_debug_typenames, dbg->de_debug_typenames_size, (Dwarf_Global **) types, /* type punning, Dwarf_Type is never a completed type */ ret_type_count, error, DW_DLA_TYPENAME_CONTEXT, DW_DLE_DEBUG_TYPENAMES_LENGTH_BAD, DW_DLE_DEBUG_TYPENAMES_VERSION_ERROR); } int dwarf_typename(Dwarf_Type type_in, char **ret_name, Dwarf_Error * error) { Dwarf_Global type = (Dwarf_Global) type_in; if (type == NULL) { _dwarf_error(NULL, error, DW_DLE_TYPE_NULL); return (DW_DLV_ERROR); } *ret_name = (char *) (type->gl_name); return DW_DLV_OK; } int dwarf_type_die_offset(Dwarf_Type type_in, Dwarf_Off * ret_offset, Dwarf_Error * error) { Dwarf_Global type = (Dwarf_Global) type_in; return dwarf_global_die_offset(type, ret_offset, error); } int dwarf_type_cu_offset(Dwarf_Type type_in, Dwarf_Off * ret_offset, Dwarf_Error * error) { Dwarf_Global type = (Dwarf_Global) type_in; return dwarf_global_cu_offset(type, ret_offset, error); } int dwarf_type_name_offsets(Dwarf_Type type_in, char **returned_name, Dwarf_Off * die_offset, Dwarf_Off * cu_die_offset, Dwarf_Error * error) { Dwarf_Global type = (Dwarf_Global) type_in; return dwarf_global_name_offsets(type, returned_name, die_offset, cu_die_offset, error); }
722,003
./hicuda/src/osprey/libdwarf/libdwarf/pro_weaks.c
/* * Copyright 2005, 2006 PathScale, Inc. All Rights Reserved. */ /* Copyright (C) 2000,2004 Silicon Graphics, Inc. All Rights Reserved. This program is free software; you can redistribute it and/or modify it under the terms of version 2.1 of the GNU Lesser General Public License as published by the Free Software Foundation. This program is distributed in the hope that it would be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Further, this software is distributed without any warranty that it is free of the rightful claim of any third person regarding infringement or the like. Any license provided herein, whether implied or otherwise, applies only to this software file. Patent licenses, if any, provided herein do not apply to combinations of this program with other software, or any other product whatsoever. You should have received a copy of the GNU Lesser General Public License along with this program; if not, write the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA. Contact information: Silicon Graphics, Inc., 1500 Crittenden Lane, Mountain View, CA 94043, or: http://www.sgi.com For further information regarding this notice, see: http://oss.sgi.com/projects/GenInfo/NoticeExplan */ #include "config.h" #include "libdwarfdefs.h" #include <stdio.h> #include <string.h> #ifdef HAVE_ELFACCESS_H #include <elfaccess.h> #endif #include "pro_incl.h" #include "pro_section.h" /* This function adds another weak name to the list of weak names for the given Dwarf_P_Debug. It returns 0 on error, and 1 otherwise. */ Dwarf_Unsigned dwarf_add_weakname(Dwarf_P_Debug dbg, Dwarf_P_Die die, char *weak_name, Dwarf_Error * error) { return _dwarf_add_simple_name_entry(dbg, die, weak_name, dwarf_snk_weakname, error); }
722,004
./hicuda/src/osprey/libdwarf/libdwarf/dwarf_vars.c
/* * Copyright 2005, 2006 PathScale, Inc. All Rights Reserved. */ /* Copyright (C) 2000,2002,2004 Silicon Graphics, Inc. All Rights Reserved. This program is free software; you can redistribute it and/or modify it under the terms of version 2.1 of the GNU Lesser General Public License as published by the Free Software Foundation. This program is distributed in the hope that it would be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Further, this software is distributed without any warranty that it is free of the rightful claim of any third person regarding infringement or the like. Any license provided herein, whether implied or otherwise, applies only to this software file. Patent licenses, if any, provided herein do not apply to combinations of this program with other software, or any other product whatsoever. You should have received a copy of the GNU Lesser General Public License along with this program; if not, write the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA. Contact information: Silicon Graphics, Inc., 1500 Crittenden Lane, Mountain View, CA 94043, or: http://www.sgi.com For further information regarding this notice, see: http://oss.sgi.com/projects/GenInfo/NoticeExplan */ #include "config.h" #include "dwarf_incl.h" #include <stdio.h> #include "dwarf_vars.h" #include "dwarf_global.h" int dwarf_get_vars(Dwarf_Debug dbg, Dwarf_Var ** vars, Dwarf_Signed * ret_var_count, Dwarf_Error * error) { int res; res = _dwarf_load_section(dbg, dbg->de_debug_varnames_index, &dbg->de_debug_varnames, error); if (res != DW_DLV_OK) { return res; } return _dwarf_internal_get_pubnames_like_data(dbg, dbg->de_debug_varnames, dbg->de_debug_varnames_size, (Dwarf_Global **) vars, /* type punning, Dwarf_Type is never a completed type */ ret_var_count, error, DW_DLA_VAR_CONTEXT, DW_DLE_DEBUG_VARNAMES_LENGTH_BAD, DW_DLE_DEBUG_VARNAMES_VERSION_ERROR); } int dwarf_varname(Dwarf_Var var_in, char **ret_varname, Dwarf_Error * error) { Dwarf_Global var = (Dwarf_Global) var_in; if (var == NULL) { _dwarf_error(NULL, error, DW_DLE_VAR_NULL); return (DW_DLV_ERROR); } *ret_varname = (char *) (var->gl_name); return DW_DLV_OK; } int dwarf_var_die_offset(Dwarf_Var var_in, Dwarf_Off * returned_offset, Dwarf_Error * error) { Dwarf_Global var = (Dwarf_Global) var_in; return dwarf_global_die_offset(var, returned_offset, error); } int dwarf_var_cu_offset(Dwarf_Var var_in, Dwarf_Off * returned_offset, Dwarf_Error * error) { Dwarf_Global var = (Dwarf_Global) var_in; return dwarf_global_cu_offset(var, returned_offset, error); } int dwarf_var_name_offsets(Dwarf_Var var_in, char **returned_name, Dwarf_Off * die_offset, Dwarf_Off * cu_offset, Dwarf_Error * error) { Dwarf_Global var = (Dwarf_Global) var_in; return dwarf_global_name_offsets(var, returned_name, die_offset, cu_offset, error); }
722,005
./hicuda/src/osprey/libdwarf/libdwarf/pro_vars.c
/* * Copyright 2005, 2006 PathScale, Inc. All Rights Reserved. */ /* Copyright (C) 2000,2004 Silicon Graphics, Inc. All Rights Reserved. This program is free software; you can redistribute it and/or modify it under the terms of version 2.1 of the GNU Lesser General Public License as published by the Free Software Foundation. This program is distributed in the hope that it would be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Further, this software is distributed without any warranty that it is free of the rightful claim of any third person regarding infringement or the like. Any license provided herein, whether implied or otherwise, applies only to this software file. Patent licenses, if any, provided herein do not apply to combinations of this program with other software, or any other product whatsoever. You should have received a copy of the GNU Lesser General Public License along with this program; if not, write the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA. Contact information: Silicon Graphics, Inc., 1500 Crittenden Lane, Mountain View, CA 94043, or: http://www.sgi.com For further information regarding this notice, see: http://oss.sgi.com/projects/GenInfo/NoticeExplan */ #include "config.h" #include "libdwarfdefs.h" #include <stdio.h> #include <string.h> #ifdef HAVE_ELFACCESS_H #include <elfaccess.h> #endif #include "pro_incl.h" #include "pro_section.h" /* This function adds another variable name to the list of variable names for the given Dwarf_P_Debug. It returns 0 on error, and 1 otherwise. */ Dwarf_Unsigned dwarf_add_varname(Dwarf_P_Debug dbg, Dwarf_P_Die die, char *var_name, Dwarf_Error * error) { return _dwarf_add_simple_name_entry(dbg, die, var_name, dwarf_snk_varname, error); }
722,006
./hicuda/src/osprey/libdwarf/libdwarf/dwarf_alloc.c
/* * Copyright 2005, 2006 PathScale, Inc. All Rights Reserved. */ /* Copyright (C) 2000,2002,2004 Silicon Graphics, Inc. All Rights Reserved. This program is free software; you can redistribute it and/or modify it under the terms of version 2.1 of the GNU Lesser General Public License as published by the Free Software Foundation. This program is distributed in the hope that it would be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Further, this software is distributed without any warranty that it is free of the rightful claim of any third person regarding infringement or the like. Any license provided herein, whether implied or otherwise, applies only to this software file. Patent licenses, if any, provided herein do not apply to combinations of this program with other software, or any other product whatsoever. You should have received a copy of the GNU Lesser General Public License along with this program; if not, write the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA. Contact information: Silicon Graphics, Inc., 1500 Crittenden Lane, Mountain View, CA 94043, or: http://www.sgi.com For further information regarding this notice, see: http://oss.sgi.com/projects/GenInfo/NoticeExplan */ #include "config.h" #include "dwarf_incl.h" #include <sys/types.h> #include <stdlib.h> #include <stdio.h> #include <malloc.h> /* These files are included to get the sizes of structs to set the ah_bytes_one_struct field of the Dwarf_Alloc_Hdr_s structs for each allocation type. */ #include "dwarf_line.h" #include "dwarf_global.h" #include "dwarf_arange.h" #include "dwarf_abbrev.h" #include "dwarf_die_deliv.h" #include "dwarf_frame.h" #include "dwarf_loc.h" #include "dwarf_funcs.h" #include "dwarf_types.h" #include "dwarf_vars.h" #include "dwarf_weaks.h" static void _dwarf_free_special_error(Dwarf_Ptr space); #ifdef DWARF_SIMPLE_MALLOC static void _dwarf_simple_malloc_add_to_list(Dwarf_Debug dbg, Dwarf_Ptr addr, unsigned long size, short alloc_type); static void _dwarf_simple_malloc_delete_from_list(Dwarf_Debug dbg, Dwarf_Ptr space, short alloc_type); void _dwarf_simple_malloc_botch(int err); #endif /* DWARF_SIMPLE_MALLOC */ /* This macro adds the size of a pointer to the size of a struct that is given to it. It rounds up the size to be a multiple of the size of a pointer. This is done so that every struct returned by _dwarf_get_alloc() can be preceded by a pointer to the chunk it came from. Before, it checks if the size of struct is less than the size of a pointer. If yes, it returns the size of 2 pointers. The returned size should be at least the size of 2 pointers, since the first points to the chunk the struct was allocated from, and the second is used to link the free list. If this is n32, we want the sizes to be 64-bit aligned so that longlong in the structure we return to user is aligned properly. Thus the _dw_fac of 2 Only long longs need to be properly aligned: we don't have long double and don't align for that. */ #if _MIPS_SIM == _MIPS_SIM_NABI32 #define _DW_FAC 2 #define _DW_PS sizeof(void *) #else #define _DW_FAC 1 #define _DW_PS sizeof(void *) #endif #define _DW_RESERVE (_DW_FAC * _DW_PS) /* Round size up to the next multiple of _DW_RESERVE bytes */ #define ROUND_SIZE(inputsize) \ (((inputsize) % (_DW_RESERVE)) == 0 ? \ (inputsize): \ ((inputsize) + \ (_DW_RESERVE) - ((inputsize) % (_DW_RESERVE)) )) #define ROUND_SIZE_WITH_POINTER(i_size) (ROUND_SIZE(i_size) + _DW_RESERVE) #define BASE_ALLOC 64 #define BIG_ALLOC 128 /* This translates into de_alloc_hdr index ** the 0,1,1 entries are special: they don't use the ** table values at all. ** Rearranging the DW_DLA values would break binary compatibility ** so that is not an option. */ struct ial_s { int ia_al_num; /* Index into de_alloc_hdr table. */ /* In bytes, one struct instance. This does not account for extra space needed per block, but that (_DW_RESERVE) will be added in later where it is needed (_DW_RESERVE space never added in here). */ int ia_struct_size; /* Number of instances per alloc block. MUST be > 0. */ int ia_base_count; }; static const struct ial_s index_into_allocated[ALLOC_AREA_INDEX_TABLE_MAX] = { {0, 1, 1}, /* none */ {0, 1, 1,}, /* 1 DW_DLA_STRING */ {1, sizeof(Dwarf_Loc), BASE_ALLOC} , /* 2 DW_DLA_LOC */ {2, sizeof(Dwarf_Locdesc), BASE_ALLOC} , /* 3 DW_DLA_LOCDESC */ {0, 1, 1} , /* not used *//* 4 DW_DLA_ELLIST */ {0, 1, 1} , /* not used *//* 5 DW_DLA_BOUNDS */ {3, sizeof(Dwarf_Block), BASE_ALLOC} , /* 6 DW_DLA_BLOCK */ {0, 1, 1} , /* the actual dwarf_debug structure *//* 7 DW_DLA_DEBUG */ {4, sizeof(struct Dwarf_Die_s), BIG_ALLOC}, /* 8 DW_DLA_DIE */ {5, sizeof(struct Dwarf_Line_s), BIG_ALLOC}, /* 9 DW_DLA_LINE */ {6, sizeof(struct Dwarf_Attribute_s), BIG_ALLOC * 2}, /* 10 DW_DLA_ATTR */ {0, 1, 1}, /* not used *//* 11 DW_DLA_TYPE */ {0, 1, 1}, /* not used *//* 12 DW_DLA_SUBSCR */ {7, sizeof(struct Dwarf_Global_s), BIG_ALLOC}, /* 13 DW_DLA_GLOBAL */ {8, sizeof(struct Dwarf_Error_s), BASE_ALLOC}, /* 14 DW_DLA_ERROR */ {0, 1, 1}, /* 15 DW_DLA_LIST */ {0, 1, 1}, /* not used *//* 16 DW_DLA_LINEBUF */ {9, sizeof(struct Dwarf_Arange_s), BASE_ALLOC}, /* 17 DW_DLA_ARANGE */ {10, sizeof(struct Dwarf_Abbrev_s), BIG_ALLOC}, /* 18 DW_DLA_ABBREV */ {11, sizeof(Dwarf_Frame_Op), BIG_ALLOC} , /* 19 DW_DLA_FRAME_OP */ {12, sizeof(struct Dwarf_Cie_s), BASE_ALLOC}, /* 20 DW_DLA_CIE */ {13, sizeof(struct Dwarf_Fde_s), BASE_ALLOC}, /* 21 DW_DLA_FDE */ {0, 1, 1}, /* 22 DW_DLA_LOC_BLOCK */ {0, 1, 1}, /* 23 DW_DLA_FRAME_BLOCK */ {14, sizeof(struct Dwarf_Global_s), BIG_ALLOC}, /* 24 DW_DLA_FUNC */ {15, sizeof(struct Dwarf_Global_s), BIG_ALLOC}, /* 25 DW_DLA_TYPENAME */ {16, sizeof(struct Dwarf_Global_s), BIG_ALLOC}, /* 26 DW_DLA_VAR */ {17, sizeof(struct Dwarf_Global_s), BASE_ALLOC}, /* 27 DW_DLA_WEAK */ {0, 1, 1}, /* 28 DW_DLA_ADDR */ {18, sizeof(struct Dwarf_Abbrev_List_s), BIG_ALLOC}, /* 29 DW_DLA_ABBREV_LIST */ {19, sizeof(struct Dwarf_Chain_s), BIG_ALLOC}, /* 30 DW_DLA_CHAIN */ {20, sizeof(struct Dwarf_CU_Context_s), BASE_ALLOC}, /* 31 DW_DLA_CU_CONTEXT */ {21, sizeof(struct Dwarf_Frame_s), BASE_ALLOC}, /* 32 DW_DLA_FRAME */ {22, sizeof(struct Dwarf_Global_Context_s), BASE_ALLOC}, /* 33 DW_DLA_GLOBAL_CONTEXT */ {23, sizeof(struct Dwarf_File_Entry_s), BASE_ALLOC}, /* 34 DW_DLA_FILE_ENTRY */ {24, sizeof(struct Dwarf_Line_Context_s), BASE_ALLOC}, /* 35 DW_DLA_LINE_CONTEXT */ {25, sizeof(struct Dwarf_Loc_Chain_s), BASE_ALLOC}, /* 36 DW_DLA_LOC_CHAIN */ {26, ABBREV_HASH_TABLE_SIZE * 2 * sizeof(Dwarf_Abbrev_List), BASE_ALLOC} , /* 37 DW_DLA_HASH_TABLE */ /* The following really use Global struct: used to be unique struct per type, but now merged (11/99). The opaque types are visible in the interface. The types are left in existence, with unchanged numbers. */ {27, sizeof(struct Dwarf_Global_Context_s), BASE_ALLOC}, /* 38 DW_DLA_FUNC_CONTEXT */ {28, sizeof(struct Dwarf_Global_Context_s), BASE_ALLOC}, /* 39 DW_DLA_TYPENAME_CONTEXT */ {29, sizeof(struct Dwarf_Global_Context_s), BASE_ALLOC}, /* 40 DW_DLA_VAR_CONTEXT */ {30, sizeof(struct Dwarf_Global_Context_s), BASE_ALLOC}, /* 41 DW_DLA_WEAK_CONTEXT */ }; #ifndef DWARF_SIMPLE_MALLOC /* This function is given a pointer to the header structure that is used to allocate 1 struct of the type given by alloc_type. It first checks if a struct is available in its free list. If not, it checks if 1 is available in its blob, which is a chunk of memory that is reserved for its use. If not, it malloc's a chunk. The initial part of it is used to store the end address of the chunk, and also to keep track of the number of free structs in that chunk. This information is used for freeing the chunk when all the structs in it are free. Assume all input arguments have been validated. This function can be used only to allocate 1 struct of the given type. It returns a pointer to the struct that the user can use. It returns NULL only when it is out of free structs, and cannot malloc any more. The struct returned is zero-ed. A pointer to the chunk that the struct belongs to is stored in the bytes preceding the returned address. Since this pointer it never overwritten, when a struct is allocated from the free_list this pointer does not have to be written. In the 2 other cases, where the struct is allocated from a new chunk, or the blob, a pointer to the chunk is written. */ static Dwarf_Ptr _dwarf_find_memory(Dwarf_Alloc_Hdr alloc_hdr) { /* Pointer to the struct allocated. */ Dwarf_Small *ret_mem = 0; /* Pointer to info about chunks allocated. */ Dwarf_Alloc_Area alloc_area; /* Size of chunk malloc'ed when no free structs left. */ Dwarf_Signed mem_block_size; /* Pointer to block malloc'ed. */ Dwarf_Small *mem_block; /* Check the alloc_area from which the last allocation was made (most recent new block). If that is not successful, then search the list of alloc_area's from alloc_header. */ alloc_area = alloc_hdr->ah_last_alloc_area; if (alloc_area == NULL || alloc_area->aa_free_structs_in_chunk == 0) for (alloc_area = alloc_hdr->ah_alloc_area_head; alloc_area != NULL; alloc_area = alloc_area->aa_next) { if (alloc_area->aa_free_structs_in_chunk > 0) { break; /* found a free entry! */ } } if (alloc_area != NULL) { alloc_area->aa_free_structs_in_chunk--; if (alloc_area->aa_free_list != NULL) { ret_mem = alloc_area->aa_free_list; /* Update the free list. The initial part of the struct is used to hold a pointer to the next struct on the free list. In this way, the free list chain is maintained at 0 memory cost. */ alloc_area->aa_free_list = ((Dwarf_Free_List) ret_mem)->fl_next; } else if (alloc_area->aa_blob_start < alloc_area->aa_blob_end) { ret_mem = alloc_area->aa_blob_start; /* Store pointer to chunk this struct belongs to in the first few bytes. Return pointer to bytes after this pointer storage. */ *(Dwarf_Alloc_Area *) ret_mem = alloc_area; ret_mem += _DW_RESERVE; alloc_area->aa_blob_start += alloc_hdr->ah_bytes_one_struct; } else { /* else fall thru , though it should be impossible to fall thru. And represents a disastrous programming error if we get here. */ #ifdef DEBUG fprintf(stderr, "libdwarf Internal error start %x end %x\n", (int) alloc_area->aa_blob_start, (int) alloc_area->aa_blob_end); #endif } } /* New memory has to malloc'ed since there are no free structs. */ if (ret_mem == 0) { Dwarf_Word rounded_area_hdr_size; alloc_hdr->ah_chunks_allocated++; { /* this nonsense avoids a warning */ /* CONSTCOND would be better */ unsigned long v = sizeof(struct Dwarf_Alloc_Area_s); rounded_area_hdr_size = ROUND_SIZE(v); } /* Allocate memory to contain the required number of structs and the Dwarf_Alloc_Area_s to control it. */ mem_block_size = alloc_hdr->ah_bytes_malloc_per_chunk + rounded_area_hdr_size; mem_block = malloc(mem_block_size); if (mem_block == NULL) { return (NULL); } /* Attach the Dwarf_Alloc_Area_s struct to the list of chunks malloc'ed for this struct type. Also initialize the fields of the Dwarf_Alloc_Area_s. */ alloc_area = (Dwarf_Alloc_Area) mem_block; alloc_area->aa_prev = 0; if (alloc_hdr->ah_alloc_area_head != NULL) { alloc_hdr->ah_alloc_area_head->aa_prev = alloc_area; } alloc_area->aa_free_list = 0; alloc_area->aa_next = alloc_hdr->ah_alloc_area_head; alloc_hdr->ah_alloc_area_head = alloc_area; alloc_area->aa_alloc_hdr = alloc_hdr; alloc_area->aa_free_structs_in_chunk = (Dwarf_Sword) alloc_hdr->ah_structs_per_chunk - 1; if (alloc_area->aa_free_structs_in_chunk < 1) { /* If we get here, there is a disastrous programming error somewhere. */ #ifdef DEBUG fprintf(stderr, "libdwarf Internal error: free structs in chunk %d\n", (int) alloc_area->aa_free_structs_in_chunk); #endif return NULL; } /* The struct returned begins immediately after the Dwarf_Alloc_Area_s struct. */ ret_mem = mem_block + rounded_area_hdr_size; alloc_area->aa_blob_start = ret_mem + alloc_hdr->ah_bytes_one_struct; alloc_area->aa_blob_end = mem_block + mem_block_size; /* Store pointer to chunk this struct belongs to in the first few bytes. Return pointer to bytes after this pointer storage. */ *(Dwarf_Alloc_Area *) ret_mem = alloc_area; ret_mem += _DW_RESERVE; } alloc_hdr->ah_last_alloc_area = alloc_area; alloc_hdr->ah_struct_user_holds++; memset(ret_mem,0, alloc_hdr->ah_bytes_one_struct - _DW_RESERVE); return (ret_mem); } #endif /* ndef DWARF_SIMPLE_MALLOC */ /* This function returns a pointer to a region of memory. For alloc_types that are not strings or lists of pointers, only 1 struct can be requested at a time. This is indicated by an input count of 1. For strings, count equals the length of the string it will contain, i.e it the length of the string plus 1 for the terminating null. For lists of pointers, count is equal to the number of pointers. For DW_DLA_FRAME_BLOCK, and DW_DLA_LOC_BLOCK allocation types also, count is the count of the number of structs needed. This function cannot be used to allocate a Dwarf_Debug_s struct. */ Dwarf_Ptr _dwarf_get_alloc(Dwarf_Debug dbg, Dwarf_Small alloc_type, Dwarf_Unsigned count) { Dwarf_Alloc_Hdr alloc_hdr; Dwarf_Ptr ret_mem; Dwarf_Signed size = 0; unsigned int index; unsigned int type = alloc_type; if (dbg == NULL) { return (NULL); } if (type >= ALLOC_AREA_INDEX_TABLE_MAX) { /* internal error */ return NULL; } index = index_into_allocated[type].ia_al_num; /* zero also illegal but not tested for */ /* If the Dwarf_Debug is not fully set up, we will get index 0 for any type and must do something. 'Not fully set up' can only happen for DW_DLA_ERROR, I (davea) believe, and for that we call special code here.. */ if (index == 0) { if (alloc_type == DW_DLA_STRING) { size = count; } else if (alloc_type == DW_DLA_LIST) { size = count * sizeof(Dwarf_Ptr); } else if (alloc_type == DW_DLA_FRAME_BLOCK) { size = count * sizeof(Dwarf_Frame_Op); } else if (alloc_type == DW_DLA_LOC_BLOCK) { size = count * sizeof(Dwarf_Loc); } else if (alloc_type == DW_DLA_ADDR) { size = count * (sizeof(Dwarf_Addr) > sizeof(Dwarf_Off) ? sizeof(Dwarf_Addr) : sizeof(Dwarf_Off)); } else if (alloc_type == DW_DLA_ERROR) { return _dwarf_special_no_dbg_error_malloc(); } else { /* If we get here, there is a disastrous programming error somewhere. */ #ifdef DEBUG fprintf(stderr, "libdwarf Internal error: type %d unexpected\n", (int) type); #endif } } else { alloc_hdr = &dbg->de_alloc_hdr[index]; if (alloc_hdr->ah_bytes_one_struct > 0) { #ifdef DWARF_SIMPLE_MALLOC size = alloc_hdr->ah_bytes_one_struct; #else return (_dwarf_find_memory(alloc_hdr)); #endif } else { /* Special case: should not really happen at all. */ if (type == DW_DLA_ERROR) { /* dwarf_init failure. Because dbg is incomplete we won't use it to record the malloc. */ return _dwarf_special_no_dbg_error_malloc(); } else { /* If we get here, there is a disastrous programming error somewhere. */ #ifdef DWARF_SIMPLE_MALLOC _dwarf_simple_malloc_botch(3); #endif #ifdef DEBUG fprintf(stderr, "libdwarf Internal error: Type %d unexpected\n", (int) type); #endif } } } ret_mem = malloc(size); #ifdef DWARF_SIMPLE_MALLOC _dwarf_simple_malloc_add_to_list(dbg,ret_mem,(unsigned long)size, alloc_type); #endif if (ret_mem != NULL) memset(ret_mem,0, size); return (ret_mem); } /* This function is used to deallocate a region of memory that was obtained by a call to _dwarf_get_alloc. Note that though dwarf_dealloc() is a public function, _dwarf_get_alloc() isn't. For lists, typically arrays of pointers, it is assumed that the space was allocated by a direct call to malloc, and so a straight free() is done. This is also the case for variable length blocks such as DW_DLA_FRAME_BLOCK and DW_DLA_LOC_BLOCK. For strings, the pointer might point to a string in .debug_info or .debug_string. After this is checked, and if found not to be the case, a free() is done, again on the assumption that a malloc was used to obtain the space. For other types of structs, a pointer to the chunk that the struct was allocated out of, is present in the bytes preceding the pointer passed in. For this chunk it is checked whether all the structs in that chunk are now free. If so, the entire chunk is free_ed. Otherwise, the space is added to the free list for that chunk, and the free count incremented. This function does not return anything. */ void dwarf_dealloc(Dwarf_Debug dbg, Dwarf_Ptr space, Dwarf_Unsigned alloc_type) { Dwarf_Alloc_Hdr alloc_hdr; Dwarf_Alloc_Area alloc_area; unsigned int type = alloc_type; unsigned int index; if (space == NULL) { return; } if (alloc_type == DW_DLA_ERROR) { /* Get pointer to Dwarf_Alloc_Area this struct came from. See dwarf_alloc.h ROUND_SIZE_WITH_POINTER stuff */ alloc_area = *(Dwarf_Alloc_Area *) ((char *) space - _DW_RESERVE); if (alloc_area == 0) { /* This is the special case of a failed dwarf_init(). Also (and more signficantly) there are a variety of other situations where libdwarf does not *know* what dbg is involved (because of a libdwarf-caller-error) so libdwarf uses NULL as the dbg. Those too wind up here. */ _dwarf_free_special_error(space); return; } } if (dbg == NULL) { /* App error, or an app that failed to succeed in a dwarf_init() call. */ return; } if (type >= ALLOC_AREA_INDEX_TABLE_MAX) { /* internal or user app error */ return; } index = index_into_allocated[alloc_type].ia_al_num; /* A string pointer may point into .debug_info or .debug_string. Otherwise, they are directly malloc'ed. */ if (index == 0) { if (alloc_type == DW_DLA_STRING) { if ((Dwarf_Small *) space >= dbg->de_debug_info && (Dwarf_Small *) space < dbg->de_debug_info + dbg->de_debug_info_size) return; if (dbg->de_debug_line != NULL && (Dwarf_Small *) space >= dbg->de_debug_line && (Dwarf_Small *) space < dbg->de_debug_line + dbg->de_debug_line_size) return; if (dbg->de_debug_pubnames != NULL && (Dwarf_Small *) space >= dbg->de_debug_pubnames && (Dwarf_Small *) space < dbg->de_debug_pubnames + dbg->de_debug_pubnames_size) return; if (dbg->de_debug_frame != NULL && (Dwarf_Small *) space >= dbg->de_debug_frame && (Dwarf_Small *) space < dbg->de_debug_frame + dbg->de_debug_frame_size) return; if (dbg->de_debug_str != NULL && (Dwarf_Small *) space >= dbg->de_debug_str && (Dwarf_Small *) space < dbg->de_debug_str + dbg->de_debug_str_size) return; if (dbg->de_debug_funcnames != NULL && (Dwarf_Small *) space >= dbg->de_debug_funcnames && (Dwarf_Small *) space < dbg->de_debug_funcnames + dbg->de_debug_funcnames_size) return; if (dbg->de_debug_typenames != NULL && (Dwarf_Small *) space >= dbg->de_debug_typenames && (Dwarf_Small *) space < dbg->de_debug_typenames + dbg->de_debug_typenames_size) return; if (dbg->de_debug_varnames != NULL && (Dwarf_Small *) space >= dbg->de_debug_varnames && (Dwarf_Small *) space < dbg->de_debug_varnames + dbg->de_debug_varnames_size) return; if (dbg->de_debug_weaknames != NULL && (Dwarf_Small *) space >= dbg->de_debug_weaknames && (Dwarf_Small *) space < dbg->de_debug_weaknames + dbg->de_debug_weaknames_size) return; free(space); return; } if (alloc_type == DW_DLA_LIST || alloc_type == DW_DLA_FRAME_BLOCK || alloc_type == DW_DLA_LOC_BLOCK || alloc_type == DW_DLA_ADDR) { free(space); return; } /* else is an alloc type that is not used */ /* app or internal error */ #ifdef DWARF_SIMPLE_MALLOC _dwarf_simple_malloc_botch(4); #endif return; } #ifdef DWARF_SIMPLE_MALLOC _dwarf_simple_malloc_delete_from_list(dbg, space, alloc_type); free(space); #else /* !DWARF_SIMPLE_MALLOC */ alloc_hdr = &dbg->de_alloc_hdr[index]; /* Get pointer to Dwarf_Alloc_Area this struct came from. See dwarf_alloc.h ROUND_SIZE_WITH_POINTER stuff */ alloc_area = *(Dwarf_Alloc_Area *) ((char *) space - _DW_RESERVE); /* ASSERT: alloc_area != NULL If NULL we could abort, let it coredump below, or return, pretending all is well. We go on, letting program crash. Is caller error. */ /* Check that the alloc_hdr field of the alloc_area we have is pointing to the right alloc_hdr. This is used to catch use of incorrect deallocation code by the user. */ if (alloc_area->aa_alloc_hdr != alloc_hdr) { /* If we get here, the user has called dwarf_dealloc wrongly or there is some other disastrous error. By leaking mem here we try to be safe... */ #ifdef DEBUG fprintf(stderr, "libdwarf Internal error: type %d hdr mismatch %x %x area ptr %x\n", (int) alloc_type, (int) alloc_area->aa_alloc_hdr, (int) alloc_hdr, (int) alloc_area); #endif return; } alloc_hdr->ah_struct_user_holds--; alloc_area->aa_free_structs_in_chunk++; /* Give chunk back to malloc only when every struct is freed */ if (alloc_area->aa_free_structs_in_chunk == alloc_hdr->ah_structs_per_chunk) { if (alloc_area->aa_prev != NULL) { alloc_area->aa_prev->aa_next = alloc_area->aa_next; } else { alloc_hdr->ah_alloc_area_head = alloc_area->aa_next; } if (alloc_area->aa_next != NULL) { alloc_area->aa_next->aa_prev = alloc_area->aa_prev; } alloc_hdr->ah_chunks_allocated--; if (alloc_area == alloc_hdr->ah_last_alloc_area) { alloc_hdr->ah_last_alloc_area = NULL; } memset(alloc_area,0, sizeof(*alloc_area)); free(alloc_area); } else { ((Dwarf_Free_List) space)->fl_next = alloc_area->aa_free_list; alloc_area->aa_free_list = space; } #endif /* !DWARF_SIMPLE_MALLOC */ } /* Allocates space for a Dwarf_Debug_s struct, since one does not exist. */ Dwarf_Debug _dwarf_get_debug(void ) { Dwarf_Debug dbg; dbg = (Dwarf_Debug) malloc(sizeof(struct Dwarf_Debug_s)); if (dbg == NULL) return (NULL); else memset(dbg,0, sizeof(struct Dwarf_Debug_s)); return (dbg); } /* Sets up the Dwarf_Debug_s struct for all the allocation types currently defined. Allocation types DW_DLA_STRING, DW_DLA_LIST, DW_DLA_FRAME_BLOCK, DW_DLA_LOC_BLOCK are malloc'ed directly. This routine should be called after _dwarf_setup(), so that information about the sizes of the Dwarf sections can be used to decide the number of structs of each type malloc'ed. Also DW_DLA_ELLIST, DW_DLA_BOUNDS, DW_DLA_TYPE, DW_DLA_SUBSCR, DW_DLA_LINEBUF allocation types are currently not used. The ah_bytes_one_struct and ah_structs_per_chunk fields for these types have been set to 1 for efficiency in dwarf_get_alloc(). Ah_alloc_num should be greater than 1 for all types that are currently being used. Therefore, for these allocation types the ah_bytes_one_struct, and ah_structs_per_chunk fields do not need to be initialized. Being an internal routine, assume proper dbg. */ /* ** Set up all the Dwarf_Alloc_Hdr records. */ Dwarf_Debug _dwarf_setup_debug(Dwarf_Debug dbg) { int i; for (i = 1; i <= MAX_DW_DLA; i++) { const struct ial_s *ialp = &index_into_allocated[i]; unsigned int hdr_index = ialp->ia_al_num; Dwarf_Word str_size = ialp->ia_struct_size; Dwarf_Word str_count = ialp->ia_base_count; Dwarf_Word rnded_size = ROUND_SIZE_WITH_POINTER(str_size); Dwarf_Alloc_Hdr alloc_hdr = &dbg->de_alloc_hdr[hdr_index]; alloc_hdr->ah_bytes_one_struct = (Dwarf_Half) rnded_size; /* ah_structs_per_chunk must be >0 else we are in trouble */ alloc_hdr->ah_structs_per_chunk = str_count; alloc_hdr->ah_bytes_malloc_per_chunk = rnded_size * str_count; } return (dbg); } /* This function prints out the statistics collected on allocation of memory chunks. */ void dwarf_print_memory_stats(Dwarf_Debug dbg) { Dwarf_Alloc_Hdr alloc_hdr; Dwarf_Shalf i; /* Alloc types start at 1, not 0. Hence, the first NULL string, and also a size of MAX_DW_DLA + 1. */ char *alloc_type_name[MAX_DW_DLA + 1] = { "", "DW_DLA_STRING", "DW_DLA_LOC", "DW_DLA_LOCDESC", "DW_DLA_ELLIST", "DW_DLA_BOUNDS", "DW_DLA_BLOCK", "DW_DLA_DEBUG", "DW_DLA_DIE", "DW_DLA_LINE", "DW_DLA_ATTR", "DW_DLA_TYPE", "DW_DLA_SUBSCR", "DW_DLA_GLOBAL", "DW_DLA_ERROR", "DW_DLA_LIST", "DW_DLA_LINEBUF", "DW_DLA_ARANGE", "DW_DLA_ABBREV", "DW_DLA_FRAME_OP", "DW_DLA_CIE", "DW_DLA_FDE", "DW_DLA_LOC_BLOCK", "DW_DLA_FRAME_BLOCK", "DW_DLA_FUNC", "DW_DLA_TYPENAME", "DW_DLA_VAR", "DW_DLA_WEAK", "DW_DLA_ADDR", "DW_DLA_ABBREV_LIST", "DW_DLA_CHAIN", "DW_DLA_CU_CONTEXT", "DW_DLA_FRAME", "DW_DLA_GLOBAL_CONTEXT", "DW_DLA_FILE_ENTRY", "DW_DLA_LINE_CONTEXT", "DW_DLA_LOC_CHAIN", "DW_DLA_HASH_TABLE", "DW_DLA_FUNC_CONTEXT", "DW_DLA_TYPENAME_CONTEXT", "DW_DLA_VAR_CONTEXT", "DW_DLA_WEAK_CONTEXT" }; if (dbg == NULL) return; printf("Size of Dwarf_Debug %4ld bytes\n", (long) sizeof(*dbg)); printf("Size of Dwarf_Alloc_Hdr_s %4ld bytes\n", (long) sizeof(struct Dwarf_Alloc_Hdr_s)); printf("size of Dwarf_Alloc_Area_s %4ld bytes\n", (long) sizeof(struct Dwarf_Alloc_Area_s)); printf(" Alloc Type Curr Structs byt str\n"); printf(" ---------- ---- ------- per per\n"); for (i = 1; i <= MAX_DW_DLA; i++) { int indx = index_into_allocated[i].ia_al_num; alloc_hdr = &dbg->de_alloc_hdr[indx]; if (alloc_hdr->ah_bytes_one_struct != 1) { printf("%2d %-25s %6d %8d %6d %6d\n", (int) i, alloc_type_name[i], (int) alloc_hdr->ah_chunks_allocated, (int) alloc_hdr->ah_struct_user_holds, (int) alloc_hdr->ah_bytes_malloc_per_chunk, (int) alloc_hdr->ah_structs_per_chunk); } } } #ifndef DWARF_SIMPLE_MALLOC /* This function is used to recursively free the chunks still allocated, and forward chained through the aa_next pointer. */ static void _dwarf_recursive_free(Dwarf_Alloc_Area alloc_area) { if (alloc_area->aa_next != NULL) { _dwarf_recursive_free(alloc_area->aa_next); } alloc_area->aa_next = 0; alloc_area->aa_prev = 0; free(alloc_area); } #endif /* Used to free all space allocated for this Dwarf_Debug. The caller should assume that the Dwarf_Debug pointer itself is no longer valid upon return from this function. In case of difficulty, this function simply returns quietly. */ int _dwarf_free_all_of_one_debug(Dwarf_Debug dbg) { Dwarf_Alloc_Hdr alloc_hdr; Dwarf_Shalf i; if (dbg == NULL) return (DW_DLV_ERROR); #ifdef DWARF_SIMPLE_MALLOC if(dbg->de_simple_malloc_base) { struct simple_malloc_record_s *smp = dbg->de_simple_malloc_base; while( smp) { int i; struct simple_malloc_record_s *prev_smp = 0; for(i = 0; i < smp->sr_used; ++i) { struct simple_malloc_entry_s *cur; cur = &smp->sr_entry[i]; if(cur->se_addr != 0) { free(cur->se_addr); cur->se_addr = 0; } } prev_smp = smp; smp = smp->sr_next; free(prev_smp); } dbg->de_simple_malloc_base = 0; dbg->de_simple_malloc_current = 0; } #else for (i = 1; i < ALLOC_AREA_REAL_TABLE_MAX; i++) { int indx = i; alloc_hdr = &dbg->de_alloc_hdr[indx]; if (alloc_hdr->ah_alloc_area_head != NULL) { _dwarf_recursive_free(alloc_hdr->ah_alloc_area_head); } } #endif memset(dbg,0, sizeof(*dbg)); /* prevent accidental use later */ free(dbg); return (DW_DLV_OK); } /* A special case: we have no dbg, no alloc header etc. So create something out of thin air that we can recognize in dwarf_dealloc. Something with the prefix (prefix space hidden from caller). Only applies to DW_DLA_ERROR, making up an error record. */ struct Dwarf_Error_s * _dwarf_special_no_dbg_error_malloc(void) { /* the union unused things are to guarantee proper alignment */ union u { Dwarf_Alloc_Area ptr_not_used; struct Dwarf_Error_s base_not_used; char data_space[sizeof(struct Dwarf_Error_s) + (_DW_RESERVE * 2)]; }; char *mem; mem = malloc(sizeof(union u)); if (mem == 0) { return 0; } memset(mem,0, sizeof(union u)); mem += _DW_RESERVE; return (struct Dwarf_Error_s *) mem; } /* The free side of _dwarf_special_no_dbg_error_malloc() */ static void _dwarf_free_special_error(Dwarf_Ptr space) { char *mem = (char *) space; mem -= _DW_RESERVE; free(mem); } #ifdef DWARF_SIMPLE_MALLOC /* here solely for planting a breakpoint. */ /* ARGSUSED */ void _dwarf_simple_malloc_botch(int err) { } static void _dwarf_simple_malloc_add_to_list(Dwarf_Debug dbg, Dwarf_Ptr addr, unsigned long size, short alloc_type) { struct simple_malloc_record_s *cur; struct simple_malloc_entry_s *newentry; if (!dbg->de_simple_malloc_current) { /* First entry to this routine. */ dbg->de_simple_malloc_current = malloc(sizeof(struct simple_malloc_record_s)); if(!dbg->de_simple_malloc_current) { return; /* no memory, give up */ } memset(dbg->de_simple_malloc_current, 0, sizeof(struct simple_malloc_record_s)); dbg->de_simple_malloc_base = dbg->de_simple_malloc_current; } cur = dbg->de_simple_malloc_current; if(cur->sr_used >= DSM_BLOCK_COUNT) { /* better not be > than as that means chaos */ /* Create a new block to link at the head. */ struct simple_malloc_record_s *newblock = malloc(sizeof(struct simple_malloc_record_s)); if(!newblock) { return; /* Can do nothing, out of memory */ } memset(newblock,0, sizeof(struct simple_malloc_record_s)); /* Link the new block at the head of the chain, and make it 'current' */ dbg->de_simple_malloc_current = newblock; newblock->sr_next = cur; cur = newblock; } newentry = &cur->sr_entry[cur->sr_used]; newentry->se_addr = addr; newentry->se_size = size; newentry->se_type = alloc_type; ++cur->sr_used; } /* DWARF_SIMPLE_MALLOC is for testing the hypothesis that the existing complex malloc scheme in libdwarf is pointless complexity. DWARF_SIMPLE_MALLOC also makes it easy for a malloc-tracing tool to verify libdwarf malloc has no botches (though of course such does not test the complicated standard-libdwarf-alloc code). To properly answer the question, the simple-malloc allocate and delete should be something other than a simple list. Perhaps a heap, or perhaps a red-black tree. */ static void _dwarf_simple_malloc_delete_from_list(Dwarf_Debug dbg, Dwarf_Ptr space, short alloc_type) { if(space == 0) { _dwarf_simple_malloc_botch(6); } if(dbg->de_simple_malloc_base) { struct simple_malloc_record_s *smp = dbg->de_simple_malloc_base; while( smp) { int i; for(i = 0; i < smp->sr_used; ++i) { struct simple_malloc_entry_s *cur; cur = &smp->sr_entry[i]; if(cur->se_addr == space) { if(cur->se_type != alloc_type ) { _dwarf_simple_malloc_botch(0); } cur->se_addr = 0; return; } } smp = smp->sr_next; } } /* Never found the space */ _dwarf_simple_malloc_botch(1); return; } #endif
722,007
./hicuda/src/osprey/libdwarf/libdwarf/pro_line.c
/* * Copyright 2005, 2006 PathScale, Inc. All Rights Reserved. */ /* Copyright (C) 2000,2004 Silicon Graphics, Inc. All Rights Reserved. This program is free software; you can redistribute it and/or modify it under the terms of version 2.1 of the GNU Lesser General Public License as published by the Free Software Foundation. This program is distributed in the hope that it would be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Further, this software is distributed without any warranty that it is free of the rightful claim of any third person regarding infringement or the like. Any license provided herein, whether implied or otherwise, applies only to this software file. Patent licenses, if any, provided herein do not apply to combinations of this program with other software, or any other product whatsoever. You should have received a copy of the GNU Lesser General Public License along with this program; if not, write the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA. Contact information: Silicon Graphics, Inc., 1500 Crittenden Lane, Mountain View, CA 94043, or: http://www.sgi.com For further information regarding this notice, see: http://oss.sgi.com/projects/GenInfo/NoticeExplan */ #include "config.h" #include "libdwarfdefs.h" #include <stdio.h> #include <string.h> #ifdef HAVE_ELF_H #include <elf.h> #endif #include "pro_incl.h" #include "pro_line.h" Dwarf_Unsigned _dwarf_pro_add_line_entry(Dwarf_P_Debug, Dwarf_Unsigned file_index, Dwarf_Addr code_address, Dwarf_Unsigned symidx, Dwarf_Unsigned line_no, Dwarf_Signed col_no, Dwarf_Bool is_stmt_begin, Dwarf_Bool is_bb_begin, Dwarf_Ubyte opc, Dwarf_Error * error); /*------------------------------------------------------------------------- Add a entry to the line information section file_index: index of file in file entries, obtained from add_file_entry() call. This function actually calls _dwarf_pro_add_line_entry(), with an extra parameter, the opcode. Done so that interface calls dwarf_lne_set_address() and dwarf_lne_end_sequence() can use this internal routine. ---------------------------------------------------------------------------*/ Dwarf_Unsigned dwarf_add_line_entry(Dwarf_P_Debug dbg, Dwarf_Unsigned file_index, Dwarf_Addr code_address, Dwarf_Unsigned line_no, Dwarf_Signed col_no, Dwarf_Bool is_stmt_begin, Dwarf_Bool is_bb_begin, Dwarf_Error * error) { Dwarf_Unsigned retval; retval = _dwarf_pro_add_line_entry(dbg, file_index, code_address, 0, line_no, col_no, is_stmt_begin, is_bb_begin, 0, error); return retval; } /*------------------------------------------------------------------------ Ask to emit DW_LNE_set_address opcode explicitly. Used by be to emit start of a new .text section, or to force a relocated address into debug line information entry. -------------------------------------------------------------------------*/ Dwarf_Unsigned dwarf_lne_set_address(Dwarf_P_Debug dbg, Dwarf_Addr offs, Dwarf_Unsigned symidx, Dwarf_Error * error) { Dwarf_Ubyte opc; Dwarf_Unsigned retval; opc = DW_LNE_set_address; retval = _dwarf_pro_add_line_entry(dbg, 0, offs, symidx, 0, 0, 0, 0, opc, error); return retval; } /*------------------------------------------------------------------------ Ask to emit end_seqence opcode. Used normally at the end of a compilation unit. Can also be used in the middle if there are gaps in the region described by the code address. -------------------------------------------------------------------------*/ Dwarf_Unsigned dwarf_lne_end_sequence(Dwarf_P_Debug dbg, Dwarf_Addr end_address, Dwarf_Error * error) { Dwarf_Ubyte opc; Dwarf_Unsigned retval; opc = DW_LNE_end_sequence; retval = _dwarf_pro_add_line_entry(dbg, 0, end_address, 0, 0, 0, 0, 0, opc, error); return retval; } /*---------------------------------------------------------------------------- Add an entry in the internal list of lines mantained by producer. Opc indicates if an opcode needs to be generated, rather than just an entry in the matrix. During opcodes generation time, these opcodes will be used. -----------------------------------------------------------------------------*/ Dwarf_Unsigned _dwarf_pro_add_line_entry(Dwarf_P_Debug dbg, Dwarf_Unsigned file_index, Dwarf_Addr code_address, Dwarf_Unsigned symidx, Dwarf_Unsigned line_no, Dwarf_Signed col_no, Dwarf_Bool is_stmt_begin, Dwarf_Bool is_bb_begin, Dwarf_Ubyte opc, Dwarf_Error * error) { if (dbg->de_lines == NULL) { dbg->de_lines = (Dwarf_P_Line) _dwarf_p_get_alloc(dbg, sizeof(struct Dwarf_P_Line_s)); if (dbg->de_lines == NULL) { DWARF_P_DBG_ERROR(dbg, DW_DLE_LINE_ALLOC, DW_DLV_NOCOUNT); } dbg->de_last_line = dbg->de_lines; _dwarf_pro_reg_init(dbg->de_lines); } else { dbg->de_last_line->dpl_next = (Dwarf_P_Line) _dwarf_p_get_alloc(dbg, sizeof(struct Dwarf_P_Line_s)); if (dbg->de_last_line->dpl_next == NULL) { DWARF_P_DBG_ERROR(dbg, DW_DLE_LINE_ALLOC, DW_DLV_NOCOUNT); } dbg->de_last_line = dbg->de_last_line->dpl_next; _dwarf_pro_reg_init(dbg->de_last_line); } dbg->de_last_line->dpl_address = code_address; dbg->de_last_line->dpl_file = (unsigned long) file_index; dbg->de_last_line->dpl_line = (unsigned long) line_no; dbg->de_last_line->dpl_column = (unsigned long) col_no; dbg->de_last_line->dpl_is_stmt = is_stmt_begin; dbg->de_last_line->dpl_basic_block = is_bb_begin; dbg->de_last_line->dpl_opc = opc; dbg->de_last_line->dpl_r_symidx = symidx; return (0); } /*----------------------------------------------------------------------- Add a directory declaration to the debug_line section. Stored in linked list. ------------------------------------------------------------------------*/ Dwarf_Unsigned dwarf_add_directory_decl(Dwarf_P_Debug dbg, char *name, Dwarf_Error * error) { if (dbg->de_inc_dirs == NULL) { dbg->de_inc_dirs = (Dwarf_P_Inc_Dir) _dwarf_p_get_alloc(dbg, sizeof(struct Dwarf_P_Inc_Dir_s)); if (dbg->de_inc_dirs == NULL) { DWARF_P_DBG_ERROR(dbg, DW_DLE_INCDIR_ALLOC, DW_DLV_NOCOUNT); } dbg->de_last_inc_dir = dbg->de_inc_dirs; dbg->de_n_inc_dirs = 1; } else { dbg->de_last_inc_dir->did_next = (Dwarf_P_Inc_Dir) _dwarf_p_get_alloc(dbg, sizeof(struct Dwarf_P_Inc_Dir_s)); if (dbg->de_last_inc_dir->did_next == NULL) { DWARF_P_DBG_ERROR(dbg, DW_DLE_INCDIR_ALLOC, DW_DLV_NOCOUNT); } dbg->de_last_inc_dir = dbg->de_last_inc_dir->did_next; dbg->de_n_inc_dirs++; } dbg->de_last_inc_dir->did_name = (char *) _dwarf_p_get_alloc(dbg, strlen(name) + 1); if (dbg->de_last_inc_dir->did_name == NULL) { DWARF_P_DBG_ERROR(dbg, DW_DLE_STRING_ALLOC, DW_DLV_NOCOUNT); } strcpy(dbg->de_last_inc_dir->did_name, name); dbg->de_last_inc_dir->did_next = NULL; return dbg->de_n_inc_dirs; } /*----------------------------------------------------------------------- Add a file entry declaration to the debug_line section. Stored in linked list. The data is immediately encodes as leb128 and stored in Dwarf_P_F_Entry_s struct. ------------------------------------------------------------------------*/ Dwarf_Unsigned dwarf_add_file_decl(Dwarf_P_Debug dbg, char *name, Dwarf_Unsigned dir_idx, Dwarf_Unsigned time_mod, Dwarf_Unsigned length, Dwarf_Error * error) { Dwarf_P_F_Entry cur; char *ptr; int nbytes_idx, nbytes_time, nbytes_len; char buffidx[ENCODE_SPACE_NEEDED]; char bufftime[ENCODE_SPACE_NEEDED]; char bufflen[ENCODE_SPACE_NEEDED]; int res; if (dbg->de_file_entries == NULL) { dbg->de_file_entries = (Dwarf_P_F_Entry) _dwarf_p_get_alloc(dbg, sizeof(struct Dwarf_P_F_Entry_s)); if (dbg->de_file_entries == NULL) { DWARF_P_DBG_ERROR(dbg, DW_DLE_FILE_ENTRY_ALLOC, DW_DLV_NOCOUNT); } cur = dbg->de_file_entries; dbg->de_last_file_entry = cur; dbg->de_n_file_entries = 1; } else { cur = dbg->de_last_file_entry; cur->dfe_next = (Dwarf_P_F_Entry) _dwarf_p_get_alloc(dbg, sizeof(struct Dwarf_P_F_Entry_s)); if (cur->dfe_next == NULL) { DWARF_P_DBG_ERROR(dbg, DW_DLE_FILE_ENTRY_ALLOC, DW_DLV_NOCOUNT); } cur = cur->dfe_next; dbg->de_last_file_entry = cur; dbg->de_n_file_entries++; } cur->dfe_name = (char *) _dwarf_p_get_alloc(dbg, strlen(name) + 1); if (cur->dfe_name == NULL) { DWARF_P_DBG_ERROR(dbg, DW_DLE_ALLOC_FAIL, DW_DLV_NOCOUNT); } strcpy((char *) cur->dfe_name, name); res = _dwarf_pro_encode_leb128_nm(dir_idx, &nbytes_idx, buffidx, sizeof(buffidx)); if (res != DW_DLV_OK) { DWARF_P_DBG_ERROR(dbg, DW_DLE_ALLOC_FAIL, DW_DLV_NOCOUNT); } res = _dwarf_pro_encode_leb128_nm(time_mod, &nbytes_time, bufftime, sizeof(bufftime)); if (res != DW_DLV_OK) { DWARF_P_DBG_ERROR(dbg, DW_DLE_ALLOC_FAIL, DW_DLV_NOCOUNT); } res = _dwarf_pro_encode_leb128_nm(length, &nbytes_len, bufflen, sizeof(bufflen)); cur->dfe_args = (char *) _dwarf_p_get_alloc(dbg, nbytes_idx + nbytes_time + nbytes_len); if (cur->dfe_args == NULL) { DWARF_P_DBG_ERROR(dbg, DW_DLE_ALLOC_FAIL, DW_DLV_NOCOUNT); } ptr = cur->dfe_args; memcpy((void *) ptr, buffidx, nbytes_idx); ptr += nbytes_idx; memcpy((void *) ptr, bufftime, nbytes_time); ptr += nbytes_time; memcpy((void *) ptr, bufflen, nbytes_len); ptr += nbytes_len; cur->dfe_nbytes = nbytes_idx + nbytes_time + nbytes_len; cur->dfe_next = NULL; return dbg->de_n_file_entries; } /*--------------------------------------------------------------------- Initialize a row of the matrix for line numbers, meaning initialize the struct corresponding to it ----------------------------------------------------------------------*/ void _dwarf_pro_reg_init(Dwarf_P_Line cur_line) { cur_line->dpl_address = 0; cur_line->dpl_file = 1; cur_line->dpl_line = 1; cur_line->dpl_column = 0; cur_line->dpl_is_stmt = DEFAULT_IS_STMT; cur_line->dpl_basic_block = false; cur_line->dpl_next = NULL; }
722,008
./hicuda/src/osprey/libdwarf/libdwarf/dwarf_frame.c
/* * Copyright 2004, 2005, 2006 PathScale, Inc. All Rights Reserved. */ /* Copyright (C) 2000,2002,2004 Silicon Graphics, Inc. All Rights Reserved. This program is free software; you can redistribute it and/or modify it under the terms of version 2.1 of the GNU Lesser General Public License as published by the Free Software Foundation. This program is distributed in the hope that it would be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Further, this software is distributed without any warranty that it is free of the rightful claim of any third person regarding infringement or the like. Any license provided herein, whether implied or otherwise, applies only to this software file. Patent licenses, if any, provided herein do not apply to combinations of this program with other software, or any other product whatsoever. You should have received a copy of the GNU Lesser General Public License along with this program; if not, write the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA. Contact information: Silicon Graphics, Inc., 1500 Crittenden Lane, Mountain View, CA 94043, or: http://www.sgi.com For further information regarding this notice, see: http://oss.sgi.com/projects/GenInfo/NoticeExplan */ #include "config.h" #include "dwarf_incl.h" #include <stdio.h> #include <stdlib.h> #include "dwarf_frame.h" #include "dwarf_arange.h" /* using Arange as a way to build a list */ static int __dwarf_get_fde_list_internal(Dwarf_Debug dbg, Dwarf_Cie ** cie_data, Dwarf_Signed * cie_element_count, Dwarf_Fde ** fde_data, Dwarf_Signed * fde_element_count, Dwarf_Small * section_ptr, Dwarf_Unsigned section_length, Dwarf_Unsigned section_index, Dwarf_Unsigned cie_id_value, int use_gnu_cie_calc, Dwarf_Error * error); /* This function is the heart of the debug_frame stuff. Don't even think of reading this without reading both the Libdwarf and consumer API carefully first. This function basically executes frame instructions contained in a Cie or an Fde, but does in a number of different ways depending on the information sought. Start_instr_ptr points to the first byte of the frame instruction stream, and final_instr_ptr to the to the first byte after the last. The offsets returned in the frame instructions are factored. That is they need to be multiplied by either the code_alignment_factor or the data_alignment_factor, as appropriate to obtain the actual offset. This makes it possible to expand an instruction stream without the corresponding Cie. However, when an Fde frame instr sequence is being expanded there must be a valid Cie with a pointer to an initial table row. If successful, returns DW_DLV_OK And sets returned_count thru the pointer if make_instr is true. If make_instr is false returned_count should NOT be used by the caller (returned_count is set to 0 thru the pointer by this routine...) If unsuccessful, returns DW_DLV_ERROR and sets returned_error to the error code It does not do a whole lot of input validation being a private function. Please make sure inputs are valid. (1) If make_instr is true, it makes a list of pointers to Dwarf_Frame_Op structures containing the frame instructions executed. A pointer to this list is returned in ret_frame_instr. Make_instr is true only when a list of frame instructions is to be returned. In this case since we are not interested in the contents of the table, the input Cie can be NULL. This is the only case where the inpute Cie can be NULL. (2) If search_pc is true, frame instructions are executed till either a location is reached that is greater than the search_pc_val provided, or all instructions are executed. At this point the last row of the table generated is returned in a structure. A pointer to this structure is supplied in table. (3) This function is also used to create the initial table row defined by a Cie. In this case, the Dwarf_Cie pointer cie, is NULL. For an FDE, however, cie points to the associated Cie. */ static int _dwarf_exec_frame_instr(Dwarf_Bool make_instr, /* Make list of frame instr? */ Dwarf_Frame_Op ** ret_frame_instr, /* Ptr to list of ptrs to fr instrs */ Dwarf_Bool search_pc, /* Search for a pc value? */ Dwarf_Addr search_pc_val, /* Search for this pc value */ Dwarf_Addr loc, /* initial location value */ Dwarf_Small * start_instr_ptr, /* Ptr to start of frame instrs. */ Dwarf_Small * final_instr_ptr, /* Ptr just past frame instrs. */ Dwarf_Frame table, /* Ptr to struct with last row. */ Dwarf_Cie cie, /* Ptr to Cie used by the Fde. */ Dwarf_Debug dbg, /* Associated Dwarf_Debug */ Dwarf_Sword * returned_count, int *returned_error) { /* Sweeps the frame instructions. */ Dwarf_Small *instr_ptr; /* Obvious from the documents. */ Dwarf_Small instr, opcode; Dwarf_Small reg_no, reg_noA, reg_noB; Dwarf_Unsigned factored_N_value; Dwarf_Addr new_loc; /* must be min de_pointer_size bytes */ Dwarf_Unsigned adv_loc; /* must be min de_pointer_size bytes and must be at least sizeof Dwarf_ufixed */ struct Dwarf_Reg_Rule_s reg[DW_FRAME_LAST_REG_NUM]; /* This is used to end executing frame instructions. */ /* Becomes true when search_pc is true and loc */ /* is greater than search_pc_val. */ Dwarf_Bool search_over = false; /* Used by the DW_FRAME_advance_loc instr */ /* to hold the increment in pc value. */ Dwarf_Addr adv_pc; /* Contains the length in bytes of */ /* an leb128 encoded number. */ Dwarf_Word leb128_length; /* Counts the number of frame instructions executed. */ Dwarf_Word instr_count = 0; /* These contain the current fields of the current frame instruction. */ Dwarf_Small fp_base_op = 0; Dwarf_Small fp_extended_op; Dwarf_Half fp_register; Dwarf_Unsigned fp_offset; Dwarf_Off fp_instr_offset; /* Stack_table points to the row (Dwarf_Frame ie) being pushed or popped by a remember or restore instruction. Top_stack points to the top of the stack of rows. */ Dwarf_Frame stack_table; Dwarf_Frame top_stack = NULL; /* These are used only when make_instr is true. Curr_instr is a pointer to the current frame instruction executed. Curr_instr_ptr, head_instr_list, and curr_instr_list are used to form a chain of Dwarf_Frame_Op structs. Dealloc_instr_ptr is used to deallocate the structs used to form the chain. Head_instr_block points to a contiguous list of pointers to the Dwarf_Frame_Op structs executed. */ Dwarf_Frame_Op *curr_instr; Dwarf_Chain curr_instr_item, dealloc_instr_item; Dwarf_Chain head_instr_chain = NULL; Dwarf_Chain tail_instr_chain = NULL; Dwarf_Frame_Op *head_instr_block; /* These are the alignment_factors taken from the Cie provided. When no input Cie is provided they are set to 1, because only factored offsets are required. */ Dwarf_Sword code_alignment_factor = 1; Dwarf_Sword data_alignment_factor = 1; /* This flag indicates when an actual alignment factor is needed. So if a frame instruction that computes an offset using an alignment factor is encountered when this flag is set, an error is returned because the Cie did not have a valid augmentation. */ Dwarf_Bool need_augmentation = false; Dwarf_Word i; /* Initialize first row from associated Cie. Using temp regs explicity */ struct Dwarf_Reg_Rule_s *t1reg; struct Dwarf_Reg_Rule_s *t1end; struct Dwarf_Reg_Rule_s *t2reg; t1reg = reg; t1end = t1reg + DW_FRAME_LAST_REG_NUM; if (cie != NULL && cie->ci_initial_table != NULL) { t2reg = cie->ci_initial_table->fr_reg; for (; t1reg < t1end; t1reg++, t2reg++) { *t1reg = *t2reg; } } else { /* initialize with same_value */ for (; t1reg < t1end; t1reg++) { t1reg->ru_is_off = 0; t1reg->ru_register = DW_FRAME_SAME_VAL; t1reg->ru_offset = 0; } } /* The idea here is that the code_alignment_factor and data_alignment_factor which are needed for certain instructions are valid only when the Cie has a proper augmentation string. So if the augmentation is not right, only Frame instruction can be read. */ if (cie != NULL && cie->ci_augmentation != NULL) { code_alignment_factor = cie->ci_code_alignment_factor; data_alignment_factor = cie->ci_data_alignment_factor; } else need_augmentation = !make_instr; instr_ptr = start_instr_ptr; while ((instr_ptr < final_instr_ptr) && (!search_over)) { fp_instr_offset = instr_ptr - start_instr_ptr; instr = *(Dwarf_Small *) instr_ptr; instr_ptr += sizeof(Dwarf_Small); fp_base_op = (instr & 0xc0) >> 6; if ((instr & 0xc0) == 0x00) { opcode = instr; /* is really extended op */ fp_extended_op = (instr & (~(0xc0))) & 0xff; } else { opcode = instr & 0xc0; /* is base op */ fp_extended_op = 0; } fp_register = 0; fp_offset = 0; switch (opcode) { case DW_CFA_advance_loc:{ /* base op */ fp_offset = adv_pc = instr & DW_FRAME_INSTR_OFFSET_MASK; if (need_augmentation) { *returned_error = (DW_DLE_DF_NO_CIE_AUGMENTATION); return DW_DLV_ERROR; } adv_pc = adv_pc * code_alignment_factor; search_over = search_pc && (loc + adv_pc > search_pc_val); /* If gone past pc needed, retain old pc. */ if (!search_over) loc = loc + adv_pc; break; } case DW_CFA_offset:{ /* base op */ reg_no = (instr & DW_FRAME_INSTR_OFFSET_MASK); if (reg_no > DW_FRAME_LAST_REG_NUM) { *returned_error = DW_DLE_DF_REG_NUM_TOO_HIGH; return DW_DLV_ERROR; } factored_N_value = _dwarf_decode_u_leb128(instr_ptr, &leb128_length); instr_ptr = instr_ptr + leb128_length; fp_register = reg_no; fp_offset = factored_N_value; if (need_augmentation) { *returned_error = (DW_DLE_DF_NO_CIE_AUGMENTATION); return DW_DLV_ERROR; } reg[reg_no].ru_is_off = 1; reg[reg_no].ru_register = DW_FRAME_CFA_COL; reg[reg_no].ru_offset = factored_N_value * data_alignment_factor; break; } case DW_CFA_restore:{ /* base op */ reg_no = (instr & DW_FRAME_INSTR_OFFSET_MASK); if (reg_no > DW_FRAME_LAST_REG_NUM) { *returned_error = (DW_DLE_DF_REG_NUM_TOO_HIGH); return DW_DLV_ERROR; } fp_register = reg_no; if (cie != NULL && cie->ci_initial_table != NULL) reg[reg_no] = cie->ci_initial_table->fr_reg[reg_no]; else if (!make_instr) { *returned_error = (DW_DLE_DF_MAKE_INSTR_NO_INIT); return DW_DLV_ERROR; } break; } case DW_CFA_set_loc:{ READ_UNALIGNED(dbg, new_loc, Dwarf_Addr, instr_ptr, dbg->de_pointer_size); instr_ptr += dbg->de_pointer_size; if (new_loc <= loc) { *returned_error = (DW_DLE_DF_NEW_LOC_LESS_OLD_LOC); return DW_DLV_ERROR; } search_over = search_pc && (new_loc > search_pc_val); /* If gone past pc needed, retain old pc. */ if (!search_over) loc = new_loc; fp_offset = new_loc; break; } case DW_CFA_advance_loc1:{ fp_offset = adv_loc = *(Dwarf_Small *) instr_ptr; instr_ptr += sizeof(Dwarf_Small); if (need_augmentation) { *returned_error = (DW_DLE_DF_NO_CIE_AUGMENTATION); return DW_DLV_ERROR; } adv_loc *= code_alignment_factor; search_over = search_pc && (loc + adv_loc > search_pc_val); /* If gone past pc needed, retain old pc. */ if (!search_over) loc = loc + adv_loc; break; } case DW_CFA_advance_loc2:{ READ_UNALIGNED(dbg, adv_loc, Dwarf_Unsigned, instr_ptr, sizeof(Dwarf_Half)); instr_ptr += sizeof(Dwarf_Half); fp_offset = adv_loc; if (need_augmentation) { *returned_error = (DW_DLE_DF_NO_CIE_AUGMENTATION); return DW_DLV_ERROR; } adv_loc *= code_alignment_factor; search_over = search_pc && (loc + adv_loc > search_pc_val); /* If gone past pc needed, retain old pc. */ if (!search_over) loc = loc + adv_loc; break; } case DW_CFA_advance_loc4:{ READ_UNALIGNED(dbg, adv_loc, Dwarf_Unsigned, instr_ptr, sizeof(Dwarf_ufixed)); instr_ptr += sizeof(Dwarf_ufixed); fp_offset = adv_loc; if (need_augmentation) { *returned_error = (DW_DLE_DF_NO_CIE_AUGMENTATION); return DW_DLV_ERROR; } adv_loc *= code_alignment_factor; search_over = search_pc && (loc + adv_loc > search_pc_val); /* If gone past pc needed, retain old pc. */ if (!search_over) loc = loc + adv_loc; break; } case DW_CFA_offset_extended:{ Dwarf_Unsigned lreg; DECODE_LEB128_UWORD(instr_ptr, lreg) reg_no = (Dwarf_Small) lreg; if (reg_no > DW_FRAME_LAST_REG_NUM) { *returned_error = (DW_DLE_DF_REG_NUM_TOO_HIGH); return DW_DLV_ERROR; } factored_N_value = _dwarf_decode_u_leb128(instr_ptr, &leb128_length); instr_ptr += leb128_length; if (need_augmentation) { *returned_error = (DW_DLE_DF_NO_CIE_AUGMENTATION); return DW_DLV_ERROR; } reg[reg_no].ru_is_off = 1; reg[reg_no].ru_register = DW_FRAME_CFA_COL; reg[reg_no].ru_offset = factored_N_value * data_alignment_factor; fp_register = reg_no; fp_offset = factored_N_value; break; } case DW_CFA_restore_extended:{ Dwarf_Unsigned lreg; DECODE_LEB128_UWORD(instr_ptr, lreg) reg_no = (Dwarf_Small) lreg; if (reg_no > DW_FRAME_LAST_REG_NUM) { *returned_error = (DW_DLE_DF_REG_NUM_TOO_HIGH); return DW_DLV_ERROR; } if (cie != NULL && cie->ci_initial_table != NULL) { reg[reg_no] = cie->ci_initial_table->fr_reg[reg_no]; } else { if (!make_instr) { *returned_error = (DW_DLE_DF_MAKE_INSTR_NO_INIT); return DW_DLV_ERROR; } } fp_register = reg_no; break; } case DW_CFA_undefined:{ Dwarf_Unsigned lreg; DECODE_LEB128_UWORD(instr_ptr, lreg) reg_no = (Dwarf_Small) lreg; if (reg_no > DW_FRAME_LAST_REG_NUM) { *returned_error = (DW_DLE_DF_REG_NUM_TOO_HIGH); return DW_DLV_ERROR; } reg[reg_no].ru_is_off = 0; reg[reg_no].ru_register = DW_FRAME_UNDEFINED_VAL; reg[reg_no].ru_offset = 0; fp_register = reg_no; break; } case DW_CFA_same_value:{ Dwarf_Unsigned lreg; DECODE_LEB128_UWORD(instr_ptr, lreg) reg_no = (Dwarf_Small) lreg; if (reg_no > DW_FRAME_LAST_REG_NUM) { *returned_error = (DW_DLE_DF_REG_NUM_TOO_HIGH); return DW_DLV_ERROR; } reg[reg_no].ru_is_off = 0; reg[reg_no].ru_register = DW_FRAME_SAME_VAL; reg[reg_no].ru_offset = 0; fp_register = reg_no; break; } case DW_CFA_register:{ Dwarf_Unsigned lreg; DECODE_LEB128_UWORD(instr_ptr, lreg) reg_noA = (Dwarf_Small) lreg; if (reg_noA > DW_FRAME_LAST_REG_NUM) { *returned_error = (DW_DLE_DF_REG_NUM_TOO_HIGH); return DW_DLV_ERROR; } DECODE_LEB128_UWORD(instr_ptr, lreg) reg_noB = (Dwarf_Small) lreg; if (reg_noB > DW_FRAME_LAST_REG_NUM) { *returned_error = (DW_DLE_DF_REG_NUM_TOO_HIGH); return DW_DLV_ERROR; } reg[reg_noA].ru_is_off = 0; reg[reg_noA].ru_register = reg_noB; reg[reg_noA].ru_offset = 0; fp_register = reg_noA; fp_offset = reg_noB; break; } case DW_CFA_remember_state:{ stack_table = (Dwarf_Frame) _dwarf_get_alloc(dbg, DW_DLA_FRAME, 1); if (stack_table == NULL) { *returned_error = (DW_DLE_DF_ALLOC_FAIL); return DW_DLV_ERROR; } for (i = 0; i < DW_FRAME_LAST_REG_NUM; i++) stack_table->fr_reg[i] = reg[i]; if (top_stack != NULL) stack_table->fr_next = top_stack; top_stack = stack_table; break; } case DW_CFA_restore_state:{ if (top_stack == NULL) { *returned_error = (DW_DLE_DF_POP_EMPTY_STACK); return DW_DLV_ERROR; } stack_table = top_stack; top_stack = stack_table->fr_next; for (i = 0; i < DW_FRAME_LAST_REG_NUM; i++) reg[i] = stack_table->fr_reg[i]; dwarf_dealloc(dbg, stack_table, DW_DLA_FRAME); break; } case DW_CFA_def_cfa:{ Dwarf_Unsigned lreg; DECODE_LEB128_UWORD(instr_ptr, lreg) reg_no = (Dwarf_Small) lreg; if (reg_no > DW_FRAME_LAST_REG_NUM) { *returned_error = (DW_DLE_DF_REG_NUM_TOO_HIGH); return (DW_DLV_ERROR); } factored_N_value = _dwarf_decode_u_leb128(instr_ptr, &leb128_length); instr_ptr += leb128_length; if (need_augmentation) { *returned_error = (DW_DLE_DF_NO_CIE_AUGMENTATION); return DW_DLV_ERROR; } reg[DW_FRAME_CFA_COL].ru_is_off = 1; reg[DW_FRAME_CFA_COL].ru_register = reg_no; reg[DW_FRAME_CFA_COL].ru_offset = factored_N_value; fp_register = reg_no; fp_offset = factored_N_value; break; } case DW_CFA_def_cfa_register:{ Dwarf_Unsigned lreg; DECODE_LEB128_UWORD(instr_ptr, lreg) reg_no = (Dwarf_Small) lreg; if (reg_no > DW_FRAME_LAST_REG_NUM) { *returned_error = (DW_DLE_DF_REG_NUM_TOO_HIGH); return DW_DLV_ERROR; } reg[DW_FRAME_CFA_COL].ru_register = reg_no; /* Do NOT set ru_offset or ru_is_off here. See dwarf2/3 spec. */ fp_register = reg_no; break; } case DW_CFA_def_cfa_offset:{ factored_N_value = _dwarf_decode_u_leb128(instr_ptr, &leb128_length); instr_ptr += leb128_length; if (need_augmentation) { *returned_error = (DW_DLE_DF_NO_CIE_AUGMENTATION); return DW_DLV_ERROR; } /* Do set ru_is_off here, as here factored_N_value counts. */ reg[DW_FRAME_CFA_COL].ru_is_off = 1; reg[DW_FRAME_CFA_COL].ru_offset = factored_N_value; fp_offset = factored_N_value; break; } case DW_CFA_nop:{ break; } #ifdef DW_CFA_GNU_window_save case DW_CFA_GNU_window_save:{ /* no information: this just tells unwinder to restore the window registers from the previous frame's window save area */ break; } #endif #ifdef DW_CFA_GNU_args_size /* single uleb128 is the current arg area size in bytes. No register exists yet to save this in */ case DW_CFA_GNU_args_size:{ Dwarf_Unsigned lreg; DECODE_LEB128_UWORD(instr_ptr, lreg) reg_no = (Dwarf_Small) lreg; break; } #endif } if (make_instr) { instr_count++; curr_instr = (Dwarf_Frame_Op *) _dwarf_get_alloc(dbg, DW_DLA_FRAME_OP, 1); if (curr_instr == NULL) { *returned_error = (DW_DLE_DF_ALLOC_FAIL); return DW_DLV_ERROR; } curr_instr->fp_base_op = fp_base_op; curr_instr->fp_extended_op = fp_extended_op; curr_instr->fp_register = fp_register; curr_instr->fp_offset = fp_offset; curr_instr->fp_instr_offset = fp_instr_offset; curr_instr_item = (Dwarf_Chain) _dwarf_get_alloc(dbg, DW_DLA_CHAIN, 1); if (curr_instr_item == NULL) { *returned_error = (DW_DLE_DF_ALLOC_FAIL); return DW_DLV_ERROR; } curr_instr_item->ch_item = curr_instr; if (head_instr_chain == NULL) head_instr_chain = tail_instr_chain = curr_instr_item; else { tail_instr_chain->ch_next = curr_instr_item; tail_instr_chain = curr_instr_item; } } } /* If frame instruction decoding was right we would stop exactly at final_instr_ptr. */ if (instr_ptr > final_instr_ptr) { *returned_error = (DW_DLE_DF_FRAME_DECODING_ERROR); return DW_DLV_ERROR; } /* Create the last row generated. */ if (table != NULL) { t1reg = reg; t1end = t1reg + DW_FRAME_LAST_REG_NUM; table->fr_loc = loc; t2reg = table->fr_reg; for (; t1reg < t1end; t1reg++, t2reg++) { *t2reg = *t1reg; } } /* Dealloc anything remaining on stack. */ for (; top_stack != NULL;) { stack_table = top_stack; top_stack = top_stack->fr_next; dwarf_dealloc(dbg, stack_table, DW_DLA_FRAME); } if (make_instr) { /* Allocate list of pointers to Dwarf_Frame_Op's. */ head_instr_block = (Dwarf_Frame_Op *) _dwarf_get_alloc(dbg, DW_DLA_FRAME_BLOCK, instr_count); if (head_instr_block == NULL) { *returned_error = DW_DLE_DF_ALLOC_FAIL; return DW_DLV_ERROR; } /* Store pointers to Dwarf_Frame_Op's in this list and deallocate the structs that chain the Dwarf_Frame_Op's. */ curr_instr_item = head_instr_chain; for (i = 0; i < instr_count; i++) { *(head_instr_block + i) = *(Dwarf_Frame_Op *) curr_instr_item->ch_item; dealloc_instr_item = curr_instr_item; curr_instr_item = curr_instr_item->ch_next; dwarf_dealloc(dbg, dealloc_instr_item->ch_item, DW_DLA_FRAME_OP); dwarf_dealloc(dbg, dealloc_instr_item, DW_DLA_CHAIN); } *ret_frame_instr = head_instr_block; *returned_count = (Dwarf_Sword) instr_count; } else { *returned_count = 0; } return DW_DLV_OK; } static int qsort_compare(const void *elem1, const void *elem2) { Dwarf_Fde fde1 = *(Dwarf_Fde *) elem1; Dwarf_Fde fde2 = *(Dwarf_Fde *) elem2; Dwarf_Addr addr1 = fde1->fd_initial_location; Dwarf_Addr addr2 = fde2->fd_initial_location; if (addr1 < addr2) { return -1; } else if (addr1 > addr2) { return 1; } return 0; } /* * This function expects as input a pointer to Dwarf_Debug (dbg) and a * a pointer to Cie. It finds the augmentation string and returns after * setting *augmentation to point to it. */ static int get_augmentation_string(Dwarf_Debug dbg, Dwarf_Small * cie_ptr, Dwarf_Unsigned cie_id_value, Dwarf_Small ** augmentation, Dwarf_Error * error) { Dwarf_Unsigned cie_id; /* must be min de_length_size bytes in size */ Dwarf_Small version; int local_length_size; Dwarf_Unsigned length; /*REFERENCED*/ /* Not used in this instance of the macro */ int local_extension_size; /* READ_AREA_LENGTH updates cie_ptr for consumed bytes */ READ_AREA_LENGTH(dbg, length, Dwarf_Unsigned, cie_ptr, local_length_size, local_extension_size); /* Read the Cie Id field. */ READ_UNALIGNED(dbg, cie_id, Dwarf_Unsigned, cie_ptr, local_length_size); SIGN_EXTEND(cie_id, local_length_size); if (cie_id != cie_id_value) { /* egcs-1.1.2 .eh_frame uses 0 as the distinguishing id. sgi uses -1 in .debug_frame. .eh_frame not quite identical to .debug_frame */ _dwarf_error(dbg, error, DW_DLE_FRAME_VERSION_BAD); return (DW_DLV_ERROR); } cie_ptr += local_length_size; /* Read the version. */ version = *(Dwarf_Small *) cie_ptr; cie_ptr++; if (version != DW_CIE_VERSION && version != DW_CIE_VERSION3) { _dwarf_error(dbg, error, DW_DLE_FRAME_VERSION_BAD); return (DW_DLV_ERROR); } /* At this point, cie_ptr is pointing at the augmentation string. */ *augmentation = cie_ptr; return DW_DLV_OK; } int dwarf_get_cie_of_fde(Dwarf_Fde fde, Dwarf_Cie * cie_returned, Dwarf_Error * error) { if (fde == NULL) { _dwarf_error(NULL, error, DW_DLE_FDE_NULL); return (DW_DLV_ERROR); } *cie_returned = fde->fd_cie; return DW_DLV_OK; } /* For g++ .eh_frame fde and cie. the cie id is different as the definition of the cie_id in an fde is the distance back from the address of the value to the cie. Or 0 if this is a true cie. Non standard dwarf, designed this way to be convenient at run time for an allocated (mapped into memory as part of the running image) section. */ int dwarf_get_fde_list_eh(Dwarf_Debug dbg, Dwarf_Cie ** cie_data, Dwarf_Signed * cie_element_count, Dwarf_Fde ** fde_data, Dwarf_Signed * fde_element_count, Dwarf_Error * error) { int res; res = _dwarf_load_section(dbg, dbg->de_debug_frame_eh_gnu_index, &dbg->de_debug_frame_eh_gnu, error); if (res != DW_DLV_OK) { return res; } res = __dwarf_get_fde_list_internal(dbg, cie_data, cie_element_count, fde_data, fde_element_count, dbg->de_debug_frame_eh_gnu, dbg->de_debug_frame_size_eh_gnu, dbg->de_debug_frame_eh_gnu_index, /* cie_id_value */ 0, /* use_gnu_cie_calc= */ 1, error); return res; } /* For standard dwarf .debug_frame cie_id is -1 in a cie, and is the section offset in the .debug_frame section of the cie otherwise. Standard dwarf */ int dwarf_get_fde_list(Dwarf_Debug dbg, Dwarf_Cie ** cie_data, Dwarf_Signed * cie_element_count, Dwarf_Fde ** fde_data, Dwarf_Signed * fde_element_count, Dwarf_Error * error) { int res; res = _dwarf_load_section(dbg, dbg->de_debug_frame_index, &dbg->de_debug_frame, error); if (res != DW_DLV_OK) { return res; } res = __dwarf_get_fde_list_internal(dbg, cie_data, cie_element_count, fde_data, fde_element_count, dbg->de_debug_frame, dbg->de_debug_frame_size, dbg->de_debug_frame_index, DW_CIE_ID, /* use_gnu_cie_calc= */ 0, error); return res; } static int __dwarf_get_fde_list_internal(Dwarf_Debug dbg, Dwarf_Cie ** cie_data, Dwarf_Signed * cie_element_count, Dwarf_Fde ** fde_data, Dwarf_Signed * fde_element_count, Dwarf_Small * section_ptr, Dwarf_Unsigned section_length, Dwarf_Unsigned section_index, Dwarf_Unsigned cie_id_value, int use_gnu_cie_calc, Dwarf_Error * error) { /* Scans the debug_frame section. */ Dwarf_Small *frame_ptr = 0; /* Points to the start of the current Fde or Cie. */ Dwarf_Small *start_frame_ptr = 0; /* Points to the start of the augmented entries of Fde or Cie. */ Dwarf_Small *saved_frame_ptr = 0; /* Fields for the current Cie being read. */ Dwarf_Unsigned length = 0; /* READ_UNALIGNED needs min de_length_size byte dest */ Dwarf_Unsigned cie_base_offset = 0; /* needs to be min de_length_size byte dest */ Dwarf_Unsigned cie_id; Dwarf_Small version = 0; Dwarf_Small *augmentation = 0; Dwarf_Word code_alignment_factor = 4; Dwarf_Sword data_alignment_factor = -1; Dwarf_Small return_address_register = 31; Dwarf_Word length_of_augmented_fields = 0; /* New_cie points to the Cie being read, and head_cie_ptr and cur_cie_ptr are used for chaining them up in sequence. */ Dwarf_Cie new_cie; Dwarf_Cie head_cie_ptr = NULL; Dwarf_Cie cur_cie_ptr; Dwarf_Word cie_count = 0; /* Points to a list of contiguous pointers to Dwarf_Cie structures. */ Dwarf_Cie *cie_list_ptr; /* Fields for the current Fde being read. */ Dwarf_Addr initial_location; /* must be min de_pointer_size bytes in size */ Dwarf_Addr address_range; /* must be min de_pointer_size bytes in size */ /* New_fde points to the current Fde being read, and head_fde_ptr and cur_fde_ptr are used to chain them up. */ Dwarf_Fde new_fde; Dwarf_Fde head_fde_ptr = NULL; Dwarf_Fde cur_fde_ptr; Dwarf_Word fde_count = 0; /* Points to a list of contiguous pointers to Dwarf_Fde structures. */ Dwarf_Fde *fde_list_ptr; /* Is used to check the offset field in the Fde by checking for a Cie at this address. */ Dwarf_Small *fde_cie_ptr; Dwarf_Word leb128_length; Dwarf_Word i, j; int res; Dwarf_Word last_cie_index; Dwarf_Small *prev_augmentation_cie_ptr = 0; Dwarf_Small *prev_augmentation_ptr = 0; frame_ptr = section_ptr; if (frame_ptr == 0) { return DW_DLV_NO_ENTRY; } while (frame_ptr < section_ptr + section_length) { Dwarf_Small *cie_ptr_addr = 0; int local_extension_size = 0; int local_length_size = 0; start_frame_ptr = frame_ptr; /* READ_AREA_LENGTH updates frame_ptr for consumed bytes */ READ_AREA_LENGTH(dbg, length, Dwarf_Unsigned, frame_ptr, local_length_size, local_extension_size); if (length % local_length_size != 0) { _dwarf_error(dbg, error, DW_DLE_DEBUG_FRAME_LENGTH_BAD); return (DW_DLV_ERROR); } if (length == 0) { /* nul bytes at end of section, seen at end of egcs eh_frame sections (in a.out). Take this as meaning no more CIE/FDE data. We should be very close to end of section. */ break; } cie_ptr_addr = frame_ptr; READ_UNALIGNED(dbg, cie_id, Dwarf_Unsigned, frame_ptr, local_length_size); SIGN_EXTEND(cie_id, local_length_size); cie_base_offset = cie_id; /* if this is a CIE, this is ignored. If it is an FDE, this is the section offset that allows us to get to the cie of this fde. Save it for the fde part of the 'if' below */ frame_ptr += local_length_size; if (cie_id == cie_id_value) { /* egcs-1.1.2 .eh_frame uses 0 as the distinguishing id. sgi uses -1 (in .debug_frame). .eh_frame not quite identical to .debug_frame */ /* this is a CIE, Common Information Entry: See the dwarf spec, section 6.4.1 */ version = *(Dwarf_Small *) frame_ptr; frame_ptr++; if (version != DW_CIE_VERSION && version != DW_CIE_VERSION3) { _dwarf_error(dbg, error, DW_DLE_FRAME_VERSION_BAD); return (DW_DLV_ERROR); } augmentation = frame_ptr; frame_ptr = frame_ptr + strlen((char *) frame_ptr) + 1; if ((strcmp((char *) augmentation, DW_DEBUG_FRAME_AUGMENTER_STRING) == 0) || (strcmp((char *) augmentation, DW_EMPTY_STRING) == 0)) { Dwarf_Unsigned lreg; DECODE_LEB128_UWORD(frame_ptr, lreg) code_alignment_factor = (Dwarf_Word) lreg; data_alignment_factor = (Dwarf_Sword) _dwarf_decode_s_leb128(frame_ptr, &leb128_length); frame_ptr = frame_ptr + leb128_length; return_address_register = *(Dwarf_Small *) frame_ptr; if (return_address_register > DW_FRAME_LAST_REG_NUM) { _dwarf_error(dbg, error, DW_DLE_CIE_RET_ADDR_REG_ERROR); return (DW_DLV_ERROR); } frame_ptr++; } else if (augmentation[0] == 'z') { /* The augmentation starts with a known prefix. See the dwarf_frame.h for details on the layout. */ Dwarf_Unsigned lreg; DECODE_LEB128_UWORD(frame_ptr, lreg) code_alignment_factor = (Dwarf_Word) lreg; data_alignment_factor = (Dwarf_Sword) _dwarf_decode_s_leb128(frame_ptr, &leb128_length); frame_ptr = frame_ptr + leb128_length; return_address_register = *(Dwarf_Small *) frame_ptr; if (return_address_register > DW_FRAME_LAST_REG_NUM) { _dwarf_error(dbg, error, DW_DLE_CIE_RET_ADDR_REG_ERROR); return (DW_DLV_ERROR); } frame_ptr++; /* Decode the length of augmented fields. */ DECODE_LEB128_UWORD(frame_ptr, lreg) length_of_augmented_fields = (Dwarf_Word) lreg; /* set the frame_ptr to point at the instruction start. */ frame_ptr += length_of_augmented_fields; } else if (0 == strcmp((const char *) augmentation, "eh")) { /*REFERENCED*/ /* Not used in this instance of the macro */ Dwarf_Unsigned exception_table_addr; /* this is per egcs-1.1.2 as on RH 6.0 */ READ_UNALIGNED(dbg, exception_table_addr, Dwarf_Unsigned, frame_ptr, local_length_size); frame_ptr += local_length_size; code_alignment_factor = (Dwarf_Word) _dwarf_decode_s_leb128(frame_ptr, &leb128_length); frame_ptr = frame_ptr + leb128_length; data_alignment_factor = (Dwarf_Sword) _dwarf_decode_s_leb128(frame_ptr, &leb128_length); frame_ptr = frame_ptr + leb128_length; return_address_register = *(Dwarf_Small *) frame_ptr; if (return_address_register > DW_FRAME_LAST_REG_NUM) { _dwarf_error(dbg, error, DW_DLE_CIE_RET_ADDR_REG_ERROR); return (DW_DLV_ERROR); } frame_ptr++; } else { /* We do not understand the augmentation string. No assumption can be made about any fields other than what we have already read. */ frame_ptr = start_frame_ptr + length + local_length_size + local_extension_size; /* FIX -- What are the values of data_alignment_factor, code_alignement_factor, return_address_register and instruction start? They were clearly uninitalized in the previous version and I am leaving them the same way. */ } new_cie = (Dwarf_Cie) _dwarf_get_alloc(dbg, DW_DLA_CIE, 1); if (new_cie == NULL) { _dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL); return (DW_DLV_ERROR); } new_cie->ci_cie_version_number = version; new_cie->ci_initial_table = NULL; new_cie->ci_length = (Dwarf_Word) length; new_cie->ci_length_size = local_length_size; new_cie->ci_extension_size = local_extension_size; new_cie->ci_augmentation = (char *) augmentation; new_cie->ci_data_alignment_factor = (Dwarf_Sbyte) data_alignment_factor; new_cie->ci_code_alignment_factor = (Dwarf_Small) code_alignment_factor; new_cie->ci_return_address_register = return_address_register; new_cie->ci_cie_start = start_frame_ptr; new_cie->ci_cie_instr_start = frame_ptr; new_cie->ci_dbg = dbg; cie_count++; if (head_cie_ptr == NULL) head_cie_ptr = cur_cie_ptr = new_cie; else { cur_cie_ptr->ci_next = new_cie; cur_cie_ptr = new_cie; } } else { /* this is an FDE, Frame Description Entry, see the Dwarf Spec, section 6.4.1 */ Dwarf_Small *cieptr; Dwarf_Small *initloc = frame_ptr; Dwarf_Signed offset_into_exception_tables /* must be min dwarf_sfixed in size */ = (Dwarf_Signed) DW_DLX_NO_EH_OFFSET; READ_UNALIGNED(dbg, initial_location, Dwarf_Addr, frame_ptr, dbg->de_pointer_size); frame_ptr += dbg->de_pointer_size; READ_UNALIGNED(dbg, address_range, Dwarf_Addr, frame_ptr, dbg->de_pointer_size); frame_ptr += dbg->de_pointer_size; /* Get the augmentation string from Cie to identify the layout of this Fde. */ if (use_gnu_cie_calc) { /* cie_id value is offset, in section, of the cie_id itself, to use vm ptr of the value, less the value, to get to the cie itself. In addition, munge cie_base_offset to look *as if* it was from real dwarf. */ cieptr = cie_ptr_addr - cie_base_offset; cie_base_offset = cieptr - section_ptr; } else { /* Traditional dwarf section offset is in cie_id */ cieptr = (Dwarf_Small *) (section_ptr + cie_base_offset); } if (prev_augmentation_cie_ptr == cieptr && prev_augmentation_ptr != NULL) { augmentation = prev_augmentation_ptr; } else { res = get_augmentation_string(dbg, cieptr, cie_id_value, &augmentation, error); if (res != DW_DLV_OK) { return res; } prev_augmentation_cie_ptr = cieptr; prev_augmentation_ptr = augmentation; } if ((strcmp((char *) augmentation, DW_DEBUG_FRAME_AUGMENTER_STRING) == 0) || (strcmp((char *) augmentation, DW_EMPTY_STRING) == 0)) { /* We are pointing at the start of instructions. Do nothing. */ } else if (augmentation[0] == 'z') { Dwarf_Unsigned lreg; DECODE_LEB128_UWORD(frame_ptr, lreg) length_of_augmented_fields = (Dwarf_Word) lreg; saved_frame_ptr = frame_ptr; if (strcmp((char *) augmentation, DW_CIE_AUGMENTER_STRING_V0) == 0) { /* The first word is an offset into execption tables. */ /* ?? THis presumes that the offset is always 32 bits */ READ_UNALIGNED(dbg, offset_into_exception_tables, Dwarf_Addr, frame_ptr, sizeof(Dwarf_sfixed)); SIGN_EXTEND(offset_into_exception_tables, sizeof(Dwarf_sfixed)); frame_ptr += local_length_size; } frame_ptr = saved_frame_ptr + length_of_augmented_fields; } else if (strcmp((const char *) augmentation, "eh") == 0) { /* gnu eh fde case. we do not need to do anything */ /*REFERENCED*/ /* Not used in this instance of the macro */ Dwarf_Unsigned exception_table_addr; READ_UNALIGNED(dbg, exception_table_addr, Dwarf_Unsigned, frame_ptr, dbg->de_pointer_size); frame_ptr += dbg->de_pointer_size; } else { /* We do not understand the augmentation string. No assumption can be made about if the instructions is present. */ /* FIX -- The old code assumed that the instruction table starts at the location pointed to by frame_ptr, clearly incorrect. */ } new_fde = (Dwarf_Fde) _dwarf_get_alloc(dbg, DW_DLA_FDE, 1); if (new_fde == NULL) { _dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL); return (DW_DLV_ERROR); } new_fde->fd_length = (Dwarf_Word) length; new_fde->fd_length_size = local_length_size; new_fde->fd_extension_size = local_extension_size; new_fde->fd_cie_offset = cie_base_offset; new_fde->fd_initial_location = initial_location; new_fde->fd_initial_loc_pos = initloc; new_fde->fd_address_range = address_range; new_fde->fd_fde_start = start_frame_ptr; new_fde->fd_fde_instr_start = frame_ptr; new_fde->fd_dbg = dbg; new_fde->fd_offset_into_exception_tables = offset_into_exception_tables; new_fde->fd_section_ptr = section_ptr; new_fde->fd_section_length = section_length; new_fde->fd_section_index = section_index; fde_count++; if (head_fde_ptr == NULL) head_fde_ptr = cur_fde_ptr = new_fde; else { cur_fde_ptr->fd_next = new_fde; cur_fde_ptr = new_fde; } } /* Skip over instructions to start of next frame. */ frame_ptr = start_frame_ptr + length + local_length_size + local_extension_size; } if (cie_count > 0) { cie_list_ptr = (Dwarf_Cie *) _dwarf_get_alloc(dbg, DW_DLA_LIST, cie_count); } else { return (DW_DLV_NO_ENTRY); } if (cie_list_ptr == NULL) { _dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL); return (DW_DLV_ERROR); } /* Return arguments. */ *cie_data = cie_list_ptr; *cie_element_count = cie_count; dbg->de_cie_data = cie_list_ptr; dbg->de_cie_count = cie_count; cur_cie_ptr = head_cie_ptr; for (i = 0; i < cie_count; i++) { *(cie_list_ptr + i) = cur_cie_ptr; cur_cie_ptr = cur_cie_ptr->ci_next; } if (fde_count > 0) { fde_list_ptr = (Dwarf_Fde *) _dwarf_get_alloc(dbg, DW_DLA_LIST, fde_count); } else { return (DW_DLV_NO_ENTRY); } if (fde_list_ptr == NULL) { _dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL); return (DW_DLV_ERROR); } /* Return arguments. */ *fde_data = fde_list_ptr; *fde_element_count = fde_count; dbg->de_fde_data = fde_list_ptr; dbg->de_fde_count = fde_count; last_cie_index = 0; cur_fde_ptr = head_fde_ptr; for (i = 0; i < fde_count; i++) { Dwarf_Sword new_cie_index = (Dwarf_Sword) cie_count; *(fde_list_ptr + i) = cur_fde_ptr; fde_cie_ptr = (Dwarf_Small *) (section_ptr + cur_fde_ptr->fd_cie_offset); /* we assume that the next fde has the same cie as the ** last fde and resume the search where we left off */ for (j = last_cie_index; j < cie_count; j++) { Dwarf_Cie ciep = (Dwarf_Cie) * (cie_list_ptr + j); if (ciep->ci_cie_start == fde_cie_ptr) { new_cie_index = (Dwarf_Sword) j; break; } } /* did not find it above, start from 0 and try again */ if (new_cie_index == cie_count) { for (j = 0; j < last_cie_index; ++j) { Dwarf_Cie ciep = (Dwarf_Cie) * (cie_list_ptr + j); if (ciep->ci_cie_start == fde_cie_ptr) { new_cie_index = (Dwarf_Sword) j; break; } } } j = new_cie_index; last_cie_index = new_cie_index; if (j == cie_count) { _dwarf_error(dbg, error, DW_DLE_NO_CIE_FOR_FDE); return (DW_DLV_ERROR); } else { cur_fde_ptr->fd_cie_index = (Dwarf_Sword) j; cur_fde_ptr->fd_cie = *(cie_list_ptr + j); } cur_fde_ptr = cur_fde_ptr->fd_next; } /* sort the list by the address, so that dwarf_get_fde_at_pc() can binary search this list. */ qsort((void *) fde_list_ptr, fde_count, sizeof(Dwarf_Ptr), qsort_compare); return (DW_DLV_OK); } /* Only works on dwarf sections, not eh_frame */ int dwarf_get_fde_for_die(Dwarf_Debug dbg, Dwarf_Die die, Dwarf_Fde * ret_fde, Dwarf_Error * error) { Dwarf_Attribute attr; Dwarf_Unsigned fde_offset; Dwarf_Signed signdval; Dwarf_Unsigned length; /* must be min de_length_size bytes */ Dwarf_Signed signed_offset; /* must be min de_length_size bytes */ Dwarf_Addr initial_location; /* must be min de_pointer_size bytes */ Dwarf_Addr address_range; /* must be min de_pointer_size bytes */ Dwarf_Fde new_fde; unsigned char *fde_ptr; Dwarf_Small *saved_fde_ptr; unsigned char *cie_ptr; unsigned char *start_cie_ptr; Dwarf_Cie new_cie; /* Fields for the current Cie being read. */ Dwarf_Small version; Dwarf_Small *augmentation; Dwarf_Word code_alignment_factor; Dwarf_Sword data_alignment_factor; Dwarf_Small return_address_register; Dwarf_Word length_of_augmented_fields; Dwarf_Signed offset_into_exception_tables = (Dwarf_Signed) DW_DLX_NO_EH_OFFSET; int res; int resattr; int sdatares; int fde_local_extension_size = 0; int fde_local_length_size = 0; int cie_local_extension_size = 0; int cie_local_length_size = 0; Dwarf_Word leb128_length; if (die == NULL) { _dwarf_error(NULL, error, DW_DLE_DIE_NULL); return (DW_DLV_ERROR); } resattr = dwarf_attr(die, DW_AT_MIPS_fde, &attr, error); if (resattr != DW_DLV_OK) { return resattr; } /* why is this formsdata? FIX */ sdatares = dwarf_formsdata(attr, &signdval, error); if (sdatares != DW_DLV_OK) { return sdatares; } res = _dwarf_load_section(dbg, dbg->de_debug_frame_index, &dbg->de_debug_frame, error); if (res != DW_DLV_OK) { return res; } fde_offset = signdval; fde_ptr = (dbg->de_debug_frame + fde_offset); /* READ_AREA_LENGTH updates fde_ptr for consumed bytes */ READ_AREA_LENGTH(dbg, length, Dwarf_Unsigned, fde_ptr, fde_local_length_size, fde_local_extension_size); if (length % fde_local_length_size != 0) { _dwarf_error(dbg, error, DW_DLE_DEBUG_FRAME_LENGTH_BAD); return (DW_DLV_ERROR); } READ_UNALIGNED(dbg, signed_offset, Dwarf_Signed, fde_ptr, fde_local_length_size); SIGN_EXTEND(signed_offset, fde_local_length_size); fde_ptr += fde_local_length_size; READ_UNALIGNED(dbg, initial_location, Dwarf_Addr, fde_ptr, dbg->de_pointer_size); fde_ptr += dbg->de_pointer_size; READ_UNALIGNED(dbg, address_range, Dwarf_Addr, fde_ptr, dbg->de_pointer_size); fde_ptr += dbg->de_pointer_size; res = get_augmentation_string(dbg, (Dwarf_Small *) (dbg->de_debug_frame + signed_offset), DW_CIE_ID, &augmentation, error); if (res != DW_DLV_OK) { return res; } if ((strcmp((char *) augmentation, DW_DEBUG_FRAME_AUGMENTER_STRING) == 0) || (strcmp((char *) augmentation, DW_EMPTY_STRING) == 0)) { /* Do nothing. The fde_ptr is pointing at start of instructions. */ } else if (augmentation[0] == 'z') { /* The augmentation starts with a known prefix. See the dwarf_frame.h for details on the layout. */ Dwarf_Unsigned lreg; DECODE_LEB128_UWORD(fde_ptr, lreg) length_of_augmented_fields = (Dwarf_Word) lreg; saved_fde_ptr = fde_ptr; if (strcmp((char *) augmentation, DW_CIE_AUGMENTER_STRING_V0) == 0) { /* The first word is an offset into execption tables. */ READ_UNALIGNED(dbg, offset_into_exception_tables, Dwarf_Signed, fde_ptr, sizeof(Dwarf_sfixed)); SIGN_EXTEND(offset_into_exception_tables, sizeof(Dwarf_sfixed)); fde_ptr += sizeof(Dwarf_sfixed); } fde_ptr = saved_fde_ptr + length_of_augmented_fields; } else { /* We do not understand the augmentation string. No assumption can be made about if the instructions is present. */ /* FIX -- The old code assumed that the instruction table starts at location pointed to by fde_ptr, clearly incorrect. */ } new_fde = (Dwarf_Fde) _dwarf_get_alloc(dbg, DW_DLA_FDE, 1); if (new_fde == NULL) { _dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL); return (DW_DLV_ERROR); } new_fde->fd_length = (Dwarf_Word) length; new_fde->fd_length_size = fde_local_length_size; new_fde->fd_extension_size = fde_local_extension_size; new_fde->fd_cie_offset = signed_offset; new_fde->fd_initial_location = initial_location; new_fde->fd_address_range = address_range; new_fde->fd_fde_start = dbg->de_debug_frame + fde_offset; new_fde->fd_fde_instr_start = (Dwarf_Small *) fde_ptr; new_fde->fd_dbg = dbg; new_fde->fd_offset_into_exception_tables = offset_into_exception_tables; new_fde->fd_section_ptr = dbg->de_debug_frame; new_fde->fd_section_length = dbg->de_debug_frame_size; new_fde->fd_section_index = dbg->de_debug_frame_index; /* now read the cie corresponding to the fde */ cie_ptr = (dbg->de_debug_frame + signed_offset); start_cie_ptr = cie_ptr; /* READ_AREA_LENGTH updates cie_ptr for consumed bytes */ READ_AREA_LENGTH(dbg, length, Dwarf_Unsigned, cie_ptr, cie_local_length_size, cie_local_extension_size); if (length % cie_local_length_size != 0) { _dwarf_error(dbg, error, DW_DLE_DEBUG_FRAME_LENGTH_BAD); return (DW_DLV_ERROR); } READ_UNALIGNED(dbg, signed_offset, Dwarf_Signed, cie_ptr, cie_local_length_size); SIGN_EXTEND(signed_offset, cie_local_length_size); cie_ptr += cie_local_length_size; if (signed_offset == DW_CIE_ID) { version = *(Dwarf_Small *) cie_ptr; cie_ptr++; if (version != DW_CIE_VERSION && version != DW_CIE_VERSION3) { _dwarf_error(dbg, error, DW_DLE_FRAME_VERSION_BAD); return (DW_DLV_ERROR); } augmentation = cie_ptr; cie_ptr = cie_ptr + strlen((char *) cie_ptr) + 1; if ((strcmp((char *) augmentation, DW_DEBUG_FRAME_AUGMENTER_STRING) == 0) || (strcmp((char *) augmentation, DW_EMPTY_STRING) == 0)) { Dwarf_Unsigned lreg; DECODE_LEB128_UWORD(cie_ptr, lreg) code_alignment_factor = (Dwarf_Word) lreg; data_alignment_factor = (Dwarf_Sword) _dwarf_decode_s_leb128(cie_ptr, &leb128_length); cie_ptr = cie_ptr + leb128_length; return_address_register = *(Dwarf_Small *) cie_ptr; if (return_address_register > DW_FRAME_LAST_REG_NUM) { _dwarf_error(dbg, error, DW_DLE_CIE_RET_ADDR_REG_ERROR); return (DW_DLV_ERROR); } cie_ptr++; } else if (augmentation[0] == 'z') { /* The augmentation starts with a known prefix. We can asssume that the first field is the length of the augmented fields. */ Dwarf_Unsigned lreg; DECODE_LEB128_UWORD(cie_ptr, lreg) code_alignment_factor = (Dwarf_Word) lreg; data_alignment_factor = (Dwarf_Sword) _dwarf_decode_s_leb128(cie_ptr, &leb128_length); cie_ptr = cie_ptr + leb128_length; return_address_register = *(Dwarf_Small *) cie_ptr; if (return_address_register > DW_FRAME_LAST_REG_NUM) { _dwarf_error(dbg, error, DW_DLE_CIE_RET_ADDR_REG_ERROR); return (DW_DLV_ERROR); } cie_ptr++; /* Decode the length of augmented fields. */ DECODE_LEB128_UWORD(cie_ptr, lreg) length_of_augmented_fields = (Dwarf_Word) lreg; /* set the cie_ptr to point at the instruction start. */ cie_ptr += length_of_augmented_fields; } else if (strcmp((const char *) augmentation, "eh") == 0) { Dwarf_Unsigned lreg; DECODE_LEB128_UWORD(cie_ptr, lreg) code_alignment_factor = (Dwarf_Word) lreg; data_alignment_factor = (Dwarf_Sword) _dwarf_decode_s_leb128(cie_ptr, &leb128_length); cie_ptr = cie_ptr + leb128_length; return_address_register = *(Dwarf_Small *) cie_ptr; if (return_address_register > DW_FRAME_LAST_REG_NUM) { _dwarf_error(dbg, error, DW_DLE_CIE_RET_ADDR_REG_ERROR); return (DW_DLV_ERROR); } cie_ptr++; } else { /* We do not understand the augmentation string. No assumption can be made about any fields other than what we have already read. */ cie_ptr = start_cie_ptr + length + cie_local_length_size + cie_local_extension_size; /* FIX -- What are the values of data_alignment_factor, code_alignement_factor, return_address_register and instruction start? They were clearly uninitalized in the previous version and I am leaving them the same way. */ } new_cie = (Dwarf_Cie) _dwarf_get_alloc(dbg, DW_DLA_CIE, 1); if (new_cie == NULL) { _dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL); return (DW_DLV_ERROR); } new_cie->ci_cie_version_number = version; new_cie->ci_initial_table = NULL; new_cie->ci_length = (Dwarf_Word) length; new_cie->ci_length_size = cie_local_length_size; new_cie->ci_extension_size = cie_local_extension_size; new_cie->ci_augmentation = (char *) augmentation; new_cie->ci_data_alignment_factor = (Dwarf_Sbyte) data_alignment_factor; new_cie->ci_code_alignment_factor = (Dwarf_Small) code_alignment_factor; new_cie->ci_return_address_register = return_address_register; new_cie->ci_cie_start = start_cie_ptr; new_cie->ci_cie_instr_start = cie_ptr; new_cie->ci_dbg = dbg; } else { _dwarf_error(dbg, error, DW_DLE_NO_CIE_FOR_FDE); return (DW_DLV_ERROR); } new_fde->fd_cie = new_cie; *ret_fde = new_fde; return DW_DLV_OK; } int dwarf_get_fde_range(Dwarf_Fde fde, Dwarf_Addr * low_pc, Dwarf_Unsigned * func_length, Dwarf_Ptr * fde_bytes, Dwarf_Unsigned * fde_byte_length, Dwarf_Off * cie_offset, Dwarf_Signed * cie_index, Dwarf_Off * fde_offset, Dwarf_Error * error) { Dwarf_Debug dbg; if (fde == NULL) { _dwarf_error(NULL, error, DW_DLE_FDE_NULL); return (DW_DLV_ERROR); } dbg = fde->fd_dbg; if (dbg == NULL) { _dwarf_error(NULL, error, DW_DLE_FDE_DBG_NULL); return (DW_DLV_ERROR); } /* We have always already done the section load here, so no need to load the section. We did the section load in order to create the Dwarf_Fde pointer passed in here. */ if (low_pc != NULL) *low_pc = fde->fd_initial_location; if (func_length != NULL) *func_length = fde->fd_address_range; if (fde_bytes != NULL) *fde_bytes = fde->fd_fde_start; if (fde_byte_length != NULL) *fde_byte_length = fde->fd_length; if (cie_offset != NULL) *cie_offset = fde->fd_cie_offset; if (cie_index != NULL) *cie_index = fde->fd_cie_index; if (fde_offset != NULL) *fde_offset = fde->fd_fde_start - fde->fd_section_ptr; return DW_DLV_OK; } int dwarf_get_fde_exception_info(Dwarf_Fde fde, Dwarf_Signed * offset_into_exception_tables, Dwarf_Error * error) { Dwarf_Debug dbg; dbg = fde->fd_dbg; if (dbg == NULL) { _dwarf_error(NULL, error, DW_DLE_FDE_DBG_NULL); return (DW_DLV_ERROR); } *offset_into_exception_tables = fde->fd_offset_into_exception_tables; return DW_DLV_OK; } int dwarf_get_cie_info(Dwarf_Cie cie, Dwarf_Unsigned * bytes_in_cie, Dwarf_Small * ptr_to_version, char **augmenter, Dwarf_Unsigned * code_alignment_factor, Dwarf_Signed * data_alignment_factor, Dwarf_Half * return_address_register, Dwarf_Ptr * initial_instructions, Dwarf_Unsigned * initial_instructions_length, Dwarf_Error * error) { Dwarf_Debug dbg; if (cie == NULL) { _dwarf_error(NULL, error, DW_DLE_CIE_NULL); return (DW_DLV_ERROR); } dbg = cie->ci_dbg; if (dbg == NULL) { _dwarf_error(NULL, error, DW_DLE_CIE_DBG_NULL); return (DW_DLV_ERROR); } if (ptr_to_version != NULL) *ptr_to_version = cie->ci_cie_version_number; if (augmenter != NULL) *augmenter = cie->ci_augmentation; if (code_alignment_factor != NULL) *code_alignment_factor = cie->ci_code_alignment_factor; if (data_alignment_factor != NULL) *data_alignment_factor = cie->ci_data_alignment_factor; if (return_address_register != NULL) *return_address_register = cie->ci_return_address_register; if (initial_instructions != NULL) *initial_instructions = cie->ci_cie_instr_start; if (initial_instructions_length != NULL) { *initial_instructions_length = cie->ci_length + cie->ci_length_size + cie->ci_extension_size - (cie->ci_cie_instr_start - cie->ci_cie_start); } *bytes_in_cie = (cie->ci_length); return (DW_DLV_OK); } static int _dwarf_get_fde_info_for_a_pc_row(Dwarf_Fde fde, Dwarf_Addr pc_requested, Dwarf_Frame table, Dwarf_Error * error) /* Return the register rules for all registers at a given pc. */ { Dwarf_Debug dbg; Dwarf_Cie cie; Dwarf_Sword i; int dw_err; Dwarf_Sword icount; int res; if (fde == NULL) { _dwarf_error(NULL, error, DW_DLE_FDE_NULL); return (DW_DLV_ERROR); } dbg = fde->fd_dbg; if (dbg == NULL) { _dwarf_error(NULL, error, DW_DLE_FDE_DBG_NULL); return (DW_DLV_ERROR); } if (pc_requested < fde->fd_initial_location || pc_requested >= fde->fd_initial_location + fde->fd_address_range) { _dwarf_error(dbg, error, DW_DLE_PC_NOT_IN_FDE_RANGE); return (DW_DLV_ERROR); } cie = fde->fd_cie; if (cie->ci_initial_table == NULL) { cie->ci_initial_table = _dwarf_get_alloc(dbg, DW_DLA_FRAME, 1); if (cie->ci_initial_table == NULL) { _dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL); return (DW_DLV_ERROR); } for (i = 0; i < DW_FRAME_LAST_REG_NUM; i++) { cie->ci_initial_table->fr_reg[i].ru_is_off = 0; cie->ci_initial_table->fr_reg[i].ru_register = DW_FRAME_SAME_VAL; cie->ci_initial_table->fr_reg[i].ru_offset = 0; } res = _dwarf_exec_frame_instr( /* make_instr= */ false, /* ret_frame_instr= */ NULL, /* search_pc */ false, /* search_pc_val */ 0, /* location */ 0, cie->ci_cie_instr_start, cie->ci_cie_instr_start + (cie->ci_length + cie->ci_length_size + cie->ci_extension_size - (cie->ci_cie_instr_start - cie->ci_cie_start)), cie->ci_initial_table, cie, dbg, &icount, &dw_err); if (res == DW_DLV_ERROR) { _dwarf_error(dbg, error, dw_err); return (res); } else if (res == DW_DLV_NO_ENTRY) { return res; } } res = _dwarf_exec_frame_instr( /* make_instr= */ false, /* ret_frame_instr= */ NULL, /* search_pc */ true, /* search_pc_val */ pc_requested, fde->fd_initial_location, fde->fd_fde_instr_start, fde->fd_fde_start + fde->fd_length + fde->fd_length_size + fde->fd_extension_size, table, cie, dbg, &icount, &dw_err); if (res == DW_DLV_ERROR) { _dwarf_error(dbg, error, dw_err); return (res); } else if (res == DW_DLV_NO_ENTRY) { return res; } return DW_DLV_OK; } int dwarf_get_fde_info_for_all_regs(Dwarf_Fde fde, Dwarf_Addr pc_requested, Dwarf_Regtable * reg_table, Dwarf_Addr * row_pc, Dwarf_Error * error) { struct Dwarf_Frame_s fde_table; Dwarf_Sword i; int res; /* _dwarf_get_fde_info_for_a_pc_row will perform more sanity checks */ res = _dwarf_get_fde_info_for_a_pc_row(fde, pc_requested, &fde_table, error); if (res != DW_DLV_OK) { return res; } for (i = 0; i < DW_REG_TABLE_SIZE; i++) { reg_table->rules[i].dw_offset_relevant = fde_table.fr_reg[i].ru_is_off; reg_table->rules[i].dw_regnum = fde_table.fr_reg[i].ru_register; reg_table->rules[i].dw_offset = fde_table.fr_reg[i].ru_offset; } if (row_pc != NULL) *row_pc = fde_table.fr_loc; return DW_DLV_OK; } int dwarf_get_fde_info_for_reg(Dwarf_Fde fde, Dwarf_Half table_column, Dwarf_Addr pc_requested, Dwarf_Signed * offset_relevant, Dwarf_Signed * register_num, Dwarf_Signed * offset, Dwarf_Addr * row_pc, Dwarf_Error * error) { struct Dwarf_Frame_s fde_table; int res; if (table_column > DW_FRAME_LAST_REG_NUM) { _dwarf_error(NULL, error, DW_DLE_FRAME_TABLE_COL_BAD); return (DW_DLV_ERROR); } /* _dwarf_get_fde_info_for_a_pc_row will perform more sanity checks */ res = _dwarf_get_fde_info_for_a_pc_row(fde, pc_requested, &fde_table, error); if (res != DW_DLV_OK) { return res; } if (register_num != NULL) *register_num = fde_table.fr_reg[table_column].ru_register; if (offset != NULL) *offset = fde_table.fr_reg[table_column].ru_offset; if (row_pc != NULL) *row_pc = fde_table.fr_loc; *offset_relevant = (fde_table.fr_reg[table_column].ru_is_off); return DW_DLV_OK; } /* Return pointer to the instructions in the dwarf fde. */ int dwarf_get_fde_instr_bytes(Dwarf_Fde inFde, Dwarf_Ptr * outinstraddr, Dwarf_Unsigned * outaddrlen, Dwarf_Error * error) { Dwarf_Unsigned len; unsigned char *instrs; Dwarf_Debug dbg; if (inFde == NULL) { _dwarf_error(NULL, error, DW_DLE_FDE_NULL); return (DW_DLV_ERROR); } dbg = inFde->fd_dbg; if (dbg == NULL) { _dwarf_error(NULL, error, DW_DLE_FDE_DBG_NULL); return (DW_DLV_ERROR); } instrs = inFde->fd_fde_instr_start, len = (inFde->fd_fde_start + inFde->fd_length + inFde->fd_length_size + inFde->fd_extension_size) - instrs; *outinstraddr = instrs; *outaddrlen = len; return DW_DLV_OK; } int dwarf_get_fde_n(Dwarf_Fde * fde_data, Dwarf_Unsigned fde_index, Dwarf_Fde * returned_fde, Dwarf_Error * error) { Dwarf_Debug dbg; if (fde_data == NULL) { _dwarf_error(NULL, error, DW_DLE_FDE_PTR_NULL); return (DW_DLV_ERROR); } if (*fde_data == NULL) { _dwarf_error(NULL, error, DW_DLE_FDE_NULL); return (DW_DLV_ERROR); } dbg = (*fde_data)->fd_dbg; if (dbg == NULL) { _dwarf_error(NULL, error, DW_DLE_FDE_DBG_NULL); return (DW_DLV_ERROR); } if (fde_index >= dbg->de_fde_count) { return (DW_DLV_NO_ENTRY); } *returned_fde = (*(fde_data + fde_index)); return DW_DLV_OK; } /* Lopc and hipc are extensions to the interface to return the range of addresses that are described by the returned fde. */ int dwarf_get_fde_at_pc(Dwarf_Fde * fde_data, Dwarf_Addr pc_of_interest, Dwarf_Fde * returned_fde, Dwarf_Addr * lopc, Dwarf_Addr * hipc, Dwarf_Error * error) { Dwarf_Debug dbg; Dwarf_Fde fde = NULL; if (fde_data == NULL) { _dwarf_error(NULL, error, DW_DLE_FDE_PTR_NULL); return (DW_DLV_ERROR); } if (*fde_data == NULL) { _dwarf_error(NULL, error, DW_DLE_FDE_NULL); return (DW_DLV_ERROR); } dbg = (*fde_data)->fd_dbg; if (dbg == NULL) { _dwarf_error(NULL, error, DW_DLE_FDE_DBG_NULL); return (DW_DLV_ERROR); } { /* The fde's are sorted by their addresses. Binary search to find correct fde. */ int low = 0; int high = dbg->de_fde_count - 1; int middle = 0; Dwarf_Fde cur_fde; while (low <= high) { middle = (low + high) / 2; cur_fde = fde_data[middle]; if (pc_of_interest < cur_fde->fd_initial_location) { high = middle - 1; } else if (pc_of_interest >= (cur_fde->fd_initial_location + cur_fde->fd_address_range)) { low = middle + 1; } else { fde = fde_data[middle]; break; } } } if (fde) { if (lopc != NULL) *lopc = fde->fd_initial_location; if (hipc != NULL) *hipc = fde->fd_initial_location + fde->fd_address_range - 1; *returned_fde = fde; return (DW_DLV_OK); } return (DW_DLV_NO_ENTRY); } int dwarf_expand_frame_instructions(Dwarf_Debug dbg, Dwarf_Ptr instruction, Dwarf_Unsigned i_length, Dwarf_Frame_Op ** returned_op_list, Dwarf_Signed * returned_op_count, Dwarf_Error * error) { Dwarf_Sword instr_count; int res; int dw_err; if (dbg == 0) { _dwarf_error(NULL, error, DW_DLE_DBG_NULL); return (DW_DLV_ERROR); } if (returned_op_list == 0 || returned_op_count == 0) { _dwarf_error(dbg, error, DW_DLE_RET_OP_LIST_NULL); return (DW_DLV_ERROR); } /* The cast to Dwarf_Ptr may get a compiler warning, but it is safe as it is just an i_length offset from 'instruction' itself. A caller has made a big mistake if the result is not a valid pointer. */ res = _dwarf_exec_frame_instr( /* make_instr= */ true, returned_op_list, /* search_pc */ false, /* search_pc_val */ 0, /* location */ 0, instruction, (Dwarf_Ptr) (instruction + i_length), /* Dwarf_Frame */ NULL, /* cie_ptr */ NULL, dbg, &instr_count, &dw_err); if (res != DW_DLV_OK) { if (res == DW_DLV_ERROR) { _dwarf_error(dbg, error, dw_err); } return (res); } *returned_op_count = instr_count; return DW_DLV_OK; } /* Used by rqs. Returns DW_DLV_OK if returns the arrays. Returns DW_DLV_NO_ENTRY if no section. ?? (How do I tell?) Returns DW_DLV_ERROR if there is an error. */ int _dwarf_frame_address_offsets(Dwarf_Debug dbg, Dwarf_Addr ** addrlist, Dwarf_Off ** offsetlist, Dwarf_Signed * returncount, Dwarf_Error * err) { int retval = DW_DLV_OK; int res; Dwarf_Cie *cie_data; Dwarf_Signed cie_count; Dwarf_Fde *fde_data; Dwarf_Signed fde_count; Dwarf_Signed i; Dwarf_Frame_Op *frame_inst; Dwarf_Fde fdep; Dwarf_Cie ciep; Dwarf_Chain curr_chain = 0; Dwarf_Chain head_chain = 0; Dwarf_Chain prev_chain = 0; Dwarf_Arange arange; Dwarf_Unsigned arange_count = 0; Dwarf_Addr *arange_addrs = 0; Dwarf_Off *arange_offsets = 0; res = dwarf_get_fde_list(dbg, &cie_data, &cie_count, &fde_data, &fde_count, err); if (res != DW_DLV_OK) { return res; } res = _dwarf_load_section(dbg, dbg->de_debug_frame_index, &dbg->de_debug_frame, err); if (res != DW_DLV_OK) { return res; } for (i = 0; i < cie_count; i++) { Dwarf_Off instoff = 0; Dwarf_Signed initial_instructions_length = 0; Dwarf_Small *instr_end = 0; Dwarf_Sword icount = 0; int j; int dw_err; ciep = cie_data[i]; instoff = ciep->ci_cie_instr_start - dbg->de_debug_frame; initial_instructions_length = ciep->ci_length + ciep->ci_length_size + ciep->ci_extension_size - (ciep->ci_cie_instr_start - ciep->ci_cie_start); instr_end = ciep->ci_cie_instr_start + initial_instructions_length; res = _dwarf_exec_frame_instr( /* make_instr */ true, &frame_inst, /* search_pc= */ false, /* search_pc_val= */ 0, /* location */ 0, ciep->ci_cie_instr_start, instr_end, /* Dwarf_frame= */ 0, /* cie= */ 0, dbg, &icount, &dw_err); if (res == DW_DLV_ERROR) { _dwarf_error(dbg, err, dw_err); return (res); } else if (res == DW_DLV_NO_ENTRY) { continue; } for (j = 0; j < icount; ++j) { Dwarf_Frame_Op *finst = frame_inst + j; if (finst->fp_base_op == 0 && finst->fp_extended_op == 1) { /* is DW_CFA_set_loc */ Dwarf_Addr add = (Dwarf_Addr) finst->fp_offset; Dwarf_Off off = finst->fp_instr_offset + instoff; arange = (Dwarf_Arange) _dwarf_get_alloc(dbg, DW_DLA_ARANGE, 1); if (arange == NULL) { _dwarf_error(dbg, err, DW_DLE_ALLOC_FAIL); return (DW_DLV_ERROR); } arange->ar_address = add; arange->ar_info_offset = off; arange_count++; curr_chain = (Dwarf_Chain) _dwarf_get_alloc(dbg, DW_DLA_CHAIN, 1); if (curr_chain == NULL) { _dwarf_error(dbg, err, DW_DLE_ALLOC_FAIL); return (DW_DLV_ERROR); } curr_chain->ch_item = arange; if (head_chain == NULL) head_chain = prev_chain = curr_chain; else { prev_chain->ch_next = curr_chain; prev_chain = curr_chain; } } } dwarf_dealloc(dbg, frame_inst, DW_DLA_FRAME_BLOCK); } for (i = 0; i < fde_count; i++) { Dwarf_Small *instr_end = 0; Dwarf_Sword icount = 0; Dwarf_Signed instructions_length = 0; Dwarf_Off instoff = 0; Dwarf_Off off = 0; Dwarf_Addr addr = 0; int j; int dw_err; fdep = fde_data[i]; off = fdep->fd_initial_loc_pos - dbg->de_debug_frame; addr = fdep->fd_initial_location; arange = (Dwarf_Arange) _dwarf_get_alloc(dbg, DW_DLA_ARANGE, 1); if (arange == NULL) { _dwarf_error(dbg, err, DW_DLE_ALLOC_FAIL); return (DW_DLV_ERROR); } arange->ar_address = addr; arange->ar_info_offset = off; arange_count++; curr_chain = (Dwarf_Chain) _dwarf_get_alloc(dbg, DW_DLA_CHAIN, 1); if (curr_chain == NULL) { _dwarf_error(dbg, err, DW_DLE_ALLOC_FAIL); return (DW_DLV_ERROR); } curr_chain->ch_item = arange; if (head_chain == NULL) head_chain = prev_chain = curr_chain; else { prev_chain->ch_next = curr_chain; prev_chain = curr_chain; } instoff = fdep->fd_fde_instr_start - dbg->de_debug_frame; instructions_length = fdep->fd_length + fdep->fd_length_size + fdep->fd_extension_size - (fdep->fd_fde_instr_start - fdep->fd_fde_start); instr_end = fdep->fd_fde_instr_start + instructions_length; res = _dwarf_exec_frame_instr( /* make_instr */ true, &frame_inst, /* search_pc= */ false, /* search_pc_val= */ 0, /* location */ 0, fdep->fd_fde_instr_start, instr_end, /* Dwarf_frame= */ 0, /* cie= */ 0, dbg, &icount, &dw_err); if (res == DW_DLV_ERROR) { _dwarf_error(dbg, err, dw_err); return (res); } else if (res == DW_DLV_NO_ENTRY) { continue; } for (j = 0; j < icount; ++j) { Dwarf_Frame_Op *finst2 = frame_inst + j; if (finst2->fp_base_op == 0 && finst2->fp_extended_op == 1) { /* is DW_CFA_set_loc */ Dwarf_Addr add = (Dwarf_Addr) finst2->fp_offset; Dwarf_Off off = finst2->fp_instr_offset + instoff; arange = (Dwarf_Arange) _dwarf_get_alloc(dbg, DW_DLA_ARANGE, 1); if (arange == NULL) { _dwarf_error(dbg, err, DW_DLE_ALLOC_FAIL); return (DW_DLV_ERROR); } arange->ar_address = add; arange->ar_info_offset = off; arange_count++; curr_chain = (Dwarf_Chain) _dwarf_get_alloc(dbg, DW_DLA_CHAIN, 1); if (curr_chain == NULL) { _dwarf_error(dbg, err, DW_DLE_ALLOC_FAIL); return (DW_DLV_ERROR); } curr_chain->ch_item = arange; if (head_chain == NULL) head_chain = prev_chain = curr_chain; else { prev_chain->ch_next = curr_chain; prev_chain = curr_chain; } } } dwarf_dealloc(dbg, frame_inst, DW_DLA_FRAME_BLOCK); } dwarf_dealloc(dbg, fde_data, DW_DLA_LIST); dwarf_dealloc(dbg, cie_data, DW_DLA_LIST); arange_addrs = (Dwarf_Addr *) _dwarf_get_alloc(dbg, DW_DLA_ADDR, arange_count); if (arange_addrs == NULL) { _dwarf_error(dbg, err, DW_DLE_ALLOC_FAIL); return (DW_DLV_ERROR); } arange_offsets = (Dwarf_Off *) _dwarf_get_alloc(dbg, DW_DLA_ADDR, arange_count); if (arange_offsets == NULL) { _dwarf_error(dbg, err, DW_DLE_ALLOC_FAIL); return (DW_DLV_ERROR); } curr_chain = head_chain; for (i = 0; i < arange_count; i++) { Dwarf_Arange ar = curr_chain->ch_item; arange_addrs[i] = ar->ar_address; arange_offsets[i] = ar->ar_info_offset; prev_chain = curr_chain; curr_chain = curr_chain->ch_next; dwarf_dealloc(dbg, ar, DW_DLA_ARANGE); dwarf_dealloc(dbg, prev_chain, DW_DLA_CHAIN); } *returncount = arange_count; *offsetlist = arange_offsets; *addrlist = arange_addrs; return retval; } /* Used by dwarfdump -v to print offsets, for debugging dwarf info */ /* ARGSUSED 4 */ int _dwarf_fde_section_offset(Dwarf_Debug dbg, Dwarf_Fde in_fde, Dwarf_Off * fde_off, Dwarf_Off * cie_off, Dwarf_Error * err) { int res; char *start; char *loc; res = _dwarf_load_section(dbg, dbg->de_debug_frame_index, &dbg->de_debug_frame, err); if (res != DW_DLV_OK) { return res; } start = (char *) dbg->de_debug_frame; loc = (char *) in_fde->fd_fde_start; *fde_off = (loc - start); *cie_off = in_fde->fd_cie_offset; return DW_DLV_OK; } /* Used by dwarfdump -v to print offsets, for debugging dwarf info */ /* ARGSUSED 4 */ int _dwarf_cie_section_offset(Dwarf_Debug dbg, Dwarf_Cie in_cie, Dwarf_Off * cie_off, Dwarf_Error * err) { int res; char *start; char *loc; res = _dwarf_load_section(dbg, dbg->de_debug_frame_index, &dbg->de_debug_frame, err); if (res != DW_DLV_OK) { return res; } start = (char *) dbg->de_debug_frame; loc = (char *) in_cie->ci_cie_start; *cie_off = (loc - start); return DW_DLV_OK; }
722,009
./hicuda/src/osprey/libdwarf/libdwarf/dwarf_print_lines.c
/* * Copyright 2005, 2006 PathScale, Inc. All Rights Reserved. */ /* Copyright (C) 2000,2002,2004 Silicon Graphics, Inc. All Rights Reserved. This program is free software; you can redistribute it and/or modify it under the terms of version 2.1 of the GNU Lesser General Public License as published by the Free Software Foundation. This program is distributed in the hope that it would be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Further, this software is distributed without any warranty that it is free of the rightful claim of any third person regarding infringement or the like. Any license provided herein, whether implied or otherwise, applies only to this software file. Patent licenses, if any, provided herein do not apply to combinations of this program with other software, or any other product whatsoever. You should have received a copy of the GNU Lesser General Public License along with this program; if not, write the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA. Contact information: Silicon Graphics, Inc., 1500 Crittenden Lane, Mountain View, CA 94043, or: http://www.sgi.com For further information regarding this notice, see: http://oss.sgi.com/projects/GenInfo/NoticeExplan */ #include "config.h" #include "dwarf_incl.h" #include <stdio.h> #include <time.h> #include "dwarf_line.h" #ifdef HAVE_ALLOCA_H #include <alloca.h> #endif static void print_line_header(void) { printf (" s b e\n" " t l s\n" " m c e\n" " section op col t k q\n" " offset code address file line umn ? ? ?\n"); } static void print_line_detail(char *prefix, int opcode, unsigned long long address, unsigned long file, unsigned long line, unsigned long column, int is_stmt, int basic_block, int end_sequence) { printf("%-15s %2d 0x%08llx " "%2lu %4lu %2lu %1d %1d %1d\n", prefix, (int) opcode, (long long) address, (unsigned long) file, (unsigned long) line, (unsigned long) column, (int) is_stmt, (int) basic_block, (int) end_sequence); } /* return DW_DLV_OK if ok. else DW_DLV_NO_ENTRY or DW_DLV_ERROR */ int _dwarf_internal_printlines(Dwarf_Die die, Dwarf_Error * error) { /* This pointer is used to scan the portion of the .debug_line section for the current cu. */ Dwarf_Small *line_ptr; Dwarf_Small *orig_line_ptr; /* This points to the last byte of the .debug_line portion for the current cu. */ Dwarf_Small *line_ptr_end; /* This points to the end of the statement program prologue for the current cu, and serves to check that the prologue was correctly decoded. */ Dwarf_Small *check_line_ptr; /* Pointer to a DW_AT_stmt_list attribute in case it exists in the die. */ Dwarf_Attribute stmt_list_attr; /* Pointer to DW_AT_comp_dir attribute in die. */ Dwarf_Attribute comp_dir_attr; /* Pointer to name of compilation directory. */ Dwarf_Small *comp_dir = NULL; /* Offset into .debug_line specified by a DW_AT_stmt_list attribute. */ Dwarf_Unsigned line_offset; /* These are the fields of the statement program header. */ Dwarf_Unsigned total_length; Dwarf_Half version; Dwarf_Unsigned prologue_length; Dwarf_Small minimum_instruction_length; Dwarf_Small default_is_stmt; Dwarf_Sbyte line_base; Dwarf_Small line_range; Dwarf_Small opcode_base; Dwarf_Small *opcode_length; /* These are the state machine state variables. */ Dwarf_Addr address; Dwarf_Word file; Dwarf_Word line; Dwarf_Word column; Dwarf_Bool is_stmt; Dwarf_Bool basic_block; Dwarf_Bool end_sequence; Dwarf_Sword i, file_entry_count, include_directories_count; /* This is the current opcode read from the statement program. */ Dwarf_Small opcode; /* Pointer to a Dwarf_Line_Context_s structure that contains the context such as file names and include directories for the set of lines being generated. */ Dwarf_Line_Context line_context; /* These variables are used to decode leb128 numbers. Leb128_num holds the decoded number, and leb128_length is its length in bytes. */ Dwarf_Word leb128_num; Dwarf_Word leb128_length; Dwarf_Sword advance_line; /* This is the operand of the latest fixed_advance_pc extended opcode. */ Dwarf_Half fixed_advance_pc; /* This is the length of an extended opcode instr. */ Dwarf_Word instr_length; Dwarf_Small ext_opcode; int local_length_size; /*REFERENCED*/ /* Not used in this instance of the macro */ int local_extension_size; /* The Dwarf_Debug this die belongs to. */ Dwarf_Debug dbg; int resattr; int lres; int res; /* ***** BEGIN CODE ***** */ if (error != NULL) *error = NULL; CHECK_DIE(die, DW_DLV_ERROR) dbg = die->di_cu_context->cc_dbg; res = _dwarf_load_section(dbg, dbg->de_debug_line_index, &dbg->de_debug_line, error); if (res != DW_DLV_OK) { return res; } resattr = dwarf_attr(die, DW_AT_stmt_list, &stmt_list_attr, error); if (resattr != DW_DLV_OK) { return resattr; } lres = dwarf_formudata(stmt_list_attr, &line_offset, error); if (lres != DW_DLV_OK) { return lres; } if (line_offset >= dbg->de_debug_line_size) { _dwarf_error(dbg, error, DW_DLE_LINE_OFFSET_BAD); return (DW_DLV_ERROR); } orig_line_ptr = dbg->de_debug_line; line_ptr = dbg->de_debug_line + line_offset; dwarf_dealloc(dbg, stmt_list_attr, DW_DLA_ATTR); /* If die has DW_AT_comp_dir attribute, get the string that names the compilation directory. */ resattr = dwarf_attr(die, DW_AT_comp_dir, &comp_dir_attr, error); if (resattr == DW_DLV_ERROR) { return resattr; } if (resattr == DW_DLV_OK) { int cres; char *cdir; cres = dwarf_formstring(comp_dir_attr, &cdir, error); if (cres == DW_DLV_ERROR) { return cres; } else if (cres == DW_DLV_OK) { comp_dir = (Dwarf_Small *) cdir; } } if (resattr == DW_DLV_OK) { dwarf_dealloc(dbg, comp_dir_attr, DW_DLA_ATTR); } /* Following is a straightforward decoding of the statement program prologue information. */ /* READ_AREA_LENGTH updates line_ptr for consumed bytes */ READ_AREA_LENGTH(dbg, total_length, Dwarf_Unsigned, line_ptr, local_length_size, local_extension_size); line_ptr_end = line_ptr + total_length; if (line_ptr_end > dbg->de_debug_line + dbg->de_debug_line_size) { _dwarf_error(dbg, error, DW_DLE_DEBUG_LINE_LENGTH_BAD); return (DW_DLV_ERROR); } printf("total line info length %ld bytes, " "line offset 0x%llx %lld\n", (long) total_length, (long long) line_offset, (long long) line_offset); printf("compilation_directory %s\n", comp_dir ? ((char *) comp_dir) : ""); READ_UNALIGNED(dbg, version, Dwarf_Half, line_ptr, sizeof(Dwarf_Half)); line_ptr += sizeof(Dwarf_Half); if (version != CURRENT_VERSION_STAMP) { _dwarf_error(dbg, error, DW_DLE_VERSION_STAMP_ERROR); return (DW_DLV_ERROR); } READ_UNALIGNED(dbg, prologue_length, Dwarf_Unsigned, line_ptr, local_length_size); line_ptr += local_length_size; check_line_ptr = line_ptr; minimum_instruction_length = *(Dwarf_Small *) line_ptr; line_ptr = line_ptr + sizeof(Dwarf_Small); default_is_stmt = *(Dwarf_Small *) line_ptr; line_ptr = line_ptr + sizeof(Dwarf_Small); line_base = *(Dwarf_Sbyte *) line_ptr; line_ptr = line_ptr + sizeof(Dwarf_Sbyte); line_range = *(Dwarf_Small *) line_ptr; line_ptr = line_ptr + sizeof(Dwarf_Small); opcode_base = *(Dwarf_Small *) line_ptr; line_ptr = line_ptr + sizeof(Dwarf_Small); printf(" min instruction length %d\n", (int) minimum_instruction_length); printf(" default is stmt %d\n", (int) default_is_stmt); printf(" line base %d\n", (int) line_base); printf(" line_range %d\n", (int) line_range); opcode_length = (Dwarf_Small *) alloca(sizeof(Dwarf_Small) * opcode_base); for (i = 1; i < opcode_base; i++) { opcode_length[i] = *(Dwarf_Small *) line_ptr; printf(" opcode[%d] length %d\n", (int) i, (int) opcode_length[i]); line_ptr = line_ptr + sizeof(Dwarf_Small); } include_directories_count = 0; while ((*(char *) line_ptr) != '\0') { printf(" include dir[%d] %s\n", (int) include_directories_count, line_ptr); line_ptr = line_ptr + strlen((char *) line_ptr) + 1; include_directories_count++; } line_ptr++; file_entry_count = 0; while (*(char *) line_ptr != '\0') { Dwarf_Unsigned tlm2; Dwarf_Unsigned di; Dwarf_Unsigned fl; printf(" file[%d] %s\n", (int) file_entry_count, (char *) line_ptr); line_ptr = line_ptr + strlen((char *) line_ptr) + 1; di = _dwarf_decode_u_leb128(line_ptr, &leb128_length); line_ptr = line_ptr + leb128_length; tlm2 = _dwarf_decode_u_leb128(line_ptr, &leb128_length); line_ptr = line_ptr + leb128_length; fl = _dwarf_decode_u_leb128(line_ptr, &leb128_length); line_ptr = line_ptr + leb128_length; printf(" dir index %d\n", (int) di); { time_t tt = (time_t) tlm2; printf(" last time 0x%x %s", /* ctime supplies newline */ (unsigned) tlm2, ctime(&tt)); } printf(" file length %ld 0x%lx\n", (long) fl, (unsigned long) fl); file_entry_count++; } line_ptr++; if (line_ptr != check_line_ptr + prologue_length) { _dwarf_error(dbg, error, DW_DLE_LINE_PROLOG_LENGTH_BAD); return (DW_DLV_ERROR); } /* Set up context structure for this set of lines. */ line_context = (Dwarf_Line_Context) _dwarf_get_alloc(dbg, DW_DLA_LINE_CONTEXT, 1); if (line_context == NULL) { _dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL); return (DW_DLV_ERROR); } printf(" statement prog offset in section: %lld 0x%llx\n", (long long) (line_ptr - orig_line_ptr), (long long) (line_ptr - orig_line_ptr)); /* Initialize the state machine. */ address = 0; file = 1; line = 1; column = 0; is_stmt = default_is_stmt; basic_block = false; end_sequence = false; print_line_header(); /* Start of statement program. */ while (line_ptr < line_ptr_end) { int type; printf(" [0x%06llx] ", (long long) (line_ptr - orig_line_ptr)); opcode = *(Dwarf_Small *) line_ptr; line_ptr++; /* 'type' is the output */ WHAT_IS_OPCODE(type, opcode, opcode_base, opcode_length, line_ptr); if (type == LOP_DISCARD) { /* do nothing, necessary ops done */ } else if (type == LOP_SPECIAL) { /* This op code is a special op in the object, no matter that it might fall into the standard op range in this compile Thatis, these are special opcodes between special_opcode_base and MAX_LINE_OP_CODE. (including special_opcode_base and MAX_LINE_OP_CODE) */ char special[50]; unsigned origop = opcode; opcode = opcode - opcode_base; address = address + minimum_instruction_length * (opcode / line_range); line = line + line_base + opcode % line_range; sprintf(special, "Specialop %3u", origop); print_line_detail(special, opcode, address, (int) file, line, column, is_stmt, basic_block, end_sequence); basic_block = false; } else if (type == LOP_STANDARD) { switch (opcode) { case DW_LNS_copy:{ if (opcode_length[DW_LNS_copy] != 0) { _dwarf_error(dbg, error, DW_DLE_LINE_NUM_OPERANDS_BAD); return (DW_DLV_ERROR); } print_line_detail("DW_LNS_copy", opcode, address, file, line, column, is_stmt, basic_block, end_sequence); basic_block = false; break; } case DW_LNS_advance_pc:{ Dwarf_Unsigned utmp2; if (opcode_length[DW_LNS_advance_pc] != 1) { _dwarf_error(dbg, error, DW_DLE_LINE_NUM_OPERANDS_BAD); return (DW_DLV_ERROR); } DECODE_LEB128_UWORD(line_ptr, utmp2) printf("DW_LNS_advance_pc val %lld 0x%llx\n", (long long) (Dwarf_Word) utmp2, (long long) (Dwarf_Word) utmp2); leb128_num = (Dwarf_Word) utmp2; address = address + minimum_instruction_length * leb128_num; break; } case DW_LNS_advance_line:{ Dwarf_Signed stmp; if (opcode_length[DW_LNS_advance_line] != 1) { _dwarf_error(dbg, error, DW_DLE_LINE_NUM_OPERANDS_BAD); return (DW_DLV_ERROR); } DECODE_LEB128_SWORD(line_ptr, stmp) advance_line = (Dwarf_Sword) stmp; printf("DW_LNS_advance_line val %lld 0x%llx\n", (long long) advance_line, (long long) advance_line); line = line + advance_line; break; } case DW_LNS_set_file:{ Dwarf_Unsigned utmp2; if (opcode_length[DW_LNS_set_file] != 1) { _dwarf_error(dbg, error, DW_DLE_LINE_NUM_OPERANDS_BAD); return (DW_DLV_ERROR); } DECODE_LEB128_UWORD(line_ptr, utmp2) file = (Dwarf_Word) utmp2; printf("DW_LNS_set_file %ld\n", (long) file); break; } case DW_LNS_set_column:{ Dwarf_Unsigned utmp2; if (opcode_length[DW_LNS_set_column] != 1) { _dwarf_error(dbg, error, DW_DLE_LINE_NUM_OPERANDS_BAD); return (DW_DLV_ERROR); } DECODE_LEB128_UWORD(line_ptr, utmp2) column = (Dwarf_Word) utmp2; printf("DW_LNS_set_column val %lld 0x%llx\n", (long long) column, (long long) column); break; } case DW_LNS_negate_stmt:{ if (opcode_length[DW_LNS_negate_stmt] != 0) { _dwarf_error(dbg, error, DW_DLE_LINE_NUM_OPERANDS_BAD); return (DW_DLV_ERROR); } is_stmt = !is_stmt; printf("DW_LNS_negate_stmt\n"); break; } case DW_LNS_set_basic_block:{ if (opcode_length[DW_LNS_set_basic_block] != 0) { _dwarf_error(dbg, error, DW_DLE_LINE_NUM_OPERANDS_BAD); return (DW_DLV_ERROR); } printf("DW_LNS_set_basic_block\n"); basic_block = true; break; } case DW_LNS_const_add_pc:{ opcode = MAX_LINE_OP_CODE - opcode_base; address = address + minimum_instruction_length * (opcode / line_range); printf("DW_LNS_const_add_pc new address 0x%llx\n", (long long) address); break; } case DW_LNS_fixed_advance_pc:{ if (opcode_length[DW_LNS_fixed_advance_pc] != 1) { _dwarf_error(dbg, error, DW_DLE_LINE_NUM_OPERANDS_BAD); return (DW_DLV_ERROR); } READ_UNALIGNED(dbg, fixed_advance_pc, Dwarf_Half, line_ptr, sizeof(Dwarf_Half)); line_ptr += sizeof(Dwarf_Half); address = address + fixed_advance_pc; printf("DW_LNS_fixed_advance_pc val %lld 0x%llx" " new address 0x%llx\n", (long long) fixed_advance_pc, (long long) fixed_advance_pc, (long long) address); break; } } } else if (type == LOP_EXTENDED) { Dwarf_Unsigned utmp3; DECODE_LEB128_UWORD(line_ptr, utmp3) instr_length = (Dwarf_Word) utmp3; ext_opcode = *(Dwarf_Small *) line_ptr; line_ptr++; switch (ext_opcode) { case DW_LNE_end_sequence:{ end_sequence = true; print_line_detail("DW_LNE_end_sequence extended", opcode, address, file, line, column, is_stmt, basic_block, end_sequence); address = 0; file = 1; line = 1; column = 0; is_stmt = default_is_stmt; basic_block = false; end_sequence = false; break; } case DW_LNE_set_address:{ if (instr_length - 1 == dbg->de_pointer_size) { READ_UNALIGNED(dbg, address, Dwarf_Addr, line_ptr, dbg->de_pointer_size); line_ptr += dbg->de_pointer_size; printf("DW_LNE_set_address address 0x%llx\n", (long long) address); } else { _dwarf_error(dbg, error, DW_DLE_LINE_SET_ADDR_ERROR); return (DW_DLV_ERROR); } break; } case DW_LNE_define_file:{ Dwarf_Small *fn; Dwarf_Signed di; Dwarf_Signed tlm; Dwarf_Unsigned fl; fn = (Dwarf_Small *) line_ptr; line_ptr = line_ptr + strlen((char *) line_ptr) + 1; di = _dwarf_decode_u_leb128(line_ptr, &leb128_length); line_ptr = line_ptr + leb128_length; tlm = _dwarf_decode_u_leb128(line_ptr, &leb128_length); line_ptr = line_ptr + leb128_length; fl = _dwarf_decode_u_leb128(line_ptr, &leb128_length); line_ptr = line_ptr + leb128_length; printf("DW_LNE_define_file %s \n", fn); printf(" dir index %d\n", (int) di); { time_t tt3 = (time_t) tlm; /* ctime supplies newline */ printf(" last time 0x%x %s", (unsigned) tlm, ctime(&tt3)); } printf(" file length %ld 0x%lx\n", (long) fl, (unsigned long) fl); break; } default:{ _dwarf_error(dbg, error, DW_DLE_LINE_EXT_OPCODE_BAD); return (DW_DLV_ERROR); } } } } return (DW_DLV_OK); } /* Caller passes in compilation unit DIE. */ int _dwarf_print_lines(Dwarf_Die die, Dwarf_Error * error) { int res; res = _dwarf_internal_printlines(die, error); if (res != DW_DLV_OK) { return res; } return res; }
722,010
./hicuda/src/osprey/libdwarf/libdwarf/dwarf_weaks.c
/* * Copyright 2005, 2006 PathScale, Inc. All Rights Reserved. */ /* Copyright (C) 2000,2002,2004 Silicon Graphics, Inc. All Rights Reserved. This program is free software; you can redistribute it and/or modify it under the terms of version 2.1 of the GNU Lesser General Public License as published by the Free Software Foundation. This program is distributed in the hope that it would be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Further, this software is distributed without any warranty that it is free of the rightful claim of any third person regarding infringement or the like. Any license provided herein, whether implied or otherwise, applies only to this software file. Patent licenses, if any, provided herein do not apply to combinations of this program with other software, or any other product whatsoever. You should have received a copy of the GNU Lesser General Public License along with this program; if not, write the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA. Contact information: Silicon Graphics, Inc., 1500 Crittenden Lane, Mountain View, CA 94043, or: http://www.sgi.com For further information regarding this notice, see: http://oss.sgi.com/projects/GenInfo/NoticeExplan */ #include "config.h" #include "dwarf_incl.h" #include <stdio.h> #include "dwarf_weaks.h" #include "dwarf_global.h" int dwarf_get_weaks(Dwarf_Debug dbg, Dwarf_Weak ** weaks, Dwarf_Signed * ret_weak_count, Dwarf_Error * error) { int res; res = _dwarf_load_section(dbg, dbg->de_debug_weaknames_index, &dbg->de_debug_weaknames, error); if (res != DW_DLV_OK) { return res; } return _dwarf_internal_get_pubnames_like_data(dbg, dbg->de_debug_weaknames, dbg->de_debug_weaknames_size, (Dwarf_Global **) weaks, /* type punning, Dwarf_Type is never a completed type */ ret_weak_count, error, DW_DLA_WEAK_CONTEXT, DW_DLE_DEBUG_WEAKNAMES_LENGTH_BAD, DW_DLE_DEBUG_WEAKNAMES_VERSION_ERROR); } int dwarf_weakname(Dwarf_Weak weak_in, char **ret_name, Dwarf_Error * error) { Dwarf_Global weak = (Dwarf_Global) weak_in; if (weak == NULL) { _dwarf_error(NULL, error, DW_DLE_WEAK_NULL); return (DW_DLV_ERROR); } *ret_name = (char *) (weak->gl_name); return DW_DLV_OK; } int dwarf_weak_die_offset(Dwarf_Weak weak_in, Dwarf_Off * weak_off, Dwarf_Error * error) { Dwarf_Global weak = (Dwarf_Global) weak_in; return dwarf_global_die_offset(weak, weak_off, error); } int dwarf_weak_cu_offset(Dwarf_Weak weak_in, Dwarf_Off * weak_off, Dwarf_Error * error) { Dwarf_Global weak = (Dwarf_Global) weak_in; return dwarf_global_cu_offset(weak, weak_off, error); } int dwarf_weak_name_offsets(Dwarf_Weak weak_in, char **weak_name, Dwarf_Off * die_offset, Dwarf_Off * cu_offset, Dwarf_Error * error) { Dwarf_Global weak = (Dwarf_Global) weak_in; return dwarf_global_name_offsets(weak, weak_name, die_offset, cu_offset, error); }
722,011
./hicuda/src/osprey/libdwarf/libdwarf/dwarf_arange.c
/* * Copyright 2005, 2006 PathScale, Inc. All Rights Reserved. */ /* Copyright (C) 2000,2002,2004 Silicon Graphics, Inc. All Rights Reserved. This program is free software; you can redistribute it and/or modify it under the terms of version 2.1 of the GNU Lesser General Public License as published by the Free Software Foundation. This program is distributed in the hope that it would be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Further, this software is distributed without any warranty that it is free of the rightful claim of any third person regarding infringement or the like. Any license provided herein, whether implied or otherwise, applies only to this software file. Patent licenses, if any, provided herein do not apply to combinations of this program with other software, or any other product whatsoever. You should have received a copy of the GNU Lesser General Public License along with this program; if not, write the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA. Contact information: Silicon Graphics, Inc., 1500 Crittenden Lane, Mountain View, CA 94043, or: http://www.sgi.com For further information regarding this notice, see: http://oss.sgi.com/projects/GenInfo/NoticeExplan */ #include "config.h" #include "dwarf_incl.h" #include <stdio.h> #include "dwarf_arange.h" /* This function returns the count of the number of aranges in the .debug_aranges section. It sets aranges to point to a block of Dwarf_Arange's describing the arange's. It returns DW_DLV_ERROR on error. Must be identical in most aspects to dwarf_get_aranges_addr_offsets! */ int dwarf_get_aranges(Dwarf_Debug dbg, Dwarf_Arange ** aranges, Dwarf_Signed * returned_count, Dwarf_Error * error) { /* Sweeps the .debug_aranges section. */ Dwarf_Small *arange_ptr; /* Start of arange header. Used for rounding offset of arange_ptr to twice the tuple size. Libdwarf requirement. */ Dwarf_Small *header_ptr; /* Version of .debug_aranges header. */ Dwarf_Half version; /* Offset of current set of aranges into .debug_info. */ Dwarf_Off info_offset; /* Size in bytes of addresses in target. */ Dwarf_Small address_size; /* Size in bytes of segment offsets in target. */ Dwarf_Small segment_size; Dwarf_Small remainder; /* Count of total number of aranges. */ Dwarf_Unsigned arange_count = 0; /* Start address of arange. */ Dwarf_Addr range_address; /* Length of arange. */ Dwarf_Unsigned range_length; Dwarf_Arange arange, *arange_block; Dwarf_Unsigned i; /* Used to chain Dwarf_Aranges structs. */ Dwarf_Chain curr_chain, prev_chain, head_chain = NULL; int res; /* ***** BEGIN CODE ***** */ if (dbg == NULL) { _dwarf_error(NULL, error, DW_DLE_DBG_NULL); return (DW_DLV_ERROR); } res = _dwarf_load_section(dbg, dbg->de_debug_aranges_index, &dbg->de_debug_aranges, error); if (res != DW_DLV_OK) { return res; } arange_ptr = dbg->de_debug_aranges; do { /* Length of current set of aranges. */ Dwarf_Unsigned length; Dwarf_Small *arange_ptr_past_end = 0; int local_length_size; /*REFERENCED*/ /* Not used in this instance of the macro */ int local_extension_size; header_ptr = arange_ptr; /* READ_AREA_LENGTH updates arange_ptr for consumed bytes */ READ_AREA_LENGTH(dbg, length, Dwarf_Unsigned, arange_ptr, local_length_size, local_extension_size); arange_ptr_past_end = arange_ptr + length; READ_UNALIGNED(dbg, version, Dwarf_Half, arange_ptr, sizeof(Dwarf_Half)); arange_ptr += sizeof(Dwarf_Half); length = length - sizeof(Dwarf_Half); if (version != CURRENT_VERSION_STAMP) { _dwarf_error(dbg, error, DW_DLE_VERSION_STAMP_ERROR); return (DW_DLV_ERROR); } READ_UNALIGNED(dbg, info_offset, Dwarf_Off, arange_ptr, local_length_size); arange_ptr += local_length_size; length = length - local_length_size; if (info_offset >= dbg->de_debug_info_size) { _dwarf_error(dbg, error, DW_DLE_ARANGE_OFFSET_BAD); return (DW_DLV_ERROR); } address_size = *(Dwarf_Small *) arange_ptr; if (address_size != dbg->de_pointer_size) { /* Internal error of some kind */ _dwarf_error(dbg, error, DW_DLE_BADBITC); return (DW_DLV_ERROR); } arange_ptr = arange_ptr + sizeof(Dwarf_Small); length = length - sizeof(Dwarf_Small); segment_size = *(Dwarf_Small *) arange_ptr; arange_ptr = arange_ptr + sizeof(Dwarf_Small); length = length - sizeof(Dwarf_Small); if (segment_size != 0) { _dwarf_error(dbg, error, DW_DLE_SEGMENT_SIZE_BAD); return (DW_DLV_ERROR); } /* Round arange_ptr offset to next multiple of address_size. */ remainder = (Dwarf_Unsigned) (arange_ptr - header_ptr) % (2 * address_size); if (remainder != 0) { arange_ptr = arange_ptr + (2 * address_size) - remainder; length = length - ((2 * address_size) - remainder); } do { READ_UNALIGNED(dbg, range_address, Dwarf_Addr, arange_ptr, address_size); arange_ptr += address_size; length = length - address_size; READ_UNALIGNED(dbg, range_length, Dwarf_Unsigned, arange_ptr, address_size); arange_ptr += address_size; length = length - address_size; if (range_address != 0 || range_length != 0) { arange = (Dwarf_Arange) _dwarf_get_alloc(dbg, DW_DLA_ARANGE, 1); if (arange == NULL) { _dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL); return (DW_DLV_ERROR); } arange->ar_address = range_address; arange->ar_length = range_length; arange->ar_info_offset = info_offset; arange->ar_dbg = dbg; arange_count++; curr_chain = (Dwarf_Chain) _dwarf_get_alloc(dbg, DW_DLA_CHAIN, 1); if (curr_chain == NULL) { _dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL); return (DW_DLV_ERROR); } curr_chain->ch_item = arange; if (head_chain == NULL) head_chain = prev_chain = curr_chain; else { prev_chain->ch_next = curr_chain; prev_chain = curr_chain; } } } while (range_address != 0 || range_length != 0); /* A compiler could emit some padding bytes here. dwarf2/3 (dwarf3 draft8 sec 7.20) does not clearly make extra padding bytes illegal. */ if(arange_ptr_past_end < arange_ptr) { _dwarf_error(dbg, error, DW_DLE_ARANGE_LENGTH_BAD); return (DW_DLV_ERROR); } /* For most compilers, arange_ptr == arange_ptr_past_end at this point. But not if there were padding bytes */ arange_ptr = arange_ptr_past_end; } while (arange_ptr < dbg->de_debug_aranges + dbg->de_debug_aranges_size); if (arange_ptr != dbg->de_debug_aranges + dbg->de_debug_aranges_size) { _dwarf_error(dbg, error, DW_DLE_ARANGE_DECODE_ERROR); return (DW_DLV_ERROR); } arange_block = (Dwarf_Arange *) _dwarf_get_alloc(dbg, DW_DLA_LIST, arange_count); if (arange_block == NULL) { _dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL); return (DW_DLV_ERROR); } curr_chain = head_chain; for (i = 0; i < arange_count; i++) { *(arange_block + i) = curr_chain->ch_item; prev_chain = curr_chain; curr_chain = curr_chain->ch_next; dwarf_dealloc(dbg, prev_chain, DW_DLA_CHAIN); } *aranges = arange_block; *returned_count = (arange_count); return DW_DLV_OK; } /* This function returns DW_DLV_OK if it succeeds and DW_DLV_ERR or DW_DLV_OK otherwise. count is set to the number of addresses in the .debug_aranges section. For each address, the corresponding element in an array is set to the address itself(aranges) and the section offset (offsets). Must be identical in most aspects to dwarf_get_aranges! */ int _dwarf_get_aranges_addr_offsets(Dwarf_Debug dbg, Dwarf_Addr ** addrs, Dwarf_Off ** offsets, Dwarf_Signed * count, Dwarf_Error * error) { /* Sweeps the .debug_aranges section. */ Dwarf_Small *arange_ptr; Dwarf_Small *arange_start_ptr; /* Start of arange header. Used for rounding offset of arange_ptr to twice the tuple size. Libdwarf requirement. */ Dwarf_Small *header_ptr; /* Length of current set of aranges. */ Dwarf_Unsigned length; /* Version of .debug_aranges header. */ Dwarf_Half version; /* Offset of current set of aranges into .debug_info. */ Dwarf_Off info_offset; /* Size in bytes of addresses in target. */ Dwarf_Small address_size; /* Size in bytes of segment offsets in target. */ Dwarf_Small segment_size; Dwarf_Small remainder; /* Count of total number of aranges. */ Dwarf_Unsigned arange_count = 0; /* Start address of arange. */ Dwarf_Addr range_address; /* Length of arange. */ Dwarf_Unsigned range_length; Dwarf_Arange arange; Dwarf_Unsigned i; /* Used to chain Dwarf_Aranges structs. */ Dwarf_Chain curr_chain, prev_chain, head_chain = NULL; Dwarf_Addr *arange_addrs; Dwarf_Off *arange_offsets; int res; /* ***** BEGIN CODE ***** */ if (error != NULL) *error = NULL; if (dbg == NULL) { _dwarf_error(NULL, error, DW_DLE_DBG_NULL); return (DW_DLV_ERROR); } res = _dwarf_load_section(dbg, dbg->de_debug_aranges_index, &dbg->de_debug_aranges, error); if (res != DW_DLV_OK) { return res; } arange_ptr = dbg->de_debug_aranges; do { int local_length_size; /*REFERENCED*/ /* not used in this instance of the macro */ int local_extension_size; header_ptr = arange_ptr; /* READ_AREA_LENGTH updates arange_ptr for consumed bytes */ READ_AREA_LENGTH(dbg, length, Dwarf_Unsigned, arange_ptr, local_length_size, local_extension_size); READ_UNALIGNED(dbg, version, Dwarf_Half, arange_ptr, sizeof(Dwarf_Half)); arange_ptr += sizeof(Dwarf_Half); length = length - sizeof(Dwarf_Half); if (version != CURRENT_VERSION_STAMP) { _dwarf_error(dbg, error, DW_DLE_VERSION_STAMP_ERROR); return (DW_DLV_ERROR); } READ_UNALIGNED(dbg, info_offset, Dwarf_Off, arange_ptr, local_length_size); arange_ptr += local_length_size; length = length - local_length_size; if (info_offset >= dbg->de_debug_info_size) { _dwarf_error(dbg, error, DW_DLE_ARANGE_OFFSET_BAD); return (DW_DLV_ERROR); } address_size = *(Dwarf_Small *) arange_ptr; arange_ptr = arange_ptr + sizeof(Dwarf_Small); length = length - sizeof(Dwarf_Small); segment_size = *(Dwarf_Small *) arange_ptr; arange_ptr = arange_ptr + sizeof(Dwarf_Small); length = length - sizeof(Dwarf_Small); if (segment_size != 0) { _dwarf_error(dbg, error, DW_DLE_SEGMENT_SIZE_BAD); return (DW_DLV_ERROR); } /* Round arange_ptr offset to next multiple of address_size. */ remainder = (Dwarf_Unsigned) (arange_ptr - header_ptr) % (2 * address_size); if (remainder != 0) { arange_ptr = arange_ptr + (2 * address_size) - remainder; length = length - ((2 * address_size) - remainder); } do { arange_start_ptr = arange_ptr; READ_UNALIGNED(dbg, range_address, Dwarf_Addr, arange_ptr, dbg->de_pointer_size); arange_ptr += dbg->de_pointer_size; length = length - dbg->de_pointer_size; READ_UNALIGNED(dbg, range_length, Dwarf_Unsigned, arange_ptr, local_length_size); arange_ptr += local_length_size; length = length - local_length_size; if (range_address != 0 || range_length != 0) { arange = (Dwarf_Arange) _dwarf_get_alloc(dbg, DW_DLA_ARANGE, 1); if (arange == NULL) { _dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL); return (DW_DLV_ERROR); } arange->ar_address = range_address; arange->ar_length = range_length; arange->ar_info_offset = arange_start_ptr - dbg->de_debug_aranges; arange->ar_dbg = dbg; arange_count++; curr_chain = (Dwarf_Chain) _dwarf_get_alloc(dbg, DW_DLA_CHAIN, 1); if (curr_chain == NULL) { _dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL); return (DW_DLV_ERROR); } curr_chain->ch_item = arange; if (head_chain == NULL) head_chain = prev_chain = curr_chain; else { prev_chain->ch_next = curr_chain; prev_chain = curr_chain; } } } while (range_address != 0 || range_length != 0); if (length != 0) { _dwarf_error(dbg, error, DW_DLE_ARANGE_LENGTH_BAD); return (DW_DLV_ERROR); } } while (arange_ptr < dbg->de_debug_aranges + dbg->de_debug_aranges_size); if (arange_ptr != dbg->de_debug_aranges + dbg->de_debug_aranges_size) { _dwarf_error(dbg, error, DW_DLE_ARANGE_DECODE_ERROR); return (DW_DLV_ERROR); } arange_addrs = (Dwarf_Addr *) _dwarf_get_alloc(dbg, DW_DLA_ADDR, arange_count); if (arange_addrs == NULL) { _dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL); return (DW_DLV_ERROR); } arange_offsets = (Dwarf_Off *) _dwarf_get_alloc(dbg, DW_DLA_ADDR, arange_count); if (arange_offsets == NULL) { _dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL); return (DW_DLV_ERROR); } curr_chain = head_chain; for (i = 0; i < arange_count; i++) { Dwarf_Arange ar = curr_chain->ch_item; arange_addrs[i] = ar->ar_address; arange_offsets[i] = ar->ar_info_offset; prev_chain = curr_chain; curr_chain = curr_chain->ch_next; dwarf_dealloc(dbg, ar, DW_DLA_ARANGE); dwarf_dealloc(dbg, prev_chain, DW_DLA_CHAIN); } *count = arange_count; *offsets = arange_offsets; *addrs = arange_addrs; return (DW_DLV_OK); } /* This function takes a pointer to a block of Dwarf_Arange's, and a count of the length of the block. It checks if the given address is within the range of an address range in the block. If yes, it returns the appropriate Dwarf_Arange. Otherwise, it returns DW_DLV_ERROR. */ int dwarf_get_arange(Dwarf_Arange * aranges, Dwarf_Unsigned arange_count, Dwarf_Addr address, Dwarf_Arange * returned_arange, Dwarf_Error * error) { Dwarf_Arange curr_arange; Dwarf_Unsigned i; if (aranges == NULL) { _dwarf_error(NULL, error, DW_DLE_ARANGES_NULL); return (DW_DLV_ERROR); } for (i = 0; i < arange_count; i++) { curr_arange = *(aranges + i); if (address >= curr_arange->ar_address && address < curr_arange->ar_address + curr_arange->ar_length) { *returned_arange = curr_arange; return (DW_DLV_OK); } } return (DW_DLV_NO_ENTRY); } /* This function takes an Dwarf_Arange, and returns the offset of the first die in the compilation-unit that the arange belongs to. Returns DW_DLV_ERROR on error. */ int dwarf_get_cu_die_offset(Dwarf_Arange arange, Dwarf_Off * returned_offset, Dwarf_Error * error) { Dwarf_Debug dbg; Dwarf_Off offset; if (arange == NULL) { _dwarf_error(NULL, error, DW_DLE_ARANGE_NULL); return (DW_DLV_ERROR); } dbg = arange->ar_dbg; offset = arange->ar_info_offset; if(!dbg->de_debug_info) { int res = _dwarf_load_debug_info(dbg,error); if(res != DW_DLV_OK) { return res; } } *returned_offset = offset + _dwarf_length_of_cu_header(dbg, offset); return DW_DLV_OK; } /* This function takes an Dwarf_Arange, and returns the offset of the CU header in the compilation-unit that the arange belongs to. Returns DW_DLV_ERROR on error. */ int dwarf_get_arange_cu_header_offset(Dwarf_Arange arange, Dwarf_Off * cu_header_offset_returned, Dwarf_Error * error) { if (arange == NULL) { _dwarf_error(NULL, error, DW_DLE_ARANGE_NULL); return (DW_DLV_ERROR); } *cu_header_offset_returned = arange->ar_info_offset; return DW_DLV_OK; } /* This function takes a Dwarf_Arange, and returns true if it is not NULL. It also stores the start address of the range in *start, the length of the range in *length, and the offset of the first die in the compilation-unit in *cu_die_offset. It returns false on error. */ int dwarf_get_arange_info(Dwarf_Arange arange, Dwarf_Addr * start, Dwarf_Unsigned * length, Dwarf_Off * cu_die_offset, Dwarf_Error * error) { if (arange == NULL) { _dwarf_error(NULL, error, DW_DLE_ARANGE_NULL); return (DW_DLV_ERROR); } if (start != NULL) *start = arange->ar_address; if (length != NULL) *length = arange->ar_length; if (cu_die_offset != NULL) { Dwarf_Debug dbg = arange->ar_dbg; Dwarf_Off offset = arange->ar_info_offset; if(!dbg->de_debug_info) { int res = _dwarf_load_debug_info(dbg,error); if(res != DW_DLV_OK) { return res; } } *cu_die_offset = offset + _dwarf_length_of_cu_header(dbg, offset); } return (DW_DLV_OK); }
722,012
./hicuda/src/osprey/libdwarf/libdwarf/pro_die.c
/* * Copyright 2005, 2006 PathScale, Inc. All Rights Reserved. */ /* Copyright (C) 2000,2004 Silicon Graphics, Inc. All Rights Reserved. This program is free software; you can redistribute it and/or modify it under the terms of version 2.1 of the GNU Lesser General Public License as published by the Free Software Foundation. This program is distributed in the hope that it would be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Further, this software is distributed without any warranty that it is free of the rightful claim of any third person regarding infringement or the like. Any license provided herein, whether implied or otherwise, applies only to this software file. Patent licenses, if any, provided herein do not apply to combinations of this program with other software, or any other product whatsoever. You should have received a copy of the GNU Lesser General Public License along with this program; if not, write the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA. Contact information: Silicon Graphics, Inc., 1500 Crittenden Lane, Mountain View, CA 94043, or: http://www.sgi.com For further information regarding this notice, see: http://oss.sgi.com/projects/GenInfo/NoticeExplan */ #include "config.h" #include "libdwarfdefs.h" #include <stdio.h> #include <string.h> #include "pro_incl.h" #include "pro_die.h" #ifndef R_MIPS_NONE #define R_MIPS_NONE 0 #endif /* adds an attribute to a die */ void _dwarf_pro_add_at_to_die(Dwarf_P_Die die, Dwarf_P_Attribute attr); /*---------------------------------------------------------------------------- This function creates a new die. tag: tag of the new die to be created parent,child,left,right: specify neighbors of the new die. Only one of these may be non-null -----------------------------------------------------------------------------*/ Dwarf_P_Die dwarf_new_die(Dwarf_P_Debug dbg, Dwarf_Tag tag, Dwarf_P_Die parent, Dwarf_P_Die child, Dwarf_P_Die left, Dwarf_P_Die right, Dwarf_Error * error) { Dwarf_P_Die new_die, ret_die; new_die = (Dwarf_P_Die) _dwarf_p_get_alloc(dbg, sizeof(struct Dwarf_P_Die_s)); if (new_die == NULL) { DWARF_P_DBG_ERROR(dbg, DW_DLE_DIE_ALLOC, (Dwarf_P_Die) DW_DLV_BADADDR); } new_die->di_parent = NULL; new_die->di_left = NULL; new_die->di_right = NULL; new_die->di_child = NULL; new_die->di_last_child = NULL; new_die->di_tag = tag; ret_die = dwarf_die_link(new_die, parent, child, left, right, error); return ret_die; } /*---------------------------------------------------------------------------- This function links up a die to specified neighbors parent,child,left,right: specify neighbors of the new die. Only one of these may be non-null -----------------------------------------------------------------------------*/ Dwarf_P_Die dwarf_die_link(Dwarf_P_Die new_die, Dwarf_P_Die parent, Dwarf_P_Die child, Dwarf_P_Die left, Dwarf_P_Die right, Dwarf_Error * error) { int n_nulls; /* to count # of non null neighbors */ n_nulls = 0; if (parent != NULL) { n_nulls++; new_die->di_parent = parent; if (parent->di_child) { /* we maintain a pointer to the last child * so that we can append children quickly */ Dwarf_P_Die curdie = parent->di_last_child; /* find last_child pointer if without */ if (curdie == NULL) { curdie = parent->di_child; while (curdie->di_right != NULL) { curdie = curdie->di_right; } } if (curdie->di_right != NULL) { DWARF_P_DBG_ERROR(NULL, DW_DLE_LAST_CHILD_ISNT, (Dwarf_P_Die) DW_DLV_BADADDR); } curdie->di_right = new_die; /* attach to sibling list */ new_die->di_left = curdie; /* back pointer */ parent->di_last_child = new_die; /* last in list */ } else { parent->di_child = new_die; parent->di_last_child = new_die; } } if (child != NULL) { n_nulls++; Dwarf_P_Die curdie = child; new_die->di_child = child; new_die->di_last_child = NULL; /* add parent pointer */ if (child->di_parent) { DWARF_P_DBG_ERROR(NULL, DW_DLE_PARENT_EXISTS, (Dwarf_P_Die) DW_DLV_BADADDR); } child->di_parent = new_die; } if (left != NULL) { n_nulls++; new_die->di_left = left; Dwarf_P_Die prtdie = left->di_parent; if (left->di_right) { /* already a right sibl, lets insert */ new_die->di_right = left->di_right; left->di_right->di_left = new_die; } else { /* last in list update parent */ if (prtdie != NULL) { prtdie->di_last_child = new_die; } } left->di_right = new_die; /* add parent pointer */ if (new_die->di_parent) { DWARF_P_DBG_ERROR(NULL, DW_DLE_PARENT_EXISTS, (Dwarf_P_Die) DW_DLV_BADADDR); } new_die->di_parent = prtdie; } if (right != NULL) { n_nulls++; new_die->di_right = right; if (right->di_left) { /* left sibl exists, try inserting */ new_die->di_left = right->di_left; right->di_left->di_right = new_die; } right->di_left = new_die; if (new_die->di_parent) { DWARF_P_DBG_ERROR(NULL, DW_DLE_PARENT_EXISTS, (Dwarf_P_Die) DW_DLV_BADADDR); } new_die->di_parent = right->di_parent; } if (n_nulls > 1) { /* multiple neighbors, error */ DWARF_P_DBG_ERROR(NULL, DW_DLE_EXTRA_NEIGHBORS, (Dwarf_P_Die) DW_DLV_BADADDR); } return new_die; } /*---------------------------------------------------------------------------- This function adds a die to dbg struct. It should be called using the root of all the dies. -----------------------------------------------------------------------------*/ Dwarf_Unsigned dwarf_add_die_to_debug(Dwarf_P_Debug dbg, Dwarf_P_Die first_die, Dwarf_Error * error) { if (first_die == NULL) { DWARF_P_DBG_ERROR(dbg, DW_DLE_DIE_NULL, DW_DLV_NOCOUNT); } if (first_die->di_tag != DW_TAG_compile_unit) { DWARF_P_DBG_ERROR(dbg, DW_DLE_WRONG_TAG, DW_DLV_NOCOUNT); } dbg->de_dies = first_die; return 0; } int _dwarf_pro_add_AT_stmt_list(Dwarf_P_Debug dbg, Dwarf_P_Die first_die, Dwarf_Error * error) { Dwarf_P_Attribute new_attr; int uwordb_size = dbg->de_offset_size; /* Add AT_stmt_list attribute */ new_attr = (Dwarf_P_Attribute) _dwarf_p_get_alloc(NULL, sizeof(struct Dwarf_P_Attribute_s)); if (new_attr == NULL) { DWARF_P_DBG_ERROR(NULL, DW_DLE_ATTR_ALLOC, DW_DLV_NOCOUNT); } new_attr->ar_attribute = DW_AT_stmt_list; new_attr->ar_attribute_form = dbg->de_ar_data_attribute_form; new_attr->ar_rel_type = dbg->de_offset_reloc; new_attr->ar_nbytes = uwordb_size; new_attr->ar_next = NULL; new_attr->ar_reloc_len = uwordb_size; new_attr->ar_data = (char *) _dwarf_p_get_alloc(NULL, uwordb_size); if (new_attr->ar_data == NULL) { DWARF_P_DBG_ERROR(NULL, DW_DLE_ADDR_ALLOC, DW_DLV_NOCOUNT); } { Dwarf_Unsigned du = 0; WRITE_UNALIGNED(dbg, (void *) new_attr->ar_data, (const void *) &du, sizeof(du), uwordb_size); } _dwarf_pro_add_at_to_die(first_die, new_attr); return 0; } /*----------------------------------------------------------------------------- Add AT_name attribute to die ------------------------------------------------------------------------------*/ Dwarf_P_Attribute dwarf_add_AT_name(Dwarf_P_Die die, char *name, Dwarf_Error * error) { Dwarf_P_Attribute new_attr; if (die == NULL) { DWARF_P_DBG_ERROR(NULL, DW_DLE_DIE_NULL, (Dwarf_P_Attribute) DW_DLV_BADADDR); } new_attr = (Dwarf_P_Attribute) _dwarf_p_get_alloc(NULL, sizeof(struct Dwarf_P_Attribute_s)); if (new_attr == NULL) { DWARF_P_DBG_ERROR(NULL, DW_DLE_ATTR_ALLOC, (Dwarf_P_Attribute) DW_DLV_BADADDR); } /* fill in the information */ new_attr->ar_attribute = DW_AT_name; /* assume that form is string, no debug_str yet */ new_attr->ar_attribute_form = DW_FORM_string; new_attr->ar_nbytes = strlen(name) + 1; new_attr->ar_next = NULL; new_attr->ar_reloc_len = 0; new_attr->ar_data = (char *) _dwarf_p_get_alloc(NULL, strlen(name) + 1); if (new_attr->ar_data == NULL) { DWARF_P_DBG_ERROR(NULL, DW_DLE_STRING_ALLOC, (Dwarf_P_Attribute) DW_DLV_BADADDR); } strcpy(new_attr->ar_data, name); new_attr->ar_rel_type = R_MIPS_NONE; /* add attribute to the die */ _dwarf_pro_add_at_to_die(die, new_attr); return new_attr; } /*----------------------------------------------------------------------------- Add AT_comp_dir attribute to die ------------------------------------------------------------------------------*/ Dwarf_P_Attribute dwarf_add_AT_comp_dir(Dwarf_P_Die ownerdie, char *current_working_directory, Dwarf_Error * error) { Dwarf_P_Attribute new_attr; if (ownerdie == NULL) { DWARF_P_DBG_ERROR(NULL, DW_DLE_DIE_NULL, (Dwarf_P_Attribute) DW_DLV_BADADDR); } new_attr = (Dwarf_P_Attribute) _dwarf_p_get_alloc(NULL, sizeof(struct Dwarf_P_Attribute_s)); if (new_attr == NULL) { DWARF_P_DBG_ERROR(NULL, DW_DLE_ATTR_ALLOC, (Dwarf_P_Attribute) DW_DLV_BADADDR); } /* fill in the information */ new_attr->ar_attribute = DW_AT_comp_dir; /* assume that form is string, no debug_str yet */ new_attr->ar_attribute_form = DW_FORM_string; new_attr->ar_nbytes = strlen(current_working_directory) + 1; new_attr->ar_next = NULL; new_attr->ar_reloc_len = 0; new_attr->ar_data = (char *) _dwarf_p_get_alloc(NULL, strlen(current_working_directory) + 1); if (new_attr->ar_data == NULL) { DWARF_P_DBG_ERROR(NULL, DW_DLE_STRING_ALLOC, (Dwarf_P_Attribute) DW_DLV_BADADDR); } strcpy(new_attr->ar_data, current_working_directory); new_attr->ar_rel_type = R_MIPS_NONE; /* add attribute to the die */ _dwarf_pro_add_at_to_die(ownerdie, new_attr); return new_attr; } int _dwarf_pro_add_AT_fde(Dwarf_P_Debug dbg, Dwarf_P_Die die, Dwarf_Unsigned offset, Dwarf_Error * error) { Dwarf_P_Attribute new_attr; int uwordb_size = dbg->de_offset_size; if (die == NULL) { DWARF_P_DBG_ERROR(NULL, DW_DLE_DIE_NULL, -1); } new_attr = (Dwarf_P_Attribute) _dwarf_p_get_alloc(NULL, sizeof(struct Dwarf_P_Attribute_s)); if (new_attr == NULL) { DWARF_P_DBG_ERROR(NULL, DW_DLE_ATTR_ALLOC, -1); } /* fill in the information */ new_attr->ar_attribute = DW_AT_MIPS_fde; new_attr->ar_attribute_form = dbg->de_ar_data_attribute_form;; new_attr->ar_rel_type = dbg->de_offset_reloc; new_attr->ar_nbytes = uwordb_size; new_attr->ar_next = NULL; new_attr->ar_reloc_len = uwordb_size; new_attr->ar_data = (char *) _dwarf_p_get_alloc(NULL, uwordb_size); if (new_attr->ar_data == NULL) { DWARF_P_DBG_ERROR(NULL, DW_DLE_ADDR_ALLOC, DW_DLV_NOCOUNT); } { Dwarf_Unsigned du = offset; WRITE_UNALIGNED(dbg, (void *) new_attr->ar_data, (const void *) &du, sizeof(du), uwordb_size); } _dwarf_pro_add_at_to_die(die, new_attr); return 0; } int _dwarf_pro_add_AT_macro_info(Dwarf_P_Debug dbg, Dwarf_P_Die die, Dwarf_Unsigned offset, Dwarf_Error * error) { Dwarf_P_Attribute new_attr; int uwordb_size = dbg->de_offset_size; if (die == NULL) { DWARF_P_DBG_ERROR(NULL, DW_DLE_DIE_NULL, -1); } new_attr = (Dwarf_P_Attribute) _dwarf_p_get_alloc(NULL, sizeof(struct Dwarf_P_Attribute_s)); if (new_attr == NULL) { DWARF_P_DBG_ERROR(NULL, DW_DLE_ATTR_ALLOC, -1); } /* fill in the information */ new_attr->ar_attribute = DW_AT_macro_info; new_attr->ar_attribute_form = dbg->de_ar_data_attribute_form; new_attr->ar_rel_type = dbg->de_offset_reloc; new_attr->ar_nbytes = uwordb_size; new_attr->ar_next = NULL; new_attr->ar_reloc_len = uwordb_size; new_attr->ar_data = (char *) _dwarf_p_get_alloc(NULL, uwordb_size); if (new_attr->ar_data == NULL) { DWARF_P_DBG_ERROR(NULL, DW_DLE_ADDR_ALLOC, DW_DLV_NOCOUNT); } { Dwarf_Unsigned du = offset; WRITE_UNALIGNED(dbg, (void *) new_attr->ar_data, (const void *) &du, sizeof(du), uwordb_size); } _dwarf_pro_add_at_to_die(die, new_attr); return 0; } void _dwarf_pro_add_at_to_die(Dwarf_P_Die die, Dwarf_P_Attribute attr) { if (die->di_last_attr) { die->di_last_attr->ar_next = attr; die->di_last_attr = attr; die->di_n_attr++; } else { die->di_n_attr = 1; die->di_attrs = die->di_last_attr = attr; } }
722,013
./hicuda/src/osprey/libdwarf/libdwarf/dwarf_stubs.c
/* * Copyright 2005, 2006 PathScale, Inc. All Rights Reserved. */ /* Copyright (C) 2000,2004 Silicon Graphics, Inc. All Rights Reserved. This program is free software; you can redistribute it and/or modify it under the terms of version 2.1 of the GNU Lesser General Public License as published by the Free Software Foundation. This program is distributed in the hope that it would be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Further, this software is distributed without any warranty that it is free of the rightful claim of any third person regarding infringement or the like. Any license provided herein, whether implied or otherwise, applies only to this software file. Patent licenses, if any, provided herein do not apply to combinations of this program with other software, or any other product whatsoever. You should have received a copy of the GNU Lesser General Public License along with this program; if not, write the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA. Contact information: Silicon Graphics, Inc., 1500 Crittenden Lane, Mountain View, CA 94043, or: http://www.sgi.com For further information regarding this notice, see: http://oss.sgi.com/projects/GenInfo/NoticeExplan */ #include "config.h" #include "dwarf_incl.h" #include <stdio.h> /*ARGSUSED*/ int dwarf_nextglob(Dwarf_Debug dbg, Dwarf_Global glob, Dwarf_Global * returned_nextglob, Dwarf_Error * error) { return (DW_DLV_NO_ENTRY); }
722,014
./hicuda/src/osprey/libdwarf/libdwarf/pro_error.c
/* * Copyright 2005, 2006 PathScale, Inc. All Rights Reserved. */ /* Copyright (C) 2000,2002,2004 Silicon Graphics, Inc. All Rights Reserved. This program is free software; you can redistribute it and/or modify it under the terms of version 2.1 of the GNU Lesser General Public License as published by the Free Software Foundation. This program is distributed in the hope that it would be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Further, this software is distributed without any warranty that it is free of the rightful claim of any third person regarding infringement or the like. Any license provided herein, whether implied or otherwise, applies only to this software file. Patent licenses, if any, provided herein do not apply to combinations of this program with other software, or any other product whatsoever. You should have received a copy of the GNU Lesser General Public License along with this program; if not, write the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA. Contact information: Silicon Graphics, Inc., 1500 Crittenden Lane, Mountain View, CA 94043, or: http://www.sgi.com For further information regarding this notice, see: http://oss.sgi.com/projects/GenInfo/NoticeExplan */ #include "config.h" #include "libdwarfdefs.h" #ifdef HAVE_ELF_H #include <elf.h> #endif #include <stdio.h> #include <sys/stat.h> #include <sys/types.h> #include <stdlib.h> #include "pro_incl.h" extern char *_dwarf_errmsgs[]; /* This function performs error handling as described in the libdwarf consumer document section 3. Dbg is the Dwarf_P_debug structure being processed. Error is a pointer to the pointer to the error descriptor that will be returned. Errval is an error code listed in dwarf_error.h. */ void _dwarf_p_error(Dwarf_P_Debug dbg, Dwarf_Error * error, Dwarf_Word errval) { Dwarf_Error errptr; /* Allow NULL dbg on entry, since sometimes that can happen and we want to report the upper-level error, not this one. */ if ((Dwarf_Sword) errval < 0) printf("ERROR VALUE: %ld - %s\n", (long) errval, _dwarf_errmsgs[-errval - 1]); if (error != NULL) { errptr = (Dwarf_Error) _dwarf_p_get_alloc(dbg, sizeof(struct Dwarf_Error_s)); if (errptr == NULL) { fprintf(stderr, "Could not allocate Dwarf_Error structure\n"); abort(); } errptr->er_errval = (Dwarf_Sword) errval; *error = errptr; return; } if (dbg != NULL && dbg->de_errhand != NULL) { errptr = (Dwarf_Error) _dwarf_p_get_alloc(dbg, sizeof(struct Dwarf_Error_s)); if (errptr == NULL) { fprintf(stderr, "Could not allocate Dwarf_Error structure\n"); abort(); } errptr->er_errval = (Dwarf_Sword) errval; dbg->de_errhand(errptr, dbg->de_errarg); return; } abort(); }
722,015
./hicuda/src/osprey/libdwarf/libdwarf/pro_pubnames.c
/* * Copyright 2005, 2006 PathScale, Inc. All Rights Reserved. */ /* Copyright (C) 2000,2004 Silicon Graphics, Inc. All Rights Reserved. This program is free software; you can redistribute it and/or modify it under the terms of version 2.1 of the GNU Lesser General Public License as published by the Free Software Foundation. This program is distributed in the hope that it would be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Further, this software is distributed without any warranty that it is free of the rightful claim of any third person regarding infringement or the like. Any license provided herein, whether implied or otherwise, applies only to this software file. Patent licenses, if any, provided herein do not apply to combinations of this program with other software, or any other product whatsoever. You should have received a copy of the GNU Lesser General Public License along with this program; if not, write the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA. Contact information: Silicon Graphics, Inc., 1500 Crittenden Lane, Mountain View, CA 94043, or: http://www.sgi.com For further information regarding this notice, see: http://oss.sgi.com/projects/GenInfo/NoticeExplan */ #include "config.h" #include "libdwarfdefs.h" #include <stdio.h> #include <string.h> #ifdef HAVE_ELFACCESS_H #include <elfaccess.h> #endif #include "pro_incl.h" #include "pro_section.h" /* This function adds another public name to the list of public names for the given Dwarf_P_Debug. It returns 0 on error, and 1 otherwise. */ Dwarf_Unsigned dwarf_add_pubname(Dwarf_P_Debug dbg, Dwarf_P_Die die, char *pubname_name, Dwarf_Error * error) { return _dwarf_add_simple_name_entry(dbg, die, pubname_name, dwarf_snk_pubname, error); }
722,016
./hicuda/src/osprey/libdwarf/libdwarf/pro_encode_nm.c
/* * Copyright 2005, 2006 PathScale, Inc. All Rights Reserved. */ /* Copyright (C) 2000,2004 Silicon Graphics, Inc. All Rights Reserved. This program is free software; you can redistribute it and/or modify it under the terms of version 2.1 of the GNU Lesser General Public License as published by the Free Software Foundation. This program is distributed in the hope that it would be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Further, this software is distributed without any warranty that it is free of the rightful claim of any third person regarding infringement or the like. Any license provided herein, whether implied or otherwise, applies only to this software file. Patent licenses, if any, provided herein do not apply to combinations of this program with other software, or any other product whatsoever. You should have received a copy of the GNU Lesser General Public License along with this program; if not, write the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA. Contact information: Silicon Graphics, Inc., 1500 Crittenden Lane, Mountain View, CA 94043, or: http://www.sgi.com For further information regarding this notice, see: http://oss.sgi.com/projects/GenInfo/NoticeExplan */ #include "config.h" #include "libdwarfdefs.h" #include <string.h> #include "pro_incl.h" #define MORE_BYTES 0x80 #define DATA_MASK 0x7f #define DIGIT_WIDTH 7 #define SIGN_BIT 0x40 /*------------------------------------------------------------- Encode val as a leb128. This encodes it as an unsigned number. ---------------------------------------------------------------*/ /* return DW_DLV_ERROR or DW_DLV_OK. ** space to write leb number is provided by caller, with caller ** passing length. ** number of bytes used returned thru nbytes arg */ int _dwarf_pro_encode_leb128_nm(Dwarf_Unsigned val, int *nbytes, char *space, int splen) { char *a; char *end = space + splen; a = space; do { unsigned char uc; if (a >= end) { return DW_DLV_ERROR; } uc = val & DATA_MASK; val >>= DIGIT_WIDTH; if (val != 0) { uc |= MORE_BYTES; } *a = uc; a++; } while (val); *nbytes = a - space; return DW_DLV_OK; } /* return DW_DLV_ERROR or DW_DLV_OK. ** space to write leb number is provided by caller, with caller ** passing length. ** number of bytes used returned thru nbytes arg ** encodes a signed number. */ int _dwarf_pro_encode_signed_leb128_nm(Dwarf_Signed value, int *nbytes, char *space, int splen) { char *str; Dwarf_Signed sign = -(value < 0); int more = 1; char *end = space + splen; str = space; do { unsigned char byte = value & DATA_MASK; value >>= DIGIT_WIDTH; if (str >= end) { return DW_DLV_ERROR; } /* * Remaining chunks would just contain the sign bit, and this chunk * has already captured at least one sign bit. */ if (value == sign && ((byte & SIGN_BIT) == (sign & SIGN_BIT))) { more = 0; } else { byte |= MORE_BYTES; } *str = byte; str++; } while (more); *nbytes = str - space; return DW_DLV_OK; }
722,017
./hicuda/src/osprey/hicuda/cuda_inc.c
/** * It appears to be very tricky to get the set of symbols in cuda_runtime.h * that is the same as the set NVCC gets when including cuda_runtime.h. The * ultimate solution is to use NVCC to preprocess an empty .cu file and * convert it to a WHIRL file. However, using opencc to compile this .ii file * leads to syntax error. * * Compiling an empty C++ file with cuda_runtim.h included, using opencc, * does not work due to the same syntax error. * * For now, we only consider C headers that NVCC will see. They are obtained * by checking cuda_inc.cpp1.ii. */ // The following header files are re-included in the generated CUDA code. // We must remove math functions because NVCC complains about the exception // handling of these functions. // #include <stdlib.h> #include <stdio.h> #include <string.h> #include <math.h>
722,018
./hicuda/src/libspin/gspin-mempool.c
/* Copyright (C) 2006. QLogic Corporation. All Rights Reserved. This program is free software; you can redistribute it and/or modify it under the terms of version 2 of the GNU General Public License as published by the Free Software Foundation. This program is distributed in the hope that it would be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Further, this software is distributed without any warranty that it is free of the rightful claim of any third person regarding infringement or the like. Any license provided herein, whether implied or otherwise, applies only to this software file. Patent licenses, if any, provided herein do not apply to combinations of this program with other software, or any other product whatsoever. You should have received a copy of the GNU General Public License along with this program; if not, write the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA. */ #include <stdio.h> #include <stdlib.h> #include "gspin-tree.h" #include "gspin-mempool.h" // following 3 defines must be in sync with each other #if 0 // this version for testing #define GS_MEMBLOCK_SIZE 0x1000 // must be power of 2 and multiple of // sizeof(struct gspin) so that we can easily // convert between index and byte address #define GS_BLOCK_IDX_SHIFT_AMT 12 #define GS_OFST_IN_BLK_MASK 0xfff #else #define GS_MEMBLOCK_SIZE 0x1000000// must be power of 2 and multiple of // sizeof(struct gspin) so that we can easily // convert between index and byte address #define GS_BLOCK_IDX_SHIFT_AMT 24 #define GS_OFST_IN_BLK_MASK 0xffffff #endif gs_arena_t gs_mempool[GS_ARENA_COUNT] = { { NULL, NULL, 0 }, // GS_ARENA (For the core struct gspin type). { NULL, NULL, 0 }, // IB_STRING_ARENA (IB_STRING ONLY!!!) }; // allocate a new memory block of size GS_MEMBLOCK_SIZE and keep track of it gs_memblock_t *gs_new_memblock(int id) { gs_memblock_t *memblk = (gs_memblock_t *)malloc(sizeof(gs_memblock_t)); memblk->block_id = id; memblk->mem = (char *)calloc(GS_MEMBLOCK_SIZE, 1); if (memblk->mem == NULL) fprintf(stderr, "Out of memory.\n"); memblk->next = NULL; return memblk; } // for GS_ARENA, count must be 4, 8, 16 or 20 void *__gs_mempool_alloc(unsigned int arena_id, unsigned int count) { gs_arena_t *arena = &gs_mempool[arena_id]; gs_memblock_t *memblk = arena->lastblock; if (memblk == NULL) { #ifdef TARG_IA64 // On IA64, the sizeof(gspin_t) is 32 GS_ASSERT(sizeof(gspin_t) == 32, "struct gspin size has changed."); #else GS_ASSERT(sizeof(gspin_t) == 20, "struct gspin size has changed."); #endif memblk = gs_new_memblock(0); arena->firstblock = arena->lastblock = memblk; arena->current_index = 0; } else if ((arena->current_index + count - 1) >= ((memblk->block_id + 1) << GS_BLOCK_IDX_SHIFT_AMT)) { memblk = gs_new_memblock(memblk->block_id + 1); arena->lastblock->next = memblk; arena->lastblock = memblk; if (count > 1) // this is needed to gaurantee locations to be contiguous arena->current_index = memblk->block_id * GS_MEMBLOCK_SIZE; } gs_void_t *p = &memblk->mem[arena->current_index & GS_OFST_IN_BLK_MASK]; arena->current_index += count; return p; } static gs_memblock_t *memblk_cache[GS_ARENA_COUNT] = {NULL, NULL}; // as cache // convert from index to memory address gs_void_t *gs_mempool_idx2address(int arena_id, int cell_index) { gs_arena_t *arena = &gs_mempool[arena_id]; int cur_block_id = cell_index >> GS_BLOCK_IDX_SHIFT_AMT; if (memblk_cache[arena_id] == NULL || memblk_cache[arena_id]->block_id > cur_block_id) memblk_cache[arena_id] = arena->firstblock; while (memblk_cache[arena_id]->block_id != cur_block_id) memblk_cache[arena_id] = memblk_cache[arena_id]->next; int block_byte_ofst = cell_index & GS_OFST_IN_BLK_MASK; return memblk_cache[arena_id]->mem + block_byte_ofst; } extern char *mem_seg; // convert from memory address to byte offset from very first cell that has // offset 0. If called from a gspin producer, the address will belong to one of // many non-contiguous blocks managed by mempool. If called from a gspin // consumer, there are two possibilities: (1) addresses for anything in the // input must belong to the mmap'ed block, whose base is mem_seg; (2) addresses // for gspin nodes allocated by the consumer are manged by mempool, and thus // will belong to one of those mempool-managed non-contiguous blocks. long gs_mempool_address2byteofst(int arena_id, char *p) { if (memblk_cache[arena_id] == NULL || !(p >= memblk_cache[arena_id]->mem && p - memblk_cache[arena_id]->mem < GS_MEMBLOCK_SIZE)) { memblk_cache[arena_id] = gs_mempool[arena_id].firstblock; // printf("+++++++++++++++++++ memblk_cache cache reset\n"); } while (memblk_cache[arena_id] != NULL && !(p >= memblk_cache[arena_id]->mem && p - memblk_cache[arena_id]->mem < GS_MEMBLOCK_SIZE)) memblk_cache[arena_id] = memblk_cache[arena_id]->next; if (memblk_cache[arena_id] != NULL) return memblk_cache[arena_id]->block_id * GS_MEMBLOCK_SIZE + p - memblk_cache[arena_id]->mem; // must be in the mmap'ed block for gspin input in consumer of .spin file GS_ASSERT(arena_id == GS_ARENA, "gs_mempool_address2byteofst failure"); return p - mem_seg; }
722,019
./hicuda/src/libspin/gspin-assert.c
/* * Copyright (C) 2006. QLogic Corporation. All Rights Reserved. */ //////////////////////////////////////////////////////////////////////////////// // // Copyright 2006 PathScale, Inc. All Rights Reserved. // // This program is free software; you can redistribute it and/or modify it // under the terms of version 2 of the GNU General Public License as // published by the Free Software Foundation. // // This program is distributed in the hope that it would be useful, but // WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. // // Further, this software is distributed without any warranty that it is // free of the rightful claim of any third person regarding infringement // or the like. Any license provided herein, whether implied or // otherwise, applies only to this software file. Patent licenses, if // any, provided herein do not apply to combinations of this program with // other software, or any other product whatsoever. // // You should have received a copy of the GNU General Public License along // with this program; if not, write the Free Software Foundation, Inc., 59 // Temple Place - Suite 330, Boston MA 02111-1307, USA. //////////////////////////////////////////////////////////////////////////////// #include <stdio.h> #include <stdlib.h> #include "gspin-base-types.h" #include "gspin-assert.h" static void gs_assert_failure (gs_string_t file, gs_string_t function, gs_count_t line, const gs_string_t message) { fprintf(stderr, "Assertion failure in file: %s, function: %s, line: %d.\n", file, function, line); fprintf (stderr, "%s\n", message); } void gs_assert(bool condition, gs_string_t file, gs_string_t function, gs_count_t line, const gs_string_t message) { if (condition == gs_true) return; gs_assert_failure(file, function, line, message); }
722,020
./hicuda/src/libspin/gspin-io.c
/* Copyright (C) 2006. QLogic Corporation. All Rights Reserved. This program is free software; you can redistribute it and/or modify it under the terms of version 2 of the GNU General Public License as published by the Free Software Foundation. This program is distributed in the hope that it would be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Further, this software is distributed without any warranty that it is free of the rightful claim of any third person regarding infringement or the like. Any license provided herein, whether implied or otherwise, applies only to this software file. Patent licenses, if any, provided herein do not apply to combinations of this program with other software, or any other product whatsoever. You should have received a copy of the GNU General Public License along with this program; if not, write the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA. */ #include <stdio.h> #include <string.h> #include <sys/stat.h> #include <fcntl.h> #include <sys/mman.h> #include <sys/types.h> #include <unistd.h> #include "gspin-tree.h" #include "gspin-list.h" #include "gspin-tel.h" // for gs_program #include "gspin-assert.h" #include "gspin-io.h" #include "gspin-mempool.h" #ifdef Is_True_On void flag_reachable_nodes(gs_t t) { if (t == NULL) return; if (gs_em(t) == true) return; _gs_em(t, true); int j; for (j = 0; j < gs_code_arity(gs_code(t)); j++) flag_reachable_nodes(gs_operand(t, j)); } #endif //////////////////////////////////////////////////////////////////////////////// // // Ref. "Advanced Programming in the UNIX Environment" by W. Richard Stevens. // Addison-Wesley. 1993. 26th Printing January 2003 // Section 12.9 "Memory Mapped I/O", pp. 407 to 413. // //////////////////////////////////////////////////////////////////////////////// // ASSUMPTIONS: Whatever happens, the root of the tree that is written out ought // to be leftmost, in mem_seg. i.e. (gs_t) mem_seg[0] should have the // root node. // // Also, we assume that the format is a run of gs nodes followed by // strings (all pointed to from code IB_STRING gs nodes). // gs_write lays out into a linear segment, each arena in gs_mempool. For each // arena, compute the total number of bytes that the mem sections consume. // Allocate a segment that long + an initial section that contains the length/ // offset of each data section. mmap(2) this segment and copy the gs_mempool // arenas over into it converting physical addresses into offsets into the // memory segment. char *mem_seg = NULL; // base of the memory map gs_void_t gs_write (const gs_string_t filename) { gs_count_t gs_length, unsigned_char_length, mem_seg_length; gs_int_t fd, lseek_rv, write_rv; #ifdef Is_True_On flag_reachable_nodes((gs_t) gs_mempool[GS_ARENA].firstblock->mem); #endif gs_arena_t *gs_arena = &gs_mempool[GS_ARENA]; gs_arena_t *gs_unsigned_char_arena = &gs_mempool[IB_STRING_ARENA]; gs_length = gs_arena->current_index; unsigned_char_length = gs_unsigned_char_arena->current_index; mem_seg_length = gs_length + unsigned_char_length; fd = open (filename, O_TRUNC|O_CREAT|O_RDWR, 0666); GS_ASSERT (!(fd < 0), "open failed.\n"); lseek_rv = lseek (fd, mem_seg_length - 1, SEEK_SET); GS_ASSERT (lseek_rv != -1, "lseek failed.\n"); write_rv = write (fd, " ", 1); GS_ASSERT (write_rv == 1, "write failed.\n"); mem_seg = mmap (0, mem_seg_length, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0); GS_ASSERT (mem_seg != MAP_FAILED, "mmap failure.\n"); // Convert physical addresses to indexes within the mem_seg. int i = 0; int size; gs_t p_in_memseg; gs_t t = (gs_t) gs_mempool_idx2address(GS_ARENA, 0); while (i < gs_arena->current_index) { p_in_memseg = (gs_t) (mem_seg + i); size = gspin_node_size(gs_code(t)); memcpy(p_in_memseg, t, size); #ifdef Is_True_On _gs_em(p_in_memseg, false); if (gs_em(t) == false) { printf("leaked node: "); gs_dump(t); } #endif if (gs_code_arity(gs_code(t)) > 0) { // convert kid pointers to indices int j; for (j = 0; j < gs_code_arity(gs_code(t)); j++) if (gs_operand(t, j) != NULL) gs_set_operand(p_in_memseg, j, (gs_t) gs_mempool_address2byteofst(GS_ARENA, (char *)gs_operand(t, j))); } else if (gs_code(t) == IB_STRING) { // convert string pointer to index gs_string_t s = gs_s(t); _gs_u(p_in_memseg, gs_length + gs_mempool_address2byteofst(IB_STRING_ARENA, s)); memcpy (mem_seg + gs_u(p_in_memseg), s, gs_slen(p_in_memseg)); } i += gspin_node_size(gs_code(t)); t = (gs_t) gs_mempool_idx2address(GS_ARENA, i); while (i < gs_arena->current_index && gs_code(t) == DOT) { i += 4; t = (gs_t) gs_mempool_idx2address(GS_ARENA, i); } } close (fd); return; } gs_unsigned_char_t *gs_read (const gs_string_t filename) { gs_int_t fd, fstat_rv; struct stat statbuf; char *p, *string_section; fd = open (filename, O_RDONLY); GS_ASSERT (fd != -1, "open failed.\n"); fstat_rv = fstat (fd, &statbuf); // printf ("statbuf.st_size: %ld\n", statbuf.st_size); // printf ("struct gspin size: %u\n", sizeof (struct gspin)); GS_ASSERT (fstat_rv == 0, "fstat failed.\n"); mem_seg = mmap (0, statbuf.st_size, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0); GS_ASSERT (mem_seg != MAP_FAILED, "mmap failure.\n"); GS_ASSERT (mem_seg != NULL, "mem_seg null!.\n"); // Convert indexes within the mem_seg to physical addresses. p = mem_seg; string_section = (char *)(~0L); while (p - mem_seg < statbuf.st_size && p < string_section) { gs_t q = (gs_t) p; if (gs_code_arity(gs_code(q)) > 0) { // convert kid indicese to pointers int j; for (j = 0; j < gs_code_arity(gs_code(q)); j++) if (gs_operand(q, j) != NULL) { GS_ASSERT((int)gs_operand(q, j) < statbuf.st_size, "right offset out of bounds!.\n"); gs_set_operand(q, j, (gs_t) (mem_seg + (long) gs_operand(q,j))); } } else if (gs_code(q) == IB_STRING) { // convert string index to pointer if (string_section == (char *)(~0L) ) string_section = mem_seg + gs_u(q); GS_ASSERT(gs_u(q) < statbuf.st_size, "left offset out of bounds!.\n"); _gs_s_no_alloc (q, (gs_unsigned_char_t *) (mem_seg + gs_u(q))); } p += gspin_node_size(gs_code(q)); while (p - mem_seg < statbuf.st_size && p < string_section && gs_code((gs_t) p) == DOT) p += 4; } close (fd); return mem_seg; } gs_t gs_read_file (const gs_string_t filename) { gs_t p; GS_ASSERT (filename != NULL, "open failed.\n"); p = (gs_t) gs_read (filename); gs_program = p; return p; }
722,021
./hicuda/src/libspin/gspin-tree.c
/* * Copyright (C) 2006. QLogic Corporation. All Rights Reserved. */ //////////////////////////////////////////////////////////////////////////////// // // Copyright 2006 PathScale, Inc. All Rights Reserved. // // This program is free software; you can redistribute it and/or modify it // under the terms of version 2 of the GNU General Public License as // published by the Free Software Foundation. // // This program is distributed in the hope that it would be useful, but // WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. // // Further, this software is distributed without any warranty that it is // free of the rightful claim of any third person regarding infringement // or the like. Any license provided herein, whether implied or // otherwise, applies only to this software file. Patent licenses, if // any, provided herein do not apply to combinations of this program with // other software, or any other product whatsoever. // // You should have received a copy of the GNU General Public License along // with this program; if not, write the Free Software Foundation, Inc., 59 // Temple Place - Suite 330, Boston MA 02111-1307, USA. //////////////////////////////////////////////////////////////////////////////// #include <ctype.h> #include <stdio.h> #include <stdlib.h> #include "gspin-tree.h" #include "gspin-list.h" #include "gspin-tel.h" #include "gspin-mempool.h" struct tree_code_property { gs_code_t tree_code; signed char arity; gs_tree_code_class_t tcc; char *name; } tree_code_table[] = { // Generic core stuff: { DOT, 0, GS_TCC_EXCEPTIONAL, "DOT" }, // list { EMPTY, 2, GS_TCC_EXCEPTIONAL, "EMPTY" }, // 2 instead of 0 so can be changed to CONS { CONS, 2, GS_TCC_EXCEPTIONAL, "CONS" }, // Inbuilt Constructors: { IB_INT, 0, GS_TCC_EXCEPTIONAL, "IB_INT" }, { IB_UNSIGNED, 0, GS_TCC_EXCEPTIONAL, "IB_UNSIGNED" }, { IB_LONG_LONG, 0, GS_TCC_EXCEPTIONAL, "IB_LONG_LONG" }, { IB_LONG, 0, GS_TCC_EXCEPTIONAL, "IB_LONG" }, { IB_LONG_DOUBLE, 0, GS_TCC_EXCEPTIONAL, "IB_LONG_DOUBLE" }, { IB_UNSIGNED_LONG, 0, GS_TCC_EXCEPTIONAL, "IB_UNSIGNED_LONG" }, { IB_UNSIGNED_LONG_LONG, 0, GS_TCC_EXCEPTIONAL, "IB_UNSIGNED_LONG_LONG" }, { IB_CHAR, 0, GS_TCC_EXCEPTIONAL, "IB_CHAR" }, { IB_STRING, 0, GS_TCC_EXCEPTIONAL, "IB_STRING" }, { IB_FLOAT, 0, GS_TCC_EXCEPTIONAL, "IB_FLOAT" }, { IB_DOUBLE, 0, GS_TCC_EXCEPTIONAL, "IB_DOUBLE" }, { IB_BOOL, 0, GS_TCC_EXCEPTIONAL, "IB_BOOL" }, { IB_BIT_VECTOR, 0, GS_TCC_EXCEPTIONAL, "IB_BIT_VECTOR" }, { GS_TCC, 0, GS_TCC_EXCEPTIONAL, "GS_TCC" }, { GSBI, 0, GS_TCC_EXCEPTIONAL, "GSBI" }, { GSBI_CLASS, 0, GS_TCC_EXCEPTIONAL, "GSBI_CLASS" }, // GCC Specific tree codes: { GS_ABS_EXPR, 13, GS_TCC_UNARY, "GS_ABS_EXPR" }, { GS_ADDR_EXPR, 13, GS_TCC_EXPRESSION, "GS_ADDR_EXPR" }, { GS_ALIGNOF_EXPR, 13, GS_TCC_EXPRESSION, "GS_ALIGNOF_EXPR" }, { GS_ALIGN_INDIRECT_REF, 13, GS_TCC_REFERENCE, "GS_ALIGN_INDIRECT_REF" }, { GS_ARRAY_RANGE_REF, 13, GS_TCC_REFERENCE, "GS_ARRAY_RANGE_REF" }, { GS_ARRAY_REF, 13, GS_TCC_REFERENCE, "GS_ARRAY_REF" }, { GS_ARRAY_TYPE, 27, GS_TCC_TYPE, "GS_ARRAY_TYPE" }, { GS_ARROW_EXPR, 13, GS_TCC_EXPRESSION, "GS_ARROW_EXPR" }, { GS_ASM_EXPR, 13, GS_TCC_STATEMENT, "GS_ASM_EXPR" }, { GS_ASSIGN_STMT, 13, GS_TCC_STATEMENT, "GS_ASSIGN_STMT" }, { GS_BIND_EXPR, 13, GS_TCC_EXPRESSION, "GS_BIND_EXPR" }, { GS_BIT_AND_EXPR, 13, GS_TCC_BINARY, "GS_BIT_AND_EXPR" }, { GS_BIT_FIELD_REF, 13, GS_TCC_REFERENCE, "GS_BIT_FIELD_REF" }, { GS_BIT_IOR_EXPR, 13, GS_TCC_BINARY, "GS_BIT_IOR_EXPR" }, { GS_BIT_NOT_EXPR, 13, GS_TCC_BINARY, "GS_BIT_NOT_EXPR" }, { GS_BIT_XOR_EXPR, 13, GS_TCC_BINARY, "GS_BIT_XOR_EXPR" }, { GS_BLOCK, 9, GS_TCC_EXCEPTIONAL, "GS_BLOCK" }, { GS_BOOLEAN_TYPE, 27, GS_TCC_TYPE, "GS_BOOLEAN_TYPE" }, { GS_BREAK_STMT, 13, GS_TCC_EXPRESSION, "GS_BREAK_STMT" }, { GS_CALL_EXPR, 13, GS_TCC_EXPRESSION, "GS_CALL_EXPR" }, { GS_CASE_LABEL_EXPR, 13, GS_TCC_STATEMENT, "GS_CASE_LABEL_EXPR" }, { GS_CATCH_EXPR, 13, GS_TCC_STATEMENT, "GS_CATCH_EXPR" }, { GS_CEIL_DIV_EXPR, 13, GS_TCC_BINARY, "GS_CEIL_DIV_EXPR" }, { GS_CEIL_MOD_EXPR, 13, GS_TCC_BINARY, "GS_CEIL_MOD_EXPR" }, { GS_CHAR_TYPE, 27, GS_TCC_TYPE, "GS_CHAR_TYPE" }, { GS_CLEANUP, 13, GS_TCC_STATEMENT, "GS_CLEANUP" }, { GS_CLEANUP_POINT_EXPR, 13, GS_TCC_EXPRESSION, "GS_CLEANUP_POINT_EXPR" }, { GS_COMPLEX_CST, 7, GS_TCC_CONSTANT, "GS_COMPLEX_CST" }, { GS_COMPLEX_EXPR, 13, GS_TCC_EXPRESSION, "GS_COMPLEX_EXPR" }, { GS_COMPLEX_TYPE, 27, GS_TCC_TYPE, "GS_COMPLEX_TYPE" }, { GS_COMPONENT_REF, 13, GS_TCC_REFERENCE, "GS_COMPONENT_REF" }, { GS_COMPOUND_EXPR, 13, GS_TCC_EXPRESSION, "GS_COMPOUND_EXPR" }, { GS_COMPOUND_LITERAL_EXPR, 13, GS_TCC_EXPRESSION, "GS_COMPOUND_LITERAL_EXPR" }, { GS_COND_EXPR, 13, GS_TCC_EXPRESSION, "GS_COND_EXPR" }, { GS_CONJ_EXPR, 13, GS_TCC_EXPRESSION, "GS_CONJ_EXPR" }, { GS_CONSTRUCTOR, 13, GS_TCC_EXPRESSION, "GS_CONSTRUCTOR" }, { GS_CONST_DECL, 42, GS_TCC_DECLARATION, "GS_CONST_DECL" }, { GS_CONTINUE_STMT, 13, GS_TCC_EXPRESSION, "GS_CONTINUE_STMT" }, { GS_CONVERT_EXPR, 13, GS_TCC_UNARY, "GS_CONVERT_EXPR" }, { GS_DECL_EXPR, 13, GS_TCC_STATEMENT, "GS_DECL_EXPR" }, { GS_DO_STMT, 13, GS_TCC_EXPRESSION, "GS_DO_STMT" }, { GS_EH_FILTER_EXPR, 13, GS_TCC_EXPRESSION, "GS_EH_FILTER_EXPR" }, { GS_ENUMERAL_TYPE, 27, GS_TCC_TYPE, "GS_ENUMERAL_TYPE" }, { GS_EQ_EXPR, 13, GS_TCC_COMPARISON, "GS_EQ_EXPR" }, { GS_ERROR_MARK, 0, GS_TCC_EXCEPTIONAL, "GS_ERROR_MARK" }, { GS_EXACT_DIV_EXPR, 13, GS_TCC_BINARY, "GS_EXACT_DIV_EXPR" }, { GS_EXC_PTR_EXPR, 13, GS_TCC_EXPRESSION, "GS_EXC_PTR_EXPR" }, { GS_EXIT_EXPR, 13, GS_TCC_EXPRESSION, "GS_EXIT_EXPR" }, { GS_EXPR_STMT, 13, GS_TCC_EXPRESSION, "GS_EXPR_STMT" }, { GS_FDESC_EXPR, 13, GS_TCC_EXPRESSION, "GS_FDESC_EXPR" }, { GS_FIELD_DECL, 42, GS_TCC_DECLARATION, "GS_FIELD_DECL" }, { GS_FILE_TYPE, 27, GS_TCC_TYPE, "GS_FILE_TYPE" }, { GS_FILTER_EXPR, 13, GS_TCC_EXPRESSION, "GS_FILTER_EXPR" }, { GS_FIX_CEIL_EXPR, 13, GS_TCC_EXPRESSION, "GS_FIX_CEIL_EXPR" }, { GS_FIX_FLOOR_EXPR, 13, GS_TCC_EXPRESSION, "GS_FIX_FLOOR_EXPR" }, { GS_FIX_ROUND_EXPR, 13, GS_TCC_EXPRESSION, "GS_FIX_ROUND_EXPR" }, { GS_FIX_TRUNC_EXPR, 13, GS_TCC_EXPRESSION, "GS_FIX_TRUNC_EXPR" }, { GS_FLOAT_EXPR, 13, GS_TCC_UNARY, "GS_FLOAT_EXPR" }, { GS_FLOOR_DIV_EXPR, 13, GS_TCC_BINARY, "GS_FLOOR_DIV_EXPR" }, { GS_FLOOR_MOD_EXPR, 13, GS_TCC_BINARY, "GS_FLOOR_MOD_EXPR" }, { GS_FOR_STMT, 13, GS_TCC_EXPRESSION, "GS_FOR_STMT" }, { GS_FUNCTION_DECL, 42, GS_TCC_DECLARATION, "GS_FUNCTION_DECL" }, { GS_FUNCTION_TYPE, 27, GS_TCC_TYPE, "GS_FUNCTION_TYPE" }, { GS_GE_EXPR, 13, GS_TCC_COMPARISON, "GS_GE_EXPR" }, { GS_GOTO_EXPR, 13, GS_TCC_STATEMENT, "GS_GOTO_EXPR" }, { GS_GT_EXPR, 13, GS_TCC_COMPARISON, "GS_GT_EXPR" }, { GS_IDENTIFIER_NODE, 9, GS_TCC_EXCEPTIONAL, "GS_IDENTIFIER_NODE" }, { GS_IMAGPART_EXPR, 13, GS_TCC_EXPRESSION, "GS_IMAGPART_EXPR" }, { GS_INDIRECT_REF, 13, GS_TCC_REFERENCE, "GS_INDIRECT_REF" }, { GS_INIT_EXPR, 13, GS_TCC_EXPRESSION, "GS_INIT_EXPR" }, { GS_INTEGER_CST, 7, GS_TCC_CONSTANT, "GS_INTEGER_CST" }, { GS_INTEGER_TYPE, 27, GS_TCC_TYPE, "GS_INTEGER_TYPE" }, { GS_LABEL_DECL, 42, GS_TCC_DECLARATION, "GS_LABEL_DECL" }, { GS_LABEL_EXPR, 13, GS_TCC_STATEMENT, "GS_LABEL_EXPR" }, { GS_LANG_TYPE, 27, GS_TCC_TYPE, "GS_LANG_TYPE" }, { GS_LE_EXPR, 13, GS_TCC_COMPARISON, "GS_LE_EXPR" }, { GS_LOOP_EXPR, 13, GS_TCC_EXPRESSION, "GS_LOOP_EXPR" }, { GS_LROTATE_EXPR, 13, GS_TCC_BINARY, "GS_LROTATE_EXPR" }, { GS_LSHIFT_EXPR, 13, GS_TCC_BINARY, "GS_LSHIFT_EXPR" }, { GS_LTGT_EXPR, 13, GS_TCC_COMPARISON, "GS_LTGT_EXPR" }, { GS_LT_EXPR, 13, GS_TCC_COMPARISON, "GS_LT_EXPR" }, { GS_MAX_EXPR, 13, GS_TCC_BINARY, "GS_MAX_EXPR" }, { GS_METHOD_TYPE, 27, GS_TCC_TYPE, "GS_METHOD_TYPE" }, { GS_MINUS_EXPR, 13, GS_TCC_BINARY, "GS_MINUS_EXPR" }, { GS_MIN_EXPR, 13, GS_TCC_BINARY, "GS_MIN_EXPR" }, { GS_MISALIGNED_INDIRECT_REF, 13, GS_TCC_REFERENCE, "GS_MISALIGNED_INDIRECT_REF" }, { GS_MODIFY_EXPR, 13, GS_TCC_EXPRESSION, "GS_MODIFY_EXPR" }, { GS_MULT_EXPR, 13, GS_TCC_BINARY, "GS_MULT_EXPR" }, { GS_NAMESPACE_DECL, 42, GS_TCC_DECLARATION, "GS_NAMESPACE_DECL" }, { GS_NEGATE_EXPR, 13, GS_TCC_UNARY, "GS_NEGATE_EXPR" }, { GS_NE_EXPR, 13, GS_TCC_COMPARISON, "GS_NE_EXPR" }, { GS_NON_LVALUE_EXPR, 13, GS_TCC_EXPRESSION, "GS_NON_LVALUE_EXPR" }, { GS_NOP_EXPR, 13, GS_TCC_UNARY, "GS_NOP_EXPR" }, { GS_OBJ_TYPE_REF, 13, GS_TCC_REFERENCE, "GS_OBJ_TYPE_REF" }, { GS_OFFSET_TYPE, 27, GS_TCC_TYPE, "GS_OFFSET_TYPE" }, { GS_ORDERED_EXPR, 13, GS_TCC_EXPRESSION, "GS_ORDERED_EXPR" }, { GS_PARM_DECL, 42, GS_TCC_DECLARATION, "GS_PARM_DECL" }, { GS_PHI_NODE, 9, GS_TCC_EXCEPTIONAL, "GS_PHI_NODE" }, { GS_PLACEHOLDER_EXPR, 13, GS_TCC_EXPRESSION, "GS_PLACEHOLDER_EXPR" }, { GS_PLUS_EXPR, 13, GS_TCC_BINARY, "GS_PLUS_EXPR" }, { GS_POINTER_TYPE, 27, GS_TCC_TYPE, "GS_POINTER_TYPE" }, { GS_POLYNOMIAL_CHREC, 13, GS_TCC_EXPRESSION, "GS_POLYNOMIAL_CHREC" }, { GS_POSTDECREMENT_EXPR, 13, GS_TCC_EXPRESSION, "GS_POSTDECREMENT_EXPR" }, { GS_POSTINCREMENT_EXPR, 13, GS_TCC_EXPRESSION, "GS_POSTINCREMENT_EXPR" }, { GS_PREDECREMENT_EXPR, 13, GS_TCC_EXPRESSION, "GS_PREDECREMENT_EXPR" }, { GS_PREINCREMENT_EXPR, 13, GS_TCC_EXPRESSION, "GS_PREINCREMENT_EXPR" }, { GS_PROGRAM, 8, GS_TCC_EXCEPTIONAL, "GS_PROGRAM" }, { GS_QUAL_UNION_TYPE, 27, GS_TCC_TYPE, "GS_QUAL_UNION_TYPE" }, { GS_RANGE_EXPR, 13, GS_TCC_EXPRESSION, "GS_RANGE_EXPR" }, { GS_RDIV_EXPR, 13, GS_TCC_BINARY, "GS_RDIV_EXPR" }, { GS_REALIGN_LOAD_EXPR, 13, GS_TCC_EXPRESSION, "GS_REALIGN_LOAD_EXPR" }, { GS_REALPART_EXPR, 13, GS_TCC_EXPRESSION, "GS_REALPART_EXPR" }, { GS_REAL_CST, 7, GS_TCC_CONSTANT, "GS_REAL_CST" }, { GS_REAL_TYPE, 27, GS_TCC_TYPE, "GS_REAL_TYPE" }, { GS_RECORD_TYPE, 27, GS_TCC_TYPE, "GS_RECORD_TYPE" }, { GS_REFERENCE_TYPE, 27, GS_TCC_TYPE, "GS_REFERENCE_TYPE" }, { GS_RESULT_DECL, 42, GS_TCC_DECLARATION, "GS_RESULT_DECL" }, { GS_RESX_EXPR, 13, GS_TCC_EXPRESSION, "GS_RESX_EXPR" }, { GS_RETURN_EXPR, 13, GS_TCC_STATEMENT, "GS_RETURN_EXPR" }, { GS_ROUND_DIV_EXPR, 13, GS_TCC_BINARY, "GS_ROUND_DIV_EXPR" }, { GS_ROUND_MOD_EXPR, 13, GS_TCC_BINARY, "GS_ROUND_MOD_EXPR" }, { GS_RROTATE_EXPR, 13, GS_TCC_BINARY, "GS_RROTATE_EXPR" }, { GS_RSHIFT_EXPR, 13, GS_TCC_BINARY, "GS_RSHIFT_EXPR" }, { GS_SAVE_EXPR, 13, GS_TCC_EXPRESSION, "GS_SAVE_EXPR" }, { GS_SCEV_KNOWN, 13, GS_TCC_EXPRESSION, "GS_SCEV_KNOWN" }, { GS_SCEV_NOT_KNOWN, 13, GS_TCC_EXPRESSION, "GS_SCEV_NOT_KNOWN" }, { GS_SCOPE, 13, GS_TCC_REFERENCE, "GS_SCOPE" }, { GS_SCOPE_STMT, 13, GS_TCC_STATEMENT, "GS_SCOPE_STMT" }, { GS_SIZEOF_EXPR, 13, GS_TCC_EXPRESSION, "GS_SIZEOF_EXPR" }, { GS_SSA_NAME, 9, GS_TCC_EXCEPTIONAL, "GS_SSA_NAME" }, { GS_STATEMENT_LIST, 9, GS_TCC_EXCEPTIONAL, "GS_STATEMENT_LIST" }, { GS_STMT_EXPR, 13, GS_TCC_EXPRESSION, "GS_STMT_EXPR" }, { GS_STRING_CST, 7, GS_TCC_CONSTANT, "GS_STRING_CST" }, { GS_SWITCH_EXPR, 13, GS_TCC_EXPRESSION, "GS_SWITCH_EXPR" }, { GS_SWITCH_STMT, 13, GS_TCC_EXPRESSION, "GS_SWITCH_STMT" }, { GS_TARGET_EXPR, 13, GS_TCC_EXPRESSION, "GS_TARGET_EXPR" }, { GS_TRANSLATION_UNIT_DECL, 42, GS_TCC_DECLARATION, "GS_TRANSLATION_UNIT_DECL" }, { GS_TREE_BINFO, 9, GS_TCC_EXCEPTIONAL, "GS_TREE_BINFO" }, { GS_TREE_LIST, 9, GS_TCC_EXCEPTIONAL, "GS_TREE_LIST" }, { GS_TREE_VEC, 9, GS_TCC_EXCEPTIONAL, "GS_TREE_VEC" }, { GS_TRUNC_DIV_EXPR, 13, GS_TCC_BINARY, "GS_TRUNC_DIV_EXPR" }, { GS_TRUNC_MOD_EXPR, 13, GS_TCC_BINARY, "GS_TRUNC_MOD_EXPR" }, { GS_TRUTH_ANDIF_EXPR, 13, GS_TCC_EXPRESSION, "GS_TRUTH_ANDIF_EXPR" }, { GS_TRUTH_AND_EXPR, 13, GS_TCC_EXPRESSION, "GS_TRUTH_AND_EXPR" }, { GS_TRUTH_NOT_EXPR, 13, GS_TCC_EXPRESSION, "GS_TRUTH_NOT_EXPR" }, { GS_TRUTH_ORIF_EXPR, 13, GS_TCC_EXPRESSION, "GS_TRUTH_ORIF_EXPR" }, { GS_TRUTH_OR_EXPR, 13, GS_TCC_EXPRESSION, "GS_TRUTH_OR_EXPR" }, { GS_TRUTH_XOR_EXPR, 13, GS_TCC_EXPRESSION, "GS_TRUTH_XOR_EXPR" }, { GS_TRY_BLOCK, 13, GS_TCC_EXPRESSION, "GS_TRY_BLOCK" }, { GS_TRY_CATCH_EXPR, 13, GS_TCC_EXPRESSION, "GS_TRY_CATCH_EXPR" }, { GS_TRY_FINALLY_EXPR, 13, GS_TCC_EXPRESSION, "GS_TRY_FINALLY_EXPR" }, { GS_TYPE_DECL, 42, GS_TCC_DECLARATION, "GS_TYPE_DECL" }, { GS_UNEQ_EXPR, 13, GS_TCC_COMPARISON, "GS_UNEQ_EXPR" }, { GS_UNGE_EXPR, 13, GS_TCC_COMPARISON, "GS_UNGE_EXPR" }, { GS_UNGT_EXPR, 13, GS_TCC_COMPARISON, "GS_UNGT_EXPR" }, { GS_UNION_TYPE, 27, GS_TCC_TYPE, "GS_UNION_TYPE" }, { GS_UNLE_EXPR, 13, GS_TCC_COMPARISON, "GS_UNLE_EXPR" }, { GS_UNLT_EXPR, 13, GS_TCC_COMPARISON, "GS_UNLT_EXPR" }, { GS_UNORDERED_EXPR, 13, GS_TCC_COMPARISON, "GS_UNORDERED_EXPR" }, { GS_VALUE_HANDLE, 9, GS_TCC_EXCEPTIONAL, "GS_VALUE_HANDLE" }, { GS_VAR_DECL, 42, GS_TCC_DECLARATION, "GS_VAR_DECL" }, { GS_VA_ARG_EXPR, 13, GS_TCC_EXPRESSION, "GS_VA_ARG_EXPR" }, { GS_VECTOR_CST, 7, GS_TCC_CONSTANT, "GS_VECTOR_CST" }, { GS_VECTOR_TYPE, 27, GS_TCC_TYPE, "GS_VECTOR_TYPE" }, { GS_VEC_COND_EXPR, 13, GS_TCC_EXPRESSION, "GS_VEC_COND_EXPR" }, { GS_VIEW_CONVERT_EXPR, 13, GS_TCC_UNARY, "GS_VIEW_CONVERT_EXPR" }, { GS_VOID_TYPE, 27, GS_TCC_TYPE, "GS_VOID_TYPE" }, { GS_WHILE_STMT, 13, GS_TCC_EXPRESSION, "GS_WHILE_STMT" }, { GS_WITH_CLEANUP_EXPR, 13, GS_TCC_EXPRESSION, "GS_WITH_CLEANUP_EXPR" }, { GS_WITH_SIZE_EXPR, 13, GS_TCC_EXPRESSION, "GS_WITH_SIZE_EXPR" }, { GS_AGGR_INIT_EXPR, 13, GS_TCC_EXPRESSION, "GS_AGGR_INIT_EXPR" }, { GS_BASELINK, 9, GS_TCC_EXCEPTIONAL, "GS_BASELINK" }, { GS_BOUND_TEMPLATE_TEMPLATE_PARM, 27, GS_TCC_TYPE, "GS_BOUND_TEMPLATE_TEMPLATE_PARM" }, { GS_CAST_EXPR, 13, GS_TCC_EXPRESSION, "GS_CAST_EXPR" }, { GS_CONST_CAST_EXPR, 13, GS_TCC_EXPRESSION, "GS_CONST_CAST_EXPR" }, { GS_CLEANUP_STMT, 13, GS_TCC_EXPRESSION, "GS_CLEANUP_STMT" }, { GS_CTOR_INITIALIZER, 13, GS_TCC_EXPRESSION, "GS_CTOR_INITIALIZER" }, { GS_DELETE_EXPR, 13, GS_TCC_EXPRESSION, "GS_DELETE_EXPR" }, { GS_DEFAULT_ARG, 9, GS_TCC_EXCEPTIONAL, "GS_DEFAULT_ARG" }, { GS_DYNAMIC_CAST_EXPR, 13, GS_TCC_EXPRESSION, "GS_DYNAMIC_CAST_EXPR" }, { GS_DOTSTAR_EXPR, 13, GS_TCC_EXPRESSION, "GS_DOTSTAR_EXPR" }, { GS_EMPTY_CLASS_EXPR, 13, GS_TCC_EXPRESSION, "GS_EMPTY_CLASS_EXPR" }, { GS_EH_SPEC_BLOCK, 13, GS_TCC_EXPRESSION, "GS_EH_SPEC_BLOCK" }, { GS_HANDLER, 13, GS_TCC_EXPRESSION, "GS_HANDLER" }, { GS_IF_STMT, 13, GS_TCC_EXPRESSION, "GS_IF_STMT" }, { GS_MEMBER_REF, 13, GS_TCC_REFERENCE, "GS_MEMBER_REF" }, { GS_MODOP_EXPR, 13, GS_TCC_EXPRESSION, "GS_MODOP_EXPR" }, { GS_MUST_NOT_THROW_EXPR, 13, GS_TCC_EXPRESSION, "GS_MUST_NOT_THROW_EXPR" }, { GS_NEW_EXPR, 13, GS_TCC_EXPRESSION, "GS_NEW_EXPR" }, { GS_NON_DEPENDENT_EXPR, 13, GS_TCC_EXPRESSION, "GS_NON_DEPENDENT_EXPR" }, { GS_OFFSET_REF, 13, GS_TCC_REFERENCE, "GS_OFFSET_REF" }, { GS_OFFSETOF_EXPR, 13, GS_TCC_EXPRESSION, "GS_OFFSETOF_EXPR" }, { GS_OVERLOAD, 9, GS_TCC_EXCEPTIONAL, "GS_OVERLOAD" }, { GS_PTRMEM_CST, 7, GS_TCC_CONSTANT, "GS_PTRMEM_CST" }, { GS_PSEUDO_DTOR_EXPR, 13, GS_TCC_EXPRESSION, "GS_PSEUDO_DTOR_EXPR" }, { GS_REINTERPRET_CAST_EXPR, 13, GS_TCC_EXPRESSION, "GS_REINTERPRET_CAST_EXPR" }, { GS_SCOPE_REF, 13, GS_TCC_REFERENCE, "GS_SCOPE_REF" }, { GS_STATIC_CAST_EXPR, 13, GS_TCC_EXPRESSION, "GS_STATIC_CAST_EXPR" }, { GS_TAG_DEFN, 13, GS_TCC_EXPRESSION, "GS_TAG_DEFN" }, { GS_TEMPLATE_DECL, 42, GS_TCC_DECLARATION, "GS_TEMPLATE_DECL" }, { GS_TEMPLATE_ID_EXPR, 13, GS_TCC_EXPRESSION, "GS_TEMPLATE_ID_EXPR" }, { GS_TEMPLATE_PARM_INDEX, 9, GS_TCC_EXCEPTIONAL, "GS_TEMPLATE_PARM_INDEX" }, { GS_TEMPLATE_TYPE_PARM, 27, GS_TCC_TYPE, "GS_TEMPLATE_TYPE_PARM" }, { GS_THROW_EXPR, 13, GS_TCC_EXPRESSION, "GS_THROW_EXPR" }, { GS_TINST_LEVEL, 9, GS_TCC_EXCEPTIONAL, "GS_TINST_LEVEL" }, { GS_TYPEOF_TYPE, 27, GS_TCC_TYPE, "GS_TYPEOF_TYPE" }, { GS_TYPENAME_TYPE, 27, GS_TCC_TYPE, "GS_TYPENAME_TYPE" }, { GS_TYPE_EXPR, 13, GS_TCC_EXPRESSION, "GS_TYPE_EXPR" }, { GS_TYPEID_EXPR, 13, GS_TCC_EXPRESSION, "GS_TYPEID_EXPR" }, { GS_USING_DECL, 42, GS_TCC_DECLARATION, "GS_USING_DECL" }, { GS_USING_STMT, 13, GS_TCC_EXPRESSION, "GS_USING_STMT" }, { GS_UNBOUND_CLASS_TEMPLATE, 27, GS_TCC_TYPE, "GS_UNBOUND_CLASS_TEMPLATE" }, { GS_VEC_DELETE_EXPR, 13, GS_TCC_EXPRESSION, "GS_VEC_DELETE_EXPR" }, { GS_VEC_NEW_EXPR, 13, GS_TCC_EXPRESSION, "GS_VEC_NEW_EXPR" }, { GS_TEMPLATE_TEMPLATE_PARM, 27, GS_TCC_TYPE, "GS_TEMPLATE_TEMPLATE_PARM" }, }; // return storage size in bytes for the gspin node int gspin_node_size(gs_code_t code) { int arity = gs_code_arity(code); if (arity != 0) return (1 + arity) * sizeof(char *); switch (code) { case IB_CHAR: case IB_BOOL: case GS_TCC: case GSBI: case GSBI_CLASS: case GS_ERROR_MARK: return 1*sizeof(char*); case IB_UNSIGNED: case IB_UNSIGNED_LONG: case IB_INT: case IB_LONG: case IB_FLOAT: case IB_STRING: return 2*sizeof(char*); case IB_LONG_LONG: case IB_UNSIGNED_LONG_LONG: case IB_BIT_VECTOR: case IB_DOUBLE: return 4*sizeof(char*); case IB_LONG_DOUBLE: return 5*sizeof(char*); default: GS_ASSERT(false, "gspin_node_size(): unrecognied tree code"); } } #ifdef Is_True_On int num_gspin_nodes = 0; int arity_dist[45] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; #endif gs_t __gs (gs_code_t code) { GS_ASSERT (code != DOT, "__gs() called with DOT"); int size = gspin_node_size(code); gs_t node = (gs_t) __gs_mempool_alloc(GS_ARENA, size); _gs_code(node, code); if (gs_mempool[GS_ARENA].current_index >= 0x3fffffff) { fprintf(stderr, "gspin mempool overflow.\n"); abort(); } #ifdef Is_True_On num_gspin_nodes++; arity_dist[tree_code_table[code].arity]++; #endif return node; } #ifdef Is_True_On void dump_arity_dist(void) { int i; for (i = 0; i < 45; i++) if (arity_dist[i] != 0) printf("%d: %d\n", i, arity_dist[i]); } #endif gs_void_t _gs_s (gs_t node, const gs_string_t s, gs_unsigned_long_t length) { GS_ASSERT (node != (gs_t) NULL, "Got null node"); node->u1.s = (gs_string_t) __gs_mempool_alloc (IB_STRING_ARENA, length); memcpy (gs_s(node), s, length); _gs_slen (node, length); return; } char *gs_code_name (gs_code_t code) { return tree_code_table[code].name; } int gs_code_arity(gs_code_t code) { return tree_code_table[code].arity; } gs_string_t gs_tree_code_class_name (gs_tree_code_class_t code) { switch (code) { case GS_TCC_EXCEPTIONAL: return (gs_string_t) "GS_TCC_EXCEPTIONAL"; case GS_TCC_CONSTANT: return (gs_string_t) "GS_TCC_CONSTANT"; case GS_TCC_TYPE: return (gs_string_t) "GS_TCC_TYPE"; case GS_TCC_DECLARATION: return (gs_string_t) "GS_TCC_DECLARATION"; case GS_TCC_REFERENCE: return (gs_string_t) "GS_TCC_REFERENCE"; case GS_TCC_COMPARISON: return (gs_string_t) "GS_TCC_COMPARISON"; case GS_TCC_UNARY: return (gs_string_t) "GS_TCC_UNARY"; case GS_TCC_BINARY: return (gs_string_t) "GS_TCC_BINARY"; case GS_TCC_STATEMENT: return (gs_string_t) "GS_TCC_STATEMENT"; case GS_TCC_EXPRESSION: return (gs_string_t) "GS_TCC_EXPRESSION"; } GS_ASSERT (gs_false, (gs_string_t) "Unexpected tree code class."); return (char *) NULL; } gs_string_t gsbi_name (gsbi_t code) { switch (code) { case GSBI_BUILT_IN_ACOS: return "GSBI_BUILT_IN_ACOS"; case GSBI_BUILT_IN_ACOSF: return "GSBI_BUILT_IN_ACOSF"; case GSBI_BUILT_IN_ACOSH: return "GSBI_BUILT_IN_ACOSH"; case GSBI_BUILT_IN_ACOSHF: return "GSBI_BUILT_IN_ACOSHF"; case GSBI_BUILT_IN_ACOSHL: return "GSBI_BUILT_IN_ACOSHL"; case GSBI_BUILT_IN_ACOSL: return "GSBI_BUILT_IN_ACOSL"; case GSBI_BUILT_IN_ASIN: return "GSBI_BUILT_IN_ASIN"; case GSBI_BUILT_IN_ASINF: return "GSBI_BUILT_IN_ASINF"; case GSBI_BUILT_IN_ASINH: return "GSBI_BUILT_IN_ASINH"; case GSBI_BUILT_IN_ASINHF: return "GSBI_BUILT_IN_ASINHF"; case GSBI_BUILT_IN_ASINHL: return "GSBI_BUILT_IN_ASINHL"; case GSBI_BUILT_IN_ASINL: return "GSBI_BUILT_IN_ASINL"; case GSBI_BUILT_IN_ATAN: return "GSBI_BUILT_IN_ATAN"; case GSBI_BUILT_IN_ATAN2: return "GSBI_BUILT_IN_ATAN2"; case GSBI_BUILT_IN_ATAN2F: return "GSBI_BUILT_IN_ATAN2F"; case GSBI_BUILT_IN_ATAN2L: return "GSBI_BUILT_IN_ATAN2L"; case GSBI_BUILT_IN_ATANF: return "GSBI_BUILT_IN_ATANF"; case GSBI_BUILT_IN_ATANH: return "GSBI_BUILT_IN_ATANH"; case GSBI_BUILT_IN_ATANHF: return "GSBI_BUILT_IN_ATANHF"; case GSBI_BUILT_IN_ATANHL: return "GSBI_BUILT_IN_ATANHL"; case GSBI_BUILT_IN_ATANL: return "GSBI_BUILT_IN_ATANL"; case GSBI_BUILT_IN_CBRT: return "GSBI_BUILT_IN_CBRT"; case GSBI_BUILT_IN_CBRTF: return "GSBI_BUILT_IN_CBRTF"; case GSBI_BUILT_IN_CBRTL: return "GSBI_BUILT_IN_CBRTL"; case GSBI_BUILT_IN_CEIL: return "GSBI_BUILT_IN_CEIL"; case GSBI_BUILT_IN_CEILF: return "GSBI_BUILT_IN_CEILF"; case GSBI_BUILT_IN_CEILL: return "GSBI_BUILT_IN_CEILL"; case GSBI_BUILT_IN_COPYSIGN: return "GSBI_BUILT_IN_COPYSIGN"; case GSBI_BUILT_IN_COPYSIGNF: return "GSBI_BUILT_IN_COPYSIGNF"; case GSBI_BUILT_IN_COPYSIGNL: return "GSBI_BUILT_IN_COPYSIGNL"; case GSBI_BUILT_IN_COS: return "GSBI_BUILT_IN_COS"; case GSBI_BUILT_IN_COSF: return "GSBI_BUILT_IN_COSF"; case GSBI_BUILT_IN_COSH: return "GSBI_BUILT_IN_COSH"; case GSBI_BUILT_IN_COSHF: return "GSBI_BUILT_IN_COSHF"; case GSBI_BUILT_IN_COSHL: return "GSBI_BUILT_IN_COSHL"; case GSBI_BUILT_IN_COSL: return "GSBI_BUILT_IN_COSL"; case GSBI_BUILT_IN_DREM: return "GSBI_BUILT_IN_DREM"; case GSBI_BUILT_IN_DREMF: return "GSBI_BUILT_IN_DREMF"; case GSBI_BUILT_IN_DREML: return "GSBI_BUILT_IN_DREML"; case GSBI_BUILT_IN_ERF: return "GSBI_BUILT_IN_ERF"; case GSBI_BUILT_IN_ERFC: return "GSBI_BUILT_IN_ERFC"; case GSBI_BUILT_IN_ERFCF: return "GSBI_BUILT_IN_ERFCF"; case GSBI_BUILT_IN_ERFCL: return "GSBI_BUILT_IN_ERFCL"; case GSBI_BUILT_IN_ERFF: return "GSBI_BUILT_IN_ERFF"; case GSBI_BUILT_IN_ERFL: return "GSBI_BUILT_IN_ERFL"; case GSBI_BUILT_IN_EXP: return "GSBI_BUILT_IN_EXP"; case GSBI_BUILT_IN_EXP10: return "GSBI_BUILT_IN_EXP10"; case GSBI_BUILT_IN_EXP10F: return "GSBI_BUILT_IN_EXP10F"; case GSBI_BUILT_IN_EXP10L: return "GSBI_BUILT_IN_EXP10L"; case GSBI_BUILT_IN_EXP2: return "GSBI_BUILT_IN_EXP2"; case GSBI_BUILT_IN_EXP2F: return "GSBI_BUILT_IN_EXP2F"; case GSBI_BUILT_IN_EXP2L: return "GSBI_BUILT_IN_EXP2L"; case GSBI_BUILT_IN_EXPF: return "GSBI_BUILT_IN_EXPF"; case GSBI_BUILT_IN_EXPL: return "GSBI_BUILT_IN_EXPL"; case GSBI_BUILT_IN_EXPM1: return "GSBI_BUILT_IN_EXPM1"; case GSBI_BUILT_IN_EXPM1F: return "GSBI_BUILT_IN_EXPM1F"; case GSBI_BUILT_IN_EXPM1L: return "GSBI_BUILT_IN_EXPM1L"; case GSBI_BUILT_IN_FABS: return "GSBI_BUILT_IN_FABS"; case GSBI_BUILT_IN_FABSF: return "GSBI_BUILT_IN_FABSF"; case GSBI_BUILT_IN_FABSL: return "GSBI_BUILT_IN_FABSL"; case GSBI_BUILT_IN_FDIM: return "GSBI_BUILT_IN_FDIM"; case GSBI_BUILT_IN_FDIMF: return "GSBI_BUILT_IN_FDIMF"; case GSBI_BUILT_IN_FDIML: return "GSBI_BUILT_IN_FDIML"; case GSBI_BUILT_IN_FLOOR: return "GSBI_BUILT_IN_FLOOR"; case GSBI_BUILT_IN_FLOORF: return "GSBI_BUILT_IN_FLOORF"; case GSBI_BUILT_IN_FLOORL: return "GSBI_BUILT_IN_FLOORL"; case GSBI_BUILT_IN_FMA: return "GSBI_BUILT_IN_FMA"; case GSBI_BUILT_IN_FMAF: return "GSBI_BUILT_IN_FMAF"; case GSBI_BUILT_IN_FMAL: return "GSBI_BUILT_IN_FMAL"; case GSBI_BUILT_IN_FMAX: return "GSBI_BUILT_IN_FMAX"; case GSBI_BUILT_IN_FMAXF: return "GSBI_BUILT_IN_FMAXF"; case GSBI_BUILT_IN_FMAXL: return "GSBI_BUILT_IN_FMAXL"; case GSBI_BUILT_IN_FMIN: return "GSBI_BUILT_IN_FMIN"; case GSBI_BUILT_IN_FMINF: return "GSBI_BUILT_IN_FMINF"; case GSBI_BUILT_IN_FMINL: return "GSBI_BUILT_IN_FMINL"; case GSBI_BUILT_IN_FMOD: return "GSBI_BUILT_IN_FMOD"; case GSBI_BUILT_IN_FMODF: return "GSBI_BUILT_IN_FMODF"; case GSBI_BUILT_IN_FMODL: return "GSBI_BUILT_IN_FMODL"; case GSBI_BUILT_IN_FREXP: return "GSBI_BUILT_IN_FREXP"; case GSBI_BUILT_IN_FREXPF: return "GSBI_BUILT_IN_FREXPF"; case GSBI_BUILT_IN_FREXPL: return "GSBI_BUILT_IN_FREXPL"; case GSBI_BUILT_IN_GAMMA: return "GSBI_BUILT_IN_GAMMA"; case GSBI_BUILT_IN_GAMMAF: return "GSBI_BUILT_IN_GAMMAF"; case GSBI_BUILT_IN_GAMMAL: return "GSBI_BUILT_IN_GAMMAL"; case GSBI_BUILT_IN_HUGE_VAL: return "GSBI_BUILT_IN_HUGE_VAL"; case GSBI_BUILT_IN_HUGE_VALF: return "GSBI_BUILT_IN_HUGE_VALF"; case GSBI_BUILT_IN_HUGE_VALL: return "GSBI_BUILT_IN_HUGE_VALL"; case GSBI_BUILT_IN_HYPOT: return "GSBI_BUILT_IN_HYPOT"; case GSBI_BUILT_IN_HYPOTF: return "GSBI_BUILT_IN_HYPOTF"; case GSBI_BUILT_IN_HYPOTL: return "GSBI_BUILT_IN_HYPOTL"; case GSBI_BUILT_IN_ILOGB: return "GSBI_BUILT_IN_ILOGB"; case GSBI_BUILT_IN_ILOGBF: return "GSBI_BUILT_IN_ILOGBF"; case GSBI_BUILT_IN_ILOGBL: return "GSBI_BUILT_IN_ILOGBL"; case GSBI_BUILT_IN_INF: return "GSBI_BUILT_IN_INF"; case GSBI_BUILT_IN_INFF: return "GSBI_BUILT_IN_INFF"; case GSBI_BUILT_IN_INFL: return "GSBI_BUILT_IN_INFL"; case GSBI_BUILT_IN_J0: return "GSBI_BUILT_IN_J0"; case GSBI_BUILT_IN_J0F: return "GSBI_BUILT_IN_J0F"; case GSBI_BUILT_IN_J0L: return "GSBI_BUILT_IN_J0L"; case GSBI_BUILT_IN_J1: return "GSBI_BUILT_IN_J1"; case GSBI_BUILT_IN_J1F: return "GSBI_BUILT_IN_J1F"; case GSBI_BUILT_IN_J1L: return "GSBI_BUILT_IN_J1L"; case GSBI_BUILT_IN_JN: return "GSBI_BUILT_IN_JN"; case GSBI_BUILT_IN_JNF: return "GSBI_BUILT_IN_JNF"; case GSBI_BUILT_IN_JNL: return "GSBI_BUILT_IN_JNL"; case GSBI_BUILT_IN_LDEXP: return "GSBI_BUILT_IN_LDEXP"; case GSBI_BUILT_IN_LDEXPF: return "GSBI_BUILT_IN_LDEXPF"; case GSBI_BUILT_IN_LDEXPL: return "GSBI_BUILT_IN_LDEXPL"; case GSBI_BUILT_IN_LGAMMA: return "GSBI_BUILT_IN_LGAMMA"; case GSBI_BUILT_IN_LGAMMAF: return "GSBI_BUILT_IN_LGAMMAF"; case GSBI_BUILT_IN_LGAMMAL: return "GSBI_BUILT_IN_LGAMMAL"; case GSBI_BUILT_IN_LLRINT: return "GSBI_BUILT_IN_LLRINT"; case GSBI_BUILT_IN_LLRINTF: return "GSBI_BUILT_IN_LLRINTF"; case GSBI_BUILT_IN_LLRINTL: return "GSBI_BUILT_IN_LLRINTL"; case GSBI_BUILT_IN_LLROUND: return "GSBI_BUILT_IN_LLROUND"; case GSBI_BUILT_IN_LLROUNDF: return "GSBI_BUILT_IN_LLROUNDF"; case GSBI_BUILT_IN_LLROUNDL: return "GSBI_BUILT_IN_LLROUNDL"; case GSBI_BUILT_IN_LOG: return "GSBI_BUILT_IN_LOG"; case GSBI_BUILT_IN_LOG10: return "GSBI_BUILT_IN_LOG10"; case GSBI_BUILT_IN_LOG10F: return "GSBI_BUILT_IN_LOG10F"; case GSBI_BUILT_IN_LOG10L: return "GSBI_BUILT_IN_LOG10L"; case GSBI_BUILT_IN_LOG1P: return "GSBI_BUILT_IN_LOG1P"; case GSBI_BUILT_IN_LOG1PF: return "GSBI_BUILT_IN_LOG1PF"; case GSBI_BUILT_IN_LOG1PL: return "GSBI_BUILT_IN_LOG1PL"; case GSBI_BUILT_IN_LOG2: return "GSBI_BUILT_IN_LOG2"; case GSBI_BUILT_IN_LOG2F: return "GSBI_BUILT_IN_LOG2F"; case GSBI_BUILT_IN_LOG2L: return "GSBI_BUILT_IN_LOG2L"; case GSBI_BUILT_IN_LOGB: return "GSBI_BUILT_IN_LOGB"; case GSBI_BUILT_IN_LOGBF: return "GSBI_BUILT_IN_LOGBF"; case GSBI_BUILT_IN_LOGBL: return "GSBI_BUILT_IN_LOGBL"; case GSBI_BUILT_IN_LOGF: return "GSBI_BUILT_IN_LOGF"; case GSBI_BUILT_IN_LOGL: return "GSBI_BUILT_IN_LOGL"; case GSBI_BUILT_IN_LRINT: return "GSBI_BUILT_IN_LRINT"; case GSBI_BUILT_IN_LRINTF: return "GSBI_BUILT_IN_LRINTF"; case GSBI_BUILT_IN_LRINTL: return "GSBI_BUILT_IN_LRINTL"; case GSBI_BUILT_IN_LROUND: return "GSBI_BUILT_IN_LROUND"; case GSBI_BUILT_IN_LROUNDF: return "GSBI_BUILT_IN_LROUNDF"; case GSBI_BUILT_IN_LROUNDL: return "GSBI_BUILT_IN_LROUNDL"; case GSBI_BUILT_IN_MODF: return "GSBI_BUILT_IN_MODF"; case GSBI_BUILT_IN_MODFF: return "GSBI_BUILT_IN_MODFF"; case GSBI_BUILT_IN_MODFL: return "GSBI_BUILT_IN_MODFL"; case GSBI_BUILT_IN_NAN: return "GSBI_BUILT_IN_NAN"; case GSBI_BUILT_IN_NANF: return "GSBI_BUILT_IN_NANF"; case GSBI_BUILT_IN_NANL: return "GSBI_BUILT_IN_NANL"; case GSBI_BUILT_IN_NANS: return "GSBI_BUILT_IN_NANS"; case GSBI_BUILT_IN_NANSF: return "GSBI_BUILT_IN_NANSF"; case GSBI_BUILT_IN_NANSL: return "GSBI_BUILT_IN_NANSL"; case GSBI_BUILT_IN_NEARBYINT: return "GSBI_BUILT_IN_NEARBYINT"; case GSBI_BUILT_IN_NEARBYINTF: return "GSBI_BUILT_IN_NEARBYINTF"; case GSBI_BUILT_IN_NEARBYINTL: return "GSBI_BUILT_IN_NEARBYINTL"; case GSBI_BUILT_IN_NEXTAFTER: return "GSBI_BUILT_IN_NEXTAFTER"; case GSBI_BUILT_IN_NEXTAFTERF: return "GSBI_BUILT_IN_NEXTAFTERF"; case GSBI_BUILT_IN_NEXTAFTERL: return "GSBI_BUILT_IN_NEXTAFTERL"; case GSBI_BUILT_IN_NEXTTOWARD: return "GSBI_BUILT_IN_NEXTTOWARD"; case GSBI_BUILT_IN_NEXTTOWARDF: return "GSBI_BUILT_IN_NEXTTOWARDF"; case GSBI_BUILT_IN_NEXTTOWARDL: return "GSBI_BUILT_IN_NEXTTOWARDL"; case GSBI_BUILT_IN_POW: return "GSBI_BUILT_IN_POW"; case GSBI_BUILT_IN_POW10: return "GSBI_BUILT_IN_POW10"; case GSBI_BUILT_IN_POW10F: return "GSBI_BUILT_IN_POW10F"; case GSBI_BUILT_IN_POW10L: return "GSBI_BUILT_IN_POW10L"; case GSBI_BUILT_IN_POWF: return "GSBI_BUILT_IN_POWF"; case GSBI_BUILT_IN_POWI: return "GSBI_BUILT_IN_POWI"; case GSBI_BUILT_IN_POWIF: return "GSBI_BUILT_IN_POWIF"; case GSBI_BUILT_IN_POWIL: return "GSBI_BUILT_IN_POWIL"; case GSBI_BUILT_IN_POWL: return "GSBI_BUILT_IN_POWL"; case GSBI_BUILT_IN_REMAINDER: return "GSBI_BUILT_IN_REMAINDER"; case GSBI_BUILT_IN_REMAINDERF: return "GSBI_BUILT_IN_REMAINDERF"; case GSBI_BUILT_IN_REMAINDERL: return "GSBI_BUILT_IN_REMAINDERL"; case GSBI_BUILT_IN_REMQUO: return "GSBI_BUILT_IN_REMQUO"; case GSBI_BUILT_IN_REMQUOF: return "GSBI_BUILT_IN_REMQUOF"; case GSBI_BUILT_IN_REMQUOL: return "GSBI_BUILT_IN_REMQUOL"; case GSBI_BUILT_IN_RINT: return "GSBI_BUILT_IN_RINT"; case GSBI_BUILT_IN_RINTF: return "GSBI_BUILT_IN_RINTF"; case GSBI_BUILT_IN_RINTL: return "GSBI_BUILT_IN_RINTL"; case GSBI_BUILT_IN_ROUND: return "GSBI_BUILT_IN_ROUND"; case GSBI_BUILT_IN_ROUNDF: return "GSBI_BUILT_IN_ROUNDF"; case GSBI_BUILT_IN_ROUNDL: return "GSBI_BUILT_IN_ROUNDL"; case GSBI_BUILT_IN_SCALB: return "GSBI_BUILT_IN_SCALB"; case GSBI_BUILT_IN_SCALBF: return "GSBI_BUILT_IN_SCALBF"; case GSBI_BUILT_IN_SCALBL: return "GSBI_BUILT_IN_SCALBL"; case GSBI_BUILT_IN_SCALBLN: return "GSBI_BUILT_IN_SCALBLN"; case GSBI_BUILT_IN_SCALBLNF: return "GSBI_BUILT_IN_SCALBLNF"; case GSBI_BUILT_IN_SCALBLNL: return "GSBI_BUILT_IN_SCALBLNL"; case GSBI_BUILT_IN_SCALBN: return "GSBI_BUILT_IN_SCALBN"; case GSBI_BUILT_IN_SCALBNF: return "GSBI_BUILT_IN_SCALBNF"; case GSBI_BUILT_IN_SCALBNL: return "GSBI_BUILT_IN_SCALBNL"; case GSBI_BUILT_IN_SIGNBIT: return "GSBI_BUILT_IN_SIGNBIT"; case GSBI_BUILT_IN_SIGNBITF: return "GSBI_BUILT_IN_SIGNBITF"; case GSBI_BUILT_IN_SIGNBITL: return "GSBI_BUILT_IN_SIGNBITL"; case GSBI_BUILT_IN_SIGNIFICAND: return "GSBI_BUILT_IN_SIGNIFICAND"; case GSBI_BUILT_IN_SIGNIFICANDF: return "GSBI_BUILT_IN_SIGNIFICANDF"; case GSBI_BUILT_IN_SIGNIFICANDL: return "GSBI_BUILT_IN_SIGNIFICANDL"; case GSBI_BUILT_IN_SIN: return "GSBI_BUILT_IN_SIN"; case GSBI_BUILT_IN_SINCOS: return "GSBI_BUILT_IN_SINCOS"; case GSBI_BUILT_IN_SINCOSF: return "GSBI_BUILT_IN_SINCOSF"; case GSBI_BUILT_IN_SINCOSL: return "GSBI_BUILT_IN_SINCOSL"; case GSBI_BUILT_IN_SINF: return "GSBI_BUILT_IN_SINF"; case GSBI_BUILT_IN_SINH: return "GSBI_BUILT_IN_SINH"; case GSBI_BUILT_IN_SINHF: return "GSBI_BUILT_IN_SINHF"; case GSBI_BUILT_IN_SINHL: return "GSBI_BUILT_IN_SINHL"; case GSBI_BUILT_IN_SINL: return "GSBI_BUILT_IN_SINL"; case GSBI_BUILT_IN_SQRT: return "GSBI_BUILT_IN_SQRT"; case GSBI_BUILT_IN_SQRTF: return "GSBI_BUILT_IN_SQRTF"; case GSBI_BUILT_IN_SQRTL: return "GSBI_BUILT_IN_SQRTL"; case GSBI_BUILT_IN_TAN: return "GSBI_BUILT_IN_TAN"; case GSBI_BUILT_IN_TANF: return "GSBI_BUILT_IN_TANF"; case GSBI_BUILT_IN_TANH: return "GSBI_BUILT_IN_TANH"; case GSBI_BUILT_IN_TANHF: return "GSBI_BUILT_IN_TANHF"; case GSBI_BUILT_IN_TANHL: return "GSBI_BUILT_IN_TANHL"; case GSBI_BUILT_IN_TANL: return "GSBI_BUILT_IN_TANL"; case GSBI_BUILT_IN_TGAMMA: return "GSBI_BUILT_IN_TGAMMA"; case GSBI_BUILT_IN_TGAMMAF: return "GSBI_BUILT_IN_TGAMMAF"; case GSBI_BUILT_IN_TGAMMAL: return "GSBI_BUILT_IN_TGAMMAL"; case GSBI_BUILT_IN_TRUNC: return "GSBI_BUILT_IN_TRUNC"; case GSBI_BUILT_IN_TRUNCF: return "GSBI_BUILT_IN_TRUNCF"; case GSBI_BUILT_IN_TRUNCL: return "GSBI_BUILT_IN_TRUNCL"; case GSBI_BUILT_IN_Y0: return "GSBI_BUILT_IN_Y0"; case GSBI_BUILT_IN_Y0F: return "GSBI_BUILT_IN_Y0F"; case GSBI_BUILT_IN_Y0L: return "GSBI_BUILT_IN_Y0L"; case GSBI_BUILT_IN_Y1: return "GSBI_BUILT_IN_Y1"; case GSBI_BUILT_IN_Y1F: return "GSBI_BUILT_IN_Y1F"; case GSBI_BUILT_IN_Y1L: return "GSBI_BUILT_IN_Y1L"; case GSBI_BUILT_IN_YN: return "GSBI_BUILT_IN_YN"; case GSBI_BUILT_IN_YNF: return "GSBI_BUILT_IN_YNF"; case GSBI_BUILT_IN_YNL: return "GSBI_BUILT_IN_YNL"; case GSBI_BUILT_IN_CABS: return "GSBI_BUILT_IN_CABS"; case GSBI_BUILT_IN_CABSF: return "GSBI_BUILT_IN_CABSF"; case GSBI_BUILT_IN_CABSL: return "GSBI_BUILT_IN_CABSL"; case GSBI_BUILT_IN_CACOS: return "GSBI_BUILT_IN_CACOS"; case GSBI_BUILT_IN_CACOSF: return "GSBI_BUILT_IN_CACOSF"; case GSBI_BUILT_IN_CACOSH: return "GSBI_BUILT_IN_CACOSH"; case GSBI_BUILT_IN_CACOSHF: return "GSBI_BUILT_IN_CACOSHF"; case GSBI_BUILT_IN_CACOSHL: return "GSBI_BUILT_IN_CACOSHL"; case GSBI_BUILT_IN_CACOSL: return "GSBI_BUILT_IN_CACOSL"; case GSBI_BUILT_IN_CARG: return "GSBI_BUILT_IN_CARG"; case GSBI_BUILT_IN_CARGF: return "GSBI_BUILT_IN_CARGF"; case GSBI_BUILT_IN_CARGL: return "GSBI_BUILT_IN_CARGL"; case GSBI_BUILT_IN_CASIN: return "GSBI_BUILT_IN_CASIN"; case GSBI_BUILT_IN_CASINF: return "GSBI_BUILT_IN_CASINF"; case GSBI_BUILT_IN_CASINH: return "GSBI_BUILT_IN_CASINH"; case GSBI_BUILT_IN_CASINHF: return "GSBI_BUILT_IN_CASINHF"; case GSBI_BUILT_IN_CASINHL: return "GSBI_BUILT_IN_CASINHL"; case GSBI_BUILT_IN_CASINL: return "GSBI_BUILT_IN_CASINL"; case GSBI_BUILT_IN_CATAN: return "GSBI_BUILT_IN_CATAN"; case GSBI_BUILT_IN_CATANF: return "GSBI_BUILT_IN_CATANF"; case GSBI_BUILT_IN_CATANH: return "GSBI_BUILT_IN_CATANH"; case GSBI_BUILT_IN_CATANHF: return "GSBI_BUILT_IN_CATANHF"; case GSBI_BUILT_IN_CATANHL: return "GSBI_BUILT_IN_CATANHL"; case GSBI_BUILT_IN_CATANL: return "GSBI_BUILT_IN_CATANL"; case GSBI_BUILT_IN_CCOS: return "GSBI_BUILT_IN_CCOS"; case GSBI_BUILT_IN_CCOSF: return "GSBI_BUILT_IN_CCOSF"; case GSBI_BUILT_IN_CCOSH: return "GSBI_BUILT_IN_CCOSH"; case GSBI_BUILT_IN_CCOSHF: return "GSBI_BUILT_IN_CCOSHF"; case GSBI_BUILT_IN_CCOSHL: return "GSBI_BUILT_IN_CCOSHL"; case GSBI_BUILT_IN_CCOSL: return "GSBI_BUILT_IN_CCOSL"; case GSBI_BUILT_IN_CEXP: return "GSBI_BUILT_IN_CEXP"; case GSBI_BUILT_IN_CEXPF: return "GSBI_BUILT_IN_CEXPF"; case GSBI_BUILT_IN_CEXPL: return "GSBI_BUILT_IN_CEXPL"; case GSBI_BUILT_IN_CIMAG: return "GSBI_BUILT_IN_CIMAG"; case GSBI_BUILT_IN_CIMAGF: return "GSBI_BUILT_IN_CIMAGF"; case GSBI_BUILT_IN_CIMAGL: return "GSBI_BUILT_IN_CIMAGL"; case GSBI_BUILT_IN_CLOG: return "GSBI_BUILT_IN_CLOG"; case GSBI_BUILT_IN_CLOGF: return "GSBI_BUILT_IN_CLOGF"; case GSBI_BUILT_IN_CLOGL: return "GSBI_BUILT_IN_CLOGL"; case GSBI_BUILT_IN_CONJ: return "GSBI_BUILT_IN_CONJ"; case GSBI_BUILT_IN_CONJF: return "GSBI_BUILT_IN_CONJF"; case GSBI_BUILT_IN_CONJL: return "GSBI_BUILT_IN_CONJL"; case GSBI_BUILT_IN_CPOW: return "GSBI_BUILT_IN_CPOW"; case GSBI_BUILT_IN_CPOWF: return "GSBI_BUILT_IN_CPOWF"; case GSBI_BUILT_IN_CPOWL: return "GSBI_BUILT_IN_CPOWL"; case GSBI_BUILT_IN_CPROJ: return "GSBI_BUILT_IN_CPROJ"; case GSBI_BUILT_IN_CPROJF: return "GSBI_BUILT_IN_CPROJF"; case GSBI_BUILT_IN_CPROJL: return "GSBI_BUILT_IN_CPROJL"; case GSBI_BUILT_IN_CREAL: return "GSBI_BUILT_IN_CREAL"; case GSBI_BUILT_IN_CREALF: return "GSBI_BUILT_IN_CREALF"; case GSBI_BUILT_IN_CREALL: return "GSBI_BUILT_IN_CREALL"; case GSBI_BUILT_IN_CSIN: return "GSBI_BUILT_IN_CSIN"; case GSBI_BUILT_IN_CSINF: return "GSBI_BUILT_IN_CSINF"; case GSBI_BUILT_IN_CSINH: return "GSBI_BUILT_IN_CSINH"; case GSBI_BUILT_IN_CSINHF: return "GSBI_BUILT_IN_CSINHF"; case GSBI_BUILT_IN_CSINHL: return "GSBI_BUILT_IN_CSINHL"; case GSBI_BUILT_IN_CSINL: return "GSBI_BUILT_IN_CSINL"; case GSBI_BUILT_IN_CSQRT: return "GSBI_BUILT_IN_CSQRT"; case GSBI_BUILT_IN_CSQRTF: return "GSBI_BUILT_IN_CSQRTF"; case GSBI_BUILT_IN_CSQRTL: return "GSBI_BUILT_IN_CSQRTL"; case GSBI_BUILT_IN_CTAN: return "GSBI_BUILT_IN_CTAN"; case GSBI_BUILT_IN_CTANF: return "GSBI_BUILT_IN_CTANF"; case GSBI_BUILT_IN_CTANH: return "GSBI_BUILT_IN_CTANH"; case GSBI_BUILT_IN_CTANHF: return "GSBI_BUILT_IN_CTANHF"; case GSBI_BUILT_IN_CTANHL: return "GSBI_BUILT_IN_CTANHL"; case GSBI_BUILT_IN_CTANL: return "GSBI_BUILT_IN_CTANL"; case GSBI_BUILT_IN_BCMP: return "GSBI_BUILT_IN_BCMP"; case GSBI_BUILT_IN_BCOPY: return "GSBI_BUILT_IN_BCOPY"; case GSBI_BUILT_IN_BZERO: return "GSBI_BUILT_IN_BZERO"; case GSBI_BUILT_IN_INDEX: return "GSBI_BUILT_IN_INDEX"; case GSBI_BUILT_IN_MEMCMP: return "GSBI_BUILT_IN_MEMCMP"; case GSBI_BUILT_IN_MEMCPY: return "GSBI_BUILT_IN_MEMCPY"; case GSBI_BUILT_IN_MEMMOVE: return "GSBI_BUILT_IN_MEMMOVE"; case GSBI_BUILT_IN_MEMPCPY: return "GSBI_BUILT_IN_MEMPCPY"; case GSBI_BUILT_IN_MEMSET: return "GSBI_BUILT_IN_MEMSET"; case GSBI_BUILT_IN_RINDEX: return "GSBI_BUILT_IN_RINDEX"; case GSBI_BUILT_IN_STPCPY: return "GSBI_BUILT_IN_STPCPY"; case GSBI_BUILT_IN_STRCAT: return "GSBI_BUILT_IN_STRCAT"; case GSBI_BUILT_IN_STRCHR: return "GSBI_BUILT_IN_STRCHR"; case GSBI_BUILT_IN_STRCMP: return "GSBI_BUILT_IN_STRCMP"; case GSBI_BUILT_IN_STRCPY: return "GSBI_BUILT_IN_STRCPY"; case GSBI_BUILT_IN_STRCSPN: return "GSBI_BUILT_IN_STRCSPN"; case GSBI_BUILT_IN_STRDUP: return "GSBI_BUILT_IN_STRDUP"; case GSBI_BUILT_IN_STRLEN: return "GSBI_BUILT_IN_STRLEN"; case GSBI_BUILT_IN_STRNCAT: return "GSBI_BUILT_IN_STRNCAT"; case GSBI_BUILT_IN_STRNCMP: return "GSBI_BUILT_IN_STRNCMP"; case GSBI_BUILT_IN_STRNCPY: return "GSBI_BUILT_IN_STRNCPY"; case GSBI_BUILT_IN_STRPBRK: return "GSBI_BUILT_IN_STRPBRK"; case GSBI_BUILT_IN_STRRCHR: return "GSBI_BUILT_IN_STRRCHR"; case GSBI_BUILT_IN_STRSPN: return "GSBI_BUILT_IN_STRSPN"; case GSBI_BUILT_IN_STRSTR: return "GSBI_BUILT_IN_STRSTR"; case GSBI_BUILT_IN_FPRINTF: return "GSBI_BUILT_IN_FPRINTF"; case GSBI_BUILT_IN_FPRINTF_UNLOCKED: return "GSBI_BUILT_IN_FPRINTF_UNLOCKED"; case GSBI_BUILT_IN_FPUTC: return "GSBI_BUILT_IN_FPUTC"; case GSBI_BUILT_IN_FPUTC_UNLOCKED: return "GSBI_BUILT_IN_FPUTC_UNLOCKED"; case GSBI_BUILT_IN_FPUTS: return "GSBI_BUILT_IN_FPUTS"; case GSBI_BUILT_IN_FPUTS_UNLOCKED: return "GSBI_BUILT_IN_FPUTS_UNLOCKED"; case GSBI_BUILT_IN_FSCANF: return "GSBI_BUILT_IN_FSCANF"; case GSBI_BUILT_IN_FWRITE: return "GSBI_BUILT_IN_FWRITE"; case GSBI_BUILT_IN_FWRITE_UNLOCKED: return "GSBI_BUILT_IN_FWRITE_UNLOCKED"; case GSBI_BUILT_IN_PRINTF: return "GSBI_BUILT_IN_PRINTF"; case GSBI_BUILT_IN_PRINTF_UNLOCKED: return "GSBI_BUILT_IN_PRINTF_UNLOCKED"; case GSBI_BUILT_IN_PUTCHAR: return "GSBI_BUILT_IN_PUTCHAR"; case GSBI_BUILT_IN_PUTCHAR_UNLOCKED: return "GSBI_BUILT_IN_PUTCHAR_UNLOCKED"; case GSBI_BUILT_IN_PUTS: return "GSBI_BUILT_IN_PUTS"; case GSBI_BUILT_IN_PUTS_UNLOCKED: return "GSBI_BUILT_IN_PUTS_UNLOCKED"; case GSBI_BUILT_IN_SCANF: return "GSBI_BUILT_IN_SCANF"; case GSBI_BUILT_IN_SNPRINTF: return "GSBI_BUILT_IN_SNPRINTF"; case GSBI_BUILT_IN_SPRINTF: return "GSBI_BUILT_IN_SPRINTF"; case GSBI_BUILT_IN_SSCANF: return "GSBI_BUILT_IN_SSCANF"; case GSBI_BUILT_IN_VFPRINTF: return "GSBI_BUILT_IN_VFPRINTF"; case GSBI_BUILT_IN_VFSCANF: return "GSBI_BUILT_IN_VFSCANF"; case GSBI_BUILT_IN_VPRINTF: return "GSBI_BUILT_IN_VPRINTF"; case GSBI_BUILT_IN_VSCANF: return "GSBI_BUILT_IN_VSCANF"; case GSBI_BUILT_IN_VSNPRINTF: return "GSBI_BUILT_IN_VSNPRINTF"; case GSBI_BUILT_IN_VSPRINTF: return "GSBI_BUILT_IN_VSPRINTF"; case GSBI_BUILT_IN_VSSCANF: return "GSBI_BUILT_IN_VSSCANF"; case GSBI_BUILT_IN_ISALNUM: return "GSBI_BUILT_IN_ISALNUM"; case GSBI_BUILT_IN_ISALPHA: return "GSBI_BUILT_IN_ISALPHA"; case GSBI_BUILT_IN_ISASCII: return "GSBI_BUILT_IN_ISASCII"; case GSBI_BUILT_IN_ISBLANK: return "GSBI_BUILT_IN_ISBLANK"; case GSBI_BUILT_IN_ISCNTRL: return "GSBI_BUILT_IN_ISCNTRL"; case GSBI_BUILT_IN_ISDIGIT: return "GSBI_BUILT_IN_ISDIGIT"; case GSBI_BUILT_IN_ISGRAPH: return "GSBI_BUILT_IN_ISGRAPH"; case GSBI_BUILT_IN_ISLOWER: return "GSBI_BUILT_IN_ISLOWER"; case GSBI_BUILT_IN_ISPRINT: return "GSBI_BUILT_IN_ISPRINT"; case GSBI_BUILT_IN_ISPUNCT: return "GSBI_BUILT_IN_ISPUNCT"; case GSBI_BUILT_IN_ISSPACE: return "GSBI_BUILT_IN_ISSPACE"; case GSBI_BUILT_IN_ISUPPER: return "GSBI_BUILT_IN_ISUPPER"; case GSBI_BUILT_IN_ISXDIGIT: return "GSBI_BUILT_IN_ISXDIGIT"; case GSBI_BUILT_IN_TOASCII: return "GSBI_BUILT_IN_TOASCII"; case GSBI_BUILT_IN_TOLOWER: return "GSBI_BUILT_IN_TOLOWER"; case GSBI_BUILT_IN_TOUPPER: return "GSBI_BUILT_IN_TOUPPER"; case GSBI_BUILT_IN_ISWALNUM: return "GSBI_BUILT_IN_ISWALNUM"; case GSBI_BUILT_IN_ISWALPHA: return "GSBI_BUILT_IN_ISWALPHA"; case GSBI_BUILT_IN_ISWBLANK: return "GSBI_BUILT_IN_ISWBLANK"; case GSBI_BUILT_IN_ISWCNTRL: return "GSBI_BUILT_IN_ISWCNTRL"; case GSBI_BUILT_IN_ISWDIGIT: return "GSBI_BUILT_IN_ISWDIGIT"; case GSBI_BUILT_IN_ISWGRAPH: return "GSBI_BUILT_IN_ISWGRAPH"; case GSBI_BUILT_IN_ISWLOWER: return "GSBI_BUILT_IN_ISWLOWER"; case GSBI_BUILT_IN_ISWPRINT: return "GSBI_BUILT_IN_ISWPRINT"; case GSBI_BUILT_IN_ISWPUNCT: return "GSBI_BUILT_IN_ISWPUNCT"; case GSBI_BUILT_IN_ISWSPACE: return "GSBI_BUILT_IN_ISWSPACE"; case GSBI_BUILT_IN_ISWUPPER: return "GSBI_BUILT_IN_ISWUPPER"; case GSBI_BUILT_IN_CTYPE_B_LOC: return "GSBI_BUILT_IN_CTYPE_B_LOC"; case GSBI_BUILT_IN_CTYPE_TOUPPER_LOC: return "GSBI_BUILT_IN_CTYPE_TOUPPER_LOC"; case GSBI_BUILT_IN_CTYPE_TOLOWER_LOC: return "GSBI_BUILT_IN_CTYPE_TOLOWER_LOC"; case GSBI_BUILT_IN_ISWXDIGIT: return "GSBI_BUILT_IN_ISWXDIGIT"; case GSBI_BUILT_IN_TOWLOWER: return "GSBI_BUILT_IN_TOWLOWER"; case GSBI_BUILT_IN_TOWUPPER: return "GSBI_BUILT_IN_TOWUPPER"; case GSBI_BUILT_IN_ABORT: return "GSBI_BUILT_IN_ABORT"; case GSBI_BUILT_IN_ABS: return "GSBI_BUILT_IN_ABS"; case GSBI_BUILT_IN_AGGREGATE_INCOMING_ADDRESS: return "GSBI_BUILT_IN_AGGREGATE_INCOMING_ADDRESS"; case GSBI_BUILT_IN_ALLOCA: return "GSBI_BUILT_IN_ALLOCA"; case GSBI_BUILT_IN_APPLY: return "GSBI_BUILT_IN_APPLY"; case GSBI_BUILT_IN_APPLY_ARGS: return "GSBI_BUILT_IN_APPLY_ARGS"; case GSBI_BUILT_IN_ARGS_INFO: return "GSBI_BUILT_IN_ARGS_INFO"; case GSBI_BUILT_IN_CALLOC: return "GSBI_BUILT_IN_CALLOC"; case GSBI_BUILT_IN_CLASSIFY_TYPE: return "GSBI_BUILT_IN_CLASSIFY_TYPE"; case GSBI_BUILT_IN_CLZ: return "GSBI_BUILT_IN_CLZ"; case GSBI_BUILT_IN_CLZIMAX: return "GSBI_BUILT_IN_CLZIMAX"; case GSBI_BUILT_IN_CLZL: return "GSBI_BUILT_IN_CLZL"; case GSBI_BUILT_IN_CLZLL: return "GSBI_BUILT_IN_CLZLL"; case GSBI_BUILT_IN_CONSTANT_P: return "GSBI_BUILT_IN_CONSTANT_P"; case GSBI_BUILT_IN_CTZ: return "GSBI_BUILT_IN_CTZ"; case GSBI_BUILT_IN_CTZIMAX: return "GSBI_BUILT_IN_CTZIMAX"; case GSBI_BUILT_IN_CTZL: return "GSBI_BUILT_IN_CTZL"; case GSBI_BUILT_IN_CTZLL: return "GSBI_BUILT_IN_CTZLL"; case GSBI_BUILT_IN_DCGETTEXT: return "GSBI_BUILT_IN_DCGETTEXT"; case GSBI_BUILT_IN_DGETTEXT: return "GSBI_BUILT_IN_DGETTEXT"; case GSBI_BUILT_IN_DWARF_CFA: return "GSBI_BUILT_IN_DWARF_CFA"; case GSBI_BUILT_IN_DWARF_SP_COLUMN: return "GSBI_BUILT_IN_DWARF_SP_COLUMN"; case GSBI_BUILT_IN_EH_RETURN: return "GSBI_BUILT_IN_EH_RETURN"; case GSBI_BUILT_IN_EH_RETURN_DATA_REGNO: return "GSBI_BUILT_IN_EH_RETURN_DATA_REGNO"; case GSBI_BUILT_IN_EXECL: return "GSBI_BUILT_IN_EXECL"; case GSBI_BUILT_IN_EXECLP: return "GSBI_BUILT_IN_EXECLP"; case GSBI_BUILT_IN_EXECLE: return "GSBI_BUILT_IN_EXECLE"; case GSBI_BUILT_IN_EXECV: return "GSBI_BUILT_IN_EXECV"; case GSBI_BUILT_IN_EXECVP: return "GSBI_BUILT_IN_EXECVP"; case GSBI_BUILT_IN_EXECVE: return "GSBI_BUILT_IN_EXECVE"; case GSBI_BUILT_IN_EXIT: return "GSBI_BUILT_IN_EXIT"; case GSBI_BUILT_IN_EXPECT: return "GSBI_BUILT_IN_EXPECT"; case GSBI_BUILT_IN_EXTEND_POINTER: return "GSBI_BUILT_IN_EXTEND_POINTER"; case GSBI_BUILT_IN_EXTRACT_RETURN_ADDR: return "GSBI_BUILT_IN_EXTRACT_RETURN_ADDR"; case GSBI_BUILT_IN_FFS: return "GSBI_BUILT_IN_FFS"; case GSBI_BUILT_IN_FFSIMAX: return "GSBI_BUILT_IN_FFSIMAX"; case GSBI_BUILT_IN_FFSL: return "GSBI_BUILT_IN_FFSL"; case GSBI_BUILT_IN_FFSLL: return "GSBI_BUILT_IN_FFSLL"; case GSBI_BUILT_IN_FORK: return "GSBI_BUILT_IN_FORK"; case GSBI_BUILT_IN_FRAME_ADDRESS: return "GSBI_BUILT_IN_FRAME_ADDRESS"; case GSBI_BUILT_IN_FROB_RETURN_ADDR: return "GSBI_BUILT_IN_FROB_RETURN_ADDR"; case GSBI_BUILT_IN_GETTEXT: return "GSBI_BUILT_IN_GETTEXT"; case GSBI_BUILT_IN_IMAXABS: return "GSBI_BUILT_IN_IMAXABS"; case GSBI_BUILT_IN_INIT_DWARF_REG_SIZES: return "GSBI_BUILT_IN_INIT_DWARF_REG_SIZES"; case GSBI_BUILT_IN_FINITE: return "GSBI_BUILT_IN_FINITE"; case GSBI_BUILT_IN_FINITEF: return "GSBI_BUILT_IN_FINITEF"; case GSBI_BUILT_IN_FINITEL: return "GSBI_BUILT_IN_FINITEL"; case GSBI_BUILT_IN_ISINF: return "GSBI_BUILT_IN_ISINF"; case GSBI_BUILT_IN_ISINFF: return "GSBI_BUILT_IN_ISINFF"; case GSBI_BUILT_IN_ISINFL: return "GSBI_BUILT_IN_ISINFL"; case GSBI_BUILT_IN_ISNAN: return "GSBI_BUILT_IN_ISNAN"; case GSBI_BUILT_IN_ISNANF: return "GSBI_BUILT_IN_ISNANF"; case GSBI_BUILT_IN_ISNANL: return "GSBI_BUILT_IN_ISNANL"; case GSBI_BUILT_IN_ISGREATER: return "GSBI_BUILT_IN_ISGREATER"; case GSBI_BUILT_IN_ISGREATEREQUAL: return "GSBI_BUILT_IN_ISGREATEREQUAL"; case GSBI_BUILT_IN_ISLESS: return "GSBI_BUILT_IN_ISLESS"; case GSBI_BUILT_IN_ISLESSEQUAL: return "GSBI_BUILT_IN_ISLESSEQUAL"; case GSBI_BUILT_IN_ISLESSGREATER: return "GSBI_BUILT_IN_ISLESSGREATER"; case GSBI_BUILT_IN_ISUNORDERED: return "GSBI_BUILT_IN_ISUNORDERED"; case GSBI_BUILT_IN_LABS: return "GSBI_BUILT_IN_LABS"; case GSBI_BUILT_IN_LLABS: return "GSBI_BUILT_IN_LLABS"; case GSBI_BUILT_IN_LONGJMP: return "GSBI_BUILT_IN_LONGJMP"; case GSBI_BUILT_IN_MALLOC: return "GSBI_BUILT_IN_MALLOC"; case GSBI_BUILT_IN_NEXT_ARG: return "GSBI_BUILT_IN_NEXT_ARG"; case GSBI_BUILT_IN_PARITY: return "GSBI_BUILT_IN_PARITY"; case GSBI_BUILT_IN_PARITYIMAX: return "GSBI_BUILT_IN_PARITYIMAX"; case GSBI_BUILT_IN_PARITYL: return "GSBI_BUILT_IN_PARITYL"; case GSBI_BUILT_IN_PARITYLL: return "GSBI_BUILT_IN_PARITYLL"; case GSBI_BUILT_IN_POPCOUNT: return "GSBI_BUILT_IN_POPCOUNT"; case GSBI_BUILT_IN_POPCOUNTIMAX: return "GSBI_BUILT_IN_POPCOUNTIMAX"; case GSBI_BUILT_IN_POPCOUNTL: return "GSBI_BUILT_IN_POPCOUNTL"; case GSBI_BUILT_IN_POPCOUNTLL: return "GSBI_BUILT_IN_POPCOUNTLL"; case GSBI_BUILT_IN_PREFETCH: return "GSBI_BUILT_IN_PREFETCH"; case GSBI_BUILT_IN_RETURN: return "GSBI_BUILT_IN_RETURN"; case GSBI_BUILT_IN_RETURN_ADDRESS: return "GSBI_BUILT_IN_RETURN_ADDRESS"; case GSBI_BUILT_IN_SAVEREGS: return "GSBI_BUILT_IN_SAVEREGS"; case GSBI_BUILT_IN_SETJMP: return "GSBI_BUILT_IN_SETJMP"; case GSBI_BUILT_IN_STDARG_START: return "GSBI_BUILT_IN_STDARG_START"; case GSBI_BUILT_IN_STRFMON: return "GSBI_BUILT_IN_STRFMON"; case GSBI_BUILT_IN_STRFTIME: return "GSBI_BUILT_IN_STRFTIME"; case GSBI_BUILT_IN_TRAP: return "GSBI_BUILT_IN_TRAP"; case GSBI_BUILT_IN_UNWIND_INIT: return "GSBI_BUILT_IN_UNWIND_INIT"; case GSBI_BUILT_IN_UPDATE_SETJMP_BUF: return "GSBI_BUILT_IN_UPDATE_SETJMP_BUF"; case GSBI_BUILT_IN_VA_COPY: return "GSBI_BUILT_IN_VA_COPY"; case GSBI_BUILT_IN_VA_END: return "GSBI_BUILT_IN_VA_END"; case GSBI_BUILT_IN_VA_START: return "GSBI_BUILT_IN_VA_START"; case GSBI_BUILT_IN__EXIT: return "GSBI_BUILT_IN__EXIT"; case GSBI_BUILT_IN__EXIT2: return "GSBI_BUILT_IN__EXIT2"; case GSBI_BUILT_IN_INIT_TRAMPOLINE: return "GSBI_BUILT_IN_INIT_TRAMPOLINE"; case GSBI_BUILT_IN_ADJUST_TRAMPOLINE: return "GSBI_BUILT_IN_ADJUST_TRAMPOLINE"; case GSBI_BUILT_IN_NONLOCAL_GOTO: return "GSBI_BUILT_IN_NONLOCAL_GOTO"; case GSBI_BUILT_IN_STACK_SAVE: return "GSBI_BUILT_IN_STACK_SAVE"; case GSBI_BUILT_IN_STACK_RESTORE: return "GSBI_BUILT_IN_STACK_RESTORE"; case GSBI_BUILT_IN_PROFILE_FUNC_ENTER: return "GSBI_BUILT_IN_PROFILE_FUNC_ENTER"; case GSBI_BUILT_IN_PROFILE_FUNC_EXIT: return "GSBI_BUILT_IN_PROFILE_FUNC_EXIT"; case GSBI_BUILT_IN_COMPLEX_MUL_MIN: return "GSBI_BUILT_IN_COMPLEX_MUL_MIN"; case GSBI_BUILT_IN_COMPLEX_MUL_MAX: return "GSBI_BUILT_IN_COMPLEX_MUL_MAX"; case GSBI_BUILT_IN_COMPLEX_DIV_MIN: return "GSBI_BUILT_IN_COMPLEX_DIV_MIN"; case GSBI_BUILT_IN_COMPLEX_DIV_MAX: return "GSBI_BUILT_IN_COMPLEX_DIV_MAX"; case GSBI_END_BUILTINS: return "GSBI_END_BUILTINS"; } GS_ASSERT (gs_false, (gs_string_t) "gsbi name not implemented."); return (char *) NULL; } gs_string_t gsbi_class_name (gsbi_class_t class_code) { switch (class_code) { case 0: return (gs_string_t) "GSBI_CLASS_NOT_BUILT_IN"; case 1: return (gs_string_t) "GSBI_CLASS_BUILT_IN_FRONTEND"; case 2: return (gs_string_t) "GSBI_CLASS_BUILT_IN_MD"; case 3: return (gs_string_t) "GSBI_CLASS_BUILT_IN_NORMAL"; default: printf("Class: %d\n", class_code); GS_ASSERT(gs_false, (gs_string_t)"gsbi class name name not implemented."); return (gs_string_t) NULL; } } gs_string_t gsbi_ts_name (gsbi_ts_t code) { switch (code) { case GSBI_IX86_BUILTIN_ADDPS: return "GSBI_IX86_BUILTIN_ADDPS"; case GSBI_IX86_BUILTIN_ADDSS: return "GSBI_IX86_BUILTIN_ADDSS"; case GSBI_IX86_BUILTIN_DIVPS: return "GSBI_IX86_BUILTIN_DIVPS"; case GSBI_IX86_BUILTIN_DIVSS: return "GSBI_IX86_BUILTIN_DIVSS"; case GSBI_IX86_BUILTIN_MULPS: return "GSBI_IX86_BUILTIN_MULPS"; case GSBI_IX86_BUILTIN_MULSS: return "GSBI_IX86_BUILTIN_MULSS"; case GSBI_IX86_BUILTIN_SUBPS: return "GSBI_IX86_BUILTIN_SUBPS"; case GSBI_IX86_BUILTIN_SUBSS: return "GSBI_IX86_BUILTIN_SUBSS"; case GSBI_IX86_BUILTIN_CMPEQPS: return "GSBI_IX86_BUILTIN_CMPEQPS"; case GSBI_IX86_BUILTIN_CMPLTPS: return "GSBI_IX86_BUILTIN_CMPLTPS"; case GSBI_IX86_BUILTIN_CMPLEPS: return "GSBI_IX86_BUILTIN_CMPLEPS"; case GSBI_IX86_BUILTIN_CMPGTPS: return "GSBI_IX86_BUILTIN_CMPGTPS"; case GSBI_IX86_BUILTIN_CMPGEPS: return "GSBI_IX86_BUILTIN_CMPGEPS"; case GSBI_IX86_BUILTIN_CMPNEQPS: return "GSBI_IX86_BUILTIN_CMPNEQPS"; case GSBI_IX86_BUILTIN_CMPNLTPS: return "GSBI_IX86_BUILTIN_CMPNLTPS"; case GSBI_IX86_BUILTIN_CMPNLEPS: return "GSBI_IX86_BUILTIN_CMPNLEPS"; case GSBI_IX86_BUILTIN_CMPNGTPS: return "GSBI_IX86_BUILTIN_CMPNGTPS"; case GSBI_IX86_BUILTIN_CMPNGEPS: return "GSBI_IX86_BUILTIN_CMPNGEPS"; case GSBI_IX86_BUILTIN_CMPORDPS: return "GSBI_IX86_BUILTIN_CMPORDPS"; case GSBI_IX86_BUILTIN_CMPUNORDPS: return "GSBI_IX86_BUILTIN_CMPUNORDPS"; case GSBI_IX86_BUILTIN_CMPNEPS: return "GSBI_IX86_BUILTIN_CMPNEPS"; case GSBI_IX86_BUILTIN_CMPEQSS: return "GSBI_IX86_BUILTIN_CMPEQSS"; case GSBI_IX86_BUILTIN_CMPLTSS: return "GSBI_IX86_BUILTIN_CMPLTSS"; case GSBI_IX86_BUILTIN_CMPLESS: return "GSBI_IX86_BUILTIN_CMPLESS"; case GSBI_IX86_BUILTIN_CMPNEQSS: return "GSBI_IX86_BUILTIN_CMPNEQSS"; case GSBI_IX86_BUILTIN_CMPNLTSS: return "GSBI_IX86_BUILTIN_CMPNLTSS"; case GSBI_IX86_BUILTIN_CMPNLESS: return "GSBI_IX86_BUILTIN_CMPNLESS"; case GSBI_IX86_BUILTIN_CMPNGTSS: return "GSBI_IX86_BUILTIN_CMPNGTSS"; case GSBI_IX86_BUILTIN_CMPNGESS: return "GSBI_IX86_BUILTIN_CMPNGESS"; case GSBI_IX86_BUILTIN_CMPORDSS: return "GSBI_IX86_BUILTIN_CMPORDSS"; case GSBI_IX86_BUILTIN_CMPUNORDSS: return "GSBI_IX86_BUILTIN_CMPUNORDSS"; case GSBI_IX86_BUILTIN_CMPNESS: return "GSBI_IX86_BUILTIN_CMPNESS"; case GSBI_IX86_BUILTIN_COMIEQSS: return "GSBI_IX86_BUILTIN_COMIEQSS"; case GSBI_IX86_BUILTIN_COMILTSS: return "GSBI_IX86_BUILTIN_COMILTSS"; case GSBI_IX86_BUILTIN_COMILESS: return "GSBI_IX86_BUILTIN_COMILESS"; case GSBI_IX86_BUILTIN_COMIGTSS: return "GSBI_IX86_BUILTIN_COMIGTSS"; case GSBI_IX86_BUILTIN_COMIGESS: return "GSBI_IX86_BUILTIN_COMIGESS"; case GSBI_IX86_BUILTIN_COMINEQSS: return "GSBI_IX86_BUILTIN_COMINEQSS"; case GSBI_IX86_BUILTIN_UCOMIEQSS: return "GSBI_IX86_BUILTIN_UCOMIEQSS"; case GSBI_IX86_BUILTIN_UCOMILTSS: return "GSBI_IX86_BUILTIN_UCOMILTSS"; case GSBI_IX86_BUILTIN_UCOMILESS: return "GSBI_IX86_BUILTIN_UCOMILESS"; case GSBI_IX86_BUILTIN_UCOMIGTSS: return "GSBI_IX86_BUILTIN_UCOMIGTSS"; case GSBI_IX86_BUILTIN_UCOMIGESS: return "GSBI_IX86_BUILTIN_UCOMIGESS"; case GSBI_IX86_BUILTIN_UCOMINEQSS: return "GSBI_IX86_BUILTIN_UCOMINEQSS"; case GSBI_IX86_BUILTIN_CVTPI2PS: return "GSBI_IX86_BUILTIN_CVTPI2PS"; case GSBI_IX86_BUILTIN_CVTPS2PI: return "GSBI_IX86_BUILTIN_CVTPS2PI"; case GSBI_IX86_BUILTIN_CVTSI2SS: return "GSBI_IX86_BUILTIN_CVTSI2SS"; case GSBI_IX86_BUILTIN_CVTSI642SS: return "GSBI_IX86_BUILTIN_CVTSI642SS"; case GSBI_IX86_BUILTIN_CVTSS2SI: return "GSBI_IX86_BUILTIN_CVTSS2SI"; case GSBI_IX86_BUILTIN_CVTSS2SI64: return "GSBI_IX86_BUILTIN_CVTSS2SI64"; case GSBI_IX86_BUILTIN_CVTTPS2PI: return "GSBI_IX86_BUILTIN_CVTTPS2PI"; case GSBI_IX86_BUILTIN_CVTTSS2SI: return "GSBI_IX86_BUILTIN_CVTTSS2SI"; case GSBI_IX86_BUILTIN_CVTTSS2SI64: return "GSBI_IX86_BUILTIN_CVTTSS2SI64"; case GSBI_IX86_BUILTIN_MAXPS: return "GSBI_IX86_BUILTIN_MAXPS"; case GSBI_IX86_BUILTIN_MAXSS: return "GSBI_IX86_BUILTIN_MAXSS"; case GSBI_IX86_BUILTIN_MINPS: return "GSBI_IX86_BUILTIN_MINPS"; case GSBI_IX86_BUILTIN_MINSS: return "GSBI_IX86_BUILTIN_MINSS"; case GSBI_IX86_BUILTIN_LOADUPS: return "GSBI_IX86_BUILTIN_LOADUPS"; case GSBI_IX86_BUILTIN_STOREUPS: return "GSBI_IX86_BUILTIN_STOREUPS"; case GSBI_IX86_BUILTIN_MOVSS: return "GSBI_IX86_BUILTIN_MOVSS"; case GSBI_IX86_BUILTIN_MOVHLPS: return "GSBI_IX86_BUILTIN_MOVHLPS"; case GSBI_IX86_BUILTIN_MOVLHPS: return "GSBI_IX86_BUILTIN_MOVLHPS"; case GSBI_IX86_BUILTIN_LOADHPS: return "GSBI_IX86_BUILTIN_LOADHPS"; case GSBI_IX86_BUILTIN_LOADLPS: return "GSBI_IX86_BUILTIN_LOADLPS"; case GSBI_IX86_BUILTIN_STOREHPS: return "GSBI_IX86_BUILTIN_STOREHPS"; case GSBI_IX86_BUILTIN_STORELPS: return "GSBI_IX86_BUILTIN_STORELPS"; case GSBI_IX86_BUILTIN_MASKMOVQ: return "GSBI_IX86_BUILTIN_MASKMOVQ"; case GSBI_IX86_BUILTIN_MOVMSKPS: return "GSBI_IX86_BUILTIN_MOVMSKPS"; case GSBI_IX86_BUILTIN_PMOVMSKB: return "GSBI_IX86_BUILTIN_PMOVMSKB"; case GSBI_IX86_BUILTIN_MOVNTPS: return "GSBI_IX86_BUILTIN_MOVNTPS"; case GSBI_IX86_BUILTIN_MOVNTQ: return "GSBI_IX86_BUILTIN_MOVNTQ"; case GSBI_IX86_BUILTIN_LOADDQU: return "GSBI_IX86_BUILTIN_LOADDQU"; case GSBI_IX86_BUILTIN_STOREDQU: return "GSBI_IX86_BUILTIN_STOREDQU"; case GSBI_IX86_BUILTIN_PACKSSWB: return "GSBI_IX86_BUILTIN_PACKSSWB"; case GSBI_IX86_BUILTIN_PACKSSDW: return "GSBI_IX86_BUILTIN_PACKSSDW"; case GSBI_IX86_BUILTIN_PACKUSWB: return "GSBI_IX86_BUILTIN_PACKUSWB"; case GSBI_IX86_BUILTIN_PADDB: return "GSBI_IX86_BUILTIN_PADDB"; case GSBI_IX86_BUILTIN_PADDW: return "GSBI_IX86_BUILTIN_PADDW"; case GSBI_IX86_BUILTIN_PADDD: return "GSBI_IX86_BUILTIN_PADDD"; case GSBI_IX86_BUILTIN_PADDQ: return "GSBI_IX86_BUILTIN_PADDQ"; case GSBI_IX86_BUILTIN_PADDSB: return "GSBI_IX86_BUILTIN_PADDSB"; case GSBI_IX86_BUILTIN_PADDSW: return "GSBI_IX86_BUILTIN_PADDSW"; case GSBI_IX86_BUILTIN_PADDUSB: return "GSBI_IX86_BUILTIN_PADDUSB"; case GSBI_IX86_BUILTIN_PADDUSW: return "GSBI_IX86_BUILTIN_PADDUSW"; case GSBI_IX86_BUILTIN_PSUBB: return "GSBI_IX86_BUILTIN_PSUBB"; case GSBI_IX86_BUILTIN_PSUBW: return "GSBI_IX86_BUILTIN_PSUBW"; case GSBI_IX86_BUILTIN_PSUBD: return "GSBI_IX86_BUILTIN_PSUBD"; case GSBI_IX86_BUILTIN_PSUBQ: return "GSBI_IX86_BUILTIN_PSUBQ"; case GSBI_IX86_BUILTIN_PSUBSB: return "GSBI_IX86_BUILTIN_PSUBSB"; case GSBI_IX86_BUILTIN_PSUBSW: return "GSBI_IX86_BUILTIN_PSUBSW"; case GSBI_IX86_BUILTIN_PSUBUSB: return "GSBI_IX86_BUILTIN_PSUBUSB"; case GSBI_IX86_BUILTIN_PSUBUSW: return "GSBI_IX86_BUILTIN_PSUBUSW"; case GSBI_IX86_BUILTIN_PAND: return "GSBI_IX86_BUILTIN_PAND"; case GSBI_IX86_BUILTIN_PANDN: return "GSBI_IX86_BUILTIN_PANDN"; case GSBI_IX86_BUILTIN_POR: return "GSBI_IX86_BUILTIN_POR"; case GSBI_IX86_BUILTIN_PXOR: return "GSBI_IX86_BUILTIN_PXOR"; case GSBI_IX86_BUILTIN_PAVGB: return "GSBI_IX86_BUILTIN_PAVGB"; case GSBI_IX86_BUILTIN_PAVGW: return "GSBI_IX86_BUILTIN_PAVGW"; case GSBI_IX86_BUILTIN_PCMPEQB: return "GSBI_IX86_BUILTIN_PCMPEQB"; case GSBI_IX86_BUILTIN_PCMPEQW: return "GSBI_IX86_BUILTIN_PCMPEQW"; case GSBI_IX86_BUILTIN_PCMPEQD: return "GSBI_IX86_BUILTIN_PCMPEQD"; case GSBI_IX86_BUILTIN_PCMPGTB: return "GSBI_IX86_BUILTIN_PCMPGTB"; case GSBI_IX86_BUILTIN_PCMPGTW: return "GSBI_IX86_BUILTIN_PCMPGTW"; case GSBI_IX86_BUILTIN_PCMPGTD: return "GSBI_IX86_BUILTIN_PCMPGTD"; case GSBI_IX86_BUILTIN_PMADDWD: return "GSBI_IX86_BUILTIN_PMADDWD"; case GSBI_IX86_BUILTIN_PMAXSW: return "GSBI_IX86_BUILTIN_PMAXSW"; case GSBI_IX86_BUILTIN_PMAXUB: return "GSBI_IX86_BUILTIN_PMAXUB"; case GSBI_IX86_BUILTIN_PMINSW: return "GSBI_IX86_BUILTIN_PMINSW"; case GSBI_IX86_BUILTIN_PMINUB: return "GSBI_IX86_BUILTIN_PMINUB"; case GSBI_IX86_BUILTIN_PMULHUW: return "GSBI_IX86_BUILTIN_PMULHUW"; case GSBI_IX86_BUILTIN_PMULHW: return "GSBI_IX86_BUILTIN_PMULHW"; case GSBI_IX86_BUILTIN_PMULLW: return "GSBI_IX86_BUILTIN_PMULLW"; case GSBI_IX86_BUILTIN_PSADBW: return "GSBI_IX86_BUILTIN_PSADBW"; case GSBI_IX86_BUILTIN_PSHUFW: return "GSBI_IX86_BUILTIN_PSHUFW"; case GSBI_IX86_BUILTIN_PSLLW: return "GSBI_IX86_BUILTIN_PSLLW"; case GSBI_IX86_BUILTIN_PSLLD: return "GSBI_IX86_BUILTIN_PSLLD"; case GSBI_IX86_BUILTIN_PSLLQ: return "GSBI_IX86_BUILTIN_PSLLQ"; case GSBI_IX86_BUILTIN_PSRAW: return "GSBI_IX86_BUILTIN_PSRAW"; case GSBI_IX86_BUILTIN_PSRAD: return "GSBI_IX86_BUILTIN_PSRAD"; case GSBI_IX86_BUILTIN_PSRLW: return "GSBI_IX86_BUILTIN_PSRLW"; case GSBI_IX86_BUILTIN_PSRLD: return "GSBI_IX86_BUILTIN_PSRLD"; case GSBI_IX86_BUILTIN_PSRLQ: return "GSBI_IX86_BUILTIN_PSRLQ"; case GSBI_IX86_BUILTIN_PSLLWI: return "GSBI_IX86_BUILTIN_PSLLWI"; case GSBI_IX86_BUILTIN_PSLLDI: return "GSBI_IX86_BUILTIN_PSLLDI"; case GSBI_IX86_BUILTIN_PSLLQI: return "GSBI_IX86_BUILTIN_PSLLQI"; case GSBI_IX86_BUILTIN_PSRAWI: return "GSBI_IX86_BUILTIN_PSRAWI"; case GSBI_IX86_BUILTIN_PSRADI: return "GSBI_IX86_BUILTIN_PSRADI"; case GSBI_IX86_BUILTIN_PSRLWI: return "GSBI_IX86_BUILTIN_PSRLWI"; case GSBI_IX86_BUILTIN_PSRLDI: return "GSBI_IX86_BUILTIN_PSRLDI"; case GSBI_IX86_BUILTIN_PSRLQI: return "GSBI_IX86_BUILTIN_PSRLQI"; case GSBI_IX86_BUILTIN_PUNPCKHBW: return "GSBI_IX86_BUILTIN_PUNPCKHBW"; case GSBI_IX86_BUILTIN_PUNPCKHWD: return "GSBI_IX86_BUILTIN_PUNPCKHWD"; case GSBI_IX86_BUILTIN_PUNPCKHDQ: return "GSBI_IX86_BUILTIN_PUNPCKHDQ"; case GSBI_IX86_BUILTIN_PUNPCKLBW: return "GSBI_IX86_BUILTIN_PUNPCKLBW"; case GSBI_IX86_BUILTIN_PUNPCKLWD: return "GSBI_IX86_BUILTIN_PUNPCKLWD"; case GSBI_IX86_BUILTIN_PUNPCKLDQ: return "GSBI_IX86_BUILTIN_PUNPCKLDQ"; case GSBI_IX86_BUILTIN_SHUFPS: return "GSBI_IX86_BUILTIN_SHUFPS"; case GSBI_IX86_BUILTIN_RCPPS: return "GSBI_IX86_BUILTIN_RCPPS"; case GSBI_IX86_BUILTIN_RCPSS: return "GSBI_IX86_BUILTIN_RCPSS"; case GSBI_IX86_BUILTIN_RSQRTPS: return "GSBI_IX86_BUILTIN_RSQRTPS"; case GSBI_IX86_BUILTIN_RSQRTSS: return "GSBI_IX86_BUILTIN_RSQRTSS"; case GSBI_IX86_BUILTIN_SQRTPS: return "GSBI_IX86_BUILTIN_SQRTPS"; case GSBI_IX86_BUILTIN_SQRTSS: return "GSBI_IX86_BUILTIN_SQRTSS"; case GSBI_IX86_BUILTIN_UNPCKHPS: return "GSBI_IX86_BUILTIN_UNPCKHPS"; case GSBI_IX86_BUILTIN_UNPCKLPS: return "GSBI_IX86_BUILTIN_UNPCKLPS"; case GSBI_IX86_BUILTIN_ANDPS: return "GSBI_IX86_BUILTIN_ANDPS"; case GSBI_IX86_BUILTIN_ANDNPS: return "GSBI_IX86_BUILTIN_ANDNPS"; case GSBI_IX86_BUILTIN_ORPS: return "GSBI_IX86_BUILTIN_ORPS"; case GSBI_IX86_BUILTIN_XORPS: return "GSBI_IX86_BUILTIN_XORPS"; case GSBI_IX86_BUILTIN_EMMS: return "GSBI_IX86_BUILTIN_EMMS"; case GSBI_IX86_BUILTIN_LDMXCSR: return "GSBI_IX86_BUILTIN_LDMXCSR"; case GSBI_IX86_BUILTIN_STMXCSR: return "GSBI_IX86_BUILTIN_STMXCSR"; case GSBI_IX86_BUILTIN_SFENCE: return "GSBI_IX86_BUILTIN_SFENCE"; case GSBI_IX86_BUILTIN_FEMMS: return "GSBI_IX86_BUILTIN_FEMMS"; case GSBI_IX86_BUILTIN_PAVGUSB: return "GSBI_IX86_BUILTIN_PAVGUSB"; case GSBI_IX86_BUILTIN_PF2ID: return "GSBI_IX86_BUILTIN_PF2ID"; case GSBI_IX86_BUILTIN_PFACC: return "GSBI_IX86_BUILTIN_PFACC"; case GSBI_IX86_BUILTIN_PFADD: return "GSBI_IX86_BUILTIN_PFADD"; case GSBI_IX86_BUILTIN_PFCMPEQ: return "GSBI_IX86_BUILTIN_PFCMPEQ"; case GSBI_IX86_BUILTIN_PFCMPGE: return "GSBI_IX86_BUILTIN_PFCMPGE"; case GSBI_IX86_BUILTIN_PFCMPGT: return "GSBI_IX86_BUILTIN_PFCMPGT"; case GSBI_IX86_BUILTIN_PFMAX: return "GSBI_IX86_BUILTIN_PFMAX"; case GSBI_IX86_BUILTIN_PFMIN: return "GSBI_IX86_BUILTIN_PFMIN"; case GSBI_IX86_BUILTIN_PFMUL: return "GSBI_IX86_BUILTIN_PFMUL"; case GSBI_IX86_BUILTIN_PFRCP: return "GSBI_IX86_BUILTIN_PFRCP"; case GSBI_IX86_BUILTIN_PFRCPIT1: return "GSBI_IX86_BUILTIN_PFRCPIT1"; case GSBI_IX86_BUILTIN_PFRCPIT2: return "GSBI_IX86_BUILTIN_PFRCPIT2"; case GSBI_IX86_BUILTIN_PFRSQIT1: return "GSBI_IX86_BUILTIN_PFRSQIT1"; case GSBI_IX86_BUILTIN_PFRSQRT: return "GSBI_IX86_BUILTIN_PFRSQRT"; case GSBI_IX86_BUILTIN_PFSUB: return "GSBI_IX86_BUILTIN_PFSUB"; case GSBI_IX86_BUILTIN_PFSUBR: return "GSBI_IX86_BUILTIN_PFSUBR"; case GSBI_IX86_BUILTIN_PI2FD: return "GSBI_IX86_BUILTIN_PI2FD"; case GSBI_IX86_BUILTIN_PMULHRW: return "GSBI_IX86_BUILTIN_PMULHRW"; case GSBI_IX86_BUILTIN_PF2IW: return "GSBI_IX86_BUILTIN_PF2IW"; case GSBI_IX86_BUILTIN_PFNACC: return "GSBI_IX86_BUILTIN_PFNACC"; case GSBI_IX86_BUILTIN_PFPNACC: return "GSBI_IX86_BUILTIN_PFPNACC"; case GSBI_IX86_BUILTIN_PI2FW: return "GSBI_IX86_BUILTIN_PI2FW"; case GSBI_IX86_BUILTIN_PSWAPDSI: return "GSBI_IX86_BUILTIN_PSWAPDSI"; case GSBI_IX86_BUILTIN_PSWAPDSF: return "GSBI_IX86_BUILTIN_PSWAPDSF"; case GSBI_IX86_BUILTIN_ADDPD: return "GSBI_IX86_BUILTIN_ADDPD"; case GSBI_IX86_BUILTIN_ADDSD: return "GSBI_IX86_BUILTIN_ADDSD"; case GSBI_IX86_BUILTIN_DIVPD: return "GSBI_IX86_BUILTIN_DIVPD"; case GSBI_IX86_BUILTIN_DIVSD: return "GSBI_IX86_BUILTIN_DIVSD"; case GSBI_IX86_BUILTIN_MULPD: return "GSBI_IX86_BUILTIN_MULPD"; case GSBI_IX86_BUILTIN_MULSD: return "GSBI_IX86_BUILTIN_MULSD"; case GSBI_IX86_BUILTIN_SUBPD: return "GSBI_IX86_BUILTIN_SUBPD"; case GSBI_IX86_BUILTIN_SUBSD: return "GSBI_IX86_BUILTIN_SUBSD"; case GSBI_IX86_BUILTIN_CMPEQPD: return "GSBI_IX86_BUILTIN_CMPEQPD"; case GSBI_IX86_BUILTIN_CMPLTPD: return "GSBI_IX86_BUILTIN_CMPLTPD"; case GSBI_IX86_BUILTIN_CMPLEPD: return "GSBI_IX86_BUILTIN_CMPLEPD"; case GSBI_IX86_BUILTIN_CMPGTPD: return "GSBI_IX86_BUILTIN_CMPGTPD"; case GSBI_IX86_BUILTIN_CMPGEPD: return "GSBI_IX86_BUILTIN_CMPGEPD"; case GSBI_IX86_BUILTIN_CMPNEQPD: return "GSBI_IX86_BUILTIN_CMPNEQPD"; case GSBI_IX86_BUILTIN_CMPNLTPD: return "GSBI_IX86_BUILTIN_CMPNLTPD"; case GSBI_IX86_BUILTIN_CMPNLEPD: return "GSBI_IX86_BUILTIN_CMPNLEPD"; case GSBI_IX86_BUILTIN_CMPNGTPD: return "GSBI_IX86_BUILTIN_CMPNGTPD"; case GSBI_IX86_BUILTIN_CMPNGEPD: return "GSBI_IX86_BUILTIN_CMPNGEPD"; case GSBI_IX86_BUILTIN_CMPORDPD: return "GSBI_IX86_BUILTIN_CMPORDPD"; case GSBI_IX86_BUILTIN_CMPUNORDPD: return "GSBI_IX86_BUILTIN_CMPUNORDPD"; case GSBI_IX86_BUILTIN_CMPNEPD: return "GSBI_IX86_BUILTIN_CMPNEPD"; case GSBI_IX86_BUILTIN_CMPEQSD: return "GSBI_IX86_BUILTIN_CMPEQSD"; case GSBI_IX86_BUILTIN_CMPLTSD: return "GSBI_IX86_BUILTIN_CMPLTSD"; case GSBI_IX86_BUILTIN_CMPLESD: return "GSBI_IX86_BUILTIN_CMPLESD"; case GSBI_IX86_BUILTIN_CMPNEQSD: return "GSBI_IX86_BUILTIN_CMPNEQSD"; case GSBI_IX86_BUILTIN_CMPNLTSD: return "GSBI_IX86_BUILTIN_CMPNLTSD"; case GSBI_IX86_BUILTIN_CMPNLESD: return "GSBI_IX86_BUILTIN_CMPNLESD"; case GSBI_IX86_BUILTIN_CMPORDSD: return "GSBI_IX86_BUILTIN_CMPORDSD"; case GSBI_IX86_BUILTIN_CMPUNORDSD: return "GSBI_IX86_BUILTIN_CMPUNORDSD"; case GSBI_IX86_BUILTIN_CMPNESD: return "GSBI_IX86_BUILTIN_CMPNESD"; case GSBI_IX86_BUILTIN_COMIEQSD: return "GSBI_IX86_BUILTIN_COMIEQSD"; case GSBI_IX86_BUILTIN_COMILTSD: return "GSBI_IX86_BUILTIN_COMILTSD"; case GSBI_IX86_BUILTIN_COMILESD: return "GSBI_IX86_BUILTIN_COMILESD"; case GSBI_IX86_BUILTIN_COMIGTSD: return "GSBI_IX86_BUILTIN_COMIGTSD"; case GSBI_IX86_BUILTIN_COMIGESD: return "GSBI_IX86_BUILTIN_COMIGESD"; case GSBI_IX86_BUILTIN_COMINEQSD: return "GSBI_IX86_BUILTIN_COMINEQSD"; case GSBI_IX86_BUILTIN_UCOMIEQSD: return "GSBI_IX86_BUILTIN_UCOMIEQSD"; case GSBI_IX86_BUILTIN_UCOMILTSD: return "GSBI_IX86_BUILTIN_UCOMILTSD"; case GSBI_IX86_BUILTIN_UCOMILESD: return "GSBI_IX86_BUILTIN_UCOMILESD"; case GSBI_IX86_BUILTIN_UCOMIGTSD: return "GSBI_IX86_BUILTIN_UCOMIGTSD"; case GSBI_IX86_BUILTIN_UCOMIGESD: return "GSBI_IX86_BUILTIN_UCOMIGESD"; case GSBI_IX86_BUILTIN_UCOMINEQSD: return "GSBI_IX86_BUILTIN_UCOMINEQSD"; case GSBI_IX86_BUILTIN_MAXPD: return "GSBI_IX86_BUILTIN_MAXPD"; case GSBI_IX86_BUILTIN_MAXSD: return "GSBI_IX86_BUILTIN_MAXSD"; case GSBI_IX86_BUILTIN_MINPD: return "GSBI_IX86_BUILTIN_MINPD"; case GSBI_IX86_BUILTIN_MINSD: return "GSBI_IX86_BUILTIN_MINSD"; case GSBI_IX86_BUILTIN_ANDPD: return "GSBI_IX86_BUILTIN_ANDPD"; case GSBI_IX86_BUILTIN_ANDNPD: return "GSBI_IX86_BUILTIN_ANDNPD"; case GSBI_IX86_BUILTIN_ORPD: return "GSBI_IX86_BUILTIN_ORPD"; case GSBI_IX86_BUILTIN_XORPD: return "GSBI_IX86_BUILTIN_XORPD"; case GSBI_IX86_BUILTIN_SQRTPD: return "GSBI_IX86_BUILTIN_SQRTPD"; case GSBI_IX86_BUILTIN_SQRTSD: return "GSBI_IX86_BUILTIN_SQRTSD"; case GSBI_IX86_BUILTIN_UNPCKHPD: return "GSBI_IX86_BUILTIN_UNPCKHPD"; case GSBI_IX86_BUILTIN_UNPCKLPD: return "GSBI_IX86_BUILTIN_UNPCKLPD"; case GSBI_IX86_BUILTIN_SHUFPD: return "GSBI_IX86_BUILTIN_SHUFPD"; case GSBI_IX86_BUILTIN_LOADUPD: return "GSBI_IX86_BUILTIN_LOADUPD"; case GSBI_IX86_BUILTIN_STOREUPD: return "GSBI_IX86_BUILTIN_STOREUPD"; case GSBI_IX86_BUILTIN_MOVSD: return "GSBI_IX86_BUILTIN_MOVSD"; case GSBI_IX86_BUILTIN_LOADHPD: return "GSBI_IX86_BUILTIN_LOADHPD"; case GSBI_IX86_BUILTIN_LOADLPD: return "GSBI_IX86_BUILTIN_LOADLPD"; case GSBI_IX86_BUILTIN_CVTDQ2PD: return "GSBI_IX86_BUILTIN_CVTDQ2PD"; case GSBI_IX86_BUILTIN_CVTDQ2PS: return "GSBI_IX86_BUILTIN_CVTDQ2PS"; case GSBI_IX86_BUILTIN_CVTPD2DQ: return "GSBI_IX86_BUILTIN_CVTPD2DQ"; case GSBI_IX86_BUILTIN_CVTPD2PI: return "GSBI_IX86_BUILTIN_CVTPD2PI"; case GSBI_IX86_BUILTIN_CVTPD2PS: return "GSBI_IX86_BUILTIN_CVTPD2PS"; case GSBI_IX86_BUILTIN_CVTTPD2DQ: return "GSBI_IX86_BUILTIN_CVTTPD2DQ"; case GSBI_IX86_BUILTIN_CVTTPD2PI: return "GSBI_IX86_BUILTIN_CVTTPD2PI"; case GSBI_IX86_BUILTIN_CVTPI2PD: return "GSBI_IX86_BUILTIN_CVTPI2PD"; case GSBI_IX86_BUILTIN_CVTSI2SD: return "GSBI_IX86_BUILTIN_CVTSI2SD"; case GSBI_IX86_BUILTIN_CVTSI642SD: return "GSBI_IX86_BUILTIN_CVTSI642SD"; case GSBI_IX86_BUILTIN_CVTSD2SI: return "GSBI_IX86_BUILTIN_CVTSD2SI"; case GSBI_IX86_BUILTIN_CVTSD2SI64: return "GSBI_IX86_BUILTIN_CVTSD2SI64"; case GSBI_IX86_BUILTIN_CVTSD2SS: return "GSBI_IX86_BUILTIN_CVTSD2SS"; case GSBI_IX86_BUILTIN_CVTSS2SD: return "GSBI_IX86_BUILTIN_CVTSS2SD"; case GSBI_IX86_BUILTIN_CVTTSD2SI: return "GSBI_IX86_BUILTIN_CVTTSD2SI"; case GSBI_IX86_BUILTIN_CVTTSD2SI64: return "GSBI_IX86_BUILTIN_CVTTSD2SI64"; case GSBI_IX86_BUILTIN_CVTPS2DQ: return "GSBI_IX86_BUILTIN_CVTPS2DQ"; case GSBI_IX86_BUILTIN_CVTPS2PD: return "GSBI_IX86_BUILTIN_CVTPS2PD"; case GSBI_IX86_BUILTIN_CVTTPS2DQ: return "GSBI_IX86_BUILTIN_CVTTPS2DQ"; case GSBI_IX86_BUILTIN_MOVNTI: return "GSBI_IX86_BUILTIN_MOVNTI"; case GSBI_IX86_BUILTIN_MOVNTPD: return "GSBI_IX86_BUILTIN_MOVNTPD"; case GSBI_IX86_BUILTIN_MOVNTDQ: return "GSBI_IX86_BUILTIN_MOVNTDQ"; case GSBI_IX86_BUILTIN_MASKMOVDQU: return "GSBI_IX86_BUILTIN_MASKMOVDQU"; case GSBI_IX86_BUILTIN_MOVMSKPD: return "GSBI_IX86_BUILTIN_MOVMSKPD"; case GSBI_IX86_BUILTIN_PMOVMSKB128: return "GSBI_IX86_BUILTIN_PMOVMSKB128"; case GSBI_IX86_BUILTIN_PACKSSWB128: return "GSBI_IX86_BUILTIN_PACKSSWB128"; case GSBI_IX86_BUILTIN_PACKSSDW128: return "GSBI_IX86_BUILTIN_PACKSSDW128"; case GSBI_IX86_BUILTIN_PACKUSWB128: return "GSBI_IX86_BUILTIN_PACKUSWB128"; case GSBI_IX86_BUILTIN_PADDB128: return "GSBI_IX86_BUILTIN_PADDB128"; case GSBI_IX86_BUILTIN_PADDW128: return "GSBI_IX86_BUILTIN_PADDW128"; case GSBI_IX86_BUILTIN_PADDD128: return "GSBI_IX86_BUILTIN_PADDD128"; case GSBI_IX86_BUILTIN_PADDQ128: return "GSBI_IX86_BUILTIN_PADDQ128"; case GSBI_IX86_BUILTIN_PADDSB128: return "GSBI_IX86_BUILTIN_PADDSB128"; case GSBI_IX86_BUILTIN_PADDSW128: return "GSBI_IX86_BUILTIN_PADDSW128"; case GSBI_IX86_BUILTIN_PADDUSB128: return "GSBI_IX86_BUILTIN_PADDUSB128"; case GSBI_IX86_BUILTIN_PADDUSW128: return "GSBI_IX86_BUILTIN_PADDUSW128"; case GSBI_IX86_BUILTIN_PSUBB128: return "GSBI_IX86_BUILTIN_PSUBB128"; case GSBI_IX86_BUILTIN_PSUBW128: return "GSBI_IX86_BUILTIN_PSUBW128"; case GSBI_IX86_BUILTIN_PSUBD128: return "GSBI_IX86_BUILTIN_PSUBD128"; case GSBI_IX86_BUILTIN_PSUBQ128: return "GSBI_IX86_BUILTIN_PSUBQ128"; case GSBI_IX86_BUILTIN_PSUBSB128: return "GSBI_IX86_BUILTIN_PSUBSB128"; case GSBI_IX86_BUILTIN_PSUBSW128: return "GSBI_IX86_BUILTIN_PSUBSW128"; case GSBI_IX86_BUILTIN_PSUBUSB128: return "GSBI_IX86_BUILTIN_PSUBUSB128"; case GSBI_IX86_BUILTIN_PSUBUSW128: return "GSBI_IX86_BUILTIN_PSUBUSW128"; case GSBI_IX86_BUILTIN_PAND128: return "GSBI_IX86_BUILTIN_PAND128"; case GSBI_IX86_BUILTIN_PANDN128: return "GSBI_IX86_BUILTIN_PANDN128"; case GSBI_IX86_BUILTIN_POR128: return "GSBI_IX86_BUILTIN_POR128"; case GSBI_IX86_BUILTIN_PXOR128: return "GSBI_IX86_BUILTIN_PXOR128"; case GSBI_IX86_BUILTIN_PAVGB128: return "GSBI_IX86_BUILTIN_PAVGB128"; case GSBI_IX86_BUILTIN_PAVGW128: return "GSBI_IX86_BUILTIN_PAVGW128"; case GSBI_IX86_BUILTIN_PCMPEQB128: return "GSBI_IX86_BUILTIN_PCMPEQB128"; case GSBI_IX86_BUILTIN_PCMPEQW128: return "GSBI_IX86_BUILTIN_PCMPEQW128"; case GSBI_IX86_BUILTIN_PCMPEQD128: return "GSBI_IX86_BUILTIN_PCMPEQD128"; case GSBI_IX86_BUILTIN_PCMPGTB128: return "GSBI_IX86_BUILTIN_PCMPGTB128"; case GSBI_IX86_BUILTIN_PCMPGTW128: return "GSBI_IX86_BUILTIN_PCMPGTW128"; case GSBI_IX86_BUILTIN_PCMPGTD128: return "GSBI_IX86_BUILTIN_PCMPGTD128"; case GSBI_IX86_BUILTIN_PMADDWD128: return "GSBI_IX86_BUILTIN_PMADDWD128"; case GSBI_IX86_BUILTIN_PMAXSW128: return "GSBI_IX86_BUILTIN_PMAXSW128"; case GSBI_IX86_BUILTIN_PMAXUB128: return "GSBI_IX86_BUILTIN_PMAXUB128"; case GSBI_IX86_BUILTIN_PMINSW128: return "GSBI_IX86_BUILTIN_PMINSW128"; case GSBI_IX86_BUILTIN_PMINUB128: return "GSBI_IX86_BUILTIN_PMINUB128"; case GSBI_IX86_BUILTIN_PMULUDQ: return "GSBI_IX86_BUILTIN_PMULUDQ"; case GSBI_IX86_BUILTIN_PMULUDQ128: return "GSBI_IX86_BUILTIN_PMULUDQ128"; case GSBI_IX86_BUILTIN_PMULHUW128: return "GSBI_IX86_BUILTIN_PMULHUW128"; case GSBI_IX86_BUILTIN_PMULHW128: return "GSBI_IX86_BUILTIN_PMULHW128"; case GSBI_IX86_BUILTIN_PMULLW128: return "GSBI_IX86_BUILTIN_PMULLW128"; case GSBI_IX86_BUILTIN_PSADBW128: return "GSBI_IX86_BUILTIN_PSADBW128"; case GSBI_IX86_BUILTIN_PSHUFHW: return "GSBI_IX86_BUILTIN_PSHUFHW"; case GSBI_IX86_BUILTIN_PSHUFLW: return "GSBI_IX86_BUILTIN_PSHUFLW"; case GSBI_IX86_BUILTIN_PSHUFD: return "GSBI_IX86_BUILTIN_PSHUFD"; case GSBI_IX86_BUILTIN_PSLLW128: return "GSBI_IX86_BUILTIN_PSLLW128"; case GSBI_IX86_BUILTIN_PSLLD128: return "GSBI_IX86_BUILTIN_PSLLD128"; case GSBI_IX86_BUILTIN_PSLLQ128: return "GSBI_IX86_BUILTIN_PSLLQ128"; case GSBI_IX86_BUILTIN_PSRAW128: return "GSBI_IX86_BUILTIN_PSRAW128"; case GSBI_IX86_BUILTIN_PSRAD128: return "GSBI_IX86_BUILTIN_PSRAD128"; case GSBI_IX86_BUILTIN_PSRLW128: return "GSBI_IX86_BUILTIN_PSRLW128"; case GSBI_IX86_BUILTIN_PSRLD128: return "GSBI_IX86_BUILTIN_PSRLD128"; case GSBI_IX86_BUILTIN_PSRLQ128: return "GSBI_IX86_BUILTIN_PSRLQ128"; case GSBI_IX86_BUILTIN_PSLLDQI128: return "GSBI_IX86_BUILTIN_PSLLDQI128"; case GSBI_IX86_BUILTIN_PSLLWI128: return "GSBI_IX86_BUILTIN_PSLLWI128"; case GSBI_IX86_BUILTIN_PSLLDI128: return "GSBI_IX86_BUILTIN_PSLLDI128"; case GSBI_IX86_BUILTIN_PSLLQI128: return "GSBI_IX86_BUILTIN_PSLLQI128"; case GSBI_IX86_BUILTIN_PSRAWI128: return "GSBI_IX86_BUILTIN_PSRAWI128"; case GSBI_IX86_BUILTIN_PSRADI128: return "GSBI_IX86_BUILTIN_PSRADI128"; case GSBI_IX86_BUILTIN_PSRLDQI128: return "GSBI_IX86_BUILTIN_PSRLDQI128"; case GSBI_IX86_BUILTIN_PSRLWI128: return "GSBI_IX86_BUILTIN_PSRLWI128"; case GSBI_IX86_BUILTIN_PSRLDI128: return "GSBI_IX86_BUILTIN_PSRLDI128"; case GSBI_IX86_BUILTIN_PSRLQI128: return "GSBI_IX86_BUILTIN_PSRLQI128"; case GSBI_IX86_BUILTIN_PUNPCKHBW128: return "GSBI_IX86_BUILTIN_PUNPCKHBW128"; case GSBI_IX86_BUILTIN_PUNPCKHWD128: return "GSBI_IX86_BUILTIN_PUNPCKHWD128"; case GSBI_IX86_BUILTIN_PUNPCKHDQ128: return "GSBI_IX86_BUILTIN_PUNPCKHDQ128"; case GSBI_IX86_BUILTIN_PUNPCKHQDQ128: return "GSBI_IX86_BUILTIN_PUNPCKHQDQ128"; case GSBI_IX86_BUILTIN_PUNPCKLBW128: return "GSBI_IX86_BUILTIN_PUNPCKLBW128"; case GSBI_IX86_BUILTIN_PUNPCKLWD128: return "GSBI_IX86_BUILTIN_PUNPCKLWD128"; case GSBI_IX86_BUILTIN_PUNPCKLDQ128: return "GSBI_IX86_BUILTIN_PUNPCKLDQ128"; case GSBI_IX86_BUILTIN_PUNPCKLQDQ128: return "GSBI_IX86_BUILTIN_PUNPCKLQDQ128"; case GSBI_IX86_BUILTIN_CLFLUSH: return "GSBI_IX86_BUILTIN_CLFLUSH"; case GSBI_IX86_BUILTIN_MFENCE: return "GSBI_IX86_BUILTIN_MFENCE"; case GSBI_IX86_BUILTIN_LFENCE: return "GSBI_IX86_BUILTIN_LFENCE"; case GSBI_IX86_BUILTIN_ADDSUBPS: return "GSBI_IX86_BUILTIN_ADDSUBPS"; case GSBI_IX86_BUILTIN_HADDPS: return "GSBI_IX86_BUILTIN_HADDPS"; case GSBI_IX86_BUILTIN_HSUBPS: return "GSBI_IX86_BUILTIN_HSUBPS"; case GSBI_IX86_BUILTIN_MOVSHDUP: return "GSBI_IX86_BUILTIN_MOVSHDUP"; case GSBI_IX86_BUILTIN_MOVSLDUP: return "GSBI_IX86_BUILTIN_MOVSLDUP"; case GSBI_IX86_BUILTIN_ADDSUBPD: return "GSBI_IX86_BUILTIN_ADDSUBPD"; case GSBI_IX86_BUILTIN_HADDPD: return "GSBI_IX86_BUILTIN_HADDPD"; case GSBI_IX86_BUILTIN_HSUBPD: return "GSBI_IX86_BUILTIN_HSUBPD"; case GSBI_IX86_BUILTIN_LDDQU: return "GSBI_IX86_BUILTIN_LDDQU"; case GSBI_IX86_BUILTIN_MONITOR: return "GSBI_IX86_BUILTIN_MONITOR"; case GSBI_IX86_BUILTIN_MWAIT: return "GSBI_IX86_BUILTIN_MWAIT"; case GSBI_IX86_BUILTIN_VEC_INIT_V2SI: return "GSBI_IX86_BUILTIN_VEC_INIT_V2SI"; case GSBI_IX86_BUILTIN_VEC_INIT_V4HI: return "GSBI_IX86_BUILTIN_VEC_INIT_V4HI"; case GSBI_IX86_BUILTIN_VEC_INIT_V8QI: return "GSBI_IX86_BUILTIN_VEC_INIT_V8QI"; case GSBI_IX86_BUILTIN_VEC_EXT_V2DF: return "GSBI_IX86_BUILTIN_VEC_EXT_V2DF"; case GSBI_IX86_BUILTIN_VEC_EXT_V2DI: return "GSBI_IX86_BUILTIN_VEC_EXT_V2DI"; case GSBI_IX86_BUILTIN_VEC_EXT_V4SF: return "GSBI_IX86_BUILTIN_VEC_EXT_V4SF"; case GSBI_IX86_BUILTIN_VEC_EXT_V4SI: return "GSBI_IX86_BUILTIN_VEC_EXT_V4SI"; case GSBI_IX86_BUILTIN_VEC_EXT_V8HI: return "GSBI_IX86_BUILTIN_VEC_EXT_V8HI"; case GSBI_IX86_BUILTIN_VEC_EXT_V2SI: return "GSBI_IX86_BUILTIN_VEC_EXT_V2SI"; case GSBI_IX86_BUILTIN_VEC_EXT_V4HI: return "GSBI_IX86_BUILTIN_VEC_EXT_V4HI"; case GSBI_IX86_BUILTIN_VEC_SET_V8HI: return "GSBI_IX86_BUILTIN_VEC_SET_V8HI"; case GSBI_IX86_BUILTIN_VEC_SET_V4HI: return "GSBI_IX86_BUILTIN_VEC_SET_V4HI"; case GSBI_IX86_BUILTIN_MAX: return "GSBI_IX86_BUILTIN_MAX"; } printf ("Code: %d\n", code); GS_ASSERT (gs_false, (gs_string_t) "gsbi_ts name name not implemented."); return (char *) NULL; } // no carriage return is printed static void gs_dump_leaf(gs_t t, FILE *f, gs_code_t parent_code, int parent_code_class, int index_in_parent) { int j; if (t == (gs_t) NULL) return; fprintf (f, "%s<%d> ", gs_code_name (gs_code (t)), gs_mempool_address2byteofst(GS_ARENA, (char *)t)); switch (gs_code (t)) { case GS_ERROR_MARK: break; case IB_STRING: fprintf (f, "\""); for (j = 0; j < gs_slen(t); j++) if (*(j + gs_s (t)) != '\0') fputc(*(j + gs_s (t)), f); fprintf (f, "\" "); break; case IB_UNSIGNED: fprintf (f, "%u ", gs_u (t)); break; case IB_LONG_LONG: fprintf (f, "%lld ", gs_ll (t)); break; case IB_UNSIGNED_LONG_LONG: fprintf (f, "%llu ", gs_ull (t)); break; case IB_INT: fprintf (f, "%d ", gs_n (t)); break; case IB_FLOAT: fprintf (f, "%f ", gs_f (t)); break; case IB_DOUBLE: fprintf (f, "%f ", gs_d (t)); break; case GS_TCC: fprintf (f, "%s ", gs_tree_code_class_name ((gs_tree_code_class_t) gs_b (t))); break; case GSBI: if (GSBI_BUILT_IN_ACOS <= (gsbi_t) gs_hword(t) && (gsbi_t) gs_hword(t) <= GSBI_END_BUILTINS) { fprintf (f, "%s ", gsbi_name ((gsbi_t) gs_hword(t))); } else if (GSBI_IX86_BUILTIN_ADDPS <= ((gsbi_ts_t) gs_hword(t)) && ((gsbi_ts_t) gs_hword(t)) <= GSBI_IX86_BUILTIN_MAX) { fprintf (f, "%s ", gsbi_ts_name ((gsbi_ts_t) gs_hword(t))); } else { fprintf (f, "GSBI_BUILT_IN_ACOS: %d, GSBI_END_BUILTINS: %d, GSBI_IX86_BUILTIN_ADDPS:%d, GSBI_IX86_BUILTIN_MAX: %d" " Warning: Unhandled GSBI case: %d ", GSBI_BUILT_IN_ACOS, GSBI_END_BUILTINS, GSBI_IX86_BUILTIN_ADDPS, GSBI_IX86_BUILTIN_MAX, gs_hword(t)); } break; case GSBI_CLASS: fprintf (f, "%s ", gsbi_class_name ((gsbi_class_t) gs_b (t))); break; case IB_LONG: fprintf (f, "%d ", gs_b(t)); break; case IB_LONG_DOUBLE: fprintf (f, "%LF ", (long double) gs_ld (t)); break; case IB_UNSIGNED_LONG: fprintf (f, "0x%x ", gs_u(t)); break; case IB_BOOL: fprintf (f, "%s ", gs_b (t) == true ? "gs_true" : "gs_false"); break; case IB_CHAR: fprintf(f, "%c ", gs_b(t)); break; case IB_BIT_VECTOR: for (j = 0; j < sizeof (gs_long_long_t) * 8; j++) { if (gs_bv (t, j) == gs_true) { fprintf(f, "%s ", gs_flag_name(parent_code, index_in_parent, j, parent_code_class)); } } break; default: GS_ASSERT (gs_false, "unexpected 0-arity tree code"); break; } } static void gs_dump_core(gs_t t, gs_count_t *indentation, FILE *f, bool concise, gs_code_t parent_code, int parent_code_class, int index_in_parent, bool indent) { static int function_nest_level = 0; gs_count_t i, j; if (t == (gs_t) NULL) return; if (indent) for (i = 0; i < *indentation; i++) fprintf (f, " "); if (gs_em (t) == true || (gs_code(t) == GS_FUNCTION_DECL && function_nest_level > 0 && gs_decl_saved_tree(t) != NULL)) { fprintf (f, "LINK %d\n", gs_mempool_address2byteofst(GS_ARENA, (char *)t)); return; } _gs_em (t, true); if (gs_code_arity(gs_code(t)) == 0) { gs_dump_leaf(t, f, parent_code, parent_code_class, index_in_parent); fprintf(f, "\n"); return; } fprintf (f, "%s<%d> ", gs_code_name (gs_code (t)), gs_mempool_address2byteofst(GS_ARENA, (char *)t)); switch (gs_code (t)) { case EMPTY: for (i = 0; i < *indentation; i++) fprintf (f, " "); fprintf (f, "[]\n"); break; case CONS: { for (i = 0; i < *indentation; i++) fprintf (f, " "); fprintf (f, "[\n"); (*indentation)++; gs_t p; for (p = t; gs_code(p) != EMPTY; p = gs_operand(p, 1)) gs_dump_core (gs_operand(p, 0), indentation, f, concise, parent_code, parent_code_class, index_in_parent, true); (*indentation)--; for (i = 0; i < *indentation; i++) fprintf (f, " "); fprintf (f, "]\n"); } break; case GS_PROGRAM: fprintf (f, "{\n"); (*indentation)++; for (j = 0; j < gs_code_arity(gs_code(t)); j++) { if (gs_operand(t, j) != NULL) { gs_string_t p; gs_int_t omit = 0; p = gs_attribute_name(j, gs_b(gs_operand(t, 0)), gs_code(t), &omit); for (i = 0; i < *indentation; i++) fprintf (f, " "); fprintf (f, "@"); for ( ; *p != '\0'; p++) fprintf (f, "%c", tolower (*p)); fprintf (f, " "); gs_dump_core(gs_operand(t, j), indentation, f, concise, gs_code(t), gs_b(gs_operand(t, GS_TREE_CODE_CLASS)), j, false); } } (*indentation)--; for (i = 0; i < *indentation; i++) fprintf (f, " "); fprintf (f, "}\n"); break; default: fprintf (f, "{ "); (*indentation)++; // do leaf kids first without inserting carriage returns for (j = 0; j < gs_code_arity(gs_code(t)); j++) { if (gs_operand(t, j) != NULL && gs_code_arity(gs_code(gs_operand(t, j))) == 0) { fprintf(f, "(%d)", j); gs_dump_leaf(gs_operand(t, j), f, gs_code(t), gs_b(gs_operand(t, GS_TREE_CODE_CLASS)), j); } } fprintf (f, "\n"); // now do non-leaf kids but skip GS_TREE_CHAIN if (gs_code(t) == GS_FUNCTION_DECL) function_nest_level++; for (j = GS_TREE_CHAIN-1; j < gs_code_arity(gs_code(t)); j++) { if (j == GS_TREE_CHAIN) continue; if (gs_operand(t, j) != NULL && gs_code_arity(gs_code(gs_operand(t, j))) != 0) { gs_string_t p; gs_int_t omit = 0; p = gs_attribute_name(j, gs_b(gs_operand(t, 0)), gs_code(t), &omit); // gs_attribute_name returns NULL if the constructor does not have // an attribute name for this attribute. This can legitimately // happen if the arg is a dummy arg put there to make the tree have // the correct number of args for the tree code class (tcc). If // so, the arg should be NULL. if (p != NULL && (!concise || !omit)) { for (i = 0; i < *indentation; i++) fprintf (f, " "); fprintf (f, "@"); for ( ; *p != '\0'; p++) fprintf (f, "%c", tolower (*p)); fprintf (f, " "); gs_dump_core(gs_operand(t, j), indentation, f, concise, gs_code(t), gs_b(gs_operand(t, GS_TREE_CODE_CLASS)), j, false); } } } // now do GS_TREE_CHAIN if (gs_operand(t, GS_TREE_CHAIN) != NULL && gs_code_arity(gs_code(gs_operand(t, GS_TREE_CHAIN))) != 0) { gs_string_t p; gs_int_t omit = 0; p = gs_attribute_name(GS_TREE_CHAIN, gs_b(gs_operand(t, 0)), gs_code(t), &omit); // gs_attribute_name returns NULL if the constructor does not have // an attribute name for this attribute. This can legitimately // happen if the arg is a dummy arg put there to make the tree have // the correct number of args for the tree code class (tcc). If // so, the arg should be NULL. if (p != NULL && (!concise || !omit)) { for (i = 0; i < *indentation; i++) fprintf (f, " "); fprintf (f, "@"); for ( ; *p != '\0'; p++) fprintf (f, "%c", tolower (*p)); fprintf (f, " "); gs_dump_core(gs_operand(t, GS_TREE_CHAIN), indentation, f, concise, gs_code(t), gs_b(gs_operand(t, GS_TREE_CODE_CLASS)), GS_TREE_CHAIN, false); } } if (gs_code(t) == GS_FUNCTION_DECL) function_nest_level--; (*indentation)--; for (i = 0; i < *indentation; i++) fprintf (f, " "); fprintf (f, "}\n"); break; } } gs_void_t gs_dump (gs_t t) { gs_count_t indentation; indentation = 0; gs_dump_core (t, &indentation, stdout, true, 0, 0, 0, false); } gs_void_t gs_dump_file (gs_t t, FILE *f) { gs_count_t indentation; indentation = 0; gs_dump_core (t, &indentation, f, false, 0, 0, 0, false); } #ifdef Is_True_On // for calling from debugger only int gs_id (gs_t node) { return gs_mempool_address2byteofst(GS_ARENA, (char *)node); } #endif
722,022
./hicuda/src/libspin/gspin-test-driver.c
/* Copyright (C) 2006. QLogic Corporation. All Rights Reserved. This program is free software; you can redistribute it and/or modify it under the terms of version 2 of the GNU General Public License as published by the Free Software Foundation. This program is distributed in the hope that it would be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Further, this software is distributed without any warranty that it is free of the rightful claim of any third person regarding infringement or the like. Any license provided herein, whether implied or otherwise, applies only to this software file. Patent licenses, if any, provided herein do not apply to combinations of this program with other software, or any other product whatsoever. You should have received a copy of the GNU General Public License along with this program; if not, write the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA. */ #include <stdio.h> #include <stdlib.h> #include "gspin-tree.h" #include "gspin-io.h" extern gs_void_t gs_dump_file (gs_t t, FILE *f) ; int main (int argc, char *argv[]) { gs_t p; char *file_name, *outfile_name; FILE *f; if (argc != 2) { printf("usage: gspin <spin_file>\n"); printf(" \"gspin foo.spin\" will dump to \"foo.spin.txt\".\n"); exit(1); } file_name = argv[1]; outfile_name = (char *) malloc(strlen(file_name) + 10); sprintf(outfile_name, "%s.txt", file_name); f = fopen(outfile_name, "w"); if (f == NULL) { printf("gspin: cannot write to %s\n", outfile_name); } p = gs_read_file (argv[1]); gs_dump_file (p, f); // printf ("struct gspin size: %d (bytes)\n", sizeof (struct gspin)); fclose(f); return 0; }
722,023
./hicuda/src/libspin/gspin-list.c
/* Copyright (C) 2006. QLogic Corporation. All Rights Reserved. This program is free software; you can redistribute it and/or modify it under the terms of version 2 of the GNU General Public License as published by the Free Software Foundation. This program is distributed in the hope that it would be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Further, this software is distributed without any warranty that it is free of the rightful claim of any third person regarding infringement or the like. Any license provided herein, whether implied or otherwise, applies only to this software file. Patent licenses, if any, provided herein do not apply to combinations of this program with other software, or any other product whatsoever. You should have received a copy of the GNU General Public License along with this program; if not, write the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA. */ #include "gspin-tree.h" #include "gspin-list.h" gs_count_t gs_length (gs_t list) { GS_ASSERT (list != (gs_t) NULL, "got null list."); int n; for (n=0;gs_code(list) != EMPTY; n++, list = gs_operand(list, 1)); return n; } gs_t gs_index (gs_t list, gs_count_t index) { GS_ASSERT (list != (gs_t) NULL, "got null list."); GS_ASSERT (gs_length(list) > index, "index >= length of list too large."); for (; index != 0; index--, list = gs_operand(list, 1)); return gs_operand(list, 0); }
722,024
./hicuda/src/libspin/gspin-tel.c
/* Copyright (C) 2006. QLogic Corporation. All Rights Reserved. This program is free software; you can redistribute it and/or modify it under the terms of version 2 of the GNU General Public License as published by the Free Software Foundation. This program is distributed in the hope that it would be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Further, this software is distributed without any warranty that it is free of the rightful claim of any third person regarding infringement or the like. Any license provided herein, whether implied or otherwise, applies only to this software file. Patent licenses, if any, provided herein do not apply to combinations of this program with other software, or any other product whatsoever. You should have received a copy of the GNU General Public License along with this program; if not, write the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA. */ #include <string.h> #include <stdio.h> #include <stdlib.h> #include "gspin-tree.h" #include "gspin-list.h" #include "gspin-tel.h" #include "gspin-mempool.h" #define OMIT *omit = 1 // from gspin-tree.c extern struct tree_code_property { gs_code_t tree_code; signed char arity; // -1 means not yet known; assert when this value gs_tree_code_class_t tcc; char *name; } tree_code_table[256]; gs_char_t operand_number[256]; gs_t gs_program = NULL; // The root program node when translating from gspin. gs_tree_code_class_t gs_tree_code_class(gs_t t) { GS_ASSERT (t != (gs_t) NULL, "Got null node"); gs_tree_code_class_t tcc = (gs_tree_code_class_t) gs_b(gs_operand (t, GS_TREE_CODE_CLASS)); GS_ASSERT(tcc == tree_code_table[gs_code(t)].tcc, "Incorrect tree code class in tree_code_table"); #ifdef Is_True_On if (tcc != tree_code_table[gs_code(t)].tcc) { printf("%s should have tcc %s\n", gs_code_name(gs_code(t)), gs_tree_code_class_name(tcc)); abort(); } #endif return tcc; } // Return the name of the attribute. Return NULL if no such attribute. gs_string_t gs_attribute_name (gs_int_t attribute, gs_tree_code_class_t tree_code_class, gs_code_t constructor, gs_int_t * omit) { if (constructor == GS_PROGRAM) { switch (attribute) { case GS_CC1_COMMAND_LINE_ARGS: return "GS_CC1_COMMAND_LINE_ARGS"; case GS_PROGRAM_DECLARATIONS: return "GS_PROGRAM_DECLARATIONS"; case GS_GLOBAL_TREES_LIST: return "GS_GLOBAL_TREES_LIST"; case GS_INTEGER_TYPES_LIST: return "GS_INTEGER_TYPES_LIST"; case GS_GXX_EMITTED_DECLS: return "GS_GXX_EMITTED_DECLS"; case GS_GXX_EMITTED_ASMS: return "GS_GXX_EMITTED_ASMS"; case GS_PROGRAM_FLAGS: return "GS_PROGRAM_FLAGS"; case GS_WEAK_DECLS: return "GS_WEAK_DECLS"; default: GS_ASSERT(gs_false,("gs_attribute_name: unkown GS_PROGRAM attribute")); return (gs_string_t) "UNKNOWN!"; } } switch (attribute) { case GS_TREE_CODE_CLASS: OMIT; return "GS_TREE_CODE_CLASS"; case GS_TREE_TYPE: OMIT; return "GS_TREE_TYPE"; case GS_FLAGS: return "GS_FLAGS"; } if (tree_code_class == GS_TCC_DECLARATION) { switch (attribute) { case GS_LABEL_DECL_UID: OMIT; return "GS_LABEL_DECL_UID"; case GS_DECL_UID: OMIT; return "GS_DECL_UID"; case GS_DECL_NAME: return "GS_DECL_NAME"; case GS_TREE_CHAIN: return "GS_TREE_CHAIN"; case GS_DECL_MODE: OMIT; return "GS_DECL_MODE"; case GS_DECL_SOURCE_FILE: OMIT; return "GS_DECL_SOURCE_FILE"; case GS_DECL_SOURCE_LINE: OMIT; return "GS_DECL_SOURCE_LINE"; case GS_DECL_SIZE: return "GS_DECL_SIZE"; case GS_DECL_SIZE_UNIT: OMIT; return "GS_DECL_SIZE_UNIT"; case GS_DECL_BUILT_IN_CLASS: OMIT; return "GS_DECL_BUILT_IN_CLASS"; case GS_DECL_FUNCTION_CODE: OMIT; return "GS_DECL_FUNCTION_CODE"; case GS_DECL_FIELD_OFFSET: return "GS_DECL_FIELD_OFFSET"; case GS_DECL_FIELD_BIT_OFFSET: OMIT; return "GS_DECL_FIELD_BIT_OFFSET"; case GS_DECL_CONTEXT: return "GS_DECL_CONTEXT"; case GS_DECL_ATTRIBUTES: return "GS_DECL_ATTRIBUTES"; case GS_DECL_ABSTRACT_ORIGIN: return "GS_DECL_ABSTRACT_ORIGIN"; case GS_DECL_ARGUMENTS: return (constructor == GS_VAR_DECL) ? "GS_DECL_ANON_UNION_ELEMS" : "GS_DECL_ARGUMENTS"; case GS_DECL_INITIAL: OMIT; return "GS_DECL_INITIAL"; case GS_DECL_ARG_TYPE: return "GS_DECL_ARG_TYPE"; case GS_DECL_ARG_TYPE_AS_WRITTEN: OMIT; return "GS_DECL_ARG_TYPE_AS_WRITTEN"; case GS_DECL_SAVED_TREE: return (constructor == GS_FUNCTION_DECL) ? "GS_DECL_SAVED_TREE" : "GS_DECL_VALUE_EXPR"; case GS_DECL_RESULT: return (constructor == GS_TYPE_DECL) ? "GS_DECL_ORIGINAL_TYPE" : "GS_DECL_RESULT"; case GS_CP_DECL_FLAGS: return "GS_CP_DECL_FLAGS"; case GS_DECL_ALIGN_UNIT: OMIT; return "GS_DECL_ALIGN_UNIT"; case GS_DECL_ASSEMBLER_NAME: return "GS_DECL_ASSEMBLER_NAME"; case GS_DECL_TEMPLATE_INFO: OMIT; return "GS_DECL_TEMPLATE_INFO"; case GS_DECL_SECTION_NAME: OMIT; return "GS_DECL_SECTION_NAME"; case GS_CP_DECL_CONTEXT: OMIT; return "GS_CP_DECL_CONTEXT"; case GS_DECL_VINDEX: OMIT; return "GS_DECL_VINDEX"; case GS_MOST_GENERAL_TEMPLATE: OMIT; return "GS_MOST_GENERAL_TEMPLATE"; case GS_DECL_ALIAS_TARGET: OMIT; return "GS_DECL_ALIAS_TARGET"; case GS_DECL_ASMREG: OMIT; return "GS_DECL_ASMREG"; case GS_DECL_NAMESPACE_ALIAS: OMIT; return "GS_DECL_NAMESPACE_ALIAS"; case GS_THUNK_TARGET: return "GS_THUNK_TARGET"; case GS_DECL_TI_TEMPLATE: OMIT; return "GS_DECL_TI_TEMPLATE"; case GS_THUNK_FIXED_OFFSET: OMIT; return "GS_THUNK_FIXED_OFFSET"; case GS_THUNK_VIRTUAL_OFFSET: OMIT; return "GS_THUNK_VIRTUAL_OFFSET"; case GS_DECL_NAMED_RETURN_OBJECT: OMIT; return "GS_DECL_NAME_RETURN_OBJECT"; } if (attribute == GS_DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P && constructor == GS_FUNCTION_DECL) return "GS_DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P"; if (attribute == GS_DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P && constructor == GS_FUNCTION_DECL) return "GS_DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P"; if (attribute == GS_CP_NAMESPACE_DECLS && constructor == GS_NAMESPACE_DECL) return "GS_CP_NAMESPACE_DECLS"; } else if (tree_code_class == GS_TCC_TYPE) { if (constructor == GS_ENUMERAL_TYPE && attribute == GS_TYPE_VALUES) return "GS_TYPE_VALUES"; if (constructor == GS_ARRAY_TYPE && attribute == GS_TYPE_DOMAIN) return "GS_TYPE_DOMAIN"; if (constructor == GS_VECTOR_TYPE) { if (attribute == GS_TYPE_VECTOR_SUBPARTS) return "GS_TYPE_VECTOR_SUBPARTS"; else if (attribute == GS_TYPE_DEBUG_REPRESENTATION_TYPE) return "GS_TYPE_DEBUG_REPRESENTATION_TYPE"; } if ((constructor == GS_RECORD_TYPE || constructor == GS_UNION_TYPE || constructor == GS_QUAL_UNION_TYPE) && attribute == GS_TYPE_FIELDS) return "GS_TYPE_FIELDS"; if ((constructor == GS_FUNCTION_TYPE || constructor == GS_METHOD_TYPE) && attribute == GS_TYPE_METHOD_BASETYPE) return "GS_TYPE_METHOD_BASETYPE"; if (constructor == GS_OFFSET_TYPE && attribute == GS_TYPE_OFFSET_BASETYPE) return "GS_TYPE_OFFSET_BASETYPE"; switch (attribute) { case GS_TYPE_NAME: return "GS_TYPE_NAME"; case GS_TREE_CHAIN: return "GS_TREE_CHAIN"; case GS_TYPE_MODE: OMIT; return "GS_TYPE_MODE"; case GS_TYPE_SIZE: return "GS_TYPE_SIZE"; case GS_TYPE_SIZE_UNIT: OMIT; return "GS_TYPE_SIZE_UNIT"; case GS_TYPE_USER_ALIGN: OMIT; return "GS_TYPE_USER_ALIGN"; case GS_TYPE_ALIGN: return "GS_TYPE_ALIGN"; case GS_TYPE_ALIAS_SET: OMIT; return "GS_TYPE_ALIAS_SET"; case GS_TYPE_ATTRIBUTES: return "GS_TYPE_ATTRIBUTES"; case GS_TYPE_PRECISION: OMIT; return "GS_TYPE_PRECISION"; case GS_TYPE_MIN_VALUE: OMIT; return (constructor == GS_RECORD_TYPE || constructor == GS_UNION_TYPE) ? "GS_TYPE_VFIELD" : (constructor == GS_POINTER_TYPE) ? "GS_TYPE_NEXT_PTR_TO" : "GS_TYPE_MIN_VALUE"; case GS_TYPE_MAX_VALUE: OMIT; return (constructor == GS_RECORD_TYPE || constructor == GS_UNION_TYPE) ? "GS_TYPE_METHODS" : "GS_TYPE_MAX_VALUE"; case GS_TYPE_ARG_TYPES: OMIT; return "GS_TYPE_ARG_TYPES"; case GS_TYPE_CONTEXT: return "GS_TYPE_CONTEXT"; case GS_TYPE_POINTER_TO: OMIT; return "GS_TYPE_POINTER_TO"; case GS_TYPE_REFERENCE_TO: return "GS_TYPE_REFERENCE_TO"; case GS_CP_TYPE_FLAGS: return "GS_CP_TYPE_FLAGS"; case GS_TYPE_BINFO: return "GS_TYPE_BINFO"; case GS_TYPE_MAIN_VARIANT: OMIT; return "GS_TYPE_MAIN_VARIANT"; case GS_CLASSTYPE_AS_BASE: return "GS_CLASSTYPE_AS_BASE"; case GS_CLASSTYPE_TYPEINFO_VAR: OMIT; return "GS_CLASSTYPE_TYPEINFO_VAR"; case GS_TYPEINFO_DECL: OMIT; return "GS_TYPEINFO_DECL"; case GS_CLASSTYPE_COPY_CONSTRUCTOR: OMIT; return "GS_CLASSTYPE_COPY_CONSTRUCTOR"; } } else if (tree_code_class == GS_TCC_EXPRESSION || tree_code_class == GS_TCC_COMPARISON || tree_code_class == GS_TCC_UNARY || tree_code_class == GS_TCC_BINARY || tree_code_class == GS_TCC_REFERENCE || tree_code_class == GS_TCC_STATEMENT) { switch (attribute) { case GS_ARITY: OMIT; return "GS_ARITY"; case GS_TREE_CHAIN: return "GS_TREE_CHAIN"; case GS_EXPR_FILENAME: OMIT; return "GS_EXPR_FILENAME"; case GS_EXPR_LINENO: OMIT; return "GS_EXPR_LINENO"; case GS_CP_EXPR_FLAGS: return "GS_CP_EXPR_FLAGS"; } switch (constructor) { case GS_ASM_EXPR: switch (attribute) { case GS_ASM_STRING: return "GS_ASM_STRING"; case GS_ASM_OUTPUTS: return "GS_ASM_OUTPUTS"; case GS_ASM_INPUTS: return "GS_ASM_INPUTS"; case GS_ASM_CLOBBERS: return "GS_ASM_CLOBBERS"; } return (gs_string_t) NULL; case GS_BIND_EXPR: switch (attribute) { case GS_BIND_EXPR_VARS: OMIT; return "GS_BIND_EXPR_VARS"; case GS_BIND_EXPR_BODY: return "GS_BIND_EXPR_BODY"; case GS_BIND_EXPR_BLOCK: OMIT; return "GS_BIND_EXPR_BLOCK"; } return (gs_string_t) NULL; case GS_CASE_LABEL_EXPR: switch (attribute) { case GS_CASE_LOW: return "GS_CASE_LOW"; case GS_CASE_HIGH: return "GS_CASE_HIGH"; case GS_CASE_LABEL: return "GS_CASE_LABEL"; } return (gs_string_t) NULL; case GS_CLEANUP_STMT: switch (attribute) { case GS_CLEANUP_EXPR: OMIT; return "GS_CLEANUP_EXPR"; case GS_CLEANUP_BODY: OMIT; return "GS_CLEANUP_BODY"; } return (gs_string_t) NULL; case GS_CONSTRUCTOR: if (attribute == GS_CONSTRUCTOR_ELTS) return "GS_CONSTRUCTOR_ELTS"; return (gs_string_t) "NONAME"; case GS_DECL_EXPR: if (attribute == GS_DECL_EXPR_DECL) return "GS_DECL_EXPR_DECL"; return (gs_string_t) "NONAME"; case GS_DO_STMT: switch (attribute) { case GS_DO_COND: return "GS_DO_COND"; case GS_DO_BODY: return "GS_DO_BODY"; } return (gs_string_t) NULL; case GS_EH_SPEC_BLOCK: switch (attribute) { case GS_EH_SPEC_STMTS: return "GS_EH_SPEC_STMTS"; case GS_EH_SPEC_RAISES: return "GS_EH_SPEC_RAISES"; } return (gs_string_t) NULL; case GS_EXPR_STMT: if (attribute == GS_EXPR_STMT_EXPR) return "GS_EXPR_STMT_EXPR"; return (gs_string_t) NULL; case GS_FOR_STMT: switch (attribute) { case GS_FOR_INIT_STMT: return "GS_FOR_INIT_STMT"; case GS_FOR_COND: return "GS_FOR_COND"; case GS_FOR_EXPR: return "GS_FOR_EXPR"; case GS_FOR_BODY: return "GS_FOR_BODY"; } return (gs_string_t) NULL; case GS_HANDLER: switch (attribute) { case GS_HANDLER_PARMS: return "GS_HANDLER_PARMS"; case GS_HANDLER_BODY: return "GS_HANDLER_BODY"; } return (gs_string_t) NULL; case GS_IF_STMT: switch (attribute) { case GS_IF_COND: return "GS_IF_COND"; case GS_THEN_CLAUSE: return "GS_THEN_CLAUSE"; case GS_ELSE_CLAUSE: return "GS_ELSE_CLAUSE"; } return (gs_string_t) NULL; case GS_LABEL_EXPR_LABEL: if (attribute == GS_LABEL_EXPR_LABEL) return "GS_LABEL_EXPR_LABEL"; return (gs_string_t) NULL; case GS_LOOP_EXPR: if (attribute == GS_LOOP_EXPR_BODY) return "GS_LOOP_EXPR_BODY"; return (gs_string_t) NULL; case GS_STMT_EXPR: if (attribute == GS_STMT_EXPR_STMT) return "GS_STMT_EXPR_STMT"; return (gs_string_t) NULL; case GS_TRY_BLOCK: switch (attribute) { case GS_TRY_STMTS: return "GS_TRY_STMTS"; case GS_TRY_HANDLERS: return "GS_TRY_HANDLERS"; } return (gs_string_t) NULL; case GS_WHILE_STMT: switch (attribute) { case GS_WHILE_COND: return "GS_WHILE_COND"; case GS_WHILE_BODY: return "GS_WHILE_BODY"; } return (gs_string_t) NULL; default: if (attribute >= GS_TREE_OPERAND_ZERO) { sprintf(operand_number, "Operand %d", attribute - GS_TREE_OPERAND_ZERO); return operand_number; } return (gs_string_t) NULL; } } else if (tree_code_class == GS_TCC_CONSTANT || tree_code_class == GS_TCC_EXCEPTIONAL) { if (attribute == GS_TREE_CHAIN) { return "GS_TREE_CHAIN"; } switch (constructor) { case GS_BASELINK: switch (attribute) { case GS_BASELINK_BINFO: return "GS_BASELINK_BINFO"; case GS_BASELINK_FUNCTIONS: return "GS_BASELINK_FUNCTIONS"; case GS_BASELINK_ACCESS_BINFO: return "GS_BASELINK_ACCESS_BINFO"; case GS_BASELINK_OPTYPE: return "GS_BASELINK_OPTYPE"; } return (gs_string_t) NULL; case GS_BLOCK: switch (attribute) { case GS_BLOCK_VARS: OMIT; return "GS_BLOCK_VARS"; case GS_BLOCK_SUPERCONTEXT: OMIT; return "GS_BLOCK_SUPERCONTEXT"; case GS_BLOCK_SUBBLOCKS: OMIT; return "GS_BLOCK_SUBBLOCKS"; case GS_BLOCK_CHAIN: OMIT; return "GS_BLOCK_CHAIN"; case GS_BLOCK_ABSTRACT_ORIGIN: OMIT; return "GS_BLOCK_ABSTRACT_ORIGIN"; } return (gs_string_t) NULL; case GS_COMPLEX_CST: switch (attribute) { case GS_TREE_REALPART: return "GS_TREE_REALPART"; case GS_TREE_IMAGPART: return "GS_TREE_IMAGPART"; } return (gs_string_t) NULL; case GS_IDENTIFIER_NODE: if (attribute == GS_IDENTIFIER_POINTER) return "GS_IDENTIFIER_POINTER"; return (gs_string_t) NULL; case GS_INTEGER_CST: switch (attribute) { case GS_TREE_INT_CST_LOW: return "GS_TREE_INT_CST_LOW"; case GS_TREE_INT_CST_HIGH: return "GS_TREE_INT_CST_HIGH"; } return (gs_string_t) NULL; case GS_PTRMEM_CST: switch (attribute) { case GS_EXPANDED_PTRMEM_CST: return "GS_EXPANDED_PTRMEM_CST"; } return (gs_string_t) NULL; case GS_REAL_CST: switch (attribute) { case GS_TREE_REAL_CST_F: return "GS_TREE_REAL_CST_F"; case GS_TREE_REAL_CST_D: return "GS_TREE_REAL_CST_D"; case GS_TREE_REAL_CST_LD: return "GS_TREE_REAL_CST_LD"; } return (gs_string_t) NULL; case GS_STATEMENT_LIST: if (attribute == GS_STATEMENT_LIST_ELTS) return "GS_STATEMENT_LIST_ELTS"; return (gs_string_t) NULL; case GS_STRING_CST: switch (attribute) { case GS_TREE_STRING_POINTER: return "GS_TREE_STRING_POINTER"; case GS_TREE_STRING_LENGTH: return "GS_TREE_STRING_LENGTH"; } return (gs_string_t) NULL; case GS_TEMPLATE_PARM_INDEX: switch (attribute) { case GS_TEMPLATE_PARM_IDX: OMIT; return "GS_TEMPLATE_PARM_IDX"; case GS_TEMPLATE_PARM_LEVEL: OMIT; return "GS_TEMPLATE_PARM_LEVEL"; case GS_TEMPLATE_PARM_DESCENDANTS: OMIT; return "GS_TEMPLATE_PARM_DESCENDANTS"; case GS_TEMPLATE_PARM_ORIG_LEVEL: OMIT; return "GS_TEMPLATE_PARM_ORIG_LEVEL"; case GS_TEMPLATE_PARM_DECL: OMIT; return "GS_TEMPLATE_PARM_DECL"; } return (gs_string_t) NULL; case GS_TREE_BINFO: switch (attribute) { case GS_BINFO_TYPE: return "GS_BINFO_TYPE"; case GS_BINFO_BASE_BINFOS: OMIT; return "GS_BINFO_BASE_BINFOS"; case GS_BINFO_VPTR_FIELD: return "GS_BINFO_VPTR_FIELD"; } return (gs_string_t) NULL; case GS_TREE_LIST: switch (attribute) { case GS_TREE_PURPOSE: return "GS_TREE_PURPOSE"; case GS_TREE_VALUE: return "GS_TREE_VALUE"; } return (gs_string_t) NULL; case GS_TREE_VEC: switch (attribute) { case GS_TREE_VEC_LENGTH: return "GS_TREE_VEC_LENGTH"; case GS_TREE_VEC_ELT: return "GS_TREE_VEC_ELT"; } return (gs_string_t) NULL; case GS_VECTOR_CST: if (attribute == GS_TREE_VECTOR_CST_ELTS) return "GS_TREE_VECTOR_CST_ELTS"; return (gs_string_t) NULL; case GS_OVERLOAD: switch (attribute) { case GS_OVL_FUNCTION: OMIT; return "GS_OVL_FUNCTION"; case GS_OVL_CHAIN: OMIT; return "GS_OVL_CHAIN"; case GS_OVL_CURRENT: OMIT; return "GS_OVL_CURRENT"; case GS_OVL_NEXT: OMIT; return "GS_OVL_NEXT"; } return (gs_string_t) NULL; default: break; } } return (gs_string_t) "NONAME"; } gs_string_t gs_flag_name (gs_code_t constructor, gs_int_t attribute, gs_count_t flag, gs_tree_code_class_t tree_code_class) { if (attribute == GS_FLAGS) { if (flag == GS_TYPE_READONLY || flag == GS_TREE_READONLY) { return (tree_code_class == GS_TCC_TYPE) ? "GS_TYPE_READONLY" : "GS_TREE_READONLY"; } if (flag == GS_TREE_CONSTANT || flag == GS_TYPE_SIZES_GIMPLIFIED) { return (tree_code_class == GS_TCC_TYPE) ? "GS_TYPE_SIZES_GIMPLIFIED" : "GS_TREE_CONSTANT"; } switch (flag) { case GS_TREE_SIDE_EFFECTS: return "GS_TREE_SIDE_EFFECTS"; case GS_TREE_INVARIANT: return "GS_TREE_INVARIANT"; case GS_TREE_ADDRESSABLE: return "GS_TREE_ADDRESSABLE"; case GS_TREE_THIS_VOLATILE: return "GS_TREE_THIS_VOLATILE"; case GS_TREE_ASM_WRITTEN: return "GS_TREE_ASM_WRITTEN"; case GS_TREE_USED: return constructor == GS_OVERLOAD ? "GS_OVL_USED" : "GS_TREE_USED"; case GS_TREE_NOTHROW: return "GS_TREE_NOTHROW"; case GS_TREE_PUBLIC: return "GS_TREE_PUBLIC"; case GS_TREE_PRIVATE: return "GS_TREE_PRIVATE"; case GS_TREE_PROTECTED: return "GS_TREE_PROTECTED"; case GS_TREE_STATIC: return (constructor == GS_IDENTIFIER_NODE)? "GS_TREE_SYMBOL_REFERENCED": (constructor == GS_POINTER_TYPE || constructor == GS_REFERENCE_TYPE) ? "GS_TYPE_REF_CAN_ALIAS_ALL": "GS_TREE_STATIC"; case GS_TREE_LANG_FLAG_0: return "GS_TREE_LANG_FLAG_0"; case GS_TREE_LANG_FLAG_1: return "GS_TREE_LANG_FLAG_1"; case GS_TREE_LANG_FLAG_2: return "GS_TREE_LANG_FLAG_2"; case GS_TREE_LANG_FLAG_3: return "GS_TREE_LANG_FLAG_3"; case GS_TREE_LANG_FLAG_4: return "GS_TREE_LANG_FLAG_4"; case GS_TREE_LANG_FLAG_5: return "GS_TREE_LANG_FLAG_5"; case GS_TREE_LANG_FLAG_6: return "GS_TREE_LANG_FLAG_6"; case GS_TREE_NOT_EMITTED_BY_GXX: return "GS_TREE_NOT_EMITTED_BY_GXX"; case GS_DWARF_ACCESS_FLAG_0: return "GS_DWARF_ACCESS_FLAG_0"; case GS_DWARF_ACCESS_FLAG_1: return "GS_DWARF_ACCESS_FLAG_1"; default: // FLAG is not in the common flags section. break; } if (tree_code_class == GS_TCC_DECLARATION) { switch (flag) { case GS_DECL_UNSIGNED: return "GS_DECL_UNSIGNED"; case GS_DECL_IGNORED_P: return "GS_DECL_IGNORED_P"; case GS_DECL_ABSTRACT: return "GS_DECL_ABSTRACT"; case GS_DECL_IN_SYSTEM_HEADER: return "GS_DECL_IN_SYSTEM_HEADER"; case GS_DECL_COMMON: return "GS_DECL_COMMON"; case GS_DECL_EXTERNAL: return "GS_DECL_EXTERNAL"; case GS_DECL_WEAK: return "GS_DECL_WEAK"; case GS_DECL_REGISTER: return "GS_DECL_REGISTER"; case GS_DECL_NONLOCAL: return "GS_DECL_NONLOCAL"; case GS_TYPE_DECL_SUPPRESS_DEBUG: return constructor == GS_FUNCTION_DECL ? "GS_DECL_NEEDED" : "GS_TYPE_DECL_SUPPRESS_DEBUG"; case GS_DECL_INLINE: return "GS_DECL_INLINE"; case GS_DECL_DECLARED_INLINE_P: return "GS_DECL_DECLARED_INLINE_P"; case GS_DECL_BUILT_IN: return "GS_DECL_BUILT_IN"; case GS_DECL_NO_STATIC_CHAIN: return "GS_DECL_NO_STATIC_CHAIN"; case GS_DECL_PACKED: return constructor == GS_FUNCTION_DECL ? "GS_DECL_REACHABLE" : "GS_DECL_PACKED"; case GS_DECL_BIT_FIELD: return "GS_DECL_BIT_FIELD"; case GS_DECL_NONADDRESSABLE_P: return "GS_DECL_NONADDRESSABLE_P"; case GS_DECL_EMITTED_BY_GXX: return "GS_DECL_EMITTED_BY_GXX"; case GS_DECL_IN_TEXT_SECTION: return "GS_DECL_IN_TEXT_SECTION"; case GS_DECL_THREAD_LOCAL: return "GS_DECL_THREAD_LOCAL"; case GS_DECL_TRANSPARENT_UNION: return "GS_DECL_TRANSPARENT_UNION"; case GS_DECL_VIRTUAL_P: return "GS_DECL_VIRTUAL_P"; case GS_DECL_DEFER_OUTPUT: return "GS_DECL_DEFER_OUTPUT"; case GS_DECL_PRESERVE_P: return "GS_DECL_PRESERVE_P"; case GS_DECL_LANG_FLAG_0: return "GS_DECL_LANG_FLAG_0"; case GS_DECL_LANG_FLAG_1: return "GS_DECL_LANG_FLAG_1"; case GS_DECL_LANG_FLAG_2: return "GS_DECL_LANG_FLAG_2"; case GS_DECL_LANG_FLAG_3: return "GS_DECL_LANG_FLAG_3"; case GS_DECL_LANG_FLAG_4: return "GS_DECL_LANG_FLAG_4"; case GS_DECL_LANG_FLAG_5: return "GS_DECL_LANG_FLAG_5"; case GS_DECL_LANG_FLAG_6: return "GS_DECL_LANG_FLAG_6"; case GS_DECL_LANG_FLAG_7: return "GS_DECL_LANG_FLAG_7"; case GS_DECL_USER_ALIGN: return "GS_DECL_USER_ALIGN"; case GS_DECL_OFFSET_ALIGN: return "GS_DECL_OFFSET_ALIGN"; case GS_DECL_POINTER_ALIAS_SET: return "GS_DECL_POINTER_ALIAS_SET"; case GS_DECL_THUNK_P: return "GS_DECL_THUNK_P"; case GS_DECL_ASSEMBLER_NAME_SET_P: return "GS_DECL_ASSEMBLER_NAME_SET_P"; case GS_DECL_ARTIFICIAL: return "GS_DECL_ARTIFICIAL"; case GS_DECL_LANG_SPECIFIC: return "GS_DECL_LANG_SPECIFIC"; case GS_DECL_THREADPRIVATE: return "GS_DECL_THREADPRIVATE"; default: GS_ASSERT(gs_false, ("gs_flag_name: missing flag name")); } } if (tree_code_class == GS_TCC_TYPE) { switch (flag) { case GS_TYPE_UNSIGNED: return "GS_TYPE_UNSIGNED"; case GS_TYPE_STRING_FLAG: return "GS_TYPE_STRING_FLAG"; case GS_TYPE_NEEDS_CONSTRUCTING: return "GS_TYPE_NEEDS_CONSTRUCTING"; case GS_TYPE_PACKED: return "GS_TYPE_PACKED"; case GS_TYPE_RESTRICT: return "GS_TYPE_RESTRICT"; case GS_TYPE_LANG_FLAG_0: return "GS_TYPE_LANG_FLAG_0"; case GS_TYPE_LANG_FLAG_1: return "GS_TYPE_LANG_FLAG_1"; case GS_TYPE_LANG_FLAG_2: return "GS_TYPE_LANG_FLAG_2"; case GS_TYPE_LANG_FLAG_3: return "GS_TYPE_LANG_FLAG_3"; case GS_TYPE_LANG_FLAG_4: return "GS_TYPE_LANG_FLAG_4"; case GS_TYPE_LANG_FLAG_5: return "GS_TYPE_LANG_FLAG_5"; case GS_TYPE_LANG_FLAG_6: return "GS_TYPE_LANG_FLAG_6"; case GS_TYPE_VOLATILE: return "GS_TYPE_VOLATILE"; case GS_TYPE_LANG_SPECIFIC: return "GS_TYPE_LANG_SPECIFIC"; case GS_POINTER_TYPE_P: return "GS_POINTER_TYPE_P"; case GS_AGGREGATE_VALUE_P: return "GS_AGGREGATE_VALUE_P"; } // Differentiate the GS_...'s that share the same numerical ID. if (flag == GS_TYPE_NO_FORCE_BLK) { switch (constructor) { case GS_RECORD_TYPE: case GS_UNION_TYPE: case GS_QUAL_UNION_TYPE: return "GS_TYPE_NO_FORCE_BLK"; case GS_INTEGER_TYPE: return "GS_TYPE_IS_SIZETYPE"; case GS_FUNCTION_TYPE: return "GS_TYPE_RETURNS_STACK_DEPRESSED"; default: GS_ASSERT(gs_false, ("gs_flag_name: bad constructor for GS_TYPE_NO_FORCE_BLK")); break; } } if (flag == GS_TYPE_TRANSPARENT_UNION) { if (constructor == GS_UNION_TYPE) return "GS_TYPE_TRANSPARENT_UNION"; else if (constructor == GS_ARRAY_TYPE) return "GS_TYPE_NONALIASED_COMPONENT"; else GS_ASSERT(gs_false, ("gs_flag_name: bad constructor for GS_TYPE_TRANSPARENT_UNION")); } GS_ASSERT(gs_false, ("gs_flag_name: missing flag name")); } // tree_code_class == GS_TCC_TYPE if (tree_code_class == GS_TCC_EXPRESSION || tree_code_class == GS_TCC_COMPARISON || tree_code_class == GS_TCC_UNARY || tree_code_class == GS_TCC_BINARY || tree_code_class == GS_TCC_REFERENCE || tree_code_class == GS_TCC_STATEMENT) { switch (flag) { case GS_BIT_FIELD_REF_UNSIGNED: return "GS_BIT_FIELD_REF_UNSIGNED"; case GS_EXPR_HAS_LOCATION: return "GS_EXPR_HAS_LOCATION"; case GS_EMIT_TARGET_EXPR_CLEANUP: GS_ASSERT(constructor == GS_TARGET_EXPR, ("gs_flag_name: unexpected flag GS_EMIT_TARGET_EXPR_CLEANUP")); return "GS_EMIT_TARGET_EXPR_CLEANUP"; default: GS_ASSERT(gs_false, ("gs_flag_name: missing flag name")); } } if (tree_code_class == GS_TCC_CONSTANT || tree_code_class == GS_TCC_EXCEPTIONAL) { if (constructor == GS_INTEGER_CST && flag == GS_TREE_CONSTANT_OVERFLOW) return "GS_TREE_CONSTANT_OVERFLOW"; if (constructor == GS_REAL_CST && flag == GS_TREE_OVERFLOW) return "GS_TREE_OVERFLOW"; switch (flag) { case GS_TREE_CONSTANT_OVERFLOW: if (constructor == GS_INTEGER_CST) return "GS_TREE_CONSTANT_OVERFLOW"; if (constructor == GS_TREE_BINFO) return "GS_BINFO_VIRTUAL_P"; GS_ASSERT(gs_false, ("gs_flag_name: missing flag name")); return "NONAME"; case GS_REAL_VALUE_ISINF: return "GS_REAL_VALUE_ISINF"; case GS_REAL_VALUE_ISNAN: return "GS_REAL_VALUE_ISNAN"; default: GS_ASSERT(gs_false, ("gs_flag_name: missing flag name")); } } } else if (attribute == GS_CP_DECL_FLAGS) { switch (flag) { case GS_DECL_COMDAT: return "GS_DECL_COMDAT"; case GS_DECL_GLOBAL_CTOR_P: return "GS_DECL_GLOBAL_CTOR_P"; case GS_DECL_GLOBAL_DTOR_P: return "GS_DECL_GLOBAL_DTOR_P"; case GS_DECL_ONE_ONLY: return "GS_DECL_ONE_ONLY"; case GS_DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P: return "GS_DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P"; case GS_DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P: return "GS_DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P"; case GS_DECL_FUNCTION_MEMBER_P: return "GS_DECL_FUNCTION_MEMBER_P"; case GS_DECL_USES_TEMPLATE_PARMS: return "GS_DECL_USES_TEMPLATE_PARMS"; case GS_DECL_COPY_CONSTRUCTOR_P: return "GS_DECL_COPY_CONSTRUCTOR_P"; case GS_DECL_IMPLICIT_INSTANTIATION: return "GS_DECL_IMPLICIT_INSTANTIATION"; case GS_DECL_NAMESPACE_SCOPE_P: return "GS_DECL_NAMESPACE_SCOPE_P"; case GS_DECL_COMPLETE_CONSTRUCTOR_P: return "GS_DECL_COMPLETE_CONSTRUCTOR_P"; case GS_DECL_REALLY_EXTERN: return "GS_DECL_REALLY_EXTERN"; case GS_DECL_USE_TEMPLATE: return "GS_DECL_USE_TEMPLATE"; case GS_DECL_TEMPLATE_INSTANTIATED: return "GS_DECL_TEMPLATE_INSTANTIATED"; case GS_DECL_TEMPLATE_SPECIALIZATION: return "GS_DECL_TEMPLATE_SPECIALIZATION"; case GS_DECL_PURE_VIRTUAL_P: return "GS_DECL_PURE_VIRTUAL_P"; case GS_DECL_THIS_THUNK_P: return "GS_DECL_THIS_THUNK_P"; case GS_DECL_EXTERN_C_P: return "GS_DECL_EXTERN_C_P"; default: GS_ASSERT(gs_false, ("gs_flag_name: missing flag name")); } } else if (attribute == GS_CP_TYPE_FLAGS) { switch (flag) { case GS_TYPE_PTRMEMFUNC_P: return "GS_TYPE_PTRMEMFUNC_P"; case GS_TYPE_PTRMEM_P: return "GS_TYPE_PTRMEM_P"; case GS_CLASSTYPE_INTERFACE_ONLY: return "GS_CLASSTYPE_INTERFACE_ONLY"; case GS_TYPE_USES_TEMPLATE_PARMS: return "GS_TYPE_USES_TEMPLATE_PARMS"; case GS_IS_EMPTY_CLASS: return "GS_IS_EMPTY_CLASS"; case GS_CLASS_TYPE_P: return "GS_CLASS_TYPE_P"; case GS_ANON_UNION_TYPE_P: return "GS_ANON_UNION_TYPE_P"; case GS_CLASSTYPE_TEMPLATE_SPECIALIZATION: return "GS_CLASSTYPE_TEMPLATE_SPECIALIZATION"; default: GS_ASSERT(gs_false, ("gs_flag_name: missing flag name")); } } else if (attribute == GS_CP_EXPR_FLAGS) { switch (flag) { case GS_STMT_IS_FULL_EXPR_P: return "GS_STMT_IS_FULL_EXPR_P"; case GS_AGGR_INIT_VIA_CTOR_P: return "GS_AGGR_INIT_VIA_CTOR_P"; case GS_CLEANUP_EH_ONLY: return "GS_CLEANUP_EH_ONLY"; default: GS_ASSERT(gs_false, ("gs_flag_name: missing flag name")); } } else if (attribute == GS_PROGRAM_FLAGS) { switch (flag) { case GS_FLAG_ERRNO_MATH: return "GS_FLAG_ERRNO_MATH"; case GS_PRAGMA_IMPLEMENTATION: return "GS_PRAGMA_IMPLEMENTATION"; case GS_PRAGMA_INTERFACE: return "GS_PRAGMA_INTERFACE"; default: GS_ASSERT(gs_false, ("gs_flag_name: missing flag name")); } } return (gs_string_t) "FLAG_NONAME"; } static inline gs_t gs_build_0(gs_tree_code_class_t code_class, gs_code_t code) { gs_t root = __gs(code); gs_t code_class_node = __gs(GS_TCC); _gs_b(code_class_node, code_class); gs_set_operand(root, 0, code_class_node); gs_set_operand(root, GS_FLAGS, __gs(IB_BIT_VECTOR)); return root; } gs_t gs_build_type(gs_code_t code) { gs_t root = gs_build_0(GS_TCC_TYPE, code); return root; } gs_t gs_build_if_stmt(gs_t k0, gs_t k1, gs_t k2) { gs_t root = __gs(GS_IF_STMT); // Argument 0 is the name of the class: gs_t code_class_node = __gs(GS_TCC); _gs_b(code_class_node, GS_TCC_STATEMENT); gs_set_operand(root, 0, code_class_node); gs_set_operand(root, GS_TREE_OPERAND_ZERO, k0); gs_set_operand(root, GS_TREE_OPERAND_ZERO+1, k1); gs_set_operand(root, GS_TREE_OPERAND_ZERO+2, k2); return root; } gs_t gs_build_target_expr(gs_t k0, gs_t k1, gs_t k2, gs_t k3) { gs_t res = __gs(GS_TARGET_EXPR); // Argument 0 is the name of the class: gs_t code_class_node = __gs(GS_TCC); _gs_b(code_class_node, GS_TCC_EXPRESSION); gs_set_operand(res, 0, code_class_node); gs_set_operand(res, GS_FLAGS, __gs(IB_BIT_VECTOR)); gs_set_operand(res, GS_TREE_OPERAND_ZERO, k0); gs_set_operand(res, GS_TREE_OPERAND_ZERO+1, k1); gs_set_operand(res, GS_TREE_OPERAND_ZERO+2, k2); gs_set_operand(res, GS_TREE_OPERAND_ZERO+3, k3); return res; } gs_t gs_build_int_cst(gs_long_long_t n) { gs_t cst = __gs(GS_INTEGER_CST); // Argument 0 is the name of the class: gs_t code_class_node = __gs(GS_TCC); _gs_b(code_class_node, GS_TCC_CONSTANT); gs_set_operand(cst, 0, code_class_node); // Add type. gs_t gs_integer_type = gs_integer_type_node(); gs_set_operand(cst, GS_TREE_TYPE, gs_integer_type); gs_t low = __gs(IB_UNSIGNED_LONG_LONG); gs_t high = __gs(IB_LONG_LONG); _gs_ull(low, n); _gs_ll(high, n < 0 ? -1 : 0); gs_set_operand(cst, GS_TREE_INT_CST_LOW, low); gs_set_operand(cst, GS_TREE_INT_CST_HIGH, high); gs_set_operand(cst, GS_FLAGS, __gs(IB_BIT_VECTOR)); return cst; } gs_t gs_build_decl(gs_code_t code, gs_t node2) { gs_t res = __gs (code); // Argument 0 is the name of the class: gs_t code_class = __gs (GS_TCC); _gs_b (code_class, GS_TCC_DECLARATION); gs_set_operand(res, 0, code_class); // TREE_TYPE gs_set_operand(res, GS_TREE_TYPE, node2); // DECL_NAME gs_set_operand(res, GS_DECL_NAME, NULL); gs_set_operand(res, GS_FLAGS, __gs (IB_BIT_VECTOR)); return res; } static inline gs_t gs_build_2(gs_tree_code_class_t code_class, gs_code_t code, gs_t k0, gs_t k1) { gs_t root = gs_build_0(code_class, code); gs_set_operand(root, GS_TREE_OPERAND_ZERO, k0); gs_set_operand(root, GS_TREE_OPERAND_ZERO + 1, k1); return root; } static inline gs_t gs_build_comparison(gs_code_t code, gs_t k0, gs_t k1) { gs_t gs_integer_type = gs_integer_type_node(); gs_t expr = gs_build_2(GS_TCC_COMPARISON, GS_NE_EXPR, k0, k1); gs_set_operand(expr, GS_TREE_TYPE, gs_integer_type); return expr; } gs_t gs_c_common_truthvalue_conversion(gs_t node) { gs_t zero = gs_build_int_cst(0); gs_t expr = gs_build_comparison(GS_NE_EXPR, node, zero); return expr; } gs_t gs_strip_nops(gs_t node) { gs_t opnd0; gs_t error_mark_node = gs_error_mark_node(); gs_code_t code = gs_tree_code(node); while ((code == GS_NOP_EXPR || code == GS_CONVERT_EXPR || code == GS_NON_LVALUE_EXPR) && (opnd0 = gs_tree_operand(node, 0)) != error_mark_node && !strcmp(gs_type_mode(gs_tree_type(node)), gs_type_mode(gs_tree_type(opnd0)))) { node = opnd0; code = gs_tree_code(node); } return node; } // Perform the function of GCC tree.c's build_pointer_type. gs_t gs_build_pointer_type(gs_t to_type) { gs_t t, type_pointer_to; gs_t error_mark_node = gs_error_mark_node(); gs_t ptr_type = gs_ptr_type_node(); gs_string_t ptr_type_mode = gs_type_mode(ptr_type); if (to_type == error_mark_node) return error_mark_node; // GCC returns NODE if the pointer_to type is not POINTER_TYPE. This case // does not occur in C/C++, type_pointer_to = gs_type_pointer_to(to_type); GS_ASSERT(!(type_pointer_to != NULL && gs_tree_code(type_pointer_to) != GS_POINTER_TYPE), ("gs_build_pointer_type: TYPE_POINTER_TO is not POINTER_TYPE")); for (t = type_pointer_to; t != NULL; t = gs_type_next_ptr_to(t)) { gs_string_t mode = gs_type_mode(t); if (!strcmp(mode, ptr_type_mode) && gs_type_ref_can_alias_all(t) == 0) { return t; } } t = gs_build_type(GS_POINTER_TYPE); gs_set_operand(t, GS_TREE_TYPE, to_type); gs_set_operand(t, GS_TYPE_MODE, ptr_type); gs_set_type_ref_can_alias_all(t, 0); gs_set_operand(t, GS_TYPE_NEXT_PTR_TO, to_type); gs_set_operand(to_type, GS_TYPE_POINTER_TO, t); // Copy pointer attributes from the generic pointer. { gs_t type_precision = __gs(IB_INT); gs_set_operand(t, GS_TYPE_SIZE, gs_operand(ptr_type, GS_TYPE_SIZE)); gs_set_operand(t, GS_TYPE_SIZE_UNIT, gs_operand(ptr_type, GS_TYPE_SIZE_UNIT)); gs_set_operand(t, GS_TYPE_ALIGN, gs_operand(ptr_type, GS_TYPE_ALIGN)); gs_set_type_unsigned(t, 1); _gs_n(type_precision, gs_type_type_precision(ptr_type)); gs_set_operand(t, GS_TYPE_PRECISION, type_precision); } return t; }
722,025
./hicuda/src/libspin/gspin-alloc.c
/* Copyright (C) 2006. QLogic Corporation. All Rights Reserved. Copyright 2006 PathScale, Inc. All Rights Reserved. This program is free software; you can redistribute it and/or modify it under the terms of version 2 of the GNU General Public License as published by the Free Software Foundation. This program is distributed in the hope that it would be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Further, this software is distributed without any warranty that it is free of the rightful claim of any third person regarding infringement or the like. Any license provided herein, whether implied or otherwise, applies only to this software file. Patent licenses, if any, provided herein do not apply to combinations of this program with other software, or any other product whatsoever. You should have received a copy of the GNU General Public License along with this program; if not, write the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA. */ #include <stdio.h> #include <stdlib.h> //////////////////////////////////////////////////////////////////////////////// // // Wrappers around calloc (3) and free (3): // //////////////////////////////////////////////////////////////////////////////// void *gs_alloc (size_t nmemb, size_t size) { void *p = NULL; p = calloc (nmemb, size); if (p == NULL) fprintf (stderr, "Out of memory.\n"); return p; }
722,026
./hicuda/regression/HTF/009/func2.c
#include <stdio.h> #include "data.h" void func2(s_node* nodes, s_disp* disps, s_element* elements, s_node_disp* node_disps) { }
722,027
./hicuda/regression/HTF/009/func1.c
#include <stdio.h> #include "data.h" void func1(s_node_disp *node_disps, s_element *elements, unsigned char *mask) { }
722,028
./hicuda/regression/HTF/009/HTF009.c
/***************************************************************************** * * This program consists of multiple files, which share a header file that * defines multiple structs. The hiCUDA compiler should always generate * correct code regardless of the order of files put in the command line. * * Here, correctness means that the unamed struct types must be given unique * names. * ****************************************************************************/ #include "HTF009.h" int main (int argc, char * argv[]) { s_node* nodes; s_disp* disps; s_node_disp* node_disps; s_element* elements; unsigned char *mask; func1(node_disps, elements, mask); func2(nodes, disps, elements, node_disps); return 0; }
722,029
./hicuda/regression/HTF/008/HTF008.c
/***************************************************************************** * * Test the code generation of various standard C (or C99) functions, when the * standard headers are not included directly in the source file. * ****************************************************************************/ #include "HTF008.h" int main(int argc, char **argv) { int src, dest; sscanf(argv[0], "%d", &src); printf("Hello world!\n"); fprintf(stderr, "Hello world!\n"); memcpy(&dest, &src, 4); // fscanf FILE *fin = fopen("test.txt", "r"); if (fin != NULL) { float x,y; if (fscanf(fin, "%f %f", &x, &y) == 2) { printf("%f %f", x, y); } fclose(fin); fin = NULL; } // malloc int *tmp = (int*)malloc(5 * sizeof(int)); free(tmp); tmp = NULL; return 0; }
722,030
./hicuda/regression/HTF/010/HTF010.c
/***************************************************************************** * * This program tests proper type cast for function arguments. * ****************************************************************************/ struct atom_t { char type[1]; float x, y; }; int main (int argc, char * argv[]) { struct atom_t atom; char type[8]; if (strcmp(atom.type, type) == 0) return 1; return 0; }
722,031
./hicuda/regression/HTF/016/HTF016.c
////////////////////////////////////////////////////////////////////////////// // // This program tests the use of a NULL pointer in various forms. // ////////////////////////////////////////////////////////////////////////////// #include <stdlib.h> #include <sys/time.h> struct timeval gtv; int main(int argc, char **argv) { struct timeval ltv; gettimeofday(&ltv, NULL); gettimeofday(&ltv, (void*)0); gettimeofday(&ltv, 0); gettimeofday(&gtv, NULL); gettimeofday(&gtv, (void*)0); gettimeofday(&gtv, 0); return 0; }
722,032
./hicuda/regression/HTF/014/HTF014.c
////////////////////////////////////////////////////////////////////////////// // // This program tests if the program does not have a main function. // // Given that an argument -e main1 is passed to hicuda, the compiler should // treat it as the entry point and retain it in the generated code. // ////////////////////////////////////////////////////////////////////////////// #include <stdlib.h> #include <sys/time.h> struct timeval gtv; int main1(int argc, char **argv) { struct timeval ltv; gettimeofday(&ltv, NULL); gettimeofday(&gtv, NULL); return 0; }
722,033
./hicuda/regression/HTF/007/HTF007.c
/***************************************************************************** * * Test the code generation of array initializer. * ****************************************************************************/ #include <stdio.h> int main(int argc, char **argv) { float* arr[3] = {NULL, NULL, NULL}; arr[2] = (float*)1; printf("%x, %x, %x\n", arr[0], arr[1], arr[2]); return 0; }
722,034
./hicuda/regression/HTF/003/HTF003.c
/***************************************************************************** * * Test the code generation of various standard C (or C99) functions. * ****************************************************************************/ #include <stdio.h> #include <string.h> #include <unistd.h> int main(int argc, char **argv) { int src, dest; sscanf(argv[0], "%d", &src); printf("Hello world!\n"); fprintf(stderr, "Hello world!\n"); memcpy(&dest, &src, 4); // fscanf FILE *fin = fopen("test.txt", "r"); if (fin != NULL) { float x,y; if (fscanf(fin, "%f %f", &x, &y) == 2) { printf("%f %f", x, y); } fclose(fin); fin = NULL; } // getopt int c; while ((c = getopt(argc, argv, "a:b:c:d")) != EOF) { switch(c) { case 'a': printf("a"); break; } } return 0; }
722,035
./hicuda/regression/HTF/005/HTF005.c
/***************************************************************************** * * This program tests the generation of complex array accesses. * * Issues to be resolved: * * - elems[i].nodes[j] is not generated as an array access on a 64-bit * machine. The reason is that Fold_Base exits early due to the mismatch of * the array base type (U8) and the array index type (I4). * * - Somehow adding the line of elems[i].nodes[j] alters the generated code * for the access a[i][j][k], to a[(int)i][j][k]. Although this does not * affect correctness, it is probably worthwhile to know why. * ****************************************************************************/ struct elem_t { int nodes[4]; }; int main(int argc, char **argv) { int a[5][6][7]; int t[5][6]; struct elem_t *elems; int i,j,k; int x, b; int (*p)[6][7]; // int c[i][6][k]; x = elems[i].nodes[j]; b = x + a[i][j][k]; a[j][k+1][i] = 1 + b; b = t[j][k]; p = &a[1]; b += (*p)[j][k]; b += p[i][j][k]; return b; }
722,036
./hicuda/regression/HTF/001/HTF001.c
#include <stdio.h> #define A_SIZE 1024 #define N_BLOCKS 4 #define N_THREADS 256 int main() { int i; float A[A_SIZE]; #pragma hicuda global alloc A[0:A_SIZE-1] copyin #pragma hicuda kernel zero tblock(N_BLOCKS) thread(N_THREADS) #pragma hicuda loop_partition over_tblock over_thread for (i = 0; i < A_SIZE; ++i) { A[i] = i; } #pragma hicuda global copyout A[*] #pragma hicuda global free A return 0; }
722,037
./hicuda/regression/HTF/013/HTF013.c
////////////////////////////////////////////////////////////////////////////// // // This program tests the declaration of a global struct timeval variable. // ////////////////////////////////////////////////////////////////////////////// #include <stdlib.h> #include <sys/time.h> struct timeval gtv; int main(int argc, char **argv) { struct timeval ltv; gettimeofday(&ltv, NULL); gettimeofday(&gtv, NULL); return 0; }
722,038
./hicuda/regression/HTF/004/HTF004.c
/***************************************************************************** * * Stress test for the code generator * ****************************************************************************/ #include <stdlib.h> #include <math.h> #include <stdio.h> /* * (c) 2007 The Board of Trustees of the University of Illinois. */ #ifdef __cplusplus extern "C" { #endif #include <unistd.h> /* Command line parameters for benchmarks */ struct pb_Parameters { char *outFile; /* If not NULL, the raw output of the * computation should be saved to this * file. The string is owned. */ char **inpFiles; /* A NULL-terminated array of strings * holding the input file(s) for the * computation. The array and strings * are owned. */ int synchronizeGpu; /* Controls behavior of CUDA benchmarks. * If nonzero, a CUDA runtime * synchronization call should happen * after each data transfer to the GPU * and after each kernel call. This * is necessary for accurate timing * measurement. */ }; /* Read command-line parameters. * * The argc and argv parameters to main are read, and any parameters * interpreted by this function are removed from the argument list. * * A new instance of struct pb_Parameters is returned. * If there is an error, then an error message is printed on stderr * and NULL is returned. */ struct pb_Parameters * pb_ReadParameters(int *_argc, char **argv); /* Free an instance of struct pb_Parameters. */ void pb_FreeParameters(struct pb_Parameters *p); /* Count the number of input files in a pb_Parameters instance. */ int pb_Parameters_CountInputs(struct pb_Parameters *p); /* A time or duration. */ #if _POSIX_VERSION >= 200112L typedef unsigned long long pb_Timestamp; /* time in microseconds */ #else # error "Timestamps not implemented" #endif enum pb_TimerState { pb_Timer_STOPPED, pb_Timer_RUNNING, }; struct pb_Timer { enum pb_TimerState state; pb_Timestamp elapsed; /* Amount of time elapsed so far */ pb_Timestamp init; /* Beginning of the current time interval, * if state is RUNNING. Undefined * otherwise. */ }; /* Reset a timer. * Use this to initialize a timer or to clear * its elapsed time. The reset timer is stopped. */ void pb_ResetTimer(struct pb_Timer *timer); /* Start a timer. The timer is set to RUNNING mode and * time elapsed while the timer is running is added to * the timer. * The timer should not already be running. */ void pb_StartTimer(struct pb_Timer *timer); /* Stop a timer. * This stops adding elapsed time to the timer. * The timer should not already be stopped. */ void pb_StopTimer(struct pb_Timer *timer); /* Get the elapsed time in seconds. */ double pb_GetElapsedTime(struct pb_Timer *timer); /* Execution time is assigned to one of these categories. */ enum pb_TimerID { pb_TimerID_NONE = 0, pb_TimerID_IO, /* Time spent in input/output */ pb_TimerID_GPU, /* Time spent computing on the GPU */ pb_TimerID_COPY, /* Time spent moving data to/from GPU and * allocating/freeing memory on the GPU */ pb_TimerID_COMPUTE, /* Time for all program execution other * than parsing command line arguments, * I/O, GPU, and copy */ pb_TimerID_LAST /* Number of timer IDs */ }; /* A set of timers for recording execution times. */ struct pb_TimerSet { enum pb_TimerID current; struct pb_Timer timers[pb_TimerID_LAST]; }; /* Reset all timers in the set. */ void pb_InitializeTimerSet(struct pb_TimerSet *timers); /* Select which timer the next interval of time should be accounted * to. The selected timer is started and other timers are stopped. * Using pb_TimerID_NONE stops all timers. */ void pb_SwitchToTimer(struct pb_TimerSet *timers, enum pb_TimerID timer); /* Print timer values to standard output. */ void pb_PrintTimerSet(struct pb_TimerSet *timers); #ifdef __cplusplus } #endif #define VOLSIZEX 512 #define VOLSIZEY 512 #define ATOMCOUNT 40000 #define MAX_ATOMS 1024 /* Size of a thread block */ #define BLOCKSIZEX 16 #define BLOCKSIZEY 8 /* Number of grid points processed by a thread */ #define UNROLLX 1 /* Number of atoms processed by a kernel */ #define MAXATOMS 4000 typedef struct { int x; int y; int z; } voldim3i; /* The main compute kernel. */ void cpuenergy(voldim3i grid, int numatoms, float gridspacing, int k, const float *atoms, float *energygrid); void cpuenergy(voldim3i grid, int numatoms, float gridspacing, int k, const float *atoms, float *energygrid) { float energy; /* Energy of current grid point */ float x,y,z; /* Coordinates of current grid point */ int i,j,n; /* Loop counters */ int atomarrdim = numatoms * 4; float atominfo[MAX_ATOMS]; //int UNROLLX = 1; //dim3 Gsz, Bsz; // printf("\tWorking on plane %i of %ld\n", k, grid.z); z = gridspacing * (float) k; #pragma hicuda constant copyin atominfo[*] int energygrid_sz = grid.x * grid.y * grid.z; #pragma hicuda shape energygrid[energygrid_sz] #pragma hicuda shape atoms[MAX_ATOMS] #pragma hicuda global alloc numatoms copyin #pragma hicuda global alloc gridspacing copyin #pragma hicuda global alloc energygrid[*] copyin #pragma hicuda global alloc atoms[*] copyin //int Gsz_x = grid.x / (BLOCKSIZEX * UNROLLX); //int Gsz_y = grid.y / (BLOCKSIZEY * UNROLLX); //int Gsz_z = grid.z / (1* UNROLLX); int nn; for (nn=0; nn < atomarrdim; nn += 4*MAX_ATOMS) { #pragma hicuda kernel addVector tblock(64, 32) thread(8, 16) //#pragma hicuda kernel addVector tblock(Gsz_z, Gsz_y, Gsz_x) thread(16) #pragma hicuda loop_partition over_tblock over_thread /* For each x, y grid point in this plane */ for (j=0; j<grid.y; j++) { y = gridspacing * (float) j; #pragma hicuda loop_partition over_tblock over_thread for (i=0; i<grid.x; i++) { x = gridspacing * (float) i; energy = 0.0f; /* help the vectorizer make the right decision */ #if defined(__INTEL_COMPILER) #pragma vector always #endif //#pragma hicuda loop_partition over_tblock over_thread /* Calculate the interaction with each atom */ for (n=nn; n< nn+4*MAX_ATOMS; n+=4) { float dx = x - atoms[n ]; float dy = y - atoms[n+1]; float dz = z - atoms[n+2]; energy += atoms[n+3] / sqrtf(dx*dx + dy*dy + dz*dz); } energygrid[grid.x*grid.y*k + grid.x*j + i] = energy; } } #pragma hicuda kernel_end } #pragma hicuda global copyout energygrid[*] } /* initatoms() * Store a pseudorandom arrangement of point charges in *atombuf. */ static int initatoms(float **atombuf, int count, voldim3i volsize, float gridspacing) { voldim3i size; int i; float *atoms; srand(54321); // Ensure that atom placement is repeatable atoms = (float *) malloc(count * 4 * sizeof(float)); *atombuf = atoms; // compute grid dimensions in angstroms size.x = gridspacing * volsize.x; size.y = gridspacing * volsize.y; size.z = gridspacing * volsize.z; for (i=0; i<count; i++) { int addr = i * 4; atoms[addr ] = (rand() / (float) RAND_MAX) * size.x; atoms[addr + 1] = (rand() / (float) RAND_MAX) * size.y; atoms[addr + 2] = (rand() / (float) RAND_MAX) * size.z; atoms[addr + 3] = ((rand() / (float) RAND_MAX) * 2.0) - 1.0; // charge } return 0; } /* writeenergy() * Write part of the energy array to an output file for verification. */ static int writeenergy(char *filename, float *energy, voldim3i volsize) { FILE *outfile; int x, y; outfile = fopen(filename, "w"); if (outfile == NULL) { fputs("Cannot open output file\n", stderr); return -1; } /* Print the execution parameters */ fprintf(outfile, "%d %d %d %d\n", volsize.x, volsize.y, volsize.z, ATOMCOUNT); /* Print a checksum */ { double sum = 0.0; for (y = 0; y < volsize.y; y++) { for (x = 0; x < volsize.x; x++) { double t = energy[y*volsize.x+x]; t = fmax(-20.0, fmin(20.0, t)); sum += t; } } fprintf(outfile, "%.4g\n", sum); } /* Print several rows of the computed data */ for (y = 0; y < 17; y++) { for (x = 0; x < volsize.x; x++) { int addr = y * volsize.x + x; fprintf(outfile, "%.4g ", energy[addr]); } fprintf(outfile, "\n"); } fclose(outfile); return 0; } int main(int argc, char** argv) { struct pb_TimerSet timers; struct pb_Parameters *parameters; float *energy = NULL; // Output of calculation float *atoms = NULL; voldim3i volsize; // number of atoms to simulate int atomcount = ATOMCOUNT; // voxel spacing const float gridspacing = 0.1; // Size of buffer on GPU int volmemsz; printf("CUDA accelerated coulombic potential microbenchmark\n"); printf("Original version by John E. Stone <johns@ks.uiuc.edu>\n"); printf("This version maintained by Chris Rodrigues\n"); parameters = pb_ReadParameters(&argc, argv); if (!parameters) return -1; if (parameters->inpFiles[0]) { fputs("No input files expected\n", stderr); return -1; } pb_InitializeTimerSet(&timers); pb_SwitchToTimer(&timers, pb_TimerID_COMPUTE); // setup energy grid size volsize.x = VOLSIZEX; volsize.y = VOLSIZEY; volsize.z = 1; // allocate and initialize atom coordinates and charges if (initatoms(&atoms, atomcount, volsize, gridspacing)) return -1; // allocate the output array volmemsz = sizeof(float) * volsize.x * volsize.y * volsize.z; energy = (float *) malloc(volmemsz); // Main computation cpuenergy(volsize, atomcount, gridspacing, 0, atoms, energy); #if 0 printf("Done\n"); #endif pb_SwitchToTimer(&timers, pb_TimerID_IO); /* Print a subset of the results to a file */ if (parameters->outFile) { if (writeenergy(parameters->outFile, energy, volsize) == -1) return -1; } pb_SwitchToTimer(&timers, pb_TimerID_COMPUTE); free(atoms); free(energy); pb_SwitchToTimer(&timers, pb_TimerID_NONE); pb_PrintTimerSet(&timers); pb_FreeParameters(parameters); return 0; } /* * (c) 2007 The Board of Trustees of the University of Illinois. */ #include <stdlib.h> #include <string.h> #include <stdio.h> #if _POSIX_VERSION >= 200112L #include <sys/time.h> #endif /* Free an array of owned strings. */ static void free_string_array(char **string_array) { char **p; if (!string_array) return; for (p = string_array; *p; p++) free(*p); free(string_array); } /* Parse a comma-delimited list of strings into an * array of strings. */ static char ** read_string_array(char *in) { char **ret; int i; int count; /* Number of items in the input */ char *substring; /* Current substring within 'in' */ /* Count the number of items in the string */ count = 1; for (i = 0; in[i]; i++) if (in[i] == ',') count++; /* Allocate storage */ ret = malloc((count + 1) * sizeof(char *)); /* Create copies of the strings from the list */ substring = in; for (i = 0; i < count; i++) { char *substring_end; int substring_length; /* Find length of substring */ for (substring_end = substring; (*substring_end != ',') && (*substring_end != 0); substring_end++); substring_length = substring_end - substring; /* Allocate memory and copy the substring */ ret[i] = malloc(substring_length + 1); memcpy(ret[i], substring, substring_length); ret[i][substring_length] = 0; /* go to next substring */ substring = substring_end + 1; } ret[i] = NULL; /* Write the sentinel value */ return ret; } struct argparse { int argc; /* Number of arguments. Mutable. */ char **argv; /* Argument values. Immutable. */ int argn; /* Current argument number. */ char **argv_get; /* Argument value being read. */ char **argv_put; /* Argument value being written. * argv_put <= argv_get. */ }; static void initialize_argparse(struct argparse *ap, int argc, char **argv) { ap->argc = argc; ap->argn = 0; ap->argv_get = ap->argv_put = ap->argv = argv; } static void finalize_argparse(struct argparse *ap) { /* Move the remaining arguments */ for(; ap->argn < ap->argc; ap->argn++) *ap->argv_put++ = *ap->argv_get++; } /* Delete the current argument. */ static void delete_argument(struct argparse *ap) { if (ap->argn >= ap->argc) { fprintf(stderr, "delete_argument\n"); } ap->argc--; ap->argv_get++; } /* Go to the next argument. Also, move the current argument to its * final location in argv. */ static void next_argument(struct argparse *ap) { if (ap->argn >= ap->argc) { fprintf(stderr, "next_argument\n"); } /* Move argument to its new location. */ *ap->argv_put++ = *ap->argv_get++; ap->argn++; } static int is_end_of_arguments(struct argparse *ap) { return ap->argn == ap->argc; } static char * get_argument(struct argparse *ap) { return *ap->argv_get; } static char * consume_argument(struct argparse *ap) { char *ret = get_argument(ap); delete_argument(ap); return ret; } struct pb_Parameters * pb_ReadParameters(int *_argc, char **argv) { char *err_message; struct argparse ap; struct pb_Parameters *ret = malloc(sizeof(struct pb_Parameters)); /* Initialize the parameters structure */ ret->outFile = NULL; ret->inpFiles = malloc(sizeof(char *)); ret->inpFiles[0] = NULL; ret->synchronizeGpu = 0; /* Each argument */ initialize_argparse(&ap, *_argc, argv); while(!is_end_of_arguments(&ap)) { char *arg = get_argument(&ap); /* Single-character flag */ if ((arg[0] == '-') && (arg[1] != 0) && (arg[2] == 0)) { delete_argument(&ap); /* This argument is consumed here */ switch(arg[1]) { case 'o': /* Output file name */ if (is_end_of_arguments(&ap)) { err_message = "Expecting file name after '-o'\n"; goto error; } free(ret->outFile); ret->outFile = strdup(consume_argument(&ap)); break; case 'i': /* Input file name */ if (is_end_of_arguments(&ap)) { err_message = "Expecting file name after '-i'\n"; goto error; } ret->inpFiles = read_string_array(consume_argument(&ap)); break; case 'S': /* Synchronize */ ret->synchronizeGpu = 1; break; case '-': /* End of options */ goto end_of_options; default: err_message = "Unexpected command-line parameter\n"; goto error; } } else { /* Other parameters are ignored */ next_argument(&ap); } } /* end for each argument */ end_of_options: *_argc = ap.argc; /* Save the modified argc value */ finalize_argparse(&ap); return ret; error: fputs(err_message, stderr); pb_FreeParameters(ret); return NULL; } void pb_FreeParameters(struct pb_Parameters *p) { char **cpp; free(p->outFile); free_string_array(p->inpFiles); free(p); } int pb_Parameters_CountInputs(struct pb_Parameters *p) { int n; for (n = 0; p->inpFiles[n]; n++); return n; } /*****************************************************************************/ /* Timer routines */ static void accumulate_time(pb_Timestamp *accum, pb_Timestamp start, pb_Timestamp end) { #if _POSIX_VERSION >= 200112L *accum += end - start; #else # error "Timestamps not implemented for this system" #endif } void pb_ResetTimer(struct pb_Timer *timer) { timer->state = pb_Timer_STOPPED; #if _POSIX_VERSION >= 200112L timer->elapsed = 0; #else # error "pb_ResetTimer: not implemented for this system" #endif } void pb_StartTimer(struct pb_Timer *timer) { if (timer->state != pb_Timer_STOPPED) { fputs("Ignoring attempt to start a running timer\n", stderr); return; } timer->state = pb_Timer_RUNNING; #if _POSIX_VERSION >= 200112L { struct timeval tv; gettimeofday(&tv, NULL); timer->init = tv.tv_sec * 1000000LL + tv.tv_usec; } #else # error "pb_StartTimer: not implemented for this system" #endif } void pb_StopTimer(struct pb_Timer *timer) { pb_Timestamp fini; if (timer->state != pb_Timer_RUNNING) { fputs("Ignoring attempt to stop a stopped timer\n", stderr); return; } timer->state = pb_Timer_STOPPED; #if _POSIX_VERSION >= 200112L { struct timeval tv; gettimeofday(&tv, NULL); fini = tv.tv_sec * 1000000LL + tv.tv_usec; } #else # error "pb_StopTimer: not implemented for this system" #endif accumulate_time(&timer->elapsed, timer->init, fini); } /* Get the elapsed time in seconds. */ double pb_GetElapsedTime(struct pb_Timer *timer) { double ret; if (timer->state != pb_Timer_STOPPED) { fputs("Elapsed time from a running timer is inaccurate\n", stderr); } #if _POSIX_VERSION >= 200112L ret = timer->elapsed / 1e6; #else # error "pb_GetElapsedTime: not implemented for this system" #endif return ret; } void pb_InitializeTimerSet(struct pb_TimerSet *timers) { int n; timers->current = pb_TimerID_NONE; for (n = 0; n < pb_TimerID_LAST; n++) pb_ResetTimer(&timers->timers[n]); } void pb_SwitchToTimer(struct pb_TimerSet *timers, enum pb_TimerID timer) { /* Stop the currently running timer */ if (timers->current != pb_TimerID_NONE) pb_StopTimer(&timers->timers[timers->current]); timers->current = timer; /* Start the new timer */ if (timer != pb_TimerID_NONE) pb_StartTimer(&timers->timers[timer]); } void pb_PrintTimerSet(struct pb_TimerSet *timers) { struct pb_Timer *t = timers->timers; double time, totTime; time = pb_GetElapsedTime(&t[pb_TimerID_IO]); totTime = time; printf("IO: %f\n", time); time = pb_GetElapsedTime(&t[pb_TimerID_GPU]); totTime += time; printf("GPU: %f\n", time); time = pb_GetElapsedTime(&t[pb_TimerID_COPY]); totTime += time; printf("Copy: %f\n", time); time = pb_GetElapsedTime(&t[pb_TimerID_COMPUTE]); totTime += time; printf("Compute: %f\n", time); printf("Total: %f\n", totTime); }
722,039
./hicuda/regression/HTF/006/HTF006.c
/***************************************************************************** * * Test the code generation for function declarations that are almost the same * as standard C functions. * ****************************************************************************/ #include <stdio.h> extern int printf1 (__const char *__restrict __format, ...); extern char func(__const char *__restrict p_c, const char c, ...) { return p_c[0] + c + 1; } int main(int argc, char **argv) { char c; c = '1'; c = func(&c, c); printf1("%d\n", (int)c); printf("%d\n", (int)c); return (int)c; }
722,040
./hicuda/regression/HTF/015/HTF015.c
////////////////////////////////////////////////////////////////////////////// // // This program tests if the program does not have a main function and the // program has a kernel so that the OpenCL backend needs to generate a clInit // call. // // In the generated code, dllinit should call clInit if -e dllinit is passed // to the hicuda compiler. // ////////////////////////////////////////////////////////////////////////////// #include <stdlib.h> #include <stdio.h> #include <sys/time.h> #include <time.h> #include "common.h" #define WA 1024 // width of matrix A #define HA 1024 // height of matrix A #define WB 1024 // width of matrix B #define TILE_SZ 16 void dllinit() { } void matrixMul_host(float *A, float *B, float *C, float *reference) { int i, j, k, kk; #pragma hicuda shape A[HA][WA] B[WA][WB] C[HA][WB] #pragma hicuda global alloc A[*][*] copyin #pragma hicuda global alloc B[*][*] copyin #pragma hicuda global alloc C[*][*] // Record the start time. struct timeval start_time; gettimeofday(&start_time, NULL); // C = A * B #pragma hicuda kernel matrixMul tblock(64,64) thread(16,16) #pragma hicuda loop_partition over_tblock over_thread for (i = 0; i < HA; ++i) { #pragma hicuda loop_partition over_tblock over_thread for (j = 0; j < WB; ++j) { float sum = 0; for (kk = 0; kk < WA; kk += TILE_SZ) { #pragma hicuda shared alloc A[i][kk:kk+15] copyin #pragma hicuda shared alloc B[kk:kk+15][j] copyin #pragma hicuda barrier for (k = 0; k < TILE_SZ; ++k) { sum += A[i*WA+(kk+k)] * B[(kk+k)*WB+j]; } #pragma hicuda barrier #pragma hicuda shared remove A B } C[i*WB+j] = sum; } } #pragma hicuda kernel_end #pragma hicuda global copyout C[*][*] #pragma hicuda global free A B C // Record the end time. struct timeval end_time; gettimeofday(&end_time, NULL); printf("Time elapsed: %6f ms\n", get_time_diff(&start_time, &end_time)); // Compute reference solution. computeGold((float*)reference, (float*)A, (float*)B, HA, WA, WB); // Check result. compare_matrices((float*)C, (float*)reference, HA*WB); }
722,041
./hicuda/regression/HTF/002/HTF002.c
/***************************************************************************** * * This program tests the generation of the struct in the header file. * It should contain all the fields (as opposed to "filler"s). * ****************************************************************************/ #include <stdlib.h> typedef unsigned long long pb_Timestamp; struct pb_Timer { pb_Timestamp init; pb_Timestamp elapsed; }; int main(int argc, char ** argv) { struct pb_Timer timer; timer.init = atoi(argv[0]); timer.elapsed = atoi(argv[1]); return (timer.init + timer.elapsed); }
722,042
./hicuda/regression/HTD/009/HTD009.c
int bar(int x) { return x + 1; } void foo(int (*a)[10]) { (*a)[9] = bar((*a)[9]); } int main(int argc, char **argv) { int arr[10]; int lbnd = argc; if (lbnd < 0) lbnd = 0; if (lbnd > 9) lbnd = 9; #pragma hicuda global alloc arr[lbnd:9] foo(arr); #pragma hicuda kernel k_test tblock(2) thread(4) foo(arr); #pragma hicuda kernel_end #pragma hicuda global copyout arr[lbnd:9] #pragma hicuda global free arr return 0; }
722,043
./hicuda/regression/HTD/008/HTD008.c
#include <stdlib.h> float glob_arr[10]; void bar(float (*arr)[10]) { (*arr)[9] = 0; } void foo(float (*arr)[10], int lbnd) { int i; for (i = lbnd; i < 10; ++i) glob_arr[i] += (*arr)[i]; bar(arr); } int main(int argc, char **argv) { float local_arr1[10]; float local_arr2[10]; int n = min(argc, 9); #pragma hicuda global alloc local_arr1[n:9] #pragma hicuda global alloc local_arr2[n:9] #pragma hicuda global alloc glob_arr[0:9] bar(&local_arr1); #pragma hicuda kernel k_test tblock(2) thread(4) foo(&local_arr1, n); foo(&local_arr2, n); #pragma hicuda kernel_end #pragma hicuda global copyout local_arr1[n:9] #pragma hicuda global copyout local_arr2[n:9] #pragma hicuda global free local_arr1 local_arr2 return 0; }
722,044
./hicuda/regression/HTD/010/HTD010.c
/***************************************************************************** * * This program tests reaching directive analysis. * * When <matrix> of <foo> is a static array, like a[6][5], there is no way for * the compiler to know that the shape of <matrix> is <height> x <width>, * unless it performs IP constant propagation. * * An alternative is to allow the user to override the shape of <a> to be * <height> x <width> outside or within <foo>. * ****************************************************************************/ #include <stdlib.h> float a[6][5]; void foo(float *matrix, int height, int width) { int i, j; #pragma hicuda kernel k_rt012 tblock(4) thread(4) #pragma hicuda loop_partition over_tblock for (i = 1; i < height-1; ++i) #pragma hicuda loop_partition over_thread for (j = 1; j < width-1; ++j) *(matrix + i*width + j) = i + j; #pragma hicuda kernel_end } int main(int argc, char **argv) { int n = argc; int m = argc + 2; float *da = (float*)malloc(n * m * sizeof(float)); #pragma hicuda shape da[n][m] #pragma hicuda global alloc da[1:n-1][1:m-1] #pragma hicuda global alloc a[*][*] foo(da, n, m); foo((float*)a, 6, 5); #pragma hicuda global copyout da[1:n-1][1:m-1] #pragma hicuda global copyout a[1:4][1:3] #pragma hicuda global free da a return 0; }
722,045
./hicuda/regression/HTD/016/HTD016.c
/***************************************************************************** * * This program tests kernel data access summary, when array accesses are made * in a function argument. * ****************************************************************************/ float test_func(float f1, float f2) { return f1 + f2; } #define N_ELEMS 32 int main(int argc, char **argv) { float *vec_a, *vec_b, *vec_c; int i; #pragma hicuda shape vec_a[N_ELEMS] vec_b[N_ELEMS] vec_c[N_ELEMS] #pragma hicuda global alloc vec_a[*] copyin #pragma hicuda global alloc vec_b[*] copyin #pragma hicuda global alloc vec_c[*] clear #pragma hicuda kernel k_test tblock(1) thread(N_ELEMS) #pragma hicuda loop_partition over_tblock over_thread for (i = 0; i < N_ELEMS; ++i) { vec_c[i] = test_func(vec_a[i], vec_b[i]); } #pragma hicuda kernel_end #pragma hicuda global copyout vec_c[*] #pragma hicuda global free vec_a vec_b vec_c return 0; }
722,046
./hicuda/regression/HTD/014/HTD014.c
/***************************************************************************** * * This program tests the construction of Def-Use chains for scalars across * kernel boundaries. * ****************************************************************************/ #include <stdlib.h> #include <stdio.h> #include <assert.h> int main(int argc, char **argv) { int i, n_threads; int x; int *arr; n_threads = atoi(argv[2]); arr = (int*)calloc(n_threads, sizeof(int)); assert(arr != NULL); x = atoi(argv[1]); #pragma hicuda shape arr[n_threads] #pragma hicuda global alloc arr[*] copyin #pragma hicuda kernel k_test tblock(1) thread(10) #pragma hicuda loop_partition over_tblock over_thread for (i = 0; i < n_threads; ++i) { int y; if (x % 2) y = x; if (x % 2) arr[i] += y; } #pragma hicuda kernel_end #pragma hicuda global copyout arr[*] #pragma hicuda global free arr printf("arr[0] = %d\n", arr[0]); free(arr); return 0; }
722,047
./hicuda/regression/HTD/007/HTD007.c
#include <stdlib.h> float glob_arr[10]; void bar(float (*arr)[10]) { (*arr)[9] = 2 * glob_arr[9]; } void foo(float (*arr)[10], int lbnd) { int i; for (i = lbnd; i < 10; ++i) glob_arr[i] += (*arr)[i]; bar(arr); } int main(int argc, char **argv) { float local_arr[10]; int n = min(argc, 9); #pragma hicuda global alloc local_arr[n:9] #pragma hicuda global alloc glob_arr[0:9] bar(&local_arr); #pragma hicuda kernel k_test tblock(2) thread(4) foo(&local_arr, n); foo(&local_arr, n); #pragma hicuda kernel_end #pragma hicuda global copyout local_arr[n:9] #pragma hicuda global free local_arr return 0; }
722,048
./hicuda/regression/HTD/017/HTD017.c
/***************************************************************************** * * This program tests function calls within a SHARED directive region. * * It also tests multiple calls to the same function with different SHARED * directive configurations, which is not supported in the current hiCUDA * compiler. * ****************************************************************************/ void test_func(int *x, int i) { x[i] = x[i] + 1; } int main() { int arr[3]; int i; int tmp; #pragma hicuda global alloc arr[*] copyin #pragma hicuda kernel d_test tblock(1) thread(1) #pragma hicuda shared alloc arr[0:1] copyin #if 0 // local variable tmp = arr[0]; test_func(&tmp, 0); arr[0] = tmp; #endif // shared memory variable test_func(arr, 1); #pragma hicuda shared copyout arr[0:1] #pragma hicuda shared remove arr // global memory variable test_func(arr, 2); #pragma hicuda kernel_end #pragma hicuda global copyout arr[*] #pragma hicuda global free arr return 0; }
722,049
./hicuda/regression/HTD/003/HTD003.c
int arr[5]; int size; int foo(int (*b)[5], int (*at)[5]) { int x = (*at)[1]; (*at)[0] = (*at)[0] + 1; #pragma hicuda global alloc b[*] copyin sum(b); #pragma hicuda global free b return x + (*at)[0]; } int sum(int (*a)[5]) { int result, i; (*a)[2] = (*a)[2] + 1; #pragma hicuda global alloc a[*] copyin #pragma hicuda global alloc result result = foo(a, a); #pragma hicuda kernel test_sum tblock(2) thread(2) for (i = 0; i < 4; ++i) { result += (*a)[i]; } #pragma hicuda kernel_end #pragma hicuda global free a result return result; } int main(int argc, char **argv) { int x, i; // int b[5]; x = sum(&arr); // x += sum(&b); // int (*b)[5] = 0; int (*b)[5]; for (i = 0; i < 4; ++i) { x += (*b)[i]; } arr[0] = 0; return x; }
722,050
./hicuda/regression/HTD/005/HTD005.c
int arr[6]; int foo(int *b, int *a) { int x = a[1]; a[0] = a[0] + 1; #pragma hicuda global alloc b[*] copyin sum(b); #pragma hicuda global free b return x + a[0]; } int sum(int *a) { int result, i; a[2] = a[2] + 1; #pragma hicuda global alloc a[*] copyin #pragma hicuda global alloc result result += foo(a, a); #pragma hicuda kernel test_sum tblock(2) thread(2) for (i = 0; i < 4; ++i) { result += a[i]; } #pragma hicuda kernel_end #pragma hicuda global free a result return result; } int foo1(int x) { // #pragma hicuda kernel test_foo1 tblock(2) thread(3) x = x + 1; // #pragma hicuda kernel_end return x + 3; } int main(int argc, char **argv) { int x, i; // int b[5]; int *a = arr + 1; #pragma hicuda shape a[4] x = sum(a); // x += sum(&b); #pragma hicuda shape a[6] x += foo(a, a); x += foo1(3); x += foo1(4); #pragma hicuda shape a[4] x += foo(a, a); // int (*b)[5] = 0; int (*b)[5]; for (i = 0; i < 4; ++i) { x += (*b)[i]; } arr[0] = 0; return x; }
722,051
./hicuda/regression/HTD/001/HTD001.c
#include <stdlib.h> #include <stdio.h> #define ARR_LEN 1000 long compute(long x) { return x * x - x; } int main(int argc, char **argv) { long *arr; arr = (long*)malloc(ARR_LEN * sizeof(long)); #pragma hicuda shape arr[ARR_LEN] #pragma hicuda global alloc arr[*] #pragma hicuda kernel gpu_compute1 tblock(16) thread(256) int i; #pragma hicuda loop_partition over_tblock over_thread for (i = 0; i < ARR_LEN; ++i) { arr[i] = compute(i); } #pragma hicuda kernel_end // #pragma hicuda kernel gpu_compute2 tblock(16) thread(256) // #pragma hicuda loop_partition over_tblock over_thread for (i = 0; i < ARR_LEN; ++i) { arr[i] = compute(arr[i]); } // #pragma hicuda kernel_end #pragma hicuda global copyout arr[*] #pragma hicuda global free arr printf("arr[10] = %ld\n", arr[10]); return 0; }
722,052
./hicuda/regression/HTD/013/HTD013.c
/***************************************************************************** * * This program tests: * 1) kernel data access analysis, switch(incr[i]) in particular * 2) constant propagation on loop tripcount * ****************************************************************************/ #include <stdlib.h> #include <stdio.h> #define WARP_SZ 32 #define N_WARPS_PER_TBLK 1 #define N_TBLKS 1 #define N_ITERS 100 int main(int argc, char **argv) { float *arr, init_val; int *incr; int n_threads; int i, j; n_threads = N_TBLKS * N_WARPS_PER_TBLK; n_threads *= WARP_SZ; incr = (int*)malloc(n_threads * sizeof(int)); arr = (float*)malloc(n_threads * sizeof(float)); #pragma hicuda shape incr[n_threads] #pragma hicuda shape arr[n_threads] // Copy propagation should NOT happen. init_val = (float)argc + 1.0F; for (i = 0; i < n_threads; ++i) { incr[i] = (i % WARP_SZ); arr[i] = init_val; } #pragma hicuda global alloc incr[*] copyin #pragma hicuda global alloc arr[*] clear #pragma hicuda kernel d_test tblock(N_TBLKS) thread(32) #pragma hicuda loop_partition over_tblock over_thread for (i = 0; i < n_threads; ++i) { for (j = 0; j < N_ITERS; ++j) { switch (incr[i]) { case 0: arr[i] += 0.0F; break; case 1: arr[i] += 1.0F; break; case 2: arr[i] += 2.0F; break; case 3: arr[i] += 3.0F; break; case 4: arr[i] += 4.0F; break; case 5: arr[i] += 5.0F; break; case 6: arr[i] += 6.0F; break; case 7: arr[i] += 7.0F; break; case 8: arr[i] += 8.0F; break; case 9: arr[i] += 9.0F; break; case 10: arr[i] += 10.0F; break; case 11: arr[i] += 11.0F; break; case 12: arr[i] += 12.0F; break; case 13: arr[i] += 13.0F; break; case 14: arr[i] += 14.0F; break; case 15: arr[i] += 15.0F; break; case 16: arr[i] += 16.0F; break; case 17: arr[i] += 17.0F; break; case 18: arr[i] += 18.0F; break; case 19: arr[i] += 19.0F; break; case 20: arr[i] += 20.0F; break; case 21: arr[i] += 21.0F; break; case 22: arr[i] += 22.0F; break; case 23: arr[i] += 23.0F; break; case 24: arr[i] += 24.0F; break; case 25: arr[i] += 25.0F; break; case 26: arr[i] += 26.0F; break; case 27: arr[i] += 27.0F; break; case 28: arr[i] += 28.0F; break; case 29: arr[i] += 29.0F; break; case 30: arr[i] += 30.0F; break; case 31: arr[i] += 31.0F; break; default: break; } } } #pragma hicuda kernel_end #pragma hicuda global copyout arr[*] #pragma hicuda global free incr arr printf("\n"); for (i = 0; i < WARP_SZ; ++i) { printf("%10.2f\n", arr[i]); } printf("\n"); free(arr); return 0; }
722,053
./hicuda/regression/HTD/004/HTD004.c
#include <stdlib.h> void fooA(int*); void fooB(int*); void fooA(int *a) { fooB(a); #pragma hicuda global alloc a[*] copyin fooB(a); #pragma hicuda kernel testA tblock(2) thread(3) fooB(a); #pragma hicuda kernel_end #pragma hicuda global free a } void fooB(int *b) { fooA(b); } int main(int argv, char **argc) { int *arr = (int*)malloc(5 * sizeof(int)); #pragma hicuda shape arr[5] fooA(arr); return 0; }
722,054
./hicuda/regression/HTD/020/HTD020.c
/***************************************************************************** * * This program tests the nowait clause in a kernel directive. * ****************************************************************************/ float test_func(float f1, float f2) { return f1 + f2; } #define N_ELEMS 32 int main(int argc, char **argv) { float *vec_a, *vec_b, *vec_c; int i; #pragma hicuda shape vec_a[N_ELEMS] vec_b[N_ELEMS] vec_c[N_ELEMS] #pragma hicuda global alloc vec_a[*] copyin #pragma hicuda global alloc vec_b[*] copyin #pragma hicuda global alloc vec_c[*] clear #pragma hicuda kernel k_test tblock(1) thread(N_ELEMS) #pragma hicuda loop_partition over_tblock over_thread for (i = 0; i < N_ELEMS; ++i) { vec_c[i] = test_func(vec_a[i], vec_b[i]); } #pragma hicuda kernel_end #pragma hicuda kernel k_test1 tblock(1) thread(N_ELEMS) nowait #pragma hicuda loop_partition over_tblock over_thread for (i = 0; i < N_ELEMS; ++i) { vec_c[i] = test_func(vec_a[i], vec_b[i]); } #pragma hicuda kernel_end #pragma hicuda global copyout vec_c[*] #pragma hicuda global free vec_a vec_b vec_c return 0; }
722,055
./hicuda/regression/HTD/006/HTD006.c
int arr[5]; int foo1(int x) { return x + 1; } int foo(int (*b)[5], int (*at)[5]) { int x = (*at)[2]; (*at)[0] = (*at)[0] + 1; #pragma hicuda global alloc b[*] copyin x += foo1(x); sum(b); #pragma hicuda global free b return x + (*at)[0]; } int sum(int (*a)[5]) { int result, i; #pragma hicuda global alloc result result = foo(a, a); result += foo(a, a); #pragma hicuda kernel test_sum tblock(2) thread(2) #pragma hicuda loop_partition over_tblock over_thread for (i = 0; i < 4; ++i) { result += (*a)[i]; } #pragma hicuda kernel_end #pragma hicuda global free result return result; } int main(int argc, char **argv) { int x, i; // int b[5]; x = foo(&arr, &arr); // x += sum(&b); // int (*b)[5] = 0; int (*b)[5]; for (i = 0; i < 4; ++i) { x += (*b)[i]; } arr[0] = 0; return x; }
722,056
./hicuda/regression/HTD/015/HTD015.c
/***************************************************************************** * * This program tests kernel outlining when some variables accessed within are * static (either program-scoped or file-scoped). * ****************************************************************************/ #include <stdio.h> static long n2; // file-scoped static long n3; int main(int argc, char **argv) { static long arr[10]; static long n1; // PU-scoped int i; // n2 = argc; n2 = n3; #pragma hicuda global alloc arr[*] clear #pragma hicuda kernel k_test tblock(1) thread(10) #pragma hicuda loop_partition over_tblock over_thread for (i = 0; i < 10; ++i) { arr[i] += i + n1 + n2; } #pragma hicuda kernel_end #pragma hicuda global copyout arr[*] #pragma hicuda global free arr printf("%d\n", arr[3]); return 0; }
722,057
./hicuda/regression/HTD/002/HTD002.c
#include <stdlib.h> int arr[6]; int foo(int *f) { int x = f[1]; int j; f[0] = f[0] + 1; #pragma hicuda loop_partition over_tblock for (j = 1; j < 5; ++j) { f[0] += f[j]; } return x + f[0]; } int sum1(int *b, int m) { int result, i; b[m-1] = b[2] + 1; #pragma hicuda global alloc b[*] copyin #pragma hicuda global alloc result #pragma hicuda kernel test_sum tblock(2) thread(2) result += foo(b); #pragma hicuda loop_partition over_tblock over_thread for (i = 0; i < 4; ++i) { result += b[i]; } #pragma hicuda kernel_end #pragma hicuda global free b result return result; } int foo1(int x) { int j; // #pragma hicuda kernel test_foo1 tblock(2) thread(3) x = x + 1; // #pragma hicuda kernel_end #pragma hicuda loop_partition over_tblock for (j = 1; j < 5; ++j) { arr[0] += arr[j]; } return x + 3; } int main(int argc, char **argv) { int x, i; // int b[5]; int *a = arr + 1; int *c = (int*)malloc(6*sizeof(int)); #pragma hicuda shape c[6] int n = atoi(argv[0]); #pragma hicuda shape a[n] x = sum1(a, n); x += sum1(&arr, 6); x += foo(c); x += foo1(3); x += foo1(4); #pragma hicuda shape a[4] x += foo(a); // int (*b)[5] = 0; int (*b)[5]; for (i = 0; i < 4; ++i) { x += (*b)[i]; } arr[0] = 0; return x; }
722,058
./hicuda/regression/HTD/012/HTD012.c
/***************************************************************************** * * This program tests the compiler's ability to reconstruct multi-dimensional * array accesses. * ****************************************************************************/ #include <stdlib.h> #include <stdio.h> #define HEIGHT 128 #define WIDTH 256 int main(int argc, char **argv) { float *arr; int h = argc + HEIGHT, w = argc + WIDTH; // prevent const propagation int i, j; arr = (float*)calloc(h * w, sizeof(float)); #pragma hicuda shape arr[h][w] #pragma hicuda global alloc arr[*][*] clear #pragma hicuda kernel k_test tblock(1,1) thread(1,1) for (i = 0; i < h; ++i) { int base_ofst = i * w; for (j = 0; j < w; ++j) { int ofst = base_ofst + j; arr[ofst] += 1; } } #pragma hicuda kernel_end #pragma hicuda global copyout arr[*][*] #pragma hicuda global free arr free(arr); return 0; }
722,059
./hicuda/regression/HTD/021/HTD021.c
////////////////////////////////////////////////////////////////////////////// // // This program tests the proper attribute generation of a function that is // called by both host and device routines. // // It should be marked __host__ __device__ . // ////////////////////////////////////////////////////////////////////////////// int common_func(int x) { return x + 1; } int test(int x) { return common_func(x) + common_func(x); } int main(int argc, char **argv) { int x = argc; x = test(x); #pragma hicuda global alloc x copyin #pragma hicuda kernel ktest tblock(8) thread(8) x = test(x); #pragma hicuda kernel_end #pragma hicuda global copyout x #pragma hicuda global free x // x = common_func(x); return x; }
722,060
./hicuda/regression/HTA/003/HTA003.c
#include <stdio.h> int main(int argv, char **argc) { int *A; int i, j; #pragma hicuda shape A[8][7] #pragma hicuda global alloc A[*][1:6] copyin A[0:3][1:3] #pragma hicuda kernel k_test tblock(8) thread(7) A[2] = 0; #pragma hicuda loop_partition over_tblock for (i = 0; i < 8; ++i) { #pragma hicuda loop_partition over_thread for (j = 1; j < 7; ++j) { *(A + i * 7 + j) = *(A + i * 7 + j) + 1; } } #pragma hicuda kernel_end #pragma hicuda global copyout A[4:8][4:6] #pragma hicuda global free A printf("%d\n", A[0]); return 0; }
722,061
./hicuda/regression/HTA/001/HTA001.c
int arr[6]; int sum(int *a) { int result, i; a[2] = a[2] + 1; #pragma hicuda global alloc a[*] copyin #pragma hicuda global alloc result #pragma hicuda kernel test_sum tblock(2) thread(2) for (i = 0; i < 4; ++i) { result += a[i]; } #pragma hicuda kernel_end #pragma hicuda global free a result return result; } int main(int argc, char **argv) { int x, i; // int b[5]; int *a = arr + 1; #pragma hicuda shape a[x+4] x = sum(a); // x += sum(&b); #pragma hicuda shape a[6] #pragma hicuda shape a[4] // int (*b)[5] = 0; int (*b)[5]; for (i = 0; i < 4; ++i) { x += (*b)[i]; } arr[0] = 0; return x; }
722,062
./hicuda/regression/HTA/004/HTA004.c
int main(int argc, char **argv) { int a[4][5]; #pragma hicuda global alloc a[*][*][*] copyin // #pragma hicuda global alloc a[*][*] copyin #pragma hicuda global copyout a[*] #pragma hicuda global free a return 0; }
722,063
./hicuda/regression/HTA/002/HTA002.c
#include <stdio.h> int main1(int argc, char **argv) { int A[8][7]; int i, j; // #pragma hicuda global alloc A[*][1:6] copyin A[0:3][1:3] #pragma hicuda global alloc A[*][1:6] copyin #pragma hicuda kernel k_test tblock(8) thread(7) A[0][2] = 0; #pragma hicuda loop_partition over_tblock for (i = 0; i < 8; ++i) { #pragma hicuda loop_partition over_thread for (j = 1; j < 7; ++j) { A[i][j]++; } } #pragma hicuda kernel_end #pragma hicuda global copyout A[4:8][4:6] #pragma hicuda global free A printf("%d\n", A[0][0]); return 0; } int main(int argc, char **argv) { return main1(argc, argv); }
722,064
./hicuda/regression/HTE/001/HTE001.c
void bar(float *b, int end) { int i; #pragma hicuda loop_partition over_thread for (i = 0; i < end; ++i) b[i] -= b[end]; } void foo(float *a, int start) { int i; #pragma hicuda loop_partition over_thread for (i = start; i < 1024; ++i) a[i] = a[i-1] + a[start]; bar(a, start); } int main(int argc, char **argv) { float arr[1024]; int i; #pragma hicuda global alloc arr[*] copyin #pragma hicuda kernel k_looppart_ex tblock(8) thread(2,3,4,8) #pragma hicuda loop_partition over_tblock for (i = 0; i < 1024; ++i) foo(arr, i); #pragma hicuda loop_partition over_tblock(CYCLIC) over_thread for (i = 1023; i >= 0; --i) bar(arr, i); #pragma hicuda kernel_end #pragma hicuda global free arr return 0; }
722,065
./hicuda/regression/HTE/002/HTE002.c
void bar(float *b, int end) { int k; #pragma hicuda loop_partition over_thread for (k = 0; k < end; ++k) b[k] -= b[end]; } void foo(float *a, int start) { int p; #pragma hicuda loop_partition over_thread for (p = start; p < 1024; ++p) bar(a, p); } int main(int argc, char **argv) { float arr[1024]; int i, j; #pragma hicuda global alloc arr[*] copyin #pragma hicuda kernel k_example tblock(8) thread(2,3,4,8) #pragma hicuda loop_partition over_tblock for (i = 0; i < 1024; ++i) foo(arr, i); #pragma hicuda loop_partition over_tblock(CYCLIC) over_thread for (j = 1023; j >= 0; --j) bar(arr, j); #pragma hicuda kernel_end }
722,066
./hicuda/regression/HTC/003/HTC003.c
/** * This is the hiCUDA version of matrix multiplication, that divides the * computation into tiles of size TILE_SZ. */ #include <stdlib.h> #include <stdio.h> #include <sys/time.h> // #include <time.h> #include "common.h" #define WA 1024 // width of matrix A #define HA 1024 // height of matrix A #define WB 1024 // width of matrix B #define TILE_SZ 16 int main(int argc, char **argv) { int i, j, k, kk; float *A, *B, *C; A = (float*)malloc(HA*WA*sizeof(float)); B = (float*)malloc(WA*WB*sizeof(float)); C = (float*)malloc(HA*WB*sizeof(float)); float *reference = (float*)malloc(HA*WB*sizeof(float)); #pragma hicuda shape A[WA][HA] B[HA][WB] C[WA][WB] // Randomly init A and B. srand(2008); randomInitArr((float*)A, HA*WA); randomInitArr((float*)B, WA*WB); #pragma hicuda global alloc A[*][*] copyin #pragma hicuda global alloc B[*][*] copyin #pragma hicuda global alloc C[*][*] // Record the start time. struct timeval start_time; gettimeofday(&start_time, NULL); // C = A * B #pragma hicuda kernel matrixMul tblock(64,64) thread(16,16) #pragma hicuda loop_partition over_tblock over_thread for (i = 0; i < HA; ++i) { #pragma hicuda loop_partition over_tblock over_thread for (j = 0; j < WB; ++j) { float sum = 0; for (kk = 0; kk <= WA - TILE_SZ; kk += TILE_SZ) { #pragma hicuda shared alloc A[i][kk:kk+15] copyin #pragma hicuda shared alloc B[kk:kk+15][j] copyin #pragma hicuda barrier for (k = 0; k < TILE_SZ; ++k) { sum += A[i*WA+kk+k] * B[(kk+k)*WB + j]; } #pragma hicuda barrier #pragma hicuda shared remove A B } C[i*WB+j] = sum; } } #pragma hicuda kernel_end #pragma hicuda global copyout C[*][*] #pragma hicuda global free A B C // Record the end time. struct timeval end_time; gettimeofday(&end_time, NULL); printf("Time elapsed: %6f ms\n", get_time_diff(&start_time, &end_time)); // Compute reference solution. computeGold(reference, A, B, HA, WA, WB); // Check result. compare_matrices(C, reference, HA*WB); // printMatrix((float*)C, HA, WB); free(A); free(B); free(C); free(reference); return 0; }
722,067
./hicuda/regression/HTC/003/common.c
#include "common.h" #include <stdio.h> #include <stdlib.h> /** * Initialize a matrix with random elements. */ void randomInitArr(float *data, unsigned int size) { unsigned int i; for (i = 0; i < size; ++i) { data[i] = rand() / (float)RAND_MAX; } } /** * Output a matrix to the standard output. */ void printMatrix(float *mat, unsigned int h, unsigned int w) { unsigned int i, j; for (i = 0; i < h; ++i) { for (j = 0; j < w; ++j) { printf("%.3f ", *(mat++)); } printf("\n"); } printf("\n"); } //////////////////////////////////////////////////////////////////////////////// //! Compute reference data set //! C = A * B //! @param C reference data, computed but preallocated //! @param A matrix A as provided to device //! @param B matrix B as provided to device //! @param hA height of matrix A //! @param wB width of matrix B //////////////////////////////////////////////////////////////////////////////// void computeGold(float* C, const float* A, const float* B, unsigned int hA, unsigned int wA, unsigned int wB) { unsigned int i, j, k; for (i = 0; i < hA; ++i) { for (j = 0; j < wB; ++j) { double sum = 0; for (k = 0; k < wA; ++k) { double a = A[i * wA + k]; double b = B[k * wB + j]; sum += a * b; } C[i * wB + j] = (float)sum; } } } void compare_matrices(float *mat, float *ref, unsigned int nelems) { int error = 0; unsigned int i; for (i = 0; i < nelems; ++i) { float diff = mat[i] - ref[i]; if (diff < 0) diff = -diff; float avg = (mat[i] + ref[i]) / 2; if (diff / avg > 1e-5) { printf("Diff at index %u: %f, %f\n", i, mat[i], ref[i]); error = 1; } } if (!error) printf("PASSED!\n"); }
722,068
./hicuda/regression/HTC/001/HTC001.c
#include "HTC001.h" int glob_a[5]; void kernel_callee(float (*E)[8][8]) { #pragma hicuda shared alloc E[*][*] copyin // (*E)[0][0] = 0; #pragma hicuda shared remove E } int main(int argc, char **argv) { float A[128], B[128], C[128], D[256], E[8][8]; #pragma hicuda global alloc E[*][*] copyin #pragma hicuda constant copyin A[*] #pragma hicuda constant copyin B[*] #pragma hicuda kernel k_name tblock(2) thread(32) // #pragma hicuda shared alloc C[*] copyin kernel_callee(&E); // #pragma hicuda shared remove C E[0][0] = B[2] + A[1]; // #pragma hicuda shared alloc D[*] copyin kernel_callee(&E); // #pragma hicuda shared remove D #pragma hicuda kernel_end #pragma hicuda constant remove A B #pragma hicuda global free E return 0; }
722,069
./hicuda/regression/HTC/002/HTC002.c
/** * This is the hiCUDA version of matrix multiplication, that divides the * computation into tiles of size TILE_SZ. */ #include <stdlib.h> #include <stdio.h> #include <sys/time.h> #include <time.h> #include "common.h" #define WA 1024 // width of matrix A #define HA 1024 // height of matrix A #define WB 1024 // width of matrix B #define TILE_SZ 16 float A[HA][WA]; float B[WA][WB]; float C[HA][WB]; float reference[HA][WB]; int main(int argc, char **argv) { int i, j, k, kk; // Randomly init A and B. srand(2008); randomInitArr((float*)A, HA*WA); randomInitArr((float*)B, WA*WB); #pragma hicuda global alloc A[*][*] copyin #pragma hicuda global alloc B[*][*] copyin #pragma hicuda global alloc C[*][*] // Record the start time. struct timeval start_time; gettimeofday(&start_time, NULL); // C = A * B #pragma hicuda kernel matrixMul tblock(64,64) thread(16,16) #pragma hicuda loop_partition over_tblock over_thread for (i = 0; i < HA; ++i) { #pragma hicuda loop_partition over_tblock over_thread for (j = 0; j < WB; ++j) { float sum = 0; for (kk = 0; kk < WA; kk += TILE_SZ) { #pragma hicuda shared alloc A[i][kk:kk+15] copyin #pragma hicuda shared alloc B[kk:kk+15][j] copyin #pragma hicuda barrier for (k = 0; k < TILE_SZ; ++k) { sum += A[i][kk+k] * B[kk+k][j]; } #pragma hicuda barrier #pragma hicuda shared remove A B } C[i][j] = sum; } } #pragma hicuda kernel_end #pragma hicuda global copyout C[*][*] #pragma hicuda global free A B C // Record the end time. struct timeval end_time; gettimeofday(&end_time, NULL); printf("Time elapsed: %6f ms\n", get_time_diff(&start_time, &end_time)); // Compute reference solution. computeGold((float*)reference, (float*)A, (float*)B, HA, WA, WB); // Check result. compare_matrices((float*)C, (float*)reference, HA*WB); // printMatrix((float*)C, HA, WB); return 0; }
722,070
./hicuda/regression/HTC/002/common.c
#include "common.h" #include <stdio.h> #include <stdlib.h> /** * Initialize a matrix with random elements. */ void randomInitArr(float *data, unsigned int size) { unsigned int i; for (i = 0; i < size; ++i) { data[i] = rand() / (float)RAND_MAX; } } /** * Output a matrix to the standard output. */ void printMatrix(float *mat, unsigned int h, unsigned int w) { unsigned int i, j; for (i = 0; i < h; ++i) { for (j = 0; j < w; ++j) { printf("%.3f ", *(mat++)); } printf("\n"); } printf("\n"); } //////////////////////////////////////////////////////////////////////////////// //! Compute reference data set //! C = A * B //! @param C reference data, computed but preallocated //! @param A matrix A as provided to device //! @param B matrix B as provided to device //! @param hA height of matrix A //! @param wB width of matrix B //////////////////////////////////////////////////////////////////////////////// void computeGold(float* C, const float* A, const float* B, unsigned int hA, unsigned int wA, unsigned int wB) { unsigned int i, j, k; for (i = 0; i < hA; ++i) { for (j = 0; j < wB; ++j) { double sum = 0; for (k = 0; k < wA; ++k) { double a = A[i * wA + k]; double b = B[k * wB + j]; sum += a * b; } C[i * wB + j] = (float)sum; } } } void compare_matrices(float *mat, float *ref, unsigned int nelems) { int error = 0; unsigned int i; for (i = 0; i < nelems; ++i) { float diff = mat[i] - ref[i]; if (diff < 0) diff = -diff; float avg = (mat[i] + ref[i]) / 2; if (diff / avg > 1e-5) { printf("Diff at index %u: %f, %f\n", i, mat[i], ref[i]); error = 1; } } if (!error) printf("PASSED!\n"); }
722,071
./hicuda/regression/HTB/001/HTB001.c
#include <stdio.h> int main(int argc, char **argv) { int i, j; float a[1000], b[1000], c[1000], d[1000]; for (i = 0; i < 1000; ++i) { a[i] = 1; d[i] = 2; } #pragma hicuda constant copyin a[*] #pragma hicuda global alloc b[*] clear #pragma hicuda global alloc c[*] clear #pragma hicuda global alloc d[*] copyin const int limit_b = 900, limit_c = 901, limit_d = 902; // Data dependences between the two loops will NOT be respected once // turned into CUDA code. #pragma hicuda kernel MYKERNEL tblock(10) thread(16) #pragma hicuda loop_partition over_tblock(CYCLIC) over_thread for (i = 0; i < limit_b; ++i) { b[i] += a[i] + i; } // should optimize to a single assignment with guard #pragma hicuda loop_partition over_tblock(CYCLIC) over_thread for (i = 0; i < limit_b; i += 6) { b[i] += a[i] + i; } // should optimize to a single assignment #pragma hicuda loop_partition over_tblock(CYCLIC) for (i = 0; i < limit_b; i += 90) { b[i] += a[i] + i; } #pragma hicuda loop_partition over_tblock over_thread for (i = 0; i < limit_c; ++i) { c[i] += a[i] + 1 + i; } // should optimize to a single assignment with guard #pragma hicuda loop_partition over_tblock over_thread for (i = 0; i < limit_c; i += 6) { c[i] += a[i] + 1 + i; } #pragma hicuda loop_partition over_tblock for (j = 0; j < limit_d; ++j) { d[j] += a[j+1]; } #pragma hicuda kernel_end #pragma hicuda global copyout b[*] #pragma hicuda global copyout c[*] #pragma hicuda global copyout d[*] for (i = 0; i < 1000; ++i) { float b_i = 0, c_i = 0, d_i = 2; if (i < limit_b) b_i = i + 1; if (i < limit_c) c_i = i + 2; if (i < limit_d) d_i = 3; if (b[i] != b_i) { printf("b[%d] is incorrect!\n", i); break; } if (c[i] != c_i) { printf("c[%d] is incorrect!\n", i); break; } if (d[i] != d_i) { printf("d[%d] is incorrect!\n", i); break; } } if (i == 1000) printf("PASSED\n"); return 0; }
722,072
./hicuda/regression/HTB/002/HTB002.c
#include <stdio.h> void loop_test(float *a, float *b, float *c, float *d, int limit_b, int limit_c, int limit_d) { int i, j; // Data depedences between the two loops will NOT be respected once turned // into CUDA code. #pragma hicuda kernel MYKERNEL tblock(10) thread(16) #pragma hicuda loop_partition over_tblock(CYCLIC) over_thread for (i = 0; i < limit_b; ++i) { b[i] += a[i] + i; } #pragma hicuda loop_partition over_tblock over_thread for (i = 0; i < limit_c; ++i) { c[i] += a[i] + 1 + i; } #pragma hicuda loop_partition over_tblock for (j = 0; j < limit_d; ++j) { d[j] += a[j+1]; } #pragma hicuda kernel_end } void loop_test1(float *a, float *b, float *c, float *d, int limit_b, int limit_c, int limit_d) { int i, j; // Data depedences between the two loops will NOT be respected once turned // into CUDA code. #pragma hicuda loop_partition over_tblock(CYCLIC) over_thread for (i = 0; i < limit_b; ++i) { b[i] += a[i] + i; } #pragma hicuda loop_partition over_tblock over_thread for (i = 0; i < limit_c; ++i) { c[i] += a[i] + 1 + i; } #pragma hicuda loop_partition over_tblock for (j = 0; j < limit_d; ++j) { d[j] += a[j+1]; } } int main(int argc, char **argv) { int i, j; float a[1000], b[1000], c[1000], d[1000]; for (i = 0; i < 1000; ++i) { a[i] = 1; d[i] = 2; } int limit_b = 900, limit_c = 901, limit_d = 902; #pragma hicuda constant copyin a[*] #pragma hicuda global alloc b[*] clear #pragma hicuda global alloc c[*] clear #pragma hicuda global alloc d[*] copyin loop_test(a, b, c, d, limit_b, limit_c, limit_d); #pragma hicuda global copyout b[*] #pragma hicuda global copyout c[*] #pragma hicuda global copyout d[*] for (i = 0; i < 1000; ++i) { float b_i = 0, c_i = 0, d_i = 2; if (i < limit_b) b_i = i + 1; if (i < limit_c) c_i = i + 2; if (i < limit_d) d_i = 3; if (b[i] != b_i) { printf("b[%d] is incorrect!\n", i); return 1; } if (c[i] != c_i) { printf("c[%d] is incorrect!\n", i); return 1; } if (d[i] != d_i) { printf("d[%d] is incorrect!\n", i); return 1; } } for (i = 0; i < 1000; ++i) { a[i] = 1; d[i] = 2; } limit_b = 902; limit_c = 901; limit_d = 900; #pragma hicuda constant copyin a[*] #pragma hicuda global alloc b[*] clear #pragma hicuda global alloc c[*] clear #pragma hicuda global alloc d[*] copyin #pragma hicuda kernel MYKERNEL1 tblock(10) thread(16) loop_test1(a, b, c, d, limit_b, limit_c, limit_d); #pragma hicuda kernel_end #pragma hicuda global copyout b[*] #pragma hicuda global copyout c[*] #pragma hicuda global copyout d[*] for (i = 0; i < 1000; ++i) { float b_i = 0, c_i = 0, d_i = 2; if (i < limit_b) b_i = i + 1; if (i < limit_c) c_i = i + 2; if (i < limit_d) d_i = 3; if (b[i] != b_i) { printf("b[%d] is incorrect!\n", i); return 1; } if (c[i] != c_i) { printf("c[%d] is incorrect!\n", i); return 1; } if (d[i] != d_i) { printf("d[%d] is incorrect!\n", i); return 1; } } printf("PASSED\n"); return 0; }
722,073
./devfest-site/devfest-site/gdata/tlslite/utils/entropy.c
#include "Python.h" #ifdef MS_WINDOWS /* The following #define is not needed on VC6 with the Platform SDK, and it may not be needed on VC7, I'm not sure. I don't think it hurts anything.*/ #define _WIN32_WINNT 0x0400 #include <windows.h> typedef BOOL (WINAPI *CRYPTACQUIRECONTEXTA)(HCRYPTPROV *phProv,\ LPCSTR pszContainer, LPCSTR pszProvider, DWORD dwProvType,\ DWORD dwFlags ); typedef BOOL (WINAPI *CRYPTGENRANDOM)(HCRYPTPROV hProv, DWORD dwLen,\ BYTE *pbBuffer ); typedef BOOL (WINAPI *CRYPTRELEASECONTEXT)(HCRYPTPROV hProv,\ DWORD dwFlags); static PyObject* entropy(PyObject *self, PyObject *args) { int howMany = 0; HINSTANCE hAdvAPI32 = NULL; CRYPTACQUIRECONTEXTA pCryptAcquireContextA = NULL; CRYPTGENRANDOM pCryptGenRandom = NULL; CRYPTRELEASECONTEXT pCryptReleaseContext = NULL; HCRYPTPROV hCryptProv = 0; unsigned char* bytes = NULL; PyObject* returnVal = NULL; /* Read arguments */ if (!PyArg_ParseTuple(args, "i", &howMany)) return(NULL); /* Obtain handle to the DLL containing CryptoAPI This should not fail */ if( (hAdvAPI32 = GetModuleHandle("advapi32.dll")) == NULL) { PyErr_Format(PyExc_SystemError, "Advapi32.dll not found"); return NULL; } /* Obtain pointers to the CryptoAPI functions This will fail on some early version of Win95 */ pCryptAcquireContextA = (CRYPTACQUIRECONTEXTA)GetProcAddress(hAdvAPI32,\ "CryptAcquireContextA"); pCryptGenRandom = (CRYPTGENRANDOM)GetProcAddress(hAdvAPI32,\ "CryptGenRandom"); pCryptReleaseContext = (CRYPTRELEASECONTEXT) GetProcAddress(hAdvAPI32,\ "CryptReleaseContext"); if (pCryptAcquireContextA == NULL || pCryptGenRandom == NULL || pCryptReleaseContext == NULL) { PyErr_Format(PyExc_NotImplementedError, "CryptoAPI not available on this version of Windows"); return NULL; } /* Allocate bytes */ if ((bytes = (unsigned char*)PyMem_Malloc(howMany)) == NULL) return PyErr_NoMemory(); /* Acquire context */ if(!pCryptAcquireContextA(&hCryptProv, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) { PyErr_Format(PyExc_SystemError, "CryptAcquireContext failed, error %d", GetLastError()); PyMem_Free(bytes); return NULL; } /* Get random data */ if(!pCryptGenRandom(hCryptProv, howMany, bytes)) { PyErr_Format(PyExc_SystemError, "CryptGenRandom failed, error %d", GetLastError()); PyMem_Free(bytes); CryptReleaseContext(hCryptProv, 0); return NULL; } /* Build return value */ returnVal = Py_BuildValue("s#", bytes, howMany); PyMem_Free(bytes); /* Release context */ if (!pCryptReleaseContext(hCryptProv, 0)) { PyErr_Format(PyExc_SystemError, "CryptReleaseContext failed, error %d", GetLastError()); return NULL; } return returnVal; } #elif defined(HAVE_UNISTD_H) && defined(HAVE_FCNTL_H) #include <unistd.h> #include <fcntl.h> static PyObject* entropy(PyObject *self, PyObject *args) { int howMany; int fd; unsigned char* bytes = NULL; PyObject* returnVal = NULL; /* Read arguments */ if (!PyArg_ParseTuple(args, "i", &howMany)) return(NULL); /* Allocate bytes */ if ((bytes = (unsigned char*)PyMem_Malloc(howMany)) == NULL) return PyErr_NoMemory(); /* Open device */ if ((fd = open("/dev/urandom", O_RDONLY, 0)) == -1) { PyErr_Format(PyExc_NotImplementedError, "No entropy source found"); PyMem_Free(bytes); return NULL; } /* Get random data */ if (read(fd, bytes, howMany) < howMany) { PyErr_Format(PyExc_SystemError, "Reading from /dev/urandom failed"); PyMem_Free(bytes); close(fd); return NULL; } /* Build return value */ returnVal = Py_BuildValue("s#", bytes, howMany); PyMem_Free(bytes); /* Close device */ close(fd); return returnVal; } #else static PyObject* entropy(PyObject *self, PyObject *args) { PyErr_Format(PyExc_NotImplementedError, "Function not supported"); return NULL; } #endif /* List of functions exported by this module */ static struct PyMethodDef entropy_functions[] = { {"entropy", (PyCFunction)entropy, METH_VARARGS, "Return a string of random bytes produced by a platform-specific\nentropy source."}, {NULL, NULL} /* Sentinel */ }; /* Initialize this module. */ PyMODINIT_FUNC initentropy(void) { Py_InitModule("entropy", entropy_functions); }
722,074
./devfest-site/devfest-site/gdata/tlslite/utils/win32prng.c
#include "Python.h" #define _WIN32_WINNT 0x0400 /* Needed for CryptoAPI on some systems */ #include <windows.h> static PyObject* getRandomBytes(PyObject *self, PyObject *args) { int howMany; HCRYPTPROV hCryptProv; unsigned char* bytes = NULL; PyObject* returnVal = NULL; /* Read Arguments */ if (!PyArg_ParseTuple(args, "i", &howMany)) return(NULL); /* Get Context */ if(CryptAcquireContext( &hCryptProv, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT) == 0) return Py_BuildValue("s#", NULL, 0); /* Allocate bytes */ bytes = malloc(howMany); /* Get random data */ if(CryptGenRandom( hCryptProv, howMany, bytes) == 0) returnVal = Py_BuildValue("s#", NULL, 0); else returnVal = Py_BuildValue("s#", bytes, howMany); free(bytes); CryptReleaseContext(hCryptProv, 0); return returnVal; } /* List of functions exported by this module */ static struct PyMethodDef win32prng_functions[] = { {"getRandomBytes", (PyCFunction)getRandomBytes, METH_VARARGS}, {NULL, NULL} /* Sentinel */ }; /* Initialize this module. */ DL_EXPORT(void) initwin32prng(void) { Py_InitModule("win32prng", win32prng_functions); }
722,075
./tone-generator/src/indicator.c
/************************************************************************* This file is part of tone-generator Copyright (C) 2010 Nokia Corporation. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation version 2.1 of the License. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *************************************************************************/ #define _GNU_SOURCE #include <stdlib.h> #include <string.h> #include <errno.h> #include <log/log.h> #include <trace/trace.h> #include "ausrv.h" #include "stream.h" #include "tone.h" #include "indicator.h" #define MAX_TONE_LENGTH (1 * 60 * 1000000) /* Special case for shorter tones, because we don't want to keep a silent * stream around for a long time after playing the actual tone. */ #define MAX_SHORT_TONE_LENGTH (1 * 5 * 1000000) #define LOG_ERROR(f, args...) log_error(logctx, f, ##args) #define LOG_INFO(f, args...) log_error(logctx, f, ##args) #define LOG_WARNING(f, args...) log_error(logctx, f, ##args) #define TRACE(f, args...) trace_write(trctx, trflags, trkeys, f, ##args) static char *ind_stream = STREAM_INDICATOR; static int standard = STD_CEPT; static void *ind_props = NULL; static uint32_t vol_scale = 100; int indicator_init(int argc, char **argv) { (void)argc; (void)argv; return 0; } void indicator_play(struct ausrv *ausrv, int type, uint32_t vol, int dur) { struct stream *stream = stream_find(ausrv, ind_stream); uint32_t timeout = dur ? dur : MAX_TONE_LENGTH; if (stream != NULL) { dtmf_stop(ausrv); indicator_stop(ausrv, PRESERVE_STREAM); } else { stream = stream_create(ausrv, ind_stream, NULL, 0, tone_write_callback, tone_destroy_callback, ind_props, NULL); if (stream == NULL) { LOG_ERROR("%s(): Can't create stream", __FUNCTION__); return; } } vol = (vol_scale * vol) / 100; switch (type) { case TONE_DIAL: switch (standard) { case STD_CEPT: tone_create(stream, type, 425, vol, 1000000, 1000000, 0,0); break; case STD_ANSI: case STD_ATNT: tone_create(stream, type, 350, (vol*7)/10, 1000000, 1000000, 0,0); tone_create(stream, type, 440, (vol*7)/10, 1000000, 1000000, 0,0); break; case STD_JAPAN: tone_create(stream, type, 400, vol, 1000000, 1000000, 0,0); break; } timeout = MAX_TONE_LENGTH; break; case TONE_BUSY: switch (standard) { case STD_CEPT: tone_create(stream, type, 425, vol, 1000000, 500000, 0,dur); break; case STD_ANSI: case STD_ATNT: tone_create(stream, type, 480, (vol*7)/10, 1000000, 500000, 0,dur); tone_create(stream, type, 620, (vol*7)/10, 1000000, 500000, 0,dur); break; case STD_JAPAN: tone_create(stream, type, 400, vol, 1000000, 500000, 0,dur); break; } break; case TONE_CONGEST: switch (standard) { case STD_CEPT: tone_create(stream, type, 425, vol, 400000, 200000, 0,dur); break; case STD_ANSI: case STD_ATNT: tone_create(stream, type, 480, (vol*7)/10, 500000, 250000, 0,dur); tone_create(stream, type, 620, (vol*7)/10, 500000, 250000, 0,dur); break; case STD_JAPAN: /* * this is non-standard, but * we play busy tone instead of being silent */ tone_create(stream, type, 400, vol, 1000000, 500000, 0,dur); break; } break; case TONE_RADIO_ACK: switch (standard) { case STD_CEPT: case STD_ANSI: case STD_ATNT: tone_create(stream, type, 425, vol, 200000, 200000, 0,200000); timeout = MAX_SHORT_TONE_LENGTH; break; case STD_JAPAN: tone_create(stream, type, 400, vol, 3000000, 1000000, 0,0); /* The Japan standard tone is repeating, so I guess we need to wait 60s anyway. */ timeout = MAX_TONE_LENGTH; break; } break; case TONE_RADIO_NA: switch (standard) { case STD_CEPT: case STD_ANSI: case STD_ATNT: tone_create(stream, type, 425, vol, 400000, 200000, 0,1200000); break; case STD_JAPAN: break; } timeout = MAX_SHORT_TONE_LENGTH; break; case TONE_ERROR: switch (standard) { case STD_CEPT: case STD_ANSI: case STD_ATNT: tone_create(stream, type, 900, vol, 2000000, 333333, 0,dur); tone_create(stream, type, 1400, vol, 2000000, 332857, 333333,dur); tone_create(stream, type, 1800, vol, 2000000, 300000, 666190,dur); break; case STD_JAPAN: /* * this is non-standard, but * we play busy tone instead of being silent */ tone_create(stream, type, 400, vol, 1000000, 500000, 0,dur); break; } break; case TONE_WAIT: switch (standard) { case STD_CEPT: tone_create(stream,type, 425, vol, 800000,200000, 0,1000000); tone_create(stream,type, 425, vol, 800000,200000, 4000000,1000000); break; case STD_ANSI: tone_create(stream,type, 440, vol, 300000,300000, 0,300000); tone_create(stream,type, 440, vol, 10000000,100000, 10000000,0); tone_create(stream,type, 440, vol, 10000000,100000, 10200000,0); break; case STD_ATNT: tone_create(stream, type, 440, vol, 4000000, 200000, 0, 0); tone_create(stream, type, 440, vol, 4000000, 200000, 500000, 0); break; case STD_JAPAN: break; } timeout = MAX_TONE_LENGTH; break; case TONE_RING: switch (standard) { case STD_CEPT: tone_create(stream, type, 425, vol, 5000000, 1000000, 0,0); break; case STD_ANSI: case STD_ATNT: tone_create(stream, type, 440, (vol*7)/10, 6000000, 2000000, 0,0); tone_create(stream, type, 480, (vol*7)/10, 6000000, 2000000, 0,0); break; case STD_JAPAN: break; } timeout = MAX_TONE_LENGTH; break; default: LOG_ERROR("%s(): invalid type %d", __FUNCTION__, type); break; } stream_set_timeout(stream, timeout); } void indicator_stop(struct ausrv *ausrv, int kill_stream) { struct stream *stream = stream_find(ausrv, ind_stream); struct tone *tone; struct tone *hd; TRACE("%s(kill_stream=%s) stream=%s", __FUNCTION__, kill_stream ? "true":"false", stream ? stream->name:"<no-stream>"); if (stream != NULL) { if (kill_stream) stream_destroy(stream); else { /* destroy all but DTMF tones */ for (hd = (struct tone *)&stream->data; hd; hd = hd->next) { while ((tone=hd->next) != NULL && !tone_chainable(tone->type)) tone_destroy(tone, KILL_CHAIN); } } } } void indicator_set_standard(int std) { if (std <= STD_UNKNOWN || std >= STD_MAX) LOG_ERROR("%s(): invalid standard %d", __FUNCTION__, std); else standard = std; } void indicator_set_properties(char *propstring) { ind_props = stream_parse_properties(propstring); } void indicator_set_volume(uint32_t volume) { vol_scale = volume; } /* * Local Variables: * c-basic-offset: 4 * indent-tabs-mode: nil * End: */
722,076
./tone-generator/src/stream.c
/************************************************************************* This file is part of tone-generator Copyright (C) 2010 Nokia Corporation. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation version 2.1 of the License. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *************************************************************************/ #define _GNU_SOURCE #include <stdlib.h> #include <string.h> #include <time.h> #include <sys/time.h> #include <errno.h> #include <pulse/pulseaudio.h> #include <log/log.h> #include <trace/trace.h> #include "ausrv.h" #include "stream.h" #define LOG_ERROR(f, args...) log_error(logctx, f, ##args) #define LOG_INFO(f, args...) log_error(logctx, f, ##args) #define LOG_WARNING(f, args...) log_error(logctx, f, ##args) #define TRACE(f, args...) trace_write(trctx, trflags, trkeys, f, ##args) static void state_callback(pa_stream *, void *); static void underflow_callback(pa_stream *, void *); static void suspended_callback(pa_stream *, void *); static void write_callback(pa_stream *, size_t, void *); static void flush_callback(pa_stream *, int, void *); static void drain_callback(pa_stream *, int, void *); static void write_samples(struct stream *, int16_t *,size_t, uint32_t *); static uint32_t default_rate = 48000; static int print_statistics = 0; static int target_buflen = 1000; /* 1000msec ie. 1sec */ static int min_bufreq = 200; /* 200msec */ int stream_init(int argc, char **argv) { (void)argc; (void)argv; return 0; } void stream_set_default_samplerate(uint32_t rate) { default_rate = rate; } void stream_print_statistics(int print) { print_statistics = print; } void stream_buffering_parameters(int tlen, int minreq) { if (!tlen && !minreq) { target_buflen = 0; min_bufreq = 0; } else { if (tlen < 20 || minreq < 10 || minreq > tlen - 10) { LOG_ERROR("Ignoring invalid buffering parameters %d %d", tlen, minreq); } else { target_buflen = tlen; min_bufreq = minreq; } } } struct stream *stream_create(struct ausrv *ausrv, char *name, char *sink, uint32_t sample_rate, uint32_t (*write)(struct stream*,int16_t*,int), void (*destroy)(void*), void *proplist, void *data) { struct stream *stream; pa_buffer_attr battr; pa_stream_flags_t flags; pa_sample_spec spec; struct timeval tv; uint64_t start; struct stream_stat *stat; uint32_t bufsize; uint32_t tlength; char tlstr[32]; char bfstr[32]; if (!ausrv->connected) { LOG_ERROR("Can't create stream '%s': no server connected", name); return NULL; } if (name == NULL) name = "generated tone"; if (sample_rate == 0) sample_rate = default_rate; memset(&spec, 0, sizeof(spec)); spec.format = PA_SAMPLE_S16LE; spec.rate = sample_rate; spec.channels = 1; /* e.g. MONO */ if (min_bufreq > 0) bufsize = pa_usec_to_bytes(min_bufreq * PA_USEC_PER_MSEC, &spec); else bufsize = (uint32_t)-1; if (target_buflen > 0) tlength = pa_usec_to_bytes(target_buflen * PA_USEC_PER_MSEC, &spec); else tlength = (uint32_t)-1; gettimeofday(&tv, NULL); start = (uint64_t)tv.tv_sec * (uint64_t)1000000 + (uint64_t)tv.tv_usec; if ((stream = (struct stream *)malloc(sizeof(*stream))) == NULL) { LOG_ERROR("%s(): Can't allocate memory", __FUNCTION__); return NULL; } memset(stream, 0, sizeof(*stream)); stream->next = ausrv->streams; stream->ausrv = ausrv; stream->id = ausrv->nextid++; stream->name = strdup(name); stream->rate = sample_rate; stream->pastr = pa_stream_new_with_proplist(ausrv->context, name, &spec, NULL, (pa_proplist *)proplist); stream->start = start; stream->flush = TRUE; stream->bufsize = bufsize; stream->write = write; stream->destroy = destroy; stream->data = data; if (print_statistics) { stat = &stream->stat; stat->wrtime = start; stat->minbuf = -1; stat->mingap = -1; stat->mincalc = -1; } if (stream->pastr == NULL) { free(stream->name); free(stream); TRACE("%s(): stream creation of '%s' failed", __FUNCTION__, name); return NULL; } /* these are for the 48Khz mono 16bit streams */ battr.maxlength = -1; /* default (4MB) */ battr.tlength = tlength; battr.minreq = bufsize; battr.prebuf = -1; /* default (tlength) */ battr.fragsize = -1; /* default (tlength) */ flags = PA_STREAM_ADJUST_LATENCY; pa_stream_set_state_callback(stream->pastr, state_callback,(void*)stream); pa_stream_set_underflow_callback(stream->pastr, underflow_callback, (void *)stream); pa_stream_set_suspended_callback(stream->pastr, suspended_callback, (void *)stream); pa_stream_set_write_callback(stream->pastr, write_callback,(void *)stream); pa_stream_connect_playback(stream->pastr, sink, &battr, flags, NULL, NULL); ausrv->streams = stream; TRACE("%s(): stream '%s' created", __FUNCTION__, stream->name); if (print_statistics) { if (battr.tlength == (uint32_t)-1) snprintf(tlstr, sizeof(tlstr), "<default>"); else snprintf(tlstr, sizeof(tlstr), "%u", battr.tlength); if (battr.minreq == (uint32_t)-1) snprintf(bfstr, sizeof(tlstr), "<default>"); else snprintf(bfstr, sizeof(tlstr), "%u", battr.minreq); TRACE("Requested buffer attributes:\n" " tlength %s\n" " minreq %s", tlstr, bfstr); } return stream; } void stream_destroy(struct stream *stream) { struct ausrv *ausrv = stream->ausrv; struct stream *prev; pa_stream *pastr; const pa_buffer_attr *battr; struct stream_stat *stat; pa_operation *oper; struct timeval tv; uint64_t stop; double upt; double strt; double dur; double freq; double flow; uint32_t avbuf; uint32_t avcalc; uint32_t avcpu; uint32_t avgap; TRACE("%s(): destroying stream '%s'", __FUNCTION__, stream->name); if (stream->killed) { TRACE("%s(): stream is already killed", __FUNCTION__); return; } gettimeofday(&tv, NULL); stop = (uint64_t)tv.tv_sec * (uint64_t)1000000 + (uint64_t)tv.tv_usec; for (prev=(struct stream *)&ausrv->streams; prev->next; prev=prev->next){ if (prev->next == stream) { pastr = stream->pastr; battr = pa_stream_get_buffer_attr(pastr); stat = &stream->stat; if (stream->flush) oper = pa_stream_flush(pastr, flush_callback, (void *)stream); else oper = pa_stream_drain(pastr, drain_callback, (void *)stream); if (oper == NULL) return; pa_operation_unref(oper); prev->next = stream->next; stream->next = NULL; stream->killed = TRUE; if (stream->destroy != NULL) stream->destroy(stream->data); stream->ausrv = NULL; free(stream->buf.samples); pa_stream_set_write_callback(pastr, NULL,NULL); if (print_statistics && stat->wrcnt > 0) { if (battr != NULL) { TRACE("Buffer attributes:\n" " maxlength %u\n" " tlength %u\n" " prebuf %u\n" " minreq %u", battr->maxlength, battr->tlength, battr->prebuf, battr->minreq); } upt = (double)(stop - stream->start) / 1000000.0; strt = (double)(stream->time) / 1000000.0; dur = (double)(stat->wrtime - stat->firstwr)/1000000.0 + 0.01; freq = (double)stat->wrcnt / dur; flow = (double)stream->bcnt / dur; avbuf = stream->bcnt / stat->wrcnt; avcpu = (stat->cpucalc / stat->wrcnt) / 1000; avcalc = (uint32_t)(stat->sumcalc/(uint64_t)stat->wrcnt)/1000; avgap = (uint32_t)(stat->sumgap /(uint64_t)stat->wrcnt)/1000; TRACE("stream '%s' killed. Statistics:\n" " up %.3lfsec tone %.3lfsec\n" " flow %.0lf byte/sec (excluding pre-buffering)\n" " write freq %.2lf buf/sec (every %.0lf msec)\n" " bufsize %u - %u - %u\n" " calc.time %u - %u - %u msec\n" " avarage cpu / buffer %u msec\n" " cpu load for all buffer calculation %.2lf%%\n" " gaps %u - %u - %u msec\n" " underflows %u\n" " %u buffer was late out of %u (%u%%)", stream->name, upt, strt, flow, freq, 1000.0/freq, stat->minbuf, avbuf, stat->maxbuf, stat->mincalc / 1000, avcalc, stat->maxcalc / 1000, avcpu, ((double)avcpu * freq) / 10.0, stat->mingap / 1000, avgap, stat->maxgap / 1000, stat->underflows, stat->late, stat->wrcnt, (stat->late * 100) / stat->wrcnt); } return; } } LOG_ERROR("%s(): Can't find stream '%s'", __FUNCTION__, stream->name); } void stream_set_timeout(struct stream *stream, uint32_t timeout) { if (timeout == 0) stream->end = 0; else stream->end = stream->time + timeout; } void stream_kill_all(struct ausrv *ausrv) { struct stream *stream; while ((stream = ausrv->streams) != NULL) { ausrv->streams = stream->next; stream->next = NULL; stream->killed = TRUE; if (stream->destroy != NULL) stream->destroy(stream->data); stream->ausrv = NULL; pa_stream_set_state_callback(stream->pastr, NULL,NULL); pa_stream_set_underflow_callback(stream->pastr, NULL,NULL); pa_stream_set_suspended_callback(stream->pastr, NULL,NULL); pa_stream_set_write_callback(stream->pastr, NULL,NULL); free(stream->name); free(stream); } } void stream_clean_buffer(struct stream *stream) { struct timeval tv; uint64_t now; uint32_t bcnt; uint32_t dcnt; size_t offs; size_t len; int i,j; int32_t sample; gettimeofday(&tv, NULL); now = (uint64_t)tv.tv_sec * (uint64_t)1000000 + (uint64_t)tv.tv_usec; bcnt = ((now - stream->start) * (uint64_t)stream->rate) / 1000000ULL; bcnt *= 2; dcnt = (10000ULL * (uint64_t)stream->rate) / 1000000ULL; if (stream->buf.samples != NULL) { offs = bcnt >= stream->bcnt ? bcnt - stream->bcnt : 0; if (offs < stream->buf.buflen) { len = stream->buf.buflen - offs; if (len < dcnt * 2) { TRACE("%s(): resetting %u bytes in write-ahead-buffer", __FUNCTION__, len); memset((char *)stream->buf.samples + offs, 0, len); } else { for (i = 0, j = offs / 2; i < dcnt; i++, j++) { sample = stream->buf.samples[j]; sample = (sample * ((int32_t)dcnt - i-1)) / (int32_t)dcnt; if (sample > 32767) stream->buf.samples[j] = 32767; else if (sample < -32767) stream->buf.samples[j] = -32767; else stream->buf.samples[j] = sample; } len -= dcnt * 2; offs += dcnt * 2; TRACE("%s(): ramping down %u and resetting %u bytes in " "write-ahead-buffer", __FUNCTION__, dcnt * 2, len); if (len > 0) memset((char *)stream->buf.samples + offs, 0, len); } } } } struct stream *stream_find(struct ausrv *ausrv, char *name) { struct stream *stream; for (stream = ausrv->streams; stream != NULL; stream = stream->next) { if (!strcmp(name, stream->name)) break; } return stream; } void *stream_parse_properties(char *propstring) { pa_proplist *proplist; char *key, *val, *next, keybuf[128]; int keylen, vallen; if (propstring == NULL) return NULL; if ((proplist = pa_proplist_new()) == NULL) { LOG_ERROR("%s(): Failed to allocate property list", __FUNCTION__); return NULL; } key = propstring; while (key != NULL) { if ((val = strchr(key, '=')) == NULL) { LOG_ERROR("%s(): Invalid property string '%s'", __FUNCTION__, propstring); goto error; } keylen = val - key; if (keylen >= (int)sizeof(keybuf)) { LOG_ERROR("%s(): property key '%*.*s' too long", __FUNCTION__, keylen, keylen, key); goto error; } strncpy(keybuf, key, keylen); keybuf[keylen] = '\0'; val++; if ((next = strchr(val, ',')) != NULL) { vallen = next - val; next++; } else vallen = strlen(val); pa_proplist_setf(proplist, keybuf, "%*.*s", vallen, vallen, val); key = next; } return (void *)proplist; error: pa_proplist_free(proplist); return NULL; } void stream_free_properties(void *proplist) { if (proplist) pa_proplist_free((pa_proplist *)proplist); } static void state_callback(pa_stream *pastr, void *userdata) { struct stream *stream = (struct stream *)userdata; if (!stream || stream->pastr != pastr) { LOG_ERROR("%s(): confused with data structures", __FUNCTION__); return; } switch (pa_stream_get_state(pastr)) { case PA_STREAM_UNCONNECTED: TRACE("%s(): stream '%s' unconnected", __FUNCTION__, stream->name); break; case PA_STREAM_CREATING: TRACE("%s(): stream '%s' creating", __FUNCTION__, stream->name); break; case PA_STREAM_READY: TRACE("%s(): stream '%s' ready", __FUNCTION__, stream->name); break; case PA_STREAM_TERMINATED: TRACE("%s(): stream '%s' terminated", __FUNCTION__, stream->name); free(stream->name); free(stream); break; default: case PA_STREAM_FAILED: LOG_ERROR("%s(): Stream error: %s", __FUNCTION__, pa_strerror(pa_context_errno(pa_stream_get_context(pastr)))); break; } } static void underflow_callback(pa_stream *pastr, void *userdata) { (void)pastr; struct stream *stream = (struct stream *)userdata; if (!stream || !stream->name) LOG_ERROR("Stream underflow"); else { LOG_ERROR("Stream '%s' underflow", stream->name); stream->stat.underflows++; stream_destroy(stream); } } static void suspended_callback(pa_stream *pastr, void *userdata) { (void)pastr; struct stream *stream = (struct stream *)userdata; if (!stream || !stream->name) LOG_ERROR("Stream suspended"); else { LOG_ERROR("Stream '%s' suspended", stream->name); } } static void write_callback(pa_stream *pastr, size_t bytes, void *userdata) { struct stream *stream = (struct stream *)userdata; struct stream_stat *stat = &stream->stat; const pa_buffer_attr *battr; int16_t *samples; size_t buflen; int16_t *extra; size_t extlen; struct timeval tv; uint32_t start; uint32_t gap; uint32_t calcend; uint32_t calc; uint32_t period; uint32_t cpu; if (!stream || stream->pastr != pastr) { LOG_ERROR("%s(): Confused with data structures", __FUNCTION__); return; } if (stream->killed) return; if (print_statistics) { gettimeofday(&tv, NULL); start = (uint64_t)tv.tv_sec * (uint64_t)1000000 + (uint64_t)tv.tv_usec; gap = start - stat->wrtime; } #if 0 TRACE("%s(): %d bytes", __FUNCTION__, bytes); #endif if (stream->buf.samples == NULL) { buflen = (bytes + 1) & (~1U); samples = (int16_t *)malloc(buflen); if (samples != NULL) write_samples(stream, samples,buflen, &cpu); else { LOG_ERROR("%s(): failed to allocate memory", __FUNCTION__); return; } } else { if (bytes <= stream->buf.buflen) { buflen = stream->buf.buflen; samples = stream->buf.samples; cpu = stream->buf.cpu; } else { buflen = (bytes + 1) & (~1U); samples = (int16_t *)realloc(stream->buf.samples, buflen); extra = samples + (stream->buf.buflen / 2); extlen = buflen - stream->buf.buflen; if (samples != NULL) { TRACE("%s(): extending write-ahead-buffer %u butes (%u -> %u)", __FUNCTION__, extlen, stream->buf.buflen, buflen); write_samples(stream, extra,extlen, &cpu); cpu += stream->buf.cpu; } else { LOG_ERROR("%s(): failed to allocate memory", __FUNCTION__); return; } } stream->buf.samples = NULL; stream->buf.cpu = 0; } if (samples != NULL) { if (print_statistics) { gettimeofday(&tv, NULL); calcend = (uint64_t)tv.tv_sec * (uint64_t)1000000 + (uint64_t)tv.tv_usec; calc = calcend - start; period = (calcend - stat->wrtime) / 1000; stat->wrtime = calcend; if (stream->bcnt == 0 /* && buflen > stream->bufsize */) { TRACE("Stream '%s' pre-buffers of %u bytes", stream->name, buflen); stat->firstwr = stat->wrtime; } else { stat->wrcnt ++; stat->sumgap += gap; stat->sumcalc += calc; stat->cpucalc += cpu; if (buflen < stat->minbuf) stat->minbuf = buflen; if (buflen > stat->maxbuf) stat->maxbuf = buflen; if (gap < stat->mingap) stat->mingap = gap; if (gap > stat->maxgap) stat->maxgap = gap; if (calc < stat->mincalc) stat->mincalc = calc; if (calc > stat->maxcalc) stat->maxcalc = calc; #if 0 TRACE("Buffer writting period %umsec", period); #endif if (period > (uint32_t)min_bufreq) { stat->late++; #if 0 TRACE("Buffer is late %umsec in stream '%s'", period - min_bufreq, stream->name); #endif } } } pa_stream_write(stream->pastr, (void*)samples,buflen, free, 0,PA_SEEK_RELATIVE); stream->bcnt += buflen; #if 0 TRACE("stream time %09umsec end %09umsec", stream->time / 1000, stream->end / 1000); #endif if (stream->end && stream->time >= stream->end) stream_destroy(stream); else { if (stream->bufsize == (uint32_t)-1) { if ((battr = pa_stream_get_buffer_attr(pastr)) != NULL) stream->bufsize = battr->minreq; } if (stream->bufsize != (uint32_t)-1) { stream->buf.samples = (int16_t *)malloc(stream->bufsize); stream->buf.buflen = stream->bufsize; if (stream->buf.samples == NULL) LOG_ERROR("%s(): failed to allocate memory", __FUNCTION__); else { write_samples(stream, stream->buf.samples,stream->bufsize, &stream->buf.cpu); } } } } } static void flush_callback(pa_stream *pastr, int success, void *userdata) { struct stream *stream = (struct stream *)userdata; if (stream->pastr != pastr) { LOG_ERROR("%s(): Confused with data structures", __FUNCTION__); return; } if (!success) LOG_ERROR("%s(): Can't flush stream '%s'", __FUNCTION__, stream->name); else TRACE("%s(): stream '%s' flushed", __FUNCTION__, stream->name); pa_stream_disconnect(pastr); pa_stream_unref(pastr); } static void drain_callback(pa_stream *pastr, int success, void *userdata) { struct stream *stream = (struct stream *)userdata; if (stream->pastr != pastr) { LOG_ERROR("%s(): Confused with data structures", __FUNCTION__); return; } if (!success) LOG_ERROR("%s(): Can't drain stream '%s'", __FUNCTION__, stream->name); else TRACE("%s(): stream '%s' drained", __FUNCTION__, stream->name); pa_stream_disconnect(pastr); pa_stream_unref(pastr); } static void write_samples(struct stream *stream, int16_t *samples, size_t bytes, uint32_t *cpu) { int length; clock_t cpubeg; clock_t cpuend; length = bytes/2; cpubeg = print_statistics ? clock() : 0; stream->time = stream->write(stream, samples, length); cpuend = print_statistics ? clock() : 0; *cpu = cpuend - cpubeg; return; } /* * Local Variables: * c-basic-offset: 4 * indent-tabs-mode: nil * End: */
722,077
./tone-generator/src/ausrv.c
/************************************************************************* This file is part of tone-generator Copyright (C) 2010 Nokia Corporation. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation version 2.1 of the License. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *************************************************************************/ #define _GNU_SOURCE #include <stdlib.h> #include <string.h> #include <errno.h> #include <log/log.h> #include <trace/trace.h> #include "stream.h" #include "ausrv.h" #if PA_API_VERSION < 9 #error Invalid PulseAudio API version #endif #define DISCONNECTED 0 #define CONNECTED 1 #define DEFAULT_SERVER "default Pulse Audio" #define CONNECT_DELAY 10 /* in seconds */ #define LOG_ERROR(f, args...) log_error(logctx, f, ##args) #define LOG_INFO(f, args...) log_error(logctx, f, ##args) #define LOG_WARNING(f, args...) log_error(logctx, f, ##args) #define TRACE(f, args...) trace_write(trctx, trflags, trkeys, f, ##args) static void set_connection_status(struct ausrv *, int); static void context_callback(pa_context *, void *); static void event_callback(pa_context *, pa_subscription_event_type_t, uint32_t, void *); static void connect_server(struct ausrv *); static void restart_timer(struct ausrv *, int); static void cancel_timer(struct ausrv *); static char *pa_client_name; int ausrv_init(int argc, char **argv) { (void)argc; char *name = basename(argv[0]); pa_client_name = name ? strdup(name) : "tonegend"; return 0; } void ausrv_exit(void) { free(pa_client_name); pa_client_name = NULL; } struct ausrv *ausrv_create(struct tonegend *tonegend, char *server) { pa_glib_mainloop *mainloop = NULL; struct ausrv *ausrv; pa_mainloop_api *mainloop_api; if ((ausrv = malloc(sizeof(*ausrv))) == NULL) { LOG_ERROR("%s(): Can't allocate memory", __FUNCTION__); goto failed; } if ((mainloop = pa_glib_mainloop_new(NULL)) == NULL) { LOG_ERROR("%s(): pa_glib_mainloop_new() failed", __FUNCTION__); goto failed; } mainloop_api = pa_glib_mainloop_get_api(mainloop); if (pa_signal_init(mainloop_api) < 0) { LOG_ERROR("%s(): pa_signal_init() failed", __FUNCTION__); goto failed; } memset(ausrv, 0, sizeof(*ausrv)); ausrv->tonegend = tonegend; ausrv->server = strdup(server ? server : DEFAULT_SERVER); ausrv->mainloop = mainloop; connect_server(ausrv); return ausrv; failed: if (mainloop != NULL) pa_glib_mainloop_free(mainloop); if (ausrv != NULL) free(ausrv); return NULL; } void ausrv_destroy(struct ausrv *ausrv) { if (ausrv != NULL) { stream_kill_all(ausrv); if (ausrv->context != NULL) pa_context_unref(ausrv->context); if (ausrv->mainloop != NULL) pa_glib_mainloop_free(ausrv->mainloop); free(ausrv->server); free(ausrv); } } static void set_connection_status(struct ausrv *ausrv, int sts) { int connected = sts ? CONNECTED : DISCONNECTED; if ((ausrv->connected ^ connected)) { ausrv->connected = connected; if (connected) TRACE("Connected to '%s' server", ausrv->server); else TRACE("Disconnected from %s server", ausrv->server); } } static void context_callback(pa_context *context, void *userdata) { struct ausrv *ausrv = (struct ausrv *)userdata; int err = 0; const char *strerr; if (context == NULL) { LOG_ERROR("%s() called with zero context", __FUNCTION__); return; } if (ausrv == NULL || ausrv->context != context) { LOG_ERROR("%s(): Confused with data structures", __FUNCTION__); return; } switch (pa_context_get_state(context)) { case PA_CONTEXT_CONNECTING: TRACE("ausrv: connecting to server"); set_connection_status(ausrv, DISCONNECTED); break; case PA_CONTEXT_AUTHORIZING: TRACE("ausrv: authorizing"); set_connection_status(ausrv, DISCONNECTED); break; case PA_CONTEXT_SETTING_NAME: TRACE("ausrv: setting name"); set_connection_status(ausrv, DISCONNECTED); break; case PA_CONTEXT_READY: TRACE("ausrv: connection established."); set_connection_status(ausrv, CONNECTED); cancel_timer(ausrv); LOG_INFO("Pulse Audio OK"); break; case PA_CONTEXT_TERMINATED: TRACE("ausrv: connection to server terminated"); goto disconnect; case PA_CONTEXT_FAILED: default: if ((err = pa_context_errno(context)) != 0) { if ((strerr = pa_strerror(err)) == NULL) strerr = "<unknown>"; LOG_ERROR("ausrv: server connection failure: %s", strerr); } disconnect: set_connection_status(ausrv, DISCONNECTED); stream_kill_all(ausrv); restart_timer(ausrv, CONNECT_DELAY); } } static void event_callback(pa_context *context, pa_subscription_event_type_t type, uint32_t idx, void *userdata) { struct ausrv *ausrv = (struct ausrv *)userdata; (void)idx; if (ausrv == NULL || ausrv->context != context) LOG_ERROR("%s(): Confused with data structures", __FUNCTION__); else { switch (type) { case PA_SUBSCRIPTION_EVENT_SINK: TRACE("Event sink"); break; case PA_SUBSCRIPTION_EVENT_SOURCE: TRACE("Event source"); break; case PA_SUBSCRIPTION_EVENT_SINK_INPUT: TRACE("Event sink input"); break; case PA_SUBSCRIPTION_EVENT_SOURCE_OUTPUT: TRACE("Event source output"); break; default: TRACE("Event %d", type); break; } } } static void retry_connect(pa_mainloop_api *api, pa_time_event *event, const struct timeval *tv, void *data) { struct ausrv *ausrv = (struct ausrv *)data; (void)api; (void)tv; if (event != ausrv->timer) { LOG_ERROR("%s(): Called with unknown timer (%p != %p)", __FUNCTION__, event, ausrv->timer); return; } ausrv->timer = NULL; connect_server(ausrv); } static void restart_timer(struct ausrv *ausrv, int secs) { pa_mainloop_api *api = pa_glib_mainloop_get_api(ausrv->mainloop); struct timeval tv; gettimeofday(&tv, NULL); tv.tv_sec += secs; if (ausrv->timer != NULL) api->time_restart(ausrv->timer, &tv); else ausrv->timer = api->time_new(api, &tv, retry_connect, (void *)ausrv); } static void cancel_timer(struct ausrv *ausrv) { pa_mainloop_api *api; if (ausrv->timer != NULL) { api = pa_glib_mainloop_get_api(ausrv->mainloop); api->time_free(ausrv->timer); ausrv->timer = NULL; } } static void connect_server(struct ausrv *ausrv) { pa_mainloop_api *api = pa_glib_mainloop_get_api(ausrv->mainloop); char *server = ausrv->server; cancel_timer(ausrv); if (server != NULL && !strcmp(ausrv->server, DEFAULT_SERVER)) server = NULL; /* * Note: It is not possible to reconnect a context if it ever gets * disconnected. If we have a context here, get rid of it and * allocate a new one. */ if (ausrv->context != NULL) { pa_context_set_state_callback(ausrv->context, NULL, NULL); pa_context_set_subscribe_callback(ausrv->context, NULL, NULL); pa_context_unref(ausrv->context); ausrv->context = NULL; } if ((ausrv->context = pa_context_new(api, pa_client_name)) == NULL) { LOG_ERROR("%s(): pa_context_new() failed, exiting", __FUNCTION__); exit(1); } pa_context_set_state_callback(ausrv->context, context_callback, ausrv); pa_context_set_subscribe_callback(ausrv->context, event_callback, ausrv); LOG_INFO("Trying to connect to %s...", server ? server : DEFAULT_SERVER); pa_context_connect(ausrv->context, server, PA_CONTEXT_NOAUTOSPAWN, NULL); } /* * Local Variables: * c-basic-offset: 4 * indent-tabs-mode: nil * End: */
722,078
./tone-generator/src/dtmf.c
/************************************************************************* This file is part of tone-generator Copyright (C) 2010 Nokia Corporation. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation version 2.1 of the License. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *************************************************************************/ #define _GNU_SOURCE #include <stdlib.h> #include <string.h> #include <errno.h> #include <glib.h> #include <log/log.h> #include <trace/trace.h> #include "ausrv.h" #include "stream.h" #include "tone.h" #include "indicator.h" #include "dtmf.h" #include "dbusif.h" #define LOG_ERROR(f, args...) log_error(logctx, f, ##args) #define LOG_INFO(f, args...) log_error(logctx, f, ##args) #define LOG_WARNING(f, args...) log_error(logctx, f, ##args) #define TRACE(f, args...) trace_write(trctx, trflags, trkeys, f, ##args) #define MUTE_ON 1 #define MUTE_OFF 0 struct dtmf { char symbol; uint32_t low_freq; uint32_t high_freq; }; static struct dtmf dtmf_defs[DTMF_MAX] = { {'0', 941, 1336}, {'1', 697, 1209}, {'2', 697, 1336}, {'3', 697, 1477}, {'4', 770, 1209}, {'5', 770, 1336}, {'6', 770, 1477}, {'7', 852, 1209}, {'8', 852, 1336}, {'9', 852, 1477}, {'*', 941, 1209}, {'#', 941, 1477}, {'A', 697, 1633}, {'B', 770, 1633}, {'C', 852, 1633}, {'D', 941, 1633} }; static char *dtmf_stream = STREAM_DTMF; static void *dtmf_props = NULL; static int vol_scale = 100; static int mute = MUTE_OFF; static guint tmute_id; static void destroy_callback(void *); static void set_mute_timeout(struct ausrv *, guint); static gboolean mute_timeout_callback(gpointer); static void request_muting(struct ausrv *, dbus_bool_t); int dtmf_init(int argc, char **argv) { (void)argc; (void)argv; return 0; } void dtmf_play(struct ausrv *ausrv, uint type, uint32_t vol, int dur) { struct stream *stream = stream_find(ausrv, dtmf_stream); struct dtmf *dtmf = dtmf_defs + type; uint32_t per = dur; uint32_t play = dur > 60000 ? dur - 20000 : dur; int type_l = TONE_DTMF_L; int type_h = TONE_DTMF_H; uint32_t timeout; if (type >= DTMF_MAX || (dur != 0 && dur < 10000)) return; if (!dur) { /* * These types will make the DTMF tone as 'indicator' * i.e. the indicator_stop() will work on them */ type_l = TONE_DTMF_IND_L; type_h = TONE_DTMF_IND_H; per = play = 1000000; } if (stream != NULL) { if (!dur) { indicator_stop(ausrv, KILL_STREAM); dtmf_stop(ausrv); } } else { stream = stream_create(ausrv, dtmf_stream, NULL, 0, tone_write_callback, destroy_callback, dtmf_props, NULL); if (stream == NULL) { LOG_ERROR("%s(): Can't create stream", __FUNCTION__); return; } } vol = (vol_scale * vol) / 100; tone_create(stream, type_l, dtmf->low_freq , vol/2, per,play, 0,dur); tone_create(stream, type_h, dtmf->high_freq, vol/2, per,play, 0,dur); timeout = dur ? dur + (30 * 1000000) : (1 * 60 * 1000000); stream_set_timeout(stream, timeout); request_muting(ausrv, MUTE_ON); set_mute_timeout(ausrv, 0); } void dtmf_stop(struct ausrv *ausrv) { struct stream *stream = stream_find(ausrv, dtmf_stream); struct tone *tone; struct tone *next; TRACE("%s() stream=%s", __FUNCTION__, stream ? stream->name:"<no-stream>"); if (stream != NULL) { for (tone = (struct tone *)stream->data; tone; tone = next) { next = tone->next; switch (tone->type) { case TONE_DTMF_IND_L: case TONE_DTMF_IND_H: /* in the future a linear ramp-down enevlop can be set */ tone_destroy(tone, KILL_CHAIN); break; default: if (!tone_chainable(tone->type)) tone_destroy(tone, KILL_CHAIN); break; } } if (stream->data == NULL) stream_clean_buffer(stream); stream_set_timeout(stream, 10 * 1000000); set_mute_timeout(ausrv, 2 * 1000000); } } void dtmf_set_properties(char *propstring) { dtmf_props = stream_parse_properties(propstring); } void dtmf_set_volume(uint32_t volume) { vol_scale = volume; } static void destroy_callback(void *data) { struct tone *tone = (struct tone *)data; struct stream *stream; struct ausrv *ausrv; set_mute_timeout(NULL, 0); if (mute && tone != NULL) { stream = tone->stream; ausrv = stream->ausrv; request_muting(ausrv, MUTE_OFF); mute = MUTE_OFF; } tone_destroy_callback(data); } static void set_mute_timeout(struct ausrv *ausrv, guint interval) { if (interval) TRACE("add %d usec mute timeout", interval); else if (tmute_id) TRACE("remove mute timeout"); if (tmute_id != 0) { g_source_remove(tmute_id); tmute_id = 0; } if (interval > 0 && ausrv != NULL) { tmute_id = g_timeout_add(interval/1000, mute_timeout_callback, ausrv); } } static gboolean mute_timeout_callback(gpointer data) { struct ausrv *ausrv = (struct ausrv *)data; TRACE("mute timeout fired"); request_muting(ausrv, MUTE_OFF); tmute_id = 0; return FALSE; } static void request_muting(struct ausrv *ausrv, dbus_bool_t new_mute) { int sts; new_mute = new_mute ? MUTE_ON : MUTE_OFF; if (ausrv != NULL && mute != new_mute) { sts = dbusif_send_signal(ausrv->tonegend, NULL, "Mute", DBUS_TYPE_BOOLEAN, &new_mute, DBUS_TYPE_INVALID); if (sts != 0) LOG_ERROR("failed to send mute signal"); else { TRACE("sent signal to turn mute %s", new_mute ? "on" : "off"); mute = new_mute; } } } /* * Local Variables: * c-basic-offset: 4 * indent-tabs-mode: nil * End: */
722,079
./tone-generator/src/dbusif.c
/************************************************************************* This file is part of tone-generator Copyright (C) 2010 Nokia Corporation. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation version 2.1 of the License. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *************************************************************************/ #define _GNU_SOURCE #include <stdlib.h> #include <string.h> #include <stdarg.h> #include <errno.h> #include <log/log.h> #include <trace/trace.h> #include "tonegend.h" #include "dbusif.h" #define LOG_ERROR(f, args...) log_error(logctx, f, ##args) #define LOG_INFO(f, args...) log_error(logctx, f, ##args) #define LOG_WARNING(f, args...) log_error(logctx, f, ##args) #define TRACE(f, args...) trace_write(trctx, trflags, trkeys, f, ##args) static DBusHandlerResult handle_message(DBusConnection *,DBusMessage *,void *); static gchar *create_key(gchar *, gchar *, gchar *); static void destroy_key(gpointer); static char *path = "/com/Nokia/Telephony/Tones"; static char *service = "com.Nokia.Telephony.Tones"; int dbusif_init(int argc, char **argv) { (void)argc; (void)argv; return 0; } void dbsuif_exit(void) { } struct dbusif *dbusif_create(struct tonegend *tonegend) { static struct DBusObjectPathVTable method = { .message_function = &handle_message }; struct dbusif *dbusif = NULL; DBusConnection *conn = NULL; DBusError err; int ret; if ((dbusif = (struct dbusif *)malloc(sizeof(*dbusif))) == NULL) { LOG_ERROR("%s(): Can't allocate memory", __FUNCTION__); goto failed; } memset(dbusif, 0, sizeof(*dbusif)); dbus_error_init(&err); if ((conn = dbus_bus_get(DBUS_BUS_SYSTEM, &err)) == NULL) { LOG_ERROR("%s(): Can't connect to D-Bus daemon: %s", __FUNCTION__, err.message); dbus_error_free(&err); goto failed; } /* * The following will make us zombie if the system bus goes down. * However, for 'clean' shutdown operation it is useful, ie. the * shutdown sequence should not assure that we go before D-Bus go */ dbus_connection_set_exit_on_disconnect(conn, FALSE); dbus_connection_setup_with_g_main(conn, NULL); if (!dbus_connection_register_object_path(conn, path, &method, dbusif)) { LOG_ERROR("%s(): failed to register object path", __FUNCTION__); goto failed; } ret = dbus_bus_request_name(conn, service, DBUS_NAME_FLAG_REPLACE_EXISTING, &err); if (ret < 0) { LOG_ERROR("%s(): request name failed: %s", __FUNCTION__, err.message); dbus_error_free(&err); goto failed; } if (ret != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) { LOG_ERROR("%s(): not a primary owner", __FUNCTION__); goto failed; } dbusif->tonegend = tonegend; dbusif->conn = conn; dbusif->hash = g_hash_table_new_full(g_str_hash, g_str_equal, destroy_key, NULL); LOG_INFO("D-Bus setup OK"); return dbusif; failed: if (dbusif != NULL) free(dbusif); return NULL; } void dbusif_destroy(struct dbusif *dbusif) { if (dbusif) { if (dbusif->hash != NULL) g_hash_table_destroy(dbusif->hash); free(dbusif); } } int dbusif_register_input_method(struct tonegend *tonegend, char *intf, char *memb, char *sig, int (*method)(DBusMessage*, struct tonegend*)) { struct dbusif *dbusif = tonegend->dbus_ctx; gchar *key; if (!memb || !sig || !method) { LOG_ERROR("%s(): Called with invalid argument(s)", __FUNCTION__); errno = EINVAL; return -1; } if (intf == NULL) intf = service; key = create_key((gchar *)memb, (gchar *)sig, (gchar *)intf); g_hash_table_insert(dbusif->hash, key, (gpointer)method); return 0; } int dbusif_unregister_input_method(struct tonegend *tonegend, char *intf, char *memb, char *sign) { (void)tonegend; (void)intf; (void)memb; (void)sign; return 0; } int dbusif_send_signal(struct tonegend *tonegend, char *intf, char *name, int first_arg_type, ...) { struct dbusif *dbusif = tonegend->dbus_ctx; DBusMessage *msg; va_list ap; int success; do { /* not a loop */ success = FALSE; if (name == NULL) { LOG_ERROR("%s(): Called with invalid argument", __FUNCTION__); errno = EINVAL; break; } if (intf == NULL) intf = service; if ((msg = dbus_message_new_signal(path, intf, name)) == NULL) { errno = ENOMEM; break; } va_start(ap, first_arg_type); if (dbus_message_append_args_valist(msg, first_arg_type, ap)) { success = dbus_connection_send(dbusif->conn, msg, NULL); } va_end(ap); dbus_message_unref(msg); } while(FALSE); return success ? 0 : -1; } static DBusHandlerResult handle_message(DBusConnection *conn, DBusMessage *msg, void *user_data) { struct dbusif *dbusif = (struct dbusif *)user_data; struct tonegend *tonegend = dbusif->tonegend; DBusMessage *reply = NULL; uint32_t ser; int (*method)(DBusMessage *, struct tonegend *); const char *intf; const char *memb; const char *sig; gchar *key; const char *errname; char errdesc[256]; int success; (void)conn; if (dbus_message_get_type(msg) != DBUS_MESSAGE_TYPE_METHOD_CALL) TRACE("%s(): ignoring non method_call's", __FUNCTION__); else { intf = dbus_message_get_interface(msg); memb = dbus_message_get_member(msg); sig = dbus_message_get_signature(msg); ser = dbus_message_get_serial(msg); #if 0 TRACE("%s(): message no #%u received: '%s', '%s', '%s'", __FUNCTION__, ser, intf, memb, sig); #endif key = create_key((gchar *)memb, (gchar *)sig, (gchar *)intf); method = g_hash_table_lookup(dbusif->hash, key); g_free(key); success = method ? method(msg, tonegend) : FALSE; if (success) reply = dbus_message_new_method_return(msg); else { if (method) { errname = DBUS_ERROR_FAILED; snprintf(errdesc, sizeof(errdesc), "Internal error"); } else { errname = DBUS_ERROR_NOT_SUPPORTED; snprintf(errdesc, sizeof(errdesc), "Method '%s(%s)' " "not supported", memb, sig); } reply = dbus_message_new_error(msg, errname, errdesc); } dbus_message_set_reply_serial(msg, ser); if (!dbus_connection_send(dbusif->conn, reply, NULL)) LOG_ERROR("%s(): D-Bus message reply failure", __FUNCTION__); #if 0 else TRACE("%s(): message no #%u replied", __FUNCTION__, ser); #endif dbus_message_unref(reply); } return DBUS_HANDLER_RESULT_HANDLED; } static gchar *create_key(gchar *memb, gchar *sign, gchar *intf) { gchar *key = NULL; if (memb == NULL) memb = ""; if (sign == NULL) sign = ""; if (intf == NULL) intf = ""; key = g_strconcat(memb, "__", sign, "__", intf, NULL); return key; } static void destroy_key(gpointer key) { g_free(key); } /* * Local Variables: * c-basic-offset: 4 * indent-tabs-mode: nil * End: */
722,080
./tone-generator/src/interact.c
/************************************************************************* This file is part of tone-generator Copyright (C) 2010 Nokia Corporation. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation version 2.1 of the License. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *************************************************************************/ #define _GNU_SOURCE #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <errno.h> #include <log/log.h> #include <trace/trace.h> #include "tonegend.h" #include "ausrv.h" #include "tone.h" #include "indicator.h" #include "dtmf.h" #include "interact.h" #define DISCONNECTED 0 #define CONNECTED 1 #define LOG_ERROR(f, args...) log_error(logctx, f, ##args) #define LOG_INFO(f, args...) log_error(logctx, f, ##args) #define LOG_WARNING(f, args...) log_error(logctx, f, ##args) #define TRACE(f, args...) trace_write(trctx, trflags, trkeys, f, ##args) static gboolean handle_input(GIOChannel *, GIOCondition, gpointer); /********************* Temporary *************************/ #include "note.h" static void ringtone(struct ausrv *ausrv) { struct ndef {int dur; int note;}; static struct ndef ndef[] = { {32, NOTE_PAUSE}, {8, NOTE_G}, {8, NOTE_PAUSE}, {16, NOTE_Ab}, {8, NOTE_PAUSE}, {16, NOTE_G}, {16, NOTE_PAUSE}, {16, NOTE_G}, {8, NOTE_C}, {8, NOTE_G}, {8, NOTE_F}, {8, NOTE_G}, {8, NOTE_PAUSE}, {16, NOTE_D}, {0, 0} }; /*8p,16g,16p,16g,8d#6,8d6,8a#,8g,8d6,8g6, 16g,16f,16p,16f,8d,8a#,2g,p,SS,16f6,8d6,8c6,8a#,g,8a#.,16g, 16p,16g,8c6,8g,8f,g,8d.6,16g,16p,16g,8d#6,8d6,8a#,8g,8d6, 8g6,16g,16f,16p,16f,8d,8a#,2g*/ struct ndef *nd; for (nd = ndef; nd->dur; nd++) { note_play(ausrv, nd->note, 5, 30, 1, nd->dur, 60, 0); } } /****************** End of Temporary *********************/ int interact_init(int argc, char **argv) { (void)argc; (void)argv; return 0; } struct interact *interact_create(struct tonegend *tonegend, int fd) { struct interact *interact = NULL; if ((interact = (struct interact *)malloc(sizeof(*interact))) == NULL) { LOG_ERROR("%s(): Can't allocate memory", __FUNCTION__); goto failed; } memset(interact, 0, sizeof(*interact)); interact->tonegend = tonegend; if ((interact->chan = g_io_channel_unix_new(fd)) == NULL) { LOG_ERROR("%s(): Can't make G-I/O channel", __FUNCTION__); goto failed; } interact->evsrc = g_io_add_watch(interact->chan, G_IO_IN|G_IO_HUP|G_IO_ERR, handle_input, interact); return interact; failed: if (interact != NULL) { free(interact); } return NULL; } void interact_destroy(struct interact *interact) { if (interact) { g_io_channel_shutdown(interact->chan, TRUE, NULL); g_io_channel_unref(interact->chan); g_source_remove(interact->evsrc); free(interact); } } static gboolean handle_input(GIOChannel *ch, GIOCondition cond, gpointer data) { #define PRINT(f, args...) printf(f "\n", ##args) #define TONE(t) indicator_play(ausrv, t, 95, 0) #define STOP indicator_stop(ausrv, KILL_STREAM) #define STANDARD(s) indicator_set_standard(STD_##s) #define DTMF(t) dtmf_play(ausrv, DTMF_##t, 100, 300000) struct interact *interact = (struct interact *)data; struct tonegend *tonegend = interact->tonegend; struct ausrv *ausrv = tonegend->ausrv_ctx; int cnt; char cmd; (void)ch; (void)cond; for (;;) { if ((cnt = read(0, &cmd, 1)) != 1) { if (errno == EINTR) continue; else return FALSE; } switch (cmd) { case 'D': PRINT("Dial tone"); TONE(TONE_DIAL); break; case 'B': PRINT("Busy tone"); TONE(TONE_BUSY); break; case 'C': PRINT("Cong.tone"); TONE(TONE_CONGEST); break; case 'A': PRINT("Radio Ack. tone"); TONE(TONE_RADIO_ACK); break; case 'N': PRINT("Radio N/A tone"); TONE(TONE_RADIO_NA); break; case 'E': PRINT("Error tone"); TONE(TONE_ERROR); break; case 'W': PRINT("Wait tone"); TONE(TONE_WAIT); break; case 'R': PRINT("Ring tone"); TONE(TONE_RING); break; case 'S': PRINT("Stop tone"); STOP; break; case '0': PRINT("DTMF: 0"); DTMF(0); break; case '1': PRINT("DTMF: 1"); DTMF(1); break; case '2': PRINT("DTMF: 2"); DTMF(2); break; case '3': PRINT("DTMF: 3"); DTMF(3); break; case '4': PRINT("DTMF: 4"); DTMF(4); break; case '5': PRINT("DTMF: 5"); DTMF(5); break; case '6': PRINT("DTMF: 6"); DTMF(6); break; case '7': PRINT("DTMF: 7"); DTMF(7); break; case '8': PRINT("DTMF: 8"); DTMF(8); break; case '9': PRINT("DTMF: 9"); DTMF(9); break; case '*': PRINT("DTMF: *"); DTMF(ASTERISK); break; case '#': PRINT("DTMF: #"); DTMF(HASHMARK); break; case 'a': PRINT("ANSI standard"); STANDARD(ANSI); break; case 'e': PRINT("EU standard"); STANDARD(CEPT); break; case 'j': PRINT("Japan standard"); STANDARD(JAPAN); break; case '!': PRINT("Play ..."); ringtone(ausrv); break; default: break; } return TRUE; } #undef DTMF #undef STANDARD #undef STOP #undef TONE #undef PRINT } /* * Local Variables: * c-basic-offset: 4 * indent-tabs-mode: nil * End: */
722,081
./tone-generator/src/main.c
/************************************************************************* This file is part of tone-generator Copyright (C) 2010 Nokia Corporation. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation version 2.1 of the License. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *************************************************************************/ #define _GNU_SOURCE #include <fcntl.h> #include <signal.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <getopt.h> #include <errno.h> #include <pwd.h> #include <sys/types.h> #include <sys/stat.h> #include <sys/mman.h> #include <glib.h> #include <log/log.h> #include <trace/trace.h> #include "tonegend.h" #include "dbusif.h" #include "ausrv.h" #include "stream.h" #include "tone.h" #include "envelop.h" #include "indicator.h" #include "dtmf.h" #include "note.h" #include "rfc4733.h" #include "notification.h" #include "interact.h" #define LOG_ERROR(f, args...) log_error(logctx, f, ##args) #define LOG_INFO(f, args...) log_error(logctx, f, ##args) #define LOG_WARNING(f, args...) log_error(logctx, f, ##args) #define TRACE(f, args...) trace_write(trctx, trflags, trkeys, f, ##args) struct cmdopt { int daemon; /* */ int uid; char *path; int standard; int interactive; int sample_rate; int statistics; int buflen; int minreq; char *dtmf_tags; char *notif_tags; char *ind_tags; uint32_t dtmf_volume; uint32_t notif_volume; uint32_t ind_volume; }; static void usage(int, char **, int); static void parse_options(int, char **, struct cmdopt *); static void signal_handler(int, siginfo_t *, void *); static int daemonize(uid_t uid, const char *path); static char *pa_server_name; static GMainLoop *main_loop; int main(int argc, char **argv) { struct sigaction sa; struct tonegend tonegend; struct cmdopt cmdopt; cmdopt.daemon = 0; cmdopt.uid = -1; cmdopt.path = NULL; cmdopt.standard = STD_CEPT; cmdopt.interactive = 0; cmdopt.sample_rate = 48000; cmdopt.statistics = 0; cmdopt.buflen = 0; cmdopt.minreq = 0; cmdopt.dtmf_tags = NULL; cmdopt.ind_tags = NULL; cmdopt.notif_tags = NULL; cmdopt.dtmf_volume = 100; cmdopt.ind_volume = 100; cmdopt.notif_volume = 100; parse_options(argc, argv, &cmdopt); memset(&tonegend, 0, sizeof(tonegend)); memset(&sa, 0, sizeof(sa)); sa.sa_sigaction = signal_handler; sa.sa_flags = SA_SIGINFO; if (sigaction(SIGHUP , &sa, NULL) < 0 || sigaction(SIGTERM, &sa, NULL) < 0 || sigaction(SIGINT , &sa, NULL) < 0 ) { LOG_ERROR("Failed to install signal handlers"); return errno; } if (dbusif_init(argc, argv) < 0 || ausrv_init(argc, argv) < 0 || stream_init(argc, argv) < 0 || tone_init(argc, argv) < 0 || envelop_init(argc, argv) < 0 || indicator_init(argc, argv) < 0 || dtmf_init(argc, argv) < 0 || note_init(argc, argv) < 0 || interact_init(argc, argv) < 0 || rfc4733_init(argc, argv) < 0 || notif_init(argc, argv) < 0) { LOG_ERROR("Error during initialization"); return EINVAL; } stream_set_default_samplerate(cmdopt.sample_rate); stream_print_statistics(cmdopt.statistics); stream_buffering_parameters(cmdopt.buflen, cmdopt.minreq); dtmf_set_properties(cmdopt.dtmf_tags); indicator_set_properties(cmdopt.ind_tags); notif_set_properties(cmdopt.notif_tags); dtmf_set_volume(cmdopt.dtmf_volume); indicator_set_volume(cmdopt.ind_volume); notif_set_volume(cmdopt.notif_volume); if (cmdopt.daemon) daemonize(cmdopt.uid, cmdopt.path); if ((main_loop = g_main_loop_new(NULL, FALSE)) == NULL) { LOG_ERROR("Can't create main loop"); return EIO; } if ((tonegend.dbus_ctx = dbusif_create(&tonegend)) == NULL) { LOG_ERROR("D-Bus setup failed"); return EIO; } if ((tonegend.ausrv_ctx = ausrv_create(&tonegend,pa_server_name)) == NULL){ LOG_ERROR("Pulse Audio setup failed"); return EIO; } if (rfc4733_create(&tonegend) < 0) { LOG_ERROR("Can't setup rfc4733 interface on D-Bus"); return EIO; } if (notif_create(&tonegend) < 0) { LOG_ERROR("Can't setup notification interface on D-Bus"); return EIO; } if (!cmdopt.daemon && cmdopt.interactive) { if (!(tonegend.intact_ctx = interact_create(&tonegend,fileno(stdin)))){ LOG_ERROR("Can't setup interactive console"); return EIO; } printf("Running in interactive mode\n"); } indicator_set_standard(cmdopt.standard); g_main_loop_run(main_loop); LOG_INFO("Exiting now ..."); ausrv_destroy(tonegend.ausrv_ctx); dbusif_destroy(tonegend.dbus_ctx); interact_destroy(tonegend.intact_ctx); if (main_loop != NULL) g_main_loop_unref(main_loop); ausrv_exit(); return 0; } static void usage(int argc, char **argv, int exit_code) { (void)argc; printf("usage: %s [-h] [-d] [-u username] " "[-s {cept | ansi | japan | atnt }] " "[-b buflen_in_ms] [-r min_req_time_in_ms] [-i] [-8] [-S] " "[--tag-dtmf tags] [--tag-indicator tags] [--tag-notif tags] " "[--volume-dtmf volume] [--volume-indicator volume] " "[--volume-notif volume]" "\n", basename(argv[0])); exit(exit_code); } static uint32_t parse_volume(char *volstr) { char *end; uint32_t vol; vol = strtoul(volstr, &end, 10); if (*end) { LOG_ERROR("%s(): ignoring invalid volume '%s'", __FUNCTION__, volstr); return (uint32_t)100; } return vol; } static void parse_options(int argc, char **argv, struct cmdopt *cmdopt) { struct option options[] = { { "help" , no_argument , NULL, 'h' }, { "daemon" , no_argument , NULL, 'd' }, { "interactive" , no_argument , NULL, 'i' }, { "8kHz" , no_argument , NULL, '8' }, { "user" , required_argument, NULL, 'u' }, { "standard" , required_argument, NULL, 's' }, { "buflen" , required_argument, NULL, 'b' }, { "minreq" , required_argument, NULL, 'r' }, { "statistics" , no_argument , NULL, 'S' }, { "tag-dtmf" , required_argument, NULL, 'D' }, { "tag-indicator" , required_argument, NULL, 'I' }, { "tag-notif" , required_argument, NULL, 'N' }, { "volume-dtmf" , required_argument, NULL, '1' }, { "volume-indicator", required_argument, NULL, '2' }, { "volume-notif" , required_argument, NULL, '3' }, #define OPTS "du:s:b:r:hi8SD:I:N:" { NULL , 0 , NULL, 0 } }; int option; struct passwd *pwd; long int t; char *e; while ((option = getopt_long(argc, argv, OPTS, options, NULL)) != -1) { switch (option) { case 'h': usage(argc, argv, 0); break; case 'd': cmdopt->daemon = 1; break; case 'i': cmdopt->interactive = 1; break; case '8': cmdopt->sample_rate = 8000; break; case 'u': if (!optarg && !*optarg) usage(argc, argv, EINVAL); cmdopt->uid = -1; while ((pwd = getpwent()) != NULL) { if (!strcmp(optarg, pwd->pw_name)) { cmdopt->uid = pwd->pw_uid; break; } } if (cmdopt->uid < 0) { printf("invalid username: %s\n", optarg); usage(argc, argv, EINVAL); } break; case 's': if (!strcmp(optarg, "cept")) cmdopt->standard = STD_CEPT; else if (!strcmp(optarg, "ansi")) cmdopt->standard = STD_ANSI; else if (!strcmp(optarg, "japan")) cmdopt->standard = STD_JAPAN; else if (!strcmp(optarg, "atnt")) cmdopt->standard = STD_ATNT; else { printf("invalid standard '%s'\n", optarg); usage(argc, argv, EINVAL); } break; case 'b': t = strtol(optarg, &e, 10); if (*e == '\0' && t > 0 && t <= 10000) cmdopt->buflen = t; else { printf("invalid buffer length '%s' msec\n", optarg); usage(argc, argv, EINVAL); } break; case 'r': t = strtol(optarg, &e, 10); if (*e == '\0' && t > 0 && t <= 1000) cmdopt->minreq = t; else { printf("invalid min.request length '%s' msec\n", optarg); usage(argc, argv, EINVAL); } break; case 'S': cmdopt->statistics = 1; break; case 'D': cmdopt->dtmf_tags = optarg; break; case 'I': cmdopt->ind_tags = optarg; break; case 'N': cmdopt->notif_tags = optarg; break; case '1': cmdopt->dtmf_volume = parse_volume(optarg); break; case '2': cmdopt->ind_volume = parse_volume(optarg); break; case '3': cmdopt->notif_volume = parse_volume(optarg); break; default: usage(argc, argv, EINVAL); break; } } if (!cmdopt->daemon && cmdopt->uid > 0) { printf("Warning: -d is not present; ignoring -u option\n"); } } static void signal_handler(int signo, siginfo_t *info, void *data) { #if 0 ucontext_t *uc = (ucontext_t *)data; #endif (void)info; (void)data; switch (signo) { case SIGHUP: case SIGTERM: case SIGINT: if (main_loop != NULL) { g_main_loop_quit(main_loop); break; } /* intentional fall over */ default: exit(EINTR); } } static int daemonize(uid_t uid, const char *path) { pid_t pid; int fd; if ((pid = fork()) < 0) return -1; else if (pid > 0) _Exit(0); /* parent exits */ else { /* child continues */ if (setsid() < 0) /* new child session; get rid of ctty */ return -1; if (uid > 0 && setuid(uid) < 0) return -1; if (path && chdir(path) < 0) return -1; if ((fd = open("/dev/null", O_RDWR, 0)) < 0) return -1; if (dup2(fd, fileno(stdin)) < 0 || dup2(fd, fileno(stdout)) < 0 || dup2(fd, fileno(stderr)) < 0 ) return -1; if (fd != fileno(stdin) && fd != fileno(stdout) && fd != fileno(stderr) ) close(fd); } return 0; } /* * Local Variables: * c-basic-offset: 4 * indent-tabs-mode: nil * End: */
722,082
./tone-generator/src/rfc4733.c
/************************************************************************* This file is part of tone-generator Copyright (C) 2010 Nokia Corporation. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation version 2.1 of the License. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *************************************************************************/ #define _GNU_SOURCE #include <math.h> #include <stdlib.h> #include <string.h> #include <errno.h> #include <log/log.h> #include <trace/trace.h> #include "tonegend.h" #include "dbusif.h" #include "tone.h" #include "indicator.h" #include "dtmf.h" #include "rfc4733.h" #define LOG_ERROR(f, args...) log_error(logctx, f, ##args) #define LOG_INFO(f, args...) log_error(logctx, f, ##args) #define LOG_WARNING(f, args...) log_error(logctx, f, ##args) #define TRACE(f, args...) trace_write(trctx, trflags, trkeys, f, ##args) struct method { char *intf; /* interface name */ char *memb; /* method name */ char *sig; /* signature */ int (*func)(DBusMessage *, struct tonegend *); /* implementing function */ }; static int start_event_tone(DBusMessage *, struct tonegend *); static int stop_tone(DBusMessage *, struct tonegend *); static int stop_event_tone(DBusMessage *, struct tonegend *); static uint32_t linear_volume(int); #define TONE_INDICATOR 0 #define TONE_DTMF 1 #define DBUS_SENDER_MAXLEN 16 static char tone_sender[2][DBUS_SENDER_MAXLEN]; static struct method method_defs[] = { {NULL, "StartEventTone", "uiu", start_event_tone}, {NULL, "StartNotificationTone", "uiu", start_event_tone}, /* backward compatible */ {NULL, "StopTone", "", stop_tone}, {NULL, "StopEventTone", "u", stop_event_tone}, {NULL, NULL, NULL, NULL} }; int rfc4733_init(int argc, char **argv) { (void)argc; (void)argv; return 0; } int rfc4733_create(struct tonegend *tonegend) { struct method *m; int err; int sts; for (m = method_defs, err = 0; m->memb != NULL; m++) { sts = dbusif_register_input_method(tonegend, m->intf, m->memb, m->sig, m->func); if (sts < 0) { LOG_ERROR("%s(): Can't register D-Bus method '%s'", __FUNCTION__, m->memb); err = -1; } } return err; } static int start_event_tone(DBusMessage *msg, struct tonegend *tonegend) { struct ausrv *ausrv = tonegend->ausrv_ctx; uint32_t event; int32_t dbm0; uint32_t duration; uint32_t volume; int indtype; int success; char *sender; success = dbus_message_get_args(msg, NULL, DBUS_TYPE_UINT32, &event, DBUS_TYPE_INT32 , &dbm0, DBUS_TYPE_UINT32, &duration, DBUS_TYPE_INVALID); if (!success) { LOG_ERROR("%s(): Can't parse arguments", __FUNCTION__); return FALSE; } volume = linear_volume(dbm0); TRACE("%s(): event %u volume %d dbm0 (%u) duration %u msec", __FUNCTION__, event, dbm0, volume, duration); sender = (char *)dbus_message_get_sender(msg); if (event < DTMF_MAX) { if (tone_sender[TONE_DTMF][0]) TRACE("%s(): got request to play the second DTMF tone", __FUNCTION__); strncpy(tone_sender[TONE_DTMF], sender, DBUS_SENDER_MAXLEN); dtmf_play(ausrv, event, volume, 0); } else { switch (event) { case 66: indtype = TONE_DIAL; break; case 72: indtype = TONE_BUSY; break; case 73: indtype = TONE_CONGEST; break; case 256: indtype = TONE_RADIO_ACK; break; case 257: indtype = TONE_RADIO_NA; break; case 74: indtype = TONE_ERROR; break; case 79: indtype = TONE_WAIT; break; case 70: indtype = TONE_RING; break; default: LOG_ERROR("%s(): invalid event %d", __FUNCTION__, event); return FALSE; } if (tone_sender[TONE_INDICATOR][0]) TRACE("%s(): got request to play the second indicator tone", __FUNCTION__); strncpy(tone_sender[TONE_INDICATOR], sender, DBUS_SENDER_MAXLEN); indicator_play(ausrv, indtype, volume, duration * 1000); } return TRUE; } static int stop_event_tone(DBusMessage *msg, struct tonegend *tonegend) { struct ausrv *ausrv = tonegend->ausrv_ctx; uint32_t event; int success; success = dbus_message_get_args(msg, NULL, DBUS_TYPE_UINT32, &event, DBUS_TYPE_INVALID); if (!success) { LOG_ERROR("%s(): Can't parse arguments", __FUNCTION__); return FALSE; } TRACE("%s(): stop %d tone", __FUNCTION__, event); if (event < DTMF_MAX) { dtmf_stop(ausrv); tone_sender[TONE_DTMF][0] = 0; } else { indicator_stop(ausrv, KILL_STREAM); tone_sender[TONE_INDICATOR][0] = 0; } return TRUE; } static int stop_tone(DBusMessage *msg, struct tonegend *tonegend) { struct ausrv *ausrv = tonegend->ausrv_ctx; char *sender; (void)msg; sender = (char *)dbus_message_get_sender(msg); if (!strncmp(sender, tone_sender[TONE_DTMF], DBUS_SENDER_MAXLEN)) { TRACE("%s(): stop DTMF tone", __FUNCTION__); dtmf_stop(ausrv); tone_sender[TONE_DTMF][0] = 0; } else if (!strncmp(sender, tone_sender[TONE_INDICATOR], DBUS_SENDER_MAXLEN)) { TRACE("%s(): stop indicator tone", __FUNCTION__); indicator_stop(ausrv, KILL_STREAM); tone_sender[TONE_INDICATOR][0] = 0; } else { /* In fallback the safest variant is to stop both type of streams */ TRACE("%s(): stop DTMF and/or indicator tones", __FUNCTION__); dtmf_stop(ausrv); indicator_stop(ausrv, KILL_STREAM); tone_sender[TONE_DTMF][0] = 0; tone_sender[TONE_INDICATOR][0] = 0; } return TRUE; } /* * This function maps the RFC4733 defined * power level of 0dbm0 - -63dbm0 * to the linear range of 0 - 100 */ static uint32_t linear_volume(int dbm0) { double volume; /* volume on the scale 0-100 */ if (dbm0 > 0) dbm0 = 0; if (dbm0 < -63) dbm0 = -63; volume = pow(10.0, (double)(dbm0 + 63) / 20.0) / 14.125375446; return (uint32_t)(volume + 0.5); } /* * Local Variables: * c-basic-offset: 4 * indent-tabs-mode: nil * End: */
722,083
./tone-generator/src/tone.c
/************************************************************************* This file is part of tone-generator Copyright (C) 2010 Nokia Corporation. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation version 2.1 of the License. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *************************************************************************/ #define _GNU_SOURCE #include <math.h> #include <limits.h> #include <stdlib.h> #include <string.h> #include <errno.h> #include <log/log.h> #include <trace/trace.h> #include "stream.h" #include "envelop.h" #include "tone.h" #ifndef TRUE #define TRUE 1 #endif #ifndef FALSE #define FALSE 0 #endif #define LOG_ERROR(f, args...) log_error(logctx, f, ##args) #define LOG_INFO(f, args...) log_error(logctx, f, ##args) #define LOG_WARNING(f, args...) log_error(logctx, f, ##args) #define TRACE(f, args...) trace_write(trctx, trflags, trkeys, f, ##args) #define AMPLITUDE SHRT_MAX /* 32767 */ #define OFFSET 8192 #define SCALE 1024ULL static inline void singen_init(struct singen *singen, uint32_t freq, uint32_t rate, uint32_t volume) { double w = 2.0 * M_PI * ((double)freq / (double)rate); #if 0 if (volume < 0 ) volume = 0; #endif if (volume > 100) volume = 100; singen->m = 2.0 * cos(w) * (AMPLITUDE * OFFSET); singen->n0 = -sin(w) * (AMPLITUDE * OFFSET); singen->n1 = 0; singen->offs = volume ? (OFFSET * 100) / volume : LONG_MAX; } static inline int32_t singen_write(struct singen *singen) { uint64_t n2 = (singen->m * singen->n1) / (AMPLITUDE * OFFSET) - singen->n0; singen->n0 = singen->n1; singen->n1 = n2; return (int32_t)(singen->n0 / singen->offs); } static void setup_envelop_for_tone(struct tone *, int, uint32_t, uint32_t); int tone_init(int argc, char **argv) { (void)argc; (void)argv; return 0; } struct tone *tone_create(struct stream *stream, int type, uint32_t freq, uint32_t volume, uint32_t period, uint32_t play, uint32_t start, uint32_t duration) { struct tone *link = NULL; uint32_t time = stream->time; struct tone *next = (struct tone *)stream->data; struct tone *tone; if (!volume || !period || !play) return NULL; if ((tone = (struct tone *)malloc(sizeof(*tone))) == NULL) { LOG_ERROR("%s(): Can't allocate memory", __FUNCTION__); return NULL; } memset(tone, 0, sizeof(*tone)); if (tone_chainable(type) && duration > 0) { for (link = (struct tone *)stream->data; link; link = link->next) { if (link->type == type) { while (link->chain) link = link->chain; next = NULL; time = link->end / SCALE; break; } } } TRACE("%s(): %s", __FUNCTION__, link ? "chain" : "don't chain"); tone->next = next; tone->stream = stream; tone->type = type; tone->period = period; tone->play = play; tone->start = (uint64_t)(time + start) * SCALE; tone->end = duration ? tone->start + (uint64_t)(duration * SCALE) : 0; setup_envelop_for_tone(tone, type, play, duration); if (!freq) tone->backend = BACKEND_UNKNOWN; else { tone->backend = BACKEND_SINGEN; singen_init(&tone->singen, freq, stream->rate, volume); } if (link) link->chain = tone; else stream->data = (void *)tone; if (duration) stream->flush = FALSE; return tone; } void tone_destroy(struct tone *tone, int kill_chain) { struct stream *stream = tone->stream; struct tone *prev; struct tone *link; struct tone *chain; for (prev = (struct tone *)&stream->data; prev; prev = prev->next) { if (prev->next == tone) { TRACE("%s(%s_chain)", __FUNCTION__, kill_chain?"kill":"preserve"); if ((link = tone->chain) == NULL) prev->next = tone->next; else { if (kill_chain) { for (link = tone->chain; link; link = chain) { chain = link->chain; envelop_destroy(link->envelop); free(link); } prev->next = tone->next; } else { prev->next = link; link->next = tone->next; } } envelop_destroy(tone->envelop); free(tone); return; } } LOG_ERROR("%s(): Can't find the stream to be destoyed", __FUNCTION__); } int tone_chainable(int type) { switch (type) { case TONE_DTMF_L: case TONE_DTMF_H: case TONE_NOTE_0: return 1; default: return 0; } } uint32_t tone_write_callback(struct stream *stream, int16_t *buf, int len) { struct tone *tone; struct tone *next; uint64_t t, dt; uint32_t abst; uint32_t relt; int32_t sine; int32_t sample; int i; t = (uint64_t)stream->time * SCALE; dt = (1000000ULL * SCALE) / (uint64_t)stream->rate; if (stream->data == NULL) { memset(buf, 0, len*sizeof(*buf)); t += dt * (uint64_t)len; } else { for (i = 0; i < len; i++) { sample = 0; for (tone=(struct tone *)stream->data; tone!=NULL; tone=next) { next = tone->next; if (tone->end && tone->end < t) tone_destroy(tone, PRESERVE_CHAIN); else if (t > tone->start) { abst = (uint32_t)((t - tone->start) / SCALE); relt = abst % tone->period; if (relt < tone->play) { switch (tone->backend) { case BACKEND_SINGEN: sine = singen_write(&tone->singen); sample += envelop_apply(tone->envelop, sine, tone->reltime ? relt:abst); break; } } } } /* for */ #if 0 if (sample < SHRT_MIN || sample > SHRT_MAX) { TRACE("sample %d is out of range (%d - %d)", sample, SHRT_MIN, SHRT_MAX); } #endif if (sample > SHRT_MAX) buf[i] = SHRT_MAX; else if (sample < SHRT_MIN) buf[i] = SHRT_MIN; else buf[i] = sample; t += dt; } } return (uint32_t)(t / SCALE); } void tone_destroy_callback(void *data) { struct stream *stream; struct tone *tone; if ((tone = (struct tone *)data) != NULL) { stream = tone->stream; if (stream->data != data) LOG_ERROR("%s(): Confused with data structures", __FUNCTION__); else { while ((tone = (struct tone *)stream->data) != NULL) tone_destroy(tone, KILL_CHAIN); } } } static void setup_envelop_for_tone(struct tone *tone, int type, uint32_t play, uint32_t duration) { switch (type) { case TONE_DIAL: case TONE_DTMF_IND_L: case TONE_DTMF_IND_H: tone->reltime = FALSE; tone->envelop = envelop_create(ENVELOP_RAMP_LINEAR, 10000, 0,duration); break; case TONE_BUSY: case TONE_CONGEST: case TONE_RADIO_ACK: case TONE_RADIO_NA: case TONE_WAIT: case TONE_RING: case TONE_DTMF_L: case TONE_DTMF_H: tone->reltime = TRUE; tone->envelop = envelop_create(ENVELOP_RAMP_LINEAR, 10000, 0, play); break; case TONE_ERROR: tone->reltime = TRUE; tone->envelop = envelop_create(ENVELOP_RAMP_LINEAR, 3000, 0, play); break; default: break; } } /* * Local Variables: * c-basic-offset: 4 * indent-tabs-mode: nil * End: */
722,084
./tone-generator/src/note.c
/************************************************************************* This file is part of tone-generator Copyright (C) 2010 Nokia Corporation. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation version 2.1 of the License. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *************************************************************************/ #define _GNU_SOURCE #include <math.h> #include <stdlib.h> #include <string.h> #include <errno.h> #include <log/log.h> #include <trace/trace.h> #include "stream.h" #include "tone.h" #include "note.h" #define LOG_ERROR(f, args...) log_error(logctx, f, ##args) #define LOG_INFO(f, args...) log_error(logctx, f, ##args) #define LOG_WARNING(f, args...) log_error(logctx, f, ##args) #define TRACE(f, args...) trace_write(trctx, trflags, trkeys, f, ##args) static char *note_stream = STREAM_NOTES; static uint32_t frequencies[OCTAVE_DIM][NOTE_DIM] = { /* Ab A B H C Db D Eb E F Gb G*/ {0, 0, 220, 233, 247, 262, 277, 294, 311, 338, 349, 370, 392}, {0, 416, 440, 466, 494, 523, 554, 587, 622, 659, 698, 740, 784}, {0, 831, 880, 932, 988, 1047, 1109, 1175, 1245, 1319, 1397, 1488, 1568}, {0,1661, 1760, 1865, 1976, 2093, 2217, 2349, 2489, 2637, 2794, 2960, 3136}, {0,3322, 3520, 3729, 3951, 4186, 4434, 4698, 4978, 5274, 5588, 5920, 6272}, {0,6644, 7040, 7458, 7902, 8372, 8870, 9396, 9956,10548,11176,11840,12544} }; static int types[] = { TONE_NOTE_0, }; static uint32_t play_percent[STYLE_DIM] = { 30, /* Staccato */ 60, /* Natural */ 100 /* Continous */ }; int note_init(int argc, char **argv) { (void)argc; (void)argv; return 0; } void note_play(struct ausrv *ausrv, int note, int scale, int beat, int style, int fract, uint32_t vol, int idx) { struct stream *stream = stream_find(ausrv, note_stream); int octave = scale - 3; int type; uint32_t freq; uint32_t period; uint32_t play; uint32_t dur; if (note < 0 || note >= NOTE_DIM || octave < 0 || octave >= OCTAVE_DIM || beat < 0 || beat >= 200 || style < 0 || style >= STYLE_DIM || fract < 1 || fract > 32 || vol < 1 || vol > 100 || idx < 0 || idx >= (int)(sizeof(types)/sizeof(types[0]))) { return; } if (stream == NULL) { stream = stream_create(ausrv, note_stream, NULL, 0, tone_write_callback, tone_destroy_callback, NULL, NULL); if (stream == NULL) { LOG_ERROR("%s(): Can't create stream", __FUNCTION__); return; } } type = types[idx]; freq = frequencies[octave][note]; dur = 60000000 / (beat * fract); period = dur; play = (period * play_percent[style]) / 100; TRACE("%s(): freq %u period %u", __FUNCTION__, freq, period); tone_create(stream, type, freq, vol, period, play, 0, dur); } /* * Local Variables: * c-basic-offset: 4 * indent-tabs-mode: nil * End: */
722,085
./tone-generator/src/notification.c
/************************************************************************* This file is part of tone-generator Copyright (C) 2010 Nokia Corporation. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation version 2.1 of the License. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *************************************************************************/ #define _GNU_SOURCE #include <math.h> #include <stdlib.h> #include <string.h> #include <errno.h> #include <log/log.h> #include <trace/trace.h> #include "tonegend.h" #include "dbusif.h" #include "tone.h" #include "stream.h" #include "notification.h" #define LOG_ERROR(f, args...) log_error(logctx, f, ##args) #define LOG_INFO(f, args...) log_error(logctx, f, ##args) #define LOG_WARNING(f, args...) log_error(logctx, f, ##args) #define TRACE(f, args...) trace_write(trctx, trflags, trkeys, f, ##args) static char *notif_stream = STREAM_NOTIFICATION; struct method { char *intf; /* interface name */ char *memb; /* method name */ char *sig; /* signature */ int (*func)(DBusMessage *, struct tonegend *); /* implementing function */ }; static int start_notif_tone(DBusMessage *, struct tonegend *); static int stop_tone(DBusMessage *, struct tonegend *); static uint32_t linear_volume(int); static void notif_play(struct ausrv *ausrv, int type, uint32_t vol, int dur); static void notif_stop(struct ausrv *ausrv, int kill_stream); static struct method method_defs[] = { {NOTIF_INTERFACE, "StartNotificationTone", "uiu", start_notif_tone}, {NOTIF_INTERFACE, "StopTone", "", stop_tone}, {NULL, NULL, NULL, NULL} }; static void *notif_props = NULL; static uint32_t vol_scale = 100; int notif_init(int argc, char **argv) { (void)argc; (void)argv; return 0; } int notif_create(struct tonegend *tonegend) { struct method *m; int err; int sts; for (m = method_defs, err = 0; m->memb != NULL; m++) { sts = dbusif_register_input_method(tonegend, m->intf, m->memb, m->sig, m->func); if (sts < 0) { LOG_ERROR("%s(): Can't register D-Bus method '%s'", __FUNCTION__, m->memb); err = -1; } } return err; } static int start_notif_tone(DBusMessage *msg, struct tonegend *tonegend) { struct ausrv *ausrv = tonegend->ausrv_ctx; uint32_t event; int32_t dbm0; uint32_t duration; uint32_t volume; int beeptype; int success; success = dbus_message_get_args(msg, NULL, DBUS_TYPE_UINT32, &event, DBUS_TYPE_INT32 , &dbm0, DBUS_TYPE_UINT32, &duration, DBUS_TYPE_INVALID); if (!success) { LOG_ERROR("%s(): Can't parse arguments", __FUNCTION__); return FALSE; } volume = linear_volume(dbm0); TRACE("%s(): event %u volume %d dbm0 (%u) duration %u msec", __FUNCTION__, event, dbm0, volume, duration); switch (event) { case 66: beeptype = TONE_DIAL; break; case 72: beeptype = TONE_BUSY; break; case 73: beeptype = TONE_CONGEST; break; case 256: beeptype = TONE_RADIO_ACK; break; case 257: beeptype = TONE_RADIO_NA; break; case 74: beeptype = TONE_ERROR; break; case 79: beeptype = TONE_WAIT; break; case 70: beeptype = TONE_RING; break; default: LOG_ERROR("%s(): invalid event %d", __FUNCTION__, event); return FALSE; } notif_play(ausrv, beeptype, volume, duration * 1000); return TRUE; } static int stop_tone(DBusMessage *msg, struct tonegend *tonegend) { struct ausrv *ausrv = tonegend->ausrv_ctx; (void)msg; TRACE("%s()", __FUNCTION__); notif_stop(ausrv, TRUE); return TRUE; } /* * This function maps the RFC4733 defined * power level of 0dbm0 - -63dbm0 * to the linear range of 0 - 100 */ static uint32_t linear_volume(int dbm0) { double volume; /* volume on the scale 0-100 */ if (dbm0 > 0) dbm0 = 0; if (dbm0 < -63) dbm0 = -63; volume = pow(10.0, (double)(dbm0 + 63) / 20.0) / 14.125375446; return (vol_scale * (uint32_t)(volume + 0.5)) / 100; } static void notif_play(struct ausrv *ausrv, int type, uint32_t vol, int dur) { struct stream *stream = stream_find(ausrv, notif_stream); if (stream != NULL) notif_stop(ausrv, FALSE); else { stream = stream_create(ausrv, notif_stream, NULL, 0, tone_write_callback, tone_destroy_callback, notif_props, NULL); if (stream == NULL) { LOG_ERROR("%s(): Can't create stream", __FUNCTION__); return; } } switch (type) { case TONE_DIAL: tone_create(stream, type, 425, vol, 1000000, 1000000, 0,0); break; case TONE_BUSY: tone_create(stream, type, 425, vol, 1000000, 500000, 0,dur); break; case TONE_CONGEST: tone_create(stream, type, 425, vol, 400000, 200000, 0,dur); break; case TONE_RADIO_ACK: tone_create(stream, type, 425, vol, 200000, 200000, 0,200000); break; case TONE_RADIO_NA: tone_create(stream, type, 425, vol, 400000, 200000, 0,1200000); break; case TONE_ERROR: tone_create(stream, type, 900, vol, 2000000, 333333, 0,dur); tone_create(stream, type, 1400, vol, 2000000, 332857, 333333,dur); tone_create(stream, type, 1800, vol, 2000000, 300000, 666190,dur); break; case TONE_WAIT: tone_create(stream,type, 425, vol, 800000,200000, 0,1000000); tone_create(stream,type, 425, vol, 800000,200000, 4000000,1000000); break; case TONE_RING: tone_create(stream, type, 425, vol, 5000000, 1000000, 0,0); break; default: LOG_ERROR("%s(): invalid type %d", __FUNCTION__, type); break; } } static void notif_stop(struct ausrv *ausrv, int kill_stream) { struct stream *stream = stream_find(ausrv, notif_stream); struct tone *tone; struct tone *hd; if (stream != NULL) { if (kill_stream) stream_destroy(stream); else { /* destroy all but DTMF tones */ for (hd = (struct tone *)&stream->data; hd; hd = hd->next) { while ((tone=hd->next) != NULL && !tone_chainable(tone->type)) tone_destroy(tone, KILL_CHAIN); } } } } void notif_set_properties(char *propstring) { notif_props = stream_parse_properties(propstring); } void notif_set_volume(uint32_t volume) { vol_scale = volume; } /* * Local Variables: * c-basic-offset: 4 * indent-tabs-mode: nil * End: */
722,086
./tone-generator/src/envelop.c
/************************************************************************* This file is part of tone-generator Copyright (C) 2010 Nokia Corporation. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation version 2.1 of the License. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *************************************************************************/ #include <math.h> #include <limits.h> #include <stdlib.h> #include <string.h> #include <errno.h> #include <log/log.h> #include <trace/trace.h> #include "envelop.h" #ifndef TRUE #define TRUE 1 #endif #ifndef FALSE #define FALSE 0 #endif #define LOG_ERROR(f, args...) log_error(logctx, f, ##args) #define LOG_INFO(f, args...) log_error(logctx, f, ##args) #define LOG_WARNING(f, args...) log_error(logctx, f, ##args) #define TRACE(f, args...) trace_write(trctx, trflags, trkeys, f, ##args) static inline union envelop *ramp_create(int type, uint32_t length, uint32_t start, uint32_t end) { union envelop *envelop; struct envelop_ramp *ramp; struct envelop_ramp_def *up; struct envelop_ramp_def *down; if ((envelop = malloc(sizeof(struct envelop_ramp))) != NULL) { ramp = &envelop->ramp; up = &ramp->up; down = &ramp->down; memset(ramp, 0, sizeof(*ramp)); ramp->type = type; up->k1 = 100; up->k2 = length / up->k1; up->start = start; up->end = start + length; if (end < start + (length * 2)) { down->k1 = 1; down->k2 = 1; down->start = -1; down->end = -1; } else { down->k1 = 100; down->k2 = length / down->k1; down->start = end - length; down->end = end; } } return envelop; } static inline void ramp_update(union envelop *envelop, uint32_t length, uint32_t end) { struct envelop_ramp_def *down = &envelop->ramp.down; down->k1 = 100; down->k2 = length / down->k1; down->start = end - length; down->end = end; } static inline void ramp_destroy(union envelop *envelop) { (void) envelop; } static inline int32_t ramp_apply(union envelop *envelop, int32_t in,uint32_t t) { struct envelop_ramp_def *up = &envelop->ramp.up; struct envelop_ramp_def *down = &envelop->ramp.down; int32_t k3; if (t > up->start && t < up->end) { k3 = (int32_t)(t - up->start) / up->k1; return (in * k3) / up->k2; } if (t > down->start && t < down->end) { k3 = (int32_t)(down->end -t) / down->k1; return (in * k3) / down->k2; } return in; } int envelop_init(int argc, char **argv) { (void)argc; (void)argv; return 0; } union envelop *envelop_create(int type, uint32_t length, uint32_t start, uint32_t end) { union envelop *env = NULL; switch (type) { case ENVELOP_RAMP_LINEAR: env = ramp_create(type, length, start, end); break; default: break; } return env; } void envelop_update(union envelop *envelop, uint32_t length, uint32_t end) { if (envelop != NULL) { switch (envelop->type) { case ENVELOP_RAMP_LINEAR: ramp_update(envelop, length, end); break; default: break; } } } void envelop_destroy(union envelop *envelop) { if (envelop != NULL) { switch (envelop->type) { case ENVELOP_RAMP_LINEAR: ramp_destroy(envelop); break; default: break; } free(envelop); } } int32_t envelop_apply(union envelop *envelop, int32_t in, uint32_t t) { uint32_t out = in; if (envelop != NULL) { switch (envelop->type) { case ENVELOP_RAMP_LINEAR: out = ramp_apply(envelop, in, t); break; default: out = in; break; } } return out; } /* * Local Variables: * c-basic-offset: 4 * indent-tabs-mode: nil * End: */
722,087
./foozel/src/core.c
#include <stdlib.h> #include <unistd.h> #include <string.h> #include <stdio.h> #include <fcntl.h> #include <sys/mman.h> #include <errno.h> #include "core.h" #include "sort.h" #include "group.h" #include "mempool.h" #include "shared.h" int compare_checksum(gconstpointer a, gconstpointer b) { Node *x = (Node*)a; Node *y = (Node*)b; return g_strcmp0(g_checksum_get_string(x->cksum), g_checksum_get_string(y->cksum)); } void hash_node_mm(Node * node, int offset, unsigned int read_size) { void * p_mmap = NULL; int r_size = read_size; FILE * f_handle = NULL ; /* open file handle */ if ((f_handle = fopen(node->path, "r")) != NULL) { /* create mmap mapping */ if ((p_mmap = mmap(NULL, node->size, PROT_READ, MAP_PRIVATE, fileno(f_handle), 0)) != NULL) { if (offset) { g_checksum_update(node->fprint,(const guchar*)((char*)p_mmap + offset), (gsize)r_size); } else { g_checksum_update(node->cksum,(const guchar*)p_mmap, node->size); } } else { printf("mmap invalid: %s",node->path); exit(EXIT_FAILURE); } } else { printf("file descriptor invalid: %s", node->path); perror("\nfdopen: "); exit(EXIT_FAILURE); } fclose(f_handle); } void hash_node_fr(Node * node, int offset, unsigned int read_size) { FILE * fp = fopen(node->path, "r"); if (fp != NULL) { if (offset != 0) { fseek(fp, offset, SEEK_SET); } MemPool * mp = globals_get_mempool(); char *buffer = mempool_get(mp); int bytes_read = -1; int to_read = -1; do { to_read = (read_size > sizeof(buffer)) ? sizeof(buffer) : read_size; bytes_read = fread(buffer, 1, to_read, fp); g_checksum_update(node->fprint, (const guchar*)buffer, bytes_read); read_size = read_size - sizeof(buffer); } while (bytes_read == to_read); fclose(fp); mempool_release(mp, buffer); } }
722,088
./foozel/src/shared.c
#include "shared.h" #define BUFFER (1024 * 1024 * 4) static void set_defaults() { shared.size_files = 0; shared.size_dups = 0; shared.count_files = 0; shared.count_dupes = 0; shared.trashstack = mempool_init(BUFFER); } void init_globals() { /* some logging needed */ set_defaults(); } MemPool * globals_get_mempool() { return shared.trashstack; }
722,089
./foozel/src/mempool.c
#include "mempool.h" MemPool * mempool_init(int size) { MemPool * mp = g_slice_new(MemPool); mp->stack = NULL; mp->size = size; return mp; } void mempool_destroy(MemPool * pool) { if (pool->stack) { while(pool->stack) { gpointer data = (gpointer)g_trash_stack_pop(&(pool->stack)); g_slice_free1(pool->size, data); } g_slice_free(MemPool, pool); } else if (!(pool->stack)) { g_slice_free(MemPool, pool); } } char * mempool_get(MemPool * pool) { if (!(pool->stack)) { gpointer data = g_slice_alloc(pool->size); return (char*)data; } else { return g_trash_stack_pop(&(pool->stack)); } } void mempool_release(MemPool * pool, char * buf) { g_trash_stack_push(&(pool->stack), buf); }
722,090
./foozel/src/worker.c
#include <glib.h> #include "worker.h" #include "core.h" #include "group.h" #define BUFFER (1024 * 4) void fingerprint_sublist(GList * list) { GList * iter = list; while(iter != NULL) { Node* node = (Node*)iter->data; hash_node_fr(node, 0, node->size); iter = g_list_next(iter); } } void hash_sublist(GList * list) { GList * iter = list; while(iter != NULL) { Node* node = iter->data; hash_node_mm(node, 0, node->size); iter = g_list_next(iter); } } void fingerprint(GList * list) { GList * iter = list; while(iter != NULL) { Subnode* subnode = iter->data; GList * tmp = (GList*)subnode->sub_start; fingerprint_sublist(tmp); iter = g_list_next(iter); } } void hash(GList * list) { GList * iter = list; while(iter != NULL) { Subnode* subnode = iter->data; GList * sublist = (GList*)subnode->sub_start; hash_sublist(sublist); iter = g_list_next(iter); } }
722,091
./foozel/src/group.c
#include <glib.h> #include "group.h" #include "core.h" #include "sort.h" GList * group_list(GList * list) { GList * iter = list; GList * grouped_list = NULL; int new = 0; while(iter != NULL) { Subnode * new_node = g_slice_new(Subnode); new_node->sub_start = iter; grouped_list = g_list_append(grouped_list, new_node); Node* file_node = (Node*)iter->data; int current = new = file_node->size; while (current == new && iter != NULL) { iter = g_list_next(iter); if (iter != NULL) { file_node = (Node*)iter->data; new = file_node->size; if (new != current) { if (iter->prev != NULL) { iter->prev->next= NULL; } if (iter != NULL) { iter->prev = NULL; } } } } } return grouped_list; }
722,092
./foozel/src/traverse.c
#include <stdio.h> #include <fts.h> #include <glib.h> #include <stdlib.h> #include <string.h> #include "traverse.h" #include "sort.h" #include "core.h" #include "group.h" #include "shared.h" /* traverses given path */ void nodelist_new_from_paths(char * const * path_argv, GList ** list) { FTS* tree = fts_open(path_argv,FTS_LOGICAL,NULL); FTSENT * node; g_assert(list); while ((node = fts_read(tree)) != NULL) { if (node->fts_info & FTS_F) { Node * data_node = g_slice_new(Node); data_node->path = g_strdup(node->fts_path); data_node->size = node->fts_statp->st_size; data_node->inode = node->fts_statp->st_ino; data_node->dev_id = node->fts_statp->st_dev; data_node->cksum = g_checksum_new(G_CHECKSUM_MD5); data_node->fprint = g_checksum_new(G_CHECKSUM_MD5); data_node->duplicate = -1; *list = g_list_append(*list,data_node); shared.size_files += data_node->size; shared.count_files += 1; } } fts_close(tree); } /* frees g_slice allocated memory used by fts nodes */ void node_destroy(gpointer data) { Node * node = (Node*)data; g_free(node->path); if(node->cksum) { g_checksum_free(node->cksum); } if(node->fprint) { g_checksum_free(node->fprint); } g_slice_free(Node, node); } void subnode_destroy(gpointer data) { Subnode * subnode = data; g_slice_free(Subnode, subnode); } void sublist_free_full(GList* list) { GList * iter = list; while(iter != NULL) { Subnode* subnode = iter->data; GList * sub_list = subnode->sub_start; g_list_free_full(sub_list, node_destroy); iter = g_list_next(iter); } g_list_free_full(list, subnode_destroy); }
722,093
./foozel/src/print.c
#include <glib.h> #include "core.h" #include "group.h" #include "shared.h" #include <stdio.h> #include "color.h" /* prints a given glist structure */ void nodelist_print(GList * list) { GList * iter = list; while(iter != NULL) { Node * node = (Node*)iter->data; if(node->fprint) { // printf("[fingerprint: %s] \n",g_checksum_get_string(node->fprint)); } else { //printf("[fingerprint: None]"); } if(node->cksum) { //printf("[checksum: %s], ",g_checksum_get_string(node->cksum)); } else { //printf("[checksum: None]"); } //printf("[duplicate: %d], ",node->duplicate); //printf("[inode: %lu], ",(unsigned long)node->inode); //printf("[size: %lu], ",(unsigned long)node->size); //printf("[file: %s]",node->path); /*printf("dev_id: %lu, ",(unsigned long)node->dev_id);*/ if (node->duplicate == 1) { shared.count_dupes += 1; shared.size_dups += node->size; } iter = g_list_next(iter); } } void sublist_test_print(GList * list) { GList * iter = list; while(iter != NULL) { Subnode * sub_node = iter->data; /* get subnode struct*/ GList * liste = sub_node->sub_start; /* get glist from subnode struct*/ nodelist_print(liste); iter = g_list_next(iter); } cprintf(RED, "%lu files checked (%lu bytes).\n%lu duplicates found (%lu bytes).", shared.count_files, shared.size_files, shared.count_dupes, shared.size_dups); }
722,094
./foozel/src/sort.c
#include "sort.h" #include "core.h" #include "group.h" #include <glib.h> #include <sys/stat.h> #include "traverse.h" int compare_by_inode(gconstpointer a, gconstpointer b) { Node *x = (Node*)a; Node *y = (Node*)b; return (glong)x->inode - (glong)y->inode; } int compare_by_size(gconstpointer a, gconstpointer b) { Node *x = (Node*)a; Node *y = (Node*)b; return (glong)x->size - (glong)y->size; } GList * sort_list(GList * list, enum sort sort_by) { if (sort_by == SIZE) { return g_list_sort(list, compare_by_size); } else { return g_list_sort(list, compare_by_inode); } } /* wrapper function to sort list of glist nodes -> subodes */ GList * sort_groups(GList * list, enum sort sort_by) { GList *iter = list; while (iter != NULL) { Subnode * subnode = iter->data; if (sort_by == SIZE) { subnode->sub_start = g_list_sort(subnode->sub_start, compare_by_size); } else { subnode->sub_start = g_list_sort(subnode->sub_start, compare_by_inode); } iter = g_list_next(iter); } return list; } GList * filter_single(GList * list) { GList * iter = list; while(iter != NULL) { Subnode* subnode = iter->data; GList * tmp = subnode->sub_start; GList * next = NULL; if (tmp && g_list_length(tmp) <= 1) { g_list_free_full(tmp, node_destroy); next = g_list_next(iter); g_slice_free(Subnode, subnode); list = g_list_delete_link(list, iter); } iter = next; } return list; } GList * filter_non_equal(GList * list) { GList * iter = list; while(iter != NULL) { Subnode * subnode = iter->data; GList * tmp = subnode->sub_start; delete_non_equal(tmp); iter = g_list_next(iter); } return list; } void delete_non_equal(GList * list) { GList * iter = list; GList * tmp = NULL; while(iter != NULL) { tmp = g_list_next(iter); Node * orig_node = iter->data; while(tmp != NULL) { Node * cur_node = tmp->data; if (!(compare_checksum(cur_node, orig_node))) { cur_node->duplicate = 0; orig_node->duplicate = 1; } tmp = g_list_next(tmp); } iter = g_list_next(iter); } }
722,095
./foozel/src/main.c
#include <stdio.h> #include <stdlib.h> #include <glib.h> #include <string.h> #include <sys/stat.h> #include "cmdparser.h" #include "cmdtest.h" #include "traverse.h" #include "worker.h" #include "group.h" #include "sort.h" #include "print.h" #include "shared.h" /* just for testing purposes */ int main(int argc, char const *argv[]) { char * path[argc-1]; memcpy(path,&argv[1],(argc+1)*sizeof(char*)); for(int i=0; i < argc-1 ; i++) { printf("%s\n",*(path+i)); } init_globals(); GList * list = NULL; /* build list from files */ nodelist_new_from_paths(path, &list); /* sort list by size */ list = sort_list(list, SIZE); /* subdevide list in groups by size */ GList* grouped_list = group_list(list); /* sort groups by inode */ grouped_list = sort_groups(grouped_list, INODE); /* filter single items */ grouped_list = filter_single(grouped_list); fingerprint(grouped_list); //hash(grouped_list); grouped_list = filter_non_equal(grouped_list); sublist_test_print(grouped_list); sublist_free_full(grouped_list); return EXIT_SUCCESS; }
722,096
./foozel/src/cmdparser.c
#include <stdio.h> #include <stdlib.h> #include <getopt.h> #include <string.h> #include "cmdparser.h" /* structure of long opts for getopt_long function */ static struct option long_opts[] = { {"paranoid", no_argument, NULL, 'p'}, {"follow-links", no_argument, NULL, 'f'}, {"first-inode", no_argument, NULL, 'i'}, {"no-color", no_argument, NULL, 'c'}, {"stripped", no_argument, NULL, 's'}, {"empty", no_argument, NULL, 'e'}, {"verbosity", required_argument, NULL, 'v'}, {"depth", required_argument, NULL, 'd'}, {"filter", required_argument, NULL, 'r'}, {"exec", required_argument, NULL, 'x'}, {"minsize", required_argument, NULL, 'j'}, {"maxsize", required_argument, NULL, 'k'}, {"help", no_argument, NULL, 'h'}, {0,0,0,0} }; /* initializing settings with default values */ void set_default_opts(opt_cache * settings) { memset(settings,0,sizeof(opt_cache)); settings->verbosity = 2; } /* reads user options and fills in settings structure */ void get_opts(int argc, char **argv, opt_cache * settings) { int c = -1; while ((c = getopt_long (argc, argv, "pfisv:ced:mr:x:j:k:h", long_opts , NULL)) != -1) { switch (c) { case 'p': settings->paranoid = true; break; case 'f': settings->follow_links = true; break; case 'i': settings->del_first_inode = true; break; case 'c': settings->no_color = true; break; case 's': settings->search.stripped = true; break; case 'e': settings->search.empty = true; break; case 'v': settings->verbosity = strtoint(optarg); break; case 'd': settings->depth = strtoint(optarg); break; case 'r': settings->filter = optarg; break; case 'x': settings->exec_parm = optarg; break; case 'j': settings->size_min = strtoint(optarg); break; case 'k': settings->size_max = strtoint(optarg); break; case 'h': printf("This is a help dummy.\n"); break; case '?': /* getopt_long prints error message */ break; default: abort(); } } } /* small little helper ;) */ long strtoint(const char * optarg) { return strtol(optarg,NULL,10); }
722,097
./foozel/src/cmdtest.c
#include <stdio.h> #include <stdlib.h> #include "cmdparser.h" /* print struct funktion only for testing purposes */ void print_struct(opt_cache * settings) { printf("paranoid mode: %s\n",(settings->paranoid!=0) ? "yes" : "no"); printf("follow links: : %s\n",(settings->follow_links!=0) ? "yes" : "no"); printf("delete first inode: : %s\n",(settings->del_first_inode!=0) ? "yes" : "no"); printf("no color: : %s\n",(settings->no_color!=0) ? "yes" : "no"); printf("search stripped: : %s\n",(settings->search.stripped!=0) ? "yes" : "no"); printf("search empty: : %s\n",(settings->search.empty!=0) ? "yes" : "no"); printf("verbosity level: : %d\n",settings->verbosity); printf("depth: : %d\n",settings->depth); printf("filter: : %s\n",settings->filter); printf("exec command: : %s\n",settings->exec_parm); printf("size min: : %d\n",settings->size_min); printf("size max: : %d\n",settings->size_max); }
722,098
./foozel/src/color.c
#include <stdio.h> #include <stdarg.h> #include "color.h" void print_color(termcolor fg) { fprintf(stdout,"%c[0;%dm", 0x1B, fg + 30); } void reset_color() { fprintf(stdout,"%c[0m",0x1B); } void cprintf(termcolor c, const char *fmt, ...) { va_list ap; va_start(ap, fmt); print_color(c); vprintf(fmt, ap); reset_color(); va_end(ap); }
722,099
./clinfinity/Clinfinity.c4d/Vehicles.c4d/Frigate.c4d/Script.c
/*-- Frigate --*/ #strict 2 // this is a control point #include L_CP local flag; local t; public func Initialize() { SetAction("MakeSound"); flag = CreateObject(FLAG, 0, 0, NO_OWNER); flag->SetAction("FlyBase", this); } private func Captured() { flag->SetOwner(GetOwner()); return inherited(...); } public func CaptureTime() { return 400; } public func CaptureZone() { // on top of the platform, between the cannons return Find_InRect(-76, -34, 168, 57); } // pendle around, no solidmask though (yet) public func Pendle() { t++; var r = Cos(t, 100); var fsin=Sin(r, 1000, 100); var fcos=Cos(r, 1000, 100); SetObjDrawTransform ( +fcos, +fsin, (1000-fcos) - fsin, -fsin, +fcos, (1000-fcos) + fsin ); }
722,100
./clinfinity/Clinfinity.c4d/Vehicles.c4d/Drone.c4d/Script.c
/* Script: Drone Flying robot for drilling solid material. A drone needs a "home quarry" where it asks for coordinates of material veins and where it delivers the drilled products. After receiving a set of coordinates, the drone will move there and search a place to drill as nearby as possible. It will drill the material and collect the resulting objects. When a configurable number of these objects has been collected, the drone will fly back to its quarry and deliver the objects there. */ #strict 2 /* Constants: Movement DRNE_MovementAngleDeviation - When flying towards a target, this is the maximum deviation from flying straight. DRNE_MovementSpeed - Drone speed. DRNE_PreciseMovementDistance - When reaching this distance from its target, the drone will fly straight. DRNE_StopDistance - When reaching this distance from its target, the drone will stop. */ static const DRNE_MovementAngleDeviation = 20; static const DRNE_MovementSpeed = 15; static const DRNE_PreciseMovementDistance = 30; static const DRNE_StopDistance = 2; /* Constants: Drilling DRNE_DrillTime - Time (in frames) that the drilling animation is played. DRNE_DrillRadius - Radius of the drilled hole. DRNE_MaxRockCollection - Number of objects to collect before returning to the quarry. */ static const DRNE_DrillTime = 80; static const DRNE_DrillRadius = 10; static const DRNE_MaxRockCollection = 20; local creationFrame; local myQuarry; local drilledMaterial, collectedMaterial; local targetX, targetY; /* Function: CreateDrone Factory method for drones. The coordinates are relative to the calling object in local calls, otherwise global. *Note:* You should always create a drone using this method. Parameters: x - Horizontal coordinate. y - Vertical coordinate. owner - Owner of the created drone: Player index. Use NO_OWNER for ownerless drones. forQuarry - Home quarry of the drone. drilledMaterial - [optional] Name of the material to drill. collectedMaterial - [optional] ID of the objects to collect. Returns: The created drone. */ public func CreateDrone(int x, int y, int owner, object forQuarry, string drilledMaterial, id collectedMaterial) { var drone = CreateObject(DRNE, x, y, owner); drone->LocalN("myQuarry") = forQuarry; if(drilledMaterial != 0) { drone->LocalN("drilledMaterial") = drilledMaterial; } if(collectedMaterial != 0) { drone->LocalN("collectedMaterial") = collectedMaterial; } return drone; } protected func Initialize() { creationFrame = FrameCounter(); Stop(); drilledMaterial = "Metalearth"; collectedMaterial = ROCK; } protected func RejectCollect(id collectedObjectId, object collectedObject) { return collectedObjectId != collectedMaterial; } /* Section: Actions/Commands */ /* Function: MoveTo Tells the drone to move to a position. Parameters: x - Horizontal coordinate. y - Vertical coordinate. */ public func MoveTo(int x, int y) { targetX = x; targetY = y; if(GetAction() != "Fly") { SetAction("Fly"); } } /* Function: Stop Tells the drone to stop. */ public func Stop() { targetX = GetX(); targetY = GetY(); SetSpeed(0); if(GetAction() != "FlyIdle") { SetAction("FlyIdle"); SetPhase(Random(GetActMapVal("Length", GetAction()))); } } /* Function: Drill Makes the drone play the drilling animation. */ public func Drill() { if(GetAction() != "Drill") { SetAction("Drill"); } } protected func DecideAction() { var drillX, drillY; if(myQuarry == 0) { if(FrameCounter() > creationFrame) { if(GetAction() != "Idle") { SetAction("Idle"); FadeOut(); } } } else if(IsAtQuarry()) { MoveRockToQuarry(); if(myQuarry->~FindDrillingPosition(drillX, drillY)) { MoveTo(drillX, drillY); } } else if(ContentsCount(collectedMaterial) >= DRNE_MaxRockCollection) { MoveToQuarry(); } else if(IsOtherDroneDrillingHere(0, 0) || !IsRockHere(0, 0)) { if(FindDrillingPosition(drillX, drillY)) { MoveTo(drillX, drillY); } else { MoveToQuarry(); } } else { Drill(); } } private func MoveToQuarry() { var width = GetDefWidth(GetID(myQuarry)); var height = GetDefHeight(GetID(myQuarry)); var x = myQuarry->GetX() + RandomX(-width / 4, width / 4); var y = myQuarry->GetY() + RandomX(-height / 4, height / 4); MoveTo(x, y); } private func IsAtQuarry() { return InArray(myQuarry, FindObjects(Find_AtPoint(0, 0))); } private func MoveRockToQuarry() { var rocks = FindObjects(Find_ID(collectedMaterial), Find_Container(this)); for(var rock in rocks) { rock->Enter(myQuarry); } } private func IsOtherDroneDrillingHere(int x, int y) { return FindObject2(Find_ID(GetID()), Find_AtPoint(x, y), Find_Exclude(this), Find_Action("Drill")) != 0; } private func IsRockHere(int x, int y) { return GetMaterial(x, y) == Material(drilledMaterial); } private func FindDrillingPosition(&x, &y) { for(var radius = DRNE_DrillRadius * 2; radius < DRNE_DrillRadius * 10; radius += DRNE_DrillRadius) { var searchAngle = Random(360); for(var j = 0; j < 360; j += 10) { var searchX = Sin(searchAngle + j, radius); var searchY = -Cos(searchAngle + j, radius); if(!IsOtherDroneDrillingHere(searchX, searchY) && IsRockHere(searchX, searchY)) { x = searchX + GetX(); y = searchY + GetY(); return true; } } } return false; } /* Action-Calls */ protected func Idling() { SetPosition(targetX, targetY + Sin(GetPhase() * 360 / GetActMapVal("Length", GetAction()), 1)); } protected func Flying() { if(Distance(GetX(), GetY(), targetX, targetY) < DRNE_StopDistance) { Stop(); return; } var angle = Angle(GetX(), GetY(), targetX, targetY); if(Distance(GetX(), GetY(), targetX, targetY) > DRNE_PreciseMovementDistance) { var angle = RandomX(angle - DRNE_MovementAngleDeviation, angle + DRNE_MovementAngleDeviation); } var speedX = Sin(angle, DRNE_MovementSpeed); var speedY = -Cos(angle, DRNE_MovementSpeed); SetSpeed(speedX, speedY); } protected func Drilling() { Sound("drill*"); SetPosition(GetX(), GetY() + Sin(GetActTime() * 2 * 360 / GetActMapVal("Length", GetAction()), 1)); var colourIndex = Random(3); var red = GetMaterialColor(Material(drilledMaterial), colourIndex, 0); var green = GetMaterialColor(Material(drilledMaterial), colourIndex, 1); var blue = GetMaterialColor(Material(drilledMaterial), colourIndex, 2); CastParticles("MatSpark", RandomX(1, 3), RandomX(10, 20), 0, 4, 20, 40, RGBa(red, green, blue, 50), RGBa(red, green, blue, 50)); if(GetActTime() > DRNE_DrillTime) { SetAction("Fly"); BlastFree(0, 0, DRNE_DrillRadius); } }