registerRecordDeviceDriver updates

Added -D and -o <outfile> options
Changed the build rules to use -o
Moved the script into src/tools
This commit is contained in:
Andrew Johnson
2012-08-10 11:40:50 -05:00
parent 93f7caebc4
commit 0faff0f03e
4 changed files with 71 additions and 54 deletions

View File

@@ -391,15 +391,13 @@ $(foreach file, $(DB_INSTALLS), $(eval $(call DB_INSTALLS_template, $(file))))
IOC_INST_TOP := $(firstword $(IOCS_APPL_TOP) \ IOC_INST_TOP := $(firstword $(IOCS_APPL_TOP) \
$(shell $(PERL) $(TOOLS)/fullPathName.pl $(INSTALL_LOCATION) ) ) $(shell $(PERL) $(TOOLS)/fullPathName.pl $(INSTALL_LOCATION) ) )
%_registerRecordDeviceDriver.cpp: $(COMMON_DIR)/%.dbd %_registerRecordDeviceDriver.cpp: $(COMMON_DIR)/%.dbd
@$(RM) $@ $*.tmp @$(RM) $@
$(REGISTERRECORDDEVICEDRIVER) $(DBDFLAGS) $< $(basename $@) $(IOC_INST_TOP) > $*.tmp $(REGISTERRECORDDEVICEDRIVER) $(DBDFLAGS) -o $@ $< $(basename $@) $(IOC_INST_TOP)
$(MV) $*.tmp $@
%_registerRecordDeviceDriver.cpp: %.dbd %_registerRecordDeviceDriver.cpp: %.dbd
@$(RM) $@ $*.tmp @$(RM) $@
$(REGISTERRECORDDEVICEDRIVER) $(DBDFLAGS) $< $(basename $@) $(IOC_INST_TOP) > $*.tmp $(REGISTERRECORDDEVICEDRIVER) $(DBDFLAGS) -o $@ $< $(basename $@) $(IOC_INST_TOP)
$(MV) $*.tmp $@
.PRECIOUS: %_registerRecordDeviceDriver.cpp .PRECIOUS: %_registerRecordDeviceDriver.cpp

View File

@@ -18,8 +18,6 @@ INC += registryFunction.h
INC += registryCommon.h INC += registryCommon.h
INC += registryIocRegister.h INC += registryIocRegister.h
SCRIPTS_HOST += registerRecordDeviceDriver.pl
dbCore_SRCS += registryRecordType.c dbCore_SRCS += registryRecordType.c
dbCore_SRCS += registryDeviceSupport.c dbCore_SRCS += registryDeviceSupport.c
dbCore_SRCS += registryDriverSupport.c dbCore_SRCS += registryDriverSupport.c

View File

@@ -50,6 +50,7 @@ PERL_SCRIPTS += dbdToMenuH.pl
PERL_SCRIPTS += dbdToRecordtypeH.pl PERL_SCRIPTS += dbdToRecordtypeH.pl
PERL_SCRIPTS += dbdExpand.pl PERL_SCRIPTS += dbdExpand.pl
PERL_SCRIPTS += dbdToHtml.pl PERL_SCRIPTS += dbdToHtml.pl
PERL_SCRIPTS += registerRecordDeviceDriver.pl
include $(TOP)/configure/RULES include $(TOP)/configure/RULES

View File

