@@ -37,6 +37,7 @@ import * as NodePath from 'path';
3737import { ArmBaseBuilderConfigData } from "./EIDEProjectModules" ;
3838import * as utility from "./utility" ;
3939import * as ArmCpuUtils from "./ArmCpuUtils" ;
40+ import * as os from "os" ;
4041
4142//! 名称应该是大写,但由于历史因素,其中 'Keil_C51' 大小写暂时无法更正(避免旧的项目出现问题)
4243export type ToolchainName =
@@ -2474,6 +2475,57 @@ class IARARM implements IToolchian {
24742475
24752476 readonly elfSuffix = '.elf' ;
24762477
2478+ readonly mcpuMap : { [ name : string ] : string } = {
2479+ "arm7ej-s" : "--cpu=ARM7EJ-S" ,
2480+ "arm7tdmi" : "--cpu=ARM7TDMI" ,
2481+ "arm720t" : "--cpu=ARM720T" ,
2482+ "arm7tdmi-s" : "--cpu=ARM7TDMI-S" ,
2483+ "arm9tdmi" : "--cpu=ARM9TDMI" ,
2484+ "arm920t" : "--cpu=ARM920T" ,
2485+ "arm922t" : "--cpu=ARM922T" ,
2486+ "arm9e-s" : "--cpu=ARM9E-S" ,
2487+ "arm926ej-s" : "--cpu=ARM926EJ-S" ,
2488+ "arm946e-s" : "--cpu=ARM946E-S" ,
2489+ "arm966e-s" : "--cpu=ARM966E-S" ,
2490+ "cortex-m0" : "--cpu=Cortex-M0" ,
2491+ "cortex-m0+" : "--cpu=Cortex-M0+" ,
2492+ "cortex-m3" : "--cpu=Cortex-M3" ,
2493+ "cortex-m4" : "--cpu=Cortex-M4 --fpu=None" ,
2494+ "cortex-m4-sp" : "--cpu=Cortex-M4 --fpu=VFPv4_sp" ,
2495+ "cortex-m7" : "--cpu=Cortex-M7 --fpu=None" ,
2496+ "cortex-m7-sp" : "--cpu=Cortex-M7 --fpu=VFPv5_sp" ,
2497+ "cortex-m7-dp" : "--cpu=Cortex-M7 --fpu=VFPv5_d16" ,
2498+ "sc000" : "--cpu=SC000" ,
2499+ "sc300" : "--cpu=SC300" ,
2500+ "cortex-m4f" : "--cpu=Cortex-M4F --fpu=None" ,
2501+ "cortex-m4f-sp" : "--cpu=Cortex-M4F --fpu=VFPv4_sp" ,
2502+ "cortex-m23" : "--cpu=Cortex-M23" ,
2503+ "cortex-m23.no_se" : "--cpu=Cortex-M23.no_se" ,
2504+ "cortex-m33" : "--cpu=Cortex-M33" ,
2505+ "cortex-m33.fp" : "--cpu=Cortex-M33.fp" ,
2506+ "cortex-m33.no_dsp" : "--cpu=Cortex-M33.no_dsp" ,
2507+ "cortex-m33.fp.no_dsp" : "--cpu=Cortex-M33.fp.no_dsp" ,
2508+ "cortex-m35p" : "--cpu=Cortex-M35P" ,
2509+ "cortex-m35p.fp" : "--cpu=Cortex-M35P.fp" ,
2510+ "cortex-m35p.no_dsp" : "--cpu=Cortex-M35P.no_dsp" ,
2511+ "cortex-m35p.fp.no_dsp" : "--cpu=Cortex-M35P.fp.no_dsp" ,
2512+ "cortex-r4" : "--cpu=Cortex-R4" ,
2513+ "cortex-r4f" : "--cpu=Cortex-R4F" ,
2514+ "cortex-r4.vfp" : "--cpu=Cortex-R4.vfp" ,
2515+ "cortex-r5" : "--cpu=Cortex-R5" ,
2516+ "cortex-r5f" : "--cpu=Cortex-R5F" ,
2517+ "cortex-r5.vfp" : "--cpu=Cortex-R5.vfp" ,
2518+ "cortex-r7" : "--cpu=Cortex-R7" ,
2519+ "cortex-r7f" : "--cpu=Cortex-R7F" ,
2520+ "cortex-r7.vfp" : "--cpu=Cortex-R7.vfp"
2521+ } ;
2522+
2523+ private randomPlaceholder : string ;
2524+
2525+ constructor ( ) {
2526+ this . randomPlaceholder = utility . generateRandomStr ( ) ;
2527+ }
2528+
24772529 newInstance ( ) : IToolchian {
24782530 return new IARARM ( ) ;
24792531 }
@@ -2517,7 +2569,64 @@ class IARARM implements IToolchian {
25172569 return SettingManager . GetInstance ( ) . getIarForArmDir ( ) ;
25182570 }
25192571
2572+ private getThumbOptionStr ( builderOpts : BuilderOptions ) : string {
2573+ if ( builderOpts . global && builderOpts . global [ 'arm-thumb-mode' ] === 'arm' )
2574+ return '--arm' ;
2575+ else
2576+ return '--thumb' ;
2577+ }
2578+
2579+ private getCompilerTargetArgs ( cpuName : string , fpuType : string , archExt : string , builderOpts : BuilderOptions ) : string [ ] {
2580+
2581+ let mcpu_id : string ;
2582+
2583+ cpuName = cpuName . toLowerCase ( ) ;
2584+ if ( fpuType == 'single' )
2585+ mcpu_id = cpuName + '-sp' ;
2586+ else if ( fpuType == 'double' )
2587+ mcpu_id = cpuName + '-dp' ;
2588+ else
2589+ mcpu_id = cpuName ;
2590+
2591+ if ( this . mcpuMap [ mcpu_id ] == undefined )
2592+ return [ ] ;
2593+
2594+ return [
2595+ this . mcpuMap [ mcpu_id ] , this . getThumbOptionStr ( builderOpts )
2596+ ] ;
2597+ }
2598+
25202599 getInternalDefines < T extends BuilderConfigData > ( builderCfg : T , builderOpts : BuilderOptions ) : utility . CppMacroDefine [ ] {
2600+ try {
2601+ const cfg : ArmBaseBuilderConfigData = < any > builderCfg ;
2602+ const cpuName = cfg . cpuType . toLowerCase ( ) ;
2603+ const fpuType = cfg . floatingPointHardware ;
2604+ const archExt = cfg . archExtensions || '' ;
2605+ const compilerArgs = this . getCompilerTargetArgs ( cpuName , fpuType , archExt , builderOpts ) ;
2606+ if ( compilerArgs . length > 0 ) {
2607+ // example:
2608+ // D:\IAR_ARM\arm\bin\iccarm.exe --cpu=Cortex-M3 --thumb --predef_macros "C:\Users\Administrator\Desktop\tmp.txt"
2609+ const tmpCfile = File . from ( os . tmpdir ( ) , `foo_${ this . randomPlaceholder } .c` ) ;
2610+ tmpCfile . Write ( 'int foo(int a) { return a * a; }' ) ;
2611+ const predefsfile = File . from ( os . tmpdir ( ) , `foo_${ this . randomPlaceholder } .defs` ) ;
2612+ const cmdArgs = compilerArgs . concat ( [ '--predef_macros' , predefsfile . path , tmpCfile . path ] ) ;
2613+ const iccarm = File . from ( this . getToolchainDir ( ) . path , 'bin' , `iccarm${ platform . exeSuffix ( ) } ` ) . path ;
2614+ child_process . execFileSync ( iccarm , cmdArgs , { cwd : tmpCfile . dir } ) ;
2615+ const outputs = predefsfile . Read ( ) . split ( / \r \n | \n / ) ;
2616+ const results : utility . CppMacroDefine [ ] = [ ] ;
2617+ outputs . filter ( ( line ) => { return line . trim ( ) !== '' ; } )
2618+ . forEach ( ( line ) => {
2619+ const value = utility . CppMacroParser . parse ( line ) ;
2620+ if ( value ) {
2621+ results . push ( value ) ;
2622+ }
2623+ } ) ;
2624+ return results ;
2625+ }
2626+ } catch ( error ) {
2627+ GlobalEvent . log_warn ( error ) ;
2628+ }
2629+
25212630 return [
25222631 { name : '__ICCARM__' , value : '1' , type : 'var' } ,
25232632 ] ;
0 commit comments