NC-Sim Tcl script tool?

D

Davy

Guest
Hi all,

I use NC-Sim Tcl command (like "stop") and found Tcl script is
white-space sensitive. And I have to wait for the Tcl report error in
run time and time-consuming. Can I debug/lint the Tcl script before run
all the simulation? Thanks!

Or is there something like Perl's "use strict" and "use warnings" in
Tcl? That I can write robust Tcl file in NC-Sim.

Thanks!
Davy
 
I use NC-Sim Tcl command (like "stop") and found Tcl script is
white-space sensitive. And I have to wait for the Tcl report error in
run time and time-consuming. Can I debug/lint the Tcl script before run
all the simulation? Thanks!

Or is there something like Perl's "use strict" and "use warnings" in
Tcl? That I can write robust Tcl file in NC-Sim.
Even if I don't use NC-Sim (we have ModelSim) I recognise your problem.
To help me check simulation and synthesis scripts before I start a long
run I wrote a Tcl syntax checker which later became "Nagelfar".

You can find it at http://nagelfar.berlios.de

/Peter
 
Davy wrote:
Hi all,

I use NC-Sim Tcl command (like "stop") and found Tcl script is
white-space sensitive. And I have to wait for the Tcl report error in
run time and time-consuming. Can I debug/lint the Tcl script before run
all the simulation? Thanks!
If you take a look at http://www.msen.com/~clif/TclLint.html, which is
a bit old, but give you some hint on what to look for.

Or is there something like Perl's "use strict" and "use warnings" in
Tcl? That I can write robust Tcl file in NC-Sim.
Tcl is developed a bit different than perl scripts since perl scripts
are compiled before they are run. Tcl scripts are evaluated in a two
pass algorithm (first time substitution then execution) and so you can
generate code dynamically which cannot be checked by a static linter.
The most common mistakes with missing spaces and braces and linefeeds
are an indication that one have to practice more with pure Tcl to get a
grip on the language.

This is normally done directly on the tclsh command line or with the
TkCon. If you are new to Tcl/Tk, I would recomend installing the
ActiveState distribution on a windows PC (if that is what you are most
convenient on) As you get the manuals and the applications readily
installed. Most operating systems have an old version of tclsh
installed as tclsh so beware. ActiveState also offer an integrated tcl
development environment in case you have money to pay for it. It will
not help you on NC-Sim command line, though.

Since Tcl is leaning towards the command line shell syntax, it is
normal to work your way from the core function outwards. In your case,
the core function will probably only be available inside NC-Sim command
line. The NC-Sim Tcl command will always return valid code (or it is a
bug) so your glue code will be able to read it. If you want to
experiment on the tclsh command line, then you would first define a
dummy "stop" function which return some typical data

proc stop {
return "This would be a typical return value from the stop command"
}

If you would be developing in TkCon you would use that function instead
of the NC-Sim function:

foreach retval [stop] {
puts $retval
}

My experience from tcl development is to check snippets in TkCon. When
they are working the way I want to, I copy-paste them into the program.
Perl do not offer this way of development, so you have to use the
modify-(compile)-run development strategy of perl. That is probably why
-w, use strict and friends are so useful for perl programmers.

If you are new to tcl, I suggest taking a look at http://wiki.tcl.tk
and news://comp.lang.tcl. The wiki is full of examples (Cadence should
offer the same for SKILL) and various comments. The search function is
a bit crap so rather use google and limit your search with a
site:wiki.tcl.tk in your search string. ("tcl lint site:wiki.tcl.tk")

This is probably the best dive-in page on tcl: http://wiki.tcl.tk/12927

--
Svenn
 
Peter Spjuth wrote:
I use NC-Sim Tcl command (like "stop") and found Tcl script is
white-space sensitive. And I have to wait for the Tcl report error in
run time and time-consuming. Can I debug/lint the Tcl script before run
all the simulation? Thanks!

Or is there something like Perl's "use strict" and "use warnings" in
Tcl? That I can write robust Tcl file in NC-Sim.

Even if I don't use NC-Sim (we have ModelSim) I recognise your problem.
To help me check simulation and synthesis scripts before I start a long
run I wrote a Tcl syntax checker which later became "Nagelfar".

[snip]
Hi Peter,

I notice "Naturally Nagelfar expects the coding style of its author so
if you do things differently, you may get false errors. "

Can you recommend the coding style used by Nagelfar?

Thanks!
Davy

You can find it at http://nagelfar.berlios.de

/Peter
 
Svenn Bjerkem wrote:
Davy wrote:
Hi all,

