[opengtl-commits] [171] start adding a shiva command line processor

[ Thread Index | Date Index | More lists.tuxfamily.org/opengtl-commits Archives ]


Revision: 171
Author:   cyrille
Date:     2008-05-19 11:09:36 +0200 (Mon, 19 May 2008)

Log Message:
-----------
start adding a shiva command line processor

Modified Paths:
--------------
    trunk/OpenGTL/OpenShiva/tools/CMakeLists.txt
    trunk/OpenGTL/OpenShiva/tools/compiler/ShivaC.cpp
    trunk/OpenGTL/OpenShiva/tools/interpreter/CMakeLists.txt

Added Paths:
-----------
    trunk/OpenGTL/OpenShiva/tools/interpreter/Shiva.cpp

Removed Paths:
-------------
    trunk/OpenGTL/OpenShiva/tools/interpreter/ShivaI.cpp


Modified: trunk/OpenGTL/OpenShiva/tools/CMakeLists.txt
===================================================================
--- trunk/OpenGTL/OpenShiva/tools/CMakeLists.txt	2008-05-19 08:41:33 UTC (rev 170)
+++ trunk/OpenGTL/OpenShiva/tools/CMakeLists.txt	2008-05-19 09:09:36 UTC (rev 171)
@@ -1 +1,2 @@
 add_subdirectory(compiler)
+add_subdirectory(interpreter)

Modified: trunk/OpenGTL/OpenShiva/tools/compiler/ShivaC.cpp
===================================================================
--- trunk/OpenGTL/OpenShiva/tools/compiler/ShivaC.cpp	2008-05-19 08:41:33 UTC (rev 170)
+++ trunk/OpenGTL/OpenShiva/tools/compiler/ShivaC.cpp	2008-05-19 09:09:36 UTC (rev 171)
@@ -21,7 +21,7 @@
 #include <iostream>
 #include <fstream>
 
-// OpenCTL Headers
+// OpenShiva Headers
 #include <OpenShiva/Kernel.h>
 #include <OpenShiva/Version.h>
 
@@ -33,7 +33,7 @@
 }
 void printHelp()
 {
-  std::cout << "Usage : shivac [option] fileName.ctl" << std::endl;
+  std::cout << "Usage : shivac [option] fileName.shiva" << std::endl;
   std::cout << std::endl;
   std::cout << "Options : " << std::endl;
   std::cout << "  -S --asm-source         print the assembly source code generated" << std::endl;

Modified: trunk/OpenGTL/OpenShiva/tools/interpreter/CMakeLists.txt
===================================================================
--- trunk/OpenGTL/OpenShiva/tools/interpreter/CMakeLists.txt	2008-05-19 08:41:33 UTC (rev 170)
+++ trunk/OpenGTL/OpenShiva/tools/interpreter/CMakeLists.txt	2008-05-19 09:09:36 UTC (rev 171)
@@ -0,0 +1,9 @@
+include_directories( ${CMAKE_SOURCE_DIR} )
+
+set(shiva_SRCS
+  Shiva.cpp
+    )
+
+add_executable(shiva ${shiva_SRCS})
+target_link_libraries(shiva OpenShiva )
+install( TARGETS shiva DESTINATION ${BIN_INSTALL_DIR} )

Copied: trunk/OpenGTL/OpenShiva/tools/interpreter/Shiva.cpp (from rev 166, trunk/OpenGTL/OpenShiva/tools/interpreter/ShivaI.cpp)
===================================================================
--- trunk/OpenGTL/OpenShiva/tools/interpreter/Shiva.cpp	                        (rev 0)
+++ trunk/OpenGTL/OpenShiva/tools/interpreter/Shiva.cpp	2008-05-19 09:09:36 UTC (rev 171)
@@ -0,0 +1,115 @@
+/*
+ *  Copyright (c) 2008 Cyrille Berger <cberger@xxxxxxxxxxx>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2 of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; see the file COPYING.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+// C++ Headers
+#include <iostream>
+#include <fstream>
+
+// OpenShiva Headers
+#include <OpenShiva/Debug.h>
+#include <OpenShiva/Kernel.h>
+#include <OpenShiva/Version.h>
+
+void printVersion()
+{
+  std::cout << OpenShiva::LibraryShortName << " - " << OpenShiva::LibraryName << " - " << OpenShiva::LibraryVersionString << std::endl;
+  std::cout << OpenShiva::LibraryCopyright << std::endl;
+  std::cout << "Shiva Version : " << OpenShiva::LanguageVersion << std::endl;
+}
+void printHelp()
+{
+  std::cout << "Usage : shiva [option] fileName.shiva [input0.png input1.png ...] output.png" << std::endl;
+  std::cout << std::endl;
+  std::cout << "Options : " << std::endl;
+//   std::cout << "  -L --module-dir   add a location where to find modules" << std::endl;
+  std::cout << std::endl;
+  std::cout << "  -h --help               print this message" << std::endl;
+  std::cout << "  -v --version            print the version information" << std::endl;
+}
+#define ARG_IS(a,b) argv[ai] == GTLCore::String(a) or argv[ai] == GTLCore::String(b)
+
+int main(char argc, char** argv)
+{
+  GTLCore::String fileName = "";
+  GTLCore::String output = "";
+  bool showAssembly = false;
+  for(int ai = 1; ai < argc; ai++)
+  {
+    if(ARG_IS("-h","--help"))
+    {
+      printHelp();
+      return EXIT_SUCCESS;
+    } else if(ARG_IS("-v","--version"))
+    {
+      printVersion();
+      return EXIT_SUCCESS;
+    } else if(ARG_IS("-L", "--module-dir")) {
+      if( ai == argc )
+      {
+        std::cerr << "Expected directory after -L --module-dir." << std::endl;
+        return EXIT_FAILURE;
+      } else {
+        ++ai;
+//         OpenShiva::ModulesManager::instance()->addDirectory(argv[ai]);
+      }
+    } else {
+      SHIVA_DEBUG( ai << " " << (int)argc << " " << ( ai > argc - 2) );
+      if( ai > argc - 2)
+      {
+        std::cerr << "Invalid command line parameters." << std::endl;
+      } else {
+        fileName = argv[ai];
+      }
+      break;
+    }
+  }
+  if( fileName == "")
+  {
+    printHelp();
+  } else {
+    GTLCore::String source;
+    std::ifstream in;
+    in.open(fileName.c_str() );
+    if(not in)
+    {
+      std::cerr << "Impossible to open file " << fileName << std::endl;
+      return EXIT_FAILURE;
+    }
+    GTLCore::String str;
+    std::getline(in,str);
+    while ( in ) {
+      source += str;
+      source += "\n";
+      std::getline(in,str);
+    }
+    OpenShiva::Kernel p(fileName);
+    p.setSource( source );
+    p.compile();
+    if(not p.isCompiled())
+    {
+      std::cout << "Error: " << std::endl << p.compilationErrorsMessage() << std::endl;
+      return EXIT_FAILURE;
+    }
+    if( showAssembly )
+    {
+      std::cout << p.asmSourceCode();
+    }
+  }
+  return EXIT_SUCCESS;
+}

Deleted: trunk/OpenGTL/OpenShiva/tools/interpreter/ShivaI.cpp
===================================================================


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/