| 1 | package SPVM::Builder::Exe; | ||||||||||||
| 2 | |||||||||||||
| 3 | 126 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 126 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | 126 | ▶ | use Carp (); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | 126 | ▶ | use JSON::PP; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | 126 | ▶ | use File::Basename 'basename', 'dirname', 'fileparse'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | 126 | ▶ | use File::Path 'mkpath', 'rmtree'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | 126 | ▶ | use File::Find 'find'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 10 | 126 | ▶ | use Archive::Tar; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 11 | 126 | ▶ | use File::Copy 'copy'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 12 | 126 | ▶ | use Time::HiRes; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 13 | 126 | ▶ | use Digest::SHA 'sha1_hex'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 14 | |||||||||||||
| 15 | 126 | ▶ | use SPVM::Builder; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 16 | 126 | ▶ | use SPVM::Builder::CC; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 17 | 126 | ▶ | use SPVM::Builder::Util; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 18 | 126 | ▶ | use SPVM::Builder::Config::Global; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 19 | 126 | ▶ | use SPVM::Builder::Config::Exe; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 20 | 126 | ▶ | use SPVM::Builder::Config::DLL; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 21 | |||||||||||||
| 22 | 126 | ▶ | use SPVM::Builder::Native::Compiler; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 23 | 126 | ▶ | use SPVM::Builder::Native::Runtime; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 24 | 126 | ▶ | use SPVM::Builder::Native::BasicType; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 25 | 126 | ▶ | use SPVM::Builder::Native::ClassFile; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 26 | 126 | ▶ | use SPVM::Builder::ScriptInfo; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 27 | 126 | ▶ | use SPVM::Builder::ObjectFileInfo; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 28 | 126 | ▶ | use SPVM::Builder::Config::Util; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 29 | |||||||||||||
| 30 | 126 | ▶ | use SPVM::Builder::Accessor 'has'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 31 | |||||||||||||
| 32 | # Fields | ||||||||||||
| 33 | 126 | my $field_names = [qw( | |||||||||||
| 34 | builder | ||||||||||||
| 35 | script_name | ||||||||||||
| 36 | class_name | ||||||||||||
| 37 | output_file | ||||||||||||
| 38 | config | ||||||||||||
| 39 | compiler | ||||||||||||
| 40 | allow_no_config_file | ||||||||||||
| 41 | mode | ||||||||||||
| 42 | runtime | ||||||||||||
| 43 | )]; | ||||||||||||
| 44 | 126 | has $field_names; | |||||||||||
| 45 | |||||||||||||
| 46 | # Class Methods | ||||||||||||
| 47 | |||||||||||||
| 48 | 125 | ▶ | sub new { | ||||||||||
|
Subroutine
new: called CC=6 SCAR=17.9
Pod
undocumented
| |||||||||||||
| 49 | 125 | my $class = shift; | |||||||||||
| 50 | |||||||||||||
| 51 | 125 | my %options = @_; | |||||||||||
| 52 | |||||||||||||
| 53 | 125 | my $self = bless { | |||||||||||
| 54 | external_object_files => [], | ||||||||||||
| 55 | %options | ||||||||||||
| 56 | }, $class; | ||||||||||||
| 57 | |||||||||||||
| 58 | 125 | my $script_name = $self->{script_name}; | |||||||||||
| 59 | |||||||||||||
| 60 | 125 | $self->check_script_name; | |||||||||||
| 61 | |||||||||||||
| 62 | # Excutable file name | ||||||||||||
| 63 | 125 | my $output_file = $self->{output_file}; | |||||||||||
| 64 | 125 | ▶ | unless (defined $output_file) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 65 | 0 | Carp::confess("A output file must be defined."); | |||||||||||
| 66 | } | ||||||||||||
| 67 | |||||||||||||
| 68 | 125 | my $app_name = $self->app_name; | |||||||||||
| 69 | |||||||||||||
| 70 | # Config mode | ||||||||||||
| 71 | 125 | my $config_mode = $self->{mode}; | |||||||||||
| 72 | |||||||||||||
| 73 | # New SPVM::Builder object | ||||||||||||
| 74 | my $builder = SPVM::Builder->new( | ||||||||||||
| 75 | 125 | ▶ | exists $self->{build_dir} ? (build_dir => $self->{build_dir}) : (), | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 76 | ); | ||||||||||||
| 77 | |||||||||||||
| 78 | # Config file settings | ||||||||||||
| 79 | 125 | my $allow_no_config_file = $self->{allow_no_config_file}; | |||||||||||
| 80 | |||||||||||||
| 81 | # Config | ||||||||||||
| 82 | 125 | my $config_file = SPVM::Builder::Config::Util::create_config_file_path_from_class_file_path($script_name); | |||||||||||
| 83 | |||||||||||||
| 84 | 125 | my $config; | |||||||||||
| 85 | 125 | ▶ | if ($allow_no_config_file) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 86 | 32 | $config = SPVM::Builder::Config::Exe->new; | |||||||||||
| 87 | } | ||||||||||||
| 88 | else { | ||||||||||||
| 89 | 93 | $config = SPVM::Builder::Config::Util::load_mode_config($config_file, $config_mode); | |||||||||||
| 90 | } | ||||||||||||
| 91 | |||||||||||||
| 92 | 125 | $self->{builder} = $builder; | |||||||||||
| 93 | |||||||||||||
| 94 | # Override config settings with command line options if defined | ||||||||||||
| 95 | { | ||||||||||||
| 96 | 125 | ▶ | if (defined $self->{external_object_files}) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 97 | 125 | $config->external_object_files($self->{external_object_files}); | |||||||||||
| 98 | } | ||||||||||||
| 99 | } | ||||||||||||
| 100 | |||||||||||||
| 101 | 125 | $self->config($config); | |||||||||||
| 102 | |||||||||||||
| 103 | 125 | my $compiler = SPVM::Builder::Native::Compiler->new; | |||||||||||
| 104 | |||||||||||||
| 105 | 125 | for my $class_search_dir (@{$builder->class_search_dirs}) { | |||||||||||
| 106 | 2267 | $compiler->add_class_search_dir($class_search_dir); | |||||||||||
| 107 | } | ||||||||||||
| 108 | |||||||||||||
| 109 | 125 | $self->{compiler} = $compiler; | |||||||||||
| 110 | |||||||||||||
| 111 | 125 | $self->prepare_compile; | |||||||||||
| 112 | |||||||||||||
| 113 | 123 | return $self; | |||||||||||
| 114 | } | ||||||||||||
| 115 | |||||||||||||
| 116 | # Instance Methods | ||||||||||||
| 117 | 123 | ▶ | sub build_exe_file { | ||||||||||
|
Subroutine
build_exe_file: called CC=9 SCAR=22.0
Pod
undocumented
| |||||||||||||
| 118 | 123 | my ($self) = @_; | |||||||||||
| 119 | |||||||||||||
| 120 | 123 | my $builder = $self->builder; | |||||||||||
| 121 | |||||||||||||
| 122 | 123 | my $config = $self->config; | |||||||||||
| 123 | |||||||||||||
| 124 | 123 | my $output_file = $self->{output_file}; | |||||||||||
| 125 | 123 | $config->output_file($output_file); | |||||||||||
| 126 | |||||||||||||
| 127 | 123 | my $class_name = $self->{class_name}; | |||||||||||
| 128 | |||||||||||||
| 129 | 123 | my $class = $self->runtime->get_basic_type_by_name($class_name); | |||||||||||
| 130 | |||||||||||||
| 131 | 123 | my $class_file = $class->get_class_file; | |||||||||||
| 132 | |||||||||||||
| 133 | 123 | my $class_names_include_spvm_script_class_name = $self->get_user_defined_basic_type_names; | |||||||||||
| 134 | 123 | my $class_names = []; | |||||||||||
| 135 | 123 | my $spvm_script_class_name; | |||||||||||
| 136 | my $spvm_script_config_file; | ||||||||||||
| 137 | 123 | for my $class_name (@$class_names_include_spvm_script_class_name) { | |||||||||||
| 138 | 3355 | my $script_name = $self->script_name; | |||||||||||
| 139 | 3355 | my $config_file; | |||||||||||
| 140 | 3355 | ▶ | if ($class_name eq $self->class_name) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 141 | 123 | $spvm_script_class_name = $class_name; | |||||||||||
| 142 | 123 | $spvm_script_config_file = SPVM::Builder::Config::Util::create_config_file_path_from_class_file_path($script_name); | |||||||||||
| 143 | } | ||||||||||||
| 144 | else { | ||||||||||||
| 145 | 3232 | push @$class_names, $class_name; | |||||||||||
| 146 | } | ||||||||||||
| 147 | } | ||||||||||||
| 148 | 123 | my $no_compile_resources = 1; | |||||||||||
| 149 | |||||||||||||
| 150 | 123 | my $builder_cc = SPVM::Builder::CC->new(builder => $builder, runtime => $self->runtime); | |||||||||||
| 151 | |||||||||||||
| 152 | 123 | my $compile_infos = []; | |||||||||||
| 153 | |||||||||||||
| 154 | 123 | my $bootstrap_link_info = $self->prepare_compile_bootstrap_source_file; | |||||||||||
| 155 | 123 | push @$compile_infos, @{$bootstrap_link_info->compile_infos}; | |||||||||||
| 156 | |||||||||||||
| 157 | 123 | my $spvm_core_link_info = $builder->prepare_compile_spvm_core_source_files; | |||||||||||
| 158 | 123 | push @$compile_infos, @{$spvm_core_link_info->compile_infos}; | |||||||||||
| 159 | |||||||||||||
| 160 | 123 | for my $class_name (@$class_names) { | |||||||||||
| 161 | 3232 | my $native_link_info = $builder_cc->prepare_compile_native_class($class_name, {no_compile_resources => $no_compile_resources}); | |||||||||||
| 162 | 3232 | ▶ | if ($native_link_info) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 163 | 120 | push @$compile_infos, @{$native_link_info->compile_infos}; | |||||||||||
| 164 | } | ||||||||||||
| 165 | } | ||||||||||||
| 166 | |||||||||||||
| 167 | 123 | for my $class_name (@$class_names) { | |||||||||||
| 168 | 3232 | my $precompile_link_info = $builder_cc->prepare_compile_precompile_class($class_name); | |||||||||||
| 169 | 3232 | ▶ | if ($precompile_link_info) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 170 | 3232 | push @$compile_infos, @{$precompile_link_info->compile_infos}; | |||||||||||
| 171 | } | ||||||||||||
| 172 | } | ||||||||||||
| 173 | |||||||||||||
| 174 | 123 | my $spvm_scritp_native_link_info = $builder_cc->prepare_compile_native_class($spvm_script_class_name, {config_file => $spvm_script_config_file}); | |||||||||||
| 175 | 123 | ▶ | if ($spvm_scritp_native_link_info) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 176 | 91 | push @$compile_infos, @{$spvm_scritp_native_link_info->compile_infos}; | |||||||||||
| 177 | } | ||||||||||||
| 178 | |||||||||||||
| 179 | 123 | for my $compile_info (@$compile_infos) { | |||||||||||
| 180 | 7509 | $compile_info->config->output_type('exe'); | |||||||||||
| 181 | } | ||||||||||||
| 182 | |||||||||||||
| 183 | 123 | my $link_info = SPVM::Builder::LinkInfo->new(config => $config, compile_infos => $compile_infos); | |||||||||||
| 184 | |||||||||||||
| 185 | 123 | my $diagnostic_message = "[Generate Executable File:\$output_file='$output_file']"; | |||||||||||
| 186 | 123 | $link_info->diagnostic_message($diagnostic_message); | |||||||||||
| 187 | |||||||||||||
| 188 | 123 | $builder->build_parallel_with_link_infos([$link_info], {config_global => $config->global}); | |||||||||||
| 189 | } | ||||||||||||
| 190 | |||||||||||||
| 191 | 125 | ▶ | sub prepare_compile { | ||||||||||
|
Subroutine
prepare_compile: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 192 | 125 | my ($self) = @_; | |||||||||||
| 193 | |||||||||||||
| 194 | 125 | my $script_name = $self->{script_name}; | |||||||||||
| 195 | |||||||||||||
| 196 | 125 | my $compiler = $self->compiler; | |||||||||||
| 197 | |||||||||||||
| 198 | 125 | ▶ | open my $script_fh, '<', $script_name | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 199 | or die "Can't open file '$script_name':$!"; | ||||||||||||
| 200 | |||||||||||||
| 201 | 125 | my $source = do { local $/; <$script_fh> }; | |||||||||||
| 202 | |||||||||||||
| 203 | 125 | $source = "#file \"$script_name\"\x{A}$source"; | |||||||||||
| 204 | |||||||||||||
| 205 | 125 | my $class_name = $compiler->compile_anon_class_with_exit($source, __FILE__, __LINE__); | |||||||||||
| 206 | |||||||||||||
| 207 | 123 | $self->class_name($class_name); | |||||||||||
| 208 | |||||||||||||
| 209 | 123 | $self->config->class_name($class_name); | |||||||||||
| 210 | |||||||||||||
| 211 | 123 | my $runtime = $compiler->get_runtime; | |||||||||||
| 212 | |||||||||||||
| 213 | 123 | $self->runtime($runtime); | |||||||||||
| 214 | } | ||||||||||||
| 215 | |||||||||||||
| 216 | 123 | ▶ | sub create_bootstrap_header_source { | ||||||||||
|
Subroutine
create_bootstrap_header_source: called CC=7 SCAR=19.5
Pod
undocumented
| |||||||||||||
| 217 | 123 | my ($self) = @_; | |||||||||||
| 218 | |||||||||||||
| 219 | 123 | my $class_name = $self->class_name; | |||||||||||
| 220 | |||||||||||||
| 221 | 123 | my $class_names = $self->get_user_defined_basic_type_names; | |||||||||||
| 222 | |||||||||||||
| 223 | 123 | my $source = ''; | |||||||||||
| 224 | |||||||||||||
| 225 | 123 | $source .= <<'EOS'; | |||||||||||
| 226 | |||||||||||||
| 227 | #include <stdio.h> | ||||||||||||
| 228 | #include <stdlib.h> | ||||||||||||
| 229 | #include <string.h> | ||||||||||||
| 230 | #include <inttypes.h> | ||||||||||||
| 231 | #include <time.h> | ||||||||||||
| 232 | #include <assert.h> | ||||||||||||
| 233 | |||||||||||||
| 234 | #include "spvm_native.h" | ||||||||||||
| 235 | |||||||||||||
| 236 | EOS | ||||||||||||
| 237 | |||||||||||||
| 238 | 123 | $source .= "// precompile functions declaration\n"; | |||||||||||
| 239 | 123 | for my $class_name (@$class_names) { | |||||||||||
| 240 | 3355 | my $class = $self->runtime->get_basic_type_by_name($class_name); | |||||||||||
| 241 | 3355 | my $precompile_method_names = $class->get_precompile_method_names; | |||||||||||
| 242 | 3355 | for my $method_name (@$precompile_method_names) { | |||||||||||
| 243 | 1260 | my $class_cname = $class_name; | |||||||||||
| 244 | 1260 | $class_cname =~ s/::/__/g; | |||||||||||
| 245 | 1260 | $source .= <<"EOS"; | |||||||||||
| 246 | int32_t SPVMPRECOMPILE__${class_cname}__$method_name(SPVM_ENV* env, SPVM_VALUE* stack); | ||||||||||||
| 247 | EOS | ||||||||||||
| 248 | } | ||||||||||||
| 249 | |||||||||||||
| 250 | 3355 | my $basic_type = $self->runtime->get_basic_type_by_name($class_name); | |||||||||||
| 251 | 3355 | my $anon_basic_type_names = $basic_type->get_anon_basic_type_names; | |||||||||||
| 252 | 3355 | for my $anon_basic_type_name (@$anon_basic_type_names) { | |||||||||||
| 253 | 290 | my $anon_basic_type_cname = $anon_basic_type_name; | |||||||||||
| 254 | 290 | $anon_basic_type_cname =~ s/::/__/g; | |||||||||||
| 255 | |||||||||||||
| 256 | 290 | my $anon_basic_type = $self->runtime->get_basic_type_by_name($anon_basic_type_name); | |||||||||||
| 257 | 290 | my $anon_method = $anon_basic_type->get_method_by_name(""); | |||||||||||
| 258 | 290 | ▶ | if ($anon_method->is_precompile) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 259 | 24 | $source .= <<"EOS"; | |||||||||||
| 260 | int32_t SPVMPRECOMPILE__${anon_basic_type_cname}__(SPVM_ENV* env, SPVM_VALUE* stack); | ||||||||||||
| 261 | EOS | ||||||||||||
| 262 | } | ||||||||||||
| 263 | } | ||||||||||||
| 264 | } | ||||||||||||
| 265 | |||||||||||||
| 266 | 123 | my $boostrap_name_space = $self->create_boostrap_name_space; | |||||||||||
| 267 | |||||||||||||
| 268 | 123 | $source .= "void ${boostrap_name_space}build_runtime(SPVM_ENV* env);\n\n"; | |||||||||||
| 269 | |||||||||||||
| 270 | 123 | $source .= "static void set_precompile_method_addresses(SPVM_ENV* env);\n"; | |||||||||||
| 271 | |||||||||||||
| 272 | 123 | $source .= "// native functions declaration\n"; | |||||||||||
| 273 | 123 | for my $class_name (@$class_names) { | |||||||||||
| 274 | 3355 | my $class = $self->runtime->get_basic_type_by_name($class_name); | |||||||||||
| 275 | 3355 | my $native_method_names = $class->get_native_method_names; | |||||||||||
| 276 | 3355 | for my $method_name (@$native_method_names) { | |||||||||||
| 277 | 1188 | my $class_name = $class_name; | |||||||||||
| 278 | 1188 | $class_name =~ s/::/__/g; | |||||||||||
| 279 | 1188 | $source .= <<"EOS"; | |||||||||||
| 280 | int32_t SPVM__${class_name}__$method_name(SPVM_ENV* env, SPVM_VALUE* stack); | ||||||||||||
| 281 | EOS | ||||||||||||
| 282 | } | ||||||||||||
| 283 | } | ||||||||||||
| 284 | |||||||||||||
| 285 | 123 | $source .= "static void set_native_method_addresses(SPVM_ENV* env);\n\n"; | |||||||||||
| 286 | |||||||||||||
| 287 | 123 | $source .= "static void compile_all_classes(SPVM_ENV* env);\n\n"; | |||||||||||
| 288 | |||||||||||||
| 289 | 123 | $source .= <<"EOS"; | |||||||||||
| 290 | static void set_precompile_method_address(SPVM_ENV* env, const char* class_name, const char* method_name, void* precompile_address); | ||||||||||||
| 291 | |||||||||||||
| 292 | EOS | ||||||||||||
| 293 | |||||||||||||
| 294 | 123 | $source .= <<"EOS"; | |||||||||||
| 295 | static void set_native_method_address(SPVM_ENV* env, const char* class_name, const char* method_name, void* native_address); | ||||||||||||
| 296 | |||||||||||||
| 297 | EOS | ||||||||||||
| 298 | |||||||||||||
| 299 | 123 | return $source; | |||||||||||
| 300 | } | ||||||||||||
| 301 | |||||||||||||
| 302 | 123 | ▶ | sub create_bootstrap_main_func_source { | ||||||||||
|
Subroutine
create_bootstrap_main_func_source: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||
| 303 | 123 | my ($self) = @_; | |||||||||||
| 304 | |||||||||||||
| 305 | 123 | my $class_name = $self->class_name; | |||||||||||
| 306 | |||||||||||||
| 307 | 123 | my $class_names = $self->get_user_defined_basic_type_names; | |||||||||||
| 308 | |||||||||||||
| 309 | 123 | ▶ | my $warning = $^W ? 1 : 0; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 310 | |||||||||||||
| 311 | 123 | my $boostrap_name_space = $self->create_boostrap_name_space; | |||||||||||
| 312 | |||||||||||||
| 313 | 123 | my $source = ''; | |||||||||||
| 314 | |||||||||||||
| 315 | 123 | $source .= <<"EOS"; | |||||||||||
| 316 | int main(int argc, char* argv[]); | ||||||||||||
| 317 | int SPVMCC__main(int argc, char* argv[]); | ||||||||||||
| 318 | |||||||||||||
| 319 | int SPVMCC__main(int argc, char* argv[]) { | ||||||||||||
| 320 | |||||||||||||
| 321 | int32_t error_id = 0; | ||||||||||||
| 322 | |||||||||||||
| 323 | SPVM_ENV* boot_env = SPVM_NATIVE_new_env(); | ||||||||||||
| 324 | |||||||||||||
| 325 | void* compiler = boot_env->api->compiler->new_instance(); | ||||||||||||
| 326 | |||||||||||||
| 327 | SPVM_ENV* env = boot_env->new_env(); | ||||||||||||
| 328 | |||||||||||||
| 329 | error_id = env->api->compiler->compile(compiler, NULL); | ||||||||||||
| 330 | assert(error_id == 0); | ||||||||||||
| 331 | |||||||||||||
| 332 | env->runtime = env->api->compiler->get_runtime(compiler); | ||||||||||||
| 333 | |||||||||||||
| 334 | ${boostrap_name_space}build_runtime(env); | ||||||||||||
| 335 | |||||||||||||
| 336 | FILE* spvm_stderr = env->api->runtime->get_spvm_stderr(env->runtime); | ||||||||||||
| 337 | |||||||||||||
| 338 | SPVM_VALUE* stack = env->new_stack(env); | ||||||||||||
| 339 | |||||||||||||
| 340 | // Set the program name and the command line arguments | ||||||||||||
| 341 | { | ||||||||||||
| 342 | int32_t mortal_stack_top = env->enter_scope(env, stack); | ||||||||||||
| 343 | |||||||||||||
| 344 | void* obj_program_name = env->new_string(env, stack, argv[0], strlen(argv[0])); | ||||||||||||
| 345 | |||||||||||||
| 346 | // ARGV - string[] | ||||||||||||
| 347 | void* obj_argv = env->new_string_array(env, stack, argc - 1); | ||||||||||||
| 348 | for (int32_t arg_index = 1; arg_index < argc; arg_index++) { | ||||||||||||
| 349 | void* obj_arg = env->new_string(env, stack, argv[arg_index], strlen(argv[arg_index])); | ||||||||||||
| 350 | env->set_elem_object(env, stack, obj_argv, arg_index - 1, obj_arg); | ||||||||||||
| 351 | } | ||||||||||||
| 352 | |||||||||||||
| 353 | int64_t base_time = time(NULL); | ||||||||||||
| 354 | |||||||||||||
| 355 | // Set command line info | ||||||||||||
| 356 | { | ||||||||||||
| 357 | error_id = env->set_command_info_program_name(env, stack, obj_program_name); | ||||||||||||
| 358 | |||||||||||||
| 359 | if (error_id) { | ||||||||||||
| 360 | env->die(env, stack, env->get_chars(env, stack, env->get_exception(env, stack)), __func__, __FILE__, __LINE__); | ||||||||||||
| 361 | goto END_OF_FUNC; | ||||||||||||
| 362 | } | ||||||||||||
| 363 | |||||||||||||
| 364 | error_id = env->set_command_info_argv(env, stack, obj_argv); | ||||||||||||
| 365 | |||||||||||||
| 366 | if (error_id) { | ||||||||||||
| 367 | env->die(env, stack, env->get_chars(env, stack, env->get_exception(env, stack)), __func__, __FILE__, __LINE__); | ||||||||||||
| 368 | goto END_OF_FUNC; | ||||||||||||
| 369 | } | ||||||||||||
| 370 | |||||||||||||
| 371 | error_id = env->set_command_info_basetime(env, stack, base_time); | ||||||||||||
| 372 | if (error_id) { | ||||||||||||
| 373 | env->die(env, stack, env->get_chars(env, stack, env->get_exception(env, stack)), __func__, __FILE__, __LINE__); | ||||||||||||
| 374 | goto END_OF_FUNC; | ||||||||||||
| 375 | } | ||||||||||||
| 376 | |||||||||||||
| 377 | error_id = env->set_command_info_warning(env, stack, $warning); | ||||||||||||
| 378 | if (error_id) { | ||||||||||||
| 379 | env->die(env, stack, env->get_chars(env, stack, env->get_exception(env, stack)), __func__, __FILE__, __LINE__); | ||||||||||||
| 380 | goto END_OF_FUNC; | ||||||||||||
| 381 | } | ||||||||||||
| 382 | } | ||||||||||||
| 383 | |||||||||||||
| 384 | env->leave_scope(env, stack, mortal_stack_top); | ||||||||||||
| 385 | } | ||||||||||||
| 386 | |||||||||||||
| 387 | const char* class_name = "$class_name"; | ||||||||||||
| 388 | |||||||||||||
| 389 | error_id = env->check_bootstrap_method(env, stack, class_name); | ||||||||||||
| 390 | |||||||||||||
| 391 | if (error_id) { | ||||||||||||
| 392 | env->die(env, stack, env->get_chars(env, stack, env->get_exception(env, stack)), __func__, __FILE__, __LINE__); | ||||||||||||
| 393 | goto END_OF_FUNC; | ||||||||||||
| 394 | } | ||||||||||||
| 395 | |||||||||||||
| 396 | error_id = env->call_init_methods(env, stack); | ||||||||||||
| 397 | if (error_id) { | ||||||||||||
| 398 | goto END_OF_FUNC; | ||||||||||||
| 399 | } | ||||||||||||
| 400 | |||||||||||||
| 401 | void* class_basic_type = env->api->runtime->get_basic_type_by_name(env->runtime, class_name); | ||||||||||||
| 402 | void* method = env->api->basic_type->get_method_by_name(env->runtime, class_basic_type, "main"); | ||||||||||||
| 403 | |||||||||||||
| 404 | int32_t args_width = 0; | ||||||||||||
| 405 | error_id = env->call_method(env, stack, method, args_width, __func__, __FILE__, __LINE__); | ||||||||||||
| 406 | if (error_id) { | ||||||||||||
| 407 | error_id = env->die(env, stack, env->get_chars(env, stack, env->get_exception(env, stack)), __func__, __FILE__, __LINE__); | ||||||||||||
| 408 | goto END_OF_FUNC; | ||||||||||||
| 409 | } | ||||||||||||
| 410 | |||||||||||||
| 411 | END_OF_FUNC: | ||||||||||||
| 412 | |||||||||||||
| 413 | if (error_id) { | ||||||||||||
| 414 | /* Enter a new scope to handle the exception message object safely */ | ||||||||||||
| 415 | int32_t scope_id = env->enter_scope(env, stack); | ||||||||||||
| 416 | |||||||||||||
| 417 | /* Reconstruct the exception message including the SPVM stack trace */ | ||||||||||||
| 418 | void* obj_exception_with_stack_trace = env->build_exception_message(env, stack, 0); | ||||||||||||
| 419 | |||||||||||||
| 420 | /* Print the full exception message to stderr */ | ||||||||||||
| 421 | env->print_stderr(env, stack, obj_exception_with_stack_trace); | ||||||||||||
| 422 | fprintf(spvm_stderr, "\\n"); | ||||||||||||
| 423 | |||||||||||||
| 424 | /* Leave the scope to free the exception message object */ | ||||||||||||
| 425 | env->leave_scope(env, stack, scope_id); | ||||||||||||
| 426 | } | ||||||||||||
| 427 | |||||||||||||
| 428 | env->call_end_methods(env, stack); | ||||||||||||
| 429 | |||||||||||||
| 430 | env->destroy_class_vars(env, stack); | ||||||||||||
| 431 | |||||||||||||
| 432 | env->free_stack(env, stack); | ||||||||||||
| 433 | |||||||||||||
| 434 | env->free_env(env); | ||||||||||||
| 435 | |||||||||||||
| 436 | boot_env->api->compiler->free_instance(compiler); | ||||||||||||
| 437 | |||||||||||||
| 438 | boot_env->free_env(boot_env); | ||||||||||||
| 439 | |||||||||||||
| 440 | return error_id; | ||||||||||||
| 441 | } | ||||||||||||
| 442 | |||||||||||||
| 443 | int main(int argc, char* argv[]) { | ||||||||||||
| 444 | return SPVMCC__main(argc, argv); | ||||||||||||
| 445 | } | ||||||||||||
| 446 | |||||||||||||
| 447 | EOS | ||||||||||||
| 448 | |||||||||||||
| 449 | 123 | return $source; | |||||||||||
| 450 | } | ||||||||||||
| 451 | |||||||||||||
| 452 | 123 | ▶ | sub create_bootstrap_build_runtime_source { | ||||||||||
|
Subroutine
create_bootstrap_build_runtime_source: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 453 | 123 | my ($self) = @_; | |||||||||||
| 454 | |||||||||||||
| 455 | 123 | my $boostrap_name_space = $self->create_boostrap_name_space; | |||||||||||
| 456 | |||||||||||||
| 457 | 123 | my $source = ''; | |||||||||||
| 458 | |||||||||||||
| 459 | 123 | $source .= <<"EOS"; | |||||||||||
| 460 | |||||||||||||
| 461 | void ${boostrap_name_space}build_runtime(SPVM_ENV* env) { | ||||||||||||
| 462 | |||||||||||||
| 463 | compile_all_classes(env); | ||||||||||||
| 464 | |||||||||||||
| 465 | set_precompile_method_addresses(env); | ||||||||||||
| 466 | |||||||||||||
| 467 | set_native_method_addresses(env); | ||||||||||||
| 468 | } | ||||||||||||
| 469 | |||||||||||||
| 470 | EOS | ||||||||||||
| 471 | |||||||||||||
| 472 | 123 | return $source; | |||||||||||
| 473 | } | ||||||||||||
| 474 | |||||||||||||
| 475 | 123 | ▶ | sub create_bootstrap_compile_source { | ||||||||||
|
Subroutine
create_bootstrap_compile_source: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||
| 476 | 123 | my ($self) = @_; | |||||||||||
| 477 | |||||||||||||
| 478 | # Namespace | ||||||||||||
| 479 | 123 | my $boostrap_name_space = $self->create_boostrap_name_space; | |||||||||||
| 480 | |||||||||||||
| 481 | 123 | my $source = ''; | |||||||||||
| 482 | |||||||||||||
| 483 | # Start function | ||||||||||||
| 484 | 123 | $source .= <<"EOS"; | |||||||||||
| 485 | static void compile_all_classes(SPVM_ENV* env) { | ||||||||||||
| 486 | |||||||||||||
| 487 | /* Get compiler */ | ||||||||||||
| 488 | void* compiler = env->api->runtime->get_compiler(env->runtime); | ||||||||||||
| 489 | |||||||||||||
| 490 | EOS | ||||||||||||
| 491 | |||||||||||||
| 492 | # User defined classes | ||||||||||||
| 493 | 123 | my $class_names = $self->get_user_defined_basic_type_names; | |||||||||||
| 494 | |||||||||||||
| 495 | 123 | my $compiler = $self->compiler; | |||||||||||
| 496 | |||||||||||||
| 497 | 123 | for my $class_name (@$class_names) { | |||||||||||
| 498 | |||||||||||||
| 499 | 3355 | my $class = $self->runtime->get_basic_type_by_name($class_name); | |||||||||||
| 500 | 3355 | my $class_file = $compiler->get_class_file($class_name); | |||||||||||
| 501 | 3355 | my $class_file_rel_file = $class_file->get_rel_file; | |||||||||||
| 502 | 3355 | my $class_file_content = $class_file->get_content; | |||||||||||
| 503 | 3355 | my $class_file_content_length = $class_file->get_content_length; | |||||||||||
| 504 | 3355 | my $source_class_file = ''; | |||||||||||
| 505 | |||||||||||||
| 506 | 3355 | $source_class_file .= qq| {\n|; | |||||||||||
| 507 | |||||||||||||
| 508 | # Add class file | ||||||||||||
| 509 | 3355 | $source_class_file .= qq| env->api->compiler->add_class_file(compiler, "$class_name");\n|; | |||||||||||
| 510 | |||||||||||||
| 511 | 3355 | $source_class_file .= qq| void* class_file = env->api->compiler->get_class_file(compiler, "$class_name");\n|; | |||||||||||
| 512 | |||||||||||||
| 513 | # Set relative file path | ||||||||||||
| 514 | 3355 | ▶ | if (defined $class_file_rel_file) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 515 | 3355 | $source_class_file .= qq| env->api->class_file->set_rel_file(compiler, class_file, "$class_file_rel_file");\n|; | |||||||||||
| 516 | } | ||||||||||||
| 517 | |||||||||||||
| 518 | # Set content as C string literal | ||||||||||||
| 519 | 3355 | ▶ | if (defined $class_file_content) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 520 | 3355 | my $content_literal = $compiler->create_c_string_literal($class_file_content); | |||||||||||
| 521 | 3355 | $source_class_file .= qq| env->api->class_file->set_content(compiler, class_file, \n$content_literal );\n|; | |||||||||||
| 522 | } | ||||||||||||
| 523 | |||||||||||||
| 524 | # Set content length | ||||||||||||
| 525 | 3355 | $source_class_file .= qq| env->api->class_file->set_content_length(compiler, class_file, $class_file_content_length);\n|; | |||||||||||
| 526 | |||||||||||||
| 527 | 3355 | $source_class_file .= qq| }\n|; | |||||||||||
| 528 | |||||||||||||
| 529 | 3355 | $source .= $source_class_file; | |||||||||||
| 530 | } | ||||||||||||
| 531 | |||||||||||||
| 532 | # Set debug info | ||||||||||||
| 533 | 123 | $source .= qq| env->api->compiler->set_start_file(compiler, __FILE__);\n|; | |||||||||||
| 534 | 123 | $source .= qq| env->api->compiler->set_start_line(compiler, __LINE__ + 1);\n|; | |||||||||||
| 535 | |||||||||||||
| 536 | # Compile | ||||||||||||
| 537 | 123 | my $start_class_name = $self->{class_name}; | |||||||||||
| 538 | 123 | $source .= qq| int32_t error_id = env->api->compiler->compile(compiler, \"$start_class_name\");\n|; | |||||||||||
| 539 | |||||||||||||
| 540 | # Error handling | ||||||||||||
| 541 | 123 | $source .= qq| void* runtime = env->api->compiler->get_runtime(compiler);\n|; | |||||||||||
| 542 | 123 | $source .= qq| FILE* spvm_stderr = env->api->runtime->get_spvm_stderr(runtime);\n|; | |||||||||||
| 543 | 123 | $source .= qq| if (error_id != 0) {\n|; | |||||||||||
| 544 | 123 | $source .= qq| fprintf(spvm_stderr, "[Unexpected Compile Error]%s.", env->api->compiler->get_error_message(compiler, 0));\n|; | |||||||||||
| 545 | 123 | $source .= qq| exit(255);\n|; | |||||||||||
| 546 | 123 | $source .= qq| }\n|; | |||||||||||
| 547 | |||||||||||||
| 548 | 123 | $source .= <<"EOS"; | |||||||||||
| 549 | } | ||||||||||||
| 550 | EOS | ||||||||||||
| 551 | |||||||||||||
| 552 | 123 | return $source; | |||||||||||
| 553 | } | ||||||||||||
| 554 | |||||||||||||
| 555 | 123 | ▶ | sub create_bootstrap_set_precompile_method_addresses_func_source { | ||||||||||
|
Subroutine
create_bootstrap_set_precompile_method_addresses_func_source: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||
| 556 | 123 | my ($self) = @_; | |||||||||||
| 557 | |||||||||||||
| 558 | 123 | my $class_names = $self->get_user_defined_basic_type_names; | |||||||||||
| 559 | |||||||||||||
| 560 | 123 | my $boostrap_name_space = $self->create_boostrap_name_space; | |||||||||||
| 561 | |||||||||||||
| 562 | 123 | my $source = ''; | |||||||||||
| 563 | |||||||||||||
| 564 | 123 | $source .= <<"EOS"; | |||||||||||
| 565 | static void set_precompile_method_address(SPVM_ENV* env, const char* class_name, const char* method_name, void* precompile_address) { | ||||||||||||
| 566 | void* class_basic_type = env->api->runtime->get_basic_type_by_name(env->runtime, class_name); | ||||||||||||
| 567 | void* method = env->api->basic_type->get_method_by_name(env->runtime, class_basic_type, method_name); | ||||||||||||
| 568 | env->api->method->set_precompile_address(env->runtime, method, precompile_address); | ||||||||||||
| 569 | } | ||||||||||||
| 570 | |||||||||||||
| 571 | EOS | ||||||||||||
| 572 | |||||||||||||
| 573 | 123 | $source .= <<"EOS"; | |||||||||||
| 574 | static void set_native_method_address(SPVM_ENV* env, const char* class_name, const char* method_name, void* native_address) { | ||||||||||||
| 575 | void* class_basic_type = env->api->runtime->get_basic_type_by_name(env->runtime, class_name); | ||||||||||||
| 576 | void* method = env->api->basic_type->get_method_by_name(env->runtime, class_basic_type, method_name); | ||||||||||||
| 577 | env->api->method->set_native_address(env->runtime, method, native_address); | ||||||||||||
| 578 | } | ||||||||||||
| 579 | |||||||||||||
| 580 | EOS | ||||||||||||
| 581 | |||||||||||||
| 582 | 123 | $source .= "static void set_precompile_method_addresses(SPVM_ENV* env){\n"; | |||||||||||
| 583 | |||||||||||||
| 584 | 123 | for my $class_name (@$class_names) { | |||||||||||
| 585 | 3355 | my $class = $self->runtime->get_basic_type_by_name($class_name); | |||||||||||
| 586 | |||||||||||||
| 587 | 3355 | my $class_cname = $class_name; | |||||||||||
| 588 | 3355 | $class_cname =~ s/::/__/g; | |||||||||||
| 589 | |||||||||||||
| 590 | 3355 | my $precompile_method_names = $class->get_precompile_method_names; | |||||||||||
| 591 | |||||||||||||
| 592 | 3355 | for my $precompile_method_name (@$precompile_method_names) { | |||||||||||
| 593 | 1260 | $source .= <<"EOS"; | |||||||||||
| 594 | set_precompile_method_address(env, "$class_name", "$precompile_method_name", &SPVMPRECOMPILE__${class_cname}__$precompile_method_name); | ||||||||||||
| 595 | |||||||||||||
| 596 | EOS | ||||||||||||
| 597 | } | ||||||||||||
| 598 | |||||||||||||
| 599 | 3355 | my $basic_type = $self->runtime->get_basic_type_by_name($class_name); | |||||||||||
| 600 | 3355 | my $anon_basic_type_names = $basic_type->get_anon_basic_type_names; | |||||||||||
| 601 | 3355 | for my $anon_basic_type_name (@$anon_basic_type_names) { | |||||||||||
| 602 | 290 | my $anon_basic_type_cname = $anon_basic_type_name; | |||||||||||
| 603 | 290 | $anon_basic_type_cname =~ s/::/__/g; | |||||||||||
| 604 | |||||||||||||
| 605 | 290 | my $anon_basic_type = $self->runtime->get_basic_type_by_name($anon_basic_type_name); | |||||||||||
| 606 | 290 | my $anon_method = $anon_basic_type->get_method_by_name(""); | |||||||||||
| 607 | 290 | ▶ | if ($anon_method->is_precompile) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 608 | 24 | $source .= <<"EOS"; | |||||||||||
| 609 | set_precompile_method_address(env, "$anon_basic_type_name", "", &SPVMPRECOMPILE__${anon_basic_type_cname}__); | ||||||||||||
| 610 | |||||||||||||
| 611 | EOS | ||||||||||||
| 612 | } | ||||||||||||
| 613 | } | ||||||||||||
| 614 | } | ||||||||||||
| 615 | |||||||||||||
| 616 | 123 | $source .= "}\n"; | |||||||||||
| 617 | |||||||||||||
| 618 | 123 | return $source; | |||||||||||
| 619 | } | ||||||||||||
| 620 | |||||||||||||
| 621 | 123 | ▶ | sub create_bootstrap_set_native_method_addresses_func_source { | ||||||||||
|
Subroutine
create_bootstrap_set_native_method_addresses_func_source: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||
| 622 | 123 | my ($self) = @_; | |||||||||||
| 623 | |||||||||||||
| 624 | 123 | my $class_names = $self->get_user_defined_basic_type_names; | |||||||||||
| 625 | |||||||||||||
| 626 | 123 | my $boostrap_name_space = $self->create_boostrap_name_space; | |||||||||||
| 627 | |||||||||||||
| 628 | 123 | my $source = ''; | |||||||||||
| 629 | |||||||||||||
| 630 | 123 | $source .= "static void set_native_method_addresses(SPVM_ENV* env){\n"; | |||||||||||
| 631 | |||||||||||||
| 632 | 123 | for my $class_name (@$class_names) { | |||||||||||
| 633 | 3355 | my $class = $self->runtime->get_basic_type_by_name($class_name); | |||||||||||
| 634 | |||||||||||||
| 635 | 3355 | my $class_cname = $class_name; | |||||||||||
| 636 | 3355 | $class_cname =~ s/::/__/g; | |||||||||||
| 637 | |||||||||||||
| 638 | 3355 | my $native_method_names = $class->get_native_method_names; | |||||||||||
| 639 | |||||||||||||
| 640 | 3355 | for my $native_method_name (@$native_method_names) { | |||||||||||
| 641 | 1188 | $source .= <<"EOS"; | |||||||||||
| 642 | set_native_method_address(env, "$class_name", "$native_method_name", &SPVM__${class_cname}__$native_method_name); | ||||||||||||
| 643 | |||||||||||||
| 644 | EOS | ||||||||||||
| 645 | } | ||||||||||||
| 646 | } | ||||||||||||
| 647 | |||||||||||||
| 648 | 123 | $source .= "}\n"; | |||||||||||
| 649 | |||||||||||||
| 650 | 123 | return $source; | |||||||||||
| 651 | } | ||||||||||||
| 652 | |||||||||||||
| 653 | 123 | ▶ | sub create_bootstrap_source { | ||||||||||
|
Subroutine
create_bootstrap_source: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 654 | 123 | my ($self) = @_; | |||||||||||
| 655 | |||||||||||||
| 656 | # Build bootstrap source content | ||||||||||||
| 657 | 123 | my $bootstrap_source = ''; | |||||||||||
| 658 | |||||||||||||
| 659 | 123 | $bootstrap_source .= $self->create_bootstrap_header_source; | |||||||||||
| 660 | |||||||||||||
| 661 | 123 | $bootstrap_source .= $self->create_bootstrap_main_func_source; | |||||||||||
| 662 | |||||||||||||
| 663 | 123 | $bootstrap_source .= $self->create_bootstrap_build_runtime_source; | |||||||||||
| 664 | |||||||||||||
| 665 | 123 | $bootstrap_source .= $self->create_bootstrap_compile_source; | |||||||||||
| 666 | |||||||||||||
| 667 | 123 | $bootstrap_source .= $self->create_bootstrap_set_precompile_method_addresses_func_source; | |||||||||||
| 668 | |||||||||||||
| 669 | 123 | $bootstrap_source .= $self->create_bootstrap_set_native_method_addresses_func_source; | |||||||||||
| 670 | |||||||||||||
| 671 | 123 | $bootstrap_source .= "\n"; | |||||||||||
| 672 | |||||||||||||
| 673 | 123 | return $bootstrap_source; | |||||||||||
| 674 | } | ||||||||||||
| 675 | |||||||||||||
| 676 | 123 | ▶ | sub prepare_compile_bootstrap_source_file { | ||||||||||
|
Subroutine
prepare_compile_bootstrap_source_file: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 677 | 123 | my ($self) = @_; | |||||||||||
| 678 | |||||||||||||
| 679 | 123 | my $builder = $self->builder; | |||||||||||
| 680 | |||||||||||||
| 681 | 123 | my $bootstrap_source = $self->create_bootstrap_source; | |||||||||||
| 682 | |||||||||||||
| 683 | 123 | my $source_rel_file = $self->create_bootstrap_source_rel_file_path($bootstrap_source); | |||||||||||
| 684 | |||||||||||||
| 685 | 123 | my $bootstrap_source_file = $builder->create_build_src_path($source_rel_file); | |||||||||||
| 686 | |||||||||||||
| 687 | 123 | SPVM::Builder::Util::spurt_binary($bootstrap_source_file, $bootstrap_source, $builder->global_lock_fh); | |||||||||||
| 688 | |||||||||||||
| 689 | 123 | my $config = SPVM::Builder::Util::API::create_default_config(); | |||||||||||
| 690 | 123 | my $source_dir = $builder->create_build_src_path; | |||||||||||
| 691 | |||||||||||||
| 692 | 123 | my $compile_info = SPVM::Builder::CompileInfo->new( | |||||||||||
| 693 | source_dir => $source_dir, | ||||||||||||
| 694 | source_rel_file => $source_rel_file, | ||||||||||||
| 695 | config => $config, | ||||||||||||
| 696 | category => 'bootstrap', | ||||||||||||
| 697 | diagnostic_message => "[Compile Bootstrap File]", | ||||||||||||
| 698 | ); | ||||||||||||
| 699 | |||||||||||||
| 700 | 123 | my $link_info = SPVM::Builder::LinkInfo->new(config => $config, compile_infos => [$compile_info]); | |||||||||||
| 701 | |||||||||||||
| 702 | 123 | return $link_info; | |||||||||||
| 703 | } | ||||||||||||
| 704 | |||||||||||||
| 705 | 738 | ▶ | sub get_user_defined_basic_type_names { | ||||||||||
|
Subroutine
get_user_defined_basic_type_names: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 706 | 738 | my ($self) = @_; | |||||||||||
| 707 | |||||||||||||
| 708 | 738 | my $runtime = $self->runtime; | |||||||||||
| 709 | |||||||||||||
| 710 | 738 | my $category = [ | |||||||||||
| 711 | 4, # SPVM_NATIVE_C_BASIC_TYPE_CATEGORY_MULNUM | ||||||||||||
| 712 | 6, # SPVM_NATIVE_C_BASIC_TYPE_CATEGORY_CLASS, | ||||||||||||
| 713 | 7, # SPVM_NATIVE_C_BASIC_TYPE_CATEGORY_INTERFACE, | ||||||||||||
| 714 | ]; | ||||||||||||
| 715 | |||||||||||||
| 716 | # Classes for anon methods are contained in another class. | ||||||||||||
| 717 | 738 | my $basic_types = [grep { $_->get_name !~ /::anon_method::/ } @{$runtime->get_basic_types({category => $category})}]; | |||||||||||
| 718 | |||||||||||||
| 719 | 738 | my $class_names = [map { $_->get_name } @$basic_types]; | |||||||||||
| 720 | |||||||||||||
| 721 | 738 | return $class_names; | |||||||||||
| 722 | } | ||||||||||||
| 723 | |||||||||||||
| 724 | 0 | ▶ | sub parse_option_values_native_class { | ||||||||||
|
Subroutine
parse_option_values_native_class: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||
| 725 | 0 | my ($class, $option_name, $option_values, $value_is_array) = @_; | |||||||||||
| 726 | |||||||||||||
| 727 | 0 | my $hash = {}; | |||||||||||
| 728 | 0 | for my $option_value (@$option_values) { | |||||||||||
| 729 | |||||||||||||
| 730 | 0 | ▶ | if ($option_value =~ /^([\w:]+)\@(.+)/) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 731 | 0 | my $class_name = $1; | |||||||||||
| 732 | |||||||||||||
| 733 | 0 | my $value = $2; | |||||||||||
| 734 | |||||||||||||
| 735 | 0 | ▶ | if ($value_is_array) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 736 | 0 | ▶ | $hash->{$class_name} //= []; | ||||||||||
|
Condition0%0/2
$hash->{$class_name} //= []
MC/DC0%0/1
$hash->{$class_name} //= []
$hash->{$class_name}
Truth table0%0/2
A
A= $hash->{$class_name}
| |||||||||||||
| 737 | 0 | push @{$hash->{$class_name}}, $value; | |||||||||||
| 738 | } | ||||||||||||
| 739 | else { | ||||||||||||
| 740 | 0 | $hash->{$class_name} = $value; | |||||||||||
| 741 | } | ||||||||||||
| 742 | } | ||||||||||||
| 743 | else { | ||||||||||||
| 744 | 0 | Carp::confess "Invalid option value '$option_value' for $option_name option."; | |||||||||||
| 745 | } | ||||||||||||
| 746 | } | ||||||||||||
| 747 | |||||||||||||
| 748 | 0 | return $hash; | |||||||||||
| 749 | } | ||||||||||||
| 750 | |||||||||||||
| 751 | 123 | ▶ | sub create_bootstrap_source_rel_file_path { | ||||||||||
|
Subroutine
create_bootstrap_source_rel_file_path: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||
| 752 | 123 | my ($self, $bootstrap_source) = @_; | |||||||||||
| 753 | |||||||||||||
| 754 | 123 | ▶ | unless (defined $bootstrap_source) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 755 | 0 | confess("A bootstrap source must be defined."); | |||||||||||
| 756 | } | ||||||||||||
| 757 | |||||||||||||
| 758 | # Create a SHA-1 hex digest from the bootstrap source content | ||||||||||||
| 759 | 123 | my $digest = sha1_hex($bootstrap_source); | |||||||||||
| 760 | 123 | my $dir_1 = substr($digest, 0, 2); | |||||||||||
| 761 | 123 | my $dir_2 = substr($digest, 2); | |||||||||||
| 762 | |||||||||||||
| 763 | # Get the base filename without extension | ||||||||||||
| 764 | 123 | my $script_name = $self->script_name; | |||||||||||
| 765 | 123 | my $file_base = basename $script_name; | |||||||||||
| 766 | 123 | $file_base =~ s/\..*$//; | |||||||||||
| 767 | |||||||||||||
| 768 | # Final relative path: bootstrap/[xx]/[xxxx...]/[script_name].c | ||||||||||||
| 769 | 123 | my $bootstrap_source_rel_file = "bootstrap/$dir_1/$dir_2/$file_base.c"; | |||||||||||
| 770 | |||||||||||||
| 771 | 123 | return $bootstrap_source_rel_file; | |||||||||||
| 772 | } | ||||||||||||
| 773 | |||||||||||||
| 774 | 125 | ▶ | sub check_script_name { | ||||||||||
|
Subroutine
check_script_name: called CC=5 SCAR=19.3
Pod
undocumented
| |||||||||||||
| 775 | 125 | my ($self) = @_; | |||||||||||
| 776 | |||||||||||||
| 777 | 125 | my $script_name = $self->{script_name}; | |||||||||||
| 778 | |||||||||||||
| 779 | 125 | ▶ | unless (defined $script_name) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 780 | 0 | Carp::confess("A script name must be defined."); | |||||||||||
| 781 | } | ||||||||||||
| 782 | |||||||||||||
| 783 | 125 | my ($script_name_base) = fileparse $script_name; | |||||||||||
| 784 | |||||||||||||
| 785 | 125 | ▶ | unless ($script_name_base =~ /^[a-zA-Z_][a-zA-Z_0-9\-]*\.spvm$/) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 786 | 0 | Carp::confess "The script base name must match the regex qr/^[a-zA-Z_][a-zA-Z_0-9\\-]*\\.spvm\$/. SCRIPT_NAME='$script_name'."; | |||||||||||
| 787 | } | ||||||||||||
| 788 | |||||||||||||
| 789 | 125 | ▶ | if ($script_name_base =~ /--/) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 790 | 0 | Carp::confess "The script base name cannnot contain '--'. SCRIPT_NAME=$script_name."; | |||||||||||
| 791 | } | ||||||||||||
| 792 | |||||||||||||
| 793 | 125 | ▶ | if ($script_name_base =~ /__/) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 794 | 0 | Carp::confess "The script base name cannot contain '__'. SCRIPT_NAME=$script_name."; | |||||||||||
| 795 | } | ||||||||||||
| 796 | |||||||||||||
| 797 | } | ||||||||||||
| 798 | |||||||||||||
| 799 | 863 | ▶ | sub app_name { | ||||||||||
|
Subroutine
app_name: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 800 | 863 | my ($self) = @_; | |||||||||||
| 801 | |||||||||||||
| 802 | 863 | my $script_name = $self->script_name; | |||||||||||
| 803 | |||||||||||||
| 804 | 863 | my $app_name = basename $script_name; | |||||||||||
| 805 | 863 | $app_name =~ s/\.spvm$//; | |||||||||||
| 806 | |||||||||||||
| 807 | 863 | return $app_name; | |||||||||||
| 808 | } | ||||||||||||
| 809 | |||||||||||||
| 810 | 738 | ▶ | sub create_boostrap_name_space { | ||||||||||
|
Subroutine
create_boostrap_name_space: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||
| 811 | 738 | my ($self, $app_name) = @_; | |||||||||||
| 812 | |||||||||||||
| 813 | 738 | ▶ | unless (defined $app_name) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 814 | 738 | $app_name = $self->app_name; | |||||||||||
| 815 | } | ||||||||||||
| 816 | |||||||||||||
| 817 | 738 | $app_name =~ s/-/____/g; | |||||||||||
| 818 | |||||||||||||
| 819 | 738 | my $name_space = "SPVM_BOOTSTRAP_${app_name}______"; | |||||||||||
| 820 | |||||||||||||
| 821 | 738 | return $name_space; | |||||||||||
| 822 | } | ||||||||||||
| 823 | |||||||||||||
| 824 | 126 | 1; | |||||||||||
| 825 | |||||||||||||
| 826 | =head1 Name | ||||||||||||
| 827 | |||||||||||||
| 828 | SPVM::Builder::Exe - Creating Executable File | ||||||||||||
| 829 | |||||||||||||
| 830 | =head1 Copyright & License | ||||||||||||
| 831 | |||||||||||||
| 832 | Copyright (c) 2023 Yuki Kimoto | ||||||||||||
| 833 | |||||||||||||
| 834 | MIT License | ||||||||||||