Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
2
2024_compilation_bauquin
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
BAUQUIN Niels
2024_compilation_bauquin
Commits
59cd6dbd
Commit
59cd6dbd
authored
1 year ago
by
BAUQUIN Niels
Browse files
Options
Downloads
Patches
Plain Diff
BAHAHHAHAHAHAHAHAHHAHAHAHHAHAHAHHAHAHAHAHHAHAHAH
parent
fa51f89e
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/Compiler.java
+1
-1
1 addition, 1 deletion
src/Compiler.java
src/c3a/Sa2c3a.java
+418
-188
418 additions, 188 deletions
src/c3a/Sa2c3a.java
src/ts/Sa2ts.java
+2
-3
2 additions, 3 deletions
src/ts/Sa2ts.java
with
421 additions
and
192 deletions
src/Compiler.java
+
1
−
1
View file @
59cd6dbd
This diff is collapsed.
Click to expand it.
src/c3a/Sa2c3a.java
+
418
−
188
View file @
59cd6dbd
...
...
@@ -2,6 +2,8 @@ package c3a;
import
ts.*
;
import
sa.*
;
import
java.util.List
;
public
class
Sa2c3a
extends
SaDepthFirstVisitor
<
C3aOperand
>
{
private
C3a
c3a
;
...
...
@@ -45,100 +47,185 @@ public class Sa2c3a extends SaDepthFirstVisitor <C3aOperand> {
return
result
;
}
@Override
public
C3aOperand
visit
(
SaProg
node
)
throws
Exception
{
defaultIn
(
node
);
defaultOut
(
node
);
return
super
.
visit
(
node
);
}
@Override
public
C3aOperand
visit
(
SaDecTab
node
)
throws
Exception
{
defaultIn
(
node
);
defaultOut
(
node
);
return
super
.
visit
(
node
);
}
@Override
public
C3aOperand
visit
(
SaExp
node
)
throws
Exception
{
defaultIn
(
node
);
defaultOut
(
node
);
return
super
.
visit
(
node
);
}
@Override
public
C3aOperand
visit
(
SaExpInt
node
)
throws
Exception
{
return
super
.
visit
(
node
);
defaultIn
(
node
);
C3aOperand
op
=
new
C3aConstant
(
node
.
getVal
());
defaultOut
(
node
);
return
op
;
}
@Override
public
C3aOperand
visit
(
SaExpVrai
node
)
throws
Exception
{
return
super
.
visit
(
node
);
defaultIn
(
node
);
C3aOperand
op
=
new
C3aConstant
(
1
);
defaultOut
(
node
);
return
op
;
}
@Override
public
C3aOperand
visit
(
SaExpFaux
node
)
throws
Exception
{
return
super
.
visit
(
node
);
defaultIn
(
node
);
C3aOperand
op
=
new
C3aConstant
(
0
);
defaultOut
(
node
);
return
op
;
}
@Override
public
C3aOperand
visit
(
SaExpVar
node
)
throws
Exception
{
return
super
.
visit
(
node
);
defaultIn
(
node
);
C3aOperand
var
=
node
.
getVar
().
accept
(
this
);
defaultOut
(
node
);
return
var
;
}
@Override
public
C3aOperand
visit
(
SaInstEcriture
node
)
throws
Exception
{
return
super
.
visit
(
node
);
defaultIn
(
node
);
C3aOperand
op
=
node
.
getArg
().
accept
(
this
);
c3a
.
ajouteInst
(
new
C3aInstWrite
(
op
,
""
));
defaultOut
(
node
);
return
op
;
}
@Override
public
C3aOperand
visit
(
SaInstTantQue
node
)
throws
Exception
{
return
super
.
visit
(
node
);
defaultIn
(
node
);
C3aLabel
labelDebut
=
c3a
.
newAutoLabel
();
C3aLabel
labelFin
=
c3a
.
newAutoLabel
();
c3a
.
addLabelToNextInst
(
labelDebut
);
C3aOperand
temp
=
node
.
getTest
().
accept
(
this
);
c3a
.
ajouteInst
(
new
C3aInstJumpIfEqual
(
temp
,
new
C3aConstant
(
0
),
labelFin
,
""
));
node
.
getFaire
().
accept
(
this
);
c3a
.
ajouteInst
(
new
C3aInstJump
(
labelDebut
,
""
));
c3a
.
addLabelToNextInst
(
labelFin
);
defaultOut
(
node
);
return
temp
;
}
@Override
public
C3aOperand
visit
(
SaLInst
node
)
throws
Exception
{
defaultIn
(
node
);
defaultOut
(
node
);
return
super
.
visit
(
node
);
}
@Override
public
C3aOperand
visit
(
SaDecFonc
node
)
throws
Exception
{
defaultIn
(
node
);
C3aOperand
result
=
c3a
.
newAutoLabel
();
c3a
.
ajouteInst
(
new
C3aInstFBegin
(
node
.
tsItem
,
"begin"
));
node
.
getCorps
().
accept
(
this
);
c3a
.
ajouteInst
(
new
C3aInstFEnd
(
"end"
));
c3a
.
ajouteInst
(
new
C3aInstFBegin
(
node
.
tsItem
,
"entree fonction"
));
C3aOperand
op
=
node
.
getCorps
().
accept
(
this
);
c3a
.
ajouteInst
(
new
C3aInstFEnd
(
""
));
defaultOut
(
node
);
return
result
;
return
op
;
}
@Override
public
C3aOperand
visit
(
SaDecVar
node
)
throws
Exception
{
defaultIn
(
node
);
defaultOut
(
node
);
return
super
.
visit
(
node
);
}
@Override
public
C3aOperand
visit
(
SaInstAffect
node
)
throws
Exception
{
return
super
.
visit
(
node
);
defaultIn
(
node
);
C3aOperand
var
=
node
.
getLhs
().
accept
(
this
);
C3aOperand
exp
=
node
.
getRhs
().
accept
(
this
);
c3a
.
ajouteInst
(
new
C3aInstAffect
(
exp
,
var
,
""
));
defaultOut
(
node
);
return
var
;
}
@Override
public
C3aOperand
visit
(
SaLDecVar
node
)
throws
Exception
{
defaultIn
(
node
);
defaultOut
(
node
);
return
super
.
visit
(
node
);
}
@Override
public
C3aOperand
visit
(
SaLDecFonc
node
)
throws
Exception
{
defaultIn
(
node
);
defaultOut
(
node
);
return
super
.
visit
(
node
);
}
@Override
public
C3aOperand
visit
(
SaVarSimple
node
)
throws
Exception
{
return
super
.
visit
(
node
);
defaultIn
(
node
);
C3aOperand
var
=
new
C3aVar
(
node
.
tsItem
,
null
);
defaultOut
(
node
);
return
var
;
}
@Override
public
C3aOperand
visit
(
SaAppel
node
)
throws
Exception
{
return
super
.
visit
(
node
);
defaultIn
(
node
);
C3aOperand
temp
=
c3a
.
newTemp
();
if
(
node
.
getArguments
()
!=
null
)
{
SaLExp
args
=
node
.
getArguments
();
for
(
int
i
=
0
;
i
<
node
.
getArguments
().
length
();
i
++)
{
C3aOperand
param
=
args
.
getTete
().
accept
(
this
);
c3a
.
ajouteInst
(
new
C3aInstParam
(
param
,
""
));
if
(
args
.
getQueue
()
==
null
)
{
break
;
}
args
=
args
.
getQueue
();
}
}
c3a
.
ajouteInst
(
new
C3aInstCall
(
new
C3aFunction
(
node
.
tsItem
),
temp
,
""
));
defaultOut
(
node
);
return
temp
;
}
@Override
public
C3aOperand
visit
(
SaExpAppel
node
)
throws
Exception
{
return
super
.
visit
(
node
);
defaultIn
(
node
);
C3aOperand
op
=
node
.
getVal
().
accept
(
this
);
defaultOut
(
node
);
return
op
;
}
@Override
...
...
@@ -179,56 +266,199 @@ public class Sa2c3a extends SaDepthFirstVisitor <C3aOperand> {
@Override
public
C3aOperand
visit
(
SaExpInf
node
)
throws
Exception
{
return
super
.
visit
(
node
);
defaultIn
(
node
);
C3aLabel
label
=
c3a
.
newAutoLabel
();
C3aOperand
temp
=
c3a
.
newTemp
();
C3aOperand
op1
=
node
.
getOp1
().
accept
(
this
);
C3aOperand
op2
=
node
.
getOp2
().
accept
(
this
);
c3a
.
ajouteInst
(
new
C3aInstAffect
(
new
C3aConstant
(
1
),
temp
,
""
));
c3a
.
ajouteInst
(
new
C3aInstJumpIfLess
(
op1
,
op2
,
label
,
""
));
c3a
.
ajouteInst
(
new
C3aInstAffect
(
new
C3aConstant
(
0
),
temp
,
""
));
c3a
.
addLabelToNextInst
(
label
);
defaultOut
(
node
);
return
temp
;
}
@Override
public
C3aOperand
visit
(
SaExpEqual
node
)
throws
Exception
{
return
super
.
visit
(
node
);
defaultIn
(
node
);
C3aOperand
result
=
c3a
.
newTemp
();
C3aLabel
label
=
c3a
.
newAutoLabel
();
C3aOperand
op1
=
node
.
getOp1
().
accept
(
this
);
C3aOperand
op2
=
node
.
getOp2
().
accept
(
this
);
c3a
.
ajouteInst
(
new
C3aInstAffect
(
new
C3aConstant
(
1
),
result
,
""
));
c3a
.
ajouteInst
(
new
C3aInstJumpIfEqual
(
op1
,
op2
,
label
,
""
));
c3a
.
ajouteInst
(
new
C3aInstAffect
(
new
C3aConstant
(
0
),
result
,
""
));
c3a
.
addLabelToNextInst
(
label
);
defaultOut
(
node
);
return
result
;
}
@Override
public
C3aOperand
visit
(
SaExpAnd
node
)
throws
Exception
{
return
super
.
visit
(
node
);
defaultIn
(
node
);
C3aOperand
result
=
c3a
.
newTemp
();
C3aLabel
label1
=
c3a
.
newAutoLabel
();
C3aLabel
label2
=
c3a
.
newAutoLabel
();
C3aOperand
op1
=
node
.
getOp1
().
accept
(
this
);
C3aOperand
op2
=
node
.
getOp2
().
accept
(
this
);
c3a
.
ajouteInst
(
new
C3aInstJumpIfEqual
(
op1
,
new
C3aConstant
(
0
),
label2
,
""
));
c3a
.
ajouteInst
(
new
C3aInstJumpIfEqual
(
op2
,
new
C3aConstant
(
0
),
label2
,
""
));
c3a
.
ajouteInst
(
new
C3aInstAffect
(
new
C3aConstant
(
1
),
result
,
""
));
c3a
.
ajouteInst
(
new
C3aInstJump
(
label1
,
""
));
c3a
.
addLabelToNextInst
(
label2
);
c3a
.
ajouteInst
(
new
C3aInstAffect
(
new
C3aConstant
(
0
),
result
,
""
));
c3a
.
addLabelToNextInst
(
label1
);
defaultOut
(
node
);
return
result
;
}
@Override
public
C3aOperand
visit
(
SaExpOr
node
)
throws
Exception
{
return
super
.
visit
(
node
);
defaultIn
(
node
);
C3aOperand
result
=
c3a
.
newTemp
();
System
.
out
.
println
(
node
);
C3aLabel
label1
=
c3a
.
newAutoLabel
();
C3aLabel
label2
=
c3a
.
newAutoLabel
();
C3aOperand
op1
=
node
.
getOp1
().
accept
(
this
);
C3aOperand
op2
=
node
.
getOp2
().
accept
(
this
);
c3a
.
ajouteInst
(
new
C3aInstJumpIfNotEqual
(
op1
,
new
C3aConstant
(
0
),
label2
,
""
));
c3a
.
ajouteInst
(
new
C3aInstJumpIfNotEqual
(
op2
,
new
C3aConstant
(
0
),
label2
,
""
));
c3a
.
ajouteInst
(
new
C3aInstAffect
(
new
C3aConstant
(
0
),
result
,
""
));
c3a
.
ajouteInst
(
new
C3aInstJump
(
label1
,
""
));
c3a
.
addLabelToNextInst
(
label2
);
c3a
.
ajouteInst
(
new
C3aInstAffect
(
new
C3aConstant
(
1
),
result
,
""
));
c3a
.
addLabelToNextInst
(
label1
);
defaultOut
(
node
);
return
result
;
}
@Override
public
C3aOperand
visit
(
SaExpNot
node
)
throws
Exception
{
return
super
.
visit
(
node
);
defaultIn
(
node
);
C3aOperand
result
=
c3a
.
newTemp
();
C3aLabel
label
=
c3a
.
newAutoLabel
();
C3aOperand
op
=
node
.
getOp1
().
accept
(
this
);
c3a
.
ajouteInst
(
new
C3aInstAffect
(
new
C3aConstant
(
1
),
result
,
""
));
c3a
.
ajouteInst
(
new
C3aInstJumpIfEqual
(
op
,
new
C3aConstant
(
0
),
label
,
""
));
c3a
.
ajouteInst
(
new
C3aInstAffect
(
new
C3aConstant
(
0
),
result
,
""
));
c3a
.
addLabelToNextInst
(
label
);
defaultOut
(
node
);
return
result
;
}
@Override
public
C3aOperand
visit
(
SaExpLire
node
)
throws
Exception
{
defaultIn
(
node
);
defaultOut
(
node
);
return
super
.
visit
(
node
);
}
@Override
public
C3aOperand
visit
(
SaInstBloc
node
)
throws
Exception
{
defaultIn
(
node
);
defaultOut
(
node
);
return
super
.
visit
(
node
);
}
@Override
public
C3aOperand
visit
(
SaInstSi
node
)
throws
Exception
{
return
super
.
visit
(
node
);
defaultIn
(
node
);
C3aLabel
label1
=
c3a
.
newAutoLabel
();
C3aLabel
label2
=
c3a
.
newAutoLabel
();
C3aOperand
test
=
node
.
getTest
().
accept
(
this
);
C3aOperand
op
=
null
;
if
(
node
.
getAlors
()
!=
null
)
{
if
(
node
.
getSinon
()
==
null
)
{
c3a
.
ajouteInst
(
new
C3aInstJumpIfEqual
(
test
,
new
C3aConstant
(
0
),
label2
,
""
));
op
=
node
.
getAlors
().
accept
(
this
);
c3a
.
addLabelToNextInst
(
label2
);
}
else
{
c3a
.
ajouteInst
(
new
C3aInstJumpIfEqual
(
test
,
new
C3aConstant
(
0
),
label1
,
""
));
op
=
node
.
getAlors
().
accept
(
this
);
c3a
.
ajouteInst
(
new
C3aInstJump
(
label2
,
""
));
c3a
.
addLabelToNextInst
(
label1
);
op
=
node
.
getSinon
().
accept
(
this
);
c3a
.
addLabelToNextInst
(
label2
);
}
;
}
defaultOut
(
node
);
return
op
;
}
@Override
public
C3aOperand
visit
(
SaInstRetour
node
)
throws
Exception
{
return
super
.
visit
(
node
);
defaultIn
(
node
);
C3aOperand
op
=
node
.
getVal
().
accept
(
this
);
c3a
.
ajouteInst
(
new
C3aInstReturn
(
op
,
""
));
c3a
.
ajouteInst
(
new
C3aInstFEnd
(
""
));
defaultOut
(
node
);
return
op
;
}
@Override
public
C3aOperand
visit
(
SaLExp
node
)
throws
Exception
{
defaultIn
(
node
);
defaultOut
(
node
);
return
super
.
visit
(
node
);
}
@Override
public
C3aOperand
visit
(
SaVarIndicee
node
)
throws
Exception
{
return
super
.
visit
(
node
);
defaultIn
(
node
);
C3aOperand
var
=
new
C3aVar
(
node
.
getTsItem
(),
node
.
getIndice
().
accept
(
this
));
defaultOut
(
node
);
return
var
;
}
}
This diff is collapsed.
Click to expand it.
src/ts/Sa2ts.java
+
2
−
3
View file @
59cd6dbd
...
...
@@ -28,7 +28,6 @@ public class Sa2ts extends SaDepthFirstVisitor <Void> {
String
idTab
=
node
.
getNom
();
Type
typeTab
=
node
.
getType
();
int
tailleTab
=
node
.
getTaille
();
System
.
out
.
println
(
node
);
if
(
context
==
Context
.
GLOBAL
)
{
if
(
tableGlobale
.
getVar
(
idTab
)
!=
null
)
{
throw
new
ErrorException
(
Error
.
TS
,
"Le tableau "
+
idTab
+
" est déjà défini."
);
...
...
@@ -167,12 +166,12 @@ public class Sa2ts extends SaDepthFirstVisitor <Void> {
public
void
defaultIn
(
SaNode
node
)
{
System
.
out
.
println
(
"<"
+
node
.
getClass
().
getSimpleName
()
+
">"
);
//
System.out.println("<" + node.getClass().getSimpleName() + ">");
}
public
void
defaultOut
(
SaNode
node
)
{
System
.
out
.
println
(
"</"
+
node
.
getClass
().
getSimpleName
()
+
">"
);
//
System.out.println("</" + node.getClass().getSimpleName() + ">");
}
...
...
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