2019-04-26 21:21:50 +02:00
|
|
|
# See LICENSE for licensing information.
|
|
|
|
|
#
|
2023-01-29 07:56:27 +01:00
|
|
|
# Copyright (c) 2016-2023 Regents of the University of California and The Board
|
2019-06-14 17:43:41 +02:00
|
|
|
# of Regents for the Oklahoma Agricultural and Mechanical College
|
|
|
|
|
# (acting for and on behalf of Oklahoma State University)
|
|
|
|
|
# All rights reserved.
|
2019-04-26 21:21:50 +02:00
|
|
|
#
|
2016-11-08 18:57:35 +01:00
|
|
|
import sys
|
2022-11-27 22:01:20 +01:00
|
|
|
import os
|
2023-10-05 23:55:05 +02:00
|
|
|
import datetime
|
2020-11-05 23:31:53 +01:00
|
|
|
import pdb
|
2022-11-27 22:01:20 +01:00
|
|
|
import inspect
|
|
|
|
|
from openram import globals
|
2016-11-08 18:57:35 +01:00
|
|
|
|
|
|
|
|
# the debug levels:
|
|
|
|
|
# 0 = minimum output (default)
|
|
|
|
|
# 1 = major stages
|
|
|
|
|
# 2 = verbose
|
|
|
|
|
# n = custom setting
|
|
|
|
|
|
2020-11-05 22:20:54 +01:00
|
|
|
|
2019-01-23 00:24:38 +01:00
|
|
|
def check(check, str):
|
2017-05-12 23:56:31 +02:00
|
|
|
if not check:
|
2019-01-30 17:42:25 +01:00
|
|
|
(frame, filename, line_number, function_name, lines,
|
|
|
|
|
index) = inspect.getouterframes(inspect.currentframe())[1]
|
2019-01-23 00:24:38 +01:00
|
|
|
sys.stderr.write("ERROR: file {0}: line {1}: {2}\n".format(
|
|
|
|
|
os.path.basename(filename), line_number, str))
|
2019-02-16 06:45:05 +01:00
|
|
|
log("ERROR: file {0}: line {1}: {2}\n".format(
|
2019-01-23 00:24:38 +01:00
|
|
|
os.path.basename(filename), line_number, str))
|
2019-01-13 23:34:46 +01:00
|
|
|
|
2020-11-05 22:20:54 +01:00
|
|
|
if globals.OPTS.debug:
|
|
|
|
|
pdb.set_trace()
|
2022-07-22 18:52:38 +02:00
|
|
|
|
2019-11-14 19:17:20 +01:00
|
|
|
assert 0
|
2016-11-08 18:57:35 +01:00
|
|
|
|
2019-01-23 00:24:38 +01:00
|
|
|
|
|
|
|
|
def error(str, return_value=0):
|
2016-11-08 18:57:35 +01:00
|
|
|
(frame, filename, line_number, function_name, lines,
|
|
|
|
|
index) = inspect.getouterframes(inspect.currentframe())[1]
|
2019-01-23 00:24:38 +01:00
|
|
|
sys.stderr.write("ERROR: file {0}: line {1}: {2}\n".format(
|
|
|
|
|
os.path.basename(filename), line_number, str))
|
2019-02-16 06:45:05 +01:00
|
|
|
log("ERROR: file {0}: line {1}: {2}\n".format(
|
2019-01-23 00:24:38 +01:00
|
|
|
os.path.basename(filename), line_number, str))
|
|
|
|
|
|
2020-11-05 22:20:54 +01:00
|
|
|
if globals.OPTS.debug:
|
|
|
|
|
pdb.set_trace()
|
2021-03-08 23:40:36 +01:00
|
|
|
|
2019-11-14 19:17:20 +01:00
|
|
|
assert return_value == 0
|
2019-01-13 23:34:46 +01:00
|
|
|
|
2016-11-08 18:57:35 +01:00
|
|
|
|
|
|
|
|
def warning(str):
|
|
|
|
|
(frame, filename, line_number, function_name, lines,
|
|
|
|
|
index) = inspect.getouterframes(inspect.currentframe())[1]
|
2019-01-23 00:24:38 +01:00
|
|
|
sys.stderr.write("WARNING: file {0}: line {1}: {2}\n".format(
|
|
|
|
|
os.path.basename(filename), line_number, str))
|
2019-02-16 06:45:05 +01:00
|
|
|
log("WARNING: file {0}: line {1}: {2}\n".format(
|
2019-01-23 00:24:38 +01:00
|
|
|
os.path.basename(filename), line_number, str))
|
2019-01-13 23:34:46 +01:00
|
|
|
|
2016-11-08 18:57:35 +01:00
|
|
|
|
2019-01-13 23:34:46 +01:00
|
|
|
def print_raw(str):
|
|
|
|
|
print(str)
|
|
|
|
|
log(str)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def log(str):
|
2023-10-05 23:55:05 +02:00
|
|
|
# Add timestamp at the beginning of the string
|
|
|
|
|
timestr = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S.%f")
|
|
|
|
|
str = "[{}] {}".format(timestr, str)
|
2019-02-16 06:45:05 +01:00
|
|
|
if globals.OPTS.output_name != '':
|
2019-02-14 00:21:16 +01:00
|
|
|
if log.create_file:
|
2019-02-21 19:23:30 +01:00
|
|
|
# We may have not yet read the config, so we need to ensure
|
|
|
|
|
# it ends with a /
|
|
|
|
|
# This is also done in read_config if we change the path
|
|
|
|
|
# FIXME: There's actually a bug here. The first few lines
|
|
|
|
|
# could be in one log file and after read_config it could be
|
|
|
|
|
# in another log file if the path or name changes.
|
|
|
|
|
if not globals.OPTS.output_path.endswith('/'):
|
|
|
|
|
globals.OPTS.output_path += "/"
|
2019-04-18 00:02:10 +02:00
|
|
|
if not os.path.isdir(globals.OPTS.output_path):
|
|
|
|
|
os.mkdir(globals.OPTS.output_path)
|
2019-02-14 00:21:16 +01:00
|
|
|
compile_log = open(globals.OPTS.output_path +
|
|
|
|
|
globals.OPTS.output_name + '.log', "w+")
|
|
|
|
|
log.create_file = 0
|
|
|
|
|
else:
|
|
|
|
|
compile_log = open(globals.OPTS.output_path +
|
|
|
|
|
globals.OPTS.output_name + '.log', "a")
|
|
|
|
|
|
|
|
|
|
if len(log.setup_output) != 0:
|
|
|
|
|
for line in log.setup_output:
|
|
|
|
|
compile_log.write(line)
|
|
|
|
|
log.setup_output = []
|
|
|
|
|
compile_log.write(str + '\n')
|
2019-01-23 00:24:38 +01:00
|
|
|
else:
|
2019-02-14 00:21:16 +01:00
|
|
|
log.setup_output.append(str + "\n")
|
2019-01-23 00:24:38 +01:00
|
|
|
|
|
|
|
|
|
2019-02-14 00:21:16 +01:00
|
|
|
# use a static list of strings to store messages until the global paths are set up
|
|
|
|
|
log.setup_output = []
|
2019-07-05 17:18:58 +02:00
|
|
|
log.create_file = True
|
2019-01-23 00:24:38 +01:00
|
|
|
|
2016-11-08 18:57:35 +01:00
|
|
|
|
|
|
|
|
def info(lev, str):
|
2022-11-27 22:01:20 +01:00
|
|
|
from openram.globals import OPTS
|
2022-07-26 21:20:15 +02:00
|
|
|
# 99 is a special never print level
|
|
|
|
|
if lev == 99:
|
|
|
|
|
return
|
|
|
|
|
|
2020-11-05 22:12:26 +01:00
|
|
|
if (OPTS.verbose_level >= lev):
|
2016-11-08 18:57:35 +01:00
|
|
|
frm = inspect.stack()[1]
|
|
|
|
|
mod = inspect.getmodule(frm[0])
|
2019-01-23 00:24:38 +01:00
|
|
|
# classname = frm.f_globals['__name__']
|
2019-10-03 01:26:02 +02:00
|
|
|
if mod.__name__ is None:
|
2019-01-23 00:24:38 +01:00
|
|
|
class_name = ""
|
2017-11-14 22:24:14 +01:00
|
|
|
else:
|
2019-01-23 00:24:38 +01:00
|
|
|
class_name = mod.__name__
|
2019-02-14 00:21:16 +01:00
|
|
|
print_raw("[{0}/{1}]: {2}".format(class_name,
|
|
|
|
|
frm[0].f_code.co_name, str))
|
2021-01-11 22:52:41 +01:00
|
|
|
|
2022-07-22 18:52:38 +02:00
|
|
|
|
2021-03-08 23:40:36 +01:00
|
|
|
def archive():
|
2022-11-27 22:01:20 +01:00
|
|
|
from openram.globals import OPTS
|
2021-03-08 23:40:36 +01:00
|
|
|
try:
|
|
|
|
|
OPENRAM_HOME = os.path.abspath(os.environ.get("OPENRAM_HOME"))
|
|
|
|
|
except:
|
|
|
|
|
error("$OPENRAM_HOME is not properly defined.", 1)
|
|
|
|
|
|
|
|
|
|
import shutil
|
|
|
|
|
zip_file = "{0}/{1}_{2}".format(OPENRAM_HOME, "fail_", os.getpid())
|
|
|
|
|
info(0, "Archiving failed files to {}.zip".format(zip_file))
|
|
|
|
|
shutil.make_archive(zip_file, 'zip', OPTS.openram_temp)
|
2021-01-11 22:52:41 +01:00
|
|
|
|
2022-07-22 18:52:38 +02:00
|
|
|
|
2021-01-11 22:52:41 +01:00
|
|
|
def bp():
|
|
|
|
|
"""
|
|
|
|
|
An empty function so you can set soft breakpoints in pdb.
|
|
|
|
|
Usage:
|
|
|
|
|
1) Add a breakpoint anywhere in your code with "import debug; debug.bp()".
|
2022-11-06 23:05:08 +01:00
|
|
|
2) Run "python3 -m pdb sram_compiler.py config.py" or "python3 -m pdb 05_bitcell_array.test" (for example)
|
2021-01-12 20:22:11 +01:00
|
|
|
3) When pdb starts, run "break debug.bp" to set a SOFT breakpoint. (Or you can add this to your ~/.pdbrc)
|
2021-01-11 22:52:41 +01:00
|
|
|
4) Then run "cont" to continue.
|
2022-07-22 18:52:38 +02:00
|
|
|
5) You can now set additional breakpoints or display commands
|
2021-01-11 22:52:41 +01:00
|
|
|
and whenever you encounter the debug.bp() they won't be "reset".
|
|
|
|
|
"""
|
|
|
|
|
pass
|