diff options
Diffstat (limited to 'src/Scilab2C/SCI2CGeneral')
-rw-r--r-- | src/Scilab2C/SCI2CGeneral/Array2String.sci | 30 | ||||
-rw-r--r-- | src/Scilab2C/SCI2CGeneral/InitializeSCI2C.sci | 106 | ||||
-rw-r--r-- | src/Scilab2C/SCI2CGeneral/PrintStepInfo.sci | 58 | ||||
-rw-r--r-- | src/Scilab2C/SCI2CGeneral/SCI2CInputParameters.sce | 14 | ||||
-rw-r--r-- | src/Scilab2C/SCI2CGeneral/Scilab2CLoader.sce | 57 | ||||
-rw-r--r-- | src/Scilab2C/SCI2CGeneral/UpdateSCI2CInfo.sci | 86 |
6 files changed, 351 insertions, 0 deletions
diff --git a/src/Scilab2C/SCI2CGeneral/Array2String.sci b/src/Scilab2C/SCI2CGeneral/Array2String.sci new file mode 100644 index 00000000..1fd15f66 --- /dev/null +++ b/src/Scilab2C/SCI2CGeneral/Array2String.sci @@ -0,0 +1,30 @@ +function [StringArray] = Array2String(InArray);
+// function [StringArray] = Array2String(InArray);
+// -----------------------------------------------------------------
+// Converts an input array into a string. Maximum 2D array are allowed.
+// Ex.: InArray = [10, 4];
+// StringArray = "[10, 4]";
+//
+// Input data:
+// InArray: Input array.
+//
+// Output data:
+// StringArray: array converted into a string.
+//
+// Status:
+// 13-May-2007 -- Nutricato Raffaele: Author.
+// -----------------------------------------------------------------
+
+[Nrows,Ncols] = size(InArray);
+
+StringArray = '[';
+for counterrows = 1:Nrows
+ for countercols = 1:Ncols
+ StringArray = StringArray + string(InArray(counterrows,countercols)) + ',';
+ end
+ StringArray = part(StringArray,1:(length(StringArray)-1)); // Remove the last ','
+ StringArray = StringArray+';';
+end
+StringArray = part(StringArray,1:(length(StringArray)-1)); // Remove the last ';'
+StringArray = StringArray+']';
+endfunction
diff --git a/src/Scilab2C/SCI2CGeneral/InitializeSCI2C.sci b/src/Scilab2C/SCI2CGeneral/InitializeSCI2C.sci new file mode 100644 index 00000000..db3a459c --- /dev/null +++ b/src/Scilab2C/SCI2CGeneral/InitializeSCI2C.sci @@ -0,0 +1,106 @@ +function [FileInfoDatFile,SharedInfoDatFile] = InitializeSCI2C(SCI2CInputPrmFile);
+// function [FileInfoDatFile,SharedInfoDatFile] = InitializeSCI2C(SCI2CInputPrmFile);
+// -----------------------------------------------------------------
+// This function initializes the SCI2C tool according
+// to the input parameters recorded in the SCI2CParameters.
+// All info will be stored into FileInfoDatFile.
+//
+// Input data:
+// SCI2CInputPrmFile: name of the .sce file containing input parameters.
+//
+// Output data:
+// FileInfoDatFile: name of the .dat file containing the FileInfo structure.
+// SharedInfoDatFile: it is a buffer containing parameters that are exchanged by the
+// functions of the SCI2C tool.
+// Status:
+// 13-Apr-2007 -- Nutricato Raffaele: Author.
+// -----------------------------------------------------------------
+
+// --- Read Input Parameters. ---
+exec(SCI2CInputPrmFile);
+
+FileInfoDatFile = fullfile(ResultDir,'FileInfo.dat');
+SharedInfoDatFile = fullfile(ResultDir,'SharedInfo.dat');
+
+// ----------------------------
+// --- Initialize FileInfo. ---
+// ----------------------------
+FileInfo.FileInfoDatFile = FileInfoDatFile;
+FileInfo.SharedInfoDatFile = SharedInfoDatFile;
+FileInfo.ResultDir = ResultDir;
+FileInfo.SCI2CLibAnnDirName = fullfile(FileInfo.ResultDir,'SCI2CLibAnnotations');
+FileInfo.USER2CLibAnnDirName = fullfile(FileInfo.ResultDir,'USER2CLibAnnotations');
+FileInfo.SCI2CLibTreeFileName = fullfile(FileInfo.ResultDir,'SCI2CLibTree.dat');
+FileInfo.USER2CLibTreeFileName = fullfile(FileInfo.ResultDir,'USER2CLibTree.dat');
+FileInfo.GeneralReport = fullfile(FileInfo.ResultDir,'SCI2CGeneralReport.txt');
+FileInfo.GlobalVarFileName = fullfile(FileInfo.ResultDir,'GBLVAR.dat');
+FileInfo.UserSciFilesPaths = UserSciFilesPaths;
+
+// ------------------------------
+// --- Initialize SharedInfo. ---
+// ------------------------------
+// File names of the next .sci files to be converted in AST and
+// successively into C.
+SharedInfo.Next(1).SCIFileName = ScilabMainFile;
+[scipath,funname,sciext] = fileparts(ScilabMainFile);
+SharedInfo.Next(1).SCIFunName = funname; //RN per ora no so cosa metter
+SharedInfo.Next(1).CFunName = funname; //RN per ora no so cosa metter
+SharedInfo.Next(1).InArg = 1; //RN per ora non so che mettere.
+SharedInfo.Next(1).OutArg = 1; //RN per ora non so che mettere.
+SharedInfo.NextSCIFunNumber = 1;
+
+SharedInfo.Annotations.GBLVAR = 'global';
+SharedInfo.Annotations.VARTYPE = '//_SCI2C_VARTYPE:';
+SharedInfo.Annotations.FUNNOUT = '//_SCI2C_NOUT:';
+SharedInfo.Annotations.FUNSIZE = '//_SCI2C_FUNSIZE:';
+SharedInfo.Annotations.FUNTYPE = '//_SCI2C_FUNTYPE:'; // Type includes also precision.
+
+// Info related to temp variables used in the C code.
+SharedInfo.WorkAreaSizeBytes = WorkAreaSizeBytes;
+SharedInfo.WorkAreaUsedBytes = 0;
+SharedInfo.WorkAreaName = '__WorkAreaPtr';
+SharedInfo.TotTempScalarVars = TotTempScalarVars;
+SharedInfo.UsedTempScalarVars = 0;
+SharedInfo.TempScalarVarsName = '__Scalar';
+// Info related to temp variables used in the AST reading phase.
+SharedInfo.ASTReader.UsedTempVars = 0;
+SharedInfo.ASTReader.TempVarsName = '__temp';
+SharedInfo.ASTReader.ReusableTempVars = [];//RN to be removed
+
+// ------------------------------
+// --- Initialize GlobalVars. ---
+// ------------------------------
+GlobalVars = [];
+
+// ----------------------------------------------------
+// --- Remove previous versions of SCI2C files/dir. ---
+// ----------------------------------------------------
+//SCI2Cmdelete(FileInfo.FileInfoDatFile);
+//SCI2Cmdelete(FileInfo.SharedInfoDatFile);
+//SCI2Cmdelete(FileInfo.SCI2CLibTreeFileName);
+//SCI2Cmdelete(FileInfo.USER2CLibTreeFileName);
+//SCI2Cmdelete(FileInfo.GeneralReport);
+//SCI2Cmdelete(FileInfo.GlobalVarFileName);
+disp('Removing directory: '+FileInfo.ResultDir);
+yesno=input('Are you sure [y/n]?','string');
+if (yesno=='y')
+ rmdir(FileInfo.ResultDir,'s');
+else
+ SCI2Cerror('Cannot continue, because you don''t want to delete: '+FileInfo.ResultDir);
+end
+
+// ---------------------------
+// --- Create Directories. ---
+// ---------------------------
+SCI2CCreateDir(FileInfo.ResultDir);
+SCI2CCreateDir(FileInfo.SCI2CLibAnnDirName);
+SCI2CCreateDir(FileInfo.USER2CLibAnnDirName);
+
+// ---------------------------------------------
+// --- Generate new versions of SCI2C files. ---
+// ---------------------------------------------
+save(FileInfo.FileInfoDatFile,FileInfo);
+save(FileInfo.SharedInfoDatFile,SharedInfo);
+save(FileInfo.GlobalVarFileName,GlobalVars);
+
+endfunction
diff --git a/src/Scilab2C/SCI2CGeneral/PrintStepInfo.sci b/src/Scilab2C/SCI2CGeneral/PrintStepInfo.sci new file mode 100644 index 00000000..66d0653e --- /dev/null +++ b/src/Scilab2C/SCI2CGeneral/PrintStepInfo.sci @@ -0,0 +1,58 @@ +function PrintStepInfo(inputstring,filename,outputtype);
+// function PrintStepInfo(inputstring,filename,outputtype);
+// -----------------------------------------------------------------
+// Prints a string by using a predefined format into a file or on
+// the stdout.
+//
+// Input data:
+// filename: optional parameter, that specifies the output file.
+// If filename is '' or it is not provided to the function,
+// the string will be printed on the stdout.
+// outputtype: 'file' -> prints only on file.
+// 'stdout' -> prints only on the stdout.
+// 'both' -> prints on both file and stdoud.
+// Default is 'stdout'.
+// Output data:
+//
+// Status:
+// 02-Jan-2006 -- Nutricato Raffaele: Author.
+// 02-Jan-2006 -- Nutricato Raffaele: TEST OK.
+// -----------------------------------------------------------------
+
+if argn(2) < 3
+ bothout = 'n';
+ if argn(2) < 2
+ filename = '';
+ else
+ SCI2Cerror('Incorrect number of input arguments.');
+ end
+end
+if (length(filename) == 0)
+ outputtype = 'stdout'; // Prints only on the stdout.
+end
+
+Nstars = length(inputstring);
+starstring = [];
+for counterstars = 1:Nstars
+ starstring = starstring+'*';
+end
+blankstring = [' '];
+
+if ((outputtype=='both') | (outputtype=='stdout'))
+ // disp(' ')
+ // disp(' ')
+ disp(blankstring+' '+starstring);
+ disp(blankstring+'==> '+inputstring);
+ disp(blankstring+' '+starstring);
+ // disp(' ')
+end
+
+if ((outputtype=='both') | (outputtype=='file'))
+ filenamefprintf(filename,'y',' ');
+ filenamefprintf(filename,'y',' ');
+ filenamefprintf(filename,'y',blankstring+' '+starstring);
+ filenamefprintf(filename,'y',blankstring+'==> '+inputstring);
+ filenamefprintf(filename,'y',blankstring+' '+starstring);
+ filenamefprintf(filename,'y',' ');
+end
+endfunction
diff --git a/src/Scilab2C/SCI2CGeneral/SCI2CInputParameters.sce b/src/Scilab2C/SCI2CGeneral/SCI2CInputParameters.sce new file mode 100644 index 00000000..b8771326 --- /dev/null +++ b/src/Scilab2C/SCI2CGeneral/SCI2CInputParameters.sce @@ -0,0 +1,14 @@ +// This script contains all the input parameters needed by the SCI2C tool.
+ScilabMainFile = 'C:\Nutricato\Projects\FP6_hArtes\Software\SVNScilab2C\src\Scilab2C\Tests\foo.sci'; // Input Parameter.
+
+// Directory where all the products of SCI2C tool will be written.
+ResultDir = 'Results';
+
+// Memory allocation.
+WorkAreaSizeBytes = 2000*8; // 2000 locations of double
+TotTempScalarVars = 20; // maximum number of temporary scalar variables that can be used.
+
+// Paths that contain the .sci files written by the user.
+UserSciFilesPaths = ...
+ ['C:\Nutricato\Projects\FP6_hArtes\Software\SVNScilab2C\src\Scilab2C\Tests';...
+ 'C:\Nutricato\Projects\FP6_hArtes\Software\SVNScilab2C\src\Scilab2C\'];
diff --git a/src/Scilab2C/SCI2CGeneral/Scilab2CLoader.sce b/src/Scilab2C/SCI2CGeneral/Scilab2CLoader.sce new file mode 100644 index 00000000..92fdb20a --- /dev/null +++ b/src/Scilab2C/SCI2CGeneral/Scilab2CLoader.sce @@ -0,0 +1,57 @@ +exec full_reset.sce
+mode(-1);
+clc
+
+// -------------------------
+// --- Input Parameters. ---
+// -------------------------
+// root directory.
+maindir = 'C:\Nutricato\Projects\FP6_hArtes\Software\SVNScilab2C\src\Scilab2C';
+// -----------------------------
+// --- End Input Parameters. ---
+// -----------------------------
+
+// -------------
+// --- exec. ---
+// -------------
+exec(fullfile(maindir,'ASTGenerator','%program_p.sci'));
+// -----------------
+// --- End exec. ---
+// -----------------
+
+// ---------------------------
+// --- Define Directories. ---
+// ---------------------------
+// Directory containing functions that perform general tasks.
+GeneralFunctions = 'GeneralFunctions';
+
+// Directory containing functions that perform general tasks for the SCI2C tool.
+SCI2CGeneral = 'SCI2CGeneral';
+
+// Directory containing functions that perform the C code generation for the SCI2C tool.
+Translation = 'Translation';
+
+// Directory containing functions related to the generation of the Abstract Syntactic tree.
+ASTGenerator = 'ASTGenerator'
+
+// Directory containing functions to read/generate SCI2C annotations.
+Annotations = 'Annotations';
+
+// Directory containing functions to read the AST and to generate the corresponding C code.
+AST_reader = 'ASTReader';
+// -------------------------------
+// --- End Define Directories. ---
+// -------------------------------
+
+// -------------
+// --- getd. ---
+// -------------
+getd(fullfile(maindir,GeneralFunctions));
+getd(fullfile(maindir,SCI2CGeneral));
+getd(fullfile(maindir,Translation));
+getd(fullfile(maindir,ASTGenerator));
+getd(fullfile(maindir,Annotations));
+getd(fullfile(maindir,AST_reader));
+// -----------------
+// --- End getd. ---
+// -----------------
diff --git a/src/Scilab2C/SCI2CGeneral/UpdateSCI2CInfo.sci b/src/Scilab2C/SCI2CGeneral/UpdateSCI2CInfo.sci new file mode 100644 index 00000000..d697907c --- /dev/null +++ b/src/Scilab2C/SCI2CGeneral/UpdateSCI2CInfo.sci @@ -0,0 +1,86 @@ +function UpdateSCI2CInfo(FileInfoDatFile);
+// function UpdateSCI2CInfo(FileInfoDatFile);
+// -----------------------------------------------------------------
+// Updates the FileInfo struct according to the new scilab function
+// to be converted in C.
+//
+// Input data:
+// FileInfoDatFile: name of the .dat file containing the FileInfo structure.
+// SharedInfoDatFile: it is a buffer containing parameters that are exchanged by the
+// functions of the SCI2C tool.
+//
+// Output data:
+//
+// Status:
+// 13-Apr-2007 -- Nutricato Raffaele: Author.
+// -----------------------------------------------------------------
+
+// ---------------------------------
+// --- Load File Info Structure. ---
+// ---------------------------------
+load(FileInfoDatFile,'FileInfo');
+
+// -----------------------------------
+// --- Load Shared Info Structure. ---
+// -----------------------------------
+load(FileInfo.SharedInfoDatFile,'SharedInfo');
+
+// ---------------------------------------------------
+// --- Extraction of the function name and number. ---
+// ---------------------------------------------------
+funname = SharedInfo.Next(1).SCIFunName;
+funnumber = SharedInfo.NextSCIFunNumber;
+
+PrintStepInfo('Translate function '+funname,...
+ FileInfo.GeneralReport,'both');
+
+PrintStepInfo('Update the File Info Struct.',...
+ FileInfo.GeneralReport,'both');
+
+// -----------------------------------
+// --- Update File Info structure. ---
+// -----------------------------------
+FileInfo.Funct(funnumber).Name = funname;
+FileInfo.Funct(funnumber).SCIFileName = SharedInfo.Next(1).SCIFileName;
+FileInfo.Funct(funnumber).ASTFileName = fullfile(FileInfo.ResultDir,funname,funname+'.ast');
+FileInfo.Funct(funnumber).CPass1V1FileName = fullfile(FileInfo.ResultDir,funname,funname+'_pass1V1.c');
+FileInfo.Funct(funnumber).CPass1V2FileName = fullfile(FileInfo.ResultDir,funname,funname+'_pass1V2.c');
+FileInfo.Funct(funnumber).ReportFileName = fullfile(FileInfo.ResultDir,funname,funname+'.rpt');
+FileInfo.Funct(funnumber).LocalVarFileName = fullfile(FileInfo.ResultDir,funname,funname+'_LOCVAR.dat');
+FileInfo.Funct(funnumber).TempVarFileName = fullfile(FileInfo.ResultDir,funname,funname+'_TMPVAR.dat');
+
+// --------------------------------------
+// --- Create the function directory. ---
+// --------------------------------------
+mkdir(FileInfo.ResultDir,funname);
+
+// -------------------------
+// --- Delete old files. ---
+// -------------------------
+SCI2Cmdelete(FileInfo.Funct(funnumber).ASTFileName);
+SCI2Cmdelete(FileInfo.Funct(funnumber).CPass1V1FileName);
+SCI2Cmdelete(FileInfo.Funct(funnumber).CPass1V2FileName);
+SCI2Cmdelete(FileInfo.Funct(funnumber).ReportFileName);
+SCI2Cmdelete(FileInfo.Funct(funnumber).LocalVarFileName);
+SCI2Cmdelete(FileInfo.Funct(funnumber).TempVarFileName);
+
+// -----------------------------------
+// --- Initialize Local/Temp Vars. ---
+// -----------------------------------
+LocalVars = [];
+TempVars = [];
+
+// ---------------------
+// --- Save section. ---
+// ---------------------
+// --- Save File Info Structure. ---
+save(FileInfoDatFile,FileInfo);
+
+// --- Save Local/Temp Vars. ---
+save(FileInfo.Funct(funnumber).LocalVarFileName,LocalVars);
+save(FileInfo.Funct(funnumber).TempVarFileName,TempVars);
+// -------------------------
+// --- End save section. ---
+// -------------------------
+
+endfunction |