r4972@macbookpro: aamine | 2009-05-26 13:24:13 +0900

* net/loveruby/cflat/asm: refactoring: rename class: AsmStatistics -> Statistics.
 * net/loveruby/cflat/sysdep/x86/CodeGenerator.java: follow it.
 


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4260 1b9489fe-b721-0410-924e-b54b9192deb8
This commit is contained in:
Minero Aoki 2009-05-26 04:24:48 +00:00
parent aabbca6e13
commit a1832aca6b
15 changed files with 27 additions and 19 deletions

View File

@ -1,3 +1,10 @@
Tue May 26 13:23:56 2009 Minero Aoki <aamine@loveruby.net>
* net/loveruby/cflat/asm: refactoring: rename class: AsmStatistics
-> Statistics.
* net/loveruby/cflat/sysdep/x86/CodeGenerator.java: follow it.
Tue May 26 13:18:52 2009 Minero Aoki <aamine@loveruby.net> Tue May 26 13:18:52 2009 Minero Aoki <aamine@loveruby.net>
* net/loveruby/cflat/asm: refactoring: rename class: AsmOperand -> * net/loveruby/cflat/asm: refactoring: rename class: AsmOperand ->

View File

@ -11,7 +11,7 @@ public class AbsoluteAddress extends Operand {
return this.register; return this.register;
} }
public void collectStatistics(AsmStatistics stats) { public void collectStatistics(Statistics stats) {
register.collectStatistics(stats); register.collectStatistics(stats);
} }

View File

@ -19,7 +19,7 @@ abstract public class Assembly {
return false; return false;
} }
public void collectStatistics(AsmStatistics stats) { public void collectStatistics(Statistics stats) {
// does nothing by default. // does nothing by default.
} }

View File

@ -5,7 +5,7 @@ abstract public class BaseSymbol implements Symbol {
return false; return false;
} }
public void collectStatistics(AsmStatistics stats) { public void collectStatistics(Statistics stats) {
stats.symbolUsed(this); stats.symbolUsed(this);
} }

View File

@ -11,7 +11,7 @@ public class DirectMemoryReference extends MemoryReference {
return this.value; return this.value;
} }
public void collectStatistics(AsmStatistics stats) { public void collectStatistics(Statistics stats) {
value.collectStatistics(stats); value.collectStatistics(stats);
} }

View File

@ -21,7 +21,7 @@ public class ImmediateValue extends Operand {
return this.expr; return this.expr;
} }
public void collectStatistics(AsmStatistics stats) { public void collectStatistics(Statistics stats) {
// does nothing // does nothing
} }

View File

@ -39,7 +39,7 @@ public class IndirectMemoryReference extends MemoryReference {
return base; return base;
} }
public void collectStatistics(AsmStatistics stats) { public void collectStatistics(Statistics stats) {
base.collectStatistics(stats); base.collectStatistics(stats);
} }

View File

