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 //===----------------------------------------------------------------------===//
24 #include <sys/types.h>
26 extern int64_t _index_;
27 extern int64_t _stack_[];
31 _stacker_dump_stack_()
34 printf("Stack Dump:\n");
35 for (i = _index_; i > 0; i-- )
37 printf("#%03lld: %lld\n", (long long int) i, (long long int) _stack_[i] );
42 main ( int argc, char** argv )
44 // Avoid modifying argc
47 // Make sure we're starting with the right index
50 // Copy the arguments to the stack in reverse order
51 // so that they get popped in the order presented
54 if ( isdigit( (int) argv[--a][0] ) )
56 _stack_[_index_++] = atoll( argv[a] );
60 _stack_[_index_++] = (int64_t) (intptr_t) argv[a];
64 // Put the argument count on the stack
65 _stack_[_index_] = argc;
67 // Invoke the user's main program
70 // Return last item on the stack
72 return _stack_[_index_];