mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2024-12-26 17:57:07 +00:00
[flang] Impose a directory structure. Move files around. Introduce
an intermediate "parser" namespace. Original-commit: flang-compiler/f18@690b6f0d1e Reviewed-on: https://github.com/flang-compiler/f18/pull/4 Tree-same-pre-rewrite: false
This commit is contained in:
parent
6e22a3563e
commit
0ba1a14be2
2
flang/.gitignore
vendored
2
flang/.gitignore
vendored
@ -1,7 +1,7 @@
|
||||
Debug
|
||||
Release
|
||||
tags
|
||||
f18
|
||||
./f18
|
||||
*.o
|
||||
*~
|
||||
CMakeCache.txt
|
||||
|
@ -9,14 +9,14 @@ set(CMAKE_BUILD_WITH_INSTALL_RPATH true)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -std=c++17")
|
||||
|
||||
set(SOURCES
|
||||
char-buffer.cc
|
||||
f2018-demo.cc
|
||||
idioms.cc
|
||||
message.cc
|
||||
parse-tree.cc
|
||||
position.cc
|
||||
preprocessor.cc
|
||||
prescan.cc
|
||||
source.cc
|
||||
tools/f18/f18.cc
|
||||
lib/parser/char-buffer.cc
|
||||
lib/parser/idioms.cc
|
||||
lib/parser/message.cc
|
||||
lib/parser/parse-tree.cc
|
||||
lib/parser/position.cc
|
||||
lib/parser/preprocessor.cc
|
||||
lib/parser/prescan.cc
|
||||
lib/parser/source.cc
|
||||
)
|
||||
add_executable(f18 ${SOURCES})
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include <string>
|
||||
|
||||
namespace Fortran {
|
||||
namespace parser {
|
||||
|
||||
// fail<A>("...") returns a parser that never succeeds. It reports an
|
||||
// error message at the current position. The result type is unused,
|
||||
@ -1316,5 +1317,6 @@ constexpr struct GetPosition {
|
||||
}
|
||||
} getPosition;
|
||||
|
||||
} // namespace parser
|
||||
} // namespace Fortran
|
||||
#endif // FORTRAN_BASIC_PARSERS_H_
|
@ -4,6 +4,7 @@
|
||||
#include <cstring>
|
||||
|
||||
namespace Fortran {
|
||||
namespace parser {
|
||||
|
||||
char *CharBuffer::FreeSpace(size_t *n) {
|
||||
int offset{LastBlockOffset()};
|
||||
@ -45,4 +46,5 @@ void CharBuffer::CopyToContiguous(char *data) {
|
||||
}
|
||||
CHECK(to == data + bytes_);
|
||||
}
|
||||
} // namespace parser
|
||||
} // namespace Fortran
|
@ -10,6 +10,7 @@
|
||||
#include <vector>
|
||||
|
||||
namespace Fortran {
|
||||
namespace parser {
|
||||
|
||||
class CharBuffer {
|
||||
public:
|
||||
@ -113,5 +114,6 @@ private:
|
||||
size_t bytes_{0};
|
||||
bool lastBlockEmpty_{false};
|
||||
};
|
||||
} // namespace parser
|
||||
} // namespace Fortran
|
||||
#endif // FORTRAN_CHAR_BUFFER_H_
|
@ -9,6 +9,7 @@
|
||||
#include <optional>
|
||||
|
||||
namespace Fortran {
|
||||
namespace parser {
|
||||
|
||||
template<char goal> struct ExactRaw {
|
||||
using resultType = char;
|
||||
@ -107,5 +108,6 @@ private:
|
||||
constexpr RawStringMatch operator""_raw(const char str[], size_t n) {
|
||||
return RawStringMatch{str, n};
|
||||
}
|
||||
} // namespace parser
|
||||
} // namespace Fortran
|
||||
#endif // FORTRAN_CHAR_PARSERS_H_
|
@ -18,6 +18,7 @@
|
||||
#include <optional>
|
||||
|
||||
namespace Fortran {
|
||||
namespace parser {
|
||||
|
||||
constexpr struct FixedFormPadding {
|
||||
using resultType = char;
|
||||
@ -210,5 +211,6 @@ static inline bool ConsumedAllInput(const ParseState &state) {
|
||||
}
|
||||
|
||||
constexpr StatePredicateGuardParser consumedAllInput{ConsumedAllInput};
|
||||
} // namespace parser
|
||||
} // namespace Fortran
|
||||
#endif // FORTRAN_COOKED_CHARS_H_
|
@ -18,6 +18,7 @@
|
||||
#include <string>
|
||||
|
||||
namespace Fortran {
|
||||
namespace parser {
|
||||
|
||||
class CharPredicateGuardParser {
|
||||
public:
|
||||
@ -430,5 +431,6 @@ template<typename PA> inline constexpr auto optionalBeforeColons(const PA &p) {
|
||||
return "," >> p / "::" || "::" >> construct<typename PA::resultType>{} ||
|
||||
!","_tok >> construct<typename PA::resultType>{};
|
||||
}
|
||||
} // namespace parser
|
||||
} // namespace Fortran
|
||||
#endif // FORTRAN_COOKED_TOKENS_H_
|
@ -12,6 +12,7 @@
|
||||
#include <string>
|
||||
|
||||
namespace Fortran {
|
||||
namespace parser {
|
||||
|
||||
class DebugParser {
|
||||
public:
|
||||
@ -34,5 +35,6 @@ private:
|
||||
constexpr DebugParser operator""_debug(const char str[], size_t n) {
|
||||
return DebugParser{str, n};
|
||||
}
|
||||
} // namespace parser
|
||||
} // namespace Fortran
|
||||
#endif // FORTRAN_DEBUG_PARSER_H_
|
@ -24,6 +24,7 @@
|
||||
#include <utility>
|
||||
|
||||
namespace Fortran {
|
||||
namespace parser {
|
||||
|
||||
// The productions that follow are derived from the draft Fortran 2018
|
||||
// standard, with some necessary modifications to remove left recursion
|
||||
@ -3643,5 +3644,6 @@ TYPE_CONTEXT_PARSER("PAUSE statement",
|
||||
// is used only via scalar-int-variable
|
||||
// R1030 default-char-constant-expr -> default-char-expr
|
||||
// is only used via scalar-default-char-constant-expr
|
||||
} // namespace parser
|
||||
} // namespace Fortran
|
||||
#endif // FORTRAN_GRAMMAR_H_
|
@ -4,6 +4,7 @@
|
||||
#include <cstdlib>
|
||||
|
||||
namespace Fortran {
|
||||
namespace parser {
|
||||
|
||||
[[noreturn]] void die(const char *msg, ...) {
|
||||
va_list ap;
|
||||
@ -18,4 +19,5 @@ namespace Fortran {
|
||||
std::ostream &operator<<(std::ostream &o, const std::monostate &) {
|
||||
return o << "(empty variant)";
|
||||
}
|
||||
} // namespace parser
|
||||
} // namespace Fortran
|
@ -34,6 +34,7 @@ struct is_trivially_copy_constructible<optional<list<A>>> : false_type {};
|
||||
using namespace std::string_literals; // enable "this is a std::string"s
|
||||
|
||||
namespace Fortran {
|
||||
namespace parser {
|
||||
|
||||
// Helper templates for combining a list of lambdas into an anonymous
|
||||
// struct for use with std::visit() on a std::variant<> sum type.
|
||||
@ -57,6 +58,7 @@ template<typename... LAMBDAS> visitors(LAMBDAS... x)->visitors<LAMBDAS...>;
|
||||
template<typename A> bool operator!(const std::optional<A> &x) {
|
||||
return !x.has_value();
|
||||
}
|
||||
} // namespace parser
|
||||
} // namespace Fortran
|
||||
|
||||
// For switch statements without default: labels.
|
||||
@ -73,6 +75,7 @@ template<typename A> struct BadType : std::false_type {};
|
||||
|
||||
// Formatting
|
||||
namespace Fortran {
|
||||
namespace parser {
|
||||
template<typename A>
|
||||
std::ostream &operator<<(std::ostream &o, const std::optional<A> &x) {
|
||||
if (x.has_value()) {
|
||||
@ -116,5 +119,6 @@ std::ostream &operator<<(std::ostream &o, const std::variant<As...> &x) {
|
||||
return std::visit(
|
||||
[&o](const auto &y) -> std::ostream & { return o << y; }, x);
|
||||
}
|
||||
} // namespace parser
|
||||
} // namespace Fortran
|
||||
#endif // FORTRAN_IDIOMS_H_
|
@ -11,6 +11,7 @@
|
||||
#include <utility>
|
||||
|
||||
namespace Fortran {
|
||||
namespace parser {
|
||||
|
||||
template<typename A> class Indirection {
|
||||
public:
|
||||
@ -54,5 +55,6 @@ template<typename A>
|
||||
std::ostream &operator<<(std::ostream &o, const Indirection<A> &x) {
|
||||
return o << *x;
|
||||
}
|
||||
} // namespace parser
|
||||
} // namespace Fortran
|
||||
#endif // FORTRAN_INDIRECTION_H_
|
@ -1,6 +1,7 @@
|
||||
#include "message.h"
|
||||
|
||||
namespace Fortran {
|
||||
namespace parser {
|
||||
|
||||
std::ostream &operator<<(std::ostream &o, const Message &msg) {
|
||||
if (msg.context()) {
|
||||
@ -21,4 +22,5 @@ std::ostream &operator<<(std::ostream &o, const Messages &ms) {
|
||||
}
|
||||
return o;
|
||||
}
|
||||
} // namespace parser
|
||||
} // namespace Fortran
|
@ -13,6 +13,7 @@
|
||||
#include <string>
|
||||
|
||||
namespace Fortran {
|
||||
namespace parser {
|
||||
|
||||
class Message;
|
||||
using MessageContext = std::shared_ptr<Message>;
|
||||
@ -103,5 +104,6 @@ private:
|
||||
|
||||
std::ostream &operator<<(std::ostream &, const Message &);
|
||||
std::ostream &operator<<(std::ostream &, const Messages &);
|
||||
} // namespace parser
|
||||
} // namespace Fortran
|
||||
#endif // FORTRAN_MESSAGE_H_
|
@ -17,6 +17,7 @@
|
||||
#include <utility>
|
||||
|
||||
namespace Fortran {
|
||||
namespace parser {
|
||||
|
||||
class UserState;
|
||||
|
||||
@ -228,5 +229,6 @@ private:
|
||||
// reflected in the copy and move constructors defined at the top of this
|
||||
// class definition!
|
||||
};
|
||||
} // namespace parser
|
||||
} // namespace Fortran
|
||||
#endif // FORTRAN_PARSE_STATE_H_
|
@ -4,6 +4,7 @@
|
||||
#include <algorithm>
|
||||
|
||||
namespace Fortran {
|
||||
namespace parser {
|
||||
|
||||
#define UNION_FORMATTER(TYPE) \
|
||||
std::ostream &operator<<(std::ostream &o, const TYPE &x) { \
|
||||
@ -1085,4 +1086,5 @@ std::ostream &operator<<(std::ostream &o, const ProcedureStmt &x) {
|
||||
std::ostream &operator<<(std::ostream &o, const Suffix &x) {
|
||||
return o << "(Suffix " << x.binding << ' ' << x.resultName << ')';
|
||||
}
|
||||
} // namespace parser
|
||||
} // namespace Fortran
|
@ -83,6 +83,7 @@
|
||||
}
|
||||
|
||||
namespace Fortran {
|
||||
namespace parser {
|
||||
|
||||
// These are the unavoidable recursively-defined productions of Fortran.
|
||||
// Some references to the representations of their parses require
|
||||
@ -3222,5 +3223,6 @@ std::ostream &operator<<(std::ostream &o, const LoopBounds<A> &x) {
|
||||
return o << "(LoopBounds " << x.name << ' ' << x.lower << ' ' << x.upper
|
||||
<< ' ' << x.step << ')';
|
||||
}
|
||||
} // namespace parser
|
||||
} // namespace Fortran
|
||||
#endif // FORTRAN_PARSE_TREE_H_
|
@ -1,7 +1,9 @@
|
||||
#include "position.h"
|
||||
|
||||
namespace Fortran {
|
||||
namespace parser {
|
||||
std::ostream &operator<<(std::ostream &o, const Position &x) {
|
||||
return o << "(at line " << x.lineNumber() << ", column " << x.column() << ')';
|
||||
}
|
||||
} // namespace parser
|
||||
} // namespace Fortran
|
@ -8,6 +8,7 @@
|
||||
#include <ostream>
|
||||
|
||||
namespace Fortran {
|
||||
namespace parser {
|
||||
|
||||
class Position {
|
||||
public:
|
||||
@ -70,5 +71,6 @@ private:
|
||||
};
|
||||
|
||||
std::ostream &operator<<(std::ostream &, const Position &);
|
||||
} // namespace parser
|
||||
} // namespace Fortran
|
||||
#endif // FORTRAN_POSITION_H_
|
@ -13,6 +13,7 @@
|
||||
#include <utility>
|
||||
|
||||
namespace Fortran {
|
||||
namespace parser {
|
||||
|
||||
bool CharPointerWithLength::IsBlank() const {
|
||||
for (size_t j{0}; j < bytes_; ++j) {
|
||||
@ -937,4 +938,5 @@ bool Preprocessor::IsIfPredicateTrue(
|
||||
}
|
||||
return result;
|
||||
}
|
||||
} // namespace parser
|
||||
} // namespace Fortran
|
@ -19,6 +19,7 @@
|
||||
#include <vector>
|
||||
|
||||
namespace Fortran {
|
||||
namespace parser {
|
||||
|
||||
class CharBuffer;
|
||||
class Prescanner;
|
||||
@ -50,11 +51,12 @@ private:
|
||||
const char *data_{nullptr};
|
||||
size_t bytes_{0};
|
||||
};
|
||||
} // namespace parser
|
||||
} // namespace Fortran
|
||||
|
||||
// Specializations to enable std::unordered_map<CharPointerWithLength, ...>
|
||||
template<> struct std::hash<Fortran::CharPointerWithLength> {
|
||||
size_t operator()(const Fortran::CharPointerWithLength &x) const {
|
||||
template<> struct std::hash<Fortran::parser::CharPointerWithLength> {
|
||||
size_t operator()(const Fortran::parser::CharPointerWithLength &x) const {
|
||||
size_t hash{0}, bytes{x.size()};
|
||||
for (size_t j{0}; j < bytes; ++j) {
|
||||
hash = (hash * 31) ^ x[j];
|
||||
@ -63,9 +65,9 @@ template<> struct std::hash<Fortran::CharPointerWithLength> {
|
||||
}
|
||||
};
|
||||
|
||||
template<> struct std::equal_to<Fortran::CharPointerWithLength> {
|
||||
bool operator()(const Fortran::CharPointerWithLength &x,
|
||||
const Fortran::CharPointerWithLength &y) const {
|
||||
template<> struct std::equal_to<Fortran::parser::CharPointerWithLength> {
|
||||
bool operator()(const Fortran::parser::CharPointerWithLength &x,
|
||||
const Fortran::parser::CharPointerWithLength &y) const {
|
||||
return x.size() == y.size() &&
|
||||
std::memcmp(static_cast<const void *>(&x[0]),
|
||||
static_cast<const void *>(&y[0]), x.size()) == 0;
|
||||
@ -73,6 +75,7 @@ template<> struct std::equal_to<Fortran::CharPointerWithLength> {
|
||||
};
|
||||
|
||||
namespace Fortran {
|
||||
namespace parser {
|
||||
|
||||
// Buffers a contiguous sequence of characters that has been partitioned into
|
||||
// a sequence of preprocessing tokens.
|
||||
@ -199,5 +202,6 @@ private:
|
||||
std::unordered_map<CharPointerWithLength, Definition> definitions_;
|
||||
std::stack<CanDeadElseAppear> ifStack_;
|
||||
};
|
||||
} // namespace parser
|
||||
} // namespace Fortran
|
||||
#endif // FORTRAN_PREPROCESSOR_H_
|
@ -8,6 +8,7 @@
|
||||
#include <vector>
|
||||
|
||||
namespace Fortran {
|
||||
namespace parser {
|
||||
|
||||
CharBuffer Prescanner::Prescan(const SourceFile &source) {
|
||||
sourceFile_ = &source;
|
||||
@ -490,4 +491,5 @@ void Prescanner::PayNewlineDebt(CharBuffer *out) {
|
||||
out->Put('\n');
|
||||
}
|
||||
}
|
||||
} // namespace parser
|
||||
} // namespace Fortran
|
@ -20,6 +20,7 @@
|
||||
#include <optional>
|
||||
|
||||
namespace Fortran {
|
||||
namespace parser {
|
||||
|
||||
class Prescanner {
|
||||
public:
|
||||
@ -109,5 +110,6 @@ private:
|
||||
int delimiterNesting_{0};
|
||||
Preprocessor preprocessor_;
|
||||
};
|
||||
} // namespace parser
|
||||
} // namespace Fortran
|
||||
#endif // FORTRAN_PRESCAN_H_
|
@ -14,6 +14,7 @@
|
||||
// TODO: Port to Windows &c.
|
||||
|
||||
namespace Fortran {
|
||||
namespace parser {
|
||||
|
||||
SourceFile::~SourceFile() { Close(); }
|
||||
|
||||
@ -122,4 +123,5 @@ void SourceFile::Close() {
|
||||
}
|
||||
path_.clear();
|
||||
}
|
||||
} // namespace parser
|
||||
} // namespace Fortran
|
@ -9,6 +9,7 @@
|
||||
#include <string>
|
||||
|
||||
namespace Fortran {
|
||||
namespace parser {
|
||||
|
||||
class SourceFile {
|
||||
public:
|
||||
@ -27,5 +28,6 @@ private:
|
||||
const char *content_{nullptr};
|
||||
size_t bytes_{0};
|
||||
};
|
||||
} // namespace parser
|
||||
} // namespace Fortran
|
||||
#endif // FORTRAN_SOURCE_H_
|
@ -10,6 +10,7 @@
|
||||
#include <unordered_set>
|
||||
|
||||
namespace Fortran {
|
||||
namespace parser {
|
||||
class UserState {
|
||||
public:
|
||||
using Label = std::uint64_t;
|
||||
@ -35,5 +36,6 @@ private:
|
||||
std::unordered_set<Label> doLabels_;
|
||||
int nonlabelDoConstructNestingDepth_{0};
|
||||
};
|
||||
}; // namespace Fortran
|
||||
} // namespace parser
|
||||
} // namespace Fortran
|
||||
#endif // FORTRAN_USER_STATE_H_
|
@ -1,15 +1,15 @@
|
||||
// Temporary Fortran front end driver main program for development scaffolding.
|
||||
|
||||
#include "basic-parsers.h"
|
||||
#include "char-buffer.h"
|
||||
#include "cooked-chars.h"
|
||||
#include "grammar.h"
|
||||
#include "idioms.h"
|
||||
#include "message.h"
|
||||
#include "parse-tree.h"
|
||||
#include "prescan.h"
|
||||
#include "source.h"
|
||||
#include "user-state.h"
|
||||
#include "../../lib/parser/basic-parsers.h"
|
||||
#include "../../lib/parser/char-buffer.h"
|
||||
#include "../../lib/parser/cooked-chars.h"
|
||||
#include "../../lib/parser/grammar.h"
|
||||
#include "../../lib/parser/idioms.h"
|
||||
#include "../../lib/parser/message.h"
|
||||
#include "../../lib/parser/parse-tree.h"
|
||||
#include "../../lib/parser/prescan.h"
|
||||
#include "../../lib/parser/source.h"
|
||||
#include "../../lib/parser/user-state.h"
|
||||
#include <cerrno>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
@ -36,9 +36,11 @@ std::list<std::string> argList(int argc, char *const argv[]) {
|
||||
} // namespace
|
||||
|
||||
namespace Fortran {
|
||||
namespace parser {
|
||||
constexpr auto grammar = program;
|
||||
} // namespace parser
|
||||
} // namespace Fortran
|
||||
using Fortran::grammar;
|
||||
using Fortran::parser::grammar;
|
||||
|
||||
int main(int argc, char *const argv[]) {
|
||||
|
||||
@ -97,7 +99,7 @@ int main(int argc, char *const argv[]) {
|
||||
}
|
||||
}
|
||||
|
||||
Fortran::SourceFile source;
|
||||
Fortran::parser::SourceFile source;
|
||||
std::stringstream error;
|
||||
if (!source.Open(path, &error)) {
|
||||
std::cerr << error.str() << '\n';
|
||||
@ -108,9 +110,9 @@ int main(int argc, char *const argv[]) {
|
||||
size_t sourceBytes{source.bytes()};
|
||||
std::unique_ptr<char[]> prescanned;
|
||||
if (prescan) {
|
||||
Fortran::Messages messages;
|
||||
Fortran::Prescanner prescanner{messages};
|
||||
Fortran::CharBuffer buffer{
|
||||
Fortran::parser::Messages messages;
|
||||
Fortran::parser::Prescanner prescanner{messages};
|
||||
Fortran::parser::CharBuffer buffer{
|
||||
prescanner.set_fixedForm(fixedForm)
|
||||
.set_enableBackslashEscapesInCharLiterals(backslashEscapes)
|
||||
.set_fixedFormColumnLimit(columns)
|
||||
@ -128,7 +130,7 @@ int main(int argc, char *const argv[]) {
|
||||
columns = std::numeric_limits<int>::max();
|
||||
}
|
||||
|
||||
Fortran::ParseState state{sourceContent, sourceBytes};
|
||||
Fortran::parser::ParseState state{sourceContent, sourceBytes};
|
||||
state.set_prescanned(prescan);
|
||||
state.set_inFixedForm(fixedForm);
|
||||
state.set_enableBackslashEscapesInCharLiterals(backslashEscapes);
|
||||
@ -136,11 +138,12 @@ int main(int argc, char *const argv[]) {
|
||||
state.set_columns(columns);
|
||||
state.set_enableOldDebugLines(enableOldDebugLines);
|
||||
state.PushContext("source file '"s + path + "'");
|
||||
Fortran::UserState ustate;
|
||||
Fortran::parser::UserState ustate;
|
||||
state.set_userState(&ustate);
|
||||
|
||||
if (dumpCookedChars) {
|
||||
while (std::optional<char> och{Fortran::cookedNextChar.Parse(&state)}) {
|
||||
while (std::optional<char>
|
||||
och{Fortran::parser::cookedNextChar.Parse(&state)}) {
|
||||
std::cout << *och;
|
||||
}
|
||||
return 0;
|
||||
@ -149,7 +152,7 @@ int main(int argc, char *const argv[]) {
|
||||
std::optional<typename decltype(grammar)::resultType> result;
|
||||
#if 0
|
||||
for (int j = 0; j < 1000; ++j) {
|
||||
Fortran::ParseState state1{state};
|
||||
Fortran::parser::ParseState state1{state};
|
||||
result = grammar.Parse(&state1);
|
||||
if (!result) {
|
||||
std::cerr << "demo FAIL in timing loop\n";
|
Loading…
Reference in New Issue
Block a user