Skip to content

Commit

Permalink
Regall: Add template
Browse files Browse the repository at this point in the history
  • Loading branch information
Lenart12 committed May 9, 2023
1 parent 0af50ce commit 2681a80
Show file tree
Hide file tree
Showing 7 changed files with 532 additions and 332 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ hs_err_pid*
**/*.asmgen.xml
**/*.livean.html
**/*.livean.xml
**/*.regall.html
**/*.regall.xml

# antlr
**/PrevLexer.tokens
Expand Down
132 changes: 132 additions & 0 deletions prev23/lib/xsl/regall.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="regall">
<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>
12 changes: 11 additions & 1 deletion prev23/src/prev23/Compiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import prev23.common.report.*;
import prev23.phase.lexan.*;
import prev23.phase.regall.RegAll;
import prev23.phase.synan.*;
import prev23.phase.abstr.*;
import prev23.phase.seman.*;
Expand Down Expand Up @@ -46,7 +47,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|livean";
private static final String phases = "none|lexan|synan|abstr|seman|memory|imcgen|imclin|asmgen|livean|regall";

/** 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 @@ -104,6 +105,7 @@ public static void main(String[] args) {
if ((cmdLineArgs.get("--target-phase") == null) || (cmdLineArgs.get("--target-phase").equals("all"))) {
cmdLineArgs.put("--target-phase", phases.replaceFirst("^.*\\|", ""));
}
cmdLineArgs.putIfAbsent("--num-regs", "32");

// Compilation process carried out phase by phase.
while (true) {
Expand Down Expand Up @@ -195,6 +197,14 @@ public static void main(String[] args) {
}
if (Compiler.cmdLineArgValue("--target-phase").equals("livean"))
break;

// Register allocation.
try (RegAll regAll = new RegAll()) {
regAll.allocate();
regAll.log();
}
if (Compiler.cmdLineArgValue("--target-phase").equals("regall"))
break;
}

Report.info("Done.");
Expand Down
8 changes: 6 additions & 2 deletions prev23/src/prev23/phase/asmgen/AsmGen.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
package prev23.phase.asmgen;

import java.util.*;

import prev23.Compiler;
import prev23.data.imc.code.stmt.*;
import prev23.data.lin.*;
import prev23.data.asm.*;
import prev23.phase.*;
import prev23.phase.imclin.*;

import java.util.*;

/**
* Machine code generator.
*/
public class AsmGen extends Phase {

public static Vector<Code> codes = new Vector<Code>();

public static int num_regs;

public AsmGen() {
super("asmgen");
num_regs = Integer.parseInt(Compiler.cmdLineArgValue("--num-regs"));
}

public void genAsmCodes() {
Expand Down
Loading

0 comments on commit 2681a80

Please sign in to comment.