Beispiel #1
0
    int check_variable(ast::Variable* var) {
        assert(var != nullptr);

        auto ptr = variables.find(var->identifier);
        assert_existing_variable(ptr, var->identifier, var->id);
        auto expected = ptr->getValue().type;
        return check_coercion(var->type, expected, var->identifier, var->id);
    }
Beispiel #2
0
 int check_assignment(ast::Assignment* assignment) {
     assert(assignment != nullptr);
     auto ptr = variables.find(assignment->identifier);
     assert_existing_variable(ptr, assignment->identifier, assignment->id);
     auto val = assignment->value.get();
     check_operation(val);
     return check_coercion(val->type, ptr->getValue().type, "assignment", assignment->id);
 }
Beispiel #3
0
 bool operator()(const Multilib &M) const override {
   for (StringRef Flag : M.flags()) {
     llvm::StringMap<bool>::const_iterator SI = FlagSet.find(Flag.substr(1));
     if (SI != FlagSet.end())
       if (SI->getValue() != isFlagEnabled(Flag))
         return true;
   }
   return false;
 }
 // Register a directive at the specified marker.
 void addDirective(StringRef MarkerName, const UnattachedDirective &UD) {
   auto MarkerIt = Markers.find(MarkerName);
   if (MarkerIt != Markers.end()) {
     Marker &M = MarkerIt->second;
     if (M.UseLoc.isInvalid())
       M.UseLoc = UD.DirectivePos;
     return attachDirective(Diags, UD, M.DefLoc);
   }
   DeferredDirectives[MarkerName].push_back(UD);
 }
Beispiel #5
0
static void rename(llvm::StringMap<cl::Option *> &map, const char *from,
                   const char *to) {
  auto i = map.find(from);
  if (i != map.end()) {
    cl::Option *opt = i->getValue();
    map.erase(i);
    opt->setArgStr(to);
    map[to] = opt;
  }
}
Beispiel #6
0
 int declare_variable(ast::Variable& it) {
     if(variables.find(it.identifier) != variables.end()) {
         std::cout << "Variable shadowing of "
                   << it.identifier;
         print_id(it.id);
         std::cout << std::endl;
     }
     variables.insert(std::pair<llvm::StringRef, ast::Variable>(it.identifier,
                      it));
     return EXIT_SUCCESS;
 }
void CGObjCJit::GenerateClass(const ObjCImplementationDecl *ClassDecl) {
  if (isUsable) {
    const char* ClassName = ClassDecl->getIdentifier()->getNameStart();

    void* Superclass = 0;
    ObjCInterfaceDecl *superClassDecl =
      ClassDecl->getClassInterface()->getSuperClass();

    if (superClassDecl) {
      const char* superClassName =
          superClassDecl->getIdentifier()->getNameStart();
      Superclass = _objc_getClass(superClassName);
    }

    void *theClass =
      _objc_allocateClassPair(Superclass, ClassName, 0); // TODO: always zero?

    // Add methods
    AddMethodsToClass(theClass);

    // Add interface ivars
    const ObjCInterfaceDecl *classInterfaceDecl = ClassDecl->getClassInterface();
    AddIvarsToClass(theClass,
                    classInterfaceDecl->ivar_begin(),
                    classInterfaceDecl->ivar_end());

    // Add implementation ivars
    AddIvarsToClass(theClass,
                    ClassDecl->ivar_begin(),
                    ClassDecl->ivar_end());

    // Add protocols
    ObjCInterfaceDecl::protocol_iterator protocol =
      classInterfaceDecl->protocol_begin();
    const ObjCInterfaceDecl::protocol_iterator protocol_end =
      classInterfaceDecl->protocol_end();
    while (protocol != protocol_end) {
      void *theProtocol = 0;
      // Search "locally" first, then from runtime
      llvm::StringMap<void*>::iterator proto_local =
        DefinedProtocols.find((*protocol)->getName());
      if (proto_local != DefinedProtocols.end()) {
        theProtocol = proto_local->second;
      } else {
        theProtocol = _objc_getProtocol((*protocol)->getNameAsString().c_str());
      }
      _class_addProtocol(theClass, theProtocol);
      protocol++;
    }

    // Finalize class (adding methods later, at runtime, in init function)
    _objc_registerClassPair(theClass);
  }
}
Beispiel #8
0
 int declare_extern(ast::Extern* extrn) {
     assert(extrn != nullptr);
     if(functions.find(extrn->identifier) != functions.end()) {
         std::cout << "Double declaration of "
                   << extrn->identifier;
         print_id(extrn->id);
         std::cout << std::endl;
     }
     functions.insert(std::pair<llvm::StringRef, ast::Extern>(extrn->identifier,
                      *extrn));
     return EXIT_SUCCESS;
 }
