diff options
Diffstat (limited to 'tools')
-rw-r--r-- | tools/gold/Makefile | 1 | ||||
-rw-r--r-- | tools/lli/lli.cpp | 7 | ||||
-rw-r--r-- | tools/llvm-mc/AsmLexer.cpp | 25 | ||||
-rw-r--r-- | tools/llvm-mc/AsmLexer.h | 12 | ||||
-rw-r--r-- | tools/llvm-mc/AsmParser.cpp | 384 | ||||
-rw-r--r-- | tools/llvm-mc/AsmParser.h | 21 | ||||
-rw-r--r-- | tools/llvm-mc/CMakeLists.txt | 2 | ||||
-rw-r--r-- | tools/llvm-mc/Makefile | 2 | ||||
-rw-r--r-- | tools/llvm-mc/llvm-mc.cpp | 11 | ||||
-rw-r--r-- | tools/llvmc/doc/LLVMC-Reference.rst | 9 | ||||
-rw-r--r-- | tools/llvmc/driver/Makefile | 11 | ||||
-rw-r--r-- | tools/llvmc/example/Skeleton/Makefile | 2 | ||||
-rw-r--r-- | tools/llvmc/example/Skeleton/driver/Makefile | 11 | ||||
-rw-r--r-- | tools/llvmc/example/mcc16/Makefile | 6 | ||||
-rw-r--r-- | tools/llvmc/example/mcc16/driver/Makefile | 11 | ||||
-rw-r--r-- | tools/lto/LTOCodeGenerator.cpp | 2 | ||||
-rw-r--r-- | tools/lto/Makefile | 1 | ||||
-rw-r--r-- | tools/lto/lto.cpp | 13 | ||||
-rw-r--r-- | tools/opt/GraphPrinters.cpp | 3 |
19 files changed, 465 insertions, 69 deletions
diff --git a/tools/gold/Makefile b/tools/gold/Makefile index f282a35..65e99bf 100644 --- a/tools/gold/Makefile +++ b/tools/gold/Makefile @@ -18,7 +18,6 @@ include $(LEVEL)/Makefile.config LINK_LIBS_IN_SHARED=1 SHARED_LIBRARY = 1 BUILD_ARCHIVE = 0 -DONT_BUILD_RELINKED = 1 LINK_COMPONENTS := LIBS += -llto diff --git a/tools/lli/lli.cpp b/tools/lli/lli.cpp index afd3c5a..2553674 100644 --- a/tools/lli/lli.cpp +++ b/tools/lli/lli.cpp @@ -18,9 +18,10 @@ #include "llvm/Type.h" #include "llvm/Bitcode/ReaderWriter.h" #include "llvm/CodeGen/LinkAllCodegenComponents.h" -#include "llvm/ExecutionEngine/JIT.h" -#include "llvm/ExecutionEngine/Interpreter.h" #include "llvm/ExecutionEngine/GenericValue.h" +#include "llvm/ExecutionEngine/Interpreter.h" +#include "llvm/ExecutionEngine/JIT.h" +#include "llvm/ExecutionEngine/JITEventListener.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/ManagedStatic.h" #include "llvm/Support/MemoryBuffer.h" @@ -149,6 +150,8 @@ int main(int argc, char **argv, char * const *envp) { exit(1); } + EE->RegisterJITEventListener(createMacOSJITEventListener()); + if (NoLazyCompilation) EE->DisableLazyCompilation(); diff --git a/tools/llvm-mc/AsmLexer.cpp b/tools/llvm-mc/AsmLexer.cpp index dbd3c06..db86825 100644 --- a/tools/llvm-mc/AsmLexer.cpp +++ b/tools/llvm-mc/AsmLexer.cpp @@ -12,6 +12,7 @@ //===----------------------------------------------------------------------===// #include "AsmLexer.h" +#include "llvm/ADT/StringSet.h" #include "llvm/Support/SourceMgr.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Config/config.h" // for strtoull. @@ -20,11 +21,21 @@ #include <cstdlib> using namespace llvm; +static StringSet<> &getSS(void *TheSS) { + return *(StringSet<>*)TheSS; +} + AsmLexer::AsmLexer(SourceMgr &SM) : SrcMgr(SM) { CurBuffer = 0; CurBuf = SrcMgr.getMemoryBuffer(CurBuffer); CurPtr = CurBuf->getBufferStart(); TokStart = 0; + + TheStringSet = new StringSet<>(); +} + +AsmLexer::~AsmLexer() { + delete &getSS(TheStringSet); } SMLoc AsmLexer::getLoc() const { @@ -75,7 +86,9 @@ asmtok::TokKind AsmLexer::LexIdentifier() { while (isalnum(*CurPtr) || *CurPtr == '_' || *CurPtr == '$' || *CurPtr == '.' || *CurPtr == '@') ++CurPtr; - CurStrVal.assign(TokStart, CurPtr); + // Unique string. + CurStrVal = + getSS(TheStringSet).GetOrCreateValue(TokStart, CurPtr, 0).getKeyData(); return asmtok::Identifier; } @@ -86,7 +99,10 @@ asmtok::TokKind AsmLexer::LexPercent() { while (isalnum(*CurPtr)) ++CurPtr; - CurStrVal.assign(TokStart, CurPtr); // Include % + + // Unique string. + CurStrVal = + getSS(TheStringSet).GetOrCreateValue(TokStart, CurPtr, 0).getKeyData(); return asmtok::Register; } @@ -208,7 +224,9 @@ asmtok::TokKind AsmLexer::LexQuote() { CurChar = getNextChar(); } - CurStrVal.assign(TokStart, CurPtr); // include quotes. + // Unique string, include quotes for now. + CurStrVal = + getSS(TheStringSet).GetOrCreateValue(TokStart, CurPtr, 0).getKeyData(); return asmtok::String; } @@ -244,6 +262,7 @@ asmtok::TokKind AsmLexer::LexToken() { case '*': return asmtok::Star; case ',': return asmtok::Comma; case '$': return asmtok::Dollar; + case '=': return asmtok::Equal; case '|': return asmtok::Pipe; case '^': return asmtok::Caret; case '&': return asmtok::Amp; diff --git a/tools/llvm-mc/AsmLexer.h b/tools/llvm-mc/AsmLexer.h index 23c5f85..19a1b38 100644 --- a/tools/llvm-mc/AsmLexer.h +++ b/tools/llvm-mc/AsmLexer.h @@ -42,7 +42,7 @@ namespace asmtok { Plus, Minus, Tilde, Slash, // '/' LParen, RParen, - Star, Comma, Dollar, + Star, Comma, Dollar, Equal, Pipe, Caret, Amp, Exclaim, Percent, LessLess, GreaterGreater @@ -55,20 +55,24 @@ class AsmLexer { const char *CurPtr; const MemoryBuffer *CurBuf; + // A llvm::StringSet<>, which provides uniqued and null-terminated strings. + void *TheStringSet; // Information about the current token. const char *TokStart; asmtok::TokKind CurKind; - std::string CurStrVal; // This is valid for Identifier. + const char *CurStrVal; // This is valid for Identifier. int64_t CurIntVal; /// CurBuffer - 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 public: AsmLexer(SourceMgr &SrcMgr); - ~AsmLexer() {} + ~AsmLexer(); asmtok::TokKind Lex() { return CurKind = LexToken(); @@ -78,7 +82,7 @@ public: bool is(asmtok::TokKind K) const { return CurKind == K; } bool isNot(asmtok::TokKind K) const { return CurKind != K; } - const std::string &getCurStrVal() const { + const char *getCurStrVal() const { assert((CurKind == asmtok::Identifier || CurKind == asmtok::Register || CurKind == asmtok::String) && "This token doesn't have a string value"); diff --git a/tools/llvm-mc/AsmParser.cpp b/tools/llvm-mc/AsmParser.cpp index 04c1d03..2b697a6 100644 --- a/tools/llvm-mc/AsmParser.cpp +++ b/tools/llvm-mc/AsmParser.cpp @@ -12,7 +12,9 @@ //===----------------------------------------------------------------------===// #include "AsmParser.h" +#include "llvm/MC/MCContext.h" #include "llvm/MC/MCInst.h" +#include "llvm/MC/MCStreamer.h" #include "llvm/Support/SourceMgr.h" #include "llvm/Support/raw_ostream.h" using namespace llvm; @@ -177,29 +179,167 @@ bool AsmParser::ParseStatement() { // If we have an identifier, handle it as the key symbol. SMLoc IDLoc = Lexer.getLoc(); - std::string IDVal = Lexer.getCurStrVal(); + const char *IDVal = Lexer.getCurStrVal(); // Consume the identifier, see what is after it. - if (Lexer.Lex() == asmtok::Colon) { + switch (Lexer.Lex()) { + case asmtok::Colon: // identifier ':' -> Label. Lexer.Lex(); + + // Since we saw a label, create a symbol and emit it. + // FIXME: If the label starts with L it is an assembler temporary label. + // Why does the client of this api need to know this? + Out.EmitLabel(Ctx.GetOrCreateSymbol(IDVal)); + return ParseStatement(); + + case asmtok::Equal: + // identifier '=' ... -> assignment statement + Lexer.Lex(); + + return ParseAssignment(IDVal, false); + + default: // Normal instruction or directive. + break; } // Otherwise, we have a normal instruction or directive. if (IDVal[0] == '.') { + // FIXME: This should be driven based on a hash lookup and callback. + if (!strcmp(IDVal, ".section")) + return ParseDirectiveDarwinSection(); + if (!strcmp(IDVal, ".text")) + // FIXME: This changes behavior based on the -static flag to the + // assembler. + return ParseDirectiveSectionSwitch("__TEXT,__text", + "regular,pure_instructions"); + if (!strcmp(IDVal, ".const")) + return ParseDirectiveSectionSwitch("__TEXT,__const"); + if (!strcmp(IDVal, ".static_const")) + return ParseDirectiveSectionSwitch("__TEXT,__static_const"); + if (!strcmp(IDVal, ".cstring")) + return ParseDirectiveSectionSwitch("__TEXT,__cstring", + "cstring_literals"); + if (!strcmp(IDVal, ".literal4")) + return ParseDirectiveSectionSwitch("__TEXT,__literal4", "4byte_literals"); + if (!strcmp(IDVal, ".literal8")) + return ParseDirectiveSectionSwitch("__TEXT,__literal8", "8byte_literals"); + if (!strcmp(IDVal, ".literal16")) + return ParseDirectiveSectionSwitch("__TEXT,__literal16", + "16byte_literals"); + if (!strcmp(IDVal, ".constructor")) + return ParseDirectiveSectionSwitch("__TEXT,__constructor"); + if (!strcmp(IDVal, ".destructor")) + return ParseDirectiveSectionSwitch("__TEXT,__destructor"); + if (!strcmp(IDVal, ".fvmlib_init0")) + return ParseDirectiveSectionSwitch("__TEXT,__fvmlib_init0"); + if (!strcmp(IDVal, ".fvmlib_init1")) + return ParseDirectiveSectionSwitch("__TEXT,__fvmlib_init1"); + if (!strcmp(IDVal, ".symbol_stub")) // FIXME: Different on PPC. + return ParseDirectiveSectionSwitch("__IMPORT,__jump_table,symbol_stubs", + "self_modifying_code+pure_instructions,5"); + // FIXME: .picsymbol_stub on PPC. + if (!strcmp(IDVal, ".data")) + return ParseDirectiveSectionSwitch("__DATA,__data"); + if (!strcmp(IDVal, ".static_data")) + return ParseDirectiveSectionSwitch("__DATA,__static_data"); + if (!strcmp(IDVal, ".non_lazy_symbol_pointer")) + return ParseDirectiveSectionSwitch("__DATA,__nl_symbol_pointer", + "non_lazy_symbol_pointers"); + if (!strcmp(IDVal, ".lazy_symbol_pointer")) + return ParseDirectiveSectionSwitch("__DATA,__la_symbol_pointer", + "lazy_symbol_pointers"); + if (!strcmp(IDVal, ".dyld")) + return ParseDirectiveSectionSwitch("__DATA,__dyld"); + if (!strcmp(IDVal, ".mod_init_func")) + return ParseDirectiveSectionSwitch("__DATA,__mod_init_func", + "mod_init_funcs"); + if (!strcmp(IDVal, ".mod_term_func")) + return ParseDirectiveSectionSwitch("__DATA,__mod_term_func", + "mod_term_funcs"); + if (!strcmp(IDVal, ".const_data")) + return ParseDirectiveSectionSwitch("__DATA,__const", "regular"); + + + // FIXME: Verify attributes on sections. + if (!strcmp(IDVal, ".objc_class")) + return ParseDirectiveSectionSwitch("__OBJC,__class"); + if (!strcmp(IDVal, ".objc_meta_class")) + return ParseDirectiveSectionSwitch("__OBJC,__meta_class"); + if (!strcmp(IDVal, ".objc_cat_cls_meth")) + return ParseDirectiveSectionSwitch("__OBJC,__cat_cls_meth"); + if (!strcmp(IDVal, ".objc_cat_inst_meth")) + return ParseDirectiveSectionSwitch("__OBJC,__cat_inst_meth"); + if (!strcmp(IDVal, ".objc_protocol")) + return ParseDirectiveSectionSwitch("__OBJC,__protocol"); + if (!strcmp(IDVal, ".objc_string_object")) + return ParseDirectiveSectionSwitch("__OBJC,__string_object"); + if (!strcmp(IDVal, ".objc_cls_meth")) + return ParseDirectiveSectionSwitch("__OBJC,__cls_meth"); + if (!strcmp(IDVal, ".objc_inst_meth")) + return ParseDirectiveSectionSwitch("__OBJC,__inst_meth"); + if (!strcmp(IDVal, ".objc_cls_refs")) + return ParseDirectiveSectionSwitch("__OBJC,__cls_refs"); + if (!strcmp(IDVal, ".objc_message_refs")) + return ParseDirectiveSectionSwitch("__OBJC,__message_refs"); + if (!strcmp(IDVal, ".objc_symbols")) + return ParseDirectiveSectionSwitch("__OBJC,__symbols"); + if (!strcmp(IDVal, ".objc_category")) + return ParseDirectiveSectionSwitch("__OBJC,__category"); + if (!strcmp(IDVal, ".objc_class_vars")) + return ParseDirectiveSectionSwitch("__OBJC,__class_vars"); + if (!strcmp(IDVal, ".objc_instance_vars")) + return ParseDirectiveSectionSwitch("__OBJC,__instance_vars"); + if (!strcmp(IDVal, ".objc_module_info")) + return ParseDirectiveSectionSwitch("__OBJC,__module_info"); + if (!strcmp(IDVal, ".objc_class_names")) + return ParseDirectiveSectionSwitch("__TEXT,__cstring","cstring_literals"); + if (!strcmp(IDVal, ".objc_meth_var_types")) + return ParseDirectiveSectionSwitch("__TEXT,__cstring","cstring_literals"); + if (!strcmp(IDVal, ".objc_meth_var_names")) + return ParseDirectiveSectionSwitch("__TEXT,__cstring","cstring_literals"); + if (!strcmp(IDVal, ".objc_selector_strs")) + return ParseDirectiveSectionSwitch("__OBJC,__selector_strs"); + + // Assembler features + if (!strcmp(IDVal, ".set")) + return ParseDirectiveSet(); + + // Data directives + + if (!strcmp(IDVal, ".ascii")) + return ParseDirectiveAscii(false); + if (!strcmp(IDVal, ".asciz")) + return ParseDirectiveAscii(true); + + // FIXME: Target hooks for size? Also for "word", "hword". + if (!strcmp(IDVal, ".byte")) + return ParseDirectiveValue(1); + if (!strcmp(IDVal, ".short")) + return ParseDirectiveValue(2); + if (!strcmp(IDVal, ".long")) + return ParseDirectiveValue(4); + if (!strcmp(IDVal, ".quad")) + return ParseDirectiveValue(8); + if (!strcmp(IDVal, ".fill")) + return ParseDirectiveFill(); + if (!strcmp(IDVal, ".org")) + return ParseDirectiveOrg(); + if (!strcmp(IDVal, ".space")) + return ParseDirectiveSpace(); + Lexer.PrintMessage(IDLoc, "warning: ignoring directive for now"); EatToEndOfStatement(); return false; } - MCInst Inst; if (ParseX86InstOperands(Inst)) return true; if (Lexer.isNot(asmtok::EndOfStatement)) - return TokError("unexpected token in operand list"); + return TokError("unexpected token in argument list"); // Eat the end of statement marker. Lexer.Lex(); @@ -211,3 +351,239 @@ bool AsmParser::ParseStatement() { // Skip to end of line for now. return false; } + +bool AsmParser::ParseAssignment(const char *Name, bool IsDotSet) { + int64_t Value; + if (ParseExpression(Value)) + return true; + + if (Lexer.isNot(asmtok::EndOfStatement)) + return TokError("unexpected token in assignment"); + + // Eat the end of statement marker. + Lexer.Lex(); + + // Get the symbol for this name. + // FIXME: Handle '.'. + MCSymbol *Sym = Ctx.GetOrCreateSymbol(Name); + Out.EmitAssignment(Sym, MCValue::get(Value), IsDotSet); + + return false; +} + +/// ParseDirectiveSet: +/// ::= .set identifier ',' expression +bool AsmParser::ParseDirectiveSet() { + if (Lexer.isNot(asmtok::Identifier)) + return TokError("expected identifier after '.set' directive"); + + const char *Name = Lexer.getCurStrVal(); + + if (Lexer.Lex() != asmtok::Comma) + return TokError("unexpected token in '.set'"); + Lexer.Lex(); + + return ParseAssignment(Name, true); +} + +/// ParseDirectiveSection: +/// ::= .section identifier (',' identifier)* +/// FIXME: This should actually parse out the segment, section, attributes and +/// sizeof_stub fields. +bool AsmParser::ParseDirectiveDarwinSection() { + if (Lexer.isNot(asmtok::Identifier)) + return TokError("expected identifier after '.section' directive"); + + std::string Section = Lexer.getCurStrVal(); + Lexer.Lex(); + + // Accept a comma separated list of modifiers. + while (Lexer.is(asmtok::Comma)) { + Lexer.Lex(); + + if (Lexer.isNot(asmtok::Identifier)) + return TokError("expected identifier in '.section' directive"); + Section += ','; + Section += Lexer.getCurStrVal(); + Lexer.Lex(); + } + + if (Lexer.isNot(asmtok::EndOfStatement)) + return TokError("unexpected token in '.section' directive"); + Lexer.Lex(); + + Out.SwitchSection(Ctx.GetSection(Section.c_str())); + return false; +} + +bool AsmParser::ParseDirectiveSectionSwitch(const char *Section, + const char *Directives) { + if (Lexer.isNot(asmtok::EndOfStatement)) + return TokError("unexpected token in section switching directive"); + Lexer.Lex(); + + std::string SectionStr = Section; + if (Directives && Directives[0]) { + SectionStr += ","; + SectionStr += Directives; + } + + Out.SwitchSection(Ctx.GetSection(Section)); + return false; +} + +/// ParseDirectiveAscii: +/// ::= ( .ascii | .asciiz ) [ "string" ( , "string" )* ] +bool AsmParser::ParseDirectiveAscii(bool ZeroTerminated) { + if (Lexer.isNot(asmtok::EndOfStatement)) { + for (;;) { + if (Lexer.isNot(asmtok::String)) + return TokError("expected string in '.ascii' or '.asciz' directive"); + + // FIXME: This shouldn't use a const char* + strlen, the string could have + // embedded nulls. + // FIXME: Should have accessor for getting string contents. + const char *Str = Lexer.getCurStrVal(); + Out.EmitBytes(Str + 1, strlen(Str) - 2); + if (ZeroTerminated) + Out.EmitBytes("\0", 1); + + Lexer.Lex(); + + if (Lexer.is(asmtok::EndOfStatement)) + break; + + if (Lexer.isNot(asmtok::Comma)) + return TokError("unexpected token in '.ascii' or '.asciz' directive"); + Lexer.Lex(); + } + } + + Lexer.Lex(); + return false; +} + +/// ParseDirectiveValue +/// ::= (.byte | .short | ... ) [ expression (, expression)* ] +bool AsmParser::ParseDirectiveValue(unsigned Size) { + if (Lexer.isNot(asmtok::EndOfStatement)) { + for (;;) { + int64_t Expr; + if (ParseExpression(Expr)) + return true; + + Out.EmitValue(MCValue::get(Expr), Size); + + if (Lexer.is(asmtok::EndOfStatement)) + break; + + // FIXME: Improve diagnostic. + if (Lexer.isNot(asmtok::Comma)) + return TokError("unexpected token in directive"); + Lexer.Lex(); + } + } + + Lexer.Lex(); + return false; +} + +/// ParseDirectiveSpace +/// ::= .space expression [ , expression ] +bool AsmParser::ParseDirectiveSpace() { + int64_t NumBytes; + if (ParseExpression(NumBytes)) + return true; + + int64_t FillExpr = 0; + bool HasFillExpr = false; + if (Lexer.isNot(asmtok::EndOfStatement)) { + if (Lexer.isNot(asmtok::Comma)) + return TokError("unexpected token in '.space' directive"); + Lexer.Lex(); + + if (ParseExpression(FillExpr)) + return true; + + HasFillExpr = true; + + if (Lexer.isNot(asmtok::EndOfStatement)) + return TokError("unexpected token in '.space' directive"); + } + + Lexer.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(MCValue::get(FillExpr), 1); + + return false; +} + +/// ParseDirectiveFill +/// ::= .fill expression , expression , expression +bool AsmParser::ParseDirectiveFill() { + int64_t NumValues; + if (ParseExpression(NumValues)) + return true; + + if (Lexer.isNot(asmtok::Comma)) + return TokError("unexpected token in '.fill' directive"); + Lexer.Lex(); + + int64_t FillSize; + if (ParseExpression(FillSize)) + return true; + + if (Lexer.isNot(asmtok::Comma)) + return TokError("unexpected token in '.fill' directive"); + Lexer.Lex(); + + int64_t FillExpr; + if (ParseExpression(FillExpr)) + return true; + + if (Lexer.isNot(asmtok::EndOfStatement)) + return TokError("unexpected token in '.fill' directive"); + + Lexer.Lex(); + + if (FillSize != 1 && FillSize != 2 && FillSize != 4) + return TokError("invalid '.fill' size, expected 1, 2, or 4"); + + for (uint64_t i = 0, e = NumValues; i != e; ++i) + Out.EmitValue(MCValue::get(FillExpr), FillSize); + + return false; +} + +/// ParseDirectiveOrg +/// ::= .org expression [ , expression ] +bool AsmParser::ParseDirectiveOrg() { + int64_t Offset; + if (ParseExpression(Offset)) + return true; + + // Parse optional fill expression. + int64_t FillExpr = 0; + if (Lexer.isNot(asmtok::EndOfStatement)) { + if (Lexer.isNot(asmtok::Comma)) + return TokError("unexpected token in '.org' directive"); + Lexer.Lex(); + + if (ParseExpression(FillExpr)) + return true; + + if (Lexer.isNot(asmtok::EndOfStatement)) + return TokError("unexpected token in '.org' directive"); + } + + Lexer.Lex(); + + Out.EmitValueToOffset(MCValue::get(Offset), FillExpr); + + return false; +} diff --git a/tools/llvm-mc/AsmParser.h b/tools/llvm-mc/AsmParser.h index c133345..da256c2 100644 --- a/tools/llvm-mc/AsmParser.h +++ b/tools/llvm-mc/AsmParser.h @@ -17,14 +17,20 @@ #include "AsmLexer.h" namespace llvm { +class MCContext; class MCInst; +class MCStreamer; class AsmParser { AsmLexer Lexer; + MCContext &Ctx; + MCStreamer &Out; + struct X86Operand; public: - AsmParser(SourceMgr &SM) : Lexer(SM) {} + AsmParser(SourceMgr &SM, MCContext &ctx, MCStreamer &OutStr) + : Lexer(SM), Ctx(ctx), Out(OutStr) {} ~AsmParser() {} bool Run(); @@ -37,6 +43,7 @@ private: void EatToEndOfStatement(); + bool ParseAssignment(const char *Name, bool IsDotSet); bool ParseExpression(int64_t &Res); bool ParsePrimaryExpr(int64_t &Res); bool ParseBinOpRHS(unsigned Precedence, int64_t &Res); @@ -46,6 +53,18 @@ private: bool ParseX86InstOperands(MCInst &Inst); bool ParseX86Operand(X86Operand &Op); bool ParseX86MemOperand(X86Operand &Op); + + // Directive Parsing. + bool ParseDirectiveDarwinSection(); // Darwin specific ".section". + bool ParseDirectiveSectionSwitch(const char *Section, + const char *Directives = 0); + bool ParseDirectiveAscii(bool ZeroTerminated); // ".ascii", ".asciiz" + bool ParseDirectiveValue(unsigned Size); // ".byte", ".long", ... + bool ParseDirectiveFill(); // ".fill" + bool ParseDirectiveSpace(); // ".space" + bool ParseDirectiveSet(); // ".set" + bool ParseDirectiveOrg(); // ".org" + }; } // end namespace llvm diff --git a/tools/llvm-mc/CMakeLists.txt b/tools/llvm-mc/CMakeLists.txt index 369d522..2dd878d 100644 --- a/tools/llvm-mc/CMakeLists.txt +++ b/tools/llvm-mc/CMakeLists.txt @@ -1,4 +1,4 @@ -set(LLVM_LINK_COMPONENTS support) +set(LLVM_LINK_COMPONENTS support MC) add_llvm_tool(llvm-mc llvm-mc.cpp diff --git a/tools/llvm-mc/Makefile b/tools/llvm-mc/Makefile index 7b4d944..3c327da 100644 --- a/tools/llvm-mc/Makefile +++ b/tools/llvm-mc/Makefile @@ -9,7 +9,7 @@ LEVEL = ../.. TOOLNAME = llvm-mc -LINK_COMPONENTS := support +LINK_COMPONENTS := support MC # This tool has no plugins, optimize startup time. TOOL_NO_EXPORTS = 1 diff --git a/tools/llvm-mc/llvm-mc.cpp b/tools/llvm-mc/llvm-mc.cpp index 52205c4..4100cb1 100644 --- a/tools/llvm-mc/llvm-mc.cpp +++ b/tools/llvm-mc/llvm-mc.cpp @@ -12,6 +12,9 @@ // //===----------------------------------------------------------------------===// +#include "llvm/MC/MCContext.h" +#include "llvm/MC/MCStreamer.h" +#include "llvm/ADT/OwningPtr.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/ManagedStatic.h" #include "llvm/Support/MemoryBuffer.h" @@ -136,7 +139,13 @@ static int AssembleInput(const char *ProgName) { // it later. SrcMgr.setIncludeDirs(IncludeDirs); - AsmParser Parser(SrcMgr); + MCContext Ctx; + OwningPtr<MCStreamer> Str(createAsmStreamer(Ctx, outs())); + + // FIXME: Target hook & command line option for initial section. + Str.get()->SwitchSection(Ctx.GetSection("__TEXT,__text,regular,pure_instructions")); + + AsmParser Parser(SrcMgr, Ctx, *Str.get()); return Parser.Run(); } diff --git a/tools/llvmc/doc/LLVMC-Reference.rst b/tools/llvmc/doc/LLVMC-Reference.rst index 7befe8f..329f9ea 100644 --- a/tools/llvmc/doc/LLVMC-Reference.rst +++ b/tools/llvmc/doc/LLVMC-Reference.rst @@ -92,6 +92,12 @@ configuration libraries: * ``-v`` - Enable verbose mode, i.e. print out all executed commands. +* ``--save-temps`` - Write temporary files to the current directory and do not + delete them on exit. This option can also take an argument: the + ``--save-temps=obj`` switch will write files into the directory specified with + the ``-o`` option. The ``--save-temps=cwd`` and ``--save-temps`` switches are + both synonyms for the default behaviour. + * ``--check-graph`` - Check the compilation for common errors like mismatched output/input language names, multiple default edges and cycles. Because of plugins, these checks can't be performed at compile-time. Exit with code zero @@ -108,9 +114,6 @@ configuration libraries: used to set the output file name. Hidden option, useful for debugging LLVMC plugins. -* ``--save-temps`` - Write temporary files to the current directory - and do not delete them on exit. Hidden option, useful for debugging. - * ``--help``, ``--help-hidden``, ``--version`` - These options have their standard meaning. diff --git a/tools/llvmc/driver/Makefile b/tools/llvmc/driver/Makefile index 5f5ec53..2f3104b 100644 --- a/tools/llvmc/driver/Makefile +++ b/tools/llvmc/driver/Makefile @@ -8,15 +8,6 @@ ##===----------------------------------------------------------------------===## LEVEL = ../../.. - -TOOLNAME = $(LLVMC_BASED_DRIVER_NAME) -LLVMLIBS = CompilerDriver.a - -ifneq ($(LLVMC_BUILTIN_PLUGINS),) -USEDLIBS += $(patsubst %,plugin_llvmc_%.a,$(LLVMC_BUILTIN_PLUGINS)) -endif - -LINK_COMPONENTS = support system -REQUIRES_EH := 1 +LLVMC_BASED_DRIVER = $(LLVMC_BASED_DRIVER_NAME) include $(LEVEL)/Makefile.common diff --git a/tools/llvmc/example/Skeleton/Makefile b/tools/llvmc/example/Skeleton/Makefile index 2e4cbb9..f489abf 100644 --- a/tools/llvmc/example/Skeleton/Makefile +++ b/tools/llvmc/example/Skeleton/Makefile @@ -8,7 +8,7 @@ ##===----------------------------------------------------------------------===## # Change this so that $(BASE_LEVEL)/Makefile.common refers to -# $LLVM_DIR/Makefile.common. +# $LLVM_DIR/Makefile.common or $YOUR_LLVM_BASED_PROJECT/Makefile.common. export LLVMC_BASE_LEVEL = ../../../.. # Change this to the name of your LLVMC-based driver. diff --git a/tools/llvmc/example/Skeleton/driver/Makefile b/tools/llvmc/example/Skeleton/driver/Makefile index bf6d7a5..93e795b 100644 --- a/tools/llvmc/example/Skeleton/driver/Makefile +++ b/tools/llvmc/example/Skeleton/driver/Makefile @@ -8,15 +8,6 @@ ##===----------------------------------------------------------------------===## LEVEL = $(LLVMC_BASE_LEVEL)/.. - -TOOLNAME = $(LLVMC_BASED_DRIVER_NAME) -LLVMLIBS = CompilerDriver - -ifneq ($(LLVMC_BUILTIN_PLUGINS),) -USEDLIBS += $(patsubst %,plugin_llvmc_%,$(LLVMC_BUILTIN_PLUGINS)) -endif - -LINK_COMPONENTS = support system -REQUIRES_EH := 1 +LLVMC_BASED_DRIVER = $(LLVMC_BASED_DRIVER_NAME) include $(LEVEL)/Makefile.common diff --git a/tools/llvmc/example/mcc16/Makefile b/tools/llvmc/example/mcc16/Makefile index efc9d2d..e94bca2 100644 --- a/tools/llvmc/example/mcc16/Makefile +++ b/tools/llvmc/example/mcc16/Makefile @@ -7,14 +7,8 @@ # ##===----------------------------------------------------------------------===## -# Change this so that $(BASE_LEVEL)/Makefile.common refers to -# $LLVM_DIR/Makefile.common. export LLVMC_BASE_LEVEL = ../../../.. - -# Change this to the name of your LLVMC-based driver. export LLVMC_BASED_DRIVER_NAME = mcc16 - -# List your plugin names here export LLVMC_BUILTIN_PLUGINS = PIC16Base LEVEL = $(LLVMC_BASE_LEVEL) diff --git a/tools/llvmc/example/mcc16/driver/Makefile b/tools/llvmc/example/mcc16/driver/Makefile index ed9ebfd..670d8bd 100644 --- a/tools/llvmc/example/mcc16/driver/Makefile +++ b/tools/llvmc/example/mcc16/driver/Makefile @@ -8,15 +8,6 @@ ##===----------------------------------------------------------------------===## LEVEL = $(LLVMC_BASE_LEVEL)/.. - -TOOLNAME = $(LLVMC_BASED_DRIVER_NAME) -LLVMLIBS = CompilerDriver - -ifneq ($(LLVMC_BUILTIN_PLUGINS),) -USEDLIBS += $(patsubst %,plugin_llvmc_%,$(LLVMC_BUILTIN_PLUGINS)) -endif - -LINK_COMPONENTS = support system -REQUIRES_EH := 1 +LLVMC_BASED_DRIVER = $(LLVMC_BASED_DRIVER_NAME) include $(LEVEL)/Makefile.common diff --git a/tools/lto/LTOCodeGenerator.cpp b/tools/lto/LTOCodeGenerator.cpp index 8db573e..52624eb 100644 --- a/tools/lto/LTOCodeGenerator.cpp +++ b/tools/lto/LTOCodeGenerator.cpp @@ -111,7 +111,7 @@ bool LTOCodeGenerator::setDebugInfo(lto_debug_model debug, std::string& errMsg) bool LTOCodeGenerator::setCodePICModel(lto_codegen_model model, - std::string& errMsg) + std::string& errMsg) { switch (model) { case LTO_CODEGEN_PIC_MODEL_STATIC: diff --git a/tools/lto/Makefile b/tools/lto/Makefile index f0f6da7..de885d9 100644 --- a/tools/lto/Makefile +++ b/tools/lto/Makefile @@ -17,7 +17,6 @@ include $(LEVEL)/Makefile.config LINK_LIBS_IN_SHARED = 1 SHARED_LIBRARY = 1 -DONT_BUILD_RELINKED = 1 LINK_COMPONENTS := $(TARGETS_TO_BUILD) ipo scalaropts linker bitreader bitwriter diff --git a/tools/lto/lto.cpp b/tools/lto/lto.cpp index 7eb39ef..a0f67b4 100644 --- a/tools/lto/lto.cpp +++ b/tools/lto/lto.cpp @@ -198,7 +198,7 @@ bool lto_codegen_set_debug_model(lto_code_gen_t cg, lto_debug_model debug) // bool lto_codegen_set_pic_model(lto_code_gen_t cg, lto_codegen_model model) { - return cg->setCodePICModel(model, sLastErrorString); + return cg->setCodePICModel(model, sLastErrorString); } // @@ -206,7 +206,7 @@ bool lto_codegen_set_pic_model(lto_code_gen_t cg, lto_codegen_model model) // void lto_codegen_set_gcc_path(lto_code_gen_t cg, const char* path) { - cg->setGccPath(path); + cg->setGccPath(path); } // @@ -224,7 +224,7 @@ void lto_codegen_set_assembler_path(lto_code_gen_t cg, const char* path) // void lto_codegen_add_must_preserve_symbol(lto_code_gen_t cg, const char* symbol) { - cg->addMustPreserveSymbol(symbol); + cg->addMustPreserveSymbol(symbol); } @@ -235,7 +235,7 @@ void lto_codegen_add_must_preserve_symbol(lto_code_gen_t cg, const char* symbol) // bool lto_codegen_write_merged_modules(lto_code_gen_t cg, const char* path) { - return cg->writeMergedModules(path, sLastErrorString); + return cg->writeMergedModules(path, sLastErrorString); } @@ -250,7 +250,7 @@ bool lto_codegen_write_merged_modules(lto_code_gen_t cg, const char* path) extern const void* lto_codegen_compile(lto_code_gen_t cg, size_t* length) { - return cg->compile(length, sLastErrorString); + return cg->compile(length, sLastErrorString); } @@ -262,6 +262,3 @@ lto_codegen_debug_options(lto_code_gen_t cg, const char * opt) { cg->setCodeGenDebugOptions(opt); } - - - diff --git a/tools/opt/GraphPrinters.cpp b/tools/opt/GraphPrinters.cpp index a52baf7..5d581e4 100644 --- a/tools/opt/GraphPrinters.cpp +++ b/tools/opt/GraphPrinters.cpp @@ -49,7 +49,8 @@ namespace llvm { return "Call Graph"; } - static std::string getNodeLabel(CallGraphNode *Node, CallGraph *Graph) { + static std::string getNodeLabel(CallGraphNode *Node, CallGraph *Graph, + bool ShortNames) { if (Node->getFunction()) return ((Value*)Node->getFunction())->getName(); else |