Changes to make the Stacker Stack use 64 bit values. This *should* get
authorReid Spencer <rspencer@reidspencer.com>
Sun, 9 May 2004 23:20:19 +0000 (23:20 +0000)
committerReid Spencer <rspencer@reidspencer.com>
Sun, 9 May 2004 23:20:19 +0000 (23:20 +0000)
around the problem with Stacker on Solaris because the Stack can handle
64-bit entries (pointer sized).

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13441 91177308-0d34-0410-b5e6-96231b3b80d8

projects/Stacker/lib/compiler/Lexer.l
projects/Stacker/lib/compiler/StackerCompiler.cpp
projects/Stacker/lib/compiler/StackerCompiler.h
projects/Stacker/lib/compiler/StackerParser.y
projects/Stacker/lib/runtime/stacker_rt.c

index 65f1a972d66ab0e9e00aa38a86054414253992f2..e45cdee87f26a351f3d7a491cd8f50fd8520aaf7 100644 (file)
 #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 @@ static uint64_t IntToVal(const char *Buffer) {
 }
 
 /* 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 12151a537d6c030f7d3831a9d3d404f3fe697f96..708ae3cc3a6ba4bdf5b04764a8b12e108361d340 100644 (file)
@@ -60,9 +60,6 @@ StackerCompiler::StackerCompiler()
     , Three(0)
     , Four(0)
     , Five(0)
-    , IZero(0)
-    , IOne(0)
-    , ITwo(0)
     , no_arguments()
     , echo(false)
     , stack_size(256)
@@ -121,8 +118,8 @@ StackerCompiler::compile(
        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 @@ StackerCompiler::compile(
        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 @@ StackerCompiler::push_value( BasicBlock* bb, Value* val )
     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 @@ StackerCompiler::push_value( BasicBlock* bb, Value* val )
 }
 
 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 @@ StackerCompiler::handle_if( char* ifTrue, char* ifFalse )
 
     // 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 @@ StackerCompiler::handle_while( char* todo )
 
     // 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 @@ StackerCompiler::handle_string( char * value )
 }
 
 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 @@ StackerCompiler::handle_word( int tkn )
        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 @@ StackerCompiler::handle_word( int tkn )
        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 @@ StackerCompiler::handle_word( int tkn )
        // 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 @@ StackerCompiler::handle_word( int tkn )
 
        // 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 @@ StackerCompiler::handle_word( int tkn )
        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 @@ StackerCompiler::handle_word( int tkn )
        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 @@ StackerCompiler::handle_word( int tkn )
        // 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 @@ StackerCompiler::handle_word( int tkn )
            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 @@ StackerCompiler::handle_word( int tkn )
            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 c724c32d5db1e23a0a1dbde19f010d49d74204a1..8939ad0d1512b8d5115d247614f1c4e6169c596b 100644 (file)
@@ -140,7 +140,7 @@ class StackerCompiler
 
        /// @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 @@ class StackerCompiler
        /// @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 @@ class StackerCompiler
        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 e45cc1a4b3891244ce17dd8c1be65c5e769d8e5d..96c724303e4407bd84512113c2be04507c31583c 100644 (file)
@@ -39,7 +39,7 @@ int yyparse();
   llvm::Module*                ModuleVal;
   llvm::Function*      FunctionVal;
   llvm::BasicBlock*    BasicBlockVal;
-  uint32_t              IntegerVal;
+  int64_t               IntegerVal;
   char*                 StringVal;
 }
 
index 9709ac49dd4f580fc45af369c7bc97367586cb4c..19ded7b4e1490b5c7c6602e018cd707ddba024e0 100644 (file)
 #include <stdio.h>
 #include <stdlib.h>
 
-extern long long _index_;
-extern int _stack_[];
+extern int64_t _index_;
+extern int64_t _stack_[];
 extern void _MAIN_();
 
 void
 _stacker_dump_stack_()
 {
-    int i;
+    int64_t i;
     printf("Stack Dump:\n");
     for (i = _index_; i > 0; i-- )
     {
-       printf("#%03d: %d\n", i, _stack_[i] );
+       printf("#%03lld: %lld\n", i, _stack_[i] );
     }
 }
 
@@ -51,7 +51,7 @@ main ( int argc, char** argv )
     {
        if ( isdigit( (int) argv[--a][0] ) )
        {
-           _stack_[_index_++] = atoi( argv[a] );
+           _stack_[_index_++] = atoll( argv[a] );
        }
        else
        {