Esempio n. 1
0
File: Main.cs Progetto: nobled/mono
	public static int Main (string [] args) {

		if (args.Length != 1) {
			Console.WriteLine ("Usage : ilasm [filename]");
			return 1;
		}
		
		StreamReader reader = File.OpenText (args [0]);
		ILTokenizer scanner = new ILTokenizer (reader);

		bool testScanner = true;

		if (testScanner) {
			ILToken tok;
			while ((tok = scanner.NextToken) != ILToken.EOF) {
				Console.WriteLine (tok);
			}
		} else {
			ILParser parser = new ILParser (new CodeGen ());
			parser.yyparse (new ScannerAdapter (scanner), new yydebug.yyDebugSimple ());

			CodeGen cg = parser.CodeGen;
			int n = cg.ClassCount;
			cg.Emit ();
		}

		return 0;
	}
Esempio n. 2
0
    public static int Main(string [] args)
    {
        if (args.Length != 1)
        {
            Console.WriteLine("Usage : ilasm [filename]");
            return(1);
        }

        StreamReader reader  = File.OpenText(args [0]);
        ILTokenizer  scanner = new ILTokenizer(reader);

        bool testScanner = true;

        if (testScanner)
        {
            ILToken tok;
            while ((tok = scanner.NextToken) != ILToken.EOF)
            {
                Console.WriteLine(tok);
            }
        }
        else
        {
            ILParser parser = new ILParser(new CodeGen());
            parser.yyparse(new ScannerAdapter(scanner), new yydebug.yyDebugSimple());

            CodeGen cg = parser.CodeGen;
            int     n  = cg.ClassCount;
            cg.Emit();
        }

        return(0);
    }
Esempio n. 3
0
            private void ProcessFile(string file_path)
            {
                if (!File.Exists(file_path))
                {
                    Console.WriteLine("File does not exist: {0}",
                                      file_path);
                    Environment.Exit(2);
                }
                Report.AssembleFile(file_path, null,
                                    target_string, output_file);
                StreamReader reader  = File.OpenText(file_path);
                ILTokenizer  scanner = new ILTokenizer(reader);

                if (show_tokens)
                {
                    scanner.NewTokenEvent += new NewTokenEvent(ShowToken);
                }
                //if (show_method_def)
                //        MethodTable.MethodDefinedEvent += new MethodDefinedEvent (ShowMethodDef);
                //if (show_method_ref)
                //       MethodTable.MethodReferencedEvent += new MethodReferencedEvent (ShowMethodRef);

                if (scan_only)
                {
                    ILToken tok;
                    while ((tok = scanner.NextToken) != ILToken.EOF)
                    {
                        Console.WriteLine(tok);
                    }
                    return;
                }

                ILParser parser = new ILParser(codegen, scanner);

                codegen.BeginSourceFile(file_path);
                try {
                    if (show_parser)
                    {
                        parser.yyparse(new ScannerAdapter(scanner),
                                       new yydebug.yyDebugSimple());
                    }
                    else
                    {
                        parser.yyparse(new ScannerAdapter(scanner), null);
                    }
                } catch (ILTokenizingException ilte) {
                    Report.Error(ilte.Location, "syntax error at token '" + ilte.Token + "'");
                } catch (Mono.ILASM.yyParser.yyException ye) {
                    Report.Error(scanner.Reader.Location, ye.Message);
                } catch (ILAsmException ie) {
                    ie.FilePath = file_path;
                    ie.Location = scanner.Reader.Location;
                    throw;
                } catch (Exception) {
                    Console.Write("{0} ({1}, {2}): ", file_path, scanner.Reader.Location.line, scanner.Reader.Location.column);
                    throw;
                } finally {
                    codegen.EndSourceFile();
                }
            }
