1 //===-- stacker_rt.c - Runtime Support For Stacker Compiler -----*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by Reid Spencer and donated to the LLVM research
6 // group and is distributed under the University of Illinois Open Source
7 // License. See LICENSE.TXT for details.
9 //===----------------------------------------------------------------------===//
11 // This file defines a stack dumping function that can be used for debugging.
12 // It is called whenever the DUMP built-in word is used in the Stacker source.
13 // It has no effect on the stack (other than to print it).
15 // The real reason this is here is to test LLVM's ability to link with
16 // separately compiled software.
18 //===----------------------------------------------------------------------===//
23 #include <sys/types.h>
25 extern int64_t _index_;
26 extern int64_t _stack_[];
30 _stacker_dump_stack_()
33 printf("Stack Dump:\n");
34 for (i = _index_; i > 0; i-- )
36 printf("#%03lld: %lld\n", (long long int) i, (long long int) _stack_[i] );
41 main ( int argc, char** argv )
43 // Avoid modifying argc
46 // Make sure we're starting with the right index
49 // Copy the arguments to the stack in reverse order
50 // so that they get popped in the order presented
53 if ( isdigit( (int) argv[--a][0] ) )
55 _stack_[_index_++] = atoll( argv[a] );
59 _stack_[_index_++] = (int64_t) (intptr_t) argv[a];
63 // Put the argument count on the stack
64 _stack_[_index_] = argc;
66 // Invoke the user's main program
69 // Return last item on the stack
71 return _stack_[_index_];