Pass command line arguments to main
This commit is contained in:
@ -1,3 +1,5 @@
|
||||
#include <array>
|
||||
|
||||
#include "elna/gcc/elna-generic.h"
|
||||
#include "elna/gcc/elna-diagnostic.h"
|
||||
|
||||
@ -94,11 +96,11 @@ namespace gcc
|
||||
{
|
||||
constant->accept(this);
|
||||
}
|
||||
tree parameter_types[] = {
|
||||
std::array<tree, 2> parameter_types{
|
||||
integer_type_node,
|
||||
build_pointer_type(build_pointer_type(char_type_node))
|
||||
};
|
||||
tree declaration_type = build_function_type_array(integer_type_node, 2, parameter_types);
|
||||
tree declaration_type = build_function_type_array(integer_type_node, 2, parameter_types.data());
|
||||
this->main_fndecl = build_fn_decl("main", declaration_type);
|
||||
tree resdecl = build_decl(UNKNOWN_LOCATION, RESULT_DECL, NULL_TREE, integer_type_node);
|
||||
DECL_CONTEXT(resdecl) = this->main_fndecl;
|
||||
@ -106,6 +108,19 @@ namespace gcc
|
||||
|
||||
enter_scope();
|
||||
|
||||
tree_chain argument_chain;
|
||||
for (std::size_t i = 0; i < 2; ++i)
|
||||
{
|
||||
std::string argument_name = i == 0 ? "count" : "parameters";
|
||||
tree argc_declaration_tree = build_decl(UNKNOWN_LOCATION, PARM_DECL,
|
||||
get_identifier(argument_name.c_str()), parameter_types[i]);
|
||||
DECL_CONTEXT(argc_declaration_tree) = this->main_fndecl;
|
||||
DECL_ARG_TYPE(argc_declaration_tree) = parameter_types[i];
|
||||
this->symbol_map->enter(argument_name, boot::make_info(argc_declaration_tree));
|
||||
argument_chain.append(argc_declaration_tree);
|
||||
}
|
||||
DECL_ARGUMENTS(this->main_fndecl) = argument_chain.head();
|
||||
|
||||
for (const auto body_statement : program->body)
|
||||
{
|
||||
body_statement->accept(this);
|
||||
@ -152,7 +167,7 @@ namespace gcc
|
||||
|
||||
enter_scope();
|
||||
}
|
||||
gcc::tree_chain argument_chain;
|
||||
tree_chain argument_chain;
|
||||
for (std::size_t i = 0; i < definition->parameters.size(); ++i)
|
||||
{
|
||||
auto parameter = definition->parameters.at(i);
|
||||
@ -241,7 +256,9 @@ namespace gcc
|
||||
|
||||
void generic_visitor::visit(boot::number_literal<bool> *boolean)
|
||||
{
|
||||
this->current_expression = build_int_cst_type(boolean_type_node, boolean->number());
|
||||
auto symbol = this->symbol_map->lookup("Bool");
|
||||
|
||||
this->current_expression = build_int_cst_type(symbol->payload, boolean->number());
|
||||
}
|
||||
|
||||
void generic_visitor::visit(boot::number_literal<unsigned char> *character)
|
||||
|
Reference in New Issue
Block a user