go-dump.cc 961 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // go-dump.cc -- Go frontend debug dumps.
  2. // Copyright 2009 The Go Authors. All rights reserved.
  3. // Use of this source code is governed by a BSD-style
  4. // license that can be found in the LICENSE file.
  5. #include "go-system.h"
  6. #include "go-c.h"
  7. #include "go-dump.h"
  8. namespace {
  9. // The list of dumps.
  10. Go_dump* dumps;
  11. } // End empty namespace.
  12. // Create a new dump.
  13. Go_dump::Go_dump(const char* name)
  14. : next_(dumps), name_(name), is_enabled_(false)
  15. {
  16. dumps = this;
  17. }
  18. // Enable a dump by name.
  19. bool
  20. Go_dump::enable_by_name(const char* name)
  21. {
  22. bool is_all = strcmp(name, "all") == 0;
  23. bool found = false;
  24. for (Go_dump* p = dumps; p != NULL; p = p->next_)
  25. {
  26. if (is_all || strcmp(name, p->name_) == 0)
  27. {
  28. p->is_enabled_ = true;
  29. found = true;
  30. }
  31. }
  32. return found;
  33. }
  34. // Enable a dump. Return 1 if this is a real name, 0 if not.
  35. GO_EXTERN_C
  36. int
  37. go_enable_dump(const char* name)
  38. {
  39. return Go_dump::enable_by_name(name) ? 1 : 0;
  40. }