public override void Generate(AstScope currentScope, GenerateContext ctx) { ctx.ListTo(SourcePosition); if (ctx.ListFile != null) { ctx.ListTo(SourcePosition); ctx.WriteListingText($"{ctx.ip:X4}: [{_bytes} bytes]"); ctx.ListToInclusive(SourcePosition); } var bytes = new byte?[_bytes]; if (ValueExpression != null) { var value = Utils.PackByte(ValueExpression.SourcePosition, ValueExpression.EvaluateNumber(currentScope)); for (int i = 0; i < bytes.Length; i++) { bytes[i] = value; } } ctx.EmitBytes(bytes, false); }
public override void Generate(AstScope currentScope, GenerateContext ctx) { ctx.ListToInclusive(SourcePosition); ctx.EnterSourceFile(_content.SourcePosition); _content.Generate(currentScope, ctx); ctx.LeaveSourceFile(); }
public override void DefineSymbols(AstScope currentScope) { var valueInScope = new ExprNodeDeferredValue(_position, _name); _valueToScopeMap.Add(currentScope, valueInScope); currentScope.Define(_name, valueInScope); }
ExprNode FindSymbol(AstScope scope) { if (Arguments == null) { // Simple symbol var symbol = scope.FindSymbol(_name); if (symbol == null) { throw new CodeException($"Unrecognized symbol: '{_name}'", SourcePosition); } var expr = symbol as ExprNode; if (expr == null) { throw new CodeException($"Invalid expression: '{_name}' is not a value", SourcePosition); } return(expr); } else { // Parameterized symbol var symbol = scope.FindSymbol(_name + ExprNodeParameterized.MakeSuffix(Arguments.Length)) as ExprNodeParameterized; if (symbol == null) { throw new CodeException($"Unrecognized symbol: '{_name}' (with {Arguments.Length} arguments)", SourcePosition); } // Resolve it return(symbol.Resolve(SourcePosition, Arguments)); } }
public override IEnumerable <ExprNode> EnumData(AstScope scope) { foreach (var ch in _value) { yield return(new ExprNodeNumberLiteral(SourcePosition, ch)); } }
public override AddressingMode GetAddressingMode(AstScope scope) { var lhsMode = LHS.GetAddressingMode(scope); var rhsMode = RHS.GetAddressingMode(scope); if (lhsMode == AddressingMode.Immediate && rhsMode == AddressingMode.Immediate) { return(AddressingMode.Immediate); } if (lhsMode == AddressingMode.Immediate && rhsMode == AddressingMode.Register) { return(AddressingMode.RegisterPlusImmediate); } if (lhsMode == AddressingMode.Register && rhsMode == AddressingMode.Immediate) { return(AddressingMode.RegisterPlusImmediate); } if (lhsMode == AddressingMode.Immediate && rhsMode == AddressingMode.RegisterPlusImmediate) { return(AddressingMode.RegisterPlusImmediate); } if (lhsMode == AddressingMode.RegisterPlusImmediate && rhsMode == AddressingMode.Immediate) { return(AddressingMode.RegisterPlusImmediate); } return(AddressingMode.Invalid); }
public override object Evaluate(AstScope scope) { // Get the LHS (which must be a type) var lhsVal = _lhs.Evaluate(scope); var type = lhsVal as AstType; if (type == null) { var fd = lhsVal as AstFieldDefinition; if (fd != null) { type = fd.Type; } else { throw new CodeException($"LHS of member operator '.{_name}' is not a type or field ", SourcePosition); } } // Get the field definition var fieldDefinition = type.FindField(_name); if (fieldDefinition == null) { throw new CodeException($"The type '{type.Name}' does not contain a field named '{_name}'", SourcePosition); } // Return the field definition return(fieldDefinition); }
public void BuildType(AstScope definingScope, ref int offset) { // Store offset _offset = offset; // Find the field's type var symbol = definingScope.FindSymbol(_typename); if (symbol == null) { throw new CodeException($"Unknown type: '{_typename}'", SourcePosition); } _type = symbol as AstType; if (_type == null) { throw new CodeException($"Invalid type declaration: '{_typename}' is not a type"); } // Resolve the array size _arraySize = 0; foreach (var d in _initializer.EnumData(definingScope)) { if (!(d is ExprNodeUninitialized)) { throw new CodeException($"Invalid struct definition: all fields must be declared with uninitialized data", SourcePosition); } _arraySize++; } // Update the size offset += _type.SizeOf * _arraySize; }
public string GetBitPattern(AstScope scope) { if (_bitPattern == null) { var value = (int)_value.EvaluateNumber(scope); var bitWidth = (int)_bitWidth.EvaluateNumber(scope); var str = Convert.ToString(value, 2); if (str.Length > bitWidth) { var cutPart = str.Substring(0, str.Length - bitWidth); if (cutPart.Distinct().Count() != 1 || cutPart[0] != str[str.Length - bitWidth]) { throw new CodeException($"DEFBITS value 0b{str} doesn't fit in {bitWidth} bits", SourcePosition); } } else { str = new string('0', bitWidth - str.Length) + str; } _bitPattern = str; } return(_bitPattern); }
public override void Layout(AstScope currentScope, LayoutContext ctx) { // Capture the current ip address as the place where this EQU was defined ((ExprNodeEquWrapper)_value).SetOverrides(ctx.ip, ctx.op); // Do default base.Layout(currentScope, ctx); }
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 (Parser.IsReservedWord(_name)) { throw new CodeException($"Illegal field name: '{_name}' is a reserved word", SourcePosition); } base.DefineSymbols(currentScope); }
public override long EvaluateNumber(AstScope scope) { if (_value.Length == 1) { return(_value[0]); } throw new CodeException($"Only single character strings can be used as numeric literals", SourcePosition); }
public override long EvaluateNumber(AstScope scope) { if (_value.HasValue) { return(_value.Value); } throw new CodeException($"The value of symbol '{_name}' can't been resolved", SourcePosition); }
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 override long GetImmediateValue(AstScope scope) { // Temporarily overridden? (See ExprNodeEquWrapper) if (_allowOverride && scope.opOverride.HasValue) { return(scope.opOverride.Value); } return(_generateContext.op); }
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 AddressingMode GetAddressingMode(AstScope scope) { var mode = Pointer.GetAddressingMode(scope); if ((mode & (AddressingMode.Deref | AddressingMode.SubOp)) == 0) { return(mode | AddressingMode.Deref); } return(AddressingMode.Invalid); }
public override void Layout(AstScope currentScope, LayoutContext ctx) { if (_isTrue) { TrueBlock.Layout(currentScope, ctx); } else if (FalseBlock != null) { FalseBlock.Layout(currentScope, ctx); } }
public override void Generate(AstScope currentScope, GenerateContext ctx) { if (_isTrue) { TrueBlock.Generate(currentScope, ctx); } else if (FalseBlock != null) { FalseBlock.Generate(currentScope, ctx); } }
public override IEnumerable <ExprNode> EnumData(AstScope scope) { if (Condition.EvaluateNumber(scope) != 0) { return(TrueValue.EnumData(scope)); } else { return(FalseValue.EnumData(scope)); } }
public override AddressingMode GetAddressingMode(AstScope scope) { if (TrueValue.GetAddressingMode(scope) == AddressingMode.Immediate && FalseValue.GetAddressingMode(scope) == AddressingMode.Immediate) { return(AddressingMode.Immediate); } else { return(AddressingMode.Invalid); } }
public override long EvaluateNumber(AstScope scope) { if (Condition.EvaluateNumber(scope) != 0) { return(TrueValue.EvaluateNumber(scope)); } else { return(FalseValue.EvaluateNumber(scope)); } }
public override void DefineSymbols(AstScope currentScope) { if (this is AstMacroDefinition) { base.DefineSymbols(currentScope); } else { base.DefineSymbols(this); } }
public override AddressingMode GetAddressingMode(AstScope scope) { if (RHS.GetAddressingMode(scope) == AddressingMode.Immediate && LHS.GetAddressingMode(scope) == AddressingMode.Immediate) { return(AddressingMode.Immediate); } else { return(AddressingMode.Invalid); } }
public override void Layout(AstScope currentScope, LayoutContext ctx) { if (this is AstMacroDefinition) { base.Layout(currentScope, ctx); } else { base.Layout(this, ctx); } }
public override void Generate(AstScope currentScope, GenerateContext ctx) { if (this is AstMacroDefinition) { base.Generate(currentScope, ctx); } else { base.Generate(this, ctx); } }
public override AddressingMode GetAddressingMode(AstScope scope) { if (_value.Length == 1) { return(AddressingMode.Immediate); } else { return(AddressingMode.Invalid); } }
public override void Generate(AstScope currentScope, GenerateContext ctx) { if (ctx.ListFile != null) { ctx.ListTo(SourcePosition); ctx.WriteListingText($"{ctx.ip:X4}: [{_data.Length} bytes]"); ctx.ListToInclusive(SourcePosition); } ctx.EmitBytes(_data, false); }
public override long EvaluateNumber(AstScope scope) { if (scope.IsSymbolDefined(_symbolName, true)) { return(1); } else { return(0); } }