-pdu=* changes

git-svn-id: https://asn1c.svn.sourceforge.net/svnroot/asn1c/trunk@1238 59561ff5-6e30-0410-9f3c-9617f08c8826
This commit is contained in:
vlm 2006-09-23 02:52:12 +00:00
parent abb8c72f68
commit d99294ac2b
8 changed files with 136 additions and 30 deletions

View File

@ -1,4 +1,8 @@
0.9.22: 2006-Sep-22
* Added -pdu=all and -pdu=<type> switches to asn1c.
0.9.21: 2006-Sep-17 0.9.21: 2006-Sep-17
* skeletons/standard-modules directory is now used for standard types. * skeletons/standard-modules directory is now used for standard types.

View File

@ -4,7 +4,7 @@ asn1c \- ASN.1 Compiler
.SH SYNOPSIS .SH SYNOPSIS
asn1c [\fB\-E\fR [\fB-F\fR] | \fB\-P\fR | \fB\-R\fR] asn1c [\fB\-E\fR [\fB-F\fR] | \fB\-P\fR | \fB\-R\fR]
[\fB\-S\fR\fIdir\fR] [\fB-X\fR] [\fB\-S\fR\fIdir\fR] [\fB-X\fR]
[\fB\-W\fR\fIdebug-\fR...] [\fB\-f\fR\fIoption\fR] [\fB\-gen-\fR\fIoption\fR] [\fB\-pdu=\fR\fIoption\fR] [\fB\-W\fR\fIdebug-\fR...] [\fB\-f\fR\fIoption\fR] [\fB\-gen-\fR\fIoption\fR] [\fB\-pdu=\fR{\fBall\fR|\fBauto\fR|\fIType\fR}\fR]
[\fB\-print-\fR\fIoption\fR] [\fB\-print-\fR\fIoption\fR]
\fIinfile\fR... \fIinfile\fR...
.SH DESCRIPTION .SH DESCRIPTION
@ -30,7 +30,7 @@ and other encoding rules.
.TP .TP
\fICodecs Generation Options\fR \fICodecs Generation Options\fR
.br .br
.B \-gen-PER \-pdu=auto .B \-gen-PER \-pdu=\fR{\fBall\fR|\fBauto\fR|\fIType\fR}
.TP .TP
\fIOutput Options\fR \fIOutput Options\fR
.br .br
@ -75,7 +75,7 @@ Enable ASN.1 syntax tree fixer debugging during the fixing stage.
.B \-Wdebug-compiler .B \-Wdebug-compiler
Enable debugging during the actual compile time. Enable debugging during the actual compile time.
.SH LANGUAGE OPTIONS .SH LANGUAGE OPTIONS
.TP .TP
.B \-fbless-SIZE .B \-fbless-SIZE
Allow SIZE() constraint for INTEGER, ENUMERATED, and other types for which this Allow SIZE() constraint for INTEGER, ENUMERATED, and other types for which this
constraint is normally prohibited by the standard. This is a violation of constraint is normally prohibited by the standard. This is a violation of
@ -119,8 +119,13 @@ Copy support files (skeletons) rather than symlink them.
.B \-gen-PER .B \-gen-PER
Generate Packed Encoding Rules (PER) support code. Generate Packed Encoding Rules (PER) support code.
.TP .TP
.B \-pdu=auto .B \-pdu=\fR{\fBall\fR|\fBauto\fR|\fIType\fR}
Generate PDU tables by discovering Protocol Data Units automatically. Create a PDU table for specified types, or discover Protocol Data Units
automatically. In case of -pdu=\fBall\fR, all ASN.1 types defined in
all modules will form a PDU table. In case of -pdu=\fBauto\fR, all types
not referenced by any other type will form a PDU table.
If \fIType\fR is an ASN.1 type identifier, it is added to a PDU table.
The last form may be specified multiple times to add any number of PDUs.
.SH OUTPUT OPTIONS .SH OUTPUT OPTIONS
.TP .TP
.B \-print-constraints .B \-print-constraints

View File

