From 1c59af0bf4fbd699aafd71082e6ba6d373b59c23 Mon Sep 17 00:00:00 2001 From: David Terei Date: Wed, 14 Jul 2010 15:25:30 +0000 Subject: [PATCH] LLVM: Add inline assembly to binding. --- compiler/llvmGen/Llvm/AbsSyn.hs | 13 +++++++++++++ compiler/llvmGen/Llvm/PpLlvm.hs | 13 +++++++++++++ 2 files changed, 26 insertions(+) diff --git a/compiler/llvmGen/Llvm/AbsSyn.hs b/compiler/llvmGen/Llvm/AbsSyn.hs index 08d27d7..e25f5be 100644 --- a/compiler/llvmGen/Llvm/AbsSyn.hs +++ b/compiler/llvmGen/Llvm/AbsSyn.hs @@ -210,5 +210,18 @@ data LlvmExpression -} | Phi LlvmType [(LlvmVar,LlvmVar)] + {- | + Inline assembly expression. Syntax is very similar to the style used by GCC. + * assembly: Actual inline assembly code. + * contraints: Operand constraints. + * return ty: Return type of function. + * vars: Any variables involved in the assembly code. + * sideeffect: Does the expression have side effects not visible from the + constraints list. + * alignstack: Should the stack be conservatively aligned before this + expression is executed. + -} + | Asm LMString LMString LlvmType [LlvmVar] Bool Bool + deriving (Show, Eq) diff --git a/compiler/llvmGen/Llvm/PpLlvm.hs b/compiler/llvmGen/Llvm/PpLlvm.hs index b3e2d98..1a972e7 100644 --- a/compiler/llvmGen/Llvm/PpLlvm.hs +++ b/compiler/llvmGen/Llvm/PpLlvm.hs @@ -176,6 +176,7 @@ ppLlvmExpression expr Load ptr -> ppLoad ptr Malloc tp amount -> ppMalloc tp amount Phi tp precessors -> ppPhi tp precessors + Asm asm c ty v se sk -> ppAsm asm c ty v se sk -------------------------------------------------------------------------------- @@ -299,6 +300,18 @@ ppSwitch scrut dflt targets = <+> ppTargets targets +ppAsm :: LMString -> LMString -> LlvmType -> [LlvmVar] -> Bool -> Bool -> Doc +ppAsm asm constraints rty vars sideeffect alignstack = + let asm' = doubleQuotes $ ftext asm + cons = doubleQuotes $ ftext constraints + rty' = texts rty + vars' = lparen <+> ppCommaJoin vars <+> rparen + side = if sideeffect then text "sideeffect" else empty + align = if alignstack then text "alignstack" else empty + in text "call" <+> rty' <+> text "asm" <+> side <+> align <+> asm' <> comma + <+> cons <> vars' + + -------------------------------------------------------------------------------- -- * Misc functions -------------------------------------------------------------------------------- -- 1.7.10.4