A Method is the container for code. It inherits from CodeContainer, to hold the
instructions in the function, and holds a MethodSignature which defines the
function's signature. It also holds a list of local
variables. A method is usually stored in a class, but
can be stored in an AssemblyDef as
well if it isn't needed outside the assembly.
The Method may be constructed either directly or through the Allocator object. Prior to
constructing it a MethodSignature must be constructed.
Note that 'entry' is set to true for the entry point of the
module. An entry point is not needed for DLL files.
Method(MethodSignature
*Prototype, Qualifiers flags, bool entry = false);
The method may be a PInvoke Method. These methods don't
have a body, but reference an external DLL and give a calling
convention to call unmanaged code.
enum InvokeType {
Cdecl, Stdcall };
void
SetPInvoke(std::string name, InvokeType type = Stdcall);
bool IsPInvoke()
const { return invokeMode_ == PInvoke; }
Add a local variable
void AddLocal(Local
*local);
Whether the Method needs a this pointer.
void Instance(bool
instance);
bool Instance() {
return !!(Flags().Value & Qualifiers::Instance); }
Method signature
MethodSignature *Signature() const { return prototype_; }
Iterate through the local variables
typedef
std::vector<Local *>::iterator iterator;
iterator begin() {
return varList_.begin(); }
iterator end() {
return varList_.end(); }
size_t size()
const { return varList_.size(); }
Validate and optimize the MSIL code. Throw a PELibError exception if any problems
are found.
virtual void
Optimize(PELib &) override;
Determine if the method is an entry point.
bool
HasEntryPoint();