Esempio n. 4
0
        private string[] GetAccessedProperties(Delegate del)
        {
            var parser = new ILParser(del.Method);

            IEnumerable <PropertyInfo> infos = parser.GetAccessedProperties();

            return(infos
                   .Select(x => x.Name)
                   .ToArray());
        }
 private IEnumerable <Completion> GenerateInstructions( )
 {
     foreach (var word in ILParser.GetWords("il.instruction").OrderBy(word => word))
     {
         yield return(new Completion(word,
                                     word,
                                     Descriptions.GetString(word.ToLowerInvariant( )),
                                     word.EndsWith(".") ? PrefixInstructionIcon : InstructionIcon,
                                     word));
     }
 }
Esempio n. 6
0
        public IList <ClassificationSpan> GetClassificationSpans(SnapshotSpan span)
        {
            var snapshot = span.Snapshot;
            var start    = span.Start.Position;

            return(ILParser.Parse(span.GetText( ))
                   .Select(token => new ClassificationSpan(new SnapshotSpan(snapshot,
                                                                            start + token.Start, token.Length),
                                                           classificationTypeRegistry.GetClassificationType(token.Class)))
                   .ToList( ));
        }
        public void SurveyViewModel_Should_Have_CommandInitialization_Injected_With_SubmitCommand_Set()
        {
            var ilVisitor = Substitute.For <IILVisitor>();

            ilVisitor.OnInlineMethod(Arg.Is(OpCodes.Call), Arg.Any <MethodReference>());
            var instance       = Assembly.GetInstance("WpfMvvmSample.SurveyViewModel");
            var objectInstance = (object)instance;
            var type           = DefinitionFinder.FindType(objectInstance.GetType());
            var method         = type.FindMethod("<Commander_Fody>InitializeCommands");

            ILParser.Parse(method, ilVisitor);
            ilVisitor.Received().OnInlineMethod(
                Arg.Is(OpCodes.Call)
                , Arg.Is <MethodReference>(x => x.Name == "set_SubmitCommand" && x.DeclaringType.Name == "SurveyViewModel")
                );
        }
