public override void DefineSymbols(AstScope currentScope) { currentScope.Define("DB", this); currentScope.Define("DEFB", this); currentScope.Define("DM", this); currentScope.Define("DEFM", this); base.DefineSymbols(currentScope); }
public override void DefineSymbols(AstScope currentScope) { if (ParameterNames == null) { // Wrap it in an IP override declaration currentScope.Define(_name, _value); } else { var value = new ExprNodeParameterized(SourcePosition, ParameterNames, _value); currentScope.Define(_name + ExprNodeParameterized.MakeSuffix(ParameterNames.Length), value); } }
public override void DefineSymbols(AstScope currentScope) { var valueInScope = new ExprNodeDeferredValue(_position, _name); _valueToScopeMap.Add(currentScope, valueInScope); currentScope.Define(_name, valueInScope); }
public ExprNodeParameterizedInstance(SourcePosition pos, string[] parameterNames, ExprNode[] arguments, ExprNode body) : base(pos) { _scope = new AstScope("parameterized equate"); for (int i = 0; i < parameterNames.Length; i++) { _scope.Define(parameterNames[i], arguments[i]); } _body = body; }
public override void DefineSymbols(AstScope currentScope) { if (_parameters == null) { _parameters = new string[0]; } // Define the symbol currentScope.Define(_name + ExprNodeParameterized.MakeSuffix(_parameters.Length), this); }
public AstScope Resolve(AstScope currentScope, ExprNode[] arguments) { // Create scope var scope = new AstScope("MACRO INVOCATION"); // Define it for (int i = 0; i < _parameters.Length; i++) { scope.Define(_parameters[i], arguments[i]); } // Setup outer scope scope.Container = currentScope; return(scope); }
public override void DefineSymbols(AstScope currentScope) { if (_character.Length != 1) { throw new CodeException("Bit pattern names must be a single character", SourcePosition); } if (_bitPattern != null) { for (int i = 0; i < _bitPattern.Length; i++) { if (_bitPattern[i] != '0' && _bitPattern[i] != '1') { throw new CodeException("Bit patterns must only contain '1' and '0' characters", SourcePosition); } } } currentScope.Define($"bitpattern'{_character}'", this, true); }
public override void DefineSymbols(AstScope currentScope) { currentScope.Define(Name, this); base.DefineSymbols(currentScope); }
public int Run(string[] args) { // Process command line if (!ProcessArgs(args)) { return(0); } // Was there an input file specified? if (_inputFile == null) { ShowLogo(); ShowHelp(); return(7); } // Create the root scope var root = new AstScope("global"); var exprNodeIP = new ExprNodeIP(true); root.Define("$", exprNodeIP); var exprNodeIP2 = new ExprNodeIP(false); root.Define("$$", exprNodeIP2); var exprNodeOP = new ExprNodeOFS(true); root.Define("$ofs", exprNodeOP); var exprNodeOP2 = new ExprNodeOFS(false); root.Define("$$ofs", exprNodeOP2); root.AddElement(new AstTypeByte()); root.AddElement(new AstTypeWord()); // Define user specified symbols foreach (var kv in _userDefines) { var defParser = new Parser(); if (kv.Value != null) { try { var exprNode = defParser.ParseExpression(kv.Value); root.Define(kv.Key, exprNode); } catch (CodeException x) { throw new InvalidOperationException(x.Message + " in command line symbol definition"); } } else { root.Define(kv.Key, new ExprNodeNumberLiteral(null, 1)); } } // Step 1 - Parse the input file var p = new Parser(); p.IncludePaths = _includePaths; var file = p.Parse(_inputFile, System.IO.Path.GetFullPath(_inputFile)); root.AddElement(file); // Run the "Define Symbols" pass root.DefineSymbols(null); if (_astFile != null) { using (var w = OpenTextWriter(_astFile, ".ast.txt")) { root.Dump(w, 0); } } // Step 2 - Layout var layoutContext = new LayoutContext(); exprNodeIP.SetContext(layoutContext); exprNodeIP2.SetContext(layoutContext); exprNodeOP.SetContext(layoutContext); exprNodeOP2.SetContext(layoutContext); root.Layout(null, layoutContext); if (Log.ErrorCount == 0) { // Step 3 - Generate var generateContext = new GenerateContext(layoutContext); exprNodeIP.SetContext(generateContext); exprNodeIP2.SetContext(generateContext); exprNodeOP.SetContext(generateContext); exprNodeOP2.SetContext(generateContext); if (_listFile != null) { generateContext.ListFile = OpenTextWriter(_listFile, "lst"); } generateContext.EnterSourceFile(file.SourcePosition); root.Generate(null, generateContext); generateContext.LeaveSourceFile(); if (_listFile != null) { generateContext.ListFile.Dispose(); generateContext.ListFile = null; } if (Log.ErrorCount == 0) { var code = generateContext.GetGeneratedBytes(); var outputFile = _outputFile == null?System.IO.Path.ChangeExtension(_inputFile, ".bin") : _outputFile; System.IO.File.WriteAllBytes(outputFile, code); } } // Write symbols file if (_symbolsFile != null && Log.ErrorCount == 0) { using (var w = OpenTextWriter(_symbolsFile, "sym")) root.DumpSymbols(w); } Log.DumpSummary(); if (Log.ErrorCount != 0) { return(7); } return(0); }