diff options
Diffstat (limited to 'macros/CCodeGeneration')
-rw-r--r-- | macros/CCodeGeneration/C_FinalizeCode.bin | bin | 16292 -> 16292 bytes | |||
-rw-r--r-- | macros/CCodeGeneration/C_FinalizeCode.sci | 6 | ||||
-rw-r--r-- | macros/CCodeGeneration/C_Funcall.bin | bin | 71972 -> 73096 bytes | |||
-rw-r--r-- | macros/CCodeGeneration/C_Funcall.sci | 277 | ||||
-rw-r--r-- | macros/CCodeGeneration/C_GenerateFunName.bin | bin | 6736 -> 7776 bytes | |||
-rw-r--r-- | macros/CCodeGeneration/C_GenerateFunName.sci | 7 | ||||
-rw-r--r-- | macros/CCodeGeneration/C_GenerateMakefile.bin | bin | 27976 -> 28780 bytes | |||
-rw-r--r-- | macros/CCodeGeneration/C_GenerateMakefile.sci | 12 | ||||
-rw-r--r-- | macros/CCodeGeneration/C_Type.bin | bin | 5232 -> 5564 bytes | |||
-rw-r--r-- | macros/CCodeGeneration/C_Type.sci | 4 | ||||
-rw-r--r-- | macros/CCodeGeneration/JoinDeclarAndCcode.bin | bin | 22604 -> 22776 bytes | |||
-rw-r--r-- | macros/CCodeGeneration/JoinDeclarAndCcode.sci | 6 |
12 files changed, 166 insertions, 146 deletions
diff --git a/macros/CCodeGeneration/C_FinalizeCode.bin b/macros/CCodeGeneration/C_FinalizeCode.bin Binary files differindex 44c534e..499d63a 100644 --- a/macros/CCodeGeneration/C_FinalizeCode.bin +++ b/macros/CCodeGeneration/C_FinalizeCode.bin diff --git a/macros/CCodeGeneration/C_FinalizeCode.sci b/macros/CCodeGeneration/C_FinalizeCode.sci index 1f3c6b5..d1fc7e6 100644 --- a/macros/CCodeGeneration/C_FinalizeCode.sci +++ b/macros/CCodeGeneration/C_FinalizeCode.sci @@ -76,10 +76,10 @@ PrintStringInfo('#include ""'+tmphdrname+tmphdrext+'""',... //If current file is main C file, include header files corresponding to ODE //functions, if any. if(SharedInfo.NextSCIFunName == SharedInfo.SCIMainFunName) - if(size(SharedInfo.ODElist) <> 0) //check if list is empty + if(size(SharedInfo.Includelist) <> 0) //check if list is empty //If not empty, add those header files here. - for cntlist = 1:size(SharedInfo.ODElist) - PrintStringInfo('#include ""'+SharedInfo.ODElist(cntlist)+'.h""',... + for cntlist = 1:size(SharedInfo.Includelist) + PrintStringInfo('#include ""'+SharedInfo.Includelist(cntlist)+'.h""',... FinalCFileName,'file','y'); end diff --git a/macros/CCodeGeneration/C_Funcall.bin b/macros/CCodeGeneration/C_Funcall.bin Binary files differindex 23b9e6f..fdfb38d 100644 --- a/macros/CCodeGeneration/C_Funcall.bin +++ b/macros/CCodeGeneration/C_Funcall.bin diff --git a/macros/CCodeGeneration/C_Funcall.sci b/macros/CCodeGeneration/C_Funcall.sci index 22a2770..248b826 100644 --- a/macros/CCodeGeneration/C_Funcall.sci +++ b/macros/CCodeGeneration/C_Funcall.sci @@ -174,85 +174,52 @@ end // --- Generate the C call. --- // ---------------------------- CCall =''; -if (FunInfo.CFunctionName == SharedInfo.CMainFunName) - if (FlagCall == 1) - error(9999, 'main function called in a source code!'); - else - CCall =CCall+'int '; - end -elseif (mtlb_strcmp(part(CFunName,1:5),'odefn') == %T) - //Return type of function containing ODEs must be int. - CCall = CCall + 'int '; -else - if (PosFirstOutScalar >= 1) +if(mtlb_strcmp(part(CFunName,1:9),'PI_thread') == %T) +//Functions that are to be ru in separate thread in case of RPi target, +//need to have specific name which is PI_THREAD(functionname) + +CCall = CCall + 'PI_THREAD('+CFunName+')' +else + + if (FunInfo.CFunctionName == SharedInfo.CMainFunName) if (FlagCall == 1) - CCall = CCall+OutArg(PosFirstOutScalar).Name+' = '; + error(9999, 'main function called in a source code!'); else - CCall = CCall+C_Type(OutArg(PosFirstOutScalar).Type)+' '; + CCall =CCall+'int '; end + elseif ((mtlb_strcmp(part(CFunName,1:5),'odefn') == %T)) + //Return type of function containing ODEs must be int. + CCall = CCall + 'int '; else - if (FlagCall == 0) - CCall = CCall+'void '; + if (PosFirstOutScalar >= 1) + if (FlagCall == 1) + CCall = CCall+OutArg(PosFirstOutScalar).Name+' = '; + else + CCall = CCall+C_Type(OutArg(PosFirstOutScalar).Type)+' '; + end + else + if (FlagCall == 0) + CCall = CCall+'void '; + end end end -end - -// FIXME : Wrap library function call with prefixed name -//if CFunName == "main" - CCall = CCall + CFunName + "("; -//else -// CCall = CCall+"SCI2C("+CFunName+")("; -//end + // FIXME : Wrap library function call with prefixed name -// #RNU_RES_B -PrintStringInfo(' C call after output scalar args check: '+CCall,ReportFileName,'file','y'); -// #RNU_RES_E -clear counterin -if(mtlb_strcmp(part(CFunName,1:5),'odefn') == %F) - for counterin = 1:NInArg - - if (InArg(counterin).Type == 'g' & InArg(counterin).Scope == 'String') - TmpInArgName = '""'+InArg(counterin).Name+'""'; - elseif (InArg(counterin).Type == 'z' & (InArg(counterin).Scope == 'Number')) - TmpInArgName = 'DoubleComplex('+SCI2Cstring(real(InArg(counterin).Value))+','+SCI2Cstring(imag(InArg(counterin).Value))+')'; - elseif (InArg(counterin).Type == 'c' & (InArg(counterin).Scope == 'Number')) - TmpInArgName = 'FloatComplex('+SCI2Cstring(real(InArg(counterin).Value))+','+SCI2Cstring(imag(InArg(counterin).Value))+')'; - else - TmpInArgName = InArg(counterin).Name; - end - - TmpInArgType = C_Type(InArg(counterin).Type); + //if CFunName == "main" + CCall = CCall + CFunName + "("; + //else + // CCall = CCall+"SCI2C("+CFunName+")("; + //end - //if (FunctionName == 'OpEqual') - // TmpInArgSizeVar = '__'+OutArg(counterin).Name+'Size'; - // else - TmpInArgSizeVar = '__'+InArg(counterin).Name+'Size'; - //end + // #RNU_RES_B + PrintStringInfo(' C call after output scalar args check: '+CCall,ReportFileName,'file','y'); + // #RNU_RES_E + clear counterin + if(mtlb_strcmp(part(CFunName,1:5),'odefn') == %F) + for counterin = 1:NInArg - if (InArg(counterin).Dimension == 0) - if (FlagCall == 0) - CCall = CCall+TmpInArgType+' '; - end - CCall = CCall+TmpInArgName+','; - else - if (FlagCall == 0) - CCall = CCall+TmpInArgType+'* '+TmpInArgName+', int* __'+TmpInArgName+'Size,'; - else - CCall = CCall+TmpInArgName+', '+TmpInArgSizeVar+','; - end - end - end -else - //If current function contains 'odefn' at the beginning, then it contains - //differnetial equations and its function call need to be differnt than - //other function call. GSL library being used for solving ODEs, requires - //function containing odes in specific format which is differnt than generated - //above. - for counterin = 1:NInArg - - //if((NInArg == 4 & counterin <> 3) | (NInArg == 5 & counterin <> 4)) //Skip third argument if (InArg(counterin).Type == 'g' & InArg(counterin).Scope == 'String') TmpInArgName = '""'+InArg(counterin).Name+'""'; elseif (InArg(counterin).Type == 'z' & (InArg(counterin).Scope == 'Number')) @@ -278,93 +245,135 @@ else CCall = CCall+TmpInArgName+','; else if (FlagCall == 0) - CCall = CCall+TmpInArgType+'* '+TmpInArgName+', ';//int* __'+TmpInArgName+'Size,'; + CCall = CCall+TmpInArgType+'* '+TmpInArgName+', int* __'+TmpInArgName+'Size,'; else - CCall = CCall+TmpInArgName+', ';//+TmpInArgSizeVar+','; + CCall = CCall+TmpInArgName+', '+TmpInArgSizeVar+','; end end - //end - end - -end - -// #RNU_RES_B -PrintStringInfo(' C call after input args analysis: '+CCall,ReportFileName,'file','y'); -// #RNU_RES_E -for counterout = 1:NOutArg - TmpOutArgName = OutArg(counterout).Name; - TmpOutArgType = C_Type(OutArg(counterout).Type); - if (counterout == PosFirstOutScalar) - if (FlagCall == 0) - // #RNU_RES_B - // --- Write in the declaration file the returned output scalar (if any). --- - // #RNU_RES_E - outscalardeclaration = TmpOutArgType+' '+TmpOutArgName+';'; - // #RNU_RES_B - PrintStringInfo(outscalardeclaration,ReportFileName,'file','y'); - // #RNU_RES_E - PrintStringInfo(C_IndentBlanks(1)+outscalardeclaration,CDeclarationFileName,'file','y'); - PrintStringInfo(' ',CDeclarationFileName,'file','y'); end else - if (OutArg(counterout).Dimension == 0) + //If current function contains 'odefn' at the beginning, then it contains + //differnetial equations and its function call need to be differnt than + //other function call. GSL library being used for solving ODEs, requires + //function containing odes in specific format which is differnt than generated + //above. + for counterin = 1:NInArg + + //if((NInArg == 4 & counterin <> 3) | (NInArg == 5 & counterin <> 4)) //Skip third argument + if (InArg(counterin).Type == 'g' & InArg(counterin).Scope == 'String') + TmpInArgName = '""'+InArg(counterin).Name+'""'; + elseif (InArg(counterin).Type == 'z' & (InArg(counterin).Scope == 'Number')) + TmpInArgName = 'DoubleComplex('+SCI2Cstring(real(InArg(counterin).Value))+','+SCI2Cstring(imag(InArg(counterin).Value))+')'; + elseif (InArg(counterin).Type == 'c' & (InArg(counterin).Scope == 'Number')) + TmpInArgName = 'FloatComplex('+SCI2Cstring(real(InArg(counterin).Value))+','+SCI2Cstring(imag(InArg(counterin).Value))+')'; + else + TmpInArgName = InArg(counterin).Name; + end + + TmpInArgType = C_Type(InArg(counterin).Type); + + //if (FunctionName == 'OpEqual') + // TmpInArgSizeVar = '__'+OutArg(counterin).Name+'Size'; + // else + TmpInArgSizeVar = '__'+InArg(counterin).Name+'Size'; + //end + + if (InArg(counterin).Dimension == 0) + if (FlagCall == 0) + CCall = CCall+TmpInArgType+' '; + end + CCall = CCall+TmpInArgName+','; + else + if (FlagCall == 0) + CCall = CCall+TmpInArgType+'* '+TmpInArgName+', ';//int* __'+TmpInArgName+'Size,'; + else + CCall = CCall+TmpInArgName+', ';//+TmpInArgSizeVar+','; + end + end + //end + end + + end + + // #RNU_RES_B + PrintStringInfo(' C call after input args analysis: '+CCall,ReportFileName,'file','y'); + // #RNU_RES_E + for counterout = 1:NOutArg + TmpOutArgName = OutArg(counterout).Name; + TmpOutArgType = C_Type(OutArg(counterout).Type); + if (counterout == PosFirstOutScalar) if (FlagCall == 0) + // #RNU_RES_B // --- Write in the declaration file the returned output scalar (if any). --- + // #RNU_RES_E outscalardeclaration = TmpOutArgType+' '+TmpOutArgName+';'; + // #RNU_RES_B PrintStringInfo(outscalardeclaration,ReportFileName,'file','y'); + // #RNU_RES_E PrintStringInfo(C_IndentBlanks(1)+outscalardeclaration,CDeclarationFileName,'file','y'); PrintStringInfo(' ',CDeclarationFileName,'file','y'); - CCall = CCall+TmpOutArgType+'* __ptr'+TmpOutArgName+', '; - else - CCall = CCall+'&'+TmpOutArgName+', ';//NUT: verifica se ci vuole l'& end else - if (FlagCall == 0) - CCall = CCall+TmpOutArgType+'* '+TmpOutArgName+','; - if (OutArg(counterout).FindLike == 1) - CCall = CCall+'int* __'+TmpOutArgName+'Size'+','; + if (OutArg(counterout).Dimension == 0) + if (FlagCall == 0) + // --- Write in the declaration file the returned output scalar (if any). --- + outscalardeclaration = TmpOutArgType+' '+TmpOutArgName+';'; + PrintStringInfo(outscalardeclaration,ReportFileName,'file','y'); + PrintStringInfo(C_IndentBlanks(1)+outscalardeclaration,CDeclarationFileName,'file','y'); + PrintStringInfo(' ',CDeclarationFileName,'file','y'); + CCall = CCall+TmpOutArgType+'* __ptr'+TmpOutArgName+', '; + else + CCall = CCall+'&'+TmpOutArgName+', ';//NUT: verifica se ci vuole l'& end - // #RNU_RES_B - //NUT prova a sostituire le variabili strutture con variabili dichiarate all'inizio del codice. - // --- Declare the size of the output arguments. --- - // #RNU_RES_E - outscalardeclaration = 'int __'+TmpOutArgName+'Size[2];'; - PrintStringInfo(outscalardeclaration,ReportFileName,'file','y'); - PrintStringInfo(C_IndentBlanks(1)+outscalardeclaration,CDeclarationFileName,'file','y'); - outscalardeclaration = '__'+TmpOutArgName+'Size[0] = '+(OutArg(counterout).Size(1))+';'; - PrintStringInfo(outscalardeclaration,ReportFileName,'file','y'); - PrintStringInfo(C_IndentBlanks(1)+outscalardeclaration,CInitVarsFileName,'file','y'); - outscalardeclaration = '__'+TmpOutArgName+'Size[1] = '+(OutArg(counterout).Size(2))+';'; - PrintStringInfo(outscalardeclaration,ReportFileName,'file','y'); - PrintStringInfo(C_IndentBlanks(1)+outscalardeclaration,CInitVarsFileName,'file','y'); - PrintStringInfo(' ',CInitVarsFileName,'file','y'); else - CCall = CCall+OutArg(counterout).Name+','; - if (OutArg(counterout).FindLike == 1) - CCall = CCall+'(int* ) __'+TmpOutArgName+'Size'+','; + if (FlagCall == 0) + CCall = CCall+TmpOutArgType+'* '+TmpOutArgName+','; + if (OutArg(counterout).FindLike == 1) + CCall = CCall+'int* __'+TmpOutArgName+'Size'+','; + end + // #RNU_RES_B + //NUT prova a sostituire le variabili strutture con variabili dichiarate all'inizio del codice. + // --- Declare the size of the output arguments. --- + // #RNU_RES_E + outscalardeclaration = 'int __'+TmpOutArgName+'Size[2];'; + PrintStringInfo(outscalardeclaration,ReportFileName,'file','y'); + PrintStringInfo(C_IndentBlanks(1)+outscalardeclaration,CDeclarationFileName,'file','y'); + outscalardeclaration = '__'+TmpOutArgName+'Size[0] = '+(OutArg(counterout).Size(1))+';'; + PrintStringInfo(outscalardeclaration,ReportFileName,'file','y'); + PrintStringInfo(C_IndentBlanks(1)+outscalardeclaration,CInitVarsFileName,'file','y'); + outscalardeclaration = '__'+TmpOutArgName+'Size[1] = '+(OutArg(counterout).Size(2))+';'; + PrintStringInfo(outscalardeclaration,ReportFileName,'file','y'); + PrintStringInfo(C_IndentBlanks(1)+outscalardeclaration,CInitVarsFileName,'file','y'); + PrintStringInfo(' ',CInitVarsFileName,'file','y'); + else + CCall = CCall+OutArg(counterout).Name+','; + if (OutArg(counterout).FindLike == 1) + CCall = CCall+'(int* ) __'+TmpOutArgName+'Size'+','; + end end end end end -end -PrintStringInfo(' C call after output args analysis: '+CCall,ReportFileName,'file','y'); -// Remove the last " " and "," -if (part(CCall,length(CCall):length(CCall)) == ' ') - CCall = part(CCall,1:length(CCall)-1); -end -if (part(CCall,length(CCall):length(CCall)) == ',') - CCall = part(CCall,1:length(CCall)-1); -end + PrintStringInfo(' C call after output args analysis: '+CCall,ReportFileName,'file','y'); + // Remove the last " " and "," + if (part(CCall,length(CCall):length(CCall)) == ' ') + CCall = part(CCall,1:length(CCall)-1); + end + if (part(CCall,length(CCall):length(CCall)) == ',') + CCall = part(CCall,1:length(CCall)-1); + end -//__ysize is added to input arguments at last to comply with form required by GSL -if(mtlb_strcmp(part(CFunName,1:5),'odefn') == %T) - CCall = CCall + ', int* '+TmpInArgSizeVar; -end + //__ysize is added to input arguments at last to comply with form required by GSL + if(mtlb_strcmp(part(CFunName,1:5),'odefn') == %T) + CCall = CCall + ', int* '+TmpInArgSizeVar; + end -CCall = CCall+')'; -if (FlagCall == 1) - CCall = CCall+';'; -end + CCall = CCall+')'; + if (FlagCall == 1) + CCall = CCall+';'; + end + +end //NUT: la parte di generazione della C call va inserita in una funzione a parte. //NUT: tale funzione deve avere anche uno switch che consenta di generare differenti versioni //NUT: delle chiamate C in accordo con la libreria disponibile, fermo restando che diff --git a/macros/CCodeGeneration/C_GenerateFunName.bin b/macros/CCodeGeneration/C_GenerateFunName.bin Binary files differindex 8486a3b..1b723f1 100644 --- a/macros/CCodeGeneration/C_GenerateFunName.bin +++ b/macros/CCodeGeneration/C_GenerateFunName.bin diff --git a/macros/CCodeGeneration/C_GenerateFunName.sci b/macros/CCodeGeneration/C_GenerateFunName.sci index d87fb9c..a1373de 100644 --- a/macros/CCodeGeneration/C_GenerateFunName.sci +++ b/macros/CCodeGeneration/C_GenerateFunName.sci @@ -24,10 +24,13 @@ function CFunName = C_GenerateFunName(FunctionName,InArg,NInArg,OutArg,NOutArg) SCI2CNInArgCheck(argn(2),5,5); CFunName = ''; if((IsAVRSupportFunction(FunctionName)) | (IsRPISupportFunction(FunctionName)) | ... - (mtlb_strcmp(part(FunctionName,1:5),'odefn') == %T)) + (mtlb_strcmp(part(FunctionName,1:5),'odefn') == %T) |... + (mtlb_strcmp(part(FunctionName,1:9),'PI_thread') == %T)| ... + (mtlb_strcmp(part(FunctionName,1:4),'ISR_') == %T)) //If current function is an AVR or RPi function, then function name can be just //plain function name without any input/output arguments types - +//Slimilarly for functions conataining ode functions and functions to be called in +//separate thread in RPi CFunName = CFunName+FunctionName; else diff --git a/macros/CCodeGeneration/C_GenerateMakefile.bin b/macros/CCodeGeneration/C_GenerateMakefile.bin Binary files differindex 4b3546e..5a095f4 100644 --- a/macros/CCodeGeneration/C_GenerateMakefile.bin +++ b/macros/CCodeGeneration/C_GenerateMakefile.bin diff --git a/macros/CCodeGeneration/C_GenerateMakefile.sci b/macros/CCodeGeneration/C_GenerateMakefile.sci index b1c1e71..29e8a08 100644 --- a/macros/CCodeGeneration/C_GenerateMakefile.sci +++ b/macros/CCodeGeneration/C_GenerateMakefile.sci @@ -70,14 +70,16 @@ else end PrintStringInfo('CFLAGS = -Wall -pedantic -g -I $(HSRCDIR) -I $(ISRCDIR) -L $(LIBDIR)',FileInfo.MakefileFilename,'file','y','y'); if (target == 'RPi') - PrintStringInfo('LDFLAGS = -llapack -lrefblas -lgfortran -lm -lbcm2835',FileInfo.MakefileFilename,'file','y','y'); + PrintStringInfo('LDFLAGS = -llapack -lrefblas -lgfortran -lm -lwiringPi',FileInfo.MakefileFilename,'file','y','y'); else PrintStringInfo('LDFLAGS = -lblas -llapack -lm ',FileInfo.MakefileFilename,'file','y','y'); end end //If ode function is used, add libgsl. -if(size(SharedInfo.ODElist) <> 0) +if(size(SharedInfo.Includelist) <> 0) + if((mtlb_strcmp(part(SharedInfo.Includelist(1),1:5),'odefn') == %T)) PrintStringInfo('LDFLAGS += -lgsl',FileInfo.MakefileFilename,'file','y','y'); + end end // Binary definition @@ -95,8 +97,10 @@ for i = 1:(nbSources(1) - 1) [tmppath,tmpfile,tmpext] = fileparts(allSources(i)); if(~isempty(strstr(allSources(i),'ode'))) - if(size(SharedInfo.ODElist) <> 0) - PrintStringInfo(' $(CSRCDIR)/'+tmpfile+tmpext+' \\', FileInfo.MakefileFilename,'file','y','y'); + if(size(SharedInfo.Includelist) <> 0) + if((mtlb_strcmp(part(SharedInfo.Includelist(1),1:5),'odefn') == %T)) + PrintStringInfo(' $(CSRCDIR)/'+tmpfile+tmpext+' \\', FileInfo.MakefileFilename,'file','y','y'); + end end else PrintStringInfo(' $(CSRCDIR)/'+tmpfile+tmpext+' \\', FileInfo.MakefileFilename,'file','y','y'); diff --git a/macros/CCodeGeneration/C_Type.bin b/macros/CCodeGeneration/C_Type.bin Binary files differindex 18e0a1b..f9bad33 100644 --- a/macros/CCodeGeneration/C_Type.bin +++ b/macros/CCodeGeneration/C_Type.bin diff --git a/macros/CCodeGeneration/C_Type.sci b/macros/CCodeGeneration/C_Type.sci index 6e9a295..3c56b71 100644 --- a/macros/CCodeGeneration/C_Type.sci +++ b/macros/CCodeGeneration/C_Type.sci @@ -43,6 +43,10 @@ elseif (ArgType == 'u16') OutC_Type = 'uint16'; elseif (ArgType == 'i16') OutC_Type = 'int16'; +elseif (ArgType == 'u32') + OutC_Type = 'uint32'; +elseif (ArgType == 'i32') + OutC_Type = 'int32'; elseif (ArgType == 'fn') //This type introduced for ODE function, // as it's one of the inout argument is name of the other function OutC_Type = ''; diff --git a/macros/CCodeGeneration/JoinDeclarAndCcode.bin b/macros/CCodeGeneration/JoinDeclarAndCcode.bin Binary files differindex a818143..084ab08 100644 --- a/macros/CCodeGeneration/JoinDeclarAndCcode.bin +++ b/macros/CCodeGeneration/JoinDeclarAndCcode.bin diff --git a/macros/CCodeGeneration/JoinDeclarAndCcode.sci b/macros/CCodeGeneration/JoinDeclarAndCcode.sci index 4328895..2c69f46 100644 --- a/macros/CCodeGeneration/JoinDeclarAndCcode.sci +++ b/macros/CCodeGeneration/JoinDeclarAndCcode.sci @@ -146,9 +146,9 @@ PrintStringInfo('** --- C code. ---',CPass2FileName,'file','y'); PrintStringInfo('** ---------------',CPass2FileName,'file','y'); PrintStringInfo('*/',CPass2FileName,'file','y'); -if(SharedInfo.Target == "RPi") - //Add bcm2835_init() function as it is required - PrintStringInfo('bcm2835_init();',CPass2FileName,'file','y'); +if((SharedInfo.Target == "RPi") & (nxtscifunname == SharedInfo.SCIMainFunName)) + //Add wiringPiSetup() function as it is required + PrintStringInfo('wiringPiSetup();',CPass2FileName,'file','y'); end // --- Copy the remaining part of V1 in V2. --- while (~meof(CPass1V1FileFid)) |