This page is still under construction and its content should be ignored. Thank you! 8-) ====== MANET Examples ====== ==== Instrumentation ==== ==== Code Transformations ==== ==== Some More Complex Examples ==== ==== Select ==== Select with full join point chain: select program.file.function.body.loop end Select with only last join point. The chain is induced, produces the same result as above: select loop end Assign the selected join points to a variable for later use: LOOPS: select loop end Assign an alias for specific join points: select ($p=loop).($c=loop) end ==== Apply ==== Apply after a select: select loop end apply println($loop.rank); end Apply on a previously selected set of join points: apply to LOOPS println($loop.rank); end It is possible to perform a natural join on two sets of join points: LOOP_START: select function.body.loop.($loop_start = first) end FUNCTION_FIRST: select function.body.first end apply to LOOP_START::FUNCTION_FIRST // Init counters at the beginning of the function $first.insert before%{counter_[[$loop.uid]] = 0;}%; // Increment counters when entering the loop $loop_start.insert before%{counter_[[$loop.uid]] = counter_[[$loop.uid]] +1;}%; // ... end Use of join points with aliases inside the apply statement: select ($p=loop).($c=loop) end apply $p.perform Interchange($c); end ==== Conditions ==== Using a condition block: select function end apply // ... end condition $function.name == 'kernel' end Combining conditions using && (and) and && (or) operators: select loop end apply $loop.perform Unroll(2); end condition $loop.is_innermost && $loop.type=="for" end Using "filter" conditions on the join point chain: select function{name=='kernel'} end apply // ... end // OR select function{'kernel'} end // uses the default attribute of the join point apply // ... end ==== Aspect Inputs and Outputs ==== Input parameter definition: input funcs, opt end Input parameter definition with default values: input funcs = ['kernel'], opt = ['unroll', 'interchange', 'tile'] end Output definition. Output cannot be initialized inside the **output** block: output optFuncs, code end optFuncs = []; code = ''; ==== Calling Aspects ==== Simple aspect call: call OptimizeProgram(); Calling an aspect with arguments: call OptimizeFunctions(functions, optimizations); Calling an aspect with named arguments: call OptimizeFunctions(opt: optimizations, funcs: ['gridIterate']); Calling an aspect and retrieving the outputs: call optimizer: OptimizeFunctions(functions, optimizations); var changedFuncs = optimizer.optFuncs; var finalCode = optimizer.code; Assigning an aspect call to a variable for later use. Can still use input arguments and outputs as shown before: var optimizer = new OptimizeFunctions(functions, optimizations); call optimizer(); var changedFuncs = optimizer.optFuncs; var finalCode = optimizer.code; ==== Using LARA Actions ==== Actions are used inside apply statements. There are two default actions, **insert** and **def**. Then, it is possible to use weaver-specific actions, which are called with the **perform** keyword: select function{'kernel'} end apply insert before '/* Creating a clone. */'; // add a comment before the function def name = 'original_kernel'; // redefine the name of the kernel function perform Clone('cloned_kernel'); // use a MANET-specific action to create a 'kernel' clone named 'cloned_kernel' end When calling an action we can specify any join point in the chain to be the action target: select function.loop end apply $loop.perform Tile(8); $function.insert before '/* This function was transformed. */'; end It is possible to omit the target, the last join point in the chain is used: select function.loop end apply perform Unroll(2); // performed on the same loop as below $loop.perform Tile(8); // performed on the same loop as above end