private void Asserts(ExtendedWarrior warrior) { if (warrior.Length > warrior.Rules.MaxLength) { WriteError("Too many instructions"); } }
private void SetAuthor(ExtendedWarrior warrior) { if (authorName != null) { warrior.Author = authorName; } }
private void SetOrg(ExtendedWarrior warrior) { if (org != null) { warrior.StartOffset = org.Evaluate(this, 0); } }
public override void ExpandStatements(ExtendedWarrior warrior, IWarriorParser parser, ref int currentAddress, int coreSize, bool evaluate) { foreach (Statement statement in Statements) { statement.ExpandStatements(warrior, parser, ref currentAddress, coreSize, evaluate); } }
private void SetName(ExtendedWarrior warrior, string implicitName) { if (warriorName != null) { warrior.Name = warriorName; } else { warrior.Name = implicitName; } }
private void SetPin(ExtendedWarrior warrior) { if (pin != null) { warrior.Pin = pin.Evaluate(this, 0); } else { warrior.Pin = PSpace.UNSHARED; } }
public override void ExpandStatements(ExtendedWarrior warrior, IWarriorParser parser, ref int currentAddress, int coreSize, bool evaluate) { if (!evaluate) { return; } if (expression.Evaluate(parser, currentAddress) == 0) { parser.WriteError("Assert failed : " + this + " at : " + Location, Location); } }
protected override IWarrior Parse(string aFileName) { fileName = aFileName; StreamReader sr = new StreamReader(fileName); string source = sr.ReadToEnd(); sr.Close(); ExtendedWarrior warrior = Parse(source, Path.GetFileNameWithoutExtension(fileName)); if (warrior != null) { warrior.FileName = fileName; } return(warrior); }
public override void ExpandStatements(ExtendedWarrior warrior, IWarriorParser parser, ref int currentAddress, int coreSize, bool evaluate) { //set labels, except last which is EQU expression for (int l = 0; l < Labels.Count; l++) { LabelName label = Labels[l]; if (l == Labels.Count - 1) {//equ parser.Variables[label.GetFullName(parser, currentAddress)] = expression; } else {//labels parser.Variables[label.GetFullName(parser, currentAddress)] = new Address(currentAddress); } } return; }
public override void ExpandStatements(ExtendedWarrior warrior, IWarriorParser parser, ref int currentAddress, int coreSize, bool evaluate) { //set labels, except last which is FOR expression for (int l = 0; l < Labels.Count - 1; l++) { LabelName label = Labels[l]; parser.Variables[label.GetFullName(parser, currentAddress)] = new Address(currentAddress); } string cnt = Labels[Labels.Count - 1].Name; int count = parser.Variables[LimitName].Evaluate(parser, currentAddress); for (int i = 1; i <= count; i++) { parser.Variables[cnt] = new Value(i); base.ExpandStatements(warrior, parser, ref currentAddress, coreSize, evaluate); } }
private ExtendedWarrior Parse(string sourceText, string implicitName) { errCount = 0; Prepare(); try { Statement statement = ParseInternal(sourceText); if (statement == null) { return(null); } ExtendedWarrior warrior = new ExtendedWarrior(project.Rules); int currentAddress; //first pass to expand for-rof cycles currentAddress = 0; variables["CURLINE"] = new Value(0); statement.ExpandStatements(warrior, this, ref currentAddress, project.Rules.CoreSize, false); SetRegisters(); //second pass to evaluate variables/labels in context of for cycles currentAddress = 0; variables["CURLINE"] = new Value(0); statement.ExpandStatements(warrior, this, ref currentAddress, project.Rules.CoreSize, true); SetOrg(warrior); SetPin(warrior); SetName(warrior, implicitName); SetAuthor(warrior); Asserts(warrior); warrior.Variables = variables; if (errCount > 0) { return(null); } return(warrior); } catch (ParserException) { return(null); } }
public ExtendedWarrior TryParse([NotNull] string sourceText, [NotNull] string implicitName) { result = new ParseResult(); Prepare(); try { Statement statement = ParseInternal(sourceText); if (statement == null) { return(null); } var warrior = new ExtendedWarrior(rules); //first pass to expand for-rof cycles var currentAddress = 0; variables["CURLINE"] = new Value(0); statement.ExpandStatements(warrior, this, ref currentAddress, rules.CoreSize, false); SetRegisters(); //second pass to evaluate variables/labels in context of for cycles currentAddress = 0; variables["CURLINE"] = new Value(0); statement.ExpandStatements(warrior, this, ref currentAddress, rules.CoreSize, true); SetOrg(warrior); SetPin(warrior); SetName(warrior, implicitName); SetAuthor(warrior); Asserts(warrior); warrior.Variables = variables; return(result.Succesfull ? warrior : null); } catch (ParserException) { return(null); } }
public override void ExpandStatements(ExtendedWarrior warrior, IWarriorParser parser, ref int currentAddress, int coreSize, bool evaluate) { //set all labels foreach (LabelName label in Labels) { parser.Variables[label.GetFullName(parser, currentAddress)] = new Address(currentAddress); } ExtendedInstruction instruction; if (!evaluate) { instruction = new ExtendedInstruction(Operation, Modifier, A.Mode, Int32.MinValue, B.Mode, Int32.MinValue); instruction.Address = currentAddress; warrior.Add(instruction); } else { instruction = (ExtendedInstruction)warrior.Instructions[currentAddress]; instruction.ValueA = Instruction.Mod(A.Expression.Evaluate(parser, currentAddress, coreSize), coreSize); instruction.ValueB = Instruction.Mod(B.Expression.Evaluate(parser, currentAddress, coreSize), coreSize); instruction.ExpressionA = A.Expression.ToString(); instruction.ExpressionB = B.Expression.ToString(); if (instruction.ModeA == Mode.NULL) { instruction.ModeA = A.Expression.GetMode(parser, currentAddress); } if (instruction.ModeA == Mode.NULL) { instruction.ModeA = Mode.Direct; } if (instruction.ModeB == Mode.NULL) { instruction.ModeB = B.Expression.GetMode(parser, currentAddress); } if (instruction.ModeB == Mode.NULL) { instruction.ModeB = Mode.Direct; } if (instruction.Modifier == Modifier.NULL) { instruction.Modifier = Instruction.DefaultModifier(instruction.Operation, instruction.ModeA, instruction.ModeB); } if (Comments != null) { instruction.Comment = Comments[Comments.Count - 1]; } else { instruction.Comment = ""; } instruction.OriginalInstruction = OriginalInstruction; if (Labels.Count > 0) { instruction.Label = Labels[Labels.Count - 1].GetFullName(parser, currentAddress); } else { instruction.Label = ""; } } currentAddress++; parser.Variables["CURLINE"] = new Value(currentAddress); }
public abstract void ExpandStatements(ExtendedWarrior warrior, IWarriorParser parser, ref int currentAddress, int coreSize, bool evaluate);