diff options
| author | Melodi <62381002+Melodi17@users.noreply.github.com> | 2025-09-05 10:20:03 +1000 |
|---|---|---|
| committer | Melodi <62381002+Melodi17@users.noreply.github.com> | 2025-09-05 10:20:03 +1000 |
| commit | 9e8ba6e00dc4a4137a5187dbe5fe5b1394219735 (patch) | |
| tree | e5a54706a8a85243fdb0fe0f2ed73fb7b7566bcd /Compiler/Optimizer.cs | |
| parent | 4ea967c6089bbcaba5d71145546d288e186fba40 (diff) | |
stuff
Diffstat (limited to 'Compiler/Optimizer.cs')
| -rw-r--r-- | Compiler/Optimizer.cs | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/Compiler/Optimizer.cs b/Compiler/Optimizer.cs new file mode 100644 index 0000000..4646c1c --- /dev/null +++ b/Compiler/Optimizer.cs @@ -0,0 +1,28 @@ +namespace Q1.Compiler; + +using System.Text.RegularExpressions; + +public class Optimizer +{ + private string _instructions; + private int _currentIndex = 0; + + public Optimizer(List<string> instructions) + { + this._instructions = string.Join(Environment.NewLine, instructions); + } + + public string Optimize() + { + string output = this._instructions; + output = this.RemoveRedundantFallbackReturns(output); + + return output; + } + + private string RemoveRedundantFallbackReturns(string input) + { + string pattern = @"(mov .*, V0\n\s*ret\n)\s*mov 0, V0\n\s*ret"; + return Regex.Replace(input, pattern, "$1"); + } +}
\ No newline at end of file |
