Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Use standard function fmax() for doubles.
[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.
7  * All rights reserved.                                                     */
8
9 /* This program is free software; you can redistribute it and/or modify it
10  * under the terms of the license (GNU LGPL) which comes with this package. */
11
12 /* Warning: autogenerated, do not edit! */
13
14 #include <string>
15 #include <unordered_map>
16
17 #include \"src/mc/mc_dwarf.hpp\""
18
19 cat - > src/mc/mc_dwarf_tagnames.cpp <<EOF
20 $HEADER
21
22 namespace {
23 const std::unordered_map<int, const char*> tagname_map = {
24     {0x00, "DW_TAG_invalid"},
25 $(cat "$1" | grep DW_TAG_ | sed 's/.*\(DW_TAG_[^ ]*\) = \(0x[0-9a-f]*\).*/    {\2, "\1"},/')
26 };
27 }
28
29 namespace simgrid {
30 namespace dwarf {
31
32 /** \brief Get the name of a dwarf tag (DW_TAG_*) from its code
33  *
34  *  \param tag tag code (see the DWARF specification)
35  *  \return name of the tag
36  */
37 XBT_PRIVATE
38 const char *tagname(int tag)
39 {
40   auto name = tagname_map.find(tag);
41   return name == tagname_map.end() ? "DW_TAG_unknown" : name->second;
42 }
43
44 }
45 }
46 EOF
47
48 cat - > src/mc/mc_dwarf_attrnames.cpp << EOF
49 $HEADER
50
51 namespace {
52 const std::unordered_map<int, const char*> attrname_map = {
53 $(cat "$1" | grep DW_AT_ | sed 's/.*\(DW_AT_[^ ]*\) = \(0x[0-9a-f]*\).*/    {\2, "\1"},/')
54 };
55 }
56
57 namespace simgrid {
58 namespace dwarf  {
59
60 /** \brief Get the name of an attribute (DW_AT_*) from its code
61  *
62  *  \param attr attribute code (see the DWARF specification)
63  *  \return name of the attribute
64  */
65 XBT_PRIVATE
66 const char *attrname(int attr)
67 {
68   auto name = attrname_map.find(attr);
69   return name == attrname_map.end() ? "DW_AT_unknown" : name->second;
70 }
71
72 }
73 }
74 EOF