mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-23 19:23:23 +01:00
fixes from Ryan Brown.
llvm-svn: 43747
This commit is contained in:
parent
4822abbbd1
commit
d0d6643883
@ -232,7 +232,7 @@ if you typed in "1.23". Feel free to extend it :). Next we handle comments:
|
|||||||
</pre>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<p>We handle comments by skipping to the end of the line and then returning the
|
<p>We handle comments by skipping to the end of the line and then return the
|
||||||
next comment. Finally, if the input doesn't match one of the above cases, it is
|
next comment. Finally, if the input doesn't match one of the above cases, it is
|
||||||
either an operator character like '+' or the end of the file. These are handled with
|
either an operator character like '+' or the end of the file. These are handled with
|
||||||
this code:</p>
|
this code:</p>
|
||||||
|
@ -325,16 +325,18 @@ static ExprAST *ParseIdentifierExpr() {
|
|||||||
// Call.
|
// Call.
|
||||||
getNextToken(); // eat (
|
getNextToken(); // eat (
|
||||||
std::vector<ExprAST*> Args;
|
std::vector<ExprAST*> Args;
|
||||||
while (1) {
|
if (CurTok != ')') {
|
||||||
ExprAST *Arg = ParseExpression();
|
while (1) {
|
||||||
if (!Arg) return 0;
|
ExprAST *Arg = ParseExpression();
|
||||||
Args.push_back(Arg);
|
if (!Arg) return 0;
|
||||||
|
Args.push_back(Arg);
|
||||||
|
|
||||||
if (CurTok == ')') break;
|
if (CurTok == ')') break;
|
||||||
|
|
||||||
if (CurTok != ',')
|
if (CurTok != ',')
|
||||||
return Error("Expected ')'");
|
return Error("Expected ')'");
|
||||||
getNextToken();
|
getNextToken();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Eat the ')'.
|
// Eat the ')'.
|
||||||
@ -985,16 +987,18 @@ static ExprAST *ParseIdentifierExpr() {
|
|||||||
// Call.
|
// Call.
|
||||||
getNextToken(); // eat (
|
getNextToken(); // eat (
|
||||||
std::vector<ExprAST*> Args;
|
std::vector<ExprAST*> Args;
|
||||||
while (1) {
|
if (CurTok != ')') {
|
||||||
ExprAST *Arg = ParseExpression();
|
while (1) {
|
||||||
if (!Arg) return 0;
|
ExprAST *Arg = ParseExpression();
|
||||||
Args.push_back(Arg);
|
if (!Arg) return 0;
|
||||||
|
Args.push_back(Arg);
|
||||||
|
|
||||||
if (CurTok == ')') break;
|
if (CurTok == ')') break;
|
||||||
|
|
||||||
if (CurTok != ',')
|
if (CurTok != ',')
|
||||||
return Error("Expected ')'");
|
return Error("Expected ')'");
|
||||||
getNextToken();
|
getNextToken();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Eat the ')'.
|
// Eat the ')'.
|
||||||
|
@ -192,7 +192,7 @@ Value *BinaryExprAST::Codegen() {
|
|||||||
case '-': return Builder.CreateSub(L, R, "subtmp");
|
case '-': return Builder.CreateSub(L, R, "subtmp");
|
||||||
case '*': return Builder.CreateMul(L, R, "multmp");
|
case '*': return Builder.CreateMul(L, R, "multmp");
|
||||||
case '<':
|
case '<':
|
||||||
L = Builder.CreateFCmpULT(L, R, "multmp");
|
L = Builder.CreateFCmpULT(L, R, "cmptmp");
|
||||||
// Convert bool 0/1 to double 0.0 or 1.0
|
// Convert bool 0/1 to double 0.0 or 1.0
|
||||||
return Builder.CreateUIToFP(L, Type::DoubleTy, "booltmp");
|
return Builder.CreateUIToFP(L, Type::DoubleTy, "booltmp");
|
||||||
default: return ErrorV("invalid binary operator");
|
default: return ErrorV("invalid binary operator");
|
||||||
@ -860,16 +860,18 @@ static ExprAST *ParseIdentifierExpr() {
|
|||||||
// Call.
|
// Call.
|
||||||
getNextToken(); // eat (
|
getNextToken(); // eat (
|
||||||
std::vector<ExprAST*> Args;
|
std::vector<ExprAST*> Args;
|
||||||
while (1) {
|
if (CurTok != ')') {
|
||||||
ExprAST *Arg = ParseExpression();
|
while (1) {
|
||||||
if (!Arg) return 0;
|
ExprAST *Arg = ParseExpression();
|
||||||
Args.push_back(Arg);
|
if (!Arg) return 0;
|
||||||
|
Args.push_back(Arg);
|
||||||
|
|
||||||
if (CurTok == ')') break;
|
if (CurTok == ')') break;
|
||||||
|
|
||||||
if (CurTok != ',')
|
if (CurTok != ',')
|
||||||
return Error("Expected ')'");
|
return Error("Expected ')'");
|
||||||
getNextToken();
|
getNextToken();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Eat the ')'.
|
// Eat the ')'.
|
||||||
@ -1034,7 +1036,7 @@ Value *BinaryExprAST::Codegen() {
|
|||||||
case '-': return Builder.CreateSub(L, R, "subtmp");
|
case '-': return Builder.CreateSub(L, R, "subtmp");
|
||||||
case '*': return Builder.CreateMul(L, R, "multmp");
|
case '*': return Builder.CreateMul(L, R, "multmp");
|
||||||
case '<':
|
case '<':
|
||||||
L = Builder.CreateFCmpULT(L, R, "multmp");
|
L = Builder.CreateFCmpULT(L, R, "cmptmp");
|
||||||
// Convert bool 0/1 to double 0.0 or 1.0
|
// Convert bool 0/1 to double 0.0 or 1.0
|
||||||
return Builder.CreateUIToFP(L, Type::DoubleTy, "booltmp");
|
return Builder.CreateUIToFP(L, Type::DoubleTy, "booltmp");
|
||||||
default: return ErrorV("invalid binary operator");
|
default: return ErrorV("invalid binary operator");
|
||||||
|
@ -715,16 +715,18 @@ static ExprAST *ParseIdentifierExpr() {
|
|||||||
// Call.
|
// Call.
|
||||||
getNextToken(); // eat (
|
getNextToken(); // eat (
|
||||||
std::vector<ExprAST*> Args;
|
std::vector<ExprAST*> Args;
|
||||||
while (1) {
|
if (CurTok != ')') {
|
||||||
ExprAST *Arg = ParseExpression();
|
while (1) {
|
||||||
if (!Arg) return 0;
|
ExprAST *Arg = ParseExpression();
|
||||||
Args.push_back(Arg);
|
if (!Arg) return 0;
|
||||||
|
Args.push_back(Arg);
|
||||||
|
|
||||||
if (CurTok == ')') break;
|
if (CurTok == ')') break;
|
||||||
|
|
||||||
if (CurTok != ',')
|
if (CurTok != ',')
|
||||||
return Error("Expected ')'");
|
return Error("Expected ')'");
|
||||||
getNextToken();
|
getNextToken();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Eat the ')'.
|
// Eat the ')'.
|
||||||
@ -890,7 +892,7 @@ Value *BinaryExprAST::Codegen() {
|
|||||||
case '-': return Builder.CreateSub(L, R, "subtmp");
|
case '-': return Builder.CreateSub(L, R, "subtmp");
|
||||||
case '*': return Builder.CreateMul(L, R, "multmp");
|
case '*': return Builder.CreateMul(L, R, "multmp");
|
||||||
case '<':
|
case '<':
|
||||||
L = Builder.CreateFCmpULT(L, R, "multmp");
|
L = Builder.CreateFCmpULT(L, R, "cmptmp");
|
||||||
// Convert bool 0/1 to double 0.0 or 1.0
|
// Convert bool 0/1 to double 0.0 or 1.0
|
||||||
return Builder.CreateUIToFP(L, Type::DoubleTy, "booltmp");
|
return Builder.CreateUIToFP(L, Type::DoubleTy, "booltmp");
|
||||||
default: return ErrorV("invalid binary operator");
|
default: return ErrorV("invalid binary operator");
|
||||||
|
@ -319,7 +319,7 @@ block. In this case, if control comes in from the "then" block, it gets the
|
|||||||
value of "calltmp". If control comes from the "else" block, it gets the value
|
value of "calltmp". If control comes from the "else" block, it gets the value
|
||||||
of "calltmp1".</p>
|
of "calltmp1".</p>
|
||||||
|
|
||||||
<p>At this point, you are probably starting to think "on no! this means my
|
<p>At this point, you are probably starting to think "oh no! this means my
|
||||||
simple and elegant front-end will have to start generating SSA form in order to
|
simple and elegant front-end will have to start generating SSA form in order to
|
||||||
use LLVM!". Fortunately, this is not the case, and we strongly advise
|
use LLVM!". Fortunately, this is not the case, and we strongly advise
|
||||||
<em>not</em> implementing an SSA construction algorithm in your front-end
|
<em>not</em> implementing an SSA construction algorithm in your front-end
|
||||||
@ -679,8 +679,8 @@ loop: ; preds = %loop, %entry
|
|||||||
%nextvar = add double %i, 1.000000e+00
|
%nextvar = add double %i, 1.000000e+00
|
||||||
|
|
||||||
; termination test
|
; termination test
|
||||||
%multmp = fcmp ult double %i, %n
|
%cmptmp = fcmp ult double %i, %n
|
||||||
%booltmp = uitofp i1 %multmp to double
|
%booltmp = uitofp i1 %cmptmp to double
|
||||||
%loopcond = fcmp one double %booltmp, 0.000000e+00
|
%loopcond = fcmp one double %booltmp, 0.000000e+00
|
||||||
br i1 %loopcond, label %loop, label %afterloop
|
br i1 %loopcond, label %loop, label %afterloop
|
||||||
|
|
||||||
@ -871,7 +871,8 @@ that is what we return from <tt>ForExprAST::Codegen</tt>.</p>
|
|||||||
the tutorial. We added two control flow constructs, and used them to motivate
|
the tutorial. We added two control flow constructs, and used them to motivate
|
||||||
a couple of aspects of the LLVM IR that are important for front-end implementors
|
a couple of aspects of the LLVM IR that are important for front-end implementors
|
||||||
to know. In the next chapter of our saga, we will get a bit crazier and add
|
to know. In the next chapter of our saga, we will get a bit crazier and add
|
||||||
operator overloading to our poor innocent language.</p>
|
<a href="LangImpl6.html">user-defined operators</a> to our poor innocent
|
||||||
|
language.</p>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -1378,7 +1379,7 @@ Value *BinaryExprAST::Codegen() {
|
|||||||
case '-': return Builder.CreateSub(L, R, "subtmp");
|
case '-': return Builder.CreateSub(L, R, "subtmp");
|
||||||
case '*': return Builder.CreateMul(L, R, "multmp");
|
case '*': return Builder.CreateMul(L, R, "multmp");
|
||||||
case '<':
|
case '<':
|
||||||
L = Builder.CreateFCmpULT(L, R, "multmp");
|
L = Builder.CreateFCmpULT(L, R, "cmptmp");
|
||||||
// Convert bool 0/1 to double 0.0 or 1.0
|
// Convert bool 0/1 to double 0.0 or 1.0
|
||||||
return Builder.CreateUIToFP(L, Type::DoubleTy, "booltmp");
|
return Builder.CreateUIToFP(L, Type::DoubleTy, "booltmp");
|
||||||
default: return ErrorV("invalid binary operator");
|
default: return ErrorV("invalid binary operator");
|
||||||
|
@ -280,7 +280,7 @@ Value *BinaryExprAST::Codegen() {
|
|||||||
case '-': return Builder.CreateSub(L, R, "subtmp");
|
case '-': return Builder.CreateSub(L, R, "subtmp");
|
||||||
case '*': return Builder.CreateMul(L, R, "multmp");
|
case '*': return Builder.CreateMul(L, R, "multmp");
|
||||||
case '<':
|
case '<':
|
||||||
L = Builder.CreateFCmpULT(L, R, "multmp");
|
L = Builder.CreateFCmpULT(L, R, "cmptmp");
|
||||||
// Convert bool 0/1 to double 0.0 or 1.0
|
// Convert bool 0/1 to double 0.0 or 1.0
|
||||||
return Builder.CreateUIToFP(L, Type::DoubleTy, "booltmp");
|
return Builder.CreateUIToFP(L, Type::DoubleTy, "booltmp");
|
||||||
<b>default: break;</b>
|
<b>default: break;</b>
|
||||||
@ -1396,7 +1396,7 @@ Value *BinaryExprAST::Codegen() {
|
|||||||
case '-': return Builder.CreateSub(L, R, "subtmp");
|
case '-': return Builder.CreateSub(L, R, "subtmp");
|
||||||
case '*': return Builder.CreateMul(L, R, "multmp");
|
case '*': return Builder.CreateMul(L, R, "multmp");
|
||||||
case '<':
|
case '<':
|
||||||
L = Builder.CreateFCmpULT(L, R, "multmp");
|
L = Builder.CreateFCmpULT(L, R, "cmptmp");
|
||||||
// Convert bool 0/1 to double 0.0 or 1.0
|
// Convert bool 0/1 to double 0.0 or 1.0
|
||||||
return Builder.CreateUIToFP(L, Type::DoubleTy, "booltmp");
|
return Builder.CreateUIToFP(L, Type::DoubleTy, "booltmp");
|
||||||
default: break;
|
default: break;
|
||||||
|
@ -546,8 +546,8 @@ entry:
|
|||||||
<b>%x1 = alloca double
|
<b>%x1 = alloca double
|
||||||
store double %x, double* %x1
|
store double %x, double* %x1
|
||||||
%x2 = load double* %x1</b>
|
%x2 = load double* %x1</b>
|
||||||
%multmp = fcmp ult double %x2, 3.000000e+00
|
%cmptmp = fcmp ult double %x2, 3.000000e+00
|
||||||
%booltmp = uitofp i1 %multmp to double
|
%booltmp = uitofp i1 %cmptmp to double
|
||||||
%ifcond = fcmp one double %booltmp, 0.000000e+00
|
%ifcond = fcmp one double %booltmp, 0.000000e+00
|
||||||
br i1 %ifcond, label %then, label %else
|
br i1 %ifcond, label %then, label %else
|
||||||
|
|
||||||
@ -585,8 +585,8 @@ PHI node for it, so we still just make the PHI.</p>
|
|||||||
<pre>
|
<pre>
|
||||||
define double @fib(double %x) {
|
define double @fib(double %x) {
|
||||||
entry:
|
entry:
|
||||||
%multmp = fcmp ult double <b>%x</b>, 3.000000e+00
|
%cmptmp = fcmp ult double <b>%x</b>, 3.000000e+00
|
||||||
%booltmp = uitofp i1 %multmp to double
|
%booltmp = uitofp i1 %cmptmp to double
|
||||||
%ifcond = fcmp one double %booltmp, 0.000000e+00
|
%ifcond = fcmp one double %booltmp, 0.000000e+00
|
||||||
br i1 %ifcond, label %then, label %else
|
br i1 %ifcond, label %then, label %else
|
||||||
|
|
||||||
@ -618,8 +618,8 @@ such blatent inefficiencies :).</p>
|
|||||||
<pre>
|
<pre>
|
||||||
define double @fib(double %x) {
|
define double @fib(double %x) {
|
||||||
entry:
|
entry:
|
||||||
%multmp = fcmp ult double %x, 3.000000e+00
|
%cmptmp = fcmp ult double %x, 3.000000e+00
|
||||||
%booltmp = uitofp i1 %multmp to double
|
%booltmp = uitofp i1 %cmptmp to double
|
||||||
%ifcond = fcmp ueq double %booltmp, 0.000000e+00
|
%ifcond = fcmp ueq double %booltmp, 0.000000e+00
|
||||||
br i1 %ifcond, label %else, label %ifcont
|
br i1 %ifcond, label %else, label %ifcont
|
||||||
|
|
||||||
@ -1674,7 +1674,7 @@ Value *BinaryExprAST::Codegen() {
|
|||||||
case '-': return Builder.CreateSub(L, R, "subtmp");
|
case '-': return Builder.CreateSub(L, R, "subtmp");
|
||||||
case '*': return Builder.CreateMul(L, R, "multmp");
|
case '*': return Builder.CreateMul(L, R, "multmp");
|
||||||
case '<':
|
case '<':
|
||||||
L = Builder.CreateFCmpULT(L, R, "multmp");
|
L = Builder.CreateFCmpULT(L, R, "cmptmp");
|
||||||
// Convert bool 0/1 to double 0.0 or 1.0
|
// Convert bool 0/1 to double 0.0 or 1.0
|
||||||
return Builder.CreateUIToFP(L, Type::DoubleTy, "booltmp");
|
return Builder.CreateUIToFP(L, Type::DoubleTy, "booltmp");
|
||||||
default: break;
|
default: break;
|
||||||
|
Loading…
Reference in New Issue
Block a user