2020-06-07 12:24:28 +08:00
|
|
|
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
# See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
|
2020-06-08 06:15:19 +08:00
|
|
|
import os
|
2020-06-07 12:24:28 +08:00
|
|
|
import string
|
|
|
|
import sys
|
|
|
|
|
2020-06-20 08:17:22 +08:00
|
|
|
__all__ = ["debug", "debug_enabled", "enable"]
|
2020-06-08 06:15:19 +08:00
|
|
|
|
|
|
|
_ENABLED = "NPCOMP_DEBUG" in os.environ
|
2020-06-07 12:24:28 +08:00
|
|
|
_formatter = string.Formatter()
|
|
|
|
|
|
|
|
|
2020-06-20 08:17:22 +08:00
|
|
|
def enable():
|
|
|
|
global _ENABLED
|
|
|
|
_ENABLED = True
|
|
|
|
|
|
|
|
|
|
|
|
def debug_enabled():
|
|
|
|
return _ENABLED
|
|
|
|
|
|
|
|
|
2020-06-07 12:24:28 +08:00
|
|
|
def debug(format_string, *args, **kwargs):
|
|
|
|
if not _ENABLED:
|
|
|
|
return
|
|
|
|
formatted = _formatter.vformat(format_string, args, kwargs)
|
|
|
|
print("DEBUG:", formatted, file=sys.stderr)
|