summaryrefslogtreecommitdiff
path: root/macros/CCodeGeneration
diff options
context:
space:
mode:
authorJorawar Singh2017-06-30 11:54:22 +0530
committerJorawar Singh2017-06-30 11:54:22 +0530
commita7d283ae2899b2530ac70a2453d4db05d03d609d (patch)
treefb93a9edddeee4601c47ce73e173331fa3addac8 /macros/CCodeGeneration
parentaef4e8398f2b1848b0e4cdd9580dbbe93e4006f9 (diff)
parentbee6bf6e37f6c36fb18b6132702e1528b7edafc2 (diff)
downloadScilab2C_fossee_old-a7d283ae2899b2530ac70a2453d4db05d03d609d.tar.gz
Scilab2C_fossee_old-a7d283ae2899b2530ac70a2453d4db05d03d609d.tar.bz2
Scilab2C_fossee_old-a7d283ae2899b2530ac70a2453d4db05d03d609d.zip
merged main repo with local
Diffstat (limited to 'macros/CCodeGeneration')
-rw-r--r--macros/CCodeGeneration/C_GenDeclarations_Dup.sci187
-rw-r--r--macros/CCodeGeneration/C_GenerateMakefile.sci19
-rw-r--r--macros/CCodeGeneration/C_GenerateMkfle_arduino.sci12
-rw-r--r--macros/CCodeGeneration/C_IfExpression.sci31
-rw-r--r--macros/CCodeGeneration/C_WhileExpression.sci28
-rw-r--r--macros/CCodeGeneration/GetClsFileName.sci4
-rw-r--r--macros/CCodeGeneration/libbin1008 -> 2449 bytes
-rw-r--r--macros/CCodeGeneration/names2
8 files changed, 272 insertions, 11 deletions
diff --git a/macros/CCodeGeneration/C_GenDeclarations_Dup.sci b/macros/CCodeGeneration/C_GenDeclarations_Dup.sci
new file mode 100644
index 0000000..475e2e0
--- /dev/null
+++ b/macros/CCodeGeneration/C_GenDeclarations_Dup.sci
@@ -0,0 +1,187 @@
+function Cdeclaration = C_GenDeclarations_Dup(InArg,NInArg,com_type,ArgStruct,CDeclarationFileName,IndentLevel,ReportFileName,FlagExt,ResizeApproach)
+// function Cdeclaration = C_GenDeclarations(ArgStruct,CDeclarationFileName,IndentLevel,ReportFileName,FlagExt,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: adapted to work with realloc function.
+//
+// Copyright 2007 Raffaele Nutricato.
+// Contact: raffaele.nutricato@tiscali.it
+// -----------------------------------------------------------------
+
+// Generate C corresponding declaration given some information in ArgStruct
+//
+
+// ------------------------------
+// --- Check input arguments. ---
+// ------------------------------
+SCI2CNInArgCheck(argn(2),9,9);
+// #RNU_RES_B
+//NUT: ilnome di questa funzione va cambiato perche' le dichiarazioni le fanno anche i for e i while.
+
+PrintStringInfo(' ',ReportFileName,'file','y');
+PrintStringInfo('***Generating C declaration***',ReportFileName,'file','y');
+// #RNU_RES_E
+
+Cdeclaration = '';
+if (ArgStruct.Dimension > 0)
+ if (FlagExt == 1)
+ Cdeclaration(1) = 'extern ';
+ Cdeclaration(2) = 'extern ';
+ else
+ Cdeclaration(1) = '';
+ Cdeclaration(2) = '';
+ end
+// #RNU_RES_B
+//NUT: vedi Mem_Alloc_Out per maggiori info sulla rimozione della temp nella if
+// if ((ArgStruct.Scope=='Temp') | (ArgStruct.FindLike == -1) | (isnum(ArgStruct.Size(1))==%F) | (isnum(ArgStruct.Size(2))==%F))
+// #RNU_RES_E
+ if (ArgStruct.Type=='g')
+// if (isnan(ArgStruct.Value) )
+ if ((isnum(ArgStruct.Size(1))==%F) | (isnum(ArgStruct.Size(2))==%F) )
+ Cdeclaration(1) = Cdeclaration(1)+C_Type(ArgStruct.Type)+...
+ ' * '+ArgStruct.Name+';';
+ else
+ if ((FlagExt == 1) | (isnan(ArgStruct.Value)))
+ Cdeclaration(1) = Cdeclaration(1)+C_Type(ArgStruct.Type)+...
+ ' '+ArgStruct.Name+'['+ArgStruct.Size(1)+'*'+ArgStruct.Size(2)+'];';
+ else
+ Cdeclaration(1) = Cdeclaration(1)+C_Type(ArgStruct.Type)+...
+ ' '+ArgStruct.Name+'['+ArgStruct.Size(1)+'*'+ArgStruct.Size(2)+'] = {'+ArgStruct.Value+'};';
+ end
+ end
+ Cdeclaration(2) = Cdeclaration(2)+C_Type('i')+' __'+ArgStruct.Name+'Size[2] = {'+ArgStruct.Size(1)+','+ArgStruct.Size(2)+'};';
+ elseif ((ArgStruct.FindLike == -1) | ...
+ (isnum(ArgStruct.Size(1))==%F) | (isnum(ArgStruct.Size(2))==%F) | ...
+ (ResizeApproach=='REALLOC_ALL_RESIZE_ALL' & ArgStruct.Type~='g'))
+// #RNU_RES_B
+//RNU sulle stringhe non ho ancora deciso se applicare la realloc.
+// Generate only the pointer that will be used by the malloc function.
+// #RNU_RES_E
+ if (FlagExt == 1)
+ Cdeclaration(1) = Cdeclaration(1)+C_Type(ArgStruct.Type)+'* '+...
+ ArgStruct.Name+';';
+ else
+ Cdeclaration(1) = Cdeclaration(1)+C_Type(ArgStruct.Type)+'* '+...
+ ArgStruct.Name+' = NULL;';
+ end
+// Declare the Size array
+ Cdeclaration(2) = Cdeclaration(2)+C_Type('i')+' __'+ArgStruct.Name+'Size[2];';
+ else
+// Declare the array with its size.
+ computedSize = ArgStruct.Size(1);
+ computedSizeLength = size(ArgStruct.Size, '*');
+ computedSizeField = ArgStruct.Size(1);
+ for sizeIterator = 2:computedSizeLength;
+ computedSize = computedSize + ' * ' + ArgStruct.Size(sizeIterator);
+ computedSizeField = computedSizeField + ', ' + ArgStruct.Size(sizeIterator);
+ end
+ Cdeclaration(1) = Cdeclaration(1)+C_Type(ArgStruct.Type)+' '+ArgStruct.Name+'['+computedSize+']={';
+ row = eval(ArgStruct.Size(1))
+ col = eval(ArgStruct.Size(2))
+ if row == 1
+ if com_type == 0
+ for i = 1:NInArg-1
+ Cdeclaration(1) = Cdeclaration(1)+InArg(i).Name+',';
+ end
+ Cdeclaration(1) = Cdeclaration(1)+InArg(NInArg).Name+'};';
+ else
+ for i=1:NInArg-1
+ if InArg(i).Type <> 'z' & InArg(i).Type <> 'c'
+ Cdeclaration(1) = Cdeclaration(1)+InArg(i).Name+',0,';
+ else
+ Cdeclaration(1) = Cdeclaration(1)+InArg(i).Name+',';
+ end
+ end
+ if InArg(NInArg).Type <> 'z' & InArg(NInArg).Type <> 'c'
+ Cdeclaration(1) = Cdeclaration(1) + InArg(NInArg).Name + ',0};'
+ else
+ Cdeclaration(1) = Cdeclaration(1) + InArg(NInArg).Name + '};'
+ end
+ end
+ else
+ if com_type == 0
+ for i = 1:col
+ for j = 0:row-1
+ if (j*col)+i ~= row*col
+ Cdeclaration(1) = Cdeclaration(1) + InArg(((j*col)+i)).Name + ',';
+ end
+ end
+ end
+ Cdeclaration(1) = Cdeclaration(1) + InArg(NInArg).Name + '};';
+ else
+ for i = 1:col
+ for j = 0:row-1
+ if (j*col)+i ~= row*col
+ if InArg(((j*col)+i)).Type <> 'z' & InArg(((j*col)+i)).Type <> 'c'
+ Cdeclaration(1) = Cdeclaration(1) + InArg(((j*col)+i)).Name + ',0,';
+ else
+ Cdeclaration(1) = Cdeclaration(1) + InArg(((j*col)+i)).Name + ',';
+ end
+ end
+ end
+ end
+ if InArg(NInArg).Type <> 'z' & InArg(NInArg).Type <> 'c'
+ Cdeclaration(1) = Cdeclaration(1) + InArg(NInArg).Name + ',0};';
+ else
+ Cdeclaration(1) = Cdeclaration(1) + InArg(NInArg).Name + '};';
+ end
+ end
+ end
+ Cdeclaration(2) = Cdeclaration(2)+C_Type('i')+' __'+ArgStruct.Name+'Size['+string(computedSizeLength)+']';
+ if (FlagExt <> 1)
+ Cdeclaration(2) = Cdeclaration(2)+' = {'+computedSizeField+'}';
+ end
+ Cdeclaration(2) = Cdeclaration(2)+';';
+ end
+else
+ if (ArgStruct.Type == 'fn')
+ //do nothing. This is a function name. Will be declared in header file.
+ 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)+';';
+ end
+end
+
+
+// --------------------------------------------
+// --- Write C declaration into the C file. ---
+// --------------------------------------------
+PrintStringInfo(' ',CDeclarationFileName,'file','y');
+for cntdecl = 1:size(Cdeclaration, '*')
+ PrintStringInfo(' '+Cdeclaration(cntdecl),ReportFileName,'file','y');
+ PrintStringInfo(C_IndentBlanks(IndentLevel)+Cdeclaration(cntdecl),CDeclarationFileName,'file','y');
+end
+
+PrintStringInfo(' Writing C declaration in: '+CDeclarationFileName,ReportFileName,'file','y');
+PrintStringInfo(' ',CDeclarationFileName,'file','y');
+
+endfunction
+// #RNU_RES_B
+//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]??
+// #RNU_RES_E
diff --git a/macros/CCodeGeneration/C_GenerateMakefile.sci b/macros/CCodeGeneration/C_GenerateMakefile.sci
index f209b38..3b977bd 100644
--- a/macros/CCodeGeneration/C_GenerateMakefile.sci
+++ b/macros/CCodeGeneration/C_GenerateMakefile.sci
@@ -78,6 +78,25 @@ else
PrintStringInfo('CXXFLAGS = -Wall -pedantic -g -I $(HSRCDIR) -I $(ISRCDIR) -L $(LIBDIR)',FileInfo.MakefileFilename,'file','y','y');
PrintStringInfo('LDFLAGS = -lblas -llapack -lm ',FileInfo.MakefileFilename,'file','y','y');
end
+
+ //If ode function is used, add libgsl.
+ if(size(SharedInfo.Includelist) <> 0)
+ if((mtlb_strcmp(part(SharedInfo.Includelist(1),1:5),'odefn') == %T))
+ if(target == 'RPi')
+ PrintStringInfo('LDFLAGS = -lgsl -lcblas',FileInfo.MakefileFilename,'file','y','y');
+ else
+ PrintStringInfo('LDFLAGS = -lgsl',FileInfo.MakefileFilename,'file','y','y');
+ end
+
+ end
+ end
+
+ if (target == 'RPi')
+ PrintStringInfo('LDFLAGS += -llapack -lrefblas -lgfortran -lwiringPi',FileInfo.MakefileFilename,'file','y','y');
+ else
+ PrintStringInfo('LDFLAGS += -lblas -llapack -lm ',FileInfo.MakefileFilename,'file','y','y');
+ end
+
if(SharedInfo.OpenCVUsed == %T)
PrintStringInfo('LDFLAGS += -lopencv_calib3d -lopencv_contrib -lopencv_features2d -lopencv_flann -lopencv_gpu',FileInfo.MakefileFilename,'file','y','y');
PrintStringInfo('LDFLAGS += -lopencv_highgui -lopencv_imgproc -lopencv_legacy -lopencv_ml -lopencv_nonfree',FileInfo.MakefileFilename,'file','y','y');
diff --git a/macros/CCodeGeneration/C_GenerateMkfle_arduino.sci b/macros/CCodeGeneration/C_GenerateMkfle_arduino.sci
new file mode 100644
index 0000000..b43eb44
--- /dev/null
+++ b/macros/CCodeGeneration/C_GenerateMkfle_arduino.sci
@@ -0,0 +1,12 @@
+function C_GenerateMkfle_arduino(FileInfo,SharedInfo)
+
+ PrintStringInfo('ARDUINO_DIR = /usr/share/arduino',FileInfo.MakefileFilename,'file','y','y');
+ PrintStringInfo('ARDMK_DIR = /usr/share/arduino',FileInfo.MakefileFilename,'file','y','y');
+ PrintStringInfo('AVR_TOOLS_DIR = /usr',FileInfo.MakefileFilename,'file','y','y');
+ PrintStringInfo('BOARD_TAG = ' + SharedInfo.Board_name ,FileInfo.MakefileFilename,'file','y','y');
+ PrintStringInfo('USER_LIB_PATH = ../',FileInfo.MakefileFilename,'file','y','y');
+ PrintStringInfo('ARDUINO_LIBS = ../src/c ../includes ../interfaces ../ Wire',FileInfo.MakefileFilename,'file','y','y');
+ PrintStringInfo('ARDUINO_PORT = /dev/ttyACM0',FileInfo.MakefileFilename,'file','y','y');
+ PrintStringInfo('include /usr/share/arduino/Arduino.mk',FileInfo.MakefileFilename,'file','y','y');
+
+endfunction
diff --git a/macros/CCodeGeneration/C_IfExpression.sci b/macros/CCodeGeneration/C_IfExpression.sci
index 48a0538..359b788 100644
--- a/macros/CCodeGeneration/C_IfExpression.sci
+++ b/macros/CCodeGeneration/C_IfExpression.sci
@@ -1,4 +1,4 @@
-function SharedInfo = C_IfExpression(IfCondArg,NIfCondArg,ASTIfExpType,FileInfo,SharedInfo)
+function SharedInfo = C_IfExpression(IfCondArg,NIfCondArg,Op,NOp,ASTIfExpType,FileInfo,SharedInfo)
// function SharedInfo = C_IfExpression(IfCondArg,NIfCondArg,ASTIfExpType,FileInfo,SharedInfo)
// -----------------------------------------------------------------
// //NUT: add description here
@@ -19,12 +19,16 @@ function SharedInfo = C_IfExpression(IfCondArg,NIfCondArg,ASTIfExpType,FileInfo,
// ------------------------------
// --- Check input arguments. ---
// ------------------------------
-SCI2CNInArgCheck(argn(2),5,5);
+SCI2CNInArgCheck(argn(2),7,7);
+
+//global SCI2CSTACK
+//global StackPosition;
+//global STACKDEDUG
// --- Check NIfCondArg value. ---
-if ((NIfCondArg ~= 1) & (ASTIfExpType~='else'))
- error(9999, 'Cannot manage ""if/elseif"" with a number of condition variables not equal to 1.');
-end
+//if ((NIfCondArg ~= 1) & (ASTIfExpType~='else'))
+ // error(9999, 'Cannot manage ""if/elseif"" with a number of condition variables not equal to 1.');
+//end
// -----------------------
// --- Initialization. ---
@@ -37,7 +41,7 @@ CPass1FileName = FileInfo.Funct(nxtscifunnumber).CPass1FileName;
// #RNU_RES_B
PrintStringInfo(' ',ReportFileName,'file','y');
-PrintStringInfo('***Generating C code***',ReportFileName,'file','y');
+PrintStringInfo('***Generating C code***'+ string(NIfCondArg),ReportFileName,'file','y');
// #RNU_RES_E
// ---------------------------
// --- End Initialization. ---
@@ -66,10 +70,23 @@ if SCI2Cstrncmps1size(ASTIfExpType,'else')
SharedInfo = C_IfElseBlocks(FileInfo,SharedInfo,'out');
end
+i=1;
+k=1;
CCall ='';
CCall = CCall+CFunName;
if (ASTIfExpType~='else')
- CCall = CCall+'('+IfCondArg(1)+')';
+ CCall = CCall+'(';
+ while i <= NIfCondArg
+ CCall = CCall + IfCondArg(i) + ' ';
+ //d = modulo(i,3);
+ //PrintStringInfo(' '+string(i)+string(d),'file','y');
+ if (modulo(i,3)==0 & i<>NIfCondArg)
+ CCall = CCall + Op(k) + ' ';
+ k = k + 1;
+ end
+ i = i + 1;
+ end
+ CCall = CCall+')';
end
PrintStringInfo(' '+CCall,ReportFileName,'file','y');
PrintStringInfo(C_IndentBlanks(SharedInfo.NIndent)+CCall,CPass1FileName,'file','y');
diff --git a/macros/CCodeGeneration/C_WhileExpression.sci b/macros/CCodeGeneration/C_WhileExpression.sci
index edd2830..368ccff 100644
--- a/macros/CCodeGeneration/C_WhileExpression.sci
+++ b/macros/CCodeGeneration/C_WhileExpression.sci
@@ -1,4 +1,4 @@
-function SharedInfo = C_WhileExpression(FileInfo,SharedInfo)
+function SharedInfo = C_WhileExpression(IfCondArg,NIfCondArg,Op,NOp,FileInfo,SharedInfo)
// function SharedInfo = C_WhileExpression(FileInfo,SharedInfo)
// -----------------------------------------------------------------
// //NUT: add description here
@@ -19,7 +19,7 @@ function SharedInfo = C_WhileExpression(FileInfo,SharedInfo)
// ------------------------------
// --- Check input arguments. ---
// ------------------------------
-SCI2CNInArgCheck(argn(2),2,2);
+SCI2CNInArgCheck(argn(2),6,6);
// -----------------------
// --- Initialization. ---
@@ -63,7 +63,7 @@ for cntstr = 1:NumCStrings
// Epilogue
if (length(C_Strings(cntstr)) == 0)
C_Strings(cntstr) = ' '; // RNU for Bruno: If I don't do that I get a PrintStringInfo error related to mputstr.
- // Function not defined for given argument type(s),
+ // Function not defined for given argument type(s),
// check arguments or define function %0_mputstr for overloading.
end
PrintStringInfo(C_Strings(cntstr),CPass1WhileEpilFileName ,'file','y','n');
@@ -76,7 +76,27 @@ PrintStringInfo('}',CPass1WhileEpilFileName ,'file','y');
// ------------------------------
// --- Insert for expression. ---
// ------------------------------
-CCall = 'while('+SharedInfo.WhileExpr.CondVar+')';
+//CCall = 'while('+SharedInfo.WhileExpr.CondVar+')';
+//PrintStringInfo(C_IndentBlanks(SharedInfo.NIndent)+CCall,CPass1FileName,'file','y');
+
+i=1;
+k=1;
+CCall ='';
+CCall = CCall+'while';
+ CCall = CCall+'(';
+ while i <= NIfCondArg
+ CCall = CCall + IfCondArg(i) + ' ';
+ //d = modulo(i,3);
+ //PrintStringInfo(' '+string(i)+string(d),'file','y');
+ if (modulo(i,3)==0 & i<>NIfCondArg)
+ CCall = CCall + Op(k) + ' ';
+ k = k + 1;
+ end
+ i = i + 1;
+ end
+ CCall = CCall+')';
+
+PrintStringInfo(' '+CCall,ReportFileName,'file','y');
PrintStringInfo(C_IndentBlanks(SharedInfo.NIndent)+CCall,CPass1FileName,'file','y');
// -------------------
diff --git a/macros/CCodeGeneration/GetClsFileName.sci b/macros/CCodeGeneration/GetClsFileName.sci
index 46f0820..d92a431 100644
--- a/macros/CCodeGeneration/GetClsFileName.sci
+++ b/macros/CCodeGeneration/GetClsFileName.sci
@@ -45,6 +45,7 @@ if SCI2Cfileexist(FileInfo.USER2CLibCAnnFun,tmpannfilename)
// #RNU_RES_B
// It is a C function of the USER2C library.
// #RNU_RES_E
+ PrintStringInfo('cUser2c',ReportFileName,'file','y');
FlagFoundAnnFile = 1;
AnnFileName = fullfile(FileInfo.USER2CLibCAnnFun,tmpannfilename);
SCI2CClassName = FL_GetFunctionClass(AnnFileName,SCI2CClassSpecifier,ReportFileName);
@@ -53,6 +54,7 @@ elseif SCI2Cfileexist(FileInfo.USER2CLibSCIAnnFun,tmpannfilename)
// #RNU_RES_B
// It is a scilab function of the USER2C library.
// #RNU_RES_E
+ PrintStringInfo('fUser2c',ReportFileName,'file','y');
FlagFoundAnnFile = 1;
AnnFileName = fullfile(FileInfo.USER2CLibSCIAnnFun,tmpannfilename);
SCI2CClassName = FL_GetFunctionClass(AnnFileName,SCI2CClassSpecifier,ReportFileName);
@@ -61,6 +63,7 @@ elseif (SCI2Cfileexist(FileInfo.SCI2CLibCAnnFun,tmpannfilename))
// #RNU_RES_B
// It is a C function of the SCI2C library.
// #RNU_RES_E
+ PrintStringInfo('csci2c',ReportFileName,'file','y');
FlagFoundAnnFile = 1;
AnnFileName = fullfile(FileInfo.SCI2CLibCAnnFun,tmpannfilename);
SCI2CClassName = FL_GetFunctionClass(AnnFileName,SCI2CClassSpecifier,ReportFileName);
@@ -69,6 +72,7 @@ elseif (SCI2Cfileexist(FileInfo.SCI2CLibSCIAnnFun,tmpannfilename))
// #RNU_RES_B
// It is a scilab function of the SCI2C library.
// #RNU_RES_E
+ PrintStringInfo('fsci2c',ReportFileName,'file','y');
FlagFoundAnnFile = 1;
AnnFileName = fullfile(FileInfo.SCI2CLibSCIAnnFun,tmpannfilename);
SCI2CClassName = FL_GetFunctionClass(AnnFileName,SCI2CClassSpecifier,ReportFileName);
diff --git a/macros/CCodeGeneration/lib b/macros/CCodeGeneration/lib
index edcb004..2db4b8c 100644
--- a/macros/CCodeGeneration/lib
+++ b/macros/CCodeGeneration/lib
Binary files differ
diff --git a/macros/CCodeGeneration/names b/macros/CCodeGeneration/names
index efbb400..56caa81 100644
--- a/macros/CCodeGeneration/names
+++ b/macros/CCodeGeneration/names
@@ -2,10 +2,12 @@ C_FinalizeCode
C_ForExpression
C_Funcall
C_GenDeclarations
+C_GenDeclarations_Dup
C_GenerateFunName
C_GenerateLaunchScript
C_GenerateMakefile
C_GenerateMakefile_msvc
+C_GenerateMkfle_arduino
C_GenerateSCI2CHeader
C_IfElseBlocks
C_IfExpression