Example #1
0
        public void WriteToFileTest( )
        {
            string path = Path.GetTempFileName( );

            try
            {
                using (var context = new Context( ))
                    using (var module = context.CreateBitcodeModule(TestModuleName))
                    {
                        _ = CreateSimpleVoidNopTestFunction(module, "foo");
                        module.WriteToFile(path);
                    }

                using var ctx     = new Context( );
                using var module2 = BitcodeModule.LoadFrom(path, ctx);

                // force a GC to ensure buffer created in LoadFrom is handled correctly
                GC.Collect(GC.MaxGeneration);
                Assert.IsTrue(module2.TryGetFunction("foo", out IrFunction? testFunc));

                // verify basics
                Assert.IsNotNull(testFunc);
                string txt = module2.WriteToString( );
                Assert.IsFalse(string.IsNullOrWhiteSpace(txt));
                string expectedText = string.Format(CultureInfo.InvariantCulture, TestModuleTemplate, Environment.NewLine, path);
                Assert.AreEqual(expectedText, txt);
            }
            finally
            {
                File.Delete(path);
            }
        }
Example #2
0
        public void WriteToFileTest( )
        {
            string path = Path.GetTempFileName( );

            try
            {
                using (var context = new Context( ))
                    using (var module = new BitcodeModule(context, TestModuleName))
                    {
                        Function testFunc = CreateSimpleVoidNopTestFunction(module, "foo");
                        module.WriteToFile(path);
                    }

                using (var ctx = new Context( ))
                    using (var module2 = BitcodeModule.LoadFrom(path, ctx))
                    {
                        Function testFunc = module2.GetFunction("foo");

                        // verify basics
                        Assert.IsNotNull(testFunc);
                        string txt = module2.WriteToString( );
                        Assert.IsFalse(string.IsNullOrWhiteSpace(txt));
                        string expectedText = string.Format(TestModuleTemplate, Environment.NewLine, path);
                        Assert.AreEqual(expectedText, txt);
                    }
            }
            finally
            {
                File.Delete(path);
            }
        }