Replace main_fndecl with current_function_decl

This commit is contained in:
Eugen Wissner 2025-02-09 23:49:57 +01:00
parent 207ae0fa0a
commit 4bf88a92e8
Signed by: belka
GPG Key ID: A27FDC1E8EE902C0
7 changed files with 272 additions and 326 deletions

View File

@ -26,12 +26,14 @@ end
desc 'Build cross toolchain'
task :cross, [:target] do |_, args|
args.with_defaults target: 'riscv32-unknown-linux-gnu'
options = find_build_target GCC_VERSION, args[:target]
Rake::Task['cross:binutils'].invoke args[:target]
Rake::Task['cross:gcc1'].invoke args[:target]
Rake::Task['cross:headers'].invoke args[:target]
Rake::Task['cross:kernel'].invoke args[:target]
Rake::Task['cross:glibc'].invoke args[:target]
Rake::Task['cross:gcc2'].invoke args[:target]
options.tools.mkpath
binutils options
gcc1 options
headers options
kernel options
glibc options
gcc2 options
Rake::Task['cross:init'].invoke args[:target]
end

View File

@ -47,10 +47,11 @@ along with GCC; see the file COPYING3. If not see
}
}
\(\* BEGIN(IN_COMMENT);
[\ \t\r] ; /* Skip the whitespaces. */
[ \t\r] {
this->location.step();
}
\n+ {
this->location.lines(yyleng);
this->location.step();
}
if {
return yy::parser::make_IF(this->location);

View File

@ -123,10 +123,11 @@ namespace gcc
build_pointer_type(build_pointer_type(char_type_node))
};
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);
DECL_CONTEXT(resdecl) = this->main_fndecl;
DECL_RESULT(this->main_fndecl) = resdecl;
DECL_CONTEXT(resdecl) = fndecl;
DECL_RESULT(fndecl) = resdecl;
enter_scope();
@ -136,33 +137,33 @@ namespace gcc
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_CONTEXT(argc_declaration_tree) = fndecl;
DECL_ARG_TYPE(argc_declaration_tree) = parameter_types[i];
this->symbol_map->enter(argument_name, 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)
{
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));
tree return_stmt = build1(RETURN_EXPR, void_type_node, set_result);
this->scope.front().append_statement(return_stmt);
tree_symbol_mapping mapping = leave_scope();
BLOCK_SUPERCONTEXT(mapping.block()) = this->main_fndecl;
DECL_INITIAL(this->main_fndecl) = mapping.block();
DECL_SAVED_TREE(this->main_fndecl) = mapping.bind_expression();
BLOCK_SUPERCONTEXT(mapping.block()) = fndecl;
DECL_INITIAL(fndecl) = mapping.block();
DECL_SAVED_TREE(fndecl) = mapping.bind_expression();
DECL_EXTERNAL(this->main_fndecl) = 0;
DECL_PRESERVE_P(this->main_fndecl) = 1;
DECL_EXTERNAL(fndecl) = 0;
DECL_PRESERVE_P(fndecl) = 1;
gimplify_function_tree(this->main_fndecl);
cgraph_node::finalize_function(this->main_fndecl, true);
current_function_decl = NULL_TREE;
gimplify_function_tree(fndecl);
cgraph_node::finalize_function(fndecl, true);
}
void generic_visitor::visit(boot::procedure_definition *definition)
@ -178,14 +179,15 @@ namespace gcc
: build_type(*definition->return_type());
tree declaration_type = build_function_type_array(return_type,
definition->parameters.size(), parameter_types.data());
this->main_fndecl = build_fn_decl(definition->identifier.c_str(), declaration_type);
this->symbol_map->enter(definition->identifier, this->main_fndecl);
tree fndecl = build_fn_decl(definition->identifier.c_str(), declaration_type);
this->symbol_map->enter(definition->identifier, fndecl);
if (definition->body() != nullptr)
{
current_function_decl = fndecl;
tree resdecl = build_decl(UNKNOWN_LOCATION, RESULT_DECL, NULL_TREE, return_type);
DECL_CONTEXT(resdecl) = this->main_fndecl;
DECL_RESULT(this->main_fndecl) = resdecl;
DECL_CONTEXT(resdecl) = fndecl;
DECL_RESULT(fndecl) = resdecl;
enter_scope();
}
@ -196,7 +198,7 @@ namespace gcc
tree declaration_tree = build_decl(get_location(&parameter->position()), PARM_DECL,
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];
if (definition->body() != nullptr)
@ -205,28 +207,28 @@ namespace gcc
}
argument_chain.append(declaration_tree);
}
DECL_ARGUMENTS(this->main_fndecl) = argument_chain.head();
TREE_PUBLIC(this->main_fndecl) = definition->exported;
DECL_ARGUMENTS(fndecl) = argument_chain.head();
TREE_PUBLIC(fndecl) = definition->exported;
if (definition->body() != nullptr)
{
definition->body()->accept(this);
tree_symbol_mapping mapping = leave_scope();
BLOCK_SUPERCONTEXT(mapping.block()) = this->main_fndecl;
DECL_INITIAL(this->main_fndecl) = mapping.block();
DECL_SAVED_TREE(this->main_fndecl) = mapping.bind_expression();
BLOCK_SUPERCONTEXT(mapping.block()) = fndecl;
DECL_INITIAL(fndecl) = mapping.block();
DECL_SAVED_TREE(fndecl) = mapping.bind_expression();
DECL_EXTERNAL(this->main_fndecl) = 0;
DECL_PRESERVE_P(this->main_fndecl) = 1;
DECL_EXTERNAL(fndecl) = 0;
DECL_PRESERVE_P(fndecl) = 1;
gimplify_function_tree(this->main_fndecl);
cgraph_node::finalize_function(this->main_fndecl, true);
current_function_decl = NULL_TREE;
gimplify_function_tree(fndecl);
cgraph_node::finalize_function(fndecl, true);
}
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",
declaration->identifier.c_str());
}
else if (this->main_fndecl == NULL_TREE)
else if (current_function_decl == NULL_TREE)
{
TREE_STATIC(declaration_tree) = 1;
varpool_node::get_create(declaration_tree);
@ -641,7 +643,7 @@ namespace gcc
}
else
{
DECL_CONTEXT(declaration_tree) = this->main_fndecl;
DECL_CONTEXT(declaration_tree) = current_function_decl;
this->scope.front().variables.append(declaration_tree);
auto declaration_statement = build1_loc(declaration_location, DECL_EXPR,
@ -822,7 +824,7 @@ namespace gcc
auto label_decl = build_decl(loc,
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;
}
@ -898,7 +900,7 @@ namespace gcc
}
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);
tree return_stmt = build1(RETURN_EXPR, void_type_node, set_result);
this->scope.front().append_statement(return_stmt);

