<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:#0563C1;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:#954F72;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Calibri","sans-serif";
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri","sans-serif";}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="#0563C1" vlink="#954F72">
<div class="WordSection1">
<p class="MsoNormal">Hello All,<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I am having a bit of trouble with inserting a function into some IR. My function takes in more than five arguments so I am trying to use the CreateCall(Value * Callee, ArrayRef<Value*> Args, const Twine & Name=””) method.<o:p></o:p></p>
<p class="MsoNormal">I believe where I am running into problems is the declaration part where I am using the getOrInsertFunction() method. Here is the code I have written so far:<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal" style="margin-left:2.5in;text-indent:.5in">//Function declaration for "mmap"<o:p></o:p></p>
<p class="MsoNormal">                                                                                                /*<o:p></o:p></p>
<p class="MsoNormal">                                                                                                Constant *b = M->getOrInsertFunction("mmap",<o:p></o:p></p>
<p class="MsoNormal">                                                                                                                FunctionType::getInt8PtrTy(F.getContext()),<o:p></o:p></p>
<p class="MsoNormal">                                                                                                                Type::getInt8PtrTy(F.getContext()),<o:p></o:p></p>
<p class="MsoNormal">                                                                                                                Type::getInt8PtrTy(F.getContext()),<o:p></o:p></p>
<p class="MsoNormal">                                                                                                                NULL);<o:p></o:p></p>
<p class="MsoNormal">                                                                                                Function *mmap = cast<Function>(b);<o:p></o:p></p>
<p class="MsoNormal">                                                                                                */<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">                                                                                                Constant *b = M->getOrInsertFunction("mmap",<o:p></o:p></p>
<p class="MsoNormal">                                                                                                                FunctionType::getInt8PtrTy(F.getContext()),<o:p></o:p></p>
<p class="MsoNormal">                                                                                                                Type::getInt8PtrTy(F.getContext()),<o:p></o:p></p>
<p class="MsoNormal">                                                                                                                Type::getInt32Ty(F.getContext()),<o:p></o:p></p>
<p class="MsoNormal">                                                                                                                Type::getInt32Ty(F.getContext()),<o:p></o:p></p>
<p class="MsoNormal">                                                                                                                Type::getInt32Ty(F.getContext()),<o:p></o:p></p>
<p class="MsoNormal">                                                                                                                Type::getInt32Ty(F.getContext()),<o:p></o:p></p>
<p class="MsoNormal">                                                                                                                Type::getInt32Ty(F.getContext()),<o:p></o:p></p>
<p class="MsoNormal">                                                                                                                NULL);<o:p></o:p></p>
<p class="MsoNormal">                                                                                                Function *mmap = cast<Function>(b);<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">                                                                                               
<o:p></o:p></p>
<p class="MsoNormal">                                                                                                //IRBuilder responsible for inserting instructions into IR<o:p></o:p></p>
<p class="MsoNormal">                                                                                                IRBuilder<> builder(inst);<o:p></o:p></p>
<p class="MsoNormal">                                                                                                                //Inserts the two variables and call for "open"<o:p></o:p></p>
<p class="MsoNormal">                                                                                                Value *strPtr = builder.CreateGlobalStringPtr("/dev/mem", ".str");<o:p></o:p></p>
<p class="MsoNormal">                                                                                                ConstantInt *open_Argument = builder.getInt32(9437184);<o:p></o:p></p>
<p class="MsoNormal">                                                                                                Value *file_desc = builder.CreateCall2(open,strPtr,open_Argument);<o:p></o:p></p>
<p class="MsoNormal">                                                                                                               
<o:p></o:p></p>
<p class="MsoNormal">                                                                                                                //Inserts the 5 variables needed for "mmap"<o:p></o:p></p>
<p class="MsoNormal">                                                                                                ConstantInt *Arg1 = builder.getInt32(0);<o:p></o:p></p>
<p class="MsoNormal">                                                                                                ConstantInt *Arg2 = builder.getInt32(4096);<o:p></o:p></p>
<p class="MsoNormal">                                                                                                ConstantInt *Arg3 = builder.getInt32(3);<o:p></o:p></p>
<p class="MsoNormal">                                                                                                ConstantInt *Arg4 = builder.getInt32(1);<o:p></o:p></p>
<p class="MsoNormal">                                                                                                ConstantInt *Arg6 = builder.getInt32(1);<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">                                                                                                                //Creates array of values to pass to "mmap"<o:p></o:p></p>
<p class="MsoNormal">                                                                                                std::vector<llvm::Value *> putsArgs;<o:p></o:p></p>
<p class="MsoNormal">                                                                                                putsArgs.push_back(Arg1);<o:p></o:p></p>
<p class="MsoNormal">                                                                                                putsArgs.push_back(Arg2);<o:p></o:p></p>
<p class="MsoNormal">                                                                                                putsArgs.push_back(Arg3);<o:p></o:p></p>
<p class="MsoNormal">                                                                                                putsArgs.push_back(Arg4);<o:p></o:p></p>
<p class="MsoNormal">                                                                                                putsArgs.push_back(file_desc);<o:p></o:p></p>
<p class="MsoNormal">                                                                                                putsArgs.push_back(Arg6);<o:p></o:p></p>
<p class="MsoNormal">                                                                                                llvm::ArrayRef<llvm::Value *> argsRef(putsArgs);<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">                                                                                                builder.CreateCall(mmap, putsArgs, "mmap");<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I have written two function declarations, but am unsure of which type I should use because I am passing an array as an argument. Is the function declaration supposed to accept each argument individually or will it be expecting a pointer
 type if I’m using an array? My assert error is just “Calling a function with a bad signature!”<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Thanks for any help!<o:p></o:p></p>
<p class="MsoNormal">Josh<o:p></o:p></p>
</div>
<div style="font-size:8pt;  font-family: 'Calibri',sans-serif;"><br>
<br>
<br>
<hr>
This message and all attachments are PRIVATE, and contain information that is PROPRIETARY to Intelligent Automation, Inc. You are not authorized to transmit or otherwise disclose this message or any attachments to any third party whatsoever without the express
 written consent of Intelligent Automation, Inc. If you received this message in error or you are not willing to view this message or any attachments on a confidential basis, please immediately delete this email and any attachments and notify Intelligent Automation,
 Inc. </div>
</body>
</html>