@ -80,7 +80,7 @@ public class Instruction extends Assembly {
return (Symbol)ref.value(); return (Symbol)ref.value();
} }
public void collectStatistics(AsmStatistics stats) { public void collectStatistics(Statistics stats) {
stats.instructionUsed(mnemonic); stats.instructionUsed(mnemonic);
for (int i = 0; i < operands.length; i++) { for (int i = 0; i < operands.length; i++) {
operands[i].collectStatistics(stats); operands[i].collectStatistics(stats);

View File

@ -40,7 +40,7 @@ public class IntegerLiteral implements Literal {
return toSource(); return toSource();
} }
public void collectStatistics(AsmStatistics stats) { public void collectStatistics(Statistics stats) {
// does nothing // does nothing
} }

View File

@ -3,7 +3,7 @@ package net.loveruby.cflat.asm;
public interface Literal extends Comparable<Literal> { public interface Literal extends Comparable<Literal> {
public String toSource(); public String toSource();
public String toSource(SymbolTable table); public String toSource(SymbolTable table);
public void collectStatistics(AsmStatistics stats); public void collectStatistics(Statistics stats);
public boolean isZero(); public boolean isZero();
public Literal plus(long diff); public Literal plus(long diff);
public int cmp(IntegerLiteral i); public int cmp(IntegerLiteral i);

View File

@ -15,7 +15,7 @@ abstract public class Operand implements OperandPattern {
return null; return null;
} }
abstract public void collectStatistics(AsmStatistics stats); abstract public void collectStatistics(Statistics stats);
// default implementation // default implementation
public boolean match(Operand operand) { public boolean match(Operand operand) {

View File

@ -5,7 +5,7 @@ abstract public class Register extends Operand {
return true; return true;
} }
public void collectStatistics(AsmStatistics stats) { public void collectStatistics(Statistics stats) {
stats.registerUsed(this); stats.registerUsed(this);
} }

View File

@ -1,20 +1,20 @@
package net.loveruby.cflat.asm; package net.loveruby.cflat.asm;
import java.util.*; import java.util.*;
public class AsmStatistics { public class Statistics {
protected Map<Register, Integer> registerUsage; protected Map<Register, Integer> registerUsage;
protected Map<String, Integer> insnUsage; protected Map<String, Integer> insnUsage;
protected Map<Symbol, Integer> symbolUsage; protected Map<Symbol, Integer> symbolUsage;
static public AsmStatistics collect(List<Assembly> assemblies) { static public Statistics collect(List<Assembly> assemblies) {
AsmStatistics stats = new AsmStatistics(); Statistics stats = new Statistics();
for (Assembly asm : assemblies) { for (Assembly asm : assemblies) {
asm.collectStatistics(stats); asm.collectStatistics(stats);
} }
return stats; return stats;
} }
public AsmStatistics() { public Statistics() {
registerUsage = new HashMap<Register, Integer>(); registerUsage = new HashMap<Register, Integer>();
insnUsage = new HashMap<String, Integer>(); insnUsage = new HashMap<String, Integer>();
symbolUsage = new HashMap<Symbol, Integer>(); symbolUsage = new HashMap<Symbol, Integer>();

View File

@ -13,7 +13,7 @@ public class SuffixedSymbol implements Symbol {
return false; return false;
} }
public void collectStatistics(AsmStatistics stats) { public void collectStatistics(Statistics stats) {
base.collectStatistics(stats); base.collectStatistics(stats);
} }

View File

@ -384,7 +384,7 @@ public class CodeGenerator
AssemblyFile file, DefinedFunction func) { AssemblyFile file, DefinedFunction func) {
AssemblyFile body = compileStmts(func); AssemblyFile body = compileStmts(func);
List<Assembly> bodyAsms = optimize(body.assemblies()); List<Assembly> bodyAsms = optimize(body.assemblies());
AsmStatistics stats = AsmStatistics.collect(bodyAsms); Statistics stats = Statistics.collect(bodyAsms);
bodyAsms = reduceLabels(bodyAsms, stats); bodyAsms = reduceLabels(bodyAsms, stats);
List<Register> saveRegs = usedCalleeSavedRegistersWithoutBP(stats); List<Register> saveRegs = usedCalleeSavedRegistersWithoutBP(stats);
long saveRegsBytes = stackSizeFromWordNum(saveRegs.size()); long saveRegsBytes = stackSizeFromWordNum(saveRegs.size());
@ -476,7 +476,8 @@ public class CodeGenerator
// #@@} // #@@}
// #@@range/reduceLabels{ // #@@range/reduceLabels{
private List<Assembly> reduceLabels(List<Assembly> assemblies, AsmStatistics stats) { private List<Assembly> reduceLabels(
List<Assembly> assemblies, Statistics stats) {
List<Assembly> result = new ArrayList<Assembly>(); List<Assembly> result = new ArrayList<Assembly>();
for (Assembly asm : assemblies) { for (Assembly asm : assemblies) {
if (asm.isLabel() && ! stats.doesSymbolUsed((Label)asm)) { if (asm.isLabel() && ! stats.doesSymbolUsed((Label)asm)) {
@ -490,7 +491,7 @@ public class CodeGenerator
} }
// #@@} // #@@}
private List<Register> usedCalleeSavedRegistersWithoutBP(AsmStatistics stats) { private List<Register> usedCalleeSavedRegistersWithoutBP(Statistics stats) {
List<Register> result = new ArrayList<Register>(); List<Register> result = new ArrayList<Register>();
for (Register reg : calleeSavedRegisters()) { for (Register reg : calleeSavedRegisters()) {
if (stats.doesRegisterUsed(reg) && !reg.equals(bp())) { if (stats.doesRegisterUsed(reg) && !reg.equals(bp())) {