@@ -38,7 +38,8 @@ import { BuilderOptions, ProjectConfigData, ProjectConfiguration } from "./EIDET
3838import {
3939 ArmBaseCompileData ,
4040 Memory , ARMStorageLayout ,
41- FloatingHardwareOption , C51BaseCompileData , RiscvCompileData , AnyGccCompileData , MipsCompileData
41+ FloatingHardwareOption , C51BaseCompileData , RiscvCompileData , AnyGccCompileData , MipsCompileData ,
42+ getRamRomName
4243} from './EIDEProjectModules' ;
4344import { SettingManager } from "./SettingManager" ;
4445import { GlobalEvent } from "./GlobalEvents" ;
@@ -561,12 +562,18 @@ interface MemorySize {
561562interface RomItem {
562563 memInfo : Memory ;
563564 selected : boolean ;
565+ name : string ;
566+ roFiles : string [ ] ;
564567}
565568
566569interface RamItem {
567570 memInfo : Memory ;
568571 selected : boolean ;
569572 noInit : boolean ;
573+ name : string ;
574+ roFiles : string [ ] ;
575+ rwFiles : string [ ] ;
576+ ziFiles : string [ ] ;
570577}
571578
572579interface MemoryScatter {
@@ -601,15 +608,21 @@ export class ARMCodeBuilder extends CodeBuilder {
601608 startAddr : '0x00000000' ,
602609 size : '0x00000000'
603610 } ,
604- selected : false
611+ selected : false ,
612+ name : '' ,
613+ roFiles : [ ] ,
605614 } ) ;
606615 memScatter . ramList . push ( {
607616 memInfo : {
608617 startAddr : '0x00000000' ,
609618 size : '0x00000000'
610619 } ,
611620 selected : false ,
612- noInit : false
621+ noInit : false ,
622+ name : '' ,
623+ roFiles : [ ] ,
624+ ziFiles : [ ] ,
625+ rwFiles : [ ]
613626 } ) ;
614627 }
615628
@@ -653,6 +666,7 @@ export class ARMCodeBuilder extends CodeBuilder {
653666 memScatter . ramList [ index ] . memInfo . size = this . FillHexNumber ( storageLayout . RAM [ i ] . mem . size ) ;
654667 memScatter . ramList [ index ] . selected = storageLayout . RAM [ i ] . isChecked ;
655668 memScatter . ramList [ index ] . noInit = storageLayout . RAM [ i ] . noInit ;
669+ memScatter . ramList [ index ] . name = getRamRomName ( storageLayout . RAM [ i ] ) ;
656670 }
657671
658672 for ( let i = 0 ; i < storageLayout . ROM . length ; i ++ ) {
@@ -672,6 +686,7 @@ export class ARMCodeBuilder extends CodeBuilder {
672686 memScatter . romList [ index ] . memInfo . startAddr = this . FillHexNumber ( storageLayout . ROM [ i ] . mem . startAddr ) ;
673687 memScatter . romList [ index ] . memInfo . size = this . FillHexNumber ( storageLayout . ROM [ i ] . mem . size ) ;
674688 memScatter . romList [ index ] . selected = storageLayout . ROM [ i ] . isChecked ;
689+ memScatter . romList [ index ] . name = getRamRomName ( storageLayout . ROM [ i ] ) ;
675690 memScatter . startUpIndex = storageLayout . ROM [ i ] . isStartup ? index : memScatter . startUpIndex ;
676691 }
677692
@@ -723,30 +738,115 @@ export class ARMCodeBuilder extends CodeBuilder {
723738 child : [ ]
724739 } ) ;
725740
741+ // Extra memory assign.
742+ const assignFileToMemory = ( fileName : string , memoryName : string , memoryList : RomItem [ ] | RamItem [ ] , attr : string ) => {
743+ memoryList . forEach ( ( item ) => {
744+ if ( item . name === memoryName && attr === 'RO' ) {
745+ item . roFiles . push ( fileName ) ;
746+ return ;
747+ }
748+
749+ if ( item . name === memoryName && attr === 'RW' ) {
750+ ( item as RamItem ) . rwFiles . push ( fileName ) ;
751+ return ;
752+ }
753+
754+ if ( item . name === memoryName && attr === 'ZI' ) {
755+ ( item as RamItem ) . ziFiles . push ( fileName ) ;
756+ return ;
757+ }
758+ } ) ;
759+ }
760+
761+ const options = this . project . getSourceExtraArgsCfg ( ) ;
762+ if ( options && options . memoryAssign ) {
763+ const memoryAssign = options . memoryAssign ;
764+ Object . keys ( memoryAssign ) . forEach ( ( key ) => {
765+ const fileName = NodePath . basename ( key ) . replace ( / \. [ ^ / . ] + $ / , '.o' ) ;
766+ const item = memoryAssign [ key ] ;
767+ if ( item . RO ) {
768+ assignFileToMemory ( fileName , item . RO , memScatter . romList , 'RO' ) ;
769+ assignFileToMemory ( fileName , item . RO , memScatter . ramList , 'RO' ) ;
770+ }
771+ if ( item . RW ) {
772+ assignFileToMemory ( fileName , item . RW , memScatter . ramList , 'RW' ) ;
773+ }
774+ if ( item . ZI ) {
775+ assignFileToMemory ( fileName , item . ZI , memScatter . ramList , 'ZI' ) ;
776+ }
777+ } ) ;
778+ }
779+
780+ const InsertFileToScatter = ( fileName : string , content : string , attr : string ) : string => {
781+ if ( content . search ( fileName ) === - 1 ) {
782+ content += `${ fileName } (+${ attr } ) \r\n` ;
783+ } else {
784+ // Insert the attribute only. e.g. "file.o (+RO)" => "file.o (+RO +RW)"
785+ const regex = new RegExp ( `(${ fileName } \\(([^)]*)\\))` ) ;
786+ content = content . replace ( regex , ( match , p1 , p2 ) => {
787+ // Don't add the same attribute again
788+ if ( p2 . includes ( `+${ attr } ` ) ) return match ;
789+ return `${ fileName } (${ p2 } +${ attr } )` ;
790+ } ) ;
791+ }
792+
793+ return content ;
794+ }
726795 //RAM
727796 memScatter . ramList . forEach ( ( item , index ) => {
797+ let content = ''
798+ if ( item . roFiles . length > 0 ) {
799+ item . roFiles . forEach ( ( fileName ) => {
800+ content = InsertFileToScatter ( fileName , content , 'RO' ) ;
801+ } ) ;
802+ }
803+ if ( item . rwFiles . length > 0 ) {
804+ item . rwFiles . forEach ( ( fileName ) => {
805+ content = InsertFileToScatter ( fileName , content , 'RW' ) ;
806+ } ) ;
807+ }
808+ if ( item . ziFiles . length > 0 ) {
809+ item . ziFiles . forEach ( ( fileName ) => {
810+ content = InsertFileToScatter ( fileName , content , 'ZI' ) ;
811+ } ) ;
812+ }
728813 if ( item . selected ) {
814+ content += '.ANY (+RW +ZI) \r\n' ;
815+ }
816+
817+ if ( content !== '' ) {
729818 staUpTxt . child . push ( {
730819 name : getRamName ( index ) ,
731820 addr : ' ' + item . memInfo . startAddr + ( item . noInit ? ' UNINIT ' : ' ' ) + item . memInfo . size + ' ' ,
732- content : '.ANY (+RW +ZI) \r\n' ,
821+ content : content ,
733822 child : [ ]
734823 } ) ;
735824 }
736825 } ) ;
737826
738827 memTxt . push ( staUpTxt ) ;
739828
829+ //ROM
740830 memScatter . romList . forEach ( ( item , index ) => {
831+ let content = ''
832+ if ( item . roFiles . length > 0 ) {
833+ item . roFiles . forEach ( ( fileName ) => {
834+ content = InsertFileToScatter ( fileName , content , 'RO' ) ;
835+ } ) ;
836+ }
741837 if ( item . selected && index !== memScatter . startUpIndex ) {
838+ content += '.ANY (+RO) \r\n' ;
839+ }
840+
841+ if ( content !== '' ) {
742842 memTxt . push ( {
743843 name : getRomName ( index , false ) ,
744844 addr : ' ' + item . memInfo . startAddr + ' ' + item . memInfo . size + ' ' ,
745845 content : '' ,
746846 child : [ {
747847 name : getRomName ( index , true ) ,
748848 addr : ' ' + item . memInfo . startAddr + ' ' + item . memInfo . size + ' ' ,
749- content : '.ANY (+RO) \r\n' ,
849+ content : content ,
750850 child : [ ]
751851 } ]
752852 } ) ;
0 commit comments