Code covered by the BSD License  

Highlights from
MCG - A Matlab Code Generation Engine

Be the first to rate this file! 6 Downloads (last 30 days) File Size: 6.07 KB File ID: #31009
image thumbnail

MCG - A Matlab Code Generation Engine

by Doug Harriman

 

10 Apr 2011

MCG is an in-place code generation engine. It is a Matlab knock off of Cog by Ned Batchelder.

| Watch this File

File Information
Description

   MCG is a tool for doing in-place code generation. MCG is intended to
   provide the maximum traceability of generated code back to the Matlab
   code generator.
 
   MCG processes a source file looking for sections of specially tagged
   code. The tags that denote generation sections exist in comment
   sections. These sections are expected to contain Matlab code. MCG
   finds the code, executes it, then places text generated back into the
   original source file.
 
   Example:
     Running MCG on itself will add a line of executable Matlab code in
     this documentation header. Example code:
 
   [[[MCG
   mcg.outl('% --Example generated code!--');
   ]]]
   [[[/MCG]]]
 
   To run MCG:
   >> m = mcg;
   >> m.codegen('mcg.m');
 
   After running the example above, the MCG source will have an additional
   line inserted between the "]]]" and "[[[/MCG]]]" lines. Note that MCG
   ships with both C and LaTeX source code generation examples.
 
   The code generation section is denoted by two tags: "[[[MCG]]]" which
   begins the section, and "[[[/MCG]]]" which ends the section. Each tag is
   started by "[[[" and ended by "]]]". All code generated by the section
   is placed between the section start and end tags.
 
   All tags must be on lines which are commented out. MCG only supports
   single line, not block, comments. MCG automatically determines the
   comment characters being used and is thus language independent.
 
   The section opening tag contains the Matlab code to run in order to
   generate code. Any amount of valid Matlab code may exist on the lines
   between "[[[MCG" and "]]]", but the "[[[MCG" and "]]]" must be on their
   own lines. In addition, the section close tag "[[[/MCG]]]" must be on
   its own line.
 
   Generated code is sent to the source file by calling the static method:
   MCG.OUTL. This method will append a carriage return, or a carriage
   return + linefeed to the end of each line it has been passed. The
   correct line ending is determined automatically.
   
   Each block of code is executed in it's own namespace. Variables are not
   retained between block calls. The MCG object provides a USERDATA
   property which is accessible from the executing instance within the
   code being executed. This property can be used to pass data between
   different code generation sections.
 
   The currently executing instance may be retrieved by the code being
   executed by calling the method: MCG.INSTANCE.
 
   MCG tag start and end characters can be customized, as can the section
   start and end characters. Care should be taken that the tag and section
   characters are not common to the language of the source file to reduce
   confusion.
 
   Code blocks are handled in the order in which they exist in the source
   file. Files are processed in the order in which they are passed.
 
   MCG is a Matlab knock off of Cog by Ned Batchelder. See:
   http://nedbatchelder.com/code/cog/index.html#h_Writing_the_source_files
 

MATLAB release MATLAB 7.11 (2010b)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
code generation Doug Harriman 11 Apr 2011 14:18:57

Contact us at files@mathworks.com