[llvm-commits] [hlvm] r38369 - in /hlvm/trunk: hlvm/Pass/Validate.cpp hlvm/Reader/HLVM.rng hlvm/Reader/XMLReader.cpp hlvm/Writer/XMLWriter.cpp test/xml2xml/intrinsics.hlx
Reid Spencer
reid at x10sys.com
Sat Jul 7 17:02:45 PDT 2007
Author: reid
Date: Sat Jul 7 19:02:44 2007
New Revision: 38369
URL: http://llvm.org/viewvc/llvm-project?rev=38369&view=rev
Log:
Remove alias once and for all. Fix the intrinsics test case
by testing various literal constants based on the intrinsic
types.
Modified:
hlvm/trunk/hlvm/Pass/Validate.cpp
hlvm/trunk/hlvm/Reader/HLVM.rng
hlvm/trunk/hlvm/Reader/XMLReader.cpp
hlvm/trunk/hlvm/Writer/XMLWriter.cpp
hlvm/trunk/test/xml2xml/intrinsics.hlx
Modified: hlvm/trunk/hlvm/Pass/Validate.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/Pass/Validate.cpp?rev=38369&r1=38368&r2=38369&view=diff
==============================================================================
--- hlvm/trunk/hlvm/Pass/Validate.cpp (original)
+++ hlvm/trunk/hlvm/Pass/Validate.cpp Sat Jul 7 19:02:44 2007
@@ -44,6 +44,7 @@
#include <llvm/ADT/StringExtras.h>
#include <iostream>
#include <cfloat>
+#include <cmath>
using namespace hlvm;
using namespace llvm;
@@ -521,7 +522,7 @@
if (val < Ty->getMin() || val > Ty->getMax())
error(CI, "Integer constant out of range of RangeType");
} else {
- error(CI,"Unknown integer constant type");
+ error(CI,"Integer constant applied to non-integer type");
}
}
}
@@ -537,7 +538,19 @@
error(CR,"Invalid real constant. Conversion failed.");
else {
// It converted to a double okay, check that it is in range
+ // But, first make sure its not one of the special values
+ if (__fpclassify(val) != FP_NORMAL)
+ return;
+ int exp = ilogbl(val);
+ uint64_t val_exp = (exp < 0 ? uint64_t(-exp) : uint64_t(exp));
+ unsigned leading_zeros = llvm::CountLeadingZeros_64(val_exp);
+ unsigned exp_bits_required = (sizeof(uint64_t)*8 - leading_zeros);
const RealType* Ty = llvm::cast<RealType>(CR->getType());
+ if (Ty->getExponent() < exp_bits_required) {
+ error(CR,"Real constant requires too many exponent bits for type '" +
+ Ty->getName() + "'");
+ return;
+ }
unsigned numBits = Ty->getMantissa() + Ty->getExponent() + 1;
if (numBits <= sizeof(float)*8) {
float x = val;
Modified: hlvm/trunk/hlvm/Reader/HLVM.rng
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/Reader/HLVM.rng?rev=38369&r1=38368&r2=38369&view=diff
==============================================================================
--- hlvm/trunk/hlvm/Reader/HLVM.rng (original)
+++ hlvm/trunk/hlvm/Reader/HLVM.rng Sat Jul 7 19:02:44 2007
@@ -242,7 +242,6 @@
</zeroOrMore>
<oneOrMore>
<choice>
- <ref name="alias.elem"/>
<ref name="any.elem"/>
<ref name="array.elem"/>
<ref name="boolean.elem"/>
@@ -284,16 +283,6 @@
<!--PATTERNS FOR DEFINING TYPES -->
- <define name="alias.elem">
- <element name="alias">
- <ref name="Named_Element.pat"/>
- <attribute name="is">
- <ref name="Identifier.type"/>
- </attribute>
- <ref name="Documentation.pat"/>
- </element>
- </define>
-
<define name="any.elem">
<element name="any">
<ref name="Named_Element.pat"/>
Modified: hlvm/trunk/hlvm/Reader/XMLReader.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/Reader/XMLReader.cpp?rev=38369&r1=38368&r2=38369&view=diff
==============================================================================
--- hlvm/trunk/hlvm/Reader/XMLReader.cpp (original)
+++ hlvm/trunk/hlvm/Reader/XMLReader.cpp Sat Jul 7 19:02:44 2007
@@ -120,7 +120,6 @@
Constant* parseConstant (xmlNodePtr& cur);
Operator* parseOperator (xmlNodePtr& cur);
void parseTree ();
- Type* parseAlias (xmlNodePtr& cur);
Type* parseInteger (xmlNodePtr& cur, bool isSigned);
template<class OpClass>
@@ -140,7 +139,8 @@
inline const char*
getAttribute(xmlNodePtr cur,const char*name,bool required = true);
inline void getTextContent(xmlNodePtr cur, std::string& buffer);
- inline void getNameType(xmlNodePtr& cur, std::string& name,std::string& type);
+ inline bool getNameType(
+ xmlNodePtr& cur, std::string& name,std::string& type, bool required = true);
inline Type* createIntrinsicType(
const std::string& tname, const std::string& name, Locator* loc);
@@ -291,11 +291,22 @@
if (cur) skipBlanks(cur);
}
-inline void
-XMLReaderImpl::getNameType(xmlNodePtr& cur, std::string& name,std::string& type)
-{
- name = getAttribute(cur,"id");
- type = getAttribute(cur,"type");
+inline bool
+XMLReaderImpl::getNameType(
+ xmlNodePtr& cur,
+ std::string& name,
+ std::string& type,
+ bool required)
+{
+ name.clear();
+ type.clear();
+ const char* nm = getAttribute(cur,"id",required);
+ if (nm)
+ name = nm;
+ const char* ty = getAttribute(cur,"type",required);
+ if (ty)
+ type = ty;
+ return !required || (nm && ty);
}
inline void
@@ -388,42 +399,47 @@
ConstantValue* C = 0;
const char* prefix = 0;
- std::string actualName(name);
int token = getToken(cur->name);
switch (token) {
case TKN_false:
{
- std::string name = actualName.empty() ? "bool_false" : actualName;
- C = ast->new_ConstantBoolean(name, bundle,Ty,false, getLocator(cur));
+ std::string nm = name.empty() ? "bool_false" : name;
+ C = ast->new_ConstantBoolean(nm, bundle,Ty,false, getLocator(cur));
break;
}
case TKN_true:
{
- std::string name = actualName.empty() ? "bool_true" : actualName;
- C = ast->new_ConstantBoolean(name,bundle,Ty,true, getLocator(cur));
+ std::string nm = name.empty() ? "bool_true" : name;
+ C = ast->new_ConstantBoolean(nm,bundle,Ty,true, getLocator(cur));
break;
}
case TKN_bool:
{
- hlvmAssert(Ty->is(BooleanTypeID));
std::string buffer;
xmlNodePtr child = cur->children;
getTextContent(child,buffer);
bool value = recognize_boolean( buffer.c_str() );
- std::string name = actualName.empty() ? std::string("bool_") +
- (value?"true_":"false") : actualName;
- C = ast->new_ConstantBoolean(name, bundle,Ty,value, getLocator(cur));
+ std::string nm = name.empty() ? std::string("bool_") +
+ (value?"true_":"false") : name;
+ C = ast->new_ConstantBoolean(nm, bundle,Ty,value, getLocator(cur));
break;
}
case TKN_char:
{
- hlvmAssert(Ty->is(CharacterTypeID));
std::string buffer;
xmlNodePtr child = cur->children;
getTextContent(child,buffer);
- std::string name= actualName.empty() ?
- std::string("char_") + buffer : actualName;
- C = ast->new_ConstantCharacter(name, bundle,Ty,buffer, getLocator(cur));
+ std::string nm = name.empty() ? std::string("char_") + buffer : name;
+ C = ast->new_ConstantCharacter(nm, bundle,Ty,buffer, getLocator(cur));
+ break;
+ }
+ case TKN_enum:
+ {
+ std::string value;
+ xmlNodePtr child = cur->children;
+ getTextContent(child,value);
+ std::string nm = name.empty() ? std::string("enum_") + value : name;
+ C = ast->new_ConstantEnumerator(nm,bundle,Ty,value,getLocator(cur));
break;
}
case TKN_bin:
@@ -431,50 +447,43 @@
case TKN_dec:
case TKN_hex:
{
- hlvmAssert(Ty->is(IntegerTypeID));
std::string value;
xmlNodePtr child = cur->children;
getTextContent(child,value);
uint16_t base = (token == TKN_dec ? 10 : (token == TKN_hex ? 16 :
(token == TKN_oct ? 8 : (token == TKN_bin ? 2 : 10))));
- std::string name = actualName.empty() ?
- std::string("int_") + value : actualName;
- C = ast->new_ConstantInteger(name,bundle,Ty,value,base,getLocator(cur));
+ std::string nm = name.empty() ? std::string("int_") + value : name;
+ C = ast->new_ConstantInteger(nm,bundle,Ty,value,base,getLocator(cur));
break;
}
case TKN_flt:
case TKN_dbl:
case TKN_real:
{
- hlvmAssert(Ty->is(RealTypeID));
std::string value;
xmlNodePtr child = cur->children;
getTextContent(child,value);
- std::string name = actualName.empty() ? std::string("real_") + value :
- actualName;
- C = ast->new_ConstantReal(name,bundle,Ty,value,getLocator(cur));
+ std::string nm = name.empty() ? std::string("real_") + value : name;
+ C = ast->new_ConstantReal(nm,bundle,Ty,value,getLocator(cur));
break;
}
case TKN_str:
{
- hlvmAssert(Ty->is(StringTypeID));
std::string value;
xmlNodePtr child = cur->children;
getTextContent(child,value);
- std::string name = actualName.empty() ? std::string("str_") + value :
- actualName;
- C = ast->new_ConstantString(name,bundle,Ty,value,getLocator(cur));
+ std::string nm = name.empty() ? std::string("str_") + value : name;
+ C = ast->new_ConstantString(nm,bundle,Ty,value,getLocator(cur));
break;
}
case TKN_ptr:
{
std::string id = getAttribute(cur,"id");
- std::string name = actualName.empty() ? std::string("ptr_") + id :
- actualName;
+ std::string nm = name.empty() ? std::string("ptr_") + id : name;
Constant* referent = bundle->getConst(id);
if (!referent)
error(loc,"Unkown referent for constant pointer");
- C = ast->new_ConstantPointer(name,bundle,Ty,referent,loc);
+ C = ast->new_ConstantPointer(nm,bundle,Ty,referent,loc);
break;
}
case TKN_arr:
@@ -488,8 +497,8 @@
elems.push_back(elem);
child = child->next;
}
- std::string name = actualName.empty() ? std::string("arr") : actualName;
- C = ast->new_ConstantArray(name,bundle,AT,elems,getLocator(cur));
+ std::string nm = name.empty() ? std::string("arr") : name;
+ C = ast->new_ConstantArray(nm,bundle,AT,elems,getLocator(cur));
break;
}
case TKN_vect:
@@ -503,8 +512,8 @@
elems.push_back(elem);
child = child->next;
}
- std::string name = actualName.empty() ? std::string("vec") : actualName;
- C = ast->new_ConstantVector(name,bundle,VT,elems,getLocator(cur));
+ std::string nm = name.empty() ? std::string("vec") : name;
+ C = ast->new_ConstantVector(nm,bundle,VT,elems,getLocator(cur));
break;
}
case TKN_struct:
@@ -519,8 +528,8 @@
child = child->next;
++I;
}
- std::string name = actualName.empty() ? std::string("struct") :actualName;
- C = ast->new_ConstantStructure(name,bundle,ST,fields,getLocator(cur));
+ std::string nm = name.empty() ? std::string("struct") :name;
+ C = ast->new_ConstantStructure(nm,bundle,ST,fields,getLocator(cur));
break;
}
case TKN_cont:
@@ -535,8 +544,8 @@
child = child->next;
++I;
}
- std::string name = actualName.empty() ? std::string("struct") :actualName;
- C = ast->new_ConstantContinuation(name,bundle,CT,fields,getLocator(cur));
+ std::string nm = name.empty() ? std::string("struct") :name;
+ C = ast->new_ConstantContinuation(nm,bundle,CT,fields,getLocator(cur));
break;
}
default:
@@ -555,40 +564,16 @@
hlvmAssert(getToken(cur->name) == TKN_constant);
std::string name;
std::string type;
- getNameType(cur,name,type);
- Type* Ty = getType(type);
- xmlNodePtr child = cur->children;
- Documentation* theDoc = parse<Documentation>(child);
- Constant* C = parseLiteralConstant(child,name,Ty);
- if (theDoc)
- C->setDoc(theDoc);
- return C;
-}
-Type*
-XMLReaderImpl::parseAlias(xmlNodePtr& cur)
-{
- Locator* loc = getLocator(cur);
- std::string name = getAttribute(cur,"id");
- if (NoIntrinsicType != bundle->getIntrinsicTypesValue(name))
- error(loc,"Attempt to redefine intrinsic type '" + name + "'");
- if (bundle->getType(name))
- error(loc,"Type '" + name + "' was already defined");
- const char* is = getAttribute(cur,"is",true);
- xmlNodePtr child = cur->children;
- Documentation* theDoc = parse<Documentation>(child);
- Type* result = 0;
- if (is) {
- IntrinsicTypes it = bundle->getIntrinsicTypesValue(is);
- if (it != NoIntrinsicType) {
- result = ast->new_IntrinsicType(name,bundle,it,loc);
- } else if (Type* Ty = bundle->getType(is)) {
- error(loc,"Not implemented yet: type cloning");
- } else
- error(loc,std::string("Type '") + is + "' does not exist.");
+ if (getNameType(cur,name,type)) {
+ Type* Ty = getType(type);
+ xmlNodePtr child = cur->children;
+ Documentation* theDoc = parse<Documentation>(child);
+ Constant* C = parseLiteralConstant(child,name,Ty);
if (theDoc)
- result->setDoc(theDoc);
+ C->setDoc(theDoc);
+ return C;
}
- return result;
+ return 0;
}
template<> AnyType*
@@ -1242,7 +1227,6 @@
int tkn = getToken(child->name);
Node* n = 0;
switch (tkn) {
- case TKN_alias : { n = parseAlias(child); break; }
case TKN_array : { n = parse<ArrayType>(child); break; }
case TKN_any : { n = parse<AnyType>(child); break; }
case TKN_boolean : { n = parse<BooleanType>(child); break; }
Modified: hlvm/trunk/hlvm/Writer/XMLWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/Writer/XMLWriter.cpp?rev=38369&r1=38368&r2=38369&view=diff
==============================================================================
--- hlvm/trunk/hlvm/Writer/XMLWriter.cpp (original)
+++ hlvm/trunk/hlvm/Writer/XMLWriter.cpp Sat Jul 7 19:02:44 2007
@@ -528,7 +528,11 @@
writeAttribute("type",r->getType()->getName());
putDoc(r);
}
- startElement("dbl");
+ const RealType* RT = cast<RealType>(r->getType());
+ if (RT->getBits() <= 32)
+ startElement("flt");
+ else
+ startElement("dbl");
writeString(r->getValue());
endElement();
}
Modified: hlvm/trunk/test/xml2xml/intrinsics.hlx
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/test/xml2xml/intrinsics.hlx?rev=38369&r1=38368&r2=38369&view=diff
==============================================================================
--- hlvm/trunk/test/xml2xml/intrinsics.hlx (original)
+++ hlvm/trunk/test/xml2xml/intrinsics.hlx Sat Jul 7 19:02:44 2007
@@ -1,37 +1,98 @@
<?xml version="1.0" encoding="UTF-8"?>
<hlvm xmlns="http://hlvm.org/src/hlvm/Reader/XML/HLVM.rng" pubid="name">
<bundle id="bundle">
- <alias id="2" is="bool"/>
- <alias id="3" is="buffer"/>
- <alias id="4" is="char"/>
- <alias id="5" is="double"/>
- <alias id="6" is="f32"/>
- <alias id="7" is="f44"/>
- <alias id="8" is="f64"/>
- <alias id="9" is="f80"/>
- <alias id="10" is="f128"/>
- <alias id="11" is="float"/>
- <alias id="12" is="int"/>
- <alias id="13" is="long"/>
- <alias id="14" is="octet"/>
- <alias id="15" is="r8"/>
- <alias id="16" is="r16"/>
- <alias id="17" is="r32"/>
- <alias id="18" is="r64"/>
- <alias id="20" is="s8"/>
- <alias id="21" is="s16"/>
- <alias id="22" is="s32"/>
- <alias id="23" is="s64"/>
- <alias id="24" is="s128"/>
- <alias id="25" is="short"/>
- <alias id="26" is="stream"/>
- <alias id="27" is="string"/>
- <alias id="28" is="text"/>
- <alias id="29" is="u8"/>
- <alias id="30" is="u16"/>
- <alias id="31" is="u32"/>
- <alias id="32" is="u64"/>
- <alias id="33" is="u128"/>
- <alias id="34" is="void"/>
+ <constant id="1" type="bool">
+ <true/>
+ </constant>
+ <constant id="2" type="bool">
+ <false/>
+ </constant>
+ <constant id="5" type="char">
+ <char>a</char>
+ </constant>
+ <constant id="6" type="char">
+ <char>></char>
+ </constant>
+ <constant id="7" type="char">
+ <char>#0064</char>
+ </constant>
+ <constant id="8" type="double">
+ <dbl>42.</dbl>
+ </constant>
+ <constant id="9" type="double">
+ <dbl>42.</dbl>
+ </constant>
+ <constant id="10" type="f32">
+ <flt>42.</flt>
+ </constant>
+ <constant id="11" type="f44">
+ <dbl>42.</dbl>
+ </constant>
+ <constant id="12" type="f64">
+ <dbl>42.</dbl>
+ </constant>
+ <constant id="13" type="f80">
+ <dbl>42.</dbl>
+ </constant>
+ <constant id="15" type="float">
+ <flt>42.</flt>
+ </constant>
+ <constant id="16" type="int">
+ <oct>52</oct>
+ </constant>
+ <constant id="17" type="long">
+ <dec>42</dec>
+ </constant>
+ <constant id="18" type="octet">
+ <hex>2A</hex>
+ </constant>
+ <constant id="19" type="r8">
+ <bin>00101010</bin>
+ </constant>
+ <constant id="20" type="r16">
+ <hex>7FFF</hex>
+ </constant>
+ <constant id="21" type="r32">
+ <dec>0</dec>
+ </constant>
+ <constant id="22" type="r64">
+ <dec>0</dec>
+ </constant>
+ <constant id="23" type="s8">
+ <dec>-42</dec>
+ </constant>
+ <constant id="24" type="s16">
+ <dec>-42</dec>
+ </constant>
+ <constant id="25" type="s32">
+ <dec>-42</dec>
+ </constant>
+ <constant id="26" type="s64">
+ <dec>-42</dec>
+ </constant>
+ <constant id="27" type="short">
+ <dec>-42</dec>
+ </constant>
+ <constant id="28" type="string">
+ <str>The quick brown fox jumped over the lazy dog.</str>
+ </constant>
+ <constant id="29" type="text">
+ <str>Nothin' says lovin' like something from the oven.</str>
+ </constant>
+ <constant id="30" type="u8">
+ <hex>FF</hex>
+ </constant>
+ <constant id="31" type="u16">
+ <dec>42</dec>
+ </constant>
+ <constant id="32" type="u32">
+ <dec>42</dec>
+ </constant>
+ <constant id="33" type="u64">
+ <dec>42</dec>
+ </constant>
+ <constant id="34" type="u128">
+ <dec>42</dec>
+ </constant>
</bundle>
</hlvm>
More information about the llvm-commits
mailing list