static void
callHandler(const llvm::StringMap<std::unique_ptr<Handler>> &Handlers,
            llvm::yaml::ScalarNode *Method, llvm::yaml::ScalarNode *Id,
            llvm::yaml::MappingNode *Params, Handler *UnknownHandler) {
  llvm::SmallString<10> MethodStorage;
  auto I = Handlers.find(Method->getValue(MethodStorage));
  auto *Handler = I != Handlers.end() ? I->second.get() : UnknownHandler;
  if (Id)
    Handler->handleMethod(Params, Id->getRawValue());
  else
    Handler->handleNotification(Params);
}
Beispiel #10
0
void incrementCount(ObjectPtr obj) {
    string buf;
    llvm::raw_string_ostream sout(buf);
    sout << obj;
    string s = sout.str();
    llvm::StringMap<int>::iterator i = countsMap.find(s);
    if (i == countsMap.end()) {
        countsMap[s] = 1;
    }
    else {
        i->second += 1;
    }
}
Beispiel #11
0
    int check_call(ast::Call* call) {
        assert(call != nullptr);

        auto func = functions.find(call->function_name);
        if(func == functions.end()) {
            std::cout << "Unknown function "
                      << call->function_name
                      << " at "
                      << call->id
                      << std::endl;
            return EXIT_FAILURE;
        }
        auto fun = func->getValue();
        auto actual_argument_size = call->arguments.size();
        auto prototype_argument_size = fun.arguments.size();
        if(actual_argument_size < prototype_argument_size) {
            std::cout << "Not enough arguments to "
                      << fun.identifier
                      << " (expected "
                      << prototype_argument_size
                      << ", got "
                      << actual_argument_size
                      << ")"
                      << std::endl;
            return EXIT_FAILURE;
        }
        if(actual_argument_size > prototype_argument_size && !fun.variadic) {
            std::cout << "Too many arguments to "
                      << fun.identifier
                      << " (expected "
                      << prototype_argument_size
                      << ", got "
                      << actual_argument_size
                      << ")"
                      << std::endl;
            return EXIT_FAILURE;
        }
        check_coercion(call->type, fun.return_value, fun.identifier, call->id);
        for (auto it = call->arguments.begin(); it != call->arguments.end(); ++it) {
            auto op = it->get();
            auto index = std::distance(call->arguments.begin(), it);
            auto prototype_op = std::next(fun.arguments.begin(), index);
            check_operation(op);
            // Variadic functions.. don't check type.
            if(prototype_op != fun.arguments.end()) {
                check_coercion(op->type, prototype_op->type, "function argument", op->id);
            }
        }
        return EXIT_SUCCESS;
    }
