summaryrefslogtreecommitdiff
path: root/2.3-1/macros/CCodeGeneration/C_MemAllocOutTempVars.sci
diff options
context:
space:
mode:
authorSiddhesh Wani2015-05-25 14:46:31 +0530
committerSiddhesh Wani2015-05-25 14:46:31 +0530
commit6a320264c2de3d6dd8cc1d1327b3c30df4c8cb26 (patch)
tree1b7bd89fdcfd01715713d8a15db471dc75a96bbf /2.3-1/macros/CCodeGeneration/C_MemAllocOutTempVars.sci
downloadScilab2C-6a320264c2de3d6dd8cc1d1327b3c30df4c8cb26.tar.gz
Scilab2C-6a320264c2de3d6dd8cc1d1327b3c30df4c8cb26.tar.bz2
Scilab2C-6a320264c2de3d6dd8cc1d1327b3c30df4c8cb26.zip
Original Version
Diffstat (limited to '2.3-1/macros/CCodeGeneration/C_MemAllocOutTempVars.sci')
-rw-r--r--2.3-1/macros/CCodeGeneration/C_MemAllocOutTempVars.sci64
1 files changed, 64 insertions, 0 deletions
diff --git a/2.3-1/macros/CCodeGeneration/C_MemAllocOutTempVars.sci b/2.3-1/macros/CCodeGeneration/C_MemAllocOutTempVars.sci
new file mode 100644
index 00000000..dedcfd33
--- /dev/null
+++ b/2.3-1/macros/CCodeGeneration/C_MemAllocOutTempVars.sci
@@ -0,0 +1,64 @@
+function C_MemAllocOutTempVars(OutArg,NOutArg,CPass1FileName,CPass1FreeFileName,IndentLevel,ReportFileName,ResizeApproach)
+// function C_MemAllocOutTempVars(OutArg,NOutArg,CPass1FileName,CPass1FreeFileName,IndentLevel,ReportFileName,ResizeApproach)
+// -----------------------------------------------------------------
+// //NUT: add description here
+//
+// Input data:
+// //NUT: add description here
+//
+// Output data:
+// //NUT: add description here
+//
+// 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),7,7);
+
+// #RNU_RES_B
+PrintStringInfo(' ',ReportFileName,'file','y');
+PrintStringInfo('***Allocating memory for temp variables***',ReportFileName,'file','y');
+// #RNU_RES_E
+
+// #RNU_RES_B
+// --- Allocate memory and size array for output arguments. ---
+// #RNU_RES_E
+for counterout = 1:NOutArg
+ if (OutArg(counterout).Dimension > 0)
+ // #RNU_RES_B
+ // if ((OutArg(counterout).Scope == 'Temp') | (OutArg(counterout).FindLike == -1) | ...
+ // (isnum(OutArg(counterout).Size(1))==%F) | (isnum(OutArg(counterout).Size(2))==%F))
+ //NUT: qui forse ci vuole un check per verificare se per caso la variabile e' globale e non se ne conosce la size numerica.
+ //NUT infatti. Per ora se la size numerica assumo che la variabile globale e' da reallocare. Secondo me occorre aggiungere
+ //NUT un campo negli argomenti che specifichi la presenza di realloc da fare.
+ //NUT: ho tolto il check sulle temp perche' se una temp ha size numerica non voglio fare malloc.
+ //RNU sulle stringhe ancora non applico realloc
+ // #RNU_RES_E
+ if ((OutArg(counterout).FindLike == -1) | ...
+ (isnum(OutArg(counterout).Size(1))==%F) | (isnum(OutArg(counterout).Size(2))==%F)| ...
+ (ResizeApproach=='REALLOC_ALL_RESIZE_ALL' & OutArg(counterout).Type ~= 'g'))
+ 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