summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/preproc/asm_file.cpp25
-rw-r--r--tools/preproc/asm_file.h1
-rw-r--r--tools/preproc/preproc.cpp15
3 files changed, 40 insertions, 1 deletions
diff --git a/tools/preproc/asm_file.cpp b/tools/preproc/asm_file.cpp
index eba486e66..7deaccc8a 100644
--- a/tools/preproc/asm_file.cpp
+++ b/tools/preproc/asm_file.cpp
@@ -197,6 +197,31 @@ Directive AsmFile::GetDirective()
return Directive::Unknown;
}
+// Checks if we're at label that ends with '::'.
+// Returns the name if so and an empty string if not.
+std::string AsmFile::GetGlobalLabel()
+{
+ long start = m_pos;
+ long pos = m_pos;
+
+ if (IsIdentifierStartingChar(m_buffer[pos]))
+ {
+ pos++;
+
+ while (IsIdentifierChar(m_buffer[pos]))
+ pos++;
+ }
+
+ if (m_buffer[pos] == ':' && m_buffer[pos + 1] == ':')
+ {
+ m_pos = pos + 2;
+ ExpectEmptyRestOfLine();
+ return std::string(&m_buffer[start], pos - start);
+ }
+
+ return std::string();
+}
+
// Skips tabs and spaces.
void AsmFile::SkipWhitespace()
{
diff --git a/tools/preproc/asm_file.h b/tools/preproc/asm_file.h
index c0aba878d..d73b36e90 100644
--- a/tools/preproc/asm_file.h
+++ b/tools/preproc/asm_file.h
@@ -42,6 +42,7 @@ public:
AsmFile(const AsmFile&) = delete;
~AsmFile();
Directive GetDirective();
+ std::string GetGlobalLabel();
std::string ReadPath();
int ReadString(unsigned char* s);
int ReadBraille(unsigned char* s);
diff --git a/tools/preproc/preproc.cpp b/tools/preproc/preproc.cpp
index 38ae762ea..b51861580 100644
--- a/tools/preproc/preproc.cpp
+++ b/tools/preproc/preproc.cpp
@@ -84,9 +84,22 @@ void PreprocAsmFile(std::string filename)
break;
}
case Directive::Unknown:
- stack.top().OutputLine();
+ {
+ std::string globalLabel = stack.top().GetGlobalLabel();
+
+ if (globalLabel.length() != 0)
+ {
+ printf("\t.global %s\n", globalLabel.c_str());
+ printf("%s:\n", globalLabel.c_str());
+ }
+ else
+ {
+ stack.top().OutputLine();
+ }
+
break;
}
+ }
}
}