Skip to content

Commit

Permalink
Change assert to log_assert
Browse files Browse the repository at this point in the history
  • Loading branch information
RCoeurjoly committed Jun 12, 2024
1 parent c7f665e commit f6f009a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 15 deletions.
9 changes: 4 additions & 5 deletions backends/functional/cxx.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
*
*/

#include <cassert>
#include "kernel/yosys.h"
#include "kernel/drivertools.h"
#include "kernel/topo_scc.h"
Expand All @@ -38,7 +37,7 @@ const char *reserved_keywords[] = {
"int","long","mutable","namespace","new","noexcept","not","not_eq",
"nullptr","operator","or","or_eq","private","protected","public",
"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",
"true","try","typedef","typeid","typename","union","unsigned",
"using","virtual","void","volatile","wchar_t","while","xor","xor_eq",
Expand Down Expand Up @@ -193,11 +192,11 @@ class CxxComputeGraphFactory {
public:
CxxComputeGraphFactory(CxxComputeGraph &g) : graph(g) {}
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});
}
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)
return graph.add(CxxFunction(ID($sign_extend), out_width, {{ID(WIDTH), out_width}}), 0, std::array<T, 1>{a});
else
Expand Down Expand Up @@ -250,7 +249,7 @@ class CxxComputeGraphFactory {
return graph.add(CxxFunction(ID($$pending), width), 0);
}
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.append_arg(node);
}
Expand Down
11 changes: 5 additions & 6 deletions backends/functional/cxx_runtime/sim.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#ifndef SIM_H
#define SIM_H

#include <cassert>
#include <array>

template<size_t n>
Expand Down Expand Up @@ -250,7 +249,7 @@ Signal<n> $shl(Signal<na> const& a, Signal<nb> const &b)
{
if(nb >= sizeof(int) * 8 - 1)
for(size_t i = sizeof(int) * 8 - 1; i < nb; i++)
assert(!b[i]);
log_assert(!b[i]);
size_t amount = as_int(b);
Signal<n> ret = $const<n>(0);
if(amount < n){
Expand All @@ -267,7 +266,7 @@ Signal<n> $shr(Signal<n> const& a, Signal<nb> const &b)
{
if(nb >= sizeof(int) * 8 - 1)
for(size_t i = sizeof(int) * 8 - 1; i < nb; i++)
assert(!b[i]);
log_assert(!b[i]);
size_t amount = as_int(b);
Signal<n> ret;
for (size_t i = 0; i < n; i++) {
Expand All @@ -284,7 +283,7 @@ Signal<n> $asr(Signal<n> const& a, Signal<nb> const &b)
{
if(nb >= sizeof(int) * 8 - 1)
for(size_t i = sizeof(int) * 8 - 1; i < nb; i++)
assert(!b[i]);
log_assert(!b[i]);
size_t amount = as_int(b);
Signal<n> ret;
for (size_t i = 0; i < n; i++) {
Expand Down Expand Up @@ -345,7 +344,7 @@ Signal<n+m> concat(Signal<n> const& a, Signal<m> const& b)
template<size_t n, size_t m>
Signal<n> $zero_extend(Signal<m> const& a)
{
assert(n >= m);
log_assert(n >= m);
Signal<n> ret;
std::copy(a.begin(), a.end(), ret.begin());
for(size_t i = m; i < n; i++)
Expand All @@ -356,7 +355,7 @@ Signal<n> $zero_extend(Signal<m> const& a)
template<size_t n, size_t m>
Signal<n> $sign_extend(Signal<m> const& a)
{
assert(n >= m);
log_assert(n >= m);
Signal<n> ret;
std::copy(a.begin(), a.end(), ret.begin());
for(size_t i = m; i < n; i++)
Expand Down
7 changes: 3 additions & 4 deletions backends/functional/smtlib.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
*
*/

#include <cassert>
#include "kernel/yosys.h"
#include "kernel/drivertools.h"
#include "kernel/topo_scc.h"
Expand Down Expand Up @@ -328,11 +327,11 @@ class SmtlibComputeGraphFactory {
public:
SmtlibComputeGraphFactory(SmtlibModule &mod) : module(mod), graph(mod.compute_graph) {}
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});
}
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)
return node(SExpr {SExpr {"_", "sign_extend", out_width - in_width}, Arg(1)}, out_width, {a});
else
Expand Down Expand Up @@ -399,7 +398,7 @@ class SmtlibComputeGraphFactory {
return node(SExpr(), width, {});
}
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.append_arg(node);
}
Expand Down

0 comments on commit f6f009a

Please sign in to comment.