mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-16 12:24:03 +00:00
Apply patches from PR136
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@10192 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -12,9 +12,9 @@ LEVEL = ../..
|
|||||||
#
|
#
|
||||||
# Directories that needs to be built.
|
# Directories that needs to be built.
|
||||||
#
|
#
|
||||||
# Disable the 'test' subdirectory until it works correctly
|
# Disable the 'test' and 'samples' subdirectories until they work correctly
|
||||||
# test
|
#DIRS = lib tools test samples
|
||||||
DIRS = lib tools samples
|
DIRS = lib tools
|
||||||
|
|
||||||
#
|
#
|
||||||
# Include the Master Makefile that knows how to build all.
|
# Include the Master Makefile that knows how to build all.
|
||||||
|
@ -131,8 +131,8 @@ StackerCompiler::compile(
|
|||||||
TheStack = new GlobalVariable(
|
TheStack = new GlobalVariable(
|
||||||
/*type=*/ stack_type,
|
/*type=*/ stack_type,
|
||||||
/*isConstant=*/ false,
|
/*isConstant=*/ false,
|
||||||
/*Linkage=*/ GlobalValue::AppendingLinkage,
|
/*Linkage=*/ GlobalValue::LinkOnceLinkage,
|
||||||
/*initializer=*/Constant::getNullValue(stack_type),
|
/*initializer=*/ Constant::getNullValue(stack_type),
|
||||||
/*name=*/ "_stack_",
|
/*name=*/ "_stack_",
|
||||||
/*parent=*/ TheModule
|
/*parent=*/ TheModule
|
||||||
);
|
);
|
||||||
@ -144,7 +144,7 @@ StackerCompiler::compile(
|
|||||||
/*type=*/Type::LongTy,
|
/*type=*/Type::LongTy,
|
||||||
/*isConstant=*/false,
|
/*isConstant=*/false,
|
||||||
/*Linkage=*/GlobalValue::LinkOnceLinkage,
|
/*Linkage=*/GlobalValue::LinkOnceLinkage,
|
||||||
/*initializer=*/Constant::getNullValue(Type::LongTy),
|
/*initializer=*/ Constant::getNullValue(Type::LongTy),
|
||||||
/*name=*/"_index_",
|
/*name=*/"_index_",
|
||||||
/*parent=*/TheModule
|
/*parent=*/TheModule
|
||||||
);
|
);
|
||||||
@ -559,28 +559,19 @@ Function*
|
|||||||
StackerCompiler::handle_main_definition( Function* func )
|
StackerCompiler::handle_main_definition( Function* func )
|
||||||
{
|
{
|
||||||
// Set the name of the function defined as the Stacker main
|
// Set the name of the function defined as the Stacker main
|
||||||
|
// This will get called by the "main" that is defined in
|
||||||
|
// the runtime library.
|
||||||
func->setName( "_MAIN_");
|
func->setName( "_MAIN_");
|
||||||
|
|
||||||
// Create the actual main for the runtime system.
|
|
||||||
//std::vector<const Type*> params; // No parameters
|
|
||||||
//FunctionType* main_type = FunctionType::get( Type::IntTy, params, false );
|
|
||||||
Function* SystemMain = new Function(
|
|
||||||
DefinitionType,
|
|
||||||
GlobalValue::ExternalLinkage,
|
|
||||||
"main", TheModule);
|
|
||||||
|
|
||||||
// Create a basic block that just calls the STACKERMAIN function. Note
|
|
||||||
// that the basic block is automatically inserted into the end of SystemMain
|
|
||||||
BasicBlock* bb = new BasicBlock( (echo?"main":"a"), SystemMain ) ;
|
|
||||||
bb->getInstList().push_back( new CallInst( func, no_arguments) );
|
|
||||||
bb->getInstList().push_back( new ReturnInst() );
|
|
||||||
|
|
||||||
// Turn "_stack_" into an initialized variable since this is the main
|
// Turn "_stack_" into an initialized variable since this is the main
|
||||||
// module. This causes it to not be "external" but defined in this module.
|
// module. This causes it to not be "external" but defined in this module.
|
||||||
TheStack->setInitializer( Constant::getNullValue(stack_type) );
|
TheStack->setInitializer( Constant::getNullValue(stack_type) );
|
||||||
|
TheStack->setLinkage( GlobalValue::LinkOnceLinkage );
|
||||||
|
|
||||||
// Turn "_index_" into an intialized variable for the same reason.
|
// Turn "_index_" into an intialized variable for the same reason.
|
||||||
TheIndex->setInitializer( Constant::getNullValue(Type::LongTy) );
|
TheIndex->setInitializer( Constant::getNullValue(Type::LongTy) );
|
||||||
|
TheIndex->setLinkage( GlobalValue::LinkOnceLinkage );
|
||||||
|
|
||||||
return func;
|
return func;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,10 +17,13 @@
|
|||||||
//
|
//
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
#include "ctype.h"
|
||||||
#include "stdio.h"
|
#include "stdio.h"
|
||||||
|
#include "stdlib.h"
|
||||||
|
|
||||||
extern long _index_;
|
extern long _index_;
|
||||||
extern int _stack_[1024];
|
extern int _stack_[1024];
|
||||||
|
extern void _MAIN_();
|
||||||
|
|
||||||
void
|
void
|
||||||
_stacker_dump_stack_()
|
_stacker_dump_stack_()
|
||||||
@ -32,3 +35,38 @@ _stacker_dump_stack_()
|
|||||||
printf("#%03d: %d\n", i, _stack_[i] );
|
printf("#%03d: %d\n", i, _stack_[i] );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
main ( int argc, char** argv )
|
||||||
|
{
|
||||||
|
// Avoid modifying argc
|
||||||
|
int a = argc;
|
||||||
|
|
||||||
|
// Make sure we're starting with the right index
|
||||||
|
_index_ = 0;
|
||||||
|
|
||||||
|
// Copy the arguments to the stack in reverse order
|
||||||
|
// so that they get popped in the order presented
|
||||||
|
while ( a > 0 )
|
||||||
|
{
|
||||||
|
if ( isdigit( argv[--a][0] ) )
|
||||||
|
{
|
||||||
|
_stack_[_index_++] = atoi( argv[a] );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_stack_[_index_++] = (int) argv[a];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Put the argument count on the stack
|
||||||
|
_stack_[_index_] = argc;
|
||||||
|
|
||||||
|
// Invoke the user's main program
|
||||||
|
_MAIN_();
|
||||||
|
|
||||||
|
// Return last item on the stack
|
||||||
|
if ( _index_ >= 0 )
|
||||||
|
return _stack_[_index_];
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
@ -14,34 +14,46 @@ LEVEL = ../../..
|
|||||||
#
|
#
|
||||||
DIRS =
|
DIRS =
|
||||||
|
|
||||||
TESTS = fibonacci hello prime
|
SAMPLES = fibonacci hello prime
|
||||||
|
|
||||||
all :: $(TESTS)
|
all :: $(SAMPLES)
|
||||||
|
|
||||||
ifdef OPTIMIZE
|
ifdef OPTIMIZE
|
||||||
%.bc : %.st
|
%.bc : %.st
|
||||||
stkrc -e -o - $< | opt -stats -q -f -o $*.bc \
|
@$(ECHO) "Compiling and Optimizing $< to $*.bc"
|
||||||
|
$(VERB)stkrc -e -o - $< | opt -stats -q -f -o $*.bc \
|
||||||
-aa-eval -adce -branch-combine -cee -constmerge -constprop -dce -die -ds-aa \
|
-aa-eval -adce -branch-combine -cee -constmerge -constprop -dce -die -ds-aa \
|
||||||
-ds-opt -gcse -globaldce -indvars -inline -instcombine \
|
-ds-opt -gcse -globaldce -indvars -inline -instcombine \
|
||||||
-ipconstprop -licm -loopsimplify -mem2reg -pre -sccp -simplifycfg \
|
-ipconstprop -licm -loopsimplify -mem2reg -pre -sccp -simplifycfg \
|
||||||
-tailcallelim -verify
|
-tailcallelim -verify
|
||||||
else
|
else
|
||||||
%.bc : %.st
|
%.bc : %.st
|
||||||
stkrc -e -f -o $*.bc $<
|
@$(ECHO) "Compiling $< to $*.bc"
|
||||||
|
$(VERB)stkrc -e -f -o $*.bc $<
|
||||||
endif
|
endif
|
||||||
|
|
||||||
%.s : %.bc
|
%.s : %.bc
|
||||||
llc -f -o $*.s $<
|
@$(ECHO) "Compiling $< to $*.s"
|
||||||
|
$(VERB)llc -f -o $*.s $<
|
||||||
|
|
||||||
% : %.s
|
% : %.s
|
||||||
gcc -g -L$(BUILD_OBJ_ROOT)/lib/Debug -lstkr_runtime -o $* $*.s
|
@$(ECHO) "Compiling and Linking $< to $*"
|
||||||
|
$(VERB)gcc -g -L$(BUILD_OBJ_ROOT)/lib/Debug -lstkr_runtime -o $* $*.s
|
||||||
|
|
||||||
%.ll : %.bc
|
%.ll : %.bc
|
||||||
llvm-dis -f -o $*.ll $<
|
@$(ECHO) "Disassembling $< to $*.ll"
|
||||||
|
$(VERB)llvm-dis -f -o $*.ll $<
|
||||||
|
|
||||||
%.bc : $(BUILD_OBJ_ROOT)/tools/Debug/stkrc
|
%.bc : $(BUILD_OBJ_ROOT)/tools/Debug/stkrc
|
||||||
|
|
||||||
.PRECIOUS: %.bc %.s %.ll %.st
|
.PRECIOUS: %.bc %.s %.ll %.st
|
||||||
|
|
||||||
|
SAMPLES_LL = $(SAMPLES:%=%.ll)
|
||||||
|
SAMPLES_BC = $(SAMPLES:%=%.bc)
|
||||||
|
SAMPLES_S = $(SAMPLES:%=%.s)
|
||||||
|
|
||||||
|
clean ::
|
||||||
|
$(VERB)rm -f gmon.out $(SAMPLES_LL) $(SAMPLES_BC) $(SAMPLES_S) $(SAMPLES)
|
||||||
#
|
#
|
||||||
# Include the Master Makefile that knows how to build all.
|
# Include the Master Makefile that knows how to build all.
|
||||||
#
|
#
|
||||||
|
@ -1 +1,25 @@
|
|||||||
: defmebaby 23 0 = ;
|
#
|
||||||
|
# goof
|
||||||
|
#
|
||||||
|
: print_one
|
||||||
|
--
|
||||||
|
SWAP
|
||||||
|
>s
|
||||||
|
DROP
|
||||||
|
;
|
||||||
|
: print_it
|
||||||
|
WHILE
|
||||||
|
print_one
|
||||||
|
END
|
||||||
|
;
|
||||||
|
|
||||||
|
: MAIN
|
||||||
|
"MICKEY: I said she was f'in goofy!"
|
||||||
|
"MICKEY: I didn't say she was insane."
|
||||||
|
"JUDGE: Yet you provide no evidence of this and I do not concur."
|
||||||
|
"JUDGE: In your pleadings you claim that Mini Mouse is insane."
|
||||||
|
"MICKEY: Well, what do you mean, your honor?"
|
||||||
|
"JUDGE: Mr. Mouse, I find your grounds for divorce insufficient. "
|
||||||
|
6
|
||||||
|
print_it
|
||||||
|
;
|
||||||
|
@ -139,7 +139,7 @@
|
|||||||
################################################################################
|
################################################################################
|
||||||
: consider_prime
|
: consider_prime
|
||||||
DUP ( save the prime number to consider )
|
DUP ( save the prime number to consider )
|
||||||
10000 < IF ( check to see if we are done yet )
|
1000000 < IF ( check to see if we are done yet )
|
||||||
done ( we are done, call "done" )
|
done ( we are done, call "done" )
|
||||||
ENDIF
|
ENDIF
|
||||||
++ ( increment to next prime number )
|
++ ( increment to next prime number )
|
||||||
@ -157,6 +157,8 @@
|
|||||||
# STACK>: empty
|
# STACK>: empty
|
||||||
################################################################################
|
################################################################################
|
||||||
: find_primes
|
: find_primes
|
||||||
|
"Prime Numbers: " >s CR ( say hello )
|
||||||
|
DROP ( get rid of that pesky string )
|
||||||
1 ( stoke the fires )
|
1 ( stoke the fires )
|
||||||
print ( print the first one, we know its prime )
|
print ( print the first one, we know its prime )
|
||||||
WHILE ( loop while the prime to consider is non zero )
|
WHILE ( loop while the prime to consider is non zero )
|
||||||
@ -165,12 +167,69 @@
|
|||||||
;
|
;
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
# The MAIN program just prints a banner and calls find_primes.
|
#
|
||||||
# STACK<: empty
|
################################################################################
|
||||||
# STACK>: empty
|
: say_yes
|
||||||
|
>d ( Print the prime number )
|
||||||
|
" is prime." ( push string to output )
|
||||||
|
>s ( output it )
|
||||||
|
CR ( print carriage return )
|
||||||
|
DROP ( pop string )
|
||||||
|
;
|
||||||
|
|
||||||
|
: say_no
|
||||||
|
>d ( Print the prime number )
|
||||||
|
" is NOT prime." ( push string to put out )
|
||||||
|
>s ( put out the string )
|
||||||
|
CR ( print carriage return )
|
||||||
|
DROP ( pop string )
|
||||||
|
;
|
||||||
|
|
||||||
|
################################################################################
|
||||||
|
# This definition processes a single command line argument and determines if it
|
||||||
|
# is a prime number or not.
|
||||||
|
# STACK<:
|
||||||
|
# n - number of arguments
|
||||||
|
# arg1 - the prime numbers to examine
|
||||||
|
# STACK>:
|
||||||
|
# n-1 - one less than number of arguments
|
||||||
|
# arg2 - we processed one argument
|
||||||
|
################################################################################
|
||||||
|
: do_one_argument
|
||||||
|
-- ( decrement loop counter )
|
||||||
|
SWAP ( get the argument value )
|
||||||
|
is_prime IF ( determine if its prime )
|
||||||
|
say_yes ( uhuh )
|
||||||
|
ELSE
|
||||||
|
say_no ( nope )
|
||||||
|
ENDIF
|
||||||
|
DROP ( done with that argument )
|
||||||
|
;
|
||||||
|
|
||||||
|
################################################################################
|
||||||
|
# The MAIN program just prints a banner and processes its arguments.
|
||||||
|
# STACK<:
|
||||||
|
# n - number of arguments
|
||||||
|
# ... - the arguments
|
||||||
|
################################################################################
|
||||||
|
: process_arguments
|
||||||
|
WHILE ( while there are more arguments )
|
||||||
|
do_one_argument ( process one argument )
|
||||||
|
END
|
||||||
|
;
|
||||||
|
|
||||||
|
################################################################################
|
||||||
|
# The MAIN program just prints a banner and processes its arguments.
|
||||||
|
# STACK<: arguments
|
||||||
################################################################################
|
################################################################################
|
||||||
: MAIN
|
: MAIN
|
||||||
"Prime Numbers: " >s CR ( say hello )
|
NIP ( get rid of the program name )
|
||||||
DROP ( get rid of that pesky string )
|
-- ( reduce number of arguments )
|
||||||
|
DUP ( save the arg counter )
|
||||||
|
1 <= IF ( See if we got an argument )
|
||||||
|
process_arguments ( tell user if they are prime )
|
||||||
|
ELSE
|
||||||
find_primes ( see how many we can find )
|
find_primes ( see how many we can find )
|
||||||
|
ENDIF
|
||||||
|
0 ( push return code )
|
||||||
;
|
;
|
||||||
|
@ -34,28 +34,38 @@ TESTS = $(LOGIC_TESTS) $(ARITHMETIC_TESTS) $(BITWISE_TESTS) $(STACK_TESTS) \
|
|||||||
all :: test_each
|
all :: test_each
|
||||||
|
|
||||||
test_each: $(TESTS)
|
test_each: $(TESTS)
|
||||||
$(BUILD_SRC_DIR)/runtests $(BUILD_OBJ_DIR) $(TESTS)
|
@$(ECHO) "Running Tests..."
|
||||||
|
$(VERB)$(BUILD_SRC_DIR)/runtests $(BUILD_OBJ_DIR) $(TESTS)
|
||||||
|
|
||||||
% : %.s testing.s
|
% : %.s testing.s
|
||||||
gcc -ggdb -L$(BUILD_OBJ_ROOT)/lib/Debug testing.s -lstkr_runtime -o $* $*.s
|
@$(ECHO) "Compiling and Linking $< to $*"
|
||||||
|
$(VERB)gcc -ggdb -L$(BUILD_OBJ_ROOT)/lib/Debug testing.s -lstkr_runtime -o $* $*.s
|
||||||
|
|
||||||
%.s : %.bc
|
%.s : %.bc
|
||||||
llc -f -o $*.s $<
|
@$(ECHO) "Compiling $< to $*.s"
|
||||||
|
$(VERB)llc -f -o $*.s $<
|
||||||
|
|
||||||
ifdef OPTIMIZE
|
ifdef OPTIMIZE
|
||||||
%.bc : %.st $(BUILD_OBJ_ROOT)/tools/Debug/stkrc
|
%.bc : %.st $(BUILD_OBJ_ROOT)/tools/Debug/stkrc
|
||||||
stkrc -e -o - $< | opt -stats -q -f -o $*.bc -adce -branch-combine -cee -constmerge -constprop -dce -die -gcse -globaldce -instcombine -pre
|
@$(ECHO) "Compiling and Optimizing $< to $*.bc"
|
||||||
|
$(VERB)stkrc -e -o - $< | opt -stats -q -f -o $*.bc -adce -branch-combine -cee -constmerge -constprop -dce -die -gcse -globaldce -instcombine -pre
|
||||||
else
|
else
|
||||||
%.bc : %.st $(BUILD_OBJ_ROOT)/tools/Debug/stkrc
|
%.bc : %.st $(BUILD_OBJ_ROOT)/tools/Debug/stkrc
|
||||||
stkrc -e -f -o $*.bc $<
|
@$(ECHO) "Compiling $< to $*.bc"
|
||||||
|
$(VERB)stkrc -e -f -o $*.bc $<
|
||||||
endif
|
endif
|
||||||
|
|
||||||
%.ll : %.bc
|
%.ll : %.bc
|
||||||
llvm-dis -o $*.ll $<
|
@$(ECHO) "Disassembling $< to $*.ll"
|
||||||
|
$(VERB)llvm-dis -o $*.ll $<
|
||||||
|
|
||||||
|
TESTS_LL = $(TESTS:%=%.ll)
|
||||||
|
TESTS_BC = $(TESTS:%=%.bc)
|
||||||
|
TESTS_S = $(TESTS:%=%.s)
|
||||||
|
|
||||||
clean ::
|
clean ::
|
||||||
rm -f $(TESTS)
|
$(VERB)rm -f gmon.out $(TESTS_LL) $(TESTS_BC) $(TESTS_S) $(TESTS) testing.bc testing.s testing.ll
|
||||||
|
|
||||||
.SUFFIXES: .st .s .ll
|
.SUFFIXES: .st .s .ll .bc
|
||||||
.PRECIOUS: %.s %.ll %.bc %.st
|
.PRECIOUS: %.s %.ll %.bc %.st
|
||||||
.PHONY: test_each test_asm
|
.PHONY: test_each
|
||||||
|
Reference in New Issue
Block a user