Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
test0.cpp File Reference
#include <stdio.h>
#include <stdlib.h>
#include "xbyak/xbyak.h"
Include dependency graph for test0.cpp:

Go to the source code of this file.

Classes

class  Sample
 
class  AddFunc
 
class  CallAtoi
 
class  JmpAtoi
 
struct  Reset
 

Macros

#define XBYAK_NO_OP_NAMES
 

Functions

void testReset ()
 
int main ()
 

Macro Definition Documentation

◆ XBYAK_NO_OP_NAMES

#define XBYAK_NO_OP_NAMES

Definition at line 10 of file test0.cpp.

Function Documentation

◆ main()

int main ( void )

Definition at line 136 of file test0.cpp.

137{
138 try {
139 Sample s;
140 printf("Xbyak version=%s\n", s.getVersionString());
141#ifdef XBYAK64_GCC
142 puts("64bit mode(gcc)");
143#elif defined(XBYAK64_WIN)
144 puts("64bit mode(win)");
145#else
146 puts("32bit");
147#endif
148 int (*func)(int) = s.getCode<int (*)(int)>();
149 for (int i = 0; i <= 10; i++) {
150 printf("0 + ... + %d = %d\n", i, func(i));
151 }
152 for (int i = 0; i < 10; i++) {
153 AddFunc a(i);
154 int (*add)(int) = a.get();
155 int y = add(i);
156 printf("%d + %d = %d\n", i, i, y);
157 }
158 CallAtoi c;
159 printf("call atoi(\"123\") = %d\n", c.get()("123"));
160 JmpAtoi j;
161 printf("jmp atoi(\"456\") = %d\n", j.get()("456"));
162 {
163 // use memory allocated by user
164 using namespace Xbyak;
165 const size_t codeSize = 1024;
166 uint8 buf[codeSize + 16];
167 uint8 *p = CodeArray::getAlignedAddress(buf);
168 CodeArray::protect(p, codeSize, true);
169 Sample s(p, codeSize);
170 int (*func)(int) = s.getCode<int (*)(int)>();
171 if (Xbyak::CastTo<uint8*>(func) != p) {
172 fprintf(stderr, "internal error %p %p\n", p, Xbyak::CastTo<uint8*>(func));
173 return 1;
174 }
175 printf("0 + ... + %d = %d\n", 100, func(100));
176 CodeArray::protect(p, codeSize, false);
177 }
178 puts("OK");
179 testReset();
180 } catch (std::exception& e) {
181 printf("ERR:%s\n", e.what());
182 } catch (...) {
183 printf("unknown error\n");
184 }
185}
const mie::Vuint & p
Definition bn.cpp:27
int(*)(const char *) get() const
Definition test0.cpp:86
LOGGING_API void printf(Category category, const char *format,...)
Definition Logging.cpp:30
Definition xbyak.h:104
const To CastTo(From p)
Definition xbyak.h:279
uint64_t y
Definition sha3.cpp:34
unsigned char uint8
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition pointer.h:1181
int add(int a, int b)
void testReset()
Definition test0.cpp:123
char * s
uint16_t j
uint8_t buf[2048]
Here is the call graph for this function:

◆ testReset()

void testReset ( )

Definition at line 123 of file test0.cpp.

124{
125 puts("testReset");
126 Reset code;
127 int (*f)(int) = code.getCode<int(*)(int)>();
128 for (int i = 0; i < 10; i++) {
129 code.init(i);
130 int v = f(i);
131 printf("%d %d\n", i, v);
132 code.reset();
133 }
134}
const uint8 * getCode() const
Definition xbyak.h:905
Here is the call graph for this function:
Here is the caller graph for this function: