Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Save worker's context directly in TLS.
[simgrid.git] / tools / generate-dwarf-functions
index 6f503c2..301c2b5 100755 (executable)
@@ -1,9 +1,9 @@
-#!/bin/sh
+#!/usr/bin/env sh
 # Generate files from a given dwarf.h
 # Usage: tools/generate-dwarf-functions /usr/include/dwarf.h
 
-cat - > src/mc/mc_dwarf_tagnames.cpp <<EOF
-/* Copyright (c) 2014-2015. The SimGrid Team.
+HEADER="\
+/* Copyright (c) 2014-$(date +%Y). The SimGrid Team.
  * All rights reserved.                                                     */
 
 /* This program is free software; you can redistribute it and/or modify it
@@ -11,29 +11,34 @@ cat - > src/mc/mc_dwarf_tagnames.cpp <<EOF
 
 /* Warning: autogenerated, do not edit! */
 
-#include <dwarf.h>
-#include <elfutils/libdw.h>
+#include <string>
+#include <unordered_map>
+
+#include \"src/mc/mc_dwarf.hpp\""
 
-#include <xbt/base.h>
+cat - > src/mc/mc_dwarf_tagnames.cpp <<EOF
+$HEADER
+
+namespace {
+const std::unordered_map<int, const char*> tagname_map = {
+    {0x00, "DW_TAG_invalid"},
+$(cat "$1" | grep DW_TAG_ | sed 's/.*\(DW_TAG_[^ ]*\) = \(0x[0-9a-f]*\).*/    {\2, "\1"},/')
+};
+}
 
 namespace simgrid {
 namespace dwarf {
 
-/** \brief Get the name of a dwarf tag (DW_TAG_*) from its code
+/** @brief Get the name of a dwarf tag (DW_TAG_*) from its code
  *
- *  \param tag tag code (see the DWARF specification)
- *  \return name of the tag
+ *  @param tag tag code (see the DWARF specification)
+ *  @return name of the tag
  */
 XBT_PRIVATE
 const char *tagname(int tag)
 {
-  switch (tag) {
-$(cat "$1" | grep DW_TAG_ | sed 's/.*\(DW_TAG_[^ ]*\) = \(0x[0-9a-f]*\).*/  case \2: return "\1";/')
-  case DW_TAG_invalid:
-    return "DW_TAG_invalid";
-  default:
-    return "DW_TAG_unknown";
-  }
+  auto name = tagname_map.find(tag);
+  return name == tagname_map.end() ? "DW_TAG_unknown" : name->second;
 }
 
 }
@@ -41,34 +46,27 @@ $(cat "$1" | grep DW_TAG_ | sed 's/.*\(DW_TAG_[^ ]*\) = \(0x[0-9a-f]*\).*/  case
 EOF
 
 cat - > src/mc/mc_dwarf_attrnames.cpp << EOF
-/* Copyright (c) 2014-2015. The SimGrid Team.
- * All rights reserved.                                                     */
+$HEADER
 
-/* This program is free software; you can redistribute it and/or modify it
- * under the terms of the license (GNU LGPL) which comes with this package. */
-
-/* Warning: autogenerated, do not edit! */
-
-#include <dwarf.h>
-
-#include <xbt/base.h>
+namespace {
+const std::unordered_map<int, const char*> attrname_map = {
+$(cat "$1" | grep DW_AT_ | sed 's/.*\(DW_AT_[^ ]*\) = \(0x[0-9a-f]*\).*/    {\2, "\1"},/')
+};
+}
 
 namespace simgrid {
 namespace dwarf  {
 
-/** \brief Get the name of an attribute (DW_AT_*) from its code
+/** @brief Get the name of an attribute (DW_AT_*) from its code
  *
- *  \param attr attribute code (see the DWARF specification)
- *  \return name of the attribute
+ *  @param attr attribute code (see the DWARF specification)
+ *  @return name of the attribute
  */
 XBT_PRIVATE
 const char *attrname(int attr)
 {
-  switch (attr) {
-$(cat "$1" | grep DW_AT_ | sed 's/.*\(DW_AT_[^ ]*\) = \(0x[0-9a-f]*\).*/  case \2: return "\1";/')
-  default:
-    return "DW_AT_unknown";
-  }
+  auto name = attrname_map.find(attr);
+  return name == attrname_map.end() ? "DW_AT_unknown" : name->second;
 }
 
 }