diff options
author | Brian Gaeke <gaeke@uiuc.edu> | 2003-11-24 02:57:25 +0000 |
---|---|---|
committer | Brian Gaeke <gaeke@uiuc.edu> | 2003-11-24 02:57:25 +0000 |
commit | 49f7a39017fba8574451deab3e3182e9fc4b0320 (patch) | |
tree | f63b6fd6fb89f9c35bb1437fc6be79e8d0917134 /llvm/projects/Stacker/lib | |
parent | cd52465b70bfd5dd5e1968863ef43fca7912a1cf (diff) | |
download | bcm5719-llvm-49f7a39017fba8574451deab3e3182e9fc4b0320.tar.gz bcm5719-llvm-49f7a39017fba8574451deab3e3182e9fc4b0320.zip |
Apply patches from PR136
llvm-svn: 10192
Diffstat (limited to 'llvm/projects/Stacker/lib')
-rw-r--r-- | llvm/projects/Stacker/lib/compiler/StackerCompiler.cpp | 25 | ||||
-rw-r--r-- | llvm/projects/Stacker/lib/runtime/stacker_rt.c | 38 |
2 files changed, 46 insertions, 17 deletions
diff --git a/llvm/projects/Stacker/lib/compiler/StackerCompiler.cpp b/llvm/projects/Stacker/lib/compiler/StackerCompiler.cpp index 4cd06461030..931796f9a81 100644 --- a/llvm/projects/Stacker/lib/compiler/StackerCompiler.cpp +++ b/llvm/projects/Stacker/lib/compiler/StackerCompiler.cpp @@ -131,8 +131,8 @@ StackerCompiler::compile( TheStack = new GlobalVariable( /*type=*/ stack_type, /*isConstant=*/ false, - /*Linkage=*/ GlobalValue::AppendingLinkage, - /*initializer=*/Constant::getNullValue(stack_type), + /*Linkage=*/ GlobalValue::LinkOnceLinkage, + /*initializer=*/ Constant::getNullValue(stack_type), /*name=*/ "_stack_", /*parent=*/ TheModule ); @@ -144,7 +144,7 @@ StackerCompiler::compile( /*type=*/Type::LongTy, /*isConstant=*/false, /*Linkage=*/GlobalValue::LinkOnceLinkage, - /*initializer=*/Constant::getNullValue(Type::LongTy), + /*initializer=*/ Constant::getNullValue(Type::LongTy), /*name=*/"_index_", /*parent=*/TheModule ); @@ -559,28 +559,19 @@ Function* StackerCompiler::handle_main_definition( Function* func ) { // Set the name of the function defined as the Stacker main + // This will get called by the "main" that is defined in + // the runtime library. func->setName( "_MAIN_"); - // Create the actual main for the runtime system. - //std::vector<const Type*> params; // No parameters - //FunctionType* main_type = FunctionType::get( Type::IntTy, params, false ); - Function* SystemMain = new Function( - DefinitionType, - GlobalValue::ExternalLinkage, - "main", TheModule); - - // Create a basic block that just calls the STACKERMAIN function. Note - // that the basic block is automatically inserted into the end of SystemMain - BasicBlock* bb = new BasicBlock( (echo?"main":"a"), SystemMain ) ; - bb->getInstList().push_back( new CallInst( func, no_arguments) ); - bb->getInstList().push_back( new ReturnInst() ); - // Turn "_stack_" into an initialized variable since this is the main // module. This causes it to not be "external" but defined in this module. TheStack->setInitializer( Constant::getNullValue(stack_type) ); + TheStack->setLinkage( GlobalValue::LinkOnceLinkage ); // Turn "_index_" into an intialized variable for the same reason. TheIndex->setInitializer( Constant::getNullValue(Type::LongTy) ); + TheIndex->setLinkage( GlobalValue::LinkOnceLinkage ); + return func; } diff --git a/llvm/projects/Stacker/lib/runtime/stacker_rt.c b/llvm/projects/Stacker/lib/runtime/stacker_rt.c index 46edf14c131..7deb54d6ea3 100644 --- a/llvm/projects/Stacker/lib/runtime/stacker_rt.c +++ b/llvm/projects/Stacker/lib/runtime/stacker_rt.c @@ -17,10 +17,13 @@ // //===----------------------------------------------------------------------===// +#include "ctype.h" #include "stdio.h" +#include "stdlib.h" extern long _index_; extern int _stack_[1024]; +extern void _MAIN_(); void _stacker_dump_stack_() @@ -32,3 +35,38 @@ _stacker_dump_stack_() printf("#%03d: %d\n", i, _stack_[i] ); } } + +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 ) + { + if ( isdigit( argv[--a][0] ) ) + { + _stack_[_index_++] = atoi( argv[a] ); + } + else + { + _stack_[_index_++] = (int) argv[a]; + } + } + + // 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 ) + return _stack_[_index_]; + return -1; +} |