Beispiel #1
0
        /**
         * Adds the indicated modify record to the Module.
         *
         * @param rec the modify record to be added
         *
         * @refcode
         * OB, LM
         * @errtest
         * @errmsg
         *  ES.47, ES.48, ES.49
         * @author Mark Mathis
         * @creation May 21, 2011
         * @modlog
         * @teststandard Andrew Buelow
         * @codestandard Mark Mathis
         */
        public void AddRecord(Modify rec)
        {
            // relocate the address as we add it
            int address = rec.Location;
            address += RelocateValue;

            if (!(0 <= address && address <= 1023))
            {
                // error, address will be relocated out of the range of memory
                throw new Error(ErrCat.Serious, 47);
            }

            if (address < HeaderRecord.LinkerLoadAddress ||
                address > HeaderRecord.LinkerLoadAddress + HeaderRecord.ModuleLength)
            {
                // error, address will be relocated out of the range of the module
                throw new Error(ErrCat.Serious, 48);
            }

            rec.Location = address;

            // add the record to the module
            if (modifyRecords.ContainsKey(rec.Location))
            {
                // error, multiple modify records with same location counter value
                throw new Error(ErrCat.Serious, 49);
            }
            else
            {
                modifyRecords.Add(rec.Location, rec);
            }
        }
Beispiel #2
0
        /**
         * Parses a single modify record.
         *
         * @param rec the modify record to be parsed
         * @param mod the module this text record will be a part of
         *
         * @refcode
         *  OB4
         * @errtest
         * @errmsg
         *  EW.15, EW.16, EW.17, ES.24, ES.25, ES.26, ES.27, ES.28, ES.29, ES.30, ES.31, ES.32
         * @author Mark Mathis
         * @creation May 19, 2011
         * @modlog
         * @teststandard Andrew Buelow
         * @codestandard Mark Mathis
         */
        public void ParseModify(string rec, Module mod)
        {
            string[] field = rec.Split(':');
            Modify modRecord = new Modify();

            // check the location
            string loc = field[1];

            // check the length of the location
            if (loc.Length != 4)
            {
                // error, incorrect length
                errPrinter.PrintError(ErrCat.Warning, 15);
            }

            // check that it is a valid hex string
            int locVal = 0;
            try
            {
                locVal = Convert.ToInt32(loc, 16);
            }
            catch (FormatException)
            {
                // error, not valid hex
                throw new Error(ErrCat.Serious, 24);
            }

            // check that the location value is in the proper range
            if (locVal < 0 || locVal > 1023)
            {
                // error, location invalid
                throw new Error(ErrCat.Serious, 25);
            }

            // add  location to the linker modification record
            modRecord.Location = locVal;

            // check the hex code of the word
            string hex = field[2];

            // check the length of the hex code
            if (hex.Length < 4)
            {
                // error, too short
                errPrinter.PrintError(ErrCat.Warning, 16);
            }
            else if (hex.Length > 4)
            {
                // error, too long
                throw new Error(ErrCat.Serious, 26);
            }

            // check that it is a valid hex string
            int hexVal = 0;
            try
            {
                hexVal = Convert.ToInt32(hex, 16);
            }
            catch (FormatException)
            {
                // error, not valid hex
                throw new Error(ErrCat.Serious, 27);
            }

            // add the hex code of the word to be modified to the linker modification record
            modRecord.Word = hexVal;

            /* Regular expression used to determine if all characters in the token are
             * letters or numbers. */
            Regex alphaNumeric = new Regex(@"[^0-9a-zA-Z]");

            // go through the modifications and make sure they are formatted correctly
            string sign = field[3];

            // check that sign is a + or -
            if (!(sign == "+" || sign == "-"))
            {
                // error, sign must be a + or -
                throw new Error(ErrCat.Serious, 28);
            }

            int i = 4;
            while (sign == "+" || sign == "-")
            {
                string label = field[i++];

                // check that label is valid label
                if (2 <= label.Length && label.Length <= 32)
                {
                    if (!(!alphaNumeric.IsMatch(label) && char.IsLetter(label[0])))
                    {
                        // label is not a valid label
                        errPrinter.PrintError(ErrCat.Serious, 29);
                    }
                }
                else
                {
                    // label is not the right length
                    errPrinter.PrintError(ErrCat.Serious, 29);
                }

                // add adjustments to the linker modification record
                modRecord.AddAdjustments(sign, label);

                // get next sign
                try
                {
                    sign = field[i++];
                }
                catch (IndexOutOfRangeException)
                {
                    throw new Error(ErrCat.Serious, 32);
                }
            }
            // reached end of modification record, or there was an error
            // in the format of modifications

            // check that label is valid label
            if (2 <= sign.Length && sign.Length <= 32)
            {
                if (!(!alphaNumeric.IsMatch(sign) && char.IsLetter(sign[0])))
                {
                    // label is not a valid label
                    errPrinter.PrintError(ErrCat.Serious, 29);
                }
            }
            else
            {
                // label is not the right length
                errPrinter.PrintError(ErrCat.Serious, 29);
            }

            // check if the label is in the symbol table
            // if it is, it's probably not an error
            // if it isn't, it could be an error: say something about it
            if (mod.ModuleName != sign)
            {
                // error, program name at the end of modification record must match
                // program name of program being parsed
                throw new Error(ErrCat.Serious, 30);
            }

            if (!symb.ContainsSymbol(sign))
            {
                // error, something isn't in the symbol table
                throw new Error(ErrCat.Serious, 31);
            }

            //check to see that the modify record doesn't have too many adjustments
            if (modRecord.Adjustments.Count > 15)
            {
                // error, can only have 15 adjustments in a modify record
                errPrinter.PrintError(ErrCat.Warning, 17);
            }

            // add modification record to module
            mod.AddRecord(modRecord);
        }