Esempio n. 1
0
        void ReportInstanceErrors(AssemblingStatus status, MixInstruction.Instance instance)
        {
            var errorArray = instance.Validate();

            if (errorArray != null)
            {
                int causeStartIndex = 0;
                int causeLength     = 0;

                foreach (InstanceValidationError error in errorArray)
                {
                    switch (error.Source)
                    {
                    case InstanceValidationError.Sources.Address:
                        causeStartIndex = 0;
                        causeLength     = mIndexPartCharIndex;
                        break;

                    case InstanceValidationError.Sources.Index:
                        causeStartIndex = mIndexPartCharIndex;
                        causeLength     = mFieldPartCharIndex - mIndexPartCharIndex;
                        break;

                    case InstanceValidationError.Sources.FieldSpec:
                        causeStartIndex = mFieldPartCharIndex;
                        causeLength     = mTextLength - mFieldPartCharIndex;
                        break;
                    }

                    status.ReportError(LineSection.AddressField, causeStartIndex, causeLength, error);
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Create a MIX instruction instance with the parameters contained in this object.
        /// </summary>
        /// <param name="instruction">MixInstruction to create an instance of. This method will throw an exception if this parameter is of a different instruction type.</param>
        /// <param name="status">AssemblingStatus object reflecting the current state of the assembly process</param>
        /// <returns></returns>
        public InstructionInstanceBase CreateInstance(InstructionBase instruction, AssemblingStatus status)
        {
            if (!(instruction is MixInstruction))
            {
                throw new ArgumentException("instruction must be a MixInstruction", nameof(instruction));
            }

            var mixInstruction = (MixInstruction)instruction;

            if (!AreValuesDefined(status))
            {
                return(null);
            }

            var addressMagnitude = mAddress.GetMagnitude(status.LocationCounter);
            var word             = new Word(MixInstruction.AddressByteCount);

            if (addressMagnitude > word.MaxMagnitude)
            {
                status.ReportError(LineSection.AddressField, 0, mIndexPartCharIndex, new MixAssembler.Finding.ParsingError("address value " + addressMagnitude + " invalid", (int)-word.MaxMagnitude, (int)word.MaxMagnitude));
                return(null);
            }

            word.MagnitudeLongValue = addressMagnitude;
            var fieldSpecValue = GetFieldSpecValue(status, mixInstruction);

            if (fieldSpecValue == null)
            {
                return(null);
            }

            var instructionWord = new FullWord
            {
                Sign = mAddress.GetSign(status.LocationCounter)
            };

            for (int i = 0; i < word.ByteCount; i++)
            {
                instructionWord[i] = word[i];
            }

            instructionWord[MixInstruction.IndexByte]     = (int)mIndex.GetValue(status.LocationCounter);
            instructionWord[MixInstruction.FieldSpecByte] = fieldSpecValue;
            instructionWord[MixInstruction.OpcodeByte]    = mixInstruction.Opcode;

            var instance = mixInstruction.CreateInstance(instructionWord);

            ReportInstanceErrors(status, instance);

            return(instance);
        }