lightning
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Lightning] lightning testing tool - assembly like language - compile an


From: Paulo César Pereira de Andrade
Subject: [Lightning] lightning testing tool - assembly like language - compile and run
Date: Fri, 13 Aug 2010 22:53:17 -0300
User-agent: SquirrelMail/1.4.19

  Hi,

  I did not work much on debugging x86_64 code generation since
my last email, but instead wrote a tool that hopefully should be
useful.

  Obligatory first example is:
-%<-
.data   32
hello:
.c      "Hello world!\n"
.code   32
        prolog 0
        prepare 1
        movi_p %r0 hello
        pusharg_p %r0
        finish @printf
        ret
-%<-

in this case, the @ modifier uses dlsym to find printf address,
but of course, there is absolute no type checking.

  A more complex second example is:
-%<-
# allocate 512 bytes for data
.data   512

# variables can be created anywhere
# but a expression without side effects (other then creating the variable)
# need help of '.'
.$($bottles = 99)

many_bottles:
.c "%d bottles of beer on the wall,\n%d bottles of beer,\n"
less_bottles:
.c "take one down, pass it around,\n%d bottles of beer on the wall.\n\n"

two_bottles:
.c "take one down, pass it around,\none bottle of beer on the wall.\n\n"

one_bottle:
.c "one bottle of beer on the wall,\none bottle of beer,\n"
last_one:
.c "take one down, pass it around,\nno more bottles of beer on the wall.\n\n"

no_more:
.c "no more bottles of beer on the wall,\nno more bottles of beer,\n"
buy_more:
.c "go to the store and buy some more,\n%d bottles of beer on the wall.\n\n"

# allocate 256 bytes for code
.code   256
        prolog 0
        # keep bottles in %v0
        movi_i %v0 $bottles

use_bottles:
        blti_i out_of_bottles %v0 1
        beqi_i only_one_left %v0 1

        prepare 3
        pusharg_i %v0
        pusharg_i %v0
        movi_p %r0 many_bottles
        pusharg_p %r0
        finish @printf

        subi_i %v0 %v0 1

        beqi_i only_two_left %v0 1

        prepare 2
        pusharg_i %v0
        movi_p %r0 less_bottles
        pusharg_p %r0
        finish @printf

        # loop
        jmpi use_bottles

only_two_left:
        prepare 1
        movi_p %r0 two_bottles
        pusharg_p %r0
        finish @printf

        subi_i %v0 %v0 1

only_one_left:
        prepare 1
        movi_p %r0 one_bottle
        pusharg_p %r0
        finish @printf
        prepare 1
        movi_p %r0 last_one
        pusharg_p %r0
        finish @printf

out_of_bottles:
        prepare 1
        movi_p %r0 no_more
        pusharg_p %r0
        finish @printf
        prepare 2
        movi_i %r0 $bottles
        pusharg_i %r0
        movi_p %r0 buy_more
        pusharg_p %r0
        finish @printf
        ret
-%<-

  The above is just to have an idea of how it works, to get your copy:

$ svn checkout http://exl.googlecode.com/svn/trunk/check/lightning
lightning-test

  I also implemented the examples in lightning.info, but there is
no extensive tests yet, just the infrastructure.

Thanks,
Paulo




reply via email to

[Prev in Thread] Current Thread [Next in Thread]