public override Intermediate.IRNode Emit(CompileContext context, Model.Scope scope, Target target) { Model.Label destination = null; foreach (var _label in scope.activeFunction.function.labels) if (_label.declaredName == label) destination = _label; if (destination == null) context.ReportError(this, "Unknown label - " + label); var r = new StatementNode(); if (destination != null) r.AddInstruction(Instructions.SET, Operand("PC"), Label(destination.realName)); return r; }
public override void ResolveTypes(CompileContext context, Model.Scope enclosingScope) { _struct = enclosingScope.FindType(typeName); if (_struct == null) { context.ReportError(this, "Could not find type " + typeName); CachedFetchToken = Constant(0); } else { var memberIndex = _struct.members.FindIndex(m => m.name == memberName); if (memberIndex < 0) { context.ReportError(this, "Member not found : " + memberName); CachedFetchToken = Constant(0); } else CachedFetchToken = Constant((ushort)memberIndex); } ResultType = "word"; }
public override void ResolveTypes(CompileContext context, Model.Scope enclosingScope) { _struct = enclosingScope.FindType(typeName); if (_struct == null) { CachedFetchToken = Constant(0); context.ReportError(this, "Could not find type " + typeName); } else if (_struct.size == 0) { throw new InternalError("Struct size must be determined before types are resolved."); } else CachedFetchToken = Constant((ushort)_struct.size); ResultType = "word"; }
Intermediate.IRNode AssignableNode.EmitAssignment(CompileContext context, Model.Scope scope, Intermediate.Operand from, Intermediate.Instructions opcode) { var r = new TransientNode(); if (member == null) { context.ReportError(this, "Member was not resolved"); return r; } var target = Target.Register(context.AllocateRegister()); r.AddChild(Child(0).Emit(context, scope, target)); r.AddInstruction(opcode, target.GetOperand(TargetUsage.Peek, Intermediate.OperandSemantics.Dereference | Intermediate.OperandSemantics.Offset, (ushort)member.offset), from); return r; }
public override Intermediate.IRNode Emit(CompileContext context, Model.Scope scope, Target target) { var r = new TransientNode(); if (member == null) { context.ReportError(this, "Member was not resolved."); return r; } Target objectTarget = target; if (target.target == Targets.Stack) objectTarget = Target.Register(context.AllocateRegister()); r.AddChild(Child(0).Emit(context, scope, objectTarget)); if (member.isArray) { if (target != objectTarget) r.AddInstruction(Instructions.SET, target.GetOperand(TargetUsage.Push), objectTarget.GetOperand(TargetUsage.Pop)); r.AddInstruction(Instructions.ADD, target.GetOperand(TargetUsage.Peek), Constant((ushort)member.offset)); } else { if (member.offset == 0) r.AddInstruction(Instructions.SET, target.GetOperand(TargetUsage.Push), objectTarget.GetOperand(TargetUsage.Pop, Intermediate.OperandSemantics.Dereference)); else r.AddInstruction(Instructions.SET, target.GetOperand(TargetUsage.Push), objectTarget.GetOperand(TargetUsage.Pop, Intermediate.OperandSemantics.Dereference | Intermediate.OperandSemantics.Offset, (ushort)member.offset)); } return r; }
public override void ResolveTypes(CompileContext context, Model.Scope enclosingScope) { Child(0).ResolveTypes(context, enclosingScope); _struct = enclosingScope.FindType(Child(0).ResultType); if (_struct == null) { context.ReportError(this, "Result of expression is not a struct"); ResultType = "word"; } else { foreach (var _member in _struct.members) if (_member.name == memberName) member = _member; if (member == null) { context.ReportError(this, "Member " + memberName + " not found on " + _struct.name); ResultType = "word"; } else ResultType = member.typeSpecifier; } }