From e59a6b8df7cdfcbf36daab9aaf3121e4f176e2d0 Mon Sep 17 00:00:00 2001 From: Cary R Date: Mon, 13 Apr 2009 18:06:17 -0700 Subject: [PATCH] Warn the user if they use both a default and `timescale based delay. This patch add code to print a warning message if it finds both a default and `timescale based delays. The -Wall or more specifically the -Wtimescale flag can be used to find the module with the missing `timescale directive. --- Module.h | 3 ++- PDelays.cc | 22 ++++++++++++++++++++-- elab_scope.cc | 1 + elaborate.cc | 28 ++++++++++++++++++++++++++++ net_scope.cc | 14 +++++++++++++- netlist.h | 3 +++ netmisc.h | 4 ++++ pform.cc | 3 +++ 8 files changed, 74 insertions(+), 4 deletions(-) diff --git a/Module.h b/Module.h index d62da62d6..f5fb524fd 100644 --- a/Module.h +++ b/Module.h @@ -1,7 +1,7 @@ #ifndef __Module_H #define __Module_H /* - * Copyright (c) 1998-2008 Stephen Williams (steve@icarus.com) + * Copyright (c) 1998-2009 Stephen Williams (steve@icarus.com) * * This source code is free software; you can redistribute it * and/or modify it in source code form under the terms of the GNU @@ -105,6 +105,7 @@ class Module : public PScope, public LineInfo { /* These are the timescale for this module. The default is set by the `timescale directive. */ int time_unit, time_precision; + bool time_from_timescale; /* Task definitions within this module */ map tasks; diff --git a/PDelays.cc b/PDelays.cc index 85c6e42ac..06729fe3d 100644 --- a/PDelays.cc +++ b/PDelays.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999-2008 Stephen Williams (steve@icarus.com) + * Copyright (c) 1999-2009 Stephen Williams (steve@icarus.com) * * This source code is free software; you can redistribute it * and/or modify it in source code form under the terms of the GNU @@ -26,6 +26,11 @@ # include "verinum.h" # include "netmisc.h" +bool dly_used_no_timescale = false; +bool dly_used_timescale = false; +bool display_ts_dly_warning = true; + + PDelays::PDelays() { delete_flag_ = true; @@ -62,10 +67,23 @@ void PDelays::set_delays(const svector*del, bool df) static NetExpr*calculate_val(Design*des, NetScope*scope, const PExpr*expr) { - NetExpr*dex = expr->elaborate_expr(des, scope, -1, false); eval_expr(dex); + /* Print a warning if we find default and `timescale based + * delays in the design, since this is likely an error. */ + if (scope->time_from_timescale()) dly_used_timescale = true; + else dly_used_no_timescale = true; + + if (display_ts_dly_warning && + dly_used_no_timescale && dly_used_timescale) { + cerr << "warning: Found both default and " + "`timescale based delays. Use" << endl; + cerr << " -Wtimescale to find the " + "module(s) with no `timescale." << endl; + display_ts_dly_warning = false; + } + /* If the delay expression is a real constant or vector constant, then evaluate it, scale it to the local time units, and return an adjusted value. */ diff --git a/elab_scope.cc b/elab_scope.cc index 03bb3664a..b9b7f9e42 100644 --- a/elab_scope.cc +++ b/elab_scope.cc @@ -1062,6 +1062,7 @@ void PGModule::elaborate_scope_mod_instances_(Design*des, Module*mod, NetScope*s // Set time units and precision. my_scope->time_unit(mod->time_unit); my_scope->time_precision(mod->time_precision); + my_scope->time_from_timescale(mod->time_from_timescale); des->set_precision(mod->time_precision); // Look for module parameter replacements. The "replace" map diff --git a/elaborate.cc b/elaborate.cc index 44ee64ab2..e5674c474 100644 --- a/elaborate.cc +++ b/elaborate.cc @@ -1827,6 +1827,20 @@ static NetExpr*elaborate_delay_expr(PExpr*expr, Design*des, NetScope*scope) probe_expr_width(des, scope, expr); NetExpr*dex = elab_and_eval(des, scope, expr, -1); + /* Print a warning if we find default and `timescale based + * delays in the design, since this is likely an error. */ + if (scope->time_from_timescale()) dly_used_timescale = true; + else dly_used_no_timescale = true; + + if (display_ts_dly_warning && + dly_used_no_timescale && dly_used_timescale) { + cerr << "warning: Found both default and " + "`timescale based delays. Use" << endl; + cerr << " -Wtimescale to find the " + "module(s) with no `timescale." << endl; + display_ts_dly_warning = false; + } + /* If the delay expression is a real constant or vector constant, then evaluate it, scale it to the local time units, and return an adjusted NetEConst. */ @@ -3737,6 +3751,19 @@ void PSpecPath::elaborate(Design*des, NetScope*scope) const if (ndelays > 12) ndelays = 12; + /* Print a warning if we find default and `timescale based + * delays in the design, since this is likely an error. */ + if (scope->time_from_timescale()) dly_used_timescale = true; + else dly_used_no_timescale = true; + + if (display_ts_dly_warning && + dly_used_no_timescale && dly_used_timescale) { + cerr << "warning: Found both default and " + "`timescale based delays. Use" << endl; + cerr << " -Wtimescale to find the " + "module(s) with no `timescale." << endl; + display_ts_dly_warning = false; + } int shift = scope->time_unit() - des->get_precision(); /* Elaborate the delay values themselves. Remember to scale @@ -4301,6 +4328,7 @@ Design* elaborate(listroots) scope->set_line(rmod); scope->time_unit(rmod->time_unit); scope->time_precision(rmod->time_precision); + scope->time_from_timescale(rmod->time_from_timescale); scope->default_nettype(rmod->default_nettype); des->set_precision(rmod->time_precision); diff --git a/net_scope.cc b/net_scope.cc index ed9853f1a..e446ced91 100644 --- a/net_scope.cc +++ b/net_scope.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000-2008 Stephen Williams (steve@icarus.com) + * Copyright (c) 2000-2009 Stephen Williams (steve@icarus.com) * * This source code is free software; you can redistribute it * and/or modify it in source code form under the terms of the GNU @@ -46,12 +46,14 @@ NetScope::NetScope(NetScope*up, const hname_t&n, NetScope::TYPE t) default_nettype_ = up->default_nettype(); time_unit_ = up->time_unit(); time_prec_ = up->time_precision(); + time_from_timescale_ = up->time_from_timescale(); sib_ = up_->sub_; up_->sub_ = this; } else { default_nettype_ = NetNet::NONE; time_unit_ = 0; time_prec_ = 0; + time_from_timescale_ = false; assert(t == MODULE); } @@ -295,6 +297,11 @@ void NetScope::time_precision(int val) time_prec_ = val; } +void NetScope::time_from_timescale(bool val) +{ + time_from_timescale_ = val; +} + int NetScope::time_unit() const { return time_unit_; @@ -305,6 +312,11 @@ int NetScope::time_precision() const return time_prec_; } +bool NetScope::time_from_timescale() const +{ + return time_from_timescale_; +} + void NetScope::default_nettype(NetNet::Type nt) { default_nettype_ = nt; diff --git a/netlist.h b/netlist.h index 256c68ebe..a105a0506 100644 --- a/netlist.h +++ b/netlist.h @@ -773,9 +773,11 @@ class NetScope : public Attrib { void time_unit(int); void time_precision(int); + void time_from_timescale(bool); int time_unit() const; int time_precision() const; + bool time_from_timescale() const; void default_nettype(NetNet::Type); NetNet::Type default_nettype() const; @@ -883,6 +885,7 @@ class NetScope : public Attrib { unsigned def_lineno_; signed char time_unit_, time_prec_; + bool time_from_timescale_; NetNet::Type default_nettype_; NetEvent *events_; diff --git a/netmisc.h b/netmisc.h index 8a72b8b9e..5617a8255 100644 --- a/netmisc.h +++ b/netmisc.h @@ -231,4 +231,8 @@ const char *human_readable_op(const char op, bool unary = false); enum const_bool { C_NON, C_0, C_1, C_X }; const_bool const_logical(const NetExpr*expr); +extern bool dly_used_no_timescale; +extern bool dly_used_timescale; +extern bool display_ts_dly_warning; + #endif diff --git a/pform.cc b/pform.cc index 898af8ca3..0127297a1 100644 --- a/pform.cc +++ b/pform.cc @@ -342,6 +342,9 @@ void pform_startmodule(const char*name, const char*file, unsigned lineno, pform_cur_module = new Module(lex_name); pform_cur_module->time_unit = pform_time_unit; pform_cur_module->time_precision = pform_time_prec; + /* If we have a timescale file then the time information is from + * a timescale directive. */ + pform_cur_module->time_from_timescale = pform_timescale_file != 0; pform_cur_module->default_nettype = pform_default_nettype; FILE_NAME(pform_cur_module, file, lineno);