<commit_before>/*
 * Copyright (C) 1995-2011 University of Karlsruhe.  All right reserved.
 *
 * This file is part of libFirm.
 *
 * This file may be distributed and/or modified under the terms of the
 * GNU General Public License version 2 as published by the Free Software
 * Foundation and appearing in the file LICENSE.GPL included in the
 * packaging of this file.
 *
 * Licensees holding valid libFirm Professional Edition licenses may use
 * this file in accordance with the libFirm Commercial License.
 * Agreement provided with the Software.
 *
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE.
 */

/**
 * @file
 * @brief   DWARF debugging info support
 * @author  <NAME>
 */
#include "config.h"

#include <stdio.h>
#include <stdlib.h>
#include <assert.h>

#include "bedwarf_t.h"
#include "obst.h"
#include "irprog.h"
#include "irgraph.h"
#include "tv.h"
#include "xmalloc.h"
#include "pmap.h"
#include "pdeq.h"
#include "pset_new.h"
#include "util.h"
#include "obst.h"
#include "array_t.h"
#include "irtools.h"
#include "lc_opts.h"
#include "lc_opts_enum.h"
#include "beabi.h"
#include "bemodule.h"
#include "beemitter.h"
#include "dbginfo.h"
#include "begnuas.h"

enum {
	LEVEL_NONE,
	LEVEL_BASIC,
	LEVEL_LOCATIONS,
	LEVEL_FRAMEINFO
};
static int debug_level = LEVEL_NONE;

/**
 * Usually we simply use the DW_TAG_xxx numbers for our abbrev IDs, but for
 * the cases where we need multiple ids with the same DW_TAG we define new IDs
 * here
 */
typedef enum custom_abbrevs {
	abbrev_void_pointer_type = 100,
	abbrev_unnamed_formal_parameter,
	abbrev_formal_parameter_no_location,
	abbrev_void_subroutine_type,
	abbrev_void_subprogram,
	abbrev_bitfield_member,
} custom_abbrevs;

/**
 * The dwarf handle.
 */
typedef struct dwarf_t {
	const ir_entity         *cur_ent;     /**< current method entity */
	unsigned                 next_type_nr; /**< next type number */
	pmap                    *file_map;    /**< a map from file names to number in file list */
	const char             **file_list;
	const ir_entity        **pubnames_list;
	pset_new_t               emitted_types;
	const char              *main_file;   /**< name of the main source file */
	const char              *curr_file;   /**< name of the current source file */
	unsigned                 label_num;
	unsigned                 last_line;
} dwarf_t;

static dwarf_t env;

static dwarf_source_language language;
static const char           *comp_dir;

static unsigned insert_file(const char *filename)
{
	unsigned num;
	void    *entry = pmap_get(env.file_map, filename);
	if (entry != NULL) {
		return PTR_TO_INT(entry);
	}
	ARR_APP1(const char*, env.file_list, filename);
	num = (unsigned)ARR_LEN(env.file_list);
	pmap_insert(env.file_map, filename, INT_TO_PTR(num));

	/* TODO: quote chars in string */<commit_msg>Resolve constness warning.<commit_after>/*
 * Copyright (C) 1995-2011 University of Karlsruhe.  All right reserved.
 *
 * This file is part of libFirm.
 *
 * This file may be distributed and/or modified under the terms of the
 * GNU General Public License version 2 as published by the Free Software
 * Foundation and appearing in the file LICENSE.GPL included in the
 * packaging of this file.
 *
 * Licensees holding valid libFirm Professional Edition licenses may use
 * this file in accordance with the libFirm Commercial License.
 * Agreement provided with the Software.
 *
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE.
 */

/**
 * @file
 * @brief   DWARF debugging info support
 * @author  <NAME>
 */
#include "config.h"

#include <stdio.h>
#include <stdlib.h>
#include <assert.h>

#include "bedwarf_t.h"
#include "obst.h"
#include "irprog.h"
#include "irgraph.h"
#include "tv.h"
#include "xmalloc.h"
#include "pmap.h"
#include "pdeq.h"
#include "pset_new.h"
#include "util.h"
#include "obst.h"
#include "array_t.h"
#include "irtools.h"
#include "lc_opts.h"
#include "lc_opts_enum.h"
#include "beabi.h"
#include "bemodule.h"
#include "beemitter.h"
#include "dbginfo.h"
#include "begnuas.h"

enum {
	LEVEL_NONE,
	LEVEL_BASIC,
	LEVEL_LOCATIONS,
	LEVEL_FRAMEINFO
};
static int debug_level = LEVEL_NONE;

/**
 * Usually we simply use the DW_TAG_xxx numbers for our abbrev IDs, but for
 * the cases where we need multiple ids with the same DW_TAG we define new IDs
 * here
 */
typedef enum custom_abbrevs {
	abbrev_void_pointer_type = 100,
	abbrev_unnamed_formal_parameter,
	abbrev_formal_parameter_no_location,
	abbrev_void_subroutine_type,
	abbrev_void_subprogram,
	abbrev_bitfield_member,
} custom_abbrevs;

/**
 * The dwarf handle.
 */
typedef struct dwarf_t {
	const ir_entity         *cur_ent;     /**< current method entity */
	unsigned                 next_type_nr; /**< next type number */
	pmap                    *file_map;    /**< a map from file names to number in file list */
	const char             **file_list;
	const ir_entity        **pubnames_list;
	pset_new_t               emitted_types;
	const char              *main_file;   /**< name of the main source file */
	const char              *curr_file;   /**< name of the current source file */
	unsigned                 label_num;
	unsigned                 last_line;
} dwarf_t;

static dwarf_t env;

static dwarf_source_language language;
static char                 *comp_dir;

static unsigned insert_file(const char *filename)
{
	unsigned num;
	void    *entry = pmap_get(env.file_map, filename);
	if (entry != NULL) {
		return PTR_TO_INT(entry);
	}
	ARR_APP1(const char*, env.file_list, filename);
	num = (unsigned)ARR_LEN(env.file_list);
	pmap_insert(env.file_map, filename, INT_TO_PTR(num));

	/* TODO: quote chars in string */
{'fraction_non_alphanumeric': 0.09753999655943575, 'fraction_numerical': 0.004472733528298641, 'mean_word_length': 3.448355011476664, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6837669', 'n_tokens_mistral': 1981, 'n_tokens_neox': 1883, 'n_words': 613}