<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On Jun 21, 2009, at 8:33 PM, Howard Su wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div>no strtoll in windows + VC.</div> <div>D:\llvm-ng\tools\llvm-mc\AsmLexer.cpp(143) : error C3861: 'strtoll': identifier not found<br>D:\llvm-ng\tools\llvm-mc\AsmLexer.cpp(156) : error C3861: 'strtoll': identifier not found<br>D:\llvm-ng\tools\llvm-mc\AsmLexer.cpp(171) : error C3861: 'strtoll': identifier not found<br> D:\llvm-ng\tools\llvm-mc\AsmLexer.cpp(176) : error C3861: 'strtoull': identifier not found<br>D:\llvm-ng\tools\llvm-mc\AsmLexer.cpp(188) : error C3861: 'strtoll': identifier not found<br></div></blockquote><div><br></div>Did my subsequent #include of <cstdlib> fix this? If not, llvm/utils/TableGen/TGLexer.cpp uses strtoull, do you know what magic does it?</div><div><br></div><div>-Chris</div><div><br></div><div><blockquote type="cite"><div><br></div> <div class="gmail_quote">On Mon, Jun 22, 2009 at 3:21 AM, Chris Lattner <span dir="ltr"><<a href="mailto:sabre@nondot.org">sabre@nondot.org</a>></span> wrote:<br> <blockquote style="BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex; PADDING-LEFT: 1ex" class="gmail_quote">Author: lattner<br>Date: Sun Jun 21 14:21:25 2009<br>New Revision: 73855<br><br>URL: <a href="http://llvm.org/viewvc/llvm-project?rev=73855&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=73855&view=rev</a><br> Log:<br>implement enough of a lexer to get through Olden/health/Output/health.llc.s<br>without errors.<br><br><br>Modified:<br> llvm/trunk/tools/llvm-mc/AsmLexer.cpp<br> llvm/trunk/tools/llvm-mc/AsmLexer.h<br> llvm/trunk/tools/llvm-mc/llvm-mc.cpp<br> <br>Modified: llvm/trunk/tools/llvm-mc/AsmLexer.cpp<br>URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mc/AsmLexer.cpp?rev=73855&r1=73854&r2=73855&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mc/AsmLexer.cpp?rev=73855&r1=73854&r2=73855&view=diff</a><br> <br>==============================================================================<br>--- llvm/trunk/tools/llvm-mc/AsmLexer.cpp (original)<br>+++ llvm/trunk/tools/llvm-mc/AsmLexer.cpp Sun Jun 21 14:21:25 2009<br>@@ -14,6 +14,7 @@<br> #include "AsmLexer.h"<br> #include "llvm/Support/SourceMgr.h"<br> #include "llvm/Support/MemoryBuffer.h"<br>+#include <cerrno><br> using namespace llvm;<br><br> AsmLexer::AsmLexer(SourceMgr &SM) : SrcMgr(SM) {<br> @@ -23,6 +24,10 @@<br> TokStart = 0;<br> }<br><br>+SMLoc AsmLexer::getLoc() const {<br>+ return SMLoc::getFromPointer(TokStart);<br>+}<br>+<br> void AsmLexer::PrintError(const char *Loc, const std::string &Msg) const {<br> SrcMgr.PrintError(SMLoc::getFromPointer(Loc), Msg);<br> }<br>@@ -31,6 +36,13 @@<br> SrcMgr.PrintError(Loc, Msg);<br> }<br><br>+/// ReturnError - Set the error to the specified string at the specified<br>+/// location. This is defined to always return asmtok::Error.<br> +asmtok::TokKind AsmLexer::ReturnError(const char *Loc, const std::string &Msg) {<br>+ PrintError(Loc, Msg);<br>+ return asmtok::Error;<br>+}<br>+<br> int AsmLexer::getNextChar() {<br> char CurChar = *CurPtr++;<br> switch (CurChar) {<br>@@ -59,6 +71,129 @@<br> }<br> }<br><br>+/// LexIdentifier: [a-zA-Z_.][a-zA-Z0-9_$.@]*<br>+asmtok::TokKind AsmLexer::LexIdentifier() {<br>+ while (isalnum(*CurPtr) || *CurPtr == '_' || *CurPtr == '$' ||<br> + *CurPtr == '.' || *CurPtr == '@')<br>+ ++CurPtr;<br>+ CurStrVal.assign(TokStart, CurPtr); // Skip %<br>+ return asmtok::Identifier;<br>+}<br>+<br>+/// LexPercent: Register: %[a-zA-Z0-9]+<br> +asmtok::TokKind AsmLexer::LexPercent() {<br>+ if (!isalnum(*CurPtr))<br>+ return asmtok::Error; // Must have at least one character.<br>+ while (isalnum(*CurPtr))<br>+ ++CurPtr;<br>+ CurStrVal.assign(TokStart, CurPtr); // Skip %<br> + return asmtok::Register;<br>+}<br>+<br>+/// LexSlash: Slash: /<br>+/// C-Style Comment: /* ... */<br>+asmtok::TokKind AsmLexer::LexSlash() {<br>+ if (*CurPtr != '*')<br>+ return asmtok::Slash;<br> +<br>+ // C Style comment.<br>+ ++CurPtr; // skip the star.<br>+ while (1) {<br>+ int CurChar = getNextChar();<br>+ switch (CurChar) {<br>+ case EOF:<br>+ PrintError(TokStart, "Unterminated comment!");<br> + return asmtok::Error;<br>+ case '*':<br>+ // End of the comment?<br>+ if (CurPtr[0] != '/') break;<br>+<br>+ ++CurPtr; // End the */.<br>+ return LexToken();<br>+ }<br>+ }<br> +}<br>+<br>+/// LexHash: Comment: #[^\n]*<br>+asmtok::TokKind AsmLexer::LexHash() {<br>+ int CurChar = getNextChar();<br>+ while (CurChar != '\n' && CurChar != '\n' && CurChar != EOF)<br> + CurChar = getNextChar();<br>+<br>+ if (CurChar == EOF)<br>+ return asmtok::Eof;<br>+ return asmtok::EndOfStatement;<br>+}<br>+<br>+<br>+/// LexDigit: First character is [0-9].<br>+/// Local Label: [0-9][:]<br> +/// Forward/Backward Label: [0-9][fb]<br>+/// Binary integer: 0b[01]+<br>+/// Octal integer: 0[0-7]+<br>+/// Hex integer: 0x[0-9a-fA-F]+<br>+/// Decimal integer: [1-9][0-9]*<br>+/// TODO: FP literal.<br>+asmtok::TokKind AsmLexer::LexDigit() {<br> + if (*CurPtr == ':')<br>+ return asmtok::Error; // FIXME LOCAL LABEL.<br>+ if (*CurPtr == 'f' || *CurPtr == 'b')<br>+ return asmtok::Error; // FIXME FORWARD/BACKWARD LABEL.<br>+<br>+ // Decimal integer: [1-9][0-9]*<br> + if (CurPtr[-1] != '0') {<br>+ while (isdigit(*CurPtr))<br>+ ++CurPtr;<br>+ CurIntVal = strtoll(TokStart, 0, 10);<br>+ return asmtok::IntVal;<br>+ }<br>+<br>+ if (*CurPtr == 'b') {<br>+ ++CurPtr;<br> + const char *NumStart = CurPtr;<br>+ while (CurPtr[0] == '0' || CurPtr[0] == '1')<br>+ ++CurPtr;<br>+<br>+ // Requires at least one binary digit.<br>+ if (CurPtr == NumStart)<br>+ return ReturnError(CurPtr-2, "Invalid binary number");<br> + CurIntVal = strtoll(NumStart, 0, 2);<br>+ return asmtok::IntVal;<br>+ }<br>+<br>+ if (*CurPtr == 'x') {<br>+ ++CurPtr;<br>+ const char *NumStart = CurPtr;<br>+ while (isxdigit(CurPtr[0]))<br>+ ++CurPtr;<br> +<br>+ // Requires at least one hex digit.<br>+ if (CurPtr == NumStart)<br>+ return ReturnError(CurPtr-2, "Invalid hexadecimal number");<br>+<br>+ errno = 0;<br>+ CurIntVal = strtoll(NumStart, 0, 16);<br> + if (errno == EINVAL)<br>+ return ReturnError(CurPtr-2, "Invalid hexadecimal number");<br>+ if (errno == ERANGE) {<br>+ errno = 0;<br>+ CurIntVal = (int64_t)strtoull(NumStart, 0, 16);<br>+ if (errno == EINVAL)<br> + return ReturnError(CurPtr-2, "Invalid hexadecimal number");<br>+ if (errno == ERANGE)<br>+ return ReturnError(CurPtr-2, "Hexadecimal number out of range");<br>+ }<br>+ return asmtok::IntVal;<br> + }<br>+<br>+ // Must be an octal number, it starts with 0.<br>+ while (*CurPtr >= '0' && *CurPtr <= '7')<br>+ ++CurPtr;<br>+ CurIntVal = strtoll(TokStart, 0, 8);<br>+ return asmtok::IntVal;<br> +}<br>+<br>+<br> asmtok::TokKind AsmLexer::LexToken() {<br> TokStart = CurPtr;<br> // This always consumes at least one character.<br>@@ -66,9 +201,9 @@<br><br> switch (CurChar) {<br> default:<br>- // Handle letters: [a-zA-Z_]<br> -// if (isalpha(CurChar) || CurChar == '_' || CurChar == '#')<br>-// return LexIdentifier();<br>+ // Handle identifier: [a-zA-Z_.][a-zA-Z0-9_$.@]*<br>+ if (isalpha(CurChar) || CurChar == '_' || CurChar == '.')<br> + return LexIdentifier();<br><br> // Unknown character, emit an error.<br> return asmtok::Error;<br>@@ -76,12 +211,29 @@<br> case 0:<br> case ' ':<br> case '\t':<br>- case '\n':<br>- case '\r':<br> // Ignore whitespace.<br> return LexToken();<br>+ case '\n': // FALL THROUGH.<br>+ case '\r': // FALL THROUGH.<br>+ case ';': return asmtok::EndOfStatement;<br> case ':': return asmtok::Colon;<br> case '+': return asmtok::Plus;<br> case '-': return asmtok::Minus;<br>+ case '(': return asmtok::LParen;<br>+ case ')': return asmtok::RParen;<br>+ case '*': return asmtok::Star;<br> + case ',': return asmtok::Comma;<br>+ case '$': return asmtok::Dollar;<br>+ case '%': return LexPercent();<br>+ case '/': return LexSlash();<br>+ case '#': return LexHash();<br> + case '0': case '1': case '2': case '3': case '4':<br>+ case '5': case '6': case '7': case '8': case '9':<br>+ return LexDigit();<br>+<br> + // TODO: Quoted identifiers (objc methods etc)<br>+ // local labels: [0-9][:]<br>+ // Forward/backward labels: [0-9][fb]<br>+ // Integers, fp constants, character constants.<br> }<br> }<br>\ No newline at end of file<br> <br>Modified: llvm/trunk/tools/llvm-mc/AsmLexer.h<br>URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mc/AsmLexer.h?rev=73855&r1=73854&r2=73855&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mc/AsmLexer.h?rev=73855&r1=73854&r2=73855&view=diff</a><br> <br>==============================================================================<br>--- llvm/trunk/tools/llvm-mc/AsmLexer.h (original)<br>+++ llvm/trunk/tools/llvm-mc/AsmLexer.h Sun Jun 21 14:21:25 2009<br>@@ -29,12 +29,16 @@<br> Eof, Error,<br><br> Identifier,<br>+ Register,<br> IntVal,<br><br>-<br>+ EndOfStatement,<br> Colon,<br> Plus,<br>- Minus<br>+ Minus,<br>+ Slash, // '/'<br>+ LParen, RParen,<br> + Star, Comma, Dollar<br> };<br> }<br><br>@@ -66,7 +70,7 @@<br> asmtok::TokKind getKind() const { return CurKind; }<br><br> const std::string &getCurStrVal() const {<br>- assert(CurKind == asmtok::Identifier &&<br> + assert((CurKind == asmtok::Identifier || CurKind == asmtok::Register) &&<br> "This token doesn't have a string value");<br> return CurStrVal;<br> }<br>@@ -82,9 +86,15 @@<br><br> private:<br> int getNextChar();<br>+ asmtok::TokKind ReturnError(const char *Loc, const std::string &Msg);<br><br> /// LexToken - Read the next token and return its code.<br> asmtok::TokKind LexToken();<br>+ asmtok::TokKind LexIdentifier();<br> + asmtok::TokKind LexPercent();<br>+ asmtok::TokKind LexSlash();<br>+ asmtok::TokKind LexHash();<br>+ asmtok::TokKind LexDigit();<br> };<br><br> } // end namespace llvm<br><br>Modified: llvm/trunk/tools/llvm-mc/llvm-mc.cpp<br> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mc/llvm-mc.cpp?rev=73855&r1=73854&r2=73855&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mc/llvm-mc.cpp?rev=73855&r1=73854&r2=73855&view=diff</a><br> <br>==============================================================================<br>--- llvm/trunk/tools/llvm-mc/llvm-mc.cpp (original)<br>+++ llvm/trunk/tools/llvm-mc/llvm-mc.cpp Sun Jun 21 14:21:25 2009<br>@@ -72,17 +72,29 @@<br> asmtok::TokKind Tok = Lexer.Lex();<br> while (Tok != asmtok::Eof) {<br> switch (Tok) {<br>- default: outs() << "<<unknown token>>\n"; break;<br>- case asmtok::Error: outs() << "<<error>>\n"; break;<br> + default: Lexer.PrintError(Lexer.getLoc(), "driver: unknown token"); break;<br>+ case asmtok::Error:<br>+ Lexer.PrintError(Lexer.getLoc(), "error, bad token");<br>+ break;<br> case asmtok::Identifier:<br> outs() << "identifier: " << Lexer.getCurStrVal() << '\n';<br> break;<br>+ case asmtok::Register:<br>+ outs() << "register: " << Lexer.getCurStrVal() << '\n';<br> + break;<br> case asmtok::IntVal:<br> outs() << "int: " << Lexer.getCurIntVal() << '\n';<br> break;<br>+ case asmtok::EndOfStatement: outs() << "EndOfStatement\n"; break;<br> case asmtok::Colon: outs() << "Colon\n"; break;<br> case asmtok::Plus: outs() << "Plus\n"; break;<br> case asmtok::Minus: outs() << "Minus\n"; break;<br>+ case asmtok::Slash: outs() << "Slash\n"; break;<br> + case asmtok::LParen: outs() << "LParen\n"; break;<br>+ case asmtok::RParen: outs() << "RParen\n"; break;<br>+ case asmtok::Star: outs() << "Star\n"; break;<br>+ case asmtok::Comma: outs() << "Comma\n"; break;<br> + case asmtok::Dollar: outs() << "Dollar\n"; break;<br> }<br><br> Tok = Lexer.Lex();<br><br><br>_______________________________________________<br>llvm-commits mailing list<br><a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br></blockquote></div><br><br clear="all"> <div></div><br>-- <br>-Howard<br> _______________________________________________<br>llvm-commits mailing list<br><a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits<br></blockquote></div><br></body></html>