I use NC-Sim Tcl command (like "stop") and found Tcl script is
white-space sensitive. And I have to wait for the Tcl report error in
run time and time-consuming. Can I debug/lint the Tcl script before run
all the simulation? Thanks!

If you take a look at http://www.msen.com/~clif/TclLint.html, which is
a bit old, but give you some hint on what to look for.


Or is there something like Perl's "use strict" and "use warnings" in
Tcl? That I can write robust Tcl file in NC-Sim.

Tcl is developed a bit different than perl scripts since perl scripts
are compiled before they are run. Tcl scripts are evaluated in a two
pass algorithm (first time substitution then execution) and so you can
generate code dynamically which cannot be checked by a static linter.
The most common mistakes with missing spaces and braces and linefeeds
are an indication that one have to practice more with pure Tcl to get a
grip on the language.

This is normally done directly on the tclsh command line or with the
TkCon. If you are new to Tcl/Tk, I would recomend installing the
ActiveState distribution on a windows PC (if that is what you are most
convenient on) As you get the manuals and the applications readily
installed. Most operating systems have an old version of tclsh
installed as tclsh so beware. ActiveState also offer an integrated tcl
development environment in case you have money to pay for it. It will
not help you on NC-Sim command line, though.

Since Tcl is leaning towards the command line shell syntax, it is
normal to work your way from the core function outwards. In your case,
the core function will probably only be available inside NC-Sim command
line. The NC-Sim Tcl command will always return valid code (or it is a
bug) so your glue code will be able to read it. If you want to
experiment on the tclsh command line, then you would first define a
dummy "stop" function which return some typical data

proc stop {
return "This would be a typical return value from the stop command"
}

If you would be developing in TkCon you would use that function instead
of the NC-Sim function:

foreach retval [stop] {
puts $retval
}

My experience from tcl development is to check snippets in TkCon. When
they are working the way I want to, I copy-paste them into the program.
[snip]
Hi Svenn,

Thanks a lot :)

I have download a ActiveState Tcl tool. TkCon seems to be a
line-by-line Tcl interprator. Do you mean enter the line of code to
TkCon? Then run, and copy them out?

You mention a way to define a dummy proc to emulate the core function
in something like NC-Sim. But it seems the core function has a lot of
input. Shall I emulate all the input and output?

PS, IMHO, I like Perl more than Tcl :)

Best regards,
Davy

Perl do not offer this way of development, so you have to use the
modify-(compile)-run development strategy of perl. That is probably why
-w, use strict and friends are so useful for perl programmers.

If you are new to tcl, I suggest taking a look at http://wiki.tcl.tk
and news://comp.lang.tcl. The wiki is full of examples (Cadence should
offer the same for SKILL) and various comments. The search function is
a bit crap so rather use google and limit your search with a
site:wiki.tcl.tk in your search string. ("tcl lint site:wiki.tcl.tk")

This is probably the best dive-in page on tcl: http://wiki.tcl.tk/12927

--
Svenn
 
Davy schrieb:

I have download a ActiveState Tcl tool. TkCon seems to be a
line-by-line Tcl interprator. Do you mean enter the line of code to
TkCon? Then run, and copy them out?
It's a very quick and convenient way to test. For instance, here's
transcript of a short tclsh session in which I wanted to look at error
message formatting:
% namespace eval foo {}
% proc foo::f x {expr {$x/0}}
% proc foo::g x {f $x}
% g 42
ambiguous command name "g": gets glob global
% foo::g 42
divide by zero
% set errorInfo
divide by zero
while executing
"expr {$x/0}"
(procedure "f" line 1)
invoked from within
"f $x"
(procedure "foo::g" line 1)
invoked from within
"foo::g 42"
% exit
But you can of course also edit script files, and run them like this:
$ tclsh myfile.tcl

You mention a way to define a dummy proc to emulate the core function
in something like NC-Sim. But it seems the core function has a lot of
input. Shall I emulate all the input and output?
For a first shot, just to get something running, you can use the "args"
argument to a proc that will contain all its arguments:

proc myMain args {puts "called myMain with [llength $args] args";
return 42}

For refined testing, you then can go analyze what came in in the
arguments, and return something more interesting...

PS, IMHO, I like Perl more than Tcl :)
Matter of taste, of course...
 
Davy wrote:
Svenn Bjerkem wrote:
snip

PS, IMHO, I like Perl more than Tcl :)
I like some things in Perl and some things in Tcl. Tcl has much better
OO frameworks (I love Snit) but Perl has the DBI and CPAN. Those 2 keep
me using Perl. Though not CPAN so much. I actully think packages are
more simple in Tcl than in Perl (but that might be because I am an end
user and not a maintainer).

