protected virtual void ReadPrefix(ISourceStream source, CompoundTokenDetails details) { if (!_prefixesFirsts.Contains(source.PreviewChar)) { return; } var comparisonType = CaseSensitivePrefixesSuffixes ? StringComparison.InvariantCulture : StringComparison.InvariantCultureIgnoreCase; foreach (var pfx in Prefixes) { // Prefixes are usually case insensitive, even if language is case-sensitive. So we cannot use source.MatchSymbol here, // we need case-specific comparison if (string.Compare(source.Text, source.PreviewPosition, pfx, 0, pfx.Length, comparisonType) != 0) { continue; } //We found prefix details.Prefix = pfx; source.PreviewPosition += pfx.Length; //Set flag from prefix if (!string.IsNullOrEmpty(details.Prefix) && PrefixFlags.TryGetValue(details.Prefix, out short pfxFlags)) { details.Flags |= pfxFlags; } return; } }
/// <summary> /// Add an instruction directly to the flow of instructions. /// </summary> /// <param name="instruction"></param> public void AddInstruction(ref Instruction instruction) { if (!_label.IsEmpty && _definedAnonLabel) { throw new InvalidOperationException("You can't create both an anonymous label and a normal label"); } if (!_label.IsEmpty) { instruction.IP = _label.Id; } else if (_definedAnonLabel) { instruction.IP = _currentAnonLabel.Id; } // Setup prefixes if (_nextPrefixFlags != PrefixFlags.None) { if ((_nextPrefixFlags & PrefixFlags.Lock) != 0) { instruction.HasLockPrefix = true; } if ((_nextPrefixFlags & PrefixFlags.Xacquire) != 0) { instruction.HasXacquirePrefix = true; } if ((_nextPrefixFlags & PrefixFlags.Xrelease) != 0) { instruction.HasXreleasePrefix = true; } if ((_nextPrefixFlags & PrefixFlags.Rep) != 0) { instruction.HasRepPrefix = true; } else if ((_nextPrefixFlags & PrefixFlags.Repe) != 0) { instruction.HasRepePrefix = true; } else if ((_nextPrefixFlags & PrefixFlags.Repne) != 0) { instruction.HasRepnePrefix = true; } if ((_nextPrefixFlags & PrefixFlags.Bnd) != 0) { instruction.HasRepnePrefix = true; } if ((_nextPrefixFlags & PrefixFlags.Notrack) != 0) { instruction.SegmentPrefix = Register.DS; } } _instructions.Add(instruction); _label = default; _definedAnonLabel = false; _nextPrefixFlags = PrefixFlags.None; }
/// <summary> /// Reset the current set of instructions and labels added to this instance. /// </summary> public void Reset() { _instructions.Clear(); _currentLabelId = 0; _label = default; _currentAnonLabel = default; _nextAnonLabel = default; _definedAnonLabel = false; _nextPrefixFlags = PrefixFlags.None; }
/// <summary> /// Reset the current set of instructions and labels added to this instance. /// </summary> public void Reset() { instructions.Clear(); currentLabelId = 0; currentLabel = default; currentAnonLabel = default; nextAnonLabel = default; definedAnonLabel = false; prefixFlags = PrefixFlags.None; }
/// <summary> /// Add an instruction directly to the flow of instructions. /// </summary> /// <param name="instruction"></param> public void AddInstruction(ref Instruction instruction) { if (!currentLabel.IsEmpty && definedAnonLabel) { throw new InvalidOperationException("You can't create both an anonymous label and a normal label"); } if (!currentLabel.IsEmpty) { instruction.IP = currentLabel.Id; } else if (definedAnonLabel) { instruction.IP = currentAnonLabel.Id; } // Setup prefixes if (prefixFlags != PrefixFlags.None) { if ((prefixFlags & PrefixFlags.Lock) != 0) { instruction.HasLockPrefix = true; } if ((prefixFlags & PrefixFlags.Repe) != 0) { instruction.HasRepePrefix = true; } else if ((prefixFlags & PrefixFlags.Repne) != 0) { instruction.HasRepnePrefix = true; } if ((prefixFlags & PrefixFlags.Notrack) != 0) { instruction.SegmentPrefix = Register.DS; } } instructions.Add(instruction); currentLabel = default; definedAnonLabel = false; prefixFlags = PrefixFlags.None; }
/// <summary> /// Creates a new instance of this assembler /// </summary> /// <param name="bitness">The assembler instruction set bitness, either 16, 32 or 64 bit.</param> public Assembler(int bitness) { switch (bitness) { case 16: case 32: case 64: break; default: throw new ArgumentOutOfRangeException(nameof(bitness)); } Bitness = bitness; instructions = new InstructionList(); currentLabelId = 0; currentLabel = default; currentAnonLabel = default; nextAnonLabel = default; definedAnonLabel = false; prefixFlags = PrefixFlags.None; PreferVex = true; PreferShortBranch = true; }
protected void AddPrefixFlag(string prefix, short flags) { PrefixFlags.Add(prefix, flags); Prefixes.Add(prefix); }
public void AddPrefix(string prefix, NumberOptions options) { PrefixFlags.Add(prefix, (short)options); Prefixes.Add(prefix); }
public void AddPrefix(string prefix, NumberFlags flags) { PrefixFlags.Add(prefix, (short)flags); Prefixes.Add(prefix); }
public void AddPrefixFlag(string prefix, ScanFlags flags) { PrefixFlags.Add(prefix, flags); Prefixes.Add(prefix); }