mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-30 05:24:22 +00:00
implement .include in the lexer/parser instead of passing it into the streamer.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@75896 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -160,12 +160,6 @@ namespace llvm {
|
|||||||
/// @param AbortReason - The reason assembly is terminated, if non-NULL.
|
/// @param AbortReason - The reason assembly is terminated, if non-NULL.
|
||||||
virtual void AbortAssembly(const char *AbortReason) = 0;
|
virtual void AbortAssembly(const char *AbortReason) = 0;
|
||||||
|
|
||||||
/// SwitchInputAssemblyFile - Assemble the contents of the specified file in
|
|
||||||
/// @param FileName at this point in the assembly.
|
|
||||||
///
|
|
||||||
/// @param FileName - The file to assemble at this point
|
|
||||||
virtual void SwitchInputAssemblyFile(const char *FileName) = 0;
|
|
||||||
|
|
||||||
/// DumpSymbolsandMacros - Dump to the specified file in @param FileName all
|
/// DumpSymbolsandMacros - Dump to the specified file in @param FileName all
|
||||||
/// symbols and macros at this point in the assembly.
|
/// symbols and macros at this point in the assembly.
|
||||||
///
|
///
|
||||||
|
@ -57,8 +57,6 @@ namespace {
|
|||||||
|
|
||||||
virtual void AbortAssembly(const char *AbortReason = NULL);
|
virtual void AbortAssembly(const char *AbortReason = NULL);
|
||||||
|
|
||||||
virtual void SwitchInputAssemblyFile(const char *FileName);
|
|
||||||
|
|
||||||
virtual void DumpSymbolsandMacros(const char *FileName);
|
virtual void DumpSymbolsandMacros(const char *FileName);
|
||||||
|
|
||||||
virtual void LoadSymbolsandMacros(const char *FileName);
|
virtual void LoadSymbolsandMacros(const char *FileName);
|
||||||
@ -143,10 +141,6 @@ void MCAsmStreamer::AbortAssembly(const char *AbortReason) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MCAsmStreamer::SwitchInputAssemblyFile(const char *FileName) {
|
|
||||||
OS << ".include" << ' ' << FileName << '\n';
|
|
||||||
}
|
|
||||||
|
|
||||||
void MCAsmStreamer::DumpSymbolsandMacros(const char *FileName) {
|
void MCAsmStreamer::DumpSymbolsandMacros(const char *FileName) {
|
||||||
OS << ".dump" << ' ' << FileName << '\n';
|
OS << ".dump" << ' ' << FileName << '\n';
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
# RUN: llvm-mc %s | FileCheck %s
|
# RUN: llvm-mc %s -I %p | FileCheck %s
|
||||||
|
|
||||||
|
# CHECK: TESTA:
|
||||||
# CHECK: TEST0:
|
# CHECK: TEST0:
|
||||||
# CHECK: .include "some/include/file"
|
# CHECK: .set a, 0
|
||||||
# CHECK: .include "mary had a little lamb"
|
# CHECK: TESTB:
|
||||||
TEST0:
|
TESTA:
|
||||||
.include "some/include/file"
|
.include "directive_set.s"
|
||||||
.include "mary had a little lamb"
|
TESTB:
|
||||||
|
@ -54,6 +54,21 @@ asmtok::TokKind AsmLexer::ReturnError(const char *Loc, const std::string &Msg) {
|
|||||||
return asmtok::Error;
|
return asmtok::Error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 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;
|
||||||
|
|
||||||
|
// Save the line number and lex buffer of the includer.
|
||||||
|
CurBuffer = NewBuf;
|
||||||
|
CurBuf = SrcMgr.getMemoryBuffer(CurBuffer);
|
||||||
|
CurPtr = CurBuf->getBufferStart();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int AsmLexer::getNextChar() {
|
int AsmLexer::getNextChar() {
|
||||||
char CurChar = *CurPtr++;
|
char CurChar = *CurPtr++;
|
||||||
switch (CurChar) {
|
switch (CurChar) {
|
||||||
@ -72,6 +87,10 @@ int AsmLexer::getNextChar() {
|
|||||||
CurBuffer = SrcMgr.FindBufferContainingLoc(ParentIncludeLoc);
|
CurBuffer = SrcMgr.FindBufferContainingLoc(ParentIncludeLoc);
|
||||||
CurBuf = SrcMgr.getMemoryBuffer(CurBuffer);
|
CurBuf = SrcMgr.getMemoryBuffer(CurBuffer);
|
||||||
CurPtr = ParentIncludeLoc.getPointer();
|
CurPtr = ParentIncludeLoc.getPointer();
|
||||||
|
|
||||||
|
// Reset the token start pointer to the start of the new file.
|
||||||
|
TokStart = CurPtr;
|
||||||
|
|
||||||
return getNextChar();
|
return getNextChar();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,6 +97,9 @@ public:
|
|||||||
|
|
||||||
SMLoc getLoc() const;
|
SMLoc getLoc() const;
|
||||||
|
|
||||||
|
/// 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;
|
void PrintMessage(SMLoc Loc, const std::string &Msg, const char *Type) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -1168,21 +1168,27 @@ bool AsmParser::ParseDirectiveDarwinLsym() {
|
|||||||
/// ParseDirectiveInclude
|
/// ParseDirectiveInclude
|
||||||
/// ::= .include "filename"
|
/// ::= .include "filename"
|
||||||
bool AsmParser::ParseDirectiveInclude() {
|
bool AsmParser::ParseDirectiveInclude() {
|
||||||
const char *Str;
|
|
||||||
|
|
||||||
if (Lexer.isNot(asmtok::String))
|
if (Lexer.isNot(asmtok::String))
|
||||||
return TokError("expected string in '.include' directive");
|
return TokError("expected string in '.include' directive");
|
||||||
|
|
||||||
Str = Lexer.getCurStrVal();
|
std::string Filename = Lexer.getCurStrVal();
|
||||||
|
SMLoc IncludeLoc = Lexer.getLoc();
|
||||||
Lexer.Lex();
|
Lexer.Lex();
|
||||||
|
|
||||||
if (Lexer.isNot(asmtok::EndOfStatement))
|
if (Lexer.isNot(asmtok::EndOfStatement))
|
||||||
return TokError("unexpected token in '.include' directive");
|
return TokError("unexpected token in '.include' directive");
|
||||||
|
|
||||||
Lexer.Lex();
|
// Strip the quotes.
|
||||||
|
Filename = Filename.substr(1, Filename.size()-2);
|
||||||
Out.SwitchInputAssemblyFile(Str);
|
|
||||||
|
// 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");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user