Sunday, May 5, 2013

Writing an Assembler for CMinus using Antlr 3 and String Templates

Recently I wrote an assembler for DLX architecture using Antlr 3 as an assignment of the Advance architecture course module.
 

Target 

Main target of this assemble is to generate an optimized assembly code by filling delayed branch slots. It can take High level language code segment as a input. First it should generate unoptimized assembly code and then optimized it to fill delayed branch slots.


Why Antlr ?

Antlr supports String template which is a java template engine that can be used to generate any type of formated texts ( source codes, emails, etc). So using string template we can perform language transformation very easily. For example Java to C#, C++ etc. For more details look at Here .

you can find antlr 3 samples at github.  I modified the cminus sample available at github for this project. 


About project

I used Cminus as High level language and DLX (RISC architecture) as target platform. It used Antlr version 3.

This project is available at Google-code svn repository.


Limitations of the Code

  • Fills only delayed branched that occurs after unconditional jump. ( j )
  • Supports multiple for, while and doWhile loops in high level language.
  • supports only addition.
  • supports only == and < 
  • do not support variable = variable + variable type assignments
and more.



Main Development Steps

  1. Building Lexer and Parser using lexer rules.
    • used Antlr IDE ( downloaded via antlr site) to generate lexer and parser.
  2. Unoptimized code generation using string template.
  3. Wrote optimizer  and Optimized code generation. 
  4. Mavenized the project. 

Building Project and Run

you can build project using maven3. ($mvn clean install) .
Maven build will execute assembler after the build and generate optimized code for sample.txt. asem_optimized.txt and asem_unoptimized.txt will be created after the build.


Improvements to the Code base

I warmly welcome your suggestions and ideas to improve this assembler.



Thursday, April 25, 2013

Tips - Some useful parameters for starting a WSO2 server

Before you start, first go to <CarbonHOME>/bin . Where <CarbonHOME> is the directory of the carbon server.


Start a carbon server with 1 port offset

(Useful when you need to start multiple servers (ESB, BPS, AS etc) at same time)

$ ./wso2server.sh -DportOffset=1



Start a Carbon server with remote-debug mode on port 5005


$ ./wso2server.sh debug 5005


 

Tips - Remote Debug with Maven 3 - Plug-in Debug

How to Debug a Maven Plug-in at Build time.

1) Open maven plug-in source code using your favorite IDE ( Eclipse, InterlliJ IDEA etc) and set break points in codes that you are going to debug.

2) Start build project using following command.

$ mvnDebug clean install 
 
3) maven starts to Listen on port 8000 till a remote debugger connects.

$ mvnDebug clean install
Preparing to Execute Maven in Debug Mode
Listening for transport dt_socket at address: 8000

 
4) Start remote debug on port 8000 using your IDE. It will trigger the build process with remote debug.