2003-11-23 17:54:18 +00:00
|
|
|
//===-- stacker_rt.c - Runtime Support For Stacker Compiler -----*- C++ -*-===//
|
2005-04-23 21:26:11 +00:00
|
|
|
//
|
2003-11-23 17:53:46 +00:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2005-04-23 21:26:11 +00:00
|
|
|
// This file was developed by Reid Spencer and donated to the LLVM research
|
|
|
|
// group and is distributed under the University of Illinois Open Source
|
2003-11-23 17:53:46 +00:00
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-23 21:26:11 +00:00
|
|
|
//
|
2003-11-23 17:53:46 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file defines a stack dumping function that can be used for debugging.
|
|
|
|
// It is called whenever the DUMP built-in word is used in the Stacker source.
|
|
|
|
// It has no effect on the stack (other than to print it).
|
|
|
|
//
|
|
|
|
// The real reason this is here is to test LLVM's ability to link with
|
|
|
|
// separately compiled software.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2003-11-27 07:48:45 +00:00
|
|
|
#include <ctype.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2004-05-11 16:14:53 +00:00
|
|
|
#include <inttypes.h>
|
2003-11-23 17:53:46 +00:00
|
|
|
|
2004-05-09 23:20:19 +00:00
|
|
|
extern int64_t _index_;
|
|
|
|
extern int64_t _stack_[];
|
2003-11-24 02:57:25 +00:00
|
|
|
extern void _MAIN_();
|
2003-11-23 17:53:46 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
_stacker_dump_stack_()
|
|
|
|
{
|
2004-05-09 23:20:19 +00:00
|
|
|
int64_t i;
|
2003-11-23 17:53:46 +00:00
|
|
|
printf("Stack Dump:\n");
|
|
|
|
for (i = _index_; i > 0; i-- )
|
|
|
|
{
|
2005-04-23 21:26:11 +00:00
|
|
|
printf("#%03lld: %lld\n", (long long int) i, (long long int) _stack_[i] );
|
2003-11-23 17:53:46 +00:00
|
|
|
}
|
|
|
|
}
|
2003-11-24 02:57:25 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
main ( int argc, char** argv )
|
|
|
|
{
|
|
|
|
// Avoid modifying argc
|
|
|
|
int a = argc;
|
|
|
|
|
|
|
|
// Make sure we're starting with the right index
|
|
|
|
_index_ = 0;
|
|
|
|
|
|
|
|
// Copy the arguments to the stack in reverse order
|
|
|
|
// so that they get popped in the order presented
|
|
|
|
while ( a > 0 )
|
|
|
|
{
|
2005-04-23 21:26:11 +00:00
|
|
|
if ( isdigit( (int) argv[--a][0] ) )
|
|
|
|
{
|
|
|
|
_stack_[_index_++] = atoll( argv[a] );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_stack_[_index_++] = (int64_t) (intptr_t) argv[a];
|
|
|
|
}
|
2003-11-24 02:57:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Put the argument count on the stack
|
|
|
|
_stack_[_index_] = argc;
|
|
|
|
|
|
|
|
// Invoke the user's main program
|
|
|
|
_MAIN_();
|
|
|
|
|
|
|
|
// Return last item on the stack
|
|
|
|
if ( _index_ >= 0 )
|
2005-04-23 21:26:11 +00:00
|
|
|
return _stack_[_index_];
|
2003-11-24 02:57:25 +00:00
|
|
|
return -1;
|
|
|
|
}
|