@@ -21,16 +21,26 @@ use EPICS::Path;
use EPICS::Getopts; use EPICS::Getopts;
use Text::Wrap; use Text::Wrap;
getopts('I@') or our ($opt_D, @opt_I, $opt_o);
die "Usage: registerRecordDeviceDriver [-I dir] in.dbd subroutinename [TOP]";
my @path = map { split /[:;]/ } @EPICS::Getopts::opt_I; # FIXME: Broken on Win32? getopts('Do:I@') or
die "Usage: registerRecordDeviceDriver [-D] [-o out.c] [-I dir] in.dbd subname [TOP]";
my @path = map { split /[:;]/ } @opt_I; # FIXME: Broken on Win32?
my ($file, $subname, $bldTop) = @ARGV; my ($file, $subname, $bldTop) = @ARGV;
my $dbd = DBD->new(); my $dbd = DBD->new();
&ParseDBD($dbd, &Readfile($file, "", \@path)); &ParseDBD($dbd, &Readfile($file, "", \@path));
if ($opt_D) { # Output dependencies only
my %filecount;
my @uniqfiles = grep { not $filecount{$_}++ } @inputfiles;
print "$opt_o: ", join(" \\\n ", @uniqfiles), "\n\n";
print map { "$_:\n" } @uniqfiles;
exit 0;
}
$Text::Wrap::columns = 75; $Text::Wrap::columns = 75;
# Eliminate chars not allowed in C symbol names # Eliminate chars not allowed in C symbol names
@@ -41,10 +51,15 @@ $subname =~ s/$c_bad_ident_chars/_/g;
$bldTop = LocalPath(UnixPath($bldTop)); $bldTop = LocalPath(UnixPath($bldTop));
$bldTop =~ s/([\\"])/\\\1/g; # escape back-slashes and double-quotes $bldTop =~ s/([\\"])/\\\1/g; # escape back-slashes and double-quotes
# Create output file
my $out;
if ($opt_o) {
open $out, '>', $opt_o or die "Can't create $opt_o: $!\n";
} else {
$out = *STDOUT;
}
# Start of generated file print $out (<< "END");
print << "END" ;
/* THIS IS A GENERATED FILE. DO NOT EDIT! */ /* THIS IS A GENERATED FILE. DO NOT EDIT! */
/* Generated from $file */ /* Generated from $file */
@@ -65,25 +80,25 @@ if (%rectypes) {
my @rtypnames = sort keys %rectypes; my @rtypnames = sort keys %rectypes;
# Declare the record support entry tables # Declare the record support entry tables
print wrap('epicsShareExtern rset ', ' ', print $out wrap('epicsShareExtern rset ', ' ',
join(', ', map {"*pvar_rset_${_}RSET"} @rtypnames)), ";\n\n"; join(', ', map {"*pvar_rset_${_}RSET"} @rtypnames)), ";\n\n";
# Declare the RecordSizeOffset functions # Declare the RecordSizeOffset functions
print "typedef int (*rso_func)(dbRecordType *pdbRecordType);\n"; print $out "typedef int (*rso_func)(dbRecordType *pdbRecordType);\n";
print wrap('epicsShareExtern rso_func ', ' ', print $out wrap('epicsShareExtern rso_func ', ' ',
join(', ', map {"pvar_func_${_}RecordSizeOffset"} @rtypnames)), ";\n\n"; join(', ', map {"pvar_func_${_}RecordSizeOffset"} @rtypnames)), ";\n\n";
# List of record type names # List of record type names
print "static const char * const recordTypeNames[] = {\n"; print $out "static const char * const recordTypeNames[] = {\n";
print wrap(' ', ' ', join(', ', map {"\"$_\""} @rtypnames)); print $out wrap(' ', ' ', join(', ', map {"\"$_\""} @rtypnames));
print "\n};\n\n"; print $out "\n};\n\n";
# List of pointers to each RSET and RecordSizeOffset function # List of pointers to each RSET and RecordSizeOffset function
print "static const recordTypeLocation rtl[] = {\n"; print $out "static const recordTypeLocation rtl[] = {\n";
print join(",\n", map { print $out join(",\n", map {
" {pvar_rset_${_}RSET, pvar_func_${_}RecordSizeOffset}" " {pvar_rset_${_}RSET, pvar_func_${_}RecordSizeOffset}"
} @rtypnames); } @rtypnames);
print "\n};\n\n"; print $out "\n};\n\n";
for my $rtype (@rtypnames) { for my $rtype (@rtypnames) {
my @devices = $rectypes{$rtype}->devices; my @devices = $rectypes{$rtype}->devices;
@@ -95,18 +110,18 @@ if (%rectypes) {
if (@dsets) { if (@dsets) {
# Declare the device support entry tables # Declare the device support entry tables
print wrap('epicsShareExtern dset ', ' ', print $out wrap('epicsShareExtern dset ', ' ',
join(', ', map {"*pvar_dset_$_"} @dsets)), ";\n\n"; join(', ', map {"*pvar_dset_$_"} @dsets)), ";\n\n";
# List of dset names # List of dset names
print "static const char * const deviceSupportNames[] = {\n"; print $out "static const char * const deviceSupportNames[] = {\n";
print wrap(' ', ' ', join(', ', map {"\"$_\""} @dsets)); print $out wrap(' ', ' ', join(', ', map {"\"$_\""} @dsets));
print "\n};\n\n"; print $out "\n};\n\n";
# List of pointers to each dset # List of pointers to each dset
print "static const dset * const devsl[] = {\n"; print $out "static const dset * const devsl[] = {\n";
print wrap(' ', ' ', join(", ", map {"pvar_dset_$_"} @dsets)); print $out wrap(' ', ' ', join(", ", map {"pvar_dset_$_"} @dsets));
print "\n};\n\n"; print $out "\n};\n\n";
} }
} }
@@ -115,18 +130,18 @@ if (%drivers) {
my @drivers = sort keys %drivers; my @drivers = sort keys %drivers;
# Declare the driver entry tables # Declare the driver entry tables
print wrap('epicsShareExtern drvet ', ' ', print $out wrap('epicsShareExtern drvet ', ' ',
join(', ', map {"*pvar_drvet_$_"} @drivers)), ";\n\n"; join(', ', map {"*pvar_drvet_$_"} @drivers)), ";\n\n";
# List of drvet names # List of drvet names
print "static const char *driverSupportNames[] = {\n"; print $out "static const char *driverSupportNames[] = {\n";
print wrap(' ', ' ', join(', ', map {"\"$_\""} @drivers)); print $out wrap(' ', ' ', join(', ', map {"\"$_\""} @drivers));
print "};\n\n"; print $out "};\n\n";
# List of pointers to each drvet # List of pointers to each drvet
print "static struct drvet *drvsl[] = {\n"; print $out "static struct drvet *drvsl[] = {\n";
print join(",\n", map {" pvar_drvet_$_"} @drivers); print $out join(",\n", map {" pvar_drvet_$_"} @drivers);
print "};\n\n"; print $out "};\n\n";
} }
my @registrars = sort keys %{$dbd->registrars}; my @registrars = sort keys %{$dbd->registrars};
@@ -134,8 +149,8 @@ my @functions = sort keys %{$dbd->functions};
push @registrars, map {"register_func_$_"} @functions; push @registrars, map {"register_func_$_"} @functions;
if (@registrars) { if (@registrars) {
# Declare the registrar functions # Declare the registrar functions
print "typedef void (*reg_func)(void);\n"; print $out "typedef void (*reg_func)(void);\n";
print wrap('epicsShareExtern reg_func ', ' ', print $out wrap('epicsShareExtern reg_func ', ' ',
join(', ', map {"pvar_func_$_"} @registrars)), ";\n\n"; join(', ', map {"pvar_func_$_"} @registrars)), ";\n\n";
} }
@@ -146,28 +161,28 @@ if (%variables) {
# Declare the variables # Declare the variables
for my $var (@varnames) { for my $var (@varnames) {
my $vtype = $variables{$var}->var_type; my $vtype = $variables{$var}->var_type;
print "epicsShareExtern $vtype * const pvar_${vtype}_$var;\n"; print $out "epicsShareExtern $vtype * const pvar_${vtype}_$var;\n";
} }
# Generate the structure for registering variables with iocsh # Generate the structure for registering variables with iocsh
print "\nstatic struct iocshVarDef vardefs[] = {\n"; print $out "\nstatic struct iocshVarDef vardefs[] = {\n";
for my $var (@varnames) { for my $var (@varnames) {
my $vtype = $variables{$var}->var_type; my $vtype = $variables{$var}->var_type;
my $itype = $variables{$var}->iocshArg_type; my $itype = $variables{$var}->iocshArg_type;
print " {\"$var\", $itype, pvar_${vtype}_$var},\n"; print $out " {\"$var\", $itype, pvar_${vtype}_$var},\n";
} }
print " {NULL, iocshArgInt, NULL}\n};\n\n"; print $out " {NULL, iocshArgInt, NULL}\n};\n\n";
} }
# Now for actual registration routine # Now for actual registration routine
print << "END"; print $out (<< "END");
int $subname(DBBASE *pbase) int $subname(DBBASE *pbase)
{ {
static int executed = 0; static int executed = 0;
END END
print << "END" if $bldTop ne ''; print $out (<< "END") if $bldTop ne '';
const char *bldTop = "$bldTop"; const char *bldTop = "$bldTop";
const char *envTop = getenv("TOP"); const char *envTop = getenv("TOP");
@@ -179,7 +194,7 @@ print << "END" if $bldTop ne '';
END END
print << 'END'; print $out (<< 'END');
if (!pbase) { if (!pbase) {
printf("pdbbase is NULL; you must load a DBD file first.\n"); printf("pdbbase is NULL; you must load a DBD file first.\n");
return -1; return -1;
@@ -192,27 +207,27 @@ print << 'END';
END END
print << 'END' if %rectypes; print $out (<< 'END') if %rectypes;
registerRecordTypes(pbase, NELEMENTS(rtl), recordTypeNames, rtl); registerRecordTypes(pbase, NELEMENTS(rtl), recordTypeNames, rtl);
END END
print << 'END' if @dsets; print $out (<< 'END') if @dsets;
registerDevices(pbase, NELEMENTS(devsl), deviceSupportNames, devsl); registerDevices(pbase, NELEMENTS(devsl), deviceSupportNames, devsl);
END END
print << 'END' if %drivers; print $out (<< 'END') if %drivers;
registerDrivers(pbase, NELEMENTS(drvsl), driverSupportNames, drvsl); registerDrivers(pbase, NELEMENTS(drvsl), driverSupportNames, drvsl);
END END
print << "END" for @registrars; print $out (<< "END") for @registrars;
pvar_func_$_(); pvar_func_$_();
END END
print << 'END' if %variables; print $out (<< 'END') if %variables;
iocshRegisterVariable(vardefs); iocshRegisterVariable(vardefs);
END END
print << "END"; print $out (<< "END");
return 0; return 0;
} }
@@ -239,3 +254,8 @@ static int Registration() {
static int done = Registration(); static int done = Registration();
END END
if ($opt_o) {
close $out or die "Closing $opt_o failed: $!\n";
}
exit 0;