Beispiel #1
0
        void detectHandlers(List <TypeDefinition> handlerTypes, CsvmInfo csvmInfo)
        {
            opCodeHandlers = new List <OpCodeHandler>();
            var detected = new List <OpCodeHandler>();

            foreach (var handlersList in OpCodeHandlers.opcodeHandlers)
            {
                opCodeHandlers.Clear();

                foreach (var handlerType in handlerTypes)
                {
                    var info = new UnknownHandlerInfo(handlerType, csvmInfo);
                    detected.Clear();
                    foreach (var opCodeHandler in handlersList)
                    {
                        if (opCodeHandler.detect(info))
                        {
                            detected.Add(opCodeHandler);
                        }
                    }
                    if (detected.Count != 1)
                    {
                        goto next;
                    }
                    opCodeHandlers.Add(detected[0]);
                }
                if (new List <OpCodeHandler>(Utils.unique(opCodeHandlers)).Count == opCodeHandlers.Count)
                {
                    return;
                }
                next :;
            }
            throw new ApplicationException("Could not detect all VM opcode handlers");
        }
Beispiel #2
0
        internal CsvmInfo createCsvmInfo()
        {
            var csvmInfo = new CsvmInfo();

            csvmInfo.StackValue = findStackValueType();
            csvmInfo.Stack      = findStackType(csvmInfo.StackValue);
            initStackTypeMethods(csvmInfo);
            return(csvmInfo);
        }
Beispiel #3
0
 public UnknownHandlerInfo(TypeDefinition type, CsvmInfo csvmInfo)
 {
     this.type     = type;
     this.csvmInfo = csvmInfo;
     fieldsInfo    = new FieldsInfo(getFields(type));
     countMethods();
     findOverrideMethods();
     executeMethodThrows = countThrows(executeMethod);
     executeMethodPops   = countPops(executeMethod);
 }
 public UnknownHandlerInfo(TypeDefinition type, CsvmInfo csvmInfo)
 {
     this.type = type;
     this.csvmInfo = csvmInfo;
     fieldsInfo = new FieldsInfo(getFields(type));
     countMethods();
     findOverrideMethods();
     executeMethodThrows = countThrows(executeMethod);
     executeMethodPops = countPops(executeMethod);
 }
Beispiel #5
0
 void initStackTypeMethods(CsvmInfo csvmInfo)
 {
     foreach (var method in csvmInfo.Stack.Methods)
     {
         if (method.Parameters.Count == 0 && method.MethodReturnType.ReturnType == csvmInfo.StackValue)
         {
             if (hasAdd(method))
             {
                 csvmInfo.PopMethod = method;
             }
             else
             {
                 csvmInfo.PeekMethod = method;
             }
         }
     }
 }
 void initStackTypeMethods(CsvmInfo csvmInfo)
 {
     foreach (var method in csvmInfo.Stack.Methods) {
         if (method.Parameters.Count == 0 && method.MethodReturnType.ReturnType == csvmInfo.StackValue) {
             if (hasAdd(method))
                 csvmInfo.PopMethod = method;
             else
                 csvmInfo.PeekMethod = method;
         }
     }
 }
 void detectHandlers(List<TypeDefinition> handlerTypes, CsvmInfo csvmInfo)
 {
     opCodeHandlers = new List<OpCodeHandler>();
     var detected = new List<OpCodeHandler>();
     foreach (var handlerType in handlerTypes) {
         var info = new UnknownHandlerInfo(handlerType, csvmInfo);
         detected.Clear();
         foreach (var opCodeHandler in opCodeHandlerDetectors) {
             if (opCodeHandler.detect(info))
                 detected.Add(opCodeHandler);
         }
         if (detected.Count != 1)
             throw new ApplicationException("Could not detect VM opcode handler");
         opCodeHandlers.Add(detected[0]);
     }
     if (new List<OpCodeHandler>(Utils.unique(opCodeHandlers)).Count != opCodeHandlers.Count)
         throw new ApplicationException("Could not detect all VM opcode handlers");
 }
        public void findHandlers()
        {
            if (opCodeHandlers != null)
                return;
            var vmHandlerTypes = findVmHandlerTypes();
            if (vmHandlerTypes == null)
                throw new ApplicationException("Could not find CSVM opcode handler types");

            var csvmInfo = new CsvmInfo();
            csvmInfo.StackValue = findStackValueType();
            csvmInfo.Stack = findStackType(csvmInfo.StackValue);
            initStackTypeMethods(csvmInfo);

            detectHandlers(vmHandlerTypes, csvmInfo);
        }
 internal CsvmInfo createCsvmInfo()
 {
     var csvmInfo = new CsvmInfo();
     csvmInfo.StackValue = findStackValueType();
     csvmInfo.Stack = findStackType(csvmInfo.StackValue);
     initStackTypeMethods(csvmInfo);
     return csvmInfo;
 }