# $Id: rulesfile.pod 13278 2006-07-13 13:40:14Z coke $ =head1 Translation Rules File This document describes the format of the translation rules file used by the translator builder, as documented in L. =head2 Syntax The file contains an entry for each .NET instruction to translate. The entry for an instruction starts with its full name in square brackets on a line of its own. [add] This is followed by a number of entries in a "key = value" format, with one entry per line. The ordering of these entries does not matter. pop = 2 Sometimes a value may need to span multiple lines. When this happens, it is specified as a here-document; that is, the value starts with <. =head3 class This entry specifies the type of instruction. Valid instruction types are: =over 4 =item * op - For any operation that operates only on the stack and results in no change of flow control (for example, add and ceq). An instruction such as debug, which has no effect on the stack or global state, would fit into this category. =item * branch - For any control flow related operation that could transfer control to an instruction other than the next one, but restricted to instructions in the current method (so call or ret are not in this class, for example). =item * load - For any operation that takes data from a location other than the stack and places it onto the stack. =item * store - For any operation that takes data from the stack and stores it in a location other than the stack. =item * calling - For any operation that is involved in calling another method or returning from a method, incorporating tail calling and method jumps. =back Example: class = op This entry is B. =head3 push The number of new items that the instruction places on the stack. Note that this is strictly the total number of pushes, not accounting for any pops. This means that the add instruction, which pops two items off the top of the stack, adds them together and pushes the result onto the stack, has a value of 1. Example: push = 1 This entry is not allowed when class is set to calling. It is optional in other classes when it would bet set to zero. =head3 pop The number of items that the instruction removes from the stack. Note that this is strictly the number of pops, not accounting for any pushes. This means that the add instruction, which pops two items off the top of the stack, adds them together and pushes the result onto the stack, has a value of 1. Example: pop = 2 This entry is not allowed when class is set to calling. It is optional in other classes when it would bet set to zero. =head3 arguments This entry specifies any arguments that an instruction takes and their types. This is specified as a list of types seperated by commas. Valid types are as follows. =over 4 =item * uint8 - unsigned 8 bit integer =item * int8 - signed 8 bit integer =item * uint16 - unsigned 16 bit integer =item * int16 - signed 16 bit integer =item * uint32 - unsigned 32 bit integer =item * int32 - signed 32 bit integer =item * int64 - signed 64 bit integer =item * float32 - single precision floating point number =item * float64 - double precision floating point number =item * tmethod - a MethodDef or MethodRef (actually MemberRef) metadata token =item * tstandalonesig - A StandAloneSig metadata token =item * tvaluetype - A valueType token =item * ttype - a TypeDef or TypeRef metadata token =item * tfield - a FieldDef or FieldRef (actually MemberRef) metadata token =item * tstring - a string (metadata token?! - the spec sucks at times) =back Examples: arguments = uint8 arguments = uint16, uint32 arguments = This entry is B if there are no arguments. =head2 Translation Entries These specify the translation itself. One of insturction or pir is required (that is, not both). =head3 instruction This can be used when the translated instructions can be produced by simply substituting some meta-variables into PIR code and emitting it. Note that PIR written with the "instruction" directive is what will be emitted by the translator. If more control is needed for producing the translated code, use the "pir" entry. Example: instruction = add ${DEST0}, ${STACK0}, ${STACK1} Multiple lines of instructions are allowed. =head3 pir This is for the times when instruction isn't enough. It allows a chunk of PIR to be written that will be inserted into the translator after meta- variables have been substituted. This may involve emitting some PIR that makes up the translated code, or just setting the right meta-variables. Example: pir = <