Tracking condition codes in translation code for different machine architectures
First Claim
1. A method of processing input computer code by a computer in a code translator to produce translated code, comprising the steps of:
- accessing and parsing said code by said computer to generate a flow graph in an intermediate language from said code, the flow graph being a data structure composed of blocks, and the blocks being composed of intermediate-- language elements, where each element represents a single expression in said code, and where each block represents a sequence of one or more elements with no intermediate entry or exit;
tracing through each said block of elements in a reverse direction from its exit to its entry to detect any elements which read or set condition codes, where said condition codes represent bits set in a status register in a processor executing said computer code;
producing from those detected elements which read condition codes a first set of condition codes;
removing from the first set those condition codes which are set by other detected elements to produce a second required set of required condition codes; and
generating from the required set instructions in said translated code to set the required condition codes to simulate reading and setting of the condition codes.
3 Assignments
0 Petitions
Accused Products
Abstract
A code translator, constructed similar to a compiler, accepts as an input to be translated the assembly code written for one architecture (e.g., VAX), and produces as an output object code for a different machine architecture (e.g., RISC). The input code is converted into an intermediate language, and a flow graph is constructed. The flow graph is referenced by a flow analyzer for recognizing certain architecture-specific and calling standard-specific coding practices or idioms that cannot be automatically converted, particularly relating to stack usage, register usage, condition codes, and passing arguments for procedure calls. By tracking stack usage within routines, the compiler can distinguish up-level stack and return address references from valid local references. Also, it can inform the user of stack misalignment, which has a severe performance penalty, and can detect code segments where different flow paths may result in different stack depths at runtime, which may indicate a source code error. Register usage is likewise tracked to determine which registers are destroyed by a routine, and generate routine prologue and epilogue code which performs register saves, as well as provide register "hints" to aid the user in adding an entry point declaration or documentation for the routine. The usage of condition codes is likewise tracked, by a backward walk through the flow graph, so that code to fabricate needed values is generated. In addition, all argument pointer based memory references in the input code is tracked to determine how the same argument reference may be made in the target environment.
188 Citations
29 Claims
-
1. A method of processing input computer code by a computer in a code translator to produce translated code, comprising the steps of:
-
accessing and parsing said code by said computer to generate a flow graph in an intermediate language from said code, the flow graph being a data structure composed of blocks, and the blocks being composed of intermediate-- language elements, where each element represents a single expression in said code, and where each block represents a sequence of one or more elements with no intermediate entry or exit; tracing through each said block of elements in a reverse direction from its exit to its entry to detect any elements which read or set condition codes, where said condition codes represent bits set in a status register in a processor executing said computer code; producing from those detected elements which read condition codes a first set of condition codes; removing from the first set those condition codes which are set by other detected elements to produce a second required set of required condition codes; and generating from the required set instructions in said translated code to set the required condition codes to simulate reading and setting of the condition codes. - View Dependent Claims (2, 3, 4, 5, 6, 7, 8)
-
-
9. Apparatus for processing input computer code by a computer in a code translator to produce translated code, comprising:
-
means for generating a flow graph in an intermediate language from said code, the flow graph being a data structure composed of blocks, and the blocks being composed of intermediate language elements, where each element represents a single expression in said code, and where each block represents a sequence of one or more elements with no intermediate exit or entry; means for tracing in a reverse direction from its exit to its entry through each block of said flow graph to detect any elements which read or set condition codes; means for producing from those detected elements which read condition codes a first set of condition codes; means for removing from the first set those condition codes which are set by other detect elements to produce a second required set of required condition codes; and means for generating from the required set instructions in said translated code to set the required condition codes to simulate reading and setting of the condition codes. - View Dependent Claims (10, 11, 12, 13)
-
-
14. A method executed by a computer for compiling input code written for a first computer architecture to produce object code for a different computer architecture, said first computer architecture including condition codes in arithmetic and logic operation, said different computer architecture not including condition codes, comprising the steps of:
-
accessing and parsing said code by said computer to generate a flow graph in an intermediate language from said input code by a converter, the flow graph being a data structure composed of blocks, and the blocks being composed of tuples, where each tuple represents a single expression in said input code, and where each block represents a sequence of one or more tuples with no intermediate exit or entry; tracing through each block of said flow graph in a reverse direction from its exit to its entry to detect any tuples which read or set condition codes; producing from those detected tuples which read condition codes a first set of condition codes; removing from the first set those condition codes which are set by other detected tuples to produce a second set of required condition codes; and generating operations in said object code using said required set to simulate setting and reading of the condition codes in said required set. - View Dependent Claims (15, 16, 17, 18, 19, 20)
-
-
21. A method of processing input computer code by a computer in a code translator to produce translated code, for detecting and reporting code errors and code which is not compilable, comprising the steps of:
-
accessing and parsing said code by said computer to generate allow graph in an intermediate language from said code, the flow graph being a data structure composed of blocks, and the blocks being composed of intermediate-- language elements, where each element represents a single expression in said code, and where each block represents a sequence of one or more elements with no intermediate exit or entry; tracing through each block of said flow graph in a reverse direction from its exit to its entry to identify elements which read or set condition codes; producing from those detected elements which read condition codes a first set of condition codes; removing from the first set those condition codes which are set by other detected elements to produce a second required set of required condition codes; and generating from the required set instructions in said translated code to set the required condition codes to simulate reading and setting of the condition codes. - View Dependent Claims (22, 23, 24, 25, 26, 27, 28, 29)
-
Specification