[llvm-commits] [hlvm] r38147 - in /hlvm/trunk/hlvm/Runtime: FileIO.cpp FileIO.h Main.cpp Main.h Memory.cpp Memory.h Program.cpp Program.h String.h
Reid Spencer
reid at x10sys.com
Sat Jul 7 17:00:27 PDT 2007
Author: reid
Date: Sat Jul 7 19:00:27 2007
New Revision: 38147
URL: http://llvm.org/viewvc/llvm-project?rev=38147&view=rev
Log:
Add more runtime functionality:
1. Memory allocation
2. Finding the program to run
3. Handling the main program
4. Naming cleanups in FileIO and String.
Added:
hlvm/trunk/hlvm/Runtime/Main.cpp
hlvm/trunk/hlvm/Runtime/Main.h
hlvm/trunk/hlvm/Runtime/Memory.cpp
hlvm/trunk/hlvm/Runtime/Memory.h
hlvm/trunk/hlvm/Runtime/Program.cpp
hlvm/trunk/hlvm/Runtime/Program.h
Modified:
hlvm/trunk/hlvm/Runtime/FileIO.cpp
hlvm/trunk/hlvm/Runtime/FileIO.h
hlvm/trunk/hlvm/Runtime/String.h
Modified: hlvm/trunk/hlvm/Runtime/FileIO.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/Runtime/FileIO.cpp?rev=38147&r1=38146&r2=38147&view=diff
==============================================================================
--- hlvm/trunk/hlvm/Runtime/FileIO.cpp (original)
+++ hlvm/trunk/hlvm/Runtime/FileIO.cpp Sat Jul 7 19:00:27 2007
@@ -38,18 +38,18 @@
{
void*
-_hlvm_op_file_open(_hlvm_ty_string* uri)
+hlvm_op_file_open(hlvm_string* uri)
{
return 0;
}
void
-_hlvm_op_file_close(void* fnum)
+hlvm_op_file_close(void* fnum)
{
}
uint32_t
-_hovm_op_file_write(void* fnum, void* data, size_t len)
+hovm_op_file_write(void* fnum, void* data, size_t len)
{
return 0;
}
Modified: hlvm/trunk/hlvm/Runtime/FileIO.h
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/Runtime/FileIO.h?rev=38147&r1=38146&r2=38147&view=diff
==============================================================================
--- hlvm/trunk/hlvm/Runtime/FileIO.h (original)
+++ hlvm/trunk/hlvm/Runtime/FileIO.h Sat Jul 7 19:00:27 2007
@@ -35,11 +35,11 @@
extern "C"
{
-void* _hlvm_op_file_open(_hlvm_ty_string* uri);
+void* hlvm_op_file_open(hlvm_string* uri);
-uint32_t _hovm_op_file_write(void* file, void* data, size_t len);
+uint32_t hlvm_op_file_write(void* file, void* data, size_t len);
-void _hlvm_op_file_close(void* file);
+void hlvm_op_file_close(void* file);
}
#endif
Added: hlvm/trunk/hlvm/Runtime/Main.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/Runtime/Main.cpp?rev=38147&view=auto
==============================================================================
--- hlvm/trunk/hlvm/Runtime/Main.cpp (added)
+++ hlvm/trunk/hlvm/Runtime/Main.cpp Sat Jul 7 19:00:27 2007
@@ -0,0 +1,92 @@
+//===-- Runtime Main Implementation -----------------------------*- C++ -*-===//
+//
+// High Level Virtual Machine (HLVM)
+//
+// Copyright (C) 2006 Reid Spencer. All Rights Reserved.
+//
+// This software 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; either version 2.1 of the License, or (at
+// your option) any later version.
+//
+// This software 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 in the file named LICENSE.txt; if not, write to the
+// Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+// MA 02110-1301 USA
+//
+//===----------------------------------------------------------------------===//
+/// @file hlvm/Runtime/Main.cpp
+/// @author Reid Spencer <rspencer at reidspencer.org> (original author)
+/// @date 2006/06/04
+/// @since 0.1.0
+/// @brief Implements the runtime main program.
+//===----------------------------------------------------------------------===//
+
+#include <hlvm/Base/Memory.h>
+#include <hlvm/Runtime/Main.h>
+#include <hlvm/Runtime/Program.h>
+#include <hlvm/Runtime/Memory.h>
+#include <llvm/Support/CommandLine.h>
+#include <string.h>
+#include <iostream>
+
+namespace {
+
+using namespace llvm;
+
+static cl::opt<std::string>
+ProgramToRun(cl::Positional, cl::desc("URI of program to run"));
+
+class Main {
+ int argc;
+ char ** argv;
+public:
+ Main(int ac, char**av) : argc(ac), argv(av) {
+ llvm::cl::ParseCommandLineOptions(argc,argv,"High Level Virtual Machine\n");
+ }
+ int run() {
+ hlvm_program_type func = hlvm_find_program(ProgramToRun.c_str());
+ if (func) {
+ hlvm_program_args args;
+ args.argc = argc - 1;
+ args.argv = (hlvm_string*)
+ hlvm_allocate_array(argc-1, sizeof(hlvm_string));
+ for (unsigned i = 0; i < args.argc; i++) {
+ uint64_t len = strlen(argv[i]);
+ args.argv[i].len = len;
+ args.argv[i].str = (const char*)
+ hlvm_allocate_array(len, sizeof(args.argv[i].str[0]));
+ }
+ return (*func)(&args);
+ } else {
+ std::cerr << argv[0] << ": Program '" << ProgramToRun << "' not found.\n";
+ return 1;
+ }
+ }
+};
+
+}
+
+extern "C" {
+
+int hlvm_runtime_main(int argc, char**argv)
+{
+ int result = 0;
+ try {
+ hlvm::initialize(argc,argv);
+ Main main(argc,argv);
+ result = main.run();
+ } catch (const std::string& msg) {
+ std::cerr << argv[0] << ": " << msg;
+ } catch (...) {
+ std::cerr << argv[0] << ": Unhandled exception\n";
+ }
+ return result;
+}
+
+}
Added: hlvm/trunk/hlvm/Runtime/Main.h
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/Runtime/Main.h?rev=38147&view=auto
==============================================================================
--- hlvm/trunk/hlvm/Runtime/Main.h (added)
+++ hlvm/trunk/hlvm/Runtime/Main.h Sat Jul 7 19:00:27 2007
@@ -0,0 +1,39 @@
+//===-- Runtime Main Program ------------------------------------*- C++ -*-===//
+//
+// High Level Virtual Machine (HLVM)
+//
+// Copyright (C) 2006 Reid Spencer. All Rights Reserved.
+//
+// This software 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; either version 2.1 of the License, or (at
+// your option) any later version.
+//
+// This software 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 in the file named LICENSE.txt; if not, write to the
+// Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+// MA 02110-1301 USA
+//
+//===----------------------------------------------------------------------===//
+/// @file hlvm/Runtime/Main.h
+/// @author Reid Spencer <rspencer at reidspencer.com> (original author)
+/// @date 2006/05/24
+/// @since 0.1.0
+/// @brief Declares the interface to the runtime main program
+//===----------------------------------------------------------------------===//
+
+#ifndef HLVM_RUNTIME_MAIN_H
+#define HLVM_RUNTIME_MAIN_H
+
+extern "C" {
+
+int hlvm_runtime_main(int argc, char**argv);
+
+}
+
+#endif
Added: hlvm/trunk/hlvm/Runtime/Memory.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/Runtime/Memory.cpp?rev=38147&view=auto
==============================================================================
--- hlvm/trunk/hlvm/Runtime/Memory.cpp (added)
+++ hlvm/trunk/hlvm/Runtime/Memory.cpp Sat Jul 7 19:00:27 2007
@@ -0,0 +1,49 @@
+//===-- Runtime Memory Management Implementation ----------------*- C++ -*-===//
+//
+// High Level Virtual Machine (HLVM)
+//
+// Copyright (C) 2006 Reid Spencer. All Rights Reserved.
+//
+// This software 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; either version 2.1 of the License, or (at
+// your option) any later version.
+//
+// This software 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 in the file named LICENSE.txt; if not, write to the
+// Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+// MA 02110-1301 USA
+//
+//===----------------------------------------------------------------------===//
+/// @file hlvm/Runtime/Program.cpp
+/// @author Reid Spencer <rspencer at reidspencer.org> (original author)
+/// @date 2006/06/04
+/// @since 0.1.0
+/// @brief Implements the runtime memory management facilities.
+//===----------------------------------------------------------------------===//
+
+#include <hlvm/Runtime/Memory.h>
+#include <stdlib.h>
+
+namespace {
+
+
+}
+
+extern "C" {
+
+void* hlvm_allocate_array(uint64_t count, uint64_t elemSize) {
+ return malloc (count * elemSize);
+}
+
+void hlvm_deallocate_array(void* ptr) {
+ free(ptr);
+ return;
+}
+
+}
Added: hlvm/trunk/hlvm/Runtime/Memory.h
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/Runtime/Memory.h?rev=38147&view=auto
==============================================================================
--- hlvm/trunk/hlvm/Runtime/Memory.h (added)
+++ hlvm/trunk/hlvm/Runtime/Memory.h Sat Jul 7 19:00:27 2007
@@ -0,0 +1,43 @@
+//===-- Runtime Program Interface -------------------------------*- C++ -*-===//
+//
+// High Level Virtual Machine (HLVM)
+//
+// Copyright (C) 2006 Reid Spencer. All Rights Reserved.
+//
+// This software 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; either version 2.1 of the License, or (at
+// your option) any later version.
+//
+// This software 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 in the file named LICENSE.txt; if not, write to the
+// Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+// MA 02110-1301 USA
+//
+//===----------------------------------------------------------------------===//
+/// @file hlvm/Runtime/Program.h
+/// @author Reid Spencer <rspencer at reidspencer.com> (original author)
+/// @date 2006/05/24
+/// @since 0.1.0
+/// @brief Declares the interface to the runtime program facilities
+//===----------------------------------------------------------------------===//
+
+#ifndef HLVM_RUNTIME_MEMORY_H
+#define HLVM_RUNTIME_MEMORY_H
+
+#include <llvm/Support/DataTypes.h>
+
+extern "C" {
+
+void* hlvm_allocate_array(uint64_t count, uint64_t elemSize);
+
+void hlvm_deallocate_array(void* ptr);
+
+}
+
+#endif
Added: hlvm/trunk/hlvm/Runtime/Program.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/Runtime/Program.cpp?rev=38147&view=auto
==============================================================================
--- hlvm/trunk/hlvm/Runtime/Program.cpp (added)
+++ hlvm/trunk/hlvm/Runtime/Program.cpp Sat Jul 7 19:00:27 2007
@@ -0,0 +1,53 @@
+//===-- Runtime Program Implementation --------------------------*- C++ -*-===//
+//
+// High Level Virtual Machine (HLVM)
+//
+// Copyright (C) 2006 Reid Spencer. All Rights Reserved.
+//
+// This software 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; either version 2.1 of the License, or (at
+// your option) any later version.
+//
+// This software 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 in the file named LICENSE.txt; if not, write to the
+// Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+// MA 02110-1301 USA
+//
+//===----------------------------------------------------------------------===//
+/// @file hlvm/Runtime/Program.cpp
+/// @author Reid Spencer <rspencer at reidspencer.org> (original author)
+/// @date 2006/06/04
+/// @since 0.1.0
+/// @brief Implements the runtime program facilities.
+//===----------------------------------------------------------------------===//
+
+#include <hlvm/Runtime/Program.h>
+#include <llvm/Support/CommandLine.h>
+
+namespace {
+
+
+}
+
+extern "C" {
+
+hlvm_programs_element hlvm_programs[1];
+
+hlvm_program_type
+hlvm_find_program(const char* uri)
+{
+ hlvm_programs_element* p = &hlvm_programs[0];
+ while (p && p->program_entry) {
+ if (strcmp(p->program_name,uri) == 0)
+ return p->program_entry;
+ }
+ return 0;
+}
+
+}
Added: hlvm/trunk/hlvm/Runtime/Program.h
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/Runtime/Program.h?rev=38147&view=auto
==============================================================================
--- hlvm/trunk/hlvm/Runtime/Program.h (added)
+++ hlvm/trunk/hlvm/Runtime/Program.h Sat Jul 7 19:00:27 2007
@@ -0,0 +1,55 @@
+//===-- Runtime Program Interface -------------------------------*- C++ -*-===//
+//
+// High Level Virtual Machine (HLVM)
+//
+// Copyright (C) 2006 Reid Spencer. All Rights Reserved.
+//
+// This software 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; either version 2.1 of the License, or (at
+// your option) any later version.
+//
+// This software 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 in the file named LICENSE.txt; if not, write to the
+// Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+// MA 02110-1301 USA
+//
+//===----------------------------------------------------------------------===//
+/// @file hlvm/Runtime/Program.h
+/// @author Reid Spencer <rspencer at reidspencer.com> (original author)
+/// @date 2006/05/24
+/// @since 0.1.0
+/// @brief Declares the interface to the runtime program facilities
+//===----------------------------------------------------------------------===//
+
+#ifndef HLVM_RUNTIME_PROGRAM_H
+#define HLVM_RUNTIME_PROGRAM_H
+
+#include <hlvm/Runtime/String.h>
+
+extern "C" {
+
+struct hlvm_program_args {
+ uint32_t argc;
+ hlvm_string* argv;
+};
+
+typedef uint32_t (*hlvm_program_type)(hlvm_program_args* args);
+
+struct hlvm_programs_element {
+ const char* program_name;
+ hlvm_program_type program_entry;
+};
+
+extern hlvm_programs_element hlvm_programs[];
+
+extern hlvm_program_type hlvm_find_program(const char* uri);
+
+}
+
+#endif
Modified: hlvm/trunk/hlvm/Runtime/String.h
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/Runtime/String.h?rev=38147&r1=38146&r2=38147&view=diff
==============================================================================
--- hlvm/trunk/hlvm/Runtime/String.h (original)
+++ hlvm/trunk/hlvm/Runtime/String.h Sat Jul 7 19:00:27 2007
@@ -34,7 +34,7 @@
extern "C" {
-struct _hlvm_ty_string {
+struct hlvm_string {
uint64_t len;
const char* str;
};
More information about the llvm-commits
mailing list