* sysdep/x86/CodeGenerator.java: refactoring: rename method: allocateParameters -> locateParameters.

* sysdep/x86/CodeGenerator.java: refactoring: rename method: allocateLocalVariablesTemp -> locateLocalVariables.
* sysdep/x86/CodeGenerator.java: refactoring: rename method: allocateLocalVariables -> fixLocalVariableOffsets.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4275 1b9489fe-b721-0410-924e-b54b9192deb8
This commit is contained in:
Minero Aoki 2009-06-06 12:28:29 +00:00
parent 6775112ebf
commit 4cf7bd2ae8
2 changed files with 26 additions and 17 deletions

View File

@ -1,3 +1,14 @@
Sat Jun 6 21:28:20 2009 Minero Aoki <aamine@loveruby.net>
* sysdep/x86/CodeGenerator.java: refactoring: rename method:
allocateParameters -> locateParameters.
* sysdep/x86/CodeGenerator.java: refactoring: rename method:
allocateLocalVariablesTemp -> locateLocalVariables.
* sysdep/x86/CodeGenerator.java: refactoring: rename method:
allocateLocalVariables -> fixLocalVariableOffsets.
Mon Jun 1 06:39:57 2009 Minero Aoki <aamine@loveruby.net> Mon Jun 1 06:39:57 2009 Minero Aoki <aamine@loveruby.net>
* net/loveruby/cflat/sysdep/x86/CodeGenerator.java: refactoring: * net/loveruby/cflat/sysdep/x86/CodeGenerator.java: refactoring:

View File

@ -381,9 +381,6 @@ public class CodeGenerator
/** Compiles a function. */ /** Compiles a function. */
// #@@range/compileFunction{ // #@@range/compileFunction{
private void compileFunction(AssemblyFile file, DefinedFunction func) { private void compileFunction(AssemblyFile file, DefinedFunction func) {
allocateParameters(func);
allocateLocalVariablesTemp(func.body().scope());
Symbol sym = globalSymbol(func.name()); Symbol sym = globalSymbol(func.name());
if (! func.isPrivate()) { if (! func.isPrivate()) {
file._globl(sym); file._globl(sym);
@ -398,20 +395,22 @@ public class CodeGenerator
// #@@range/compileFunctionBody{ // #@@range/compileFunctionBody{
private void compileFunctionBody( private void compileFunctionBody(
AssemblyFile file, DefinedFunction func) { AssemblyFile file, DefinedFunction func) {
locateParameters(func.parameters());
locateLocalVariables(func.body().scope());
AssemblyFile body = compileStmts(func); AssemblyFile body = compileStmts(func);
List<Assembly> bodyAsms = optimize(body.assemblies()); List<Assembly> bodyAsms = optimize(body.assemblies());
Statistics stats = Statistics.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());
long lvarBytes = allocateLocalVariables( long lvarBytes = fixLocalVariableOffsets(
func.body().scope(), saveRegsBytes); func.body().scope(), saveRegsBytes);
fixTmpOffsets(bodyAsms, saveRegsBytes + lvarBytes); fixTmpOffsets(bodyAsms, saveRegsBytes + lvarBytes);
if (options.isVerboseAsm()) { if (options.isVerboseAsm()) {
printStackFrameLayout(file, printStackFrameLayout(file, saveRegsBytes, lvarBytes,
saveRegsBytes, lvarBytes, body.maxTmpBytes(), body.maxTmpBytes(), func.localVariables());
func.localVariables());
} }
file.initVirtualStack(); file.initVirtualStack();
@ -569,13 +568,13 @@ public class CodeGenerator
} }
// #@@} // #@@}
// #@@range/allocateParameters{ // #@@range/locateParameters{
static final private long paramStartWordNum = 2; static final private long PARAM_START_WORD = 2;
// return addr and saved bp // return addr and saved bp
private void allocateParameters(DefinedFunction func) { private void locateParameters(List<Parameter> params) {
long numWords = paramStartWordNum; long numWords = PARAM_START_WORD;
for (Parameter var : func.parameters()) { for (Parameter var : params) {
var.setMemref(mem(stackSizeFromWordNum(numWords), bp())); var.setMemref(mem(stackSizeFromWordNum(numWords), bp()));
numWords++; numWords++;
} }
@ -586,8 +585,8 @@ public class CodeGenerator
* Allocates addresses of local variables, but offset is still * Allocates addresses of local variables, but offset is still
* not determined, assign unfixed IndirectMemoryReference. * not determined, assign unfixed IndirectMemoryReference.
*/ */
// #@@range/allocateLocalVariablesTemp{ // #@@range/locateLocalVariables{
private void allocateLocalVariablesTemp(LocalScope scope) { private void locateLocalVariables(LocalScope scope) {
for (DefinedVariable var : scope.allLocalVariables()) { for (DefinedVariable var : scope.allLocalVariables()) {
var.setMemref(new IndirectMemoryReference(bp())); var.setMemref(new IndirectMemoryReference(bp()));
} }
@ -597,10 +596,9 @@ public class CodeGenerator
/** /**
* Fixes addresses of local variables. * Fixes addresses of local variables.
* Returns byte-length of the local variable area. * Returns byte-length of the local variable area.
* Note that numSavedRegs includes bp.
*/ */
// #@@range/allocateLocalVariables{ // #@@range/fixLocalVariableOffsets{
private long allocateLocalVariables(LocalScope scope, long initLen) { private long fixLocalVariableOffsets(LocalScope scope, long initLen) {
long maxLen = allocateScope(scope, initLen); long maxLen = allocateScope(scope, initLen);
return maxLen - initLen; return maxLen - initLen;
} }