View File

@ -19,17 +19,11 @@ along with GCC; see the file COPYING3. If not see
#include "system.h"
#include "coretypes.h"
#include "target.h"
#include "tree.h"
#include "tree-iterator.h"
#include "gimple-expr.h"
#include "diagnostic.h"
#include "opts.h"
#include "fold-const.h"
#include "stor-layout.h"
#include "debug.h"
#include "langhooks.h"
#include "langhooks-def.h"
#include "common/common-target.h"
#include <fstream>
#include <elna/boot/driver.h>
@ -52,14 +46,6 @@ struct GTY (()) lang_decl
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. */
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
{
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. */
@ -83,9 +68,6 @@ struct GTY (()) language_function
static bool elna_langhook_init(void)
{
build_common_tree_nodes(false);
void_list_node = build_tree_list(NULL_TREE, void_type_node);
build_common_builtin_nodes();
return true;
@ -198,36 +180,18 @@ static tree elna_langhook_type_for_mode(enum machine_mode mode, int unsignedp)
return nullptr;
}
static tree elna_langhook_type_for_size(unsigned int bits ATTRIBUTE_UNUSED,
int unsignedp ATTRIBUTE_UNUSED)
static bool global_bindings_p(void)
{
gcc_unreachable();
return current_function_decl == NULL_TREE;
}
/* Record a builtin function. We just ignore builtin functions. */
static tree elna_langhook_builtin_function(tree decl)
static tree pushdecl(tree 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
#define LANG_HOOKS_NAME "Elna"
#define LANG_HOOKS_NAME "GNU Elna"
#undef LANG_HOOKS_INIT
#define LANG_HOOKS_INIT elna_langhook_init
@ -238,20 +202,14 @@ static tree elna_langhook_getdecls(void)
#undef LANG_HOOKS_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
#define LANG_HOOKS_BUILTIN_FUNCTION elna_langhook_builtin_function
#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
#define LANG_HOOKS_BUILTIN_FUNCTION pushdecl
#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;

View File

@ -39,7 +39,6 @@ namespace gcc
std::forward_list<block_scope> scope;
tree current_expression{ NULL_TREE };
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_type(boot::type_expression& type);

View File

@ -6,6 +6,7 @@ require 'uri'
require 'net/http'
require 'open3'
require 'etc'
require 'fileutils'
require_relative 'shared'
BINUTILS_VERSION = '2.43.1'
@ -52,199 +53,185 @@ def download_and_unarchive(url, target)
target + root_directory
end
def configure_make_install(source_directory, configure_options, env, cwd)
configure = source_directory.relative_path_from(cwd) + 'configure'
system env, configure.to_path, *configure_options, chdir: cwd.to_path, exception: true
system 'make', '-j', Etc.nprocessors.to_s, chdir: cwd.to_path, exception: true
system env, 'make', 'install', chdir: cwd.to_path, exception: true
end
# Build cross binutils.
def binutils(options)
source_directory = download_and_unarchive(
URI.parse("https://ftp.gnu.org/gnu/binutils/binutils-#{BINUTILS_VERSION}.tar.xz"),
options.tools)
cwd = source_directory.dirname + 'build-binutils'
cwd.mkpath
options.rootfs.mkpath
env = {
'CC' => options.gcc,
'CXX' => options.gxx
}
configure_options = [
"--prefix=#{options.rootfs.realpath}",
"--target=#{options.target}",
'--disable-nls',
'--enable-gprofng=no',
'--disable-werror',
'--enable-default-hash-style=gnu',
'--disable-libquadmath'
]
configure_make_install source_directory, configure_options, env, cwd
end
# Build stage 1 GCC.
def gcc1(options)
source_directory = download_and_unarchive(
URI.parse("https://gcc.gnu.org/pub/gcc/releases/gcc-#{GCC_VERSION}/gcc-#{GCC_VERSION}.tar.xz"),
options.tools)
cwd = source_directory.dirname + 'build-gcc'
cwd.mkpath
options.rootfs.mkpath
options.sysroot.mkpath
system 'contrib/download_prerequisites', chdir: source_directory.to_path, exception: true
configure_options = options.configuration + [
"--prefix=#{options.rootfs.realpath}",
"--with-sysroot=#{options.sysroot.realpath}",
'--enable-languages=c,c++',
'--disable-shared',
'--disable-bootstrap',
'--disable-multilib',
'--disable-libmudflap',
'--disable-libssp',
'--disable-libquadmath',
'--disable-libsanitizer',
'--disable-threads',
'--disable-libatomic',
'--disable-libgomp',
'--disable-libvtv',
'--disable-libstdcxx',
'--disable-nls',
'--with-newlib',
'--without-headers',
"--target=#{options.target}",
"--build=#{options.build}",
"--host=#{options.build}"
]
flags = '-O2 -fPIC'
env = {
'CC' => options.gcc,
'CXX' => options.gxx,
'CFLAGS' => flags,
'CXXFLAGS' => flags,
'PATH' => "#{options.rootfs.realpath + 'bin'}:#{ENV['PATH']}"
}
configure_make_install source_directory, configure_options, env, cwd
end
# Copy glibc headers.
def headers(options)
source_directory = download_and_unarchive(
URI.parse("https://ftp.gnu.org/gnu/glibc/glibc-#{GLIBC_VERSION}.tar.xz"),
options.tools)
include_directory = options.tools + 'include'
include_directory.mkpath
FileUtils.cp (source_directory + 'elf/elf.h'), (include_directory + 'elf.h')
end
# Build linux kernel.
def kernel(options)
cwd = download_and_unarchive(
URI.parse("https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-#{KERNEL_VERSION}.tar.xz"),
options.tools)
env = {
'CROSS_COMPILE' => "#{options.target}-",
'ARCH' => 'riscv',
'PATH' => "#{options.rootfs.realpath + 'bin'}:#{ENV['PATH']}",
'HOSTCFLAGS' => "-D_UUID_T -D__GETHOSTUUID_H -I#{options.tools.realpath + 'include'}"
}
system env, 'make', 'rv32_defconfig', chdir: cwd.to_path, exception: true
system env, 'make', '-j', Etc.nprocessors.to_s, chdir: cwd.to_path, exception: true
system env, 'make', 'headers', chdir: cwd.to_path, exception: true
user_directory = options.sysroot + 'usr'
user_directory.mkpath
FileUtils.cp_r (cwd + 'usr/include'), (user_directory + 'include')
end
# Build glibc.
def glibc(options)
source_directory = options.tools + "glibc-#{GLIBC_VERSION}"
configure_options = [
'--prefix=/usr',
"--host=#{options.target}",
"--target=#{options.target}",
"--build=#{options.build}",
"--enable-kernel=#{KERNEL_VERSION}",
"--with-headers=#{options.sysroot.realpath + 'usr/include'}",
'--disable-nscd',
'--disable-libquadmath',
'--disable-libitm',
'--disable-werror',
'libc_cv_forced_unwind=yes'
]
bin = options.rootfs.realpath + 'bin'
env = {
'PATH' => "#{bin}:#{ENV['PATH']}",
'MAKE' => 'make' # Otherwise it uses gnumake which can be different and too old.
}
cwd = source_directory.dirname + 'build-glibc'
cwd.mkpath
configure = source_directory.relative_path_from(cwd) +'./configure'
system env, configure.to_path, *configure_options, chdir: cwd.to_path, exception: true
system env, 'make', '-j', Etc.nprocessors.to_s, chdir: cwd.to_path, exception: true
system env, 'make', "install_root=#{options.sysroot.realpath}", 'install', chdir: cwd.to_path, exception: true
end
# Build stage 2 GCC.
def gcc2(options)
source_directory = options.tools + "gcc-#{GCC_VERSION}"
cwd = options.tools + 'build-gcc'
FileUtils.rm_rf cwd
cwd.mkpath
configure_options = options.configuration + [
"--prefix=#{options.rootfs.realpath}",
"--with-sysroot=#{options.sysroot.realpath}",
'--enable-languages=c,c++,lto',
'--enable-lto',
'--enable-shared',
'--disable-bootstrap',
'--disable-multilib',
'--enable-checking=release',
'--disable-libssp',
'--disable-libquadmath',
'--enable-threads=posix',
'--with-default-libstdcxx-abi=new',
'--disable-nls',
"--target=#{options.target}",
"--build=#{options.build}",
"--host=#{options.build}"
]
flags = '-O2 -fPIC'
env = {
'CFLAGS' => flags,
'CXXFLAGS' => flags,
'PATH' => "#{options.rootfs.realpath + 'bin'}:#{ENV['PATH']}"
}
configure_make_install source_directory, configure_options, env, cwd
end
namespace :cross do
desc 'Build cross binutils'
task :binutils, [:target] do |_, args|
options = find_build_target GCC_VERSION, args[:target]
options.tools.mkpath
source_directory = download_and_unarchive(
URI.parse("https://ftp.gnu.org/gnu/binutils/binutils-#{BINUTILS_VERSION}.tar.xz"),
options.tools)
cwd = source_directory.dirname + 'build-binutils'
cwd.mkpath
options.rootfs.mkpath
env = {
'CC' => options.gcc,
'CXX' => options.gxx
}
configure_options = [
"--prefix=#{options.rootfs.realpath}",
"--target=#{options.target}",
'--disable-nls',
'--enable-gprofng=no',
'--disable-werror',
'--enable-default-hash-style=gnu',
'--disable-libquadmath'
]
configure = source_directory.relative_path_from(cwd) + 'configure'
sh env, configure.to_path, *configure_options, chdir: cwd.to_path
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'
task :gcc1, [:target] do |_, args|
options = find_build_target GCC_VERSION, args[:target]
options.tools.mkpath
source_directory = download_and_unarchive(
URI.parse("https://gcc.gnu.org/pub/gcc/releases/gcc-#{GCC_VERSION}/gcc-#{GCC_VERSION}.tar.xz"),
options.tools)
cwd = source_directory.dirname + 'build-gcc'
cwd.mkpath
options.rootfs.mkpath
options.sysroot.mkpath
sh 'contrib/download_prerequisites', chdir: source_directory.to_path
configure_options = options.configuration + [
"--prefix=#{options.rootfs.realpath}",
"--with-sysroot=#{options.sysroot.realpath}",
'--enable-languages=c,c++',
'--disable-shared',
'--disable-bootstrap',
'--disable-multilib',
'--disable-libmudflap',
'--disable-libssp',
'--disable-libquadmath',
'--disable-libsanitizer',
'--disable-threads',
'--disable-libatomic',
'--disable-libgomp',
'--disable-libvtv',
'--disable-libstdcxx',
'--disable-nls',
'--with-newlib',
'--without-headers',
"--target=#{options.target}",
"--build=#{options.build}",
"--host=#{options.build}"
]
flags = '-O2 -fPIC'
env = {
'CC' => options.gcc,
'CXX' => options.gxx,
'CFLAGS' => flags,
'CXXFLAGS' => flags,
'PATH' => "#{options.rootfs.realpath + 'bin'}:#{ENV['PATH']}"
}
configure = source_directory.relative_path_from(cwd) + 'configure'
sh env, configure.to_path, *configure_options, chdir: cwd.to_path
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
source_directory = download_and_unarchive(
URI.parse("https://ftp.gnu.org/gnu/glibc/glibc-#{GLIBC_VERSION}.tar.xz"),
options.tools)
include_directory = options.tools + 'include'
include_directory.mkpath
cp (source_directory + 'elf/elf.h'), (include_directory + 'elf.h')
end
desc 'Build linux kernel'
task :kernel, [:target] do |_, args|
options = find_build_target GCC_VERSION, args[:target]
options.tools.mkpath
cwd = download_and_unarchive(
URI.parse("https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-#{KERNEL_VERSION}.tar.xz"),
options.tools)
env = {
'CROSS_COMPILE' => "#{options.target}-",
'ARCH' => 'riscv',
'PATH' => "#{options.rootfs.realpath + 'bin'}:#{ENV['PATH']}",
'HOSTCFLAGS' => "-D_UUID_T -D__GETHOSTUUID_H -I#{options.tools.realpath + 'include'}"
}
sh env, 'make', 'rv32_defconfig', chdir: cwd.to_path
sh env, 'make', '-j', Etc.nprocessors.to_s, chdir: cwd.to_path
sh env, 'make', 'headers', chdir: cwd.to_path
user_directory = options.sysroot + 'usr'
user_directory.mkpath
cp_r (cwd + 'usr/include'), (user_directory + 'include')
end
desc 'Build glibc'
task :glibc, [:target] do |_, args|
options = find_build_target GCC_VERSION, args[:target]
source_directory = options.tools + "glibc-#{GLIBC_VERSION}"
configure_options = [
'--prefix=/usr',
"--host=#{options.target}",
"--target=#{options.target}",
"--build=#{options.build}",
"--enable-kernel=#{KERNEL_VERSION}",
"--with-headers=#{options.sysroot.realpath + 'usr/include'}",
'--disable-nscd',
'--disable-libquadmath',
'--disable-libitm',
'--disable-werror',
'libc_cv_forced_unwind=yes'
]
bin = options.rootfs.realpath + 'bin'
env = {
'PATH' => "#{bin}:#{ENV['PATH']}",
'MAKE' => 'make' # Otherwise it uses gnumake which can be different and too old.
}
cwd = source_directory.dirname + 'build-glibc'
cwd.mkpath
configure = source_directory.relative_path_from(cwd) +'./configure'
sh env, configure.to_path, *configure_options, chdir: cwd.to_path
sh env, 'make', '-j', Etc.nprocessors.to_s, chdir: cwd.to_path
sh env, 'make', "install_root=#{options.sysroot.realpath}", 'install', chdir: cwd.to_path
end
desc 'Build stage 2 GCC'
task :gcc2, [:target] do |_, args|
options = find_build_target GCC_VERSION, args[:target]
source_directory = options.tools + "gcc-#{GCC_VERSION}"
cwd = options.tools + 'build-gcc'
rm_rf cwd
cwd.mkpath
configure_options = options.configuration + [
"--prefix=#{options.rootfs.realpath}",
"--with-sysroot=#{options.sysroot.realpath}",
'--enable-languages=c,c++,lto',
'--enable-lto',
'--enable-shared',
'--disable-bootstrap',
'--disable-multilib',
'--enable-checking=release',
'--disable-libssp',
'--disable-libquadmath',
'--enable-threads=posix',
'--with-default-libstdcxx-abi=new',
'--disable-nls',
"--target=#{options.target}",
"--build=#{options.build}",
"--host=#{options.build}"
]
flags = '-O2 -fPIC'
env = {
'CFLAGS' => flags,
'CXXFLAGS' => flags,
'PATH' => "#{options.rootfs.realpath + 'bin'}:#{ENV['PATH']}"
}
configure = source_directory.relative_path_from(cwd) + 'configure'
sh env, configure.to_path, *configure_options, chdir: cwd.to_path
sh env, 'make', '-j', Etc.nprocessors.to_s, chdir: cwd.to_path
sh env, 'make', 'install', chdir: cwd.to_path
end
task :init, [:target] do |_, args|
options = find_build_target GCC_VERSION, args[:target]
env = {

View File

@ -174,14 +174,12 @@ begin
return c = ' ' or c = '\n' or c = '\t'
end
proc string_equals_chars(this: String, that: pointer to Char, length: Word): Bool;
var
i: Word;
proc string_equals(this: String, that: String): Bool;
begin
if this.length <> length then
if this.length <> that.length then
return false
end;
return strncmp(this.ptr, that, length) = 0
return strncmp(this.ptr, that.ptr, this.length) = 0
end
proc open_substring(string: String, start: Word): String;
@ -482,7 +480,7 @@ begin
write_s("SIZEOF")
elsif current_token^.kind = TOKEN_IDENTIFIER then
write_c('<');
write_z(current_token^.value.string_value);
write_s(current_token^.value.string);
write_c('>')
elsif current_token^.kind = TOKEN_LEFT_PAREN then
write_s("(")
@ -558,76 +556,75 @@ begin
write_c('\n')
end
proc categorize_identifier(input_pointer: pointer to Char, token_length: Int): Token;
proc categorize_identifier(token_content: String): Token;
var
current_token: Token;
begin
if string_equals_chars("if", input_pointer, token_length) then
if string_equals("if", token_content) then
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
elsif string_equals_chars("else", input_pointer, token_length) then
elsif string_equals("else", token_content) then
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
elsif string_equals_chars("while", input_pointer, token_length) then
elsif string_equals("while", token_content) then
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
elsif string_equals_chars("proc", input_pointer, token_length) then
elsif string_equals("proc", token_content) then
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
elsif string_equals_chars("end", input_pointer, token_length) then
elsif string_equals("end", token_content) then
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
elsif string_equals_chars("const", input_pointer, token_length) then
elsif string_equals("const", token_content) then
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
elsif string_equals_chars("array", input_pointer, token_length) then
elsif string_equals("array", token_content) then
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
elsif string_equals_chars("type", input_pointer, token_length) then
elsif string_equals("type", token_content) then
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
elsif string_equals_chars("union", input_pointer, token_length) then
elsif string_equals("union", token_content) then
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
elsif string_equals_chars("to", input_pointer, token_length) then
elsif string_equals("to", token_content) then
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.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.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
elsif string_equals_chars("and", input_pointer, token_length) then
elsif string_equals("and", token_content) then
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
elsif string_equals_chars("not", input_pointer, token_length) then
elsif string_equals("not", token_content) then
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
elsif string_equals_chars("cast", input_pointer, token_length) then
elsif string_equals("cast", token_content) then
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
elsif string_equals_chars("sizeof", input_pointer, token_length) then
elsif string_equals("sizeof", token_content) then
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
else
current_token.kind := TOKEN_IDENTIFIER;
current_token.value.string_value := cast(calloc(token_length + 1, 1) as pointer to Char);
strncpy(current_token.value.string_value, input_pointer, token_length)
current_token.value.string := string_dup(token_content)
end;
return current_token
@ -653,7 +650,7 @@ begin
if is_alpha(first_char) or first_char = '_' then
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)
elsif is_digit(first_char) then