@ -123,12 +123,19 @@ main(int ac, char **av) {
case 'p': case 'p':
if(strncmp(optarg, "du=", 3) == 0) { if(strncmp(optarg, "du=", 3) == 0) {
char *pduname = optarg + 3; char *pduname = optarg + 3;
if(strcmp(pduname, "auto")) { if(strcmp(pduname, "all") == 0) {
fprintf(stderr, "-pdu=%s: expected -pdu=auto\n", asn1_compiler_flags |= A1C_PDU_ALL;
} else if(strcmp(pduname, "auto") == 0) {
asn1_compiler_flags |= A1C_PDU_AUTO;
} else if(pduname[0] >= 'A' && pduname[0] <= 'Z') {
asn1c__add_pdu_type(pduname);
asn1_compiler_flags |= A1C_PDU_TYPE;
} else {
fprintf(stderr, "-pdu=%s"
": expected -pdu={all|auto|Type}\n",
pduname); pduname);
exit(EX_USAGE); exit(EX_USAGE);
} }
asn1_compiler_flags |= A1C_PDU_AUTO;
} else if(strcmp(optarg, "rint-class-matrix") == 0) { } else if(strcmp(optarg, "rint-class-matrix") == 0) {
asn1_printer_flags |= APF_PRINT_CLASS_MATRIX; asn1_printer_flags |= APF_PRINT_CLASS_MATRIX;
} else if(strcmp(optarg, "rint-constraints") == 0) { } else if(strcmp(optarg, "rint-constraints") == 0) {
@ -456,7 +463,7 @@ usage(const char *av0) {
"\n" "\n"
" -gen-PER Generate PER support code\n" " -gen-PER Generate PER support code\n"
" -pdu=auto Generate PDU table (discover PDUs automatically)\n" " -pdu={all|auto|Type} Generate PDU table (discover PDUs automatically)\n"
"\n" "\n"
" -print-class-matrix Print out the collected object class matrix (debug)\n" " -print-class-matrix Print out the collected object class matrix (debug)\n"

View File

@ -23,12 +23,14 @@ if test -z "$ASN1PDU" \
exit exit
fi fi
CMDOPTS="-pdu=${ASN1PDU} ${ASN1CMDOPTS} ${ASN1MODULES}"
if test -x ../../asn1c/asn1c ; then if test -x ../../asn1c/asn1c ; then
echo "Compiling ${ASN1MODULES} using local compiler" echo "Compiling ${ASN1MODULES} using local compiler"
../../asn1c/asn1c -S ../../skeletons ${ASN1CMDOPTS} ${ASN1MODULES} || exit $? ../../asn1c/asn1c -S ../../skeletons ${CMDOPTS} || exit $?
else else
echo "Compiling ${ASN1MODULES} using system compiler" echo "Compiling ${ASN1MODULES} using system compiler"
asn1c ${ASN1CMDOPTS} ${ASN1MODULES} || exit $? asn1c ${CMDOPTS} || exit $?
fi fi
if test ! -f Makefile.am.sample ; then if test ! -f Makefile.am.sample ; then
@ -36,15 +38,14 @@ if test ! -f Makefile.am.sample ; then
exit 1 exit 1
fi fi
ASN1DEFPDU=`echo "$ASN1PDU" | tr - _` EXTRA_CFLAGS=""
CFLAGS="-DPDU=${ASN1DEFPDU}"
if test -f config.h ; then if test -f config.h ; then
CFLAGS="-DHAVE_CONFIG_H $CFLAGS" EXTRA_CFLAGS="-DHAVE_CONFIG_H $EXTRA_CFLAGS"
fi fi
set -x set -x
cat Makefile.am.sample \ cat Makefile.am.sample \
| sed -e "s/^CFLAGS += /CFLAGS += ${CFLAGS} /" \ | sed -e "s/^CFLAGS += /CFLAGS += ${EXTRA_CFLAGS} /" \
| sed -e "s/^all: /all: ${ASN1PDU}.c /" \ | sed -e "s/^all: /all: ${ASN1PDU}.c /" \
| sed -e "s/progname/${PROGNAME}/" \ | sed -e "s/progname/${PROGNAME}/" \
> Makefile.$$ > Makefile.$$

View File

@ -4761,7 +4761,7 @@ clean:
regen: regenerate-from-asn1-source regen: regenerate-from-asn1-source
regenerate-from-asn1-source: regenerate-from-asn1-source:
../../asn1c/asn1c -S ../../skeletons -fcompound-names -pdu=auto -gen-PER ../rrc.asn1 ../../asn1c/asn1c -S ../../skeletons -pdu=DL-DCCH-Message -pdu=auto -fcompound-names -gen-PER ../rrc.asn1
DL-DCCH-Message.c: ../sample.makefile.regen ../rrc.asn1 DL-DCCH-Message.c: ../sample.makefile.regen ../rrc.asn1
@ -4770,7 +4770,7 @@ DL-DCCH-Message.c: ../sample.makefile.regen ../rrc.asn1
make make
regen-makefile: regen-makefile:
ASN1CMDOPTS="-fcompound-names -pdu=auto -gen-PER" \ ASN1CMDOPTS="-pdu=auto -fcompound-names -gen-PER" \
ASN1MODULES="../rrc.asn1" \ ASN1MODULES="../rrc.asn1" \
ASN1PDU=DL-DCCH-Message \ ASN1PDU=DL-DCCH-Message \
PROGNAME=rrc-dump \ PROGNAME=rrc-dump \

View File

@ -51,7 +51,6 @@ typedef struct arg_s {
struct compiler_streams *target; struct compiler_streams *target;
asn1p_t *asn; asn1p_t *asn;
//asn1p_module_t *mod;
asn1p_expr_t *expr; asn1p_expr_t *expr;
int embed; int embed;

View File

@ -11,8 +11,12 @@ static int asn1c_print_streams(arg_t *arg);
static int asn1c_save_streams(arg_t *arg, asn1c_fdeps_t *, int, char **); static int asn1c_save_streams(arg_t *arg, asn1c_fdeps_t *, int, char **);
static int asn1c_copy_over(arg_t *arg, char *path); static int asn1c_copy_over(arg_t *arg, char *path);
static int identical_files(const char *fname1, const char *fname2); static int identical_files(const char *fname1, const char *fname2);
static int need_to_generate_pdu_collection(arg_t *arg);
static int generate_pdu_collection_file(arg_t *arg); static int generate_pdu_collection_file(arg_t *arg);
static int generate_preamble(arg_t *, FILE *, int optc, char **argv); static int generate_preamble(arg_t *, FILE *, int optc, char **argv);
static int include_type_to_pdu_collection(arg_t *arg);
static void pdu_collection_print_unused_types(arg_t *arg);
static const char *generate_pdu_C_definition(void);
int int
asn1c_save_compiled_output(arg_t *arg, const char *datadir, asn1c_save_compiled_output(arg_t *arg, const char *datadir,
@ -121,7 +125,7 @@ asn1c_save_compiled_output(arg_t *arg, const char *datadir,
} }
} }
if(arg->flags & A1C_PDU_AUTO) { if(need_to_generate_pdu_collection(arg)) {
fprintf(mkf, "ASN_CONVERTER_SOURCES+=pdu_collection.c\n"); fprintf(mkf, "ASN_CONVERTER_SOURCES+=pdu_collection.c\n");
if(generate_pdu_collection_file(arg)) if(generate_pdu_collection_file(arg))
return -1; return -1;
@ -135,7 +139,7 @@ asn1c_save_compiled_output(arg_t *arg, const char *datadir,
"# This file may be used as an input for make(3)\n" "# This file may be used as an input for make(3)\n"
"# Remove the lines below to convert it into a pure .am file\n" "# Remove the lines below to convert it into a pure .am file\n"
"TARGET = progname\n" "TARGET = progname\n"
"CFLAGS +=%s -I.\n" "CFLAGS +=%s%s -I.\n"
"OBJS=${ASN_MODULE_SOURCES:.c=.o}" "OBJS=${ASN_MODULE_SOURCES:.c=.o}"
" ${ASN_CONVERTER_SOURCES:.c=.o}\n" " ${ASN_CONVERTER_SOURCES:.c=.o}\n"
"\nall: $(TARGET)\n" "\nall: $(TARGET)\n"
@ -150,7 +154,10 @@ asn1c_save_compiled_output(arg_t *arg, const char *datadir,
"\n\trm -f $(OBJS)\n" "\n\trm -f $(OBJS)\n"
"\nregen: regenerate-from-asn1-source\n" "\nregen: regenerate-from-asn1-source\n"
"\nregenerate-from-asn1-source:\n\t" "\nregenerate-from-asn1-source:\n\t"
, (arg->flags & A1C_PDU_AUTO) ? " -DASN_PDU_COLLECTION" : "" , (arg->flags & A1C_PDU_TYPE)
? generate_pdu_C_definition() : ""
, need_to_generate_pdu_collection(arg)
? " -DASN_PDU_COLLECTION" : ""
); );
for(i = 0; i < argc; i++) for(i = 0; i < argc; i++)
@ -483,9 +490,7 @@ generate_pdu_collection_file(arg_t *arg) {
TQ_FOR(mod, &(arg->asn->modules), mod_next) { TQ_FOR(mod, &(arg->asn->modules), mod_next) {
TQ_FOR(arg->expr, &(mod->members), next) { TQ_FOR(arg->expr, &(mod->members), next) {
if(arg->expr->_type_referenced if(!include_type_to_pdu_collection(arg))
|| !asn1_lang_map[arg->expr->meta_type]
[arg->expr->expr_type].type_cb)
continue; continue;
fprintf(fp, "extern struct asn_TYPE_descriptor_s " fprintf(fp, "extern struct asn_TYPE_descriptor_s "
"asn_DEF_%s;\n", "asn_DEF_%s;\n",
@ -498,9 +503,7 @@ generate_pdu_collection_file(arg_t *arg) {
TQ_FOR(mod, &(arg->asn->modules), mod_next) { TQ_FOR(mod, &(arg->asn->modules), mod_next) {
int mod_printed = 0; int mod_printed = 0;
TQ_FOR(arg->expr, &(mod->members), next) { TQ_FOR(arg->expr, &(mod->members), next) {
if(arg->expr->_type_referenced if(!include_type_to_pdu_collection(arg))
|| !asn1_lang_map[arg->expr->meta_type]
[arg->expr->expr_type].type_cb)
continue; continue;
if(!mod_printed++) if(!mod_printed++)
fprintf(fp, "\t/* From module %s in %s */\n", fprintf(fp, "\t/* From module %s in %s */\n",
@ -513,9 +516,92 @@ generate_pdu_collection_file(arg_t *arg) {
fprintf(fp, "\t0\n};\n\n"); fprintf(fp, "\t0\n};\n\n");
pdu_collection_print_unused_types(arg);
fclose(fp); fclose(fp);
fprintf(stderr, "Generated pdu_collection.c\n"); fprintf(stderr, "Generated pdu_collection.c\n");
return 0; return 0;
} }
static struct PDUType {
char *typename;
int used;
} *pduType;
static int pduTypes;
static const char *
generate_pdu_C_definition(void) {
const char *src;
char *def;
char *dst;
if(pduTypes == 0) return "";
def = malloc(strlen(pduType[0].typename) + 20);
strcpy(def, " -DPDU=");
for(src = pduType[0].typename, dst = def + 7; *src; src++, dst++)
if((*dst = *src) == '-')
*dst = '_';
*dst = 0;
return def;
}
void
asn1c__add_pdu_type(const char *ctypename) {
char *typename = strdup(ctypename);
assert(typename && *typename);
pduType = realloc(pduType, sizeof(pduType[0]) * (pduTypes + 1));
assert(pduType);
pduType[pduTypes].used = 0;
pduType[pduTypes].typename = typename;
pduTypes++;
}
static int
asn1c__pdu_type_lookup(const char *typename) {
int i;
for(i = 0; i < pduTypes; i++) {
struct PDUType *pt = &pduType[i];
if(strcmp(pt->typename, typename) == 0) {
pt->used++;
return 1;
}
}
return 0;
}
static int
need_to_generate_pdu_collection(arg_t *arg) {
if(arg->flags & (A1C_PDU_ALL|A1C_PDU_AUTO))
return 1;
if(arg->flags & A1C_PDU_TYPE)
return (pduTypes > 1) ? 1 : 0;
return 0;
}
static void
pdu_collection_print_unused_types(arg_t *arg) {
int i;
for(i = 0; i < pduTypes; i++) {
struct PDUType *pt = &pduType[i];
if(!pt->used) {
WARNING("Missing type specified in -pdu=%s",
pt->typename);
}
}
}
static int
include_type_to_pdu_collection(arg_t *arg) {
if(!asn1_lang_map[arg->expr->meta_type]
[arg->expr->expr_type].type_cb)
return 0;
if((arg->flags & A1C_PDU_ALL)
|| ((arg->flags & A1C_PDU_AUTO) && !arg->expr->_type_referenced)
|| asn1c__pdu_type_lookup(arg->expr->Identifier)) {
return 1;
}
return 0;
}

View File

@ -62,10 +62,12 @@ enum asn1c_flags {
*/ */
A1C_GEN_PER = 0x1000, A1C_GEN_PER = 0x1000,
/* /*
* -pdu=auto * -pdu={all|auto|Type}
* Generate PDU table * Generate PDU table
*/ */
A1C_PDU_AUTO = 0x2000 A1C_PDU_ALL = 0x2000,
A1C_PDU_AUTO = 0x4000,
A1C_PDU_TYPE = 0x8000
}; };
/* /*
@ -74,4 +76,6 @@ enum asn1c_flags {
int asn1_compile(asn1p_t *asn, const char *datadir, enum asn1c_flags, int asn1_compile(asn1p_t *asn, const char *datadir, enum asn1c_flags,
int argc, int optc, char **argv); int argc, int optc, char **argv);
void asn1c__add_pdu_type(const char *typename);
#endif /* ASN1_COMPILER_H */ #endif /* ASN1_COMPILER_H */