Move reader related files to the reader namespace
This commit is contained in:
parent
e9daeb9d13
commit
f50e20567a
|
@ -1,11 +1,11 @@
|
||||||
add_executable(serene serene.cpp)
|
add_executable(serenec serene.cpp)
|
||||||
# Make sure to generate files related to the dialects first
|
# Make sure to generate files related to the dialects first
|
||||||
add_dependencies(serene SereneDialectGen)
|
add_dependencies(serenec SereneDialectGen)
|
||||||
|
|
||||||
target_compile_features(serene PRIVATE cxx_std_14)
|
target_compile_features(serenec PRIVATE cxx_std_14)
|
||||||
|
|
||||||
target_link_libraries(serene PRIVATE
|
target_link_libraries(serenec PRIVATE
|
||||||
lserene
|
serene
|
||||||
${llvm_libs}
|
${llvm_libs}
|
||||||
fmt::fmt
|
fmt::fmt
|
||||||
MLIRAnalysis
|
MLIRAnalysis
|
||||||
|
@ -19,6 +19,6 @@ target_link_libraries(serene PRIVATE
|
||||||
target_include_directories(serene SYSTEM PRIVATE $ENV{INCLUDE})
|
target_include_directories(serene SYSTEM PRIVATE $ENV{INCLUDE})
|
||||||
target_include_directories(serene PRIVATE ${INCLUDE_DIR})
|
target_include_directories(serene PRIVATE ${INCLUDE_DIR})
|
||||||
|
|
||||||
install(TARGETS serene DESTINATION bin)
|
install(TARGETS serenec DESTINATION bin)
|
||||||
install(FILES "${PROJECT_BINARY_DIR}/config.h" DESTINATION include)
|
install(FILES "${PROJECT_BINARY_DIR}/config.h" DESTINATION include)
|
||||||
cotire(serene)
|
cotire(serenec)
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "serene/serene.hpp"
|
#include "serene/serene.hpp"
|
||||||
#include "serene/reader.hpp"
|
#include "serene/reader/reader.hpp"
|
||||||
#include "serene/sir/sir.hpp"
|
#include "serene/sir/sir.hpp"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <llvm/Support/CommandLine.h>
|
#include <llvm/Support/CommandLine.h>
|
||||||
|
@ -52,13 +52,13 @@ int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
switch (emitAction) {
|
switch (emitAction) {
|
||||||
case Action::DumpAST: {
|
case Action::DumpAST: {
|
||||||
FileReader *r = new FileReader(inputFile);
|
reader::FileReader *r = new reader::FileReader(inputFile);
|
||||||
r->dumpAST();
|
r->dumpAST();
|
||||||
delete r;
|
delete r;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
case Action::DumpIR: {
|
case Action::DumpIR: {
|
||||||
FileReader *r = new FileReader(inputFile);
|
reader::FileReader *r = new reader::FileReader(inputFile);
|
||||||
|
|
||||||
serene::sir::dumpSIR(*r->read());
|
serene::sir::dumpSIR(*r->read());
|
||||||
delete r;
|
delete r;
|
||||||
|
|
2
builder
2
builder
|
@ -47,7 +47,7 @@ function clean() {
|
||||||
|
|
||||||
function run() {
|
function run() {
|
||||||
pushed_build
|
pushed_build
|
||||||
$BUILD_DIR/bin/serene "$@"
|
$BUILD_DIR/bin/serenec "$@"
|
||||||
popd_build
|
popd_build
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,48 @@
|
||||||
|
/**
|
||||||
|
* Serene programming language.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2020 Sameer Rahmani <lxsameer@gnu.org>
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef LOCATION_H
|
||||||
|
#define LOCATION_H
|
||||||
|
|
||||||
|
namespace serene {
|
||||||
|
namespace reader {
|
||||||
|
/**
|
||||||
|
* It represents a location in the input string to the parser via `line`,
|
||||||
|
*/
|
||||||
|
struct Location {
|
||||||
|
int pos; // Position of in the input string.
|
||||||
|
int line;
|
||||||
|
int col;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct LocationRange {
|
||||||
|
Location start;
|
||||||
|
Location end;
|
||||||
|
};
|
||||||
|
|
||||||
|
void inc_location(Location &, bool);
|
||||||
|
|
||||||
|
} // namespace reader
|
||||||
|
} // namespace serene
|
||||||
|
#endif
|
|
@ -36,6 +36,7 @@
|
||||||
#include "serene/expr.hpp"
|
#include "serene/expr.hpp"
|
||||||
#include "serene/list.hpp"
|
#include "serene/list.hpp"
|
||||||
#include "serene/logger.hpp"
|
#include "serene/logger.hpp"
|
||||||
|
#include "serene/reader/location.hpp"
|
||||||
#include "serene/serene.hpp"
|
#include "serene/serene.hpp"
|
||||||
#include "serene/symbol.hpp"
|
#include "serene/symbol.hpp"
|
||||||
|
|
||||||
|
@ -46,6 +47,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace serene {
|
namespace serene {
|
||||||
|
namespace reader {
|
||||||
|
|
||||||
class ReadError : public std::exception {
|
class ReadError : public std::exception {
|
||||||
private:
|
private:
|
||||||
|
@ -59,6 +61,7 @@ public:
|
||||||
class Reader {
|
class Reader {
|
||||||
private:
|
private:
|
||||||
std::stringstream input_stream;
|
std::stringstream input_stream;
|
||||||
|
Location current_location{0, 0, 0};
|
||||||
|
|
||||||
char get_char(bool skip_whitespace);
|
char get_char(bool skip_whitespace);
|
||||||
void unget_char();
|
void unget_char();
|
||||||
|
@ -99,6 +102,6 @@ public:
|
||||||
|
|
||||||
~FileReader();
|
~FileReader();
|
||||||
};
|
};
|
||||||
|
} // namespace reader
|
||||||
} // namespace serene
|
} // namespace serene
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -74,7 +74,10 @@ def ValueOp: Serene_Op<"value"> {
|
||||||
// let verifier = [{ return serene::sir::verify(*this); }];
|
// let verifier = [{ return serene::sir::verify(*this); }];
|
||||||
|
|
||||||
let builders = [
|
let builders = [
|
||||||
OpBuilder<(ins "int":$value)>,
|
OpBuilder<(ins "int":$value), [{
|
||||||
|
// Build from fix 64 bit int
|
||||||
|
build(odsBuilder, odsState, odsBuilder.getI64Type(), (uint64_t) value);
|
||||||
|
}]>,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,37 +1,46 @@
|
||||||
# Optionally glob, but only for CMake 3.12 or later:
|
|
||||||
#file(GLOB HEADER_LIST CONFIGURE_DEPENDS "${INCLUDE_DIR}/**/*.hpp")
|
|
||||||
#file(GLOB SOURCES_LIST CONFIGURE_DEPENDS "${SOURCE_DIR}/**/*.cpp")
|
|
||||||
set(HEADER_LIST
|
set(HEADER_LIST
|
||||||
"${INCLUDE_DIR}/serene/expr.hpp"
|
"${INCLUDE_DIR}/serene/expr.hpp"
|
||||||
"${INCLUDE_DIR}/serene/serene.hpp"
|
"${INCLUDE_DIR}/serene/serene.hpp"
|
||||||
"${INCLUDE_DIR}/serene/state.hpp"
|
"${INCLUDE_DIR}/serene/state.hpp"
|
||||||
|
# Reader
|
||||||
|
"${INCLUDE_DIR}/serene/reader/reader.hpp"
|
||||||
|
"${INCLUDE_DIR}/serene/reader/location.hpp"
|
||||||
|
|
||||||
|
|
||||||
"${INCLUDE_DIR}/serene/sir/sir.hpp"
|
"${INCLUDE_DIR}/serene/sir/sir.hpp"
|
||||||
"${INCLUDE_DIR}/serene/sir/dialect.hpp"
|
"${INCLUDE_DIR}/serene/sir/dialect.hpp"
|
||||||
"${INCLUDE_DIR}/serene/sir/generator.hpp"
|
"${INCLUDE_DIR}/serene/sir/generator.hpp"
|
||||||
"${INCLUDE_DIR}/serene/namespace.hpp")
|
"${INCLUDE_DIR}/serene/namespace.hpp")
|
||||||
|
|
||||||
# Make an automatic library - will be static or dynamic based on user setting
|
# Make an automatic library - will be static or dynamic based on user setting
|
||||||
add_library(lserene
|
add_library(serene
|
||||||
serene.cpp
|
serene.cpp
|
||||||
reader.cpp
|
|
||||||
symbol.cpp
|
symbol.cpp
|
||||||
list.cpp
|
list.cpp
|
||||||
namespace.cpp
|
namespace.cpp
|
||||||
state.cpp
|
state.cpp
|
||||||
|
|
||||||
|
# Reader
|
||||||
|
reader/reader.cpp
|
||||||
|
reader/location.cpp
|
||||||
|
|
||||||
|
# IR
|
||||||
sir/sir.cpp
|
sir/sir.cpp
|
||||||
sir/dialect.cpp
|
sir/dialect.cpp
|
||||||
sir/value_op.cpp
|
sir/value_op.cpp
|
||||||
sir/generator.cpp
|
sir/generator.cpp
|
||||||
${HEADER_LIST})
|
${HEADER_LIST})
|
||||||
|
|
||||||
|
|
||||||
# Make sure to generate files related to the dialects first
|
# Make sure to generate files related to the dialects first
|
||||||
add_dependencies(lserene SereneDialectGen)
|
add_dependencies(serene SereneDialectGen)
|
||||||
|
|
||||||
# We need this directory, and users of our library will need it too
|
# We need this directory, and users of our library will need it too
|
||||||
target_compile_features(lserene PUBLIC cxx_std_14)
|
target_compile_features(serene PUBLIC cxx_std_14)
|
||||||
target_include_directories(lserene PRIVATE ${INCLUDE_DIR})
|
target_include_directories(serene PRIVATE ${INCLUDE_DIR})
|
||||||
target_include_directories(lserene PUBLIC ${PROJECT_BINARY_DIR})
|
target_include_directories(serene PUBLIC ${PROJECT_BINARY_DIR})
|
||||||
|
|
||||||
# This depends on (header only) boost
|
# This depends on (header only) boost
|
||||||
target_link_libraries(lserene ${llvm_libs} fmt::fmt)
|
target_link_libraries(serene ${llvm_libs} fmt::fmt)
|
||||||
source_group(TREE "${INCLUDE_DIR}" PREFIX "Header Files" FILES ${HEADER_LIST})
|
source_group(TREE "${INCLUDE_DIR}" PREFIX "Header Files" FILES ${HEADER_LIST})
|
||||||
|
#target_precompile_headers(serene PRIVATE ${HEADER_LIST})
|
||||||
|
|
|
@ -0,0 +1,48 @@
|
||||||
|
/**
|
||||||
|
* Serene programming language.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2020 Sameer Rahmani <lxsameer@gnu.org>
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "serene/reader/location.hpp"
|
||||||
|
|
||||||
|
namespace serene {
|
||||||
|
namespace reader {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Increase the given location by one and set the line/col value in respect to
|
||||||
|
* the `newline` in place.
|
||||||
|
* @param loc The `Location` data
|
||||||
|
* @param newline Whether or not we reached a new line
|
||||||
|
*/
|
||||||
|
void inc_location(Location &loc, bool newline) {
|
||||||
|
loc.pos++;
|
||||||
|
|
||||||
|
if (!newline) {
|
||||||
|
loc.col++;
|
||||||
|
} else {
|
||||||
|
loc.col = 0;
|
||||||
|
loc.line++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace reader
|
||||||
|
} // namespace serene
|
|
@ -22,7 +22,7 @@
|
||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "serene/reader.hpp"
|
#include "serene/reader/reader.hpp"
|
||||||
#include "serene/error.hpp"
|
#include "serene/error.hpp"
|
||||||
#include "serene/list.hpp"
|
#include "serene/list.hpp"
|
||||||
#include "serene/symbol.hpp"
|
#include "serene/symbol.hpp"
|
||||||
|
@ -37,18 +37,31 @@
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
namespace serene {
|
namespace serene {
|
||||||
|
|
||||||
|
namespace reader {
|
||||||
Reader::Reader(const string input) { this->setInput(input); };
|
Reader::Reader(const string input) { this->setInput(input); };
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the input of the reader.
|
||||||
|
* @param input Set the input to the given string
|
||||||
|
*/
|
||||||
void Reader::setInput(const string input) {
|
void Reader::setInput(const string input) {
|
||||||
input_stream.write(input.c_str(), input.size());
|
input_stream.write(input.c_str(), input.size());
|
||||||
};
|
};
|
||||||
|
|
||||||
Reader::~Reader() { READER_LOG("Destroying the reader"); }
|
Reader::~Reader() { READER_LOG("Destroying the reader"); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the next character in the buffer.
|
||||||
|
* @param skip_whitespace If true it will skip whitespaces and EOL chars
|
||||||
|
*/
|
||||||
char Reader::get_char(bool skip_whitespace) {
|
char Reader::get_char(bool skip_whitespace) {
|
||||||
for (;;) {
|
for (;;) {
|
||||||
char c = input_stream.get();
|
char c = input_stream.get();
|
||||||
|
inc_location(current_location, c == '\n');
|
||||||
|
|
||||||
if (skip_whitespace == true && isspace(c)) {
|
if (skip_whitespace == true && isspace(c)) {
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
return c;
|
return c;
|
||||||
|
@ -205,5 +218,5 @@ FileReader::~FileReader() {
|
||||||
delete this->reader;
|
delete this->reader;
|
||||||
READER_LOG("Destroying the file reader");
|
READER_LOG("Destroying the file reader");
|
||||||
}
|
}
|
||||||
|
} // namespace reader
|
||||||
} // namespace serene
|
} // namespace serene
|
|
@ -23,5 +23,5 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "serene/serene.hpp"
|
#include "serene/serene.hpp"
|
||||||
#include "serene/reader.hpp"
|
#include "serene/reader/reader.hpp"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
|
@ -28,11 +28,5 @@
|
||||||
#include "serene/sir/sir.hpp"
|
#include "serene/sir/sir.hpp"
|
||||||
|
|
||||||
namespace serene {
|
namespace serene {
|
||||||
namespace sir {
|
namespace sir {} // namespace sir
|
||||||
void ValueOp::build(::mlir::OpBuilder &odsBuilder,
|
|
||||||
::mlir::OperationState &odsState, int value) {
|
|
||||||
ValueOp::build(odsBuilder, odsState, odsBuilder.getI64Type(),
|
|
||||||
(uint64_t)value);
|
|
||||||
}
|
|
||||||
} // namespace sir
|
|
||||||
} // namespace serene
|
} // namespace serene
|
||||||
|
|
|
@ -13,7 +13,7 @@ add_executable(tests serenetests.cpp)
|
||||||
target_compile_features(tests PRIVATE cxx_std_20)
|
target_compile_features(tests PRIVATE cxx_std_20)
|
||||||
|
|
||||||
# Should be linked to the main library, as well as the Catch2 testing library
|
# Should be linked to the main library, as well as the Catch2 testing library
|
||||||
target_link_libraries(tests PRIVATE lserene Catch2::Catch2)
|
target_link_libraries(tests PRIVATE serene Catch2::Catch2)
|
||||||
|
|
||||||
# If you register a test, then ctest and make test will run it.
|
# If you register a test, then ctest and make test will run it.
|
||||||
# You can also run examples and check the output, as well.
|
# You can also run examples and check the output, as well.
|
||||||
|
|
Loading…
Reference in New Issue