{"id":9912,"date":"2025-11-03T16:06:05","date_gmt":"2025-11-03T13:06:05","guid":{"rendered":"https:\/\/staging.intechcore.com\/?p=9912"},"modified":"2025-12-01T13:44:31","modified_gmt":"2025-12-01T10:44:31","slug":"development-of-an-own-programming-language-in-javaantlr-compiler","status":"publish","type":"post","link":"https:\/\/intechcore.com\/en\/development-of-an-own-programming-language-in-javaantlr-compiler\/","title":{"rendered":"Developing your own programming language in Java+ANTLR: Compiler"},"content":{"rendered":"<p>This is the third article in the series &#8220;Developing your own programming language in Java&#8221;. For better understanding, you should read the <a href=\"https:\/\/intechcore.com\/en\/development-of-an-own-programming-language-in-javaantlr-interpreter\/\">first<\/a> and <a href=\"https:\/\/intechcore.com\/en\/entwicklung-einer-eigenen-programmiersprache-in-javaantlr-fehlerdiagnose\/\">second<\/a> articles.<\/p>\n<p>In this article, we will learn how to compile our programming language (Jimple) to Java bytecode. We will also compare the execution time of Jimple code interpretation (from the first article) and compiled Jimple to Java bytecode.<\/p>\n<h2>Java Bytecode<\/h2>\n<p>Java bytecode is a set of instructions for the Java Virtual Machine (JVM). Source code written in Java and other JVM-compatible languages is compiled into bytecode. The JVM executes bytecode by converting it to <a href=\"https:\/\/en.wikipedia.org\/wiki\/Native_(computing)\" target=\"_blank\" rel=\"noopener\">machine code<\/a> that is understandable by a specific platform. However, bytecode is not immediately converted to machine code; it is first interpreted by the JVM. If the JVM detects that code is executed frequently (or for <a href=\"https:\/\/www.youtube.com\/watch?v=p7ipmAa9_9E&amp;t=744s\" target=\"_blank\" rel=\"noopener\">other reasons<\/a>), it can compile it to machine code. This approach is called JIT compilation (<a href=\"https:\/\/en.wikipedia.org\/wiki\/Just-in-time_compilation\" target=\"_blank\" rel=\"noopener\">Just-In-Time<\/a>). There are also AOT compilers (<a href=\"https:\/\/en.wikipedia.org\/wiki\/Ahead-of-time_compilation\" target=\"_blank\" rel=\"noopener\">Ahead-Of-Time<\/a>) that allow application developers to compile programs to machine code before execution. This can improve application startup time and reduce memory usage, which is especially useful for microservices and <a href=\"https:\/\/en.wikipedia.org\/wiki\/Serverless_computing\" target=\"_blank\" rel=\"noopener\">serverless applications<\/a>.<\/p>\n<p>Let&#8217;s compile the famous <strong>&#8220;Hello, world!&#8221;<\/strong> program in Java and see what its bytecode looks like. For this, we&#8217;ll create a file <em>HelloWorld.java<\/em> with the following content:<\/p>\n<div style=\"white-space:pre;font-family:Monospace;color:#333333;background-color:#f8f8f8;-moz-tab-size:2;tab-size:2;border:1px solid #E5E5E5;padding:3px;margin: 6px 0 6px 0;font-size:12px;\"><span style=\"color:#ec5f66;\">public<\/span> <span style=\"color:#c695c6;font-style:italic;\">class<\/span> <span style=\"color:#f9ae58;\">HelloWorld<\/span> {<br \/>    <span style=\"color:#ec5f66;\">public<\/span> <span style=\"color:#ec5f66;\">static<\/span> <span style=\"color:#c695c6;font-style:italic;\">void<\/span> <span style=\"color:#5fb4b4;\">main<\/span>(<span style=\"color:#6699cc;font-style:italic;\">String<\/span><span style=\"color:#ec5f66;\">[]<\/span> <span style=\"color:#f9ae58;\">args<\/span>) {<br \/>        <span style=\"color:#6699cc;font-style:italic;\">System<\/span><span style=\"color:#f97b58;\">.<\/span>out<span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">println<\/span>(<span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#80b979;\">Hello, <\/span><span style=\"color:#80b979;\">World!<\/span><span style=\"color:#5fb4b4;\">&#8220;<\/span>)<span style=\"color:#ac7a68;\">;<\/span><br \/>    }<br \/>}<\/div>\n<p>Then execute the following command:<\/p>\n<div style=\"white-space:pre-wrap;font-family:Monospace;color:#333333;background-color:#f8f8f8;-moz-tab-size:2;tab-size:2;border:1px solid #E5E5E5;padding:3px;margin: 6px 0 6px 0;font-size:12px;\"><span style=\"color:#6699cc;\">javac<\/span> <span style=\"color:#80b979;\">HelloWorld.java<\/span><\/div>\n<p>After compilation, a file <em>HelloWorld.class<\/em> containing the bytecode will appear in the current directory. This file is usually smaller than the source code because bytecode is optimized for execution by the Java virtual machine. This file is binary and can be viewed with any <a href=\"https:\/\/en.wikipedia.org\/wiki\/Hex_editor\" target=\"_blank\" rel=\"noopener\">hex editor<\/a>.<\/p>\n<div>\n<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-9983\" src=\"https:\/\/intechcore.com\/wp-content\/uploads\/2025\/10\/hello_world_java_hex.png\" alt=\"Hex-view of HelloWorld.class\" width=\"781\" height=\"545\" srcset=\"https:\/\/intechcore.com\/wp-content\/uploads\/2025\/10\/hello_world_java_hex.png 781w, https:\/\/intechcore.com\/wp-content\/uploads\/2025\/10\/hello_world_java_hex-300x209.png 300w, https:\/\/intechcore.com\/wp-content\/uploads\/2025\/10\/hello_world_java_hex-768x536.png 768w\" sizes=\"auto, (max-width: 781px) 100vw, 781px\" \/>\n<\/div>\n<p>As you can see from the figure, bytecode in this form is difficult for humans to read. For convenient bytecode reading, we can use the special utility <em>javap<\/em>, which is part of the <a href=\"https:\/\/en.wikipedia.org\/wiki\/Java_Development_Kit\" target=\"_blank\" rel=\"noopener\">JDK<\/a>. This utility allows you to view the contents of <em>.class<\/em> files in a readable format. Execute the following command:<\/p>\n<div style=\"white-space:pre-wrap;font-family:Monospace;color:#333333;background-color:#f8f8f8;-moz-tab-size:2;tab-size:2;border:1px solid #E5E5E5;padding:3px;margin: 6px 0 6px 0;font-size:12px;\"><span style=\"color:#6699cc;\">javap<\/span> <span style=\"color:#5fb4b4;\">&#8211;<\/span><span style=\"color:#f9ae58;\">v<\/span> <span style=\"color:#80b979;\">HelloWorld<\/span><\/div>\n<p>The output will be approximately like this:<\/p>\n<div style=\"white-space:pre;font-family:Monospace;color:#333333;background-color:#f8f8f8;-moz-tab-size:2;tab-size:2;border:1px solid #E5E5E5;padding:3px;margin: 6px 0 6px 0;font-size:12px;\"><span style=\"color:#c695c6;\">public<\/span> <span style=\"color:#c695c6;\">class<\/span> HelloWorld<\/p>\n<p>  minor version: 0<br \/>  major version: 52<br \/>  flags: ACC_PUBLIC, ACC_SUPER<br \/>Constant pool:<br \/>   #1 = Methodref          #6.#15         <span style=\"color:#999999;\">\/\/ <\/span><span style=\"color:#999999;\">java<\/span><span style=\"color:#999999;\">\/<\/span><span style=\"color:#999999;\">lang<\/span><span style=\"color:#999999;\">\/<\/span><span style=\"color:#999999;\">Object.&#8221;&lt;init>&#8221;:()V<\/span><br \/>   #2 = Fieldref           #16.#17        <span style=\"color:#999999;\">\/\/ <\/span><span style=\"color:#999999;\">java<\/span><span style=\"color:#999999;\">\/<\/span><span style=\"color:#999999;\">lang<\/span><span style=\"color:#999999;\">\/<\/span><span style=\"color:#999999;\">System.out:Ljava<\/span><span style=\"color:#999999;\">\/<\/span><span style=\"color:#999999;\">io<\/span><span style=\"color:#999999;\">\/<\/span><span style=\"color:#999999;\">PrintStream;<\/span><br \/>   #3 = String             #18            <span style=\"color:#999999;\">\/\/ <\/span><span style=\"color:#999999;\">Hello, <\/span><span style=\"color:#999999;\">World!<\/span><br \/>   #4 = Methodref          #19.#20        <span style=\"color:#999999;\">\/\/ <\/span><span style=\"color:#999999;\">java<\/span><span style=\"color:#999999;\">\/<\/span><span style=\"color:#999999;\">io<\/span><span style=\"color:#999999;\">\/<\/span><span style=\"color:#999999;\">PrintStream.println:(Ljava<\/span><span style=\"color:#999999;\">\/<\/span><span style=\"color:#999999;\">lang<\/span><span style=\"color:#999999;\">\/<\/span><span style=\"color:#999999;\">String;)V<\/span><br \/>   #5 = Class              #21            <span style=\"color:#999999;\">\/\/ <\/span><span style=\"color:#999999;\">HelloWorld<\/span><br \/>   #6 = Class              #22            <span style=\"color:#999999;\">\/\/ <\/span><span style=\"color:#999999;\">java<\/span><span style=\"color:#999999;\">\/<\/span><span style=\"color:#999999;\">lang<\/span><span style=\"color:#999999;\">\/<\/span><span style=\"color:#999999;\">Object<\/span><br \/>   #7 = Utf8               &lt;init><br \/>   #8 = Utf8               ()V<br \/>   #9 = Utf8               Code<br \/>  #10 = Utf8               LineNumberTable<br \/>  #11 = Utf8               main<br \/>  #12 = Utf8               ([<span style=\"color:#6699cc;font-style:italic;\">Ljava<\/span><span style=\"color:#6699cc;font-style:italic;\">\/<\/span><span style=\"color:#6699cc;font-style:italic;\">lang<\/span><span style=\"color:#6699cc;font-style:italic;\">\/<\/span><span style=\"color:#6699cc;font-style:italic;\">String<\/span>;)V<br \/>  #13 = Utf8               SourceFile<br \/>  #14 = Utf8               HelloWorld.java<br \/>  #15 = NameAndType        #<span style=\"color:#999999;\">7:<\/span>#8          <span style=\"color:#999999;\">\/\/ <\/span><span style=\"color:#999999;\">&#8220;&lt;init>&#8221;:()V<\/span><br \/>  #16 = Class              #23            <span style=\"color:#999999;\">\/\/ <\/span><span style=\"color:#999999;\">java<\/span><span style=\"color:#999999;\">\/<\/span><span style=\"color:#999999;\">lang<\/span><span style=\"color:#999999;\">\/<\/span><span style=\"color:#999999;\">System<\/span><br \/>  #17 = NameAndType        #<span style=\"color:#999999;\">24:<\/span>#25        <span style=\"color:#999999;\">\/\/ <\/span><span style=\"color:#999999;\">out:Ljava<\/span><span style=\"color:#999999;\">\/<\/span><span style=\"color:#999999;\">io<\/span><span style=\"color:#999999;\">\/<\/span><span style=\"color:#999999;\">PrintStream;<\/span><br \/>  #18 = Utf8               Hello, World!<br \/>  #19 = Class              #26            <span style=\"color:#999999;\">\/\/ <\/span><span style=\"color:#999999;\">java<\/span><span style=\"color:#999999;\">\/<\/span><span style=\"color:#999999;\">io<\/span><span style=\"color:#999999;\">\/<\/span><span style=\"color:#999999;\">PrintStream<\/span><br \/>  #20 = NameAndType        #<span style=\"color:#999999;\">27:<\/span>#28        <span style=\"color:#999999;\">\/\/ <\/span><span style=\"color:#999999;\">println:(Ljava<\/span><span style=\"color:#999999;\">\/<\/span><span style=\"color:#999999;\">lang<\/span><span style=\"color:#999999;\">\/<\/span><span style=\"color:#999999;\">String;)V<\/span><br \/>  #21 = Utf8               HelloWorld<br \/>  #22 = Utf8               <span style=\"color:#6699cc;font-style:italic;\">java<\/span><span style=\"color:#6699cc;font-style:italic;\">\/<\/span><span style=\"color:#6699cc;font-style:italic;\">lang<\/span><span style=\"color:#6699cc;font-style:italic;\">\/<\/span><span style=\"color:#6699cc;font-style:italic;\">Object<\/span><br \/>  #23 = Utf8               <span style=\"color:#6699cc;font-style:italic;\">java<\/span><span style=\"color:#6699cc;font-style:italic;\">\/<\/span><span style=\"color:#6699cc;font-style:italic;\">lang<\/span><span style=\"color:#6699cc;font-style:italic;\">\/<\/span><span style=\"color:#6699cc;font-style:italic;\">System<\/span><br \/>  #24 = Utf8               out<br \/>  #25 = Utf8               <span style=\"color:#6699cc;font-style:italic;\">Ljava<\/span><span style=\"color:#6699cc;font-style:italic;\">\/<\/span><span style=\"color:#6699cc;font-style:italic;\">io<\/span><span style=\"color:#6699cc;font-style:italic;\">\/<\/span><span style=\"color:#6699cc;font-style:italic;\">PrintStream<\/span>;<br \/>  #26 = Utf8               <span style=\"color:#6699cc;font-style:italic;\">java<\/span><span style=\"color:#6699cc;font-style:italic;\">\/<\/span><span style=\"color:#6699cc;font-style:italic;\">io<\/span><span style=\"color:#6699cc;font-style:italic;\">\/<\/span><span style=\"color:#6699cc;font-style:italic;\">PrintStream<\/span><br \/>  #27 = Utf8               println<br \/>  #28 = Utf8               (<span style=\"color:#6699cc;font-style:italic;\">Ljava<\/span><span style=\"color:#6699cc;font-style:italic;\">\/<\/span><span style=\"color:#6699cc;font-style:italic;\">lang<\/span><span style=\"color:#6699cc;font-style:italic;\">\/<\/span><span style=\"color:#6699cc;font-style:italic;\">String<\/span>;)V<br \/>{<br \/>  <span style=\"color:#c695c6;\">public<\/span> HelloWorld();<br \/>    descriptor: ()V<br \/>    flags: ACC_PUBLIC<br \/>    <span style=\"color:#999999;\">Code:<\/span><br \/>      stack=1, locals=1, args_size=1<br \/>         <span style=\"color:#999999;\">0:<\/span> <span style=\"color:#f9ae58;\">aload_0<\/span><br \/>         <span style=\"color:#999999;\">1:<\/span> <span style=\"color:#5fb4b4;\">invokespecial<\/span> #1                  <span style=\"color:#999999;\">\/\/ <\/span><span style=\"color:#999999;\">Method <\/span><span style=\"color:#999999;\">java<\/span><span style=\"color:#999999;\">\/<\/span><span style=\"color:#999999;\">lang<\/span><span style=\"color:#999999;\">\/<\/span><span style=\"color:#999999;\">Object.&#8221;&lt;init>&#8221;:()V<\/span><br \/>         <span style=\"color:#999999;\">4:<\/span> <span style=\"color:#c695c6;font-style:italic;\">return<\/span><br \/>      LineNumberTable:<br \/>        line <span style=\"color:#999999;\">2:<\/span> 0<\/p>\n<p>  <span style=\"color:#c695c6;\">public<\/span> <span style=\"color:#c695c6;\">static<\/span> <span style=\"color:#c695c6;\">void<\/span> main(java.lang.String[]);<br \/>    descriptor: ([<span style=\"color:#6699cc;font-style:italic;\">Ljava<\/span><span style=\"color:#6699cc;font-style:italic;\">\/<\/span><span style=\"color:#6699cc;font-style:italic;\">lang<\/span><span style=\"color:#6699cc;font-style:italic;\">\/<\/span><span style=\"color:#6699cc;font-style:italic;\">String<\/span>;)V<br \/>    flags: ACC_PUBLIC, ACC_STATIC<br \/>    <span style=\"color:#999999;\">Code:<\/span><br \/>      stack=2, locals=1, args_size=1<br \/>         <span style=\"color:#999999;\">0:<\/span> <span style=\"color:#c695c6;font-style:italic;\">getstatic<\/span>     #2                  <span style=\"color:#999999;\">\/\/ <\/span><span style=\"color:#999999;\">Field <\/span><span style=\"color:#999999;\">java<\/span><span style=\"color:#999999;\">\/<\/span><span style=\"color:#999999;\">lang<\/span><span style=\"color:#999999;\">\/<\/span><span style=\"color:#999999;\">System.out:Ljava<\/span><span style=\"color:#999999;\">\/<\/span><span style=\"color:#999999;\">io<\/span><span style=\"color:#999999;\">\/<\/span><span style=\"color:#999999;\">PrintStream;<\/span><br \/>         <span style=\"color:#999999;\">3:<\/span> <span style=\"color:#c695c6;\">ldc<\/span>           #3                  <span style=\"color:#999999;\">\/\/ <\/span><span style=\"color:#999999;\">String <\/span><span style=\"color:#999999;\">Hello, <\/span><span style=\"color:#999999;\">World!<\/span><br \/>         <span style=\"color:#999999;\">5:<\/span> <span style=\"color:#5fb4b4;\">invokevirtual<\/span> #4                  <span style=\"color:#999999;\">\/\/ <\/span><span style=\"color:#999999;\">Method <\/span><span style=\"color:#999999;\">java<\/span><span style=\"color:#999999;\">\/<\/span><span style=\"color:#999999;\">io<\/span><span style=\"color:#999999;\">\/<\/span><span style=\"color:#999999;\">PrintStream.println:(Ljava<\/span><span style=\"color:#999999;\">\/<\/span><span style=\"color:#999999;\">lang<\/span><span style=\"color:#999999;\">\/<\/span><span style=\"color:#999999;\">String;)V<\/span><br \/>         <span style=\"color:#999999;\">8:<\/span> <span style=\"color:#c695c6;font-style:italic;\">return<\/span><br \/>      LineNumberTable:<br \/>        line <span style=\"color:#999999;\">4:<\/span> 0<br \/>        line <span style=\"color:#999999;\">5:<\/span> 8<br \/>}<\/div>\n<p>Even in this form, the bytecode doesn&#8217;t look very readable, but you can already see the program structure. For example, we see the symbol table, information about methods and used classes. You can also see that the <em>main<\/em> method gets a reference to the standard output stream <em>System.out<\/em>, then calls the <em>println<\/em> method to output the string &#8220;Hello, World!&#8221;. Mnemonics (e.g., <em>getstatic, ldc, invokevirtual<\/em>) are symbolic <a href=\"https:\/\/en.wikipedia.org\/wiki\/List_of_Java_bytecode_instructions\" target=\"_blank\" rel=\"noopener\">representations of bytecode instructions<\/a> executed by the JVM. We won&#8217;t delve deeply into mnemonics, but this is precisely the level of abstraction we&#8217;ll work with when compiling Jimple to bytecode.<\/p>\n<h3>JVM Stack Architecture<\/h3>\n<p>The Java Virtual Machine has a stack-oriented architecture. This means operations are performed on values stored in a <a href=\"https:\/\/en.wikipedia.org\/wiki\/Stack_(abstract_data_type)\" target=\"_blank\" rel=\"noopener\">stack<\/a>. The virtual machine uses the stack to store operands, local variables, and intermediate computation results. For example, when performing addition of two numbers, both numbers are placed on the stack, then the addition operation is executed, which extracts these two numbers from the stack, adds them, and places the result back on the stack.<\/p>\n<p>For example, let&#8217;s compile a method that adds two integers:<\/p>\n<div style=\"white-space:pre;font-family:Monospace;color:#333333;background-color:#f8f8f8;-moz-tab-size:2;tab-size:2;border:1px solid #E5E5E5;padding:3px;margin: 6px 0 6px 0;font-size:12px;\"><span style=\"color:#c695c6;font-style:italic;\">int<\/span> <span style=\"color:#5fb4b4;\">sum<\/span>(<span style=\"color:#c695c6;font-style:italic;\">int<\/span> <span style=\"color:#f9ae58;\">a<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#c695c6;font-style:italic;\">int<\/span> <span style=\"color:#f9ae58;\">b<\/span>) {<br \/>    <span style=\"color:#c695c6;\">return<\/span> a <span style=\"color:#f97b58;\">+<\/span> b<span style=\"color:#ac7a68;\">;<\/span><br \/>}<\/div>\n<p>The bytecode for this method will look as follows:<\/p>\n<div style=\"white-space:pre-wrap;font-family:Monospace;color:#333333;background-color:#f8f8f8;-moz-tab-size:2;tab-size:2;border:1px solid #E5E5E5;padding:3px;margin: 6px 0 6px 0;font-size:12px;\"><span style=\"color:#6699cc;\">iload_1<\/span>   <span style=\"color:#80b979;\">\/\/<\/span> <span style=\"color:#80b979;\">Load<\/span> <span style=\"color:#80b979;\">the<\/span> <span style=\"color:#80b979;\">first<\/span> <span style=\"color:#80b979;\">int<\/span> <span style=\"color:#80b979;\">argument<\/span> <span style=\"color:#80b979;\">onto<\/span> <span style=\"color:#80b979;\">the<\/span> <span style=\"color:#80b979;\">stack<\/span><br \/><span style=\"color:#6699cc;\">iload_2<\/span>   <span style=\"color:#80b979;\">\/\/<\/span> <span style=\"color:#80b979;\">Load<\/span> <span style=\"color:#80b979;\">the<\/span> <span style=\"color:#80b979;\">second<\/span> <span style=\"color:#80b979;\">int<\/span> <span style=\"color:#80b979;\">argument<\/span> <span style=\"color:#80b979;\">onto<\/span> <span style=\"color:#80b979;\">the<\/span> <span style=\"color:#80b979;\">stack<\/span><br \/><span style=\"color:#6699cc;\">iadd<\/span>      <span style=\"color:#80b979;\">\/\/<\/span> <span style=\"color:#80b979;\">Extract<\/span> <span style=\"color:#80b979;\">the<\/span> <span style=\"color:#80b979;\">top<\/span> <span style=\"color:#80b979;\">two<\/span> <span style=\"color:#80b979;\">values<\/span> <span style=\"color:#80b979;\">from<\/span> <span style=\"color:#80b979;\">the<\/span> <span style=\"color:#80b979;\">stack,<\/span> <span style=\"color:#80b979;\">add<\/span> <span style=\"color:#80b979;\">them,<\/span> <span style=\"color:#80b979;\">and<\/span> <span style=\"color:#80b979;\">put<\/span> <span style=\"color:#80b979;\">the<\/span> <span style=\"color:#80b979;\">result<\/span> <span style=\"color:#80b979;\">back<\/span> <span style=\"color:#80b979;\">on<\/span> <span style=\"color:#80b979;\">the<\/span> <span style=\"color:#80b979;\">stack<\/span><br \/><span style=\"color:#6699cc;\">ireturn<\/span>   <span style=\"color:#80b979;\">\/\/<\/span> <span style=\"color:#80b979;\">The<\/span> <span style=\"color:#80b979;\">top<\/span> <span style=\"color:#80b979;\">stack<\/span> <span style=\"color:#80b979;\">value<\/span> <span style=\"color:#80b979;\">is<\/span> <span style=\"color:#80b979;\">extracted<\/span> <span style=\"color:#80b979;\">and<\/span> <span style=\"color:#80b979;\">returned<\/span> <span style=\"color:#80b979;\">to<\/span> <span style=\"color:#80b979;\">the<\/span> <span style=\"color:#80b979;\">calling<\/span> <span style=\"color:#80b979;\">method<\/span><\/div>\n<p>However, a single stack is not sufficient for efficient method execution, so the virtual machine uses the concept of frames. A frame is a data structure that contains all the data necessary for executing a specific method, including local variables, operands, and stack state information. Every time a method or constructor is called, a new frame is created and placed on the call stack. When a method completes, its frame is removed from the call stack. The method&#8217;s return value is placed on the operand stack of the calling method.<\/p>\n<h3>What to Use for Bytecode Generation?<\/h3>\n<p>To compile Jimple to Java bytecode, we&#8217;ll use the time-tested <a href=\"https:\/\/asm.ow2.io\/\" target=\"_blank\" rel=\"noopener\">ASM<\/a> library. It allows working with Java bytecode at a low level and also provides useful tools for validation and analysis of generated code.<\/p>\n<p>An example of generation for the &#8220;Hello, world!&#8221; program using ASM might look like this:<\/p>\n<div style=\"white-space:pre;font-family:Monospace;color:#333333;background-color:#f8f8f8;-moz-tab-size:2;tab-size:2;border:1px solid #E5E5E5;padding:3px;margin: 6px 0 6px 0;font-size:12px;\"><span style=\"color:#6699cc;font-style:italic;\">ClassWriter<\/span> cw <span style=\"color:#f97b58;\">=<\/span> <span style=\"color:#c695c6;\">new<\/span> <span style=\"color:#6699cc;font-style:italic;\">ClassWriter<\/span>(<span style=\"color:#6699cc;font-style:italic;\">ClassWriter<\/span><span style=\"color:#f97b58;\">.<\/span><span style=\"color:#c695c6;\">COMPUTE_FRAMES<\/span> <span style=\"color:#f97b58;\">|<\/span> <span style=\"color:#6699cc;font-style:italic;\">ClassWriter<\/span><span style=\"color:#f97b58;\">.<\/span><span style=\"color:#c695c6;\">COMPUTE_MAXS<\/span>)<span style=\"color:#ac7a68;\">;<\/span><\/p>\n<p>cw<span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">visit<\/span>(<span style=\"color:#c695c6;\">V17<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#c695c6;\">ACC_PUBLIC<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#80b979;\">HelloWorld<\/span><span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#ec5f66;font-style:italic;\">null<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#80b979;\">java<\/span><span style=\"color:#80b979;\">\/<\/span><span style=\"color:#80b979;\">lang<\/span><span style=\"color:#80b979;\">\/<\/span><span style=\"color:#80b979;\">Object<\/span><span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#ec5f66;font-style:italic;\">null<\/span>)<span style=\"color:#ac7a68;\">;<\/span><\/p>\n<p><span style=\"color:#999999;\">\/\/<\/span><span style=\"color:#999999;\"> <\/span><span style=\"color:#999999;\">Generate <\/span><span style=\"color:#999999;\">default <\/span><span style=\"color:#999999;\">constructor<\/span><br \/><span style=\"color:#6699cc;font-style:italic;\">MethodVisitor<\/span> mv <span style=\"color:#f97b58;\">=<\/span> cw<span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">visitMethod<\/span>(<span style=\"color:#c695c6;\">ACC_PUBLIC<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#80b979;\">&lt;<\/span><span style=\"color:#80b979;\">init><\/span><span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#80b979;\">()V<\/span><span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#ec5f66;font-style:italic;\">null<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#ec5f66;font-style:italic;\">null<\/span>)<span style=\"color:#ac7a68;\">;<\/span><br \/>mv<span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">visitCode<\/span>()<span style=\"color:#ac7a68;\">;<\/span><br \/>mv<span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">visitVarInsn<\/span>(<span style=\"color:#c695c6;\">ALOAD<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#f9ae58;\">0<\/span>)<span style=\"color:#ac7a68;\">;<\/span><br \/>mv<span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">visitMethodInsn<\/span>(<span style=\"color:#c695c6;\">INVOKESPECIAL<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#80b979;\">java<\/span><span style=\"color:#80b979;\">\/<\/span><span style=\"color:#80b979;\">lang<\/span><span style=\"color:#80b979;\">\/<\/span><span style=\"color:#80b979;\">Object<\/span><span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#80b979;\">&lt;<\/span><span style=\"color:#80b979;\">init><\/span><span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#80b979;\">()V<\/span><span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#ec5f66;font-style:italic;\">false<\/span>)<span style=\"color:#ac7a68;\">;<\/span><br \/>mv<span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">visitInsn<\/span>(<span style=\"color:#c695c6;\">RETURN<\/span>)<span style=\"color:#ac7a68;\">;<\/span><br \/>mv<span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">visitMaxs<\/span>(<span style=\"color:#f9ae58;\">0<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#f9ae58;\">0<\/span>)<span style=\"color:#ac7a68;\">;<\/span><br \/>mv<span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">visitEnd<\/span>()<span style=\"color:#ac7a68;\">;<\/span><\/p>\n<p><span style=\"color:#999999;\">\/\/<\/span><span style=\"color:#999999;\"> <\/span><span style=\"color:#999999;\">Generate <\/span><span style=\"color:#999999;\">public <\/span><span style=\"color:#999999;\">static <\/span><span style=\"color:#999999;\">void <\/span><span style=\"color:#999999;\">main<\/span><span style=\"color:#999999;\">(<\/span><span style=\"color:#999999;\">String[] <\/span><span style=\"color:#999999;\">args)<\/span><br \/>mv <span style=\"color:#f97b58;\">=<\/span> cw<span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">visitMethod<\/span>(<span style=\"color:#c695c6;\">ACC_PUBLIC<\/span> <span style=\"color:#f97b58;\">+<\/span> <span style=\"color:#c695c6;\">ACC_STATIC<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#80b979;\">main<\/span><span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#80b979;\">([Ljava<\/span><span style=\"color:#80b979;\">\/<\/span><span style=\"color:#80b979;\">lang<\/span><span style=\"color:#80b979;\">\/<\/span><span style=\"color:#80b979;\">String;)V<\/span><span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#ec5f66;font-style:italic;\">null<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#ec5f66;font-style:italic;\">null<\/span>)<span style=\"color:#ac7a68;\">;<\/span><br \/>mv<span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">visitCode<\/span>()<span style=\"color:#ac7a68;\">;<\/span><\/p>\n<p><span style=\"color:#999999;\">\/\/<\/span><span style=\"color:#999999;\"> <\/span><span style=\"color:#999999;\">System.out<\/span><br \/>mv<span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">visitFieldInsn<\/span>(<span style=\"color:#c695c6;\">GETSTATIC<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#80b979;\">java<\/span><span style=\"color:#80b979;\">\/<\/span><span style=\"color:#80b979;\">lang<\/span><span style=\"color:#80b979;\">\/<\/span><span style=\"color:#80b979;\">System<\/span><span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#80b979;\">out<\/span><span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#80b979;\">Ljava<\/span><span style=\"color:#80b979;\">\/<\/span><span style=\"color:#80b979;\">io<\/span><span style=\"color:#80b979;\">\/<\/span><span style=\"color:#80b979;\">PrintStream;<\/span><span style=\"color:#5fb4b4;\">&#8220;<\/span>)<span style=\"color:#ac7a68;\">;<\/span><\/p>\n<p><span style=\"color:#999999;\">\/\/<\/span><span style=\"color:#999999;\"> <\/span><span style=\"color:#999999;\">&#8220;Hello, <\/span><span style=\"color:#999999;\">World!&#8221; <\/span><span style=\"color:#999999;\">string<\/span><br \/>mv<span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">visitLdcInsn<\/span>(<span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#80b979;\">Hello, <\/span><span style=\"color:#80b979;\">World!<\/span><span style=\"color:#5fb4b4;\">&#8220;<\/span>)<span style=\"color:#ac7a68;\">;<\/span><\/p>\n<p><span style=\"color:#999999;\">\/\/<\/span><span style=\"color:#999999;\"> <\/span><span style=\"color:#999999;\">println <\/span><span style=\"color:#999999;\">call<\/span><br \/>mv<span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">visitMethodInsn<\/span>(<span style=\"color:#c695c6;\">INVOKEVIRTUAL<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#80b979;\">java<\/span><span style=\"color:#80b979;\">\/<\/span><span style=\"color:#80b979;\">io<\/span><span style=\"color:#80b979;\">\/<\/span><span style=\"color:#80b979;\">PrintStream<\/span><span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#80b979;\">println<\/span><span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#80b979;\">(<\/span><span style=\"color:#80b979;\">Ljava<\/span><span style=\"color:#80b979;\">\/<\/span><span style=\"color:#80b979;\">lang<\/span><span style=\"color:#80b979;\">\/<\/span><span style=\"color:#80b979;\">String;)V<\/span><span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#ec5f66;font-style:italic;\">false<\/span>)<span style=\"color:#ac7a68;\">;<\/span><\/p>\n<p>mv<span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">visitInsn<\/span>(<span style=\"color:#c695c6;\">RETURN<\/span>)<span style=\"color:#ac7a68;\">;<\/span><br \/>mv<span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">visitEnd<\/span>()<span style=\"color:#ac7a68;\">;<\/span><\/p>\n<p>cw<span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">visitEnd<\/span>()<span style=\"color:#ac7a68;\">;<\/span><\/p>\n<p><span style=\"color:#999999;\">\/\/<\/span><span style=\"color:#999999;\"> <\/span><span style=\"color:#999999;\">Write <\/span><span style=\"color:#999999;\">the <\/span><span style=\"color:#999999;\">generated <\/span><span style=\"color:#999999;\">class <\/span><span style=\"color:#999999;\">to <\/span><span style=\"color:#999999;\">a <\/span><span style=\"color:#999999;\">file<\/span><br \/><span style=\"color:#c695c6;\">try<\/span> (<span style=\"color:#6699cc;font-style:italic;\">FileOutputStream<\/span> fos <span style=\"color:#f97b58;\">=<\/span> <span style=\"color:#c695c6;\">new<\/span> <span style=\"color:#6699cc;font-style:italic;\">FileOutputStream<\/span>(<span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#80b979;\">HelloWorld.class<\/span><span style=\"color:#5fb4b4;\">&#8220;<\/span>)) {<br \/>    fos<span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">write<\/span>(cw<span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">toByteArray<\/span>())<span style=\"color:#ac7a68;\">;<\/span><br \/>}<\/div>\n<p>Starting with JDK 24, you can parse, generate, and transform class files without third-party libraries, as a built-in API has been added that simplifies these operations (<a href=\"https:\/\/openjdk.org\/jeps\/484\" target=\"_blank\" rel=\"noopener\">JEP 484: Class-File API<\/a>).<\/p>\n<p>There&#8217;s another way to generate bytecode from a new language &#8211; first convert Jimple to another language (e.g., Java or Kotlin), then compile it using a standard compiler (e.g., <em>javac<\/em> for Java). This type of compilation is called <a href=\"https:\/\/martinfowler.com\/bliki\/TransparentCompilation.html\" target=\"_blank\" rel=\"noopener\">transpilation<\/a>.<\/p>\n<h3>JimpleBaseVisitor Again<\/h3>\n<p>To compile Jimple to Java bytecode, we&#8217;ll use the already familiar (from the previous two articles) abstract class <em>JimpleBaseVisitor<\/em> (generated by ANTLR). It allows traversing the AST tree (<a href=\"https:\/\/en.wikipedia.org\/wiki\/Abstract_syntax_tree\" target=\"_blank\" rel=\"noopener\">Abstract Syntax Tree<\/a>) and performing actions on each tree node. We&#8217;ll override methods for each node type to generate corresponding bytecode.<\/p>\n<p>We&#8217;ll create a new class <em>JimpleCompilerVisitor<\/em> that inherits from <em>JimpleBaseVisitor<\/em> and implements methods for bytecode generation. It&#8217;s known that each method of this class must return a value of a specific type. In our case, we&#8217;ll return information about the node type in the tree &#8211; <em>CompilationInfo<\/em>.<\/p>\n<p>Why do we need type information? Many bytecode instructions depend on operand types, so we need to know what data type we&#8217;re processing at the moment. For example, if we&#8217;re processing an integer, we should use instructions for working with integers. Many instructions have prefixes and\/or suffixes indicating the operand types they work with. These include the following:<\/p>\n<table class=\"t1\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"td1\" valign=\"top\">\n<p class=\"p1\"><b>Suffix\/Prefix<span class=\"Apple-converted-space\">\u00a0<\/span><\/b><\/p>\n<\/td>\n<td class=\"td1\" valign=\"top\">\n<p class=\"p1\"><b>Operand Type<span class=\"Apple-converted-space\">\u00a0<\/span><\/b><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td class=\"td1\" valign=\"top\">\n<p class=\"p1\">i<span class=\"Apple-converted-space\">\u00a0<\/span><\/p>\n<\/td>\n<td class=\"td1\" valign=\"top\">\n<p class=\"p1\">integer<span class=\"Apple-converted-space\">\u00a0<\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td class=\"td1\" valign=\"top\">\n<p class=\"p1\">l<span class=\"Apple-converted-space\">\u00a0<\/span><\/p>\n<\/td>\n<td class=\"td1\" valign=\"top\">\n<p class=\"p1\">long<span class=\"Apple-converted-space\">\u00a0<\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td class=\"td1\" valign=\"top\">\n<p class=\"p1\">s<span class=\"Apple-converted-space\">\u00a0<\/span><\/p>\n<\/td>\n<td class=\"td1\" valign=\"top\">\n<p class=\"p1\">short<span class=\"Apple-converted-space\">\u00a0<\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td class=\"td1\" valign=\"top\">\n<p class=\"p1\">b<span class=\"Apple-converted-space\">\u00a0<\/span><\/p>\n<\/td>\n<td class=\"td1\" valign=\"top\">\n<p class=\"p1\">byte<span class=\"Apple-converted-space\">\u00a0<\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td class=\"td1\" valign=\"top\">\n<p class=\"p1\">c<span class=\"Apple-converted-space\">\u00a0<\/span><\/p>\n<\/td>\n<td class=\"td1\" valign=\"top\">\n<p class=\"p1\">character<span class=\"Apple-converted-space\">\u00a0<\/span><\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<p>Another type-related problem is that in Jimple we don&#8217;t use explicit types for function parameters and return values. When I wrote the Jimple interpreter (first article), I identified types during runtime. This was quite easy to implement and the language itself looks simpler. But in a compiler, we must know types in advance to generate correct bytecode (or always return Object). Therefore, we&#8217;ll have to compute the function&#8217;s return value type based on its body. To identify the type of any expression, a <em>getExpressionType<\/em> method was written with one parameter of type <em>ExpressionContext<\/em> (base class of all expressions).<\/p>\n<h3>Compiler Implementation<\/h3>\n<p>Since the root rule of our grammar is the <em>program<\/em> rule (see <em>Jimple.g4<\/em> file), code compilation starts with it. For this, we call the <em>visitProgram<\/em> method on the <em>JimpleCompilerVisitor<\/em> object, passing it an object of class <em>ProgramContext<\/em>. After calling this method, all AST nodes will be processed, and we can get the generated bytecode using the <em>getBytecode<\/em> method. The bytecode, which is an array of bytes, can be written to a file and run using the JVM.<\/p>\n<div style=\"white-space:pre;font-family:Monospace;color:#333333;background-color:#f8f8f8;-moz-tab-size:2;tab-size:2;border:1px solid #E5E5E5;padding:3px;margin: 6px 0 6px 0;font-size:12px;\"><span style=\"color:#6699cc;font-style:italic;\">JimpleCompilerVisitor<\/span> visitor <span style=\"color:#f97b58;\">=<\/span> <span style=\"color:#c695c6;\">new<\/span> <span style=\"color:#6699cc;font-style:italic;\">JimpleCompilerVisitor<\/span>()<span style=\"color:#ac7a68;\">;<\/span><br \/>visitor<span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">visitProgram<\/span>(parser<span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">program<\/span>())<span style=\"color:#ac7a68;\">;<\/span><br \/><span style=\"color:#c695c6;font-style:italic;\">byte<\/span><span style=\"color:#ec5f66;\">[]<\/span> bytecode <span style=\"color:#f97b58;\">=<\/span> visitor<span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">getBytecode<\/span>()<span style=\"color:#ac7a68;\">;<\/span><\/div>\n<p>In the <em>visitProgram<\/em> method, the main <em>ClassWriter<\/em> class is created, which will be used for bytecode generation. In this method, we also create a constructor and <em>main<\/em> method. Methods in ASM are created by calling <em>visitMethod<\/em>, which returns an object of type <em>MethodVisitor<\/em>. Using this class, we can generate bytecode for each method. The <em>visitMethod<\/em> method takes parameters: access attributes (e.g., <em>ACC_PUBLIC<\/em>), method name, its descriptor, and others.<\/p>\n<p>The method descriptor deserves special attention: it defines the parameter types that the method accepts and what type the method returns. Descriptors in the JVM are encoded in a special way. For example, for the main method it looks like &#8220;(<em>[Ljava\/lang\/String;)V&#8221;<\/em>, which can be deciphered as the method takes one argument of type string array &#8211; [<em>Ljava\/lang\/String<\/em>; and returns <em>void &#8211; V<\/em>. A description of descriptors can be found in the <a href=\"https:\/\/docs.oracle.com\/javase\/specs\/jvms\/se21\/html\/jvms-4.html#jvms-4.3\" target=\"_blank\" rel=\"noopener\">JVM specification<\/a>.<\/p>\n<p>Since there can be multiple methods calling each other (and even themselves), we use a stack to store all methods, where the &#8220;head&#8221; of the stack stores the current method. Therefore, to start traversing the entire tree, we need to put the <em>MethodVisitor<\/em> (of the <em>main<\/em> method) on the stack and call the parent implementation <em>visitProgram<\/em> (<em>super.visitProgram(ctx)<\/em>). At the end of the <em>visitProgram<\/em> method, we can get the generated bytecode using the <em>toByteArray<\/em> method on the <em>ClassWriter<\/em> object.<\/p>\n<div style=\"white-space:pre;font-family:Monospace;color:#333333;background-color:#f8f8f8;-moz-tab-size:2;tab-size:2;border:1px solid #E5E5E5;padding:3px;margin: 6px 0 6px 0;font-size:12px;\"><span style=\"color:#ec5f66;\">public<\/span> <span style=\"color:#6699cc;font-style:italic;\">CompilationInfo<\/span> <span style=\"color:#5fb4b4;\">visitProgram<\/span>(<span style=\"color:#6699cc;font-style:italic;\">JimpleParser<\/span><span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;font-style:italic;\">ProgramContext<\/span> <span style=\"color:#f9ae58;\">ctx<\/span>) {<br \/>    <span style=\"color:#6699cc;font-style:italic;\">ClassWriter<\/span> cw <span style=\"color:#f97b58;\">=<\/span> <span style=\"color:#c695c6;\">new<\/span> <span style=\"color:#6699cc;font-style:italic;\">ClassWriter<\/span>(<span style=\"color:#6699cc;font-style:italic;\">ClassWriter<\/span><span style=\"color:#f97b58;\">.<\/span><span style=\"color:#c695c6;\">COMPUTE_MAXS<\/span> <span style=\"color:#f97b58;\">|<\/span> <span style=\"color:#6699cc;font-style:italic;\">ClassWriter<\/span><span style=\"color:#f97b58;\">.<\/span><span style=\"color:#c695c6;\">COMPUTE_FRAMES<\/span>)<span style=\"color:#ac7a68;\">;<\/span><\/p>\n<p>    <span style=\"color:#999999;\">\/\/<\/span><span style=\"color:#999999;\"> <\/span><span style=\"color:#999999;\">create <\/span><span style=\"color:#999999;\">the <\/span><span style=\"color:#999999;\">class <\/span><span style=\"color:#999999;\">with <\/span><span style=\"color:#999999;\">name <\/span><span style=\"color:#999999;\">&#8220;JimpleAutoGenApp&#8221;<\/span><br \/>    cw<span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">visit<\/span>(<span style=\"color:#6699cc;font-style:italic;\">Opcodes<\/span><span style=\"color:#f97b58;\">.<\/span><span style=\"color:#c695c6;\">V1_8<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#6699cc;font-style:italic;\">Opcodes<\/span><span style=\"color:#f97b58;\">.<\/span><span style=\"color:#c695c6;\">ACC_PUBLIC<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#80b979;\">JimpleAutoGenApp<\/span><span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#ec5f66;font-style:italic;\">null<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#80b979;\">java<\/span><span style=\"color:#80b979;\">\/<\/span><span style=\"color:#80b979;\">lang<\/span><span style=\"color:#80b979;\">\/<\/span><span style=\"color:#80b979;\">Object<\/span><span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#ec5f66;font-style:italic;\">null<\/span>)<span style=\"color:#ac7a68;\">;<\/span><\/p>\n<p>    <span style=\"color:#999999;\">\/\/<\/span><span style=\"color:#999999;\"> <\/span><span style=\"color:#999999;\">Define <\/span><span style=\"color:#999999;\">a <\/span><span style=\"color:#999999;\">constructor<\/span><br \/>    <span style=\"color:#6699cc;font-style:italic;\">MethodVisitor<\/span> constructor <span style=\"color:#f97b58;\">=<\/span> cw<span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">visitMethod<\/span>(<span style=\"color:#6699cc;font-style:italic;\">Opcodes<\/span><span style=\"color:#f97b58;\">.<\/span><span style=\"color:#c695c6;\">ACC_PUBLIC<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#80b979;\">&lt;<\/span><span style=\"color:#80b979;\">init><\/span><span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#80b979;\">()V<\/span><span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#ec5f66;font-style:italic;\">null<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#ec5f66;font-style:italic;\">null<\/span>)<span style=\"color:#ac7a68;\">;<\/span><br \/>    constructor<span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">visitCode<\/span>()<span style=\"color:#ac7a68;\">;<\/span><br \/>    constructor<span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">visitVarInsn<\/span>(<span style=\"color:#6699cc;font-style:italic;\">Opcodes<\/span><span style=\"color:#f97b58;\">.<\/span><span style=\"color:#c695c6;\">ALOAD<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#f9ae58;\">0<\/span>)<span style=\"color:#ac7a68;\">;<\/span><br \/>    constructor<span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">visitMethodInsn<\/span>(<span style=\"color:#6699cc;font-style:italic;\">Opcodes<\/span><span style=\"color:#f97b58;\">.<\/span><span style=\"color:#c695c6;\">INVOKESPECIAL<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#80b979;\">java<\/span><span style=\"color:#80b979;\">\/<\/span><span style=\"color:#80b979;\">lang<\/span><span style=\"color:#80b979;\">\/<\/span><span style=\"color:#80b979;\">Object<\/span><span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#80b979;\">&lt;<\/span><span style=\"color:#80b979;\">init><\/span><span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#80b979;\">()V<\/span><span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#ec5f66;font-style:italic;\">false<\/span>)<span style=\"color:#ac7a68;\">;<\/span><br \/>    constructor<span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">visitInsn<\/span>(<span style=\"color:#6699cc;font-style:italic;\">Opcodes<\/span><span style=\"color:#f97b58;\">.<\/span><span style=\"color:#c695c6;\">RETURN<\/span>)<span style=\"color:#ac7a68;\">;<\/span><br \/>    constructor<span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">visitEnd<\/span>()<span style=\"color:#ac7a68;\">;<\/span><\/p>\n<p>    <span style=\"color:#999999;\">\/\/<\/span><span style=\"color:#999999;\"> <\/span><span style=\"color:#999999;\">Create <\/span><span style=\"color:#999999;\">the <\/span><span style=\"color:#999999;\">main <\/span><span style=\"color:#999999;\">method<\/span><br \/>    <span style=\"color:#6699cc;font-style:italic;\">MethodVisitor<\/span> mainMethod <span style=\"color:#f97b58;\">=<\/span> cw<span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">visitMethod<\/span>(<span style=\"color:#6699cc;font-style:italic;\">Opcodes<\/span><span style=\"color:#f97b58;\">.<\/span><span style=\"color:#c695c6;\">ACC_PUBLIC<\/span> <span style=\"color:#f97b58;\">+<\/span> <span style=\"color:#6699cc;font-style:italic;\">Opcodes<\/span><span style=\"color:#f97b58;\">.<\/span><span style=\"color:#c695c6;\">ACC_STATIC<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#80b979;\">main<\/span><span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#80b979;\">([Ljava<\/span><span style=\"color:#80b979;\">\/<\/span><span style=\"color:#80b979;\">lang<\/span><span style=\"color:#80b979;\">\/<\/span><span style=\"color:#80b979;\">String;)V<\/span><span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#ec5f66;font-style:italic;\">null<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#ec5f66;font-style:italic;\">null<\/span>)<span style=\"color:#ac7a68;\">;<\/span><br \/>    mainMethod<span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">visitCode<\/span>()<span style=\"color:#ac7a68;\">;<\/span><\/p>\n<p>    <span style=\"color:#999999;\">\/\/<\/span><span style=\"color:#999999;\"> <\/span><span style=\"color:#999999;\">set <\/span><span style=\"color:#999999;\">mainMethod <\/span><span style=\"color:#999999;\">as <\/span><span style=\"color:#999999;\">current <\/span><span style=\"color:#999999;\">(<\/span><span style=\"color:#999999;\">put <\/span><span style=\"color:#999999;\">on <\/span><span style=\"color:#999999;\">the <\/span><span style=\"color:#999999;\">top)<\/span><br \/>    methods<span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">push<\/span>(mainMethod)<span style=\"color:#ac7a68;\">;<\/span>    <br \/>    <span style=\"color:#ec5f66;font-style:italic;\">super<\/span><span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">visitProgram<\/span>(ctx)<span style=\"color:#ac7a68;\">;<\/span><br \/>    methods<span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">pop<\/span>()<span style=\"color:#ac7a68;\">;<\/span><\/p>\n<p>    mainMethod<span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">visitInsn<\/span>(<span style=\"color:#6699cc;font-style:italic;\">Opcodes<\/span><span style=\"color:#f97b58;\">.<\/span><span style=\"color:#c695c6;\">RETURN<\/span>)<span style=\"color:#ac7a68;\">;<\/span><br \/>    mainMethod<span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">visitEnd<\/span>()<span style=\"color:#ac7a68;\">;<\/span><\/p>\n<p>    cw<span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">visitEnd<\/span>()<span style=\"color:#ac7a68;\">;<\/span><br \/>    <span style=\"color:#ec5f66;font-style:italic;\">this<\/span><span style=\"color:#f97b58;\">.<\/span>bytecode <span style=\"color:#f97b58;\">=<\/span> cw<span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">toByteArray<\/span>()<span style=\"color:#ac7a68;\">;<\/span><\/p>\n<p>    <span style=\"color:#c695c6;\">return<\/span> <span style=\"color:#c695c6;\">VOID<\/span><span style=\"color:#ac7a68;\">;<\/span><br \/>}<\/div>\n<p>To ultimately get bytecode, we need to implement all necessary <em>visitXxx<\/em> methods. They will generate corresponding bytecode for each language construct. Let&#8217;s consider a simple case when a string is encountered in the program text. In this case, we need to generate an <em>ldc &lt;index&gt;<\/em> instruction, where index is the index from the constant pool of the current class. Where do we get it? In ASM library, this is done automatically using the <em>visitLdcInsn<\/em> method. You can pass a string, number, type, etc. as a parameter to this method. In our case, we pass a string. After calling this method, the string will be placed in the class constant pool, and an <em>ldc<\/em> instruction with the corresponding index will be added to the bytecode. At the end of the method, we return information about the node type &#8211; <em>CompilationInfo.STRING<\/em>. For other types, similar methods need to be implemented.<\/p>\n<div style=\"white-space:pre;font-family:Monospace;color:#333333;background-color:#f8f8f8;-moz-tab-size:2;tab-size:2;border:1px solid #E5E5E5;padding:3px;margin: 6px 0 6px 0;font-size:12px;\"><span style=\"color:#5fb4b4;\">@<\/span><span style=\"color:#6699cc;\">Override<\/span><br \/><span style=\"color:#ec5f66;\">public<\/span> <span style=\"color:#6699cc;font-style:italic;\">CompilationInfo<\/span> <span style=\"color:#5fb4b4;\">visitStringExpr<\/span>(<span style=\"color:#6699cc;font-style:italic;\">JimpleParser<\/span><span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;font-style:italic;\">StringExprContext<\/span> <span style=\"color:#f9ae58;\">ctx<\/span>) {<br \/>    <span style=\"color:#6699cc;font-style:italic;\">String<\/span> value <span style=\"color:#f97b58;\">=<\/span> <span style=\"color:#6699cc;font-style:italic;\">StringUtil<\/span><span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">cleanStringLiteral<\/span>(ctx<span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;font-style:italic;\">STRING_LITERAL<\/span>()<span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">getText<\/span>())<span style=\"color:#ac7a68;\">;<\/span><br \/>    <span style=\"color:#6699cc;\">getCurrentMethod<\/span>()<span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">visitLdcInsn<\/span>(value)<span style=\"color:#ac7a68;\">;<\/span><br \/>    <span style=\"color:#c695c6;\">return<\/span> <span style=\"color:#6699cc;font-style:italic;\">CompilationInfo<\/span><span style=\"color:#f97b58;\">.<\/span><span style=\"color:#c695c6;\">STRING<\/span><span style=\"color:#ac7a68;\">;<\/span><br \/>}<\/div>\n<p>A more complex case is arithmetic operations. For example, consider the addition operation. In Jimple, it might look like: <em>a + b<\/em>, where <em>a<\/em> and <em>b<\/em> can be variables or constants. In this case, we need to generate instructions for loading values <em>a<\/em> and <em>b<\/em> onto the stack, then an instruction for adding these values. For this, we call the <em>getExpressionType<\/em> method for each operand to get their types. Then, depending on the operand types, we generate the corresponding addition instruction. For example, if both operands are of type <em>long<\/em>, we generate the <em>ladd<\/em> instruction. If one of the operands is of type <em>double<\/em>, we generate the <em>dadd<\/em> instruction.<\/p>\n<p>We also need to consider the case when one of the operands is a string. In this case, the + operation should be interpreted as string concatenation. For this, we use the <em>StringBuilder<\/em> class to assemble the resulting string.<\/p>\n<p>Another important point is type casting. Java has implicit and explicit type casting. In our compiler, we implement implicit type casting to simplify language usage. For example, if one operand is of type <em>long<\/em> and the other is of type <em>double<\/em>, we automatically cast <em>long<\/em> to <em>double<\/em>. For this, we use the <em>convertAfterFirstArg<\/em> and <em>convertAfterSecondArg<\/em> methods, which generate corresponding type casting instructions. The method itself returns information about the resulting type of this expression.<\/p>\n<div style=\"white-space:pre;font-family:Monospace;color:#333333;background-color:#f8f8f8;-moz-tab-size:2;tab-size:2;border:1px solid #E5E5E5;padding:3px;margin: 6px 0 6px 0;font-size:12px;\"><span style=\"color:#ec5f66;\">public<\/span> <span style=\"color:#6699cc;font-style:italic;\">CompilationInfo<\/span> <span style=\"color:#5fb4b4;\">visitPlusMinusExpr<\/span>(<span style=\"color:#6699cc;font-style:italic;\">JimpleParser<\/span><span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;font-style:italic;\">PlusMinusExprContext<\/span> <span style=\"color:#f9ae58;\">ctx<\/span>) {<br \/>    <span style=\"color:#6699cc;font-style:italic;\">MethodVisitor<\/span> method <span style=\"color:#f97b58;\">=<\/span> <span style=\"color:#6699cc;\">getCurrentMethod<\/span>()<span style=\"color:#ac7a68;\">;<\/span><br \/>    <span style=\"color:#c695c6;font-style:italic;\">int<\/span> typeLeft <span style=\"color:#f97b58;\">=<\/span> <span style=\"color:#6699cc;\">getExpressionType<\/span>(ctx<span style=\"color:#f97b58;\">.<\/span>left)<span style=\"color:#ac7a68;\">;<\/span><br \/>    <span style=\"color:#c695c6;font-style:italic;\">int<\/span> typeRight <span style=\"color:#f97b58;\">=<\/span> <span style=\"color:#6699cc;\">getExpressionType<\/span>(ctx<span style=\"color:#f97b58;\">.<\/span>right)<span style=\"color:#ac7a68;\">;<\/span><\/p>\n<p>    <span style=\"color:#999999;\">\/\/<\/span><span style=\"color:#999999;\"> <\/span><span style=\"color:#999999;\">check <\/span><span style=\"color:#999999;\">if <\/span><span style=\"color:#999999;\">plus <\/span><span style=\"color:#999999;\">is <\/span><span style=\"color:#999999;\">string <\/span><span style=\"color:#999999;\">concat <\/span><span style=\"color:#999999;\">operator<\/span><br \/>    <span style=\"color:#c695c6;\">if<\/span> (ctx<span style=\"color:#f97b58;\">.<\/span>op<span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">getType<\/span>() <span style=\"color:#f97b58;\">==<\/span> <span style=\"color:#6699cc;font-style:italic;\">JimpleParser<\/span><span style=\"color:#f97b58;\">.<\/span><span style=\"color:#c695c6;\">PLUS<\/span> <span style=\"color:#f97b58;\">&amp;&amp;<\/span> (<span style=\"color:#6699cc;\">isStaticString<\/span>(typeLeft) <span style=\"color:#f97b58;\">||<\/span> <span style=\"color:#6699cc;\">isStaticString<\/span>(typeRight))) {<br \/>        method<span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">visitTypeInsn<\/span>(<span style=\"color:#c695c6;\">NEW<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#80b979;\">java<\/span><span style=\"color:#80b979;\">\/<\/span><span style=\"color:#80b979;\">lang<\/span><span style=\"color:#80b979;\">\/<\/span><span style=\"color:#80b979;\">StringBuilder<\/span><span style=\"color:#5fb4b4;\">&#8220;<\/span>)<span style=\"color:#ac7a68;\">;<\/span><br \/>        method<span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">visitInsn<\/span>(<span style=\"color:#c695c6;\">DUP<\/span>)<span style=\"color:#ac7a68;\">;<\/span><br \/>        method<span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">visitMethodInsn<\/span>(<span style=\"color:#c695c6;\">INVOKESPECIAL<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#80b979;\">java<\/span><span style=\"color:#80b979;\">\/<\/span><span style=\"color:#80b979;\">lang<\/span><span style=\"color:#80b979;\">\/<\/span><span style=\"color:#80b979;\">StringBuilder<\/span><span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#80b979;\">&lt;<\/span><span style=\"color:#80b979;\">init><\/span><span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#80b979;\">()V<\/span><span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#ec5f66;font-style:italic;\">false<\/span>)<span style=\"color:#ac7a68;\">;<\/span><br \/>        <span style=\"color:#6699cc;font-style:italic;\">CompilationInfo<\/span> left <span style=\"color:#f97b58;\">=<\/span> <span style=\"color:#6699cc;\">visit<\/span>(ctx<span style=\"color:#f97b58;\">.<\/span>left)<span style=\"color:#ac7a68;\">;<\/span><br \/>        <span style=\"color:#6699cc;font-style:italic;\">String<\/span> typeDescrLeft <span style=\"color:#f97b58;\">=<\/span> <span style=\"color:#6699cc;\">makeFuncDescriptor<\/span>(left<span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#80b979;\">Ljava<\/span><span style=\"color:#80b979;\">\/<\/span><span style=\"color:#80b979;\">lang<\/span><span style=\"color:#80b979;\">\/<\/span><span style=\"color:#80b979;\">StringBuilder;<\/span><span style=\"color:#5fb4b4;\">&#8220;<\/span>)<span style=\"color:#ac7a68;\">;<\/span><br \/>        method<span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">visitMethodInsn<\/span>(<span style=\"color:#c695c6;\">INVOKEVIRTUAL<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#80b979;\">java<\/span><span style=\"color:#80b979;\">\/<\/span><span style=\"color:#80b979;\">lang<\/span><span style=\"color:#80b979;\">\/<\/span><span style=\"color:#80b979;\">StringBuilder<\/span><span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#80b979;\">append<\/span><span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#ac7a68;\">,<\/span> typeDescrLeft<span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#ec5f66;font-style:italic;\">false<\/span>)<span style=\"color:#ac7a68;\">;<\/span><br \/>        <span style=\"color:#6699cc;font-style:italic;\">CompilationInfo<\/span> right <span style=\"color:#f97b58;\">=<\/span> <span style=\"color:#6699cc;\">visit<\/span>(ctx<span style=\"color:#f97b58;\">.<\/span>right)<span style=\"color:#ac7a68;\">;<\/span><br \/>        <span style=\"color:#6699cc;font-style:italic;\">String<\/span> typeDescrRight <span style=\"color:#f97b58;\">=<\/span> <span style=\"color:#6699cc;\">makeFuncDescriptor<\/span>(right<span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#80b979;\">Ljava<\/span><span style=\"color:#80b979;\">\/<\/span><span style=\"color:#80b979;\">lang<\/span><span style=\"color:#80b979;\">\/<\/span><span style=\"color:#80b979;\">StringBuilder;<\/span><span style=\"color:#5fb4b4;\">&#8220;<\/span>)<span style=\"color:#ac7a68;\">;<\/span><br \/>        method<span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">visitMethodInsn<\/span>(<span style=\"color:#c695c6;\">INVOKEVIRTUAL<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#80b979;\">java<\/span><span style=\"color:#80b979;\">\/<\/span><span style=\"color:#80b979;\">lang<\/span><span style=\"color:#80b979;\">\/<\/span><span style=\"color:#80b979;\">StringBuilder<\/span><span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#80b979;\">append<\/span><span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#ac7a68;\">,<\/span> typeDescrRight<span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#ec5f66;font-style:italic;\">false<\/span>)<span style=\"color:#ac7a68;\">;<\/span><br \/>        method<span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">visitMethodInsn<\/span>(<span style=\"color:#c695c6;\">INVOKEVIRTUAL<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#80b979;\">java<\/span><span style=\"color:#80b979;\">\/<\/span><span style=\"color:#80b979;\">lang<\/span><span style=\"color:#80b979;\">\/<\/span><span style=\"color:#80b979;\">StringBuilder<\/span><span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#80b979;\">toString<\/span><span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#80b979;\">()Ljava<\/span><span style=\"color:#80b979;\">\/<\/span><span style=\"color:#80b979;\">lang<\/span><span style=\"color:#80b979;\">\/<\/span><span style=\"color:#80b979;\">String;<\/span><span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#ec5f66;font-style:italic;\">false<\/span>)<span style=\"color:#ac7a68;\">;<\/span><br \/>        <span style=\"color:#c695c6;\">return<\/span> <span style=\"color:#6699cc;font-style:italic;\">CompilationInfo<\/span><span style=\"color:#f97b58;\">.<\/span><span style=\"color:#c695c6;\">STRING<\/span><span style=\"color:#ac7a68;\">;<\/span><br \/>    }<\/p>\n<p>    <span style=\"color:#c695c6;font-style:italic;\">int<\/span> commonType <span style=\"color:#f97b58;\">=<\/span> <span style=\"color:#6699cc;\">commonType<\/span>(typeLeft<span style=\"color:#ac7a68;\">,<\/span> typeRight)<span style=\"color:#ac7a68;\">;<\/span><br \/>    <span style=\"color:#c695c6;\">switch<\/span> (ctx<span style=\"color:#f97b58;\">.<\/span>op<span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">getType<\/span>()) {<br \/>        <span style=\"color:#c695c6;\">case<\/span> <span style=\"color:#6699cc;font-style:italic;\">JimpleParser<\/span><span style=\"color:#f97b58;\">.<\/span><span style=\"color:#c695c6;\">PLUS<\/span><span style=\"color:#ac7a68;\">:<\/span><br \/>            <span style=\"color:#6699cc;\">visit<\/span>(ctx<span style=\"color:#f97b58;\">.<\/span>left)<span style=\"color:#ac7a68;\">;<\/span><br \/>            <span style=\"color:#6699cc;\">convertAfterFirstArg<\/span>(typeLeft<span style=\"color:#ac7a68;\">,<\/span> typeRight)<span style=\"color:#ac7a68;\">;<\/span><br \/>            <span style=\"color:#6699cc;\">visit<\/span>(ctx<span style=\"color:#f97b58;\">.<\/span>right)<span style=\"color:#ac7a68;\">;<\/span><br \/>            <span style=\"color:#6699cc;\">convertAfterSecondArg<\/span>(typeLeft<span style=\"color:#ac7a68;\">,<\/span> typeRight)<span style=\"color:#ac7a68;\">;<\/span><br \/>            method<span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">visitInsn<\/span>(<span style=\"color:#6699cc;\">getAddOpcode<\/span>(commonType))<span style=\"color:#ac7a68;\">;<\/span><br \/>            <span style=\"color:#c695c6;\">return<\/span> <span style=\"color:#c695c6;\">new<\/span> <span style=\"color:#6699cc;font-style:italic;\">CompilationInfo<\/span>(commonType)<span style=\"color:#ac7a68;\">;<\/span><br \/>        <span style=\"color:#c695c6;\">case<\/span> <span style=\"color:#6699cc;font-style:italic;\">JimpleParser<\/span><span style=\"color:#f97b58;\">.<\/span><span style=\"color:#c695c6;\">MINUS<\/span><span style=\"color:#ac7a68;\">:<\/span><br \/>            <span style=\"color:#6699cc;\">visit<\/span>(ctx<span style=\"color:#f97b58;\">.<\/span>left)<span style=\"color:#ac7a68;\">;<\/span><br \/>            <span style=\"color:#6699cc;\">convertAfterFirstArg<\/span>(typeLeft<span style=\"color:#ac7a68;\">,<\/span> typeRight)<span style=\"color:#ac7a68;\">;<\/span><br \/>            <span style=\"color:#6699cc;\">visit<\/span>(ctx<span style=\"color:#f97b58;\">.<\/span>right)<span style=\"color:#ac7a68;\">;<\/span><br \/>            <span style=\"color:#6699cc;\">convertAfterSecondArg<\/span>(typeLeft<span style=\"color:#ac7a68;\">,<\/span> typeRight)<span style=\"color:#ac7a68;\">;<\/span><br \/>            method<span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">visitInsn<\/span>(<span style=\"color:#6699cc;\">getSubOpcode<\/span>(commonType))<span style=\"color:#ac7a68;\">;<\/span><br \/>            <span style=\"color:#c695c6;\">return<\/span> <span style=\"color:#c695c6;\">new<\/span> <span style=\"color:#6699cc;font-style:italic;\">CompilationInfo<\/span>(commonType)<span style=\"color:#ac7a68;\">;<\/span><br \/>        <span style=\"color:#c695c6;\">default<\/span><span style=\"color:#ac7a68;\">:<\/span><br \/>            <span style=\"color:#c695c6;\">throw<\/span> <span style=\"color:#c695c6;\">new<\/span> <span style=\"color:#6699cc;font-style:italic;\">UnsupportedOperationException<\/span>(<span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#80b979;\">Unsupported <\/span><span style=\"color:#80b979;\">operator: <\/span><span style=\"color:#5fb4b4;\">&#8220;<\/span> <span style=\"color:#f97b58;\">+<\/span> ctx<span style=\"color:#f97b58;\">.<\/span>op<span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">getText<\/span>())<span style=\"color:#ac7a68;\">;<\/span><br \/>    }<br \/>}<\/div>\n<p>Another important but not complex construct to implement is the conditional <em>if<\/em> statement. This statement consists of three parts: condition, <em>if<\/em> body, and optional <em>else<\/em> body. In bytecode, we can implement the <em>if<\/em> statement using conditional and unconditional jump instructions. First, we generate code for evaluating the condition. Then we create two labels: one for jumping to the <em>else<\/em> body and another for exiting the entire <em>if<\/em> statement. If the condition is false, we jump to the <em>labelFalse<\/em> label, otherwise we execute the <em>if<\/em> body. If an <em>else<\/em> body is present, we add an unconditional jump instruction (<em>goto<\/em>) to the exit label after executing the <em>if<\/em> body.<\/p>\n<div style=\"white-space:pre;font-family:Monospace;color:#333333;background-color:#f8f8f8;-moz-tab-size:2;tab-size:2;border:1px solid #E5E5E5;padding:3px;margin: 6px 0 6px 0;font-size:12px;\"><span style=\"color:#ec5f66;\">public<\/span> <span style=\"color:#6699cc;font-style:italic;\">CompilationInfo<\/span> <span style=\"color:#5fb4b4;\">visitIfStatement<\/span>(<span style=\"color:#6699cc;font-style:italic;\">JimpleParser<\/span><span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;font-style:italic;\">IfStatementContext<\/span> <span style=\"color:#f9ae58;\">ctx<\/span>) {<br \/>    <span style=\"color:#6699cc;\">visit<\/span>(ctx<span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">expression<\/span>())<span style=\"color:#ac7a68;\">;<\/span><\/p>\n<p>    <span style=\"color:#6699cc;font-style:italic;\">Label<\/span> labelFalse <span style=\"color:#f97b58;\">=<\/span> <span style=\"color:#c695c6;\">new<\/span> <span style=\"color:#6699cc;font-style:italic;\">Label<\/span>()<span style=\"color:#ac7a68;\">;<\/span><br \/>    <span style=\"color:#6699cc;font-style:italic;\">Label<\/span> labelExit <span style=\"color:#f97b58;\">=<\/span> <span style=\"color:#c695c6;\">new<\/span> <span style=\"color:#6699cc;font-style:italic;\">Label<\/span>()<span style=\"color:#ac7a68;\">;<\/span><br \/>    <span style=\"color:#c695c6;font-style:italic;\">boolean<\/span> hasElse <span style=\"color:#f97b58;\">=<\/span> ctx<span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">elseStatement<\/span>() <span style=\"color:#f97b58;\">!=<\/span> <span style=\"color:#ec5f66;font-style:italic;\">null<\/span><span style=\"color:#ac7a68;\">;<\/span><br \/>    <span style=\"color:#999999;\">\/\/<\/span><span style=\"color:#999999;\"> <\/span><span style=\"color:#999999;\">if <\/span><span style=\"color:#999999;\">the <\/span><span style=\"color:#999999;\">value <\/span><span style=\"color:#999999;\">is <\/span><span style=\"color:#999999;\">false, <\/span><span style=\"color:#999999;\">then <\/span><span style=\"color:#999999;\">go <\/span><span style=\"color:#999999;\">to <\/span><span style=\"color:#999999;\">the <\/span><span style=\"color:#999999;\">else <\/span><span style=\"color:#999999;\">statement <\/span><span style=\"color:#999999;\">or <\/span><span style=\"color:#999999;\">exit <\/span><span style=\"color:#999999;\">if <\/span><span style=\"color:#999999;\">there <\/span><span style=\"color:#999999;\">is <\/span><span style=\"color:#999999;\">no <\/span><span style=\"color:#999999;\">else<\/span><br \/>    <span style=\"color:#6699cc;font-style:italic;\">MethodVisitor<\/span> method <span style=\"color:#f97b58;\">=<\/span> <span style=\"color:#6699cc;\">getCurrentMethod<\/span>()<span style=\"color:#ac7a68;\">;<\/span>    <br \/>    method<span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">visitJumpInsn<\/span>(<span style=\"color:#c695c6;\">IFEQ<\/span><span style=\"color:#ac7a68;\">,<\/span> hasElse <span style=\"color:#f97b58;\">?<\/span> labelFalse <span style=\"color:#f97b58;\">:<\/span> labelExit)<span style=\"color:#ac7a68;\">;<\/span><\/p>\n<p>    <span style=\"color:#999999;\">\/\/<\/span><span style=\"color:#999999;\"> <\/span><span style=\"color:#999999;\">true<\/span><br \/>    <span style=\"color:#6699cc;\">visit<\/span>(ctx<span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">statement<\/span>())<span style=\"color:#ac7a68;\">;<\/span><\/p>\n<p>    <span style=\"color:#c695c6;\">if<\/span> (hasElse) {<br \/>        method<span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">visitJumpInsn<\/span>(<span style=\"color:#c695c6;\">GOTO<\/span><span style=\"color:#ac7a68;\">,<\/span> labelExit)<span style=\"color:#ac7a68;\">;<\/span><br \/>        <span style=\"color:#999999;\">\/\/<\/span><span style=\"color:#999999;\"> <\/span><span style=\"color:#999999;\">false<\/span><br \/>        method<span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">visitLabel<\/span>(labelFalse)<span style=\"color:#ac7a68;\">;<\/span><br \/>        <span style=\"color:#6699cc;\">visit<\/span>(ctx<span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">elseStatement<\/span>())<span style=\"color:#ac7a68;\">;<\/span><br \/>    }<br \/>    method<span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">visitLabel<\/span>(labelExit)<span style=\"color:#ac7a68;\">;<\/span><\/p>\n<p>    <span style=\"color:#c695c6;\">return<\/span> <span style=\"color:#6699cc;font-style:italic;\">CompilationInfo<\/span><span style=\"color:#f97b58;\">.<\/span><span style=\"color:#c695c6;\">VOID<\/span><span style=\"color:#ac7a68;\">;<\/span><br \/>}<\/div>\n<h3>Monomorphization<\/h3>\n<p>As mentioned above, Jimple has no explicit types for function parameters and return values. Types are computed during compilation. This in turn allows implementing an interesting capability in the language. Consider the following example:<\/p>\n<div style=\"white-space:pre;font-family:Monospace;color:#333333;background-color:#f8f8f8;-moz-tab-size:2;tab-size:2;border:1px solid #E5E5E5;padding:3px;margin: 6px 0 6px 0;font-size:12px;\"><span style=\"color:#6699cc;font-style:italic;\">fun<\/span> <span style=\"color:#5fb4b4;\">sum<\/span>(<span style=\"color:#6699cc;font-style:italic;\">a<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#6699cc;font-style:italic;\">b<\/span>) {<br \/>    <span style=\"color:#c695c6;\">return<\/span> a <span style=\"color:#f97b58;\">+<\/span> b<br \/>}<\/p>\n<p><span style=\"color:#6699cc;font-style:italic;\">println<\/span> <span style=\"color:#5fb4b4;\">sum<\/span>(4<span style=\"color:#ac7a68;\">,<\/span> 2)<br \/><span style=\"color:#6699cc;font-style:italic;\">println<\/span> <span style=\"color:#5fb4b4;\">sum<\/span>(&#8220;4&#8221;<span style=\"color:#ac7a68;\">,<\/span> &#8220;2&#8221;)<\/div>\n<p>In this example, the <em>sum<\/em> function is declared once but called twice: first with two integers, and second with two strings. In Jimple, during the compilation, two versions of the <em>sum<\/em> function will be generated: one for integers and another for strings. This allows using the same code for different data types. This process is called <a href=\"https:\/\/en.wikipedia.org\/wiki\/Monomorphization\" target=\"_blank\" rel=\"noopener\">monomorphization<\/a>, and the function is <a href=\"https:\/\/en.wikipedia.org\/wiki\/Polymorphism_(computer_science)\" target=\"_blank\" rel=\"noopener\">polymorphic<\/a>. In Java, this would have to be implemented by defining multiple methods (see <a href=\"https:\/\/en.wikipedia.org\/wiki\/Function_overloading\" target=\"_blank\" rel=\"noopener\">method overloading<\/a>).<\/p>\n<p>In bytecode, this would look as follows:<\/p>\n<div style=\"white-space:pre-wrap;font-family:Monospace;color:#333333;background-color:#f8f8f8;-moz-tab-size:2;tab-size:2;border:1px solid #E5E5E5;padding:3px;margin: 6px 0 6px 0;font-size:12px;\"><span style=\"color:#c695c6;\">public<\/span> <span style=\"color:#c695c6;\">static<\/span> main([<span style=\"color:#6699cc;font-style:italic;\">Ljava<\/span><span style=\"color:#6699cc;font-style:italic;\">\/<\/span><span style=\"color:#6699cc;font-style:italic;\">lang<\/span><span style=\"color:#6699cc;font-style:italic;\">\/<\/span><span style=\"color:#6699cc;font-style:italic;\">String<\/span>;)V<br \/>  GETSTATIC <span style=\"color:#6699cc;font-style:italic;\">java<\/span><span style=\"color:#6699cc;font-style:italic;\">\/<\/span><span style=\"color:#6699cc;font-style:italic;\">lang<\/span><span style=\"color:#6699cc;font-style:italic;\">\/<\/span><span style=\"color:#6699cc;font-style:italic;\">System<\/span><span style=\"color:#5fb4b4;font-style:italic;\">.out <\/span><span style=\"color:#5fb4b4;font-style:italic;\">: <\/span><span style=\"color:#5fb4b4;font-style:italic;\">Ljava<\/span><span style=\"color:#5fb4b4;font-style:italic;\">\/<\/span><span style=\"color:#5fb4b4;font-style:italic;\">io<\/span><span style=\"color:#5fb4b4;font-style:italic;\">\/<\/span><span style=\"color:#5fb4b4;font-style:italic;\">PrintStream<\/span>;<br \/>  LDC 4<br \/>  LDC 2<br \/>  INVOKESTATIC JimpleAutoGenApp.sum (JJ)J<br \/>  INVOKEVIRTUAL <span style=\"color:#6699cc;font-style:italic;\">java<\/span><span style=\"color:#6699cc;font-style:italic;\">\/<\/span><span style=\"color:#6699cc;font-style:italic;\">io<\/span><span style=\"color:#6699cc;font-style:italic;\">\/<\/span><span style=\"color:#6699cc;font-style:italic;\">PrintStream<\/span><span style=\"color:#5fb4b4;font-style:italic;\">.println <\/span><span style=\"color:#5fb4b4;font-style:italic;\">(<\/span><span style=\"color:#5fb4b4;font-style:italic;\">J<\/span><span style=\"color:#5fb4b4;font-style:italic;\">)<\/span><span style=\"color:#5fb4b4;font-style:italic;\">V<\/span><br \/>  GETSTATIC <span style=\"color:#6699cc;font-style:italic;\">java<\/span><span style=\"color:#6699cc;font-style:italic;\">\/<\/span><span style=\"color:#6699cc;font-style:italic;\">lang<\/span><span style=\"color:#6699cc;font-style:italic;\">\/<\/span><span style=\"color:#6699cc;font-style:italic;\">System<\/span><span style=\"color:#5fb4b4;font-style:italic;\">.out <\/span><span style=\"color:#5fb4b4;font-style:italic;\">: <\/span><span style=\"color:#5fb4b4;font-style:italic;\">Ljava<\/span><span style=\"color:#5fb4b4;font-style:italic;\">\/<\/span><span style=\"color:#5fb4b4;font-style:italic;\">io<\/span><span style=\"color:#5fb4b4;font-style:italic;\">\/<\/span><span style=\"color:#5fb4b4;font-style:italic;\">PrintStream<\/span>;<br \/>  LDC <span style=\"color:#80b979;\">&#8220;<\/span><span style=\"color:#80b979;\">4<\/span><span style=\"color:#80b979;\">&#8220;<\/span><br \/>  LDC <span style=\"color:#80b979;\">&#8220;<\/span><span style=\"color:#80b979;\">2<\/span><span style=\"color:#80b979;\">&#8220;<\/span><br \/>  INVOKESTATIC JimpleAutoGenApp.sum (<span style=\"color:#6699cc;font-style:italic;\">Ljava<\/span><span style=\"color:#6699cc;font-style:italic;\">\/<\/span><span style=\"color:#6699cc;font-style:italic;\">lang<\/span><span style=\"color:#6699cc;font-style:italic;\">\/<\/span><span style=\"color:#6699cc;font-style:italic;\">String<\/span>;<span style=\"color:#6699cc;font-style:italic;\">Ljava<\/span><span style=\"color:#6699cc;font-style:italic;\">\/<\/span><span style=\"color:#6699cc;font-style:italic;\">lang<\/span><span style=\"color:#6699cc;font-style:italic;\">\/<\/span><span style=\"color:#6699cc;font-style:italic;\">String<\/span>\ud83d\ude09<span style=\"color:#6699cc;font-style:italic;\">Ljava<\/span><span style=\"color:#6699cc;font-style:italic;\">\/<\/span><span style=\"color:#6699cc;font-style:italic;\">lang<\/span><span style=\"color:#6699cc;font-style:italic;\">\/<\/span><span style=\"color:#6699cc;font-style:italic;\">String<\/span>;<br \/>  INVOKEVIRTUAL <span style=\"color:#6699cc;font-style:italic;\">java<\/span><span style=\"color:#6699cc;font-style:italic;\">\/<\/span><span style=\"color:#6699cc;font-style:italic;\">io<\/span><span style=\"color:#6699cc;font-style:italic;\">\/<\/span><span style=\"color:#6699cc;font-style:italic;\">PrintStream<\/span><span style=\"color:#5fb4b4;font-style:italic;\">.println <\/span><span style=\"color:#5fb4b4;font-style:italic;\">(<\/span><span style=\"color:#5fb4b4;font-style:italic;\">Ljava<\/span><span style=\"color:#5fb4b4;font-style:italic;\">\/<\/span><span style=\"color:#5fb4b4;font-style:italic;\">lang<\/span><span style=\"color:#5fb4b4;font-style:italic;\">\/<\/span><span style=\"color:#5fb4b4;font-style:italic;\">String<\/span>;)V<br \/>  RETURN<\/p>\n<p><span style=\"color:#c695c6;\">private<\/span> <span style=\"color:#c695c6;\">static<\/span> sum(JJ)J<br \/>  LLOAD 0<br \/>  LLOAD 2<br \/>  LADD<br \/>  LRETURN<\/p>\n<p><span style=\"color:#c695c6;\">private<\/span> <span style=\"color:#c695c6;\">static<\/span> sum(<span style=\"color:#6699cc;font-style:italic;\">Ljava<\/span><span style=\"color:#6699cc;font-style:italic;\">\/<\/span><span style=\"color:#6699cc;font-style:italic;\">lang<\/span><span style=\"color:#6699cc;font-style:italic;\">\/<\/span><span style=\"color:#6699cc;font-style:italic;\">String<\/span>;<span style=\"color:#6699cc;font-style:italic;\">Ljava<\/span><span style=\"color:#6699cc;font-style:italic;\">\/<\/span><span style=\"color:#6699cc;font-style:italic;\">lang<\/span><span style=\"color:#6699cc;font-style:italic;\">\/<\/span><span style=\"color:#6699cc;font-style:italic;\">String<\/span>\ud83d\ude09<span style=\"color:#6699cc;font-style:italic;\">Ljava<\/span><span style=\"color:#6699cc;font-style:italic;\">\/<\/span><span style=\"color:#6699cc;font-style:italic;\">lang<\/span><span style=\"color:#6699cc;font-style:italic;\">\/<\/span><span style=\"color:#6699cc;font-style:italic;\">String<\/span>;<br \/>  NEW <span style=\"color:#6699cc;font-style:italic;\">java<\/span><span style=\"color:#6699cc;font-style:italic;\">\/<\/span><span style=\"color:#6699cc;font-style:italic;\">lang<\/span><span style=\"color:#6699cc;font-style:italic;\">\/<\/span><span style=\"color:#6699cc;font-style:italic;\">StringBuilder<\/span><br \/>  DUP<br \/>  INVOKESPECIAL <span style=\"color:#6699cc;font-style:italic;\">java<\/span><span style=\"color:#6699cc;font-style:italic;\">\/<\/span><span style=\"color:#6699cc;font-style:italic;\">lang<\/span><span style=\"color:#6699cc;font-style:italic;\">\/<\/span><span style=\"color:#6699cc;font-style:italic;\">StringBuilder<\/span><span style=\"color:#5fb4b4;font-style:italic;\">.&lt;init> <\/span><span style=\"color:#5fb4b4;font-style:italic;\">()V<\/span><br \/>  ALOAD 0<br \/>  INVOKEVIRTUAL <span style=\"color:#6699cc;font-style:italic;\">java<\/span><span style=\"color:#6699cc;font-style:italic;\">\/<\/span><span style=\"color:#6699cc;font-style:italic;\">lang<\/span><span style=\"color:#6699cc;font-style:italic;\">\/<\/span><span style=\"color:#6699cc;font-style:italic;\">StringBuilder<\/span><span style=\"color:#5fb4b4;font-style:italic;\">.append <\/span><span style=\"color:#5fb4b4;font-style:italic;\">(<\/span><span style=\"color:#5fb4b4;font-style:italic;\">Ljava<\/span><span style=\"color:#5fb4b4;font-style:italic;\">\/<\/span><span style=\"color:#5fb4b4;font-style:italic;\">lang<\/span><span style=\"color:#5fb4b4;font-style:italic;\">\/<\/span><span style=\"color:#5fb4b4;font-style:italic;\">String<\/span>\ud83d\ude09<span style=\"color:#6699cc;font-style:italic;\">Ljava<\/span><span style=\"color:#6699cc;font-style:italic;\">\/<\/span><span style=\"color:#6699cc;font-style:italic;\">lang<\/span><span style=\"color:#6699cc;font-style:italic;\">\/<\/span><span style=\"color:#6699cc;font-style:italic;\">StringBuilder<\/span>;<br \/>  ALOAD 1<br \/>  INVOKEVIRTUAL <span style=\"color:#6699cc;font-style:italic;\">java<\/span><span style=\"color:#6699cc;font-style:italic;\">\/<\/span><span style=\"color:#6699cc;font-style:italic;\">lang<\/span><span style=\"color:#6699cc;font-style:italic;\">\/<\/span><span style=\"color:#6699cc;font-style:italic;\">StringBuilder<\/span><span style=\"color:#5fb4b4;font-style:italic;\">.append <\/span><span style=\"color:#5fb4b4;font-style:italic;\">(<\/span><span style=\"color:#5fb4b4;font-style:italic;\">Ljava<\/span><span style=\"color:#5fb4b4;font-style:italic;\">\/<\/span><span style=\"color:#5fb4b4;font-style:italic;\">lang<\/span><span style=\"color:#5fb4b4;font-style:italic;\">\/<\/span><span style=\"color:#5fb4b4;font-style:italic;\">String<\/span>\ud83d\ude09<span style=\"color:#6699cc;font-style:italic;\">Ljava<\/span><span style=\"color:#6699cc;font-style:italic;\">\/<\/span><span style=\"color:#6699cc;font-style:italic;\">lang<\/span><span style=\"color:#6699cc;font-style:italic;\">\/<\/span><span style=\"color:#6699cc;font-style:italic;\">StringBuilder<\/span>;<br \/>  INVOKEVIRTUAL <span style=\"color:#6699cc;font-style:italic;\">java<\/span><span style=\"color:#6699cc;font-style:italic;\">\/<\/span><span style=\"color:#6699cc;font-style:italic;\">lang<\/span><span style=\"color:#6699cc;font-style:italic;\">\/<\/span><span style=\"color:#6699cc;font-style:italic;\">StringBuilder<\/span><span style=\"color:#5fb4b4;font-style:italic;\">.toString <\/span><span style=\"color:#5fb4b4;font-style:italic;\">()Ljava<\/span><span style=\"color:#5fb4b4;font-style:italic;\">\/<\/span><span style=\"color:#5fb4b4;font-style:italic;\">lang<\/span><span style=\"color:#5fb4b4;font-style:italic;\">\/<\/span><span style=\"color:#5fb4b4;font-style:italic;\">String<\/span>;<br \/>  ARETURN<\/div>\n<h3>Textifier and ASMifier<\/h3>\n<p>ASM provides two useful classes for textual visualization of bytecode: <em>Textifier<\/em> and <em>ASMifier<\/em>. The first class allows outputting bytecode in text format, similar to javap -v output. The second class allows outputting bytecode as Java code that can be used to generate bytecode using ASM. This is useful for debugging and understanding how to use ASM. Usage example:<\/p>\n<div style=\"white-space:pre;font-family:Monospace;color:#333333;background-color:#f8f8f8;-moz-tab-size:2;tab-size:2;border:1px solid #E5E5E5;padding:3px;margin: 6px 0 6px 0;font-size:12px;\"><span style=\"color:#6699cc;font-style:italic;\">Textifier<\/span><span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">main<\/span>(<span style=\"color:#c695c6;\">new<\/span> <span style=\"color:#6699cc;font-style:italic;\">String<\/span>[]{<span style=\"color:#6699cc;font-style:italic;\">FooBar<\/span><span style=\"color:#f97b58;\">.<\/span><span style=\"color:#ec5f66;font-style:italic;\">class<\/span><span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">getName<\/span>()})<span style=\"color:#ac7a68;\">;<\/span><br \/><span style=\"color:#6699cc;font-style:italic;\">ASMifier<\/span><span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">main<\/span>(<span style=\"color:#c695c6;\">new<\/span> <span style=\"color:#6699cc;font-style:italic;\">String<\/span>[]{<span style=\"color:#6699cc;font-style:italic;\">FooBar<\/span><span style=\"color:#f97b58;\">.<\/span><span style=\"color:#ec5f66;font-style:italic;\">class<\/span><span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">getName<\/span>()})<span style=\"color:#ac7a68;\">;<\/span><\/div>\n<h3>Testing<\/h3>\n<p>Back in the first article, a special <a href=\"https:\/\/github.com\/intechcore\/articles\/blob\/main\/antlr\/JimpleLang\/src\/test\/java\/org\/jimple\/interpreter\/JimpleInterpreterCaseTest.java\" target=\"_blank\" rel=\"noopener\">mini-framework<\/a> was written for testing the Jimple interpreter that allows running chunks of Jimple code and checking the actual program output against the expected output. To test the compiler, we can use the same approach. Instead of running the interpreter, we&#8217;ll compile Jimple code to JVM bytecode and run the compiled class directly from the test. The nicest part is that the compiler can be tested on the same test programs as the interpreter.<\/p>\n<h3>Bytecode Validation<\/h3>\n<p>Generating bytecode manually, even with a library, is not the most trivial task. It&#8217;s easy to make a mistake that leads to incorrect bytecode. The ASM library provides the <em>CheckClassAdapter<\/em> class for validating generated bytecode. This class allows checking bytecode for compliance with some JVM specification rules. If the bytecode is incorrect, an exception with an error description will be thrown. <em>CheckClassAdapter<\/em> can be used both after and during bytecode generation. In the second case, we simply need to wrap <em>ClassWriter<\/em> in <em>CheckClassAdapter<\/em> since the latter also implements the <em>ClassVisitor<\/em> interface.<\/p>\n<p>Let&#8217;s consider the following correct example of bytecode generation using <em>CheckClassAdapter<\/em>:<\/p>\n<div style=\"white-space:pre;font-family:Monospace;color:#333333;background-color:#f8f8f8;-moz-tab-size:2;tab-size:2;border:1px solid #E5E5E5;padding:3px;margin: 6px 0 6px 0;font-size:12px;\"><span style=\"color:#6699cc;font-style:italic;\">ClassWriter<\/span> cw <span style=\"color:#f97b58;\">=<\/span> <span style=\"color:#c695c6;\">new<\/span> <span style=\"color:#6699cc;font-style:italic;\">ClassWriter<\/span>(<span style=\"color:#6699cc;font-style:italic;\">ClassWriter<\/span><span style=\"color:#f97b58;\">.<\/span><span style=\"color:#c695c6;\">COMPUTE_FRAMES<\/span>)<span style=\"color:#ac7a68;\">;<\/span><br \/><span style=\"color:#6699cc;font-style:italic;\">CheckClassAdapter<\/span> cv <span style=\"color:#f97b58;\">=<\/span> <span style=\"color:#c695c6;\">new<\/span> <span style=\"color:#6699cc;font-style:italic;\">CheckClassAdapter<\/span>(cw)<span style=\"color:#ac7a68;\">;<\/span><br \/>cv<span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">visit<\/span>(<span style=\"color:#6699cc;font-style:italic;\">Opcodes<\/span><span style=\"color:#f97b58;\">.<\/span><span style=\"color:#c695c6;\">V1_8<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#c695c6;\">ACC_PUBLIC<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#c695c6;\">CLASS_NAME<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#ec5f66;font-style:italic;\">null<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#80b979;\">java<\/span><span style=\"color:#80b979;\">\/<\/span><span style=\"color:#80b979;\">lang<\/span><span style=\"color:#80b979;\">\/<\/span><span style=\"color:#80b979;\">Object<\/span><span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#ec5f66;font-style:italic;\">null<\/span>)<span style=\"color:#ac7a68;\">;<\/span><\/p>\n<p><span style=\"color:#6699cc;font-style:italic;\">MethodVisitor<\/span> method <span style=\"color:#f97b58;\">=<\/span> cv<span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">visitMethod<\/span>(<span style=\"color:#c695c6;\">ACC_PUBLIC<\/span> <span style=\"color:#f97b58;\">+<\/span> <span style=\"color:#c695c6;\">ACC_STATIC<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#80b979;\">main<\/span><span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#80b979;\">([Ljava<\/span><span style=\"color:#80b979;\">\/<\/span><span style=\"color:#80b979;\">lang<\/span><span style=\"color:#80b979;\">\/<\/span><span style=\"color:#80b979;\">String;)V<\/span><span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#ec5f66;font-style:italic;\">null<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#ec5f66;font-style:italic;\">null<\/span>)<span style=\"color:#ac7a68;\">;<\/span><br \/>method<span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">visitCode<\/span>()<span style=\"color:#ac7a68;\">;<\/span><br \/>method<span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">visitFieldInsn<\/span>(<span style=\"color:#c695c6;\">GETSTATIC<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#80b979;\">java<\/span><span style=\"color:#80b979;\">\/<\/span><span style=\"color:#80b979;\">lang<\/span><span style=\"color:#80b979;\">\/<\/span><span style=\"color:#80b979;\">System<\/span><span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#80b979;\">out<\/span><span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#80b979;\">Ljava<\/span><span style=\"color:#80b979;\">\/<\/span><span style=\"color:#80b979;\">io<\/span><span style=\"color:#80b979;\">\/<\/span><span style=\"color:#80b979;\">PrintStream;<\/span><span style=\"color:#5fb4b4;\">&#8220;<\/span>)<span style=\"color:#ac7a68;\">;<\/span><br \/>method<span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">visitLdcInsn<\/span>(<span style=\"color:#f9ae58;\">12<\/span><span style=\"color:#c695c6;font-style:italic;\">L<\/span>)<span style=\"color:#ac7a68;\">;<\/span><br \/>method<span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">visitLdcInsn<\/span>(<span style=\"color:#f9ae58;\">33<\/span><span style=\"color:#c695c6;font-style:italic;\">L<\/span>)<span style=\"color:#ac7a68;\">;<\/span><br \/>method<span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">visitMethodInsn<\/span>(<span style=\"color:#c695c6;\">INVOKESTATIC<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#80b979;\">java<\/span><span style=\"color:#80b979;\">\/<\/span><span style=\"color:#80b979;\">lang<\/span><span style=\"color:#80b979;\">\/<\/span><span style=\"color:#80b979;\">Math<\/span><span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#80b979;\">max<\/span><span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#80b979;\">(<\/span><span style=\"color:#80b979;\">JJ<\/span><span style=\"color:#80b979;\">)<\/span><span style=\"color:#80b979;\">J<\/span><span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#ec5f66;font-style:italic;\">false<\/span>)<span style=\"color:#ac7a68;\">;<\/span><br \/>method<span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">visitMethodInsn<\/span>(<span style=\"color:#c695c6;\">INVOKEVIRTUAL<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#80b979;\">java<\/span><span style=\"color:#80b979;\">\/<\/span><span style=\"color:#80b979;\">io<\/span><span style=\"color:#80b979;\">\/<\/span><span style=\"color:#80b979;\">PrintStream<\/span><span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#80b979;\">println<\/span><span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#80b979;\">(<\/span><span style=\"color:#80b979;\">J<\/span><span style=\"color:#80b979;\">)<\/span><span style=\"color:#80b979;\">V<\/span><span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#ec5f66;font-style:italic;\">false<\/span>)<span style=\"color:#ac7a68;\">;<\/span><br \/>method<span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">visitInsn<\/span>(<span style=\"color:#c695c6;\">RETURN<\/span>)<span style=\"color:#ac7a68;\">;<\/span><br \/>method<span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">visitEnd<\/span>()<span style=\"color:#ac7a68;\">;<\/span><\/div>\n<p>The code is successfully generated and executed. This is equivalent to the following Java code:<\/p>\n<div style=\"white-space:pre;font-family:Monospace;color:#333333;background-color:#f8f8f8;-moz-tab-size:2;tab-size:2;border:1px solid #E5E5E5;padding:3px;margin: 6px 0 6px 0;font-size:12px;\"><span style=\"color:#ec5f66;\">public<\/span> <span style=\"color:#ec5f66;\">static<\/span> <span style=\"color:#c695c6;font-style:italic;\">void<\/span> <span style=\"color:#5fb4b4;\">main<\/span>(<span style=\"color:#6699cc;font-style:italic;\">String<\/span><span style=\"color:#ec5f66;\">[]<\/span> <span style=\"color:#f9ae58;\">args<\/span>) {<br \/>    <span style=\"color:#6699cc;font-style:italic;\">System<\/span><span style=\"color:#f97b58;\">.<\/span>out<span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">println<\/span>(<span style=\"color:#6699cc;font-style:italic;\">Math<\/span><span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">max<\/span>(<span style=\"color:#f9ae58;\">12<\/span><span style=\"color:#c695c6;font-style:italic;\">L<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#f9ae58;\">33<\/span><span style=\"color:#c695c6;font-style:italic;\">L<\/span>))<span style=\"color:#ac7a68;\">;<\/span><br \/>}<\/div>\n<p>However, if we accidentally make a mistake and, for example, write <em>method.visitLdcInsn(&#8220;33&#8221;)<\/em>; instead of <em>method.visitLdcInsn(33L)<\/em>;, then during bytecode generation an <em>IllegalArgumentException<\/em> will be thrown with an error message:<\/p>\n<div style=\"white-space:pre-wrap;font-family:Monospace;color:#333333;background-color:#f8f8f8;-moz-tab-size:2;tab-size:2;border:1px solid #E5E5E5;padding:3px;margin: 6px 0 6px 0;font-size:12px;\">java.lang.IllegalArgumentException: Error at instruction <span style=\"color:#999999;\">3:<\/span> Argument <span style=\"color:#999999;\">2:<\/span> expected J, but found R main([<span style=\"color:#6699cc;font-style:italic;\">Ljava<\/span><span style=\"color:#6699cc;font-style:italic;\">\/<\/span><span style=\"color:#6699cc;font-style:italic;\">lang<\/span><span style=\"color:#6699cc;font-style:italic;\">\/<\/span><span style=\"color:#6699cc;font-style:italic;\">String<\/span>;)V<br \/>00000 R  :  :     GETSTATIC <span style=\"color:#6699cc;font-style:italic;\">java<\/span><span style=\"color:#6699cc;font-style:italic;\">\/<\/span><span style=\"color:#6699cc;font-style:italic;\">lang<\/span><span style=\"color:#6699cc;font-style:italic;\">\/<\/span><span style=\"color:#6699cc;font-style:italic;\">System<\/span><span style=\"color:#5fb4b4;font-style:italic;\">.out <\/span><span style=\"color:#5fb4b4;font-style:italic;\">: <\/span><span style=\"color:#5fb4b4;font-style:italic;\">Ljava<\/span><span style=\"color:#5fb4b4;font-style:italic;\">\/<\/span><span style=\"color:#5fb4b4;font-style:italic;\">io<\/span><span style=\"color:#5fb4b4;font-style:italic;\">\/<\/span><span style=\"color:#5fb4b4;font-style:italic;\">PrintStream<\/span>;<br \/>00001 R  : R  :     LDC 12<br \/>00002 R  : R J  :     LDC <span style=\"color:#80b979;\">&#8220;<\/span><span style=\"color:#80b979;\">33<\/span><span style=\"color:#80b979;\">&#8220;<\/span><br \/>00003 R  : R J R  :     INVOKESTATIC <span style=\"color:#6699cc;font-style:italic;\">java<\/span><span style=\"color:#6699cc;font-style:italic;\">\/<\/span><span style=\"color:#6699cc;font-style:italic;\">lang<\/span><span style=\"color:#6699cc;font-style:italic;\">\/<\/span><span style=\"color:#6699cc;font-style:italic;\">Math<\/span><span style=\"color:#5fb4b4;font-style:italic;\">.max <\/span><span style=\"color:#5fb4b4;font-style:italic;\">(<\/span><span style=\"color:#5fb4b4;font-style:italic;\">JJ<\/span><span style=\"color:#5fb4b4;font-style:italic;\">)<\/span><span style=\"color:#5fb4b4;font-style:italic;\">J<\/span><br \/>00004 ? :     INVOKEVIRTUAL <span style=\"color:#6699cc;font-style:italic;\">java<\/span><span style=\"color:#6699cc;font-style:italic;\">\/<\/span><span style=\"color:#6699cc;font-style:italic;\">io<\/span><span style=\"color:#6699cc;font-style:italic;\">\/<\/span><span style=\"color:#6699cc;font-style:italic;\">PrintStream<\/span><span style=\"color:#5fb4b4;font-style:italic;\">.println <\/span><span style=\"color:#5fb4b4;font-style:italic;\">(<\/span><span style=\"color:#5fb4b4;font-style:italic;\">J<\/span><span style=\"color:#5fb4b4;font-style:italic;\">)<\/span><span style=\"color:#5fb4b4;font-style:italic;\">V<\/span><br \/>00005 ? :     RETURN<\/div>\n<p>Just for the sake of curiosity, you could comment out <em>CheckClassAdapter<\/em>. In this case, the bytecode will be successfully generated, but when attempting to execute it, a <em>VerifyError<\/em> exception will occur, as the JVM will detect type mismatch.<\/p>\n<h3>Compilation and Execution<\/h3>\n<p>For convenient compilation and execution of compiled code, a utility <em>JimpleCompilerCli<\/em> was written that takes a file with Jimple code as input, compiles it to Java bytecode, and saves it as an executable jar file. This utility can be used via jimplec.sh\/jimplec.bat scripts. First, we need to compile the project using Maven:<\/p>\n<div style=\"white-space:pre-wrap;font-family:Monospace;color:#333333;background-color:#f8f8f8;-moz-tab-size:2;tab-size:2;border:1px solid #E5E5E5;padding:3px;margin: 6px 0 6px 0;font-size:12px;\"><span style=\"color:#6699cc;\">mvn<\/span> <span style=\"color:#80b979;\">clean<\/span> <span style=\"color:#80b979;\">package<\/span><\/div>\n<p>Then, to compile <em>example.jimple<\/em>, execute the following command:<\/p>\n<div style=\"white-space:pre-wrap;font-family:Monospace;color:#333333;background-color:#f8f8f8;-moz-tab-size:2;tab-size:2;border:1px solid #E5E5E5;padding:3px;margin: 6px 0 6px 0;font-size:12px;\"><span style=\"color:#c695c6;\">.<\/span><span style=\"color:#ac7a68;\">\/<\/span><span style=\"color:#6699cc;\">jimplec.sh<\/span> <span style=\"color:#80b979;\">example.jimple<\/span><br \/><span style=\"color:#999999;\">#<\/span><span style=\"color:#999999;\"> <\/span><span style=\"color:#999999;\">or <\/span><span style=\"color:#999999;\">jimplec.bat <\/span><span style=\"color:#999999;\">example.jimple <\/span><span style=\"color:#999999;\">for <\/span><span style=\"color:#999999;\">Windows<\/span><\/div>\n<p>This command will create a <em>target\/example.jar<\/em> file that can be run using the JVM:<\/p>\n<div style=\"white-space:pre-wrap;font-family:Monospace;color:#333333;background-color:#f8f8f8;-moz-tab-size:2;tab-size:2;border:1px solid #E5E5E5;padding:3px;margin: 6px 0 6px 0;font-size:12px;\"><span style=\"color:#6699cc;\">java<\/span> <span style=\"color:#5fb4b4;\">&#8211;<\/span><span style=\"color:#f9ae58;\">jar<\/span> <span style=\"color:#80b979;\">target<\/span><span style=\"color:#80b979;\">\/<\/span><span style=\"color:#80b979;\">example.jar<\/span><\/div>\n<h3>Performance Comparison<\/h3>\n<p>To compare the performance of the Jimple interpreter and compiled Jimple to bytecode, we can use the following test example:<\/p>\n<div style=\"white-space:pre;font-family:Monospace;color:#333333;background-color:#f8f8f8;-moz-tab-size:2;tab-size:2;border:1px solid #E5E5E5;padding:3px;margin: 6px 0 6px 0;font-size:12px;\"><span style=\"color:#c695c6;font-style:italic;\">var<\/span> counter <span style=\"color:#f97b58;\">=<\/span> <span style=\"color:#f9ae58;\">0<\/span><br \/><span style=\"color:#c695c6;font-style:italic;\">var<\/span> lastFactorial <span style=\"color:#f97b58;\">=<\/span> <span style=\"color:#f9ae58;\">0<\/span><br \/><span style=\"color:#c695c6;font-style:italic;\">var<\/span> startTime <span style=\"color:#f97b58;\">=<\/span> <span style=\"color:#6699cc;\">now<\/span>()<\/p>\n<p><span style=\"color:#c695c6;\">while<\/span>(counter <span style=\"color:#f97b58;\">&lt;<\/span> <span style=\"color:#f9ae58;\">1000000<\/span>) {<br \/>    lastFactorial <span style=\"color:#f97b58;\">=<\/span> <span style=\"color:#6699cc;\">factorial<\/span>(counter <span style=\"color:#f97b58;\">%<\/span> <span style=\"color:#f9ae58;\">20<\/span> <span style=\"color:#f97b58;\">+<\/span> lastFactorial <span style=\"color:#f97b58;\">%<\/span> <span style=\"color:#f9ae58;\">5<\/span>)<br \/>    counter <span style=\"color:#f97b58;\">=<\/span> counter <span style=\"color:#f97b58;\">+<\/span> <span style=\"color:#f9ae58;\">1<\/span><br \/>}<\/p>\n<p><span style=\"color:#c695c6;font-style:italic;\">var<\/span> time <span style=\"color:#f97b58;\">=<\/span> <span style=\"color:#6699cc;\">now<\/span>() <span style=\"color:#f97b58;\">&#8211;<\/span> startTime<br \/>println <span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#80b979;\">lastFactorial: <\/span><span style=\"color:#5fb4b4;\">&#8220;<\/span> <span style=\"color:#f97b58;\">+<\/span> lastFactorial<br \/>println <span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#80b979;\">counter: <\/span><span style=\"color:#5fb4b4;\">&#8220;<\/span> <span style=\"color:#f97b58;\">+<\/span> counter<br \/>println <span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#80b979;\">time: <\/span><span style=\"color:#5fb4b4;\">&#8220;<\/span> <span style=\"color:#f97b58;\">+<\/span> time<\/p>\n<p>fun <span style=\"color:#6699cc;\">factorial<\/span>(n) {<br \/>    <span style=\"color:#6699cc;\">if<\/span> (n <span style=\"color:#f97b58;\">==<\/span> <span style=\"color:#f9ae58;\">0<\/span>) {<br \/>        return <span style=\"color:#f9ae58;\">1<\/span><br \/>    }<br \/>    return n <span style=\"color:#f97b58;\">*<\/span> <span style=\"color:#6699cc;\">factorial<\/span>(n<span style=\"color:#f97b58;\">&#8211;<\/span><span style=\"color:#f9ae58;\">1<\/span>)<br \/>}<\/div>\n<p>This code calculates the factorial of a number in a loop one million times using a recursive <em>factorial<\/em> function, where the argument of the <em>factorial<\/em> function depends on the previous result. This is done to avoid JIT compiler optimization in the JVM, which might notice that the function is always called with the same arguments and cache the result. In the interpreter, we don&#8217;t have such optimization, so the comparison will be fair. This code was run 100 times each in the interpreter and in compiled form. The average execution time looks as follows:<\/p>\n<table class=\"t1\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"td1\" valign=\"top\">\n<p class=\"p1\"><b>Jimple Interpreter<span class=\"Apple-converted-space\">\u00a0<\/span><\/b><\/p>\n<\/td>\n<td class=\"td1\" valign=\"top\">\n<p class=\"p1\"><b>Compiled Jimple<span class=\"Apple-converted-space\">\u00a0<\/span><\/b><\/p>\n<\/td>\n<td class=\"td1\" valign=\"top\">\n<p class=\"p1\"><b>Difference<span class=\"Apple-converted-space\">\u00a0<\/span><\/b><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td class=\"td1\" valign=\"top\">\n<p class=\"p1\">3466 ms<span class=\"Apple-converted-space\">\u00a0<\/span><\/p>\n<\/td>\n<td class=\"td1\" valign=\"top\">\n<p class=\"p1\">9 ms<span class=\"Apple-converted-space\">\u00a0<\/span><\/p>\n<\/td>\n<td class=\"td1\" valign=\"top\">\n<p class=\"p1\"><b>~385x<span class=\"Apple-converted-space\">\u00a0<\/span><\/b><\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<p>As you can see from the table, <strong>compiled code executes 385 times faster than interpreted code.<\/strong> Testing was conducted on a machine with Intel Core i9-13900K 3.00 GHz processor and with JVM flag -Xmx500M.<\/p>\n<h3>Bonus: AOT Compilation to Native Code<\/h3>\n<p>Starting with JDK 9, Oracle provides <a href=\"https:\/\/www.graalvm.org\/\" target=\"_blank\" rel=\"noopener\">GraalVM JDK<\/a>, which includes the <a href=\"https:\/\/www.graalvm.org\/latest\/reference-manual\/native-image\/\" target=\"_blank\" rel=\"noopener\">Native Image<\/a> tool. This tool allows compiling JVM bytecode to machine (native) code. Using this tool can significantly improve application startup time and reduce its size, as native code doesn&#8217;t require a JVM to execute. To compile Jimple to native code, we first need to compile it to bytecode (jar file), then use Native Image to create a native executable file. Example compilation command:<\/p>\n<div style=\"white-space:pre-wrap;font-family:Monospace;color:#333333;background-color:#f8f8f8;-moz-tab-size:2;tab-size:2;border:1px solid #E5E5E5;padding:3px;margin: 6px 0 6px 0;font-size:12px;\"><span style=\"color:#6699cc;\">native-image<\/span> <span style=\"color:#5fb4b4;\">&#8211;<\/span><span style=\"color:#f9ae58;\">jar<\/span> <span style=\"color:#80b979;\">example.jar<\/span><\/div>\n<p>This command will create an executable file named <em>example<\/em> in Linux (or <em>example.exe<\/em> on Windows) that can be run directly from the command line (without java). By the way, the factorial from the previous example on native code executes on average slightly faster than compiled bytecode &#8211; about 7 ms.<\/p>\n<h3>Summary<\/h3>\n<p>In this article, we examined what Java bytecode is, its stack architecture, and how to generate bytecode from code in our language using the ASM library. At the end of the article, we compared the performance of interpreted code and compiled bytecode, and also looked at the possibility of compiling to native code using GraalVM.<\/p>\n<p>All the compiler source code can be viewed at this <a href=\"https:\/\/github.com\/intechcore\/articles\/tree\/main\/antlr\/JimpleLang\" target=\"_blank\" rel=\"noopener\">link<\/a>.<\/p>\n<h3>References<\/h3>\n<ul>\n<li><a href=\"https:\/\/docs.oracle.com\/javase\/specs\/jvms\/se7\/html\/jvms-6.html\" target=\"_blank\" rel=\"noopener\">https:\/\/docs.oracle.com\/javase\/specs\/jvms\/se7\/html\/jvms-6.html<\/a><\/li>\n<li><a href=\"https:\/\/dzone.com\/articles\/introduction-to-java-bytecode\" target=\"_blank\" rel=\"noopener\">https:\/\/dzone.com\/articles\/introduction-to-java-bytecode<\/a><\/li>\n<li><a href=\"https:\/\/asm.ow2.io\/\" target=\"_blank\" rel=\"noopener\">https:\/\/asm.ow2.io\/<\/a><\/li>\n<li><a href=\"https:\/\/en.wikipedia.org\/wiki\/List_of_Java_bytecode_instructions\" target=\"_blank\" rel=\"noopener\">https:\/\/en.wikipedia.org\/wiki\/List_of_Java_bytecode_instructions<\/a><\/li>\n<li><a href=\"https:\/\/www.youtube.com\/watch?v=p7ipmAa9_9E\" target=\"_blank\" rel=\"noopener\">https:\/\/www.youtube.com\/watch?v=p7ipmAa9_9E<\/a><\/li>\n<li><a href=\"https:\/\/openjdk.org\/jeps\/484\" target=\"_blank\" rel=\"noopener\">https:\/\/openjdk.org\/jeps\/484<\/a><\/li>\n<li><a href=\"https:\/\/martinfowler.com\/bliki\/TransparentCompilation.html\" target=\"_blank\" rel=\"noopener\">https:\/\/martinfowler.com\/bliki\/TransparentCompilation.html<\/a><\/li>\n<li><a href=\"https:\/\/www.graalvm.org\/latest\/reference-manual\/native-image\/\" target=\"_blank\" rel=\"noopener\">https:\/\/www.graalvm.org\/latest\/reference-manual\/native-image\/<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>In this article, we will learn how to compile our programming language (Jimple) to Java bytecode. We will also compare the execution time of Jimple code interpretation (from the first article) and compiled Jimple to Java bytecode.<\/p>\n","protected":false},"author":3,"featured_media":8116,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[3],"tags":[59,148,145,143,62,144],"class_list":{"0":"post-9912","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-articles","8":"tag-antlr-en","9":"tag-aot","10":"tag-bytecode","11":"tag-compiler","12":"tag-java-en","13":"tag-jvm","14":"anons"},"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.1.1 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Intechcore GmbH - Developing your own programming language in Java+ANTLR: Compiler<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/intechcore.com\/en\/development-of-an-own-programming-language-in-javaantlr-compiler\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Intechcore GmbH - Developing your own programming language in Java+ANTLR: Compiler\" \/>\n<meta property=\"og:description\" content=\"In this article, we will learn how to compile our programming language (Jimple) to Java bytecode. We will also compare the execution time of Jimple code interpretation (from the first article) and compiled Jimple to Java bytecode.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/intechcore.com\/en\/development-of-an-own-programming-language-in-javaantlr-compiler\/\" \/>\n<meta property=\"og:site_name\" content=\"Intechcore GmbH\" \/>\n<meta property=\"article:published_time\" content=\"2025-11-03T13:06:05+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-12-01T10:44:31+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/intechcore.com\/wp-content\/uploads\/2024\/10\/chess-6.png\" \/>\n\t<meta property=\"og:image:width\" content=\"616\" \/>\n\t<meta property=\"og:image:height\" content=\"350\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Ruslan Absaliamov\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Ruslan Absaliamov\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"24 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/intechcore.com\/en\/development-of-an-own-programming-language-in-javaantlr-compiler\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/intechcore.com\/en\/development-of-an-own-programming-language-in-javaantlr-compiler\/\"},\"author\":{\"name\":\"Ruslan Absaliamov\",\"@id\":\"https:\/\/intechcore.com\/en\/#\/schema\/person\/366b8eb5c4abbccd8a17d7328dc0a2e6\"},\"headline\":\"Developing your own programming language in Java+ANTLR: Compiler\",\"datePublished\":\"2025-11-03T13:06:05+00:00\",\"dateModified\":\"2025-12-01T10:44:31+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/intechcore.com\/en\/development-of-an-own-programming-language-in-javaantlr-compiler\/\"},\"wordCount\":3952,\"publisher\":{\"@id\":\"https:\/\/intechcore.com\/en\/#organization\"},\"image\":{\"@id\":\"https:\/\/intechcore.com\/en\/development-of-an-own-programming-language-in-javaantlr-compiler\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/intechcore.com\/wp-content\/uploads\/2024\/10\/chess-6.png\",\"keywords\":[\"ANTLR\",\"AOT\",\"Bytecode\",\"Compiler\",\"Java\",\"JVM\"],\"articleSection\":[\"Articles\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/intechcore.com\/en\/development-of-an-own-programming-language-in-javaantlr-compiler\/\",\"url\":\"https:\/\/intechcore.com\/en\/development-of-an-own-programming-language-in-javaantlr-compiler\/\",\"name\":\"Intechcore GmbH - Developing your own programming language in Java+ANTLR: Compiler\",\"isPartOf\":{\"@id\":\"https:\/\/intechcore.com\/en\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/intechcore.com\/en\/development-of-an-own-programming-language-in-javaantlr-compiler\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/intechcore.com\/en\/development-of-an-own-programming-language-in-javaantlr-compiler\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/intechcore.com\/wp-content\/uploads\/2024\/10\/chess-6.png\",\"datePublished\":\"2025-11-03T13:06:05+00:00\",\"dateModified\":\"2025-12-01T10:44:31+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/intechcore.com\/en\/development-of-an-own-programming-language-in-javaantlr-compiler\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/intechcore.com\/en\/development-of-an-own-programming-language-in-javaantlr-compiler\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/intechcore.com\/en\/development-of-an-own-programming-language-in-javaantlr-compiler\/#primaryimage\",\"url\":\"https:\/\/intechcore.com\/wp-content\/uploads\/2024\/10\/chess-6.png\",\"contentUrl\":\"https:\/\/intechcore.com\/wp-content\/uploads\/2024\/10\/chess-6.png\",\"width\":616,\"height\":350,\"caption\":\"Frau an Laptop und Computer mit Programmcode\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/intechcore.com\/en\/development-of-an-own-programming-language-in-javaantlr-compiler\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/intechcore.com\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Articles\",\"item\":\"https:\/\/intechcore.com\/en\/articles\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Developing your own programming language in Java+ANTLR: Compiler\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/intechcore.com\/en\/#website\",\"url\":\"https:\/\/intechcore.com\/en\/\",\"name\":\"Intechcore GmbH - Software Development Company\",\"description\":\"Technology Leading Software Development Company\",\"publisher\":{\"@id\":\"https:\/\/intechcore.com\/en\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/intechcore.com\/en\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/intechcore.com\/en\/#organization\",\"name\":\"Intechcore GmbH\",\"alternateName\":\"Software Development Company\",\"url\":\"https:\/\/intechcore.com\/en\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/intechcore.com\/en\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/new.intechcore.com\/wp-content\/uploads\/2024\/09\/favicon.png\",\"contentUrl\":\"https:\/\/new.intechcore.com\/wp-content\/uploads\/2024\/09\/favicon.png\",\"width\":64,\"height\":64,\"caption\":\"Intechcore GmbH\"},\"image\":{\"@id\":\"https:\/\/intechcore.com\/en\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/intechcore.com\/en\/#\/schema\/person\/366b8eb5c4abbccd8a17d7328dc0a2e6\",\"name\":\"Ruslan Absaliamov\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/intechcore.com\/en\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/9095380f9a38f10fce91553dcefa1b20f0a83ced000c99ab4f17343f92557a10?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/9095380f9a38f10fce91553dcefa1b20f0a83ced000c99ab4f17343f92557a10?s=96&d=mm&r=g\",\"caption\":\"Ruslan Absaliamov\"},\"url\":\"https:\/\/intechcore.com\/en\/author\/ruslan-absaliamov\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Intechcore GmbH - Developing your own programming language in Java+ANTLR: Compiler","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/intechcore.com\/en\/development-of-an-own-programming-language-in-javaantlr-compiler\/","og_locale":"en_US","og_type":"article","og_title":"Intechcore GmbH - Developing your own programming language in Java+ANTLR: Compiler","og_description":"In this article, we will learn how to compile our programming language (Jimple) to Java bytecode. We will also compare the execution time of Jimple code interpretation (from the first article) and compiled Jimple to Java bytecode.","og_url":"https:\/\/intechcore.com\/en\/development-of-an-own-programming-language-in-javaantlr-compiler\/","og_site_name":"Intechcore GmbH","article_published_time":"2025-11-03T13:06:05+00:00","article_modified_time":"2025-12-01T10:44:31+00:00","og_image":[{"width":616,"height":350,"url":"https:\/\/intechcore.com\/wp-content\/uploads\/2024\/10\/chess-6.png","type":"image\/png"}],"author":"Ruslan Absaliamov","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Ruslan Absaliamov","Est. reading time":"24 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/intechcore.com\/en\/development-of-an-own-programming-language-in-javaantlr-compiler\/#article","isPartOf":{"@id":"https:\/\/intechcore.com\/en\/development-of-an-own-programming-language-in-javaantlr-compiler\/"},"author":{"name":"Ruslan Absaliamov","@id":"https:\/\/intechcore.com\/en\/#\/schema\/person\/366b8eb5c4abbccd8a17d7328dc0a2e6"},"headline":"Developing your own programming language in Java+ANTLR: Compiler","datePublished":"2025-11-03T13:06:05+00:00","dateModified":"2025-12-01T10:44:31+00:00","mainEntityOfPage":{"@id":"https:\/\/intechcore.com\/en\/development-of-an-own-programming-language-in-javaantlr-compiler\/"},"wordCount":3952,"publisher":{"@id":"https:\/\/intechcore.com\/en\/#organization"},"image":{"@id":"https:\/\/intechcore.com\/en\/development-of-an-own-programming-language-in-javaantlr-compiler\/#primaryimage"},"thumbnailUrl":"https:\/\/intechcore.com\/wp-content\/uploads\/2024\/10\/chess-6.png","keywords":["ANTLR","AOT","Bytecode","Compiler","Java","JVM"],"articleSection":["Articles"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/intechcore.com\/en\/development-of-an-own-programming-language-in-javaantlr-compiler\/","url":"https:\/\/intechcore.com\/en\/development-of-an-own-programming-language-in-javaantlr-compiler\/","name":"Intechcore GmbH - Developing your own programming language in Java+ANTLR: Compiler","isPartOf":{"@id":"https:\/\/intechcore.com\/en\/#website"},"primaryImageOfPage":{"@id":"https:\/\/intechcore.com\/en\/development-of-an-own-programming-language-in-javaantlr-compiler\/#primaryimage"},"image":{"@id":"https:\/\/intechcore.com\/en\/development-of-an-own-programming-language-in-javaantlr-compiler\/#primaryimage"},"thumbnailUrl":"https:\/\/intechcore.com\/wp-content\/uploads\/2024\/10\/chess-6.png","datePublished":"2025-11-03T13:06:05+00:00","dateModified":"2025-12-01T10:44:31+00:00","breadcrumb":{"@id":"https:\/\/intechcore.com\/en\/development-of-an-own-programming-language-in-javaantlr-compiler\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/intechcore.com\/en\/development-of-an-own-programming-language-in-javaantlr-compiler\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/intechcore.com\/en\/development-of-an-own-programming-language-in-javaantlr-compiler\/#primaryimage","url":"https:\/\/intechcore.com\/wp-content\/uploads\/2024\/10\/chess-6.png","contentUrl":"https:\/\/intechcore.com\/wp-content\/uploads\/2024\/10\/chess-6.png","width":616,"height":350,"caption":"Frau an Laptop und Computer mit Programmcode"},{"@type":"BreadcrumbList","@id":"https:\/\/intechcore.com\/en\/development-of-an-own-programming-language-in-javaantlr-compiler\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/intechcore.com\/en\/"},{"@type":"ListItem","position":2,"name":"Articles","item":"https:\/\/intechcore.com\/en\/articles\/"},{"@type":"ListItem","position":3,"name":"Developing your own programming language in Java+ANTLR: Compiler"}]},{"@type":"WebSite","@id":"https:\/\/intechcore.com\/en\/#website","url":"https:\/\/intechcore.com\/en\/","name":"Intechcore GmbH - Software Development Company","description":"Technology Leading Software Development Company","publisher":{"@id":"https:\/\/intechcore.com\/en\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/intechcore.com\/en\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/intechcore.com\/en\/#organization","name":"Intechcore GmbH","alternateName":"Software Development Company","url":"https:\/\/intechcore.com\/en\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/intechcore.com\/en\/#\/schema\/logo\/image\/","url":"https:\/\/new.intechcore.com\/wp-content\/uploads\/2024\/09\/favicon.png","contentUrl":"https:\/\/new.intechcore.com\/wp-content\/uploads\/2024\/09\/favicon.png","width":64,"height":64,"caption":"Intechcore GmbH"},"image":{"@id":"https:\/\/intechcore.com\/en\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/intechcore.com\/en\/#\/schema\/person\/366b8eb5c4abbccd8a17d7328dc0a2e6","name":"Ruslan Absaliamov","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/intechcore.com\/en\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/9095380f9a38f10fce91553dcefa1b20f0a83ced000c99ab4f17343f92557a10?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/9095380f9a38f10fce91553dcefa1b20f0a83ced000c99ab4f17343f92557a10?s=96&d=mm&r=g","caption":"Ruslan Absaliamov"},"url":"https:\/\/intechcore.com\/en\/author\/ruslan-absaliamov\/"}]}},"_links":{"self":[{"href":"https:\/\/intechcore.com\/en\/wp-json\/wp\/v2\/posts\/9912","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/intechcore.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/intechcore.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/intechcore.com\/en\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/intechcore.com\/en\/wp-json\/wp\/v2\/comments?post=9912"}],"version-history":[{"count":28,"href":"https:\/\/intechcore.com\/en\/wp-json\/wp\/v2\/posts\/9912\/revisions"}],"predecessor-version":[{"id":10140,"href":"https:\/\/intechcore.com\/en\/wp-json\/wp\/v2\/posts\/9912\/revisions\/10140"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/intechcore.com\/en\/wp-json\/wp\/v2\/media\/8116"}],"wp:attachment":[{"href":"https:\/\/intechcore.com\/en\/wp-json\/wp\/v2\/media?parent=9912"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/intechcore.com\/en\/wp-json\/wp\/v2\/categories?post=9912"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/intechcore.com\/en\/wp-json\/wp\/v2\/tags?post=9912"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}