[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Libjit-developers] First Attempt at libjit
From: |
manoloohara |
Subject: |
[Libjit-developers] First Attempt at libjit |
Date: |
Sun, 20 Feb 2005 16:51:29 -0500 (EST) |
I'm trying to make a simple microprocessor emulator, but I don't know how to
work with pointers with libjit.
I want to put a 0 in the more significative byte (msb) of AX.
Here is my code. It doesn't compile, and I don't know why.
Any idea?
#include <stdio.h>
#include <jit/jit-plus.h>
class register_class
{
private: jit_ubyte msb,lsb;
public: void msb_write(jit_ubyte new_value)
{msb=new_value; }
jit_ubyte *msb_address(void)
{return (&msb); }
void lsb_write(jit_ubyte new_value)
{lsb=new_value; }
jit_ubyte *lsb_address(void)
{return (&lsb);}
void print(void)
{printf("msb= %d lsb=%d\n",msb,lsb);
}
};
class ld_zero_function : public jit_function
{
public: register_class AX;
jit_function_t function;
ld_zero_function(jit_context& context) : jit_function(context)
{create();}
void print(void);
protected:
virtual jit_type_t create_signature();
virtual void build();
};
void ld_zero_function::print(void)
{AX.print();}
jit_type_t ld_zero_function::create_signature()
{ return signature_helper (jit_type_void, end_params);
// Return type, terminated with "end_params".
}
void ld_zero_function::build()
{// Put 0 in AX.msb;
jit_value_t x,temp1,zero_ubyte,y;
zero_ubyte=jit_value_create_nint_constant(jit_function_t(),jit_type_ubyte,0);
y=jit_type_create_pointer(jit_type_ubyte,1);
y=jit_insn_load(jit_function_t(),AX.msb_address); //DOESN'T COMPILE. WHY?
x=jit_insn_load_relative(jit_function_t(),y,0,jit_type_int);
temp1=jit_insn_load_relative(jit_function_t(),x,0,jit_type_int);
jit_insn_store_relative(jit_function_t(),temp1,0,zero_ubyte);
};
int main(int argc, char **argv)
{ void *dummy_args[0];
// Create a context to hold the JIT's primary state.
jit_context context;
// Create the function object.
ld_zero_function ld_zero(context);
// Execute the function.
ld_zero.apply(dummy_args,dummy_args);
// Print AX
ld_zero.print();
/* Finished */
return 0;
}
_______________________________________________
No banners. No pop-ups. No kidding.
Make My Way your home on the Web - http://www.myway.com
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Libjit-developers] First Attempt at libjit,
manoloohara <=