Patent ID: 8205192

Claim:
A compiler device for optimizing a program which manipulates a character string, the compiler device comprising: a processor including at least an append instruction detection unit for detecting an append instruction to append a character string to a string variable for storing a character string, in the program; the processor further including a store code generation unit for generating, as a substitute for each of a plurality of the append instructions detected by the append instruction detection unit, a store code for storing an address in memory where an appendant character string to be appended to the string variable by the append instruction is stored, into a buffer, the plurality of append instructions appending character strings to the same string variable; and the processor further including an append code generation unit for generating an append code for appending a plurality of the appendant character strings stored in a plurality of the addresses, to the string variable, at a position to be executed before an instruction to refer to the string variable in the program, wherein the append instruction detection unit detects, as the append instruction, a combination of: an instruction to convert an immutable string variable in which a process of appending a character string is not allowed, into a mutable string variable in which a process of appending a character string is allowed; an instruction to append the appendant character string to the mutable string variable; and an instruction to convert the mutable string variable into the immutable string variable, the processor further including an instruction elimination unit for eliminating an immutable-to-mutable conversion instruction and for causing the mutable string variable to be used as the mutable string variable after the immutable-to-mutable conversion instruction, if an instruction to be executed between a mutable-to-immutable conversion instruction and the immutable-to-mutable conversion instruction does not modify a character string stored in the mutable string variable, and if an instruction to be executed between the immutable-to-mutable conversion instruction and use of the mutable string variable does not modify any of the mutable string variable used as a source variable of the mutable-to-immutable conversion instruction and the mutable string variable.