[llvm-commits] CVS: llvm/projects/Stacker/lib/compiler/Lexer.l StackerCompiler.cpp StackerCompiler.h StackerParser.y
LLVM
llvm at cs.uiuc.edu
Sun May 9 18:20:06 PDT 2004
Changes in directory llvm/projects/Stacker/lib/compiler:
Lexer.l updated: 1.2 -> 1.3
StackerCompiler.cpp updated: 1.5 -> 1.6
StackerCompiler.h updated: 1.2 -> 1.3
StackerParser.y updated: 1.4 -> 1.5
---
Log message:
Changes to make the Stacker Stack use 64 bit values. This *should* get
around the problem with Stacker on Solaris because the Stack can handle
64-bit entries (pointer sized).
---
Diffs of the changes: (+32 -37)
Index: llvm/projects/Stacker/lib/compiler/Lexer.l
diff -u llvm/projects/Stacker/lib/compiler/Lexer.l:1.2 llvm/projects/Stacker/lib/compiler/Lexer.l:1.3
--- llvm/projects/Stacker/lib/compiler/Lexer.l:1.2 Tue Mar 30 21:49:47 2004
+++ llvm/projects/Stacker/lib/compiler/Lexer.l Sun May 9 18:20:19 2004
@@ -31,10 +31,10 @@
#include "StackerParser.h"
/* Conversion of text ints to binary */
-static uint64_t IntToVal(const char *Buffer) {
- uint64_t Result = 0;
+static int64_t IntToVal(const char *Buffer) {
+ int64_t Result = 0;
for (; *Buffer; Buffer++) {
- uint64_t OldRes = Result;
+ int64_t OldRes = Result;
Result *= 10;
Result += *Buffer-'0';
if (Result < OldRes) // Uh, oh, overflow detected!!!
@@ -44,10 +44,10 @@
}
/* Conversion of text hexadecimal ints to binary */
-static uint64_t HexIntToVal(const char *Buffer) {
- uint64_t Result = 0;
+static int64_t HexIntToVal(const char *Buffer) {
+ int64_t Result = 0;
for (; *Buffer; ++Buffer) {
- uint64_t OldRes = Result;
+ int64_t OldRes = Result;
Result *= 16;
char C = *Buffer;
if (C >= '0' && C <= '9')
Index: llvm/projects/Stacker/lib/compiler/StackerCompiler.cpp
diff -u llvm/projects/Stacker/lib/compiler/StackerCompiler.cpp:1.5 llvm/projects/Stacker/lib/compiler/StackerCompiler.cpp:1.6
--- llvm/projects/Stacker/lib/compiler/StackerCompiler.cpp:1.5 Tue Mar 30 21:49:47 2004
+++ llvm/projects/Stacker/lib/compiler/StackerCompiler.cpp Sun May 9 18:20:19 2004
@@ -60,9 +60,6 @@
, Three(0)
, Four(0)
, Five(0)
- , IZero(0)
- , IOne(0)
- , ITwo(0)
, no_arguments()
, echo(false)
, stack_size(256)
@@ -121,8 +118,8 @@
TheModule = new Module( CurFilename );
// Create a type to represent the stack. This is the same as the LLVM
- // Assembly type [ 256 x int ]
- stack_type = ArrayType::get( Type::IntTy, stack_size );
+ // Assembly type [ 256 x long ]
+ stack_type = ArrayType::get( Type::LongTy, stack_size );
// Create a global variable for the stack. Note the use of appending
// linkage linkage so that multiple modules will make the stack larger.
@@ -240,9 +237,6 @@
Three = ConstantInt::get( Type::LongTy, 3 );
Four = ConstantInt::get( Type::LongTy, 4 );
Five = ConstantInt::get( Type::LongTy, 5 );
- IZero = ConstantInt::get( Type::IntTy, 0 );
- IOne = ConstantInt::get( Type::IntTy, 1 );
- ITwo = ConstantInt::get( Type::IntTy, 2 );
// Reset the current line number
Stackerlineno = 1;
@@ -366,8 +360,8 @@
GetElementPtrInst* gep = cast<GetElementPtrInst>(
get_stack_pointer( bb ) );
- // Cast the value to an integer .. hopefully it works
- CastInst* cast_inst = new CastInst( val, Type::IntTy );
+ // Cast the value to a long .. hopefully it works
+ CastInst* cast_inst = new CastInst( val, Type::LongTy );
bb->getInstList().push_back( cast_inst );
// Store the value
@@ -378,10 +372,10 @@
}
Instruction*
-StackerCompiler::push_integer(BasicBlock* bb, int32_t value )
+StackerCompiler::push_integer(BasicBlock* bb, int64_t value )
{
// Just push a constant integer value
- return push_value( bb, ConstantSInt::get( Type::IntTy, value ) );
+ return push_value( bb, ConstantSInt::get( Type::LongTy, value ) );
}
Instruction*
@@ -639,7 +633,7 @@
// Compare the condition against 0
SetCondInst* cond_inst = new SetCondInst( Instruction::SetNE, cond,
- ConstantSInt::get( Type::IntTy, 0) );
+ ConstantSInt::get( Type::LongTy, 0) );
bb->getInstList().push_back( cond_inst );
// Create an exit block
@@ -723,7 +717,7 @@
// Compare the condition against 0
SetCondInst* cond_inst = new SetCondInst(
- Instruction::SetNE, cond, ConstantSInt::get( Type::IntTy, 0) );
+ Instruction::SetNE, cond, ConstantSInt::get( Type::LongTy, 0) );
test->getInstList().push_back( cond_inst );
// Add the branch instruction
@@ -789,7 +783,7 @@
}
BasicBlock*
-StackerCompiler::handle_integer( const int32_t value )
+StackerCompiler::handle_integer( const int64_t value )
{
// Create a new basic block for the push operation
BasicBlock* bb = new BasicBlock((echo?"int":""));
@@ -927,7 +921,7 @@
if (echo) bb->setName("INCR");
LoadInst* op1 = cast<LoadInst>(pop_integer(bb));
BinaryOperator* addop =
- BinaryOperator::create( Instruction::Add, op1, IOne );
+ BinaryOperator::create( Instruction::Add, op1, One );
bb->getInstList().push_back( addop );
push_value( bb, addop );
break;
@@ -937,7 +931,7 @@
if (echo) bb->setName("DECR");
LoadInst* op1 = cast<LoadInst>(pop_integer(bb));
BinaryOperator* subop = BinaryOperator::create( Instruction::Sub, op1,
- ConstantSInt::get( Type::IntTy, 1 ) );
+ ConstantSInt::get( Type::LongTy, 1 ) );
bb->getInstList().push_back( subop );
push_value( bb, subop );
break;
@@ -1007,7 +1001,7 @@
// bb->getInstList().push_back( negop );
// So we'll multiply by -1 (ugh)
BinaryOperator* multop = BinaryOperator::create( Instruction::Mul, op1,
- ConstantSInt::get( Type::IntTy, -1 ) );
+ ConstantSInt::get( Type::LongTy, -1 ) );
bb->getInstList().push_back( multop );
push_value( bb, multop );
break;
@@ -1020,7 +1014,7 @@
// Determine if its negative
SetCondInst* cond_inst =
- new SetCondInst( Instruction::SetLT, op1, IZero );
+ new SetCondInst( Instruction::SetLT, op1, Zero );
bb->getInstList().push_back( cond_inst );
// Create a block for storing the result
@@ -1367,7 +1361,7 @@
if (echo) bb->setName("PICK");
LoadInst* n = cast<LoadInst>( stack_top( bb ) );
BinaryOperator* addop =
- BinaryOperator::create( Instruction::Add, n, IOne );
+ BinaryOperator::create( Instruction::Add, n, One );
bb->getInstList().push_back( addop );
LoadInst* x0 = cast<LoadInst>( stack_top( bb, addop ) );
replace_top( bb, x0 );
@@ -1379,11 +1373,11 @@
LoadInst* m = cast<LoadInst>( stack_top(bb) );
LoadInst* n = cast<LoadInst>( stack_top(bb, One) );
BinaryOperator* index =
- BinaryOperator::create( Instruction::Add, m, IOne );
+ BinaryOperator::create( Instruction::Add, m, One );
bb->getInstList().push_back( index );
LoadInst* Xm = cast<LoadInst>( stack_top(bb, index ) );
BinaryOperator* n_plus_1 =
- BinaryOperator::create( Instruction::Add, n, IOne );
+ BinaryOperator::create( Instruction::Add, n, One );
bb->getInstList().push_back( n_plus_1 );
decr_stack_index( bb, n_plus_1 );
replace_top( bb, Xm );
@@ -1496,9 +1490,13 @@
// Get the result value
LoadInst* op1 = cast<LoadInst>(pop_integer(bb));
+ // Cast down to an integer
+ CastInst* caster = new CastInst( op1, Type::IntTy );
+ bb->getInstList().push_back( caster );
+
// Call exit(3)
std::vector<Value*> params;
- params.push_back(op1);
+ params.push_back(caster);
CallInst* call_inst = new CallInst( TheExit, params );
bb->getInstList().push_back( call_inst );
break;
@@ -1514,7 +1512,7 @@
new GetElementPtrInst( ChrFormat, indexVec );
bb->getInstList().push_back( format_gep );
- // Get the character to print (a newline)
+ // Get the character to print (a tab)
ConstantSInt* newline = ConstantSInt::get(Type::IntTy,
static_cast<int>('\t'));
@@ -1536,7 +1534,7 @@
new GetElementPtrInst( ChrFormat, indexVec );
bb->getInstList().push_back( format_gep );
- // Get the character to print (a newline)
+ // Get the character to print (a space)
ConstantSInt* newline = ConstantSInt::get(Type::IntTy,
static_cast<int>(' '));
Index: llvm/projects/Stacker/lib/compiler/StackerCompiler.h
diff -u llvm/projects/Stacker/lib/compiler/StackerCompiler.h:1.2 llvm/projects/Stacker/lib/compiler/StackerCompiler.h:1.3
--- llvm/projects/Stacker/lib/compiler/StackerCompiler.h:1.2 Thu Apr 15 10:38:48 2004
+++ llvm/projects/Stacker/lib/compiler/StackerCompiler.h Sun May 9 18:20:19 2004
@@ -140,7 +140,7 @@
/// @brief Handle the push of an integer onto the stack.
/// @param value The integer value to be pushed.
- BasicBlock* handle_integer( const int32_t value );
+ BasicBlock* handle_integer( const int64_t value );
/// @brief Handle one of the reserved words (given as a token)
BasicBlock* handle_word( int tkn );
@@ -169,7 +169,7 @@
/// @brief Generate code to push any value onto the stack.
Instruction* push_value( BasicBlock* bb, Value* value );
/// @brief Generate code to push a constant integer onto the stack.
- Instruction* push_integer( BasicBlock* bb, int32_t value );
+ Instruction* push_integer( BasicBlock* bb, int64_t value );
/// @brief Generate code to pop an integer off the stack.
Instruction* pop_integer( BasicBlock* bb );
/// @brief Generate code to push a string pointer onto the stack.
@@ -211,9 +211,6 @@
ConstantInt* Three; ///< long constant 3
ConstantInt* Four; ///< long constant 4
ConstantInt* Five; ///< long constant 5
- ConstantInt* IZero; ///< int constant 0
- ConstantInt* IOne; ///< int constant 1
- ConstantInt* ITwo; ///< int constant 2
std::vector<Value*> no_arguments; ///< no arguments for Stacker
bool echo; ///< Echo flag
size_t stack_size; ///< Size of stack to gen.
Index: llvm/projects/Stacker/lib/compiler/StackerParser.y
diff -u llvm/projects/Stacker/lib/compiler/StackerParser.y:1.4 llvm/projects/Stacker/lib/compiler/StackerParser.y:1.5
--- llvm/projects/Stacker/lib/compiler/StackerParser.y:1.4 Tue Mar 30 21:49:47 2004
+++ llvm/projects/Stacker/lib/compiler/StackerParser.y Sun May 9 18:20:19 2004
@@ -39,7 +39,7 @@
llvm::Module* ModuleVal;
llvm::Function* FunctionVal;
llvm::BasicBlock* BasicBlockVal;
- uint32_t IntegerVal;
+ int64_t IntegerVal;
char* StringVal;
}
More information about the llvm-commits
mailing list