Ejemplo n.º 1
0
        private NumericStackType StackTypeForTypeSpec(CLR.CLRTypeSpec typeSpec)
        {
            if (typeSpec is CLR.CLRTypeSpecClass)
            {
                CLR.CLRTypeSpecClass asClass = (CLR.CLRTypeSpecClass)typeSpec;
                if (asClass.TypeDef.ContainerClass == null && asClass.TypeDef.TypeNamespace == "System")
                {
                    string typeName = asClass.TypeDef.TypeName;
                    if (typeName == "Char" ||
                        typeName == "Boolean" ||
                        typeName == "Byte" ||
                        typeName == "SByte" ||
                        typeName == "Int16" ||
                        typeName == "UInt16" ||
                        typeName == "Int32" ||
                        typeName == "UInt32")
                        return NumericStackType.Int32;
                    if (typeName == "Int64" || typeName == "UInt64")
                        return NumericStackType.Int64;
                    if (typeName == "IntPtr" || typeName == "UIntPtr")
                        return NumericStackType.NativeInt;
                    if (typeName == "Single")
                        return NumericStackType.Float32;
                    if (typeName == "Double")
                        return NumericStackType.Float64;
                }

                CppClass typeClass = m_builder.GetCachedClass(typeSpec);
                if (typeClass.IsEnum)
                    return StackTypeForTypeSpec(typeClass.GetEnumUnderlyingType());
            }
            throw new Exception("Unrecognized numeric type spec");
        }
Ejemplo n.º 2
0
        private CLR.CLRTypeSpec TypeSpecForArrayIndex(CLR.CLRTypeSpec indexBaseSpec)
        {
            NumericStackType indexNst = StackTypeForTypeSpec(indexBaseSpec);
            CLR.CLRSigType.ElementType indexElementType;

            if (indexNst == NumericStackType.Int32)
                indexElementType = CLR.CLRSigType.ElementType.I4;
            else if (indexNst == NumericStackType.NativeInt)
                indexElementType = CLR.CLRSigType.ElementType.I;    // CLARITYTODO: Test UIntPtr
            else
                throw new ArgumentException("Unusual array index type");

            return m_builder.Assemblies.InternVagueType(new CLR.CLRSigTypeSimple(indexElementType));
        }
Ejemplo n.º 3
0
 private static MidInstruction.OpcodeEnum SimpleTranslateInstr(CLR.CIL.HLOpcode opcode)
 {
     switch (opcode)
     {
         case CLR.CIL.HLOpcode.bge:
             return MidInstruction.OpcodeEnum.bge;
         case CLR.CIL.HLOpcode.bgt:
             return MidInstruction.OpcodeEnum.bgt;
         case CLR.CIL.HLOpcode.ble:
             return MidInstruction.OpcodeEnum.ble;
         case CLR.CIL.HLOpcode.blt:
             return MidInstruction.OpcodeEnum.blt;
         case CLR.CIL.HLOpcode.clt:
             return MidInstruction.OpcodeEnum.clt;
         case CLR.CIL.HLOpcode.add:
             return MidInstruction.OpcodeEnum.add;
         case CLR.CIL.HLOpcode.sub:
             return MidInstruction.OpcodeEnum.sub;
         case CLR.CIL.HLOpcode.mul:
             return MidInstruction.OpcodeEnum.mul;
         case CLR.CIL.HLOpcode.div:
             return MidInstruction.OpcodeEnum.div;
         case CLR.CIL.HLOpcode.rem:
             return MidInstruction.OpcodeEnum.rem;
         case CLR.CIL.HLOpcode.and:
             return MidInstruction.OpcodeEnum.and;
         case CLR.CIL.HLOpcode.or:
             return MidInstruction.OpcodeEnum.or;
         case CLR.CIL.HLOpcode.xor:
             return MidInstruction.OpcodeEnum.xor;
         case CLR.CIL.HLOpcode.shl:
             return MidInstruction.OpcodeEnum.shl;
         case CLR.CIL.HLOpcode.shr:
             return MidInstruction.OpcodeEnum.shr;
         case CLR.CIL.HLOpcode.not:
             return MidInstruction.OpcodeEnum.not;
         case CLR.CIL.HLOpcode.neg:
             return MidInstruction.OpcodeEnum.neg;
         default:
             throw new ArgumentException();
     }
 }