コード例 #1
0
ファイル: Symbols.cs プロジェクト: ZiCog/HomeSpun
        public static GlobalSymbolInfo Add(SimpleToken token, ObjectFileSymbolTable objectFileSymbolTable)
        {
            // New global symbols are added to the global symbol table and to globalList (at the end).
            // Existing global symbols are moved to the end of globalList. This is done to duplicate
            // PropTool's behavior. Why PropTool does what it does I have no idea.
            // 7/24 Finally realized why: when the objects are laid out in this order, all
            // the inter-object offsets are positive.

            GlobalSymbolInfo gsi = GlobalSymbolTable.Lookup(token);
            if (gsi == null)
            {
                gsi = new GlobalSymbolInfo(token, objectFileSymbolTable);
                globalSymbolTable.AddSymbolInfo(gsi);
                globalList.Add(gsi);
            }
            else
            {
                if (!gsi.AlreadyRead)
                    throw new ParseException("Circular object reference", token);
                for (int i = 0; i < globalList.Count; ++i)
                {
                    if (globalList[i] == gsi)
                    {
                        globalList.RemoveAt(i);
                        globalList.Add(gsi);
                        break;
                    }
                }
            }
            return gsi;
        }
コード例 #2
0
ファイル: Symbols.cs プロジェクト: ZiCog/HomeSpun
        public bool CompareSymbolTable(ObjectFileSymbolTable otherSymbolTable)
        {
            ArrayList msiList0 = new ArrayList();
            ArrayList msiList1 = new ArrayList();
            foreach (MethodSymbolInfo msi in pubList)
                msiList0.Add(msi);
            foreach (MethodSymbolInfo msi in priList)
                msiList0.Add(msi);
            foreach (MethodSymbolInfo msi in otherSymbolTable.pubList)
                msiList1.Add(msi);
            foreach (MethodSymbolInfo msi in otherSymbolTable.priList)
                msiList1.Add(msi);
            if (msiList0.Count != msiList1.Count)
                return false;

            for (int i = 0; i < msiList0.Count; ++i)
            {
                MethodSymbolInfo msi0 = (MethodSymbolInfo)msiList0[i];
                MethodSymbolInfo msi1 = (MethodSymbolInfo)msiList1[i];
                if (msi0.Offset != msi1.Offset)
                    return false;
                if (msi0.LocalsSize != msi1.LocalsSize)
                    return false;
                if (msi0.SizeInBytes != msi1.SizeInBytes)
                    return false;
                byte[] bytes0 = new byte[msi0.SizeInBytes];
                byte[] bytes1 = new byte[msi1.SizeInBytes];
                msi0.ToMemory(bytes0, 0);
                msi1.ToMemory(bytes1, 0);
                for (int j = 0; j < bytes0.Length; ++j)
                    if (bytes0[j] != bytes1[j])
                        return false;
            }

            ArrayList varOffsetList0 = new ArrayList();
            ArrayList includedObjectList0 = new ArrayList();
            ArrayList varOffsetList1 = new ArrayList();
            ArrayList includedObjectList1 = new ArrayList();

            int varOffset = varSize;
            foreach (ObjSymbolInfo osi in objList)
            {
                for (int i = 0; i < osi.Count; ++i)
                {
                    GlobalSymbolInfo gsi = GlobalSymbolTable.Lookup(osi.FilenameToken);
                    GlobalSymbolInfo p = gsi.ForwardLink == null ? gsi : gsi.ForwardLink;
                    includedObjectList0.Add(p);
                    varOffsetList0.Add(varOffset);
                    varOffset += gsi.SymbolTable.TotalVarSize();
                }
            }

            varOffset = varSize;
            foreach (ObjSymbolInfo osi in otherSymbolTable.objList)
            {
                for (int i = 0; i < osi.Count; ++i)
                {
                    GlobalSymbolInfo gsi = GlobalSymbolTable.Lookup(osi.FilenameToken);
                    GlobalSymbolInfo p = gsi.ForwardLink == null ? gsi : gsi.ForwardLink;
                    includedObjectList1.Add(p);
                    varOffsetList1.Add(varOffset);
                    varOffset += gsi.SymbolTable.TotalVarSize();
                }
            }

            if (varOffsetList0.Count != varOffsetList1.Count)
            {
                Console.WriteLine("different # of objs: {0} <> {1}", varOffsetList0.Count, varOffsetList1.Count); ; ;
                return false;
            }

            for (int i = 0; i < includedObjectList0.Count; ++i)
            {
                //Console.WriteLine( "here we go" );;;
                //Console.WriteLine( "::: {0} ::: {1}", (includedObjectList0[i] as GlobalSymbolInfo).IdToken.Text,
                //				 (includedObjectList1[i] as GlobalSymbolInfo).IdToken.Text );;;
                if (includedObjectList0[i] != includedObjectList1[i])
                {
                    //					Console.WriteLine( "different objs: {0} <> {1}", (includedObjectList0[i] as GlobalSymbolInfo).IdToken.Text,
                    //											 (includedObjectList1[i] as GlobalSymbolInfo).IdToken.Text );;;
                    return false;
                }
            }

            for (int i = 0; i < varOffsetList0.Count; ++i)
            {
                if ((int)varOffsetList0[i] != (int)varOffsetList1[i])
                {
                    //Console.WriteLine( "**** UNEXPECTED **** different offsets: {0} <> {1}", (int)varOffsetList0[i], (int)varOffsetList1[i] );
                    return false;
                }
            }

            // Compare DAT bytes.
            if (this.datBytes.Length != otherSymbolTable.datBytes.Length)
                return false;
            for (int i = 0; i < this.datBytes.Length; ++i)
                if (this.datBytes[i] != otherSymbolTable.datBytes[i])
                    return false;

            return true;
        }
コード例 #3
0
ファイル: Symbols.cs プロジェクト: ZiCog/HomeSpun
 public GlobalSymbolInfo(SimpleToken idToken, ObjectFileSymbolTable symbolTable)
     : base(idToken)
 {
     this.symbolTable = symbolTable;
 }
コード例 #4
0
ファイル: Cstokenizer.cs プロジェクト: ZiCog/HomeSpun
        public Tokenizer(SimpleToken filenameToken, Hashtable inheritedDefines)
        {
            this.filenameToken = filenameToken;
            filename = filenameToken.Text;
            path = Options.TryPaths(filenameToken);

            symbolTable = new ObjectFileSymbolTable(this);
            foreach (DictionaryEntry de in inheritedDefines)
            {
                defines.Add(de.Key, de.Value);
            }
        }