Chapter Contents |
Previous |
Next |
The DSECT2C Utility |
Input and Output |
The input file to DSECT2C is an assembler listing file (under OS/390, this is the SYSPRINT data set; under CMS, it is the filetype LISTING file). To generate this file, create an assembler language program consisting of only the DSECT definition and an END instruction. Sample Assembler Language Input File shows a sample assembler language input file. If the DSECT is in an existing assembler language source library, it can be included with a COPY instruction, followed by an END instruction. DSECTs in macro libraries can be allowed to expand in the listing.
Sample Assembler Language Input File
SAMPLECB DSECT NAME DS CL8 ADDRESS DS A NUMBER DS F ORG ADDRESS DNUM DS D ORG , FLAGS DS XL1 ADDR3 DS AL3 END
Invoke the assembler and produce a listing file. DSECT2C
expects
stdin
to be redirected to the listing file.
DSECT2C writes the C structure definition to
stdout
. This file also
includes any
typedefs
used in the structure, a set of macro definitions for the
structure members, and other output as specified by DSECT2C options.
Sample DSECT2C Output File shows the output file produced by DSECT2C for the DSECT defined in Sample Assembler Language Input File. There are four distinct parts:
typedefs
corresponding to assembler language types
Sample DSECT2C Output File
#if !defined(_AL3) #define _AL3 typedef struct { char BF : 24; } AL3; #endif #if !defined(_CL8) #define _CL8 typedef char CL8(|8|); #endif struct SAMPLECB { CL8 name; union { struct { void *address; int number; } _s0; double dnum; }; char flags; AL3 addr3; }; #define ADDRESS _s0.address #define ADDR3 addr3 #define DNUM dnum #define FLAGS flags #define NAME name #define NUMBER _s0.number /* SYMBOL OFFSET LENGTH TYPE C-TYPE C-NAME ADDRESS 000008 000004 A void * _s0.address ADDR3 000011 000003 AL3 AL3 addr3 DNUM 000008 000008 D double dnum FLAGS 000010 000001 XL1 char flags NAME 000000 000008 CL8 CL8 name NUMBER 00000C 000004 F int _s0.number SAMPLECB 000000 000000 */
Note:
DSECT2C generates identifiers for unnamed
fields and inner structures when necessary. These identifiers always have
the format
_f
or
_s
followed by an integer number.
Options |
DSECT2C accepts six options, as shown in DSECT2C Options.
Usage Notes |
bitfield
option, using
char
as the default allocation
unit.
For more information about language extensions, see Language Extensions. For more information on compiler options, see Compiler Options.
@ A_ # P_ $ D_
Note that only leading $'s are changed. Use the
dollars
compiler option if a structure member identifier contains embedded
$'s.
BEGINBUF DS 0C
By default, DSECT2C converts this to the following structure member:
char beginbuf(|0|);
The
SAS/C Compiler accepts
such an array declaration within a structure definition as a language extension.
However, most C compilers do not allow a declaration of an array with 0 elements.
If you attempt to compile a program containing a structure generated by DSECT2C
that contains this kind of declaration using another compiler, that compiler
will probably generate an error message and refuse to compile the program.
The
-z
option causes DSECT2C to generate
LENGTH_ZERO
,
LENGTH_ZERO_2D
, and
LENGTH_ZERO_REF
macros, which can be used to overcome this problem.
The
-z
option causes DSECT2C to substitute a call to
the
LENGTH_ZERO
macro instead of generating an array of 0 elements. The
LENGTH_ZERO
macro accepts two arguments, the type and name of the member. For
example, if the
-z
option is used, DSECT2C converts the assembler
language statement shown above (
BEGINBUF DS 0C
) to the following statement:
LENGTH_ZERO(char, beginbuf);
You must supply a definition of the
LENGTH_ZERO
macro that
generates a declaration for the member that is acceptable to the target compiler.
The
LENGTH_ZERO_2D
macro is used when the member is a two-dimensional array whose first
dimension is 0. As shown here, the
LENGTH_ZERO_2D
macro accepts three
arguments, the type of the member, its name, and the second dimension:
LENGTH_ZERO_2D(int, nfield, 2);
The
LENGTH_ZERO_REF
macro is generated by DSECT2C in the C macro corresponding to a structure
member. By default, the macro for a zero-length array member is defined as
follows:
#define BEGINBUF beginbuf(|0|)
If the
-z
option is used, DSECT2C substitutes the following
LENGTH_ZERO_REF
macro:
#define BEGINBUF LENGTH_ZERO_REF(beginbuf)
The
LENGTH_ZERO_REF
macro accepts one argument, the
member name.
DSECT2C also generates default definitions of these
three macros. These definitions produce the same member declaration as would
be generated if the
-z
option were not in effect. Each definition is
protected by an
#if !defined
preprocessor statement, so any definitions you supply
override the default definitions. The default definitions generated by DSECT2C
are
#if !defined(LENGTH_ZERO) #define LENGTH_ZERO(type, name) type name(|0|) #endif #if !defined(LENGTH_ZERO_2D) #define LENGTH_ZERO_2D(type, name, dim) type name(|0|)(|dim|) #endif #if !defined(LENGTH_ZERO_REF) #define LENGTH_ZERO_REF(name) name(|0|) #endif
Invoking DSECT2C |
DSECT2C is a C program and can be invoked as you would
any other C program. In general, you must specify the name of the DSECT to
be converted and any options, redirect
stdin
to the assembler listing file,
and redirect
stdout
to the desired output file.
CALL 'library.name(DSECT2C)' 'dsect [listing] output options'
CALL 'SASC.LOAD(DSECT2C)' 'IHADCB <tso:MYDSECT.LIST(IHADCB) >tso:MYDSECT.H(IHADCB)'
Consult your SAS Software Representative for C compiler
products for the correct library.name.
Under CMS, invoke DSECT2C as follows:
DSECT2C dsect [listing ]output options
dsect | is the name of the DSECT to be converted. |
listing | is the assembler listing file. |
output | is the output file. |
options | are DSECT2C options. |
DSECT2C FSCBD <FSCBD.LISTING >FSCBD.H
The DSECT2C cataloged procedure can be used to execute DSECT2C under OS/390 batch. This procedure allocates SYSPRINT to a temporary data set, invokes the assembler, and then invokes DSECT2C to produce the C structure. You should provide a DD card for the assembler SYSIN data set and a DD card for DSECT2C's D2COUT data set. Sample JCL for Running the DSECT2C Cataloged Procedure shows typical JCL for using the DSECT2C cataloged procedure.
Sample JCL for Running the DSECT2C Cataloged Procedure
//SAMPD2C JOB job card information //*---------------------------------------------------- //* INVOKE ASSEMBLER AND DSECT2C //* //* REPLACE GENERIC DATA SET NAMES AS APPROPRIATE //*---------------------------------------------------- //STEP1 EXEC DSECT2C,PARM.D2C='dsect-name options ' //ASM.SYSIN DD DSN=assembler.source.file ,DISP=SHR //D2C.D2COUT DD DSN=your.output.file ,DISP=OLD //
dsect-name | is the name of the DSECT to be converted. |
options | are DSECT2C options. Separate options with blanks, not commas. |
The DSECT2C procedure contains the JCL shown in Expanded JCL for DSECT2C.
Expanded JCL for DSECT2C
//DSECT2C PROC //ASM EXEC PGM=ASMBLR,PARM=TERM //SYSTERM DD SYSOUT=* //SYSPUNCH DD DUMMY //SYSLIN DD DUMMY //SYSUT1 DD DSN=&&SYSUT1,UNIT=SYSDA,SPACE=(TRK,(5,1)) //SYSUT2 DD DSN=&&SYSUT2,UNIT=SYSDA,SPACE=(TRK,(5,1)) //SYSUT3 DD DSN=&&SYSUT3,UNIT=SYSDA,SPACE=(TRK,(5,1)) //SYSLIB DD DSN=SYS1.MACLIB,DISP=(SHR,KEEP,KEEP) // DD DSN=SYS1.AMODGEN,DISP=(SHR,KEEP,KEEP) //SYSPRINT DD DSN=&&LISTING,DCB=(RECFM=FBA,LRECL=121,BLKSIZE=1089), // DISP=(NEW,PASS),UNIT=SYSDA //D2C EXEC PGM=DSECT2C,COND=(0,NE,ASM) //STEPLIB DD DSN=SASC.LOAD,DISP=SHR COMPILER LIBRARY // DD DSN=SASC.LINKLIB,DISP=SHR RUNTIME LIBRARY //SYSIN DD DSN=*.ASM.SYSPRINT,DISP=(OLD,DELETE,DELETE), // VOL=REF=*.ASM.SYSPRINT //SYSTERM DD SYSOUT=* //SYSPRINT DD DDNAME=D2COUT
Chapter Contents |
Previous |
Next |
Top of Page |
Copyright © 2001 by SAS Institute Inc., Cary, NC, USA. All rights reserved.