diff options
| author | Melodi <62381002+Melodi17@users.noreply.github.com> | 2026-07-11 09:03:50 +1000 |
|---|---|---|
| committer | Melodi <62381002+Melodi17@users.noreply.github.com> | 2026-07-11 09:03:50 +1000 |
| commit | cb3cc7e94327c57a0f7539d8f8f2406ca4b04037 (patch) | |
| tree | 8e4d241a466e58b438579622a8a1a6e2339489e9 /Q1.core/Pipeline/AssemblerBlock.cs | |
| parent | 512a5f0efeea46994d01124b409ef51f9b9177a0 (diff) | |
checkpointstability-rewrite
Diffstat (limited to 'Q1.core/Pipeline/AssemblerBlock.cs')
| -rw-r--r-- | Q1.core/Pipeline/AssemblerBlock.cs | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/Q1.core/Pipeline/AssemblerBlock.cs b/Q1.core/Pipeline/AssemblerBlock.cs new file mode 100644 index 0000000..e40cbec --- /dev/null +++ b/Q1.core/Pipeline/AssemblerBlock.cs @@ -0,0 +1,60 @@ +namespace Q1.core.Pipeline; + +public class AssemblerBlock +{ + private readonly MemoryStream _stream = new(); + public readonly Dictionary<i64, (bool word, string constant)> DeferredConstants = new(); + + public long Size => this._stream.Length; + + public void WriteByte(u8 data) + { + this._stream.WriteByte(data); + } + + public void WriteWord(u16 data) + { + u8 high = (u8) (data & 0xFF); + u8 low = (u8) ((data >> 8) & 0xFF); + this._stream.WriteByte(low); + this._stream.WriteByte(high); + } + + public void DeferWordConstant(string constant) + { + this.DeferredConstants.Add(this._stream.Length - 1, (true, constant)); + this.WriteWord(0); + } + + public void DeferByteConstant(string constant) + { + this.DeferredConstants.Add(this._stream.Length - 1, (false, constant)); + this.WriteByte(0); + } + + public void ResolveWordConstant(i32 offset, u16 value) + { + long currentPos = this._stream.Position; + this._stream.Position = offset; + + this.WriteWord(value); + + this._stream.Position = currentPos; + } + + public void ResolveByteConstant(i32 offset, u8 value) + { + long currentPos = this._stream.Position; + this._stream.Position = offset; + + this.WriteByte(value); + + this._stream.Position = currentPos; + } + + public void WriteToStream(MemoryStream target) + { + this._stream.Position = 0; + this._stream.CopyTo(target); + } +}
\ No newline at end of file |
