DI/Verifier: Fix argument bitrot in DILocalVariable
[oota-llvm.git] / examples / Kaleidoscope / Chapter8 / toy.cpp
index eb16516b6d23c57b87f9bea115dbcfbcaacc906c..72e5089177b7c3f3ddda22f18a129b382dbdf487 100644 (file)
@@ -93,13 +93,13 @@ class ExprAST;
 }
 static IRBuilder<> Builder(getGlobalContext());
 struct DebugInfo {
-  MDCompileUnit *TheCU;
-  MDType *DblTy;
-  std::vector<MDScope *> LexicalBlocks;
-  std::map<const PrototypeAST *, MDScope *> FnScopeMap;
+  DICompileUnit *TheCU;
+  DIType *DblTy;
+  std::vector<DIScope *> LexicalBlocks;
+  std::map<const PrototypeAST *, DIScope *> FnScopeMap;
 
   void emitLocation(ExprAST *AST);
-  MDType *getDoubleTy();
+  DIType *getDoubleTy();
 } KSDbgInfo;
 
 static std::string IdentifierStr; // Filled in if tok_identifier
@@ -816,7 +816,7 @@ static PrototypeAST *ParseExtern() {
 
 static DIBuilder *DBuilder;
 
-MDType *DebugInfo::getDoubleTy() {
+DIType *DebugInfo::getDoubleTy() {
   if (DblTy)
     return DblTy;
 
@@ -827,7 +827,7 @@ MDType *DebugInfo::getDoubleTy() {
 void DebugInfo::emitLocation(ExprAST *AST) {
   if (!AST)
     return Builder.SetCurrentDebugLocation(DebugLoc());
-  MDScope *Scope;
+  DIScope *Scope;
   if (LexicalBlocks.empty())
     Scope = TheCU;
   else
@@ -836,9 +836,9 @@ void DebugInfo::emitLocation(ExprAST *AST) {
       DebugLoc::get(AST->getLine(), AST->getCol(), Scope));
 }
 
-static MDSubroutineType *CreateFunctionType(unsigned NumArgs, MDFile *Unit) {
+static DISubroutineType *CreateFunctionType(unsigned NumArgs, DIFile *Unit) {
   SmallVector<Metadata *, 8> EltTys;
-  MDType *DblTy = KSDbgInfo.getDoubleTy();
+  DIType *DblTy = KSDbgInfo.getDoubleTy();
 
   // Add the result type.
   EltTys.push_back(DblTy);
@@ -908,7 +908,10 @@ Value *BinaryExprAST::Codegen() {
   // Special case '=' because we don't want to emit the LHS as an expression.
   if (Op == '=') {
     // Assignment requires the LHS to be an identifier.
-    VariableExprAST *LHSE = dynamic_cast<VariableExprAST *>(LHS);
+    // This assume we're building without RTTI because LLVM builds that way by
+    // default.  If you build LLVM with RTTI this can be changed to a
+    // dynamic_cast for automatic error checking.
+    VariableExprAST *LHSE = static_cast<VariableExprAST *>(LHS);
     if (!LHSE)
       return ErrorV("destination of '=' must be a variable");
     // Codegen the RHS.
@@ -1224,15 +1227,15 @@ Function *PrototypeAST::Codegen() {
     AI->setName(Args[Idx]);
 
   // Create a subprogram DIE for this function.
-  MDFile *Unit = DBuilder->createFile(KSDbgInfo.TheCU->getFilename(),
+  DIFile *Unit = DBuilder->createFile(KSDbgInfo.TheCU->getFilename(),
                                       KSDbgInfo.TheCU->getDirectory());
-  MDScope *FContext = Unit;
+  DIScope *FContext = Unit;
   unsigned LineNo = Line;
   unsigned ScopeLine = Line;
-  MDSubprogram *SP = DBuilder->createFunction(
+  DISubprogram *SP = DBuilder->createFunction(
       FContext, Name, StringRef(), Unit, LineNo,
       CreateFunctionType(Args.size(), Unit), false /* internal linkage */,
-      true /* definition */, ScopeLine, DebugNode::FlagPrototyped, false, F);
+      true /* definition */, ScopeLine, DINode::FlagPrototyped, false, F);
 
   KSDbgInfo.FnScopeMap[this] = SP;
   return F;
@@ -1247,12 +1250,12 @@ void PrototypeAST::CreateArgumentAllocas(Function *F) {
     AllocaInst *Alloca = CreateEntryBlockAlloca(F, Args[Idx]);
 
     // Create a debug descriptor for the variable.
-    MDScope *Scope = KSDbgInfo.LexicalBlocks.back();
-    MDFile *Unit = DBuilder->createFile(KSDbgInfo.TheCU->getFilename(),
+    DIScope *Scope = KSDbgInfo.LexicalBlocks.back();
+    DIFile *Unit = DBuilder->createFile(KSDbgInfo.TheCU->getFilename(),
                                         KSDbgInfo.TheCU->getDirectory());
-    MDLocalVariable *D = DBuilder->createLocalVariable(
+    DILocalVariable *D = DBuilder->createLocalVariable(
         dwarf::DW_TAG_arg_variable, Scope, Args[Idx], Unit, Line,
-        KSDbgInfo.getDoubleTy(), Idx);
+        KSDbgInfo.getDoubleTy(), true, 0, Idx + 1);
 
     DBuilder->insertDeclare(Alloca, D, DBuilder->createExpression(),
                             DebugLoc::get(Line, 0, Scope),
@@ -1459,7 +1462,7 @@ int main() {
 
   // Set up the optimizer pipeline.  Start with registering info about how the
   // target lays out data structures.
-  TheModule->setDataLayout(*TheExecutionEngine->getDataLayout());
+  TheModule->setDataLayout(TheExecutionEngine->getDataLayout());
 #if 0
   // Provide basic AliasAnalysis support for GVN.
   OurFPM.add(createBasicAliasAnalysisPass());