[llvm-commits] CVS: llvm-java/lib/Compiler/OperandStack.h OperandStack.cpp Locals.h Locals.cpp
Alkis Evlogimenos
alkis at cs.uiuc.edu
Fri Oct 15 19:38:17 PDT 2004
Changes in directory llvm-java/lib/Compiler:
OperandStack.h added (r1.1)
OperandStack.cpp added (r1.1)
Locals.h added (r1.1)
Locals.cpp added (r1.1)
---
Log message:
Add OperandStack and Locals abstractions for use wit hthe upcoming
changes to the java bytecode to LLVM compiler.
---
Diffs of the changes: (+179 -0)
Index: llvm-java/lib/Compiler/OperandStack.h
diff -c /dev/null llvm-java/lib/Compiler/OperandStack.h:1.1
*** /dev/null Fri Oct 15 21:38:17 2004
--- llvm-java/lib/Compiler/OperandStack.h Fri Oct 15 21:38:07 2004
***************
*** 0 ****
--- 1,49 ----
+ //===-- OperandStack.h - Java operand stack ---------------------*- C++ -*-===//
+ //
+ // The LLVM Compiler Infrastructure
+ //
+ // This file was developed by the LLVM research group and is distributed under
+ // the University of Illinois Open Source License. See LICENSE.TXT for details.
+ //
+ //===----------------------------------------------------------------------===//
+ //
+ // This file contains the abstraction of a Java operand stack. We
+ // model the java operand stack as a stack of LLVM allocas.
+ //
+ //===----------------------------------------------------------------------===//
+
+ #ifndef LLVM_JAVA_OPERANDSTACK_H
+ #define LLVM_JAVA_OPERANDSTACK_H
+
+ #include <llvm/Value.h>
+ #include <llvm/Instruction.h>
+ #include <llvm/Java/Bytecode.h>
+
+ #include <stack>
+
+ namespace llvm {
+
+ class AllocaInst;
+
+ } // namespace llvm
+
+ namespace llvm { namespace Java {
+
+ class OperandStack {
+ std::stack<AllocaInst*, std::vector<AllocaInst*> > TheStack;
+
+ public:
+ /// @brief - Pushes the value \c value on the virtual operand
+ /// stack and appends any instructions to implement this to \c
+ /// insertAtEnd BasicBlock
+ void push(Value* value, BasicBlock* insertAtEnd);
+
+ /// @brief - Pops a value from the virtual operand stack and
+ /// appends any instructions to implement this to \c insertAtEnd
+ /// BasicBlock
+ Value* pop(BasicBlock* insertAtEnd);
+ };
+
+ } } // namespace llvm::Java
+
+ #endif//LLVM_JAVA_OPERANDSTACK_H
Index: llvm-java/lib/Compiler/OperandStack.cpp
diff -c /dev/null llvm-java/lib/Compiler/OperandStack.cpp:1.1
*** /dev/null Fri Oct 15 21:38:17 2004
--- llvm-java/lib/Compiler/OperandStack.cpp Fri Oct 15 21:38:07 2004
***************
*** 0 ****
--- 1,36 ----
+ //===-- OperandStack.cpp - Java operand stack -----------------------------===//
+ //
+ // The LLVM Compiler Infrastructure
+ //
+ // This file was developed by the LLVM research group and is distributed under
+ // the University of Illinois Open Source License. See LICENSE.TXT for details.
+ //
+ //===----------------------------------------------------------------------===//
+ //
+ // This file contains the abstraction of a Java operand stack. We
+ // model the java operand stack as a stack of LLVM allocas.
+ //
+ //===----------------------------------------------------------------------===//
+
+ #include "OperandStack.h"
+ #include <llvm/DerivedTypes.h>
+ #include <llvm/Instructions.h>
+ #include <llvm/ADT/StringExtras.h>
+
+ using namespace llvm::Java;
+
+ void OperandStack::push(Value* value, BasicBlock* insertAtEnd)
+ {
+ TheStack.push(new AllocaInst(value->getType(),
+ NULL,
+ "opStack" + utostr(TheStack.size()),
+ insertAtEnd));
+ new StoreInst(value, TheStack.top(), false, insertAtEnd);
+ }
+
+ llvm::Value* OperandStack::pop(BasicBlock* insertAtEnd)
+ {
+ Value* val = TheStack.top();
+ TheStack.pop();
+ return new LoadInst(val, "pop", false, insertAtEnd);
+ }
Index: llvm-java/lib/Compiler/Locals.h
diff -c /dev/null llvm-java/lib/Compiler/Locals.h:1.1
*** /dev/null Fri Oct 15 21:38:17 2004
--- llvm-java/lib/Compiler/Locals.h Fri Oct 15 21:38:07 2004
***************
*** 0 ****
--- 1,50 ----
+ //===-- Locals.h - Java locals ----------------------------------*- C++ -*-===//
+ //
+ // The LLVM Compiler Infrastructure
+ //
+ // This file was developed by the LLVM research group and is distributed under
+ // the University of Illinois Open Source License. See LICENSE.TXT for details.
+ //
+ //===----------------------------------------------------------------------===//
+ //
+ // This file contains the abstraction of Java locals. We model the
+ // locals as an array of lazily created allocas.
+ //
+ //===----------------------------------------------------------------------===//
+
+ #ifndef LLVM_JAVA_LOCALS_H
+ #define LLVM_JAVA_LOCALS_H
+
+ #include <llvm/Java/Bytecode.h>
+ #include <vector>
+
+ namespace llvm {
+
+ class AllocaInst;
+ class BasicBlock;
+ class Value;
+
+ } // namespace llvm
+
+ namespace llvm { namespace Java {
+
+ class Locals {
+ std::vector<AllocaInst*> TheLocals;
+
+ public:
+ explicit Locals(unsigned maxLocals);
+
+ /// @brief - Stores the value \c value on the \c i'th local
+ /// variable and appends any instructions to implement this to \c
+ /// insertAtEnd BasicBlock
+ void store(unsigned i, Value* value, BasicBlock* insertAtEnd);
+
+ /// @brief - Loads the value of the \c i'th local variable and
+ /// appends any instructions to implement this to \c insertAtEnd
+ /// BasicBlock
+ Value* load(unsigned i, BasicBlock* insertAtEnd);
+ };
+
+ } } // namespace llvm::Java
+
+ #endif//LLVM_JAVA_LOCALS_H
Index: llvm-java/lib/Compiler/Locals.cpp
diff -c /dev/null llvm-java/lib/Compiler/Locals.cpp:1.1
*** /dev/null Fri Oct 15 21:38:17 2004
--- llvm-java/lib/Compiler/Locals.cpp Fri Oct 15 21:38:07 2004
***************
*** 0 ****
--- 1,44 ----
+ //===-- Locals.h - Java locals ----------------------------------*- C++ -*-===//
+ //
+ // The LLVM Compiler Infrastructure
+ //
+ // This file was developed by the LLVM research group and is distributed under
+ // the University of Illinois Open Source License. See LICENSE.TXT for details.
+ //
+ //===----------------------------------------------------------------------===//
+ //
+ // This file contains the abstraction of Java locals. We model the
+ // locals as an array of lazily created allocas.
+ //
+ //===----------------------------------------------------------------------===//
+
+ #include "Locals.h"
+ #include <llvm/DerivedTypes.h>
+ #include <llvm/Instructions.h>
+ #include <llvm/ADT/StringExtras.h>
+
+ using namespace llvm::Java;
+
+ Locals::Locals(unsigned maxLocals)
+ : TheLocals(maxLocals)
+ {
+
+ }
+
+ void Locals::store(unsigned i, Value* value, BasicBlock* insertAtEnd)
+ {
+ if (!TheLocals[i] ||
+ TheLocals[i]->getType()->getElementType() != value->getType())
+ TheLocals[i] = new AllocaInst(value->getType(),
+ NULL,
+ "local" + utostr(i),
+ insertAtEnd);
+
+ new StoreInst(value, TheLocals[i], false, insertAtEnd);
+ }
+
+ llvm::Value* Locals::load(unsigned i, BasicBlock* insertAtEnd)
+ {
+ assert(TheLocals[i] && "Attempt to load a non initialized global!");
+ return new LoadInst(TheLocals[i], "load", false, insertAtEnd);
+ }
More information about the llvm-commits
mailing list