Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Unused import.
[simgrid.git] / tools / generate-dwarf-functions
1 #!/usr/bin/env sh
2 # Generate files from a given dwarf.h
3 # Usage: tools/generate-dwarf-functions /usr/include/dwarf.h
4
5 HEADER="\
6 /* Copyright (c) 2014-$(date +%Y). The SimGrid Team. All rights reserved.          */
7
8 /* This program is free software; you can redistribute it and/or modify it
9  * under the terms of the license (GNU LGPL) which comes with this package. */
10
11 /* Warning: autogenerated, do not edit! */
12
13 #include \"src/mc/inspect/mc_dwarf.hpp\"
14
15 #include <string>
16 #include <unordered_map>"
17
18 cat - > src/mc/inspect/mc_dwarf_tagnames.cpp <<EOF
19 $HEADER
20
21 namespace {
22 const std::unordered_map<int, const char*> tagname_map = {
23     {0x00, "DW_TAG_invalid"},
24 $(sed -n 's/.*\(DW_TAG_[^ ]*\) = \(0x[0-9a-f]*\).*/    {\2, "\1"},/p' -- "$1")
25 };
26 }
27
28 namespace simgrid::dwarf {
29
30 /** @brief Get the name of a dwarf tag (DW_TAG_*) from its code
31  *
32  *  @param tag tag code (see the DWARF specification)
33  *  @return name of the tag
34  */
35 XBT_PRIVATE
36 const char* tagname(int tag)
37 {
38   auto name = tagname_map.find(tag);
39   return name == tagname_map.end() ? "DW_TAG_unknown" : name->second;
40 }
41
42 } // namespace simgrid::dwarf
43 EOF
44
45 cat - > src/mc/inspect/mc_dwarf_attrnames.cpp << EOF
46 $HEADER
47
48 namespace {
49 const std::unordered_map<int, const char*> attrname_map = {
50 $(sed -n 's/.*\(DW_AT_[^ ]*\) = \(0x[0-9a-f]*\).*/    {\2, "\1"},/p' -- "$1")
51 };
52 }
53
54 namespace simgrid::dwarf {
55
56 /** @brief Get the name of an attribute (DW_AT_*) from its code
57  *
58  *  @param attr attribute code (see the DWARF specification)
59  *  @return name of the attribute
60  */
61 XBT_PRIVATE
62 const char* attrname(int attr)
63 {
64   auto name = attrname_map.find(attr);
65   return name == attrname_map.end() ? "DW_AT_unknown" : name->second;
66 }
67
68 } // namespace simgrid::dwarf
69 EOF