예제 #1
0
        public Value CreateAttributeSingleton(AttributeType type)
        {
            if (type.Members.Count != 0)
            {
                throw new CompilerBugException();
            }

            var name = "singleton_" + type.GetMangledName();
            var attr = LlvmModule.GetNamedGlobal(name);

            if (attr != null)
            {
                goto Ret;
            }

            attr             = LlvmModule.AddGlobal(type, name);
            attr.Initializer = LLVMValueRef.CreateConstNamedStruct(type, ReadOnlySpan <LLVMValueRef> .Empty);

Ret:
            return(new Value
            {
                Type = type,
                LlvmValue = attr,
            });
        }
예제 #2
0
        private LLVMSymbolTable ProcessGlobals(LLVMModuleRef mod, LLVMExecutionEngineRef engine,
                                               Dictionary <string, GCHandle> globals)
        {
            var res = new LLVMSymbolTable(null);

            foreach (var kv in globals)
            {
                var gs = mod.AddGlobal(LLVMTypeRef.Int32, kv.Key);
                engine.AddGlobalMapping(gs, kv.Value.AddrOfPinnedObject());
                res.Add(kv.Key, gs);
            }

            return(res);
        }
예제 #3
0
        public void AlignmentTest()
        {
            LLVMModuleRef m = LLVMModuleRef.CreateWithName("netscripten");

            m.Target     = "wasm32-unknown-unknown-wasm";
            m.DataLayout = "e-m:e-p:32:32-i64:64-n32:64-S128";
            LLVMExecutionEngineRef engineRef  = m.CreateExecutionEngine();
            LLVMTargetDataRef      target     = engineRef.TargetData;
            LLVMTypeRef            testStruct = LLVMTypeRef.CreateStruct(
                new[]
            {
                LLVMTypeRef.Int16,
                LLVMTypeRef.Int32
            }, true);

            Assert.AreEqual(1, target.ABIAlignmentOfType(testStruct));
            Assert.AreEqual(1, target.CallFrameAlignmentOfType(testStruct));
            Assert.AreEqual(8, target.PreferredAlignmentOfType(testStruct));

            LLVMValueRef global = m.AddGlobal(LLVMTypeRef.CreatePointer(LLVMTypeRef.Int8, 0), "someGlobal");

            Assert.AreEqual(4, target.PreferredAlignmentOfGlobal(global));
        }