summaryrefslogtreecommitdiff
path: root/src/Scilab2C
diff options
context:
space:
mode:
Diffstat (limited to 'src/Scilab2C')
-rw-r--r--src/Scilab2C/Scilab2C/CCodeGeneration/C_Funcall.sci177
1 files changed, 173 insertions, 4 deletions
diff --git a/src/Scilab2C/Scilab2C/CCodeGeneration/C_Funcall.sci b/src/Scilab2C/Scilab2C/CCodeGeneration/C_Funcall.sci
index fcda4ebb..3c91ee15 100644
--- a/src/Scilab2C/Scilab2C/CCodeGeneration/C_Funcall.sci
+++ b/src/Scilab2C/Scilab2C/CCodeGeneration/C_Funcall.sci
@@ -1,6 +1,13 @@
function SharedInfo = C_Funcall(FunInfo,FileInfo,SharedInfo,FlagCall)
// function SharedInfo = C_Funcall(FunInfo,FileInfo,SharedInfo,FlagCall)
// -----------------------------------------------------------------
+// Get function for a generic SCI2C table.
+//
+// Input data:
+// //NUT: add description here
+//
+// Output data:
+// //NUT: add description here
//
// Status:
// 27-Oct-2007 -- Raffaele Nutricato: Author.
@@ -29,6 +36,7 @@ CInitVarsFileName = FileInfo.Funct(nxtscifunnumber).CInitVarsFileName;
IndentLevel = SharedInfo.NIndent;
CCall = '';
+// --- Extract Function Info. ---
FunctionName = FunInfo.SCIFunctionName;
CFunName = FunInfo.CFunctionName;
InArg = FunInfo.InArg;
@@ -37,27 +45,129 @@ OutArg = FunInfo.OutArg;
NOutArg = FunInfo.NOutArg;
PosFirstOutScalar = FunInfo.PosFirstOutScalar;
+// #RNU_RES_B
+PrintStringInfo(' ',ReportFileName,'file','y');
+PrintStringInfo('***Generating C code***',ReportFileName,'file','y');
+// #RNU_RES_E
+// ---------------------------
+// --- End Initialization. ---
+// ---------------------------
+// --------------------------------------------------
+// --- Manage anticipated exit from the function. ---
+// --------------------------------------------------
if (SharedInfo.SkipNextFun > 0)
SharedInfo.SkipNextFun = SharedInfo.SkipNextFun - 1;
return;
end
+// #RNU_RES_B
+// Exit if the function is a precision specifier and the corresponding flag is 1.
+// #RNU_RES_E
if ((sum(mtlb_strcmp(FunctionName,SharedInfo.Annotations.DataPrec)) > 0) & ...
(SharedInfo.SkipNextPrec == 1))
+ // #RNU_RES_B
+ PrintStringInfo(' Skipping code generating because already generated in the previous function.',ReportFileName,'file','y');
+ // #RNU_RES_E
SharedInfo.SkipNextPrec = SharedInfo.SkipNextPrec - 1;
return;
end
+// #RNU_RES_B
+// Exit if the function is OpEqual and the corresponding skip flag is enabled.
+// #RNU_RES_E
if ((mtlb_strcmp(FunctionName,'OpEqual')) & ...
(SharedInfo.SkipNextEqual == 1))
+ // #RNU_RES_B
+ PrintStringInfo(' Skipping code generating because already generated in the previous function.',ReportFileName,'file','y');
+ // #RNU_RES_E
SharedInfo.SkipNextEqual = SharedInfo.SkipNextEqual - 1;
return;
end
+// #RNU_RES_B
+// Exit if the function is size.
+// #RNU_RES_E
+if ((mtlb_strcmp(FunctionName,'size')))
+ // #RNU_RES_B
+ PrintStringInfo(' Anticipated exit for the size function.',ReportFileName,'file','y');
+ // #RNU_RES_E
+ CCall ='';
+ if (NInArg == 1)
+ if (NOutArg == 1)
+ CCall = CCall+OutArg(1).Name+'[0] = __'+InArg(1).Name+'Size[0];';
+ // #RNU_RES_B
+ PrintStringInfo(' '+CCall,ReportFileName,'file','y');
+ // #RNU_RES_E
+ PrintStringInfo(C_IndentBlanks(IndentLevel)+CCall,CPass1FileName,'file','y');
+
+ CCall ='';
+ CCall = CCall+OutArg(1).Name+'[1] = __'+InArg(1).Name+'Size[1];';
+ // #RNU_RES_B
+ PrintStringInfo(' '+CCall,ReportFileName,'file','y');
+ // #RNU_RES_E
+ PrintStringInfo(C_IndentBlanks(IndentLevel)+CCall,CPass1FileName,'file','y');
+ elseif (NOutArg == 2)
+ CCall = CCall+OutArg(1).Name+' = __'+InArg(1).Name+'Size[0];';
+ // #RNU_RES_B
+ PrintStringInfo(' '+CCall,ReportFileName,'file','y');
+ // #RNU_RES_E
+ PrintStringInfo(C_IndentBlanks(IndentLevel)+CCall,CPass1FileName,'file','y');
+
+ CCall ='';
+ CCall = CCall+OutArg(2).Name+' = __'+InArg(1).Name+'Size[1];';
+ // #RNU_RES_B
+ PrintStringInfo(' '+CCall,ReportFileName,'file','y');
+ // #RNU_RES_E
+ PrintStringInfo(C_IndentBlanks(IndentLevel)+CCall,CPass1FileName,'file','y');
+ else
+ SCI2Cerror('Don''t know how to manage size function with number of output args different from 1 and 2.');
+ end
+ elseif (NInArg == 2)
+ if (NOutArg == 1)
+ if (InArg(1).Value == 1)
+ CCall = CCall+OutArg(1).Name+' = __'+InArg(1).Name+'Size[0];';
+ // #RNU_RES_B
+ PrintStringInfo(' '+CCall,ReportFileName,'file','y');
+ // #RNU_RES_E
+ PrintStringInfo(C_IndentBlanks(IndentLevel)+CCall,CPass1FileName,'file','y');
+ elseif (InArg(1).Value == 2)
+ CCall = CCall+OutArg(1).Name+' = __'+InArg(1).Name+'Size[1];';
+ // #RNU_RES_B
+ PrintStringInfo(' '+CCall,ReportFileName,'file','y');
+ // #RNU_RES_E
+ PrintStringInfo(C_IndentBlanks(IndentLevel)+CCall,CPass1FileName,'file','y');
+ else
+ SCI2Cerror('Not known the value of the second input arg for the size function.');
+ end
+ else
+ SCI2Cerror('Don''t know how to manage size function with number of output args different from 1.');
+ end
+ else
+ SCI2Cerror('Don''t know how to manage size function with number of input args different from 1 and 2.');
+ end
+ return;
+end
+// ------------------------------------------------------
+// --- End Manage anticipated exit from the function. ---
+// ------------------------------------------------------
+// #RNU_RES_B
+// ------------------------------------------------------------
+// --- Allocate memory and size array for output arguments. ---
+// ------------------------------------------------------------
+// #RNU_RES_E
+if (FlagCall == 1)
+// #RNU_RES_B
+//RNU qui va tolto tutto una volta sicuri che la memallocout puo' essere fatta dentro la st_insoutarg
+// C_MemAllocOutTempVars(OutArg,NOutArg,CPass1FileName,CPass1FreeFileName,IndentLevel,ReportFileName);
+// #RNU_RES_E
+end
+// ----------------------------
+// --- Generate the C call. ---
+// ----------------------------
CCall ='';
if (FunInfo.CFunctionName == SharedInfo.CMainFunName)
if (FlagCall == 1)
@@ -81,7 +191,9 @@ end
CCall = CCall+CFunName+'(';
-
+// #RNU_RES_B
+PrintStringInfo(' C call after output scalar args check: '+CCall,ReportFileName,'file','y');
+// #RNU_RES_E
clear counterin
for counterin = 1:NInArg
@@ -116,14 +228,21 @@ for counterin = 1:NInArg
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 = 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
@@ -132,6 +251,7 @@ for counterout = 1:NOutArg
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+', ';
@@ -144,11 +264,18 @@ for counterout = 1:NOutArg
if (OutArg(counterout).FindLike == 1)
CCall = CCall+'SCI2Cint* __'+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 = 'SCI2Cint __'+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
@@ -160,7 +287,8 @@ for counterout = 1:NOutArg
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
@@ -184,10 +312,14 @@ if mtlb_strcmp(FunctionName,'return')
CCall = '';
CCall = CCall+'*__ptr'+SharedInfo.CurrentFunInfo.OutArg(cntout).Name+' = '+...
SharedInfo.CurrentFunInfo.OutArg(cntout).Name+';';
+ PrintStringInfo(' '+CCall,ReportFileName,'file','y');
PrintStringInfo(C_IndentBlanks(IndentLevel)+CCall,CPass1FileName,'file','y');
end
end
-
+ // --- Then I free the memory dinamically allocated. ---
+ // ----------------------------
+ // --- Handle Free section. ---
+ // ----------------------------
PrintStringInfo(C_IndentBlanks(1)+'/*',CPass1FreeFileName,'file','y');
PrintStringInfo(C_IndentBlanks(1)+'** ------------------------- ',CPass1FreeFileName,'file','y');
PrintStringInfo(C_IndentBlanks(1)+'** --- End Free Section. --- ',CPass1FreeFileName,'file','y');
@@ -196,8 +328,18 @@ if mtlb_strcmp(FunctionName,'return')
PrintStringInfo(' ',CPass1FreeFileName,'file','y');
SCI2Ccopyfile(CPass1FreeFileName,...
CPass1FileName,'append');
+ // --------------------------------
+ // --- End Handle Free section. ---
+ // --------------------------------
+ // --- Then I introduce the return to the first scalar output arguments. ---
CCall = '';
+ // #RNU_RES_B
+ //NUT: non capisco questo skip a questo punto.
+ //NUT: perche' la return finale la sto gestendo nella AST_HandleEndProgram.
+ PrintStringInfo(' return function of the AST is skipped.',ReportFileName,'file','y');
+ //RN provo a non skippare e a mettere la return.
+ // #RNU_RES_E
if (SharedInfo.CurrentFunInfo.CFunctionName == SharedInfo.CMainFunName)
CCall = CCall+'return(0);';
else
@@ -205,16 +347,43 @@ if mtlb_strcmp(FunctionName,'return')
CCall = CCall+'return('+SharedInfo.CurrentFunInfo.OutArg(SharedInfo.CurrentFunInfo.PosFirstOutScalar).Name+');'
end
end
+ // #RNU_RES_B
+ PrintStringInfo(' '+CCall,ReportFileName,'file','y');
+ // #RNU_RES_E
PrintStringInfo(C_IndentBlanks(IndentLevel)+CCall,CPass1FileName,'file','y');
else
+ // #RNU_RES_B
+ PrintStringInfo(' '+CCall,ReportFileName,'file','y');
+ // #RNU_RES_E
PrintStringInfo(C_IndentBlanks(IndentLevel)+CCall,CPass1FileName,'file','y');
if (FlagCall == 0)
// Add prototype to the header file
C_InitHeader(CCall+';',HeaderFileName,SharedInfo.Sci2CLibMainHeaderFName);
// Add { at the beginning of the function.
+ PrintStringInfo(' {',ReportFileName,'file','y');
PrintStringInfo(C_IndentBlanks(IndentLevel)+'{',CPass1FileName,'file','y');
end
end
+
+// #RNU_RES_B
+// Add in the C code the new size of the output argument when SCI2Cresize function is called.
+// #RNU_RES_E
+if (FunctionName == 'SCI2Cresize')
+ // #RNU_RES_B
+ PrintStringInfo(' Found SCI2Cresize -> Changing the size of the output argument.',ReportFileName,'file','y');
+ // #RNU_RES_E
+ OutArgName = OutArg(counterout).Name;
+ tmpcode = '__'+OutArgName+'Size[0]='+OutArg(counterout).Size(1)+';';
+ PrintStringInfo(C_IndentBlanks(IndentLevel)+tmpcode,CPass1FileName,'file','y');
+ // #RNU_RES_B
+ PrintStringInfo(' '+tmpcode,ReportFileName,'file','y');
+ // #RNU_RES_E
+ tmpcode = '__'+OutArgName+'Size[1]='+OutArg(counterout).Size(2)+';';
+ PrintStringInfo(C_IndentBlanks(IndentLevel)+tmpcode,CPass1FileName,'file','y');
+ // #RNU_RES_B
+ PrintStringInfo(' '+tmpcode,ReportFileName,'file','y');
+ // #RNU_RES_E
+end
endfunction