I was trying to run a testbench on Verilog, but I keep running into some problems. I added the errors at the end for y'all to see them.
Here is the module:
module combinational_logic(
A,
B,
C,
D,
AnotCnotD,
BCDnot,
ACnotDnot,
F,
);
input A;
input B;
input C;
input D;
output F;
output AnotCnotD;
output BCDnot;
output ACnotDnot;
assign AnotCnotD = ~A&~C&D;
assign BCDnot = B&C&~D;
assign ACnotDnot = A&~C&~D;
assign F = AnotCnotD|CDnot|ACnotDnot;
endmodule
and here is the test:
`include "project4.v"
module tb_combLogic;
reg A;
reg B;
reg C;
reg D;
reg F;
wire AnotCnotD;
wire BCDnot;
wire ACnotDnot;
combinational_logic uut (
.A(A),
.B(B),
.C(C),
.D(D),
.AnotCnotD(AnotCnotD),
.BCDnot(BCDnot),
.ACnotDnot(ACnotDnot)
);
initial begin
$display("Start of Test.");
$dumpfile("comb_logic.vcd");
$dumpvars(0, project4_test);
$display("End of Test.");
end
endmodule
and here are the errors:
./project4.v:29: error: Unable to bind wire/reg/memory `CDnot' in `tb_combLogic.uut'
./project4.v:29: error: Unable to elaborate r-value: ((AnotCnotD)|(CDnot))|(ACnotDnot)
project4_test.v:31: error: Unable to bind wire/reg/memory `project4_test' in `tb_combLogic'
3 error(s) during elaboration.
The first 2 messages are letting you know that you do not have a signal named CDnot. You likely meant BCDnot. Change:
assign F = AnotCnotD|CDnot|ACnotDnot;
to:
assign F = AnotCnotD|BCDnot|ACnotDnot;
The third message is letting you know that you do not have a signal or module instance named project4_test. One way to fix this is to change:
$dumpvars(0, project4_test);
to:
$dumpvars;
This will dump all signals in both modules to the VCD file. For large designs, VCD files can be huge. But, you don't need to worry about that with this code.
Related
I added the yosys tag, though this question is probably more about nextpnr (which has no tag on this site).
I'm using yosys with nextpnr-ice40 on the following file.
When I dump the design with --post-route /path/to/nextpnr/python/dump_design.py (I didn't bother with the GUI), it seems as though it's using separate logic units for the DFF as for LUT4, whereas I would expect it to fuse them into one logic unit using the logic unit's built-in DFF.
In my run they end up on Bels X12/Y12/lc4 and X12/Y12/lc2, and the logic unit that hosts the LUT4 has the DFF disabled.
Am I not doing it correctly? I tried swapping the order of the instantiations in the input file to no avail.
module top(input clk, output blinky);
wire clk2;
wire blinky2;
wire blinky3;
SB_IO #(
.PIN_TYPE(6'b 1010_01),
.PULLUP(1'b 0)
) clk_buf (
.PACKAGE_PIN(clk),
.OUTPUT_ENABLE(1'b0),
.D_OUT_0(1'b0),
.D_IN_0(clk2)
);
SB_IO #(
.PIN_TYPE(6'b 1010_01),
.PULLUP(1'b 0)
) blinky_buf (
.PACKAGE_PIN(blinky),
.OUTPUT_ENABLE(1'b1),
.D_OUT_0(blinky2)
);
SB_LUT4 #(
.LUT_INIT(16'b0000_0000_0000_0000)
) lut(blinky2, blinky3, blinky3, blinky3, blinky3);
SB_DFF dff(blinky3 /* O */, clk2, blinky2 /* D */);
endmodule
Ah, found the answer myself. It's the .D_OUT_0(blinky2) that is preventing the packing optimization, as it requires the value before the DFF. Changing that to .D_OUT_0(blinky3) exhibits packing.
I am trying to instantiate a state machine at top level module and connect the states at top level ports to probe them as part of debug. I am trying something like this as in example below:
.state[0](DEBUG_1),
.state[1](DEBUG_2),
DEBUG_1 and DEBUG_2 are output ports in the top level module, and I want to probe these signals at the top logic.
The above is not working in SystemVerilog and gives errors. How else can this be done?
package states;
typedef enum logic [2:0] {RE = 3'b000,
NOR = 3'b001,
WD = 3'b011,
TO = 3'b010,
EVL = 3'b110,
DEC = 3'b111} state_t;
endpackage
import states::*;
module fsm (
input clk,
input reset,
output state_t state
);
import rtl_pkg::*;
import states::*;
module top (
output logic DEBUG_1,
output logic DEBUG_2
);
fsm fsm_inst (
.clk(sys_clk),
.reset(sys_reset),
.state[0](DEBUG_1),
.state[1](DEBUG_2),
.state[2](DEBUG_3),
);
ERROR - (VERI-1137) syntax error near '['
ERROR - module top ignored due to previous errors
Here is one way to get rid of the compile errors:
module top (
output logic DEBUG_1,
output logic DEBUG_2, DEBUG_3
);
// ... signal declarations
fsm fsm_inst (
.clk (sys_clk),
.reset (sys_reset),
.state ({DEBUG_3, DEBUG_2, DEBUG_1})
);
endmodule
Concatenate the 3 DEBUG bits using {}, then connect it directly to the state port.
I'm teaching myself Pro*C and this is a program with a cursor through records in a database, and it compiles and runs. It gets as a far as prompting "Enter a Guest_ID(type exit to terminate)>>". After that it errors as "Segmentation fault (core dumped)" if an integer is entered. If a string is entered, it seems to go into the conditional immediately inside the outer for loop at
if(nGuest_ID==0)
{
printf("BYE\n");
exit(0);
}
and prints "BYE" then exits. Since I'm still getting familiar with how variables are declared and fed in from SQL, I wasn't sure what declarations might be crucial for troubleshooting here so I'm leaving the code largely intact here.
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
exec sql include sqlca;
// OK - Here we GO
void main()
{
// First, create all the variables that we will need to communicate between
// the "C" program and the database
exec sql begin declare section;
//VARCHAR sLastName[51], sFirstName[51], sHotelName[51], sCheckInDate[12], sRoom[11];
VARCHAR sLastName[51], sFirstName[51], sHotelName[51], sTransDate[11];
//int nDays, nGuest_ID, nCount;
int nGuest_ID, nQuantity, nUnitPrice, nCount, nHotelID, nItemID;
//VARCHAR sInCity[11];
VARCHAR sItemName[31], sTaxable[11];
VARCHAR sUserID[21], sPassword[21];
exec sql end declare section;
/////// begin needs work ///////
// Now define the cursor we will use to get all of the charges that the guest incurred at all hotels
exec sql declare dbGuest cursor for
Select G.Guest_ID, G.Last_Name, G.First_Name, C.Item_ID, C.Item_Name, C.Quantity, C.Unit_Price, C.Trans_Date, H.Hotel_Name, H.Hotel_ID, SI.Taxable
From Hotel H, Charge C, Stay S, Guest G, Sales_Item SI Where
C.Stay_ID=S.Stay_ID And H.Hotel_ID=S.Hotel_ID And G.Guest_ID=S.Guest_ID
And SI.Item_ID=C.Item_ID
Group By S.Guest_ID;
//////// end needs work ///////
// Set up the user-id and password to access my database
// Because we are using the local database on this server
// we don't need to use any database location or SID
strcpy(sUserID.arr,"myusername");
strcpy(sPassword.arr,"mypassword");
sUserID.len=strlen(sUserID.arr);
sPassword.len=strlen(sPassword.arr);
exec sql connect :sUserID identified by :sPassword;
// sqlca.sqlcode is a variable that is set based on the last command sent in to the database
// a value anything other than zero for what we just did (connect to the database) indicates
// a error.
if(sqlca.sqlcode !=0)
{
//printf("Sorry, cannot connect to server, pgm aborted %s\n",sqlca.sqlcode); //correction 2/5/14
printf("Sorry, cannot connect to server, pgm aborted %d\n",sqlca.sqlcode); //change to %d
exit(1);
}
//we made it here, so we were able to open the database correctly
exec sql SELECT COUNT(*) INTO :nCount FROM Guest;
printf ("There are %d Guests.\n",nCount);
for(;;){
// Read in through stdio the Guest we want to query, then set it up do we can use it
printf("Enter a Guest_ID(type exit to terminate)>>\n");
scanf("%d",nGuest_ID);
//Guest_ID.len= strlen(Guest_ID.arr);
if(nGuest_ID==0)
{
printf("BYE\n");
exit(0);
}
printf("%s %s %s %s %d\n","Charge Summary for:", sFirstName.arr, sLastName.arr, " Guest_ID:", nGuest_ID);
//printf("I do not work yet (type exit to terminate)>>\n");
// Open our cursor and begin reading records
exec sql open dbGuest;
for(;;)
{
//exec sql fetch dbGuest into :nGuest_ID, :sLastName, :sFirstName, :sHotelName, :sCheckInDate, :nDays, :sRoom;
exec sql fetch dbGuest into :nGuest_ID, :sLastName, :sFirstName, :nItemID, :sItemName, :nQuantity, :nUnitPrice, :sTransDate, :sHotelName, :nHotelID;
if(sqlca.sqlcode !=0) // If anything went wrong or we read past eof, stop the loop
{
break;
}
// Do the crazy stuff to end the C-Strings
sLastName.arr[sLastName.len] = 0;
sFirstName.arr[sFirstName.len] = 0;
sItemName.arr[sItemName.len] = 0;
sTransDate.arr[sTransDate.len] = 0;
sHotelName.arr[sHotelName.len] = 0;
// Print out the information for this guest
printf("%s %d %s %s \n", "Sales_Item: ", nItemID, " - ", sItemName.arr);
}
// close the cursor and end the program
exec sql close dbGuest ;
}
exit(0);
}
I'm sure I'm making some simple mistake but I didn't find anything helpful on search. I'm running this on a server, and I'm not getting any debugging back (this is the only major bug I haven't been able to solve up to this point), so what you have is what I have. Normally C programs would be run in debuggers but this is ProC and I'm kind of lost with the whole Oracle ProC debugging thing (since it's running on a remote database). With this kind of error I'd usually suspect not allocating memory properly, but I don't see anything like that here.
Went through these but not helpful:
Segmentation fault (core dumped) runtime error in C
Not so Useful Error -- Segmentation Fault (Core Dump) in Homework Assignment
Segmentation Fault(core dumped)
Segmentation fault (core dumped) read from stdin
Since nGuest_ID is an int, when calling scanf(), you'll need to provide address of nGuest_ID:
scanf("%d",&nGuest_ID);
That's the likely cause of the core dump you're experiencing, but, also, OracleUser made some excellent suggestions.
Hope that helps.
Please have a look at the following code
Formula.ads
package Formula is
procedure CalculateFormula;
end Formula;
Formula.adb
with Ada.Text_IO; use Ada.Text_IO;
with Formula; use Formula;
package body Formula is
procedure CalculateFormula is
package fom_io is new Ada.Float_Text_IO(Float);
use fom_io;
u : Float;
t : Float;
a : Float;
answer : Float;
begin
put_line("Enter 'U'");
get(u);
put_line("Enter 'T'");
get(t);
put_line("Enter 'A'");
get(a);
answer = (u*t)+ 0.5(a(t*t));
put("Answer is: ");
put(answer,Fore => 1,Aft => 1,Exp => 1);
end CalclualeFormula;
end Formula;
When I run this code, I get the following error
gnatmake -d -PC:\Users\yohan\Documents\Ada\Formula\formula.gpr
gcc -c -I- -gnatA C:\Users\yohan\Documents\Ada\Formula\formula.ads
cannot generate code for file formula.ads (package spec)
gnatmake: "C:\Users\yohan\Documents\Ada\Formula\formula.ads" compilation error
[2013-04-06 03:18:22] process exited with status 4 (elapsed time: 00.22s)
I am very new to Ada. Started coding few hours back. Please help me to get rid of the above issue. Thank you.
EDIT
formula.gpr
project Formula is
for Main use ("formula.ads");
end Formula;
The GPR file shows that you are trying to use a package specification as a main program unit - that doesn't work.
Two ways to fix this: The simplest one is to make "CalculateFormula" a standalone main program in a file "calculateformula.adb" and set this in your project file:
for Main use ("calculateformula.adb");
But if you want to see how packages work, there is a "better" way (in that it gets you to understand what packages are for and how they are used...)
Packages are reusable components : the package spec is all you need to see in order to use them ... but you actually use them in another program. So in this case you would create a main program
with Formula; use Formula;
procedure MyMain is
begin
CalculateFormula;
end MyMain;
and in the .gpr file,
for Main use ("mymain.adb");
And then the compiler will automatically compile the correct packages and find the other issues that Shark has pointed out.
You really don't need a separate Main here, as the "hello world" example showed. However such trivial "main subprograms" (in the correct Ada lingo) are not so unusual, especially for purposes like unit testing packages to be used in more complex apps later.
This is puzzling because there are some big errors that the compiler should be flagging, like:
package fom_io is new Ada.Float_Text_IO(Float);
which isn't withed, and
answer = (u*t)+ 0.5(a(t*t));
because:
= is not the assignment operator; you need :=.
0.5(XXXX) isn't valid multiplication.
Also, there's exponentiation in Ada, so t**2 can replace t*t.
formula.adb
with
Ada.Float_Text_IO,
Ada.Text_IO;
use
Ada.Text_IO;
package body Formula is
procedure CalculateFormula is
use Ada.Float_Text_IO;
u, t, a, answer : Float;
Procedure Prompt( Item : out Float; Name : String ) is
begin
put_line("Enter '"& Name &"'");
get(Item);
end prompt;
begin
prompt( u, "U" );
prompt( t, "T" );
prompt( a, "A" );
answer:= (u*t) + 0.5*( a*t**2 );
put("Answer is: ");
put(answer,Fore => 1,Aft => 1,Exp => 1);
New_Line;
end CalculateFormula;
end Formula;
This corrects the syntax errors you had. The other answer seems right in that this ["cannot generate code for" error] seems to be a problem with the gpr-file rather than the source itself.
Whenever I create a large Mathematica project I run into this problem: Preventing avalanche of runtime errors in Mathematica, i.e., Mathematica's error message are opaque, archaic, and legion.
The idea then is to disable all of Mathematica's own error messages and implement type checking and error messages of your own in every Function and Module. However I have not found a simple and efficient way of doing this and end up with, e.g., some function generating an error 20 function calls deep and then get a whole cascade of error messages all the way back up to the main routine.
How would you set up a simple mechanism for this that only generates one error message at the function that experiences the error and a simple list of the chain of function calls?
EDIT: Since it has come up in a couple of answers; I am specifically looking for something lightweight regarding the output it produces (otherwise I could just stick with Mathematica's error messages) and obviously also lightweight in computational overhead. So while Stack and Trace are definitely light on the overhead, their output in complex projects is not quick to parse and some work needs to be done simplifying it.
YAsI - Yet Another (silly?) Idea ...
Re-reading your question ...
The idea then is to disable all of Mathematica's own error messages and implement type checking and error messages of your own in every Function and Module.
Found this:
$MessagePrePrint = ( #; Print[Stack[_][[;; -5]]]; Abort[]) &
v[x_, y_] := w[x, y];
w[x_, y_] := x/y;
StackComplete#v[1, 0];
During evaluation of In[267]:= {StackComplete[v[1,0]];,
StackComplete[v[1,0]], v[1,0], w[1,0], 1/0, 1/0, Message[Power::infy,1/0]}
Out[267]= $Aborted
conclusion ... Aborts at first message and leaves a "reasonable" stack trace. "Reasonable" means "Should be improved".
But it is completely non-intrusive!
To get the ball rolling here is one idea that I've been toying with; the creation of a pseudo stack.
First make a global variable theStack={} and then in every Function or Module start with AppendTo[theStack,"thisFuncName"] and end with theStack=Most#theStack. Assuming moderate (~a few tens) depth of function calls, this should not add any significant overhead.
Then implement your own typing/error checking and use Print#theStack;Abort[]; on errors.
Refinements of this method could include:
Figuring out a way to dynamically get "thisFuncionName" so that the AppendTo[] can be made into an identical function call for all Functions and Module.
Using Message[] Instead of Print[].
Pushing other important variables / stateful information on theStack.
One attempt to implement #Timo's idea (theStack)
Incomplete and perhaps flawed, but just to keep thinking about it:
Clear["Global`*"];
funcDef = t_[args___] \[CircleMinus] a_ :>
{t["nude", args] := a,
ReleaseHold[Hold[t[args] :=
(If[! ValueQ[theStack], theStack = {}];
AppendTo[theStack, ToString[t]];
Check[ss = a, Print[{"-TheStack->", Evaluate#theStack}];
Print#Hold[a]; Abort[]];
theStack = Most#theStack;
Return[ss])
]]};
v[x_, y_]\[CircleMinus] (Sin# g[x, y]) /. funcDef;
g[x_, y_]\[CircleMinus] x/y /. funcDef;
v[2, 3]
v[2, 0]
Output:
Out[299]= Sin[2/3]
During evaluation of In[295]:= Power::infy: Infinite expression 1/0 encountered. >>
During evaluation of In[295]:= {-TheStack->,{v,g}}
During evaluation of In[295]:= Hold[2/0]
Out[300]= $Aborted
A suggestion for extracting stack, maybe something that relies on Trace?
An example of using Trace below, from Chris Chiasson. This code saves evaluation tree of 1 + Sin[x + y] + Tan[x + y] into ~/temp/msgStream.m
Developer`ClearCache[];
SetAttributes[recordSteps, HoldAll];
recordSteps[expr_] :=
Block[{$Output = List#OpenWrite["~/temp/msgStream.m"]},
TracePrint[Unevaluated[expr], _?(FreeQ[#, Off] &),
TraceInternal -> True];
Close /# $Output;
Thread[
Union#Cases[
ReadList["~/temp/msgStream.m", HoldComplete[Expression]],
symb_Symbol /;
AtomQ#Unevaluated#symb &&
Context#Unevaluated#symb === "System`" :>
HoldComplete#symb, {0, Infinity}, Heads -> True],
HoldComplete]
];
recordSteps[1 + Tan[x + y] + Sin[x + y]]
To answer Samsdram's question, the code below (also from Chris) gives evaluation tree of a Mathematica expression. Here is the post from MathGroup with source code and examples.
(Attributes## = {HoldAllComplete}) & /# {traceToTreeAux, toVertex,
HoldFormComplete, getAtoms, getAtomsAux}
MakeBoxes[HoldFormComplete[args___], form_] :=
MakeBoxes[HoldForm[args], form]
edge[{head1_, pos1_, xpr1_}, {head2_, pos2_, xpr2_}] :=
Quiet[Rule[{head1, vertexNumberFunction#pos1, xpr1}, {head2,
vertexNumberFunction#pos2, xpr2}], {Rule::"rhs"}]
getAtomsAux[atom_ /; AtomQ#Unevaluated#atom] :=
Sow[HoldFormComplete#atom, getAtomsAux]
getAtomsAux[xpr_] := Map[getAtomsAux, Unevaluated#xpr, Heads -> True]
getAtoms[xpr_] := Flatten#Reap[getAtomsAux#xpr][[2]]
toVertex[traceToTreeAux[HoldForm[heldXpr_], pos_]] := toVertex[heldXpr]
toVertex[traceToTreeAux[HoldForm[heldXprs___], pos_]] :=
toVertex#traceToTreeAux[Sequence[], pos]
(*this code is strong enough to not need the ToString commands,but \
some of the resulting graph vertices give trouble to the graphing \
routines*)
toVertex[
traceToTreeAux[xpr_, pos_]] := {ToString[
Short#Extract[Unevaluated#xpr, 0, HoldFormComplete], StandardForm],
pos, ToString[Short#First#originalTraceExtract#{pos}, StandardForm]}
traceToTreeAux[xpr_ /; AtomQ#Unevaluated#xpr, ___] := Sequence[]
traceToTreeAux[_HoldForm, ___] := Sequence[]
traceToTreeAux[xpr_, pos_] :=
With[{lhs = toVertex#traceToTreeAux[xpr, pos],
args = HoldComplete ## Unevaluated#xpr},
Identity[Sequence][
ReleaseHold[
Function[Null, edge[lhs, toVertex##], HoldAllComplete] /# args],
ReleaseHold#args]]
traceToTree[xpr_] :=
Block[{vertexNumber = -1, vertexNumberFunction,
originalTraceExtract},
vertexNumberFunction[arg_] :=
vertexNumberFunction[arg] = ++vertexNumber;
originalTraceExtract[pos_] :=
Extract[Unevaluated#xpr, pos, HoldFormComplete]; {MapIndexed[
traceToTreeAux, Unevaluated#xpr, {0, Infinity}]}]
TraceTreeFormPlot[trace_, opts___] :=
Block[{$traceExpressionToTree = True},
Through#{Unprotect, Update}#SparseArray`ExpressionToTree;
SparseArray`ExpressionToTree[trace, Infinity] = traceToTree#trace;
With[{result = ToExpression#ToBoxes#TreeForm[trace, opts]},
Through#{Unprotect, Update}#SparseArray`ExpressionToTree;
SparseArray`ExpressionToTree[trace, Infinity] =.;
Through#{Update, Protect, Update}#SparseArray`ExpressionToTree;
result]];
TraceTreeFormPlot[Trace[Tan[x] + Sin[x] - 2*3 - 55]]
Perhaps we have been over thinking this. What if we just tweaked the pattern matching on the arguments a little. For instance, if we modified the function to check for a numeric quantity and added some code to print an error if it fails. For instance,
TypeNumeric[x_] := If[! NumericQ[Evaluate[x]],
Print["error at "]; Print[Stack[]]; Print["Expression "]; Print[x]; Print["Did
not return a numeric value"];Return[False],
(*Else*)
Return[True];]
SetAttributes[TypeNumeric, HoldAll];
Step 2: If you have a function, f[x_] that requires a numeric quantity, just write it with the standard pattern test and all should be well
Input:
f[x_?TypeNumeric] := Sqrt[x]
f[Log[y]]
f[Log[5]]
Output:
error at
{f}
Expression
Log[y]
Did not return a numeric value
f[Log[y]]
Sqrt[Log[5]]
I believe this will work and, it makes robust type checking as simple as a writing a function or two. The problem is that this could be hugely inefficient because this code evaluates the expression x twice, once for the type checking and once for real. This could be bad if an expensive function call is involved.
I haven't figured out the way around this second problem and would welcome suggestions on that front. Are continuations the way out of this problem?
Hope this helps.