예제 #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");
        }
예제 #2
0
        internal CsvmInfo createCsvmInfo()
        {
            var csvmInfo = new CsvmInfo();

            csvmInfo.StackValue = findStackValueType();
            csvmInfo.Stack      = findStackType(csvmInfo.StackValue);
            initStackTypeMethods(csvmInfo);
            return(csvmInfo);
        }
예제 #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);
 }
예제 #4
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);
 }
예제 #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;
             }
         }
     }
 }
예제 #6
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;
         }
     }
 }
예제 #7
0
 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");
 }
예제 #8
0
        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);
        }
예제 #9
0
 internal CsvmInfo createCsvmInfo()
 {
     var csvmInfo = new CsvmInfo();
     csvmInfo.StackValue = findStackValueType();
     csvmInfo.Stack = findStackType(csvmInfo.StackValue);
     initStackTypeMethods(csvmInfo);
     return csvmInfo;
 }