Replace main_fndecl with current_function_decl
This commit is contained in:
parent
207ae0fa0a
commit
4bf88a92e8
14
Rakefile
14
Rakefile
@ -26,12 +26,14 @@ end
|
|||||||
desc 'Build cross toolchain'
|
desc 'Build cross toolchain'
|
||||||
task :cross, [:target] do |_, args|
|
task :cross, [:target] do |_, args|
|
||||||
args.with_defaults target: 'riscv32-unknown-linux-gnu'
|
args.with_defaults target: 'riscv32-unknown-linux-gnu'
|
||||||
|
options = find_build_target GCC_VERSION, args[:target]
|
||||||
|
|
||||||
Rake::Task['cross:binutils'].invoke args[:target]
|
options.tools.mkpath
|
||||||
Rake::Task['cross:gcc1'].invoke args[:target]
|
binutils options
|
||||||
Rake::Task['cross:headers'].invoke args[:target]
|
gcc1 options
|
||||||
Rake::Task['cross:kernel'].invoke args[:target]
|
headers options
|
||||||
Rake::Task['cross:glibc'].invoke args[:target]
|
kernel options
|
||||||
Rake::Task['cross:gcc2'].invoke args[:target]
|
glibc options
|
||||||
|
gcc2 options
|
||||||
Rake::Task['cross:init'].invoke args[:target]
|
Rake::Task['cross:init'].invoke args[:target]
|
||||||
end
|
end
|
||||||
|
@ -47,10 +47,11 @@ along with GCC; see the file COPYING3. If not see
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
\(\* BEGIN(IN_COMMENT);
|
\(\* BEGIN(IN_COMMENT);
|
||||||
[\ \t\r] ; /* Skip the whitespaces. */
|
[ \t\r] {
|
||||||
|
this->location.step();
|
||||||
|
}
|
||||||
\n+ {
|
\n+ {
|
||||||
this->location.lines(yyleng);
|
this->location.lines(yyleng);
|
||||||
this->location.step();
|
|
||||||
}
|
}
|
||||||
if {
|
if {
|
||||||
return yy::parser::make_IF(this->location);
|
return yy::parser::make_IF(this->location);
|
||||||
|
@ -123,10 +123,11 @@ namespace gcc
|
|||||||
build_pointer_type(build_pointer_type(char_type_node))
|
build_pointer_type(build_pointer_type(char_type_node))
|
||||||
};
|
};
|
||||||
tree declaration_type = build_function_type_array(integer_type_node, 2, parameter_types.data());
|
tree declaration_type = build_function_type_array(integer_type_node, 2, parameter_types.data());
|
||||||
this->main_fndecl = build_fn_decl("main", declaration_type);
|
tree fndecl = build_fn_decl("main", declaration_type);
|
||||||
|
current_function_decl = fndecl;
|
||||||
tree resdecl = build_decl(UNKNOWN_LOCATION, RESULT_DECL, NULL_TREE, integer_type_node);
|
tree resdecl = build_decl(UNKNOWN_LOCATION, RESULT_DECL, NULL_TREE, integer_type_node);
|
||||||
DECL_CONTEXT(resdecl) = this->main_fndecl;
|
DECL_CONTEXT(resdecl) = fndecl;
|
||||||
DECL_RESULT(this->main_fndecl) = resdecl;
|
DECL_RESULT(fndecl) = resdecl;
|
||||||
|
|
||||||
enter_scope();
|
enter_scope();
|
||||||
|
|
||||||
@ -136,33 +137,33 @@ namespace gcc
|
|||||||
std::string argument_name = i == 0 ? "count" : "parameters";
|
std::string argument_name = i == 0 ? "count" : "parameters";
|
||||||
tree argc_declaration_tree = build_decl(UNKNOWN_LOCATION, PARM_DECL,
|
tree argc_declaration_tree = build_decl(UNKNOWN_LOCATION, PARM_DECL,
|
||||||
get_identifier(argument_name.c_str()), parameter_types[i]);
|
get_identifier(argument_name.c_str()), parameter_types[i]);
|
||||||
DECL_CONTEXT(argc_declaration_tree) = this->main_fndecl;
|
DECL_CONTEXT(argc_declaration_tree) = fndecl;
|
||||||
DECL_ARG_TYPE(argc_declaration_tree) = parameter_types[i];
|
DECL_ARG_TYPE(argc_declaration_tree) = parameter_types[i];
|
||||||
this->symbol_map->enter(argument_name, argc_declaration_tree);
|
this->symbol_map->enter(argument_name, argc_declaration_tree);
|
||||||
argument_chain.append(argc_declaration_tree);
|
argument_chain.append(argc_declaration_tree);
|
||||||
}
|
}
|
||||||
DECL_ARGUMENTS(this->main_fndecl) = argument_chain.head();
|
DECL_ARGUMENTS(fndecl) = argument_chain.head();
|
||||||
|
|
||||||
for (boot::statement *const body_statement : program->body)
|
for (boot::statement *const body_statement : program->body)
|
||||||
{
|
{
|
||||||
body_statement->accept(this);
|
body_statement->accept(this);
|
||||||
}
|
}
|
||||||
tree set_result = build2(INIT_EXPR, void_type_node, DECL_RESULT(main_fndecl),
|
tree set_result = build2(INIT_EXPR, void_type_node, DECL_RESULT(fndecl),
|
||||||
build_int_cst_type(integer_type_node, 0));
|
build_int_cst_type(integer_type_node, 0));
|
||||||
tree return_stmt = build1(RETURN_EXPR, void_type_node, set_result);
|
tree return_stmt = build1(RETURN_EXPR, void_type_node, set_result);
|
||||||
this->scope.front().append_statement(return_stmt);
|
this->scope.front().append_statement(return_stmt);
|
||||||
tree_symbol_mapping mapping = leave_scope();
|
tree_symbol_mapping mapping = leave_scope();
|
||||||
|
|
||||||
BLOCK_SUPERCONTEXT(mapping.block()) = this->main_fndecl;
|
BLOCK_SUPERCONTEXT(mapping.block()) = fndecl;
|
||||||
DECL_INITIAL(this->main_fndecl) = mapping.block();
|
DECL_INITIAL(fndecl) = mapping.block();
|
||||||
DECL_SAVED_TREE(this->main_fndecl) = mapping.bind_expression();
|
DECL_SAVED_TREE(fndecl) = mapping.bind_expression();
|
||||||
|
|
||||||
DECL_EXTERNAL(this->main_fndecl) = 0;
|
DECL_EXTERNAL(fndecl) = 0;
|
||||||
DECL_PRESERVE_P(this->main_fndecl) = 1;
|
DECL_PRESERVE_P(fndecl) = 1;
|
||||||
|
|
||||||
gimplify_function_tree(this->main_fndecl);
|
current_function_decl = NULL_TREE;
|
||||||
|
gimplify_function_tree(fndecl);
|
||||||
cgraph_node::finalize_function(this->main_fndecl, true);
|
cgraph_node::finalize_function(fndecl, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void generic_visitor::visit(boot::procedure_definition *definition)
|
void generic_visitor::visit(boot::procedure_definition *definition)
|
||||||
@ -178,14 +179,15 @@ namespace gcc
|
|||||||
: build_type(*definition->return_type());
|
: build_type(*definition->return_type());
|
||||||
tree declaration_type = build_function_type_array(return_type,
|
tree declaration_type = build_function_type_array(return_type,
|
||||||
definition->parameters.size(), parameter_types.data());
|
definition->parameters.size(), parameter_types.data());
|
||||||
this->main_fndecl = build_fn_decl(definition->identifier.c_str(), declaration_type);
|
tree fndecl = build_fn_decl(definition->identifier.c_str(), declaration_type);
|
||||||
this->symbol_map->enter(definition->identifier, this->main_fndecl);
|
this->symbol_map->enter(definition->identifier, fndecl);
|
||||||
|
|
||||||
if (definition->body() != nullptr)
|
if (definition->body() != nullptr)
|
||||||
{
|
{
|
||||||
|
current_function_decl = fndecl;
|
||||||
tree resdecl = build_decl(UNKNOWN_LOCATION, RESULT_DECL, NULL_TREE, return_type);
|
tree resdecl = build_decl(UNKNOWN_LOCATION, RESULT_DECL, NULL_TREE, return_type);
|
||||||
DECL_CONTEXT(resdecl) = this->main_fndecl;
|
DECL_CONTEXT(resdecl) = fndecl;
|
||||||
DECL_RESULT(this->main_fndecl) = resdecl;
|
DECL_RESULT(fndecl) = resdecl;
|
||||||
|
|
||||||
enter_scope();
|
enter_scope();
|
||||||
}
|
}
|
||||||
@ -196,7 +198,7 @@ namespace gcc
|
|||||||
|
|
||||||
tree declaration_tree = build_decl(get_location(¶meter->position()), PARM_DECL,
|
tree declaration_tree = build_decl(get_location(¶meter->position()), PARM_DECL,
|
||||||
get_identifier(parameter->identifier.c_str()), parameter_types[i]);
|
get_identifier(parameter->identifier.c_str()), parameter_types[i]);
|
||||||
DECL_CONTEXT(declaration_tree) = this->main_fndecl;
|
DECL_CONTEXT(declaration_tree) = fndecl;
|
||||||
DECL_ARG_TYPE(declaration_tree) = parameter_types[i];
|
DECL_ARG_TYPE(declaration_tree) = parameter_types[i];
|
||||||
|
|
||||||
if (definition->body() != nullptr)
|
if (definition->body() != nullptr)
|
||||||
@ -205,28 +207,28 @@ namespace gcc
|
|||||||
}
|
}
|
||||||
argument_chain.append(declaration_tree);
|
argument_chain.append(declaration_tree);
|
||||||
}
|
}
|
||||||
DECL_ARGUMENTS(this->main_fndecl) = argument_chain.head();
|
DECL_ARGUMENTS(fndecl) = argument_chain.head();
|
||||||
TREE_PUBLIC(this->main_fndecl) = definition->exported;
|
TREE_PUBLIC(fndecl) = definition->exported;
|
||||||
|
|
||||||
if (definition->body() != nullptr)
|
if (definition->body() != nullptr)
|
||||||
{
|
{
|
||||||
definition->body()->accept(this);
|
definition->body()->accept(this);
|
||||||
tree_symbol_mapping mapping = leave_scope();
|
tree_symbol_mapping mapping = leave_scope();
|
||||||
|
|
||||||
BLOCK_SUPERCONTEXT(mapping.block()) = this->main_fndecl;
|
BLOCK_SUPERCONTEXT(mapping.block()) = fndecl;
|
||||||
DECL_INITIAL(this->main_fndecl) = mapping.block();
|
DECL_INITIAL(fndecl) = mapping.block();
|
||||||
DECL_SAVED_TREE(this->main_fndecl) = mapping.bind_expression();
|
DECL_SAVED_TREE(fndecl) = mapping.bind_expression();
|
||||||
|
|
||||||
DECL_EXTERNAL(this->main_fndecl) = 0;
|
DECL_EXTERNAL(fndecl) = 0;
|
||||||
DECL_PRESERVE_P(this->main_fndecl) = 1;
|
DECL_PRESERVE_P(fndecl) = 1;
|
||||||
|
|
||||||
gimplify_function_tree(this->main_fndecl);
|
current_function_decl = NULL_TREE;
|
||||||
|
gimplify_function_tree(fndecl);
|
||||||
cgraph_node::finalize_function(this->main_fndecl, true);
|
cgraph_node::finalize_function(fndecl, true);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
DECL_EXTERNAL(this->main_fndecl) = 1;
|
DECL_EXTERNAL(fndecl) = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -633,7 +635,7 @@ namespace gcc
|
|||||||
error_at(declaration_location, "variable '%s' already declared in this scope",
|
error_at(declaration_location, "variable '%s' already declared in this scope",
|
||||||
declaration->identifier.c_str());
|
declaration->identifier.c_str());
|
||||||
}
|
}
|
||||||
else if (this->main_fndecl == NULL_TREE)
|
else if (current_function_decl == NULL_TREE)
|
||||||
{
|
{
|
||||||
TREE_STATIC(declaration_tree) = 1;
|
TREE_STATIC(declaration_tree) = 1;
|
||||||
varpool_node::get_create(declaration_tree);
|
varpool_node::get_create(declaration_tree);
|
||||||
@ -641,7 +643,7 @@ namespace gcc
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
DECL_CONTEXT(declaration_tree) = this->main_fndecl;
|
DECL_CONTEXT(declaration_tree) = current_function_decl;
|
||||||
this->scope.front().variables.append(declaration_tree);
|
this->scope.front().variables.append(declaration_tree);
|
||||||
|
|
||||||
auto declaration_statement = build1_loc(declaration_location, DECL_EXPR,
|
auto declaration_statement = build1_loc(declaration_location, DECL_EXPR,
|
||||||
@ -822,7 +824,7 @@ namespace gcc
|
|||||||
auto label_decl = build_decl(loc,
|
auto label_decl = build_decl(loc,
|
||||||
LABEL_DECL, get_identifier(name), void_type_node);
|
LABEL_DECL, get_identifier(name), void_type_node);
|
||||||
|
|
||||||
DECL_CONTEXT(label_decl) = this->main_fndecl;
|
DECL_CONTEXT(label_decl) = current_function_decl;
|
||||||
|
|
||||||
return label_decl;
|
return label_decl;
|
||||||
}
|
}
|
||||||
@ -898,7 +900,7 @@ namespace gcc
|
|||||||
}
|
}
|
||||||
return_expression->accept(this);
|
return_expression->accept(this);
|
||||||
|
|
||||||
tree set_result = build2(INIT_EXPR, void_type_node, DECL_RESULT(main_fndecl),
|
tree set_result = build2(INIT_EXPR, void_type_node, DECL_RESULT(current_function_decl),
|
||||||
this->current_expression);
|
this->current_expression);
|
||||||
tree return_stmt = build1(RETURN_EXPR, void_type_node, set_result);
|
tree return_stmt = build1(RETURN_EXPR, void_type_node, set_result);
|
||||||
this->scope.front().append_statement(return_stmt);
|
this->scope.front().append_statement(return_stmt);
|
||||||
|
60
gcc/elna1.cc
60
gcc/elna1.cc
@ -19,17 +19,11 @@ along with GCC; see the file COPYING3. If not see
|
|||||||
#include "system.h"
|
#include "system.h"
|
||||||
#include "coretypes.h"
|
#include "coretypes.h"
|
||||||
#include "target.h"
|
#include "target.h"
|
||||||
#include "tree.h"
|
|
||||||
#include "tree-iterator.h"
|
|
||||||
#include "gimple-expr.h"
|
|
||||||
#include "diagnostic.h"
|
#include "diagnostic.h"
|
||||||
#include "opts.h"
|
#include "opts.h"
|
||||||
#include "fold-const.h"
|
|
||||||
#include "stor-layout.h"
|
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
#include "langhooks.h"
|
#include "langhooks.h"
|
||||||
#include "langhooks-def.h"
|
#include "langhooks-def.h"
|
||||||
#include "common/common-target.h"
|
|
||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <elna/boot/driver.h>
|
#include <elna/boot/driver.h>
|
||||||
@ -52,14 +46,6 @@ struct GTY (()) lang_decl
|
|||||||
char dummy;
|
char dummy;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Language-dependent contents of an identifier. This must include a
|
|
||||||
tree_identifier. */
|
|
||||||
|
|
||||||
struct GTY (()) lang_identifier
|
|
||||||
{
|
|
||||||
struct tree_identifier common;
|
|
||||||
};
|
|
||||||
|
|
||||||
/* The resulting tree type. */
|
/* The resulting tree type. */
|
||||||
|
|
||||||
union GTY ((desc ("TREE_CODE (&%h.generic) == IDENTIFIER_NODE"),
|
union GTY ((desc ("TREE_CODE (&%h.generic) == IDENTIFIER_NODE"),
|
||||||
@ -68,7 +54,6 @@ union GTY ((desc ("TREE_CODE (&%h.generic) == IDENTIFIER_NODE"),
|
|||||||
"(&%h.generic)) : NULL"))) lang_tree_node
|
"(&%h.generic)) : NULL"))) lang_tree_node
|
||||||
{
|
{
|
||||||
union tree_node GTY ((tag ("0"), desc ("tree_node_structure (&%h)"))) generic;
|
union tree_node GTY ((tag ("0"), desc ("tree_node_structure (&%h)"))) generic;
|
||||||
struct lang_identifier GTY ((tag ("1"))) identifier;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/* We don't use language_function. */
|
/* We don't use language_function. */
|
||||||
@ -83,9 +68,6 @@ struct GTY (()) language_function
|
|||||||
static bool elna_langhook_init(void)
|
static bool elna_langhook_init(void)
|
||||||
{
|
{
|
||||||
build_common_tree_nodes(false);
|
build_common_tree_nodes(false);
|
||||||
|
|
||||||
void_list_node = build_tree_list(NULL_TREE, void_type_node);
|
|
||||||
|
|
||||||
build_common_builtin_nodes();
|
build_common_builtin_nodes();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -198,36 +180,18 @@ static tree elna_langhook_type_for_mode(enum machine_mode mode, int unsignedp)
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
static tree elna_langhook_type_for_size(unsigned int bits ATTRIBUTE_UNUSED,
|
static bool global_bindings_p(void)
|
||||||
int unsignedp ATTRIBUTE_UNUSED)
|
|
||||||
{
|
{
|
||||||
gcc_unreachable();
|
return current_function_decl == NULL_TREE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Record a builtin function. We just ignore builtin functions. */
|
static tree pushdecl(tree decl)
|
||||||
|
|
||||||
static tree elna_langhook_builtin_function(tree decl)
|
|
||||||
{
|
{
|
||||||
return decl;
|
return decl;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool elna_langhook_global_bindings_p(void)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
static tree elna_langhook_pushdecl(tree decl ATTRIBUTE_UNUSED)
|
|
||||||
{
|
|
||||||
gcc_unreachable();
|
|
||||||
}
|
|
||||||
|
|
||||||
static tree elna_langhook_getdecls(void)
|
|
||||||
{
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
#undef LANG_HOOKS_NAME
|
#undef LANG_HOOKS_NAME
|
||||||
#define LANG_HOOKS_NAME "Elna"
|
#define LANG_HOOKS_NAME "GNU Elna"
|
||||||
|
|
||||||
#undef LANG_HOOKS_INIT
|
#undef LANG_HOOKS_INIT
|
||||||
#define LANG_HOOKS_INIT elna_langhook_init
|
#define LANG_HOOKS_INIT elna_langhook_init
|
||||||
@ -238,20 +202,14 @@ static tree elna_langhook_getdecls(void)
|
|||||||
#undef LANG_HOOKS_TYPE_FOR_MODE
|
#undef LANG_HOOKS_TYPE_FOR_MODE
|
||||||
#define LANG_HOOKS_TYPE_FOR_MODE elna_langhook_type_for_mode
|
#define LANG_HOOKS_TYPE_FOR_MODE elna_langhook_type_for_mode
|
||||||
|
|
||||||
#undef LANG_HOOKS_TYPE_FOR_SIZE
|
|
||||||
#define LANG_HOOKS_TYPE_FOR_SIZE elna_langhook_type_for_size
|
|
||||||
|
|
||||||
#undef LANG_HOOKS_BUILTIN_FUNCTION
|
#undef LANG_HOOKS_BUILTIN_FUNCTION
|
||||||
#define LANG_HOOKS_BUILTIN_FUNCTION elna_langhook_builtin_function
|
#define LANG_HOOKS_BUILTIN_FUNCTION pushdecl
|
||||||
|
|
||||||
#undef LANG_HOOKS_GLOBAL_BINDINGS_P
|
|
||||||
#define LANG_HOOKS_GLOBAL_BINDINGS_P elna_langhook_global_bindings_p
|
|
||||||
|
|
||||||
#undef LANG_HOOKS_PUSHDECL
|
|
||||||
#define LANG_HOOKS_PUSHDECL elna_langhook_pushdecl
|
|
||||||
|
|
||||||
#undef LANG_HOOKS_GETDECLS
|
#undef LANG_HOOKS_GETDECLS
|
||||||
#define LANG_HOOKS_GETDECLS elna_langhook_getdecls
|
#define LANG_HOOKS_GETDECLS hook_tree_void_null
|
||||||
|
|
||||||
|
#undef LANG_HOOKS_IDENTIFIER_SIZE
|
||||||
|
#define LANG_HOOKS_IDENTIFIER_SIZE sizeof(struct tree_identifier)
|
||||||
|
|
||||||
struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER;
|
struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER;
|
||||||
|
|
||||||
|
@ -39,7 +39,6 @@ namespace gcc
|
|||||||
std::forward_list<block_scope> scope;
|
std::forward_list<block_scope> scope;
|
||||||
tree current_expression{ NULL_TREE };
|
tree current_expression{ NULL_TREE };
|
||||||
std::shared_ptr<boot::symbol_table<tree>> symbol_map;
|
std::shared_ptr<boot::symbol_table<tree>> symbol_map;
|
||||||
tree main_fndecl{ NULL_TREE };
|
|
||||||
|
|
||||||
tree build_label_decl(const char *name, location_t loc);
|
tree build_label_decl(const char *name, location_t loc);
|
||||||
tree build_type(boot::type_expression& type);
|
tree build_type(boot::type_expression& type);
|
||||||
|
@ -6,6 +6,7 @@ require 'uri'
|
|||||||
require 'net/http'
|
require 'net/http'
|
||||||
require 'open3'
|
require 'open3'
|
||||||
require 'etc'
|
require 'etc'
|
||||||
|
require 'fileutils'
|
||||||
require_relative 'shared'
|
require_relative 'shared'
|
||||||
|
|
||||||
BINUTILS_VERSION = '2.43.1'
|
BINUTILS_VERSION = '2.43.1'
|
||||||
@ -52,11 +53,15 @@ def download_and_unarchive(url, target)
|
|||||||
target + root_directory
|
target + root_directory
|
||||||
end
|
end
|
||||||
|
|
||||||
namespace :cross do
|
def configure_make_install(source_directory, configure_options, env, cwd)
|
||||||
desc 'Build cross binutils'
|
configure = source_directory.relative_path_from(cwd) + 'configure'
|
||||||
task :binutils, [:target] do |_, args|
|
system env, configure.to_path, *configure_options, chdir: cwd.to_path, exception: true
|
||||||
options = find_build_target GCC_VERSION, args[:target]
|
system 'make', '-j', Etc.nprocessors.to_s, chdir: cwd.to_path, exception: true
|
||||||
options.tools.mkpath
|
system env, 'make', 'install', chdir: cwd.to_path, exception: true
|
||||||
|
end
|
||||||
|
|
||||||
|
# Build cross binutils.
|
||||||
|
def binutils(options)
|
||||||
source_directory = download_and_unarchive(
|
source_directory = download_and_unarchive(
|
||||||
URI.parse("https://ftp.gnu.org/gnu/binutils/binutils-#{BINUTILS_VERSION}.tar.xz"),
|
URI.parse("https://ftp.gnu.org/gnu/binutils/binutils-#{BINUTILS_VERSION}.tar.xz"),
|
||||||
options.tools)
|
options.tools)
|
||||||
@ -78,16 +83,11 @@ namespace :cross do
|
|||||||
'--enable-default-hash-style=gnu',
|
'--enable-default-hash-style=gnu',
|
||||||
'--disable-libquadmath'
|
'--disable-libquadmath'
|
||||||
]
|
]
|
||||||
configure = source_directory.relative_path_from(cwd) + 'configure'
|
configure_make_install source_directory, configure_options, env, cwd
|
||||||
sh env, configure.to_path, *configure_options, chdir: cwd.to_path
|
end
|
||||||
sh env, 'make', '-j', Etc.nprocessors.to_s, chdir: cwd.to_path
|
|
||||||
sh env, 'make', 'install', chdir: cwd.to_path
|
|
||||||
end
|
|
||||||
|
|
||||||
desc 'Build stage 1 GCC'
|
# Build stage 1 GCC.
|
||||||
task :gcc1, [:target] do |_, args|
|
def gcc1(options)
|
||||||
options = find_build_target GCC_VERSION, args[:target]
|
|
||||||
options.tools.mkpath
|
|
||||||
source_directory = download_and_unarchive(
|
source_directory = download_and_unarchive(
|
||||||
URI.parse("https://gcc.gnu.org/pub/gcc/releases/gcc-#{GCC_VERSION}/gcc-#{GCC_VERSION}.tar.xz"),
|
URI.parse("https://gcc.gnu.org/pub/gcc/releases/gcc-#{GCC_VERSION}/gcc-#{GCC_VERSION}.tar.xz"),
|
||||||
options.tools)
|
options.tools)
|
||||||
@ -97,7 +97,7 @@ namespace :cross do
|
|||||||
options.rootfs.mkpath
|
options.rootfs.mkpath
|
||||||
options.sysroot.mkpath
|
options.sysroot.mkpath
|
||||||
|
|
||||||
sh 'contrib/download_prerequisites', chdir: source_directory.to_path
|
system 'contrib/download_prerequisites', chdir: source_directory.to_path, exception: true
|
||||||
configure_options = options.configuration + [
|
configure_options = options.configuration + [
|
||||||
"--prefix=#{options.rootfs.realpath}",
|
"--prefix=#{options.rootfs.realpath}",
|
||||||
"--with-sysroot=#{options.sysroot.realpath}",
|
"--with-sysroot=#{options.sysroot.realpath}",
|
||||||
@ -129,31 +129,22 @@ namespace :cross do
|
|||||||
'CXXFLAGS' => flags,
|
'CXXFLAGS' => flags,
|
||||||
'PATH' => "#{options.rootfs.realpath + 'bin'}:#{ENV['PATH']}"
|
'PATH' => "#{options.rootfs.realpath + 'bin'}:#{ENV['PATH']}"
|
||||||
}
|
}
|
||||||
configure = source_directory.relative_path_from(cwd) + 'configure'
|
configure_make_install source_directory, configure_options, env, cwd
|
||||||
sh env, configure.to_path, *configure_options, chdir: cwd.to_path
|
end
|
||||||
sh env, 'make', '-j', Etc.nprocessors.to_s, chdir: cwd.to_path
|
|
||||||
sh env, 'make', 'install', chdir: cwd.to_path
|
|
||||||
end
|
|
||||||
|
|
||||||
desc 'Copy glibc headers'
|
|
||||||
task :headers, [:target] do |_, args|
|
|
||||||
options = find_build_target GCC_VERSION, args[:target]
|
|
||||||
options.tools.mkpath
|
|
||||||
|
|
||||||
|
# Copy glibc headers.
|
||||||
|
def headers(options)
|
||||||
source_directory = download_and_unarchive(
|
source_directory = download_and_unarchive(
|
||||||
URI.parse("https://ftp.gnu.org/gnu/glibc/glibc-#{GLIBC_VERSION}.tar.xz"),
|
URI.parse("https://ftp.gnu.org/gnu/glibc/glibc-#{GLIBC_VERSION}.tar.xz"),
|
||||||
options.tools)
|
options.tools)
|
||||||
include_directory = options.tools + 'include'
|
include_directory = options.tools + 'include'
|
||||||
|
|
||||||
include_directory.mkpath
|
include_directory.mkpath
|
||||||
cp (source_directory + 'elf/elf.h'), (include_directory + 'elf.h')
|
FileUtils.cp (source_directory + 'elf/elf.h'), (include_directory + 'elf.h')
|
||||||
end
|
end
|
||||||
|
|
||||||
desc 'Build linux kernel'
|
|
||||||
task :kernel, [:target] do |_, args|
|
|
||||||
options = find_build_target GCC_VERSION, args[:target]
|
|
||||||
options.tools.mkpath
|
|
||||||
|
|
||||||
|
# Build linux kernel.
|
||||||
|
def kernel(options)
|
||||||
cwd = download_and_unarchive(
|
cwd = download_and_unarchive(
|
||||||
URI.parse("https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-#{KERNEL_VERSION}.tar.xz"),
|
URI.parse("https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-#{KERNEL_VERSION}.tar.xz"),
|
||||||
options.tools)
|
options.tools)
|
||||||
@ -164,19 +155,18 @@ namespace :cross do
|
|||||||
'PATH' => "#{options.rootfs.realpath + 'bin'}:#{ENV['PATH']}",
|
'PATH' => "#{options.rootfs.realpath + 'bin'}:#{ENV['PATH']}",
|
||||||
'HOSTCFLAGS' => "-D_UUID_T -D__GETHOSTUUID_H -I#{options.tools.realpath + 'include'}"
|
'HOSTCFLAGS' => "-D_UUID_T -D__GETHOSTUUID_H -I#{options.tools.realpath + 'include'}"
|
||||||
}
|
}
|
||||||
sh env, 'make', 'rv32_defconfig', chdir: cwd.to_path
|
system env, 'make', 'rv32_defconfig', chdir: cwd.to_path, exception: true
|
||||||
sh env, 'make', '-j', Etc.nprocessors.to_s, chdir: cwd.to_path
|
system env, 'make', '-j', Etc.nprocessors.to_s, chdir: cwd.to_path, exception: true
|
||||||
sh env, 'make', 'headers', chdir: cwd.to_path
|
system env, 'make', 'headers', chdir: cwd.to_path, exception: true
|
||||||
|
|
||||||
user_directory = options.sysroot + 'usr'
|
user_directory = options.sysroot + 'usr'
|
||||||
|
|
||||||
user_directory.mkpath
|
user_directory.mkpath
|
||||||
cp_r (cwd + 'usr/include'), (user_directory + 'include')
|
FileUtils.cp_r (cwd + 'usr/include'), (user_directory + 'include')
|
||||||
end
|
end
|
||||||
|
|
||||||
desc 'Build glibc'
|
# Build glibc.
|
||||||
task :glibc, [:target] do |_, args|
|
def glibc(options)
|
||||||
options = find_build_target GCC_VERSION, args[:target]
|
|
||||||
source_directory = options.tools + "glibc-#{GLIBC_VERSION}"
|
source_directory = options.tools + "glibc-#{GLIBC_VERSION}"
|
||||||
configure_options = [
|
configure_options = [
|
||||||
'--prefix=/usr',
|
'--prefix=/usr',
|
||||||
@ -200,18 +190,17 @@ namespace :cross do
|
|||||||
cwd.mkpath
|
cwd.mkpath
|
||||||
|
|
||||||
configure = source_directory.relative_path_from(cwd) +'./configure'
|
configure = source_directory.relative_path_from(cwd) +'./configure'
|
||||||
sh env, configure.to_path, *configure_options, chdir: cwd.to_path
|
system env, configure.to_path, *configure_options, chdir: cwd.to_path, exception: true
|
||||||
sh env, 'make', '-j', Etc.nprocessors.to_s, chdir: cwd.to_path
|
system env, 'make', '-j', Etc.nprocessors.to_s, chdir: cwd.to_path, exception: true
|
||||||
sh env, 'make', "install_root=#{options.sysroot.realpath}", 'install', chdir: cwd.to_path
|
system env, 'make', "install_root=#{options.sysroot.realpath}", 'install', chdir: cwd.to_path, exception: true
|
||||||
end
|
end
|
||||||
|
|
||||||
desc 'Build stage 2 GCC'
|
# Build stage 2 GCC.
|
||||||
task :gcc2, [:target] do |_, args|
|
def gcc2(options)
|
||||||
options = find_build_target GCC_VERSION, args[:target]
|
|
||||||
source_directory = options.tools + "gcc-#{GCC_VERSION}"
|
source_directory = options.tools + "gcc-#{GCC_VERSION}"
|
||||||
cwd = options.tools + 'build-gcc'
|
cwd = options.tools + 'build-gcc'
|
||||||
|
|
||||||
rm_rf cwd
|
FileUtils.rm_rf cwd
|
||||||
cwd.mkpath
|
cwd.mkpath
|
||||||
|
|
||||||
configure_options = options.configuration + [
|
configure_options = options.configuration + [
|
||||||
@ -239,12 +228,10 @@ namespace :cross do
|
|||||||
'CXXFLAGS' => flags,
|
'CXXFLAGS' => flags,
|
||||||
'PATH' => "#{options.rootfs.realpath + 'bin'}:#{ENV['PATH']}"
|
'PATH' => "#{options.rootfs.realpath + 'bin'}:#{ENV['PATH']}"
|
||||||
}
|
}
|
||||||
configure = source_directory.relative_path_from(cwd) + 'configure'
|
configure_make_install source_directory, configure_options, env, cwd
|
||||||
sh env, configure.to_path, *configure_options, chdir: cwd.to_path
|
end
|
||||||
sh env, 'make', '-j', Etc.nprocessors.to_s, chdir: cwd.to_path
|
|
||||||
sh env, 'make', 'install', chdir: cwd.to_path
|
|
||||||
end
|
|
||||||
|
|
||||||
|
namespace :cross do
|
||||||
task :init, [:target] do |_, args|
|
task :init, [:target] do |_, args|
|
||||||
options = find_build_target GCC_VERSION, args[:target]
|
options = find_build_target GCC_VERSION, args[:target]
|
||||||
env = {
|
env = {
|
||||||
|
77
source.elna
77
source.elna
@ -174,14 +174,12 @@ begin
|
|||||||
return c = ' ' or c = '\n' or c = '\t'
|
return c = ' ' or c = '\n' or c = '\t'
|
||||||
end
|
end
|
||||||
|
|
||||||
proc string_equals_chars(this: String, that: pointer to Char, length: Word): Bool;
|
proc string_equals(this: String, that: String): Bool;
|
||||||
var
|
|
||||||
i: Word;
|
|
||||||
begin
|
begin
|
||||||
if this.length <> length then
|
if this.length <> that.length then
|
||||||
return false
|
return false
|
||||||
end;
|
end;
|
||||||
return strncmp(this.ptr, that, length) = 0
|
return strncmp(this.ptr, that.ptr, this.length) = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
proc open_substring(string: String, start: Word): String;
|
proc open_substring(string: String, start: Word): String;
|
||||||
@ -482,7 +480,7 @@ begin
|
|||||||
write_s("SIZEOF")
|
write_s("SIZEOF")
|
||||||
elsif current_token^.kind = TOKEN_IDENTIFIER then
|
elsif current_token^.kind = TOKEN_IDENTIFIER then
|
||||||
write_c('<');
|
write_c('<');
|
||||||
write_z(current_token^.value.string_value);
|
write_s(current_token^.value.string);
|
||||||
write_c('>')
|
write_c('>')
|
||||||
elsif current_token^.kind = TOKEN_LEFT_PAREN then
|
elsif current_token^.kind = TOKEN_LEFT_PAREN then
|
||||||
write_s("(")
|
write_s("(")
|
||||||
@ -558,76 +556,75 @@ begin
|
|||||||
write_c('\n')
|
write_c('\n')
|
||||||
end
|
end
|
||||||
|
|
||||||
proc categorize_identifier(input_pointer: pointer to Char, token_length: Int): Token;
|
proc categorize_identifier(token_content: String): Token;
|
||||||
var
|
var
|
||||||
current_token: Token;
|
current_token: Token;
|
||||||
begin
|
begin
|
||||||
if string_equals_chars("if", input_pointer, token_length) then
|
if string_equals("if", token_content) then
|
||||||
current_token.kind := TOKEN_IF
|
current_token.kind := TOKEN_IF
|
||||||
elsif string_equals_chars("then", input_pointer, token_length) then
|
elsif string_equals("then", token_content) then
|
||||||
current_token.kind := TOKEN_THEN
|
current_token.kind := TOKEN_THEN
|
||||||
elsif string_equals_chars("else", input_pointer, token_length) then
|
elsif string_equals("else", token_content) then
|
||||||
current_token.kind := TOKEN_ELSE
|
current_token.kind := TOKEN_ELSE
|
||||||
elsif string_equals_chars("elsif", input_pointer, token_length) then
|
elsif string_equals("elsif", token_content) then
|
||||||
current_token.kind := TOKEN_ELSIF
|
current_token.kind := TOKEN_ELSIF
|
||||||
elsif string_equals_chars("while", input_pointer, token_length) then
|
elsif string_equals("while", token_content) then
|
||||||
current_token.kind := TOKEN_WHILE
|
current_token.kind := TOKEN_WHILE
|
||||||
elsif string_equals_chars("do", input_pointer, token_length) then
|
elsif string_equals("do", token_content) then
|
||||||
current_token.kind := TOKEN_DO
|
current_token.kind := TOKEN_DO
|
||||||
elsif string_equals_chars("proc", input_pointer, token_length) then
|
elsif string_equals("proc", token_content) then
|
||||||
current_token.kind := TOKEN_PROC
|
current_token.kind := TOKEN_PROC
|
||||||
elsif string_equals_chars("begin", input_pointer, token_length) then
|
elsif string_equals("begin", token_content) then
|
||||||
current_token.kind := TOKEN_BEGIN
|
current_token.kind := TOKEN_BEGIN
|
||||||
elsif string_equals_chars("end", input_pointer, token_length) then
|
elsif string_equals("end", token_content) then
|
||||||
current_token.kind := TOKEN_END
|
current_token.kind := TOKEN_END
|
||||||
elsif string_equals_chars("extern", input_pointer, token_length) then
|
elsif string_equals("extern", token_content) then
|
||||||
current_token.kind := TOKEN_EXTERN
|
current_token.kind := TOKEN_EXTERN
|
||||||
elsif string_equals_chars("const", input_pointer, token_length) then
|
elsif string_equals("const", token_content) then
|
||||||
current_token.kind := TOKEN_CONST
|
current_token.kind := TOKEN_CONST
|
||||||
elsif string_equals_chars("var", input_pointer, token_length) then
|
elsif string_equals("var", token_content) then
|
||||||
current_token.kind := TOKEN_VAR
|
current_token.kind := TOKEN_VAR
|
||||||
elsif string_equals_chars("array", input_pointer, token_length) then
|
elsif string_equals("array", token_content) then
|
||||||
current_token.kind := TOKEN_ARRAY
|
current_token.kind := TOKEN_ARRAY
|
||||||
elsif string_equals_chars("of", input_pointer, token_length) then
|
elsif string_equals("of", token_content) then
|
||||||
current_token.kind := TOKEN_OF
|
current_token.kind := TOKEN_OF
|
||||||
elsif string_equals_chars("type", input_pointer, token_length) then
|
elsif string_equals("type", token_content) then
|
||||||
current_token.kind := TOKEN_TYPE
|
current_token.kind := TOKEN_TYPE
|
||||||
elsif string_equals_chars("record", input_pointer, token_length) then
|
elsif string_equals("record", token_content) then
|
||||||
current_token.kind := TOKEN_RECORD
|
current_token.kind := TOKEN_RECORD
|
||||||
elsif string_equals_chars("union", input_pointer, token_length) then
|
elsif string_equals("union", token_content) then
|
||||||
current_token.kind := TOKEN_UNION
|
current_token.kind := TOKEN_UNION
|
||||||
elsif string_equals_chars("pointer", input_pointer, token_length) then
|
elsif string_equals("pointer", token_content) then
|
||||||
current_token.kind := TOKEN_POINTER
|
current_token.kind := TOKEN_POINTER
|
||||||
elsif string_equals_chars("to", input_pointer, token_length) then
|
elsif string_equals("to", token_content) then
|
||||||
current_token.kind := TOKEN_TO
|
current_token.kind := TOKEN_TO
|
||||||
elsif string_equals_chars("true", input_pointer, token_length) then
|
elsif string_equals("true", token_content) then
|
||||||
current_token.kind := TOKEN_BOOLEAN;
|
current_token.kind := TOKEN_BOOLEAN;
|
||||||
current_token.value.boolean_value := true
|
current_token.value.boolean_value := true
|
||||||
elsif string_equals_chars("false", input_pointer, token_length) then
|
elsif string_equals("false", token_content) then
|
||||||
current_token.kind := TOKEN_BOOLEAN;
|
current_token.kind := TOKEN_BOOLEAN;
|
||||||
current_token.value.boolean_value := false
|
current_token.value.boolean_value := false
|
||||||
elsif string_equals_chars("nil", input_pointer, token_length) then
|
elsif string_equals("nil", token_content) then
|
||||||
current_token.kind := TOKEN_NIL
|
current_token.kind := TOKEN_NIL
|
||||||
elsif string_equals_chars("and", input_pointer, token_length) then
|
elsif string_equals("and", token_content) then
|
||||||
current_token.kind := TOKEN_AND
|
current_token.kind := TOKEN_AND
|
||||||
elsif string_equals_chars("or", input_pointer, token_length) then
|
elsif string_equals("or", token_content) then
|
||||||
current_token.kind := TOKEN_OR
|
current_token.kind := TOKEN_OR
|
||||||
elsif string_equals_chars("not", input_pointer, token_length) then
|
elsif string_equals("not", token_content) then
|
||||||
current_token.kind := TOKEN_NOT
|
current_token.kind := TOKEN_NOT
|
||||||
elsif string_equals_chars("return", input_pointer, token_length) then
|
elsif string_equals("return", token_content) then
|
||||||
current_token.kind := TOKEN_RETURN
|
current_token.kind := TOKEN_RETURN
|
||||||
elsif string_equals_chars("cast", input_pointer, token_length) then
|
elsif string_equals("cast", token_content) then
|
||||||
current_token.kind := TOKEN_CAST
|
current_token.kind := TOKEN_CAST
|
||||||
elsif string_equals_chars("as", input_pointer, token_length) then
|
elsif string_equals("as", token_content) then
|
||||||
current_token.kind := TOKEN_AS
|
current_token.kind := TOKEN_AS
|
||||||
elsif string_equals_chars("sizeof", input_pointer, token_length) then
|
elsif string_equals("sizeof", token_content) then
|
||||||
current_token.kind := TOKEN_SIZEOF
|
current_token.kind := TOKEN_SIZEOF
|
||||||
elsif string_equals_chars("defer", input_pointer, token_length) then
|
elsif string_equals("defer", token_content) then
|
||||||
current_token.kind := TOKEN_DEFER
|
current_token.kind := TOKEN_DEFER
|
||||||
else
|
else
|
||||||
current_token.kind := TOKEN_IDENTIFIER;
|
current_token.kind := TOKEN_IDENTIFIER;
|
||||||
current_token.value.string_value := cast(calloc(token_length + 1, 1) as pointer to Char);
|
current_token.value.string := string_dup(token_content)
|
||||||
strncpy(current_token.value.string_value, input_pointer, token_length)
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
return current_token
|
return current_token
|
||||||
@ -653,7 +650,7 @@ begin
|
|||||||
|
|
||||||
if is_alpha(first_char) or first_char = '_' then
|
if is_alpha(first_char) or first_char = '_' then
|
||||||
lex_identifier(@source_code, @token_content);
|
lex_identifier(@source_code, @token_content);
|
||||||
current_token^ := categorize_identifier(token_content.ptr, token_content.length);
|
current_token^ := categorize_identifier(token_content);
|
||||||
|
|
||||||
source_code := advance_source(source_code, 1u)
|
source_code := advance_source(source_code, 1u)
|
||||||
elsif is_digit(first_char) then
|
elsif is_digit(first_char) then
|
||||||
|
Loading…
x
Reference in New Issue
Block a user