Commit 66adab48 authored by Lev Walkin's avatar Lev Walkin
Browse files

-pdu=* changes

parent 610fbba8
0.9.22: 2006-Sep-22
* Added -pdu=all and -pdu=<type> switches to asn1c.
0.9.21: 2006-Sep-17
* skeletons/standard-modules directory is now used for standard types.
......
......@@ -4,7 +4,7 @@ asn1c \- ASN.1 Compiler
.SH SYNOPSIS
asn1c [\fB\-E\fR [\fB-F\fR] | \fB\-P\fR | \fB\-R\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]
\fIinfile\fR...
.SH DESCRIPTION
......@@ -30,7 +30,7 @@ and other encoding rules.
.TP
\fICodecs Generation Options\fR
.br
.B \-gen-PER \-pdu=auto
.B \-gen-PER \-pdu=\fR{\fBall\fR|\fBauto\fR|\fIType\fR}
.TP
\fIOutput Options\fR
.br
......@@ -75,7 +75,7 @@ Enable ASN.1 syntax tree fixer debugging during the fixing stage.
.B \-Wdebug-compiler
Enable debugging during the actual compile time.
.SH LANGUAGE OPTIONS
.TP
.TP
.B \-fbless-SIZE
Allow SIZE() constraint for INTEGER, ENUMERATED, and other types for which this
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
Generate Packed Encoding Rules (PER) support code.
.TP
.B \-pdu=auto
Generate PDU tables by discovering Protocol Data Units automatically.
.B \-pdu=\fR{\fBall\fR|\fBauto\fR|\fIType\fR}
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
.TP
.B \-print-constraints
......
......@@ -123,12 +123,19 @@ main(int ac, char **av) {
case 'p':
if(strncmp(optarg, "du=", 3) == 0) {
char *pduname = optarg + 3;
if(strcmp(pduname, "auto")) {
fprintf(stderr, "-pdu=%s: expected -pdu=auto\n",
if(strcmp(pduname, "all") == 0) {
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);
exit(EX_USAGE);
}
asn1_compiler_flags |= A1C_PDU_AUTO;
} else if(strcmp(optarg, "rint-class-matrix") == 0) {
asn1_printer_flags |= APF_PRINT_CLASS_MATRIX;
} else if(strcmp(optarg, "rint-constraints") == 0) {
......@@ -456,7 +463,7 @@ usage(const char *av0) {
"\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"
" -print-class-matrix Print out the collected object class matrix (debug)\n"
......
......@@ -23,12 +23,14 @@ if test -z "$ASN1PDU" \
exit
fi
CMDOPTS="-pdu=${ASN1PDU} ${ASN1CMDOPTS} ${ASN1MODULES}"
if test -x ../../asn1c/asn1c ; then
echo "Compiling ${ASN1MODULES} using local compiler"
../../asn1c/asn1c -S ../../skeletons ${ASN1CMDOPTS} ${ASN1MODULES} || exit $?
../../asn1c/asn1c -S ../../skeletons ${CMDOPTS} || exit $?
else
echo "Compiling ${ASN1MODULES} using system compiler"
asn1c ${ASN1CMDOPTS} ${ASN1MODULES} || exit $?
asn1c ${CMDOPTS} || exit $?
fi
if test ! -f Makefile.am.sample ; then
......@@ -36,15 +38,14 @@ if test ! -f Makefile.am.sample ; then
exit 1
fi
ASN1DEFPDU=`echo "$ASN1PDU" | tr - _`
CFLAGS="-DPDU=${ASN1DEFPDU}"
EXTRA_CFLAGS=""
if test -f config.h ; then
CFLAGS="-DHAVE_CONFIG_H $CFLAGS"
EXTRA_CFLAGS="-DHAVE_CONFIG_H $EXTRA_CFLAGS"
fi
set -x
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/progname/${PROGNAME}/" \
> Makefile.$$
......
......@@ -4740,7 +4740,7 @@ libsomething_la_SOURCES=$(ASN_MODULE_SOURCES) $(ASN_MODULE_HEADERS)
# This file may be used as an input for make(3)
# Remove the lines below to convert it into a pure .am file
TARGET = rrc-dump
CFLAGS += -DHAVE_CONFIG_H -DPDU=DL_DCCH_Message -DASN_PDU_COLLECTION -I.
CFLAGS += -DHAVE_CONFIG_H -DPDU=DL_DCCH_Message -DASN_PDU_COLLECTION -I.
OBJS=${ASN_MODULE_SOURCES:.c=.o} ${ASN_CONVERTER_SOURCES:.c=.o}
all: DL-DCCH-Message.c $(TARGET)
......@@ -4761,7 +4761,7 @@ clean:
regen: 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
......@@ -4770,7 +4770,7 @@ DL-DCCH-Message.c: ../sample.makefile.regen ../rrc.asn1
make
regen-makefile:
ASN1CMDOPTS="-fcompound-names -pdu=auto -gen-PER" \
ASN1CMDOPTS="-pdu=auto -fcompound-names -gen-PER" \
ASN1MODULES="../rrc.asn1" \
ASN1PDU=DL-DCCH-Message \
PROGNAME=rrc-dump \
......
......@@ -51,7 +51,6 @@ typedef struct arg_s {
struct compiler_streams *target;
asn1p_t *asn;
//asn1p_module_t *mod;
asn1p_expr_t *expr;
int embed;
......
......@@ -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_copy_over(arg_t *arg, char *path);
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_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
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");
if(generate_pdu_collection_file(arg))
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"
"# Remove the lines below to convert it into a pure .am file\n"
"TARGET = progname\n"
"CFLAGS +=%s -I.\n"
"CFLAGS +=%s%s -I.\n"
"OBJS=${ASN_MODULE_SOURCES:.c=.o}"
" ${ASN_CONVERTER_SOURCES:.c=.o}\n"
"\nall: $(TARGET)\n"
......@@ -150,7 +154,10 @@ asn1c_save_compiled_output(arg_t *arg, const char *datadir,
"\n\trm -f $(OBJS)\n"
"\nregen: regenerate-from-asn1-source\n"
"\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++)
......@@ -483,9 +490,7 @@ generate_pdu_collection_file(arg_t *arg) {
TQ_FOR(mod, &(arg->asn->modules), mod_next) {
TQ_FOR(arg->expr, &(mod->members), next) {
if(arg->expr->_type_referenced
|| !asn1_lang_map[arg->expr->meta_type]
[arg->expr->expr_type].type_cb)
if(!include_type_to_pdu_collection(arg))
continue;
fprintf(fp, "extern struct asn_TYPE_descriptor_s "
"asn_DEF_%s;\n",
......@@ -498,9 +503,7 @@ generate_pdu_collection_file(arg_t *arg) {
TQ_FOR(mod, &(arg->asn->modules), mod_next) {
int mod_printed = 0;
TQ_FOR(arg->expr, &(mod->members), next) {
if(arg->expr->_type_referenced
|| !asn1_lang_map[arg->expr->meta_type]
[arg->expr->expr_type].type_cb)
if(!include_type_to_pdu_collection(arg))
continue;
if(!mod_printed++)
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");
pdu_collection_print_unused_types(arg);
fclose(fp);
fprintf(stderr, "Generated pdu_collection.c\n");
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;
}
......@@ -62,10 +62,12 @@ enum asn1c_flags {
*/
A1C_GEN_PER = 0x1000,
/*
* -pdu=auto
* -pdu={all|auto|Type}
* 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 argc, int optc, char **argv);
void asn1c__add_pdu_type(const char *typename);
#endif /* ASN1_COMPILER_H */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment