コード例 #1
0
        public void DoneObjectNode()
        {
            int pointerSize = _nodeFactory.Target.PointerSize;

            EmitAlignment(_nodeFactory.Target.PointerSize);
            Debug.Assert(_nodeFactory.Target.PointerSize == 4);
            int countOfPointerSizedElements = _currentObjectData.Count / _nodeFactory.Target.PointerSize;

            ISymbolNode symNode = _currentObjectNode as ISymbolNode;

            if (symNode == null)
            {
                symNode = ((IHasStartSymbol)_currentObjectNode).StartSymbol;
            }
            string realName = GetBaseSymbolName(symNode, _nodeFactory.NameMangler, true);

            var intPtrType  = LLVM.PointerType(LLVM.Int32Type(), 0);
            var arrayglobal = LLVM.AddGlobalInAddressSpace(Module, LLVM.ArrayType(intPtrType, (uint)countOfPointerSizedElements), realName, 0);

            LLVM.SetLinkage(arrayglobal, LLVMLinkage.LLVMExternalLinkage);

            _dataToFill.Add(new ObjectNodeDataEmission(arrayglobal, _currentObjectData.ToArray(), _currentObjectSymbolRefs));

            foreach (var symbolIdInfo in _symbolDefs)
            {
                EmitSymbolDef(arrayglobal, symbolIdInfo.Key, symbolIdInfo.Value);
            }

            _currentObjectNode       = null;
            _currentObjectSymbolRefs = new Dictionary <int, SymbolRefData>();
            _currentObjectData       = new ArrayBuilder <byte>();
            _symbolDefs.Clear();
        }
コード例 #2
0
        public static LLVMValueRef GetSymbolValuePointer(LLVMModuleRef module, ISymbolNode symbol, NameMangler nameMangler, bool objectWriterUse = false)
        {
            if (symbol is WebAssemblyMethodCodeNode)
            {
                ThrowHelper.ThrowInvalidProgramException();
            }

            string       symbolAddressGlobalName = symbol.GetMangledName(nameMangler) + "___SYMBOL";
            LLVMValueRef symbolAddress;

            if (s_symbolValues.TryGetValue(symbolAddressGlobalName, out symbolAddress))
            {
                return(symbolAddress);
            }
            var intPtrType = LLVM.PointerType(LLVM.Int32Type(), 0);
            var myGlobal   = LLVM.AddGlobalInAddressSpace(module, intPtrType, symbolAddressGlobalName, 0);

            LLVM.SetGlobalConstant(myGlobal, (LLVMBool)true);
            LLVM.SetLinkage(myGlobal, LLVMLinkage.LLVMInternalLinkage);
            s_symbolValues.Add(symbolAddressGlobalName, myGlobal);
            return(myGlobal);
        }