The Tcl community is by far the nicest and most informative of all the
ones I have participated in (i.e. Python, Ruby, Perl). That is a big
plus.

Robert
 
Robert Hicks schrieb:
Davy wrote:
Svenn Bjerkem wrote:
snip
PS, IMHO, I like Perl more than Tcl :)


I like some things in Perl and some things in Tcl. Tcl has much better
OO frameworks (I love Snit) but Perl has the DBI and CPAN. Those 2 keep
me using Perl. Though not CPAN so much. I actully think packages are
more simple in Tcl than in Perl (but that might be because I am an end
user and not a maintainer).
For something like DBI take a look at the things listed here:
http://wiki.tcl.tk/14972

Michael
 
Michael Schlenker wrote:
Robert Hicks schrieb:
Davy wrote:
Svenn Bjerkem wrote:
snip
PS, IMHO, I like Perl more than Tcl :)


I like some things in Perl and some things in Tcl. Tcl has much better
OO frameworks (I love Snit) but Perl has the DBI and CPAN. Those 2 keep
me using Perl. Though not CPAN so much. I actully think packages are
more simple in Tcl than in Perl (but that might be because I am an end
user and not a maintainer).

For something like DBI take a look at the things listed here:
http://wiki.tcl.tk/14972

Michael
Oh, I know all about that. : )

"nstcl" is the closest probably. I haven't used it yet but I am
thinking about it.

Luckily I use Oracle at work so I can use Oratcl. Todd is a great help.

:Robert
 
Davy wrote:
I notice "Naturally Nagelfar expects the coding style of its author so
if you do things differently, you may get false errors. "

Can you recommend the coding style used by Nagelfar?
I recommend reading http://wiki.tcl.tk/708.
I personally don't follow it all but it's a start.

Some style things that are checked are:

Indentation, or rather close brace alignment to opening statement.

Braced expressions. Since it is generally a really good idea to brace
your exprs.

Subcommands and options should not be abbreviated. If you do you run
the risk of failure if new options are added.

Enforce "else", as recommended by the guidelines.

/Peter
 
Davy wrote:
Hi Svenn,

Thanks a lot :)

I have download a ActiveState Tcl tool. TkCon seems to be a
line-by-line Tcl interprator. Do you mean enter the line of code to
TkCon? Then run, and copy them out?
I think Suchenwirth gave a nice little session example maybe a bit
advanced as he introduced namespaces in Lection 1, but on the other
hand it is important to understand the difference of local and global
variables between Tcl and Perl.

You can develop your procs in tkcon from scratch or you can copy-paste
them between the NC-Sim command line and tkcon. If you want to develop
a proc from scratch in tkcon you just start hacking right away:
1% proc hello {args} {
puts "Hello friend, you gave me $args to chew on"
}
2 % hello World
Hello friend, you gave me World to chew on
3 %

With the arrow buttons you go back in history, and if you want to
insert a line you use ctrl-Enter. When you are finished with the
editing, you press enter and the proc will be defined with your new
code.

After a long day of debugging, you can use "info body hello" and you
will get the body of your proc hello printed to the screen ready for
copy-paste.

The commands you use on tkcon commandline are also available from the
tclsh command line (but there you do not have such nice history
functions etc.)

One thing that I haven't tried is to load the tkcon code in the NC-Sim
environment. If that is possible then tkcon should be able to see the
NC-Sim specific modules. tkcon is a tcl application so it should be
able to run with any tcl interpreter. You would need to change the #!
or exec call at the beginning of tkcon.

I haven't tested this so I am not sure if it works.

PS, IMHO, I like Perl more than Tcl :)
As a Tool Command Language I think Tcl is better than Perl. It simply
has something to do with the close relationship to the unix command
line where you first have a command and then a bunch of option switches
and then some arguments. Knowing Tcl make it a bit easier to live with
SKILL (Cadence Tool command Lisp). Rest is personal taste and a lot has
to do with how easy it is to integrate the interpreters into your
c-code. Tcl was made for this, I don't know about Perl.

--
Svenn
 
Davy wrote:
Hi all,

I use NC-Sim Tcl command (like "stop") and found Tcl script is
white-space sensitive. And I have to wait for the Tcl report error in
run time and time-consuming. Can I debug/lint the Tcl script before run
all the simulation? Thanks!

Or is there something like Perl's "use strict" and "use warnings" in
Tcl? That I can write robust Tcl file in NC-Sim.

though i dont use nc-sim but what works for me is to create
a test file that checks automated atleast new procs with a
certain set of cases that could happen and execute the test
via make for each unmature module. if i have a simple mispell
or something it raises the error.

hope this is applicable
 

Welcome to EDABoard.com

Sponsor

Back
Top