Skip to content

Instantly share code, notes, and snippets.

@cartazio
Last active August 29, 2015 13:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cartazio/8748569 to your computer and use it in GitHub Desktop.
Save cartazio/8748569 to your computer and use it in GitHub Desktop.
Module {moduleName = "<string>", moduleDataLayout = Just (DataLayout {endianness = Just LittleEndian, stackAlignment = Just 128, pointerLayouts = fromList [(AddrSpace 0,(64,AlignmentInfo {abiAlignment = 64, preferredAlignment = Just 64}))], typeLayouts = fromList [((IntegerAlign,1),AlignmentInfo {abiAlignment = 8, preferredAlignment = Just 8}),((IntegerAlign,8),AlignmentInfo {abiAlignment = 8, preferredAlignment = Just 8}),((IntegerAlign,16),AlignmentInfo {abiAlignment = 16, preferredAlignment = Just 16}),((IntegerAlign,32),AlignmentInfo {abiAlignment = 32, preferredAlignment = Just 32}),((IntegerAlign,64),AlignmentInfo {abiAlignment = 64, preferredAlignment = Just 64}),((VectorAlign,64),AlignmentInfo {abiAlignment = 64, preferredAlignment = Just 64}),((VectorAlign,128),AlignmentInfo {abiAlignment = 128, preferredAlignment = Just 128}),((FloatAlign,32),AlignmentInfo {abiAlignment = 32, preferredAlignment = Just 32}),((FloatAlign,64),AlignmentInfo {abiAlignment = 64, preferredAlignment = Just 64}),((FloatAlign,80),AlignmentInfo {abiAlignment = 128, preferredAlignment = Just 128}),((AggregateAlign,0),AlignmentInfo {abiAlignment = 0, preferredAlignment = Just 64}),((StackAlign,0),AlignmentInfo {abiAlignment = 64, preferredAlignment = Just 64})], nativeSizes = Just (fromList [8,16,32,64])}), moduleTargetTriple = Just "x86_64-apple-macosx10.9.0", moduleDefinitions = [GlobalDefinition (Function {linkage = External, visibility = Default, callingConvention = C, returnAttributes = [], returnType = IntegerType {typeBits = 32}, name = Name "plus", parameters = ([Parameter (IntegerType {typeBits = 32}) (Name "a") [],Parameter (IntegerType {typeBits = 32}) (Name "b") []],False), functionAttributes = [NoUnwind,StackProtect,UWTable], section = Nothing, alignment = 0, garbageCollectorName = Nothing, basicBlocks = [BasicBlock (UnName 0) [UnName 1 := Alloca {allocatedType = IntegerType {typeBits = 32}, numElements = Nothing, alignment = 4, metadata = []},UnName 2 := Alloca {allocatedType = IntegerType {typeBits = 32}, numElements = Nothing, alignment = 4, metadata = []},Do (Store {volatile = False, address = LocalReference (UnName 1), value = LocalReference (Name "a"), maybeAtomicity = Nothing, alignment = 4, metadata = []}),Do (Store {volatile = False, address = LocalReference (UnName 2), value = LocalReference (Name "b"), maybeAtomicity = Nothing, alignment = 4, metadata = []}),UnName 3 := Load {volatile = False, address = LocalReference (UnName 1), maybeAtomicity = Nothing, alignment = 4, metadata = []},UnName 4 := Load {volatile = False, address = LocalReference (UnName 2), maybeAtomicity = Nothing, alignment = 4, metadata = []},UnName 5 := Add {nsw = True, nuw = False, operand0 = LocalReference (UnName 3), operand1 = LocalReference (UnName 4), metadata = []}] (Do (Ret {returnOperand = Just (LocalReference (UnName 5)), metadata' = []}))]})]}
"; ModuleID = 'test.c'\ntarget datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-apple-macosx10.9.0\"\n\ndefine i32 @plus(i32 %a, i32 %b) nounwind ssp uwtable {\n %1 = alloca i32, align 4\n %2 = alloca i32, align 4\n store i32 %a, i32* %1, align 4\n store i32 %b, i32* %2, align 4\n %3 = load i32* %1, align 4\n %4 = load i32* %2, align 4\n %5 = add nsw i32 %3, %4\n ret i32 %5\n}\n"
int plus(int a, int b) ;
int plus(int a, int b){
return a + b ;
}
import LLVM.General
import LLVM.General.Context
import Control.Monad.Error
parseStringLLVM str = do
res <- withContext (\x -> do
(Right modAST) <- runErrorT $ withModuleFromString x str moduleAST
return modAST
)
return res
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment