From c98a1274d9cd80fc4bc3da38cc00230d5839e91b Mon Sep 17 00:00:00 2001 From: Siu Kwan Lam Date: Tue, 5 Feb 2013 18:48:09 -0600 Subject: [PATCH] Add Linker and Assembly (IR) Parser --- newbinding/src/Assembly/Parser.py | 14 ++++++++ newbinding/src/Linker.py | 51 +++++++++++++++++++++++++++++ newbinding/src/Support/SourceMgr.py | 10 ++++++ 3 files changed, 75 insertions(+) create mode 100644 newbinding/src/Assembly/Parser.py create mode 100644 newbinding/src/Linker.py create mode 100644 newbinding/src/Support/SourceMgr.py diff --git a/newbinding/src/Assembly/Parser.py b/newbinding/src/Assembly/Parser.py new file mode 100644 index 0000000..1858bcd --- /dev/null +++ b/newbinding/src/Assembly/Parser.py @@ -0,0 +1,14 @@ +from binding import * +from ..namespace import llvm +from ..Module import Module +from ..LLVMContext import LLVMContext +from ..Support.SourceMgr import SMDiagnostic + +llvm.includes.add('llvm/Assembly/Parser.h') + +ParseAssemblyString = llvm.Function('ParseAssemblyString', + ptr(Module), + cast(str, ConstCharPtr), + ptr(Module), # can be None + ref(SMDiagnostic), + ref(LLVMContext)) diff --git a/newbinding/src/Linker.py b/newbinding/src/Linker.py new file mode 100644 index 0000000..0b846d6 --- /dev/null +++ b/newbinding/src/Linker.py @@ -0,0 +1,51 @@ +from binding import * +from namespace import llvm +from ADT.StringRef import StringRef +from Module import Module +from LLVMContext import LLVMContext + +llvm.includes.add('llvm/Linker.h') + +Linker = llvm.Class() + +@Linker +class Linker: + ControlFlags = Enum('Verbose, QuietWarnings, QuietErrors') + LinkerMode = Enum('DestroySource, PreserveSource') + + _new_w_empty = Constructor(cast(str, StringRef), + cast(str, StringRef), + ref(LLVMContext), + cast(int, Unsigned)).require_only(3) + + _new_w_existing = Constructor(cast(str, StringRef), + ptr(Module), + cast(int, Unsigned)).require_only(2) + + @CustomPythonStaticMethod + def new(progname, module_or_name, *args): + if isinstance(module_or_name, Module): + return _new_w_existing(progname, module_or_name, *args) + else: + return _new_w_empty(progname, module_or_name, *args) + + delete = Destructor() + + getModule = Method(ptr(Module)) + releaseModule = Method(ptr(Module)) + getLastError = Method(cast(ConstStdString, str)) + + LinkInModule = CustomMethod('Linker_LinkInModule', + PyObjectPtr, # boolean + ptr(Module), + PyObjectPtr, # errmsg + ) + + LinkModules = CustomStaticMethod('Linker_LinkModules', + PyObjectPtr, # boolean + ptr(Module), + ptr(Module), + LinkerMode, + PyObjectPtr, # errsg + ) + diff --git a/newbinding/src/Support/SourceMgr.py b/newbinding/src/Support/SourceMgr.py new file mode 100644 index 0000000..7dc75be --- /dev/null +++ b/newbinding/src/Support/SourceMgr.py @@ -0,0 +1,10 @@ +from binding import * +from ..namespace import llvm + +llvm.includes.add('llvm/Support/SourceMgr.h') + +@llvm.Class() +class SMDiagnostic: + new = Constructor() + delete = Destructor() +