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

@@ -1,3 +1,8 @@
/*
* 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/.
*/
%require "3.2"
%language "c++"
@@ -70,7 +75,7 @@
%type <std::vector<std::unique_ptr<elna::source::declaration>>> variable_declarations variable_declaration_part
formal_parameter_list;
%type <std::unique_ptr<elna::source::type_expression>> type_expression;
%type <std::unique_ptr<elna::source::expression>> expression pointer summand factor address;
%type <std::unique_ptr<elna::source::expression>> expression pointer summand factor address comparand;
%type <std::vector<std::unique_ptr<elna::source::expression>>> expressions actual_parameter_list;
%type <std::unique_ptr<elna::source::variable_expression>> variable_expression;
%type <std::unique_ptr<elna::source::compound_statement>> compound_statement;
@@ -81,24 +86,25 @@
%type <std::unique_ptr<elna::source::statement>> statement;
%type <std::vector<std::unique_ptr<elna::source::statement>>> statements optional_statements;
%type <std::unique_ptr<elna::source::procedure_definition>> procedure_definition;
%type <std::vector<std::unique_ptr<elna::source::procedure_definition>>> procedure_definitions;
%type <std::vector<std::unique_ptr<elna::source::procedure_definition>>> procedure_definitions
procedure_definition_part;
%type <std::unique_ptr<elna::source::block>> block;
%%
program: constant_definition_part variable_declaration_part procedure_definitions statement DOT
program: constant_definition_part procedure_definition_part variable_declaration_part statement DOT
{
std::vector<std::unique_ptr<elna::source::definition>> definitions($1.size() + $3.size());
std::vector<std::unique_ptr<elna::source::definition>> definitions($1.size() + $2.size());
std::vector<std::unique_ptr<elna::source::definition>>::iterator definition = definitions.begin();
for (auto& constant : $1)
{
*definition++ = std::move(constant);
}
for (auto& constant : $3)
for (auto& procedure : $2)
{
*definition++ = std::move(constant);
*definition++ = std::move(procedure);
}
driver.tree = std::make_unique<elna::source::program>(elna::source::position{},
std::move(definitions), std::move($2),
std::move(definitions), std::move($3),
std::move($4));
}
block: constant_definition_part variable_declaration_part statement
@@ -127,6 +133,9 @@ procedure_definitions:
$$.emplace($$.cbegin(), std::move($1));
}
| procedure_definition { $$.emplace_back(std::move($1)); }
procedure_definition_part:
/* no procedure definitions */ {}
| procedure_definitions { std::swap($$, $1); }
integer_literal: NUMBER
{
$$ = std::make_unique<elna::source::integer_literal>(elna::source::make_position(@1), $1);
@@ -191,38 +200,50 @@ factor:
std::move($2), '@');
}
| address { $$ = std::move($1); }
comparand:
summand PLUS summand
{
$$ = std::make_unique<elna::source::binary_expression>(elna::source::make_position(@1),
std::move($1), std::move($3), '+');
}
| summand MINUS summand
{
$$ = std::make_unique<elna::source::binary_expression>(elna::source::make_position(@1),
std::move($1), std::move($3), '-');
}
| summand { $$ = std::move($1); }
expression:
summand EQUALS summand
comparand EQUALS comparand
{
$$ = std::make_unique<elna::source::binary_expression>(elna::source::make_position(@1),
std::move($1), std::move($3), '=');
}
| summand NOT_EQUAL summand
| comparand NOT_EQUAL comparand
{
$$ = std::make_unique<elna::source::binary_expression>(elna::source::make_position(@1),
std::move($1), std::move($3), 'n');
}
| summand LESS_THAN summand
| comparand LESS_THAN comparand
{
$$ = std::make_unique<elna::source::binary_expression>(elna::source::make_position(@1),
std::move($1), std::move($3), '<');
}
| summand GREATER_THAN summand
| comparand GREATER_THAN comparand
{
$$ = std::make_unique<elna::source::binary_expression>(elna::source::make_position(@1),
std::move($1), std::move($3), '>');
}
| summand LESS_EQUAL summand
| comparand LESS_EQUAL comparand
{
$$ = std::make_unique<elna::source::binary_expression>(elna::source::make_position(@1),
std::move($1), std::move($3), '<');
}
| summand GREATER_EQUAL summand
| comparand GREATER_EQUAL comparand
{
$$ = std::make_unique<elna::source::binary_expression>(elna::source::make_position(@1),
std::move($1), std::move($3), '>');
}
| summand { $$ = std::move($1); }
| comparand { $$ = std::move($1); }
expressions:
expression COMMA expressions
{