⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 import.pl

📁 这是整套横扫千军3D版游戏的源码
💻 PL
📖 第 1 页 / 共 2 页
字号:
    if (/^#define _IEEE754_H.*/) {
        $_.="#include \"../streflop_libm_bridge.h\"\n\n";
    }
    # Protect the Simple section by a #define
    if (/.*?ieee754_float.*?/) {
        $_ = "#if defined(LIBM_COMPILING_FLT32)\n".$_;
    }
    if (/.*?IEEE754_FLOAT_BIAS.*?/) {
        $_ = $_."\n#endif\n";
    }
    # Protect the Double section by a #define
    if (/.*?ieee754_double.*?/) {
        $_ = "#if defined(LIBM_COMPILING_DBL64)\n".$_;
    }
    if (/.*?IEEE754_DOUBLE_BIAS.*?/) {
        $_ = $_."\n#endif\n";
    }
    # Protect the Extended section by a #define
    if (/.*?ieee854_long_double.*?/) {
        $_ = "#if defined(Extended)\n".$_;
        $_ = "#if defined(LIBM_COMPILING_LDBL96)\n".$_;
    }
    if (/.*?IEEE854_LONG_DOUBLE_BIAS.*?/) {
        $_ = $_."\n#endif\n";
        $_ = $_."\n#endif\n";
    }
    $content.=$_;
}
$ieeeAccessorSimple=
 "inline Simple& f() {return SIMPLE_FROM_INT_PTR(&storage[0]);}\n"
."inline const Simple& f() const {return CONST_SIMPLE_FROM_INT_PTR(&storage[0]);}\n";
$ieeeAccessorDouble=
 "inline Double& d() {return DOUBLE_FROM_INT_PTR(&storage[0]);}\n"
."inline const Double& d() const {return CONST_DOUBLE_FROM_INT_PTR(&storage[0]);}\n";
$ieeeAccessorExtended=
 "inline Extended& d() {return EXTENDED_FROM_INT_PTR(&storage[0]);}\n"
."inline const Extended& d() const {return CONST_EXTENDED_FROM_INT_PTR(&storage[0]);}\n";

