blob: f604687b24c792ccd910b0efb2d3dc55dd6add53 [file] [log] [blame]
vlmfa67ddc2004-06-03 03:38:44 +00001#ifndef _ASN1_COMPILED_OUTPUT_H_
2#define _ASN1_COMPILED_OUTPUT_H_
3
4/*
5 * An elementary chunk of target language text.
6 */
7typedef struct out_chunk {
8 char *buf;
9 int len;
10
11 TQ_ENTRY(struct out_chunk) next;
12} out_chunk_t;
13
14typedef struct compiler_streams {
15 enum {
vlm6e73a042004-08-11 07:17:22 +000016 OT_IGNORE = -1,
17 OT_ASSERT = 0,
vlm33a4ff12004-08-11 05:21:32 +000018 OT_INCLUDES, /* #include files */
19 OT_DEPS, /* Dependencies (other than #includes) */
vlmfa67ddc2004-06-03 03:38:44 +000020 OT_TYPE_DECLS, /* Type declarations */
21 OT_FUNC_DECLS, /* Function declarations */
vlmb2839012004-08-20 13:37:01 +000022 OT_CTABLES, /* Constraint tables */
vlmfa67ddc2004-06-03 03:38:44 +000023 OT_CODE, /* Some code */
vlmb2839012004-08-20 13:37:01 +000024 OT_STAT_DEFS, /* Static definitions */
vlmfa67ddc2004-06-03 03:38:44 +000025 OT_MAX
26 } target;
vlmb2839012004-08-20 13:37:01 +000027
28 struct compiler_stream_destination_s {
29 TQ_HEAD(out_chunk_t) chunks;
30 int indent_level;
31 int indented;
32 } destination[OT_MAX];
vlmfa67ddc2004-06-03 03:38:44 +000033} compiler_streams_t;
34
35static char *_compiler_stream2str[] __attribute__ ((unused))
vlmb2839012004-08-20 13:37:01 +000036 = { "ASSERT", "INCLUDES", "DEPS", "TYPE-DECLS", "FUNC-DECLS", "CTABLES", "CODE", "STAT-DEFS" };
vlmfa67ddc2004-06-03 03:38:44 +000037
38int asn1c_compiled_output(arg_t *arg, const char *fmt, ...);
39
vlm33a4ff12004-08-11 05:21:32 +000040
41/*****************************************************************
42 * Useful macros for invoking asn1c_compiled_output() and friends.
43 */
44
45/* Redirect output to a different stream. */
46#define REDIR(foo) do { arg->target->target = foo; } while(0)
vlmb2839012004-08-20 13:37:01 +000047#define INDENT_LEVEL \
48 arg->target->destination[arg->target->target].indent_level
49#define INDENT(val) INDENT_LEVEL += (val)
50#define INDENTED(code) do { \
51 INDENT(+1); \
52 do { code; } while(0); \
53 INDENT(-1); \
vlm33a4ff12004-08-11 05:21:32 +000054 } while(0)
55
vlmb2839012004-08-20 13:37:01 +000056#define FLAT(code) do { \
57 int _il = INDENT_LEVEL; \
58 INDENT_LEVEL = 0; \
59 do { code; } while(0); \
60 INDENT_LEVEL = _il; \
vlm33a4ff12004-08-11 05:21:32 +000061 } while(0)
62
63#define EMBED(ev) do { \
64 int saved_target = arg->target->target; \
65 REDIR(OT_TYPE_DECLS); \
66 arg->embed++; \
67 INDENTED(arg_t _tmp = *arg; \
68 _tmp.expr = ev; \
69 _tmp.default_cb(&_tmp); \
70 ); \
71 arg->embed--; \
72 assert(arg->target->target == OT_TYPE_DECLS); \
73 REDIR(saved_target); \
74 } while(0)
75
76/* Output a piece of text into a default stream */
77#define OUT(fmt, args...) asn1c_compiled_output(arg, fmt, ##args)
vlmb2839012004-08-20 13:37:01 +000078#define OUT_NOINDENT(fmt, args...) do { \
79 int _saved_indent = INDENT_LEVEL; \
80 INDENT_LEVEL = 0; \
81 OUT(fmt, ##args); \
82 INDENT_LEVEL = _saved_indent; \
vlm33a4ff12004-08-11 05:21:32 +000083} while(0)
84
85/* Generate #include line */
86#define GEN_INCLUDE(filename) do { \
87 int saved_target = arg->target->target; \
88 REDIR(OT_INCLUDES); \
89 OUT_NOINDENT("#include <%s.h>\n", filename); \
90 REDIR(saved_target); \
91} while(0)
92
93/* Generate ASN.1 type declaration */
94#define GEN_DECLARE(expr) do { \
95 int saved_target = arg->target->target; \
96 REDIR(OT_DEPS); \
97 OUT_NOINDENT("extern asn1_TYPE_descriptor_t " \
98 "asn1_DEF_%s;\n", \
99 MKID(expr->Identifier)); \
100 REDIR(saved_target); \
101} while(0)
102
vlmfa67ddc2004-06-03 03:38:44 +0000103#endif /* _ASN1_COMPILED_OUTPUT_H_ */