Skip to content

Commit 967b03d

Browse files
committed
Added tcl support
1 parent 95b3ade commit 967b03d

11 files changed

+3102
-11
lines changed

.gitignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,7 @@ lib*.so
77
*~
88

99
#Build directories
10-
x86_64/lib64
10+
x86_64/lib64
11+
12+
#Generated header file
13+
include/sknobs.h

legacy_notes/RELEASE_NOTES

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
0.25
2+
- Limit use of "long" data type.
3+
- Fix bug, ensuring that seed value is representable in 32 bits
4+
5+
0.24
6+
- Use getcwd() instead of $PWD.
7+
- Use /dev/urandom instead of time() if it exists for the implicit seed
8+
value if no explicit seed is specified.
9+
10+
0.23
11+
- Handle '+='. Now an error. This is a bit inconsistent with bare '+'
12+
handling (a warning). Consider making both either errors or warnings in
13+
the future.
14+
- Move atol() usage to strto*(). Check errno for errors.
15+
- Weights are treated as unsigned values. This avoids the foggy semantics
16+
of negative weights.
17+
- Seed sources now can supply either signed or unsigned values. In prior
18+
releases, on a 32-bit platform, if a seed value was specified as a "large"
19+
32-bit unsigned value (>LONG_MAX) the atol() call was saturating the value
20+
to LONG_MAX. In this release, seed value strings are converted to 64-bit
21+
unsigned values, and then the lower 32-bits are used.
22+
- All messages now indicate sknobs as the source.
23+
24+
0.22
25+
- Handle bare '+' gracefully. Warn and ignore.
26+
27+
0.21
28+
- Fix corruption issue when encountering strings > 8KB.
29+
30+
0.20
31+
- In c, add install dependency on libsknobs.so.
32+
- Fixed bug in parsing -f args from files if the delimiter flavor is
33+
set to "crnl".
34+
- Improve clean target in src/python.
35+
36+
0.19
37+
- Add new way of tokenizing a string to get knobs. Search for "token" in
38+
doc/README for an explanation. This feature enables whitespace in knob
39+
string values! Default behavior is backward compatible.
40+
41+
0.18
42+
- Default target in src/c/ is now libsknobs.a and libsknobs.so. To run
43+
test, use "test" target.
44+
- Better perl install. Still installs locally: not to site-packages.
45+
- Verilog install is just sknobs.sv. DPI users should point to libsknobs.so.
46+
- DPI and VPI tests for Questa (see "testquesta_dpi" and "testquesta_vpi"
47+
targets. Haven't touched VCS.
48+
- VPI sknobs iterate now works on 64-bit platform. Use vpiHexStrVal to pass
49+
iterator pointer (sknobsvpi.c).
50+
51+
0.17
52+
- Remove all generated files from tarball. Still need distclean target to
53+
automate this.
54+
- Remove random old versions of sknobs.c and patch output from src/c.
55+
- Python test now works without SKNOBS_HOME set.
56+
- Tweaks to vcs and questa test targets. Neither robust.
57+
- Enhancements to VPI code from Sankalp.
58+
59+
0.16
60+
- Change to src/c/sknobs.c.
61+
- Cleaning up error handling.

src/Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ clean:
1111
#$(MAKE) -C perl clean
1212

1313
build:
14-
echo $(ARCH)
15-
echo $(CURDIR)
14+
@echo ARCH=$(ARCH)
15+
@echo CURDIR=$(CURDIR)
1616
$(MAKE) -C c
1717
$(MAKE) -C tcl
1818
#$(MAKE) -C python

src/c/Makefile

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
CFLAGS = -fPIC -Wall -Werror
2-
3-
INSTALL_LIB=lib
2+
INSTALL_LIB=lib64
43

54
default: libsknobs.a libsknobs.so
65

src/c/sknobs.c

-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
////////////////////////////////////////////////////////////////////////////
22
// C implementation of knobs
3-
//
4-
// $Revision: #1 $
5-
// $Author: jscheid $
6-
// $Date: 2010/04/28 $
7-
// $Id: //depot/users/jscheid/src/sknobs/0.25/src/c/sknobs.c#1 $
8-
//
93
////////////////////////////////////////////////////////////////////////////
104

115
#include <stdio.h>

src/tcl/Makefile

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
SWIG = swig
2+
DEBUG = -g
3+
CFLAGS = -fPIC -I../c
4+
TCL_CFLAGS = -I/usr/include/tcl
5+
INSTALL_LIB=lib64
6+
7+
default: sknobs.so
8+
9+
# TCL interface built as swig wrapper around C interface
10+
sknobs_wrap.c: sknobs.i
11+
$(SWIG) -I../c -includeall -tcl $<
12+
13+
sknobs_wrap.o: sknobs_wrap.c
14+
$(CC) $(CFLAGS) $(TCL_CFLAGS) -c -o $@ $<
15+
16+
sknobs.so: sknobs_wrap.o
17+
gcc -shared $(CFLAGS) $^ ../c/libsknobs.a -o $@
18+
19+
install: sknobs.so
20+
install -D sknobs.so $(PREFIX)/$(ARCH)/$(INSTALL_LIB}/tcl/sknobs.so
21+
22+
test: sknobs.so
23+
./testsknobs +abc=5 +xyz=10
24+
25+
# clean up
26+
clean:
27+
$(RM) *.o *.a *~ *.so
28+
$(RM) sknobs_wrap.*
29+

src/tcl/README

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// This tells SWIG to treat char ** as a special case
2+
%typemap(in) (int argc, char **argv) {
3+
Tcl_Obj **listobjv;
4+
int nitems;
5+
int i;
6+
if (Tcl_ListObjGetElements(interp, $input, &nitems, &listobjv) == TCL_ERROR) {
7+
return TCL_ERROR;
8+
}
9+
$1 = (char **) malloc((nitems+1)*sizeof(char *));
10+
for (i = 0; i < nitems; i++) {
11+
$2[i] = Tcl_GetStringFromObj(listobjv[i],0);
12+
}
13+
$1[i] = 0;
14+
}
15+
16+
// This gives SWIG some cleanup code that will get called after the function call
17+
%typemap(freearg) (int argc, char **argv) {
18+
if ($2) {
19+
free($2);
20+
}
21+
22+
}

src/tcl/sknobs.h

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
2+
int sknobs_init(int argc, char **argv);
3+
void sknobs_close(void);
4+
5+
int sknobs_add(char *pattern, char *value, char *comment);
6+
int sknobs_load(int argc, char *argv[], char *comment);
7+
int sknobs_load_string(char *name, char *buffer, char *comment);
8+
int sknobs_load_file(char *filename);
9+
int sknobs_load_file_if_exists(char *filename);
10+
11+
int sknobs_exists(char *name);
12+
13+
typedef void *sknobs_iterator_p;
14+
sknobs_iterator_p sknobs_iterate(char *name);
15+
int sknobs_iterator_next(sknobs_iterator_p iterator);
16+
char *sknobs_iterator_get_string(sknobs_iterator_p iterator);
17+
18+
char *sknobs_get_string(char *name, char *defaultValue);
19+
char *sknobs_find_file(char *filename);
20+
char *sknobs_get_filename(char *name, char *defaultValue);
21+
22+
unsigned long long sknobs_get_value(char *name, unsigned long long defaultValue);
23+
unsigned long long sknobs_get_dynamic_value(char *name, unsigned long long defaultValue);
24+
25+
void sknobs_set_string(char *name, char *value);
26+
void sknobs_set_value(char *name, unsigned long long value);
27+
void sknobs_set_seed(long value);
28+
29+
unsigned long long sknobs_eval(char *expr);
30+
31+
void sknobs_dump(void);
32+
void sknobs_save(char *filename);
33+

src/tcl/sknobs.i

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
%module sknobs
2+
3+
// This tells SWIG to treat char ** as a special case
4+
%typemap(in) (int argc, char **argv) {
5+
Tcl_Obj **listobjv;
6+
int nitems;
7+
int i;
8+
if (Tcl_ListObjLength(interp, $input, &nitems) == TCL_ERROR) {
9+
return TCL_ERROR;
10+
}
11+
if (Tcl_ListObjGetElements(interp, $input, &nitems, &listobjv) == TCL_ERROR) {
12+
return TCL_ERROR;
13+
}
14+
$2 = (char **) malloc((nitems+2)*sizeof(char *));
15+
$2[0] = "sknobs";
16+
for (i = 0; i < nitems; i++) {
17+
$2[i+1] = Tcl_GetStringFromObj(listobjv[i],0);
18+
}
19+
$2[i+1] = 0;
20+
$1 = nitems+1;
21+
}
22+
23+
// This gives SWIG some cleanup code that will get called after the function call
24+
%typemap(freearg) (int argc, char **argv) {
25+
if ($2) {
26+
free($2);
27+
}
28+
29+
}
30+
31+
#include "sknobs.h"
32+
33+
%{
34+
#include "sknobs.h"
35+
%}
36+

0 commit comments

Comments
 (0)