Skip to content

Commit

Permalink
Livean: Add template
Browse files Browse the repository at this point in the history
  • Loading branch information
Lenart12 committed Apr 27, 2023
1 parent c2ecd00 commit 00cf741
Show file tree
Hide file tree
Showing 5 changed files with 221 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ hs_err_pid*
**/*.imclin.xml
**/*.asmgen.html
**/*.asmgen.xml

**/*.livean.html
**/*.livean.xml

# antlr
**/PrevLexer.tokens
Expand Down
132 changes: 132 additions & 0 deletions prev23/lib/xsl/livean.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="livean">
<html>
<style>
table, tr, td {
text-align: center;
vertical-align: top;
}
</style>
<body>
<table>
<xsl:apply-templates select="code"/>
</table>
</body>
</html>
</xsl:template>

<xsl:template match="code">
<td bgcolor="FFEE00">
<table>
<tr>
<td bgcolor="EECF00">
<xsl:apply-templates select="frame"/>
</td>
</tr>
<tr>
<td bgcolor="EECF00">
<nobr>
entryLabel=<xsl:value-of select="@entrylabel"/>
exitLabel=<xsl:value-of select="@exitlabel"/>
temps=<xsl:value-of select="@tempsize"/>
</nobr>
</td>
</tr>
<xsl:apply-templates select="instructions"/>
</table>
</td>
</xsl:template>

<xsl:template match="instructions">
<xsl:apply-templates select="instruction"/>
</xsl:template>

<xsl:template match="instruction">
<tr></tr>
<tr>
<td bgcolor="00BBFF">
<xsl:value-of select="@code"/>
</td>
<xsl:apply-templates select="temps"/>
</tr>
</xsl:template>

<xsl:template match="temps">
<tr bgcolor="00DDFF">
<td>
<xsl:value-of select="@name"/>:
<xsl:apply-templates select="temp"/>
</td>
</tr>
</xsl:template>

<xsl:template match="temp">
<xsl:text> </xsl:text>
<xsl:value-of select="@name"/>
</xsl:template>

<xsl:template match="frame">
<table width="100%">
<tr>
<td>
<nobr>
FRAME
label=<font style="font-family:courier new"><xsl:value-of select="@label"/></font>
</nobr>
</td>
</tr>
<tr>
<td>
<nobr>
depth=<xsl:value-of select="@depth"/>
size=<xsl:value-of select="@size"/>
locs=<xsl:value-of select="@locssize"/>
args=<xsl:value-of select="@argssize"/>
</nobr>
</td>
</tr>
<tr>
<td>
<nobr>
FP=<xsl:value-of select="@FP"/>
RV=<xsl:value-of select="@RV"/>
</nobr>
</td>
</tr>
</table>
</xsl:template>

<xsl:template match="frame">
<table width="100%">
<tr>
<td>
<nobr>
FRAME
label=<font style="font-family:courier new"><xsl:value-of select="@label"/></font>
</nobr>
</td>
</tr>
<tr>
<td>
<nobr>
depth=<xsl:value-of select="@depth"/>
size=<xsl:value-of select="@size"/>
locs=<xsl:value-of select="@locssize"/>
args=<xsl:value-of select="@argssize"/>
</nobr>
</td>
</tr>
<tr>
<td>
<nobr>
FP=<xsl:value-of select="@FP"/>
RV=<xsl:value-of select="@RV"/>
</nobr>
</td>
</tr>
</table>
</xsl:template>

</xsl:stylesheet>
11 changes: 10 additions & 1 deletion prev23/src/prev23/Compiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import prev23.phase.imcgen.*;
import prev23.phase.imclin.*;
import prev23.phase.asmgen.*;
import prev23.phase.livean.*;

/**
* The compiler.
Expand Down Expand Up @@ -45,7 +46,7 @@ private Compiler() {
// COMMAND LINE ARGUMENTS

/** All valid phases of the compiler. */
private static final String phases = "none|lexan|synan|abstr|seman|memory|imcgen|imclin|asmgen";
private static final String phases = "none|lexan|synan|abstr|seman|memory|imcgen|imclin|asmgen|livean";

/** Values of command line arguments indexed by their command line switch. */
private static HashMap<String, String> cmdLineArgs = new HashMap<String, String>();
Expand Down Expand Up @@ -186,6 +187,14 @@ public static void main(String[] args) {
}
if (Compiler.cmdLineArgValue("--target-phase").equals("asmgen"))
break;

// Liveness analysis.
try (LiveAn livean = new LiveAn()) {
livean.analysis();
livean.log();
}
if (Compiler.cmdLineArgValue("--target-phase").equals("livean"))
break;
}

Report.info("Done.");
Expand Down
73 changes: 73 additions & 0 deletions prev23/src/prev23/phase/livean/LiveAn.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package prev23.phase.livean;

import prev23.data.mem.*;
import prev23.data.asm.*;
import prev23.phase.*;
import prev23.phase.asmgen.*;

/**
* Liveness analysis.
*/
public class LiveAn extends Phase {

public LiveAn() {
super("livean");
}

public void analysis() {
// TODO
}

public void log() {
if (logger == null)
return;
for (Code code : AsmGen.codes) {
logger.begElement("code");
logger.addAttribute("entrylabel", code.entryLabel.name);
logger.addAttribute("exitlabel", code.exitLabel.name);
logger.addAttribute("tempsize", Long.toString(code.tempSize));
code.frame.log(logger);
logger.begElement("instructions");
for (AsmInstr instr : code.instrs) {
logger.begElement("instruction");
logger.addAttribute("code", instr.toString());
logger.begElement("temps");
logger.addAttribute("name", "use");
for (MemTemp temp : instr.uses()) {
logger.begElement("temp");
logger.addAttribute("name", temp.toString());
logger.endElement();
}
logger.endElement();
logger.begElement("temps");
logger.addAttribute("name", "def");
for (MemTemp temp : instr.defs()) {
logger.begElement("temp");
logger.addAttribute("name", temp.toString());
logger.endElement();
}
logger.endElement();
logger.begElement("temps");
logger.addAttribute("name", "in");
for (MemTemp temp : instr.in()) {
logger.begElement("temp");
logger.addAttribute("name", temp.toString());
logger.endElement();
}
logger.endElement();
logger.begElement("temps");
logger.addAttribute("name", "out");
for (MemTemp temp : instr.out()) {
logger.begElement("temp");
logger.addAttribute("name", temp.toString());
logger.endElement();
}
logger.endElement();
logger.endElement();
}
logger.endElement();
logger.endElement();
}
}

}
4 changes: 4 additions & 0 deletions prev23/src/prev23/phase/livean/package-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/**
* Liveness analysis.
*/
package prev23.phase.livean;

0 comments on commit 00cf741

Please sign in to comment.