Esempio n. 8
0
        bool MethodIsLiteralMatch(PEFile module, MethodDefinition methodDefinition)
        {
            var blob = module.Reader.GetMethodBody(methodDefinition.RelativeVirtualAddress).GetILReader();

            if (searchTermLiteralType == TypeCode.Int64)
            {
                long val = (long)searchTermLiteralValue;
                while (blob.RemainingBytes > 0)
                {
                    ILOpCode code;
                    switch (code = ILParser.DecodeOpCode(ref blob))
                    {
                    case ILOpCode.Ldc_i8:
                        if (val == blob.ReadInt64())
                        {
                            return(true);
                        }
                        break;

                    case ILOpCode.Ldc_i4:
                        if (val == blob.ReadInt32())
                        {
                            return(true);
                        }
                        break;

                    case ILOpCode.Ldc_i4_s:
                        if (val == blob.ReadSByte())
                        {
                            return(true);
                        }
                        break;

                    case ILOpCode.Ldc_i4_m1:
                        if (val == -1)
                        {
                            return(true);
                        }
                        break;

                    case ILOpCode.Ldc_i4_0:
                        if (val == 0)
                        {
                            return(true);
                        }
                        break;

                    case ILOpCode.Ldc_i4_1:
                        if (val == 1)
                        {
                            return(true);
                        }
                        break;

                    case ILOpCode.Ldc_i4_2:
                        if (val == 2)
                        {
                            return(true);
                        }
                        break;

                    case ILOpCode.Ldc_i4_3:
                        if (val == 3)
                        {
                            return(true);
                        }
                        break;

                    case ILOpCode.Ldc_i4_4:
                        if (val == 4)
                        {
                            return(true);
                        }
                        break;

                    case ILOpCode.Ldc_i4_5:
                        if (val == 5)
                        {
                            return(true);
                        }
                        break;

                    case ILOpCode.Ldc_i4_6:
                        if (val == 6)
                        {
                            return(true);
                        }
                        break;

                    case ILOpCode.Ldc_i4_7:
                        if (val == 7)
                        {
                            return(true);
                        }
                        break;

                    case ILOpCode.Ldc_i4_8:
                        if (val == 8)
                        {
                            return(true);
                        }
                        break;

                    default:
                        ILParser.SkipOperand(ref blob, code);
                        break;
                    }
                }
            }
            else if (searchTermLiteralType != TypeCode.Empty)
            {
                ILOpCode expectedCode;
                switch (searchTermLiteralType)
                {
                case TypeCode.Single:
                    expectedCode = ILOpCode.Ldc_r4;
                    break;

                case TypeCode.Double:
                    expectedCode = ILOpCode.Ldc_r8;
                    break;

                case TypeCode.String:
                    expectedCode = ILOpCode.Ldstr;
                    break;

                default:
                    throw new InvalidOperationException();
                }
                while (blob.RemainingBytes > 0)
                {
                    var code = ILParser.DecodeOpCode(ref blob);
                    if (code != expectedCode)
                    {
                        ILParser.SkipOperand(ref blob, code);
                        continue;
                    }
                    switch (code)
                    {
                    case ILOpCode.Ldc_r4:
                        if ((float)searchTermLiteralValue == blob.ReadSingle())
                        {
                            return(true);
                        }
                        break;

                    case ILOpCode.Ldc_r8:
                        if ((double)searchTermLiteralValue == blob.ReadDouble())
                        {
                            return(true);
                        }
                        break;

                    case ILOpCode.Ldstr:
                        if ((string)searchTermLiteralValue == ILParser.DecodeUserString(ref blob, module.Metadata))
                        {
                            return(true);
                        }
                        break;
                    }
                }
            }
            else
            {
                while (blob.RemainingBytes > 0)
                {
                    var code = ILParser.DecodeOpCode(ref blob);
                    if (code != ILOpCode.Ldstr)
                    {
                        ILParser.SkipOperand(ref blob, code);
                        continue;
                    }
                    if (IsMatch(ILParser.DecodeUserString(ref blob, module.Metadata)))
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Esempio n. 9
0
                        private void ProcessFile (string file_path)
                        {
                                if (!File.Exists (file_path)) {
                                        Console.WriteLine ("File does not exist: {0}",
                                                file_path);
                                        Environment.Exit (2);
                                }
                                Report.AssembleFile (file_path, null,
                                                target_string, output_file);
                                StreamReader reader = File.OpenText (file_path);
                                ILTokenizer scanner = new ILTokenizer (reader);

                                if (show_tokens)
                                        scanner.NewTokenEvent += new NewTokenEvent (ShowToken);
                                //if (show_method_def)
                                //        MethodTable.MethodDefinedEvent += new MethodDefinedEvent (ShowMethodDef);
                                //if (show_method_ref)
                                //       MethodTable.MethodReferencedEvent += new MethodReferencedEvent (ShowMethodRef);

                                if (scan_only) {
                                        ILToken tok;
                                        while ((tok = scanner.NextToken) != ILToken.EOF) {
                                                Console.WriteLine (tok);
                                        }
                                        return;
                                }

                                ILParser parser = new ILParser (codegen, scanner);
				codegen.BeginSourceFile (file_path);
                                try {
                                        if (show_parser)
                                                parser.yyparse (new ScannerAdapter (scanner),
                                                                new yydebug.yyDebugSimple ());
                                        else
                                                parser.yyparse (new ScannerAdapter (scanner),  null);
                                } catch (ILTokenizingException ilte) {
                                        Report.Error (ilte.Location, "syntax error at token '" + ilte.Token + "'");
                                } catch (Mono.ILASM.yyParser.yyException ye) {
                                        Report.Error (scanner.Reader.Location, ye.Message);
                                } catch (ILAsmException ie) {
                                        ie.FilePath = file_path;
                                        ie.Location = scanner.Reader.Location;
                                        throw;
                                } catch (Exception e){
                                        Console.Write ("{0} ({1}, {2}): ",file_path, scanner.Reader.Location.line, scanner.Reader.Location.column);
                                        throw;
                                } finally {
					codegen.EndSourceFile ();
				}
                        }