Change assert to log_assert

This commit is contained in:
Roland Coeurjoly 2024-06-12 09:23:44 +02:00 committed by Emily Schmidt
parent 720429b1fd
commit 76371d177f
3 changed files with 12 additions and 15 deletions

View File

@ -17,7 +17,6 @@
* *
*/ */
#include <cassert>
#include "kernel/yosys.h" #include "kernel/yosys.h"
#include "kernel/drivertools.h" #include "kernel/drivertools.h"
#include "kernel/topo_scc.h" #include "kernel/topo_scc.h"
@ -38,7 +37,7 @@ const char *reserved_keywords[] = {
"int","long","mutable","namespace","new","noexcept","not","not_eq", "int","long","mutable","namespace","new","noexcept","not","not_eq",
"nullptr","operator","or","or_eq","private","protected","public", "nullptr","operator","or","or_eq","private","protected","public",
"reflexpr","register","reinterpret_cast","requires","return","short", "reflexpr","register","reinterpret_cast","requires","return","short",
"signed","sizeof","static","static_assert","static_cast","struct", "signed","sizeof","static","static_log_assert","static_cast","struct",
"switch","synchronized","template","this","thread_local","throw", "switch","synchronized","template","this","thread_local","throw",
"true","try","typedef","typeid","typename","union","unsigned", "true","try","typedef","typeid","typename","union","unsigned",
"using","virtual","void","volatile","wchar_t","while","xor","xor_eq", "using","virtual","void","volatile","wchar_t","while","xor","xor_eq",
@ -193,11 +192,11 @@ class CxxComputeGraphFactory {
public: public:
CxxComputeGraphFactory(CxxComputeGraph &g) : graph(g) {} CxxComputeGraphFactory(CxxComputeGraph &g) : graph(g) {}
T slice(T a, int in_width, int offset, int out_width) { T slice(T a, int in_width, int offset, int out_width) {
assert(offset + out_width <= in_width); log_assert(offset + out_width <= in_width);
return graph.add(CxxFunction(ID($$slice), out_width, {{ID(offset), offset}}), 0, std::array<T, 1>{a}); return graph.add(CxxFunction(ID($$slice), out_width, {{ID(offset), offset}}), 0, std::array<T, 1>{a});
} }
T extend(T a, int in_width, int out_width, bool is_signed) { T extend(T a, int in_width, int out_width, bool is_signed) {
assert(in_width < out_width); log_assert(in_width < out_width);
if(is_signed) if(is_signed)
return graph.add(CxxFunction(ID($sign_extend), out_width, {{ID(WIDTH), out_width}}), 0, std::array<T, 1>{a}); return graph.add(CxxFunction(ID($sign_extend), out_width, {{ID(WIDTH), out_width}}), 0, std::array<T, 1>{a});
else else
@ -250,7 +249,7 @@ public:
return graph.add(CxxFunction(ID($$pending), width), 0); return graph.add(CxxFunction(ID($$pending), width), 0);
} }
void update_pending(T pending, T node) { void update_pending(T pending, T node) {
assert(pending.function().name == ID($$pending)); log_assert(pending.function().name == ID($$pending));
pending.set_function(CxxFunction(ID($$buf), pending.function().width)); pending.set_function(CxxFunction(ID($$buf), pending.function().width));
pending.append_arg(node); pending.append_arg(node);
} }

View File

@ -20,7 +20,6 @@
#ifndef SIM_H #ifndef SIM_H
#define SIM_H #define SIM_H
#include <cassert>
#include <array> #include <array>
template<size_t n> template<size_t n>
@ -250,7 +249,7 @@ Signal<n> $shl(Signal<na> const& a, Signal<nb> const &b)
{ {
if(nb >= sizeof(int) * 8 - 1) if(nb >= sizeof(int) * 8 - 1)
for(size_t i = sizeof(int) * 8 - 1; i < nb; i++) for(size_t i = sizeof(int) * 8 - 1; i < nb; i++)
assert(!b[i]); log_assert(!b[i]);
size_t amount = as_int(b); size_t amount = as_int(b);
Signal<n> ret = $const<n>(0); Signal<n> ret = $const<n>(0);
if(amount < n){ if(amount < n){
@ -267,7 +266,7 @@ Signal<n> $shr(Signal<n> const& a, Signal<nb> const &b)
{ {
if(nb >= sizeof(int) * 8 - 1) if(nb >= sizeof(int) * 8 - 1)
for(size_t i = sizeof(int) * 8 - 1; i < nb; i++) for(size_t i = sizeof(int) * 8 - 1; i < nb; i++)
assert(!b[i]); log_assert(!b[i]);
size_t amount = as_int(b); size_t amount = as_int(b);
Signal<n> ret; Signal<n> ret;
for (size_t i = 0; i < n; i++) { for (size_t i = 0; i < n; i++) {
@ -284,7 +283,7 @@ Signal<n> $asr(Signal<n> const& a, Signal<nb> const &b)
{ {
if(nb >= sizeof(int) * 8 - 1) if(nb >= sizeof(int) * 8 - 1)
for(size_t i = sizeof(int) * 8 - 1; i < nb; i++) for(size_t i = sizeof(int) * 8 - 1; i < nb; i++)
assert(!b[i]); log_assert(!b[i]);
size_t amount = as_int(b); size_t amount = as_int(b);
Signal<n> ret; Signal<n> ret;
for (size_t i = 0; i < n; i++) { for (size_t i = 0; i < n; i++) {
@ -345,7 +344,7 @@ Signal<n+m> concat(Signal<n> const& a, Signal<m> const& b)
template<size_t n, size_t m> template<size_t n, size_t m>
Signal<n> $zero_extend(Signal<m> const& a) Signal<n> $zero_extend(Signal<m> const& a)
{ {
assert(n >= m); log_assert(n >= m);
Signal<n> ret; Signal<n> ret;
std::copy(a.begin(), a.end(), ret.begin()); std::copy(a.begin(), a.end(), ret.begin());
for(size_t i = m; i < n; i++) for(size_t i = m; i < n; i++)
@ -356,7 +355,7 @@ Signal<n> $zero_extend(Signal<m> const& a)
template<size_t n, size_t m> template<size_t n, size_t m>
Signal<n> $sign_extend(Signal<m> const& a) Signal<n> $sign_extend(Signal<m> const& a)
{ {
assert(n >= m); log_assert(n >= m);
Signal<n> ret; Signal<n> ret;
std::copy(a.begin(), a.end(), ret.begin()); std::copy(a.begin(), a.end(), ret.begin());
for(size_t i = m; i < n; i++) for(size_t i = m; i < n; i++)

View File

@ -17,7 +17,6 @@
* *
*/ */
#include <cassert>
#include "kernel/yosys.h" #include "kernel/yosys.h"
#include "kernel/drivertools.h" #include "kernel/drivertools.h"
#include "kernel/topo_scc.h" #include "kernel/topo_scc.h"
@ -328,11 +327,11 @@ class SmtlibComputeGraphFactory {
public: public:
SmtlibComputeGraphFactory(SmtlibModule &mod) : module(mod), graph(mod.compute_graph) {} SmtlibComputeGraphFactory(SmtlibModule &mod) : module(mod), graph(mod.compute_graph) {}
T slice(T a, int in_width, int offset, int out_width) { T slice(T a, int in_width, int offset, int out_width) {
assert(offset + out_width <= in_width); log_assert(offset + out_width <= in_width);
return node(extract(Arg(1), offset, out_width), out_width, {a}); return node(extract(Arg(1), offset, out_width), out_width, {a});
} }
T extend(T a, int in_width, int out_width, bool is_signed) { T extend(T a, int in_width, int out_width, bool is_signed) {
assert(in_width < out_width); log_assert(in_width < out_width);
if(is_signed) if(is_signed)
return node(SExpr {SExpr {"_", "sign_extend", out_width - in_width}, Arg(1)}, out_width, {a}); return node(SExpr {SExpr {"_", "sign_extend", out_width - in_width}, Arg(1)}, out_width, {a});
else else
@ -399,7 +398,7 @@ public:
return node(SExpr(), width, {}); return node(SExpr(), width, {});
} }
void update_pending(T pending, T node) { void update_pending(T pending, T node) {
assert(pending.function().expr.is_none()); log_assert(pending.function().expr.is_none());
pending.set_function(Node(Arg(1), pending.function().width)); pending.set_function(Node(Arg(1), pending.function().width));
pending.append_arg(node); pending.append_arg(node);
} }