llvm::Optional<DurationScale> getScaleForTimeInverse(llvm::StringRef Name) {
  static const llvm::StringMap<DurationScale> ScaleMap(
      {{"ToUnixHours", DurationScale::Hours},
       {"ToUnixMinutes", DurationScale::Minutes},
       {"ToUnixSeconds", DurationScale::Seconds},
       {"ToUnixMillis", DurationScale::Milliseconds},
       {"ToUnixMicros", DurationScale::Microseconds},
       {"ToUnixNanos", DurationScale::Nanoseconds}});

  auto ScaleIter = ScaleMap.find(std::string(Name));
  if (ScaleIter == ScaleMap.end())
    return llvm::None;

  return ScaleIter->second;
}
/// Check if a fixed size width buffer type matches the MPI datatype.
///
/// \param Typedef buffer type
/// \param BufferTypeName buffer type name, gets assigned
/// \param MPIDatatype name of the MPI datatype
///
/// \returns true if the type matches or the buffer type is unknown
static bool isTypedefTypeMatching(const TypedefType *const Typedef,
                                  std::string &BufferTypeName,
                                  const std::string &MPIDatatype) {
  static llvm::StringMap<std::string> FixedWidthMatches = {
      {"int8_t", "MPI_INT8_T"},     {"int16_t", "MPI_INT16_T"},
      {"int32_t", "MPI_INT32_T"},   {"int64_t", "MPI_INT64_T"},
      {"uint8_t", "MPI_UINT8_T"},   {"uint16_t", "MPI_UINT16_T"},
      {"uint32_t", "MPI_UINT32_T"}, {"uint64_t", "MPI_UINT64_T"}};

  const auto it = FixedWidthMatches.find(Typedef->getDecl()->getName());
  // Check if the typedef is known and not matching the MPI datatype.
  if (it != FixedWidthMatches.end() && it->getValue() != MPIDatatype) {
    BufferTypeName = Typedef->getDecl()->getName();
    return false;
  }
  return true;
}
llvm::Value *CGObjCJit::GenerateProtocolRef(CodeGenFunction &CGF,
                                            const ObjCProtocolDecl *PD) {
  if (isUsable) {
    llvm::Value *theProtocol;  
    // If not locally defined, retrieve from runtime
    llvm::StringMap<void*>::iterator it =
      DefinedProtocols.find(PD->getIdentifier()->getNameStart());
    if (it != DefinedProtocols.end()) {
      theProtocol =
          llvm::Constant::getIntegerValue(ObjCTypes.ProtocolPtrTy,
                                          llvm::APInt(sizeof(void*) * 8,
                                                      (uint64_t)it->second));
    } else {
      llvm::Value *ProtocolName =
          CGF.Builder.CreateGlobalStringPtr(PD->getNameAsString());
      theProtocol = CGF.Builder.CreateCall(fn_objc_getProtocol, ProtocolName);
    }
    return CGF.Builder.CreateBitCast(theProtocol, ObjCTypes.getExternalProtocolPtrTy());
  }
  return 0;
}
  // Register a marker.
  void addMarker(StringRef MarkerName, SourceLocation Pos) {
    auto InsertResult = Markers.insert(
        {MarkerName, Marker{Pos, SourceLocation(), SourceLocation()}});

    Marker &M = InsertResult.first->second;
    if (!InsertResult.second) {
      // Marker was redefined.
      M.RedefLoc = Pos;
    } else {
      // First definition: build any deferred directives.
      auto Deferred = DeferredDirectives.find(MarkerName);
      if (Deferred != DeferredDirectives.end()) {
        for (auto &UD : Deferred->second) {
          if (M.UseLoc.isInvalid())
            M.UseLoc = UD.DirectivePos;
          attachDirective(Diags, UD, Pos);
        }
        DeferredDirectives.erase(Deferred);
      }
    }
  }
llvm::Optional<DurationScale> getScaleForDurationInverse(llvm::StringRef Name) {
  static const llvm::StringMap<DurationScale> ScaleMap(
      {{"ToDoubleHours", DurationScale::Hours},
       {"ToInt64Hours", DurationScale::Hours},
       {"ToDoubleMinutes", DurationScale::Minutes},
       {"ToInt64Minutes", DurationScale::Minutes},
       {"ToDoubleSeconds", DurationScale::Seconds},
       {"ToInt64Seconds", DurationScale::Seconds},
       {"ToDoubleMilliseconds", DurationScale::Milliseconds},
       {"ToInt64Milliseconds", DurationScale::Milliseconds},
       {"ToDoubleMicroseconds", DurationScale::Microseconds},
       {"ToInt64Microseconds", DurationScale::Microseconds},
       {"ToDoubleNanoseconds", DurationScale::Nanoseconds},
       {"ToInt64Nanoseconds", DurationScale::Nanoseconds}});

  auto ScaleIter = ScaleMap.find(std::string(Name));
  if (ScaleIter == ScaleMap.end())
    return llvm::None;

  return ScaleIter->second;
}
static void collectCheckers(const CheckerRegistry::CheckerInfoList &checkers,
                            const llvm::StringMap<size_t> &packageSizes,
                            CheckerOptInfo &opt, CheckerInfoSet &collected) {
  // Use a binary search to find the possible start of the package.
  CheckerRegistry::CheckerInfo packageInfo(NULL, opt.getName(), "");
  CheckerRegistry::CheckerInfoList::const_iterator e = checkers.end();
  CheckerRegistry::CheckerInfoList::const_iterator i =
    std::lower_bound(checkers.begin(), e, packageInfo, checkerNameLT);

  // If we didn't even find a possible package, give up.
  if (i == e)
    return;

  // If what we found doesn't actually start the package, give up.
  if (!isInPackage(*i, opt.getName()))
    return;

  // There is at least one checker in the package; claim the option.
  opt.claim();

  // See how large the package is.
  // If the package doesn't exist, assume the option refers to a single checker.
  size_t size = 1;
  llvm::StringMap<size_t>::const_iterator packageSize =
    packageSizes.find(opt.getName());
  if (packageSize != packageSizes.end())
    size = packageSize->getValue();

  // Step through all the checkers in the package.
  for (e = i+size; i != e; ++i) {
    if (opt.isEnabled())
      collected.insert(&*i);
    else
      collected.remove(&*i);
  }
}
Beispiel #18
0
const void* getValueOfRelocatableSym(const std::string& str) {
    auto it = relocatable_syms.find(str);
    if (it != relocatable_syms.end())
        return it->second;
    return NULL;
}