Ejemplo n.º 1
0
  const std::string SymbolConstantValue::getCompleteConstantMangledName()
  {
    if(m_state.isScalar(getUlamTypeIdx()))
      return getMangledName();

    std::ostringstream mangledfullname;
    if(isDataMember())
      {
	UTI dmclassuti = getDataMemberClass(); //t3881
	mangledfullname << m_state.getTheInstanceMangledNameByIndex(dmclassuti).c_str();
	mangledfullname << "." << getMangledName().c_str();
      }
    else if(isLocalsFilescopeDef())
      {
	//local filescope constant arrays end with filescope name (e.g. _3Foo4ulam)
	UTI locuti = getLocalsFilescopeType();
	u32 mangledclassid = m_state.getMangledClassNameIdForUlamLocalsFilescope(locuti);
	mangledfullname << m_state.m_pool.getDataAsString(mangledclassid).c_str();
	mangledfullname << "<EC>::THE_INSTANCE." << getMangledName().c_str();
      }
    else if(isClassArgument())
      {
	mangledfullname << m_state.getTheInstanceMangledNameByIndex(m_state.getCompileThisIdx()).c_str();
	mangledfullname << "." << getMangledName().c_str(); //t3894
      }
    else
      mangledfullname << getMangledName().c_str();
    return mangledfullname.str();
  } //getCompleteConstantMangledName
Ejemplo n.º 2
0
  // replaced by NodeVarDecl:genCode to leverage the declaration order preserved by the parse tree.
  void SymbolVariableDataMember::generateCodedVariableDeclarations(File * fp, ULAMCLASSTYPE classtype)
  {
    assert(classtype == UC_ELEMENT); //really?
    UTI vuti = getUlamTypeIdx();
    UlamType * vut = m_state.getUlamTypeByIndex(vuti);
    ULAMCLASSTYPE vclasstype = vut->getUlamClassType();

    m_state.indentUlamCode(fp);
    fp->write(vut->getUlamTypeMangledName().c_str()); //for C++

    if(vclasstype == UC_QUARK) //called on classtype elements only
      {
	fp->write("<");
	fp->write_decimal(getPosOffset());
	fp->write(">");
      }
    fp->write(" ");
    fp->write(getMangledName().c_str());

#if 0
    s32 arraysize = vut->getArraySize();
    if(arraysize > NONARRAYSIZE)
      {
	fp->write("[");
	fp->write_decimal(arraysize);
	fp->write("]");
      }
    else if(arraysize == UNKNOWNSIZE)
      {
	fp->write("[UNKNOWN]");
      }
#endif
    fp->write(";"); GCNL;
  } //generateCodedVariableDeclarations
Ejemplo n.º 3
0
  //atomic parameter type, not model parameter.
  const std::string Symbol::getMangledNameForParameterType()
  {
    assert(!isModelParameter());

    UlamType * sut = m_state.getUlamTypeByIndex(getUlamTypeIdx());
    ULAMCLASSTYPE classtype = sut->getUlamClass();

    //another way, like this?
    if(isModelParameter())
      {
	std::ostringstream epmangled;
	epmangled << sut->getImmediateModelParameterStorageTypeAsString();
	//if(classtype == UC_QUARK)
	//  epmangled << "::Us";
	assert(classtype == UC_NOTACLASS);
	return epmangled.str();
      }

    // to distinguish btn an atomic parameter typedef and quark typedef;
    // use atomic parameter with array of classes
    bool isaclass = (( classtype == UC_QUARK || classtype == UC_ELEMENT || classtype == UC_UNSEEN) && sut->isScalar());

    std::ostringstream pmangled;
    pmangled << Symbol::getParameterTypePrefix(isaclass).c_str() << getMangledName();
    return pmangled.str();
  } //getMangledNameForParameterType
Ejemplo n.º 4
0
  void SymbolWithValue::printPostfixValueArrayStringAsComment(File * fp)
  {
    BV8K dval;
    bool oktoprint = getValueReadyToPrint(dval);

    UTI tuti = getUlamTypeIdx();
    UlamType * tut = m_state.getUlamTypeByIndex(tuti);
    bool isString = (tut->getUlamTypeEnum() == String); //t3953
    assert(isString);

    if(!oktoprint)
      {
	fp->write("// ");
	fp->write(getMangledName().c_str());
	fp->write(": NONREADYCONSTARRAY OF STRINGS"); GCNL;
	return;
      }

    //like the code generated in CS::genCodeClassDefaultConstantArray
    u32 uvals[ARRAY_LEN8K];
    dval.ToArray(uvals);

    u32 nwords = tut->getTotalNumberOfWords();

    //indented comments of string value items (one per line); e.g. t3953,4
    for(u32 w = 0; w < nwords; w++)
      {
	m_state.indent(fp);
	fp->write("// ");
	fp->write("[");
	fp->write_decimal_unsigned(w);
	fp->write("] = ");
	fp->write(m_state.getDataAsFormattedUserString(uvals[w]).c_str());
	fp->write("\n");
      }
    m_state.indent(fp);
    fp->write("// = ");
    fp->write(getMangledName().c_str());
    fp->write("[");
    fp->write_decimal_unsigned(nwords);
    fp->write("]");
    GCNL;
  } //printPostfixValueArrayStringAsComment
