Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ Passes come in three kinds: module `Pass`, `FunctionPass` (run per function), an

## utility
- [**verify:**](./pass/verify.h) Edge consistency + per-opcode structural invariants (see [ir](#ir)).
- [**rename-symbol:**](./pass/opt/rename_symbol.h) Rename a function or global and every reference to it.

Visualization passes (`text-emitter`, `graph-emitter`) are covered in [x86-64 backend](#x86-64-backend).

Expand Down
34 changes: 0 additions & 34 deletions src/backend/pass/opt/rename_symbol.cpp

This file was deleted.

21 changes: 0 additions & 21 deletions src/backend/pass/opt/rename_symbol.h

This file was deleted.

2 changes: 0 additions & 2 deletions src/backend/rat.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,4 @@
#include "pass/emit/x86/x86_lower.h"
#include "pass/emit/x86/x86_peephole.h"

#include "pass/opt/rename_symbol.h"

#endif
11 changes: 6 additions & 5 deletions src/compiler/builtin_headers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,15 @@ namespace rat::cc {
return ec ? fs::path() : p;
#endif
}

String includeDirOf(const fs::path& exe) {
fs::path h = exe.parent_path() / ".." / "src" / "compiler" / "headers";
return h.lexically_normal().generic_string();
}
} // namespace detail

const String& builtinIncludeDir() {
static const String dir = [] {
detail::fs::path exe = detail::selfExePath();
detail::fs::path h = exe.parent_path() / ".." / "src" / "compiler" / "headers";
return h.lexically_normal().generic_string();
}();
static const String dir = detail::includeDirOf(detail::selfExePath());
return dir;
}
} // namespace rat::cc
1 change: 1 addition & 0 deletions src/compiler/builtin_headers.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace rat::cc {
namespace detail {
// absolute path of the running executable, cross-platform
std::filesystem::path selfExePath();
String includeDirOf(const std::filesystem::path& exe);
} // namespace detail

const String& builtinIncludeDir();
Expand Down
3 changes: 0 additions & 3 deletions src/compiler/compile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@

namespace rat::cc {
void composePipeline(PassManager& pm, CompileOptions& opt, std::ostream& out) {
if(!opt.renameMain.empty())
pm.add<RenameSymbolPass>("main", opt.renameMain);

Set<String> seen;
for(UniquePtr<Pass>& p : opt.optPasses) {
String name = p->name();
Expand Down
1 change: 0 additions & 1 deletion src/compiler/compile.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ namespace rat::cc {
struct CompileOptions {
List<UniquePtr<Pass>> optPasses;
List<UniquePtr<MachinePass>> machinePasses; // empty = default x86 pipeline
String renameMain;
};

void composePipeline(PassManager& pm, CompileOptions& opt, std::ostream& out);
Expand Down
26 changes: 14 additions & 12 deletions src/compiler/host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,22 @@

namespace rat::cc {
namespace detail {
TargetTriple& hostTripleStorage() {
static TargetTriple triple = [] {
TargetTriple t;
TargetTriple defaultTriple() {
TargetTriple t;
#if defined(_WIN32)
t.os = OS::Windows; // native builds default to the host platform
t.os = OS::Windows; // native builds default to the host platform
#endif
const char* env = std::getenv("RATCC_TARGET");
if(env && *env) {
String err;
if(!TargetTriple::parse(env, t, err))
std::fprintf(stderr, "ratcc: ignoring RATCC_TARGET: %s\n", err.c_str());
}
return t;
}();
const C8* env = std::getenv("RATCC_TARGET");
if(env && *env) {
String err;
if(!TargetTriple::parse(env, t, err))
std::fprintf(stderr, "ratcc: ignoring RATCC_TARGET: %s\n", err.c_str());
}
return t;
}

TargetTriple& hostTripleStorage() {
static TargetTriple triple = defaultTriple();
return triple;
}
} // namespace detail
Expand Down
1 change: 1 addition & 0 deletions src/compiler/host.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace rat::cc {
namespace detail {
TargetTriple defaultTriple();
TargetTriple& hostTripleStorage();
} // namespace detail

Expand Down
44 changes: 8 additions & 36 deletions src/compiler/lex/char_class.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,43 +23,15 @@ namespace rat::cc {
return -1;
}
inline B32 simpleEscape(C8 e, U8& out) {
switch(e) {
case 'n':
out = '\n';
return true;
case 't':
out = '\t';
return true;
case 'r':
out = '\r';
return true;
case '\\':
out = '\\';
return true;
case '\'':
out = '\'';
return true;
case '"':
out = '"';
return true;
case 'a':
out = '\a';
return true;
case 'b':
out = '\b';
return true;
case 'f':
out = '\f';
return true;
case 'v':
out = '\v';
return true;
case 'e':
out = 27;
return true;
default:
return false;
constexpr C8 kFrom[] = {'n', 't', 'r', '\\', '\'', '"', 'a', 'b', 'f', 'v', 'e'};
constexpr U8 kTo[] = {'\n', '\t', '\r', '\\', '\'', '"', '\a', '\b', '\f', '\v', 27};
for(U32 i = 0; i < sizeof kTo; ++i) {
if(kFrom[i] == e) {
out = kTo[i];
return true;
}
}
return false;
}
} // namespace rat::cc

Expand Down
41 changes: 19 additions & 22 deletions src/compiler/lex/lexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ namespace rat::cc {
"kTokNames must cover every TokKind");

B32 validIntSuffix(const C8* s, U32 n) {
B32 haveU = false, haveL = false;
B32 haveU = false;
B32 haveL = false;
U32 i = 0;
while(i < n) {
C8 c = s[i];
Expand All @@ -49,7 +50,8 @@ namespace rat::cc {
}

B32 validFloatSuffix(const C8* s, U32 n) {
B32 haveSize = false, imag = false;
B32 haveSize = false;
B32 imag = false;
for(U32 i = 0; i < n; ++i) {
C8 c = s[i];
if(c == 'f' || c == 'F' || c == 'l' || c == 'L') {
Expand Down Expand Up @@ -89,6 +91,19 @@ namespace rat::cc {
return true;
}

B32 scanExponent(const C8* s, U32 n, U32& i, const C8* missing, String& err) {
++i;
if(charAt(s, n, i) == '+' || charAt(s, n, i) == '-')
++i;
if(!isDigit(charAt(s, n, i))) {
err = missing;
return false;
}
while(isDigit(charAt(s, n, i)))
++i;
return true;
}

B32 scanHexNumber(const C8* s, U32 n, U32& i, B32& isFloat, String& err) {
i += 2; // "0x"
B32 anyDigits = false;
Expand Down Expand Up @@ -116,16 +131,7 @@ namespace rat::cc {
return false;
}
isFloat = true;
++i;
if(charAt(s, n, i) == '+' || charAt(s, n, i) == '-')
++i;
if(!isDigit(charAt(s, n, i))) {
err = "expected digits in binary exponent";
return false;
}
while(isDigit(charAt(s, n, i)))
++i;
return true;
return scanExponent(s, n, i, "expected digits in binary exponent", err);
}

B32 scanDecNumber(const C8* s, U32 n, U32& i, B32& isFloat, String& err) {
Expand All @@ -141,16 +147,7 @@ namespace rat::cc {
if(c != 'e' && c != 'E')
return true;
isFloat = true;
++i;
if(charAt(s, n, i) == '+' || charAt(s, n, i) == '-')
++i;
if(!isDigit(charAt(s, n, i))) {
err = "expected digits in exponent";
return false;
}
while(isDigit(charAt(s, n, i)))
++i;
return true;
return scanExponent(s, n, i, "expected digits in exponent", err);
}

B32 scanNumber(const C8* s, U32 n, U32& i, TokKind& kind, String& err) {
Expand Down
1 change: 1 addition & 0 deletions src/compiler/lex/lexer.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ namespace rat::cc {

// scanners over one token spelling; advance i, false on error with err set
B32 scanSuffix(const C8* s, U32 n, U32& i, B32 isFloat, TokKind& kind, String& err);
B32 scanExponent(const C8* s, U32 n, U32& i, const C8* missing, String& err);
B32 scanHexNumber(const C8* s, U32 n, U32& i, B32& isFloat, String& err);
B32 scanDecNumber(const C8* s, U32 n, U32& i, B32& isFloat, String& err);
U32 encodingPrefix(const C8* s, U32 n);
Expand Down
Loading
Loading