⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 emitter.vb

📁 大名鼎鼎的mono是.NET平台的跨平台(支持linux
💻 VB
📖 第 1 页 / 共 5 页
字号:
' ' Visual Basic.Net Compiler' Copyright (C) 2004 - 2007 Rolf Bjarne Kvinge, RKvinge@novell.com' ' This library is free software; you can redistribute it and/or' modify it under the terms of the GNU Lesser General Public' License as published by the Free Software Foundation; either' version 2.1 of the License, or (at your option) any later version.' ' This library is distributed in the hope that it will be useful,' but WITHOUT ANY WARRANTY; without even the implied warranty of' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU' Lesser General Public License for more details.' ' You should have received a copy of the GNU Lesser General Public' License along with this library; if not, write to the Free Software' Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA' Imports System.ReflectionImports System.Reflection.Emit#If DEBUG Then#Const DEBUGIMPLICITCONVERSION = 0#Const EXTENDEDDEBUG = 0#End IfPartial Public Class Emitter    Shared Function DefineLabel(ByVal Info As EmitInfo) As Label        Return Info.ILGen.DefineLabel    End Function    Shared Sub MarkSequencePoint(ByVal Info As EmitInfo, ByVal Location As Span)        'If Location Is Nothing Then Return        If Location.File(Info.Compiler) Is Nothing Then Return        If Location.File(Info.Compiler).SymbolDocument Is Nothing Then Return        If Location.Line <= 0 Then Return        Info.ILGen.MarkSequencePoint(Location.File(Info.Compiler).SymbolDocument, CInt(Location.Line), Location.Column, CInt(Location.Line), Location.EndColumn)    End Sub    Shared Function DeclareLocal(ByVal Info As EmitInfo, ByVal Type As Type, Optional ByVal Name As String = "") As LocalBuilder        Dim result As LocalBuilder        Type = Helper.GetTypeOrTypeBuilder(Type)        result = Info.ILGen.DeclareLocal(Type)        If Name <> String.Empty AndAlso Info.Compiler.EmittingDebugInfo Then            result.SetLocalSymInfo(Name)        End If        Return result    End Function    Shared Sub FreeLocal(ByVal Local As LocalBuilder)        'local variable reuse not implemented yet.    End Sub    Shared Sub MarkLabel(ByVal Info As EmitInfo, ByVal Label As Label)        Info.ILGen.MarkLabel(Label)    End Sub    Shared Sub EmitBeginExceptionFilter(ByVal Info As EmitInfo)        Helper.Assert(Info.InExceptionFilter = False)        Info.ILGen.BeginExceptFilterBlock()        Info.Stack.Push(Info.Compiler.TypeCache.System_Object)        Info.InExceptionFilter = True    End Sub    Shared Sub EmitBeginCatch(ByVal Info As EmitInfo, ByVal ExceptionType As Type)        If ExceptionType IsNot Nothing Then ExceptionType = Helper.GetTypeOrTypeBuilder(ExceptionType)        If Info.InExceptionFilter Then            Info.Stack.Pop(Info.Compiler.TypeCache.System_Boolean)        End If        Info.ILGen.BeginCatchBlock(ExceptionType)        If ExceptionType IsNot Nothing Then            Info.Stack.Push(ExceptionType)        Else            Info.Stack.Push(Info.Compiler.TypeCache.System_Object)        End If        Info.InExceptionFilter = False    End Sub    Shared Sub EmitEndExceptionBlock(ByVal Info As EmitInfo)        Helper.Assert(Info.InExceptionFilter = False)        Info.ILGen.EndExceptionBlock()    End Sub    Shared Function EmitBeginExceptionBlock(ByVal Info As EmitInfo) As Label        Helper.Assert(Info.InExceptionFilter = False)        Dim result As Label        result = Info.ILGen.BeginExceptionBlock        Return result    End Function    Shared Sub EmitBeginFinallyBlock(ByVal Info As EmitInfo)        Info.ILGen.BeginFinallyBlock()    End Sub    <Obsolete("Do not use this!")> Shared ReadOnly Property Compiler() As Compiler        Get            Throw New InternalException("")        End Get    End Property    Shared Sub EmitPop(ByVal Info As EmitInfo, ByVal Type As Type)        Type = Helper.GetTypeOrTypeBuilder(Type)        Info.ILGen.Emit(OpCodes.Pop)        Info.Stack.Pop(Type)    End Sub    Shared Sub EmitBranchIfFalse(ByVal Info As EmitInfo, ByVal Label As Label)#If DEBUG Then        If Info.Stack.Peek.IsClass OrElse Info.Stack.Peek.IsInterface Then            'comparison with Nothing, operand can be a class or interface.            Info.Stack.Pop(Info.Stack.Peek)        Else            Info.Stack.Pop(Info.Compiler.TypeCache.System_Boolean)        End If#End If        Info.ILGen.Emit(OpCodes.Brfalse, Label)    End Sub    Shared Sub EmitBranchIfTrue(ByVal Info As EmitInfo, ByVal Label As Label)        Info.Stack.Pop(Info.Compiler.TypeCache.System_Boolean)        Info.ILGen.Emit(OpCodes.Brtrue, Label)    End Sub    Shared Sub EmitBranchIfTrue(ByVal Info As EmitInfo, ByVal Label As Label, ByVal Type As Type)        Type = Helper.GetTypeOrTypeBuilder(Type)        Helper.Assert(Helper.CompareType(Type, Info.Compiler.TypeCache.System_Boolean) OrElse Type.IsClass OrElse Type.IsInterface)        Info.Stack.Pop(Type)        Info.ILGen.Emit(OpCodes.Brtrue, Label)    End Sub    Shared Sub EmitBranch(ByVal Info As EmitInfo, ByVal Label As Label)        Info.ILGen.Emit(OpCodes.Br, Label)    End Sub    Shared Sub EmitBranchOrLeave(ByVal Info As EmitInfo, ByVal Label As Label, ByVal FromStatement As Statement, ByVal ToStatement As Statement)        If IsLeaveNecessary(FromStatement, ToStatement) Then            EmitLeave(Info, Label)        Else            EmitBranch(Info, Label)        End If    End Sub    Shared Sub EmitLeave(ByVal Info As EmitInfo, ByVal Label As Label)        Info.ILGen.Emit(OpCodes.Leave, Label)        Info.Stack.Clear()    End Sub    Shared Sub EmitSub(ByVal Info As EmitInfo, ByVal SubType As Type)        SubType = Helper.GetTypeOrTypeBuilder(SubType)        Info.Stack.Pop(SubType)        Info.Stack.Pop(SubType)        Info.ILGen.Emit(OpCodes.Sub)        Info.Stack.Push(SubType)    End Sub    Shared Sub EmitSubOvf(ByVal Info As EmitInfo, ByVal SubType As Type)        SubType = Helper.GetTypeOrTypeBuilder(SubType)        Info.Stack.Pop(SubType)        Info.Stack.Pop(SubType)        Info.ILGen.Emit(OpCodes.Sub_Ovf)        Info.Stack.Push(SubType)    End Sub    Shared Sub EmitSubOvfUn(ByVal Info As EmitInfo, ByVal SubType As Type)        SubType = Helper.GetTypeOrTypeBuilder(SubType)        Info.Stack.Pop(SubType)        Info.Stack.Pop(SubType)        Info.ILGen.Emit(OpCodes.Sub_Ovf_Un)        Info.Stack.Push(SubType)    End Sub    Shared Sub EmitSubOrSubOvfOrSubOvfUn(ByVal Info As EmitInfo, ByVal SubType As Type)        If Info.IntegerOverflowChecks Then            EmitSubOvf(Info, SubType)        Else            EmitSub(Info, SubType)        End If    End Sub    Shared Sub EmitOr(ByVal Info As EmitInfo, ByVal OrType As Type)        OrType = Helper.GetTypeOrTypeBuilder(OrType)        Info.Stack.Pop(OrType)        Info.Stack.Pop(OrType)        Info.ILGen.Emit(OpCodes.Or)        Info.Stack.Push(OrType)    End Sub    Shared Sub EmitAnd(ByVal Info As EmitInfo, ByVal AndType As Type)        AndType = Helper.GetTypeOrTypeBuilder(AndType)        Info.Stack.Pop(AndType)        Info.Stack.Pop(AndType)        Info.ILGen.Emit(OpCodes.And)        Info.Stack.Push(AndType)    End Sub    Shared Sub EmitXOr(ByVal Info As EmitInfo, ByVal XorType As Type)        XorType = Helper.GetTypeOrTypeBuilder(XorType)        Info.Stack.Pop(XorType)        Info.Stack.Pop(XorType)        Info.ILGen.Emit(OpCodes.Xor)        Info.Stack.Push(XorType)    End Sub    Shared Sub EmitNot(ByVal Info As EmitInfo, ByVal NotType As Type)        NotType = Helper.GetTypeOrTypeBuilder(NotType)        Info.Stack.Pop(NotType)        Info.ILGen.Emit(OpCodes.Not)        Info.Stack.Push(NotType)    End Sub    Shared Sub EmitMod(ByVal Info As EmitInfo, ByVal ModType As Type)        ModType = Helper.GetTypeOrTypeBuilder(ModType)        Info.Stack.Pop(ModType)        Info.Stack.Pop(ModType)        Info.ILGen.Emit(OpCodes.[Rem])        Info.Stack.Push(ModType)    End Sub    Shared Sub EmitEquals(ByVal Info As EmitInfo, ByVal CompareType As Type)        CompareType = Helper.GetTypeOrTypeBuilder(CompareType)        Info.Stack.Pop(CompareType)        Info.Stack.Pop(CompareType)        Info.ILGen.Emit(OpCodes.Ceq)        Info.Stack.Push(Info.Compiler.TypeCache.System_Boolean)    End Sub    Shared Sub EmitNotEquals(ByVal Info As EmitInfo, ByVal CompareType As Type)        CompareType = Helper.GetTypeOrTypeBuilder(CompareType)        Info.Stack.Pop(CompareType)        Info.Stack.Pop(CompareType)        Info.ILGen.Emit(OpCodes.Ceq)        Info.ILGen.Emit(OpCodes.Ldc_I4_0)        Info.ILGen.Emit(OpCodes.Ceq)        Info.Stack.Push(Info.Compiler.TypeCache.System_Boolean)    End Sub    Shared Sub EmitGE(ByVal Info As EmitInfo, ByVal CompareType As Type)        CompareType = Helper.GetTypeOrTypeBuilder(CompareType)        Info.Stack.Pop(CompareType)        Info.Stack.Pop(CompareType)        Info.ILGen.Emit(OpCodes.Clt)        Info.ILGen.Emit(OpCodes.Ldc_I4_0)        Info.ILGen.Emit(OpCodes.Ceq)        Info.Stack.Push(Info.Compiler.TypeCache.System_Boolean)    End Sub    Shared Sub EmitGT(ByVal Info As EmitInfo, ByVal CompareType As Type)        CompareType = Helper.GetTypeOrTypeBuilder(CompareType)        Info.Stack.Pop(CompareType)        Info.Stack.Pop(CompareType)        Info.ILGen.Emit(OpCodes.Cgt)        Info.Stack.Push(Info.Compiler.TypeCache.System_Boolean)    End Sub    Shared Sub EmitGT_Un(ByVal Info As EmitInfo, ByVal CompareType As Type)        CompareType = Helper.GetTypeOrTypeBuilder(CompareType)        Info.Stack.Pop(CompareType)        Info.Stack.Pop(CompareType)        Info.ILGen.Emit(OpCodes.Cgt_Un)        Info.Stack.Push(Info.Compiler.TypeCache.System_Boolean)    End Sub    Shared Sub EmitLE(ByVal Info As EmitInfo, ByVal CompareType As Type)        CompareType = Helper.GetTypeOrTypeBuilder(CompareType)        Info.Stack.Pop(CompareType)        Info.Stack.Pop(CompareType)        Info.ILGen.Emit(OpCodes.Cgt)        Info.ILGen.Emit(OpCodes.Ldc_I4_0)        Info.ILGen.Emit(OpCodes.Ceq)        Info.Stack.Push(Info.Compiler.TypeCache.System_Boolean)    End Sub    Shared Sub EmitLT(ByVal Info As EmitInfo, ByVal CompareType As Type)        CompareType = Helper.GetTypeOrTypeBuilder(CompareType)        Info.Stack.Pop(CompareType)        Info.Stack.Pop(CompareType)        Info.ILGen.Emit(OpCodes.Clt)        Info.Stack.Push(Info.Compiler.TypeCache.System_Boolean)    End Sub    Shared Sub EmitAdd(ByVal Info As EmitInfo, ByVal OperandType As Type)        OperandType = Helper.GetTypeOrTypeBuilder(OperandType)        Info.Stack.Pop(OperandType)        Info.Stack.Pop(OperandType)        Info.ILGen.Emit(OpCodes.Add)        Info.Stack.Push(OperandType)    End Sub    Shared Sub EmitAddOrAddOvf(ByVal Info As EmitInfo, ByVal OperandType As Type)        If Info.IntegerOverflowChecks Then            EmitAddOvf(Info, OperandType)        Else            EmitAdd(Info, OperandType)        End If    End Sub    Shared Sub EmitAddOvf(ByVal Info As EmitInfo, ByVal OperandType As Type)        OperandType = Helper.GetTypeOrTypeBuilder(OperandType)        Info.Stack.Pop(OperandType)        Info.Stack.Pop(OperandType)        Info.ILGen.Emit(OpCodes.Add_Ovf)        Info.Stack.Push(OperandType)    End Sub    Shared Sub EmitMult(ByVal Info As EmitInfo, ByVal OperandType As Type)        OperandType = Helper.GetTypeOrTypeBuilder(OperandType)        Info.Stack.Pop(OperandType)        Info.Stack.Pop(OperandType)        Info.ILGen.Emit(OpCodes.Mul)        Info.Stack.Push(OperandType)    End Sub    Shared Sub EmitMultOvf(ByVal Info As EmitInfo, ByVal OperandType As Type)        OperandType = Helper.GetTypeOrTypeBuilder(OperandType)        Info.Stack.Pop(OperandType)        Info.Stack.Pop(OperandType)        Info.ILGen.Emit(OpCodes.Mul_Ovf)        Info.Stack.Push(OperandType)    End Sub

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -