示例#1
0
        /**
         * Adds the indicated text record to the Module.
         *
         * @param rec the text record to be added
         *
         * @refcode
         * OB, LM
         * @errtest
         * @errmsg
         *  ES.40, ES.41, ES.42, ES.43
         * @author Mark Mathis
         * @creation May 21, 2011
         * @modlog
         * @teststandard Andrew Buelow
         * @codestandard Mark Mathis
         */
        public void AddRecord(Text 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, 40);
            }

            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, 41);
            }

            rec.Location = address;

            // add the record to the module
            if (textRecords.ContainsKey(rec.Location))
            {
                // error, multiple text records with same location counter value
                throw new Error(ErrCat.Serious, 42);
            }
            else
            {
                if (rec.Flag == 'R')
                {
                    int s = Convert.ToInt32(Convert.ToString(rec.Word, 2).Substring(6), 2);
                    s += this.relocationValue;
                    if (0 <= s && s <= 1023)
                    {
                        rec.Word += this.relocationValue;
                    }
                    else
                    {
                        // Error: Address Field relocation will be out of range of this program
                        // NOP substituted
                        errPrinter.PrintError(ErrCat.Serious, 43);
                        rec.Word = 32768;
                    }
                }
                textRecords.Add(rec.Location, rec);
            }
        }
示例#2
0
        /**
         * Parses a single text record.
         *
         * @param rec the text record to be parsed
         * @param mod the module this text record will be a part of
         *
         * @refcode
         *  OB3
         * @errtest
         * @errmsg
         *  EW.11, EW.12, EW.13, EW.14, ES.16, ES.17, ES.18, ES.19, ES.20, ES.21, ES.22, ES.23
         * @author Mark Mathis
         * @creation May 19, 2011
         * @modlog
         * @teststandard Andrew Buelow
         * @codestandard Mark Mathis
         */
        public void ParseText(string rec, Module mod)
        {
            string[] field = rec.Split(':');
            Text textRecord = new Text();

            // check that the record has the correct number of fields
            if (field.Length != 6)
            {
                // error, wrong number of fields
                throw new Error(ErrCat.Serious, 16);
            }

            // check program assigned location
            string progLoc = field[1].ToUpper();

            // check length, should be 4 digit hex number
            if (progLoc.Length != 4)
            {
                // error, wrong length
                errPrinter.PrintError(ErrCat.Warning, 11);
            }

            //check that it is valid hex
            int progLocVal = 0;
            try
            {
                progLocVal = Convert.ToInt32(progLoc, 16);
            }
            catch (FormatException)
            {
                // error, not valid hex
                errPrinter.PrintError(ErrCat.Serious, 17);
            }

            // check that it is in the correct range
            if (progLocVal < 0 || progLocVal > 1023)
            {
                // error, must be between 0 and 1023
                errPrinter.PrintError(ErrCat.Serious, 18);
            }

            // add program location to the linker text record
            textRecord.Location = progLocVal;

            // check the hex code of the instruction
            string hexCode = field[2].ToUpper();

            // check length, should be 4 digit hex number
            if (hexCode.Length < 4)
            {
                // error, too short
                errPrinter.PrintError(ErrCat.Warning, 12);
            }
            else if (hexCode.Length > 4)
            {
                // error, too long
                errPrinter.PrintError(ErrCat.Serious, 19);
                hexCode = "8000";
            }

            //check that it is valid hex
            int hexCodeVal = 0;
            try
            {
                hexCodeVal = Convert.ToInt32(hexCode, 16);
            }
            catch (FormatException)
            {
                // error, not valid hex
                errPrinter.PrintError(ErrCat.Serious, 20);
                hexCodeVal = Convert.ToInt32("8000", 16);
            }

            // add hex code of instruction to linker text record
            textRecord.Word = hexCodeVal;

            // check address status flag
            string addStatus = field[3].ToUpper();

            // check length of flag, should be 1
            if (addStatus.Length != 1)
            {
                // error wrong length
                errPrinter.PrintError(ErrCat.Serious, 21);
                addStatus = "A";
            }

            // check that the flag is a valid value
            if (!(addStatus[0] == 'A' || addStatus[0] == 'R' || addStatus[0] == 'M'))
            {
                // error, invalid value for status flag
                errPrinter.PrintError(ErrCat.Serious, 21);
                addStatus = "A";
            }

            // add status flag to linker text record
            textRecord.Flag = addStatus[0];

            // check number of M adjustments needed
            string mAdj = field[4].ToUpper();

            // check that it is the correct length, should be 1
            if (mAdj.Length != 1)
            {
                // error wrong length
                errPrinter.PrintError(ErrCat.Warning, 13);
                mAdj = "1";
            }

            // check that it is valid hex
            int mAdjVal = 0;
            try
            {
                mAdjVal = Convert.ToInt32(mAdj, 16);
            }
            catch (FormatException)
            {
                // error, not valid hex
                errPrinter.PrintError(ErrCat.Warning, 14);
                mAdjVal = 1;
            }
            // if it's valid then it should be in the correct range
            // since one hex digit can only be 0-15

            // add number of adjustments to the linker text record
            textRecord.Adjustments = mAdjVal;

            // check the program name
            string prgmName = field[5];

            // check that the program name is in the symbol table
            if (mod.ModuleName != prgmName)
            {
                // error, program name at end of text record must match
                // program name of program being parsed
                throw new Error(ErrCat.Serious, 22);
            }

            if (!symb.ContainsSymbol(prgmName))
            {
                // error, program name is not in symbol table
                throw new Error(ErrCat.Serious, 23);
            }

            mod.AddRecord(textRecord);
        }