Exemplo n.º 1
0
        private void ApplyChangesButton_Click(object sender, EventArgs e)
        {
            // Turn the text into the expected encoding.
            IDxcBlobEncoding sourceBlob = EditorForm.CreateBlobForText(this.Library, this.CodeBox.Text);

            sourceBlob = this.Library.GetBlobAstUf8(sourceBlob);
            IDxcBlob bitcodeBlob = sourceBlob;

            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);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        private void btnViewCFGOnly_Click(object sender, EventArgs e)
        {
            if (PassesListBox.SelectedIndex == -1)
            {
                MessageBox.Show("Select a pass first");
                return;
            }
            TextSection section = (TextSection)PassesListBox.SelectedItem;

            var source = EditorForm.CreateBlobForText(this.Library, section.Text);

            source = this.Library.GetBlobAstUf8(source);

            string[] options = new string [1];
            options[0] = "-view-cfg-only";
            EditorForm.OptimizeResult opt = EditorForm.RunOptimize(this.Library, options, source);
            if (!opt.Succeeded)
            {
                MessageBox.Show("Failed to optimize: " + opt.ResultText);
                return;
            }

            string dotText = opt.ResultText.Substring(opt.ResultText.IndexOf("digraph"));

            EditorForm.LogContextMenuHelper.ShowDot(dotText);
        }
Exemplo n.º 4
0
        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);
        }