mirror of https://github.com/YosysHQ/yosys.git
libparse: fix quoting and negedge in filterlib -verilogsim
This commit is contained in:
parent
504b668ea6
commit
90553267b0
|
|
@ -25,6 +25,7 @@
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
#ifdef FILTERLIB
|
#ifdef FILTERLIB
|
||||||
#undef log_assert
|
#undef log_assert
|
||||||
|
|
@ -825,6 +826,12 @@ std::string func2vl(std::string str)
|
||||||
return LibertyExpression::parse(helper).vlog_str();
|
return LibertyExpression::parse(helper).vlog_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string vlog_identifier(std::string str)
|
||||||
|
{
|
||||||
|
str.erase(std::remove(str.begin(), str.end(), '\"'), str.end());
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
void event2vl(const LibertyAst *ast, std::string &edge, std::string &expr)
|
void event2vl(const LibertyAst *ast, std::string &edge, std::string &expr)
|
||||||
{
|
{
|
||||||
edge.clear();
|
edge.clear();
|
||||||
|
|
@ -867,13 +874,13 @@ void gen_verilogsim_cell(const LibertyAst *ast)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
CHECK_NV(ast->args.size(), == 1);
|
CHECK_NV(ast->args.size(), == 1);
|
||||||
printf("module %s (", ast->args[0].c_str());
|
printf("module %s (", vlog_identifier(ast->args[0]).c_str());
|
||||||
bool first = true;
|
bool first = true;
|
||||||
for (auto child : ast->children) {
|
for (auto child : ast->children) {
|
||||||
if (child->id != "pin")
|
if (child->id != "pin")
|
||||||
continue;
|
continue;
|
||||||
CHECK_NV(child->args.size(), == 1);
|
CHECK_NV(child->args.size(), == 1);
|
||||||
printf("%s%s", first ? "" : ", ", child->args[0].c_str());
|
printf("%s%s", first ? "" : ", ", vlog_identifier(child->args[0]).c_str());
|
||||||
first = false;
|
first = false;
|
||||||
}
|
}
|
||||||
printf(");\n");
|
printf(");\n");
|
||||||
|
|
@ -884,7 +891,7 @@ void gen_verilogsim_cell(const LibertyAst *ast)
|
||||||
printf(" reg ");
|
printf(" reg ");
|
||||||
first = true;
|
first = true;
|
||||||
for (auto arg : child->args) {
|
for (auto arg : child->args) {
|
||||||
printf("%s%s", first ? "" : ", ", arg.c_str());
|
printf("%s%s", first ? "" : ", ", vlog_identifier(arg).c_str());
|
||||||
first = false;
|
first = false;
|
||||||
}
|
}
|
||||||
printf(";\n");
|
printf(";\n");
|
||||||
|
|
@ -896,9 +903,10 @@ void gen_verilogsim_cell(const LibertyAst *ast)
|
||||||
CHECK_NV(child->args.size(), == 1);
|
CHECK_NV(child->args.size(), == 1);
|
||||||
const LibertyAst *dir = find_non_null(child, "direction");
|
const LibertyAst *dir = find_non_null(child, "direction");
|
||||||
const LibertyAst *func = child->find("function");
|
const LibertyAst *func = child->find("function");
|
||||||
printf(" %s %s;\n", dir->value.c_str(), child->args[0].c_str());
|
std::string var = vlog_identifier(child->args[0]);
|
||||||
|
printf(" %s %s;\n", dir->value.c_str(), var.c_str());
|
||||||
if (func != NULL)
|
if (func != NULL)
|
||||||
printf(" assign %s = %s; // %s\n", child->args[0].c_str(), func2vl(func->value).c_str(), func->value.c_str());
|
printf(" assign %s = %s; // %s\n", var.c_str(), func2vl(func->value).c_str(), func->value.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto child : ast->children)
|
for (auto child : ast->children)
|
||||||
|
|
@ -906,8 +914,8 @@ void gen_verilogsim_cell(const LibertyAst *ast)
|
||||||
if (child->id != "ff" || child->args.size() != 2)
|
if (child->id != "ff" || child->args.size() != 2)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
std::string iq_var = child->args[0];
|
std::string iq_var = vlog_identifier(child->args[0]);
|
||||||
std::string iqn_var = child->args[1];
|
std::string iqn_var = vlog_identifier(child->args[1]);
|
||||||
|
|
||||||
std::string clock_edge, clock_expr;
|
std::string clock_edge, clock_expr;
|
||||||
event2vl(child->find("clocked_on"), clock_edge, clock_expr);
|
event2vl(child->find("clocked_on"), clock_edge, clock_expr);
|
||||||
|
|
@ -970,8 +978,8 @@ void gen_verilogsim_cell(const LibertyAst *ast)
|
||||||
if (child->id != "latch" || child->args.size() != 2)
|
if (child->id != "latch" || child->args.size() != 2)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
std::string iq_var = child->args[0];
|
std::string iq_var = vlog_identifier(child->args[0]);
|
||||||
std::string iqn_var = child->args[1];
|
std::string iqn_var = vlog_identifier(child->args[1]);
|
||||||
|
|
||||||
std::string enable_edge, enable_expr;
|
std::string enable_edge, enable_expr;
|
||||||
event2vl(child->find("enable"), enable_edge, enable_expr);
|
event2vl(child->find("enable"), enable_edge, enable_expr);
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,12 @@
|
||||||
module dff (D, CLK, Q);
|
module dff (D, CLK, Q);
|
||||||
reg "IQ", "IQN";
|
reg IQ, IQN;
|
||||||
input D;
|
input D;
|
||||||
input CLK;
|
input CLK;
|
||||||
output Q;
|
output Q;
|
||||||
assign Q = IQ; // IQ
|
assign Q = IQ; // IQ
|
||||||
always @(posedge CLK) begin
|
always @(posedge CLK) begin
|
||||||
// "(D)"
|
// "(D)"
|
||||||
"IQ" <= D;
|
IQ <= D;
|
||||||
"IQN" <= ~(D);
|
IQN <= ~(D);
|
||||||
end
|
end
|
||||||
endmodule
|
endmodule
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ module imux2 (A, B, S, Y);
|
||||||
assign Y = (~((A&S)|(B&(~S)))); // "( (A * S) + (B * S') )'"
|
assign Y = (~((A&S)|(B&(~S)))); // "( (A * S) + (B * S') )'"
|
||||||
endmodule
|
endmodule
|
||||||
module dff (D, CLK, RESET, PRESET, Q, QN);
|
module dff (D, CLK, RESET, PRESET, Q, QN);
|
||||||
reg "IQ", "IQN";
|
reg IQ, IQN;
|
||||||
input D;
|
input D;
|
||||||
input CLK;
|
input CLK;
|
||||||
input RESET;
|
input RESET;
|
||||||
|
|
@ -51,26 +51,26 @@ module dff (D, CLK, RESET, PRESET, Q, QN);
|
||||||
assign QN = IQN; // "IQN"
|
assign QN = IQN; // "IQN"
|
||||||
always @(posedge CLK, posedge RESET, posedge PRESET) begin
|
always @(posedge CLK, posedge RESET, posedge PRESET) begin
|
||||||
if ((RESET) && (PRESET)) begin
|
if ((RESET) && (PRESET)) begin
|
||||||
"IQ" <= 0;
|
IQ <= 0;
|
||||||
"IQN" <= 0;
|
IQN <= 0;
|
||||||
end
|
end
|
||||||
else if (RESET) begin
|
else if (RESET) begin
|
||||||
"IQ" <= 0;
|
IQ <= 0;
|
||||||
"IQN" <= 1;
|
IQN <= 1;
|
||||||
end
|
end
|
||||||
else if (PRESET) begin
|
else if (PRESET) begin
|
||||||
"IQ" <= 1;
|
IQ <= 1;
|
||||||
"IQN" <= 0;
|
IQN <= 0;
|
||||||
end
|
end
|
||||||
else begin
|
else begin
|
||||||
// "D"
|
// "D"
|
||||||
"IQ" <= D;
|
IQ <= D;
|
||||||
"IQN" <= ~(D);
|
IQN <= ~(D);
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
endmodule
|
endmodule
|
||||||
module latch (D, G, Q, QN);
|
module latch (D, G, Q, QN);
|
||||||
reg "IQ", "IQN";
|
reg IQ, IQN;
|
||||||
input D;
|
input D;
|
||||||
input G;
|
input G;
|
||||||
output Q;
|
output Q;
|
||||||
|
|
@ -79,8 +79,8 @@ module latch (D, G, Q, QN);
|
||||||
assign QN = IQN; // "IQN"
|
assign QN = IQN; // "IQN"
|
||||||
always @* begin
|
always @* begin
|
||||||
if (G) begin
|
if (G) begin
|
||||||
"IQ" <= D;
|
IQ <= D;
|
||||||
"IQN" <= ~(D);
|
IQN <= ~(D);
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
endmodule
|
endmodule
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,13 @@
|
||||||
module dff1 (D, CLK, Q);
|
module dff1 (D, CLK, Q);
|
||||||
reg "IQ", "IQN";
|
reg IQ, IQN;
|
||||||
input D;
|
input D;
|
||||||
input CLK;
|
input CLK;
|
||||||
output Q;
|
output Q;
|
||||||
assign Q = IQ; // IQ
|
assign Q = IQ; // IQ
|
||||||
always @(posedge CLK) begin
|
always @(posedge CLK) begin
|
||||||
// !D
|
// !D
|
||||||
"IQ" <= (~D);
|
IQ <= (~D);
|
||||||
"IQN" <= ~((~D));
|
IQN <= ~((~D));
|
||||||
end
|
end
|
||||||
endmodule
|
endmodule
|
||||||
module dff2 (D, CLK, Q);
|
module dff2 (D, CLK, Q);
|
||||||
|
|
@ -23,7 +23,7 @@ module dff2 (D, CLK, Q);
|
||||||
end
|
end
|
||||||
endmodule
|
endmodule
|
||||||
module dffe (D, EN, CLK, Q, QN);
|
module dffe (D, EN, CLK, Q, QN);
|
||||||
reg "IQ", "IQN";
|
reg IQ, IQN;
|
||||||
input D;
|
input D;
|
||||||
input EN;
|
input EN;
|
||||||
input CLK;
|
input CLK;
|
||||||
|
|
@ -31,9 +31,9 @@ module dffe (D, EN, CLK, Q, QN);
|
||||||
assign Q = IQ; // "IQ"
|
assign Q = IQ; // "IQ"
|
||||||
output QN;
|
output QN;
|
||||||
assign QN = IQN; // "IQN"
|
assign QN = IQN; // "IQN"
|
||||||
always @(posedge (~CLK)) begin
|
always @(negedge CLK) begin
|
||||||
// ( D & EN ) | ( IQ & ! EN )
|
// ( D & EN ) | ( IQ & ! EN )
|
||||||
"IQ" <= ((D&EN)|(IQ&(~EN)));
|
IQ <= ((D&EN)|(IQ&(~EN)));
|
||||||
"IQN" <= ~(((D&EN)|(IQ&(~EN))));
|
IQN <= ~(((D&EN)|(IQ&(~EN))));
|
||||||
end
|
end
|
||||||
endmodule
|
endmodule
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue