dnl (c)INRIA 2000 Christophe Lavarenne dnl $Id: syndex.m4x,v 1.1 2000/04/17 13:03:01 lavarenn Exp $ divert(-1) # SynDEx v5 generic executive macros definitions (executive generator), # relying on processor-specific or media-specific macros, # see .m4x for macros specific to processor or media type . ################## # ERROR MANAGEMENT # ------ # error_(msg) displays error message with file and line error location define(`error_',`errprint(__file__:__line__: m4: `$1' )') ifdef(`__gnu__',,`dnl GNU m4 predefines the `__gnu__' macro error_(`this file must be processed by GNU m4 (REQUIRED!)')m4exit(1)') ifdef( __file__`_already_included',`error_(`already included')m4exit(1)', `define(__file__`_already_included')') # ------------ # unsupported_(macroName) for TARGET LANGUAGE DEPENDENT macros define(`unsupported_',`def(`$1',`error_(``$1' macro is not supported')')') ########## # COMMENTS # Portable, target language independent, comments must be enclosed # between `comment{' and `}comment', they may include any characters, # including unbalanced quotes, but included braces must be balanced, as in: # `comment{Comments with {balanced} curly braces}comment' # This generates target language dependent comments from the macros # `comment' and `comment_', which are TARGET LANGUAGE DEPENDENT. # ------- # comment{}comment C-style multi-line comments: define(`comment',`pushdef(`comment',`changequote)`'popdef(`comment')')changequote({,})comment_(') define(`comment_', `changequote({,}){/* $1 */}changequote') # Shell-style till-end-of-line comments: # The TARGET LANGUAGE DEPENDENT start-comment character (# for As) is given # as 3rd argument of the patsubst macro in the following definition: #define(`comment_',`changequote({,})patsubst({{$1}},{^},{# })changequote') #define(`comment',`pushdef(`comment',`changequote)`'popdef(`comment') #dnl')changequote({,})comment_(') # ----------- # _(codeline) # ALL TARGET PROCESSOR DEPENDENT CODE IS GENERATED WITH THE MACRO `_' # ALL OTHER DEPENDENCIES ARE DULY ANNOTATED WITH `TARGET ... DEPENDENT'. # _(codeline) generates a newline, indentation spaces, and codeline; # use `indent_(+)' to increase by 2 the number of indentation spaces; # use `indent_(-)' to decrease by 2 the number of indentation spaces; # use `define(`NOindent')' to make the next `_' generate only codeline. define(`_',`ifdef(`NOindent',`undefine(`NOindent')',` indentString')$@') define(`indentString') define(`indent_',`ifelse( $1,+,`pushdef(`indentString', indentString` ')', $1,-,`popdef(`indentString')ifdef(`indentString',,`define(`indentString')'dnl `error_(`more `indent_(-)' than `indent_(+)'')')', `error_(`expected `+' or `-' as argument for `indent_'')')') # ------------------------ # def(macroName, macroDef) # The `def' macro defines macros which are generated by SynDEx, they # generate a trace of the macro call, unless the NOTRACEDEF macro is defined: define(`def', `define(`$1', `ifdef(`NOTRACEDEF', `define(`NOindent')', `comment{''changequote([,])[``$][0($][*)'']changequote``}comment`'')$2')') ################## # SOURCE STRUCTURE # The executive source is structured by pairs of macros which must be balanced # (the second macro of a pair is named as the first, prefixed with `end'). # For example, the pair `processor_' and `endprocessor_' enclose all other # macros (except maybe some header and footer comments). # `pushtag' and `poptag' are used by macro pairs to check their balance, # and to generate unique labels for control structures. # ------- # pushtag(key) Open a new block structure with its own tagged key: define(`tagnumber_',0) dnl block structure counter define(`pushtag', `dnl pushdef(`tag_',`$1_'tagnumber_)dnl push tagged key on tag stack define(`tagnumber_',incr(tagnumber_))dnl next tagnumber ') # ------ # poptag(key) Check block structure balance and pop tag stack if ok. define(`poptag', `ifelse(index(tag_,$1),0, `popdef(`tag_')', dnl if balanced, pop tag stack. `ifdef(`tag_', dnl otherwise complain: `error_(`Unbalanced control structure: expected end'tag_)', `error_(`Unbalanced control structure: no previous '$1`_')')')') # ---------- # processor_(1procrType,2procrName, 3appliName, 4versionStamp,5dateStamp) # Very first macro generated at beginning of file def(`processor_', `dnl *** versionStamp $4 SHOULD be checked 'define(`NOTRACEDEF')`undefine(`NOTRACEDEF')undefine(`NOindent')dnl define(`processorType_', $1)define(`processorName_', $2)dnl include($1.m4x)dnl SynDEx executive macros customization for processor type $1 comment{$4, $5, application $3, processor $2 type=$1}comment undivert`'dnl to allow $1.m4x to generate something after the previous comment sinclude($3.m4x)dnl application specific macros, file MAY not exist sinclude($2.m4x)dnl processor specific macros, file MAY not exist pushtag(`processor')') # ------------- # endprocessor_() Very last macro generated before the end of file def(`endprocessor_',`poptag(`processor')checkTagBalance') define(`checkTagBalance',`ifdef(`tag_', `dnl error_(`Uncomplete control structure: missing end'tag_)dnl popdef(`tag_')checkTagBalance')') ############ # DATA TYPES # Data types are used to check buffers access consistency, and to convert # buffers sizes, specified in type units, into memory address units. # `typedef_' defines a new type with its size in address units: # -------- # typedef_(typeName,typeSize) def(`typedef_', `ifelse($#,2,`ifdef(`$1_size_', `error_(`WARNING: type $1 redefined')')`'define(`$1_size_',$2)', `error_(`Expected arguments: typeName, typeSizeInAddressUnits')')') # The macro-executive specific to the target processor MUST `typedef_' # the `bool' type, that the executive generator uses for conditionning. # It SHOULD also `typedef_' basic C-like types `char, int, float, double'. ################### # MEMORY ALLOCATION # `basicAlloc_' allocates and labels memory cells: TARGET LANGUAGE DEPENDENT # `alloc_' compiles arguments for `basicAlloc_' unless # `_alloc_' if defined for type-specific memory allocations, or # `_alloc_' if defined for name-specific memory allocations (constants) # `basicAlias_' relabels already allocated memory: TARGET LANGUAGE DEPENDENT # `alias_' compiles arguments for `basicAlias_' # The type and size of a label created by `alloc_' and `alias_' are stored # as `