github.com/tinygo-org/tinygo@v0.31.3-0.20240404173401-90b0bf646c27/builder/builtins.go (about)

     1  package builder
     2  
     3  import (
     4  	"os"
     5  	"path/filepath"
     6  	"strings"
     7  
     8  	"github.com/tinygo-org/tinygo/goenv"
     9  )
    10  
    11  // These are the GENERIC_SOURCES according to CMakeList.txt.
    12  var genericBuiltins = []string{
    13  	"absvdi2.c",
    14  	"absvsi2.c",
    15  	"absvti2.c",
    16  	"adddf3.c",
    17  	"addsf3.c",
    18  	"addtf3.c",
    19  	"addvdi3.c",
    20  	"addvsi3.c",
    21  	"addvti3.c",
    22  	"apple_versioning.c",
    23  	"ashldi3.c",
    24  	"ashlti3.c",
    25  	"ashrdi3.c",
    26  	"ashrti3.c",
    27  	"bswapdi2.c",
    28  	"bswapsi2.c",
    29  	"clzdi2.c",
    30  	"clzsi2.c",
    31  	"clzti2.c",
    32  	"cmpdi2.c",
    33  	"cmpti2.c",
    34  	"comparedf2.c",
    35  	"comparesf2.c",
    36  	"ctzdi2.c",
    37  	"ctzsi2.c",
    38  	"ctzti2.c",
    39  	"divdc3.c",
    40  	"divdf3.c",
    41  	"divdi3.c",
    42  	"divmoddi4.c",
    43  	"divsc3.c",
    44  	"divsf3.c",
    45  	"divsi3.c",
    46  	"divtc3.c",
    47  	"divti3.c",
    48  	"divtf3.c",
    49  	"extendsfdf2.c",
    50  	"extendhfsf2.c",
    51  	"ffsdi2.c",
    52  	"ffssi2.c",
    53  	"ffsti2.c",
    54  	"fixdfdi.c",
    55  	"fixdfsi.c",
    56  	"fixdfti.c",
    57  	"fixsfdi.c",
    58  	"fixsfsi.c",
    59  	"fixsfti.c",
    60  	"fixunsdfdi.c",
    61  	"fixunsdfsi.c",
    62  	"fixunsdfti.c",
    63  	"fixunssfdi.c",
    64  	"fixunssfsi.c",
    65  	"fixunssfti.c",
    66  	"floatdidf.c",
    67  	"floatdisf.c",
    68  	"floatsidf.c",
    69  	"floatsisf.c",
    70  	"floattidf.c",
    71  	"floattisf.c",
    72  	"floatundidf.c",
    73  	"floatundisf.c",
    74  	"floatunsidf.c",
    75  	"floatunsisf.c",
    76  	"floatuntidf.c",
    77  	"floatuntisf.c",
    78  	"fp_mode.c",
    79  	//"int_util.c",
    80  	"lshrdi3.c",
    81  	"lshrti3.c",
    82  	"moddi3.c",
    83  	"modsi3.c",
    84  	"modti3.c",
    85  	"muldc3.c",
    86  	"muldf3.c",
    87  	"muldi3.c",
    88  	"mulodi4.c",
    89  	"mulosi4.c",
    90  	"muloti4.c",
    91  	"mulsc3.c",
    92  	"mulsf3.c",
    93  	"multi3.c",
    94  	"multf3.c",
    95  	"mulvdi3.c",
    96  	"mulvsi3.c",
    97  	"mulvti3.c",
    98  	"negdf2.c",
    99  	"negdi2.c",
   100  	"negsf2.c",
   101  	"negti2.c",
   102  	"negvdi2.c",
   103  	"negvsi2.c",
   104  	"negvti2.c",
   105  	"os_version_check.c",
   106  	"paritydi2.c",
   107  	"paritysi2.c",
   108  	"parityti2.c",
   109  	"popcountdi2.c",
   110  	"popcountsi2.c",
   111  	"popcountti2.c",
   112  	"powidf2.c",
   113  	"powisf2.c",
   114  	"powitf2.c",
   115  	"subdf3.c",
   116  	"subsf3.c",
   117  	"subvdi3.c",
   118  	"subvsi3.c",
   119  	"subvti3.c",
   120  	"subtf3.c",
   121  	"trampoline_setup.c",
   122  	"truncdfhf2.c",
   123  	"truncdfsf2.c",
   124  	"truncsfhf2.c",
   125  	"ucmpdi2.c",
   126  	"ucmpti2.c",
   127  	"udivdi3.c",
   128  	"udivmoddi4.c",
   129  	"udivmodti4.c",
   130  	"udivsi3.c",
   131  	"udivti3.c",
   132  	"umoddi3.c",
   133  	"umodsi3.c",
   134  	"umodti3.c",
   135  }
   136  
   137  var aeabiBuiltins = []string{
   138  	"arm/aeabi_cdcmp.S",
   139  	"arm/aeabi_cdcmpeq_check_nan.c",
   140  	"arm/aeabi_cfcmp.S",
   141  	"arm/aeabi_cfcmpeq_check_nan.c",
   142  	"arm/aeabi_dcmp.S",
   143  	"arm/aeabi_div0.c",
   144  	"arm/aeabi_drsub.c",
   145  	"arm/aeabi_fcmp.S",
   146  	"arm/aeabi_frsub.c",
   147  	"arm/aeabi_idivmod.S",
   148  	"arm/aeabi_ldivmod.S",
   149  	"arm/aeabi_memcmp.S",
   150  	"arm/aeabi_memcpy.S",
   151  	"arm/aeabi_memmove.S",
   152  	"arm/aeabi_memset.S",
   153  	"arm/aeabi_uidivmod.S",
   154  	"arm/aeabi_uldivmod.S",
   155  
   156  	// These two are not technically EABI builtins but are used by them and only
   157  	// seem to be used on ARM. LLVM seems to use __divsi3 and __modsi3 on most
   158  	// other architectures.
   159  	// Most importantly, they have a different calling convention on AVR so
   160  	// should not be used on AVR.
   161  	"divmodsi4.c",
   162  	"udivmodsi4.c",
   163  }
   164  
   165  var avrBuiltins = []string{
   166  	"avr/divmodhi4.S",
   167  	"avr/divmodqi4.S",
   168  	"avr/mulhi3.S",
   169  	"avr/mulqi3.S",
   170  	"avr/udivmodhi4.S",
   171  	"avr/udivmodqi4.S",
   172  }
   173  
   174  // CompilerRT is a library with symbols required by programs compiled with LLVM.
   175  // These symbols are for operations that cannot be emitted with a single
   176  // instruction or a short sequence of instructions for that target.
   177  //
   178  // For more information, see: https://compiler-rt.llvm.org/
   179  var CompilerRT = Library{
   180  	name: "compiler-rt",
   181  	cflags: func(target, headerPath string) []string {
   182  		return []string{"-Werror", "-Wall", "-std=c11", "-nostdlibinc"}
   183  	},
   184  	sourceDir: func() string {
   185  		llvmDir := filepath.Join(goenv.Get("TINYGOROOT"), "llvm-project/compiler-rt/lib/builtins")
   186  		if _, err := os.Stat(llvmDir); err == nil {
   187  			// Release build.
   188  			return llvmDir
   189  		}
   190  		// Development build.
   191  		return filepath.Join(goenv.Get("TINYGOROOT"), "lib/compiler-rt-builtins")
   192  	},
   193  	librarySources: func(target string) ([]string, error) {
   194  		builtins := append([]string{}, genericBuiltins...) // copy genericBuiltins
   195  		if strings.HasPrefix(target, "arm") || strings.HasPrefix(target, "thumb") {
   196  			builtins = append(builtins, aeabiBuiltins...)
   197  		}
   198  		if strings.HasPrefix(target, "avr") {
   199  			builtins = append(builtins, avrBuiltins...)
   200  		}
   201  		return builtins, nil
   202  	},
   203  }