Generating Java from m4 macros
Pounding code on my now-two-week-old open source project PigIron , I am confronted by a problem I've seen before: a wire protocol with a large number of data types. The macro language Gnu m4 rides to the rescue!
There are 100 remote-callable functions in IBM z/VM V5R3.0 Systems Management Application Programming (VSMAPI) at which PigIron is targeted. Many parameter types are common between many or all VSMAPI individual functions, but many or most possess function-specific struct or array-of-struct types.
I'm now generating the .java files to embody these struct and array types from simple description files in m4, specifically, Gnu m4, using macros which I call (in order to have some name for the directory in which they are stored) PigGen.
Below are two description files. One generates MemorySegmentStruct.java and the other generates MemorySegmentArray.java for the array which contains repeating instances of (an intermediate counted-struct representation (not shown here) of) the memory segment struct. The code for pigstruct.m4 and pigarray.m4 which do all the work is in the PigIron source tree (though not in the first release. 0.1, currently posted on SourceForge ).
{geshibot}include(`pigstruct.m4')dnl \\ memory_segment_struct.m4
pigparm_start()dnl
pigparm_import(`com.softwoehr.pigiron.access.*')dnl
pigparm_class(`MemorySegmentStruct', `VSMStruct',`com.softwoehr.pigiron.access.paramstructs',`dnl
/**
* MemorySegmentStruct implements the memory_segment_structure from Shared_Memory_Query
* @see com.softwoehr.pigiron.functions.SharedMemoryQuery
*/')dnl
pigparm_constant(`public', `int', `MEMORY_SEGMENT_STATUS_SKELETON', `1', `Skeleton')dnl
pigparm_constant(`public', `int', `MEMORY_SEGMENT_STATUS_AVAILABLE_NONRESTRICTED', `2', `Available and nonrestricted')dnl
pigparm_constant(`public', `int', `MEMORY_SEGMENT_STATUS_AVAILABLE_RESTRICTED', `3', `Available and restricted')dnl
pigparm_constant(`public', `int', `MEMORY_SEGMENT_STATUS_PENDING_PURGE', `4', `Pending purge')dnl
pigparm_ctors()dnl
pigparm_model_start()dnl
pigparm_model_parm(`VSMInt4', `-1', `memory_segment_name_length')dnl
pigparm_model_parm(`VSMString', `null', `memory_segment_name')dnl
pigparm_model_parm(`VSMInt1', `-1', `memory_segment_status')dnl
pigparm_model_parm(`VSMInt4', `-1', `page_range_array_length')dnl
pigparm_model_parm(`PageRangeArray', `null', `page_range_array')dnl
pigparm_model_end()dnl
pigparm_endclass()dnl
pigparm_end()dnl{/geshibot}
{geshibot}include(`pigarray.m4')dnl \\ memory_segment_array.m4
pigparm_start()dnl
pigparm_import(`com.softwoehr.pigiron.access.*')dnl
pigparm_class(`MemorySegmentArray', `VSMArray',`com.softwoehr.pigiron.access.paramstructs',`dnl
/**
* MemorySegmentArray implements the memory_segment_array from Shared_Memory_Query
* @see com.softwoehr.pigiron.functions.SharedMemoryQuery
* @see com.softwoehr.pigiron.access.paramstructs.PageRangeStruct
*/')dnl
pigparm_ctors()dnl
pigparm_model_start()dnl
pigparm_model_parm(`MemorySegmentStructCounted', `null', `memory_segment_structure_counted')dnl
pigparm_model_end()dnl
pigparm_endclass()dnl
pigparm_end()dnl{/geshibot}

