diff options
author | Chris Lattner <sabre@nondot.org> | 2001-10-03 06:12:09 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2001-10-03 06:12:09 +0000 |
commit | f4ba6c710c298fe9b492b9cde82ce5efd46afd5d (patch) | |
tree | 6d4f20e184d04b74697cfe74c75227e83104a7f0 /lib/AsmParser/llvmAsmParser.y | |
parent | d05adbcdce7a7f56e7c3e4fad42e41132dd7361e (diff) | |
download | external_llvm-f4ba6c710c298fe9b492b9cde82ce5efd46afd5d.zip external_llvm-f4ba6c710c298fe9b492b9cde82ce5efd46afd5d.tar.gz external_llvm-f4ba6c710c298fe9b492b9cde82ce5efd46afd5d.tar.bz2 |
First try at a horrible global value reference wrapper
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@701 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AsmParser/llvmAsmParser.y')
-rw-r--r-- | lib/AsmParser/llvmAsmParser.y | 59 |
1 files changed, 40 insertions, 19 deletions
diff --git a/lib/AsmParser/llvmAsmParser.y b/lib/AsmParser/llvmAsmParser.y index 5771318..6852df7 100644 --- a/lib/AsmParser/llvmAsmParser.y +++ b/lib/AsmParser/llvmAsmParser.y @@ -175,6 +175,23 @@ static const Type *getTypeVal(const ValID &D, bool DoNotImprovise = false) { return Typ; } +static Value *lookupInSymbolTable(const Type *Ty, const string &Name) { + SymbolTable *SymTab = + CurMeth.CurrentMethod ? CurMeth.CurrentMethod->getSymbolTable() : 0; + Value *N = SymTab ? SymTab->lookup(Ty, Name) : 0; + + if (N == 0) { + // Symbol table doesn't automatically chain yet... because the method + // hasn't been added to the module... + // + SymTab = CurModule.CurrentModule->getSymbolTable(); + if (SymTab) + N = SymTab->lookup(Ty, Name); + } + + return N; +} + static Value *getVal(const Type *Ty, const ValID &D, bool DoNotImprovise = false) { assert(Ty != Type::TypeTy && "Should use getTypeVal for types!"); @@ -204,20 +221,8 @@ static Value *getVal(const Type *Ty, const ValID &D, } case ValID::NameVal: { // Is it a named definition? string Name(D.Name); - SymbolTable *SymTab = 0; - if (CurMeth.CurrentMethod) - SymTab = CurMeth.CurrentMethod->getSymbolTable(); - Value *N = SymTab ? SymTab->lookup(Ty, Name) : 0; - - if (N == 0) { - // Symbol table doesn't automatically chain yet... because the method - // hasn't been added to the module... - // - SymTab = CurModule.CurrentModule->getSymbolTable(); - if (SymTab) - N = SymTab->lookup(Ty, Name); - if (N == 0) break; - } + Value *N = lookupInSymbolTable(Ty, Name); + if (N == 0) break; D.destroy(); // Free old strdup'd memory... return N; @@ -849,12 +854,28 @@ ConstVal: Types '[' ConstVector ']' { // Nonempty unsized arr $$ = ConstPoolPointer::getNullPointer(PTy); delete $1; } -/* - | Types '*' ConstVal { - assert(0); - $$ = 0; + | Types VAR_ID { + string Name($2); free($2); // Change to a responsible mem manager + const PointerType *Ty = dyn_cast<const PointerType>($1->get()); + if (Ty == 0) + ThrowException("Global const reference must be a pointer type!"); + + Value *N = lookupInSymbolTable(Ty, Name); + if (N == 0) + ThrowException("Global pointer reference '%" + Name + + "' must be defined before use!"); + + // TODO FIXME: This should also allow methods... when common baseclass + // exists + if (GlobalVariable *GV = dyn_cast<GlobalVariable>(N)) { + $$ = ConstPoolPointerReference::get(GV); + } else { + ThrowException("'%" + Name + "' is not a global value reference!"); + } + + delete $1; } -*/ + ConstVal : SIntType EINT64VAL { // integral constants if (!ConstPoolSInt::isValueValidForType($1, $2)) |