mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-08-17 21:29:20 +00:00
Implement support for internal methods
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@1373 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
a2eb259c6b
commit
dda719665b
@ -125,6 +125,7 @@ declare { return DECLARE; }
|
|||||||
global { return GLOBAL; }
|
global { return GLOBAL; }
|
||||||
constant { return CONSTANT; }
|
constant { return CONSTANT; }
|
||||||
const { return CONST; }
|
const { return CONST; }
|
||||||
|
internal { return INTERNAL; }
|
||||||
uninitialized { return UNINIT; }
|
uninitialized { return UNINIT; }
|
||||||
implementation { return IMPLEMENTATION; }
|
implementation { return IMPLEMENTATION; }
|
||||||
\.\.\. { return DOTDOTDOT; }
|
\.\.\. { return DOTDOTDOT; }
|
||||||
|
@ -174,7 +174,8 @@ struct BBPlaceHolderHelper : public BasicBlock {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct MethPlaceHolderHelper : public Method {
|
struct MethPlaceHolderHelper : public Method {
|
||||||
MethPlaceHolderHelper(const Type *Ty) : Method(cast<const MethodType>(Ty)) {}
|
MethPlaceHolderHelper(const Type *Ty) : Method(cast<const MethodType>(Ty),
|
||||||
|
true) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef PlaceholderValue<InstPlaceHolderHelper> ValuePlaceHolder;
|
typedef PlaceholderValue<InstPlaceHolderHelper> ValuePlaceHolder;
|
||||||
|
@ -451,7 +451,7 @@ static bool ResolveType(PATypeHolder<Type> &T) {
|
|||||||
// refering to the number can be resolved. Do this now.
|
// refering to the number can be resolved. Do this now.
|
||||||
//
|
//
|
||||||
static void ResolveTypeTo(char *Name, const Type *ToTy) {
|
static void ResolveTypeTo(char *Name, const Type *ToTy) {
|
||||||
vector<PATypeHolder<Type> > &Types = inMethodScope ?
|
vector<PATypeHolder<Type> > &Types = inMethodScope() ?
|
||||||
CurMeth.Types : CurModule.Types;
|
CurMeth.Types : CurModule.Types;
|
||||||
|
|
||||||
ValID D;
|
ValID D;
|
||||||
@ -684,7 +684,7 @@ Module *RunVMAsmParser(const string &Filename, FILE *F) {
|
|||||||
%type <ValueList> IndexList // For GEP derived indices
|
%type <ValueList> IndexList // For GEP derived indices
|
||||||
%type <TypeList> TypeListI ArgTypeListI
|
%type <TypeList> TypeListI ArgTypeListI
|
||||||
%type <JumpTable> JumpTable
|
%type <JumpTable> JumpTable
|
||||||
%type <BoolVal> GlobalType // GLOBAL or CONSTANT?
|
%type <BoolVal> GlobalType OptInternal // GLOBAL or CONSTANT? Intern?
|
||||||
|
|
||||||
// ValueRef - Unresolved reference to a definition or BB
|
// ValueRef - Unresolved reference to a definition or BB
|
||||||
%type <ValIDVal> ValueRef ConstValueRef SymbolicValueRef
|
%type <ValIDVal> ValueRef ConstValueRef SymbolicValueRef
|
||||||
@ -715,7 +715,7 @@ Module *RunVMAsmParser(const string &Filename, FILE *F) {
|
|||||||
|
|
||||||
|
|
||||||
%token IMPLEMENTATION TRUE FALSE BEGINTOK END DECLARE GLOBAL CONSTANT UNINIT
|
%token IMPLEMENTATION TRUE FALSE BEGINTOK END DECLARE GLOBAL CONSTANT UNINIT
|
||||||
%token TO EXCEPT DOTDOTDOT STRING NULL_TOK CONST
|
%token TO EXCEPT DOTDOTDOT STRING NULL_TOK CONST INTERNAL
|
||||||
|
|
||||||
// Basic Block Terminating Operators
|
// Basic Block Terminating Operators
|
||||||
%token <TermOpVal> RET BR SWITCH
|
%token <TermOpVal> RET BR SWITCH
|
||||||
@ -780,6 +780,7 @@ OptAssign : VAR_ID '=' {
|
|||||||
$$ = 0;
|
$$ = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
OptInternal : INTERNAL { $$ = true; } | /*empty*/ { $$ = false; }
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
// Types includes all predefined types... except void, because it can only be
|
// Types includes all predefined types... except void, because it can only be
|
||||||
@ -987,7 +988,7 @@ ConstVal: Types '[' ConstVector ']' { // Nonempty unsized arr
|
|||||||
// TODO: GlobalVariable here that includes the said information!
|
// TODO: GlobalVariable here that includes the said information!
|
||||||
|
|
||||||
// Create a placeholder for the global variable reference...
|
// Create a placeholder for the global variable reference...
|
||||||
GlobalVariable *GV = new GlobalVariable(PT->getValueType(), false);
|
GlobalVariable *GV = new GlobalVariable(PT->getValueType(), false,true);
|
||||||
// Keep track of the fact that we have a forward ref to recycle it
|
// Keep track of the fact that we have a forward ref to recycle it
|
||||||
CurModule.GlobalRefs.insert(make_pair(make_pair(PT, $2), GV));
|
CurModule.GlobalRefs.insert(make_pair(make_pair(PT, $2), GV));
|
||||||
|
|
||||||
@ -1067,14 +1068,14 @@ ConstPool : ConstPool OptAssign CONST ConstVal {
|
|||||||
}
|
}
|
||||||
| ConstPool MethodProto { // Method prototypes can be in const pool
|
| ConstPool MethodProto { // Method prototypes can be in const pool
|
||||||
}
|
}
|
||||||
| ConstPool OptAssign GlobalType ConstVal {
|
| ConstPool OptAssign OptInternal GlobalType ConstVal {
|
||||||
const Type *Ty = $4->getType();
|
const Type *Ty = $5->getType();
|
||||||
// Global declarations appear in Constant Pool
|
// Global declarations appear in Constant Pool
|
||||||
ConstPoolVal *Initializer = $4;
|
ConstPoolVal *Initializer = $5;
|
||||||
if (Initializer == 0)
|
if (Initializer == 0)
|
||||||
ThrowException("Global value initializer is not a constant!");
|
ThrowException("Global value initializer is not a constant!");
|
||||||
|
|
||||||
GlobalVariable *GV = new GlobalVariable(Ty, $3, Initializer);
|
GlobalVariable *GV = new GlobalVariable(Ty, $4, $3, Initializer);
|
||||||
if (!setValueName(GV, $2)) { // If not redefining...
|
if (!setValueName(GV, $2)) { // If not redefining...
|
||||||
CurModule.CurrentModule->getGlobalList().push_back(GV);
|
CurModule.CurrentModule->getGlobalList().push_back(GV);
|
||||||
int Slot = InsertValue(GV, CurModule.Values);
|
int Slot = InsertValue(GV, CurModule.Values);
|
||||||
@ -1087,10 +1088,10 @@ ConstPool : ConstPool OptAssign CONST ConstVal {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
| ConstPool OptAssign UNINIT GlobalType Types {
|
| ConstPool OptAssign OptInternal UNINIT GlobalType Types {
|
||||||
const Type *Ty = *$5;
|
const Type *Ty = *$6;
|
||||||
// Global declarations appear in Constant Pool
|
// Global declarations appear in Constant Pool
|
||||||
GlobalVariable *GV = new GlobalVariable(Ty, $4);
|
GlobalVariable *GV = new GlobalVariable(Ty, $5, $3);
|
||||||
if (!setValueName(GV, $2)) { // If not redefining...
|
if (!setValueName(GV, $2)) { // If not redefining...
|
||||||
CurModule.CurrentModule->getGlobalList().push_back(GV);
|
CurModule.CurrentModule->getGlobalList().push_back(GV);
|
||||||
int Slot = InsertValue(GV, CurModule.Values);
|
int Slot = InsertValue(GV, CurModule.Values);
|
||||||
@ -1169,51 +1170,52 @@ ArgList : ArgListH {
|
|||||||
$$ = 0;
|
$$ = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
MethodHeaderH : TypesV STRINGCONSTANT '(' ArgList ')' {
|
MethodHeaderH : OptInternal TypesV STRINGCONSTANT '(' ArgList ')' {
|
||||||
UnEscapeLexed($2);
|
UnEscapeLexed($3);
|
||||||
|
string MethodName($3);
|
||||||
|
|
||||||
vector<const Type*> ParamTypeList;
|
vector<const Type*> ParamTypeList;
|
||||||
if ($4)
|
if ($5)
|
||||||
for (list<MethodArgument*>::iterator I = $4->begin(); I != $4->end(); ++I)
|
for (list<MethodArgument*>::iterator I = $5->begin(); I != $5->end(); ++I)
|
||||||
ParamTypeList.push_back((*I)->getType());
|
ParamTypeList.push_back((*I)->getType());
|
||||||
|
|
||||||
bool isVarArg = ParamTypeList.size() && ParamTypeList.back() == Type::VoidTy;
|
bool isVarArg = ParamTypeList.size() && ParamTypeList.back() == Type::VoidTy;
|
||||||
if (isVarArg) ParamTypeList.pop_back();
|
if (isVarArg) ParamTypeList.pop_back();
|
||||||
|
|
||||||
const MethodType *MT = MethodType::get(*$1, ParamTypeList, isVarArg);
|
const MethodType *MT = MethodType::get(*$2, ParamTypeList, isVarArg);
|
||||||
const PointerType *PMT = PointerType::get(MT);
|
const PointerType *PMT = PointerType::get(MT);
|
||||||
delete $1;
|
delete $2;
|
||||||
|
|
||||||
Method *M = 0;
|
Method *M = 0;
|
||||||
if (SymbolTable *ST = CurModule.CurrentModule->getSymbolTable()) {
|
if (SymbolTable *ST = CurModule.CurrentModule->getSymbolTable()) {
|
||||||
if (Value *V = ST->lookup(PMT, $2)) { // Method already in symtab?
|
if (Value *V = ST->lookup(PMT, MethodName)) { // Method already in symtab?
|
||||||
M = cast<Method>(V);
|
M = cast<Method>(V);
|
||||||
|
|
||||||
// Yes it is. If this is the case, either we need to be a forward decl,
|
// Yes it is. If this is the case, either we need to be a forward decl,
|
||||||
// or it needs to be.
|
// or it needs to be.
|
||||||
if (!CurMeth.isDeclare && !M->isExternal())
|
if (!CurMeth.isDeclare && !M->isExternal())
|
||||||
ThrowException("Redefinition of method '" + string($2) + "'!");
|
ThrowException("Redefinition of method '" + MethodName + "'!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (M == 0) { // Not already defined?
|
if (M == 0) { // Not already defined?
|
||||||
M = new Method(MT, $2);
|
M = new Method(MT, $1, MethodName);
|
||||||
InsertValue(M, CurModule.Values);
|
InsertValue(M, CurModule.Values);
|
||||||
CurModule.DeclareNewGlobalValue(M, ValID::create($2));
|
CurModule.DeclareNewGlobalValue(M, ValID::create($3));
|
||||||
}
|
}
|
||||||
|
free($3); // Free strdup'd memory!
|
||||||
free($2); // Free strdup'd memory!
|
|
||||||
|
|
||||||
CurMeth.MethodStart(M);
|
CurMeth.MethodStart(M);
|
||||||
|
|
||||||
// Add all of the arguments we parsed to the method...
|
// Add all of the arguments we parsed to the method...
|
||||||
if ($4 && !CurMeth.isDeclare) { // Is null if empty...
|
if ($5 && !CurMeth.isDeclare) { // Is null if empty...
|
||||||
Method::ArgumentListType &ArgList = M->getArgumentList();
|
Method::ArgumentListType &ArgList = M->getArgumentList();
|
||||||
|
|
||||||
for (list<MethodArgument*>::iterator I = $4->begin(); I != $4->end(); ++I) {
|
for (list<MethodArgument*>::iterator I = $5->begin(); I != $5->end(); ++I) {
|
||||||
InsertValue(*I);
|
InsertValue(*I);
|
||||||
ArgList.push_back(*I);
|
ArgList.push_back(*I);
|
||||||
}
|
}
|
||||||
delete $4; // We're now done with the argument list
|
delete $5; // We're now done with the argument list
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -320,6 +320,7 @@ void AssemblyWriter::printModule(const Module *M) {
|
|||||||
void AssemblyWriter::printGlobal(const GlobalVariable *GV) {
|
void AssemblyWriter::printGlobal(const GlobalVariable *GV) {
|
||||||
if (GV->hasName()) Out << "%" << GV->getName() << " = ";
|
if (GV->hasName()) Out << "%" << GV->getName() << " = ";
|
||||||
|
|
||||||
|
if (GV->hasInternalLinkage()) Out << "internal ";
|
||||||
if (!GV->hasInitializer()) Out << "uninitialized ";
|
if (!GV->hasInitializer()) Out << "uninitialized ";
|
||||||
|
|
||||||
Out << (GV->isConstant() ? "constant " : "global ");
|
Out << (GV->isConstant() ? "constant " : "global ");
|
||||||
@ -383,7 +384,8 @@ void AssemblyWriter::printConstant(const ConstPoolVal *CPV) {
|
|||||||
//
|
//
|
||||||
void AssemblyWriter::printMethod(const Method *M) {
|
void AssemblyWriter::printMethod(const Method *M) {
|
||||||
// Print out the return type and name...
|
// Print out the return type and name...
|
||||||
Out << "\n" << (M->isExternal() ? "declare " : "");
|
Out << "\n" << (M->isExternal() ? "declare " : "")
|
||||||
|
<< (M->hasInternalLinkage() ? "internal " : "");
|
||||||
printType(M->getReturnType()) << " \"" << M->getName() << "\"(";
|
printType(M->getReturnType()) << " \"" << M->getName() << "\"(";
|
||||||
Table.incorporateMethod(M);
|
Table.incorporateMethod(M);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user