Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Aparapi Examples
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
We are moving to Forgejo!
You are on a read-only GitLab instance.
Show more breadcrumbs
Aparapi
Aparapi Examples
Commits
7571e46c
Commit
7571e46c
authored
10 years ago
by
kishida
Browse files
Options
Downloads
Patches
Plain Diff
Add brackets around conditional expression
parent
f1150493
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
com.amd.aparapi/src/java/com/amd/aparapi/internal/writer/BlockWriter.java
+805
-803
805 additions, 803 deletions
...src/java/com/amd/aparapi/internal/writer/BlockWriter.java
with
805 additions
and
803 deletions
com.amd.aparapi/src/java/com/amd/aparapi/internal/writer/BlockWriter.java
+
805
−
803
View file @
7571e46c
/*
/*
Copyright (c) 2010-2011, Advanced Micro Devices, Inc.
Copyright (c) 2010-2011, Advanced Micro Devices, Inc.
All rights reserved.
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
following conditions are met:
following conditions are met:
Redistributions of source code must retain the above copyright notice, this list of conditions and the following
Redistributions of source code must retain the above copyright notice, this list of conditions and the following
disclaimer.
disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided with the distribution.
disclaimer in the documentation and/or other materials provided with the distribution.
Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products
Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
If you use the software (in whole or in part), you shall adhere to all applicable U.S., European, and other export
If you use the software (in whole or in part), you shall adhere to all applicable U.S., European, and other export
laws, including but not limited to the U.S. Export Administration Regulations ("EAR"), (15 C.F.R. Sections 730 through
laws, including but not limited to the U.S. Export Administration Regulations ("EAR"), (15 C.F.R. Sections 730 through
774), and E.U. Council Regulation (EC) No 1334/2000 of 22 June 2000. Further, pursuant to Section 740.6 of the EAR,
774), and E.U. Council Regulation (EC) No 1334/2000 of 22 June 2000. Further, pursuant to Section 740.6 of the EAR,
you hereby certify that, except pursuant to a license granted by the United States Department of Commerce Bureau of
you hereby certify that, except pursuant to a license granted by the United States Department of Commerce Bureau of
Industry and Security or as otherwise permitted pursuant to a License Exception under the U.S. Export Administration
Industry and Security or as otherwise permitted pursuant to a License Exception under the U.S. Export Administration
Regulations ("EAR"), you will not (1) export, re-export or release to a national of a country in Country Groups D:1,
Regulations ("EAR"), you will not (1) export, re-export or release to a national of a country in Country Groups D:1,
E:1 or E:2 any restricted technology, software, or source code you receive hereunder, or (2) export to Country Groups
E:1 or E:2 any restricted technology, software, or source code you receive hereunder, or (2) export to Country Groups
D:1, E:1 or E:2 the direct product of such technology or software, if such foreign produced direct product is subject
D:1, E:1 or E:2 the direct product of such technology or software, if such foreign produced direct product is subject
to national security controls as identified on the Commerce Control List (currently found in Supplement 1 to Part 774
to national security controls as identified on the Commerce Control List (currently found in Supplement 1 to Part 774
of EAR). For the most current Country Group listings, or for additional information about the EAR or your obligations
of EAR). For the most current Country Group listings, or for additional information about the EAR or your obligations
under those regulations, please refer to the U.S. Bureau of Industry and Security's website at http://www.bis.doc.gov/.
under those regulations, please refer to the U.S. Bureau of Industry and Security's website at http://www.bis.doc.gov/.
*/
*/
package
com.amd.aparapi.internal.writer
;
package
com.amd.aparapi.internal.writer
;
import
com.amd.aparapi.*
;
import
com.amd.aparapi.*
;
import
com.amd.aparapi.internal.exception.*
;
import
com.amd.aparapi.internal.exception.*
;
import
com.amd.aparapi.internal.instruction.*
;
import
com.amd.aparapi.internal.instruction.*
;
import
com.amd.aparapi.internal.instruction.BranchSet.LogicalExpressionNode
;
import
com.amd.aparapi.internal.instruction.BranchSet.LogicalExpressionNode
;
import
com.amd.aparapi.internal.instruction.InstructionSet.AccessInstanceField
;
import
com.amd.aparapi.internal.instruction.InstructionSet.AccessInstanceField
;
import
com.amd.aparapi.internal.instruction.BranchSet.*
;
import
com.amd.aparapi.internal.instruction.BranchSet.*
;
import
com.amd.aparapi.internal.instruction.InstructionSet.*
;
import
com.amd.aparapi.internal.instruction.InstructionSet.*
;
import
com.amd.aparapi.internal.model.ClassModel.ConstantPool.*
;
import
com.amd.aparapi.internal.model.ClassModel.ConstantPool.*
;
import
com.amd.aparapi.internal.model.ClassModel.*
;
import
com.amd.aparapi.internal.model.ClassModel.*
;
import
com.amd.aparapi.internal.model.*
;
import
com.amd.aparapi.internal.model.*
;
import
com.amd.aparapi.internal.model.ClassModel.ConstantPool.NameAndTypeEntry
;
import
com.amd.aparapi.internal.model.ClassModel.ConstantPool.NameAndTypeEntry
;
import
java.util.*
;
import
java.util.*
;
/**
/**
* Base abstract class for converting <code>Aparapi</code> IR to text.<br/>
* Base abstract class for converting <code>Aparapi</code> IR to text.<br/>
*
*
*
*
* @author gfrost
* @author gfrost
*
*
*/
*/
public
abstract
class
BlockWriter
{
public
abstract
class
BlockWriter
{
public
final
static
String
arrayLengthMangleSuffix
=
"__javaArrayLength"
;
public
final
static
String
arrayLengthMangleSuffix
=
"__javaArrayLength"
;
public
final
static
String
arrayDimMangleSuffix
=
"__javaArrayDimension"
;
public
final
static
String
arrayDimMangleSuffix
=
"__javaArrayDimension"
;
public
abstract
void
write
(
String
_string
);
public
abstract
void
write
(
String
_string
);
public
void
writeln
(
String
_string
)
{
public
void
writeln
(
String
_string
)
{
write
(
_string
);
write
(
_string
);
newLine
();
newLine
();
}
}
public
int
indent
=
0
;
public
int
indent
=
0
;
public
void
in
()
{
public
void
in
()
{
indent
++;
indent
++;
}
}
public
void
out
()
{
public
void
out
()
{
indent
--;
indent
--;
}
}
public
void
newLine
()
{
public
void
newLine
()
{
write
(
"\n"
);
write
(
"\n"
);
for
(
int
i
=
0
;
i
<
indent
;
i
++)
{
for
(
int
i
=
0
;
i
<
indent
;
i
++)
{
write
(
" "
);
write
(
" "
);
}
}
}
}
public
void
writeConditionalBranch16
(
ConditionalBranch16
_branch16
,
boolean
_invert
)
throws
CodeGenException
{
public
void
writeConditionalBranch16
(
ConditionalBranch16
_branch16
,
boolean
_invert
)
throws
CodeGenException
{
if
(
_branch16
instanceof
If
)
{
if
(
_branch16
instanceof
If
)
{
final
If
iff
=
(
If
)
_branch16
;
final
If
iff
=
(
If
)
_branch16
;
writeInstruction
(
iff
.
getLhs
());
writeInstruction
(
iff
.
getLhs
());
write
(
_branch16
.
getOperator
().
getText
(
_invert
));
write
(
_branch16
.
getOperator
().
getText
(
_invert
));
writeInstruction
(
iff
.
getRhs
());
writeInstruction
(
iff
.
getRhs
());
}
else
if
(
_branch16
instanceof
I_IFNULL
)
{
}
else
if
(
_branch16
instanceof
I_IFNULL
)
{
final
I_IFNULL
iff
=
(
I_IFNULL
)
_branch16
;
final
I_IFNULL
iff
=
(
I_IFNULL
)
_branch16
;
writeInstruction
(
iff
.
getFirstChild
());
writeInstruction
(
iff
.
getFirstChild
());
if
(
_invert
)
{
if
(
_invert
)
{
write
(
" != NULL"
);
write
(
" != NULL"
);
}
else
{
}
else
{
write
(
" == NULL"
);
write
(
" == NULL"
);
}
}
}
else
if
(
_branch16
instanceof
I_IFNONNULL
)
{
}
else
if
(
_branch16
instanceof
I_IFNONNULL
)
{
final
I_IFNONNULL
iff
=
(
I_IFNONNULL
)
_branch16
;
final
I_IFNONNULL
iff
=
(
I_IFNONNULL
)
_branch16
;
writeInstruction
(
iff
.
getFirstChild
());
writeInstruction
(
iff
.
getFirstChild
());
if
(
_invert
)
{
if
(
_invert
)
{
write
(
" == NULL"
);
write
(
" == NULL"
);
}
else
{
}
else
{
write
(
" != NULL"
);
write
(
" != NULL"
);
}
}
}
else
if
(
_branch16
instanceof
IfUnary
)
{
}
else
if
(
_branch16
instanceof
IfUnary
)
{
final
IfUnary
branch16
=
(
IfUnary
)
_branch16
;
final
IfUnary
branch16
=
(
IfUnary
)
_branch16
;
final
Instruction
comparison
=
branch16
.
getUnary
();
final
Instruction
comparison
=
branch16
.
getUnary
();
final
ByteCode
comparisonByteCode
=
comparison
.
getByteCode
();
final
ByteCode
comparisonByteCode
=
comparison
.
getByteCode
();
final
String
comparisonOperator
=
_branch16
.
getOperator
().
getText
(
_invert
);
final
String
comparisonOperator
=
_branch16
.
getOperator
().
getText
(
_invert
);
switch
(
comparisonByteCode
)
{
switch
(
comparisonByteCode
)
{
case
FCMPG:
case
FCMPG:
case
DCMPG:
case
DCMPG:
case
FCMPL:
case
FCMPL:
case
DCMPL:
case
DCMPL:
if
(
Config
.
verboseComparitor
)
{
if
(
Config
.
verboseComparitor
)
{
write
(
"/* bytecode="
+
comparisonByteCode
.
getName
()
+
" invert="
+
_invert
+
"*/"
);
write
(
"/* bytecode="
+
comparisonByteCode
.
getName
()
+
" invert="
+
_invert
+
"*/"
);
}
}
writeInstruction
(
comparison
.
getFirstChild
());
writeInstruction
(
comparison
.
getFirstChild
());
write
(
comparisonOperator
);
write
(
comparisonOperator
);
writeInstruction
(
comparison
.
getLastChild
());
writeInstruction
(
comparison
.
getLastChild
());
break
;
break
;
default
:
default
:
if
(
Config
.
verboseComparitor
)
{
if
(
Config
.
verboseComparitor
)
{
write
(
"/* default bytecode="
+
comparisonByteCode
.
getName
()
+
" invert="
+
_invert
+
"*/"
);
write
(
"/* default bytecode="
+
comparisonByteCode
.
getName
()
+
" invert="
+
_invert
+
"*/"
);
}
}
writeInstruction
(
comparison
);
writeInstruction
(
comparison
);
write
(
comparisonOperator
);
write
(
comparisonOperator
);
write
(
"0"
);
write
(
"0"
);
}
}
}
}
}
}
public
void
writeComposite
(
CompositeInstruction
instruction
)
throws
CodeGenException
{
public
void
writeComposite
(
CompositeInstruction
instruction
)
throws
CodeGenException
{
if
(
instruction
instanceof
CompositeArbitraryScopeInstruction
)
{
if
(
instruction
instanceof
CompositeArbitraryScopeInstruction
)
{
newLine
();
newLine
();
writeBlock
(
instruction
.
getFirstChild
(),
null
);
writeBlock
(
instruction
.
getFirstChild
(),
null
);
}
else
if
(
instruction
instanceof
CompositeIfInstruction
)
{
}
else
if
(
instruction
instanceof
CompositeIfInstruction
)
{
newLine
();
newLine
();
write
(
"if ("
);
write
(
"if ("
);
final
Instruction
blockStart
=
writeConditional
(
instruction
.
getBranchSet
());
final
Instruction
blockStart
=
writeConditional
(
instruction
.
getBranchSet
());
write
(
")"
);
write
(
")"
);
writeBlock
(
blockStart
,
null
);
writeBlock
(
blockStart
,
null
);
}
else
if
(
instruction
instanceof
CompositeIfElseInstruction
)
{
}
else
if
(
instruction
instanceof
CompositeIfElseInstruction
)
{
newLine
();
newLine
();
write
(
"if ("
);
write
(
"if ("
);
final
Instruction
blockStart
=
writeConditional
(
instruction
.
getBranchSet
());
final
Instruction
blockStart
=
writeConditional
(
instruction
.
getBranchSet
());
write
(
")"
);
write
(
")"
);
Instruction
elseGoto
=
blockStart
;
Instruction
elseGoto
=
blockStart
;
while
(!(
elseGoto
.
isBranch
()
&&
elseGoto
.
asBranch
().
isUnconditional
()))
{
while
(!(
elseGoto
.
isBranch
()
&&
elseGoto
.
asBranch
().
isUnconditional
()))
{
elseGoto
=
elseGoto
.
getNextExpr
();
elseGoto
=
elseGoto
.
getNextExpr
();
}
}
writeBlock
(
blockStart
,
elseGoto
);
writeBlock
(
blockStart
,
elseGoto
);
write
(
" else "
);
write
(
" else "
);
writeBlock
(
elseGoto
.
getNextExpr
(),
null
);
writeBlock
(
elseGoto
.
getNextExpr
(),
null
);
}
else
if
(
instruction
instanceof
CompositeForSunInstruction
)
{
}
else
if
(
instruction
instanceof
CompositeForSunInstruction
)
{
newLine
();
newLine
();
write
(
"for ("
);
write
(
"for ("
);
Instruction
topBranch
=
instruction
.
getFirstChild
();
Instruction
topBranch
=
instruction
.
getFirstChild
();
if
(
topBranch
instanceof
AssignToLocalVariable
)
{
if
(
topBranch
instanceof
AssignToLocalVariable
)
{
writeInstruction
(
topBranch
);
writeInstruction
(
topBranch
);
topBranch
=
topBranch
.
getNextExpr
();
topBranch
=
topBranch
.
getNextExpr
();
}
}
write
(
"; "
);
write
(
"; "
);
final
BranchSet
branchSet
=
instruction
.
getBranchSet
();
final
BranchSet
branchSet
=
instruction
.
getBranchSet
();
final
Instruction
blockStart
=
writeConditional
(
branchSet
);
final
Instruction
blockStart
=
writeConditional
(
branchSet
);
final
Instruction
lastGoto
=
instruction
.
getLastChild
();
final
Instruction
lastGoto
=
instruction
.
getLastChild
();
if
(
branchSet
.
getFallThrough
()
==
lastGoto
)
{
if
(
branchSet
.
getFallThrough
()
==
lastGoto
)
{
// empty body no delta!
// empty body no delta!
write
(
";){}"
);
write
(
";){}"
);
}
else
{
}
else
{
final
Instruction
delta
=
lastGoto
.
getPrevExpr
();
final
Instruction
delta
=
lastGoto
.
getPrevExpr
();
write
(
"; "
);
write
(
"; "
);
if
(!(
delta
instanceof
CompositeInstruction
))
{
if
(!(
delta
instanceof
CompositeInstruction
))
{
writeInstruction
(
delta
);
writeInstruction
(
delta
);
write
(
")"
);
write
(
")"
);
writeBlock
(
blockStart
,
delta
);
writeBlock
(
blockStart
,
delta
);
}
else
{
}
else
{
write
(
"){"
);
write
(
"){"
);
in
();
in
();
writeSequence
(
blockStart
,
delta
);
writeSequence
(
blockStart
,
delta
);
newLine
();
newLine
();
writeSequence
(
delta
,
delta
.
getNextExpr
());
writeSequence
(
delta
,
delta
.
getNextExpr
());
out
();
out
();
newLine
();
newLine
();
write
(
"}"
);
write
(
"}"
);
}
}
}
}
}
else
if
(
instruction
instanceof
CompositeWhileInstruction
)
{
}
else
if
(
instruction
instanceof
CompositeWhileInstruction
)
{
newLine
();
newLine
();
write
(
"while ("
);
write
(
"while ("
);
final
BranchSet
branchSet
=
instruction
.
getBranchSet
();
final
BranchSet
branchSet
=
instruction
.
getBranchSet
();
final
Instruction
blockStart
=
writeConditional
(
branchSet
);
final
Instruction
blockStart
=
writeConditional
(
branchSet
);
write
(
")"
);
write
(
")"
);
final
Instruction
lastGoto
=
instruction
.
getLastChild
();
final
Instruction
lastGoto
=
instruction
.
getLastChild
();
writeBlock
(
blockStart
,
lastGoto
);
writeBlock
(
blockStart
,
lastGoto
);
}
else
if
(
instruction
instanceof
CompositeEmptyLoopInstruction
)
{
}
else
if
(
instruction
instanceof
CompositeEmptyLoopInstruction
)
{
newLine
();
newLine
();
write
(
"for ("
);
write
(
"for ("
);
Instruction
topBranch
=
instruction
.
getFirstChild
();
Instruction
topBranch
=
instruction
.
getFirstChild
();
if
(
topBranch
instanceof
AssignToLocalVariable
)
{
if
(
topBranch
instanceof
AssignToLocalVariable
)
{
writeInstruction
(
topBranch
);
writeInstruction
(
topBranch
);
topBranch
=
topBranch
.
getNextExpr
();
topBranch
=
topBranch
.
getNextExpr
();
}
}
write
(
"; "
);
write
(
"; "
);
writeConditional
(
instruction
.
getBranchSet
());
writeConditional
(
instruction
.
getBranchSet
());
write
(
";){}"
);
write
(
";){}"
);
}
else
if
(
instruction
instanceof
CompositeForEclipseInstruction
)
{
}
else
if
(
instruction
instanceof
CompositeForEclipseInstruction
)
{
newLine
();
newLine
();
write
(
"for ("
);
write
(
"for ("
);
Instruction
topGoto
=
instruction
.
getFirstChild
();
Instruction
topGoto
=
instruction
.
getFirstChild
();
if
(
topGoto
instanceof
AssignToLocalVariable
)
{
if
(
topGoto
instanceof
AssignToLocalVariable
)
{
writeInstruction
(
topGoto
);
writeInstruction
(
topGoto
);
topGoto
=
topGoto
.
getNextExpr
();
topGoto
=
topGoto
.
getNextExpr
();
}
}
write
(
"; "
);
write
(
"; "
);
Instruction
last
=
instruction
.
getLastChild
();
Instruction
last
=
instruction
.
getLastChild
();
while
(
last
.
getPrevExpr
().
isBranch
())
{
while
(
last
.
getPrevExpr
().
isBranch
())
{
last
=
last
.
getPrevExpr
();
last
=
last
.
getPrevExpr
();
}
}
writeConditional
(
instruction
.
getBranchSet
(),
true
);
writeConditional
(
instruction
.
getBranchSet
(),
true
);
write
(
"; "
);
write
(
"; "
);
final
Instruction
delta
=
last
.
getPrevExpr
();
final
Instruction
delta
=
last
.
getPrevExpr
();
if
(!(
delta
instanceof
CompositeInstruction
))
{
if
(!(
delta
instanceof
CompositeInstruction
))
{
writeInstruction
(
delta
);
writeInstruction
(
delta
);
write
(
")"
);
write
(
")"
);
writeBlock
(
topGoto
.
getNextExpr
(),
delta
);
writeBlock
(
topGoto
.
getNextExpr
(),
delta
);
}
else
{
}
else
{
write
(
"){"
);
write
(
"){"
);
in
();
in
();
writeSequence
(
topGoto
.
getNextExpr
(),
delta
);
writeSequence
(
topGoto
.
getNextExpr
(),
delta
);
newLine
();
newLine
();
writeSequence
(
delta
,
delta
.
getNextExpr
());
writeSequence
(
delta
,
delta
.
getNextExpr
());
out
();
out
();
newLine
();
newLine
();
write
(
"}"
);
write
(
"}"
);
}
}
}
else
if
(
instruction
instanceof
CompositeDoWhileInstruction
)
{
}
else
if
(
instruction
instanceof
CompositeDoWhileInstruction
)
{
newLine
();
newLine
();
write
(
"do"
);
write
(
"do"
);
Instruction
blockStart
=
instruction
.
getFirstChild
();
Instruction
blockStart
=
instruction
.
getFirstChild
();
Instruction
blockEnd
=
instruction
.
getLastChild
();
Instruction
blockEnd
=
instruction
.
getLastChild
();
writeBlock
(
blockStart
,
blockEnd
);
writeBlock
(
blockStart
,
blockEnd
);
write
(
"while("
);
write
(
"while("
);
writeConditional
(((
CompositeInstruction
)
instruction
).
getBranchSet
(),
true
);
writeConditional
(((
CompositeInstruction
)
instruction
).
getBranchSet
(),
true
);
write
(
");"
);
write
(
");"
);
newLine
();
newLine
();
}
}
}
}
public
void
writeSequence
(
Instruction
_first
,
Instruction
_last
)
throws
CodeGenException
{
public
void
writeSequence
(
Instruction
_first
,
Instruction
_last
)
throws
CodeGenException
{
for
(
Instruction
instruction
=
_first
;
instruction
!=
_last
;
instruction
=
instruction
.
getNextExpr
())
{
for
(
Instruction
instruction
=
_first
;
instruction
!=
_last
;
instruction
=
instruction
.
getNextExpr
())
{
if
(
instruction
instanceof
CompositeInstruction
)
{
if
(
instruction
instanceof
CompositeInstruction
)
{
writeComposite
((
CompositeInstruction
)
instruction
);
writeComposite
((
CompositeInstruction
)
instruction
);
}
else
if
(!
instruction
.
getByteCode
().
equals
(
ByteCode
.
NONE
))
{
}
else
if
(!
instruction
.
getByteCode
().
equals
(
ByteCode
.
NONE
))
{
newLine
();
newLine
();
writeInstruction
(
instruction
);
writeInstruction
(
instruction
);
write
(
";"
);
write
(
";"
);
}
}
}
}
}
}
protected
void
writeGetterBlock
(
FieldEntry
accessorVariableFieldEntry
)
{
protected
void
writeGetterBlock
(
FieldEntry
accessorVariableFieldEntry
)
{
write
(
"{"
);
write
(
"{"
);
in
();
in
();
newLine
();
newLine
();
write
(
"return this->"
);
write
(
"return this->"
);
write
(
accessorVariableFieldEntry
.
getNameAndTypeEntry
().
getNameUTF8Entry
().
getUTF8
());
write
(
accessorVariableFieldEntry
.
getNameAndTypeEntry
().
getNameUTF8Entry
().
getUTF8
());
write
(
";"
);
write
(
";"
);
out
();
out
();
newLine
();
newLine
();
write
(
"}"
);
write
(
"}"
);
}
}
public
void
writeBlock
(
Instruction
_first
,
Instruction
_last
)
throws
CodeGenException
{
public
void
writeBlock
(
Instruction
_first
,
Instruction
_last
)
throws
CodeGenException
{
write
(
"{"
);
write
(
"{"
);
in
();
in
();
writeSequence
(
_first
,
_last
);
writeSequence
(
_first
,
_last
);
out
();
out
();
newLine
();
newLine
();
write
(
"}"
);
write
(
"}"
);
}
}
public
Instruction
writeConditional
(
BranchSet
_branchSet
)
throws
CodeGenException
{
public
Instruction
writeConditional
(
BranchSet
_branchSet
)
throws
CodeGenException
{
return
(
writeConditional
(
_branchSet
,
false
));
return
(
writeConditional
(
_branchSet
,
false
));
}
}
public
Instruction
writeConditional
(
BranchSet
_branchSet
,
boolean
_invert
)
throws
CodeGenException
{
public
Instruction
writeConditional
(
BranchSet
_branchSet
,
boolean
_invert
)
throws
CodeGenException
{
final
LogicalExpressionNode
logicalExpression
=
_branchSet
.
getLogicalExpression
();
final
LogicalExpressionNode
logicalExpression
=
_branchSet
.
getLogicalExpression
();
write
(
_invert
?
logicalExpression
:
logicalExpression
.
cloneInverted
());
write
(
_invert
?
logicalExpression
:
logicalExpression
.
cloneInverted
());
return
(
_branchSet
.
getLast
().
getNextExpr
());
return
(
_branchSet
.
getLast
().
getNextExpr
());
}
}
public
void
write
(
LogicalExpressionNode
_node
)
throws
CodeGenException
{
public
void
write
(
LogicalExpressionNode
_node
)
throws
CodeGenException
{
if
(
_node
instanceof
SimpleLogicalExpressionNode
)
{
if
(
_node
instanceof
SimpleLogicalExpressionNode
)
{
final
SimpleLogicalExpressionNode
sn
=
(
SimpleLogicalExpressionNode
)
_node
;
final
SimpleLogicalExpressionNode
sn
=
(
SimpleLogicalExpressionNode
)
_node
;
writeConditionalBranch16
((
ConditionalBranch16
)
sn
.
getBranch
(),
sn
.
isInvert
());
writeConditionalBranch16
((
ConditionalBranch16
)
sn
.
getBranch
(),
sn
.
isInvert
());
}
else
{
}
else
{
final
CompoundLogicalExpressionNode
ln
=
(
CompoundLogicalExpressionNode
)
_node
;
final
CompoundLogicalExpressionNode
ln
=
(
CompoundLogicalExpressionNode
)
_node
;
boolean
needParenthesis
=
false
;
boolean
needParenthesis
=
false
;
final
CompoundLogicalExpressionNode
parent
=
(
CompoundLogicalExpressionNode
)
ln
.
getParent
();
final
CompoundLogicalExpressionNode
parent
=
(
CompoundLogicalExpressionNode
)
ln
.
getParent
();
if
(
parent
!=
null
)
{
if
(
parent
!=
null
)
{
if
(!
ln
.
isAnd
()
&&
parent
.
isAnd
())
{
if
(!
ln
.
isAnd
()
&&
parent
.
isAnd
())
{
needParenthesis
=
true
;
needParenthesis
=
true
;
}
}
}
}
if
(
needParenthesis
)
{
if
(
needParenthesis
)
{
write
(
"("
);
write
(
"("
);
}
}
write
(
ln
.
getLhs
());
write
(
ln
.
getLhs
());
write
(
ln
.
isAnd
()
?
" && "
:
" || "
);
write
(
ln
.
isAnd
()
?
" && "
:
" || "
);
write
(
ln
.
getRhs
());
write
(
ln
.
getRhs
());
if
(
needParenthesis
)
{
if
(
needParenthesis
)
{
write
(
")"
);
write
(
")"
);
}
}
}
}
}
}
public
String
convertType
(
String
_typeDesc
,
boolean
useClassModel
)
{
public
String
convertType
(
String
_typeDesc
,
boolean
useClassModel
)
{
return
(
_typeDesc
);
return
(
_typeDesc
);
}
}
public
String
convertCast
(
String
_cast
)
{
public
String
convertCast
(
String
_cast
)
{
// Strip parens off cast
// Strip parens off cast
//System.out.println("cast = " + _cast);
//System.out.println("cast = " + _cast);
final
String
raw
=
convertType
(
_cast
.
substring
(
1
,
_cast
.
length
()
-
1
),
false
);
final
String
raw
=
convertType
(
_cast
.
substring
(
1
,
_cast
.
length
()
-
1
),
false
);
return
(
"("
+
raw
+
")"
);
return
(
"("
+
raw
+
")"
);
}
}
public
void
writeInstruction
(
Instruction
_instruction
)
throws
CodeGenException
{
public
void
writeInstruction
(
Instruction
_instruction
)
throws
CodeGenException
{
if
(
_instruction
instanceof
CompositeIfElseInstruction
)
{
if
(
_instruction
instanceof
CompositeIfElseInstruction
)
{
write
(
"("
);
write
(
"("
);
final
Instruction
lhs
=
writeConditional
(((
CompositeInstruction
)
_instruction
).
getBranchSet
());
write
(
"("
);
write
(
")?"
);
final
Instruction
lhs
=
writeConditional
(((
CompositeInstruction
)
_instruction
).
getBranchSet
());
writeInstruction
(
lhs
);
write
(
")?"
);
write
(
":"
);
writeInstruction
(
lhs
);
writeInstruction
(
lhs
.
getNextExpr
().
getNextExpr
());
write
(
":"
);
}
else
if
(
_instruction
instanceof
CompositeInstruction
)
{
writeInstruction
(
lhs
.
getNextExpr
().
getNextExpr
());
writeComposite
((
CompositeInstruction
)
_instruction
);
write
(
")"
);
}
else
if
(
_instruction
instanceof
CompositeInstruction
)
{
}
else
if
(
_instruction
instanceof
AssignToLocalVariable
)
{
writeComposite
((
CompositeInstruction
)
_instruction
);
final
AssignToLocalVariable
assignToLocalVariable
=
(
AssignToLocalVariable
)
_instruction
;
}
else
if
(
_instruction
instanceof
AssignToLocalVariable
)
{
final
LocalVariableInfo
localVariableInfo
=
assignToLocalVariable
.
getLocalVariableInfo
();
final
AssignToLocalVariable
assignToLocalVariable
=
(
AssignToLocalVariable
)
_instruction
;
if
(
assignToLocalVariable
.
isDeclaration
())
{
final
String
descriptor
=
localVariableInfo
.
getVariableDescriptor
();
final
LocalVariableInfo
localVariableInfo
=
assignToLocalVariable
.
getLocalVariableInfo
();
// Arrays always map to __global arrays
if
(
assignToLocalVariable
.
isDeclaration
())
{
if
(
descriptor
.
startsWith
(
"["
))
{
final
String
descriptor
=
localVariableInfo
.
getVariableDescriptor
();
write
(
" __global "
);
// Arrays always map to __global arrays
}
if
(
descriptor
.
startsWith
(
"["
))
{
write
(
convertType
(
descriptor
,
true
));
write
(
" __global "
);
}
}
if
(
localVariableInfo
==
null
)
{
write
(
convertType
(
descriptor
,
true
));
throw
new
CodeGenException
(
"outOfScope"
+
_instruction
.
getThisPC
()
+
" = "
);
}
}
else
{
if
(
localVariableInfo
==
null
)
{
write
(
localVariableInfo
.
getVariableName
()
+
" = "
);
throw
new
CodeGenException
(
"outOfScope"
+
_instruction
.
getThisPC
()
+
" = "
);
}
}
else
{
write
(
localVariableInfo
.
getVariableName
()
+
" = "
);
for
(
Instruction
operand
=
_instruction
.
getFirstChild
();
operand
!=
null
;
operand
=
operand
.
getNextExpr
())
{
}
writeInstruction
(
operand
);
}
for
(
Instruction
operand
=
_instruction
.
getFirstChild
();
operand
!=
null
;
operand
=
operand
.
getNextExpr
())
{
writeInstruction
(
operand
);
}
else
if
(
_instruction
instanceof
AssignToArrayElement
)
{
}
final
AssignToArrayElement
arrayAssignmentInstruction
=
(
AssignToArrayElement
)
_instruction
;
writeInstruction
(
arrayAssignmentInstruction
.
getArrayRef
());
}
else
if
(
_instruction
instanceof
AssignToArrayElement
)
{
write
(
"["
);
final
AssignToArrayElement
arrayAssignmentInstruction
=
(
AssignToArrayElement
)
_instruction
;
writeInstruction
(
arrayAssignmentInstruction
.
getArrayIndex
());
writeInstruction
(
arrayAssignmentInstruction
.
getArrayRef
());
write
(
"]"
);
write
(
"["
);
write
(
" "
);
writeInstruction
(
arrayAssignmentInstruction
.
getArrayIndex
());
write
(
" = "
);
write
(
"]"
);
writeInstruction
(
arrayAssignmentInstruction
.
getValue
());
write
(
" "
);
}
else
if
(
_instruction
instanceof
AccessArrayElement
)
{
write
(
" = "
);
writeInstruction
(
arrayAssignmentInstruction
.
getValue
());
//we're getting an element from an array
}
else
if
(
_instruction
instanceof
AccessArrayElement
)
{
//if the array is a primitive then we just return the value
//so the generated code looks like
//we're getting an element from an array
//arrayName[arrayIndex];
//if the array is a primitive then we just return the value
//but if the array is an object, or multidimensional array, then we want to return
//so the generated code looks like
//a pointer to our index our position in the array. The code will look like
//arrayName[arrayIndex];
//&(arrayName[arrayIndex * this->arrayNameLen_dimension]
//but if the array is an object, or multidimensional array, then we want to return
//
//a pointer to our index our position in the array. The code will look like
final
AccessArrayElement
arrayLoadInstruction
=
(
AccessArrayElement
)
_instruction
;
//&(arrayName[arrayIndex * this->arrayNameLen_dimension]
//
//object array, get address
final
AccessArrayElement
arrayLoadInstruction
=
(
AccessArrayElement
)
_instruction
;
boolean
isMultiDimensional
=
arrayLoadInstruction
instanceof
I_AALOAD
&&
isMultiDimensionalArray
(
arrayLoadInstruction
);
if
(
isMultiDimensional
)
{
//object array, get address
write
(
"(&"
);
boolean
isMultiDimensional
=
arrayLoadInstruction
instanceof
I_AALOAD
&&
isMultiDimensionalArray
(
arrayLoadInstruction
);
}
if
(
isMultiDimensional
)
{
writeInstruction
(
arrayLoadInstruction
.
getArrayRef
());
write
(
"(&"
);
write
(
"["
);
}
writeInstruction
(
arrayLoadInstruction
.
getArrayIndex
());
writeInstruction
(
arrayLoadInstruction
.
getArrayRef
());
write
(
"["
);
//object array, find the size of each object in the array
writeInstruction
(
arrayLoadInstruction
.
getArrayIndex
());
//for 2D arrays, this size is the size of a row.
if
(
isMultiDimensional
)
{
//object array, find the size of each object in the array
int
dim
=
0
;
//for 2D arrays, this size is the size of a row.
Instruction
load
=
arrayLoadInstruction
.
getArrayRef
();
if
(
isMultiDimensional
)
{
while
(
load
instanceof
I_AALOAD
)
{
int
dim
=
0
;
load
=
load
.
getFirstChild
();
Instruction
load
=
arrayLoadInstruction
.
getArrayRef
();
dim
++;
while
(
load
instanceof
I_AALOAD
)
{
}
load
=
load
.
getFirstChild
();
dim
++;
NameAndTypeEntry
nameAndTypeEntry
=
((
AccessInstanceField
)
load
).
getConstantPoolFieldEntry
().
getNameAndTypeEntry
();
}
if
(
isMultiDimensionalArray
(
nameAndTypeEntry
))
{
String
arrayName
=
nameAndTypeEntry
.
getNameUTF8Entry
().
getUTF8
();
NameAndTypeEntry
nameAndTypeEntry
=
((
AccessInstanceField
)
load
).
getConstantPoolFieldEntry
().
getNameAndTypeEntry
();
write
(
" * this->"
+
arrayName
+
arrayDimMangleSuffix
+
dim
);
if
(
isMultiDimensionalArray
(
nameAndTypeEntry
))
{
}
String
arrayName
=
nameAndTypeEntry
.
getNameUTF8Entry
().
getUTF8
();
}
write
(
" * this->"
+
arrayName
+
arrayDimMangleSuffix
+
dim
);
}
write
(
"]"
);
}
//object array, close parentheses
write
(
"]"
);
if
(
isMultiDimensional
)
{
write
(
")"
);
//object array, close parentheses
}
if
(
isMultiDimensional
)
{
}
else
if
(
_instruction
instanceof
AccessField
)
{
write
(
")"
);
final
AccessField
accessField
=
(
AccessField
)
_instruction
;
}
if
(
accessField
instanceof
AccessInstanceField
)
{
}
else
if
(
_instruction
instanceof
AccessField
)
{
Instruction
accessInstanceField
=
((
AccessInstanceField
)
accessField
).
getInstance
();
final
AccessField
accessField
=
(
AccessField
)
_instruction
;
if
(
accessInstanceField
instanceof
CloneInstruction
)
{
if
(
accessField
instanceof
AccessInstanceField
)
{
accessInstanceField
=
((
CloneInstruction
)
accessInstanceField
).
getReal
();
Instruction
accessInstanceField
=
((
AccessInstanceField
)
accessField
).
getInstance
();
}
if
(
accessInstanceField
instanceof
CloneInstruction
)
{
if
(!(
accessInstanceField
instanceof
I_ALOAD_0
))
{
accessInstanceField
=
((
CloneInstruction
)
accessInstanceField
).
getReal
();
writeInstruction
(
accessInstanceField
);
}
write
(
"."
);
if
(!(
accessInstanceField
instanceof
I_ALOAD_0
))
{
}
else
{
writeInstruction
(
accessInstanceField
);
writeThisRef
();
write
(
"."
);
}
}
else
{
}
writeThisRef
();
write
(
accessField
.
getConstantPoolFieldEntry
().
getNameAndTypeEntry
().
getNameUTF8Entry
().
getUTF8
());
}
}
}
else
if
(
_instruction
instanceof
I_ARRAYLENGTH
)
{
write
(
accessField
.
getConstantPoolFieldEntry
().
getNameAndTypeEntry
().
getNameUTF8Entry
().
getUTF8
());
//getting the length of an array.
}
else
if
(
_instruction
instanceof
I_ARRAYLENGTH
)
{
//if this is a primitive array, then this is trivial
//if we're getting an object array, then we need to find what dimension
//getting the length of an array.
//we're looking at
//if this is a primitive array, then this is trivial
int
dim
=
0
;
//if we're getting an object array, then we need to find what dimension
Instruction
load
=
_instruction
.
getFirstChild
();
//we're looking at
while
(
load
instanceof
I_AALOAD
)
{
int
dim
=
0
;
load
=
load
.
getFirstChild
();
Instruction
load
=
_instruction
.
getFirstChild
();
dim
++;
while
(
load
instanceof
I_AALOAD
)
{
}
load
=
load
.
getFirstChild
();
NameAndTypeEntry
nameAndTypeEntry
=
((
AccessInstanceField
)
load
).
getConstantPoolFieldEntry
().
getNameAndTypeEntry
();
dim
++;
final
String
arrayName
=
nameAndTypeEntry
.
getNameUTF8Entry
().
getUTF8
();
}
String
dimSuffix
=
isMultiDimensionalArray
(
nameAndTypeEntry
)
?
Integer
.
toString
(
dim
)
:
""
;
NameAndTypeEntry
nameAndTypeEntry
=
((
AccessInstanceField
)
load
).
getConstantPoolFieldEntry
().
getNameAndTypeEntry
();
write
(
"this->"
+
arrayName
+
arrayLengthMangleSuffix
+
dimSuffix
);
final
String
arrayName
=
nameAndTypeEntry
.
getNameUTF8Entry
().
getUTF8
();
}
else
if
(
_instruction
instanceof
AssignToField
)
{
String
dimSuffix
=
isMultiDimensionalArray
(
nameAndTypeEntry
)
?
Integer
.
toString
(
dim
)
:
""
;
final
AssignToField
assignedField
=
(
AssignToField
)
_instruction
;
write
(
"this->"
+
arrayName
+
arrayLengthMangleSuffix
+
dimSuffix
);
}
else
if
(
_instruction
instanceof
AssignToField
)
{
if
(
assignedField
instanceof
AssignToInstanceField
)
{
final
AssignToField
assignedField
=
(
AssignToField
)
_instruction
;
final
Instruction
accessInstanceField
=
((
AssignToInstanceField
)
assignedField
).
getInstance
().
getReal
();
if
(
assignedField
instanceof
AssignToInstanceField
)
{
if
(!(
accessInstanceField
instanceof
I_ALOAD_0
))
{
final
Instruction
accessInstanceField
=
((
AssignToInstanceField
)
assignedField
).
getInstance
().
getReal
();
writeInstruction
(
accessInstanceField
);
write
(
"."
);
if
(!(
accessInstanceField
instanceof
I_ALOAD_0
))
{
}
else
{
writeInstruction
(
accessInstanceField
);
writeThisRef
();
write
(
"."
);
}
}
else
{
}
writeThisRef
();
write
(
assignedField
.
getConstantPoolFieldEntry
().
getNameAndTypeEntry
().
getNameUTF8Entry
().
getUTF8
());
}
write
(
"="
);
}
writeInstruction
(
assignedField
.
getValueToAssign
());
write
(
assignedField
.
getConstantPoolFieldEntry
().
getNameAndTypeEntry
().
getNameUTF8Entry
().
getUTF8
());
}
else
if
(
_instruction
instanceof
Constant
<?>)
{
write
(
"="
);
final
Constant
<?>
constantInstruction
=
(
Constant
<?>)
_instruction
;
writeInstruction
(
assignedField
.
getValueToAssign
());
final
Object
value
=
constantInstruction
.
getValue
();
}
else
if
(
_instruction
instanceof
Constant
<?>)
{
final
Constant
<?>
constantInstruction
=
(
Constant
<?>)
_instruction
;
if
(
value
instanceof
Float
)
{
final
Object
value
=
constantInstruction
.
getValue
();
final
Float
f
=
(
Float
)
value
;
if
(
value
instanceof
Float
)
{
if
(
f
.
isNaN
())
{
write
(
"NAN"
);
final
Float
f
=
(
Float
)
value
;
}
else
if
(
f
.
isInfinite
())
{
if
(
f
.
isNaN
())
{
if
(
f
<
0
)
{
write
(
"NAN"
);
write
(
"-"
);
}
else
if
(
f
.
isInfinite
())
{
}
if
(
f
<
0
)
{
write
(
"INFINITY"
);
write
(
"-"
);
}
else
{
}
write
(
value
.
toString
());
write
(
"INFINITY"
);
write
(
"f"
);
}
else
{
}
write
(
value
.
toString
());
}
else
if
(
value
instanceof
Double
)
{
write
(
"f"
);
}
final
Double
d
=
(
Double
)
value
;
}
else
if
(
value
instanceof
Double
)
{
if
(
d
.
isNaN
())
{
write
(
"NAN"
);
final
Double
d
=
(
Double
)
value
;
}
else
if
(
d
.
isInfinite
())
{
if
(
d
.
isNaN
())
{
if
(
d
<
0
)
{
write
(
"NAN"
);
write
(
"-"
);
}
else
if
(
d
.
isInfinite
())
{
}
if
(
d
<
0
)
{
write
(
"INFINITY"
);
write
(
"-"
);
}
else
{
}
write
(
value
.
toString
());
write
(
"INFINITY"
);
}
}
else
{
}
else
{
write
(
value
.
toString
());
write
(
value
.
toString
());
}
if
(
value
instanceof
Long
)
{
}
else
{
write
(
"L"
);
write
(
value
.
toString
());
}
if
(
value
instanceof
Long
)
{
}
write
(
"L"
);
}
}
else
if
(
_instruction
instanceof
AccessLocalVariable
)
{
}
final
AccessLocalVariable
localVariableLoadInstruction
=
(
AccessLocalVariable
)
_instruction
;
final
LocalVariableInfo
localVariable
=
localVariableLoadInstruction
.
getLocalVariableInfo
();
}
else
if
(
_instruction
instanceof
AccessLocalVariable
)
{
write
(
localVariable
.
getVariableName
());
final
AccessLocalVariable
localVariableLoadInstruction
=
(
AccessLocalVariable
)
_instruction
;
}
else
if
(
_instruction
instanceof
I_IINC
)
{
final
LocalVariableInfo
localVariable
=
localVariableLoadInstruction
.
getLocalVariableInfo
();
final
I_IINC
location
=
(
I_IINC
)
_instruction
;
write
(
localVariable
.
getVariableName
());
final
LocalVariableInfo
localVariable
=
location
.
getLocalVariableInfo
();
}
else
if
(
_instruction
instanceof
I_IINC
)
{
final
int
adjust
=
location
.
getAdjust
();
final
I_IINC
location
=
(
I_IINC
)
_instruction
;
final
LocalVariableInfo
localVariable
=
location
.
getLocalVariableInfo
();
write
(
localVariable
.
getVariableName
());
final
int
adjust
=
location
.
getAdjust
();
if
(
adjust
==
1
)
{
write
(
"++"
);
write
(
localVariable
.
getVariableName
());
}
else
if
(
adjust
==
-
1
)
{
if
(
adjust
==
1
)
{
write
(
"--"
);
write
(
"++"
);
}
else
if
(
adjust
>
1
)
{
}
else
if
(
adjust
==
-
1
)
{
write
(
"+="
+
adjust
);
write
(
"--"
);
}
else
if
(
adjust
<
-
1
)
{
}
else
if
(
adjust
>
1
)
{
write
(
"-="
+
(-
adjust
));
write
(
"+="
+
adjust
);
}
}
else
if
(
adjust
<
-
1
)
{
}
else
if
(
_instruction
instanceof
BinaryOperator
)
{
write
(
"-="
+
(-
adjust
));
final
BinaryOperator
binaryInstruction
=
(
BinaryOperator
)
_instruction
;
}
final
Instruction
parent
=
binaryInstruction
.
getParentExpr
();
}
else
if
(
_instruction
instanceof
BinaryOperator
)
{
boolean
needsParenthesis
=
true
;
final
BinaryOperator
binaryInstruction
=
(
BinaryOperator
)
_instruction
;
final
Instruction
parent
=
binaryInstruction
.
getParentExpr
();
if
(
parent
instanceof
AssignToLocalVariable
)
{
boolean
needsParenthesis
=
true
;
needsParenthesis
=
false
;
}
else
if
(
parent
instanceof
AssignToField
)
{
if
(
parent
instanceof
AssignToLocalVariable
)
{
needsParenthesis
=
false
;
needsParenthesis
=
false
;
}
else
if
(
parent
instanceof
AssignToArrayElement
)
{
}
else
if
(
parent
instanceof
AssignToField
)
{
needsParenthesis
=
false
;
needsParenthesis
=
false
;
}
else
{
}
else
if
(
parent
instanceof
AssignToArrayElement
)
{
/**
needsParenthesis
=
false
;
if (parent instanceof BinaryOperator) {
}
else
{
BinaryOperator parentBinaryOperator = (BinaryOperator) parent;
/**
if (parentBinaryOperator.getOperator().ordinal() > binaryInstruction.getOperator().ordinal()) {
if (parent instanceof BinaryOperator) {
needsParenthesis = false;
BinaryOperator parentBinaryOperator = (BinaryOperator) parent;
}
if (parentBinaryOperator.getOperator().ordinal() > binaryInstruction.getOperator().ordinal()) {
}
needsParenthesis = false;
**/
}
}
}
**/
if
(
needsParenthesis
)
{
}
write
(
"("
);
}
if
(
needsParenthesis
)
{
write
(
"("
);
writeInstruction
(
binaryInstruction
.
getLhs
());
}
write
(
" "
+
binaryInstruction
.
getOperator
().
getText
()
+
" "
);
writeInstruction
(
binaryInstruction
.
getLhs
());
writeInstruction
(
binaryInstruction
.
getRhs
());
write
(
" "
+
binaryInstruction
.
getOperator
().
getText
()
+
" "
);
if
(
needsParenthesis
)
{
writeInstruction
(
binaryInstruction
.
getRhs
());
write
(
")"
);
}
if
(
needsParenthesis
)
{
write
(
")"
);
}
else
if
(
_instruction
instanceof
CastOperator
)
{
}
final
CastOperator
castInstruction
=
(
CastOperator
)
_instruction
;
// write("(");
}
else
if
(
_instruction
instanceof
CastOperator
)
{
write
(
convertCast
(
castInstruction
.
getOperator
().
getText
()));
final
CastOperator
castInstruction
=
(
CastOperator
)
_instruction
;
// write("(");
writeInstruction
(
castInstruction
.
getUnary
());
write
(
convertCast
(
castInstruction
.
getOperator
().
getText
()));
// write(")");
}
else
if
(
_instruction
instanceof
UnaryOperator
)
{
writeInstruction
(
castInstruction
.
getUnary
());
final
UnaryOperator
unaryInstruction
=
(
UnaryOperator
)
_instruction
;
// write(")");
// write("(");
}
else
if
(
_instruction
instanceof
UnaryOperator
)
{
write
(
unaryInstruction
.
getOperator
().
getText
());
final
UnaryOperator
unaryInstruction
=
(
UnaryOperator
)
_instruction
;
// write("(");
writeInstruction
(
unaryInstruction
.
getUnary
());
write
(
unaryInstruction
.
getOperator
().
getText
());
// write(")");
}
else
if
(
_instruction
instanceof
Return
)
{
writeInstruction
(
unaryInstruction
.
getUnary
());
// write(")");
final
Return
ret
=
(
Return
)
_instruction
;
}
else
if
(
_instruction
instanceof
Return
)
{
write
(
"return"
);
if
(
ret
.
getStackConsumeCount
()
>
0
)
{
final
Return
ret
=
(
Return
)
_instruction
;
write
(
"("
);
write
(
"return"
);
writeInstruction
(
ret
.
getFirstChild
());
if
(
ret
.
getStackConsumeCount
()
>
0
)
{
write
(
")"
);
write
(
"("
);
}
writeInstruction
(
ret
.
getFirstChild
());
write
(
")"
);
}
else
if
(
_instruction
instanceof
MethodCall
)
{
}
final
MethodCall
methodCall
=
(
MethodCall
)
_instruction
;
}
else
if
(
_instruction
instanceof
MethodCall
)
{
final
MethodEntry
methodEntry
=
methodCall
.
getConstantPoolMethodEntry
();
final
MethodCall
methodCall
=
(
MethodCall
)
_instruction
;
writeMethod
(
methodCall
,
methodEntry
);
final
MethodEntry
methodEntry
=
methodCall
.
getConstantPoolMethodEntry
();
}
else
if
(
_instruction
.
getByteCode
().
equals
(
ByteCode
.
CLONE
))
{
final
CloneInstruction
cloneInstruction
=
(
CloneInstruction
)
_instruction
;
writeMethod
(
methodCall
,
methodEntry
);
writeInstruction
(
cloneInstruction
.
getReal
());
}
else
if
(
_instruction
.
getByteCode
().
equals
(
ByteCode
.
CLONE
))
{
}
else
if
(
_instruction
.
getByteCode
().
equals
(
ByteCode
.
INCREMENT
))
{
final
CloneInstruction
cloneInstruction
=
(
CloneInstruction
)
_instruction
;
final
IncrementInstruction
incrementInstruction
=
(
IncrementInstruction
)
_instruction
;
writeInstruction
(
cloneInstruction
.
getReal
());
}
else
if
(
_instruction
.
getByteCode
().
equals
(
ByteCode
.
INCREMENT
))
{
if
(
incrementInstruction
.
isPre
())
{
final
IncrementInstruction
incrementInstruction
=
(
IncrementInstruction
)
_instruction
;
if
(
incrementInstruction
.
isInc
())
{
write
(
"++"
);
if
(
incrementInstruction
.
isPre
())
{
}
else
{
if
(
incrementInstruction
.
isInc
())
{
write
(
"--"
);
write
(
"++"
);
}
}
else
{
}
write
(
"--"
);
}
writeInstruction
(
incrementInstruction
.
getFieldOrVariableReference
());
}
if
(!
incrementInstruction
.
isPre
())
{
if
(
incrementInstruction
.
isInc
())
{
writeInstruction
(
incrementInstruction
.
getFieldOrVariableReference
());
write
(
"++"
);
if
(!
incrementInstruction
.
isPre
())
{
}
else
{
if
(
incrementInstruction
.
isInc
())
{
write
(
"--"
);
write
(
"++"
);
}
}
else
{
}
write
(
"--"
);
}
else
if
(
_instruction
.
getByteCode
().
equals
(
ByteCode
.
MULTI_ASSIGN
))
{
}
final
MultiAssignInstruction
multiAssignInstruction
=
(
MultiAssignInstruction
)
_instruction
;
}
AssignToLocalVariable
from
=
(
AssignToLocalVariable
)
multiAssignInstruction
.
getFrom
();
}
else
if
(
_instruction
.
getByteCode
().
equals
(
ByteCode
.
MULTI_ASSIGN
))
{
final
AssignToLocalVariable
last
=
(
AssignToLocalVariable
)
multiAssignInstruction
.
getTo
();
final
MultiAssignInstruction
multiAssignInstruction
=
(
MultiAssignInstruction
)
_instruction
;
final
Instruction
common
=
multiAssignInstruction
.
getCommon
();
AssignToLocalVariable
from
=
(
AssignToLocalVariable
)
multiAssignInstruction
.
getFrom
();
final
Stack
<
AssignToLocalVariable
>
stack
=
new
Stack
<
AssignToLocalVariable
>();
final
AssignToLocalVariable
last
=
(
AssignToLocalVariable
)
multiAssignInstruction
.
getTo
();
final
Instruction
common
=
multiAssignInstruction
.
getCommon
();
while
(
from
!=
last
)
{
final
Stack
<
AssignToLocalVariable
>
stack
=
new
Stack
<
AssignToLocalVariable
>();
stack
.
push
(
from
);
from
=
(
AssignToLocalVariable
)
((
Instruction
)
from
).
getNextExpr
();
while
(
from
!=
last
)
{
}
stack
.
push
(
from
);
from
=
(
AssignToLocalVariable
)
((
Instruction
)
from
).
getNextExpr
();
for
(
AssignToLocalVariable
alv
=
stack
.
pop
();
alv
!=
null
;
alv
=
stack
.
size
()
>
0
?
stack
.
pop
()
:
null
)
{
}
final
LocalVariableInfo
localVariableInfo
=
alv
.
getLocalVariableInfo
();
for
(
AssignToLocalVariable
alv
=
stack
.
pop
();
alv
!=
null
;
alv
=
stack
.
size
()
>
0
?
stack
.
pop
()
:
null
)
{
if
(
alv
.
isDeclaration
())
{
write
(
convertType
(
localVariableInfo
.
getVariableDescriptor
(),
true
));
final
LocalVariableInfo
localVariableInfo
=
alv
.
getLocalVariableInfo
();
}
if
(
alv
.
isDeclaration
())
{
if
(
localVariableInfo
==
null
)
{
write
(
convertType
(
localVariableInfo
.
getVariableDescriptor
(),
true
));
throw
new
CodeGenException
(
"outOfScope"
+
_instruction
.
getThisPC
()
+
" = "
);
}
}
else
{
if
(
localVariableInfo
==
null
)
{
write
(
localVariableInfo
.
getVariableName
()
+
" = "
);
throw
new
CodeGenException
(
"outOfScope"
+
_instruction
.
getThisPC
()
+
" = "
);
}
}
else
{
write
(
localVariableInfo
.
getVariableName
()
+
" = "
);
}
}
writeInstruction
(
common
);
}
else
if
(
_instruction
.
getByteCode
().
equals
(
ByteCode
.
INLINE_ASSIGN
))
{
}
final
InlineAssignInstruction
inlineAssignInstruction
=
(
InlineAssignInstruction
)
_instruction
;
writeInstruction
(
common
);
final
AssignToLocalVariable
assignToLocalVariable
=
inlineAssignInstruction
.
getAssignToLocalVariable
();
}
else
if
(
_instruction
.
getByteCode
().
equals
(
ByteCode
.
INLINE_ASSIGN
))
{
final
InlineAssignInstruction
inlineAssignInstruction
=
(
InlineAssignInstruction
)
_instruction
;
final
LocalVariableInfo
localVariableInfo
=
assignToLocalVariable
.
getLocalVariableInfo
();
final
AssignToLocalVariable
assignToLocalVariable
=
inlineAssignInstruction
.
getAssignToLocalVariable
();
if
(
assignToLocalVariable
.
isDeclaration
())
{
// this is bad! we need a general way to hoist up a required declaration
final
LocalVariableInfo
localVariableInfo
=
assignToLocalVariable
.
getLocalVariableInfo
();
throw
new
CodeGenException
(
"/* we can't declare this "
+
convertType
(
localVariableInfo
.
getVariableDescriptor
(),
true
)
if
(
assignToLocalVariable
.
isDeclaration
())
{
+
" here */"
);
// this is bad! we need a general way to hoist up a required declaration
}
throw
new
CodeGenException
(
"/* we can't declare this "
+
convertType
(
localVariableInfo
.
getVariableDescriptor
(),
true
)
write
(
localVariableInfo
.
getVariableName
());
+
" here */"
);
write
(
"="
);
}
writeInstruction
(
inlineAssignInstruction
.
getRhs
());
write
(
localVariableInfo
.
getVariableName
());
}
else
if
(
_instruction
.
getByteCode
().
equals
(
ByteCode
.
FIELD_ARRAY_ELEMENT_ASSIGN
))
{
write
(
"="
);
final
FieldArrayElementAssign
inlineAssignInstruction
=
(
FieldArrayElementAssign
)
_instruction
;
writeInstruction
(
inlineAssignInstruction
.
getRhs
());
final
AssignToArrayElement
arrayAssignmentInstruction
=
inlineAssignInstruction
.
getAssignToArrayElement
();
}
else
if
(
_instruction
.
getByteCode
().
equals
(
ByteCode
.
FIELD_ARRAY_ELEMENT_ASSIGN
))
{
final
FieldArrayElementAssign
inlineAssignInstruction
=
(
FieldArrayElementAssign
)
_instruction
;
writeInstruction
(
arrayAssignmentInstruction
.
getArrayRef
());
final
AssignToArrayElement
arrayAssignmentInstruction
=
inlineAssignInstruction
.
getAssignToArrayElement
();
write
(
"["
);
writeInstruction
(
arrayAssignmentInstruction
.
getArrayIndex
());
writeInstruction
(
arrayAssignmentInstruction
.
getArrayRef
());
write
(
"]"
);
write
(
"["
);
write
(
" "
);
writeInstruction
(
arrayAssignmentInstruction
.
getArrayIndex
());
write
(
" = "
);
write
(
"]"
);
write
(
" "
);
writeInstruction
(
inlineAssignInstruction
.
getRhs
());
write
(
" = "
);
}
else
if
(
_instruction
.
getByteCode
().
equals
(
ByteCode
.
FIELD_ARRAY_ELEMENT_INCREMENT
))
{
writeInstruction
(
inlineAssignInstruction
.
getRhs
());
final
FieldArrayElementIncrement
fieldArrayElementIncrement
=
(
FieldArrayElementIncrement
)
_instruction
;
}
else
if
(
_instruction
.
getByteCode
().
equals
(
ByteCode
.
FIELD_ARRAY_ELEMENT_INCREMENT
))
{
final
AssignToArrayElement
arrayAssignmentInstruction
=
fieldArrayElementIncrement
.
getAssignToArrayElement
();
if
(
fieldArrayElementIncrement
.
isPre
())
{
final
FieldArrayElementIncrement
fieldArrayElementIncrement
=
(
FieldArrayElementIncrement
)
_instruction
;
if
(
fieldArrayElementIncrement
.
isInc
())
{
final
AssignToArrayElement
arrayAssignmentInstruction
=
fieldArrayElementIncrement
.
getAssignToArrayElement
();
write
(
"++"
);
if
(
fieldArrayElementIncrement
.
isPre
())
{
}
else
{
if
(
fieldArrayElementIncrement
.
isInc
())
{
write
(
"--"
);
write
(
"++"
);
}
}
else
{
}
write
(
"--"
);
writeInstruction
(
arrayAssignmentInstruction
.
getArrayRef
());
}
}
write
(
"["
);
writeInstruction
(
arrayAssignmentInstruction
.
getArrayRef
());
writeInstruction
(
arrayAssignmentInstruction
.
getArrayIndex
());
write
(
"]"
);
write
(
"["
);
if
(!
fieldArrayElementIncrement
.
isPre
())
{
writeInstruction
(
arrayAssignmentInstruction
.
getArrayIndex
());
if
(
fieldArrayElementIncrement
.
isInc
())
{
write
(
"]"
);
write
(
"++"
);
if
(!
fieldArrayElementIncrement
.
isPre
())
{
}
else
{
if
(
fieldArrayElementIncrement
.
isInc
())
{
write
(
"--"
);
write
(
"++"
);
}
}
else
{
}
write
(
"--"
);
}
}
else
if
(
_instruction
.
getByteCode
().
equals
(
ByteCode
.
NONE
))
{
}
// we are done
}
else
if
(
_instruction
instanceof
Branch
)
{
}
else
if
(
_instruction
.
getByteCode
().
equals
(
ByteCode
.
NONE
))
{
throw
new
CodeGenException
(
String
.
format
(
"%s -> %04d"
,
_instruction
.
getByteCode
().
toString
().
toLowerCase
(),
// we are done
((
Branch
)
_instruction
).
getTarget
().
getThisPC
()));
}
else
if
(
_instruction
instanceof
Branch
)
{
}
else
if
(
_instruction
instanceof
I_POP
)
{
throw
new
CodeGenException
(
String
.
format
(
"%s -> %04d"
,
_instruction
.
getByteCode
().
toString
().
toLowerCase
(),
//POP discarded void call return?
((
Branch
)
_instruction
).
getTarget
().
getThisPC
()));
writeInstruction
(
_instruction
.
getFirstChild
());
}
else
if
(
_instruction
instanceof
I_POP
)
{
}
else
{
//POP discarded void call return?
throw
new
CodeGenException
(
String
.
format
(
"%s"
,
_instruction
.
getByteCode
().
toString
().
toLowerCase
()));
writeInstruction
(
_instruction
.
getFirstChild
());
}
}
else
{
throw
new
CodeGenException
(
String
.
format
(
"%s"
,
_instruction
.
getByteCode
().
toString
().
toLowerCase
()));
}
}
private
boolean
isMultiDimensionalArray
(
NameAndTypeEntry
nameAndTypeEntry
)
{
}
return
nameAndTypeEntry
.
getDescriptorUTF8Entry
().
getUTF8
().
startsWith
(
"[["
);
}
private
boolean
isMultiDimensionalArray
(
NameAndTypeEntry
nameAndTypeEntry
)
{
return
nameAndTypeEntry
.
getDescriptorUTF8Entry
().
getUTF8
().
startsWith
(
"[["
);
private
boolean
isObjectArray
(
NameAndTypeEntry
nameAndTypeEntry
)
{
}
return
nameAndTypeEntry
.
getDescriptorUTF8Entry
().
getUTF8
().
startsWith
(
"[L"
);
}
private
boolean
isObjectArray
(
NameAndTypeEntry
nameAndTypeEntry
)
{
return
nameAndTypeEntry
.
getDescriptorUTF8Entry
().
getUTF8
().
startsWith
(
"[L"
);
private
boolean
isMultiDimensionalArray
(
final
AccessArrayElement
arrayLoadInstruction
)
{
}
AccessInstanceField
accessInstanceField
=
getUltimateInstanceFieldAccess
(
arrayLoadInstruction
);
return
isMultiDimensionalArray
(
accessInstanceField
.
getConstantPoolFieldEntry
().
getNameAndTypeEntry
());
private
boolean
isMultiDimensionalArray
(
final
AccessArrayElement
arrayLoadInstruction
)
{
}
AccessInstanceField
accessInstanceField
=
getUltimateInstanceFieldAccess
(
arrayLoadInstruction
);
return
isMultiDimensionalArray
(
accessInstanceField
.
getConstantPoolFieldEntry
().
getNameAndTypeEntry
());
private
boolean
isObjectArray
(
final
AccessArrayElement
arrayLoadInstruction
)
{
}
AccessInstanceField
accessInstanceField
=
getUltimateInstanceFieldAccess
(
arrayLoadInstruction
);
return
isObjectArray
(
accessInstanceField
.
getConstantPoolFieldEntry
().
getNameAndTypeEntry
());
private
boolean
isObjectArray
(
final
AccessArrayElement
arrayLoadInstruction
)
{
}
AccessInstanceField
accessInstanceField
=
getUltimateInstanceFieldAccess
(
arrayLoadInstruction
);
return
isObjectArray
(
accessInstanceField
.
getConstantPoolFieldEntry
().
getNameAndTypeEntry
());
private
AccessInstanceField
getUltimateInstanceFieldAccess
(
final
AccessArrayElement
arrayLoadInstruction
)
{
}
Instruction
load
=
arrayLoadInstruction
.
getArrayRef
();
while
(
load
instanceof
I_AALOAD
)
{
private
AccessInstanceField
getUltimateInstanceFieldAccess
(
final
AccessArrayElement
arrayLoadInstruction
)
{
load
=
load
.
getFirstChild
();
Instruction
load
=
arrayLoadInstruction
.
getArrayRef
();
}
while
(
load
instanceof
I_AALOAD
)
{
load
=
load
.
getFirstChild
();
return
(
AccessInstanceField
)
load
;
}
}
return
(
AccessInstanceField
)
load
;
public
void
writeMethod
(
MethodCall
_methodCall
,
MethodEntry
_methodEntry
)
throws
CodeGenException
{
}
boolean
noCL
=
_methodEntry
.
getOwnerClassModel
().
getNoCLMethods
()
.
contains
(
_methodEntry
.
getNameAndTypeEntry
().
getNameUTF8Entry
().
getUTF8
());
public
void
writeMethod
(
MethodCall
_methodCall
,
MethodEntry
_methodEntry
)
throws
CodeGenException
{
if
(
noCL
)
{
boolean
noCL
=
_methodEntry
.
getOwnerClassModel
().
getNoCLMethods
()
return
;
.
contains
(
_methodEntry
.
getNameAndTypeEntry
().
getNameUTF8Entry
().
getUTF8
());
}
if
(
noCL
)
{
return
;
if
(
_methodCall
instanceof
VirtualMethodCall
)
{
}
final
Instruction
instanceInstruction
=
((
VirtualMethodCall
)
_methodCall
).
getInstanceReference
();
if
(!(
instanceInstruction
instanceof
I_ALOAD_0
))
{
if
(
_methodCall
instanceof
VirtualMethodCall
)
{
writeInstruction
(
instanceInstruction
);
final
Instruction
instanceInstruction
=
((
VirtualMethodCall
)
_methodCall
).
getInstanceReference
();
write
(
"."
);
if
(!(
instanceInstruction
instanceof
I_ALOAD_0
))
{
}
else
{
writeInstruction
(
instanceInstruction
);
writeThisRef
();
write
(
"."
);
}
}
else
{
}
writeThisRef
();
final
int
argc
=
_methodEntry
.
getStackConsumeCount
();
}
write
(
_methodEntry
.
getNameAndTypeEntry
().
getNameUTF8Entry
().
getUTF8
());
}
write
(
"("
);
final
int
argc
=
_methodEntry
.
getStackConsumeCount
();
write
(
_methodEntry
.
getNameAndTypeEntry
().
getNameUTF8Entry
().
getUTF8
());
for
(
int
arg
=
0
;
arg
<
argc
;
arg
++)
{
write
(
"("
);
if
(
arg
!=
0
)
{
write
(
", "
);
for
(
int
arg
=
0
;
arg
<
argc
;
arg
++)
{
}
if
(
arg
!=
0
)
{
writeInstruction
(
_methodCall
.
getArg
(
arg
));
write
(
", "
);
}
}
write
(
")"
);
writeInstruction
(
_methodCall
.
getArg
(
arg
));
}
}
write
(
")"
);
public
void
writeThisRef
()
{
}
write
(
"this."
);
}
public
void
writeThisRef
()
{
write
(
"this."
);
public
void
writeMethodBody
(
MethodModel
_methodModel
)
throws
CodeGenException
{
}
if
(
_methodModel
.
isGetter
()
&&
!
_methodModel
.
isNoCL
())
{
FieldEntry
accessorVariableFieldEntry
=
_methodModel
.
getAccessorVariableFieldEntry
();
public
void
writeMethodBody
(
MethodModel
_methodModel
)
throws
CodeGenException
{
writeGetterBlock
(
accessorVariableFieldEntry
);
if
(
_methodModel
.
isGetter
()
&&
!
_methodModel
.
isNoCL
())
{
}
else
{
FieldEntry
accessorVariableFieldEntry
=
_methodModel
.
getAccessorVariableFieldEntry
();
writeBlock
(
_methodModel
.
getExprHead
(),
null
);
writeGetterBlock
(
accessorVariableFieldEntry
);
}
}
else
{
}
writeBlock
(
_methodModel
.
getExprHead
(),
null
);
}
public
abstract
void
write
(
Entrypoint
entryPoint
)
throws
CodeGenException
;
}
}
public
abstract
void
write
(
Entrypoint
entryPoint
)
throws
CodeGenException
;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment