diff options
author | rdivacky <rdivacky@FreeBSD.org> | 2010-01-23 11:09:33 +0000 |
---|---|---|
committer | rdivacky <rdivacky@FreeBSD.org> | 2010-01-23 11:09:33 +0000 |
commit | 3fd58f91dd318518f7daa4ba64c0aaf31799d89b (patch) | |
tree | 74eecbae571601ec6a626a53374b1eddc7b164a5 /tools | |
parent | 3fba7d16b41dfbefe3b1be6bc0ab94c017728f79 (diff) | |
download | FreeBSD-src-3fd58f91dd318518f7daa4ba64c0aaf31799d89b.zip FreeBSD-src-3fd58f91dd318518f7daa4ba64c0aaf31799d89b.tar.gz |
Update LLVM to r94309.
Diffstat (limited to 'tools')
28 files changed, 308 insertions, 284 deletions
diff --git a/tools/bugpoint/Miscompilation.cpp b/tools/bugpoint/Miscompilation.cpp index a591417..c2b002f 100644 --- a/tools/bugpoint/Miscompilation.cpp +++ b/tools/bugpoint/Miscompilation.cpp @@ -22,7 +22,6 @@ #include "llvm/Module.h" #include "llvm/Pass.h" #include "llvm/Analysis/Verifier.h" -#include "llvm/Support/Mangler.h" #include "llvm/Transforms/Utils/Cloning.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/FileUtilities.h" @@ -235,30 +234,16 @@ bool ReduceMiscompilingFunctions::TestFuncs(const std::vector<Function*>&Funcs){ return TestFn(BD, ToOptimize, ToNotOptimize); } -/// DisambiguateGlobalSymbols - Mangle symbols to guarantee uniqueness by -/// modifying predominantly internal symbols rather than external ones. +/// DisambiguateGlobalSymbols - Give anonymous global values names. /// static void DisambiguateGlobalSymbols(Module *M) { - // Try not to cause collisions by minimizing chances of renaming an - // already-external symbol, so take in external globals and functions as-is. - // The code should work correctly without disambiguation (assuming the same - // mangler is used by the two code generators), but having symbols with the - // same name causes warnings to be emitted by the code generator. - Mangler Mang(*M); - // Agree with the CBE on symbol naming - Mang.markCharUnacceptable('.'); for (Module::global_iterator I = M->global_begin(), E = M->global_end(); - I != E; ++I) { - // Don't mangle asm names. - if (!I->hasName() || I->getName()[0] != 1) - I->setName(Mang.getMangledName(I)); - } - for (Module::iterator I = M->begin(), E = M->end(); I != E; ++I) { - // Don't mangle asm names or intrinsics. - if ((!I->hasName() || I->getName()[0] != 1) && - I->getIntrinsicID() == 0) - I->setName(Mang.getMangledName(I)); - } + I != E; ++I) + if (!I->hasName()) + I->setName("anon_global"); + for (Module::iterator I = M->begin(), E = M->end(); I != E; ++I) + if (!I->hasName()) + I->setName("anon_fn"); } /// ExtractLoops - Given a reduced list of functions that still exposed the bug, @@ -548,10 +533,6 @@ DebugAMiscompilation(BugDriver &BD, ExtractLoops(BD, TestFn, MiscompiledFunctions)) { // Okay, we extracted some loops and the problem still appears. See if we // can eliminate some of the created functions from being candidates. - - // Loop extraction can introduce functions with the same name (foo_code). - // Make sure to disambiguate the symbols so that when the program is split - // apart that we can link it back together again. DisambiguateGlobalSymbols(BD.getProgram()); // Do the reduction... @@ -569,10 +550,6 @@ DebugAMiscompilation(BugDriver &BD, ExtractBlocks(BD, TestFn, MiscompiledFunctions)) { // Okay, we extracted some blocks and the problem still appears. See if we // can eliminate some of the created functions from being candidates. - - // Block extraction can introduce functions with the same name (foo_code). - // Make sure to disambiguate the symbols so that when the program is split - // apart that we can link it back together again. DisambiguateGlobalSymbols(BD.getProgram()); // Do the reduction... diff --git a/tools/gold/Makefile b/tools/gold/Makefile index 7bac4ec..3f77229 100644 --- a/tools/gold/Makefile +++ b/tools/gold/Makefile @@ -19,6 +19,7 @@ LINK_LIBS_IN_SHARED=1 SHARED_LIBRARY = 1 BUILD_ARCHIVE = 0 LOADABLE_MODULE = 1 +CXXFLAGS = -fno-rtti LINK_COMPONENTS := support system LIBS += -llto diff --git a/tools/llc/Makefile b/tools/llc/Makefile index 7319aad..6b5b125 100644 --- a/tools/llc/Makefile +++ b/tools/llc/Makefile @@ -9,6 +9,7 @@ LEVEL = ../.. TOOLNAME = llc +CXXFLAGS = -fno-rtti # Include this here so we can get the configuration of the targets # that have been configured for construction. We have to do this diff --git a/tools/llc/llc.cpp b/tools/llc/llc.cpp index 930de26..4f93a43 100644 --- a/tools/llc/llc.cpp +++ b/tools/llc/llc.cpp @@ -366,9 +366,7 @@ int main(int argc, char **argv) { sys::Path(OutputFilename).eraseFromDisk(); return 1; case FileModel::AsmFile: - break; case FileModel::MachOFile: - OCE = AddMachOWriter(Passes, *Out, Target); break; case FileModel::ElfFile: OCE = AddELFWriter(Passes, *Out, Target); diff --git a/tools/lli/Makefile b/tools/lli/Makefile index 8f6eeed..2341bed 100644 --- a/tools/lli/Makefile +++ b/tools/lli/Makefile @@ -9,6 +9,7 @@ LEVEL := ../.. TOOLNAME := lli +CXXFLAGS = -fno-rtti LINK_COMPONENTS := jit interpreter nativecodegen bitreader selectiondag # Enable JIT support diff --git a/tools/llvm-ar/Makefile b/tools/llvm-ar/Makefile index e4fe4e8..3db7964 100644 --- a/tools/llvm-ar/Makefile +++ b/tools/llvm-ar/Makefile @@ -11,6 +11,7 @@ LEVEL = ../.. TOOLNAME = llvm-ar LINK_COMPONENTS = archive REQUIRES_EH := 1 +#CXXFLAGS = -fno-rtti # This tool has no plugins, optimize startup time. TOOL_NO_EXPORTS = 1 diff --git a/tools/llvm-as/Makefile b/tools/llvm-as/Makefile index ae449c4..d6fbd71 100644 --- a/tools/llvm-as/Makefile +++ b/tools/llvm-as/Makefile @@ -10,7 +10,7 @@ LEVEL = ../.. TOOLNAME = llvm-as LINK_COMPONENTS := asmparser bitwriter -REQUIRES_EH := 1 +CXXFLAGS = -fno-rtti # This tool has no plugins, optimize startup time. TOOL_NO_EXPORTS = 1 diff --git a/tools/llvm-bcanalyzer/Makefile b/tools/llvm-bcanalyzer/Makefile index 251f758..488387d 100644 --- a/tools/llvm-bcanalyzer/Makefile +++ b/tools/llvm-bcanalyzer/Makefile @@ -10,7 +10,6 @@ LEVEL = ../.. TOOLNAME = llvm-bcanalyzer LINK_COMPONENTS := bitreader -REQUIRES_EH := 1 # This tool has no plugins, optimize startup time. TOOL_NO_EXPORTS = 1 diff --git a/tools/llvm-config/Makefile b/tools/llvm-config/Makefile index 6eedca0..e5bdc04 100644 --- a/tools/llvm-config/Makefile +++ b/tools/llvm-config/Makefile @@ -10,7 +10,6 @@ LEVEL = ../.. EXTRA_DIST = LibDeps.txt FinalLibDeps.txt llvm-config.in.in find-cycles.pl -REQUIRES_EH := 1 include $(LEVEL)/Makefile.common diff --git a/tools/llvm-config/llvm-config.in.in b/tools/llvm-config/llvm-config.in.in index d0edda0..d435d57 100644 --- a/tools/llvm-config/llvm-config.in.in +++ b/tools/llvm-config/llvm-config.in.in @@ -18,6 +18,7 @@ use 5.006; use strict; use warnings; +use Cwd 'abs_path'; #---- begin autoconf values ---- my $PACKAGE_NAME = q{@PACKAGE_NAME@}; @@ -53,20 +54,14 @@ my $LLVM_BUILDMODE = q{@LLVM_BUILDMODE@}; # Convert the current executable name into its directory (e.g. "."). my ($RUN_DIR) = ($0 =~ /^(.*)\/.*$/); -# Find the unix pwd program: we don't want to use the bash builtin, as it does -# not look through symlinks etc. -my $PWD = `which pwd`; -chomp($PWD); -$PWD = "pwd" if (!-e $PWD); - # Turn the directory into an absolute directory on the file system, also pop up # from "bin" into the build or prefix dir. -my $ABS_RUN_DIR = `cd $RUN_DIR/..; $PWD`; +my $ABS_RUN_DIR = abs_path("$RUN_DIR/.."); chomp($ABS_RUN_DIR); # Compute the absolute object directory build, e.g. "foo/llvm/Debug". my $ABS_OBJ_ROOT = "$LLVM_OBJ_ROOT/$LLVM_BUILDMODE"; -$ABS_OBJ_ROOT = `cd $ABS_OBJ_ROOT; $PWD` if (-d $ABS_OBJ_ROOT); +$ABS_OBJ_ROOT = abs_path("$ABS_OBJ_ROOT") if (-d $ABS_OBJ_ROOT); chomp($ABS_OBJ_ROOT); my $INCLUDEDIR = "$ABS_RUN_DIR/include"; @@ -134,9 +129,9 @@ foreach my $arg (@ARGV) { } elsif ($arg eq "--build-mode") { $has_opt = 1; print "$LLVM_BUILDMODE\n"; } elsif ($arg eq "--obj-root") { - $has_opt = 1; print `cd $LLVM_OBJ_ROOT/; $PWD`; + $has_opt = 1; print abs_path("$LLVM_OBJ_ROOT/"); } elsif ($arg eq "--src-root") { - $has_opt = 1; print `cd $LLVM_SRC_ROOT/; $PWD`; + $has_opt = 1; print abs_path("$LLVM_SRC_ROOT/"); } else { usage(); } diff --git a/tools/llvm-dis/Makefile b/tools/llvm-dis/Makefile index dfd5e34..96f3cbb 100644 --- a/tools/llvm-dis/Makefile +++ b/tools/llvm-dis/Makefile @@ -10,7 +10,7 @@ LEVEL = ../.. TOOLNAME = llvm-dis LINK_COMPONENTS := bitreader -REQUIRES_EH := 1 +CXXFLAGS = -fno-rtti # This tool has no plugins, optimize startup time. TOOL_NO_EXPORTS = 1 diff --git a/tools/llvm-extract/Makefile b/tools/llvm-extract/Makefile index 5672aa3..dee0572 100644 --- a/tools/llvm-extract/Makefile +++ b/tools/llvm-extract/Makefile @@ -11,6 +11,7 @@ LEVEL = ../.. TOOLNAME = llvm-extract LINK_COMPONENTS := ipo bitreader bitwriter asmparser +CXXFLAGS = -fno-rtti # This tool has no plugins, optimize startup time. TOOL_NO_EXPORTS = 1 diff --git a/tools/llvm-ld/Makefile b/tools/llvm-ld/Makefile index 1ef9bf1..1da1966 100644 --- a/tools/llvm-ld/Makefile +++ b/tools/llvm-ld/Makefile @@ -11,5 +11,6 @@ LEVEL = ../.. TOOLNAME = llvm-ld LINK_COMPONENTS = ipo scalaropts linker archive bitwriter +CXXFLAGS = -fno-rtti include $(LEVEL)/Makefile.common diff --git a/tools/llvm-link/Makefile b/tools/llvm-link/Makefile index 2637018..de592aa 100644 --- a/tools/llvm-link/Makefile +++ b/tools/llvm-link/Makefile @@ -10,6 +10,7 @@ LEVEL = ../.. TOOLNAME = llvm-link LINK_COMPONENTS = linker bitreader bitwriter asmparser +CXXFLAGS = -fno-rtti # This tool has no plugins, optimize startup time. TOOL_NO_EXPORTS = 1 diff --git a/tools/llvm-mc/AsmLexer.cpp b/tools/llvm-mc/AsmLexer.cpp index ba0d247..234b8f3 100644 --- a/tools/llvm-mc/AsmLexer.cpp +++ b/tools/llvm-mc/AsmLexer.cpp @@ -12,7 +12,7 @@ //===----------------------------------------------------------------------===// #include "AsmLexer.h" -#include "llvm/Support/SourceMgr.h" +#include "llvm/Support/SMLoc.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Config/config.h" // for strtoull. #include "llvm/MC/MCAsmInfo.h" @@ -21,78 +21,53 @@ #include <cstdlib> using namespace llvm; -AsmLexer::AsmLexer(SourceMgr &SM, const MCAsmInfo &_MAI) : SrcMgr(SM), - MAI(_MAI) { - CurBuffer = 0; - CurBuf = SrcMgr.getMemoryBuffer(CurBuffer); - CurPtr = CurBuf->getBufferStart(); +AsmLexer::AsmLexer(const MCAsmInfo &_MAI) : MAI(_MAI) { + CurBuf = NULL; + CurPtr = NULL; TokStart = 0; } AsmLexer::~AsmLexer() { } -SMLoc AsmLexer::getLoc() const { - return SMLoc::getFromPointer(TokStart); +void AsmLexer::setBuffer(const MemoryBuffer *buf, const char *ptr) { + CurBuf = buf; + + if (ptr) + CurPtr = ptr; + else + CurPtr = CurBuf->getBufferStart(); + + TokStart = 0; } -void AsmLexer::PrintMessage(SMLoc Loc, const std::string &Msg, - const char *Type) const { - SrcMgr.PrintMessage(Loc, Msg, Type); +SMLoc AsmLexer::getLoc() const { + return SMLoc::getFromPointer(TokStart); } /// ReturnError - Set the error to the specified string at the specified /// location. This is defined to always return AsmToken::Error. AsmToken AsmLexer::ReturnError(const char *Loc, const std::string &Msg) { - PrintMessage(SMLoc::getFromPointer(Loc), Msg, "error"); - return AsmToken(AsmToken::Error, StringRef(Loc, 0)); -} - -/// EnterIncludeFile - Enter the specified file. This prints an error and -/// returns true on failure. -bool AsmLexer::EnterIncludeFile(const std::string &Filename) { - int NewBuf = SrcMgr.AddIncludeFile(Filename, SMLoc::getFromPointer(CurPtr)); - if (NewBuf == -1) - return true; + SetError(SMLoc::getFromPointer(Loc), Msg); - // Save the line number and lex buffer of the includer. - CurBuffer = NewBuf; - CurBuf = SrcMgr.getMemoryBuffer(CurBuffer); - CurPtr = CurBuf->getBufferStart(); - return false; + return AsmToken(AsmToken::Error, StringRef(Loc, 0)); } - int AsmLexer::getNextChar() { char CurChar = *CurPtr++; switch (CurChar) { default: return (unsigned char)CurChar; - case 0: { + case 0: // A nul character in the stream is either the end of the current buffer or // a random nul in the file. Disambiguate that here. if (CurPtr-1 != CurBuf->getBufferEnd()) return 0; // Just whitespace. - // If this is the end of an included file, pop the parent file off the - // include stack. - SMLoc ParentIncludeLoc = SrcMgr.getParentIncludeLoc(CurBuffer); - if (ParentIncludeLoc != SMLoc()) { - CurBuffer = SrcMgr.FindBufferContainingLoc(ParentIncludeLoc); - CurBuf = SrcMgr.getMemoryBuffer(CurBuffer); - CurPtr = ParentIncludeLoc.getPointer(); - - // Reset the token start pointer to the start of the new file. - TokStart = CurPtr; - - return getNextChar(); - } - // Otherwise, return end of file. --CurPtr; // Another call to lex will return EOF again. return EOF; } - } } /// LexIdentifier: [a-zA-Z_.][a-zA-Z0-9_$.@]* diff --git a/tools/llvm-mc/AsmLexer.h b/tools/llvm-mc/AsmLexer.h index ce292f6..1d49e4b 100644 --- a/tools/llvm-mc/AsmLexer.h +++ b/tools/llvm-mc/AsmLexer.h @@ -23,23 +23,17 @@ namespace llvm { class MemoryBuffer; -class SourceMgr; class SMLoc; class MCAsmInfo; /// AsmLexer - Lexer class for assembly files. class AsmLexer : public MCAsmLexer { - SourceMgr &SrcMgr; const MCAsmInfo &MAI; const char *CurPtr; const MemoryBuffer *CurBuf; const char *TokStart; - - /// This is the current buffer index we're lexing from as managed by the - /// SourceMgr object. - int CurBuffer; void operator=(const AsmLexer&); // DO NOT IMPLEMENT AsmLexer(const AsmLexer&); // DO NOT IMPLEMENT @@ -49,20 +43,19 @@ protected: virtual AsmToken LexToken(); public: - AsmLexer(SourceMgr &SrcMgr, const MCAsmInfo &MAI); + AsmLexer(const MCAsmInfo &MAI); ~AsmLexer(); + void setBuffer(const MemoryBuffer *buf, const char *ptr = NULL); + SMLoc getLoc() const; StringRef LexUntilEndOfStatement(); bool isAtStartOfComment(char Char); - - /// EnterIncludeFile - Enter the specified file. This returns true on failure. - bool EnterIncludeFile(const std::string &Filename); - - void PrintMessage(SMLoc Loc, const std::string &Msg, const char *Type) const; + const MCAsmInfo &getMAI() const { return MAI; } + private: int getNextChar(); AsmToken ReturnError(const char *Loc, const std::string &Msg); diff --git a/tools/llvm-mc/AsmParser.cpp b/tools/llvm-mc/AsmParser.cpp index 2eb75a7..068e506 100644 --- a/tools/llvm-mc/AsmParser.cpp +++ b/tools/llvm-mc/AsmParser.cpp @@ -29,10 +29,8 @@ #include "llvm/Target/TargetAsmParser.h" using namespace llvm; -/// getStartLoc - Get the location of the first token of this operand. -SMLoc MCParsedAsmOperand::getStartLoc() const { return SMLoc(); } -SMLoc MCParsedAsmOperand::getEndLoc() const { return SMLoc(); } +enum { DEFAULT_ADDRSPACE = 0 }; // Mach-O section uniquing. // @@ -42,8 +40,10 @@ typedef StringMap<const MCSectionMachO*> MachOUniqueMapTy; AsmParser::AsmParser(SourceMgr &_SM, MCContext &_Ctx, MCStreamer &_Out, const MCAsmInfo &_MAI) - : Lexer(_SM, _MAI), Ctx(_Ctx), Out(_Out), TargetParser(0), - SectionUniquingMap(0) { + : Lexer(_MAI), Ctx(_Ctx), Out(_Out), SrcMgr(_SM), TargetParser(0), + CurBuffer(0), SectionUniquingMap(0) { + Lexer.setBuffer(SrcMgr.getMemoryBuffer(CurBuffer)); + // Debugging directives. AddDirectiveHandler(".file", &AsmParser::ParseDirectiveFile); AddDirectiveHandler(".line", &AsmParser::ParseDirectiveLine); @@ -89,19 +89,57 @@ const MCSection *AsmParser::getMachOSection(const StringRef &Segment, } void AsmParser::Warning(SMLoc L, const Twine &Msg) { - Lexer.PrintMessage(L, Msg.str(), "warning"); + PrintMessage(L, Msg.str(), "warning"); } bool AsmParser::Error(SMLoc L, const Twine &Msg) { - Lexer.PrintMessage(L, Msg.str(), "error"); + PrintMessage(L, Msg.str(), "error"); return true; } bool AsmParser::TokError(const char *Msg) { - Lexer.PrintMessage(Lexer.getLoc(), Msg, "error"); + PrintMessage(Lexer.getLoc(), Msg, "error"); return true; } +void AsmParser::PrintMessage(SMLoc Loc, const std::string &Msg, + const char *Type) const { + SrcMgr.PrintMessage(Loc, Msg, Type); +} + +bool AsmParser::EnterIncludeFile(const std::string &Filename) { + int NewBuf = SrcMgr.AddIncludeFile(Filename, Lexer.getLoc()); + if (NewBuf == -1) + return true; + + CurBuffer = NewBuf; + + Lexer.setBuffer(SrcMgr.getMemoryBuffer(CurBuffer)); + + return false; +} + +const AsmToken &AsmParser::Lex() { + const AsmToken *tok = &Lexer.Lex(); + + if (tok->is(AsmToken::Eof)) { + // If this is the end of an included file, pop the parent file off the + // include stack. + SMLoc ParentIncludeLoc = SrcMgr.getParentIncludeLoc(CurBuffer); + if (ParentIncludeLoc != SMLoc()) { + CurBuffer = SrcMgr.FindBufferContainingLoc(ParentIncludeLoc); + Lexer.setBuffer(SrcMgr.getMemoryBuffer(CurBuffer), + ParentIncludeLoc.getPointer()); + tok = &Lexer.Lex(); + } + } + + if (tok->is(AsmToken::Error)) + PrintMessage(Lexer.getErrLoc(), Lexer.getErr(), "error"); + + return *tok; +} + bool AsmParser::Run() { // Create the initial section. // @@ -113,7 +151,7 @@ bool AsmParser::Run() { // Prime the lexer. - Lexer.Lex(); + Lex(); bool HadError = false; @@ -124,7 +162,7 @@ bool AsmParser::Run() { // Handle conditional assembly here before calling ParseStatement() if (Lexer.getKind() == AsmToken::Identifier) { // If we have an identifier, handle it as the key symbol. - AsmToken ID = Lexer.getTok(); + AsmToken ID = getTok(); SMLoc IDLoc = ID.getLoc(); StringRef IDVal = ID.getString(); @@ -180,11 +218,11 @@ bool AsmParser::ParseConditionalAssemblyDirectives(StringRef Directive, void AsmParser::EatToEndOfStatement() { while (Lexer.isNot(AsmToken::EndOfStatement) && Lexer.isNot(AsmToken::Eof)) - Lexer.Lex(); + Lex(); // Eat EOL. if (Lexer.is(AsmToken::EndOfStatement)) - Lexer.Lex(); + Lex(); } @@ -193,11 +231,12 @@ void AsmParser::EatToEndOfStatement() { /// /// parenexpr ::= expr) /// -bool AsmParser::ParseParenExpr(const MCExpr *&Res) { +bool AsmParser::ParseParenExpr(const MCExpr *&Res, SMLoc &EndLoc) { if (ParseExpression(Res)) return true; if (Lexer.isNot(AsmToken::RParen)) return TokError("expected ')' in parentheses expression"); - Lexer.Lex(); + EndLoc = Lexer.getLoc(); + Lex(); return false; } @@ -217,21 +256,22 @@ MCSymbol *AsmParser::CreateSymbol(StringRef Name) { /// primaryexpr ::= symbol /// primaryexpr ::= number /// primaryexpr ::= ~,+,- primaryexpr -bool AsmParser::ParsePrimaryExpr(const MCExpr *&Res) { +bool AsmParser::ParsePrimaryExpr(const MCExpr *&Res, SMLoc &EndLoc) { switch (Lexer.getKind()) { default: return TokError("unknown token in expression"); case AsmToken::Exclaim: - Lexer.Lex(); // Eat the operator. - if (ParsePrimaryExpr(Res)) + Lex(); // Eat the operator. + if (ParsePrimaryExpr(Res, EndLoc)) return true; Res = MCUnaryExpr::CreateLNot(Res, getContext()); return false; case AsmToken::String: case AsmToken::Identifier: { // This is a symbol reference. - MCSymbol *Sym = CreateSymbol(Lexer.getTok().getIdentifier()); - Lexer.Lex(); // Eat identifier. + MCSymbol *Sym = CreateSymbol(getTok().getIdentifier()); + EndLoc = Lexer.getLoc(); + Lex(); // Eat identifier. // If this is an absolute variable reference, substitute it now to preserve // semantics in the face of reassignment. @@ -245,33 +285,39 @@ bool AsmParser::ParsePrimaryExpr(const MCExpr *&Res) { return false; } case AsmToken::Integer: - Res = MCConstantExpr::Create(Lexer.getTok().getIntVal(), getContext()); - Lexer.Lex(); // Eat token. + Res = MCConstantExpr::Create(getTok().getIntVal(), getContext()); + EndLoc = Lexer.getLoc(); + Lex(); // Eat token. return false; case AsmToken::LParen: - Lexer.Lex(); // Eat the '('. - return ParseParenExpr(Res); + Lex(); // Eat the '('. + return ParseParenExpr(Res, EndLoc); case AsmToken::Minus: - Lexer.Lex(); // Eat the operator. - if (ParsePrimaryExpr(Res)) + Lex(); // Eat the operator. + if (ParsePrimaryExpr(Res, EndLoc)) return true; Res = MCUnaryExpr::CreateMinus(Res, getContext()); return false; case AsmToken::Plus: - Lexer.Lex(); // Eat the operator. - if (ParsePrimaryExpr(Res)) + Lex(); // Eat the operator. + if (ParsePrimaryExpr(Res, EndLoc)) return true; Res = MCUnaryExpr::CreatePlus(Res, getContext()); return false; case AsmToken::Tilde: - Lexer.Lex(); // Eat the operator. - if (ParsePrimaryExpr(Res)) + Lex(); // Eat the operator. + if (ParsePrimaryExpr(Res, EndLoc)) return true; Res = MCUnaryExpr::CreateNot(Res, getContext()); return false; } } +bool AsmParser::ParseExpression(const MCExpr *&Res) { + SMLoc EndLoc; + return ParseExpression(Res, EndLoc); +} + /// ParseExpression - Parse an expression and return it. /// /// expr ::= expr +,- expr -> lowest. @@ -279,14 +325,14 @@ bool AsmParser::ParsePrimaryExpr(const MCExpr *&Res) { /// expr ::= expr *,/,%,<<,>> expr -> highest. /// expr ::= primaryexpr /// -bool AsmParser::ParseExpression(const MCExpr *&Res) { +bool AsmParser::ParseExpression(const MCExpr *&Res, SMLoc &EndLoc) { Res = 0; - return ParsePrimaryExpr(Res) || - ParseBinOpRHS(1, Res); + return ParsePrimaryExpr(Res, EndLoc) || + ParseBinOpRHS(1, Res, EndLoc); } -bool AsmParser::ParseParenExpression(const MCExpr *&Res) { - if (ParseParenExpr(Res)) +bool AsmParser::ParseParenExpression(const MCExpr *&Res, SMLoc &EndLoc) { + if (ParseParenExpr(Res, EndLoc)) return true; return false; @@ -381,7 +427,8 @@ static unsigned getBinOpPrecedence(AsmToken::TokenKind K, /// ParseBinOpRHS - Parse all binary operators with precedence >= 'Precedence'. /// Res contains the LHS of the expression on input. -bool AsmParser::ParseBinOpRHS(unsigned Precedence, const MCExpr *&Res) { +bool AsmParser::ParseBinOpRHS(unsigned Precedence, const MCExpr *&Res, + SMLoc &EndLoc) { while (1) { MCBinaryExpr::Opcode Kind = MCBinaryExpr::Add; unsigned TokPrec = getBinOpPrecedence(Lexer.getKind(), Kind); @@ -391,18 +438,18 @@ bool AsmParser::ParseBinOpRHS(unsigned Precedence, const MCExpr *&Res) { if (TokPrec < Precedence) return false; - Lexer.Lex(); + Lex(); // Eat the next primary expression. const MCExpr *RHS; - if (ParsePrimaryExpr(RHS)) return true; + if (ParsePrimaryExpr(RHS, EndLoc)) return true; // If BinOp binds less tightly with RHS than the operator after RHS, let // the pending operator take RHS as its LHS. MCBinaryExpr::Opcode Dummy; unsigned NextTokPrec = getBinOpPrecedence(Lexer.getKind(), Dummy); if (TokPrec < NextTokPrec) { - if (ParseBinOpRHS(Precedence+1, RHS)) return true; + if (ParseBinOpRHS(Precedence+1, RHS, EndLoc)) return true; } // Merge LHS and RHS according to operator. @@ -419,12 +466,12 @@ bool AsmParser::ParseBinOpRHS(unsigned Precedence, const MCExpr *&Res) { /// ::= Label* Identifier OperandList* EndOfStatement bool AsmParser::ParseStatement() { if (Lexer.is(AsmToken::EndOfStatement)) { - Lexer.Lex(); + Lex(); return false; } // Statements always start with an identifier. - AsmToken ID = Lexer.getTok(); + AsmToken ID = getTok(); SMLoc IDLoc = ID.getLoc(); StringRef IDVal; if (ParseIdentifier(IDVal)) @@ -436,7 +483,7 @@ bool AsmParser::ParseStatement() { switch (Lexer.getKind()) { case AsmToken::Colon: { // identifier ':' -> Label. - Lexer.Lex(); + Lex(); // Diagnose attempt to use a variable as a label. // @@ -455,7 +502,7 @@ bool AsmParser::ParseStatement() { case AsmToken::Equal: // identifier '=' ... -> assignment statement - Lexer.Lex(); + Lex(); return ParseAssignment(IDVal); @@ -727,7 +774,7 @@ bool AsmParser::ParseStatement() { return TokError("unexpected token in argument list"); // Eat the end of statement marker. - Lexer.Lex(); + Lex(); MCInst Inst; @@ -764,7 +811,7 @@ bool AsmParser::ParseAssignment(const StringRef &Name) { return TokError("unexpected token in assignment"); // Eat the end of statement marker. - Lexer.Lex(); + Lex(); // Validate that the LHS is allowed to be a variable (either it has not been // used as a symbol, or it is an absolute symbol). @@ -800,9 +847,9 @@ bool AsmParser::ParseIdentifier(StringRef &Res) { Lexer.isNot(AsmToken::String)) return true; - Res = Lexer.getTok().getIdentifier(); + Res = getTok().getIdentifier(); - Lexer.Lex(); // Consume the identifier token. + Lex(); // Consume the identifier token. return false; } @@ -817,7 +864,7 @@ bool AsmParser::ParseDirectiveSet() { if (Lexer.isNot(AsmToken::Comma)) return TokError("unexpected token in '.set'"); - Lexer.Lex(); + Lex(); return ParseAssignment(Name); } @@ -845,10 +892,10 @@ bool AsmParser::ParseDirectiveDarwinSection() { StringRef EOL = Lexer.LexUntilEndOfStatement(); SectionSpec.append(EOL.begin(), EOL.end()); - Lexer.Lex(); + Lex(); if (Lexer.isNot(AsmToken::EndOfStatement)) return TokError("unexpected token in '.section' directive"); - Lexer.Lex(); + Lex(); StringRef Segment, Section; @@ -873,7 +920,7 @@ bool AsmParser::ParseDirectiveSectionSwitch(const char *Segment, unsigned StubSize) { if (Lexer.isNot(AsmToken::EndOfStatement)) return TokError("unexpected token in section switching directive"); - Lexer.Lex(); + Lex(); // FIXME: Arch specific. Out.SwitchSection(getMachOSection(Segment, Section, TAA, StubSize, @@ -897,7 +944,7 @@ bool AsmParser::ParseEscapedString(std::string &Data) { assert(Lexer.is(AsmToken::String) && "Unexpected current token!"); Data = ""; - StringRef Str = Lexer.getTok().getStringContents(); + StringRef Str = getTok().getStringContents(); for (unsigned i = 0, e = Str.size(); i != e; ++i) { if (Str[i] != '\\') { Data += Str[i]; @@ -963,22 +1010,22 @@ bool AsmParser::ParseDirectiveAscii(bool ZeroTerminated) { if (ParseEscapedString(Data)) return true; - Out.EmitBytes(Data); + Out.EmitBytes(Data, DEFAULT_ADDRSPACE); if (ZeroTerminated) - Out.EmitBytes(StringRef("\0", 1)); + Out.EmitBytes(StringRef("\0", 1), DEFAULT_ADDRSPACE); - Lexer.Lex(); + Lex(); if (Lexer.is(AsmToken::EndOfStatement)) break; if (Lexer.isNot(AsmToken::Comma)) return TokError("unexpected token in '.ascii' or '.asciz' directive"); - Lexer.Lex(); + Lex(); } } - Lexer.Lex(); + Lex(); return false; } @@ -992,7 +1039,7 @@ bool AsmParser::ParseDirectiveValue(unsigned Size) { if (ParseExpression(Value)) return true; - Out.EmitValue(Value, Size); + Out.EmitValue(Value, Size, DEFAULT_ADDRSPACE); if (Lexer.is(AsmToken::EndOfStatement)) break; @@ -1000,11 +1047,11 @@ bool AsmParser::ParseDirectiveValue(unsigned Size) { // FIXME: Improve diagnostic. if (Lexer.isNot(AsmToken::Comma)) return TokError("unexpected token in directive"); - Lexer.Lex(); + Lex(); } } - Lexer.Lex(); + Lex(); return false; } @@ -1020,7 +1067,7 @@ bool AsmParser::ParseDirectiveSpace() { if (Lexer.isNot(AsmToken::EndOfStatement)) { if (Lexer.isNot(AsmToken::Comma)) return TokError("unexpected token in '.space' directive"); - Lexer.Lex(); + Lex(); if (ParseAbsoluteExpression(FillExpr)) return true; @@ -1031,14 +1078,13 @@ bool AsmParser::ParseDirectiveSpace() { return TokError("unexpected token in '.space' directive"); } - Lexer.Lex(); + Lex(); if (NumBytes <= 0) return TokError("invalid number of bytes in '.space' directive"); // FIXME: Sometimes the fill expr is 'nop' if it isn't supplied, instead of 0. - for (uint64_t i = 0, e = NumBytes; i != e; ++i) - Out.EmitValue(MCConstantExpr::Create(FillExpr, getContext()), 1); + Out.EmitFill(NumBytes, FillExpr, DEFAULT_ADDRSPACE); return false; } @@ -1052,7 +1098,7 @@ bool AsmParser::ParseDirectiveFill() { if (Lexer.isNot(AsmToken::Comma)) return TokError("unexpected token in '.fill' directive"); - Lexer.Lex(); + Lex(); int64_t FillSize; if (ParseAbsoluteExpression(FillSize)) @@ -1060,7 +1106,7 @@ bool AsmParser::ParseDirectiveFill() { if (Lexer.isNot(AsmToken::Comma)) return TokError("unexpected token in '.fill' directive"); - Lexer.Lex(); + Lex(); int64_t FillExpr; if (ParseAbsoluteExpression(FillExpr)) @@ -1069,13 +1115,14 @@ bool AsmParser::ParseDirectiveFill() { if (Lexer.isNot(AsmToken::EndOfStatement)) return TokError("unexpected token in '.fill' directive"); - Lexer.Lex(); + Lex(); if (FillSize != 1 && FillSize != 2 && FillSize != 4 && FillSize != 8) return TokError("invalid '.fill' size, expected 1, 2, 4, or 8"); for (uint64_t i = 0, e = NumValues; i != e; ++i) - Out.EmitValue(MCConstantExpr::Create(FillExpr, getContext()), FillSize); + Out.EmitValue(MCConstantExpr::Create(FillExpr, getContext()), FillSize, + DEFAULT_ADDRSPACE); return false; } @@ -1093,7 +1140,7 @@ bool AsmParser::ParseDirectiveOrg() { if (Lexer.isNot(AsmToken::EndOfStatement)) { if (Lexer.isNot(AsmToken::Comma)) return TokError("unexpected token in '.org' directive"); - Lexer.Lex(); + Lex(); if (ParseAbsoluteExpression(FillExpr)) return true; @@ -1102,7 +1149,7 @@ bool AsmParser::ParseDirectiveOrg() { return TokError("unexpected token in '.org' directive"); } - Lexer.Lex(); + Lex(); // FIXME: Only limited forms of relocatable expressions are accepted here, it // has to be relative to the current section. @@ -1126,7 +1173,7 @@ bool AsmParser::ParseDirectiveAlign(bool IsPow2, unsigned ValueSize) { if (Lexer.isNot(AsmToken::EndOfStatement)) { if (Lexer.isNot(AsmToken::Comma)) return TokError("unexpected token in directive"); - Lexer.Lex(); + Lex(); // The fill expression can be omitted while specifying a maximum number of // alignment bytes, e.g: @@ -1140,7 +1187,7 @@ bool AsmParser::ParseDirectiveAlign(bool IsPow2, unsigned ValueSize) { if (Lexer.isNot(AsmToken::EndOfStatement)) { if (Lexer.isNot(AsmToken::Comma)) return TokError("unexpected token in directive"); - Lexer.Lex(); + Lex(); MaxBytesLoc = Lexer.getLoc(); if (ParseAbsoluteExpression(MaxBytesToFill)) @@ -1151,7 +1198,7 @@ bool AsmParser::ParseDirectiveAlign(bool IsPow2, unsigned ValueSize) { } } - Lexer.Lex(); + Lex(); if (!HasFillExpr) { // FIXME: Sometimes fill with nop. @@ -1209,11 +1256,11 @@ bool AsmParser::ParseDirectiveSymbolAttribute(MCStreamer::SymbolAttr Attr) { if (Lexer.isNot(AsmToken::Comma)) return TokError("unexpected token in directive"); - Lexer.Lex(); + Lex(); } } - Lexer.Lex(); + Lex(); return false; } @@ -1229,7 +1276,7 @@ bool AsmParser::ParseDirectiveDarwinSymbolDesc() { if (Lexer.isNot(AsmToken::Comma)) return TokError("unexpected token in '.desc' directive"); - Lexer.Lex(); + Lex(); SMLoc DescLoc = Lexer.getLoc(); int64_t DescValue; @@ -1239,7 +1286,7 @@ bool AsmParser::ParseDirectiveDarwinSymbolDesc() { if (Lexer.isNot(AsmToken::EndOfStatement)) return TokError("unexpected token in '.desc' directive"); - Lexer.Lex(); + Lex(); // Set the n_desc field of this Symbol to this DescValue Out.EmitSymbolDesc(Sym, DescValue); @@ -1260,7 +1307,7 @@ bool AsmParser::ParseDirectiveComm(bool IsLocal) { if (Lexer.isNot(AsmToken::Comma)) return TokError("unexpected token in directive"); - Lexer.Lex(); + Lex(); int64_t Size; SMLoc SizeLoc = Lexer.getLoc(); @@ -1270,16 +1317,23 @@ bool AsmParser::ParseDirectiveComm(bool IsLocal) { int64_t Pow2Alignment = 0; SMLoc Pow2AlignmentLoc; if (Lexer.is(AsmToken::Comma)) { - Lexer.Lex(); + Lex(); Pow2AlignmentLoc = Lexer.getLoc(); if (ParseAbsoluteExpression(Pow2Alignment)) return true; + + // If this target takes alignments in bytes (not log) validate and convert. + if (Lexer.getMAI().getAlignmentIsInBytes()) { + if (!isPowerOf2_64(Pow2Alignment)) + return Error(Pow2AlignmentLoc, "alignment must be a power of 2"); + Pow2Alignment = Log2_64(Pow2Alignment); + } } if (Lexer.isNot(AsmToken::EndOfStatement)) return TokError("unexpected token in '.comm' or '.lcomm' directive"); - Lexer.Lex(); + Lex(); // NOTE: a size of zero for a .comm should create a undefined symbol // but a size of .lcomm creates a bss symbol of size zero. @@ -1319,18 +1373,18 @@ bool AsmParser::ParseDirectiveDarwinZerofill() { if (Lexer.isNot(AsmToken::Identifier)) return TokError("expected segment name after '.zerofill' directive"); - StringRef Segment = Lexer.getTok().getString(); - Lexer.Lex(); + StringRef Segment = getTok().getString(); + Lex(); if (Lexer.isNot(AsmToken::Comma)) return TokError("unexpected token in directive"); - Lexer.Lex(); + Lex(); if (Lexer.isNot(AsmToken::Identifier)) return TokError("expected section name after comma in '.zerofill' " "directive"); - StringRef Section = Lexer.getTok().getString(); - Lexer.Lex(); + StringRef Section = getTok().getString(); + Lex(); // If this is the end of the line all that was wanted was to create the // the section but with no symbol. @@ -1344,19 +1398,19 @@ bool AsmParser::ParseDirectiveDarwinZerofill() { if (Lexer.isNot(AsmToken::Comma)) return TokError("unexpected token in directive"); - Lexer.Lex(); + Lex(); if (Lexer.isNot(AsmToken::Identifier)) return TokError("expected identifier in directive"); // handle the identifier as the key symbol. SMLoc IDLoc = Lexer.getLoc(); - MCSymbol *Sym = CreateSymbol(Lexer.getTok().getString()); - Lexer.Lex(); + MCSymbol *Sym = CreateSymbol(getTok().getString()); + Lex(); if (Lexer.isNot(AsmToken::Comma)) return TokError("unexpected token in directive"); - Lexer.Lex(); + Lex(); int64_t Size; SMLoc SizeLoc = Lexer.getLoc(); @@ -1366,7 +1420,7 @@ bool AsmParser::ParseDirectiveDarwinZerofill() { int64_t Pow2Alignment = 0; SMLoc Pow2AlignmentLoc; if (Lexer.is(AsmToken::Comma)) { - Lexer.Lex(); + Lex(); Pow2AlignmentLoc = Lexer.getLoc(); if (ParseAbsoluteExpression(Pow2Alignment)) return true; @@ -1375,7 +1429,7 @@ bool AsmParser::ParseDirectiveDarwinZerofill() { if (Lexer.isNot(AsmToken::EndOfStatement)) return TokError("unexpected token in '.zerofill' directive"); - Lexer.Lex(); + Lex(); if (Size < 0) return Error(SizeLoc, "invalid '.zerofill' directive size, can't be less " @@ -1408,7 +1462,7 @@ bool AsmParser::ParseDirectiveDarwinSubsectionsViaSymbols() { if (Lexer.isNot(AsmToken::EndOfStatement)) return TokError("unexpected token in '.subsections_via_symbols' directive"); - Lexer.Lex(); + Lex(); Out.EmitAssemblerFlag(MCStreamer::SubsectionsViaSymbols); @@ -1426,15 +1480,15 @@ bool AsmParser::ParseDirectiveAbort() { if (Lexer.isNot(AsmToken::String)) return TokError("expected string in '.abort' directive"); - Str = Lexer.getTok().getString(); + Str = getTok().getString(); - Lexer.Lex(); + Lex(); } if (Lexer.isNot(AsmToken::EndOfStatement)) return TokError("unexpected token in '.abort' directive"); - Lexer.Lex(); + Lex(); // FIXME: Handle here. if (Str.empty()) @@ -1457,7 +1511,7 @@ bool AsmParser::ParseDirectiveDarwinLsym() { if (Lexer.isNot(AsmToken::Comma)) return TokError("unexpected token in '.lsym' directive"); - Lexer.Lex(); + Lex(); const MCExpr *Value; SMLoc StartLoc = Lexer.getLoc(); @@ -1467,7 +1521,7 @@ bool AsmParser::ParseDirectiveDarwinLsym() { if (Lexer.isNot(AsmToken::EndOfStatement)) return TokError("unexpected token in '.lsym' directive"); - Lexer.Lex(); + Lex(); // We don't currently support this directive. // @@ -1482,9 +1536,9 @@ bool AsmParser::ParseDirectiveInclude() { if (Lexer.isNot(AsmToken::String)) return TokError("expected string in '.include' directive"); - std::string Filename = Lexer.getTok().getString(); + std::string Filename = getTok().getString(); SMLoc IncludeLoc = Lexer.getLoc(); - Lexer.Lex(); + Lex(); if (Lexer.isNot(AsmToken::EndOfStatement)) return TokError("unexpected token in '.include' directive"); @@ -1494,10 +1548,10 @@ bool AsmParser::ParseDirectiveInclude() { // Attempt to switch the lexer to the included file before consuming the end // of statement to avoid losing it when we switch. - if (Lexer.EnterIncludeFile(Filename)) { - Lexer.PrintMessage(IncludeLoc, - "Could not find include file '" + Filename + "'", - "error"); + if (EnterIncludeFile(Filename)) { + PrintMessage(IncludeLoc, + "Could not find include file '" + Filename + "'", + "error"); return true; } @@ -1510,12 +1564,12 @@ bool AsmParser::ParseDirectiveDarwinDumpOrLoad(SMLoc IDLoc, bool IsDump) { if (Lexer.isNot(AsmToken::String)) return TokError("expected string in '.dump' or '.load' directive"); - Lexer.Lex(); + Lex(); if (Lexer.isNot(AsmToken::EndOfStatement)) return TokError("unexpected token in '.dump' or '.load' directive"); - Lexer.Lex(); + Lex(); // FIXME: If/when .dump and .load are implemented they will be done in the // the assembly parser and not have any need for an MCStreamer API. @@ -1531,7 +1585,7 @@ bool AsmParser::ParseDirectiveDarwinDumpOrLoad(SMLoc IDLoc, bool IsDump) { /// ::= .if expression bool AsmParser::ParseDirectiveIf(SMLoc DirectiveLoc) { // Consume the identifier that was the .if directive - Lexer.Lex(); + Lex(); TheCondStack.push_back(TheCondState); TheCondState.TheCond = AsmCond::IfCond; @@ -1546,7 +1600,7 @@ bool AsmParser::ParseDirectiveIf(SMLoc DirectiveLoc) { if (Lexer.isNot(AsmToken::EndOfStatement)) return TokError("unexpected token in '.if' directive"); - Lexer.Lex(); + Lex(); TheCondState.CondMet = ExprValue; TheCondState.Ignore = !TheCondState.CondMet; @@ -1565,7 +1619,7 @@ bool AsmParser::ParseDirectiveElseIf(SMLoc DirectiveLoc) { TheCondState.TheCond = AsmCond::ElseIfCond; // Consume the identifier that was the .elseif directive - Lexer.Lex(); + Lex(); bool LastIgnoreState = false; if (!TheCondStack.empty()) @@ -1582,7 +1636,7 @@ bool AsmParser::ParseDirectiveElseIf(SMLoc DirectiveLoc) { if (Lexer.isNot(AsmToken::EndOfStatement)) return TokError("unexpected token in '.elseif' directive"); - Lexer.Lex(); + Lex(); TheCondState.CondMet = ExprValue; TheCondState.Ignore = !TheCondState.CondMet; } @@ -1594,12 +1648,12 @@ bool AsmParser::ParseDirectiveElseIf(SMLoc DirectiveLoc) { /// ::= .else bool AsmParser::ParseDirectiveElse(SMLoc DirectiveLoc) { // Consume the identifier that was the .else directive - Lexer.Lex(); + Lex(); if (Lexer.isNot(AsmToken::EndOfStatement)) return TokError("unexpected token in '.else' directive"); - Lexer.Lex(); + Lex(); if (TheCondState.TheCond != AsmCond::IfCond && TheCondState.TheCond != AsmCond::ElseIfCond) @@ -1621,12 +1675,12 @@ bool AsmParser::ParseDirectiveElse(SMLoc DirectiveLoc) { /// ::= .endif bool AsmParser::ParseDirectiveEndIf(SMLoc DirectiveLoc) { // Consume the identifier that was the .endif directive - Lexer.Lex(); + Lex(); if (Lexer.isNot(AsmToken::EndOfStatement)) return TokError("unexpected token in '.endif' directive"); - Lexer.Lex(); + Lex(); if ((TheCondState.TheCond == AsmCond::NoCond) || TheCondStack.empty()) @@ -1646,8 +1700,8 @@ bool AsmParser::ParseDirectiveFile(StringRef, SMLoc DirectiveLoc) { // FIXME: I'm not sure what this is. int64_t FileNumber = -1; if (Lexer.is(AsmToken::Integer)) { - FileNumber = Lexer.getTok().getIntVal(); - Lexer.Lex(); + FileNumber = getTok().getIntVal(); + Lex(); if (FileNumber < 1) return TokError("file number less than one"); @@ -1656,8 +1710,8 @@ bool AsmParser::ParseDirectiveFile(StringRef, SMLoc DirectiveLoc) { if (Lexer.isNot(AsmToken::String)) return TokError("unexpected token in '.file' directive"); - StringRef ATTRIBUTE_UNUSED FileName = Lexer.getTok().getString(); - Lexer.Lex(); + StringRef ATTRIBUTE_UNUSED FileName = getTok().getString(); + Lex(); if (Lexer.isNot(AsmToken::EndOfStatement)) return TokError("unexpected token in '.file' directive"); @@ -1674,9 +1728,9 @@ bool AsmParser::ParseDirectiveLine(StringRef, SMLoc DirectiveLoc) { if (Lexer.isNot(AsmToken::Integer)) return TokError("unexpected token in '.line' directive"); - int64_t LineNumber = Lexer.getTok().getIntVal(); + int64_t LineNumber = getTok().getIntVal(); (void) LineNumber; - Lexer.Lex(); + Lex(); // FIXME: Do something with the .line. } @@ -1695,26 +1749,26 @@ bool AsmParser::ParseDirectiveLoc(StringRef, SMLoc DirectiveLoc) { return TokError("unexpected token in '.loc' directive"); // FIXME: What are these fields? - int64_t FileNumber = Lexer.getTok().getIntVal(); + int64_t FileNumber = getTok().getIntVal(); (void) FileNumber; // FIXME: Validate file. - Lexer.Lex(); + Lex(); if (Lexer.isNot(AsmToken::EndOfStatement)) { if (Lexer.isNot(AsmToken::Integer)) return TokError("unexpected token in '.loc' directive"); - int64_t Param2 = Lexer.getTok().getIntVal(); + int64_t Param2 = getTok().getIntVal(); (void) Param2; - Lexer.Lex(); + Lex(); if (Lexer.isNot(AsmToken::EndOfStatement)) { if (Lexer.isNot(AsmToken::Integer)) return TokError("unexpected token in '.loc' directive"); - int64_t Param3 = Lexer.getTok().getIntVal(); + int64_t Param3 = getTok().getIntVal(); (void) Param3; - Lexer.Lex(); + Lex(); // FIXME: Do something with the .loc. } diff --git a/tools/llvm-mc/AsmParser.h b/tools/llvm-mc/AsmParser.h index 171dfcd..9336d35 100644 --- a/tools/llvm-mc/AsmParser.h +++ b/tools/llvm-mc/AsmParser.h @@ -25,21 +25,28 @@ namespace llvm { class AsmCond; +class AsmToken; class MCContext; class MCExpr; class MCInst; class MCStreamer; class MCAsmInfo; class MCValue; +class SourceMgr; class TargetAsmParser; class Twine; class AsmParser : public MCAsmParser { -private: +private: AsmLexer Lexer; MCContext &Ctx; MCStreamer &Out; + SourceMgr &SrcMgr; TargetAsmParser *TargetParser; + + /// This is the current buffer index we're lexing from as managed by the + /// SourceMgr object. + int CurBuffer; AsmCond TheCondState; std::vector<AsmCond> TheCondStack; @@ -79,8 +86,11 @@ public: virtual void Warning(SMLoc L, const Twine &Meg); virtual bool Error(SMLoc L, const Twine &Msg); - virtual bool ParseExpression(const MCExpr *&Res); - virtual bool ParseParenExpression(const MCExpr *&Res); + const AsmToken &Lex(); + + bool ParseExpression(const MCExpr *&Res); + virtual bool ParseExpression(const MCExpr *&Res, SMLoc &EndLoc); + virtual bool ParseParenExpression(const MCExpr *&Res, SMLoc &EndLoc); virtual bool ParseAbsoluteExpression(int64_t &Res); /// } @@ -99,15 +109,20 @@ private: bool TokError(const char *Msg); + void PrintMessage(SMLoc Loc, const std::string &Msg, const char *Type) const; + + /// EnterIncludeFile - Enter the specified file. This returns true on failure. + bool EnterIncludeFile(const std::string &Filename); + bool ParseConditionalAssemblyDirectives(StringRef Directive, SMLoc DirectiveLoc); void EatToEndOfStatement(); bool ParseAssignment(const StringRef &Name); - bool ParsePrimaryExpr(const MCExpr *&Res); - bool ParseBinOpRHS(unsigned Precedence, const MCExpr *&Res); - bool ParseParenExpr(const MCExpr *&Res); + bool ParsePrimaryExpr(const MCExpr *&Res, SMLoc &EndLoc); + bool ParseBinOpRHS(unsigned Precedence, const MCExpr *&Res, SMLoc &EndLoc); + bool ParseParenExpr(const MCExpr *&Res, SMLoc &EndLoc); /// ParseIdentifier - Parse an identifier or string (as a quoted identifier) /// and set \arg Res to the identifier contents. diff --git a/tools/llvm-mc/CMakeLists.txt b/tools/llvm-mc/CMakeLists.txt index 46c5c6b..49c2932 100644 --- a/tools/llvm-mc/CMakeLists.txt +++ b/tools/llvm-mc/CMakeLists.txt @@ -1,8 +1,6 @@ -set(LLVM_LINK_COMPONENTS ${LLVM_TARGETS_TO_BUILD} support MC) +set(LLVM_LINK_COMPONENTS ${LLVM_TARGETS_TO_BUILD} support MC MCParser) add_llvm_tool(llvm-mc llvm-mc.cpp - AsmLexer.cpp - AsmParser.cpp Disassembler.cpp ) diff --git a/tools/llvm-mc/Makefile b/tools/llvm-mc/Makefile index 9bfb773..5ce1a8f 100644 --- a/tools/llvm-mc/Makefile +++ b/tools/llvm-mc/Makefile @@ -13,12 +13,13 @@ TOOLNAME = llvm-mc # This tool has no plugins, optimize startup time. TOOL_NO_EXPORTS = 1 NO_INSTALL = 1 +CXXFLAGS = -fno-rtti # Include this here so we can get the configuration of the targets # that have been configured for construction. We have to do this # early so we can set up LINK_COMPONENTS before including Makefile.rules include $(LEVEL)/Makefile.config -LINK_COMPONENTS := $(TARGETS_TO_BUILD) MC support +LINK_COMPONENTS := $(TARGETS_TO_BUILD) MCParser MC support include $(LLVM_SRC_ROOT)/Makefile.rules diff --git a/tools/llvm-mc/llvm-mc.cpp b/tools/llvm-mc/llvm-mc.cpp index 30cdfba..342ae99 100644 --- a/tools/llvm-mc/llvm-mc.cpp +++ b/tools/llvm-mc/llvm-mc.cpp @@ -12,7 +12,7 @@ // //===----------------------------------------------------------------------===// -#include "llvm/MC/MCAsmLexer.h" +#include "llvm/MC/MCParser/MCAsmLexer.h" #include "llvm/MC/MCContext.h" #include "llvm/MC/MCCodeEmitter.h" #include "llvm/MC/MCInstPrinter.h" @@ -28,10 +28,11 @@ #include "llvm/Support/raw_ostream.h" #include "llvm/System/Signals.h" #include "llvm/Target/TargetAsmParser.h" +#include "llvm/Target/TargetData.h" #include "llvm/Target/TargetRegistry.h" #include "llvm/Target/TargetMachine.h" // FIXME. #include "llvm/Target/TargetSelect.h" -#include "AsmParser.h" +#include "llvm/MC/MCParser/AsmParser.h" #include "Disassembler.h" using namespace llvm; @@ -133,14 +134,14 @@ static int AsLexInput(const char *ProgName) { const MCAsmInfo *MAI = TheTarget->createAsmInfo(TripleName); assert(MAI && "Unable to create target asm info!"); - AsmLexer Lexer(SrcMgr, *MAI); + AsmLexer Lexer(*MAI); bool Error = false; while (Lexer.Lex().isNot(AsmToken::Eof)) { switch (Lexer.getKind()) { default: - Lexer.PrintMessage(Lexer.getLoc(), "unknown token", "warning"); + SrcMgr.PrintMessage(Lexer.getLoc(), "unknown token", "warning"); Error = true; break; case AsmToken::Error: @@ -263,7 +264,9 @@ static int AssembleInput(const char *ProgName) { IP.reset(TheTarget->createMCInstPrinter(OutputAsmVariant, *MAI, *Out)); if (ShowEncoding) CE.reset(TheTarget->createCodeEmitter(*TM)); - Str.reset(createAsmStreamer(Ctx, *Out, *MAI, IP.get(), CE.get())); + Str.reset(createAsmStreamer(Ctx, *Out, *MAI, + TM->getTargetData()->isLittleEndian(), + /*asmverbose*/true, IP.get(), CE.get())); } else { assert(FileType == OFT_ObjectFile && "Invalid file type!"); CE.reset(TheTarget->createCodeEmitter(*TM)); diff --git a/tools/llvm-nm/Makefile b/tools/llvm-nm/Makefile index ecf5f8c..bdefaa6 100644 --- a/tools/llvm-nm/Makefile +++ b/tools/llvm-nm/Makefile @@ -13,5 +13,6 @@ LINK_COMPONENTS = archive bitreader # This tool has no plugins, optimize startup time. TOOL_NO_EXPORTS = 1 +CXXFLAGS = -fno-rtti include $(LEVEL)/Makefile.common diff --git a/tools/llvm-prof/Makefile b/tools/llvm-prof/Makefile index 86eb54d..b1fd330 100644 --- a/tools/llvm-prof/Makefile +++ b/tools/llvm-prof/Makefile @@ -13,5 +13,6 @@ LINK_COMPONENTS = bitreader analysis # This tool has no plugins, optimize startup time. TOOL_NO_EXPORTS = 1 +CXXFLAGS = -fno-rtti include $(LEVEL)/Makefile.common diff --git a/tools/lto/LTOCodeGenerator.cpp b/tools/lto/LTOCodeGenerator.cpp index 93eb0a5..46e967a 100644 --- a/tools/lto/LTOCodeGenerator.cpp +++ b/tools/lto/LTOCodeGenerator.cpp @@ -32,13 +32,13 @@ #include "llvm/CodeGen/FileWriters.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/FormattedStream.h" -#include "llvm/Support/Mangler.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/StandardPasses.h" #include "llvm/Support/SystemUtils.h" #include "llvm/System/Host.h" #include "llvm/System/Program.h" #include "llvm/System/Signals.h" +#include "llvm/Target/Mangler.h" #include "llvm/Target/SubtargetFeature.h" #include "llvm/Target/TargetOptions.h" #include "llvm/MC/MCAsmInfo.h" @@ -323,19 +323,18 @@ void LTOCodeGenerator::applyScopeRestrictions() // mark which symbols can not be internalized if ( !_mustPreserveSymbols.empty() ) { - Mangler mangler(*mergedModule, - _target->getMCAsmInfo()->getGlobalPrefix()); + Mangler mangler(*_target->getMCAsmInfo()); std::vector<const char*> mustPreserveList; for (Module::iterator f = mergedModule->begin(), e = mergedModule->end(); f != e; ++f) { if ( !f->isDeclaration() - && _mustPreserveSymbols.count(mangler.getMangledName(f)) ) + && _mustPreserveSymbols.count(mangler.getNameWithPrefix(f)) ) mustPreserveList.push_back(::strdup(f->getNameStr().c_str())); } for (Module::global_iterator v = mergedModule->global_begin(), e = mergedModule->global_end(); v != e; ++v) { if ( !v->isDeclaration() - && _mustPreserveSymbols.count(mangler.getMangledName(v)) ) + && _mustPreserveSymbols.count(mangler.getNameWithPrefix(v)) ) mustPreserveList.push_back(::strdup(v->getNameStr().c_str())); } passes.add(createInternalizePass(mustPreserveList)); @@ -403,14 +402,12 @@ bool LTOCodeGenerator::generateAssemblyCode(formatted_raw_ostream& out, switch (_target->addPassesToEmitFile(*codeGenPasses, out, TargetMachine::AssemblyFile, CodeGenOpt::Aggressive)) { - case FileModel::MachOFile: - oce = AddMachOWriter(*codeGenPasses, out, *_target); - break; case FileModel::ElfFile: oce = AddELFWriter(*codeGenPasses, out, *_target); break; case FileModel::AsmFile: break; + case FileModel::MachOFile: case FileModel::Error: case FileModel::None: errMsg = "target file type not supported"; diff --git a/tools/lto/LTOModule.cpp b/tools/lto/LTOModule.cpp index bce4162..64de668 100644 --- a/tools/lto/LTOModule.cpp +++ b/tools/lto/LTOModule.cpp @@ -22,12 +22,12 @@ #include "llvm/ADT/Triple.h" #include "llvm/Bitcode/ReaderWriter.h" #include "llvm/Support/SystemUtils.h" -#include "llvm/Support/Mangler.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/MathExtras.h" #include "llvm/System/Host.h" #include "llvm/System/Path.h" #include "llvm/System/Process.h" +#include "llvm/Target/Mangler.h" #include "llvm/Target/SubtargetFeature.h" #include "llvm/MC/MCAsmInfo.h" #include "llvm/Target/TargetMachine.h" @@ -320,7 +320,7 @@ void LTOModule::addDefinedSymbol(GlobalValue* def, Mangler &mangler, return; // string is owned by _defines - const char* symbolName = ::strdup(mangler.getMangledName(def).c_str()); + const char* symbolName = ::strdup(mangler.getNameWithPrefix(def).c_str()); // set alignment part log2() can have rounding errors uint32_t align = def->getAlignment(); @@ -393,7 +393,7 @@ void LTOModule::addPotentialUndefinedSymbol(GlobalValue* decl, Mangler &mangler) if (isa<GlobalAlias>(decl)) return; - std::string name = mangler.getMangledName(decl); + std::string name = mangler.getNameWithPrefix(decl); // we already have the symbol if (_undefines.find(name) != _undefines.end()) @@ -439,15 +439,7 @@ void LTOModule::lazyParseSymbols() _symbolsParsed = true; // Use mangler to add GlobalPrefix to names to match linker names. - Mangler mangler(*_module, _target->getMCAsmInfo()->getGlobalPrefix()); - // add chars used in ObjC method names so method names aren't mangled - mangler.markCharAcceptable('['); - mangler.markCharAcceptable(']'); - mangler.markCharAcceptable('('); - mangler.markCharAcceptable(')'); - mangler.markCharAcceptable('-'); - mangler.markCharAcceptable('+'); - mangler.markCharAcceptable(' '); + Mangler mangler(*_target->getMCAsmInfo()); // add functions for (Module::iterator f = _module->begin(); f != _module->end(); ++f) { diff --git a/tools/lto/Makefile b/tools/lto/Makefile index 3120aa5..f0bc67c 100644 --- a/tools/lto/Makefile +++ b/tools/lto/Makefile @@ -17,6 +17,7 @@ include $(LEVEL)/Makefile.config LINK_LIBS_IN_SHARED = 1 SHARED_LIBRARY = 1 +CXXFLAGS = -fno-rtti LINK_COMPONENTS := $(TARGETS_TO_BUILD) ipo scalaropts linker bitreader bitwriter diff --git a/tools/opt/Makefile b/tools/opt/Makefile index 726cad8..2f184a6 100644 --- a/tools/opt/Makefile +++ b/tools/opt/Makefile @@ -8,6 +8,7 @@ ##===----------------------------------------------------------------------===## LEVEL = ../.. TOOLNAME = opt +CXXFLAGS = -fno-rtti LINK_COMPONENTS := bitreader bitwriter asmparser instrumentation scalaropts ipo diff --git a/tools/opt/opt.cpp b/tools/opt/opt.cpp index a636bd9..6ed8c9d 100644 --- a/tools/opt/opt.cpp +++ b/tools/opt/opt.cpp @@ -288,7 +288,17 @@ void AddOptimizationPasses(PassManager &MPM, FunctionPassManager &FPM, unsigned OptLevel) { createStandardFunctionPasses(&FPM, OptLevel); - llvm::Pass *InliningPass = OptLevel > 1 ? createFunctionInliningPass() : 0; + llvm::Pass *InliningPass = 0; + if (DisableInline) { + // No inlining pass + } else if (OptLevel) { + unsigned Threshold = 200; + if (OptLevel > 2) + Threshold = 250; + InliningPass = createFunctionInliningPass(Threshold); + } else { + InliningPass = createAlwaysInlinerPass(); + } createStandardModulePasses(&MPM, OptLevel, /*OptimizeSize=*/ false, UnitAtATime, @@ -373,24 +383,29 @@ int main(int argc, char **argv) { // FIXME: outs() is not binary! raw_ostream *Out = &outs(); // Default to printing to stdout... if (OutputFilename != "-") { - // Make sure that the Output file gets unlinked from the disk if we get a - // SIGINT - sys::RemoveFileOnSignal(sys::Path(OutputFilename)); - - std::string ErrorInfo; - Out = new raw_fd_ostream(OutputFilename.c_str(), ErrorInfo, - raw_fd_ostream::F_Binary); - if (!ErrorInfo.empty()) { - errs() << ErrorInfo << '\n'; - delete Out; - return 1; + if (NoOutput || AnalyzeOnly) { + errs() << "WARNING: The -o (output filename) option is ignored when\n" + "the --disable-output or --analyze options are used.\n"; + } else { + // Make sure that the Output file gets unlinked from the disk if we get a + // SIGINT + sys::RemoveFileOnSignal(sys::Path(OutputFilename)); + + std::string ErrorInfo; + Out = new raw_fd_ostream(OutputFilename.c_str(), ErrorInfo, + raw_fd_ostream::F_Binary); + if (!ErrorInfo.empty()) { + errs() << ErrorInfo << '\n'; + delete Out; + return 1; + } } } // If the output is set to be emitted to standard out, and standard out is a // console, print out a warning message and refuse to do it. We don't // impress anyone by spewing tons of binary goo to a terminal. - if (!Force && !NoOutput && !OutputAssembly) + if (!Force && !NoOutput && !AnalyzeOnly && !OutputAssembly) if (CheckBitcodeOutputToConsole(*Out, !Quiet)) NoOutput = true; @@ -461,24 +476,26 @@ int main(int argc, char **argv) { errs() << argv[0] << ": cannot create pass: " << PassInf->getPassName() << "\n"; if (P) { - bool isBBPass = dynamic_cast<BasicBlockPass*>(P) != 0; - bool isLPass = !isBBPass && dynamic_cast<LoopPass*>(P) != 0; - bool isFPass = !isLPass && dynamic_cast<FunctionPass*>(P) != 0; - bool isCGSCCPass = !isFPass && dynamic_cast<CallGraphSCCPass*>(P) != 0; - addPass(Passes, P); if (AnalyzeOnly) { - if (isBBPass) + switch (P->getPassKind()) { + case PT_BasicBlock: Passes.add(new BasicBlockPassPrinter(PassInf)); - else if (isLPass) + break; + case PT_Loop: Passes.add(new LoopPassPrinter(PassInf)); - else if (isFPass) + break; + case PT_Function: Passes.add(new FunctionPassPrinter(PassInf)); - else if (isCGSCCPass) + break; + case PT_CallGraphSCC: Passes.add(new CallGraphSCCPassPrinter(PassInf)); - else + break; + default: Passes.add(new ModulePassPrinter(PassInf)); + break; + } } } @@ -517,7 +534,7 @@ int main(int argc, char **argv) { if (!NoVerify && !VerifyEach) Passes.add(createVerifierPass()); - // Write bitcode or assembly out to disk or outs() as the last step... + // Write bitcode or assembly out to disk or outs() as the last step... if (!NoOutput && !AnalyzeOnly) { if (OutputAssembly) Passes.add(createPrintModulePass(Out)); |