tinycc-devel
[Top][All Lists]
Advanced

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

Re: [Tinycc-devel] Compiling to memory


From: Richard Brett
Subject: Re: [Tinycc-devel] Compiling to memory
Date: Mon, 25 Jul 2016 11:36:38 +1200
User-agent: Thunderbird 2.0.0.24 (Windows/20100228)

Hi Philip

The process I use is as follows (simplified from actual, error checking removed etc)

// set we want code in memory
tcc_set_output_type(state, TCC_OUTPUT_MEMORY);

// compile the program
tcc_compile_string(state,   Program);

// Add symbols for functions in current program, if any
tcc_add_symbol(state, "MyHostFunction", TccHostFunction);

// Get size of compiled code
int Size = tcc_relocate(state, NULL);

// Create some memory to place it in
if (Size > 0) {
    void *pMem = malloc(Size);
   
    // Call relocate again, and it will place memory we pass
    int err = tcc_relocate(state, pMem);
}

// Get function address, it will be inside pMem
pFunction = tcc_get_symbol(state, "FunctionName");


Cheers
.Richard


Philip Picard wrote:

I am emulating a fantasy computer based on a late 1980s computer. I did not want to write my own C compiler for this fantasy computer so I want to port TCC. However the main road block I have encountered is controlling where TCC compiles when it compiles to memory. For this emulator I need to control specifically where in the block of memory the code is located. With the TO_MEMORY option can I somehow change where in memory the binary code is placed?

 

Thanks,

Philip

 

Sent from Mail for Windows 10

 


_______________________________________________ Tinycc-devel mailing list address@hidden https://lists.nongnu.org/mailman/listinfo/tinycc-devel


reply via email to

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