Sunday, February 3, 2008

Generating Memory Allocation for C Variables for the ASN.1 Types

There's now a function to generate the C memory allocation code for type assignments.

*Asn1cTest> declareTypePointer (TYPEASS "Type12" Nothing type12)

/* Declare a pointer to a Type12 type */
Type12_t *type12;

/* Allocate an instance of Type12 */
type12 = calloc(1, sizeof(Type12_t)); /* not malloc! */
assert(type12); /* Assume infinite memory */

There's also a function to generate random type assignments and values but the formatting is not quite right for pretty / show. This may not matter (at the moment) as the next step is to generate C code to assign values to the C form of the ASN.1 types.

*Asn1cTest> genModule''
[Type1 ::= CHOICE {i INTEGER}: Type1 ::= i:1,
Type2 ::= CHOICE {xc INTEGER}: Type2 ::= xc:1,
Type3 ::= SEQUENCE {}: Type3 ::= {},
Type4 ::= CHOICE {k [1] IMPLICIT INTEGER,
h INTEGER}: Type4 ::= h:4,
Type5 ::= SEQUENCE {}: Type5 ::= {},
Type6 ::= CHOICE {a [5] IMPLICIT SEQUENCE {m [-3] IMPLICIT INTEGER},
m INTEGER}: Type6 ::= m:-3,
Type7 ::= BIT STRING (SIZE (5..6)) (SIZE (6..6)) (SIZE (6..6)): Type7 ::= '001110'B,
Type8 ::= BIT STRING: Type8 ::= '0010'B,
Type9 ::= INTEGER: Type9 ::= -9,
Type10 ::= INTEGER: Type10 ::= 6]

No comments: