示例#1
0
bool CompilerInstance::InitializeSourceManager(llvm::StringRef InputFile,
                                               Diagnostic &Diags,
                                               FileManager &FileMgr,
                                               SourceManager &SourceMgr,
                                               const FrontendOptions &Opts) {
  // Figure out where to get and map in the main file.
  if (Opts.EmptyInputOnly) {
    const char *EmptyStr = "";
    llvm::MemoryBuffer *SB =
      llvm::MemoryBuffer::getMemBuffer(EmptyStr, EmptyStr, "<empty input>");
    SourceMgr.createMainFileIDForMemBuffer(SB);
  } else if (InputFile != "-") {
    const FileEntry *File = FileMgr.getFile(InputFile);
    if (File) SourceMgr.createMainFileID(File, SourceLocation());
    if (SourceMgr.getMainFileID().isInvalid()) {
      Diags.Report(diag::err_fe_error_reading) << InputFile;
      return false;
    }
  } else {
    llvm::MemoryBuffer *SB = llvm::MemoryBuffer::getSTDIN();
    SourceMgr.createMainFileIDForMemBuffer(SB);
    if (SourceMgr.getMainFileID().isInvalid()) {
      Diags.Report(diag::err_fe_error_reading_stdin);
      return false;
    }
  }

  return true;
}
示例#2
0
void
yasm::DirIntNum(NameValue& nv,
                Diagnostic& diags,
                Object* obj,
                IntNum* out,
                bool* out_set)
{
    if (!nv.isExpr())
    {
        diags.Report(nv.getNameSource(), diag::err_value_integer)
            << nv.getValueRange();
        return;
    }

    std::auto_ptr<Expr> e(nv.ReleaseExpr(*obj));
    e->Simplify(diags);
    if (!e->isIntNum())
    {
        diags.Report(nv.getNameSource(), diag::err_value_integer)
            << nv.getValueRange();
        return;
    }

    *out = e->getIntNum();
    *out_set = true;
}
示例#3
0
void CompilerInvocation::CreateFromArgs(CompilerInvocation &Res,
                                        const char **ArgBegin,
                                        const char **ArgEnd,
                                        Diagnostic &Diags) {
  // Parse the arguments.
  llvm::OwningPtr<OptTable> Opts(createCC1OptTable());
  unsigned MissingArgIndex, MissingArgCount;
  llvm::OwningPtr<InputArgList> Args(
    Opts->ParseArgs(ArgBegin, ArgEnd,MissingArgIndex, MissingArgCount));

  // Check for missing argument error.
  if (MissingArgCount)
    Diags.Report(diag::err_drv_missing_argument)
      << Args->getArgString(MissingArgIndex) << MissingArgCount;

  // Issue errors on unknown arguments.
  for (arg_iterator it = Args->filtered_begin(OPT_UNKNOWN),
         ie = Args->filtered_end(); it != ie; ++it)
    Diags.Report(diag::err_drv_unknown_argument) << it->getAsString(*Args);

  ParseAnalyzerArgs(Res.getAnalyzerOpts(), *Args, Diags);
  ParseCodeGenArgs(Res.getCodeGenOpts(), *Args, Diags);
  ParseDependencyOutputArgs(Res.getDependencyOutputOpts(), *Args);
  ParseDiagnosticArgs(Res.getDiagnosticOpts(), *Args, Diags);
  FrontendOptions::InputKind DashX =
    ParseFrontendArgs(Res.getFrontendOpts(), *Args, Diags);
  ParseHeaderSearchArgs(Res.getHeaderSearchOpts(), *Args);
  if (DashX != FrontendOptions::IK_AST)
    ParseLangArgs(Res.getLangOpts(), *Args, DashX, Diags);
  ParsePreprocessorArgs(Res.getPreprocessorOpts(), *Args, Diags);
  ParsePreprocessorOutputArgs(Res.getPreprocessorOutputOpts(), *Args);
  ParseTargetArgs(Res.getTargetOpts(), *Args);
}
示例#4
0
static void
CheckSymbol(const Symbol& sym, Diagnostic& diags)
{
    int vis = sym.getVisibility();

    // Don't check internally-generated symbols.  Only internally generated
    // symbols have symrec data, so simply check for its presence.
    if (sym.getAssocData<BinSymbol>())
        return;

    if (vis & Symbol::EXTERN)
    {
        diags.Report(sym.getDeclSource(), diag::warn_bin_unsupported_decl)
            << "EXTERN";
    }
    else if (vis & Symbol::GLOBAL)
    {
        diags.Report(sym.getDeclSource(), diag::warn_bin_unsupported_decl)
            << "GLOBAL";
    }
    else if (vis & Symbol::COMMON)
    {
        diags.Report(sym.getDeclSource(), diag::warn_bin_unsupported_decl)
            << "COMMON";
    }
}
示例#5
0
bool
Operand::Finalize(Diagnostic& diags)
{
    switch (m_type)
    {
        case MEMORY:
            if (!m_ea)
                break;
            if (Expr* abs = m_ea->m_disp.getAbs())
            {
                if (!ExpandEqu(*abs))
                {
                    diags.Report(m_source, diag::err_equ_circular_reference_mem);
                    return false;
                }

                // Don't get over-ambitious here; some archs' memory expr
                // parser are sensitive to the presence of *1, etc, so don't
                // simplify reg*1 identities.
                abs->Simplify(diags, false);
            }
            break;
        case IMM:
            if (!ExpandEqu(*m_val))
            {
                diags.Report(m_source, diag::err_equ_circular_reference_imm);
                return false;
            }
            m_val->Simplify(diags);
            break;
        default:
            break;
    }
    return true;
}
示例#6
0
bool CompilerInstance::InitializeSourceManager(llvm::StringRef InputFile,
                                               Diagnostic &Diags,
                                               FileManager &FileMgr,
                                               SourceManager &SourceMgr,
                                               const FrontendOptions &Opts) {
  // Figure out where to get and map in the main file, unless it's already
  // been created (e.g., by a precompiled preamble).
  if (!SourceMgr.getMainFileID().isInvalid()) {
    // Do nothing: the main file has already been set.
  } else if (InputFile != "-") {
    const FileEntry *File = FileMgr.getFile(InputFile);
    if (!File) {
      Diags.Report(diag::err_fe_error_reading) << InputFile;
      return false;
    }
    SourceMgr.createMainFileID(File);
  } else {
    llvm::OwningPtr<llvm::MemoryBuffer> SB;
    if (llvm::MemoryBuffer::getSTDIN(SB)) {
      // FIXME: Give ec.message() in this diag.
      Diags.Report(diag::err_fe_error_reading_stdin);
      return false;
    }
    const FileEntry *File = FileMgr.getVirtualFile(SB->getBufferIdentifier(),
                                                   SB->getBufferSize(), 0);
    SourceMgr.createMainFileID(File);
    SourceMgr.overrideFileContents(File, SB.take());
  }

  assert(!SourceMgr.getMainFileID().isInvalid() &&
         "Couldn't establish MainFileID!");
  return true;
}
示例#7
0
bool
Bytecode::Finalize(Diagnostic& diags)
{
    for (std::vector<Fixup>::iterator i=m_fixed_fixups.begin(),
         end=m_fixed_fixups.end(); i != end; ++i)
    {
        if (!i->Finalize(diags, i->isJumpTarget() ? diag::err_too_complex_jump :
                         diag::err_too_complex_expression))
            return false;

        if (i->isJumpTarget() && i->isComplexRelative())
        {
            diags.Report(i->getSource().getBegin(),
                         diag::err_invalid_jump_target);
            return false;
        }

        // Do curpos subtraction for IP-relative flagged values.
        if (i->isIPRelative())
        {
            Location sub_loc = {this, i->getOffset()};
            if (!i->SubRelative(m_container->getObject(), sub_loc))
                diags.Report(i->getSource().getBegin(),
                             diag::err_too_complex_expression);
        }
    }

    if (m_contents.get() != 0)
        return m_contents->Finalize(*this, diags);
    return true;
}
// Initialize the remapping of files to alternative contents, e.g.,
// those specified through other files.
static void InitializeFileRemapping(Diagnostic &Diags,
                                    SourceManager &SourceMgr,
                                    FileManager &FileMgr,
                                    const PreprocessorOptions &InitOpts) {
  // Remap files in the source manager (with buffers).
  for (PreprocessorOptions::const_remapped_file_buffer_iterator
         Remap = InitOpts.remapped_file_buffer_begin(),
         RemapEnd = InitOpts.remapped_file_buffer_end();
       Remap != RemapEnd;
       ++Remap) {
    // Create the file entry for the file that we're mapping from.
    const FileEntry *FromFile = FileMgr.getVirtualFile(Remap->first,
                                                Remap->second->getBufferSize(),
                                                       0);
    if (!FromFile) {
      Diags.Report(diag::err_fe_remap_missing_from_file)
        << Remap->first;
      if (!InitOpts.RetainRemappedFileBuffers)
        delete Remap->second;
      continue;
    }

    // Override the contents of the "from" file with the contents of
    // the "to" file.
    SourceMgr.overrideFileContents(FromFile, Remap->second,
                                   InitOpts.RetainRemappedFileBuffers);
  }

  // Remap files in the source manager (with other files).
  for (PreprocessorOptions::const_remapped_file_iterator
         Remap = InitOpts.remapped_file_begin(),
         RemapEnd = InitOpts.remapped_file_end();
       Remap != RemapEnd;
       ++Remap) {
    // Find the file that we're mapping to.
    const FileEntry *ToFile = FileMgr.getFile(Remap->second);
    if (!ToFile) {
      Diags.Report(diag::err_fe_remap_missing_to_file)
      << Remap->first << Remap->second;
      continue;
    }
    
    // Create the file entry for the file that we're mapping from.
    const FileEntry *FromFile = FileMgr.getVirtualFile(Remap->first,
                                                       ToFile->getSize(), 0);
    if (!FromFile) {
      Diags.Report(diag::err_fe_remap_missing_from_file)
      << Remap->first;
      continue;
    }
    
    // Override the contents of the "from" file with the contents of
    // the "to" file.
    SourceMgr.overrideFileContents(FromFile, ToFile);
  }

  SourceMgr.setOverridenFilesKeepOriginalName(
                                        InitOpts.RemappedFilesKeepOriginalName);
}
示例#9
0
void
BinObject::Output(llvm::raw_fd_ostream& os,
                  bool all_syms,
                  DebugFormat& dbgfmt,
                  Diagnostic& diags)
{
    // Set ORG to 0 unless otherwise specified
    IntNum origin(0);
    if (m_org.get() != 0)
    {
        m_org->Simplify(diags);
        if (!m_org->isIntNum())
        {
            diags.Report(m_org_source, diag::err_org_too_complex);
            return;
        }
        IntNum orgi = m_org->getIntNum();
        if (orgi.getSign() < 0)
        {
            diags.Report(m_org_source, diag::err_org_negative);
            return;
        }
        origin = orgi;
    }

    // Check symbol table
    for (Object::const_symbol_iterator i=m_object.symbols_begin(),
         end=m_object.symbols_end(); i != end; ++i)
        CheckSymbol(*i, diags);

    BinLink link(m_object, diags);

    if (!link.DoLink(origin))
        return;

    // Output map file
    OutputMap(origin, link.getLMAGroups(), diags);

    // Ensure we don't have overlapping progbits LMAs.
    if (!link.CheckLMAOverlap())
        return;

    // Output sections
    BinOutput out(os, m_object, diags);
    for (Object::section_iterator i=m_object.sections_begin(),
         end=m_object.sections_end(); i != end; ++i)
    {
        out.OutputSection(*i, origin);
    }
}
示例#10
0
void
NumericOutput::EmitWarnings(Diagnostic& diags) const
{
    if (m_sign && (m_warns & INT_OVERFLOW) != 0)
        diags.Report(m_source, diag::warn_signed_overflow) << m_size;
    if (!m_sign && (m_warns & INT_OVERFLOW) != 0)
        diags.Report(m_source, diag::warn_unsigned_overflow) << m_size;
    if ((m_warns & FP_UNDERFLOW) != 0)
        diags.Report(m_source, diag::warn_float_underflow);
    if ((m_warns & FP_OVERFLOW) != 0)
        diags.Report(m_source, diag::warn_float_overflow);
    if ((m_warns & TRUNCATED) != 0)
        diags.Report(m_source, diag::warn_truncated) << m_rshift;
}
示例#11
0
void
Win64Object::DirProcFrame(DirectiveInfo& info, Diagnostic& diags)
{
    assert(info.isObject(m_object));
    NameValues& namevals = info.getNameValues();
    SourceLocation source = info.getSource();

    NameValue& name_nv = namevals.front();
    if (!name_nv.isId())
    {
        diags.Report(info.getSource(), diag::err_value_id)
            << name_nv.getValueRange();
        return;
    }
    llvm::StringRef name = name_nv.getId();

    if (m_proc_frame.isValid())
    {
        diags.Report(info.getSource(),
                     diags.getCustomDiagID(Diagnostic::Error,
            "nested procedures not supported (didn't use [ENDPROC_FRAME]?)"));
        diags.Report(m_proc_frame,
                     diags.getCustomDiagID(Diagnostic::Note,
                                           "previous procedure started here"));
        return;
    }
    m_proc_frame = source;
    m_done_prolog = SourceLocation();
    m_unwind.reset(new UnwindInfo);

    SymbolRef proc = m_object.getSymbol(name);
    proc->Use(source);
    m_unwind->setProc(proc);

    // Optional error handler
    if (namevals.size() > 1)
    {
        NameValue& ehandler_nv = namevals[1];
        if (!ehandler_nv.isId())
        {
            diags.Report(info.getSource(), diag::err_value_id)
                << ehandler_nv.getValueRange();
            return;
        }
        SymbolRef ehandler = m_object.getSymbol(ehandler_nv.getId());
        ehandler->Use(ehandler_nv.getValueRange().getBegin());
        m_unwind->setEHandler(ehandler);
    }
}
示例#12
0
void
Win64Object::DirPushReg(DirectiveInfo& info, Diagnostic& diags)
{
    assert(info.isObject(m_object));
    NameValues& namevals = info.getNameValues();

    assert(!namevals.empty());
    if (!CheckProcFrameState(info.getSource(), diags))
        return;

    if (!namevals.front().isRegister())
    {
        diags.Report(info.getSource(), diag::err_value_register)
            << namevals.front().getValueRange();
        return;
    }
    const Register* reg = namevals.front().getRegister();

    // Generate a PUSH_NONVOL unwind code.
    m_unwind->AddCode(std::auto_ptr<UnwindCode>(new UnwindCode(
        m_unwind->getProc(),
        m_object.getSymbol(info.getLocation()),
        UnwindCode::PUSH_NONVOL,
        reg->getNum() & 0xF)));
}
示例#13
0
bool
yasm::DirNameValueWarn(NameValue& nv,
                       SourceLocation dir_source,
                       Diagnostic& diags)
{
    if (nv.getNameSource().isValid())
    {
        diags.Report(nv.getNameSource(), diag::warn_unrecognized_qualifier);
        return false;
    }

    diags.Report(nv.getValueRange().getBegin(),
                 diag::warn_unrecognized_qualifier);

    return false;
}
示例#14
0
void
Win64Object::DirAllocStack(DirectiveInfo& info, Diagnostic& diags)
{
    assert(info.isObject(m_object));
    NameValues& namevals = info.getNameValues();

    assert(!namevals.empty());
    if (!CheckProcFrameState(info.getSource(), diags))
        return;

    NameValue& nv = namevals.front();
    if (!nv.isExpr())
    {
        diags.Report(info.getSource(), diag::err_value_expression)
            << nv.getValueRange();
        return;
    }

    // Generate an ALLOC_SMALL unwind code; this will get enlarged to an
    // ALLOC_LARGE if necessary.
    m_unwind->AddCode(std::auto_ptr<UnwindCode>(new UnwindCode(
        m_unwind->getProc(),
        m_object.getSymbol(info.getLocation()),
        UnwindCode::ALLOC_SMALL,
        0,
        7,
        nv.ReleaseExpr(m_object))));
}
示例#15
0
void
ElfSymbol::Write(Bytes& bytes, const ElfConfig& config, Diagnostic& diags)
{
    // Pull referenced elf symbol information type and size
    if (m_value_rel)
    {
        ElfSymbol* elfrel = m_value_rel->getAssocData<ElfSymbol>();
        if (elfrel)
        {
            if (!hasType() && elfrel->hasType())
                m_type = elfrel->m_type;
            if (!hasSize() && elfrel->hasSize())
            {
                m_size = elfrel->m_size;
                m_size_source = elfrel->m_size_source;
                // just in case, simplify it
                SimplifyCalcDist(m_size, diags);
                if (!m_size.isIntNum())
                    diags.Report(m_size_source, diag::err_size_integer);
            }
        }
    }

    bytes.resize(0);
    config.setEndian(bytes);

    Write32(bytes, m_name_index);

    if (config.cls == ELFCLASS32)
    {
        Write32(bytes, m_value);
        Write32(bytes, hasSize() && m_size.isIntNum() ? m_size.getIntNum() : 0);
    }

    Write8(bytes, ELF_ST_INFO(m_bind, m_type));
    Write8(bytes, ELF_ST_OTHER(m_vis));

    if (m_sect)
    {
        ElfSection* elfsect = m_sect->getAssocData<ElfSection>();
        assert(elfsect != 0);
        Write16(bytes, elfsect->getIndex());
    }
    else
    {
        Write16(bytes, m_index);
    }

    if (config.cls == ELFCLASS64)
    {
        Write64(bytes, m_value);
        Write64(bytes, hasSize() ? m_size.getIntNum() : 0);
    }

    if (config.cls == ELFCLASS32)
        assert(bytes.size() == SYMTAB32_SIZE);
    else if (config.cls == ELFCLASS64)
        assert(bytes.size() == SYMTAB64_SIZE);
}
示例#16
0
void
Win64Object::SaveCommon(DirectiveInfo& info,
                        UnwindCode::Opcode op,
                        Diagnostic& diags)
{
    assert(info.isObject(m_object));
    NameValues& namevals = info.getNameValues();
    SourceLocation source = info.getSource();

    assert(!namevals.empty());
    if (!CheckProcFrameState(info.getSource(), diags))
        return;

    if (!namevals.front().isRegister())
    {
        diags.Report(source, diag::err_value_register)
            << namevals.front().getValueRange();
        return;
    }
    const Register* reg = namevals.front().getRegister();

    if (namevals.size() < 2)
    {
        diags.Report(source, diag::err_no_offset);
        return;
    }

    if (!namevals[1].isExpr())
    {
        diags.Report(source, diag::err_offset_expression)
            << namevals[1].getValueRange();
        return;
    }

    // Generate a SAVE_XXX unwind code; this will get enlarged to a
    // SAVE_XXX_FAR if necessary.
    m_unwind->AddCode(std::auto_ptr<UnwindCode>(new UnwindCode(
        m_unwind->getProc(),
        m_object.getSymbol(info.getLocation()),
        op,
        reg->getNum() & 0xF,
        16,
        namevals[1].ReleaseExpr(m_object))));
}
示例#17
0
// Initialize the remapping of files to alternative contents, e.g.,
// those specified through other files.
static void InitializeFileRemapping(Diagnostic &Diags,
                                    SourceManager &SourceMgr,
                                    FileManager &FileMgr,
                                    const PreprocessorOptions &InitOpts) {
  // Remap files in the source manager.
  for (PreprocessorOptions::remapped_file_iterator
         Remap = InitOpts.remapped_file_begin(),
         RemapEnd = InitOpts.remapped_file_end();
       Remap != RemapEnd;
       ++Remap) {
    // Find the file that we're mapping to.
    const FileEntry *ToFile = FileMgr.getFile(Remap->second);
    if (!ToFile) {
      Diags.Report(diag::err_fe_remap_missing_to_file)
        << Remap->first << Remap->second;
      continue;
    }

    // Create the file entry for the file that we're mapping from.
    const FileEntry *FromFile = FileMgr.getVirtualFile(Remap->first,
                                                       ToFile->getSize(),
                                                       0);
    if (!FromFile) {
      Diags.Report(diag::err_fe_remap_missing_from_file)
        << Remap->first;
      continue;
    }

    // Load the contents of the file we're mapping to.
    std::string ErrorStr;
    const llvm::MemoryBuffer *Buffer
      = llvm::MemoryBuffer::getFile(ToFile->getName(), &ErrorStr);
    if (!Buffer) {
      Diags.Report(diag::err_fe_error_opening)
        << Remap->second << ErrorStr;
      continue;
    }

    // Override the contents of the "from" file with the contents of
    // the "to" file.
    SourceMgr.overrideFileContents(FromFile, Buffer);
  }
}
bool
Multiple::CalcForOutput(SourceLocation source, Diagnostic& diags)
{
    SimplifyCalcDist(m_expr, diags);
    if (!m_expr.isIntNum())
    {
        diags.Report(source, diag::err_multiple_unknown);
        return false;
    }
    IntNum num = m_expr.getIntNum();
    if (num.getSign() < 0)
    {
        diags.Report(source, diag::err_multiple_negative);
        return false;
    }
    assert(m_int == num.getInt() && "multiple changed after optimize");
    m_int = num.getInt();
    return true;
}
示例#19
0
bool
BinObject::setMapFilename(const NameValue& nv,
                          SourceLocation dir_source,
                          Diagnostic& diags)
{
    if (!m_map_filename.empty())
    {
        diags.Report(nv.getValueRange().getBegin(),
            diags.getCustomDiagID(Diagnostic::Error,
                                  "map file already specified"));
        return true;
    }

    if (!nv.isString())
    {
        diags.Report(nv.getValueRange().getBegin(),
                     diag::err_value_string_or_id);
        return false;
    }
    m_map_filename = nv.getString();
    return true;
}
示例#20
0
static int getLastArgIntValue(ArgList &Args, cc1options::ID ID,
                              int Default, Diagnostic &Diags) {
  Arg *A = Args.getLastArg(ID);
  if (!A)
    return Default;

  int Res = Default;
  if (llvm::StringRef(A->getValue(Args)).getAsInteger(10, Res))
    Diags.Report(diag::err_drv_invalid_int_value)
        << A->getAsString(Args) << A->getValue(Args);

  return Res;
}
示例#21
0
bool
Win64Object::CheckProcFrameState(SourceLocation dir_source, Diagnostic& diags)
{
    if (!m_proc_frame.isValid())
    {
        diags.Report(dir_source,
                     diags.getCustomDiagID(Diagnostic::Error,
                                           "no preceding [PROC_FRAME]"));
        return false;
    }

    if (m_done_prolog.isValid())
    {
        diags.Report(dir_source,
                     diags.getCustomDiagID(Diagnostic::Error,
                                           "must come before [END_PROLOGUE]"));
        diags.Report(m_done_prolog,
            diags.getCustomDiagID(Diagnostic::Note, "prologue ended here"));
        return false;
    }
    return true;
}
示例#22
0
static void ParsePreprocessorArgs(PreprocessorOptions &Opts, ArgList &Args,
                                  Diagnostic &Diags) {
  using namespace cc1options;
  Opts.ImplicitPCHInclude = getLastArgValue(Args, OPT_include_pch);
  Opts.ImplicitPTHInclude = getLastArgValue(Args, OPT_include_pth);
  if (const Arg *A = Args.getLastArg(OPT_token_cache))
      Opts.TokenCache = A->getValue(Args);
  else
    Opts.TokenCache = Opts.ImplicitPTHInclude;
  Opts.UsePredefines = !Args.hasArg(OPT_undef);

  // Add macros from the command line.
  for (arg_iterator it = Args.filtered_begin(OPT_D, OPT_U),
         ie = Args.filtered_end(); it != ie; ++it) {
    if (it->getOption().matches(OPT_D))
      Opts.addMacroDef(it->getValue(Args));
    else
      Opts.addMacroUndef(it->getValue(Args));
  }

  Opts.MacroIncludes = getAllArgValues(Args, OPT_imacros);

  // Add the ordered list of -includes.
  for (arg_iterator it = Args.filtered_begin(OPT_include, OPT_include_pch,
                                             OPT_include_pth),
         ie = Args.filtered_end(); it != ie; ++it) {
    // PCH is handled specially, we need to extra the original include path.
    if (it->getOption().matches(OPT_include_pch)) {
      std::string OriginalFile =
        PCHReader::getOriginalSourceFile(it->getValue(Args), Diags);
      if (OriginalFile.empty())
        continue;

      Opts.Includes.push_back(OriginalFile);
    } else
      Opts.Includes.push_back(it->getValue(Args));
  }

  for (arg_iterator it = Args.filtered_begin(OPT_remap_file),
         ie = Args.filtered_end(); it != ie; ++it) {
    std::pair<llvm::StringRef,llvm::StringRef> Split =
      llvm::StringRef(it->getValue(Args)).split(';');

    if (Split.second.empty()) {
      Diags.Report(diag::err_drv_invalid_remap_file) << it->getAsString(Args);
      continue;
    }

    Opts.addRemappedFile(Split.first, Split.second);
  }
}
示例#23
0
void
BinObject::DirOrg(DirectiveInfo& info, Diagnostic& diags)
{
    // We only allow a single ORG in a program.
    if (m_org.get() != 0)
    {
        diags.Report(info.getSource(),
            diags.getCustomDiagID(Diagnostic::Error,
                                  "program origin redefined"));
        return;
    }

    // ORG takes just a simple expression as param
    const NameValue& nv = info.getNameValues().front();
    if (!nv.isExpr())
    {
        diags.Report(info.getSource(), diag::err_value_expression)
            << nv.getValueRange();
        return;
    }
    m_org.reset(new Expr(nv.getExpr(info.getObject())));
    m_org_source = info.getSource();
}
示例#24
0
ElfSymbol::ElfSymbol(const ElfConfig&           config,
                     const llvm::MemoryBuffer&  in,
                     const ElfSection&          symtab_sect,
                     ElfSymbolIndex             index,
                     Section*                   sections[],
                     Diagnostic&                diags)
    : m_sect(0)
    , m_name_index(0)
    , m_value(0)
    , m_symindex(index)
    , m_in_table(true)
    , m_weak_ref(false)
    , m_weak_refr(false)
{
    InputBuffer inbuf(in);

    ElfSize symsize = symtab_sect.getEntSize();
    inbuf.setPosition(symtab_sect.getFileOffset() + index * symsize);
    if (inbuf.getReadableSize() < symsize)
    {
        diags.Report(SourceLocation(), diag::err_symbol_unreadable);
        return;
    }

    config.setEndian(inbuf);

    m_name_index = ReadU32(inbuf);

    if (config.cls == ELFCLASS32)
    {
        m_value = ReadU32(inbuf);
        m_size = Expr(ReadU32(inbuf));
    }

    unsigned char info = ReadU8(inbuf);
    m_bind = ELF_ST_BIND(info);
    m_type = ELF_ST_TYPE(info);
    m_vis = ELF_ST_VISIBILITY(ReadU8(inbuf));

    m_index = static_cast<ElfSectionIndex>(ReadU16(inbuf));
    if (m_index != SHN_UNDEF && m_index < config.secthead_count)
        m_sect = sections[m_index];

    if (config.cls == ELFCLASS64)
    {
        m_value = ReadU64(inbuf);
        m_size = Expr(ReadU64(inbuf));
    }
}
示例#25
0
void
yasm::DirRegister(NameValue& nv,
                  Diagnostic& diags,
                  RegisterPtr* out,
                  bool* out_set)
{
    if (!nv.isRegister())
    {
        diags.Report(nv.getNameSource(), diag::err_value_register)
            << nv.getValueRange();
        return;
    }
    *out = nv.getRegister();
    *out_set = true;
}
示例#26
0
void
yasm::DirString(NameValue& nv,
                Diagnostic& diags,
                std::string* out,
                bool* out_set)
{
    if (!nv.isString())
    {
        diags.Report(nv.getNameSource(), diag::err_value_string_or_id)
            << nv.getValueRange();
        return;
    }
    *out = nv.getString();
    *out_set = true;
}
bool
Multiple::CalcLen(Bytecode& bc,
                  const Bytecode::AddSpanFunc& add_span,
                  Diagnostic& diags)
{
    // Calculate multiple value as an integer
    m_int = 1;
    if (m_expr.isIntNum())
    {
        IntNum num = m_expr.getIntNum();
        if (num.getSign() < 0)
        {
            m_int = 0;
            diags.Report(bc.getSource(), diag::err_multiple_negative);
            return false;
        }
        else
            m_int = num.getInt();
    }
    else
    {
        if (m_expr.Contains(ExprTerm::FLOAT))
        {
            m_int = 0;
            diags.Report(bc.getSource(), diag::err_expr_contains_float);
            return false;
        }
        else
        {
            Value value(0, Expr::Ptr(m_expr.clone()));
            add_span(bc, 0, value, 0, 0);
            m_int = 0;      // assume 0 to start
        }
    }
    return true;
}
示例#28
0
static void ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args,
                             Diagnostic &Diags) {
  using namespace cc1options;
  // -Os implies -O2
  if (Args.hasArg(OPT_Os))
    Opts.OptimizationLevel = 2;
  else {
    Opts.OptimizationLevel = getLastArgIntValue(Args, OPT_O, 0, Diags);
    if (Opts.OptimizationLevel > 3) {
      Diags.Report(diag::err_drv_invalid_value)
        << Args.getLastArg(OPT_O)->getAsString(Args) << Opts.OptimizationLevel;
      Opts.OptimizationLevel = 3;
    }
  }

  // We must always run at least the always inlining pass.
  Opts.Inlining = (Opts.OptimizationLevel > 1) ? CodeGenOptions::NormalInlining
    : CodeGenOptions::OnlyAlwaysInlining;

  Opts.DebugInfo = Args.hasArg(OPT_g);
  Opts.DisableLLVMOpts = Args.hasArg(OPT_disable_llvm_optzns);
  Opts.DisableRedZone = Args.hasArg(OPT_disable_red_zone);
  Opts.MergeAllConstants = !Args.hasArg(OPT_fno_merge_all_constants);
  Opts.NoCommon = Args.hasArg(OPT_fno_common);
  Opts.NoImplicitFloat = Args.hasArg(OPT_no_implicit_float);
  Opts.OptimizeSize = Args.hasArg(OPT_Os);
  Opts.UnrollLoops = (Opts.OptimizationLevel > 1 && !Opts.OptimizeSize);

  Opts.AsmVerbose = Args.hasArg(OPT_masm_verbose);
  Opts.CodeModel = getLastArgValue(Args, OPT_mcode_model);
  Opts.DebugPass = getLastArgValue(Args, OPT_mdebug_pass);
  Opts.DisableFPElim = Args.hasArg(OPT_mdisable_fp_elim);
  Opts.FloatABI = getLastArgValue(Args, OPT_mfloat_abi);
  Opts.LimitFloatPrecision = getLastArgValue(Args, OPT_mlimit_float_precision);
  Opts.NoZeroInitializedInBSS = Args.hasArg(OPT_mno_zero_initialized_in_bss);
  Opts.SoftFloat = Args.hasArg(OPT_msoft_float);
  Opts.UnwindTables = Args.hasArg(OPT_munwind_tables);
  Opts.RelocationModel = getLastArgValue(Args, OPT_mrelocation_model, "pic");

  Opts.MainFileName = getLastArgValue(Args, OPT_main_file_name);

  // FIXME: Put elsewhere?
#ifdef NDEBUG
  Opts.VerifyModule = 0;
#else
  Opts.VerifyModule = 1;
#endif
}
示例#29
0
void
yasm::DirExpr(NameValue& nv,
              Diagnostic& diags,
              Object* obj,
              std::auto_ptr<Expr>* out,
              bool* out_set)
{
    if (!nv.isExpr())
    {
        diags.Report(nv.getNameSource(), diag::err_value_expression)
            << nv.getValueRange();
        return;
    }
    *out = nv.ReleaseExpr(*obj);
    *out_set = true;
}
示例#30
0
// Append a #define line to Buf for Macro.  Macro should be of the form XXX,
// in which case we emit "#define XXX 1" or "XXX=Y z W" in which case we emit
// "#define XXX Y z W".  To get a #define with no value, use "XXX=".
static void DefineBuiltinMacro(MacroBuilder &Builder, llvm::StringRef Macro,
                               Diagnostic &Diags) {
  std::pair<llvm::StringRef, llvm::StringRef> MacroPair = Macro.split('=');
  llvm::StringRef MacroName = MacroPair.first;
  llvm::StringRef MacroBody = MacroPair.second;
  if (MacroName.size() != Macro.size()) {
    // Per GCC -D semantics, the macro ends at \n if it exists.
    llvm::StringRef::size_type End = MacroBody.find_first_of("\n\r");
    if (End != llvm::StringRef::npos)
      Diags.Report(diag::warn_fe_macro_contains_embedded_newline)
        << MacroName;
    Builder.defineMacro(MacroName, MacroBody.substr(0, End));
  } else {
    // Push "macroname 1".
    Builder.defineMacro(Macro);
  }
}