Example #1
0
        private static string MatchEval(Match match)
        {
            GroupCollection groupCollection = match.Groups;

            string replaceStr = "";

            replaceStr += groupCollection["whitespace"].Value; // Whitespace

            if (groupCollection["labeltype"].Value == "JUMP_LABEL,")
            {
                replaceStr += "JUMP, ";
            }
            else if (groupCollection["labeltype"].Value == "JUMP_IF_FALSE_LABEL,")
            {
                replaceStr += "JUMP_IF_FALSE, ";
            }

            string labelName = groupCollection["label"].Value;

            JumpLabel targetLabel = currentLabelTable.GetLabel(labelName);

            replaceStr += targetLabel.AddresStr();

            replaceStr += groupCollection["commentwhitespace"];

            // optional comment
            if (groupCollection.Count > 4)
            {
                replaceStr += groupCollection["comment"].Value;
            }

            return(replaceStr);
        }
Example #2
0
        public void AddJumpIfFalse(JumpLabel jumpTarget, string comment = "")
        {
            if (jumpTarget.IsResolved)
            {
                AppendCommentedLine($"JUMP_IF_FALSE, {jumpTarget.AddresStr()}", comment);
            }
            else
            {
                AppendCommentedLine($"JUMP_IF_FALSE_LABEL, [{jumpTarget.uniqueName}]", comment);
            }

            programCounter += UdonSharpUtils.GetUdonInstructionSize("JUMP_IF_FALSE");
        }
        public void AddJump(JumpLabel jumpTarget, string comment = "")
        {
#if USE_UDON_LABELS
            AppendCommentedLine($"JUMP, {jumpTarget.uniqueName}", comment);
#else
            if (jumpTarget.IsResolved)
            {
                AppendCommentedLine($"JUMP, {jumpTarget.AddresStr()}", comment);
            }
            else
            {
                AppendCommentedLine($"JUMP_LABEL, [{jumpTarget.uniqueName}]", comment);
            }
#endif

            programCounter += UdonSharpUtils.GetUdonInstructionSize("JUMP");
        }
        private string ReplaceLabels(string assemblyString, LabelTable labelTable)
        {
            StringBuilder newAssemblyBuilder = new StringBuilder();

            using (StringReader reader = new StringReader(assemblyString))
            {
                string currentLine = reader.ReadLine();

                while (currentLine != null)
                {
                    string line = currentLine.TrimStart(' ', '\n', '\r');
                    if (line.StartsWith("JUMP_LABEL,"))
                    {
                        int       startIdx  = line.IndexOf('[') + 1;
                        int       endIdx    = line.IndexOf(']');
                        string    labelName = line.Substring(startIdx, endIdx - startIdx);
                        JumpLabel label     = labelTable.GetLabel(labelName);
                        newAssemblyBuilder.Append($"        JUMP, {label.AddresStr()}\n");
                    }
                    else if (line.StartsWith("JUMP_IF_FALSE_LABEL,"))
                    {
                        int       startIdx  = line.IndexOf('[') + 1;
                        int       endIdx    = line.IndexOf(']');
                        string    labelName = line.Substring(startIdx, endIdx - startIdx);
                        JumpLabel label     = labelTable.GetLabel(labelName);
                        newAssemblyBuilder.Append($"        JUMP_IF_FALSE, {label.AddresStr()}\n");
                    }
                    else
                    {
                        newAssemblyBuilder.Append(currentLine + "\n");
                    }

                    currentLine = reader.ReadLine();
                }
            }

            return(newAssemblyBuilder.ToString());
        }