From b02fbfc485a68cebeede24810b0cd8f0d97c9e51 Mon Sep 17 00:00:00 2001 From: Jeff Cohen Date: Sat, 23 Apr 2005 21:26:11 +0000 Subject: [PATCH] Eliminate tabs and trailing spaces git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21479 91177308-0d34-0410-b5e6-96231b3b80d8 --- projects/Stacker/lib/compiler/StackerCompiler.cpp | 1860 ++++++++++---------- projects/Stacker/lib/compiler/StackerCompiler.h | 248 +-- projects/Stacker/lib/runtime/stacker_rt.c | 28 +- projects/Stacker/tools/stkrc/stkrc.cpp | 4 +- projects/sample/include/sample.h | 4 +- projects/sample/lib/sample/sample.c | 8 +- projects/sample/tools/sample/main.c | 4 +- test/C++Frontend/2003-09-22-CompositeExprValue.cpp | 4 +- .../2003-09-29-ArgumentNumberMismatch.cpp | 6 +- test/CFrontend/2002-02-13-TypeVarNameCollision.c | 6 +- test/CFrontend/2002-02-18-64bitConstant.c | 5 +- test/CFrontend/2002-03-11-LargeCharInString.c | 8 +- test/CFrontend/2002-03-14-QuotesInStrConst.c | 4 +- test/CFrontend/2002-05-23-StaticValues.c | 4 +- test/CFrontend/2002-05-24-Alloca.c | 6 +- test/CFrontend/2002-06-25-FWriteInterfaceFailure.c | 2 +- test/CFrontend/2002-07-14-MiscTests3.c | 56 +- test/CFrontend/2002-07-30-SubregSetAssertion.c | 6 +- test/CFrontend/2002-07-30-UnionTest.c | 14 +- test/CFrontend/2002-07-30-VarArgsCallFailure.c | 4 +- test/CFrontend/2002-08-02-UnionTest.c | 10 +- test/CFrontend/2002-09-08-PointerShifts.c | 2 +- test/CFrontend/2002-10-12-TooManyArguments.c | 2 +- test/CodeGen/Generic/BasicInstrs.c | 4 +- test/Debugger/funccall.c | 12 +- 25 files changed, 1155 insertions(+), 1156 deletions(-) diff --git a/projects/Stacker/lib/compiler/StackerCompiler.cpp b/projects/Stacker/lib/compiler/StackerCompiler.cpp index 7b1ebe02f95..c9a3e626276 100644 --- a/projects/Stacker/lib/compiler/StackerCompiler.cpp +++ b/projects/Stacker/lib/compiler/StackerCompiler.cpp @@ -39,7 +39,7 @@ extern int Stackerparse(); StackerCompiler* StackerCompiler::TheInstance = 0; static Statistic<> NumDefinitions( - "numdefs","The # of definitions encoutered while compiling Stacker"); + "numdefs","The # of definitions encoutered while compiling Stacker"); StackerCompiler::StackerCompiler() : CurFilename("") @@ -106,160 +106,160 @@ StackerCompiler::compile( /// if (filename != "-") { - F = fopen(filename.c_str(), "r"); + F = fopen(filename.c_str(), "r"); - if (F == 0) - { - throw ParseException(filename, - "Could not open file '" + filename + "'"); - } + if (F == 0) + { + throw ParseException(filename, + "Could not open file '" + filename + "'"); + } } Module *Result; try { - // Create the module we'll return - TheModule = new Module( CurFilename ); + // Create the module we'll return + TheModule = new Module( CurFilename ); // Tell the module about our runtime library TheModule->addLibrary("stkr_runtime"); - // Create a type to represent the stack. This is the same as the LLVM - // 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. - // Also note that the last argument causes the global to be inserted - // automatically into the module. - TheStack = new GlobalVariable( - /*type=*/ stack_type, - /*isConstant=*/ false, - /*Linkage=*/ GlobalValue::LinkOnceLinkage, - /*initializer=*/ Constant::getNullValue(stack_type), - /*name=*/ "_stack_", - /*parent=*/ TheModule - ); - - // Create a global variable for indexing into the stack. Note the use - // of LinkOnce linkage. Only one copy of _index_ will be retained - // after linking - TheIndex = new GlobalVariable( - /*type=*/Type::LongTy, - /*isConstant=*/false, - /*Linkage=*/GlobalValue::LinkOnceLinkage, - /*initializer=*/ Constant::getNullValue(Type::LongTy), - /*name=*/"_index_", - /*parent=*/TheModule - ); - - // Create a function prototype for definitions. No parameters, no - // result. This is used below any time a function is created. - std::vector params; // No parameters - DefinitionType = FunctionType::get( Type::VoidTy, params, false ); - - // Create a function for printf(3) - params.push_back( PointerType::get( Type::SByteTy ) ); - FunctionType* printf_type = - FunctionType::get( Type::IntTy, params, true ); - ThePrintf = new Function( - printf_type, GlobalValue::ExternalLinkage, "printf", TheModule); - - // Create a function for scanf(3) - TheScanf = new Function( - printf_type, GlobalValue::ExternalLinkage, "scanf", TheModule); - - // Create a function for exit(3) - params.clear(); - params.push_back( Type::IntTy ); - FunctionType* exit_type = - FunctionType::get( Type::VoidTy, params, false ); - TheExit = new Function( - exit_type, GlobalValue::ExternalLinkage, "exit", TheModule); - - Constant* str_format = ConstantArray::get("%s"); - StrFormat = new GlobalVariable( - /*type=*/ArrayType::get( Type::SByteTy, 3 ), - /*isConstant=*/true, - /*Linkage=*/GlobalValue::LinkOnceLinkage, - /*initializer=*/str_format, - /*name=*/"_str_format_", - /*parent=*/TheModule - ); - - Constant* in_str_format = ConstantArray::get(" %as"); - InStrFormat = new GlobalVariable( - /*type=*/ArrayType::get( Type::SByteTy, 5 ), - /*isConstant=*/true, - /*Linkage=*/GlobalValue::LinkOnceLinkage, - /*initializer=*/in_str_format, - /*name=*/"_in_str_format_", - /*parent=*/TheModule - ); - - Constant* num_format = ConstantArray::get("%d"); - NumFormat = new GlobalVariable( - /*type=*/ArrayType::get( Type::SByteTy, 3 ), - /*isConstant=*/true, - /*Linkage=*/GlobalValue::LinkOnceLinkage, - /*initializer=*/num_format, - /*name=*/"_num_format_", - /*parent=*/TheModule - ); - - Constant* in_num_format = ConstantArray::get(" %d"); - InNumFormat = new GlobalVariable( - /*type=*/ArrayType::get( Type::SByteTy, 4 ), - /*isConstant=*/true, - /*Linkage=*/GlobalValue::LinkOnceLinkage, - /*initializer=*/in_num_format, - /*name=*/"_in_num_format_", - /*parent=*/TheModule - ); - - Constant* chr_format = ConstantArray::get("%c"); - ChrFormat = new GlobalVariable( - /*type=*/ArrayType::get( Type::SByteTy, 3 ), - /*isConstant=*/true, - /*Linkage=*/GlobalValue::LinkOnceLinkage, - /*initializer=*/chr_format, - /*name=*/"_chr_format_", - /*parent=*/TheModule - ); - - Constant* in_chr_format = ConstantArray::get(" %c"); - InChrFormat = new GlobalVariable( - /*type=*/ArrayType::get( Type::SByteTy, 4 ), - /*isConstant=*/true, - /*Linkage=*/GlobalValue::LinkOnceLinkage, - /*initializer=*/in_chr_format, - /*name=*/"_in_chr_format_", - /*parent=*/TheModule - ); - - // Get some constants so we aren't always creating them - Zero = ConstantInt::get( Type::LongTy, 0 ); - One = ConstantInt::get( Type::LongTy, 1 ); - Two = ConstantInt::get( Type::LongTy, 2 ); - Three = ConstantInt::get( Type::LongTy, 3 ); - Four = ConstantInt::get( Type::LongTy, 4 ); - Five = ConstantInt::get( Type::LongTy, 5 ); - - // Reset the current line number - Stackerlineno = 1; - - // Reset the parser's input to F - Stackerin = F; // Set the input file. - - // Let the parse know about this instance - TheInstance = this; - - // Parse the file. The parser (see StackParser.y) will call back to - // the StackerCompiler via the "handle*" methods - Stackerparse(); - - // Avoid potential illegal use (TheInstance might be on the stack) - TheInstance = 0; + // Create a type to represent the stack. This is the same as the LLVM + // 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. + // Also note that the last argument causes the global to be inserted + // automatically into the module. + TheStack = new GlobalVariable( + /*type=*/ stack_type, + /*isConstant=*/ false, + /*Linkage=*/ GlobalValue::LinkOnceLinkage, + /*initializer=*/ Constant::getNullValue(stack_type), + /*name=*/ "_stack_", + /*parent=*/ TheModule + ); + + // Create a global variable for indexing into the stack. Note the use + // of LinkOnce linkage. Only one copy of _index_ will be retained + // after linking + TheIndex = new GlobalVariable( + /*type=*/Type::LongTy, + /*isConstant=*/false, + /*Linkage=*/GlobalValue::LinkOnceLinkage, + /*initializer=*/ Constant::getNullValue(Type::LongTy), + /*name=*/"_index_", + /*parent=*/TheModule + ); + + // Create a function prototype for definitions. No parameters, no + // result. This is used below any time a function is created. + std::vector params; // No parameters + DefinitionType = FunctionType::get( Type::VoidTy, params, false ); + + // Create a function for printf(3) + params.push_back( PointerType::get( Type::SByteTy ) ); + FunctionType* printf_type = + FunctionType::get( Type::IntTy, params, true ); + ThePrintf = new Function( + printf_type, GlobalValue::ExternalLinkage, "printf", TheModule); + + // Create a function for scanf(3) + TheScanf = new Function( + printf_type, GlobalValue::ExternalLinkage, "scanf", TheModule); + + // Create a function for exit(3) + params.clear(); + params.push_back( Type::IntTy ); + FunctionType* exit_type = + FunctionType::get( Type::VoidTy, params, false ); + TheExit = new Function( + exit_type, GlobalValue::ExternalLinkage, "exit", TheModule); + + Constant* str_format = ConstantArray::get("%s"); + StrFormat = new GlobalVariable( + /*type=*/ArrayType::get( Type::SByteTy, 3 ), + /*isConstant=*/true, + /*Linkage=*/GlobalValue::LinkOnceLinkage, + /*initializer=*/str_format, + /*name=*/"_str_format_", + /*parent=*/TheModule + ); + + Constant* in_str_format = ConstantArray::get(" %as"); + InStrFormat = new GlobalVariable( + /*type=*/ArrayType::get( Type::SByteTy, 5 ), + /*isConstant=*/true, + /*Linkage=*/GlobalValue::LinkOnceLinkage, + /*initializer=*/in_str_format, + /*name=*/"_in_str_format_", + /*parent=*/TheModule + ); + + Constant* num_format = ConstantArray::get("%d"); + NumFormat = new GlobalVariable( + /*type=*/ArrayType::get( Type::SByteTy, 3 ), + /*isConstant=*/true, + /*Linkage=*/GlobalValue::LinkOnceLinkage, + /*initializer=*/num_format, + /*name=*/"_num_format_", + /*parent=*/TheModule + ); + + Constant* in_num_format = ConstantArray::get(" %d"); + InNumFormat = new GlobalVariable( + /*type=*/ArrayType::get( Type::SByteTy, 4 ), + /*isConstant=*/true, + /*Linkage=*/GlobalValue::LinkOnceLinkage, + /*initializer=*/in_num_format, + /*name=*/"_in_num_format_", + /*parent=*/TheModule + ); + + Constant* chr_format = ConstantArray::get("%c"); + ChrFormat = new GlobalVariable( + /*type=*/ArrayType::get( Type::SByteTy, 3 ), + /*isConstant=*/true, + /*Linkage=*/GlobalValue::LinkOnceLinkage, + /*initializer=*/chr_format, + /*name=*/"_chr_format_", + /*parent=*/TheModule + ); + + Constant* in_chr_format = ConstantArray::get(" %c"); + InChrFormat = new GlobalVariable( + /*type=*/ArrayType::get( Type::SByteTy, 4 ), + /*isConstant=*/true, + /*Linkage=*/GlobalValue::LinkOnceLinkage, + /*initializer=*/in_chr_format, + /*name=*/"_in_chr_format_", + /*parent=*/TheModule + ); + + // Get some constants so we aren't always creating them + Zero = ConstantInt::get( Type::LongTy, 0 ); + One = ConstantInt::get( Type::LongTy, 1 ); + Two = ConstantInt::get( Type::LongTy, 2 ); + Three = ConstantInt::get( Type::LongTy, 3 ); + Four = ConstantInt::get( Type::LongTy, 4 ); + Five = ConstantInt::get( Type::LongTy, 5 ); + + // Reset the current line number + Stackerlineno = 1; + + // Reset the parser's input to F + Stackerin = F; // Set the input file. + + // Let the parse know about this instance + TheInstance = this; + + // Parse the file. The parser (see StackParser.y) will call back to + // the StackerCompiler via the "handle*" methods + Stackerparse(); + + // Avoid potential illegal use (TheInstance might be on the stack) + TheInstance = 0; // Set up a pass manager PassManager Passes; @@ -342,8 +342,8 @@ StackerCompiler::compile( Passes.run(*TheModule); } catch (...) { - if (F != stdin) fclose(F); // Make sure to close file descriptor - throw; // if an exception is thrown + if (F != stdin) fclose(F); // Make sure to close file descriptor + throw; // if an exception is thrown } // Close the file @@ -370,7 +370,7 @@ StackerCompiler::incr_stack_index( BasicBlock* bb, Value* ival = 0 ) CastInst* caster = new CastInst( ival, Type::LongTy ); bb->getInstList().push_back( caster ); BinaryOperator* addop = BinaryOperator::create( Instruction::Add, - loadop, caster); + loadop, caster); bb->getInstList().push_back( addop ); // Store the incremented value @@ -391,7 +391,7 @@ StackerCompiler::decr_stack_index( BasicBlock* bb, Value* ival = 0 ) CastInst* caster = new CastInst( ival, Type::LongTy ); bb->getInstList().push_back( caster ); BinaryOperator* subop = BinaryOperator::create( Instruction::Sub, - loadop, caster); + loadop, caster); bb->getInstList().push_back( subop ); // Store the incremented value @@ -418,21 +418,21 @@ StackerCompiler::get_stack_pointer( BasicBlock* bb, Value* index = 0 ) if ( index == 0 ) { - indexVec.push_back(loadop); + indexVec.push_back(loadop); } else { - CastInst* caster = new CastInst( index, Type::LongTy ); - bb->getInstList().push_back( caster ); - BinaryOperator* subop = BinaryOperator::create( - Instruction::Sub, loadop, caster ); - bb->getInstList().push_back( subop ); - indexVec.push_back(subop); + CastInst* caster = new CastInst( index, Type::LongTy ); + bb->getInstList().push_back( caster ); + BinaryOperator* subop = BinaryOperator::create( + Instruction::Sub, loadop, caster ); + bb->getInstList().push_back( subop ); + indexVec.push_back(subop); } // Get the address of the indexed stack element GetElementPtrInst* gep = new GetElementPtrInst( TheStack, indexVec ); - bb->getInstList().push_back( gep ); // Put GEP in Block + bb->getInstList().push_back( gep ); // Put GEP in Block return gep; } @@ -445,7 +445,7 @@ StackerCompiler::push_value( BasicBlock* bb, Value* val ) // Get the stack pointer GetElementPtrInst* gep = cast( - get_stack_pointer( bb ) ); + get_stack_pointer( bb ) ); // Cast the value to a long .. hopefully it works CastInst* cast_inst = new CastInst( val, Type::LongTy ); @@ -470,7 +470,7 @@ StackerCompiler::pop_integer( BasicBlock*bb ) { // Get the stack pointer GetElementPtrInst* gep = cast( - get_stack_pointer( bb )); + get_stack_pointer( bb )); // Load the value LoadInst* load_inst = new LoadInst( gep ); @@ -498,12 +498,12 @@ StackerCompiler::push_string( BasicBlock* bb, const char* value ) // Create an internal linkage global variable to hold the constant. GlobalVariable* strconst = new GlobalVariable( - char_array, - /*isConstant=*/true, - GlobalValue::InternalLinkage, - /*initializer=*/initVal, - "", - TheModule + char_array, + /*isConstant=*/true, + GlobalValue::InternalLinkage, + /*initializer=*/initVal, + "", + TheModule ); // Push the casted value @@ -515,7 +515,7 @@ StackerCompiler::pop_string( BasicBlock* bb ) { // Get location of stack pointer GetElementPtrInst* gep = cast( - get_stack_pointer( bb )); + get_stack_pointer( bb )); // Load the value from the stack LoadInst* loader = new LoadInst( gep ); @@ -537,7 +537,7 @@ StackerCompiler::replace_top( BasicBlock* bb, Value* new_top, Value* index = 0 ) { // Get the stack pointer GetElementPtrInst* gep = cast( - get_stack_pointer( bb, index )); + get_stack_pointer( bb, index )); // Store the value there StoreInst* store_inst = new StoreInst( new_top, gep ); @@ -552,7 +552,7 @@ StackerCompiler::stack_top( BasicBlock* bb, Value* index = 0 ) { // Get the stack pointer GetElementPtrInst* gep = cast( - get_stack_pointer( bb, index )); + get_stack_pointer( bb, index )); // Load the value LoadInst* load_inst = new LoadInst( gep ); @@ -567,7 +567,7 @@ StackerCompiler::stack_top_string( BasicBlock* bb, Value* index = 0 ) { // Get location of stack pointer GetElementPtrInst* gep = cast( - get_stack_pointer( bb, index )); + get_stack_pointer( bb, index )); // Load the value from the stack LoadInst* loader = new LoadInst( gep ); @@ -586,8 +586,8 @@ add_block( Function*f, BasicBlock* bb ) { if ( ! f->empty() && f->back().getTerminator() == 0 ) { - BranchInst* branch = new BranchInst(bb); - f->back().getInstList().push_back( branch ); + BranchInst* branch = new BranchInst(bb); + f->back().getInstList().push_back( branch ); } f->getBasicBlockList().push_back( bb ); } @@ -622,11 +622,11 @@ StackerCompiler::handle_definition_list_end( Module* mod, Function* definition ) { if ( ! definition->empty() ) { - BasicBlock& last_block = definition->back(); - if ( last_block.getTerminator() == 0 ) - { - last_block.getInstList().push_back( new ReturnInst() ); - } + BasicBlock& last_block = definition->back(); + if ( last_block.getTerminator() == 0 ) + { + last_block.getInstList().push_back( new ReturnInst() ); + } } // Insert the definition into the module mod->getFunctionList().push_back( definition ); @@ -661,9 +661,9 @@ StackerCompiler::handle_forward( char * name ) { // Just create a placeholder function Function* the_function = new Function ( - DefinitionType, - GlobalValue::ExternalLinkage, - name ); + DefinitionType, + GlobalValue::ExternalLinkage, + name ); assert( the_function->isExternal() ); free( name ); @@ -681,9 +681,9 @@ StackerCompiler::handle_definition( char * name, Function* f ) // If the function already exists... if ( existing_function ) { - // Just get rid of the placeholder - existing_function->dropAllReferences(); - delete existing_function; + // Just get rid of the placeholder + existing_function->dropAllReferences(); + delete existing_function; } #endif @@ -720,7 +720,7 @@ StackerCompiler::handle_if( char* ifTrue, char* ifFalse ) // Compare the condition against 0 SetCondInst* cond_inst = new SetCondInst( Instruction::SetNE, cond, - ConstantSInt::get( Type::LongTy, 0) ); + ConstantSInt::get( Type::LongTy, 0) ); bb->getInstList().push_back( cond_inst ); // Create an exit block @@ -735,22 +735,22 @@ StackerCompiler::handle_if( char* ifTrue, char* ifFalse ) // Create a branch on the SetCond BranchInst* br_inst = new BranchInst( true_bb, - ( ifFalse ? false_bb : exit_bb ), cond_inst ); + ( ifFalse ? false_bb : exit_bb ), cond_inst ); bb->getInstList().push_back( br_inst ); // Fill the true block std::vector args; if ( Function* true_func = TheModule->getNamedFunction(ifTrue) ) { - true_bb->getInstList().push_back( - new CallInst( true_func, args ) ); - true_bb->getInstList().push_back( - new BranchInst( exit_bb ) ); + true_bb->getInstList().push_back( + new CallInst( true_func, args ) ); + true_bb->getInstList().push_back( + new BranchInst( exit_bb ) ); } else { - ThrowException(std::string("Function '") + ifTrue + - "' must be declared first.'"); + ThrowException(std::string("Function '") + ifTrue + + "' must be declared first.'"); } free( ifTrue ); @@ -758,19 +758,19 @@ StackerCompiler::handle_if( char* ifTrue, char* ifFalse ) // Fill the false block if ( false_bb ) { - if ( Function* false_func = TheModule->getNamedFunction(ifFalse) ) - { - false_bb->getInstList().push_back( - new CallInst( false_func, args ) ); - false_bb->getInstList().push_back( - new BranchInst( exit_bb ) ); - } - else - { - ThrowException(std::string("Function '") + ifFalse + - "' must be declared first.'"); - } - free( ifFalse ); + if ( Function* false_func = TheModule->getNamedFunction(ifFalse) ) + { + false_bb->getInstList().push_back( + new CallInst( false_func, args ) ); + false_bb->getInstList().push_back( + new BranchInst( exit_bb ) ); + } + else + { + ThrowException(std::string("Function '") + ifFalse + + "' must be declared first.'"); + } + free( ifFalse ); } // Add the blocks to the function @@ -804,7 +804,7 @@ StackerCompiler::handle_while( char* todo ) // Compare the condition against 0 SetCondInst* cond_inst = new SetCondInst( - Instruction::SetNE, cond, ConstantSInt::get( Type::LongTy, 0) ); + Instruction::SetNE, cond, ConstantSInt::get( Type::LongTy, 0) ); test->getInstList().push_back( cond_inst ); // Add the branch instruction @@ -815,13 +815,13 @@ StackerCompiler::handle_while( char* todo ) std::vector args; if ( Function* body_func = TheModule->getNamedFunction(todo) ) { - body->getInstList().push_back( new CallInst( body_func, args ) ); - body->getInstList().push_back( new BranchInst( test ) ); + body->getInstList().push_back( new CallInst( body_func, args ) ); + body->getInstList().push_back( new BranchInst( test ) ); } else { - ThrowException(std::string("Function '") + todo + - "' must be declared first.'"); + ThrowException(std::string("Function '") + todo + + "' must be declared first.'"); } free( todo ); @@ -841,13 +841,13 @@ StackerCompiler::handle_identifier( char * name ) BasicBlock* bb = new BasicBlock((echo?"call":"")); if ( func ) { - CallInst* call_def = new CallInst( func , no_arguments ); - bb->getInstList().push_back( call_def ); + CallInst* call_def = new CallInst( func , no_arguments ); + bb->getInstList().push_back( call_def ); } else { - ThrowException(std::string("Definition '") + name + - "' must be defined before it can be used."); + ThrowException(std::string("Definition '") + name + + "' must be defined before it can be used."); } free( name ); @@ -892,910 +892,910 @@ StackerCompiler::handle_word( int tkn ) { case DUMP : // Dump the stack (debugging aid) { - if (echo) bb->setName("DUMP"); - Function* f = TheModule->getOrInsertFunction( - "_stacker_dump_stack_", DefinitionType); - std::vector args; - bb->getInstList().push_back( new CallInst( f, args ) ); - break; + if (echo) bb->setName("DUMP"); + Function* f = TheModule->getOrInsertFunction( + "_stacker_dump_stack_", DefinitionType); + std::vector args; + bb->getInstList().push_back( new CallInst( f, args ) ); + break; } // Logical Operations case TRUETOK : // -- -1 { - if (echo) bb->setName("TRUE"); - push_integer(bb,-1); - break; + if (echo) bb->setName("TRUE"); + push_integer(bb,-1); + break; } case FALSETOK : // -- 0 { - if (echo) bb->setName("FALSE"); - push_integer(bb,0); - break; + if (echo) bb->setName("FALSE"); + push_integer(bb,0); + break; } case LESS : // w1 w2 -- w2setName("LESS"); - LoadInst* op1 = cast(pop_integer(bb)); - LoadInst* op2 = cast(pop_integer(bb)); - SetCondInst* cond_inst = - new SetCondInst( Instruction::SetLT, op1, op2 ); - bb->getInstList().push_back( cond_inst ); - push_value( bb, cond_inst ); - break; + if (echo) bb->setName("LESS"); + LoadInst* op1 = cast(pop_integer(bb)); + LoadInst* op2 = cast(pop_integer(bb)); + SetCondInst* cond_inst = + new SetCondInst( Instruction::SetLT, op1, op2 ); + bb->getInstList().push_back( cond_inst ); + push_value( bb, cond_inst ); + break; } case MORE : // w1 w2 -- w2>w1 { - if (echo) bb->setName("MORE"); - LoadInst* op1 = cast(pop_integer(bb)); - LoadInst* op2 = cast(pop_integer(bb)); - SetCondInst* cond_inst = - new SetCondInst( Instruction::SetGT, op1, op2 ); - bb->getInstList().push_back( cond_inst ); - push_value( bb, cond_inst ); - break; + if (echo) bb->setName("MORE"); + LoadInst* op1 = cast(pop_integer(bb)); + LoadInst* op2 = cast(pop_integer(bb)); + SetCondInst* cond_inst = + new SetCondInst( Instruction::SetGT, op1, op2 ); + bb->getInstList().push_back( cond_inst ); + push_value( bb, cond_inst ); + break; } case LESS_EQUAL : // w1 w2 -- w2<=w1 { - if (echo) bb->setName("LE"); - LoadInst* op1 = cast(pop_integer(bb)); - LoadInst* op2 = cast(pop_integer(bb)); - SetCondInst* cond_inst = - new SetCondInst( Instruction::SetLE, op1, op2 ); - bb->getInstList().push_back( cond_inst ); - push_value( bb, cond_inst ); - break; + if (echo) bb->setName("LE"); + LoadInst* op1 = cast(pop_integer(bb)); + LoadInst* op2 = cast(pop_integer(bb)); + SetCondInst* cond_inst = + new SetCondInst( Instruction::SetLE, op1, op2 ); + bb->getInstList().push_back( cond_inst ); + push_value( bb, cond_inst ); + break; } case MORE_EQUAL : // w1 w2 -- w2>=w1 { - if (echo) bb->setName("GE"); - LoadInst* op1 = cast(pop_integer(bb)); - LoadInst* op2 = cast(pop_integer(bb)); - SetCondInst* cond_inst = - new SetCondInst( Instruction::SetGE, op1, op2 ); - bb->getInstList().push_back( cond_inst ); - push_value( bb, cond_inst ); - break; + if (echo) bb->setName("GE"); + LoadInst* op1 = cast(pop_integer(bb)); + LoadInst* op2 = cast(pop_integer(bb)); + SetCondInst* cond_inst = + new SetCondInst( Instruction::SetGE, op1, op2 ); + bb->getInstList().push_back( cond_inst ); + push_value( bb, cond_inst ); + break; } case NOT_EQUAL : // w1 w2 -- w2!=w1 { - if (echo) bb->setName("NE"); - LoadInst* op1 = cast(pop_integer(bb)); - LoadInst* op2 = cast(pop_integer(bb)); - SetCondInst* cond_inst = - new SetCondInst( Instruction::SetNE, op1, op2 ); - bb->getInstList().push_back( cond_inst ); - push_value( bb, cond_inst ); - break; + if (echo) bb->setName("NE"); + LoadInst* op1 = cast(pop_integer(bb)); + LoadInst* op2 = cast(pop_integer(bb)); + SetCondInst* cond_inst = + new SetCondInst( Instruction::SetNE, op1, op2 ); + bb->getInstList().push_back( cond_inst ); + push_value( bb, cond_inst ); + break; } case EQUAL : // w1 w2 -- w1==w2 { - if (echo) bb->setName("EQ"); - LoadInst* op1 = cast(pop_integer(bb)); - LoadInst* op2 = cast(pop_integer(bb)); - SetCondInst* cond_inst = - new SetCondInst( Instruction::SetEQ, op1, op2 ); - bb->getInstList().push_back( cond_inst ); - push_value( bb, cond_inst ); - break; + if (echo) bb->setName("EQ"); + LoadInst* op1 = cast(pop_integer(bb)); + LoadInst* op2 = cast(pop_integer(bb)); + SetCondInst* cond_inst = + new SetCondInst( Instruction::SetEQ, op1, op2 ); + bb->getInstList().push_back( cond_inst ); + push_value( bb, cond_inst ); + break; } // Arithmetic Operations case PLUS : // w1 w2 -- w2+w1 { - if (echo) bb->setName("ADD"); - LoadInst* op1 = cast(pop_integer(bb)); - LoadInst* op2 = cast(pop_integer(bb)); - BinaryOperator* addop = - BinaryOperator::create( Instruction::Add, op1, op2); - bb->getInstList().push_back( addop ); - push_value( bb, addop ); - break; + if (echo) bb->setName("ADD"); + LoadInst* op1 = cast(pop_integer(bb)); + LoadInst* op2 = cast(pop_integer(bb)); + BinaryOperator* addop = + BinaryOperator::create( Instruction::Add, op1, op2); + bb->getInstList().push_back( addop ); + push_value( bb, addop ); + break; } case MINUS : // w1 w2 -- w2-w1 { - if (echo) bb->setName("SUB"); - LoadInst* op1 = cast(pop_integer(bb)); - LoadInst* op2 = cast(pop_integer(bb)); - BinaryOperator* subop = - BinaryOperator::create( Instruction::Sub, op1, op2); - bb->getInstList().push_back( subop ); - push_value( bb, subop ); - break; + if (echo) bb->setName("SUB"); + LoadInst* op1 = cast(pop_integer(bb)); + LoadInst* op2 = cast(pop_integer(bb)); + BinaryOperator* subop = + BinaryOperator::create( Instruction::Sub, op1, op2); + bb->getInstList().push_back( subop ); + push_value( bb, subop ); + break; } case INCR : // w1 -- w1+1 { - if (echo) bb->setName("INCR"); - LoadInst* op1 = cast(pop_integer(bb)); - BinaryOperator* addop = - BinaryOperator::create( Instruction::Add, op1, One ); - bb->getInstList().push_back( addop ); - push_value( bb, addop ); - break; + if (echo) bb->setName("INCR"); + LoadInst* op1 = cast(pop_integer(bb)); + BinaryOperator* addop = + BinaryOperator::create( Instruction::Add, op1, One ); + bb->getInstList().push_back( addop ); + push_value( bb, addop ); + break; } case DECR : // w1 -- w1-1 { - if (echo) bb->setName("DECR"); - LoadInst* op1 = cast(pop_integer(bb)); - BinaryOperator* subop = BinaryOperator::create( Instruction::Sub, op1, - ConstantSInt::get( Type::LongTy, 1 ) ); - bb->getInstList().push_back( subop ); - push_value( bb, subop ); - break; + if (echo) bb->setName("DECR"); + LoadInst* op1 = cast(pop_integer(bb)); + BinaryOperator* subop = BinaryOperator::create( Instruction::Sub, op1, + ConstantSInt::get( Type::LongTy, 1 ) ); + bb->getInstList().push_back( subop ); + push_value( bb, subop ); + break; } case MULT : // w1 w2 -- w2*w1 { - if (echo) bb->setName("MUL"); - LoadInst* op1 = cast(pop_integer(bb)); - LoadInst* op2 = cast(pop_integer(bb)); - BinaryOperator* multop = - BinaryOperator::create( Instruction::Mul, op1, op2); - bb->getInstList().push_back( multop ); - push_value( bb, multop ); - break; + if (echo) bb->setName("MUL"); + LoadInst* op1 = cast(pop_integer(bb)); + LoadInst* op2 = cast(pop_integer(bb)); + BinaryOperator* multop = + BinaryOperator::create( Instruction::Mul, op1, op2); + bb->getInstList().push_back( multop ); + push_value( bb, multop ); + break; } case DIV :// w1 w2 -- w2/w1 { - if (echo) bb->setName("DIV"); - LoadInst* op1 = cast(pop_integer(bb)); - LoadInst* op2 = cast(pop_integer(bb)); - BinaryOperator* divop = - BinaryOperator::create( Instruction::Div, op1, op2); - bb->getInstList().push_back( divop ); - push_value( bb, divop ); - break; + if (echo) bb->setName("DIV"); + LoadInst* op1 = cast(pop_integer(bb)); + LoadInst* op2 = cast(pop_integer(bb)); + BinaryOperator* divop = + BinaryOperator::create( Instruction::Div, op1, op2); + bb->getInstList().push_back( divop ); + push_value( bb, divop ); + break; } case MODULUS : // w1 w2 -- w2%w1 { - if (echo) bb->setName("MOD"); - LoadInst* op1 = cast(pop_integer(bb)); - LoadInst* op2 = cast(pop_integer(bb)); - BinaryOperator* divop = - BinaryOperator::create( Instruction::Rem, op1, op2); - bb->getInstList().push_back( divop ); - push_value( bb, divop ); - break; + if (echo) bb->setName("MOD"); + LoadInst* op1 = cast(pop_integer(bb)); + LoadInst* op2 = cast(pop_integer(bb)); + BinaryOperator* divop = + BinaryOperator::create( Instruction::Rem, op1, op2); + bb->getInstList().push_back( divop ); + push_value( bb, divop ); + break; } case STAR_SLASH : // w1 w2 w3 -- (w3*w2)/w1 { - if (echo) bb->setName("STAR_SLASH"); - // Get the operands - LoadInst* op1 = cast(pop_integer(bb)); - LoadInst* op2 = cast(pop_integer(bb)); - LoadInst* op3 = cast(pop_integer(bb)); + if (echo) bb->setName("STAR_SLASH"); + // Get the operands + LoadInst* op1 = cast(pop_integer(bb)); + LoadInst* op2 = cast(pop_integer(bb)); + LoadInst* op3 = cast(pop_integer(bb)); - // Multiply the first two - BinaryOperator* multop = - BinaryOperator::create( Instruction::Mul, op1, op2); - bb->getInstList().push_back( multop ); + // Multiply the first two + BinaryOperator* multop = + BinaryOperator::create( Instruction::Mul, op1, op2); + bb->getInstList().push_back( multop ); - // Divide by the third operand - BinaryOperator* divop = - BinaryOperator::create( Instruction::Div, multop, op3); - bb->getInstList().push_back( divop ); + // Divide by the third operand + BinaryOperator* divop = + BinaryOperator::create( Instruction::Div, multop, op3); + bb->getInstList().push_back( divop ); - // Push the result - push_value( bb, divop ); + // Push the result + push_value( bb, divop ); - break; + break; } case NEGATE : // w1 -- -w1 { - if (echo) bb->setName("NEG"); - LoadInst* op1 = cast(pop_integer(bb)); - // APPARENTLY, the following doesn't work: - // BinaryOperator* negop = BinaryOperator::createNeg( op1 ); - // bb->getInstList().push_back( negop ); - // So we'll multiply by -1 (ugh) - BinaryOperator* multop = BinaryOperator::create( Instruction::Mul, op1, - ConstantSInt::get( Type::LongTy, -1 ) ); - bb->getInstList().push_back( multop ); - push_value( bb, multop ); - break; + if (echo) bb->setName("NEG"); + LoadInst* op1 = cast(pop_integer(bb)); + // APPARENTLY, the following doesn't work: + // BinaryOperator* negop = BinaryOperator::createNeg( op1 ); + // bb->getInstList().push_back( negop ); + // So we'll multiply by -1 (ugh) + BinaryOperator* multop = BinaryOperator::create( Instruction::Mul, op1, + ConstantSInt::get( Type::LongTy, -1 ) ); + bb->getInstList().push_back( multop ); + push_value( bb, multop ); + break; } case ABS : // w1 -- |w1| { - if (echo) bb->setName("ABS"); - // Get the top of stack value - LoadInst* op1 = cast(stack_top(bb)); + if (echo) bb->setName("ABS"); + // Get the top of stack value + LoadInst* op1 = cast(stack_top(bb)); - // Determine if its negative - SetCondInst* cond_inst = - new SetCondInst( Instruction::SetLT, op1, Zero ); - bb->getInstList().push_back( cond_inst ); + // Determine if its negative + SetCondInst* cond_inst = + new SetCondInst( Instruction::SetLT, op1, Zero ); + bb->getInstList().push_back( cond_inst ); - // Create a block for storing the result - BasicBlock* exit_bb = new BasicBlock((echo?"exit":"")); + // Create a block for storing the result + BasicBlock* exit_bb = new BasicBlock((echo?"exit":"")); - // Create a block for making it a positive value - BasicBlock* pos_bb = new BasicBlock((echo?"neg":"")); + // Create a block for making it a positive value + BasicBlock* pos_bb = new BasicBlock((echo?"neg":"")); - // Create the branch on the SetCond - BranchInst* br_inst = new BranchInst( pos_bb, exit_bb, cond_inst ); - bb->getInstList().push_back( br_inst ); + // Create the branch on the SetCond + BranchInst* br_inst = new BranchInst( pos_bb, exit_bb, cond_inst ); + bb->getInstList().push_back( br_inst ); - // Fill out the negation block - LoadInst* pop_op = cast( pop_integer(pos_bb) ); - BinaryOperator* neg_op = BinaryOperator::createNeg( pop_op ); - pos_bb->getInstList().push_back( neg_op ); - push_value( pos_bb, neg_op ); - pos_bb->getInstList().push_back( new BranchInst( exit_bb ) ); + // Fill out the negation block + LoadInst* pop_op = cast( pop_integer(pos_bb) ); + BinaryOperator* neg_op = BinaryOperator::createNeg( pop_op ); + pos_bb->getInstList().push_back( neg_op ); + push_value( pos_bb, neg_op ); + pos_bb->getInstList().push_back( new BranchInst( exit_bb ) ); - // Add the new blocks in the correct order - add_block( TheFunction, bb ); - add_block( TheFunction, pos_bb ); - bb = exit_bb; - break; + // Add the new blocks in the correct order + add_block( TheFunction, bb ); + add_block( TheFunction, pos_bb ); + bb = exit_bb; + break; } case MIN : // w1 w2 -- (w2setName("MIN"); + if (echo) bb->setName("MIN"); - // Create the three blocks - BasicBlock* exit_bb = new BasicBlock((echo?"exit":"")); - BasicBlock* op1_block = new BasicBlock((echo?"less":"")); - BasicBlock* op2_block = new BasicBlock((echo?"more":"")); + // Create the three blocks + BasicBlock* exit_bb = new BasicBlock((echo?"exit":"")); + BasicBlock* op1_block = new BasicBlock((echo?"less":"")); + BasicBlock* op2_block = new BasicBlock((echo?"more":"")); - // Get the two operands - LoadInst* op1 = cast(pop_integer(bb)); - LoadInst* op2 = cast(pop_integer(bb)); + // Get the two operands + LoadInst* op1 = cast(pop_integer(bb)); + LoadInst* op2 = cast(pop_integer(bb)); - // Compare them - SetCondInst* cond_inst = - new SetCondInst( Instruction::SetLT, op1, op2); - bb->getInstList().push_back( cond_inst ); + // Compare them + SetCondInst* cond_inst = + new SetCondInst( Instruction::SetLT, op1, op2); + bb->getInstList().push_back( cond_inst ); - // Create a branch on the SetCond - BranchInst* br_inst = - new BranchInst( op1_block, op2_block, cond_inst ); - bb->getInstList().push_back( br_inst ); + // Create a branch on the SetCond + BranchInst* br_inst = + new BranchInst( op1_block, op2_block, cond_inst ); + bb->getInstList().push_back( br_inst ); - // Create a block for pushing the first one - push_value(op1_block, op1); - op1_block->getInstList().push_back( new BranchInst( exit_bb ) ); + // Create a block for pushing the first one + push_value(op1_block, op1); + op1_block->getInstList().push_back( new BranchInst( exit_bb ) ); - // Create a block for pushing the second one - push_value(op2_block, op2); - op2_block->getInstList().push_back( new BranchInst( exit_bb ) ); + // Create a block for pushing the second one + push_value(op2_block, op2); + op2_block->getInstList().push_back( new BranchInst( exit_bb ) ); - // Add the blocks - add_block( TheFunction, bb ); - add_block( TheFunction, op1_block ); - add_block( TheFunction, op2_block ); - bb = exit_bb; - break; + // Add the blocks + add_block( TheFunction, bb ); + add_block( TheFunction, op1_block ); + add_block( TheFunction, op2_block ); + bb = exit_bb; + break; } case MAX : // w1 w2 -- (w2>w1?w2:w1) { - if (echo) bb->setName("MAX"); - // Get the two operands - LoadInst* op1 = cast(pop_integer(bb)); - LoadInst* op2 = cast(pop_integer(bb)); + if (echo) bb->setName("MAX"); + // Get the two operands + LoadInst* op1 = cast(pop_integer(bb)); + LoadInst* op2 = cast(pop_integer(bb)); - // Compare them - SetCondInst* cond_inst = - new SetCondInst( Instruction::SetGT, op1, op2); - bb->getInstList().push_back( cond_inst ); + // Compare them + SetCondInst* cond_inst = + new SetCondInst( Instruction::SetGT, op1, op2); + bb->getInstList().push_back( cond_inst ); - // Create an exit block - BasicBlock* exit_bb = new BasicBlock((echo?"exit":"")); + // Create an exit block + BasicBlock* exit_bb = new BasicBlock((echo?"exit":"")); - // Create a block for pushing the larger one - BasicBlock* op1_block = new BasicBlock((echo?"more":"")); - push_value(op1_block, op1); - op1_block->getInstList().push_back( new BranchInst( exit_bb ) ); + // Create a block for pushing the larger one + BasicBlock* op1_block = new BasicBlock((echo?"more":"")); + push_value(op1_block, op1); + op1_block->getInstList().push_back( new BranchInst( exit_bb ) ); - // Create a block for pushing the smaller or equal one - BasicBlock* op2_block = new BasicBlock((echo?"less":"")); - push_value(op2_block, op2); - op2_block->getInstList().push_back( new BranchInst( exit_bb ) ); + // Create a block for pushing the smaller or equal one + BasicBlock* op2_block = new BasicBlock((echo?"less":"")); + push_value(op2_block, op2); + op2_block->getInstList().push_back( new BranchInst( exit_bb ) ); - // Create a banch on the SetCond - BranchInst* br_inst = - new BranchInst( op1_block, op2_block, cond_inst ); - bb->getInstList().push_back( br_inst ); + // Create a banch on the SetCond + BranchInst* br_inst = + new BranchInst( op1_block, op2_block, cond_inst ); + bb->getInstList().push_back( br_inst ); - // Add the blocks - add_block( TheFunction, bb ); - add_block( TheFunction, op1_block ); - add_block( TheFunction, op2_block ); + // Add the blocks + add_block( TheFunction, bb ); + add_block( TheFunction, op1_block ); + add_block( TheFunction, op2_block ); - bb = exit_bb; - break; + bb = exit_bb; + break; } // Bitwise Operators case AND : // w1 w2 -- w2&w1 { - if (echo) bb->setName("AND"); - LoadInst* op1 = cast(pop_integer(bb)); - LoadInst* op2 = cast(pop_integer(bb)); - BinaryOperator* andop = - BinaryOperator::create( Instruction::And, op1, op2); - bb->getInstList().push_back( andop ); - push_value( bb, andop ); - break; + if (echo) bb->setName("AND"); + LoadInst* op1 = cast(pop_integer(bb)); + LoadInst* op2 = cast(pop_integer(bb)); + BinaryOperator* andop = + BinaryOperator::create( Instruction::And, op1, op2); + bb->getInstList().push_back( andop ); + push_value( bb, andop ); + break; } case OR : // w1 w2 -- w2|w1 { - if (echo) bb->setName("OR"); - LoadInst* op1 = cast(pop_integer(bb)); - LoadInst* op2 = cast(pop_integer(bb)); - BinaryOperator* orop = - BinaryOperator::create( Instruction::Or, op1, op2); - bb->getInstList().push_back( orop ); - push_value( bb, orop ); - break; + if (echo) bb->setName("OR"); + LoadInst* op1 = cast(pop_integer(bb)); + LoadInst* op2 = cast(pop_integer(bb)); + BinaryOperator* orop = + BinaryOperator::create( Instruction::Or, op1, op2); + bb->getInstList().push_back( orop ); + push_value( bb, orop ); + break; } case XOR : // w1 w2 -- w2^w1 { - if (echo) bb->setName("XOR"); - LoadInst* op1 = cast(pop_integer(bb)); - LoadInst* op2 = cast(pop_integer(bb)); - BinaryOperator* xorop = - BinaryOperator::create( Instruction::Xor, op1, op2); - bb->getInstList().push_back( xorop ); - push_value( bb, xorop ); - break; + if (echo) bb->setName("XOR"); + LoadInst* op1 = cast(pop_integer(bb)); + LoadInst* op2 = cast(pop_integer(bb)); + BinaryOperator* xorop = + BinaryOperator::create( Instruction::Xor, op1, op2); + bb->getInstList().push_back( xorop ); + push_value( bb, xorop ); + break; } case LSHIFT : // w1 w2 -- w1<setName("SHL"); - LoadInst* op1 = cast(pop_integer(bb)); - LoadInst* op2 = cast(pop_integer(bb)); - CastInst* castop = new CastInst( op1, Type::UByteTy ); - bb->getInstList().push_back( castop ); - ShiftInst* shlop = new ShiftInst( Instruction::Shl, op2, castop ); - bb->getInstList().push_back( shlop ); - push_value( bb, shlop ); - break; + if (echo) bb->setName("SHL"); + LoadInst* op1 = cast(pop_integer(bb)); + LoadInst* op2 = cast(pop_integer(bb)); + CastInst* castop = new CastInst( op1, Type::UByteTy ); + bb->getInstList().push_back( castop ); + ShiftInst* shlop = new ShiftInst( Instruction::Shl, op2, castop ); + bb->getInstList().push_back( shlop ); + push_value( bb, shlop ); + break; } case RSHIFT : // w1 w2 -- w1>>w2 { - if (echo) bb->setName("SHR"); - LoadInst* op1 = cast(pop_integer(bb)); - LoadInst* op2 = cast(pop_integer(bb)); - CastInst* castop = new CastInst( op1, Type::UByteTy ); - bb->getInstList().push_back( castop ); - ShiftInst* shrop = new ShiftInst( Instruction::Shr, op2, castop ); - bb->getInstList().push_back( shrop ); - push_value( bb, shrop ); - break; + if (echo) bb->setName("SHR"); + LoadInst* op1 = cast(pop_integer(bb)); + LoadInst* op2 = cast(pop_integer(bb)); + CastInst* castop = new CastInst( op1, Type::UByteTy ); + bb->getInstList().push_back( castop ); + ShiftInst* shrop = new ShiftInst( Instruction::Shr, op2, castop ); + bb->getInstList().push_back( shrop ); + push_value( bb, shrop ); + break; } // Stack Manipulation Operations - case DROP: // w -- - { - if (echo) bb->setName("DROP"); - decr_stack_index(bb, One); - break; - } - case DROP2: // w1 w2 -- - { - if (echo) bb->setName("DROP2"); - decr_stack_index( bb, Two ); - break; - } - case NIP: // w1 w2 -- w2 - { - if (echo) bb->setName("NIP"); - LoadInst* w2 = cast( stack_top( bb ) ); - decr_stack_index( bb ); - replace_top( bb, w2 ); - break; - } - case NIP2: // w1 w2 w3 w4 -- w3 w4 - { - if (echo) bb->setName("NIP2"); - LoadInst* w4 = cast( stack_top( bb ) ); - LoadInst* w3 = cast( stack_top( bb, One ) ); - decr_stack_index( bb, Two ); - replace_top( bb, w4 ); - replace_top( bb, w3, One ); - break; - } - case DUP: // w -- w w - { - if (echo) bb->setName("DUP"); - LoadInst* w = cast( stack_top( bb ) ); - push_value( bb, w ); - break; - } - case DUP2: // w1 w2 -- w1 w2 w1 w2 - { - if (echo) bb->setName("DUP2"); - LoadInst* w2 = cast( stack_top(bb) ); - LoadInst* w1 = cast( stack_top(bb, One ) ); - incr_stack_index( bb, Two ); - replace_top( bb, w1, One ); - replace_top( bb, w2 ); - break; - } - case SWAP: // w1 w2 -- w2 w1 - { - if (echo) bb->setName("SWAP"); - LoadInst* w2 = cast( stack_top( bb ) ); - LoadInst* w1 = cast( stack_top( bb, One ) ); - replace_top( bb, w1 ); - replace_top( bb, w2, One ); - break; - } - case SWAP2: // w1 w2 w3 w4 -- w3 w4 w1 w2 - { - if (echo) bb->setName("SWAP2"); - LoadInst* w4 = cast( stack_top( bb ) ); - LoadInst* w3 = cast( stack_top( bb, One ) ); - LoadInst* w2 = cast( stack_top( bb, Two ) ); - LoadInst* w1 = cast( stack_top( bb, Three ) ); - replace_top( bb, w2 ); - replace_top( bb, w1, One ); - replace_top( bb, w4, Two ); - replace_top( bb, w3, Three ); - break; - } - case OVER: // w1 w2 -- w1 w2 w1 - { - if (echo) bb->setName("OVER"); - LoadInst* w1 = cast( stack_top( bb, One ) ); - push_value( bb, w1 ); - break; - } - case OVER2: // w1 w2 w3 w4 -- w1 w2 w3 w4 w1 w2 - { - if (echo) bb->setName("OVER2"); - LoadInst* w2 = cast( stack_top( bb, Two ) ); - LoadInst* w1 = cast( stack_top( bb, Three ) ); - incr_stack_index( bb, Two ); - replace_top( bb, w2 ); - replace_top( bb, w1, One ); - break; - } - case ROT: // w1 w2 w3 -- w2 w3 w1 - { - if (echo) bb->setName("ROT"); - LoadInst* w3 = cast( stack_top( bb ) ); - LoadInst* w2 = cast( stack_top( bb, One ) ); - LoadInst* w1 = cast( stack_top( bb, Two ) ); - replace_top( bb, w1 ); - replace_top( bb, w3, One ); - replace_top( bb, w2, Two ); - break; - } - case ROT2: // w1 w2 w3 w4 w5 w6 -- w3 w4 w5 w6 w1 w2 - { - if (echo) bb->setName("ROT2"); - LoadInst* w6 = cast( stack_top( bb ) ); - LoadInst* w5 = cast( stack_top( bb, One ) ); - LoadInst* w4 = cast( stack_top( bb, Two ) ); - LoadInst* w3 = cast( stack_top( bb, Three) ); - LoadInst* w2 = cast( stack_top( bb, Four ) ); - LoadInst* w1 = cast( stack_top( bb, Five ) ); - replace_top( bb, w2 ); - replace_top( bb, w1, One ); - replace_top( bb, w6, Two ); - replace_top( bb, w5, Three ); - replace_top( bb, w4, Four ); - replace_top( bb, w3, Five ); - break; - } - case RROT: // w1 w2 w3 -- w3 w1 w2 - { - if (echo) bb->setName("RROT2"); - LoadInst* w3 = cast( stack_top( bb ) ); - LoadInst* w2 = cast( stack_top( bb, One ) ); - LoadInst* w1 = cast( stack_top( bb, Two ) ); - replace_top( bb, w2 ); - replace_top( bb, w1, One ); - replace_top( bb, w3, Two ); - break; - } - case RROT2: // w1 w2 w3 w4 w5 w6 -- w5 w6 w1 w2 w3 w4 - { - if (echo) bb->setName("RROT2"); - LoadInst* w6 = cast( stack_top( bb ) ); - LoadInst* w5 = cast( stack_top( bb, One ) ); - LoadInst* w4 = cast( stack_top( bb, Two ) ); - LoadInst* w3 = cast( stack_top( bb, Three) ); - LoadInst* w2 = cast( stack_top( bb, Four ) ); - LoadInst* w1 = cast( stack_top( bb, Five ) ); - replace_top( bb, w4 ); - replace_top( bb, w3, One ); - replace_top( bb, w2, Two ); - replace_top( bb, w1, Three ); - replace_top( bb, w6, Four ); - replace_top( bb, w5, Five ); - break; - } - case TUCK: // w1 w2 -- w2 w1 w2 - { - if (echo) bb->setName("TUCK"); - LoadInst* w2 = cast( stack_top( bb ) ); - LoadInst* w1 = cast( stack_top( bb, One ) ); - incr_stack_index( bb ); - replace_top( bb, w2 ); - replace_top( bb, w1, One ); - replace_top( bb, w2, Two ); - break; - } - case TUCK2: // w1 w2 w3 w4 -- w3 w4 w1 w2 w3 w4 - { - if (echo) bb->setName("TUCK2"); - LoadInst* w4 = cast( stack_top( bb ) ); - LoadInst* w3 = cast( stack_top( bb, One ) ); - LoadInst* w2 = cast( stack_top( bb, Two ) ); - LoadInst* w1 = cast( stack_top( bb, Three) ); - incr_stack_index( bb, Two ); - replace_top( bb, w4 ); - replace_top( bb, w3, One ); - replace_top( bb, w2, Two ); - replace_top( bb, w1, Three ); - replace_top( bb, w4, Four ); - replace_top( bb, w3, Five ); - break; - } - case ROLL: // x0 x1 .. xn n -- x1 .. xn x0 - { - /// THIS OEPRATOR IS OMITTED PURPOSEFULLY AND IS LEFT TO THE - /// READER AS AN EXERCISE. THIS IS ONE OF THE MORE COMPLICATED - /// OPERATORS. IF YOU CAN GET THIS ONE RIGHT, YOU COMPLETELY - /// UNDERSTAND HOW BOTH LLVM AND STACKER WOR. - /// HINT: LOOK AT PICK AND SELECT. ROLL IS SIMILAR. - if (echo) bb->setName("ROLL"); - break; - } - case PICK: // x0 ... Xn n -- x0 ... Xn x0 - { - if (echo) bb->setName("PICK"); - LoadInst* n = cast( stack_top( bb ) ); - BinaryOperator* addop = - BinaryOperator::create( Instruction::Add, n, One ); - bb->getInstList().push_back( addop ); - LoadInst* x0 = cast( stack_top( bb, addop ) ); - replace_top( bb, x0 ); - break; - } - case SELECT: // m n X0..Xm Xm+1 .. Xn -- Xm - { - if (echo) bb->setName("SELECT"); - LoadInst* m = cast( stack_top(bb) ); - LoadInst* n = cast( stack_top(bb, One) ); - BinaryOperator* index = - BinaryOperator::create( Instruction::Add, m, One ); - bb->getInstList().push_back( index ); - LoadInst* Xm = cast( stack_top(bb, index ) ); - BinaryOperator* n_plus_1 = - BinaryOperator::create( Instruction::Add, n, One ); - bb->getInstList().push_back( n_plus_1 ); - decr_stack_index( bb, n_plus_1 ); - replace_top( bb, Xm ); - break; + case DROP: // w -- + { + if (echo) bb->setName("DROP"); + decr_stack_index(bb, One); + break; + } + case DROP2: // w1 w2 -- + { + if (echo) bb->setName("DROP2"); + decr_stack_index( bb, Two ); + break; + } + case NIP: // w1 w2 -- w2 + { + if (echo) bb->setName("NIP"); + LoadInst* w2 = cast( stack_top( bb ) ); + decr_stack_index( bb ); + replace_top( bb, w2 ); + break; + } + case NIP2: // w1 w2 w3 w4 -- w3 w4 + { + if (echo) bb->setName("NIP2"); + LoadInst* w4 = cast( stack_top( bb ) ); + LoadInst* w3 = cast( stack_top( bb, One ) ); + decr_stack_index( bb, Two ); + replace_top( bb, w4 ); + replace_top( bb, w3, One ); + break; + } + case DUP: // w -- w w + { + if (echo) bb->setName("DUP"); + LoadInst* w = cast( stack_top( bb ) ); + push_value( bb, w ); + break; + } + case DUP2: // w1 w2 -- w1 w2 w1 w2 + { + if (echo) bb->setName("DUP2"); + LoadInst* w2 = cast( stack_top(bb) ); + LoadInst* w1 = cast( stack_top(bb, One ) ); + incr_stack_index( bb, Two ); + replace_top( bb, w1, One ); + replace_top( bb, w2 ); + break; + } + case SWAP: // w1 w2 -- w2 w1 + { + if (echo) bb->setName("SWAP"); + LoadInst* w2 = cast( stack_top( bb ) ); + LoadInst* w1 = cast( stack_top( bb, One ) ); + replace_top( bb, w1 ); + replace_top( bb, w2, One ); + break; + } + case SWAP2: // w1 w2 w3 w4 -- w3 w4 w1 w2 + { + if (echo) bb->setName("SWAP2"); + LoadInst* w4 = cast( stack_top( bb ) ); + LoadInst* w3 = cast( stack_top( bb, One ) ); + LoadInst* w2 = cast( stack_top( bb, Two ) ); + LoadInst* w1 = cast( stack_top( bb, Three ) ); + replace_top( bb, w2 ); + replace_top( bb, w1, One ); + replace_top( bb, w4, Two ); + replace_top( bb, w3, Three ); + break; + } + case OVER: // w1 w2 -- w1 w2 w1 + { + if (echo) bb->setName("OVER"); + LoadInst* w1 = cast( stack_top( bb, One ) ); + push_value( bb, w1 ); + break; + } + case OVER2: // w1 w2 w3 w4 -- w1 w2 w3 w4 w1 w2 + { + if (echo) bb->setName("OVER2"); + LoadInst* w2 = cast( stack_top( bb, Two ) ); + LoadInst* w1 = cast( stack_top( bb, Three ) ); + incr_stack_index( bb, Two ); + replace_top( bb, w2 ); + replace_top( bb, w1, One ); + break; + } + case ROT: // w1 w2 w3 -- w2 w3 w1 + { + if (echo) bb->setName("ROT"); + LoadInst* w3 = cast( stack_top( bb ) ); + LoadInst* w2 = cast( stack_top( bb, One ) ); + LoadInst* w1 = cast( stack_top( bb, Two ) ); + replace_top( bb, w1 ); + replace_top( bb, w3, One ); + replace_top( bb, w2, Two ); + break; + } + case ROT2: // w1 w2 w3 w4 w5 w6 -- w3 w4 w5 w6 w1 w2 + { + if (echo) bb->setName("ROT2"); + LoadInst* w6 = cast( stack_top( bb ) ); + LoadInst* w5 = cast( stack_top( bb, One ) ); + LoadInst* w4 = cast( stack_top( bb, Two ) ); + LoadInst* w3 = cast( stack_top( bb, Three) ); + LoadInst* w2 = cast( stack_top( bb, Four ) ); + LoadInst* w1 = cast( stack_top( bb, Five ) ); + replace_top( bb, w2 ); + replace_top( bb, w1, One ); + replace_top( bb, w6, Two ); + replace_top( bb, w5, Three ); + replace_top( bb, w4, Four ); + replace_top( bb, w3, Five ); + break; + } + case RROT: // w1 w2 w3 -- w3 w1 w2 + { + if (echo) bb->setName("RROT2"); + LoadInst* w3 = cast( stack_top( bb ) ); + LoadInst* w2 = cast( stack_top( bb, One ) ); + LoadInst* w1 = cast( stack_top( bb, Two ) ); + replace_top( bb, w2 ); + replace_top( bb, w1, One ); + replace_top( bb, w3, Two ); + break; + } + case RROT2: // w1 w2 w3 w4 w5 w6 -- w5 w6 w1 w2 w3 w4 + { + if (echo) bb->setName("RROT2"); + LoadInst* w6 = cast( stack_top( bb ) ); + LoadInst* w5 = cast( stack_top( bb, One ) ); + LoadInst* w4 = cast( stack_top( bb, Two ) ); + LoadInst* w3 = cast( stack_top( bb, Three) ); + LoadInst* w2 = cast( stack_top( bb, Four ) ); + LoadInst* w1 = cast( stack_top( bb, Five ) ); + replace_top( bb, w4 ); + replace_top( bb, w3, One ); + replace_top( bb, w2, Two ); + replace_top( bb, w1, Three ); + replace_top( bb, w6, Four ); + replace_top( bb, w5, Five ); + break; + } + case TUCK: // w1 w2 -- w2 w1 w2 + { + if (echo) bb->setName("TUCK"); + LoadInst* w2 = cast( stack_top( bb ) ); + LoadInst* w1 = cast( stack_top( bb, One ) ); + incr_stack_index( bb ); + replace_top( bb, w2 ); + replace_top( bb, w1, One ); + replace_top( bb, w2, Two ); + break; + } + case TUCK2: // w1 w2 w3 w4 -- w3 w4 w1 w2 w3 w4 + { + if (echo) bb->setName("TUCK2"); + LoadInst* w4 = cast( stack_top( bb ) ); + LoadInst* w3 = cast( stack_top( bb, One ) ); + LoadInst* w2 = cast( stack_top( bb, Two ) ); + LoadInst* w1 = cast( stack_top( bb, Three) ); + incr_stack_index( bb, Two ); + replace_top( bb, w4 ); + replace_top( bb, w3, One ); + replace_top( bb, w2, Two ); + replace_top( bb, w1, Three ); + replace_top( bb, w4, Four ); + replace_top( bb, w3, Five ); + break; + } + case ROLL: // x0 x1 .. xn n -- x1 .. xn x0 + { + /// THIS OEPRATOR IS OMITTED PURPOSEFULLY AND IS LEFT TO THE + /// READER AS AN EXERCISE. THIS IS ONE OF THE MORE COMPLICATED + /// OPERATORS. IF YOU CAN GET THIS ONE RIGHT, YOU COMPLETELY + /// UNDERSTAND HOW BOTH LLVM AND STACKER WOR. + /// HINT: LOOK AT PICK AND SELECT. ROLL IS SIMILAR. + if (echo) bb->setName("ROLL"); + break; + } + case PICK: // x0 ... Xn n -- x0 ... Xn x0 + { + if (echo) bb->setName("PICK"); + LoadInst* n = cast( stack_top( bb ) ); + BinaryOperator* addop = + BinaryOperator::create( Instruction::Add, n, One ); + bb->getInstList().push_back( addop ); + LoadInst* x0 = cast( stack_top( bb, addop ) ); + replace_top( bb, x0 ); + break; + } + case SELECT: // m n X0..Xm Xm+1 .. Xn -- Xm + { + if (echo) bb->setName("SELECT"); + LoadInst* m = cast( stack_top(bb) ); + LoadInst* n = cast( stack_top(bb, One) ); + BinaryOperator* index = + BinaryOperator::create( Instruction::Add, m, One ); + bb->getInstList().push_back( index ); + LoadInst* Xm = cast( stack_top(bb, index ) ); + BinaryOperator* n_plus_1 = + BinaryOperator::create( Instruction::Add, n, One ); + bb->getInstList().push_back( n_plus_1 ); + decr_stack_index( bb, n_plus_1 ); + replace_top( bb, Xm ); + break; } case MALLOC : // n -- p { - if (echo) bb->setName("MALLOC"); - // Get the number of bytes to mallocate - LoadInst* op1 = cast( pop_integer(bb) ); + if (echo) bb->setName("MALLOC"); + // Get the number of bytes to mallocate + LoadInst* op1 = cast( pop_integer(bb) ); - // Make sure its a UIntTy - CastInst* caster = new CastInst( op1, Type::UIntTy ); - bb->getInstList().push_back( caster ); + // Make sure its a UIntTy + CastInst* caster = new CastInst( op1, Type::UIntTy ); + bb->getInstList().push_back( caster ); - // Allocate the bytes - MallocInst* mi = new MallocInst( Type::SByteTy, caster ); - bb->getInstList().push_back( mi ); + // Allocate the bytes + MallocInst* mi = new MallocInst( Type::SByteTy, caster ); + bb->getInstList().push_back( mi ); - // Push the pointer - push_value( bb, mi ); - break; + // Push the pointer + push_value( bb, mi ); + break; } case FREE : // p -- { - if (echo) bb->setName("FREE"); - // Pop the value off the stack - CastInst* ptr = cast( pop_string(bb) ); + if (echo) bb->setName("FREE"); + // Pop the value off the stack + CastInst* ptr = cast( pop_string(bb) ); - // Free the memory - FreeInst* fi = new FreeInst( ptr ); - bb->getInstList().push_back( fi ); + // Free the memory + FreeInst* fi = new FreeInst( ptr ); + bb->getInstList().push_back( fi ); - break; + break; } case GET : // p w1 -- p w2 { - if (echo) bb->setName("GET"); - // Get the character index - LoadInst* op1 = cast( stack_top(bb) ); - CastInst* chr_idx = new CastInst( op1, Type::LongTy ); - bb->getInstList().push_back( chr_idx ); + if (echo) bb->setName("GET"); + // Get the character index + LoadInst* op1 = cast( stack_top(bb) ); + CastInst* chr_idx = new CastInst( op1, Type::LongTy ); + bb->getInstList().push_back( chr_idx ); - // Get the String pointer - CastInst* ptr = cast( stack_top_string(bb,One) ); + // Get the String pointer + CastInst* ptr = cast( stack_top_string(bb,One) ); - // Get address of op1'th element of the string - std::vector indexVec; - indexVec.push_back( chr_idx ); - GetElementPtrInst* gep = new GetElementPtrInst( ptr, indexVec ); - bb->getInstList().push_back( gep ); + // Get address of op1'th element of the string + std::vector indexVec; + indexVec.push_back( chr_idx ); + GetElementPtrInst* gep = new GetElementPtrInst( ptr, indexVec ); + bb->getInstList().push_back( gep ); - // Get the value and push it - LoadInst* loader = new LoadInst( gep ); - bb->getInstList().push_back( loader ); - CastInst* caster = new CastInst( loader, Type::IntTy ); - bb->getInstList().push_back( caster ); + // Get the value and push it + LoadInst* loader = new LoadInst( gep ); + bb->getInstList().push_back( loader ); + CastInst* caster = new CastInst( loader, Type::IntTy ); + bb->getInstList().push_back( caster ); - // Push the result back on stack - replace_top( bb, caster ); + // Push the result back on stack + replace_top( bb, caster ); - break; + break; } case PUT : // p w2 w1 -- p { - if (echo) bb->setName("PUT"); + if (echo) bb->setName("PUT"); - // Get the value to put - LoadInst* w1 = cast( pop_integer(bb) ); + // Get the value to put + LoadInst* w1 = cast( pop_integer(bb) ); - // Get the character index - LoadInst* w2 = cast( pop_integer(bb) ); - CastInst* chr_idx = new CastInst( w2, Type::LongTy ); - bb->getInstList().push_back( chr_idx ); + // Get the character index + LoadInst* w2 = cast( pop_integer(bb) ); + CastInst* chr_idx = new CastInst( w2, Type::LongTy ); + bb->getInstList().push_back( chr_idx ); - // Get the String pointer - CastInst* ptr = cast( stack_top_string(bb) ); + // Get the String pointer + CastInst* ptr = cast( stack_top_string(bb) ); - // Get address of op2'th element of the string - std::vector indexVec; - indexVec.push_back( chr_idx ); - GetElementPtrInst* gep = new GetElementPtrInst( ptr, indexVec ); - bb->getInstList().push_back( gep ); + // Get address of op2'th element of the string + std::vector indexVec; + indexVec.push_back( chr_idx ); + GetElementPtrInst* gep = new GetElementPtrInst( ptr, indexVec ); + bb->getInstList().push_back( gep ); - // Cast the value and put it - CastInst* caster = new CastInst( w1, Type::SByteTy ); - bb->getInstList().push_back( caster ); - StoreInst* storer = new StoreInst( caster, gep ); - bb->getInstList().push_back( storer ); + // Cast the value and put it + CastInst* caster = new CastInst( w1, Type::SByteTy ); + bb->getInstList().push_back( caster ); + StoreInst* storer = new StoreInst( caster, gep ); + bb->getInstList().push_back( storer ); - break; + break; } case RECURSE : { - if (echo) bb->setName("RECURSE"); - std::vector params; - CallInst* call_inst = new CallInst( TheFunction, params ); - bb->getInstList().push_back( call_inst ); - break; + if (echo) bb->setName("RECURSE"); + std::vector params; + CallInst* call_inst = new CallInst( TheFunction, params ); + bb->getInstList().push_back( call_inst ); + break; } case RETURN : { - if (echo) bb->setName("RETURN"); - bb->getInstList().push_back( new ReturnInst() ); - break; + if (echo) bb->setName("RETURN"); + bb->getInstList().push_back( new ReturnInst() ); + break; } case EXIT : { - if (echo) bb->setName("EXIT"); - // Get the result value - LoadInst* op1 = cast(pop_integer(bb)); + if (echo) bb->setName("EXIT"); + // Get the result value + LoadInst* op1 = cast(pop_integer(bb)); - // Cast down to an integer - CastInst* caster = new CastInst( op1, Type::IntTy ); - bb->getInstList().push_back( caster ); + // Cast down to an integer + CastInst* caster = new CastInst( op1, Type::IntTy ); + bb->getInstList().push_back( caster ); - // Call exit(3) - std::vector params; - params.push_back(caster); - CallInst* call_inst = new CallInst( TheExit, params ); - bb->getInstList().push_back( call_inst ); - break; + // Call exit(3) + std::vector params; + params.push_back(caster); + CallInst* call_inst = new CallInst( TheExit, params ); + bb->getInstList().push_back( call_inst ); + break; } case TAB : { - if (echo) bb->setName("TAB"); - // Get the format string for a character - std::vector indexVec; - indexVec.push_back( Zero ); - indexVec.push_back( Zero ); - GetElementPtrInst* format_gep = - new GetElementPtrInst( ChrFormat, indexVec ); - bb->getInstList().push_back( format_gep ); - - // Get the character to print (a tab) - ConstantSInt* newline = ConstantSInt::get(Type::IntTy, - static_cast('\t')); - - // Call printf - std::vector args; - args.push_back( format_gep ); - args.push_back( newline ); - bb->getInstList().push_back( new CallInst( ThePrintf, args ) ); - break; + if (echo) bb->setName("TAB"); + // Get the format string for a character + std::vector indexVec; + indexVec.push_back( Zero ); + indexVec.push_back( Zero ); + GetElementPtrInst* format_gep = + new GetElementPtrInst( ChrFormat, indexVec ); + bb->getInstList().push_back( format_gep ); + + // Get the character to print (a tab) + ConstantSInt* newline = ConstantSInt::get(Type::IntTy, + static_cast('\t')); + + // Call printf + std::vector args; + args.push_back( format_gep ); + args.push_back( newline ); + bb->getInstList().push_back( new CallInst( ThePrintf, args ) ); + break; } case SPACE : { - if (echo) bb->setName("SPACE"); - // Get the format string for a character - std::vector indexVec; - indexVec.push_back( Zero ); - indexVec.push_back( Zero ); - GetElementPtrInst* format_gep = - new GetElementPtrInst( ChrFormat, indexVec ); - bb->getInstList().push_back( format_gep ); - - // Get the character to print (a space) - ConstantSInt* newline = ConstantSInt::get(Type::IntTy, - static_cast(' ')); - - // Call printf - std::vector args; - args.push_back( format_gep ); - args.push_back( newline ); - bb->getInstList().push_back( new CallInst( ThePrintf, args ) ); - break; + if (echo) bb->setName("SPACE"); + // Get the format string for a character + std::vector indexVec; + indexVec.push_back( Zero ); + indexVec.push_back( Zero ); + GetElementPtrInst* format_gep = + new GetElementPtrInst( ChrFormat, indexVec ); + bb->getInstList().push_back( format_gep ); + + // Get the character to print (a space) + ConstantSInt* newline = ConstantSInt::get(Type::IntTy, + static_cast(' ')); + + // Call printf + std::vector args; + args.push_back( format_gep ); + args.push_back( newline ); + bb->getInstList().push_back( new CallInst( ThePrintf, args ) ); + break; } case CR : { - if (echo) bb->setName("CR"); - // Get the format string for a character - std::vector indexVec; - indexVec.push_back( Zero ); - indexVec.push_back( Zero ); - GetElementPtrInst* format_gep = - new GetElementPtrInst( ChrFormat, indexVec ); - bb->getInstList().push_back( format_gep ); - - // Get the character to print (a newline) - ConstantSInt* newline = ConstantSInt::get(Type::IntTy, - static_cast('\n')); - - // Call printf - std::vector args; - args.push_back( format_gep ); - args.push_back( newline ); - bb->getInstList().push_back( new CallInst( ThePrintf, args ) ); - break; + if (echo) bb->setName("CR"); + // Get the format string for a character + std::vector indexVec; + indexVec.push_back( Zero ); + indexVec.push_back( Zero ); + GetElementPtrInst* format_gep = + new GetElementPtrInst( ChrFormat, indexVec ); + bb->getInstList().push_back( format_gep ); + + // Get the character to print (a newline) + ConstantSInt* newline = ConstantSInt::get(Type::IntTy, + static_cast('\n')); + + // Call printf + std::vector args; + args.push_back( format_gep ); + args.push_back( newline ); + bb->getInstList().push_back( new CallInst( ThePrintf, args ) ); + break; } case IN_STR : { - if (echo) bb->setName("IN_STR"); - // Make room for the value result - incr_stack_index(bb); - GetElementPtrInst* gep_value = - cast(get_stack_pointer(bb)); - CastInst* caster = - new CastInst( gep_value, PointerType::get( Type::SByteTy ) ); - - // Make room for the count result - incr_stack_index(bb); - GetElementPtrInst* gep_count = - cast(get_stack_pointer(bb)); - - // Call scanf(3) - std::vector args; - args.push_back( InStrFormat ); - args.push_back( caster ); - CallInst* scanf = new CallInst( TheScanf, args ); - bb->getInstList().push_back( scanf ); - - // Store the result - bb->getInstList().push_back( new StoreInst( scanf, gep_count ) ); - break; + if (echo) bb->setName("IN_STR"); + // Make room for the value result + incr_stack_index(bb); + GetElementPtrInst* gep_value = + cast(get_stack_pointer(bb)); + CastInst* caster = + new CastInst( gep_value, PointerType::get( Type::SByteTy ) ); + + // Make room for the count result + incr_stack_index(bb); + GetElementPtrInst* gep_count = + cast(get_stack_pointer(bb)); + + // Call scanf(3) + std::vector args; + args.push_back( InStrFormat ); + args.push_back( caster ); + CallInst* scanf = new CallInst( TheScanf, args ); + bb->getInstList().push_back( scanf ); + + // Store the result + bb->getInstList().push_back( new StoreInst( scanf, gep_count ) ); + break; } case IN_NUM : { - if (echo) bb->setName("IN_NUM"); - // Make room for the value result - incr_stack_index(bb); - GetElementPtrInst* gep_value = - cast(get_stack_pointer(bb)); + if (echo) bb->setName("IN_NUM"); + // Make room for the value result + incr_stack_index(bb); + GetElementPtrInst* gep_value = + cast(get_stack_pointer(bb)); - // Make room for the count result - incr_stack_index(bb); - GetElementPtrInst* gep_count = - cast(get_stack_pointer(bb)); + // Make room for the count result + incr_stack_index(bb); + GetElementPtrInst* gep_count = + cast(get_stack_pointer(bb)); - // Call scanf(3) - std::vector args; - args.push_back( InStrFormat ); - args.push_back( gep_value ); - CallInst* scanf = new CallInst( TheScanf, args ); - bb->getInstList().push_back( scanf ); + // Call scanf(3) + std::vector args; + args.push_back( InStrFormat ); + args.push_back( gep_value ); + CallInst* scanf = new CallInst( TheScanf, args ); + bb->getInstList().push_back( scanf ); - // Store the result - bb->getInstList().push_back( new StoreInst( scanf, gep_count ) ); - break; + // Store the result + bb->getInstList().push_back( new StoreInst( scanf, gep_count ) ); + break; } case IN_CHAR : { - if (echo) bb->setName("IN_CHAR"); - // Make room for the value result - incr_stack_index(bb); - GetElementPtrInst* gep_value = - cast(get_stack_pointer(bb)); + if (echo) bb->setName("IN_CHAR"); + // Make room for the value result + incr_stack_index(bb); + GetElementPtrInst* gep_value = + cast(get_stack_pointer(bb)); - // Make room for the count result - incr_stack_index(bb); - GetElementPtrInst* gep_count = - cast(get_stack_pointer(bb)); + // Make room for the count result + incr_stack_index(bb); + GetElementPtrInst* gep_count = + cast(get_stack_pointer(bb)); - // Call scanf(3) - std::vector args; - args.push_back( InChrFormat ); - args.push_back( gep_value ); - CallInst* scanf = new CallInst( TheScanf, args ); - bb->getInstList().push_back( scanf ); + // Call scanf(3) + std::vector args; + args.push_back( InChrFormat ); + args.push_back( gep_value ); + CallInst* scanf = new CallInst( TheScanf, args ); + bb->getInstList().push_back( scanf ); - // Store the result - bb->getInstList().push_back( new StoreInst( scanf, gep_count ) ); - break; + // Store the result + bb->getInstList().push_back( new StoreInst( scanf, gep_count ) ); + break; } case OUT_STR : { - if (echo) bb->setName("OUT_STR"); - LoadInst* op1 = cast(stack_top(bb)); - - // Get the address of the format string - std::vector indexVec; - indexVec.push_back( Zero ); - indexVec.push_back( Zero ); - GetElementPtrInst* format_gep = - new GetElementPtrInst( StrFormat, indexVec ); - bb->getInstList().push_back( format_gep ); - // Build function call arguments - std::vector args; - args.push_back( format_gep ); - args.push_back( op1 ); - // Call printf - bb->getInstList().push_back( new CallInst( ThePrintf, args ) ); - break; + if (echo) bb->setName("OUT_STR"); + LoadInst* op1 = cast(stack_top(bb)); + + // Get the address of the format string + std::vector indexVec; + indexVec.push_back( Zero ); + indexVec.push_back( Zero ); + GetElementPtrInst* format_gep = + new GetElementPtrInst( StrFormat, indexVec ); + bb->getInstList().push_back( format_gep ); + // Build function call arguments + std::vector args; + args.push_back( format_gep ); + args.push_back( op1 ); + // Call printf + bb->getInstList().push_back( new CallInst( ThePrintf, args ) ); + break; } case OUT_NUM : { - if (echo) bb->setName("OUT_NUM"); - // Pop the numeric operand off the stack - LoadInst* op1 = cast(stack_top(bb)); + if (echo) bb->setName("OUT_NUM"); + // Pop the numeric operand off the stack + LoadInst* op1 = cast(stack_top(bb)); - // Get the address of the format string - std::vector indexVec; - indexVec.push_back( Zero ); - indexVec.push_back( Zero ); - GetElementPtrInst* format_gep = - new GetElementPtrInst( NumFormat, indexVec ); - bb->getInstList().push_back( format_gep ); + // Get the address of the format string + std::vector indexVec; + indexVec.push_back( Zero ); + indexVec.push_back( Zero ); + GetElementPtrInst* format_gep = + new GetElementPtrInst( NumFormat, indexVec ); + bb->getInstList().push_back( format_gep ); - // Build function call arguments - std::vector args; - args.push_back( format_gep ); - args.push_back( op1 ); + // Build function call arguments + std::vector args; + args.push_back( format_gep ); + args.push_back( op1 ); - // Call printf - bb->getInstList().push_back( new CallInst( ThePrintf, args ) ); - break; + // Call printf + bb->getInstList().push_back( new CallInst( ThePrintf, args ) ); + break; } case OUT_CHAR : { - if (echo) bb->setName("OUT_CHAR"); - // Pop the character operand off the stack - LoadInst* op1 = cast(stack_top(bb)); - - // Get the address of the format string - std::vector indexVec; - indexVec.push_back( Zero ); - indexVec.push_back( Zero ); - GetElementPtrInst* format_gep = - new GetElementPtrInst( ChrFormat, indexVec ); - bb->getInstList().push_back( format_gep ); - - // Build function call arguments - std::vector args; - args.push_back( format_gep ); - args.push_back( op1 ); - // Call printf - bb->getInstList().push_back( new CallInst( ThePrintf, args ) ); - break; + if (echo) bb->setName("OUT_CHAR"); + // Pop the character operand off the stack + LoadInst* op1 = cast(stack_top(bb)); + + // Get the address of the format string + std::vector indexVec; + indexVec.push_back( Zero ); + indexVec.push_back( Zero ); + GetElementPtrInst* format_gep = + new GetElementPtrInst( ChrFormat, indexVec ); + bb->getInstList().push_back( format_gep ); + + // Build function call arguments + std::vector args; + args.push_back( format_gep ); + args.push_back( op1 ); + // Call printf + bb->getInstList().push_back( new CallInst( ThePrintf, args ) ); + break; } default : { - ThrowException(std::string("Compiler Error: Unhandled token #")); + ThrowException(std::string("Compiler Error: Unhandled token #")); } } diff --git a/projects/Stacker/lib/compiler/StackerCompiler.h b/projects/Stacker/lib/compiler/StackerCompiler.h index cd48ccb382d..383e569c251 100644 --- a/projects/Stacker/lib/compiler/StackerCompiler.h +++ b/projects/Stacker/lib/compiler/StackerCompiler.h @@ -46,176 +46,176 @@ class StackerCompiler /// @name Constructors and Operators /// @{ public: - /// Default Constructor - StackerCompiler(); + /// Default Constructor + StackerCompiler(); - /// Destructor - ~StackerCompiler(); + /// Destructor + ~StackerCompiler(); private: - /// Do not copy StackerCompilers - StackerCompiler(const StackerCompiler&); + /// Do not copy StackerCompilers + StackerCompiler(const StackerCompiler&); - /// Do not copy StackerCompilers. - StackerCompiler& operator=(const StackerCompiler& ); + /// Do not copy StackerCompilers. + StackerCompiler& operator=(const StackerCompiler& ); /// @} /// @name High Level Interface /// @{ public: - /// @brief Compile a single file to LLVM bytecode. - /// - /// To use the StackerCompiler, just create one on - /// the stack and call this method. - Module* compile( - const std::string& filename, ///< File to compile - bool echo, ///< Causes compiler to echo output + /// @brief Compile a single file to LLVM bytecode. + /// + /// To use the StackerCompiler, just create one on + /// the stack and call this method. + Module* compile( + const std::string& filename, ///< File to compile + bool echo, ///< Causes compiler to echo output unsigned optLevel, ///< Level of optimization - size_t stack_size ); ///< Size of generated stack + size_t stack_size ); ///< Size of generated stack /// @} /// @name Accessors /// @{ public: - /// @brief Returns the name of the file being compiled. - std::string& filename() { return CurFilename; } + /// @brief Returns the name of the file being compiled. + std::string& filename() { return CurFilename; } /// @} /// @name Parse Handling Methods /// @{ private: - /// Allow only the parser to access these methods. No - /// one else should call them. - friend int Stackerparse(); + /// Allow only the parser to access these methods. No + /// one else should call them. + friend int Stackerparse(); - /// @brief Handle the start of a module - Module* handle_module_start(); + /// @brief Handle the start of a module + Module* handle_module_start(); - /// @brief Handle the end of a module - /// @param mod The module we're defining. - Module* handle_module_end( Module* mod ); + /// @brief Handle the end of a module + /// @param mod The module we're defining. + Module* handle_module_end( Module* mod ); - /// @brief Handle the start of a list of definitions - Module* handle_definition_list_start( ); + /// @brief Handle the start of a list of definitions + Module* handle_definition_list_start( ); - /// @brief Handle the end of a list of definitions - /// @param mod The module we're constructing - /// @param definition A definition (function) to add to the module - Module* handle_definition_list_end( Module* mod, Function* definition ); + /// @brief Handle the end of a list of definitions + /// @param mod The module we're constructing + /// @param definition A definition (function) to add to the module + Module* handle_definition_list_end( Module* mod, Function* definition ); - /// @brief Handle creation of the MAIN definition - /// @param func The function to be used as the MAIN definition - Function* handle_main_definition( Function* func ); + /// @brief Handle creation of the MAIN definition + /// @param func The function to be used as the MAIN definition + Function* handle_main_definition( Function* func ); - /// @brief Handle a forward definition - /// @param name The name of the definition being declared - Function* handle_forward( char* name ); + /// @brief Handle a forward definition + /// @param name The name of the definition being declared + Function* handle_forward( char* name ); - /// @brief Handle a general definition - /// @param name The name of the definition being defined - /// @param func The Function definition. - Function* handle_definition( char* name, Function* func ); + /// @brief Handle a general definition + /// @param name The name of the definition being defined + /// @param func The Function definition. + Function* handle_definition( char* name, Function* func ); - /// @brief Handle the start of a definition's word list - Function* handle_word_list_start(); + /// @brief Handle the start of a definition's word list + Function* handle_word_list_start(); - /// @brief Handle the end of a definition's word list - /// @param func The function to which the basic block is added - /// @param next The block to add to the function - Function* handle_word_list_end( Function* func, BasicBlock* next ); + /// @brief Handle the end of a definition's word list + /// @param func The function to which the basic block is added + /// @param next The block to add to the function + Function* handle_word_list_end( Function* func, BasicBlock* next ); - /// @brief Handle an if statement, possibly without an else - /// @brief ifTrue The block to execute if true - /// @brief ifFalse The optional block to execute if false - BasicBlock* handle_if( char* ifTrue, char* ifFalse = 0 ); + /// @brief Handle an if statement, possibly without an else + /// @brief ifTrue The block to execute if true + /// @brief ifFalse The optional block to execute if false + BasicBlock* handle_if( char* ifTrue, char* ifFalse = 0 ); - /// @brief Handle a while statement - /// @brief todo The block to repeatedly execute - BasicBlock* handle_while( char* todo ); + /// @brief Handle a while statement + /// @brief todo The block to repeatedly execute + BasicBlock* handle_while( char* todo ); - /// @brief Handle an identifier to call the identified definition - /// @param name The name of the identifier to be called. - BasicBlock* handle_identifier( char * name ); + /// @brief Handle an identifier to call the identified definition + /// @param name The name of the identifier to be called. + BasicBlock* handle_identifier( char * name ); - /// @brief Handle the push of a string onto the stack - /// @param value The string to be pushed. - BasicBlock* handle_string( char * value ); + /// @brief Handle the push of a string onto the stack + /// @param value The string to be pushed. + BasicBlock* handle_string( char * value ); - /// @brief Handle the push of an integer onto the stack. - /// @param value The integer value to be pushed. - BasicBlock* handle_integer( const int64_t value ); + /// @brief Handle the push of an integer onto the stack. + /// @param value The integer value to be pushed. + BasicBlock* handle_integer( const int64_t value ); - /// @brief Handle one of the reserved words (given as a token) - BasicBlock* handle_word( int tkn ); + /// @brief Handle one of the reserved words (given as a token) + BasicBlock* handle_word( int tkn ); /// @} /// @name Utility functions /// @{ public: - /// @brief Throws an exception to indicate an error - /// @param message The message to be output - /// @param line Override for the current line no - static inline void ThrowException( const std::string &message, - int line = -1) - { - if (line == -1) line = Stackerlineno; - // TODO: column number in exception - throw ParseException(TheInstance->CurFilename, message, line); - } + /// @brief Throws an exception to indicate an error + /// @param message The message to be output + /// @param line Override for the current line no + static inline void ThrowException( const std::string &message, + int line = -1) + { + if (line == -1) line = Stackerlineno; + // TODO: column number in exception + throw ParseException(TheInstance->CurFilename, message, line); + } private: - /// @brief Generate code to increment the stack index - Instruction* incr_stack_index( BasicBlock* bb, Value* ); - /// @brief Generate code to decrement the stack index. - Instruction* decr_stack_index( BasicBlock* bb, Value* ); - /// @brief Generate code to dereference the top of stack. - Instruction* get_stack_pointer( BasicBlock* bb, Value* ); - /// @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, 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. - Instruction* push_string( BasicBlock* bb, const char* value ); - /// @brief Generate code to pop a string pointer off the stack. - Instruction* pop_string( BasicBlock* bb ); - /// @brief Generate code to get the top stack element. - Instruction* stack_top( BasicBlock* bb, Value* index ); - /// @brief Generate code to get the top stack element as a string. - Instruction* stack_top_string( BasicBlock* bb, Value* index ); - /// @brief Generate code to replace the top element of the stack. - Instruction* replace_top( BasicBlock* bb, Value* new_top, Value* index); + /// @brief Generate code to increment the stack index + Instruction* incr_stack_index( BasicBlock* bb, Value* ); + /// @brief Generate code to decrement the stack index. + Instruction* decr_stack_index( BasicBlock* bb, Value* ); + /// @brief Generate code to dereference the top of stack. + Instruction* get_stack_pointer( BasicBlock* bb, Value* ); + /// @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, 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. + Instruction* push_string( BasicBlock* bb, const char* value ); + /// @brief Generate code to pop a string pointer off the stack. + Instruction* pop_string( BasicBlock* bb ); + /// @brief Generate code to get the top stack element. + Instruction* stack_top( BasicBlock* bb, Value* index ); + /// @brief Generate code to get the top stack element as a string. + Instruction* stack_top_string( BasicBlock* bb, Value* index ); + /// @brief Generate code to replace the top element of the stack. + Instruction* replace_top( BasicBlock* bb, Value* new_top, Value* index); /// @} /// @name Data Members (used during parsing) /// @{ public: - static StackerCompiler* TheInstance; ///< The instance for the parser + static StackerCompiler* TheInstance; ///< The instance for the parser private: - std::string CurFilename; ///< Current file name - Module* TheModule; ///< Module instance we'll build - Function* TheFunction; ///< Function we're building - FunctionType* DefinitionType; ///< FT for Definitions - GlobalVariable* TheStack; ///< For referencing _stack_ - GlobalVariable* TheIndex; ///< For referencing _index_ - Function* TheScanf; ///< External input function - Function* ThePrintf; ///< External output function - Function* TheExit; ///< External exit function - GlobalVariable* StrFormat; ///< Format for strings - GlobalVariable* NumFormat; ///< Format for numbers - GlobalVariable* ChrFormat; ///< Format for chars - GlobalVariable* InStrFormat; ///< Format for input strings - GlobalVariable* InNumFormat; ///< Format for input numbers - GlobalVariable* InChrFormat; ///< Format for input chars - ConstantInt* Zero; ///< long constant 0 - ConstantInt* One; ///< long constant 1 - ConstantInt* Two; ///< long constant 2 - ConstantInt* Three; ///< long constant 3 - ConstantInt* Four; ///< long constant 4 - ConstantInt* Five; ///< long constant 5 - std::vector no_arguments; ///< no arguments for Stacker - bool echo; ///< Echo flag - size_t stack_size; ///< Size of stack to gen. - ArrayType* stack_type; ///< The type of the stack + std::string CurFilename; ///< Current file name + Module* TheModule; ///< Module instance we'll build + Function* TheFunction; ///< Function we're building + FunctionType* DefinitionType; ///< FT for Definitions + GlobalVariable* TheStack; ///< For referencing _stack_ + GlobalVariable* TheIndex; ///< For referencing _index_ + Function* TheScanf; ///< External input function + Function* ThePrintf; ///< External output function + Function* TheExit; ///< External exit function + GlobalVariable* StrFormat; ///< Format for strings + GlobalVariable* NumFormat; ///< Format for numbers + GlobalVariable* ChrFormat; ///< Format for chars + GlobalVariable* InStrFormat; ///< Format for input strings + GlobalVariable* InNumFormat; ///< Format for input numbers + GlobalVariable* InChrFormat; ///< Format for input chars + ConstantInt* Zero; ///< long constant 0 + ConstantInt* One; ///< long constant 1 + ConstantInt* Two; ///< long constant 2 + ConstantInt* Three; ///< long constant 3 + ConstantInt* Four; ///< long constant 4 + ConstantInt* Five; ///< long constant 5 + std::vector no_arguments; ///< no arguments for Stacker + bool echo; ///< Echo flag + size_t stack_size; ///< Size of stack to gen. + ArrayType* stack_type; ///< The type of the stack /// @} }; diff --git a/projects/Stacker/lib/runtime/stacker_rt.c b/projects/Stacker/lib/runtime/stacker_rt.c index d19b1131548..0ca4cc7a95c 100644 --- a/projects/Stacker/lib/runtime/stacker_rt.c +++ b/projects/Stacker/lib/runtime/stacker_rt.c @@ -1,11 +1,11 @@ //===-- stacker_rt.c - Runtime Support For Stacker Compiler -----*- C++ -*-===// -// +// // The LLVM Compiler Infrastructure // -// This file was developed by Reid Spencer and donated to the LLVM research -// group and is distributed under the University of Illinois Open Source +// This file was developed by Reid Spencer and donated to the LLVM research +// group and is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. -// +// //===----------------------------------------------------------------------===// // // This file defines a stack dumping function that can be used for debugging. @@ -33,7 +33,7 @@ _stacker_dump_stack_() printf("Stack Dump:\n"); for (i = _index_; i > 0; i-- ) { - printf("#%03lld: %lld\n", (long long int) i, (long long int) _stack_[i] ); + printf("#%03lld: %lld\n", (long long int) i, (long long int) _stack_[i] ); } } @@ -50,14 +50,14 @@ main ( int argc, char** argv ) // so that they get popped in the order presented while ( a > 0 ) { - if ( isdigit( (int) argv[--a][0] ) ) - { - _stack_[_index_++] = atoll( argv[a] ); - } - else - { - _stack_[_index_++] = (int64_t) (intptr_t) argv[a]; - } + if ( isdigit( (int) argv[--a][0] ) ) + { + _stack_[_index_++] = atoll( argv[a] ); + } + else + { + _stack_[_index_++] = (int64_t) (intptr_t) argv[a]; + } } // Put the argument count on the stack @@ -68,6 +68,6 @@ main ( int argc, char** argv ) // Return last item on the stack if ( _index_ >= 0 ) - return _stack_[_index_]; + return _stack_[_index_]; return -1; } diff --git a/projects/Stacker/tools/stkrc/stkrc.cpp b/projects/Stacker/tools/stkrc/stkrc.cpp index 34b28203713..647fee42a91 100644 --- a/projects/Stacker/tools/stkrc/stkrc.cpp +++ b/projects/Stacker/tools/stkrc/stkrc.cpp @@ -34,14 +34,14 @@ InputFilename(cl::Positional, cl::desc(""), cl::init("-")); static cl::opt OutputFilename("o", cl::desc("Override output filename"), - cl::value_desc("filename")); + cl::value_desc("filename")); static cl::opt Force("f", cl::desc("Overwrite output files")); static cl::opt StackSize("s", cl::desc("Specify program maximum stack size"), - cl::init(1024), cl::value_desc("stack size")); + cl::init(1024), cl::value_desc("stack size")); static cl::opt DumpAsm("d", cl::desc("Print LLVM Assembly as parsed"), cl::Hidden); diff --git a/projects/sample/include/sample.h b/projects/sample/include/sample.h index db3441f76ff..b3ce9ce2928 100644 --- a/projects/sample/include/sample.h +++ b/projects/sample/include/sample.h @@ -1,8 +1,8 @@ /* * File: sample.h * - * This is a sample header file that is global to the entire project. - * It is located here so that everyone will find it. + * This is a sample header file that is global to the entire project. + * It is located here so that everyone will find it. */ extern int compute_sample (int a); diff --git a/projects/sample/lib/sample/sample.c b/projects/sample/lib/sample/sample.c index 631a48d1ad1..73c1fee79b2 100644 --- a/projects/sample/lib/sample/sample.c +++ b/projects/sample/lib/sample/sample.c @@ -2,9 +2,9 @@ * File: sample.c * * Description: - * This is a sample source file for a library. It helps to demonstrate - * how to setup a project that uses the LLVM build system, header files, - * and libraries. + * This is a sample source file for a library. It helps to demonstrate + * how to setup a project that uses the LLVM build system, header files, + * and libraries. */ #include @@ -19,6 +19,6 @@ int compute_sample (int a) { - return a; + return a; } diff --git a/projects/sample/tools/sample/main.c b/projects/sample/tools/sample/main.c index 66073352de0..2880265f845 100644 --- a/projects/sample/tools/sample/main.c +++ b/projects/sample/tools/sample/main.c @@ -8,7 +8,7 @@ int main (int argc, char ** argv) { - printf ("%d\n", compute_sample (5)); - exit (0); + printf ("%d\n", compute_sample (5)); + exit (0); } diff --git a/test/C++Frontend/2003-09-22-CompositeExprValue.cpp b/test/C++Frontend/2003-09-22-CompositeExprValue.cpp index b1373ba66dc..a8208adc512 100644 --- a/test/C++Frontend/2003-09-22-CompositeExprValue.cpp +++ b/test/C++Frontend/2003-09-22-CompositeExprValue.cpp @@ -2,10 +2,10 @@ struct duration { duration operator/=(int c) { - return *this; + return *this; } }; void a000090() { - duration() /= 1; + duration() /= 1; } diff --git a/test/C++Frontend/2003-09-29-ArgumentNumberMismatch.cpp b/test/C++Frontend/2003-09-29-ArgumentNumberMismatch.cpp index 19435c60750..4873123d124 100644 --- a/test/C++Frontend/2003-09-29-ArgumentNumberMismatch.cpp +++ b/test/C++Frontend/2003-09-29-ArgumentNumberMismatch.cpp @@ -5,13 +5,13 @@ // was mistakenly "thinking" that 'foo' took a structure by component. struct C { - int A, B; - ~C() {} + int A, B; + ~C() {} }; void foo(C b); void test(C *P) { - foo(*P); + foo(*P); } diff --git a/test/CFrontend/2002-02-13-TypeVarNameCollision.c b/test/CFrontend/2002-02-13-TypeVarNameCollision.c index f4daa2186b2..ec334013ae0 100644 --- a/test/CFrontend/2002-02-13-TypeVarNameCollision.c +++ b/test/CFrontend/2002-02-13-TypeVarNameCollision.c @@ -1,16 +1,16 @@ // RUN: %llvmgcc -S %s -o - | llvm-as -f -o /dev/null -/* This testcase causes a symbol table collision. Type names and variable +/* This testcase causes a symbol table collision. Type names and variable * names should be in distinct namespaces */ typedef struct foo { - int X, Y; + int X, Y; } FOO; static FOO foo[100]; int test() { - return foo[4].Y; + return foo[4].Y; } diff --git a/test/CFrontend/2002-02-18-64bitConstant.c b/test/CFrontend/2002-02-18-64bitConstant.c index f2ed1216524..6fd3e29d242 100644 --- a/test/CFrontend/2002-02-18-64bitConstant.c +++ b/test/CFrontend/2002-02-18-64bitConstant.c @@ -3,7 +3,6 @@ /* GCC wasn't handling 64 bit constants right fixed */ void main() { - long long Var = 123455678902ll; - printf("%lld\n", Var); - + long long Var = 123455678902ll; + printf("%lld\n", Var); } diff --git a/test/CFrontend/2002-03-11-LargeCharInString.c b/test/CFrontend/2002-03-11-LargeCharInString.c index 8ae86436fe0..d8a1671fc77 100644 --- a/test/CFrontend/2002-03-11-LargeCharInString.c +++ b/test/CFrontend/2002-03-11-LargeCharInString.c @@ -3,8 +3,8 @@ #include int test(char *X) { - /* LLVM-GCC used to emit: - %.LC0 = internal global [3 x sbyte] c"\1F\FFFFFF8B\00" - */ - return strcmp(X, "\037\213"); + /* LLVM-GCC used to emit: + %.LC0 = internal global [3 x sbyte] c"\1F\FFFFFF8B\00" + */ + return strcmp(X, "\037\213"); } diff --git a/test/CFrontend/2002-03-14-QuotesInStrConst.c b/test/CFrontend/2002-03-14-QuotesInStrConst.c index 20348488760..42f82bfa895 100644 --- a/test/CFrontend/2002-03-14-QuotesInStrConst.c +++ b/test/CFrontend/2002-03-14-QuotesInStrConst.c @@ -1,10 +1,10 @@ // RUN: %llvmgcc -S %s -o - | llvm-as -f -o /dev/null -/* GCC was not escaping quotes in string constants correctly, so this would +/* GCC was not escaping quotes in string constants correctly, so this would * get emitted: * %.LC1 = internal global [32 x sbyte] c"*** Word "%s" on line %d is not\00" */ const char *Foo() { - return "*** Word \"%s\" on line %d is not"; + return "*** Word \"%s\" on line %d is not"; } diff --git a/test/CFrontend/2002-05-23-StaticValues.c b/test/CFrontend/2002-05-23-StaticValues.c index 79d46ae8ab0..bf583e203d3 100644 --- a/test/CFrontend/2002-05-23-StaticValues.c +++ b/test/CFrontend/2002-05-23-StaticValues.c @@ -10,6 +10,6 @@ static void foo(int Z) { } void *test() { - foo(12); - return &Y; + foo(12); + return &Y; } diff --git a/test/CFrontend/2002-05-24-Alloca.c b/test/CFrontend/2002-05-24-Alloca.c index 0a44db12ea2..ac5b78d0c99 100644 --- a/test/CFrontend/2002-05-24-Alloca.c +++ b/test/CFrontend/2002-05-24-Alloca.c @@ -5,7 +5,7 @@ #include int main(int argc, char **argv) { - char *C = (char*)alloca(argc); - strcpy(C, argv[0]); - puts(C); + char *C = (char*)alloca(argc); + strcpy(C, argv[0]); + puts(C); } diff --git a/test/CFrontend/2002-06-25-FWriteInterfaceFailure.c b/test/CFrontend/2002-06-25-FWriteInterfaceFailure.c index 654709299d0..fb1b54bf72e 100644 --- a/test/CFrontend/2002-06-25-FWriteInterfaceFailure.c +++ b/test/CFrontend/2002-06-25-FWriteInterfaceFailure.c @@ -3,5 +3,5 @@ #include void test() { - fprintf(stderr, "testing\n"); + fprintf(stderr, "testing\n"); } diff --git a/test/CFrontend/2002-07-14-MiscTests3.c b/test/CFrontend/2002-07-14-MiscTests3.c index a19e2d54c93..9a262d5fcef 100644 --- a/test/CFrontend/2002-07-14-MiscTests3.c +++ b/test/CFrontend/2002-07-14-MiscTests3.c @@ -23,7 +23,7 @@ struct Quad { struct SubStruct *SSP; char c; int y; -}; +}; struct Quad GlobalQuad = { 4, {1, 2}, 0, 3, 156 }; @@ -65,7 +65,7 @@ int F1(struct Quad *Q, int i) { /* Pass Q by address */ int BadFunc(float Val) { - int Result; + int Result; if (Val > 12.345) Result = 4; return Result; /* Test use of undefined value */ } @@ -80,14 +80,14 @@ int Func(int Param, long long Param2) { int Result = Param; {{{{ - char c; int X; - EF1(&Result, &c, &X); - }}} - - { // c & X are duplicate names! - char c; int X; - EF1(&Result, &c, &X); - } + char c; int X; + EF1(&Result, &c, &X); + }}} + + { // c & X are duplicate names! + char c; int X; + EF1(&Result, &c, &X); + } } return Result; @@ -129,7 +129,7 @@ int ArrayToSum(void) { for (i = 0; i < 100; ++i) A[i] = i*4; - return A[A[0]]; //SumArray(A, 100); + return A[A[0]]; //SumArray(A, 100); } @@ -141,7 +141,7 @@ int main(int argc, char *argv[]) { ExternFunc(-1, 0, (short)argc, 2); //func(argc, argc); - + for (i = 0; i < 10; i++) puts(argv[3]); return 0; @@ -159,29 +159,29 @@ double MathFunc(double X, double Y, double Z, void strcpy(char *s1, char *s2) { - while (*s1++ = *s2++); + while (*s1++ = *s2++); } void strcat(char *s1, char *s2) { - while (*s1++); - s1--; - while (*s1++ = *s2++); + while (*s1++); + s1--; + while (*s1++ = *s2++); } int strcmp(char *s1, char *s2) { - while (*s1++ == *s2++); - if (*s1 == 0) { - if (*s2 == 0) { - return 0; - } else { - return -1; - } + while (*s1++ == *s2++); + if (*s1 == 0) { + if (*s2 == 0) { + return 0; + } else { + return -1; + } + } else { + if (*s2 == 0) { + return 1; } else { - if (*s2 == 0) { - return 1; - } else { - return (*(--s1) - *(--s2)); - } + return (*(--s1) - *(--s2)); } + } } diff --git a/test/CFrontend/2002-07-30-SubregSetAssertion.c b/test/CFrontend/2002-07-30-SubregSetAssertion.c index 7eab19b0456..6d4f9f62058 100644 --- a/test/CFrontend/2002-07-30-SubregSetAssertion.c +++ b/test/CFrontend/2002-07-30-SubregSetAssertion.c @@ -6,7 +6,7 @@ union X { }; union X foo() { - union X A; - A.B = (void*)123; - return A; + union X A; + A.B = (void*)123; + return A; } diff --git a/test/CFrontend/2002-07-30-UnionTest.c b/test/CFrontend/2002-07-30-UnionTest.c index 634ed3f61bf..b2c481e4079 100644 --- a/test/CFrontend/2002-07-30-UnionTest.c +++ b/test/CFrontend/2002-07-30-UnionTest.c @@ -7,16 +7,16 @@ union Q { union Q *X; }; union X { char C; int A, Z; - long long B; + long long B; void *b1; struct { int A; long long Z; } Q; }; union X foo(union X A) { - A.C = 123; - A.A = 39249; - //A.B = (void*)123040123321; - A.B = 12301230123123LL; - A.Z = 1; - return A; + A.C = 123; + A.A = 39249; + //A.B = (void*)123040123321; + A.B = 12301230123123LL; + A.Z = 1; + return A; } diff --git a/test/CFrontend/2002-07-30-VarArgsCallFailure.c b/test/CFrontend/2002-07-30-VarArgsCallFailure.c index 14c879c7a92..b37a462220b 100644 --- a/test/CFrontend/2002-07-30-VarArgsCallFailure.c +++ b/test/CFrontend/2002-07-30-VarArgsCallFailure.c @@ -3,6 +3,6 @@ int tcount; void test(char *, const char*, int); void foo() { - char Buf[10]; - test(Buf, "n%%%d", tcount++); + char Buf[10]; + test(Buf, "n%%%d", tcount++); } diff --git a/test/CFrontend/2002-08-02-UnionTest.c b/test/CFrontend/2002-08-02-UnionTest.c index b9e2c2e0506..bc44e461dec 100644 --- a/test/CFrontend/2002-08-02-UnionTest.c +++ b/test/CFrontend/2002-08-02-UnionTest.c @@ -8,12 +8,12 @@ union X { char X; void *B; int a, b, c, d;}; union X foo() { - union X Global; - Global.B = (void*)123; /* Interesting part */ - return Global; + union X Global; + Global.B = (void*)123; /* Interesting part */ + return Global; } void main() { - union X test = foo(); - printf("0x%p", test.B); + union X test = foo(); + printf("0x%p", test.B); } diff --git a/test/CFrontend/2002-09-08-PointerShifts.c b/test/CFrontend/2002-09-08-PointerShifts.c index e58d858c37e..cc7e91a7f9a 100644 --- a/test/CFrontend/2002-09-08-PointerShifts.c +++ b/test/CFrontend/2002-09-08-PointerShifts.c @@ -2,5 +2,5 @@ int foo(int *A, unsigned X) { - return A[X]; + return A[X]; } diff --git a/test/CFrontend/2002-10-12-TooManyArguments.c b/test/CFrontend/2002-10-12-TooManyArguments.c index 0c31f2b90a1..206cdd98da0 100644 --- a/test/CFrontend/2002-10-12-TooManyArguments.c +++ b/test/CFrontend/2002-10-12-TooManyArguments.c @@ -4,5 +4,5 @@ void foo() {} void bar() { - foo(1, 2, 3); /* Too many arguments passed */ + foo(1, 2, 3); /* Too many arguments passed */ } diff --git a/test/CodeGen/Generic/BasicInstrs.c b/test/CodeGen/Generic/BasicInstrs.c index 9a378b996a0..141d32bbc09 100644 --- a/test/CodeGen/Generic/BasicInstrs.c +++ b/test/CodeGen/Generic/BasicInstrs.c @@ -1,4 +1,4 @@ -// This file can be used to see what a native C compiler is generating for a +// This file can be used to see what a native C compiler is generating for a // variety of interesting operations. // // RUN: %llvmgcc -c %s -o - | llc @@ -23,4 +23,4 @@ _Bool setlt(int X, int Y) { _Bool setgt(int X, int Y) { return X > Y; } - + diff --git a/test/Debugger/funccall.c b/test/Debugger/funccall.c index b99a8851d31..4d016ecd017 100644 --- a/test/Debugger/funccall.c +++ b/test/Debugger/funccall.c @@ -2,15 +2,15 @@ static int q; void foo() { - int t = q; - q = t + 1; + int t = q; + q = t + 1; } int main() { - q = 0; - foo(); - q = q - 1; + q = 0; + foo(); + q = q - 1; - return q; + return q; } // This is the source that corresponds to funccall.ll -- 2.11.0