summaryrefslogtreecommitdiff
path: root/macros/CCodeGeneration/C_Funcall.sci
diff options
context:
space:
mode:
authorsiddhu89902016-07-25 15:59:40 +0530
committersiddhu89902016-07-25 15:59:40 +0530
commit24fbba33153e7758df4a990cb4c21ae8e53e6f3e (patch)
treeb12075cf236142e6e0b9c024a37a2fc4ee5e6761 /macros/CCodeGeneration/C_Funcall.sci
parent169db0082ebd07baea82d00213db6ffd4dee7cf6 (diff)
downloadScilab2C_fossee_old-24fbba33153e7758df4a990cb4c21ae8e53e6f3e.tar.gz
Scilab2C_fossee_old-24fbba33153e7758df4a990cb4c21ae8e53e6f3e.tar.bz2
Scilab2C_fossee_old-24fbba33153e7758df4a990cb4c21ae8e53e6f3e.zip
WiringPi used for RaspberryPi (Gpio, serial, Threads, ISRs)
Diffstat (limited to 'macros/CCodeGeneration/C_Funcall.sci')
-rw-r--r--macros/CCodeGeneration/C_Funcall.sci277
1 files changed, 143 insertions, 134 deletions
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