[llvm-commits] [hlvm] r38383 - in /hlvm/trunk/hlvm: CodeGen/LLVMEmitter.cpp CodeGen/LLVMGenerator.cpp Pass/Validate.cpp
Reid Spencer
reid at x10sys.com
Sat Jul 7 17:02:52 PDT 2007
Author: reid
Date: Sat Jul 7 19:02:52 2007
New Revision: 38383
URL: http://llvm.org/viewvc/llvm-project?rev=38383&view=rev
Log:
Handle constant characters and constant arguments to functions. This permits
HLVM to correctly compile the first batch of 66 generated test functions.
Modified:
hlvm/trunk/hlvm/CodeGen/LLVMEmitter.cpp
hlvm/trunk/hlvm/CodeGen/LLVMGenerator.cpp
hlvm/trunk/hlvm/Pass/Validate.cpp
Modified: hlvm/trunk/hlvm/CodeGen/LLVMEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/CodeGen/LLVMEmitter.cpp?rev=38383&r1=38382&r2=38383&view=diff
==============================================================================
--- hlvm/trunk/hlvm/CodeGen/LLVMEmitter.cpp (original)
+++ hlvm/trunk/hlvm/CodeGen/LLVMEmitter.cpp Sat Jul 7 19:02:52 2007
@@ -500,7 +500,17 @@
// The result must be a first class type at this point, ensure it
hlvmAssert(F->getReturnType()->isFirstClassType());
- return new llvm::CallInst(F, args, F->getName() + "_result", TheBlock);
+ // Copy the other arguments
+ ArgList newArgs;
+ for (ArgList::const_iterator I = args.begin(), E = args.end();
+ I != E; ++I)
+ if (isa<Constant>(*I) && !isa<GlobalValue>(*I) &&
+ !(*I)->getType()->isFirstClassType())
+ newArgs.push_back(NewGConst((*I)->getType(),
+ cast<Constant>(*I), (*I)->getName()));
+ else
+ newArgs.push_back(*I);
+ return new llvm::CallInst(F, newArgs, F->getName() + "_result", TheBlock);
}
void
Modified: hlvm/trunk/hlvm/CodeGen/LLVMGenerator.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/CodeGen/LLVMGenerator.cpp?rev=38383&r1=38382&r2=38383&view=diff
==============================================================================
--- hlvm/trunk/hlvm/CodeGen/LLVMGenerator.cpp (original)
+++ hlvm/trunk/hlvm/CodeGen/LLVMGenerator.cpp Sat Jul 7 19:02:52 2007
@@ -174,7 +174,7 @@
// Okay, we haven't seen this type before so let's construct it
switch (ty->getID()) {
case BooleanTypeID: result = llvm::Type::BoolTy; break;
- case CharacterTypeID: result = llvm::Type::IntTy; break;
+ case CharacterTypeID: result = llvm::Type::UIntTy; break;
case AnyTypeID:
hlvmNotImplemented("Any Type");
break;
@@ -341,6 +341,23 @@
result = llvm::ConstantBool::get(CI->getValue());
break;
}
+ case ConstantCharacterID:
+ {
+ const ConstantCharacter* CE = llvm::cast<ConstantCharacter>(C);
+ const std::string& cVal = CE->getValue();
+ hlvmAssert(!cVal.empty() && "Empty constant character?");
+ uint32_t val = 0;
+ if (cVal[0] == '#') {
+ const char* startptr = &cVal.c_str()[1];
+ char* endptr = 0;
+ val = strtoul(startptr,&endptr,16);
+ hlvmAssert(startptr != endptr);
+ } else {
+ val = cVal[0];
+ }
+ result = em.getUVal(llvm::Type::UIntTy,val);
+ break;
+ }
case ConstantEnumeratorID:
{
const ConstantEnumerator* CE = llvm::cast<ConstantEnumerator>(C);
@@ -1559,6 +1576,12 @@
case ConstantBooleanID:
getConstant(llvm::cast<ConstantBoolean>(n));
break;
+ case ConstantCharacterID:
+ getConstant(llvm::cast<ConstantCharacter>(n));
+ break;
+ case ConstantEnumeratorID:
+ getConstant(llvm::cast<ConstantEnumerator>(n));
+ break;
case ConstantIntegerID:
getConstant(llvm::cast<ConstantInteger>(n));
break;
@@ -1706,6 +1729,7 @@
modules.push_back(em.FinishModule());
break;
case ConstantBooleanID:
+ case ConstantCharacterID:
case ConstantEnumeratorID:
case ConstantIntegerID:
case ConstantRealID:
Modified: hlvm/trunk/hlvm/Pass/Validate.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/Pass/Validate.cpp?rev=38383&r1=38382&r2=38383&view=diff
==============================================================================
--- hlvm/trunk/hlvm/Pass/Validate.cpp (original)
+++ hlvm/trunk/hlvm/Pass/Validate.cpp Sat Jul 7 19:02:52 2007
@@ -45,6 +45,7 @@
#include <iostream>
#include <cfloat>
#include <cmath>
+#include <cerrno>
using namespace hlvm;
using namespace llvm;
@@ -483,7 +484,25 @@
template<> inline void
ValidateImpl::validate(ConstantCharacter* n)
{
- checkConstant(n,ConstantCharacterID);
+ if (checkConstant(n,ConstantCharacterID)) {
+ if (const CharacterType* CT = dyn_cast<CharacterType>(n->getType())) {
+ const std::string& cVal = n->getValue();
+ if (cVal.empty()) {
+ error(n,"Constant character of zero length not permitted");
+ } else if (cVal[0] == '#') {
+ const char* startptr = &cVal.c_str()[1];
+ char* endptr;
+ uint32_t val = strtoul(startptr, &endptr, 16);
+ if (endptr == startptr || (val == ULONG_MAX && errno != 0))
+ error(n,"Invalid numeric constant character '" + cVal + "'");
+ else if (val == 0)
+ error(n,"Zero valued character constant not permitted");
+ } else if (cVal.size() > 1) {
+ error(n,"Too many characters (" + utostr(cVal.size()) +
+ ") for character constant");
+ }
+ }
+ }
}
template<> inline void
More information about the llvm-commits
mailing list