Exemplo n.º 1
0
 public void Run(ICommandInteraction writer, [Values(TraceEnableCommand)] LiteralToken enable, LiteralToken cpuToken, StringToken functionName, BooleanToken traceReturn, params LiteralToken[] types)
 {
     var cpu = (Arm)monitor.ConvertValueOrThrowRecoverable(cpuToken.Value, typeof(Arm));
     var cpuTracer = EnsureTracer(cpu);
     var handler = new DefaultFunctionHandler(cpu);
     var paramList = new List<FunctionCallParameter>();
     foreach(var parameter in types)
     {
         FunctionCallParameterType paramType;
         if(!Enum.TryParse(parameter.Value, out paramType))
         {
             throw new RecoverableException("{0} is not a proper parameter type.".FormatWith(parameter.Value));
         }
         paramList.Add(new FunctionCallParameter{ Type = paramType });
     }
     handler.CallParameters = paramList.Take(paramList.Count - (traceReturn.Value ? 1 : 0));
     handler.ReturnParameter = traceReturn.Value ? paramList.Last() : (FunctionCallParameter?)null;
     if(traceReturn.Value)
     {
         cpuTracer.TraceFunction(functionName.Value, handler.CallParameters, handler.CallHandler, handler.ReturnParameter, handler.ReturnHandler);
     }
     else
     {
         cpuTracer.TraceFunction(functionName.Value, handler.CallParameters, handler.CallHandler);
     }
     
 }
Exemplo n.º 2
0
        private void Execute(ICommandInteraction writer, LiteralToken cpuToken, String functionName, bool traceReturn, int? numberOfParameters)
        {

            var cpu = (Arm)monitor.ConvertValueOrThrowRecoverable(cpuToken.Value, typeof(Arm));

            var cpuTracer = EnsureTracer(cpu);
            Type handlerType;
            IFunctionHandler handler;
            if(!handlers.TryGetValue(functionName, out handlerType))
            {
                if(numberOfParameters.HasValue)
                {
                    var paramList = new List<FunctionCallParameter>();
                    for(var i = 0; i < numberOfParameters; ++i)
                    {
                        paramList.Add(new FunctionCallParameter{ Type = FunctionCallParameterType.UInt32 });
                    }
                    FunctionCallParameter? returnParameter = null;
                    if(traceReturn)
                    {
                        returnParameter = new FunctionCallParameter{ Type = FunctionCallParameterType.UInt32 };
                    }
                    var defHandler = new DefaultFunctionHandler(cpu);
                    defHandler.CallParameters = paramList;
                    defHandler.ReturnParameter = returnParameter;
                    handler = defHandler;
                }
                else
                {
                    throw new RecoverableException("Handler for {0} not register. You must provide numberOfParameters to use default handler.".FormatWith(functionName));
                }  
            }
            else
            {
                handler = Dynamic.InvokeConstructor(handlerType, cpu);
            }
            if(traceReturn)
            {
                cpuTracer.TraceFunction(functionName, handler.CallParameters, handler.CallHandler, handler.ReturnParameter, handler.ReturnHandler);
            }
            else
            {
                cpuTracer.TraceFunction(functionName, handler.CallParameters, handler.CallHandler);
            }
        }