# multi-line spanning regexp
$content =~ s/union(.*?ieee854_long_double.*?){.*?;/union$1\{\nint storage[sizeof(long double)\/sizeof(int)];\n$ieeeAccessorExtended/sg;
$content =~ s/union(.*?ieee754_double.*?){.*?;/union$1\{\nint storage[sizeof(double)\/sizeof(int)];\n$ieeeAccessorDouble/sg;
$content =~ s/union(.*?ieee754_float.*?){.*?;/union$1\{\nint storage[sizeof(float)\/sizeof(int)];\n$ieeeAccessorSimple/sg;
close FILE;
open(FILE,">headers/ieee754.h");
print FILE $importNotice;
print FILE $content;
close FILE;

# math_private.h needs a special treatement to define the macros for the wrapper objects
# The macros will be defined separately
open(FILE,"<headers/math_private.h");
my $flag=1;
my $precisionMode = "none";
@convert=();
MPRIV_LOOP: while(<FILE>) {
    # keep initial lines with header information and #define file protection
    # skip all lines defining macros and unions
    if (/^#define _MATH_PRIVATE_H_.*/) {
        push @convert,$_;
        push @convert,"\n/* import.pl: Skipped the macro definitions, keep only the declarations, converted to use streflop types (aliases or wrappers) */\n#include \"../streflop_libm_bridge.h\"\n\nnamespace streflop_libm {\n\n";
        # ensure strict separation of precision mode, each one does not have access to the other names
        push @convert,"#ifdef LIBM_COMPILING_FLT32\n";
        # define wrappers as the libm would do in IEEE754 mode
        push @convert,"#define __sqrtf __ieee754_sqrtf\n";
        push @convert,"#define fabsf __fabsf\n";
        push @convert,"#define copysignf __copysignf\n";
        # add missing defines
        push @convert,"extern Simple __log1pf(Simple x);\n";
        push @convert,"extern Simple __fabsf(Simple x);\n";
        push @convert,"extern Simple __atanf(Simple x);\n";
        push @convert,"extern Simple __expm1f(Simple x);\n";
        push @convert,"extern int __isinff(Simple x);\n";
        push @convert,"extern Simple __rintf(Simple x);\n";
        push @convert,"extern Simple __cosf(Simple x);\n";
        push @convert,"extern void __sincosf (Simple x, Simple *sinx, Simple *cosx);\n";
        push @convert,"extern Simple __floorf(Simple x);\n";
        push @convert,"extern Simple __scalbnf (Simple x, int n);\n";
        push @convert,"extern Simple __frexpf(Simple x, int *eptr);\n";
        push @convert,"extern Simple __ldexpf(Simple value, int exp);\n";
        push @convert,"extern int __finitef(Simple x);\n";
        push @convert,"#endif\n\n";
        push @convert,"#ifdef LIBM_COMPILING_DBL64\n";
        push @convert,"#define __sqrt __ieee754_sqrt\n";
        push @convert,"#define fabs __fabs\n";
        push @convert,"#define copysign __copysign\n";
        push @convert,"extern Double __log1p(Double x);\n";
        push @convert,"extern Double __fabs(Double x);\n";
        push @convert,"extern Double atan(Double x);\n";
        push @convert,"extern Double __expm1(Double x);\n";
        push @convert,"extern int __isinf(Double x);\n";
        push @convert,"extern Double __rint(Double x);\n";
        push @convert,"extern Double __cos(Double x);\n";
        push @convert,"extern void __sincos (Double x, Double *sinx, Double *cosx);\n";
        push @convert,"extern Double __floor(Double x);\n";
        push @convert,"extern Double __scalbn(Double x, int n);\n";
        push @convert,"extern Double __frexp(Double x, int *eptr);\n";
        push @convert,"extern Double __ldexp(Double value, int exp);\n";
        push @convert,"extern int __finite(Double x);\n";
        push @convert,"#endif\n\n";
        push @convert,"#ifdef LIBM_COMPILING_LDBL96\n";
        push @convert,"#if defined(Extended)\n";
        push @convert,"#define fabsl __fabsl\n";
        push @convert,"extern Extended __cosl(Extended x);\n";
        push @convert,"extern Extended __sinl(Extended x);\n";
        push @convert,"extern Extended __fabsl(Extended x);\n";
        push @convert,"#endif\n";
        push @convert,"#endif\n";
        push @convert,"\n";
        $flag = 0;
    }
    if (/^extern(.*)/) {
        $flag = 1;
    }
    if ($flag==0) {next MPRIV_LOOP;}


    
    # Now substitute the base types by their Simple/Double/Extended aliases or wrapper
    s/\blong double\b/Extended/g; # before double
    s/\bdouble\b/Double/g;
    s/\bfloat\b/Simple/g;
    # Protect the Extended section by a #define
    if (/.*?elementary Extended functions.*?/) {
        $_ = "#if defined(Extended)\n".$_;
    }
    if (/.*?functions of the IBM.*?/) {
        $_ = "#endif\n\n".$_;
    }
    # remove the inline aliases
    s/__GNUC_PREREQ \(.*?\)/0/;
    # end namespace protection
    if (/^#endif.*_MATH_PRIVATE_H_/) {
        $_ = "}\n\n".$_;
    }

    # now insert protection for symbols separation
    if (/^extern(.*)/) {
        $remline = $1;
        if ($remline =~ /Extended/) {
            if ($precisionMode ne "Extended") {
                if ($precisionMode ne "none") {$_ = "#endif\n".$_;}
                $_ = "#ifdef LIBM_COMPILING_LDBL96\n".$_;
                $precisionMode = "Extended";
            }
        }
        elsif ($remline =~ /Double/) {
            if ($precisionMode ne "Double") {
                if ($precisionMode ne "none") {$_ = "#endif\n".$_;}
                $_ = "#ifdef LIBM_COMPILING_DBL64\n".$_;
                $precisionMode = "Double";
            }
        }
        elsif ($remline =~ /Simple/) {
            if ($precisionMode ne "Simple") {
                if ($precisionMode ne "none") {$_ = "#endif\n".$_;}
                $_ = "#ifdef LIBM_COMPILING_FLT32\n".$_;
                $precisionMode = "Simple";
            }
        }
    } else {
        $line = $_;
        chomp $line;
        if (($line =~ /^(\s)*$/) && ($precisionMode ne "none")) {
            $_ = "#endif\n".$_;
            $precisionMode = "none";
        }
    }
    
    push @convert,$_;
}
close FILE;
open(FILE,">headers/math_private.h");
print FILE $importNotice;
print FILE @convert;
close FILE;

# features.h is nearly ready, just do not include more external defs
open(FILE,"<headers/features.h");
@convert=();
while(<FILE>) {
    # commment out external includes
    s,(.*?#.*?include.*),//$1,;
    push @convert,$_;
}
close FILE;
open(FILE,">headers/features.h");
print FILE $importNotice;
print FILE @convert;
close FILE;

# headers/endian.h
open(FILE,"<headers/endian.h");
@convert=();
while(<FILE>) {
    # change machine specific bits/endian by streflop configuration
    if (/<bits\/endian\.h>/) {
        s,<bits/endian\.h>,\"../streflop_libm_bridge.h\",;
    #keep features.h, but locally
    } elsif (/<features\.h>/) {
        s,<features\.h>,"features.h",;
    } else {
    # commment out all other external includes
    s,(.*?#.*?include.*),//$1,;
    }
    #unconditional definition of endian things
    if (/defined _LIBC/) {
        $_ = "#if 1\n//".$_;
    }
    push @convert,$_;
}
close FILE;
open(FILE,">headers/endian.h");
print FILE $importNotice;
print FILE @convert;
close FILE;


# include the bridge from mpa.h
open(FILE,"<dbl-64/mpa.h");
$content="#include \"../streflop_libm_bridge.h\"\nnamespace streflop_libm {";
while(<FILE>) {
    # special case
    s/->d\(\)/->mantissa/g;
    $content.=$_;
}
close FILE;
$mpAccessor=
 "inline Double& d(int idx) {return mantissa[idx];}\n"
."inline const Double& d(int idx) const {return mantissa[idx];}\n";
# multi-line spanning regexp
$content =~ s/Double d\[(.*?)\].*?} mp_no/Double mantissa[$1];\n$mpAccessor} mp_no/sg;
open(FILE,">dbl-64/mpa.h");
print FILE $content."}\n"; # also close namespace
close FILE;

# Generate specific Makefiles
$parentMakefile="";
foreach $dir ("flt-32", "dbl-64", "ldbl-96") {
    @objFiles = glob("$dir/*.cpp");
    $parentObjects = "$dir-objects =";
    foreach $f (@objFiles) {
        $f =~ s/\.cpp$/.o/;
        $parentObjects .= " libm/$f";
        $f =~ s/^$dir\///;
    }
    open(FILE, ">$dir/Makefile");
    my $DIR = uc($dir);
    $DIR =~ s/\-//;
    print FILE "# Makefile automatically generated by import.pl\n"
              ."include ../../Makefile.common\n"
              ."CPPFLAGS += -I../headers -DLIBM_COMPILING_$DIR=1\n"
              ."all: @objFiles\n"
              ."\techo '$dir done!'\n";
    close FILE;
    $parentMakefile .= $parentObjects."\n\n";
}

# generate Makefile rule in parent directory
@projectFiles = glob("flt-32/* dbl-64/* ldbl-96/* headers/*");
foreach $f (@projectFiles) {$f = " libm/$f";}
open(FILE, ">../Makefile.libm_objects");
print FILE "# Makefile automatically generated by libm/import.pl. Do not edit.\n\n"
            .$parentMakefile
            ."\nlibm-src =";
print FILE @projectFiles;
print FILE "\n";
close FILE;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -