import java.io.Writer;
import java.io.PrintWriter;

public class SimpleIA32Generator extends AssemblyGenerator {
	public int getSystemIntSize() {
		return 4;
	}

	public int getPointerSize() {
		return 4;
	}

	public int getFunctionSize() {
		return 4;
	}

	PrintWriter out;

	public void generateAssembly(Writer out,
	StaticVariable[] staticVariableDefinitionList,
	Function[] functionDefinitionList) {
		this.out = new PrintWriter(out);

		// プログラムを出力する
		this.out.println(".section .text");
		for (int i = 0; i < functionDefinitionList.length; i++) {
			generateFunction(functionDefinitionList[i]);
		}

		// データの領域を出力する
		this.out.println(".section .bss");
		for (int i = 0; i < staticVariableDefinitionList.length; i++) {
			StaticVariable sv = staticVariableDefinitionList[i];
			this.out.println(".comm " + sv.getName() + ", " + sv.getDataType().getWidth());
		}

		this.out.flush();
	}

	private void generateFunction(Function func) {
		// 関数の開始
		out.println(".globl " + func.getName());
		out.println(func.getName() + ":");
		// 関数内の命令をそれぞれ出力する
		int instNum = func.getInstructionNumber();
		for (int i = 0; i < instNum; i++) {
			generateInstruction(func.getInstruction(i));
		}
		// 関数の終わり
		out.println("stoa.funcend." + func.getName() + ":");
		out.println("\tret");
	}

	private void generateInstruction(Instruction inst) {
		if (inst instanceof NormalExpression) {
			throw new SystemLimitException("NormalExpression not implemented yet");
		} else if (inst instanceof ReturnInstruction) {
			throw new SystemLimitException("ReturnInstruction not implemented yet");
		} else if (inst instanceof ConditionalBranch) {
			throw new SystemLimitException("ConditionalBranch not implemented yet");
		} else if (inst instanceof InfiniteLoop) {
			throw new SystemLimitException("InfiniteLoop not implemented yet");
		} else if (inst instanceof WhileLoop) {
			throw new SystemLimitException("WhileLoop not implemented yet");
		} else if (inst instanceof BreakInstruction) {
			throw new SystemLimitException("BreakInstruction not implemented yet");
		} else if (inst instanceof ContinueInstruction) {
			throw new SystemLimitException("ContinueInstruction not implemented yet");
		}
	}
}

@@ -2187,11 +2187,1050 @@
 ;%0A%09%09%7D%0A%09%7D
+%0A%0A%09private void generateExpressionEvaluation(Expression expr) %7B%0A%09%09generateExpressionEvaluation(expr, false);%0A%09%7D%0A%0A%09private void generateExpressionEvaluation(Expression expr, boolean wantAddress) %7B%0A%09%09if (expr instanceof BinaryOperator) %7B%0A%09%09%09throw new SystemLimitException(%22BinaryOperator not implemented yet%22);%0A%09%09%7D else if (expr instanceof UnaryOperator) %7B%0A%09%09%09throw new SystemLimitException(%22UnaryOperator not implemented yet%22);%0A%09%09%7D else if (expr instanceof FunctionCallOperator) %7B%0A%09%09%09throw new SystemLimitException(%22FunctionCallOperator not implemented yet%22);%0A%09%09%7D else if (expr instanceof CastOperator) %7B%0A%09%09%09throw new SystemLimitException(%22CastOperator not implemented yet%22);%0A%09%09%7D else if (expr instanceof VariableAccess) %7B%0A%09%09%09throw new SystemLimitException(%22VariableAccess not implemented yet%22);%0A%09%09%7D else if (expr instanceof IntegerLiteral) %7B%0A%09%09%09throw new SystemLimitException(%22IntegerLiteral not implemented yet%22);%0A%09%09%7D else if (expr instanceof StringLiteral) %7B%0A%09%09%09throw new SystemLimitException(%22StringLiteral not implemented yet%22);%0A%09%09%7D%0A%09%7D
 %0A%7D%0A

add generateExpressionEvaluation() method