Ejemplo n.º 5
0
llvm::Function *Prototype::getOrInsert(llvm::Module *M) {
  auto FnTy = cast<llvm::FunctionType>(type()->generate(M));
  auto MangledName = getMangledName();

  /// getOrInsertFunction::
  ///
  /// Look up the specified function in the module symbol table.
  /// Four possibilities:
  /// 1. If it does not exist, add a prototype for the function and return it.
  /// 2. If it exists, and has a local linkage, the existing function is
  /// renamed and a new one is inserted.
  /// 3. Otherwise, if the existing function has the correct prototype, return
  /// the existing function.
  /// 4. Finally, the function exists but has the wrong prototype: return the
  /// function with a constantexpr cast to the right prototype.
  auto Const = M->getOrInsertFunction(MangledName, FnTy);

  if (auto FunctionCandidate = dyn_cast<llvm::Function>(Const))
    return FunctionCandidate;
  auto Error = MangledName + " was declared with different signature earlier";
  DiagnosticPrinter(SourceLoc) << Error;
  exit(1);
}
Ejemplo n.º 6
0
void TFunction::dump(TInfoSink &infoSink) const
{
    infoSink.debug << getName().c_str() << ": " <<  returnType.getBasicString() << " " << getMangledName().c_str() << "\n";
}
Ejemplo n.º 7
0
 std::string getMangledName(const GlobalValue *GV)
 {
     return getMangledName(GV->getName());
 }
Ejemplo n.º 8
0
 uint64_t getFunctionAddress(const std::string &Name)
 {
     return findSymbol(getMangledName(Name), false).getAddress();
 }
Ejemplo n.º 9
0
 uint64_t getGlobalValueAddress(const std::string &Name)
 {
     return findSymbol(getMangledName(Name), false).getAddress();
 }
Ejemplo n.º 10
0
 orc::JITSymbol findUnmangledSymbol(const std::string Name)
 {
     return findSymbol(getMangledName(Name), true);
 }
Ejemplo n.º 11
0
 void *getPointerToGlobalIfAvailable(const GlobalValue *GV)
 {
     return getPointerToGlobalIfAvailable(getMangledName(GV));
 }
Ejemplo n.º 12
0
 void addGlobalMapping(const GlobalValue *GV, void *Addr)
 {
     addGlobalMapping(getMangledName(GV), (uintptr_t)Addr);
 }
    // Deal with all the call expr in the transaction.
    bool VisitCallExpr(CallExpr* TheCall) {
      if (FunctionDecl* FDecl = TheCall->getDirectCallee()) {
        std::bitset<32> ArgIndexs;
        for (FunctionDecl::redecl_iterator RI = FDecl->redecls_begin(),
             RE = FDecl->redecls_end(); RI != RE; ++RI) {
          for (specific_attr_iterator<NonNullAttr>
               I = RI->specific_attr_begin<NonNullAttr>(),
               E = RI->specific_attr_end<NonNullAttr>(); I != E; ++I) {
            NonNullAttr *NonNull = *I;

            // Store all the null attr argument's index into "ArgIndexs".
            for (NonNullAttr::args_iterator i = NonNull->args_begin(),
                 e = NonNull->args_end(); i != e; ++i) {

              // Get the argument with the nonnull attribute.
              const Expr* Arg = TheCall->getArg(*i);

              // Check whether we can get the argument'value. If the argument is
              // not null, then ignore this argument and continue to deal with the
              // next argument with the nonnull attribute.ArgIndexs.set(*i);
              bool Result;
              ASTContext& Context = m_Sema->getASTContext();
              if (Arg->EvaluateAsBooleanCondition(Result, Context) && Result) {
                continue;
              }
              ArgIndexs.set(*i);
            }
            break;
          }
        }

        if (ArgIndexs.any()) {

          // Get the function decl's name.
          std::string FName = getMangledName(FDecl);

          // Store the function decl's name into the vector.
          m_NonNullDeclNames.push_back(FName);

          // Store the function decl's name with its null attr args' indexes
          // into the map.
          m_NonNullArgIndexs.insert(std::make_pair(FName, ArgIndexs));
        }

        // FIXME: For now we will only work/check on declarations that are not
        // deserialized. We want to avoid our null deref transaformer to 
        // deserialize all the contents of a PCH/PCM.
        // We have to think of a better way to find the annotated 
        // declarations, without that to cause too much deserialization.
        Stmt* S = (FDecl->isFromASTFile()) ? 0 : FDecl->getBody();
        if (S) {
          for (Stmt::child_iterator II = S->child_begin(), EE = S->child_end();
               II != EE; ++II) {
            CallExpr* child = dyn_cast<CallExpr>(*II);
            if (child && child->getDirectCallee() != FDecl)
              VisitCallExpr(child);
          }
        }
      }
      return true; // returning false will abort the in-depth traversal.
    }