Add GCC backend glue

This commit is contained in:
2024-12-27 10:51:46 +01:00
parent 40306ac986
commit 51f5603c4a
24 changed files with 601 additions and 329 deletions

View File

@ -15,10 +15,13 @@ namespace gcc
class generic_visitor final : public source::empty_visitor
{
tree current_statements{ NULL_TREE };
tree current_expression{ NULL_TREE };
public:
void visit(source::program *program) override;
void visit(source::call_statement *statement) override;
void visit(source::integer_literal *literal) override;
void visit(source::binary_expression *expression) override;
};
}
}

View File

@ -1,5 +1,9 @@
// This Source Code Form is subject to the terms of the Mozilla Public License
// v. 2.0. If a copy of the MPL was not distributed with this file, You can
// obtain one at http://mozilla.org/MPL/2.0/.
#pragma once
#include <cstdint>
#include <memory>
#include "elna/source/result.h"
#include "elna/source/types.h"

View File

@ -1,3 +1,6 @@
// This Source Code Form is subject to the terms of the Mozilla Public License
// v. 2.0. If a copy of the MPL was not distributed with this file, You can
// obtain one at http://mozilla.org/MPL/2.0/.
#pragma once
#include <list>
@ -16,7 +19,7 @@ namespace source
public:
syntax_error(const std::string& message,
const std::filesystem::path& input_file, const yy::location& location);
const char *input_file, const yy::location& location);
virtual std::string what() const override;
};
@ -24,12 +27,12 @@ namespace source
class driver
{
std::list<std::unique_ptr<struct error>> m_errors;
const std::filesystem::path input_file;
const char *input_file;
public:
std::unique_ptr<program> tree;
driver(const std::filesystem::path& input_file);
driver(const char *input_file);
void error(const yy::location& loc, const std::string& message);
const std::list<std::unique_ptr<struct error>>& errors() const noexcept;

View File

@ -1,7 +1,9 @@
// This Source Code Form is subject to the terms of the Mozilla Public License
// v. 2.0. If a copy of the MPL was not distributed with this file, You can
// obtain one at http://mozilla.org/MPL/2.0/.
#pragma once
#include <cstddef>
#include <filesystem>
#include "elna/source/types.h"
namespace elna
@ -26,7 +28,6 @@ namespace source
class error
{
position m_position;
std::filesystem::path m_path;
protected:
/**
@ -35,9 +36,11 @@ namespace source
* \param path Source file name.
* \param position Error position in the source text.
*/
error(const std::filesystem::path& path, const position position);
error(const char *path, const position position);
public:
const char *path;
virtual ~error() noexcept = default;
/// Error text.
@ -48,9 +51,6 @@ namespace source
/// Error column in the source text.
std::size_t column() const noexcept;
/// Source file name.
const std::filesystem::path& path() const noexcept;
};
class name_collision final : public error
@ -65,7 +65,7 @@ namespace source
* \param current Current symbol position.
* \param previous Position of the previously defined symbol.
*/
name_collision(const std::string& name, const std::filesystem::path& path,
name_collision(const std::string& name, const char *path,
const position current, const position previous);
std::string what() const override;
@ -92,7 +92,7 @@ namespace source
* \param path Source file name.
* \param position Operation position.
*/
type_mismatch(std::shared_ptr<const type> got, operation kind, const std::filesystem::path& path,
type_mismatch(std::shared_ptr<const type> got, operation kind, const char *path,
const struct position position);
std::string what() const override;

View File

@ -1,3 +1,6 @@
// This Source Code Form is subject to the terms of the Mozilla Public License
// v. 2.0. If a copy of the MPL was not distributed with this file, You can
// obtain one at http://mozilla.org/MPL/2.0/.
#pragma once
#include <list>
@ -11,7 +14,7 @@ namespace source
class name_analysis_visitor final : public empty_visitor
{
std::shared_ptr<symbol_table> table;
const std::filesystem::path filename;
const char *filename;
std::list<std::unique_ptr<error>> m_errors;
const std::size_t pointer_size;
@ -23,7 +26,7 @@ namespace source
* \param path Source filename.
* \param target_pointer_size Pointer size on the target platform.
*/
name_analysis_visitor(std::shared_ptr<symbol_table> table, const std::filesystem::path& filename,
name_analysis_visitor(std::shared_ptr<symbol_table> table, const char *filename,
const std::size_t target_pointer_size);
/**
@ -62,7 +65,7 @@ namespace source
class type_analysis_visitor final : public empty_visitor
{
std::shared_ptr<symbol_table> table;
const std::filesystem::path filename;
const char *filename;
const std::size_t pointer_size;
std::list<std::unique_ptr<error>> m_errors;
@ -72,7 +75,7 @@ namespace source
* \param path Source filename.
* \param target_pointer_size Pointer size on the target platform.
*/
type_analysis_visitor(std::shared_ptr<symbol_table> table, const std::filesystem::path& filename,
type_analysis_visitor(std::shared_ptr<symbol_table> table, const char *filename,
const std::size_t target_pointer_size);
/**

View File

@ -1,3 +1,6 @@
// This Source Code Form is subject to the terms of the Mozilla Public License
// v. 2.0. If a copy of the MPL was not distributed with this file, You can
// obtain one at http://mozilla.org/MPL/2.0/.
#pragma once
#include <cstdint>

View File

@ -1,3 +1,6 @@
// This Source Code Form is subject to the terms of the Mozilla Public License
// v. 2.0. If a copy of the MPL was not distributed with this file, You can
// obtain one at http://mozilla.org/MPL/2.0/.
#pragma once
#include <memory>