internal WebAssemblyCodegenCompilation(
            DependencyAnalyzerBase <NodeFactory> dependencyGraph,
            WebAssemblyCodegenNodeFactory nodeFactory,
            IEnumerable <ICompilationRootProvider> roots,
            ILProvider ilProvider,
            DebugInformationProvider debugInformationProvider,
            Logger logger,
            WebAssemblyCodegenConfigProvider options)
            : base(dependencyGraph, nodeFactory, GetCompilationRoots(roots, nodeFactory), ilProvider, debugInformationProvider, null, logger)
        {
            NodeFactory = nodeFactory;
            LLVMModuleRef m = LLVMModuleRef.CreateWithName("netscripten");

            m.Target = "wasm32-unknown-emscripten";
            // https://llvm.org/docs/LangRef.html#langref-datalayout
            // e litte endian, mangled names
            // m:e ELF mangling
            // p:32:32 pointer size 32, abi 32
            // i64:64 64 ints aligned 64
            // n:32:64 native widths
            // S128 natural alignment of stack
            m.DataLayout     = "e-m:e-p:32:32-i64:64-n32:64-S128";
            Module           = m;
            TargetData       = m.CreateExecutionEngine().TargetData;
            Options          = options;
            DIBuilder        = Module.CreateDIBuilder();
            DebugMetadataMap = new Dictionary <string, DebugMetadata>();
        }
Exemple #2
0
        public void SizeTest()
        {
            LLVMModuleRef          m          = LLVMModuleRef.CreateWithName("netscripten");
            LLVMExecutionEngineRef engineRef  = m.CreateExecutionEngine();
            LLVMTargetDataRef      target     = engineRef.TargetData;
            LLVMTypeRef            testStruct = LLVMTypeRef.CreateStruct(
                new[]
            {
                LLVMTypeRef.Int16,
                LLVMTypeRef.Int32
            }, true);

            Assert.AreEqual(48, target.SizeOfTypeInBits(testStruct));
            Assert.AreEqual(6, target.StoreSizeOfType(testStruct));
            Assert.AreEqual(6, target.ABISizeOfType(testStruct));
        }
Exemple #3
0
        public void OffsetTest()
        {
            LLVMModuleRef          m          = LLVMModuleRef.CreateWithName("netscripten");
            LLVMExecutionEngineRef engineRef  = m.CreateExecutionEngine();
            LLVMTargetDataRef      target     = engineRef.TargetData;
            LLVMTypeRef            testStruct = LLVMTypeRef.CreateStruct(
                new[]
            {
                LLVMTypeRef.Int16,
                LLVMTypeRef.Int32
            }, true);

            Assert.AreEqual(0, target.OffsetOfElement(testStruct, 0));
            Assert.AreEqual(2, target.OffsetOfElement(testStruct, 1));

            Assert.AreEqual(target.ElementAtOffset(testStruct, 0), 0);
            Assert.AreEqual(target.ElementAtOffset(testStruct, 2), 1);
        }
Exemple #4
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));
        }