Commit 7d5d9303 authored by Lev Walkin's avatar Lev Walkin

more precise OER and PER code bundling

parent 30566d13
#include "asn1c_internal.h" #include "asn1c_internal.h"
#include "asn1c_compat.h" #include "asn1c_compat.h"
#ifndef PATH_MAX
#define PATH_MAX 1024
#endif
/* Normally file permissions are (DEFFILEMODE & ~umask(2)) */ /* Normally file permissions are (DEFFILEMODE & ~umask(2)) */
#ifndef DEFFILEMODE /* Normally in <sys/stat.h> */ #ifndef DEFFILEMODE /* Normally in <sys/stat.h> */
......
This diff is collapsed.
#ifndef ASN1C_FDEPS_H #ifndef ASN1C_FDEPS_H
#define ASN1C_FDEPS_H #define ASN1C_FDEPS_H
typedef struct asn1c_fdeps_s { typedef struct {
char *filename; /* Or 0, if root. */ char *filename;
int lineno;
enum fdep_usage { int column;
FDEP_IGNORE = -1, /* Ignore contents of the section */ } asn1c_dep_filename;
FDEP_NOTUSED = 0,
FDEP_REFERRED = 1, /* Dynamic list of dependencies */
FDEP_CONVERTER = 2, /* Name of the int main() file */ /*
FDEP_COMMON_FILES = 3, /* Section for mandatory dependencies */ * Format:
FDEP_CODEC_OER = 4, /* Use contents only if -gen-OER */ * <observed-name> [<dependent-name> ...]
FDEP_CODEC_PER = 8, /* Use contents only if -gen-PER */ */
} usage; /* Some file refers to it */ typedef struct {
asn1c_dep_filename **deps;
struct asn1c_fdeps_s **elements; size_t deps_count;
int el_size; } asn1c_dep_chain;
int el_count;
} asn1c_fdeps_t; /*
* A single dependency chain, marked with the usage tag and activation tag.
asn1c_fdeps_t *asn1c_read_file_dependencies(arg_t *arg, const char *datadir); */
typedef struct {
enum asn1c_dep_section {
FDEP_IGNORE = 0, /* Section is not used */
FDEP_DEFAULT = (1 << 1), /* Default dependency list */
FDEP_REFERRED = (1 << 2), /* Dynamic list of dependencies */
FDEP_CONVERTER = (1 << 3), /* Name of the file with int main() */
FDEP_COMMON_FILES = (1 << 4), /* Section for mandatory dependencies */
FDEP_CODEC_OER = (1 << 5), /* Use contents only if -gen-OER */
FDEP_CODEC_PER = (1 << 6), /* Use contents only if -gen-PER */
} section; /* Some file refers to it */
/* Whether this chain is alive and has to be present in the output */
struct {
int active;
char *by;
} activated;
asn1c_dep_chain *chain;
} asn1c_tagged_dep_chain;
typedef struct {
asn1c_tagged_dep_chain **chains;
size_t chains_count;
} asn1c_dep_chainset;
asn1c_dep_chainset *asn1c_read_file_dependencies(arg_t *arg,
const char *datadir);
/* Data may be a filename or an "#include <>" string. */ /* Data may be a filename or an "#include <>" string. */
int asn1c_activate_dependency(asn1c_fdeps_t *deps, asn1c_fdeps_t *cur, void asn1c_activate_dependency(asn1c_dep_chainset *deps, const char *data,
const char *data); const char *by);
asn1c_dep_chain *asn1c_deps_flatten(const asn1c_dep_chainset *deps,
enum asn1c_dep_section);
asn1c_fdeps_t *asn1c_deps_flatten(const asn1c_fdeps_t *deps); void asn1c_dep_chain_free(asn1c_dep_chain *);
void asn1c_deps_freelist(asn1c_fdeps_t *deps); void asn1c_dep_chainset_free(asn1c_dep_chainset *);
#endif /* ASN1C_FDEPS_H */ #endif /* ASN1C_FDEPS_H */
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include <string.h> /* for strlen(3) and memset(3) */ #include <string.h> /* for strlen(3) and memset(3) */
#include <ctype.h> /* for isalnum(3) */ #include <ctype.h> /* for isalnum(3) */
#include <sys/types.h> /* for fstat(2) */ #include <sys/types.h> /* for fstat(2) */
#include <limits.h> /* for PATH_MAX */
#include <stdarg.h> #include <stdarg.h>
#include <errno.h> #include <errno.h>
#include <assert.h> #include <assert.h>
...@@ -22,6 +23,10 @@ ...@@ -22,6 +23,10 @@
#include <unistd.h> /* for unlink(2) */ #include <unistd.h> /* for unlink(2) */
#endif #endif
#ifndef PATH_MAX
#define PATH_MAX 1024
#endif
#ifdef _WIN32 #ifdef _WIN32
#include <io.h> #include <io.h>
#include <malloc.h> #include <malloc.h>
......
...@@ -38,10 +38,10 @@ enum include_type_result { ...@@ -38,10 +38,10 @@ enum include_type_result {
TI_INCLUDED_FROM_CMDLINE TI_INCLUDED_FROM_CMDLINE
}; };
static int asn1c_dump_streams(arg_t *arg, asn1c_fdeps_t *, int, char **); static int asn1c_dump_streams(arg_t *arg, asn1c_dep_chainset *, int, char **);
static int asn1c_print_streams(arg_t *arg); 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_dep_chainset *, int, char **);
static int asn1c_copy_over(arg_t *arg, char *path); static int asn1c_copy_over(arg_t *arg, const char *path, const char *msg);
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 need_to_generate_pdu_collection(arg_t *arg);
static abuf *generate_pdu_collection(arg_t *arg); static abuf *generate_pdu_collection(arg_t *arg);
...@@ -54,8 +54,8 @@ static void asn1c__cleanup_pdu_type(void); ...@@ -54,8 +54,8 @@ static void asn1c__cleanup_pdu_type(void);
static int asn1c__pdu_type_lookup(const char *typename); static int asn1c__pdu_type_lookup(const char *typename);
static int static int
asn1c__save_library_makefile(arg_t *arg, const asn1c_fdeps_t *deps, const char *datadir, const char *makefile_name) { asn1c__save_library_makefile(arg_t *arg, const asn1c_dep_chainset *deps,
asn1c_fdeps_t *dlist; const char *datadir, const char *makefile_name) {
asn1p_module_t *mod; asn1p_module_t *mod;
FILE *mkf; FILE *mkf;
...@@ -90,49 +90,51 @@ asn1c__save_library_makefile(arg_t *arg, const asn1c_fdeps_t *deps, const char * ...@@ -90,49 +90,51 @@ asn1c__save_library_makefile(arg_t *arg, const asn1c_fdeps_t *deps, const char *
/* /*
* Move necessary skeleton files and add them to Makefile.am.targets. * Move necessary skeleton files and add them to Makefile.am.targets.
*/ */
dlist = asn1c_deps_flatten(deps); asn1c_dep_chain *dlist = asn1c_deps_flatten(deps, ~FDEP_CONVERTER);
if(dlist) { if(dlist) {
char buf[8129]; char dstpath[PATH_MAX];
char *dir_end; char *dir_end;
size_t dlen = strlen(datadir); size_t dlen = strlen(datadir);
assert(dlen < (sizeof(buf) / 2 - 2)); assert(dlen < (sizeof(dstpath) / 2 - 2));
memcpy(buf, datadir, dlen); memcpy(dstpath, datadir, dlen);
dir_end = buf + dlen; dir_end = dstpath + dlen;
*dir_end++ = '/'; *dir_end++ = '/';
for(int i = 0; i < dlist->el_count; i++) { for(size_t i = 0; i < dlist->deps_count; i++) {
char where[32]; /* Location of the */
char *what_kind; /* HEADERS or SOURCES */ char *what_kind; /* HEADERS or SOURCES */
char *fname = dlist->elements[i]->filename; const asn1c_dep_filename *dep_file = dlist->deps[i];
char *fname = dep_file->filename;
char *dotH; char *dotH;
assert(strlen(fname) < (sizeof(buf) / 2)); assert(strlen(fname) < (sizeof(dstpath) / 2));
strcpy(dir_end, fname); strcpy(dir_end, fname);
if(dlist->elements[i]->usage == FDEP_CONVERTER if(arg->flags & A1C_DEBUG) {
&& !(arg->flags & A1C_GEN_EXAMPLE)) snprintf(where, sizeof(where), "(line %d col %d)",
continue; dep_file->lineno, dep_file->column);
} else {
where[0] = '\0';
}
if(asn1c_copy_over(arg, buf) == -1) { if(asn1c_copy_over(arg, dstpath, where) == -1) {
safe_fprintf(mkf, ">>>ABORTED<<<"); safe_fprintf(mkf, ">>>ABORTED<<<");
fclose(mkf); fclose(mkf);
return -1; return -1;
} }
/* no CONVERTER data in Makefile.am.targets */ /* HEADERS versus SOURCES */
if(dlist->elements[i]->usage != FDEP_CONVERTER) { dotH = strrchr(fname, 'h');
/* HEADERS versus SOURCES */ if(dotH && fname < dotH && dotH[-1] == '.' && !dotH[1]) {
dotH = strrchr(fname, 'h'); what_kind = "HEADERS";
if(dotH && fname<dotH && dotH[-1] == '.' && !dotH[1]) } else {
what_kind = "HEADERS"; what_kind = "SOURCES";
else }
what_kind = "SOURCES"; safe_fprintf(mkf, "ASN_MODULE_%s+=%s\n", what_kind, fname);
safe_fprintf(mkf, "ASN_MODULE_%s+=%s\n",
what_kind, fname);
}
} }
asn1c_deps_freelist(dlist); asn1c_dep_chain_free(dlist);
} }
safe_fprintf( safe_fprintf(
...@@ -156,8 +158,8 @@ asn1c__save_library_makefile(arg_t *arg, const asn1c_fdeps_t *deps, const char * ...@@ -156,8 +158,8 @@ asn1c__save_library_makefile(arg_t *arg, const asn1c_fdeps_t *deps, const char *
} }
static int static int
asn1c__save_example_makefile(arg_t *arg, const asn1c_fdeps_t *deps, asn1c__save_example_makefile(arg_t *arg, const asn1c_dep_chainset *deps,
const char *makefile_name, const char *datadir, const char *makefile_name,
const char *library_makefile_name, int argc, const char *library_makefile_name, int argc,
char **argv) { char **argv) {
FILE *mkf; FILE *mkf;
...@@ -180,15 +182,21 @@ asn1c__save_example_makefile(arg_t *arg, const asn1c_fdeps_t *deps, ...@@ -180,15 +182,21 @@ asn1c__save_example_makefile(arg_t *arg, const asn1c_fdeps_t *deps,
need_to_generate_pdu_collection(arg) ? "-DASN_PDU_COLLECTION " : ""); need_to_generate_pdu_collection(arg) ? "-DASN_PDU_COLLECTION " : "");
if(arg->flags & A1C_GEN_EXAMPLE) { if(arg->flags & A1C_GEN_EXAMPLE) {
asn1c_fdeps_t *dlist = asn1c_deps_flatten(deps); asn1c_dep_chain *dlist = asn1c_deps_flatten(deps, FDEP_CONVERTER);
if(dlist) { if(dlist) {
/* only CONVERTER data in the makefile */ for(size_t i = 0; i < dlist->deps_count; i++) {
for(int i = 0; i < dlist->el_count; i++) { char dstpath[PATH_MAX];
if(dlist->elements[i]->usage == FDEP_CONVERTER) { int ret = snprintf(dstpath, sizeof(dstpath), "%s/%s", datadir,
safe_fprintf(mkf, "\\\n\t%s", dlist->elements[i]->filename); dlist->deps[i]->filename);
assert(ret > 0 && (size_t)ret < sizeof(dstpath));
if(asn1c_copy_over(arg, dstpath, "implicit") == -1) {
safe_fprintf(mkf, ">>>ABORTED<<<");
fclose(mkf);
return -1;
} }
safe_fprintf(mkf, "\\\n\t%s", dlist->deps[i]->filename);
} }
asn1c_deps_freelist(dlist); asn1c_dep_chain_free(dlist);
} }
} }
...@@ -237,7 +245,6 @@ can_generate_pdu_collection(arg_t *arg) { ...@@ -237,7 +245,6 @@ can_generate_pdu_collection(arg_t *arg) {
int int
asn1c_save_compiled_output(arg_t *arg, const char *datadir, asn1c_save_compiled_output(arg_t *arg, const char *datadir,
int argc, int optc, char **argv) { int argc, int optc, char **argv) {
asn1c_fdeps_t *deps = 0;
int ret = -1; int ret = -1;
/* /*
...@@ -247,6 +254,7 @@ asn1c_save_compiled_output(arg_t *arg, const char *datadir, ...@@ -247,6 +254,7 @@ asn1c_save_compiled_output(arg_t *arg, const char *datadir,
return -1; return -1;
} }
asn1c_dep_chainset *deps;
do { do {
asn1p_module_t *mod; asn1p_module_t *mod;
...@@ -281,14 +289,14 @@ asn1c_save_compiled_output(arg_t *arg, const char *datadir, ...@@ -281,14 +289,14 @@ asn1c_save_compiled_output(arg_t *arg, const char *datadir,
if(ret) break; if(ret) break;
if(arg->flags & A1C_GEN_EXAMPLE) { if(arg->flags & A1C_GEN_EXAMPLE) {
ret = asn1c__save_example_makefile(arg, deps, "Makefile.am.example", ret = asn1c__save_example_makefile(
"Makefile.am.libasncodec", argc, arg, deps, datadir, "Makefile.am.example",
argv); "Makefile.am.libasncodec", argc, argv);
if(ret) break; if(ret) break;
} }
} while(0); } while(0);
asn1c_deps_freelist(deps); asn1c_dep_chainset_free(deps);
asn1c__cleanup_pdu_type(); asn1c__cleanup_pdu_type();
return ret; return ret;
...@@ -298,8 +306,9 @@ asn1c_save_compiled_output(arg_t *arg, const char *datadir, ...@@ -298,8 +306,9 @@ asn1c_save_compiled_output(arg_t *arg, const char *datadir,
* Dump the streams. * Dump the streams.
*/ */
static int static int
asn1c_dump_streams(arg_t *arg, asn1c_fdeps_t *deps, int optc, char **argv) { asn1c_dump_streams(arg_t *arg, asn1c_dep_chainset *deps, int optc,
if(arg->flags & A1C_PRINT_COMPILED) { char **argv) {
if(arg->flags & A1C_PRINT_COMPILED) {
return asn1c_print_streams(arg); return asn1c_print_streams(arg);
} else { } else {
return asn1c_save_streams(arg, deps, optc, argv); return asn1c_save_streams(arg, deps, optc, argv);
...@@ -330,8 +339,9 @@ asn1c_print_streams(arg_t *arg) { ...@@ -330,8 +339,9 @@ asn1c_print_streams(arg_t *arg) {
} }
static int static int
asn1c_save_streams(arg_t *arg, asn1c_fdeps_t *deps, int optc, char **argv) { asn1c_save_streams(arg_t *arg, asn1c_dep_chainset *deps, int optc,
asn1p_expr_t *expr = arg->expr; char **argv) {
asn1p_expr_t *expr = arg->expr;
compiler_streams_t *cs = expr->data; compiler_streams_t *cs = expr->data;
out_chunk_t *ot; out_chunk_t *ot;
FILE *fp_c, *fp_h; FILE *fp_c, *fp_h;
...@@ -373,7 +383,7 @@ asn1c_save_streams(arg_t *arg, asn1c_fdeps_t *deps, int optc, char **argv) { ...@@ -373,7 +383,7 @@ asn1c_save_streams(arg_t *arg, asn1c_fdeps_t *deps, int optc, char **argv) {
if(TQ_FIRST(&(cs->destination[idx].chunks)) && *msg) \ if(TQ_FIRST(&(cs->destination[idx].chunks)) && *msg) \
safe_fprintf(fp, "\n/* %s */\n", msg); \ safe_fprintf(fp, "\n/* %s */\n", msg); \
TQ_FOR(ot, &(cs->destination[idx].chunks), next) { \ TQ_FOR(ot, &(cs->destination[idx].chunks), next) { \
if(actdep) asn1c_activate_dependency(deps, 0, ot->buf); \ if(actdep) asn1c_activate_dependency(deps, ot->buf, header_id); \
safe_fwrite(ot->buf, ot->len, 1, fp); \ safe_fwrite(ot->buf, ot->len, 1, fp); \
} \ } \
} while(0) } while(0)
...@@ -554,7 +564,7 @@ real_copy(const char *src, const char *dst) { ...@@ -554,7 +564,7 @@ real_copy(const char *src, const char *dst) {
} }
static int static int
asn1c_copy_over(arg_t *arg, char *path) { asn1c_copy_over(arg_t *arg, const char *path, const char *msg) {
#ifdef _WIN32 #ifdef _WIN32
int use_real_copy = 1; int use_real_copy = 1;
#else #else
...@@ -595,10 +605,12 @@ asn1c_copy_over(arg_t *arg, char *path) { ...@@ -595,10 +605,12 @@ asn1c_copy_over(arg_t *arg, char *path) {
} }
} }
safe_fprintf(stderr, "%s %s\t-> %s\n", const int has_msg = msg && *msg;
use_real_copy ? "Copied" : "Symlinked", path, fname); safe_fprintf(stderr, "%s %s\t-> %s%s%s\n",
use_real_copy ? "Copied" : "Symlinked", path, fname,
has_msg ? " " : "", has_msg ? msg : "");
return 1; return 1;
} }
......
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
#include <asn_application.h> #include <asn_application.h>
#include <asn_codecs_prim.h> #include <asn_codecs_prim.h>
#include <NativeInteger.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
......
...@@ -69,17 +69,19 @@ CONVERTER: # THIS IS A SPECIAL SECTION ...@@ -69,17 +69,19 @@ CONVERTER: # THIS IS A SPECIAL SECTION
converter-example.c # A default name for the example transcoder converter-example.c # A default name for the example transcoder
CODEC-OER: # THIS IS A SPECIAL SECTION CODEC-OER: # THIS IS A SPECIAL SECTION
oer_decoder.h oer_decoder.c OPEN_TYPE.h # OER decoding support oer_decoder.h
oer_encoder.h oer_encoder.c # OER encoding support oer_encoder.h
oer_support.h oer_support.c # OER support oer_support.h
oer_decoder.h oer_decoder.c OPEN_TYPE.h
oer_encoder.h oer_encoder.c
oer_support.h oer_support.c
OPEN_TYPE.h OPEN_TYPE_oer.c constr_CHOICE.h OPEN_TYPE.h OPEN_TYPE_oer.c constr_CHOICE.h
INTEGER_oer.c INTEGER.h INTEGER.h INTEGER_oer.c
OCTET_STRING_oer.c BIT_STRING.h BIT_STRING_oer.c OCTET_STRING_oer.c
NativeInteger_oer.c NativeInteger.h NativeInteger.h NativeInteger_oer.c
NativeEnumerated_oer.c NativeEnumerated.h NativeEnumerated.h NativeEnumerated_oer.c
constr_SEQUENCE_oer.c constr_SEQUENCE.h constr_CHOICE.h constr_CHOICE_oer.c
constr_CHOICE_oer.c constr_SEQUENCE.h constr_SEQUENCE_oer.c
constr_SET_OF_oer.c constr_SET_OF.h asn_SET_OF.h asn_SET_OF.c constr_SET_OF.h constr_SET_OF_oer.c
BIT_STRING_oer.c
CODEC-PER: # THIS IS A SPECIAL SECTION CODEC-PER: # THIS IS A SPECIAL SECTION
...@@ -30,7 +30,7 @@ verify() { ...@@ -30,7 +30,7 @@ verify() {
cleanup cleanup
asncmd="${top_builddir}/asn1c/asn1c -flink-skeletons -S ${top_srcdir}/skeletons $flags test.asn" asncmd="${top_builddir}/asn1c/asn1c -Wdebug-compiler -flink-skeletons -S ${top_srcdir}/skeletons $flags test.asn"
{ {
echo "$asncmd" echo "$asncmd"
...@@ -52,9 +52,12 @@ verify_type_with_variants() { ...@@ -52,9 +52,12 @@ verify_type_with_variants() {
} }
verify_compile_and_link_variants() { verify_compile_and_link_variants() {
for type in INTEGER "ENUMERATED{foo}" NULL BOOLEAN "BIT STRING" \ for type in INTEGER "INTEGER(0..1)" "ENUMERATED{foo}" NULL BOOLEAN \
"OBJECT IDENTIFIER" "RELATIVE-OID" "SEQUENCE{f INTEGER}" \ "BIT STRING" \
"CHOICE{f INTEGER}" "OCTET STRING" IA5String UTF8String \ "OBJECT IDENTIFIER" "RELATIVE-OID" \
"SEQUENCE{f INTEGER}" \
"CHOICE{f INTEGER}" \
"OCTET STRING" IA5String "IA5String(SIZE(1))" UTF8String \
REAL "SET OF INTEGER" "SEQUENCE OF INTEGER"; do REAL "SET OF INTEGER" "SEQUENCE OF INTEGER"; do
verify_type_with_variants "$type" verify_type_with_variants "$type"
...@@ -69,6 +72,8 @@ else ...@@ -69,6 +72,8 @@ else
verify_type_with_variants "$type" verify_type_with_variants "$type"
done done
fi fi
set +x
trap '' EXIT ERR trap '' EXIT ERR
cleanup cleanup
echo "OK"
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