summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Scilab2C/Scilab2C/CCodeGeneration/C_GenDeclarations.sci182
-rw-r--r--src/Scilab2C/Scilab2C/CCodeGeneration/C_MemAllocOutTempVars.sci74
2 files changed, 132 insertions, 124 deletions
diff --git a/src/Scilab2C/Scilab2C/CCodeGeneration/C_GenDeclarations.sci b/src/Scilab2C/Scilab2C/CCodeGeneration/C_GenDeclarations.sci
index 795d182d..0848f33f 100644
--- a/src/Scilab2C/Scilab2C/CCodeGeneration/C_GenDeclarations.sci
+++ b/src/Scilab2C/Scilab2C/CCodeGeneration/C_GenDeclarations.sci
@@ -1,92 +1,90 @@
-function Cdeclaration = C_GenDeclarations(ArgStruct,CDeclarationFileName,IndentLevel,ReportFileName,FlagExt)
-// function Cdeclaration = C_GenDeclarations(ArgStruct,CDeclarationFileName,IndentLevel,ReportFileName,FlagExt)
-// -----------------------------------------------------------------
-//
-// Status:
-// 27-Oct-2007 -- Raffaele Nutricato: Author.
-//
-// Copyright 2007 Raffaele Nutricato.
-// Contact: raffaele.nutricato@tiscali.it
-// -----------------------------------------------------------------
-
-// ------------------------------
-// --- Check input arguments. ---
-// ------------------------------
-SCI2CNInArgCheck(argn(2),5,5);
-
-//NUT: ilnome di questa funzione va cambiato perche' le dichiarazioni le fanno anche i for e i while.
-
-
-Cdeclaration = '';
-NDeclarations = 0;
-if (ArgStruct.Dimension > 0)
- if (FlagExt == 1)
- Cdeclaration(1) = 'extern ';
- Cdeclaration(2) = 'extern ';
- else
- Cdeclaration(1) = '';
- Cdeclaration(2) = '';
- end
- //NUT: vedi Mem_Alloc_Out per maggiori info sulla rimozione della temp nella if
- // if ((ArgStruct.Scope=='Temp') | (ArgStruct.FindLike == -1) | (SCI2Cisnum(ArgStruct.Size(1))==%F) | (SCI2Cisnum(ArgStruct.Size(2))==%F))
- if (ArgStruct.Type=='g')
- if (isnan(ArgStruct.Value))
- Cdeclaration(1) = Cdeclaration(1)+C_Type(ArgStruct.Type)+...
- ' * '+ArgStruct.Name+';';
- else
- Cdeclaration(1) = Cdeclaration(1)+C_Type(ArgStruct.Type)+...
- ' '+ArgStruct.Name+'['+ArgStruct.Size(1)+']['+ArgStruct.Size(2)+'] = {'+ArgStruct.Value+'};';
- end
- Cdeclaration(2) = Cdeclaration(2)+C_Type('i')+' __'+ArgStruct.Name+'Size[2] = {'+ArgStruct.Size(1)+','+ArgStruct.Size(2)+'};';
- NDeclarations = 2;
- elseif ((ArgStruct.FindLike == -1) | (SCI2Cisnum(ArgStruct.Size(1))==%F) | (SCI2Cisnum(ArgStruct.Size(2))==%F))
- // Generate only the pointer that will be used by the malloc function.
- Cdeclaration(1) = Cdeclaration(1)+C_Type(ArgStruct.Type)+'* '+...
- ArgStruct.Name+';';
- // Declare the Size array
- Cdeclaration(2) = Cdeclaration(2)+C_Type('i')+' __'+ArgStruct.Name+'Size[2];';
- NDeclarations = 2;
- else
- // Declare the array with its size.
- Cdeclaration(1) = Cdeclaration(1)+C_Type(ArgStruct.Type)+...
- ' '+ArgStruct.Name+'['+ArgStruct.Size(1)+']['+ArgStruct.Size(2)+'];';
- Cdeclaration(2) = Cdeclaration(2)+C_Type('i')+' __'+ArgStruct.Name+'Size[2] = {'+ArgStruct.Size(1)+','+ArgStruct.Size(2)+'};';
- NDeclarations = 2;
- end
-else
- if (FlagExt == 1)
- Cdeclaration(1) = 'extern ';
- else
- Cdeclaration(1) = '';
- end
- Cdeclaration(1) = Cdeclaration(1)+C_Type(ArgStruct.Type)+' '+ArgStruct.Name;
- if (~isnan(ArgStruct.Value) & (FlagExt == 0))
- if isreal(ArgStruct.Value)
- Cdeclaration(1) = Cdeclaration(1)+' = '+SCI2Cstring(ArgStruct.Value);
- else
- if (ArgStruct.Type == 'z')
- Cdeclaration(1) = Cdeclaration(1)+' = DoubleComplex('+SCI2Cstring(real(ArgStruct.Value))+','+SCI2Cstring(imag(ArgStruct.Value))+')';
- else
- Cdeclaration(1) = Cdeclaration(1)+' = FloatComplex('+SCI2Cstring(real(ArgStruct.Value))+','+SCI2Cstring(imag(ArgStruct.Value))+')';
- end
- end
- end
- Cdeclaration(1) = Cdeclaration(1)+';';
- NDeclarations = 1;
-end
-
-
-// --------------------------------------------
-// --- Write C declaration into the C file. ---
-// --------------------------------------------
-for cntdecl = 1:NDeclarations
- PrintStringInfo(' '+Cdeclaration(cntdecl),ReportFileName,'file','y');
-end
-for cntdecl = 1:NDeclarations
- PrintStringInfo(C_IndentBlanks(IndentLevel)+Cdeclaration(cntdecl),CDeclarationFileName,'file','y');
-end
-PrintStringInfo(' ',CDeclarationFileName,'file','y');
-
-endfunction
-//NUT: dove sta il controllo che verifica se dopo aver dichiarato una local A[10] essa viene utilizzata
-//NUT: per memorizzare un A = sin(B) dove B[11]??
+function Cdeclaration = C_GenDeclarations(ArgStruct,CDeclarationFileName,IndentLevel,ReportFileName,FlagExt)
+// function Cdeclaration = C_GenDeclarations(ArgStruct,CDeclarationFileName,IndentLevel,ReportFileName,FlagExt)
+// -----------------------------------------------------------------
+// Status:
+// 27-Oct-2007 -- Raffaele Nutricato: Author.
+// 10-Jun-2008 -- Raffaele Nutricato: adapted to work with realloc function.
+//
+// Copyright 2007 Raffaele Nutricato.
+// Contact: raffaele.nutricato@tiscali.it
+// -----------------------------------------------------------------
+
+// ------------------------------
+// --- Check input arguments. ---
+// ------------------------------
+SCI2CNInArgCheck(argn(2),5,5);
+
+
+PrintStringInfo(' ',ReportFileName,'file','y');
+PrintStringInfo('***Generating C declaration***',ReportFileName,'file','y');
+
+Cdeclaration = '';
+NDeclarations = 0;
+if (ArgStruct.Dimension > 0)
+ if (FlagExt == 1)
+ Cdeclaration(1) = 'extern ';
+ Cdeclaration(2) = 'extern ';
+ else
+ Cdeclaration(1) = '';
+ Cdeclaration(2) = '';
+ end
+ if (ArgStruct.Type=='g')
+ if (isnan(ArgStruct.Value))
+ Cdeclaration(1) = Cdeclaration(1)+C_Type(ArgStruct.Type)+...
+ ' * '+ArgStruct.Name+';';
+ else
+ Cdeclaration(1) = Cdeclaration(1)+C_Type(ArgStruct.Type)+...
+ ' '+ArgStruct.Name+'['+ArgStruct.Size(1)+']['+ArgStruct.Size(2)+'] = {'+ArgStruct.Value+'};';
+ end
+ Cdeclaration(2) = Cdeclaration(2)+C_Type('i')+' __'+ArgStruct.Name+'Size[2] = {'+ArgStruct.Size(1)+','+ArgStruct.Size(2)+'};';
+ NDeclarations = 2;
+ elseif ((ArgStruct.FindLike == -1) | (SCI2Cisnum(ArgStruct.Size(1))==%F) | (SCI2Cisnum(ArgStruct.Size(2))==%F))
+ // Generate only the pointer that will be used by the malloc function.
+ Cdeclaration(1) = Cdeclaration(1)+C_Type(ArgStruct.Type)+'* '+...
+ ArgStruct.Name+' = NULL;';
+ // Declare the Size array
+ Cdeclaration(2) = Cdeclaration(2)+C_Type('i')+' __'+ArgStruct.Name+'Size[2];';
+ NDeclarations = 2;
+ else
+ // Declare the array with its size.
+ Cdeclaration(1) = Cdeclaration(1)+C_Type(ArgStruct.Type)+...
+ ' '+ArgStruct.Name+'['+ArgStruct.Size(1)+']['+ArgStruct.Size(2)+'];';
+ Cdeclaration(2) = Cdeclaration(2)+C_Type('i')+' __'+ArgStruct.Name+'Size[2] = {'+ArgStruct.Size(1)+','+ArgStruct.Size(2)+'};';
+ NDeclarations = 2;
+ end
+else
+ if (FlagExt == 1)
+ Cdeclaration(1) = 'extern ';
+ else
+ Cdeclaration(1) = '';
+ end
+ Cdeclaration(1) = Cdeclaration(1)+C_Type(ArgStruct.Type)+' '+ArgStruct.Name;
+ if (~isnan(ArgStruct.Value) & (FlagExt == 0))
+ if isreal(ArgStruct.Value)
+ Cdeclaration(1) = Cdeclaration(1)+' = '+SCI2Cstring(ArgStruct.Value);
+ else
+ if (ArgStruct.Type == 'z')
+ Cdeclaration(1) = Cdeclaration(1)+' = DoubleComplex('+SCI2Cstring(real(ArgStruct.Value))+','+SCI2Cstring(imag(ArgStruct.Value))+')';
+ else
+ Cdeclaration(1) = Cdeclaration(1)+' = FloatComplex('+SCI2Cstring(real(ArgStruct.Value))+','+SCI2Cstring(imag(ArgStruct.Value))+')';
+ end
+ end
+ end
+ Cdeclaration(1) = Cdeclaration(1)+';';
+ NDeclarations = 1;
+end
+
+
+// --------------------------------------------
+// --- Write C declaration into the C file. ---
+// --------------------------------------------
+for cntdecl = 1:NDeclarations
+ PrintStringInfo(' '+Cdeclaration(cntdecl),ReportFileName,'file','y');
+end
+PrintStringInfo(' Writing C declaration in: '+CDeclarationFileName,ReportFileName,'file','y');
+for cntdecl = 1:NDeclarations
+ PrintStringInfo(C_IndentBlanks(IndentLevel)+Cdeclaration(cntdecl),CDeclarationFileName,'file','y');
+end
+PrintStringInfo(' ',CDeclarationFileName,'file','y');
+
+endfunction
diff --git a/src/Scilab2C/Scilab2C/CCodeGeneration/C_MemAllocOutTempVars.sci b/src/Scilab2C/Scilab2C/CCodeGeneration/C_MemAllocOutTempVars.sci
index 5570f42a..6272a22a 100644
--- a/src/Scilab2C/Scilab2C/CCodeGeneration/C_MemAllocOutTempVars.sci
+++ b/src/Scilab2C/Scilab2C/CCodeGeneration/C_MemAllocOutTempVars.sci
@@ -1,32 +1,42 @@
-function C_MemAllocOutTempVars(OutArg,NOutArg,CPass1FileName,CPass1FreeFileName,IndentLevel,ReportFileName)
-// function C_MemAllocOutTempVars(OutArg,NOutArg,CPass1FileName,CPass1FreeFileName,IndentLevel,ReportFileName)
-// -----------------------------------------------------------------
-//
-// Status:
-// 27-Oct-2007 -- Raffaele Nutricato: Author.
-//
-// Copyright 2007 Raffaele Nutricato.
-// Contact: raffaele.nutricato@tiscali.it
-// -----------------------------------------------------------------
-
-SCI2CNInArgCheck(argn(2),6,6);
-
-for counterout = 1:NOutArg
- if (OutArg(counterout).Dimension > 0)
- if ((OutArg(counterout).FindLike == -1) | (SCI2Cisnum(OutArg(counterout).Size(1))==%F) | (SCI2Cisnum(OutArg(counterout).Size(2))==%F))
- OutArgName = OutArg(counterout).Name;
- tmpcode = '__'+OutArgName+'Size[0]='+OutArg(counterout).Size(1)+';';
- PrintStringInfo(C_IndentBlanks(IndentLevel)+tmpcode,CPass1FileName,'file','y');
- PrintStringInfo(' '+tmpcode,ReportFileName,'file','y');
- tmpcode = '__'+OutArgName+'Size[1]='+OutArg(counterout).Size(2)+';';
- PrintStringInfo(C_IndentBlanks(IndentLevel)+tmpcode,CPass1FileName,'file','y');
- PrintStringInfo(' '+tmpcode,ReportFileName,'file','y');
- tmpcode = OutArgName+' = ('+C_Type(OutArg(counterout).Type)+'*) malloc(('+OutArg(counterout).Size(1)+')*('+OutArg(counterout).Size(2)+')*sizeof('+C_Type(OutArg(counterout).Type)+'));';
- PrintStringInfo(C_IndentBlanks(IndentLevel)+tmpcode,CPass1FileName,'file','y');
- PrintStringInfo(' '+tmpcode,ReportFileName,'file','y');
- PrintStringInfo(C_IndentBlanks(1)+'free('+OutArgName+');',CPass1FreeFileName,'file','y');
- end
- end
-end
-
-endfunction
+function C_MemAllocOutTempVars(OutArg,NOutArg,CPass1FileName,CPass1FreeFileName,IndentLevel,ReportFileName)
+// function C_MemAllocOutTempVars(OutArg,NOutArg,CPass1FileName,CPass1FreeFileName,IndentLevel,ReportFileName)
+// -----------------------------------------------------------------
+//
+// Status:
+// 27-Oct-2007 -- Raffaele Nutricato: Author.
+// 10-Jun-2008 -- Raffaele Nutricato: replaced malloc with realloc.
+//
+// Copyright 2007 Raffaele Nutricato.
+// Contact: raffaele.nutricato@tiscali.it
+// -----------------------------------------------------------------
+
+// ------------------------------
+// --- Check input arguments. ---
+// ------------------------------
+SCI2CNInArgCheck(argn(2),6,6);
+
+PrintStringInfo(' ',ReportFileName,'file','y');
+PrintStringInfo('***Allocating memory for temp variables***',ReportFileName,'file','y');
+
+// --- Allocate memory and size array for output arguments. ---
+for counterout = 1:NOutArg
+ if (OutArg(counterout).Dimension > 0)
+ if ((OutArg(counterout).FindLike == -1) | (SCI2Cisnum(OutArg(counterout).Size(1))==%F) | (SCI2Cisnum(OutArg(counterout).Size(2))==%F))
+ OutArgName = OutArg(counterout).Name;
+ tmpcode = '__'+OutArgName+'Size[0]='+OutArg(counterout).Size(1)+';';
+ PrintStringInfo(C_IndentBlanks(IndentLevel)+tmpcode,CPass1FileName,'file','y');
+ PrintStringInfo(' '+tmpcode,ReportFileName,'file','y');
+ tmpcode = '__'+OutArgName+'Size[1]='+OutArg(counterout).Size(2)+';';
+ PrintStringInfo(C_IndentBlanks(IndentLevel)+tmpcode,CPass1FileName,'file','y');
+ PrintStringInfo(' '+tmpcode,ReportFileName,'file','y');
+ //a->val = (double *) malloc(nnz * sizeof(double));
+ // numbers = (int*) realloc (numbers, count * sizeof(int));
+ tmpcode = OutArgName+' = ('+C_Type(OutArg(counterout).Type)+'*) realloc('+OutArgName+',('+OutArg(counterout).Size(1)+')*('+OutArg(counterout).Size(2)+')*sizeof('+C_Type(OutArg(counterout).Type)+'));';
+ PrintStringInfo(C_IndentBlanks(IndentLevel)+tmpcode,CPass1FileName,'file','y');
+ PrintStringInfo(' '+tmpcode,ReportFileName,'file','y');
+ PrintStringInfo(C_IndentBlanks(1)+'free('+OutArgName+');',CPass1FreeFileName,'file','y');
+ end
+ end
+end
+
+endfunction