コード例 #1
0
ファイル: OptEditorForm.cs プロジェクト: johnathonm1981/dx
        private void CopyContainerButton_Click(object sender, EventArgs e)
        {
            // The intent is to copy compiled code (possibly customized) into the
            // clipboard so it can be pasted into an XML file to be run interactively.

            var text           = this.CodeBox.Text;
            var source         = EditorForm.CreateBlobForText(this.Library, text);
            var assembler      = HlslDxcLib.CreateDxcAssembler();
            var assembleResult = assembler.AssembleToContainer(source);

            if (assembleResult.GetStatus() < 0)
            {
                var errors = assembleResult.GetErrors();
                MessageBox.Show(EditorForm.GetStringFromBlob(this.Library, errors));
                return;
            }
            var container = assembleResult.GetResult();

            // Now copy that to the clipboard.
            var bytes   = ContainerData.BlobToBytes(container);
            var stream  = new System.IO.MemoryStream(bytes);
            var dataObj = new DataObject();

            dataObj.SetData(ContainerData.DataFormat.Name, stream);
            dataObj.SetText(text);
            Clipboard.SetDataObject(dataObj, true);
        }
コード例 #2
0
ファイル: DotNetDxcTests.cs プロジェクト: tgjones/DotNetDxc
        private static IDxcTranslationUnit ParseTranslationUnit(string path)
        {
            var dxcIntelliSense = HlslDxcLib.CreateDxcIntelliSense();

            var index = dxcIntelliSense.CreateIndex();

            var commandLineArgs = new string[0];

            var unsavedFiles = new IDxcUnsavedFile[]
            {
                new TrivialDxcUnsavedFile(path, System.IO.File.ReadAllText(path))
            };

            var translationUnit = index.ParseTranslationUnit(
                path,
                commandLineArgs,
                commandLineArgs.Length,
                unsavedFiles,
                (uint)unsavedFiles.Length,
                (uint)DxcTranslationUnitFlags.DxcTranslationUnitFlags_UseCallerThread);

            Assert.NotNull(translationUnit);

            return(translationUnit);
        }
コード例 #3
0
        static void PrintOutTokenColors(string path)
        {
            IDxcIntelliSense isense;

            try
            {
                isense = HlslDxcLib.CreateDxcIntelliSense();
            }
            catch (System.DllNotFoundException dllNotFound)
            {
                Console.WriteLine("Unable to create IntelliSense helper - DLL not found there.");
                Console.WriteLine(dllNotFound.ToString());
                return;
            }
            catch (Exception e)
            {
                Console.WriteLine("Unable to create IntelliSense helper.");
                Console.WriteLine(e.ToString());
                return;
            }

            IDxcIndex index        = isense.CreateIndex();
            string    fileName     = path;
            string    fileContents = System.IO.File.ReadAllText(path);

            string[] commandLineArgs = new string[] { "-ferror-limit=200" };

            IDxcUnsavedFile[] unsavedFiles = new IDxcUnsavedFile[]
            {
                new TrivialDxcUnsavedFile(fileName, fileContents)
            };

            Console.WriteLine("{0}:\n{1}", fileName, fileContents);

            IDxcTranslationUnit tu = index.ParseTranslationUnit(fileName, commandLineArgs,
                                                                commandLineArgs.Length, unsavedFiles, (uint)unsavedFiles.Length, 0);

            if (tu == null)
            {
                Console.WriteLine("Unable to parse translation unit");
            }
            else
            {
                IDxcSourceRange range = tu.GetCursor().GetExtent();
                IDxcToken[]     tokens;
                uint            tokenCount;
                tu.Tokenize(range, out tokens, out tokenCount);
                Console.WriteLine("{0} tokens found.", tokenCount);
                for (UInt32 i = 0; i < tokenCount; i++)
                {
                    PrintToken(tokens[i]);
                }
            }
        }
コード例 #4
0
ファイル: OptEditorForm.cs プロジェクト: johnathonm1981/dx
        private void ApplyChangesButton_Click(object sender, EventArgs e)
        {
            // Turn the text into a container.
            IDxcBlobEncoding sourceBlob = EditorForm.CreateBlobForText(this.Library, this.CodeBox.Text);

            EditorForm.AssembleResult assembleResult = EditorForm.RunAssembly(this.Library, sourceBlob);
            if (assembleResult.Blob == null)
            {
                MessageBox.Show("Failed to assemble: " + assembleResult.ResultText);
                return;
            }

            // Extract the bitcode portion.
            const uint DxilKind = 0x4c495844; // 'LIXD' - DXIL
            uint       index;
            IDxcContainerReflection reflection = HlslDxcLib.CreateDxcContainerReflection();

            reflection.Load(assembleResult.Blob);
            reflection.FindFirstPartKind(DxilKind, out index);
            IDxcBlob bitcodeBlob = reflection.GetPartContent(index);

            List <string> passes = new List <string>();

            passes.Add("hlsl-passes-resume");
            for (int i = PassesListBox.SelectedIndex; i < PassesListBox.Items.Count; ++i)
            {
                passes.Add(((TextSection)PassesListBox.Items[i]).Title);
            }
            string[] options = EditorForm.CreatePassOptions(passes, false, true);
            EditorForm.OptimizeResult opt = EditorForm.RunOptimize(this.Library, options, bitcodeBlob);
            if (!opt.Succeeded)
            {
                MessageBox.Show("Failed to optimize: " + opt.ResultText);
                return;
            }

            OptEditorForm form = new OptEditorForm();

            form.CodeFont        = this.CodeBox.Font;
            form.Library         = this.Library;
            form.HighLevelSource = this.HighLevelSource;
            form.Sections        = TextSection.EnumerateSections(new string[] { "MODULE-PRINT", "Phase:" }, opt.ResultText).ToArray();
            form.StartPosition   = FormStartPosition.CenterParent;
            form.Show(this);
        }