public void PrepareAssembly(AssemblyDefinition assembly) { this.assembly = assembly; RegisterExternalTypes(); // Resolve corlib assembly corlib = assembly.MainModule.Import(typeof (void)).Resolve().Module.Assembly; // Prepare LLVM context, module and data layouts context = LLVM.GetGlobalContext(); module = LLVM.ModuleCreateWithName(assembly.Name.Name); // Prepare system types, for easier access InitializeCommonTypes(); // TODO: Choose appropriate triple depending on target LLVM.SetTarget(module, triple); // Initialize ABI abi = new DefaultABI(context, targetData); // Prepare LLVM builders builder = LLVM.CreateBuilderInContext(context); builder2 = LLVM.CreateBuilderInContext(context); builderAlloca = LLVM.CreateBuilderInContext(context); InitializeDebug(); if (!TestMode) { // Register SharpLangModule objects for each module metadataPerModule = new Dictionary<Mono.Cecil.ModuleDefinition, ValueRef>(); var mangledModuleName = Regex.Replace(assembly.Name.Name + ".sharplangmodule", @"(\W)", "_"); var sharpLangModuleGlobal = LLVM.AddGlobal(module, sharpLangModuleType.ObjectTypeLLVM, mangledModuleName); metadataPerModule[assembly.MainModule] = sharpLangModuleGlobal; // Generate extern globals for SharpLangModule instances of other modules foreach (var referencedAssembly in referencedAssemblies) { mangledModuleName = Regex.Replace(referencedAssembly.Name.Name + ".sharplangmodule", @"(\W)", "_"); var externalSharpLangModuleGlobal = LLVM.AddGlobal(module, sharpLangModuleType.ObjectTypeLLVM, mangledModuleName); LLVM.SetLinkage(externalSharpLangModuleGlobal, Linkage.ExternalLinkage); metadataPerModule[referencedAssembly.MainModule] = externalSharpLangModuleGlobal; } } }
public unsafe static DIBuilderRef DIBuilderCreate(ModuleRef M) { DIBuilderRef ret = new DIBuilderRef(LLVMPINVOKE.DIBuilderCreate(M.Value)); return ret; }
public unsafe static bool VerifyModule(ModuleRef M, VerifierFailureAction Action, out string OutMessage) { bool ret = LLVMPINVOKE.VerifyModule(M.Value, (int)Action, out OutMessage); return ret; }
public unsafe static bool TargetMachineEmitToFile(TargetMachineRef T, ModuleRef M, string Filename, CodeGenFileType codegen, out string ErrorMessage) { bool ret = LLVMPINVOKE.TargetMachineEmitToFile(T.Value, M.Value, Filename, (int)codegen, out ErrorMessage); return ret; }
public unsafe static int WriteBitcodeToFileHandle(ModuleRef M, int Handle) { int ret = LLVMPINVOKE.WriteBitcodeToFileHandle(M.Value, Handle); return ret; }
public unsafe static int WriteBitcodeToFile(ModuleRef M, string Path) { int ret = LLVMPINVOKE.WriteBitcodeToFile(M.Value, Path); return ret; }
public unsafe static bool ParseBitcodeInContext(ContextRef ContextRef, MemoryBufferRef MemBuf, out ModuleRef OutModule, out string OutMessage) { bool ret = LLVMPINVOKE.ParseBitcodeInContext(ContextRef.Value, MemBuf.Value, out OutModule.Value, out OutMessage); return ret; }
public unsafe static string GetDataLayout(ModuleRef M) { string ret = LLVMPINVOKE.GetDataLayout(M.Value); return ret; }
/// <summary> /// Creates a <see cref="ModuleReferenceNode"/> /// </summary> /// <param name="modRef">Module reference</param> /// <returns></returns> public ModuleReferenceNode Create(ModuleRef modRef) => Context.DocumentTreeView.Create(modRef);
public static ITextOutput Write(ITextOutput output, ModuleRef r, Language language) { output.Write(CleanUpIdentifier(r.Name), TextTokenType.Text); r.MDToken.WriteSuffixString(output); return(output); }
// For tests internal void AddUnimportableModule(string moduleName) => Modules[moduleName] = new ModuleRef(new SentinelModule(moduleName, _services));
public virtual FileTreeNodeFilterResult GetResult(ModuleRef modRef) { return(new FileTreeNodeFilterResult(FilterType.Hide, false)); }
/// <summary> /// Constructor /// </summary> /// <param name="moduleRef">Module reference</param> protected ModuleReferenceNode(ModuleRef moduleRef) => ModuleRef = moduleRef ?? throw new ArgumentNullException(nameof(moduleRef));
public ModuleReferenceNodeImpl(ITreeNodeGroup treeNodeGroup, ModuleRef moduleRef) : base(moduleRef) => TreeNodeGroup = treeNodeGroup;
public unsafe static ModuleRef ModuleCreateWithName(string ModuleID) { ModuleRef ret = new ModuleRef(LLVMPINVOKE.ModuleCreateWithName(ModuleID)); return ret; }
public unsafe static ValueRef AddGlobal(ModuleRef M, TypeRef Ty, string Name) { ValueRef ret = new ValueRef(LLVMPINVOKE.AddGlobal(M.Value, Ty.Value, Name)); return ret; }
public unsafe static ModuleRef CloneModule(ModuleRef M) { ModuleRef ret = new ModuleRef(LLVMPINVOKE.CloneModule(M.Value)); return ret; }
public unsafe static ValueRef AddGlobalInAddressSpace(ModuleRef M, TypeRef Ty, string Name, uint AddressSpace) { ValueRef ret = new ValueRef(LLVMPINVOKE.AddGlobalInAddressSpace(M.Value, Ty.Value, Name, AddressSpace)); return ret; }
public IModuleReferenceNode Create(ModuleRef modRef) => Context.FileTreeView.Create(modRef);
public unsafe static ValueRef GetFirstGlobal(ModuleRef M) { ValueRef ret = new ValueRef(LLVMPINVOKE.GetFirstGlobal(M.Value)); return ret; }
public unsafe static bool GetBitcodeModule(MemoryBufferRef MemBuf, out ModuleRef OutM, out string OutMessage) { bool ret = LLVMPINVOKE.GetBitcodeModule(MemBuf.Value, out OutM.Value, out OutMessage); return ret; }
public unsafe static void AddNamedMetadataOperand(ModuleRef M, string name, ValueRef Val) { LLVMPINVOKE.AddNamedMetadataOperand(M.Value, name, Val.Value); }
public unsafe static int WriteBitcodeToFD(ModuleRef M, int FD, int ShouldClose, int Unbuffered) { int ret = LLVMPINVOKE.WriteBitcodeToFD(M.Value, FD, ShouldClose, Unbuffered); return ret; }
public unsafe static ValueRef AddFunction(ModuleRef M, string Name, TypeRef FunctionTy) { ValueRef ret = new ValueRef(LLVMPINVOKE.AddFunction(M.Value, Name, FunctionTy.Value)); return ret; }
public unsafe static MemoryBufferRef WriteBitcodeToMemoryBuffer(ModuleRef M) { MemoryBufferRef ret = new MemoryBufferRef(LLVMPINVOKE.WriteBitcodeToMemoryBuffer(M.Value)); return ret; }
public unsafe static ValueRef AddAlias(ModuleRef M, TypeRef Ty, ValueRef Aliasee, string Name) { ValueRef ret = new ValueRef(LLVMPINVOKE.AddAlias(M.Value, Ty.Value, Aliasee.Value, Name)); return ret; }
public unsafe static bool TargetMachineEmitToMemoryBuffer(TargetMachineRef T, ModuleRef M, CodeGenFileType codegen, out string ErrorMessage, out MemoryBufferRef OutMemBuf) { bool ret = LLVMPINVOKE.TargetMachineEmitToMemoryBuffer(T.Value, M.Value, (int)codegen, out ErrorMessage, out OutMemBuf.Value); return ret; }
public unsafe static ValueRef GetNamedFunction(ModuleRef M, string Name) { ValueRef ret = new ValueRef(LLVMPINVOKE.GetNamedFunction(M.Value, Name)); return ret; }
public unsafe static ValueRef IntrinsicGetDeclaration(ModuleRef M, uint ID, TypeRef[] ParamTypes) { fixed (TypeRef* swig_ptrTo_ParamTypes = ParamTypes) { ValueRef ret = new ValueRef(LLVMPINVOKE.IntrinsicGetDeclaration(M.Value, ID, (System.IntPtr)swig_ptrTo_ParamTypes, (uint)ParamTypes.Length)); return ret; } }
public unsafe static ValueRef GetLastFunction(ModuleRef M) { ValueRef ret = new ValueRef(LLVMPINVOKE.GetLastFunction(M.Value)); return ret; }
public unsafe static void AddModuleFlag(ModuleRef M, string name, uint value) { LLVMPINVOKE.AddModuleFlag(M.Value, name, value); }
public unsafe static ModuleProviderRef CreateModuleProviderForExistingModule(ModuleRef M) { ModuleProviderRef ret = new ModuleProviderRef(LLVMPINVOKE.CreateModuleProviderForExistingModule(M.Value)); return ret; }
public unsafe static ModuleRef ModuleCreateWithNameInContext(string ModuleID, ContextRef C) { ModuleRef ret = new ModuleRef(LLVMPINVOKE.ModuleCreateWithNameInContext(ModuleID, C.Value)); return ret; }
public unsafe static PassManagerRef CreateFunctionPassManagerForModule(ModuleRef M) { PassManagerRef ret = new PassManagerRef(LLVMPINVOKE.CreateFunctionPassManagerForModule(M.Value)); return ret; }
public unsafe static void DisposeModule(ModuleRef M) { LLVMPINVOKE.DisposeModule(M.Value); }
public unsafe static bool RunPassManager(PassManagerRef PM, ModuleRef M) { bool ret = LLVMPINVOKE.RunPassManager(PM.Value, M.Value); return ret; }
public unsafe static void SetDataLayout(ModuleRef M, string Triple) { LLVMPINVOKE.SetDataLayout(M.Value, Triple); }
public IModuleReferenceNode Create(ModuleRef modRef) { return(Context.FileTreeView.Create(modRef)); }