Finally abstracted constants properly. Changed how the event module works; wasn't really abstract before. Removed libs we're not going to use: native, signal.

This commit is contained in:
rude
2009-10-10 11:11:04 +02:00
parent 0a2ae705dd
commit 87e3c4131c
101 changed files with 3225 additions and 33496 deletions
-1
View File
@@ -272,7 +272,6 @@ namespace audio
w.flags = MODULE_T;
w.functions = functions;
w.types = types;
w.constants = 0;
return luax_register_module(L, w);
}
+235
View File
@@ -0,0 +1,235 @@
/**
* Copyright (c) 2006-2009 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
**/
#include "Event.h"
namespace love
{
namespace event
{
Event::~Event()
{
}
bool Event::getConstant(const char * in, Event::Type & out)
{
return types.find(in, out);
}
bool Event::getConstant(Event::Type in, const char *& out)
{
return types.find(in, out);
}
bool Event::getConstant(const char * in, love::mouse::Mouse::Button & out)
{
return buttons.find(in, out);
}
bool Event::getConstant(love::mouse::Mouse::Button in, const char *& out)
{
return buttons.find(in, out);
}
bool Event::getConstant(const char * in, love::keyboard::Keyboard::Key & out)
{
return keys.find(in, out);
}
bool Event::getConstant(love::keyboard::Keyboard::Key in, const char *& out)
{
return keys.find(in, out);
}
StringMap<Event::Type, Event::TYPE_MAX_ENUM>::Entry Event::typeEntries[] =
{
{"kp", Event::TYPE_KEY_PRESSED},
{"kr", Event::TYPE_KEY_RELEASED},
{"mp", Event::TYPE_MOUSE_PRESSED},
{"mr", Event::TYPE_MOUSE_RELEASED},
{"jp", Event::TYPE_JOYSTICK_PRESSED},
{"jr", Event::TYPE_JOYSTICK_RELEASED},
{"q", Event::TYPE_QUIT},
};
StringMap<Event::Type, Event::TYPE_MAX_ENUM> Event::types(Event::typeEntries, sizeof(Event::typeEntries));
StringMap<love::mouse::Mouse::Button, love::mouse::Mouse::BUTTON_MAX_ENUM>::Entry Event::buttonEntries[] =
{
{"l", love::mouse::Mouse::BUTTON_LEFT},
{"m", love::mouse::Mouse::BUTTON_MIDDLE},
{"r", love::mouse::Mouse::BUTTON_RIGHT},
{"wu", love::mouse::Mouse::BUTTON_WHEELUP},
{"wd", love::mouse::Mouse::BUTTON_WHEELDOWN},
{"x1", love::mouse::Mouse::BUTTON_X1},
{"x2", love::mouse::Mouse::BUTTON_X2},
};
StringMap<love::mouse::Mouse::Button, love::mouse::Mouse::BUTTON_MAX_ENUM> Event::buttons(Event::buttonEntries, sizeof(Event::buttonEntries));
StringMap<love::keyboard::Keyboard::Key, love::keyboard::Keyboard::KEY_MAX_ENUM>::Entry Event::keyEntries[] =
{
{"backspace", love::keyboard::Keyboard::KEY_BACKSPACE},
{"tab", love::keyboard::Keyboard::KEY_TAB},
{"clear", love::keyboard::Keyboard::KEY_CLEAR},
{"return", love::keyboard::Keyboard::KEY_RETURN},
{"pause", love::keyboard::Keyboard::KEY_PAUSE},
{"escape", love::keyboard::Keyboard::KEY_ESCAPE},
{" ", love::keyboard::Keyboard::KEY_SPACE},
{"!", love::keyboard::Keyboard::KEY_EXCLAIM},
{"\"", love::keyboard::Keyboard::KEY_QUOTEDBL},
{"#", love::keyboard::Keyboard::KEY_HASH},
{"$", love::keyboard::Keyboard::KEY_DOLLAR},
{"&", love::keyboard::Keyboard::KEY_AMPERSAND},
{"'", love::keyboard::Keyboard::KEY_QUOTE},
{"(", love::keyboard::Keyboard::KEY_LEFTPAREN},
{")", love::keyboard::Keyboard::KEY_RIGHTPAREN},
{"*", love::keyboard::Keyboard::KEY_ASTERISK},
{"+", love::keyboard::Keyboard::KEY_PLUS},
{",", love::keyboard::Keyboard::KEY_COMMA},
{"-", love::keyboard::Keyboard::KEY_MINUS},
{".", love::keyboard::Keyboard::KEY_PERIOD},
{"/", love::keyboard::Keyboard::KEY_SLASH},
{"0", love::keyboard::Keyboard::KEY_0},
{"1", love::keyboard::Keyboard::KEY_1},
{"2", love::keyboard::Keyboard::KEY_2},
{"3", love::keyboard::Keyboard::KEY_3},
{"4", love::keyboard::Keyboard::KEY_4},
{"5", love::keyboard::Keyboard::KEY_5},
{"6", love::keyboard::Keyboard::KEY_6},
{"7", love::keyboard::Keyboard::KEY_7},
{"8", love::keyboard::Keyboard::KEY_8},
{"9", love::keyboard::Keyboard::KEY_9},
{":", love::keyboard::Keyboard::KEY_COLON},
{";", love::keyboard::Keyboard::KEY_SEMICOLON},
{"<", love::keyboard::Keyboard::KEY_LESS},
{"=", love::keyboard::Keyboard::KEY_EQUALS},
{">", love::keyboard::Keyboard::KEY_GREATER},
{"?", love::keyboard::Keyboard::KEY_QUESTION},
{"@", love::keyboard::Keyboard::KEY_AT},
{"[", love::keyboard::Keyboard::KEY_LEFTBRACKET},
{"\\", love::keyboard::Keyboard::KEY_BACKSLASH},
{"]", love::keyboard::Keyboard::KEY_RIGHTBRACKET},
{"^", love::keyboard::Keyboard::KEY_CARET},
{"_", love::keyboard::Keyboard::KEY_UNDERSCORE},
{"`", love::keyboard::Keyboard::KEY_BACKQUOTE},
{"a", love::keyboard::Keyboard::KEY_A},
{"b", love::keyboard::Keyboard::KEY_B},
{"c", love::keyboard::Keyboard::KEY_C},
{"d", love::keyboard::Keyboard::KEY_D},
{"e", love::keyboard::Keyboard::KEY_E},
{"f", love::keyboard::Keyboard::KEY_F},
{"g", love::keyboard::Keyboard::KEY_G},
{"h", love::keyboard::Keyboard::KEY_H},
{"i", love::keyboard::Keyboard::KEY_I},
{"j", love::keyboard::Keyboard::KEY_J},
{"k", love::keyboard::Keyboard::KEY_K},
{"l", love::keyboard::Keyboard::KEY_L},
{"m", love::keyboard::Keyboard::KEY_M},
{"n", love::keyboard::Keyboard::KEY_N},
{"o", love::keyboard::Keyboard::KEY_O},
{"p", love::keyboard::Keyboard::KEY_P},
{"q", love::keyboard::Keyboard::KEY_Q},
{"r", love::keyboard::Keyboard::KEY_R},
{"s", love::keyboard::Keyboard::KEY_S},
{"t", love::keyboard::Keyboard::KEY_T},
{"u", love::keyboard::Keyboard::KEY_U},
{"v", love::keyboard::Keyboard::KEY_V},
{"w", love::keyboard::Keyboard::KEY_W},
{"x", love::keyboard::Keyboard::KEY_X},
{"y", love::keyboard::Keyboard::KEY_Y},
{"z", love::keyboard::Keyboard::KEY_Z},
{"delete", love::keyboard::Keyboard::KEY_DELETE},
{"kp0", love::keyboard::Keyboard::KEY_KP0},
{"kp1", love::keyboard::Keyboard::KEY_KP1},
{"kp2", love::keyboard::Keyboard::KEY_KP2},
{"kp3", love::keyboard::Keyboard::KEY_KP3},
{"kp4", love::keyboard::Keyboard::KEY_KP4},
{"kp5", love::keyboard::Keyboard::KEY_KP5},
{"kp6", love::keyboard::Keyboard::KEY_KP6},
{"kp7", love::keyboard::Keyboard::KEY_KP7},
{"kp8", love::keyboard::Keyboard::KEY_KP8},
{"kp9", love::keyboard::Keyboard::KEY_KP9},
{"kp.", love::keyboard::Keyboard::KEY_KP_PERIOD},
{"kp/", love::keyboard::Keyboard::KEY_KP_DIVIDE},
{"kp*", love::keyboard::Keyboard::KEY_KP_MULTIPLY},
{"kp-", love::keyboard::Keyboard::KEY_KP_MINUS},
{"kp+", love::keyboard::Keyboard::KEY_KP_PLUS},
{"kpenter", love::keyboard::Keyboard::KEY_KP_ENTER},
{"kp=", love::keyboard::Keyboard::KEY_KP_EQUALS},
{"kpup", love::keyboard::Keyboard::KEY_UP},
{"kpdown", love::keyboard::Keyboard::KEY_DOWN},
{"kpright", love::keyboard::Keyboard::KEY_RIGHT},
{"kpleft", love::keyboard::Keyboard::KEY_LEFT},
{"kpinsert", love::keyboard::Keyboard::KEY_INSERT},
{"kphome", love::keyboard::Keyboard::KEY_HOME},
{"kpend", love::keyboard::Keyboard::KEY_END},
{"kppageup", love::keyboard::Keyboard::KEY_PAGEUP},
{"kppagedown", love::keyboard::Keyboard::KEY_PAGEDOWN},
{"f1", love::keyboard::Keyboard::KEY_F1},
{"f2", love::keyboard::Keyboard::KEY_F2},
{"f3", love::keyboard::Keyboard::KEY_F3},
{"f4", love::keyboard::Keyboard::KEY_F4},
{"f5", love::keyboard::Keyboard::KEY_F5},
{"f6", love::keyboard::Keyboard::KEY_F6},
{"f7", love::keyboard::Keyboard::KEY_F7},
{"f8", love::keyboard::Keyboard::KEY_F8},
{"f9", love::keyboard::Keyboard::KEY_F9},
{"f10", love::keyboard::Keyboard::KEY_F10},
{"f11", love::keyboard::Keyboard::KEY_F11},
{"f12", love::keyboard::Keyboard::KEY_F12},
{"f13", love::keyboard::Keyboard::KEY_F13},
{"f14", love::keyboard::Keyboard::KEY_F14},
{"f15", love::keyboard::Keyboard::KEY_F15},
{"numlock", love::keyboard::Keyboard::KEY_NUMLOCK},
{"capslock", love::keyboard::Keyboard::KEY_CAPSLOCK},
{"scrollock", love::keyboard::Keyboard::KEY_SCROLLOCK},
{"rshift", love::keyboard::Keyboard::KEY_RSHIFT},
{"lshift", love::keyboard::Keyboard::KEY_LSHIFT},
{"rctrl", love::keyboard::Keyboard::KEY_RCTRL},
{"lctrl", love::keyboard::Keyboard::KEY_LCTRL},
{"ralt", love::keyboard::Keyboard::KEY_RALT},
{"lalt", love::keyboard::Keyboard::KEY_LALT},
{"rmeta", love::keyboard::Keyboard::KEY_RMETA},
{"lmeta", love::keyboard::Keyboard::KEY_LMETA},
{"lsuper", love::keyboard::Keyboard::KEY_LSUPER},
{"rsuper", love::keyboard::Keyboard::KEY_RSUPER},
{"mode", love::keyboard::Keyboard::KEY_MODE},
{"compose", love::keyboard::Keyboard::KEY_COMPOSE},
{"help", love::keyboard::Keyboard::KEY_HELP},
{"print", love::keyboard::Keyboard::KEY_PRINT},
{"sysreq", love::keyboard::Keyboard::KEY_SYSREQ},
{"break", love::keyboard::Keyboard::KEY_BREAK},
{"menu", love::keyboard::Keyboard::KEY_MENU},
{"power", love::keyboard::Keyboard::KEY_POWER},
{"euro", love::keyboard::Keyboard::KEY_EURO},
{"undo", love::keyboard::Keyboard::KEY_UNDO},
};
StringMap<love::keyboard::Keyboard::Key, love::keyboard::Keyboard::KEY_MAX_ENUM> Event::keys(Event::keyEntries, sizeof(Event::keyEntries));
} // event
} // love
+58 -29
View File
@@ -23,6 +23,9 @@
// LOVE
#include <common/Module.h>
#include <common/StringMap.h>
#include <keyboard/Keyboard.h>
#include <mouse/Mouse.h>
namespace love
{
@@ -30,40 +33,66 @@ namespace event
{
class Event : public Module
{
protected:
virtual ~Event(){};
public:
enum
enum Type
{
EVENT_NOEVENT = 0,
EVENT_ACTIVEEVENT,
EVENT_KEYDOWN,
EVENT_KEYUP,
EVENT_MOUSEMOTION,
EVENT_MOUSEBUTTONDOWN,
EVENT_MOUSEBUTTONUP,
EVENT_JOYAXISMOTION,
EVENT_JOYBALLMOTION,
EVENT_JOYHATMOTION,
EVENT_JOYBUTTONDOWN,
EVENT_JOYBUTTONUP,
EVENT_QUIT,
EVENT_SYSWMEVENT,
EVENT_RESERVEDA,
EVENT_RESERVEDB,
EVENT_VIDEORESIZE,
EVENT_VIDEOEXPOSE,
EVENT_RESERVED2,
EVENT_RESERVED3,
EVENT_RESERVED4,
EVENT_RESERVED5,
EVENT_RESERVED6,
EVENT_RESERVED7,
EVENT_USEREVENT = 24,
EVENT_NUMEVENTS = 32
TYPE_INVALID,
TYPE_KEY_PRESSED,
TYPE_KEY_RELEASED,
TYPE_MOUSE_PRESSED,
TYPE_MOUSE_RELEASED,
TYPE_JOYSTICK_RELEASED,
TYPE_JOYSTICK_PRESSED,
TYPE_QUIT,
TYPE_MAX_ENUM = 32
};
union Message
{
Type type;
struct
{
Type type;
love::mouse::Mouse::Button b;
unsigned x;
unsigned y;
} mouse;
struct
{
Type type;
unsigned index;
unsigned button;
} joystick;
struct
{
Type type;
love::keyboard::Keyboard::Key k;
unsigned short u;
} keyboard;
};
virtual ~Event();
static bool getConstant(const char * in, Type & out);
static bool getConstant(Type in, const char *& out);
static bool getConstant(const char * in, love::mouse::Mouse::Button & out);
static bool getConstant(love::mouse::Mouse::Button in, const char *& out);
static bool getConstant(const char * in, love::keyboard::Keyboard::Key & out);
static bool getConstant(love::keyboard::Keyboard::Key in, const char *& out);
private:
static StringMap<Type, TYPE_MAX_ENUM>::Entry typeEntries[];
static StringMap<Type, TYPE_MAX_ENUM> types;
static StringMap<love::mouse::Mouse::Button, love::mouse::Mouse::BUTTON_MAX_ENUM>::Entry buttonEntries[];
static StringMap<love::mouse::Mouse::Button, love::mouse::Mouse::BUTTON_MAX_ENUM> buttons;
static StringMap<love::keyboard::Keyboard::Key, love::keyboard::Keyboard::KEY_MAX_ENUM>::Entry keyEntries[];
static StringMap<love::keyboard::Keyboard::Key, love::keyboard::Keyboard::KEY_MAX_ENUM> keys;
}; // Event
} // event
+230 -98
View File
@@ -20,6 +20,9 @@
#include "Event.h"
#include <keyboard/Keyboard.h>
#include <mouse/Mouse.h>
namespace love
{
namespace event
@@ -31,138 +34,267 @@ namespace sdl
return "love.event.sdl";
}
Event::Event()
{
SDL_EnableUNICODE(1);
}
void Event::pump()
{
SDL_PumpEvents();
}
int Event::poll(lua_State * L)
bool Event::poll(Message & message)
{
lua_pushcclosure(L, &poll_i, 0);
return 1;
}
int Event::wait(lua_State * L)
{
SDL_EnableUNICODE(1);
// The union used to get SDL events.
static SDL_Event e;
SDL_WaitEvent(&e);
return Event::pushEvent(L, e);
}
void Event::quit()
{
SDL_Event e;
e.type = Event::EVENT_QUIT;
SDL_PushEvent(&e);
}
int Event::push(lua_State * L)
{
SDL_Event e;
getEvent(L, e);
SDL_PushEvent(&e);
return 0;
}
int Event::poll_i(lua_State * L)
{
SDL_EnableUNICODE(1);
// The union used to get SDL events.
static SDL_Event e;
// Get ONE event.
while(SDL_PollEvent(&e))
{
int args = Event::pushEvent(L, e);
if(args > 0)
return args;
}
// No pending events.
return 0;
if(convert(e, message))
return true;
}
return false;
}
int Event::pushEvent(lua_State * L, SDL_Event & e)
bool Event::wait(Message & message)
{
static SDL_Event e;
bool ok = (SDL_WaitEvent(&e) == 1);
return ok && convert(e, message);
}
bool Event::push(Message & message)
{
static SDL_Event e;
bool ok = convert(message, e);
return ok && (SDL_PushEvent(&e) == 0);
}
bool Event::convert(SDL_Event & e, Message & m)
{
switch(e.type)
{
case SDL_KEYDOWN:
lua_pushinteger(L, e.type);
lua_pushinteger(L, e.key.keysym.sym);
lua_pushinteger(L, e.key.keysym.unicode);
return 3;
m.type = Event::TYPE_KEY_PRESSED;
m.keyboard.u = e.key.keysym.unicode;
return keys.find(e.key.keysym.sym, m.keyboard.k);
case SDL_KEYUP:
lua_pushinteger(L, e.type);
lua_pushinteger(L, e.key.keysym.sym);
return 2;
m.type = Event::TYPE_KEY_RELEASED;
return keys.find(e.key.keysym.sym, m.keyboard.k);
case SDL_MOUSEBUTTONDOWN:
case SDL_MOUSEBUTTONUP:
lua_pushinteger(L, e.type);
lua_pushinteger(L, e.button.x);
lua_pushinteger(L, e.button.y);
lua_pushinteger(L, e.button.button);
return 4;
m.type = (e.type == SDL_MOUSEBUTTONDOWN) ? Event::TYPE_MOUSE_PRESSED : Event::TYPE_MOUSE_RELEASED;
m.mouse.x = e.button.x;
m.mouse.y = e.button.y;
return buttons.find(e.button.button, m.mouse.b);
case SDL_JOYBUTTONDOWN:
case SDL_JOYBUTTONUP:
lua_pushinteger(L, e.type);
lua_pushinteger(L, e.jbutton.which);
lua_pushinteger(L, e.jbutton.button);
return 3;
m.type = (e.type == SDL_JOYBUTTONDOWN) ? Event::TYPE_JOYSTICK_PRESSED : Event::TYPE_JOYSTICK_RELEASED;
m.joystick.button = e.jbutton.button;
m.joystick.index = e.jbutton.which;
return true;
case SDL_QUIT:
lua_pushinteger(L, e.type);
return 1;
default:
break;
m.type = Event::TYPE_QUIT;
return true;
}
return 0;
return false;
}
int Event::getEvent(lua_State * L, SDL_Event & e)
bool Event::convert(Message & m, SDL_Event & e)
{
int type = luaL_checkint(L, 1);
switch(type)
switch(m.type)
{
case EVENT_KEYDOWN:
e.type = type;
e.key.keysym.sym = (SDLKey)luaL_checkint(L, 2);
e.key.keysym.unicode = luaL_checkint(L, 3);
return 3;
case EVENT_KEYUP:
e.type = type;
e.key.keysym.sym = (SDLKey)luaL_checkint(L, 2);
return 2;
case EVENT_MOUSEBUTTONDOWN:
case EVENT_MOUSEBUTTONUP:
e.type = type;
e.button.x = luaL_checkint(L, 2);
e.button.y = luaL_checkint(L, 3);
e.button.button = luaL_checkint(L, 4);
return 4;
case EVENT_JOYBUTTONDOWN:
case EVENT_JOYBUTTONUP:
e.type = type;
e.jbutton.which = luaL_checkint(L, 2);
e.jbutton.button = luaL_checkint(L, 3);
return 3;
case EVENT_QUIT:
e.type = type;
return 1;
default:
e.type = EVENT_NOEVENT;
break;
case Event::TYPE_KEY_PRESSED:
e.type = SDL_KEYDOWN;
e.key.keysym.unicode = (Uint16)m.keyboard.u;
return keys.find(m.keyboard.k, e.key.keysym.sym);;
case Event::TYPE_KEY_RELEASED:
e.type = SDL_KEYUP;
return keys.find(m.keyboard.k, e.key.keysym.sym);
case Event::TYPE_MOUSE_PRESSED:
case Event::TYPE_MOUSE_RELEASED:
e.type = (m.type == Event::TYPE_MOUSE_PRESSED) ? SDL_MOUSEBUTTONDOWN : SDL_MOUSEBUTTONUP;
e.button.x = m.mouse.x;
e.button.y = m.mouse.y;
return buttons.find(m.mouse.b, e.button.button);
case Event::TYPE_JOYSTICK_PRESSED:
case Event::TYPE_JOYSTICK_RELEASED:
e.type = (m.type == Event::TYPE_JOYSTICK_PRESSED) ? SDL_JOYBUTTONDOWN : SDL_JOYBUTTONUP;
e.jbutton.which = m.joystick.index;
e.jbutton.button = m.joystick.button;
return true;
case Event::TYPE_QUIT:
e.type = SDL_QUIT;
return true;
}
return 0;
return true;
}
EnumMap<love::keyboard::Keyboard::Key, SDLKey, love::keyboard::Keyboard::KEY_MAX_ENUM>::Entry Event::keyEntries[] =
{
{ love::keyboard::Keyboard::KEY_BACKSPACE, SDLK_BACKSPACE},
{ love::keyboard::Keyboard::KEY_TAB, SDLK_TAB},
{ love::keyboard::Keyboard::KEY_CLEAR, SDLK_CLEAR},
{ love::keyboard::Keyboard::KEY_RETURN, SDLK_RETURN},
{ love::keyboard::Keyboard::KEY_PAUSE, SDLK_PAUSE},
{ love::keyboard::Keyboard::KEY_ESCAPE, SDLK_ESCAPE },
{ love::keyboard::Keyboard::KEY_SPACE, SDLK_SPACE },
{ love::keyboard::Keyboard::KEY_EXCLAIM, SDLK_EXCLAIM },
{ love::keyboard::Keyboard::KEY_QUOTEDBL, SDLK_QUOTEDBL },
{ love::keyboard::Keyboard::KEY_HASH, SDLK_HASH },
{ love::keyboard::Keyboard::KEY_DOLLAR, SDLK_DOLLAR },
{ love::keyboard::Keyboard::KEY_AMPERSAND, SDLK_AMPERSAND },
{ love::keyboard::Keyboard::KEY_QUOTE, SDLK_QUOTE },
{ love::keyboard::Keyboard::KEY_LEFTPAREN, SDLK_LEFTPAREN },
{ love::keyboard::Keyboard::KEY_RIGHTPAREN, SDLK_RIGHTPAREN },
{ love::keyboard::Keyboard::KEY_ASTERISK, SDLK_ASTERISK },
{ love::keyboard::Keyboard::KEY_PLUS, SDLK_PLUS },
{ love::keyboard::Keyboard::KEY_COMMA, SDLK_COMMA },
{ love::keyboard::Keyboard::KEY_MINUS, SDLK_MINUS },
{ love::keyboard::Keyboard::KEY_PERIOD, SDLK_PERIOD },
{ love::keyboard::Keyboard::KEY_SLASH, SDLK_SLASH },
{ love::keyboard::Keyboard::KEY_0, SDLK_0 },
{ love::keyboard::Keyboard::KEY_1, SDLK_1 },
{ love::keyboard::Keyboard::KEY_2, SDLK_2 },
{ love::keyboard::Keyboard::KEY_3, SDLK_3 },
{ love::keyboard::Keyboard::KEY_4, SDLK_4 },
{ love::keyboard::Keyboard::KEY_5, SDLK_5 },
{ love::keyboard::Keyboard::KEY_6, SDLK_6 },
{ love::keyboard::Keyboard::KEY_7, SDLK_7 },
{ love::keyboard::Keyboard::KEY_8, SDLK_8 },
{ love::keyboard::Keyboard::KEY_9, SDLK_9 },
{ love::keyboard::Keyboard::KEY_COLON, SDLK_COLON },
{ love::keyboard::Keyboard::KEY_SEMICOLON, SDLK_SEMICOLON },
{ love::keyboard::Keyboard::KEY_LESS, SDLK_LESS },
{ love::keyboard::Keyboard::KEY_EQUALS, SDLK_EQUALS },
{ love::keyboard::Keyboard::KEY_GREATER, SDLK_GREATER },
{ love::keyboard::Keyboard::KEY_QUESTION, SDLK_QUESTION },
{ love::keyboard::Keyboard::KEY_AT, SDLK_AT },
{ love::keyboard::Keyboard::KEY_LEFTBRACKET, SDLK_LEFTBRACKET },
{ love::keyboard::Keyboard::KEY_BACKSLASH, SDLK_BACKSLASH },
{ love::keyboard::Keyboard::KEY_RIGHTBRACKET, SDLK_RIGHTBRACKET },
{ love::keyboard::Keyboard::KEY_CARET, SDLK_CARET },
{ love::keyboard::Keyboard::KEY_UNDERSCORE, SDLK_UNDERSCORE },
{ love::keyboard::Keyboard::KEY_BACKQUOTE, SDLK_BACKQUOTE },
{ love::keyboard::Keyboard::KEY_A, SDLK_a },
{ love::keyboard::Keyboard::KEY_B, SDLK_b },
{ love::keyboard::Keyboard::KEY_C, SDLK_c },
{ love::keyboard::Keyboard::KEY_D, SDLK_d },
{ love::keyboard::Keyboard::KEY_E, SDLK_e },
{ love::keyboard::Keyboard::KEY_F, SDLK_f },
{ love::keyboard::Keyboard::KEY_G, SDLK_g },
{ love::keyboard::Keyboard::KEY_H, SDLK_h },
{ love::keyboard::Keyboard::KEY_I, SDLK_i },
{ love::keyboard::Keyboard::KEY_J, SDLK_j },
{ love::keyboard::Keyboard::KEY_K, SDLK_k },
{ love::keyboard::Keyboard::KEY_L, SDLK_l },
{ love::keyboard::Keyboard::KEY_M, SDLK_m },
{ love::keyboard::Keyboard::KEY_N, SDLK_n },
{ love::keyboard::Keyboard::KEY_O, SDLK_o },
{ love::keyboard::Keyboard::KEY_P, SDLK_p },
{ love::keyboard::Keyboard::KEY_Q, SDLK_q },
{ love::keyboard::Keyboard::KEY_R, SDLK_r },
{ love::keyboard::Keyboard::KEY_S, SDLK_s },
{ love::keyboard::Keyboard::KEY_T, SDLK_t },
{ love::keyboard::Keyboard::KEY_U, SDLK_u },
{ love::keyboard::Keyboard::KEY_V, SDLK_v },
{ love::keyboard::Keyboard::KEY_W, SDLK_w },
{ love::keyboard::Keyboard::KEY_X, SDLK_x },
{ love::keyboard::Keyboard::KEY_Y, SDLK_y },
{ love::keyboard::Keyboard::KEY_Z, SDLK_z },
{ love::keyboard::Keyboard::KEY_DELETE, SDLK_DELETE },
{ love::keyboard::Keyboard::KEY_KP0, SDLK_KP0 },
{ love::keyboard::Keyboard::KEY_KP1, SDLK_KP1 },
{ love::keyboard::Keyboard::KEY_KP2, SDLK_KP2 },
{ love::keyboard::Keyboard::KEY_KP3, SDLK_KP3 },
{ love::keyboard::Keyboard::KEY_KP4, SDLK_KP4 },
{ love::keyboard::Keyboard::KEY_KP5, SDLK_KP5 },
{ love::keyboard::Keyboard::KEY_KP6, SDLK_KP6 },
{ love::keyboard::Keyboard::KEY_KP7, SDLK_KP7 },
{ love::keyboard::Keyboard::KEY_KP8, SDLK_KP8 },
{ love::keyboard::Keyboard::KEY_KP9, SDLK_KP9 },
{ love::keyboard::Keyboard::KEY_KP_PERIOD, SDLK_KP_PERIOD },
{ love::keyboard::Keyboard::KEY_KP_DIVIDE, SDLK_KP_DIVIDE },
{ love::keyboard::Keyboard::KEY_KP_MULTIPLY, SDLK_KP_MULTIPLY},
{ love::keyboard::Keyboard::KEY_KP_MINUS, SDLK_KP_MINUS },
{ love::keyboard::Keyboard::KEY_KP_PLUS, SDLK_KP_PLUS },
{ love::keyboard::Keyboard::KEY_KP_ENTER, SDLK_KP_ENTER },
{ love::keyboard::Keyboard::KEY_KP_EQUALS, SDLK_KP_EQUALS },
{ love::keyboard::Keyboard::KEY_UP, SDLK_UP },
{ love::keyboard::Keyboard::KEY_DOWN, SDLK_DOWN },
{ love::keyboard::Keyboard::KEY_RIGHT, SDLK_RIGHT },
{ love::keyboard::Keyboard::KEY_LEFT, SDLK_LEFT },
{ love::keyboard::Keyboard::KEY_INSERT, SDLK_INSERT },
{ love::keyboard::Keyboard::KEY_HOME, SDLK_HOME },
{ love::keyboard::Keyboard::KEY_END, SDLK_END },
{ love::keyboard::Keyboard::KEY_PAGEUP, SDLK_PAGEUP },
{ love::keyboard::Keyboard::KEY_PAGEDOWN, SDLK_PAGEDOWN },
{ love::keyboard::Keyboard::KEY_F1, SDLK_F1 },
{ love::keyboard::Keyboard::KEY_F2, SDLK_F2 },
{ love::keyboard::Keyboard::KEY_F3, SDLK_F3 },
{ love::keyboard::Keyboard::KEY_F4, SDLK_F4 },
{ love::keyboard::Keyboard::KEY_F5, SDLK_F5 },
{ love::keyboard::Keyboard::KEY_F6, SDLK_F6 },
{ love::keyboard::Keyboard::KEY_F7, SDLK_F7 },
{ love::keyboard::Keyboard::KEY_F8, SDLK_F8 },
{ love::keyboard::Keyboard::KEY_F9, SDLK_F9 },
{ love::keyboard::Keyboard::KEY_F10, SDLK_F10 },
{ love::keyboard::Keyboard::KEY_F11, SDLK_F11 },
{ love::keyboard::Keyboard::KEY_F12, SDLK_F12 },
{ love::keyboard::Keyboard::KEY_F13, SDLK_F13 },
{ love::keyboard::Keyboard::KEY_F14, SDLK_F14 },
{ love::keyboard::Keyboard::KEY_F15, SDLK_F15 },
{ love::keyboard::Keyboard::KEY_NUMLOCK, SDLK_NUMLOCK },
{ love::keyboard::Keyboard::KEY_CAPSLOCK, SDLK_CAPSLOCK },
{ love::keyboard::Keyboard::KEY_SCROLLOCK, SDLK_SCROLLOCK },
{ love::keyboard::Keyboard::KEY_RSHIFT, SDLK_RSHIFT },
{ love::keyboard::Keyboard::KEY_LSHIFT, SDLK_LSHIFT },
{ love::keyboard::Keyboard::KEY_RCTRL, SDLK_RCTRL },
{ love::keyboard::Keyboard::KEY_LCTRL, SDLK_LCTRL },
{ love::keyboard::Keyboard::KEY_RALT, SDLK_RALT },
{ love::keyboard::Keyboard::KEY_LALT, SDLK_LALT },
{ love::keyboard::Keyboard::KEY_RMETA, SDLK_RMETA },
{ love::keyboard::Keyboard::KEY_LMETA, SDLK_LMETA },
{ love::keyboard::Keyboard::KEY_LSUPER, SDLK_LSUPER },
{ love::keyboard::Keyboard::KEY_RSUPER, SDLK_RSUPER },
{ love::keyboard::Keyboard::KEY_MODE, SDLK_MODE },
{ love::keyboard::Keyboard::KEY_COMPOSE, SDLK_COMPOSE },
{ love::keyboard::Keyboard::KEY_HELP, SDLK_HELP },
{ love::keyboard::Keyboard::KEY_PRINT, SDLK_PRINT },
{ love::keyboard::Keyboard::KEY_SYSREQ, SDLK_SYSREQ },
{ love::keyboard::Keyboard::KEY_BREAK, SDLK_BREAK },
{ love::keyboard::Keyboard::KEY_MENU, SDLK_MENU },
{ love::keyboard::Keyboard::KEY_POWER, SDLK_POWER },
{ love::keyboard::Keyboard::KEY_EURO, SDLK_EURO },
{ love::keyboard::Keyboard::KEY_UNDO, SDLK_UNDO },
};
EnumMap<love::keyboard::Keyboard::Key, SDLKey, love::keyboard::Keyboard::KEY_MAX_ENUM> Event::keys(Event::keyEntries, sizeof(Event::keyEntries));
EnumMap<love::mouse::Mouse::Button, Uint8, love::mouse::Mouse::BUTTON_MAX_ENUM>::Entry Event::buttonEntries[] =
{
{ love::mouse::Mouse::BUTTON_LEFT, SDL_BUTTON_LEFT},
{ love::mouse::Mouse::BUTTON_MIDDLE, SDL_BUTTON_MIDDLE},
{ love::mouse::Mouse::BUTTON_RIGHT, SDL_BUTTON_RIGHT},
{ love::mouse::Mouse::BUTTON_WHEELUP, SDL_BUTTON_WHEELUP},
{ love::mouse::Mouse::BUTTON_WHEELDOWN, SDL_BUTTON_WHEELDOWN},
{ love::mouse::Mouse::BUTTON_X1, SDL_BUTTON_X1},
{ love::mouse::Mouse::BUTTON_X2, SDL_BUTTON_X2},
};
EnumMap<love::mouse::Mouse::Button, Uint8, love::mouse::Mouse::BUTTON_MAX_ENUM> Event::buttons(Event::buttonEntries, sizeof(Event::buttonEntries));
} // sdl
} // event
} // love
+27 -24
View File
@@ -24,6 +24,7 @@
// LOVE
#include <event/Event.h>
#include <common/runtime.h>
#include <common/EnumMap.h>
// SDL
#include <SDL.h>
@@ -34,13 +35,15 @@ namespace event
{
namespace sdl
{
class Event : public event::Event
class Event : public love::event::Event
{
public:
// Implements Module.
const char * getName() const;
Event();
/**
* Pumps the event queue. This function gathers all the pending input information
* from devices and places it on the event queue. Normally not needed if you poll
@@ -48,38 +51,38 @@ namespace sdl
**/
void pump();
/**
* Returns an iterator function for iterating over pending events.
/**
* Checks if there are messages in the queue.
*
* @param message The next message in the queue, if the return value is true.
* @return True if there a message was found, false otherwise.
**/
int poll(lua_State * L);
bool poll(Message & message);
/**
* Waits for the next event (indefinitely). Useful for creating games where
* the screen and game state only needs updating when the user interacts with
* the window.
**/
int wait(lua_State * L);
bool wait(Message & message);
/**
* Push a message onto the event queue.
*
* @param message The message to push onto the queue.
* @return True on success, false if the queue was full.
**/
bool push(Message & message);
/**
* Push a quit event. Calling this does not mean the application
* will exit immediately, it just means an quit event will be issued.
* How to respond to the quit event is up the application.
**/
void quit();
/**
* Pushes an event into the queue.
**/
int push(lua_State * L);
/**
* The iterator function.
**/
static int poll_i(lua_State * L);
private:
static int pushEvent(lua_State * L, SDL_Event & e);
static int getEvent(lua_State * L, SDL_Event & e);
bool convert(SDL_Event & e, Message & m);
bool convert(Message & m, SDL_Event & e);
static EnumMap<love::keyboard::Keyboard::Key, SDLKey, love::keyboard::Keyboard::KEY_MAX_ENUM>::Entry keyEntries[];
static EnumMap<love::keyboard::Keyboard::Key, SDLKey, love::keyboard::Keyboard::KEY_MAX_ENUM> keys;
static EnumMap<love::mouse::Mouse::Button, Uint8, love::mouse::Mouse::BUTTON_MAX_ENUM>::Entry buttonEntries[];
static EnumMap<love::mouse::Mouse::Button, Uint8, love::mouse::Mouse::BUTTON_MAX_ENUM> buttons;
}; // System
+113 -21
View File
@@ -34,6 +34,100 @@ namespace sdl
{
static Event * instance = 0;
static bool to_message(lua_State * L, Event::Message & msg)
{
const char * str = luaL_checkstring(L, 1);
if(!Event::getConstant(str, msg.type))
return false;
switch(msg.type)
{
case Event::TYPE_KEY_PRESSED:
if(!Event::getConstant(luaL_checkstring(L, 2), msg.keyboard.k))
return false;
msg.keyboard.u = (unsigned short)luaL_optint(L, 3, 0);
return true;
case Event::TYPE_KEY_RELEASED:
if(!Event::getConstant(luaL_checkstring(L, 2), msg.keyboard.k))
return false;
return true;
case Event::TYPE_MOUSE_PRESSED:
case Event::TYPE_MOUSE_RELEASED:
if(!Event::getConstant(luaL_checkstring(L, 2), msg.mouse.b))
return false;
msg.mouse.x = luaL_checkint(L, 3);
msg.mouse.y = luaL_checkint(L, 4);
return true;
case Event::TYPE_JOYSTICK_PRESSED:
case Event::TYPE_JOYSTICK_RELEASED:
msg.joystick.index = luaL_checkint(L, 2);
msg.joystick.button = luaL_checkint(L, 3);
return true;
case Event::TYPE_QUIT:
return true;
}
return false;
}
static int push_message(lua_State * L, const Event::Message & msg)
{
const char * str = 0;
if(!Event::getConstant(msg.type, str))
return 0;
lua_pushstring(L, str);
switch(msg.type)
{
case Event::TYPE_KEY_PRESSED:
if(!Event::getConstant(msg.keyboard.k, str))
return 0;
lua_pushstring(L, str);
lua_pushinteger(L, msg.keyboard.u);
return 3;
case Event::TYPE_KEY_RELEASED:
if(!Event::getConstant(msg.keyboard.k, str))
return 0;
lua_pushstring(L, str);
return 2;
case Event::TYPE_MOUSE_PRESSED:
case Event::TYPE_MOUSE_RELEASED:
if(!Event::getConstant(msg.mouse.b, str))
return 0;
lua_pushinteger(L, msg.mouse.x);
lua_pushinteger(L, msg.mouse.y);
lua_pushstring(L, str);
return 4;
case Event::TYPE_JOYSTICK_PRESSED:
case Event::TYPE_JOYSTICK_RELEASED:
lua_pushinteger(L, msg.joystick.index);
lua_pushinteger(L, msg.joystick.button);
return 3;
case Event::TYPE_QUIT:
return 1;
}
return 0;
}
static int poll_i(lua_State * L)
{
static Event::Message m;
while(instance->poll(m))
{
int args = push_message(L, m);
if(args > 0)
return args;
}
// No pending events.
return 0;
}
int w_pump(lua_State * L)
{
instance->pump();
@@ -42,23 +136,35 @@ namespace sdl
int w_poll(lua_State * L)
{
return instance->poll(L);
lua_pushcclosure(L, &poll_i, 0);
return 1;
}
int w_wait(lua_State * L)
{
return instance->wait(L);
}
static Event::Message m;
if(instance->wait(m))
{
return push_message(L, m);
}
int w_quit(lua_State * L)
{
instance->quit();
return 0;
}
int w_push(lua_State * L)
{
return instance->push(L);
static Event::Message m;
if(!to_message(L, m))
{
luax_pushboolean(L, false);
return 1;
}
luax_pushboolean(L, instance->push(m));
return 1;
}
// List of functions to wrap.
@@ -66,23 +172,10 @@ namespace sdl
{ "pump", w_pump },
{ "poll", w_poll },
{ "wait", w_wait },
{ "quit", w_quit },
{ "push", w_push },
{ 0, 0 }
};
// List of constants.
static const Constant constants[] = {
{ "event_keypressed", Event::EVENT_KEYDOWN },
{ "event_keyreleased", Event::EVENT_KEYUP },
{ "event_mousepressed", Event::EVENT_MOUSEBUTTONDOWN },
{ "event_mousereleased", Event::EVENT_MOUSEBUTTONUP },
{ "event_joystickpressed", Event::EVENT_JOYBUTTONDOWN },
{ "event_joystickreleased", Event::EVENT_JOYBUTTONUP },
{ "event_quit", Event::EVENT_QUIT },
{ 0, 0 }
};
int luaopen_love_event(lua_State * L)
{
if(instance == 0)
@@ -103,7 +196,6 @@ namespace sdl
w.flags = MODULE_T;
w.functions = functions;
w.types = 0;
w.constants = constants;
return luax_register_module(L, w);
}
-1
View File
@@ -34,7 +34,6 @@ namespace sdl
int w_pump(lua_State * L);
int w_poll(lua_State * L);
int w_wait(lua_State * L);
int w_quit(lua_State * L);
int w_push(lua_State * L);
extern "C" LOVE_EXPORT int luaopen_love_event(lua_State * L);
@@ -18,40 +18,35 @@
* 3. This notice may not be removed or altered from any source distribution.
**/
#ifndef LOVE_SIGNAL_POSIX_SIGNAL_H
#define LOVE_SIGNAL_POSIX_SIGNAL_H
// signal
#include <csignal>
// LOVE
#include <common/Module.h>
#include <common/Reference.h>
#include "File.h"
namespace love
{
namespace signal
namespace filesystem
{
namespace posix
{
class Signal : public Module
File::~File()
{
private:
int signals;
}
bool File::getConstant(const char * in, Mode & out)
{
return modes.find(in, out);
}
bool File::getConstant(Mode in, const char *& out)
{
return modes.find(in, out);
}
StringMap<File::Mode, File::MODE_MAX_ENUM>::Entry File::modeEntries[] =
{
{"c", File::CLOSED},
{"r", File::READ},
{"w", File::WRITE},
{"w+", File::APPEND},
};
StringMap<File::Mode, File::MODE_MAX_ENUM> File::modes(File::modeEntries, sizeof(File::modeEntries));
public:
Signal();
~Signal();
bool hook(int sgn);
void setCallback(lua_State *L);
const char * getName() const;
bool raise(int sgn);
}; // Signal
void handler(int signal);
static Reference *cb;
} // posix
} // signal
} // filesystem
} // love
#endif // LOVE_SIGNAL_POSIX_SIGNAL_H
+11 -1
View File
@@ -27,6 +27,7 @@
// LOVE
#include <common/Data.h>
#include <common/Object.h>
#include <common/StringMap.h>
namespace love
{
@@ -49,6 +50,7 @@ namespace filesystem
READ,
WRITE,
APPEND,
MODE_MAX_ENUM
};
/**
@@ -59,7 +61,7 @@ namespace filesystem
/**
* Destructor.
**/
virtual ~File(){};
virtual ~File();
/**
* Opens the file in a certain mode.
@@ -158,6 +160,14 @@ namespace filesystem
**/
virtual std::string getExtension() const = 0;
static bool getConstant(const char * in, Mode & out);
static bool getConstant(Mode in, const char *& out);
private:
static StringMap<Mode, MODE_MAX_ENUM>::Entry modeEntries[];
static StringMap<Mode, MODE_MAX_ENUM> modes;
}; // File
} // filesystem
+4 -4
View File
@@ -21,7 +21,7 @@
#include "File.h"
// STD
#include <string.h>
#include <cstring>
// LOVE
#include "Filesystem.h"
@@ -46,6 +46,9 @@ namespace physfs
bool File::open(Mode mode)
{
if(mode == CLOSED)
return true;
// File must exist if read mode.
if((mode == READ))
if(!PHYSFS_exists(filename.c_str()))
@@ -73,9 +76,6 @@ namespace physfs
case WRITE:
file = PHYSFS_openWrite(filename.c_str());
break;
case CLOSED:
// Heh. Case closed.
return true;
}
return (file != 0);
+5 -2
View File
@@ -44,11 +44,14 @@ namespace physfs
int w_File_open(lua_State * L)
{
File * file = luax_checkfile(L, 1);
int mode = luaL_optint(L, 2, File::READ);
File::Mode mode;
if(!File::getConstant(luaL_checkstring(L, 2), mode))
return luaL_error(L, "Incorrect file open mode: %s", luaL_checkstring(L, 2));
try
{
lua_pushboolean(L, file->open((File::Mode)mode) ? 1 : 0);
lua_pushboolean(L, file->open(mode) ? 1 : 0);
}
catch(Exception e)
{
@@ -265,15 +265,6 @@ namespace physfs
0
};
// List of constants.
static const Constant constants[] = {
{ "file_closed", File::CLOSED },
{ "file_read", File::READ },
{ "file_write", File::WRITE },
{ "file_append", File::APPEND },
{ 0, 0 }
};
int luaopen_love_filesystem(lua_State * L)
{
if(instance == 0)
@@ -295,7 +286,6 @@ namespace physfs
w.flags = MODULE_FILESYSTEM_T;
w.functions = functions;
w.types = types;
w.constants = constants;
return luax_register_module(L, w);
}
-1
View File
@@ -86,7 +86,6 @@ namespace freetype
w.flags = MODULE_T;
w.functions = functions;
w.types = types;
w.constants = 0;
return luax_register_module(L, w);
}
+141
View File
@@ -0,0 +1,141 @@
/**
* Copyright (c) 2006-2009 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
**/
#include "Graphics.h"
namespace love
{
namespace graphics
{
Graphics::~Graphics()
{
}
bool Graphics::getConstant(const char * in, DrawMode & out)
{
return drawModes.find(in, out);
}
bool Graphics::getConstant(DrawMode in, const char *& out)
{
return drawModes.find(in, out);
}
bool Graphics::getConstant(const char * in, AlignMode & out)
{
return alignModes.find(in, out);
}
bool Graphics::getConstant(AlignMode in, const char *& out)
{
return alignModes.find(in, out);
}
bool Graphics::getConstant(const char * in, BlendMode & out)
{
return blendModes.find(in, out);
}
bool Graphics::getConstant(BlendMode in, const char *& out)
{
return blendModes.find(in, out);
}
bool Graphics::getConstant(const char * in, ColorMode & out)
{
return colorModes.find(in, out);
}
bool Graphics::getConstant(ColorMode in, const char *& out)
{
return colorModes.find(in, out);
}
bool Graphics::getConstant(const char * in, LineStyle & out)
{
return lineStyles.find(in, out);
}
bool Graphics::getConstant(LineStyle in, const char *& out)
{
return lineStyles.find(in, out);
}
bool Graphics::getConstant(const char * in, PointStyle & out)
{
return pointStyles.find(in, out);
}
bool Graphics::getConstant(PointStyle in, const char *& out)
{
return pointStyles.find(in, out);
}
StringMap<Graphics::DrawMode, Graphics::DRAW_MAX_ENUM>::Entry Graphics::drawModeEntries[] =
{
{ "line", Graphics::DRAW_LINE },
{ "fill", Graphics::DRAW_FILL },
};
StringMap<Graphics::DrawMode, Graphics::DRAW_MAX_ENUM> Graphics::drawModes(Graphics::drawModeEntries, sizeof(Graphics::drawModeEntries));
StringMap<Graphics::AlignMode, Graphics::ALIGN_MAX_ENUM>::Entry Graphics::alignModeEntries[] =
{
{ "left", Graphics::ALIGN_LEFT },
{ "right", Graphics::ALIGN_RIGHT },
{ "center", Graphics::ALIGN_CENTER },
};
StringMap<Graphics::AlignMode, Graphics::ALIGN_MAX_ENUM> Graphics::alignModes(Graphics::alignModeEntries, sizeof(Graphics::alignModeEntries));
StringMap<Graphics::BlendMode, Graphics::BLEND_MAX_ENUM>::Entry Graphics::blendModeEntries[] =
{
{ "alpha", Graphics::BLEND_ALPHA },
{ "additive", Graphics::BLEND_ADDITIVE },
};
StringMap<Graphics::BlendMode, Graphics::BLEND_MAX_ENUM> Graphics::blendModes(Graphics::blendModeEntries, sizeof(Graphics::blendModeEntries));
StringMap<Graphics::ColorMode, Graphics::COLOR_MAX_ENUM>::Entry Graphics::colorModeEntries[] =
{
{ "replace", Graphics::COLOR_REPLACE },
{ "modulate", Graphics::COLOR_MODULATE },
};
StringMap<Graphics::ColorMode, Graphics::COLOR_MAX_ENUM> Graphics::colorModes(Graphics::colorModeEntries, sizeof(Graphics::colorModeEntries));
StringMap<Graphics::LineStyle, Graphics::LINE_MAX_ENUM>::Entry Graphics::lineStyleEntries[] =
{
{ "smooth", Graphics::LINE_SMOOTH },
{ "rough", Graphics::LINE_ROUGH }
};
StringMap<Graphics::LineStyle, Graphics::LINE_MAX_ENUM> Graphics::lineStyles(Graphics::lineStyleEntries, sizeof(Graphics::lineStyleEntries));
StringMap<Graphics::PointStyle, Graphics::POINT_MAX_ENUM>::Entry Graphics::pointStyleEntries[] =
{
{ "smooth", Graphics::POINT_SMOOTH },
{ "rough", Graphics::POINT_ROUGH }
};
StringMap<Graphics::PointStyle, Graphics::POINT_MAX_ENUM> Graphics::pointStyles(Graphics::pointStyleEntries, sizeof(Graphics::pointStyleEntries));
} // graphics
} // love
+59 -14
View File
@@ -23,6 +23,7 @@
// LOVE
#include <common/Module.h>
#include <common/StringMap.h>
namespace love
{
@@ -34,43 +35,87 @@ namespace graphics
enum DrawMode
{
DRAW_LINE,
DRAW_FILL
DRAW_LINE = 1,
DRAW_FILL,
DRAW_MAX_ENUM
};
enum AlignMode
{
ALIGN_LEFT,
ALIGN_LEFT = 1,
ALIGN_CENTER,
ALIGN_RIGHT
ALIGN_RIGHT,
ALIGN_MAX_ENUM
};
enum BlendMode
{
BLEND_ALPHA,
BLEND_ADDITIVE
BLEND_ALPHA = 1,
BLEND_ADDITIVE,
BLEND_MAX_ENUM
};
enum ColorMode
{
COLOR_MODULATE,
COLOR_REPLACE
COLOR_MODULATE = 1,
COLOR_REPLACE,
COLOR_MAX_ENUM
};
enum LineStyle
{
LINE_ROUGH,
LINE_SMOOTH
LINE_ROUGH = 1,
LINE_SMOOTH,
LINE_MAX_ENUM
};
enum PointStyle
{
POINT_ROUGH,
POINT_SMOOTH
POINT_ROUGH = 1,
POINT_SMOOTH,
POINT_MAX_ENUM
};
virtual ~Graphics(){};
virtual ~Graphics();
static bool getConstant(const char * in, DrawMode & out);
static bool getConstant(DrawMode in, const char *& out);
static bool getConstant(const char * in, AlignMode & out);
static bool getConstant(AlignMode in, const char *& out);
static bool getConstant(const char * in, BlendMode & out);
static bool getConstant(BlendMode in, const char *& out);
static bool getConstant(const char * in, ColorMode & out);
static bool getConstant(ColorMode in, const char *& out);
static bool getConstant(const char * in, LineStyle & out);
static bool getConstant(LineStyle in, const char *& out);
static bool getConstant(const char * in, PointStyle & out);
static bool getConstant(PointStyle in, const char *& out);
private:
static StringMap<DrawMode, DRAW_MAX_ENUM>::Entry drawModeEntries[];
static StringMap<DrawMode, DRAW_MAX_ENUM> drawModes;
static StringMap<AlignMode, ALIGN_MAX_ENUM>::Entry alignModeEntries[];
static StringMap<AlignMode, ALIGN_MAX_ENUM> alignModes;
static StringMap<BlendMode, BLEND_MAX_ENUM>::Entry blendModeEntries[];
static StringMap<BlendMode, BLEND_MAX_ENUM> blendModes;
static StringMap<ColorMode, COLOR_MAX_ENUM>::Entry colorModeEntries[];
static StringMap<ColorMode, COLOR_MAX_ENUM> colorModes;
static StringMap<LineStyle, LINE_MAX_ENUM>::Entry lineStyleEntries[];
static StringMap<LineStyle, LINE_MAX_ENUM> lineStyles;
static StringMap<PointStyle, POINT_MAX_ENUM>::Entry pointStyleEntries[];
static StringMap<PointStyle, POINT_MAX_ENUM> pointStyles;
}; // Graphics
} // graphics
+24 -152
View File
@@ -38,7 +38,7 @@ namespace opengl
currentMode.width = 0;
currentMode.height = 0;
// Windows should be centered.
// Window should be centered.
SDL_putenv("SDL_VIDEO_CENTERED=center");
if(SDL_InitSubSystem(SDL_INIT_VIDEO) < 0)
@@ -511,7 +511,7 @@ namespace opengl
return currentFont;
}
void Graphics::setBlendMode( int mode )
void Graphics::setBlendMode( Graphics::BlendMode mode )
{
if(mode == BLEND_ADDITIVE)
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
@@ -519,7 +519,7 @@ namespace opengl
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
void Graphics::setColorMode ( int mode )
void Graphics::setColorMode ( Graphics::ColorMode mode )
{
if(mode == COLOR_MODULATE)
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
@@ -527,7 +527,7 @@ namespace opengl
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
}
int Graphics::getBlendMode()
Graphics::BlendMode Graphics::getBlendMode()
{
GLint dst, src;
glGetIntegerv(GL_BLEND_DST, &dst);
@@ -539,7 +539,7 @@ namespace opengl
return BLEND_ALPHA;
}
int Graphics::getColorMode()
Graphics::ColorMode Graphics::getColorMode()
{
GLint mode;
glGetTexEnviv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, &mode);
@@ -555,7 +555,7 @@ namespace opengl
glLineWidth(width);
}
void Graphics::setLineStyle( int style )
void Graphics::setLineStyle(Graphics::LineStyle style )
{
if(style == LINE_ROUGH)
glDisable (GL_LINE_SMOOTH);
@@ -566,7 +566,7 @@ namespace opengl
}
}
void Graphics::setLine( float width, int style )
void Graphics::setLine( float width, Graphics::LineStyle style )
{
glLineWidth(width);
@@ -600,7 +600,7 @@ namespace opengl
return w;
}
int Graphics::getLineStyle()
Graphics::LineStyle Graphics::getLineStyle()
{
if(glIsEnabled(GL_LINE_SMOOTH) == GL_TRUE)
return LINE_SMOOTH;
@@ -626,7 +626,7 @@ namespace opengl
glPointSize((GLfloat)size);
}
void Graphics::setPointStyle( int style )
void Graphics::setPointStyle( Graphics::PointStyle style )
{
if( style == POINT_SMOOTH )
glEnable(GL_POINT_SMOOTH);
@@ -634,7 +634,7 @@ namespace opengl
glDisable(GL_POINT_SMOOTH);
}
void Graphics::setPoint( float size, int style )
void Graphics::setPoint( float size, Graphics::PointStyle style )
{
if( style == POINT_SMOOTH )
glEnable(GL_POINT_SMOOTH);
@@ -651,7 +651,7 @@ namespace opengl
return (float)size;
}
int Graphics::getPointStyle()
Graphics::PointStyle Graphics::getPointStyle()
{
if(glIsEnabled(GL_POINT_SMOOTH) == GL_TRUE)
return POINT_SMOOTH;
@@ -724,7 +724,7 @@ namespace opengl
}
}
void Graphics::printf( const char * str, float x, float y, float wrap, int align)
void Graphics::printf( const char * str, float x, float y, float wrap, AlignMode align)
{
if(currentFont != 0)
{
@@ -846,13 +846,13 @@ namespace opengl
glEnable(GL_TEXTURE_2D);
}
void Graphics::triangle( int type, float x1, float y1, float x2, float y2, float x3, float y3 )
void Graphics::triangle(DrawMode mode, float x1, float y1, float x2, float y2, float x3, float y3 )
{
glDisable(GL_CULL_FACE);
glDisable(GL_TEXTURE_2D);
glPushMatrix();
switch(type)
switch(mode)
{
case DRAW_LINE:
glBegin(GL_LINE_LOOP);
@@ -877,12 +877,12 @@ namespace opengl
glEnable(GL_CULL_FACE);
}
void Graphics::rectangle( int type, float x, float y, float w, float h )
void Graphics::rectangle(DrawMode mode, float x, float y, float w, float h )
{
glDisable(GL_TEXTURE_2D);
glPushMatrix();
switch(type)
switch(mode)
{
case DRAW_LINE:
glBegin(GL_LINE_LOOP);
@@ -908,13 +908,13 @@ namespace opengl
glEnable(GL_TEXTURE_2D);
}
void Graphics::quad( int type, float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4 )
void Graphics::quad(DrawMode mode, float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4 )
{
glDisable(GL_CULL_FACE);
glDisable(GL_TEXTURE_2D);
glPushMatrix();
switch(type)
switch(mode)
{
case DRAW_LINE:
glBegin(GL_LINE_LOOP);
@@ -941,7 +941,7 @@ namespace opengl
glEnable(GL_CULL_FACE);
}
void Graphics::circle( int type, float x, float y, float radius, int points )
void Graphics::circle(DrawMode mode, float x, float y, float radius, int points )
{
float two_pi = 3.14159265f * 2;
if(points <= 0) points = 1;
@@ -952,7 +952,7 @@ namespace opengl
glTranslatef(x, y, 0.0f);
switch(type)
switch(mode)
{
case DRAW_LINE:
glBegin(GL_LINE_LOOP);
@@ -987,12 +987,11 @@ namespace opengl
if( n < 2 )
return luaL_error(L, "Error: function needs at least two parameters.");
// The first one MUST be a number.
if( !lua_isnumber(L, 1) )
return luaL_error(L, "Error: first parameter must be a number.");
DrawMode mode;
// Get rendering mode. (line/fill)
int mode = (int)lua_tonumber(L, 1);
const char * str = luaL_checkstring(L, 1);
if(!getConstant(str, mode))
return luaL_error(L, "Invalid draw mode: %s", str);
// Get the type of the second argument.
int luatype = lua_type(L, 2);
@@ -1046,133 +1045,6 @@ namespace opengl
return 0;
}
int Graphics::polygong( lua_State * L )
{
// Get number of params.
int n = lua_gettop(L);
// Need at least two params.
if( n < 2 )
return luaL_error(L, "Error: function needs at least two parameters.");
// The first one MUST be a number.
if( !lua_isnumber(L, 1) )
return luaL_error(L, "Error: first parameter must be a number.");
int vertc = 0, colorc = 0;
if( n == 3 )
{
if((!lua_istable(L, 2) || !lua_istable(L, 3)))
return luaL_error(L, "Error: two tables expected.");
vertc = (int)lua_objlen(L, 2);
colorc = (int)lua_objlen(L, 3);
if( (vertc <= 0 || colorc <= 0))
return luaL_error(L, "Error: empty table.");
}
// Get rendering mode. (line/fill)
int mode = (int)lua_tonumber(L, 1);
GLenum glmode = (mode==DRAW_LINE) ? GL_LINE_LOOP : GL_POLYGON;
// Get the type of the second argument.
int luatype = lua_type(L, 2);
if(!(luatype == LUA_TTABLE || luatype == LUA_TNUMBER))
return luaL_error(L, "Error: expected number or table values.");
glPushAttrib(GL_CURRENT_BIT);
glDisable(GL_CULL_FACE);
glDisable(GL_TEXTURE_2D);
switch(luatype)
{
case LUA_TTABLE:
if( n == 2 )
{
glBegin(glmode);
lua_pushnil(L);
while(true)
{
if(lua_next(L, 2) == 0) break;
GLfloat x = (GLfloat)lua_tonumber(L, -1);
lua_pop(L, 1);
if(lua_next(L, 2) == 0) break;
GLfloat y = (GLfloat)lua_tonumber(L, -1);
lua_pop(L, 1);
if(lua_next(L, 2) == 0) break;
GLubyte r = (GLubyte)lua_tonumber(L, -1);
lua_pop(L, 1);
if(lua_next(L, 2) == 0) break;
GLubyte g = (GLubyte)lua_tonumber(L, -1);
lua_pop(L, 1);
if(lua_next(L, 2) == 0) break;
GLubyte b = (GLubyte)lua_tonumber(L, -1);
lua_pop(L, 1);
if(lua_next(L, 2) == 0) break;
GLubyte a = (GLubyte)lua_tonumber(L, -1);
lua_pop(L, 1);
glColor4ub(r, g, b, a);
glVertex2f(x, y);
}
glEnd();
}
else if(n == 3)
{
// Allocate memory.
GLfloat * verts = new GLfloat[vertc];
GLubyte * colors = new GLubyte[colorc];
int verti = 0, colori = 0;
// Get verts.
lua_pushnil(L);
while(lua_next(L, 2))
{
verts[verti++] = (GLfloat)lua_tonumber(L, -1);
lua_pop(L, 1);
}
// Get colors.
lua_pushnil(L);
while(lua_next(L, 3))
{
colors[colori++] = (GLubyte)lua_tonumber(L, -1);
lua_pop(L, 1);
}
glEnable(GL_VERTEX_ARRAY);
glEnable(GL_COLOR_ARRAY);
glColorPointer(4, GL_UNSIGNED_BYTE, 0, colors);
glVertexPointer(2, GL_FLOAT, 0, verts);
glDrawArrays(glmode, 0, (GLint)(vertc/2));
glDisable(GL_VERTEX_ARRAY);
glDisable(GL_COLOR_ARRAY);
delete [] verts;
delete [] colors;
}
break;
case LUA_TNUMBER:
// Assume params to be packed like this: x, y, r, g, b, a, x, y, r, ...
glBegin(glmode);
for(int i = 2; i < (n-1); i+=6)
{
glColor4ub((GLubyte)lua_tonumber(L, i+2), (GLubyte)lua_tonumber(L, i+3), (GLubyte)lua_tonumber(L, i+4), (GLubyte)lua_tonumber(L, i+5));
glVertex2f((GLfloat)lua_tonumber(L, i), (GLfloat)lua_tonumber(L, i+1));
}
glEnd();
break;
}
glEnable(GL_CULL_FACE);
glEnable(GL_TEXTURE_2D);
glPopAttrib();
return 0;
}
love::image::ImageData * Graphics::newScreenshot(love::image::Image * image)
{
int w = getWidth();
+30 -30
View File
@@ -284,7 +284,7 @@ namespace opengl
* Sets the current font.
* @parm font A Font object.
**/
void setFont( Font * font );
void setFont(Font * font);
/**
* Sets a default font. The font is
@@ -293,7 +293,7 @@ namespace opengl
* @param data Data
* @param size The size of the font.
**/
void setFont( Data * data, int size = 12);
void setFont(Data * data, int size = 12);
/**
* Gets the current Font, or nil if none.
@@ -303,40 +303,40 @@ namespace opengl
/**
* Sets the current blend mode.
**/
void setBlendMode( int mode );
void setBlendMode(BlendMode mode);
/**
* Sets the current color mode.
**/
void setColorMode ( int mode );
void setColorMode (ColorMode mode);
/**
* Gets the current blend mode.
**/
int getBlendMode();
BlendMode getBlendMode();
/**
* Gets the current color mode.
**/
int getColorMode();
ColorMode getColorMode();
/**
* Sets the line width.
* @param width The new width of the line.
**/
void setLineWidth( float width );
void setLineWidth(float width);
/**
* Sets the line style.
* @param style LINE_ROUGH or LINE_SMOOTH.
**/
void setLineStyle( int style );
void setLineStyle(LineStyle style);
/**
* Sets the type of line used to draw primitives.
* A shorthand for setLineWidth and setLineStyle.
**/
void setLine( float width, int style = 0 );
void setLine(float width, LineStyle style);
/**
* Disables line stippling.
@@ -356,7 +356,7 @@ namespace opengl
/**
* Gets the line style.
**/
int getLineStyle();
LineStyle getLineStyle();
/**
* Gets the line stipple pattern and repeat factor.
@@ -368,18 +368,18 @@ namespace opengl
/**
* Sets the size of points.
**/
void setPointSize( float size );
void setPointSize(float size);
/**
* Sets the style of points.
* @param style POINT_SMOOTH or POINT_ROUGH.
**/
void setPointStyle( int style );
void setPointStyle(PointStyle style);
/**
* Shorthand for setPointSize and setPointStyle.
**/
void setPoint( float size, int style );
void setPoint(float size, PointStyle style);
/**
* Gets the point size.
@@ -389,7 +389,7 @@ namespace opengl
/**
* Gets the point style.
**/
int getPointStyle();
PointStyle getPointStyle();
/**
* Gets the maximum point size supported.
@@ -404,7 +404,7 @@ namespace opengl
* @param x The x-coordiante.
* @param y The y-coordiante.
**/
void print( const char * str, float x, float y );
void print(const char * str, float x, float y);
/**
* Draws text at the specified coordinates, with rotation.
@@ -412,7 +412,7 @@ namespace opengl
* @param y The y-coordinate.
* @param angle The amount of rotation.
**/
void print( const char * str, float x, float y , float angle );
void print(const char * str, float x, float y , float angle);
/**
* Draws text at the specified coordinates, with rotation and
@@ -422,7 +422,7 @@ namespace opengl
* @param angle The amount of rotation.
* @param s The scale factor. (1 = normal).
**/
void print( const char * str, float x, float y , float angle, float s );
void print(const char * str, float x, float y , float angle, float s);
/**
* Draws text at the specified coordinates, with rotation and
@@ -433,7 +433,7 @@ namespace opengl
* @param sx The scale factor along the x-axis. (1 = normal).
* @param sy The scale factor along the y-axis. (1 = normal).
**/
void print( const char * str, float x, float y , float angle, float sx, float sy);
void print(const char * str, float x, float y , float angle, float sx, float sy);
/**
* Draw formatted text on screen at the specified coordinates.
@@ -444,14 +444,14 @@ namespace opengl
* @param wrap The maximum width of the text area.
* @param align Where to align the text.
**/
void printf( const char * str, float x, float y, float wrap, int align = 0 );
void printf(const char * str, float x, float y, float wrap, AlignMode align);
/**
* Draws a point at (x,y).
* @param x Point along x-axis.
* @param y Point along y-axis.
**/
void point( float x, float y );
void point(float x, float y);
/**
* Draws a line from (x1,y1) to (x2,y2).
@@ -460,11 +460,11 @@ namespace opengl
* @param x2 Second x-coordinate.
* @param y2 Second y-coordinate.
**/
void line( float x1, float y1, float x2, float y2 );
void line(float x1, float y1, float x2, float y2);
/**
* Draws a triangle using the three coordinates passed.
* @param type The type of drawing (line/filled).
* @param mode The mode of drawing (line/filled).
* @param x1 First x-coordinate.
* @param y1 First y-coordinate.
* @param x2 Second x-coordinate.
@@ -472,7 +472,7 @@ namespace opengl
* @param x3 Third x-coordinate.
* @param y3 Third y-coordinate.
**/
void triangle( int type, float x1, float y1, float x2, float y2, float x3, float y3 );
void triangle(DrawMode mode, float x1, float y1, float x2, float y2, float x3, float y3);
/**
* Draws a rectangle.
@@ -481,11 +481,11 @@ namespace opengl
* @param w The width of the rectangle.
* @param h The height of the rectangle.
**/
void rectangle( int type, float x, float y, float w, float h );
void rectangle(DrawMode mode, float x, float y, float w, float h);
/**
* Draws a quadrilateral using the four coordinates passed.
* @param type The type of drawing (line/filled).
* @param mode The mode of drawing (line/filled).
* @param x1 First x-coordinate.
* @param y1 First y-coordinate.
* @param x2 Second x-coordinate.
@@ -495,25 +495,25 @@ namespace opengl
* @param x4 Fourth x-coordinate.
* @param y4 Fourth y-coordinate.
**/
void quad( int type, float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4 );
void quad(DrawMode mode, float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4);
/**
* Draws a circle using the specified arguments.
* @param type The type of drawing (line/filled).
* @param mode The mode of drawing (line/filled).
* @param x X-coordinate.
* @param y Y-coordinate.
* @param radius Radius of the circle.
* @param points Amount of points to use to draw the circle.
**/
void circle( int type, float x, float y, float radius, int points = 10 );
void circle(DrawMode mode, float x, float y, float radius, int points = 10);
/**
* Draws a polygon with an arbitrary number of vertices.
* @param type The type of drawing (line/filled).
* @param ... Vertex components (x1, y1, x2, y2, etc).
**/
int polygon( lua_State * L );
int polygong( lua_State * L );
int polygon(lua_State * L);
int polygong(lua_State * L);
/**
* Creates a screenshot of the view and saves it to the default folder.
+86 -70
View File
@@ -360,27 +360,45 @@ namespace opengl
int w_setBlendMode(lua_State * L)
{
int mode = luaL_checkint(L, 1);
Graphics::BlendMode mode;
const char * str = luaL_checkstring(L, 1);
if(!Graphics::getConstant(str, mode))
return luaL_error(L, "Invalid blend mode: %s", str);
instance->setBlendMode(mode);
return 0;
}
int w_setColorMode(lua_State * L)
{
int mode = luaL_checkint(L, 1);
Graphics::ColorMode mode;
const char * str = luaL_checkstring(L, 1);
if(!Graphics::getConstant(str, mode))
return luaL_error(L, "Invalid color mode: %s", str);
instance->setColorMode(mode);
return 0;
}
int w_getBlendMode(lua_State * L)
{
lua_pushinteger(L, instance->getBlendMode());
Graphics::BlendMode mode = instance->getBlendMode();
const char * str = luaL_checkstring(L, 1);
if(!Graphics::getConstant(str, mode))
return luaL_error(L, "Invalid blend mode: %s", str);
lua_pushstring(L, str);
return 1;
}
int w_getColorMode(lua_State * L)
{
lua_pushinteger(L, instance->getColorMode());
Graphics::ColorMode mode = instance->getColorMode();
const char * str = luaL_checkstring(L, 1);
if(!Graphics::getConstant(str, mode))
return luaL_error(L, "Invalid blend mode: %s", str);
lua_pushstring(L, str);
return 1;
}
@@ -393,7 +411,11 @@ namespace opengl
int w_setLineStyle(lua_State * L)
{
int style = luaL_checkint(L, 1);
Graphics::LineStyle style;
const char * str = luaL_checkstring(L, 1);
if(!Graphics::getConstant(str, style))
return luaL_error(L, "Invalid line style: %s", str);
instance->setLineStyle(style);
return 0;
}
@@ -401,7 +423,16 @@ namespace opengl
int w_setLine(lua_State * L)
{
float width = (float)luaL_checknumber(L, 1);
int style = luaL_optint(L, 2, Graphics::LINE_SMOOTH);
Graphics::LineStyle style = Graphics::LINE_SMOOTH;
if(lua_gettop(L) >= 2)
{
const char * str = luaL_checkstring(L, 1);
if(!Graphics::getConstant(str, style))
return luaL_error(L, "Invalid line style: %s", str);
}
instance->setLine(width, style);
return 0;
}
@@ -446,7 +477,15 @@ namespace opengl
int w_setPointStyle(lua_State * L)
{
int style = luaL_checkint(L, 1);
Graphics::PointStyle style = Graphics::POINT_SMOOTH;
if(lua_gettop(L) >= 2)
{
const char * str = luaL_checkstring(L, 1);
if(!Graphics::getConstant(str, style))
return luaL_error(L, "Invalid point style: %s", str);
}
instance->setPointStyle(style);
return 0;
}
@@ -454,7 +493,12 @@ namespace opengl
int w_setPoint(lua_State * L)
{
float size = (float)luaL_checknumber(L, 1);
int style = luaL_optint(L, 2, Graphics::POINT_SMOOTH);
Graphics::PointStyle style;
const char * str = luaL_checkstring(L, 1);
if(!Graphics::getConstant(str, style))
return luaL_error(L, "Invalid point style: %s", str);
instance->setPoint(size, style);
return 0;
}
@@ -587,7 +631,16 @@ namespace opengl
float x = (float)luaL_checknumber(L, 2);
float y = (float)luaL_checknumber(L, 3);
float wrap = (float)luaL_checknumber(L, 4);
int align = luaL_optint(L, 5, 0);
Graphics::AlignMode align = Graphics::ALIGN_LEFT;
if(lua_gettop(L) >= 5)
{
const char * str = luaL_checkstring(L, 5);
if(!Graphics::getConstant(str, align))
return luaL_error(L, "Incorrect alignment: %s", str);
}
instance->printf(str, x, y, wrap, align);
return 0;
}
@@ -612,31 +665,43 @@ namespace opengl
int w_triangle(lua_State * L)
{
int type = luaL_checkint(L, 1);
Graphics::DrawMode mode;
const char * str = luaL_checkstring(L, 1);
if(!Graphics::getConstant(str, mode))
return luaL_error(L, "Incorrect draw mode %s", str);
float x1 = (float)luaL_checknumber(L, 2);
float y1 = (float)luaL_checknumber(L, 3);
float x2 = (float)luaL_checknumber(L, 4);
float y2 = (float)luaL_checknumber(L, 5);
float x3 = (float)luaL_checknumber(L, 6);
float y3 = (float)luaL_checknumber(L, 7);
instance->triangle(type, x1, y1, x2, y2, x3, y3);
instance->triangle(mode, x1, y1, x2, y2, x3, y3);
return 0;
}
int w_rectangle(lua_State * L)
{
int type = luaL_checkint(L, 1);
Graphics::DrawMode mode;
const char * str = luaL_checkstring(L, 1);
if(!Graphics::getConstant(str, mode))
return luaL_error(L, "Incorrect draw mode %s", str);
float x = (float)luaL_checknumber(L, 2);
float y = (float)luaL_checknumber(L, 3);
float w = (float)luaL_checknumber(L, 4);
float h = (float)luaL_checknumber(L, 5);
instance->rectangle(type, x, y, w, h);
instance->rectangle(mode, x, y, w, h);
return 0;
}
int w_quad(lua_State * L)
{
int type = luaL_checkint(L, 1);
Graphics::DrawMode mode;
const char * str = luaL_checkstring(L, 1);
if(!Graphics::getConstant(str, mode))
return luaL_error(L, "Incorrect draw mode %s", str);
float x1 = (float)luaL_checknumber(L, 2);
float y1 = (float)luaL_checknumber(L, 3);
float x2 = (float)luaL_checknumber(L, 4);
@@ -645,18 +710,22 @@ namespace opengl
float y3 = (float)luaL_checknumber(L, 7);
float x4 = (float)luaL_checknumber(L, 6);
float y4 = (float)luaL_checknumber(L, 7);
instance->quad(type, x1, y1, x2, y2, x3, y3, x4, y4);
instance->quad(mode, x1, y1, x2, y2, x3, y3, x4, y4);
return 0;
}
int w_circle(lua_State * L)
{
int type = luaL_checkint(L, 1);
Graphics::DrawMode mode;
const char * str = luaL_checkstring(L, 1);
if(!Graphics::getConstant(str, mode))
return luaL_error(L, "Incorrect draw mode %s", str);
float x = (float)luaL_checknumber(L, 2);
float y = (float)luaL_checknumber(L, 3);
float radius = (float)luaL_checknumber(L, 4);
int points = luaL_optint(L, 5, 10);
instance->circle(type, x, y, radius, points);
instance->circle(mode, x, y, radius, points);
return 0;
}
@@ -795,58 +864,6 @@ namespace opengl
0
};
// List of constants.
static const Constant constants[] = {
{ "align_left", Graphics::ALIGN_LEFT },
{ "align_right", Graphics::ALIGN_RIGHT },
{ "align_center", Graphics::ALIGN_CENTER },
{ "blend_alpha", Graphics::BLEND_ALPHA },
{ "blend_additive", Graphics::BLEND_ADDITIVE },
{ "color_replace", Graphics::COLOR_REPLACE },
{ "color_modulate", Graphics::COLOR_MODULATE },
{ "draw_line", Graphics::DRAW_LINE },
{ "draw_fill", Graphics::DRAW_FILL },
{ "line_smooth", Graphics::LINE_SMOOTH },
{ "line_rough", Graphics::LINE_ROUGH },
{ "point_smooth", Graphics::POINT_SMOOTH },
{ "point_rough", Graphics::POINT_ROUGH },
{ "filter_linear", Image::FILTER_LINEAR },
{ "filter_nearest", Image::FILTER_NEAREST },
{ "wrap_clamp", Image::WRAP_CLAMP },
{ "wrap_repeat", Image::WRAP_REPEAT },
/**
// Vertex buffer geometry types.
{ "type_points", TYPE_POINTS },
{ "type_lines", TYPE_LINES },
{ "type_line_strip", TYPE_LINE_STRIP },
{ "type_triangles", TYPE_TRIANGLES },
{ "type_triangle_strip", TYPE_TRIANGLE_STRIP },
{ "type_triangle_fan", TYPE_TRIANGLE_FAN },
{ "type_num", TYPE_NUM },
// Vertex buffer usage hints.
{ "usage_array", USAGE_ARRAY },
{ "usage_dynamic", USAGE_DYNAMIC },
{ "usage_static", USAGE_STATIC },
{ "usage_stream", USAGE_STREAM },
{ "usage_num", USAGE_NUM },
**/
{ 0, 0 }
};
int luaopen_love_graphics(lua_State * L)
{
if(instance == 0)
@@ -867,7 +884,6 @@ namespace opengl
w.flags = MODULE_T;
w.functions = functions;
w.types = types;
w.constants = constants;
luax_register_module(L, w);
+28 -7
View File
@@ -24,22 +24,43 @@ namespace love
{
namespace image
{
EncodedImageData::EncodedImageData(void * d, Image::ImageFormat f, int s) {
data = d;
format = f;
size = s;
EncodedImageData::EncodedImageData(void * d, Format f, int s)
: data(d), format(f), size(s)
{
}
void * EncodedImageData::getData() const {
void * EncodedImageData::getData() const
{
return data;
}
Image::ImageFormat EncodedImageData::getFormat() {
EncodedImageData::Format EncodedImageData::getFormat() const
{
return format;
}
int EncodedImageData::getSize() const {
int EncodedImageData::getSize() const
{
return size;
}
bool EncodedImageData::getConstant(const char * in, EncodedImageData::Format & out)
{
return formats.find(in, out);
}
bool EncodedImageData::getConstant(EncodedImageData::Format in, const char *& out)
{
return formats.find(in, out);
}
StringMap<EncodedImageData::Format, EncodedImageData::FORMAT_MAX_ENUM>::Entry EncodedImageData::formatEntries[] =
{
{"tga", EncodedImageData::FORMAT_TGA},
{"bmp", EncodedImageData::FORMAT_BMP},
};
StringMap<EncodedImageData::Format, EncodedImageData::FORMAT_MAX_ENUM> EncodedImageData::formats(EncodedImageData::formatEntries, sizeof(EncodedImageData::formatEntries));
} // image
} // love
+60 -47
View File
@@ -23,60 +23,73 @@
// LOVE
#include <common/Data.h>
#include <common/StringMap.h>
#include "Image.h"
namespace love
{
namespace image
namespace image
{
/**
* Represents encoded pixel data.
**/
class EncodedImageData : public Data
{
/**
* Represents encoded pixel data.
**/
class EncodedImageData : public Data
{
public:
/**
* Constructor.
**/
EncodedImageData(void * data, Image::ImageFormat format, int size);
/**
* Destructor.
**/
virtual ~EncodedImageData(){};
// Implements Data.
void * getData() const;
int getSize() const;
/**
* Get the format the data is encoded in.
**/
Image::ImageFormat getFormat();
private:
/**
* Actual data.
**/
void * data;
/**
* Size of the data.
**/
int size;
/**
* Image format.
**/
Image::ImageFormat format;
}; // EncodedImageData
public:
} // image
enum Format
{
FORMAT_TGA = 1,
FORMAT_BMP,
FORMAT_MAX_ENUM
};
/**
* Constructor.
**/
EncodedImageData(void * data, Format format, int size);
/**
* Destructor.
**/
virtual ~EncodedImageData(){};
// Implements Data.
void * getData() const;
int getSize() const;
/**
* Get the format the data is encoded in.
**/
Format getFormat() const;
static bool getConstant(const char * in, Format & out);
static bool getConstant(Format in, const char *& out);
private:
/**
* Actual data.
**/
void * data;
/**
* Size of the data.
**/
int size;
/**
* Image format.
**/
Format format;
static StringMap<Format, FORMAT_MAX_ENUM>::Entry formatEntries[];
static StringMap<Format, FORMAT_MAX_ENUM> formats;
}; // EncodedImageData
} // image
} // love
#endif // LOVE_IMAGE_ENCODED_IMAGE_DATA_H
-5
View File
@@ -76,11 +76,6 @@ namespace image
* @return The new ImageData.
**/
virtual ImageData * newImageData(int width, int height, void *data) = 0;
enum ImageFormat {
FORMAT_TGA,
FORMAT_BMP
};
}; // Image
+4 -4
View File
@@ -165,13 +165,13 @@ namespace devil
return pixels[y*width+x];
}
love::image::EncodedImageData * ImageData::encodeImageData(love::image::ImageData * d, love::image::Image::ImageFormat f) {
love::image::EncodedImageData * ImageData::encodeImageData(love::image::ImageData * d, EncodedImageData::Format f) {
ILubyte * data;
ILuint w = d->getWidth();
int h = d->getHeight(); // has to be a signed int so we can make it negative for BMPs
int headerLen, bpp, row, size, padding, filesize;
switch (f) {
case Image::FORMAT_BMP:
case EncodedImageData::FORMAT_BMP:
headerLen = 54;
bpp = 3;
row = w * bpp;
@@ -231,7 +231,7 @@ namespace devil
}
data -= filesize;
break;
case Image::FORMAT_TGA:
case EncodedImageData::FORMAT_TGA:
default: // TGA is the default format
headerLen = 18;
bpp = 3;
@@ -263,7 +263,7 @@ namespace devil
ILubyte * temp = new ILubyte[row];
ILubyte * src = data - row;
ILubyte * dst = data + size;
for (unsigned i = 0; i < (h >> 1); i++) {
for (int i = 0; i < (h >> 1); i++) {
memcpy(temp,src+=row,row);
memcpy(src,dst-=row,row);
memcpy(dst,temp,row);
+1 -1
View File
@@ -84,7 +84,7 @@ namespace devil
* @param f The format to convert to.
* @return A pointer to the encoded image data.
**/
static love::image::EncodedImageData * encodeImageData(love::image::ImageData * d, love::image::Image::ImageFormat f);
static love::image::EncodedImageData * encodeImageData(love::image::ImageData * d, EncodedImageData::Format f);
}; // ImageData
+4 -9
View File
@@ -21,6 +21,7 @@
#include "wrap_Image.h"
#include <common/Data.h>
#include <common/StringMap.h>
#include "devil/Image.h"
#include "devil/ImageData.h"
@@ -30,7 +31,7 @@ namespace love
namespace image
{
static Image * instance = 0;
int w_newImageData(lua_State * L)
{
@@ -72,7 +73,8 @@ namespace image
int w_newEncodedImageData(lua_State * L) {
ImageData * t = luax_checkimagedata(L, 1);
Image::ImageFormat format = (Image::ImageFormat)luaL_optint(L, 2, Image::FORMAT_TGA);
EncodedImageData::Format format;
EncodedImageData::getConstant(luaL_checkstring(L, 2), format);
EncodedImageData * e = love::image::devil::ImageData::encodeImageData(t, format);
luax_newtype(L, "Data", DATA_T, (void*)e); // since we don't need any of EncodedImageData's features
return 1;
@@ -89,12 +91,6 @@ namespace image
luaopen_imagedata,
0
};
static const Constant constants[] = {
{ "format_tga", Image::FORMAT_TGA },
{ "format_bmp", Image::FORMAT_BMP },
{ 0, 0 }
};
int luaopen_love_image(lua_State * L)
{
@@ -116,7 +112,6 @@ namespace image
w.flags = MODULE_IMAGE_T;
w.functions = functions;
w.types = types;
w.constants = constants;
return luax_register_module(L, w);
}
@@ -1,85 +1,58 @@
/**
* Copyright (c) 2006-2009 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
/**
* Copyright (c) 2006-2009 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
**/
#include "Signal.h"
#include "Joystick.h"
namespace love
{
namespace signal
{
namespace posix
namespace joystick
{
Signal::Signal()
: signals(0)
Joystick::~Joystick()
{
cb = 0;
}
Signal::~Signal()
{
//::signal(signals, SIG_DFL);
}
bool Signal::hook(int sgn)
{
signals |= sgn;
::signal(sgn, (void (*)(int)) &handler);
return true;
}
void Signal::setCallback(lua_State *L)
{
luax_assert_argc(L, 1, 1);
luax_assert_function(L, -1);
if(cb != 0)
{
delete cb;
cb = 0;
}
cb = new Reference(L);
}
bool Signal::raise(int sgn)
{
// MSVC warns about int -> bool conversion.
return ::raise(sgn) ? true : false;
}
void handler(int signal)
{
if (cb == 0)
return;
lua_State *L = cb->getL();
cb->push();
lua_pushnumber(L, signal);
lua_call(L, 1, 0);
}
const char * Signal::getName() const
{
return "love.signal.posix";
}
} // posix
} // signal
bool Joystick::getConstant(const char * in, Joystick::Hat & out)
{
return hats.find(in, out);
}
bool Joystick::getConstant(Joystick::Hat in, const char *& out)
{
return hats.find(in, out);
}
StringMap<Joystick::Hat, Joystick::HAT_MAX_ENUM>::Entry Joystick::hatEntries[] =
{
{"c", Joystick::HAT_CENTERED},
{"u", Joystick::HAT_UP},
{"r", Joystick::HAT_RIGHT},
{"d", Joystick::HAT_DOWN},
{"l", Joystick::HAT_LEFT},
{"ru", Joystick::HAT_RIGHTUP},
{"rd", Joystick::HAT_RIGHTDOWN},
{"lu", Joystick::HAT_LEFTUP},
{"ld", Joystick::HAT_LEFTDOWN},
};
StringMap<Joystick::Hat, Joystick::HAT_MAX_ENUM> Joystick::hats(Joystick::hatEntries, sizeof(Joystick::hatEntries));
} // joystick
} // love
+21 -16
View File
@@ -23,6 +23,7 @@
// LOVE
#include <common/Module.h>
#include <common/StringMap.h>
namespace love
{
@@ -32,26 +33,30 @@ namespace joystick
{
public:
enum JoystickAxis
enum Hat
{
JOYSTICK_AXIS_HORIZONTAL = 0,
JOYSTICK_AXIS_VERITCAL = 1,
HAT_INVALID,
HAT_CENTERED,
HAT_UP,
HAT_RIGHT,
HAT_DOWN,
HAT_LEFT,
HAT_RIGHTUP,
HAT_RIGHTDOWN,
HAT_LEFTUP,
HAT_LEFTDOWN,
HAT_MAX_ENUM = 16
};
enum JoystickHat
{
JOYSTICK_HAT_CENTERED = 0,
JOYSTICK_HAT_UP = 1,
JOYSTICK_HAT_RIGHT = 2,
JOYSTICK_HAT_DOWN = 4,
JOYSTICK_HAT_LEFT = 8,
JOYSTICK_HAT_RIGHTUP = (2|1),
JOYSTICK_HAT_RIGHTDOWN = (2|4),
JOYSTICK_HAT_LEFTUP = (8|1),
JOYSTICK_HAT_LEFTDOWN = (8|4)
};
virtual ~Joystick();
virtual ~Joystick(){};
static bool getConstant(const char * in, Hat & out);
static bool getConstant(Hat in, const char *& out);
private:
static StringMap<Hat, HAT_MAX_ENUM>::Entry hatEntries[];
static StringMap<Hat, HAT_MAX_ENUM> hats;
}; // Joystick
+23 -4
View File
@@ -202,15 +202,19 @@ namespace sdl
return (SDL_JoystickGetButton(joysticks[index], button) == 1);
}
int Joystick::getHat(int index, int hat)
Joystick::Hat Joystick::getHat(int index, int hat)
{
Hat h = HAT_INVALID;
if(!verifyJoystick(index))
return 0;
return h;
if(hat >= getNumHats(index))
return 0;
return h;
return SDL_JoystickGetHat(joysticks[index], hat);
hats.find(SDL_JoystickGetHat(joysticks[index], hat), h);
return h;
}
void Joystick::close(int index)
@@ -225,6 +229,21 @@ namespace sdl
}
}
EnumMap<Joystick::Hat, Uint8, Joystick::HAT_MAX_ENUM>::Entry Joystick::hatEntries[] =
{
{Joystick::HAT_CENTERED, SDL_HAT_CENTERED},
{Joystick::HAT_UP, SDL_HAT_UP},
{Joystick::HAT_RIGHT, SDL_HAT_RIGHT},
{Joystick::HAT_DOWN, SDL_HAT_DOWN},
{Joystick::HAT_LEFT, SDL_HAT_LEFT},
{Joystick::HAT_RIGHTUP, SDL_HAT_RIGHTUP},
{Joystick::HAT_RIGHTDOWN, SDL_HAT_RIGHTDOWN},
{Joystick::HAT_LEFTUP, SDL_HAT_LEFTUP},
{Joystick::HAT_LEFTDOWN, SDL_HAT_LEFTDOWN},
};
EnumMap<Joystick::Hat, Uint8, Joystick::HAT_MAX_ENUM> Joystick::hats(Joystick::hatEntries, sizeof(Joystick::hatEntries));
} // sdl
} // joystick
} // love
+10 -4
View File
@@ -21,11 +21,12 @@
#ifndef LOVE_JOYSTICK_SDL_JOYSTICK_H
#define LOVE_JOYSTICK_SDL_JOYSTICK_H
// SDL
#include <SDL.h>
// LOVE
#include <joystick/Joystick.h>
#include <common/EnumMap.h>
// SDL
#include <SDL.h>
namespace love
{
@@ -59,9 +60,14 @@ namespace sdl
int getAxes(lua_State * L);
int getBall(lua_State * L);
bool isDown(int index, int button);
int getHat(int index, int hat);
Hat getHat(int index, int hat);
void close(int index);
private:
static EnumMap<Hat, Uint8, Joystick::HAT_MAX_ENUM>::Entry hatEntries[];
static EnumMap<Hat, Uint8, Joystick::HAT_MAX_ENUM> hats;
}; // Joystick
} // sdl
+7 -19
View File
@@ -113,7 +113,13 @@ namespace sdl
{
int index = luaL_checkint(L, 1);
int hat = luaL_checkint(L, 2);
lua_pushinteger(L, instance->getHat(index, hat));
Joystick::Hat h = instance->getHat(index, hat);
const char * direction = "";
Joystick::getConstant(h, direction);
lua_pushstring(L, direction);
return 1;
}
@@ -145,23 +151,6 @@ namespace sdl
{ 0, 0 }
};
// List of constants.
static const Constant constants[] = {
{ "joystick_axis_horizontal", Joystick::JOYSTICK_AXIS_HORIZONTAL },
{ "joystick_axis_vertical", Joystick::JOYSTICK_AXIS_VERITCAL },
{ "joystick_hat_centered", Joystick::JOYSTICK_HAT_CENTERED },
{ "joystick_hat_up", Joystick::JOYSTICK_HAT_UP },
{ "joystick_hat_right", Joystick::JOYSTICK_HAT_RIGHT },
{ "joystick_hat_down", Joystick::JOYSTICK_HAT_DOWN },
{ "joystick_hat_left", Joystick::JOYSTICK_HAT_LEFT },
{ "joystick_hat_rightup", Joystick::JOYSTICK_HAT_RIGHTUP },
{ "joystick_hat_rightdown", Joystick::JOYSTICK_HAT_RIGHTDOWN },
{ "joystick_hat_leftup", Joystick::JOYSTICK_HAT_LEFTUP },
{ "joystick_hat_leftdown", Joystick::JOYSTICK_HAT_LEFTDOWN },
{ 0, 0 }
};
int luaopen_love_joystick(lua_State * L)
{
if(instance == 0)
@@ -183,7 +172,6 @@ namespace sdl
w.flags = MODULE_T;
w.functions = functions;
w.types = 0;
w.constants = constants;
return luax_register_module(L, w);
}
+187
View File
@@ -0,0 +1,187 @@
/**
* Copyright (c) 2006-2009 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
**/
#include "Keyboard.h"
namespace love
{
namespace keyboard
{
bool Keyboard::getConstant(const char * in, Keyboard::Key & out)
{
return keys.find(in, out);
}
bool Keyboard::getConstant(Keyboard::Key in, const char *& out)
{
return keys.find(in, out);
}
StringMap<Keyboard::Key, Keyboard::KEY_MAX_ENUM>::Entry Keyboard::keyEntries[] =
{
{"backspace", Keyboard::KEY_BACKSPACE},
{"tab", Keyboard::KEY_TAB},
{"clear", Keyboard::KEY_CLEAR},
{"return", Keyboard::KEY_RETURN},
{"pause", Keyboard::KEY_PAUSE},
{"escape", Keyboard::KEY_ESCAPE},
{" ", Keyboard::KEY_SPACE},
{"!", Keyboard::KEY_EXCLAIM},
{"\"", Keyboard::KEY_QUOTEDBL},
{"#", Keyboard::KEY_HASH},
{"$", Keyboard::KEY_DOLLAR},
{"&", Keyboard::KEY_AMPERSAND},
{"'", Keyboard::KEY_QUOTE},
{"(", Keyboard::KEY_LEFTPAREN},
{")", Keyboard::KEY_RIGHTPAREN},
{"*", Keyboard::KEY_ASTERISK},
{"+", Keyboard::KEY_PLUS},
{",", Keyboard::KEY_COMMA},
{"-", Keyboard::KEY_MINUS},
{".", Keyboard::KEY_PERIOD},
{"/", Keyboard::KEY_SLASH},
{"0", Keyboard::KEY_0},
{"1", Keyboard::KEY_1},
{"2", Keyboard::KEY_2},
{"3", Keyboard::KEY_3},
{"4", Keyboard::KEY_4},
{"5", Keyboard::KEY_5},
{"6", Keyboard::KEY_6},
{"7", Keyboard::KEY_7},
{"8", Keyboard::KEY_8},
{"9", Keyboard::KEY_9},
{":", Keyboard::KEY_COLON},
{";", Keyboard::KEY_SEMICOLON},
{"<", Keyboard::KEY_LESS},
{"=", Keyboard::KEY_EQUALS},
{">", Keyboard::KEY_GREATER},
{"?", Keyboard::KEY_QUESTION},
{"@", Keyboard::KEY_AT},
{"[", Keyboard::KEY_LEFTBRACKET},
{"\\", Keyboard::KEY_BACKSLASH},
{"]", Keyboard::KEY_RIGHTBRACKET},
{"^", Keyboard::KEY_CARET},
{"_", Keyboard::KEY_UNDERSCORE},
{"`", Keyboard::KEY_BACKQUOTE},
{"a", Keyboard::KEY_A},
{"b", Keyboard::KEY_B},
{"c", Keyboard::KEY_C},
{"d", Keyboard::KEY_D},
{"e", Keyboard::KEY_E},
{"f", Keyboard::KEY_F},
{"g", Keyboard::KEY_G},
{"h", Keyboard::KEY_H},
{"i", Keyboard::KEY_I},
{"j", Keyboard::KEY_J},
{"k", Keyboard::KEY_K},
{"l", Keyboard::KEY_L},
{"m", Keyboard::KEY_M},
{"n", Keyboard::KEY_N},
{"o", Keyboard::KEY_O},
{"p", Keyboard::KEY_P},
{"q", Keyboard::KEY_Q},
{"r", Keyboard::KEY_R},
{"s", Keyboard::KEY_S},
{"t", Keyboard::KEY_T},
{"u", Keyboard::KEY_U},
{"v", Keyboard::KEY_V},
{"w", Keyboard::KEY_W},
{"x", Keyboard::KEY_X},
{"y", Keyboard::KEY_Y},
{"z", Keyboard::KEY_Z},
{"delete", Keyboard::KEY_DELETE},
{"kp0", Keyboard::KEY_KP0},
{"kp1", Keyboard::KEY_KP1},
{"kp2", Keyboard::KEY_KP2},
{"kp3", Keyboard::KEY_KP3},
{"kp4", Keyboard::KEY_KP4},
{"kp5", Keyboard::KEY_KP5},
{"kp6", Keyboard::KEY_KP6},
{"kp7", Keyboard::KEY_KP7},
{"kp8", Keyboard::KEY_KP8},
{"kp9", Keyboard::KEY_KP9},
{"kp.", Keyboard::KEY_KP_PERIOD},
{"kp/", Keyboard::KEY_KP_DIVIDE},
{"kp*", Keyboard::KEY_KP_MULTIPLY},
{"kp-", Keyboard::KEY_KP_MINUS},
{"kp+", Keyboard::KEY_KP_PLUS},
{"kpenter", Keyboard::KEY_KP_ENTER},
{"kp=", Keyboard::KEY_KP_EQUALS},
{"kpup", Keyboard::KEY_UP},
{"kpdown", Keyboard::KEY_DOWN},
{"kpright", Keyboard::KEY_RIGHT},
{"kpleft", Keyboard::KEY_LEFT},
{"kpinsert", Keyboard::KEY_INSERT},
{"kphome", Keyboard::KEY_HOME},
{"kpend", Keyboard::KEY_END},
{"kppageup", Keyboard::KEY_PAGEUP},
{"kppagedown", Keyboard::KEY_PAGEDOWN},
{"f1", Keyboard::KEY_F1},
{"f2", Keyboard::KEY_F2},
{"f3", Keyboard::KEY_F3},
{"f4", Keyboard::KEY_F4},
{"f5", Keyboard::KEY_F5},
{"f6", Keyboard::KEY_F6},
{"f7", Keyboard::KEY_F7},
{"f8", Keyboard::KEY_F8},
{"f9", Keyboard::KEY_F9},
{"f10", Keyboard::KEY_F10},
{"f11", Keyboard::KEY_F11},
{"f12", Keyboard::KEY_F12},
{"f13", Keyboard::KEY_F13},
{"f14", Keyboard::KEY_F14},
{"f15", Keyboard::KEY_F15},
{"numlock", Keyboard::KEY_NUMLOCK},
{"capslock", Keyboard::KEY_CAPSLOCK},
{"scrollock", Keyboard::KEY_SCROLLOCK},
{"rshift", Keyboard::KEY_RSHIFT},
{"lshift", Keyboard::KEY_LSHIFT},
{"rctrl", Keyboard::KEY_RCTRL},
{"lctrl", Keyboard::KEY_LCTRL},
{"ralt", Keyboard::KEY_RALT},
{"lalt", Keyboard::KEY_LALT},
{"rmeta", Keyboard::KEY_RMETA},
{"lmeta", Keyboard::KEY_LMETA},
{"lsuper", Keyboard::KEY_LSUPER},
{"rsuper", Keyboard::KEY_RSUPER},
{"mode", Keyboard::KEY_MODE},
{"compose", Keyboard::KEY_COMPOSE},
{"help", Keyboard::KEY_HELP},
{"print", Keyboard::KEY_PRINT},
{"sysreq", Keyboard::KEY_SYSREQ},
{"break", Keyboard::KEY_BREAK},
{"menu", Keyboard::KEY_MENU},
{"power", Keyboard::KEY_POWER},
{"euro", Keyboard::KEY_EURO},
{"undo", Keyboard::KEY_UNDO},
};
StringMap<Keyboard::Key, Keyboard::KEY_MAX_ENUM> Keyboard::keys(Keyboard::keyEntries, sizeof(Keyboard::keyEntries));
} // keyboard
} // love
+157 -2
View File
@@ -23,6 +23,7 @@
// LOVE
#include <common/Module.h>
#include <common/StringMap.h>
namespace love
{
@@ -32,11 +33,165 @@ namespace keyboard
{
public:
static const int KEY_REPEAT_DELAY = -1;
static const int KEY_REPEAT_INTERVAL = -2;
enum Key
{
KEY_UNKNOWN,
KEY_BACKSPACE,
KEY_TAB,
KEY_CLEAR,
KEY_RETURN,
KEY_PAUSE,
KEY_ESCAPE,
KEY_SPACE,
KEY_EXCLAIM,
KEY_QUOTEDBL,
KEY_HASH,
KEY_DOLLAR,
KEY_AMPERSAND,
KEY_QUOTE,
KEY_LEFTPAREN,
KEY_RIGHTPAREN,
KEY_ASTERISK,
KEY_PLUS,
KEY_COMMA,
KEY_MINUS,
KEY_PERIOD,
KEY_SLASH,
KEY_0,
KEY_1,
KEY_2,
KEY_3,
KEY_4,
KEY_5,
KEY_6,
KEY_7,
KEY_8,
KEY_9,
KEY_COLON,
KEY_SEMICOLON,
KEY_LESS,
KEY_EQUALS,
KEY_GREATER,
KEY_QUESTION,
KEY_AT,
KEY_LEFTBRACKET,
KEY_BACKSLASH,
KEY_RIGHTBRACKET,
KEY_CARET,
KEY_UNDERSCORE,
KEY_BACKQUOTE,
KEY_A,
KEY_B,
KEY_C,
KEY_D,
KEY_E,
KEY_F,
KEY_G,
KEY_H,
KEY_I,
KEY_J,
KEY_K,
KEY_L,
KEY_M,
KEY_N,
KEY_O,
KEY_P,
KEY_Q,
KEY_R,
KEY_S,
KEY_T,
KEY_U,
KEY_V,
KEY_W,
KEY_X,
KEY_Y,
KEY_Z,
KEY_DELETE,
KEY_KP0,
KEY_KP1,
KEY_KP2,
KEY_KP3,
KEY_KP4,
KEY_KP5,
KEY_KP6,
KEY_KP7,
KEY_KP8,
KEY_KP9,
KEY_KP_PERIOD,
KEY_KP_DIVIDE,
KEY_KP_MULTIPLY,
KEY_KP_MINUS,
KEY_KP_PLUS,
KEY_KP_ENTER,
KEY_KP_EQUALS,
KEY_UP,
KEY_DOWN,
KEY_RIGHT,
KEY_LEFT,
KEY_INSERT,
KEY_HOME,
KEY_END,
KEY_PAGEUP,
KEY_PAGEDOWN,
KEY_F1,
KEY_F2,
KEY_F3,
KEY_F4,
KEY_F5,
KEY_F6,
KEY_F7,
KEY_F8,
KEY_F9,
KEY_F10,
KEY_F11,
KEY_F12,
KEY_F13,
KEY_F14,
KEY_F15,
KEY_NUMLOCK,
KEY_CAPSLOCK,
KEY_SCROLLOCK,
KEY_RSHIFT,
KEY_LSHIFT,
KEY_RCTRL,
KEY_LCTRL,
KEY_RALT,
KEY_LALT,
KEY_RMETA,
KEY_LMETA,
KEY_LSUPER,
KEY_RSUPER,
KEY_MODE,
KEY_COMPOSE,
KEY_HELP,
KEY_PRINT,
KEY_SYSREQ,
KEY_BREAK,
KEY_MENU,
KEY_POWER,
KEY_EURO,
KEY_UNDO,
KEY_MAX_ENUM = 512
};
static const int DEFAULT = 0;
virtual ~Keyboard(){}
static bool getConstant(const char * in, Key & out);
static bool getConstant(Key in, const char *& out);
private:
static StringMap<Key, KEY_MAX_ENUM>::Entry keyEntries[];
static StringMap<Key, KEY_MAX_ENUM> keys;
}; // Keyboard
} // keyboard
+160 -11
View File
@@ -20,9 +20,6 @@
#include "Keyboard.h"
// SDL
#include <SDL.h>
namespace love
{
namespace keyboard
@@ -34,22 +31,26 @@ namespace sdl
return "love.keyboard.sdl";
}
bool Keyboard::isDown(int key) const
bool Keyboard::isDown(Key key) const
{
Uint8 * keystate = SDL_GetKeyState(0);
return keystate[key] == 1;
SDLKey k;
if(keys.find(key, k))
{
Uint8 * keystate = SDL_GetKeyState(0);
return keystate[(unsigned)k] == 1;
}
return false;
}
void Keyboard::setKeyRepeat(int delay, int interval) const
{
if(delay == KEY_REPEAT_DELAY)
if(delay == DEFAULT)
delay = SDL_DEFAULT_REPEAT_DELAY;
if(interval == KEY_REPEAT_INTERVAL)
if(interval == DEFAULT)
interval = SDL_DEFAULT_REPEAT_INTERVAL;
if(SDL_EnableKeyRepeat(delay, interval) == -1)
throw new Exception("[Keyboard::enableKeyRepeat] Unable to enable key repeat");
}
int Keyboard::getKeyRepeatDelay() const
@@ -66,6 +67,154 @@ namespace sdl
return interval;
}
EnumMap<Keyboard::Key, SDLKey, Keyboard::KEY_MAX_ENUM>::Entry Keyboard::keyEntries[] =
{
{ Keyboard::KEY_BACKSPACE, SDLK_BACKSPACE},
{ Keyboard::KEY_TAB, SDLK_TAB},
{ Keyboard::KEY_CLEAR, SDLK_CLEAR},
{ Keyboard::KEY_RETURN, SDLK_RETURN},
{ Keyboard::KEY_PAUSE, SDLK_PAUSE},
{ Keyboard::KEY_ESCAPE, SDLK_ESCAPE },
{ Keyboard::KEY_SPACE, SDLK_SPACE },
{ Keyboard::KEY_EXCLAIM, SDLK_EXCLAIM },
{ Keyboard::KEY_QUOTEDBL, SDLK_QUOTEDBL },
{ Keyboard::KEY_HASH, SDLK_HASH },
{ Keyboard::KEY_DOLLAR, SDLK_DOLLAR },
{ Keyboard::KEY_AMPERSAND, SDLK_AMPERSAND },
{ Keyboard::KEY_QUOTE, SDLK_QUOTE },
{ Keyboard::KEY_LEFTPAREN, SDLK_LEFTPAREN },
{ Keyboard::KEY_RIGHTPAREN, SDLK_RIGHTPAREN },
{ Keyboard::KEY_ASTERISK, SDLK_ASTERISK },
{ Keyboard::KEY_PLUS, SDLK_PLUS },
{ Keyboard::KEY_COMMA, SDLK_COMMA },
{ Keyboard::KEY_MINUS, SDLK_MINUS },
{ Keyboard::KEY_PERIOD, SDLK_PERIOD },
{ Keyboard::KEY_SLASH, SDLK_SLASH },
{ Keyboard::KEY_0, SDLK_0 },
{ Keyboard::KEY_1, SDLK_1 },
{ Keyboard::KEY_2, SDLK_2 },
{ Keyboard::KEY_3, SDLK_3 },
{ Keyboard::KEY_4, SDLK_4 },
{ Keyboard::KEY_5, SDLK_5 },
{ Keyboard::KEY_6, SDLK_6 },
{ Keyboard::KEY_7, SDLK_7 },
{ Keyboard::KEY_8, SDLK_8 },
{ Keyboard::KEY_9, SDLK_9 },
{ Keyboard::KEY_COLON, SDLK_COLON },
{ Keyboard::KEY_SEMICOLON, SDLK_SEMICOLON },
{ Keyboard::KEY_LESS, SDLK_LESS },
{ Keyboard::KEY_EQUALS, SDLK_EQUALS },
{ Keyboard::KEY_GREATER, SDLK_GREATER },
{ Keyboard::KEY_QUESTION, SDLK_QUESTION },
{ Keyboard::KEY_AT, SDLK_AT },
{ Keyboard::KEY_LEFTBRACKET, SDLK_LEFTBRACKET },
{ Keyboard::KEY_BACKSLASH, SDLK_BACKSLASH },
{ Keyboard::KEY_RIGHTBRACKET, SDLK_RIGHTBRACKET },
{ Keyboard::KEY_CARET, SDLK_CARET },
{ Keyboard::KEY_UNDERSCORE, SDLK_UNDERSCORE },
{ Keyboard::KEY_BACKQUOTE, SDLK_BACKQUOTE },
{ Keyboard::KEY_A, SDLK_a },
{ Keyboard::KEY_B, SDLK_b },
{ Keyboard::KEY_C, SDLK_c },
{ Keyboard::KEY_D, SDLK_d },
{ Keyboard::KEY_E, SDLK_e },
{ Keyboard::KEY_F, SDLK_f },
{ Keyboard::KEY_G, SDLK_g },
{ Keyboard::KEY_H, SDLK_h },
{ Keyboard::KEY_I, SDLK_i },
{ Keyboard::KEY_J, SDLK_j },
{ Keyboard::KEY_K, SDLK_k },
{ Keyboard::KEY_L, SDLK_l },
{ Keyboard::KEY_M, SDLK_m },
{ Keyboard::KEY_N, SDLK_n },
{ Keyboard::KEY_O, SDLK_o },
{ Keyboard::KEY_P, SDLK_p },
{ Keyboard::KEY_Q, SDLK_q },
{ Keyboard::KEY_R, SDLK_r },
{ Keyboard::KEY_S, SDLK_s },
{ Keyboard::KEY_T, SDLK_t },
{ Keyboard::KEY_U, SDLK_u },
{ Keyboard::KEY_V, SDLK_v },
{ Keyboard::KEY_W, SDLK_w },
{ Keyboard::KEY_X, SDLK_x },
{ Keyboard::KEY_Y, SDLK_y },
{ Keyboard::KEY_Z, SDLK_z },
{ Keyboard::KEY_DELETE, SDLK_DELETE },
{ Keyboard::KEY_KP0, SDLK_KP0 },
{ Keyboard::KEY_KP1, SDLK_KP1 },
{ Keyboard::KEY_KP2, SDLK_KP2 },
{ Keyboard::KEY_KP3, SDLK_KP3 },
{ Keyboard::KEY_KP4, SDLK_KP4 },
{ Keyboard::KEY_KP5, SDLK_KP5 },
{ Keyboard::KEY_KP6, SDLK_KP6 },
{ Keyboard::KEY_KP7, SDLK_KP7 },
{ Keyboard::KEY_KP8, SDLK_KP8 },
{ Keyboard::KEY_KP9, SDLK_KP9 },
{ Keyboard::KEY_KP_PERIOD, SDLK_KP_PERIOD },
{ Keyboard::KEY_KP_DIVIDE, SDLK_KP_DIVIDE },
{ Keyboard::KEY_KP_MULTIPLY, SDLK_KP_MULTIPLY},
{ Keyboard::KEY_KP_MINUS, SDLK_KP_MINUS },
{ Keyboard::KEY_KP_PLUS, SDLK_KP_PLUS },
{ Keyboard::KEY_KP_ENTER, SDLK_KP_ENTER },
{ Keyboard::KEY_KP_EQUALS, SDLK_KP_EQUALS },
{ Keyboard::KEY_UP, SDLK_UP },
{ Keyboard::KEY_DOWN, SDLK_DOWN },
{ Keyboard::KEY_RIGHT, SDLK_RIGHT },
{ Keyboard::KEY_LEFT, SDLK_LEFT },
{ Keyboard::KEY_INSERT, SDLK_INSERT },
{ Keyboard::KEY_HOME, SDLK_HOME },
{ Keyboard::KEY_END, SDLK_END },
{ Keyboard::KEY_PAGEUP, SDLK_PAGEUP },
{ Keyboard::KEY_PAGEDOWN, SDLK_PAGEDOWN },
{ Keyboard::KEY_F1, SDLK_F1 },
{ Keyboard::KEY_F2, SDLK_F2 },
{ Keyboard::KEY_F3, SDLK_F3 },
{ Keyboard::KEY_F4, SDLK_F4 },
{ Keyboard::KEY_F5, SDLK_F5 },
{ Keyboard::KEY_F6, SDLK_F6 },
{ Keyboard::KEY_F7, SDLK_F7 },
{ Keyboard::KEY_F8, SDLK_F8 },
{ Keyboard::KEY_F9, SDLK_F9 },
{ Keyboard::KEY_F10, SDLK_F10 },
{ Keyboard::KEY_F11, SDLK_F11 },
{ Keyboard::KEY_F12, SDLK_F12 },
{ Keyboard::KEY_F13, SDLK_F13 },
{ Keyboard::KEY_F14, SDLK_F14 },
{ Keyboard::KEY_F15, SDLK_F15 },
{ Keyboard::KEY_NUMLOCK, SDLK_NUMLOCK },
{ Keyboard::KEY_CAPSLOCK, SDLK_CAPSLOCK },
{ Keyboard::KEY_SCROLLOCK, SDLK_SCROLLOCK },
{ Keyboard::KEY_RSHIFT, SDLK_RSHIFT },
{ Keyboard::KEY_LSHIFT, SDLK_LSHIFT },
{ Keyboard::KEY_RCTRL, SDLK_RCTRL },
{ Keyboard::KEY_LCTRL, SDLK_LCTRL },
{ Keyboard::KEY_RALT, SDLK_RALT },
{ Keyboard::KEY_LALT, SDLK_LALT },
{ Keyboard::KEY_RMETA, SDLK_RMETA },
{ Keyboard::KEY_LMETA, SDLK_LMETA },
{ Keyboard::KEY_LSUPER, SDLK_LSUPER },
{ Keyboard::KEY_RSUPER, SDLK_RSUPER },
{ Keyboard::KEY_MODE, SDLK_MODE },
{ Keyboard::KEY_COMPOSE, SDLK_COMPOSE },
{ Keyboard::KEY_HELP, SDLK_HELP },
{ Keyboard::KEY_PRINT, SDLK_PRINT },
{ Keyboard::KEY_SYSREQ, SDLK_SYSREQ },
{ Keyboard::KEY_BREAK, SDLK_BREAK },
{ Keyboard::KEY_MENU, SDLK_MENU },
{ Keyboard::KEY_POWER, SDLK_POWER },
{ Keyboard::KEY_EURO, SDLK_EURO },
{ Keyboard::KEY_UNDO, SDLK_UNDO },
};
EnumMap<Keyboard::Key, SDLKey, Keyboard::KEY_MAX_ENUM> Keyboard::keys(Keyboard::keyEntries, sizeof(Keyboard::keyEntries));
} // sdl
} // keyboard
} // love
+11 -2
View File
@@ -23,6 +23,10 @@
// LOVE
#include <keyboard/Keyboard.h>
#include <common/EnumMap.h>
// SDL
#include <SDL.h>
namespace love
{
@@ -42,14 +46,14 @@ namespace sdl
* @param key A key identifier.
* @return boolean
**/
bool isDown(int key) const;
bool isDown(Key key) const;
/**
* Enables key repeating.
* @param delay The amount of delay before repeating the key (in milliseconds)
* @param interval Specifies the amount of time between repeats (in milliseconds)
**/
void setKeyRepeat(int delay = 0, int interval = 0) const;
void setKeyRepeat(int delay, int interval) const;
/**
* Gets the specified delay for the key repeat.
@@ -63,6 +67,11 @@ namespace sdl
**/
int getKeyRepeatInterval() const;
private:
static EnumMap<Key, SDLKey, Keyboard::KEY_MAX_ENUM>::Entry keyEntries[];
static EnumMap<Key, SDLKey, Keyboard::KEY_MAX_ENUM> keys;
}; // Keyboard
} // sdl
+14 -162
View File
@@ -26,12 +26,21 @@ namespace keyboard
{
namespace sdl
{
static Keyboard * instance = 0;
static Keyboard * instance;
int w_isDown(lua_State * L)
{
int b = luaL_checkint(L, 1);
luax_pushboolean(L, instance->isDown(b));
Keyboard::Key k;
if(Keyboard::getConstant(luaL_checkstring(L, 1), k))
{
luax_pushboolean(L, instance->isDown(k));
}
else
{
luax_pushboolean(L, false);
}
return 1;
}
@@ -39,13 +48,11 @@ namespace sdl
{
if(lua_gettop(L) == 0)
{
instance->setKeyRepeat();
instance->setKeyRepeat(0, 0);
return 0;
}
int a = luaL_checkint(L, 1);
int b = luaL_checkint(L, 2);
instance->setKeyRepeat(a, b);
instance->setKeyRepeat(luaL_checkint(L, 1), luaL_checkint(L, 2));
return 0;
}
@@ -64,160 +71,6 @@ namespace sdl
{ 0, 0 }
};
// List of constants.
static const Constant constants[] = {
{ "key_unknown", 0 },
{ "key_first", 0 },
{ "key_backspace", 8 },
{ "key_tab", 9 },
{ "key_clear", 12 },
{ "key_return", 13 },
{ "key_pause", 19 },
{ "key_escape", 27 },
{ "key_space", 32 },
{ "key_exclaim", 33 },
{ "key_quotedbl", 34 },
{ "key_hash", 35 },
{ "key_dollar", 36 },
{ "key_ampersand", 38 },
{ "key_quote", 39 },
{ "key_leftparen", 40 },
{ "key_rightparen", 41 },
{ "key_asterisk", 42 },
{ "key_plus", 43 },
{ "key_comma", 44 },
{ "key_minus", 45 },
{ "key_period", 46 },
{ "key_slash", 47 },
{ "key_0", 48 },
{ "key_1", 49 },
{ "key_2", 50 },
{ "key_3", 51 },
{ "key_4", 52 },
{ "key_5", 53 },
{ "key_6", 54 },
{ "key_7", 55 },
{ "key_8", 56 },
{ "key_9", 57 },
{ "key_colon", 58 },
{ "key_semicolon", 59 },
{ "key_less", 60 },
{ "key_equals", 61 },
{ "key_greater", 62 },
{ "key_question", 63 },
{ "key_at", 64 },
{ "key_leftbracket", 91 },
{ "key_backslash", 92 },
{ "key_rightbracket", 93 },
{ "key_caret", 94 },
{ "key_underscore", 95 },
{ "key_backquote", 96 },
{ "key_a", 97 },
{ "key_b", 98 },
{ "key_c", 99 },
{ "key_d", 100 },
{ "key_e", 101 },
{ "key_f", 102 },
{ "key_g", 103 },
{ "key_h", 104 },
{ "key_i", 105 },
{ "key_j", 106 },
{ "key_k", 107 },
{ "key_l", 108 },
{ "key_m", 109 },
{ "key_n", 110 },
{ "key_o", 111 },
{ "key_p", 112 },
{ "key_q", 113 },
{ "key_r", 114 },
{ "key_s", 115 },
{ "key_t", 116 },
{ "key_u", 117 },
{ "key_v", 118 },
{ "key_w", 119 },
{ "key_x", 120 },
{ "key_y", 121 },
{ "key_z", 122 },
{ "key_delete", 127 },
{ "key_kp0", 256 },
{ "key_kp1", 257 },
{ "key_kp2", 258 },
{ "key_kp3", 259 },
{ "key_kp4", 260 },
{ "key_kp5", 261 },
{ "key_kp6", 262 },
{ "key_kp7", 263 },
{ "key_kp8", 264 },
{ "key_kp9", 265 },
{ "key_kp_period", 266 },
{ "key_kp_divide", 267 },
{ "key_kp_multiply", 268 },
{ "key_kp_minus", 269 },
{ "key_kp_plus", 270 },
{ "key_kp_enter", 271 },
{ "key_kp_equals", 272 },
{ "key_up", 273 },
{ "key_down", 274 },
{ "key_right", 275 },
{ "key_left", 276 },
{ "key_insert", 277 },
{ "key_home", 278 },
{ "key_end", 279 },
{ "key_pageup", 280 },
{ "key_pagedown", 281 },
{ "key_f1", 282 },
{ "key_f2", 283 },
{ "key_f3", 284 },
{ "key_f4", 285 },
{ "key_f5", 286 },
{ "key_f6", 287 },
{ "key_f7", 288 },
{ "key_f8", 289 },
{ "key_f9", 290 },
{ "key_f10", 291 },
{ "key_f11", 292 },
{ "key_f12", 293 },
{ "key_f13", 294 },
{ "key_f14", 295 },
{ "key_f15", 296 },
{ "key_numlock", 300 },
{ "key_capslock", 301 },
{ "key_scrollock", 302 },
{ "key_rshift", 303 },
{ "key_lshift", 304 },
{ "key_rctrl", 305 },
{ "key_lctrl", 306 },
{ "key_ralt", 307 },
{ "key_lalt", 308 },
{ "key_rmeta", 309 },
{ "key_lmeta", 310 },
{ "key_lsuper", 311 },
{ "key_rsuper", 312 },
{ "key_mode", 313 },
{ "key_compose", 314 },
{ "key_help", 315 },
{ "key_print", 316 },
{ "key_sysreq", 317 },
{ "key_break", 318 },
{ "key_menu", 319 },
{ "key_power", 320 },
{ "key_euro", 321 },
{ "key_undo", 322 },
{ "key_repeat_delay", Keyboard::KEY_REPEAT_DELAY },
{ "key_repeat_interval", Keyboard::KEY_REPEAT_INTERVAL },
{ 0, 0 }
};
int luaopen_love_keyboard(lua_State * L)
{
if(instance == 0)
@@ -238,7 +91,6 @@ namespace sdl
w.flags = MODULE_T;
w.functions = functions;
w.types = 0;
w.constants = constants;
return luax_register_module(L, w);
}
+3
View File
@@ -25,6 +25,9 @@
#include <common/config.h>
#include "Keyboard.h"
// SDL
#include <SDL.h>
namespace love
{
namespace keyboard
@@ -16,27 +16,36 @@
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
**/
#ifndef LOVE_NATIVE_TCC_WRAP_NATIVE_H
#define LOVE_NATIVE_TCC_WRAP_NATIVE_H
// LOVE
#include <common/config.h>
#include "Native.h"
namespace love
{
namespace native
{
namespace tcc
{
int w_compile(lua_State * L);
int w_getSymbol(lua_State * L);
extern "C" LOVE_EXPORT int luaopen_love_native(lua_State * L);
} // tcc
} // native
} // love
#endif // LOVE_NATIVE_TCC_WRAP_NATIVE_H
**/
#include "Mouse.h"
namespace love
{
namespace mouse
{
bool Mouse::getConstant(const char * in, Button & out)
{
return buttons.find(in, out);
}
bool Mouse::getConstant(Button in, const char *& out)
{
return buttons.find(in, out);
}
StringMap<Mouse::Button, Mouse::BUTTON_MAX_ENUM>::Entry Mouse::buttonEntries[] =
{
{"l", Mouse::BUTTON_LEFT},
{"m", Mouse::BUTTON_MIDDLE},
{"r", Mouse::BUTTON_RIGHT},
{"wu", Mouse::BUTTON_WHEELUP},
{"wd", Mouse::BUTTON_WHEELDOWN},
{"x1", Mouse::BUTTON_X1},
{"x2", Mouse::BUTTON_X2},
};
StringMap<Mouse::Button, Mouse::BUTTON_MAX_ENUM> Mouse::buttons(Mouse::buttonEntries, sizeof(Mouse::buttonEntries));
} // mouse
} // love
+19 -6
View File
@@ -23,6 +23,7 @@
// LOVE
#include <common/Module.h>
#include <common/StringMap.h>
namespace love
{
@@ -32,17 +33,29 @@ namespace mouse
{
public:
enum MouseButton
enum Button
{
MOUSE_LEFT = 1,
MOUSE_MIDDLE,
MOUSE_RIGHT,
MOUSE_WHEELUP,
MOUSE_WHEELDOWN
BUTTON_INVALID,
BUTTON_LEFT,
BUTTON_MIDDLE,
BUTTON_RIGHT,
BUTTON_WHEELUP,
BUTTON_WHEELDOWN,
BUTTON_X1,
BUTTON_X2,
BUTTON_MAX_ENUM
};
virtual ~Mouse(){};
static bool getConstant(const char * in, Button & out);
static bool getConstant(Button in, const char *& out);
private:
static StringMap<Button, BUTTON_MAX_ENUM>::Entry buttonEntries[];
static StringMap<Button, BUTTON_MAX_ENUM> buttons;
}; // Mouse
} // mouse
+22 -4
View File
@@ -48,9 +48,9 @@ namespace sdl
return y;
}
void Mouse::getPosition(int * x, int * y) const
void Mouse::getPosition(int & x, int & y) const
{
SDL_GetMouseState(x, y);
SDL_GetMouseState(&x, &y);
}
void Mouse::setPosition(int x, int y)
@@ -63,9 +63,14 @@ namespace sdl
SDL_ShowCursor(visible ? SDL_ENABLE : SDL_DISABLE);
}
bool Mouse::isDown(int button) const
bool Mouse::isDown(Button button) const
{
return (SDL_GetMouseState(0, 0) & SDL_BUTTON(button)) != 0;
unsigned b = 0;
if(!buttons.find(button, b))
return false;
return (SDL_GetMouseState(0, 0) & SDL_BUTTON(b)) != 0;
}
bool Mouse::isVisible() const
@@ -83,6 +88,19 @@ namespace sdl
return (SDL_WM_GrabInput(SDL_GRAB_QUERY) == SDL_GRAB_ON ? true : false);
}
EnumMap<Mouse::Button, unsigned, Mouse::BUTTON_MAX_ENUM>::Entry Mouse::buttonEntries[] =
{
{ Mouse::BUTTON_LEFT, SDL_BUTTON_LEFT},
{ Mouse::BUTTON_MIDDLE, SDL_BUTTON_MIDDLE},
{ Mouse::BUTTON_RIGHT, SDL_BUTTON_RIGHT},
{ Mouse::BUTTON_WHEELUP, SDL_BUTTON_WHEELUP},
{ Mouse::BUTTON_WHEELDOWN, SDL_BUTTON_WHEELDOWN},
{ Mouse::BUTTON_X1, SDL_BUTTON_X1},
{ Mouse::BUTTON_X2, SDL_BUTTON_X2},
};
EnumMap<Mouse::Button, unsigned, Mouse::BUTTON_MAX_ENUM> Mouse::buttons(Mouse::buttonEntries, sizeof(Mouse::buttonEntries));
} // sdl
} // mouse
} // love
+8 -2
View File
@@ -23,6 +23,7 @@
// LOVE
#include <mouse/Mouse.h>
#include <common/EnumMap.h>
namespace love
{
@@ -39,14 +40,19 @@ namespace sdl
int getX() const;
int getY() const;
void getPosition(int * x, int * y) const;
void getPosition(int & x, int & y) const;
void setPosition(int x, int y);
void setVisible(bool visible);
bool isDown(int button) const;
bool isDown(Button button) const;
bool isVisible() const;
void setGrab(bool grab);
bool isGrabbed() const;
public:
static EnumMap<Button, unsigned, BUTTON_MAX_ENUM>::Entry buttonEntries[];
static EnumMap<Button, unsigned, BUTTON_MAX_ENUM> buttons;
}; // Mouse
} // sdl
+9 -16
View File
@@ -25,7 +25,7 @@ namespace love
namespace mouse
{
namespace sdl
{
{
static Mouse * instance = 0;
int w_getX(lua_State * L)
@@ -43,7 +43,7 @@ namespace sdl
int w_getPosition(lua_State * L)
{
int x, y;
instance->getPosition(&x, &y);
instance->getPosition(x, y);
lua_pushinteger(L, x);
lua_pushinteger(L, y);
return 2;
@@ -59,8 +59,13 @@ namespace sdl
int w_isDown(lua_State * L)
{
int b = luaL_checkint(L, 1);
luax_pushboolean(L, instance->isDown(b));
Mouse::Button button;
if(!Mouse::getConstant(luaL_checkstring(L, 1), button))
luax_pushboolean(L, false);
else
luax_pushboolean(L, instance->isDown(button));
return 1;
}
@@ -104,17 +109,6 @@ namespace sdl
{ 0, 0 }
};
// List of constants.
static const Constant constants[] = {
{ "mouse_left", Mouse::MOUSE_LEFT },
{ "mouse_middle", Mouse::MOUSE_MIDDLE },
{ "mouse_right", Mouse::MOUSE_RIGHT },
{ "mouse_wheelup", Mouse::MOUSE_WHEELUP },
{ "mouse_wheeldown", Mouse::MOUSE_WHEELDOWN },
{ 0, 0 }
};
int luaopen_love_mouse(lua_State * L)
{
if(instance == 0)
@@ -135,7 +129,6 @@ namespace sdl
w.flags = MODULE_T;
w.functions = functions;
w.types = 0;
w.constants = constants;
return luax_register_module(L, w);
}
-162
View File
@@ -1,162 +0,0 @@
/**
* Copyright (c) 2006-2009 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
**/
#include "Native.h"
#include <cstring>
#include <cstdlib>
// The API which should be made available to TCC.
#include "api.h"
namespace love
{
namespace native
{
namespace tcc
{
Compiler::Compiler()
: state(0), buffer(0)
{
state = tcc_new();
if(!state)
{
throw love::Exception("Could not create TCC state.");
}
tcc_set_output_type(state, TCC_OUTPUT_MEMORY);
// Add APIs here.
for(const tcc_function * f = tcc_api; (*f).name != 0; f++)
{
tcc_add_symbol(state, (*f).name, (*f).fn);
}
}
Compiler::~Compiler()
{
if(state != 0)
tcc_delete(state);
if(buffer != 0)
free(buffer);
}
bool Compiler::compile(const char ** str, int size)
{
if(state == 0)
return false;
for(int i =0; i<size; i++)
{
if (tcc_compile_string(state, str[i]) == -1)
return false;
}
if(!relocate())
return false;
return true;
}
bool Compiler::relocate()
{
if(state == 0)
return false;
int size = tcc_relocate(state, 0);
if(size == -1)
return false;
buffer = malloc(size);
if(buffer == 0)
return false;
if(tcc_relocate(state, buffer) == -1)
{
free(buffer);
buffer = 0;
return false;
}
return true;
}
void * Compiler::getSymbol(const char * sym)
{
if(state == 0)
return 0;
return tcc_get_symbol(state, sym);
}
Native::Native()
{
}
Native::~Native()
{
for(int i = 0; i<(int)compilers.size(); i++)
delete compilers[i];
}
const char * Native::getName() const
{
return "love.native.tcc";
}
bool Native::compile(const char ** str, int size)
{
// Create a new compiler.
Compiler * c = new Compiler();
// Compile the code.
if(!c->compile(str, size))
{
delete c;
return false;
}
compilers.push_back(c);
return true;
}
void * Native::getSymbol(const char * sym)
{
for(int i = 0; i<(int)compilers.size(); i++)
{
void * s = compilers[i]->getSymbol(sym);
if(s != 0)
return s;
}
return 0;
}
} // tcc
} // native
} // love
-99
View File
@@ -1,99 +0,0 @@
/**
* Copyright (c) 2006-2009 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
**/
#ifndef LOVE_NATIVE_TCC_NATIVE_H
#define LOVE_NATIVE_TCC_NATIVE_H
// C++
#include <vector>
// tcc
#include "libtcc/libtcc.h"
// LOVE
#include <common/Module.h>
namespace love
{
namespace native
{
namespace tcc
{
class Compiler
{
friend class Native;
private:
TCCState * state;
void * buffer;
public:
Compiler();
~Compiler();
bool compile(const char ** str, int size);
void * getSymbol(const char * sym);
private:
bool relocate();
};
class Native : public Module
{
private:
std::vector<Compiler *> compilers;
public:
/**
* Constructor.
**/
Native();
/**
* Destructor.
**/
~Native();
/**
* Gets the name of the module.
* @return Always returns "love.native.tcc".
**/
const char * getName() const;
/**
* Compile an array of strings in order, and relocate.
* @param The array of strings to compile.
* @param The number of strings to compile.
* @return True on success, false otherwise.
**/
bool compile(const char ** str, int size);
void * getSymbol(const char * sym);
}; // Native
} // tcc
} // native
} // love
#endif // LOVE_NATIVE_TCC_NATIVE_H
-113
View File
@@ -1,113 +0,0 @@
/**
* Copyright (c) 2006-2009 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
**/
#ifdef __cplusplus
extern "C" {
#endif
#include "api.h"
#include <stdlib.h>
#include <string.h>
// Lua
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
/*
* MSVC did not require that every funtion be
* cast to (void*), but gcc did. Ah well, this
* is shorter than {"funcname", funcname} anyway.
*/
#define FVOID(f) { #f, (void*)f }
const tcc_function tcc_api[] =
{
// cstring
FVOID(memcpy),
FVOID(memmove),
FVOID(strcpy),
FVOID(strncpy),
FVOID(strcat),
FVOID(strncat),
FVOID(memcmp),
FVOID(strcmp),
FVOID(strcoll),
FVOID(strncmp),
FVOID(strxfrm),
FVOID(memchr),
FVOID(strchr),
FVOID(strcspn),
FVOID(strpbrk),
FVOID(strrchr),
FVOID(strspn),
FVOID(strstr),
FVOID(strtok),
FVOID(memset),
FVOID(strerror),
FVOID(strlen),
// Lua (some of it)
FVOID(lua_isnumber),
FVOID(lua_isstring),
FVOID(lua_iscfunction),
FVOID(lua_isuserdata),
FVOID(lua_type),
FVOID(lua_typename),
FVOID(lua_equal),
FVOID(lua_rawequal),
FVOID(lua_lessthan),
FVOID(lua_tonumber),
FVOID(lua_tointeger),
FVOID(lua_toboolean),
FVOID(lua_tolstring),
FVOID(lua_objlen),
FVOID(lua_tocfunction),
FVOID(lua_touserdata),
FVOID(lua_tothread),
FVOID(lua_topointer),
FVOID(lua_pushnil),
FVOID(lua_pushnumber),
FVOID(lua_pushinteger),
FVOID(lua_pushlstring),
FVOID(lua_pushstring),
FVOID(lua_pushvfstring),
FVOID(lua_pushfstring),
FVOID(lua_pushcclosure),
FVOID(lua_pushboolean),
FVOID(lua_pushlightuserdata),
FVOID(lua_pushthread),
FVOID(luaL_register),
FVOID(luaL_error),
// End
{ 0, 0 }
};
#ifdef __cplusplus
}
#endif
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
-446
View File
@@ -1,446 +0,0 @@
/**************************************************************************/
/* COFF.H */
/* COFF data structures and related definitions used by the linker */
/**************************************************************************/
/*------------------------------------------------------------------------*/
/* COFF FILE HEADER */
/*------------------------------------------------------------------------*/
struct filehdr {
unsigned short f_magic; /* magic number */
unsigned short f_nscns; /* number of sections */
long f_timdat; /* time & date stamp */
long f_symptr; /* file pointer to symtab */
long f_nsyms; /* number of symtab entries */
unsigned short f_opthdr; /* sizeof(optional hdr) */
unsigned short f_flags; /* flags */
unsigned short f_TargetID; /* for C6x = 0x0099 */
};
/*------------------------------------------------------------------------*/
/* File header flags */
/*------------------------------------------------------------------------*/
#define F_RELFLG 0x01 /* relocation info stripped from file */
#define F_EXEC 0x02 /* file is executable (no unresolved refs) */
#define F_LNNO 0x04 /* line nunbers stripped from file */
#define F_LSYMS 0x08 /* local symbols stripped from file */
#define F_GSP10 0x10 /* 34010 version */
#define F_GSP20 0x20 /* 34020 version */
#define F_SWABD 0x40 /* bytes swabbed (in names) */
#define F_AR16WR 0x80 /* byte ordering of an AR16WR (PDP-11) */
#define F_LITTLE 0x100 /* byte ordering of an AR32WR (vax) */
#define F_BIG 0x200 /* byte ordering of an AR32W (3B, maxi) */
#define F_PATCH 0x400 /* contains "patch" list in optional header */
#define F_NODF 0x400
#define F_VERSION (F_GSP10 | F_GSP20)
#define F_BYTE_ORDER (F_LITTLE | F_BIG)
#define FILHDR struct filehdr
//#define FILHSZ sizeof(FILHDR)
#define FILHSZ 22 // above rounds to align on 4 bytes which causes problems
#define COFF_C67_MAGIC 0x00c2
/*------------------------------------------------------------------------*/
/* Macros to recognize magic numbers */
/*------------------------------------------------------------------------*/
#define ISMAGIC(x) (((unsigned short)(x))==(unsigned short)magic)
#define ISARCHIVE(x) ((((unsigned short)(x))==(unsigned short)ARTYPE))
#define BADMAGIC(x) (((unsigned short)(x) & 0x8080) && !ISMAGIC(x))
/*------------------------------------------------------------------------*/
/* OPTIONAL FILE HEADER */
/*------------------------------------------------------------------------*/
typedef struct aouthdr {
short magic; /* see magic.h */
short vstamp; /* version stamp */
long tsize; /* text size in bytes, padded to FW bdry*/
long dsize; /* initialized data " " */
long bsize; /* uninitialized data " " */
long entrypt; /* entry pt. */
long text_start; /* base of text used for this file */
long data_start; /* base of data used for this file */
} AOUTHDR;
#define AOUTSZ sizeof(AOUTHDR)
/*----------------------------------------------------------------------*/
/* When a UNIX aout header is to be built in the optional header, */
/* the following magic numbers can appear in that header: */
/* */
/* AOUT1MAGIC : default : readonly sharable text segment */
/* AOUT2MAGIC: : writable text segment */
/* PAGEMAGIC : : configured for paging */
/*----------------------------------------------------------------------*/
#define AOUT1MAGIC 0410
#define AOUT2MAGIC 0407
#define PAGEMAGIC 0413
/*------------------------------------------------------------------------*/
/* COMMON ARCHIVE FILE STRUCTURES */
/* */
/* ARCHIVE File Organization: */
/* _______________________________________________ */
/* |__________ARCHIVE_MAGIC_STRING_______________| */
/* |__________ARCHIVE_FILE_MEMBER_1______________| */
/* | | */
/* | Archive File Header "ar_hdr" | */
/* |.............................................| */
/* | Member Contents | */
/* | 1. External symbol directory | */
/* | 2. Text file | */
/* |_____________________________________________| */
/* |________ARCHIVE_FILE_MEMBER_2________________| */
/* | "ar_hdr" | */
/* |.............................................| */
/* | Member Contents (.o or text file) | */
/* |_____________________________________________| */
/* | . . . | */
/* | . . . | */
/* | . . . | */
/* |_____________________________________________| */
/* |________ARCHIVE_FILE_MEMBER_n________________| */
/* | "ar_hdr" | */
/* |.............................................| */
/* | Member Contents | */
/* |_____________________________________________| */
/* */
/*------------------------------------------------------------------------*/
#define COFF_ARMAG "!<arch>\n"
#define SARMAG 8
#define ARFMAG "`\n"
struct ar_hdr /* archive file member header - printable ascii */
{
char ar_name[16]; /* file member name - `/' terminated */
char ar_date[12]; /* file member date - decimal */
char ar_uid[6]; /* file member user id - decimal */
char ar_gid[6]; /* file member group id - decimal */
char ar_mode[8]; /* file member mode - octal */
char ar_size[10]; /* file member size - decimal */
char ar_fmag[2]; /* ARFMAG - string to end header */
};
/*------------------------------------------------------------------------*/
/* SECTION HEADER */
/*------------------------------------------------------------------------*/
struct scnhdr {
char s_name[8]; /* section name */
long s_paddr; /* physical address */
long s_vaddr; /* virtual address */
long s_size; /* section size */
long s_scnptr; /* file ptr to raw data for section */
long s_relptr; /* file ptr to relocation */
long s_lnnoptr; /* file ptr to line numbers */
unsigned int s_nreloc; /* number of relocation entries */
unsigned int s_nlnno; /* number of line number entries */
unsigned int s_flags; /* flags */
unsigned short s_reserved; /* reserved byte */
unsigned short s_page; /* memory page id */
};
#define SCNHDR struct scnhdr
#define SCNHSZ sizeof(SCNHDR)
/*------------------------------------------------------------------------*/
/* Define constants for names of "special" sections */
/*------------------------------------------------------------------------*/
//#define _TEXT ".text"
#define _DATA ".data"
#define _BSS ".bss"
#define _CINIT ".cinit"
#define _TV ".tv"
/*------------------------------------------------------------------------*/
/* The low 4 bits of s_flags is used as a section "type" */
/*------------------------------------------------------------------------*/
#define STYP_REG 0x00 /* "regular" : allocated, relocated, loaded */
#define STYP_DSECT 0x01 /* "dummy" : not allocated, relocated, not loaded */
#define STYP_NOLOAD 0x02 /* "noload" : allocated, relocated, not loaded */
#define STYP_GROUP 0x04 /* "grouped" : formed of input sections */
#define STYP_PAD 0x08 /* "padding" : not allocated, not relocated, loaded */
#define STYP_COPY 0x10 /* "copy" : used for C init tables -
not allocated, relocated,
loaded; reloc & lineno
entries processed normally */
#define STYP_TEXT 0x20 /* section contains text only */
#define STYP_DATA 0x40 /* section contains data only */
#define STYP_BSS 0x80 /* section contains bss only */
#define STYP_ALIGN 0x100 /* align flag passed by old version assemblers */
#define ALIGN_MASK 0x0F00 /* part of s_flags that is used for align vals */
#define ALIGNSIZE(x) (1 << ((x & ALIGN_MASK) >> 8))
/*------------------------------------------------------------------------*/
/* RELOCATION ENTRIES */
/*------------------------------------------------------------------------*/
struct reloc
{
long r_vaddr; /* (virtual) address of reference */
short r_symndx; /* index into symbol table */
unsigned short r_disp; /* additional bits for address calculation */
unsigned short r_type; /* relocation type */
};
#define RELOC struct reloc
#define RELSZ 10 /* sizeof(RELOC) */
/*--------------------------------------------------------------------------*/
/* define all relocation types */
/*--------------------------------------------------------------------------*/
#define R_ABS 0 /* absolute address - no relocation */
#define R_DIR16 01 /* UNUSED */
#define R_REL16 02 /* UNUSED */
#define R_DIR24 04 /* UNUSED */
#define R_REL24 05 /* 24 bits, direct */
#define R_DIR32 06 /* UNUSED */
#define R_RELBYTE 017 /* 8 bits, direct */
#define R_RELWORD 020 /* 16 bits, direct */
#define R_RELLONG 021 /* 32 bits, direct */
#define R_PCRBYTE 022 /* 8 bits, PC-relative */
#define R_PCRWORD 023 /* 16 bits, PC-relative */
#define R_PCRLONG 024 /* 32 bits, PC-relative */
#define R_OCRLONG 030 /* GSP: 32 bits, one's complement direct */
#define R_GSPPCR16 031 /* GSP: 16 bits, PC relative (in words) */
#define R_GSPOPR32 032 /* GSP: 32 bits, direct big-endian */
#define R_PARTLS16 040 /* Brahma: 16 bit offset of 24 bit address*/
#define R_PARTMS8 041 /* Brahma: 8 bit page of 24 bit address */
#define R_PARTLS7 050 /* DSP: 7 bit offset of 16 bit address */
#define R_PARTMS9 051 /* DSP: 9 bit page of 16 bit address */
#define R_REL13 052 /* DSP: 13 bits, direct */
/*------------------------------------------------------------------------*/
/* LINE NUMBER ENTRIES */
/*------------------------------------------------------------------------*/
struct lineno
{
union
{
long l_symndx ; /* sym. table index of function name
iff l_lnno == 0 */
long l_paddr ; /* (physical) address of line number */
} l_addr ;
unsigned short l_lnno ; /* line number */
};
#define LINENO struct lineno
#define LINESZ 6 /* sizeof(LINENO) */
/*------------------------------------------------------------------------*/
/* STORAGE CLASSES */
/*------------------------------------------------------------------------*/
#define C_EFCN -1 /* physical end of function */
#define C_NULL 0
#define C_AUTO 1 /* automatic variable */
#define C_EXT 2 /* external symbol */
#define C_STAT 3 /* static */
#define C_REG 4 /* register variable */
#define C_EXTDEF 5 /* external definition */
#define C_LABEL 6 /* label */
#define C_ULABEL 7 /* undefined label */
#define C_MOS 8 /* member of structure */
#define C_ARG 9 /* function argument */
#define C_STRTAG 10 /* structure tag */
#define C_MOU 11 /* member of union */
#define C_UNTAG 12 /* union tag */
#define C_TPDEF 13 /* type definition */
#define C_USTATIC 14 /* undefined static */
#define C_ENTAG 15 /* enumeration tag */
#define C_MOE 16 /* member of enumeration */
#define C_REGPARM 17 /* register parameter */
#define C_FIELD 18 /* bit field */
#define C_BLOCK 100 /* ".bb" or ".eb" */
#define C_FCN 101 /* ".bf" or ".ef" */
#define C_EOS 102 /* end of structure */
#define C_FILE 103 /* file name */
#define C_LINE 104 /* dummy sclass for line number entry */
#define C_ALIAS 105 /* duplicate tag */
#define C_HIDDEN 106 /* special storage class for external */
/* symbols in dmert public libraries */
/*------------------------------------------------------------------------*/
/* SYMBOL TABLE ENTRIES */
/*------------------------------------------------------------------------*/
#define SYMNMLEN 8 /* Number of characters in a symbol name */
#define FILNMLEN 14 /* Number of characters in a file name */
#define DIMNUM 4 /* Number of array dimensions in auxiliary entry */
struct syment
{
union
{
char _n_name[SYMNMLEN]; /* old COFF version */
struct
{
long _n_zeroes; /* new == 0 */
long _n_offset; /* offset into string table */
} _n_n;
char *_n_nptr[2]; /* allows for overlaying */
} _n;
long n_value; /* value of symbol */
short n_scnum; /* section number */
unsigned short n_type; /* type and derived type */
char n_sclass; /* storage class */
char n_numaux; /* number of aux. entries */
};
#define n_name _n._n_name
#define n_nptr _n._n_nptr[1]
#define n_zeroes _n._n_n._n_zeroes
#define n_offset _n._n_n._n_offset
/*------------------------------------------------------------------------*/
/* Relocatable symbols have a section number of the */
/* section in which they are defined. Otherwise, section */
/* numbers have the following meanings: */
/*------------------------------------------------------------------------*/
#define N_UNDEF 0 /* undefined symbol */
#define N_ABS -1 /* value of symbol is absolute */
#define N_DEBUG -2 /* special debugging symbol */
#define N_TV (unsigned short)-3 /* needs transfer vector (preload) */
#define P_TV (unsigned short)-4 /* needs transfer vector (postload) */
/*------------------------------------------------------------------------*/
/* The fundamental type of a symbol packed into the low */
/* 4 bits of the word. */
/*------------------------------------------------------------------------*/
#define _EF ".ef"
#define T_NULL 0 /* no type info */
#define T_ARG 1 /* function argument (only used by compiler) */
#define T_CHAR 2 /* character */
#define T_SHORT 3 /* short integer */
#define T_INT 4 /* integer */
#define T_LONG 5 /* long integer */
#define T_FLOAT 6 /* floating point */
#define T_DOUBLE 7 /* double word */
#define T_STRUCT 8 /* structure */
#define T_UNION 9 /* union */
#define T_ENUM 10 /* enumeration */
#define T_MOE 11 /* member of enumeration */
#define T_UCHAR 12 /* unsigned character */
#define T_USHORT 13 /* unsigned short */
#define T_UINT 14 /* unsigned integer */
#define T_ULONG 15 /* unsigned long */
/*------------------------------------------------------------------------*/
/* derived types are: */
/*------------------------------------------------------------------------*/
#define DT_NON 0 /* no derived type */
#define DT_PTR 1 /* pointer */
#define DT_FCN 2 /* function */
#define DT_ARY 3 /* array */
#define MKTYPE(basic, d1,d2,d3,d4,d5,d6) \
((basic) | ((d1) << 4) | ((d2) << 6) | ((d3) << 8) |\
((d4) << 10) | ((d5) << 12) | ((d6) << 14))
/*------------------------------------------------------------------------*/
/* type packing constants and macros */
/*------------------------------------------------------------------------*/
#define N_BTMASK_COFF 017
#define N_TMASK_COFF 060
#define N_TMASK1_COFF 0300
#define N_TMASK2_COFF 0360
#define N_BTSHFT_COFF 4
#define N_TSHIFT_COFF 2
#define BTYPE_COFF(x) ((x) & N_BTMASK_COFF)
#define ISINT(x) (((x) >= T_CHAR && (x) <= T_LONG) || \
((x) >= T_UCHAR && (x) <= T_ULONG) || (x) == T_ENUM)
#define ISFLT_COFF(x) ((x) == T_DOUBLE || (x) == T_FLOAT)
#define ISPTR_COFF(x) (((x) & N_TMASK_COFF) == (DT_PTR << N_BTSHFT_COFF))
#define ISFCN_COFF(x) (((x) & N_TMASK_COFF) == (DT_FCN << N_BTSHFT_COFF))
#define ISARY_COFF(x) (((x) & N_TMASK_COFF) == (DT_ARY << N_BTSHFT_COFF))
#define ISTAG_COFF(x) ((x)==C_STRTAG || (x)==C_UNTAG || (x)==C_ENTAG)
#define INCREF_COFF(x) ((((x)&~N_BTMASK_COFF)<<N_TSHIFT_COFF)|(DT_PTR<<N_BTSHFT_COFF)|(x&N_BTMASK_COFF))
#define DECREF_COFF(x) ((((x)>>N_TSHIFT_COFF)&~N_BTMASK_COFF)|((x)&N_BTMASK_COFF))
/*------------------------------------------------------------------------*/
/* AUXILIARY SYMBOL ENTRY */
/*------------------------------------------------------------------------*/
union auxent
{
struct
{
long x_tagndx; /* str, un, or enum tag indx */
union
{
struct
{
unsigned short x_lnno; /* declaration line number */
unsigned short x_size; /* str, union, array size */
} x_lnsz;
long x_fsize; /* size of function */
} x_misc;
union
{
struct /* if ISFCN, tag, or .bb */
{
long x_lnnoptr; /* ptr to fcn line # */
long x_endndx; /* entry ndx past block end */
} x_fcn;
struct /* if ISARY, up to 4 dimen. */
{
unsigned short x_dimen[DIMNUM];
} x_ary;
} x_fcnary;
unsigned short x_regcount; /* number of registers used by func */
} x_sym;
struct
{
char x_fname[FILNMLEN];
} x_file;
struct
{
long x_scnlen; /* section length */
unsigned short x_nreloc; /* number of relocation entries */
unsigned short x_nlinno; /* number of line numbers */
} x_scn;
};
#define SYMENT struct syment
#define SYMESZ 18 /* sizeof(SYMENT) */
#define AUXENT union auxent
#define AUXESZ 18 /* sizeof(AUXENT) */
/*------------------------------------------------------------------------*/
/* NAMES OF "SPECIAL" SYMBOLS */
/*------------------------------------------------------------------------*/
#define _STEXT ".text"
#define _ETEXT "etext"
#define _SDATA ".data"
#define _EDATA "edata"
#define _SBSS ".bss"
#define _END "end"
#define _CINITPTR "cinit"
/*--------------------------------------------------------------------------*/
/* ENTRY POINT SYMBOLS */
/*--------------------------------------------------------------------------*/
#define _START "_start"
#define _MAIN "_main"
/* _CSTART "_c_int00" (defined in params.h) */
#define _TVORIG "_tvorig"
#define _TORIGIN "_torigin"
#define _DORIGIN "_dorigin"
#define _SORIGIN "_sorigin"
-4
View File
@@ -1,4 +0,0 @@
#define TCC_VERSION "0.9.25"
#define TCC_TARGET_PE 1
#define CONFIG_TCCDIR "."
#define CONFIG_SYSROOT ""
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
-446
View File
@@ -1,446 +0,0 @@
DEF_ASM_OP0(pusha, 0x60) /* must be first OP0 */
DEF_ASM_OP0(popa, 0x61)
DEF_ASM_OP0(clc, 0xf8)
DEF_ASM_OP0(cld, 0xfc)
DEF_ASM_OP0(cli, 0xfa)
DEF_ASM_OP0(clts, 0x0f06)
DEF_ASM_OP0(cmc, 0xf5)
DEF_ASM_OP0(lahf, 0x9f)
DEF_ASM_OP0(sahf, 0x9e)
DEF_ASM_OP0(pushfl, 0x9c)
DEF_ASM_OP0(popfl, 0x9d)
DEF_ASM_OP0(pushf, 0x9c)
DEF_ASM_OP0(popf, 0x9d)
DEF_ASM_OP0(stc, 0xf9)
DEF_ASM_OP0(std, 0xfd)
DEF_ASM_OP0(sti, 0xfb)
DEF_ASM_OP0(aaa, 0x37)
DEF_ASM_OP0(aas, 0x3f)
DEF_ASM_OP0(daa, 0x27)
DEF_ASM_OP0(das, 0x2f)
DEF_ASM_OP0(aad, 0xd50a)
DEF_ASM_OP0(aam, 0xd40a)
DEF_ASM_OP0(cbw, 0x6698)
DEF_ASM_OP0(cwd, 0x6699)
DEF_ASM_OP0(cwde, 0x98)
DEF_ASM_OP0(cdq, 0x99)
DEF_ASM_OP0(cbtw, 0x6698)
DEF_ASM_OP0(cwtl, 0x98)
DEF_ASM_OP0(cwtd, 0x6699)
DEF_ASM_OP0(cltd, 0x99)
DEF_ASM_OP0(int3, 0xcc)
DEF_ASM_OP0(into, 0xce)
DEF_ASM_OP0(iret, 0xcf)
DEF_ASM_OP0(rsm, 0x0faa)
DEF_ASM_OP0(hlt, 0xf4)
DEF_ASM_OP0(wait, 0x9b)
DEF_ASM_OP0(nop, 0x90)
DEF_ASM_OP0(xlat, 0xd7)
/* strings */
ALT(DEF_ASM_OP0L(cmpsb, 0xa6, 0, OPC_BWL))
ALT(DEF_ASM_OP0L(scmpb, 0xa6, 0, OPC_BWL))
ALT(DEF_ASM_OP0L(insb, 0x6c, 0, OPC_BWL))
ALT(DEF_ASM_OP0L(outsb, 0x6e, 0, OPC_BWL))
ALT(DEF_ASM_OP0L(lodsb, 0xac, 0, OPC_BWL))
ALT(DEF_ASM_OP0L(slodb, 0xac, 0, OPC_BWL))
ALT(DEF_ASM_OP0L(movsb, 0xa4, 0, OPC_BWL))
ALT(DEF_ASM_OP0L(smovb, 0xa4, 0, OPC_BWL))
ALT(DEF_ASM_OP0L(scasb, 0xae, 0, OPC_BWL))
ALT(DEF_ASM_OP0L(sscab, 0xae, 0, OPC_BWL))
ALT(DEF_ASM_OP0L(stosb, 0xaa, 0, OPC_BWL))
ALT(DEF_ASM_OP0L(sstob, 0xaa, 0, OPC_BWL))
/* bits */
ALT(DEF_ASM_OP2(bsfw, 0x0fbc, 0, OPC_MODRM | OPC_WL, OPT_REGW | OPT_EA, OPT_REGW))
ALT(DEF_ASM_OP2(bsrw, 0x0fbd, 0, OPC_MODRM | OPC_WL, OPT_REGW | OPT_EA, OPT_REGW))
ALT(DEF_ASM_OP2(btw, 0x0fa3, 0, OPC_MODRM | OPC_WL, OPT_REGW, OPT_REGW | OPT_EA))
ALT(DEF_ASM_OP2(btw, 0x0fba, 4, OPC_MODRM | OPC_WL, OPT_IM8, OPT_REGW | OPT_EA))
ALT(DEF_ASM_OP2(btsw, 0x0fab, 0, OPC_MODRM | OPC_WL, OPT_REGW, OPT_REGW | OPT_EA))
ALT(DEF_ASM_OP2(btsw, 0x0fba, 5, OPC_MODRM | OPC_WL, OPT_IM8, OPT_REGW | OPT_EA))
ALT(DEF_ASM_OP2(btrw, 0x0fb3, 0, OPC_MODRM | OPC_WL, OPT_REGW, OPT_REGW | OPT_EA))
ALT(DEF_ASM_OP2(btrw, 0x0fba, 6, OPC_MODRM | OPC_WL, OPT_IM8, OPT_REGW | OPT_EA))
ALT(DEF_ASM_OP2(btcw, 0x0fbb, 0, OPC_MODRM | OPC_WL, OPT_REGW, OPT_REGW | OPT_EA))
ALT(DEF_ASM_OP2(btcw, 0x0fba, 7, OPC_MODRM | OPC_WL, OPT_IM8, OPT_REGW | OPT_EA))
/* prefixes */
DEF_ASM_OP0(aword, 0x67)
DEF_ASM_OP0(addr16, 0x67)
DEF_ASM_OP0(word, 0x66)
DEF_ASM_OP0(data16, 0x66)
DEF_ASM_OP0(lock, 0xf0)
DEF_ASM_OP0(rep, 0xf3)
DEF_ASM_OP0(repe, 0xf3)
DEF_ASM_OP0(repz, 0xf3)
DEF_ASM_OP0(repne, 0xf2)
DEF_ASM_OP0(repnz, 0xf2)
DEF_ASM_OP0(invd, 0x0f08)
DEF_ASM_OP0(wbinvd, 0x0f09)
DEF_ASM_OP0(cpuid, 0x0fa2)
DEF_ASM_OP0(wrmsr, 0x0f30)
DEF_ASM_OP0(rdtsc, 0x0f31)
DEF_ASM_OP0(rdmsr, 0x0f32)
DEF_ASM_OP0(rdpmc, 0x0f33)
DEF_ASM_OP0(ud2, 0x0f0b)
/* NOTE: we took the same order as gas opcode definition order */
ALT(DEF_ASM_OP2(movb, 0xa0, 0, OPC_BWL, OPT_ADDR, OPT_EAX))
ALT(DEF_ASM_OP2(movb, 0xa2, 0, OPC_BWL, OPT_EAX, OPT_ADDR))
ALT(DEF_ASM_OP2(movb, 0x88, 0, OPC_MODRM | OPC_BWL, OPT_REG, OPT_EA | OPT_REG))
ALT(DEF_ASM_OP2(movb, 0x8a, 0, OPC_MODRM | OPC_BWL, OPT_EA | OPT_REG, OPT_REG))
ALT(DEF_ASM_OP2(movb, 0xb0, 0, OPC_REG | OPC_BWL, OPT_IM, OPT_REG))
ALT(DEF_ASM_OP2(movb, 0xc6, 0, OPC_MODRM | OPC_BWL, OPT_IM, OPT_REG | OPT_EA))
ALT(DEF_ASM_OP2(movw, 0x8c, 0, OPC_MODRM | OPC_WL, OPT_SEG, OPT_EA | OPT_REG))
ALT(DEF_ASM_OP2(movw, 0x8e, 0, OPC_MODRM | OPC_WL, OPT_EA | OPT_REG, OPT_SEG))
ALT(DEF_ASM_OP2(movw, 0x0f20, 0, OPC_MODRM | OPC_WL, OPT_CR, OPT_REG32))
ALT(DEF_ASM_OP2(movw, 0x0f21, 0, OPC_MODRM | OPC_WL, OPT_DB, OPT_REG32))
ALT(DEF_ASM_OP2(movw, 0x0f24, 0, OPC_MODRM | OPC_WL, OPT_TR, OPT_REG32))
ALT(DEF_ASM_OP2(movw, 0x0f22, 0, OPC_MODRM | OPC_WL, OPT_REG32, OPT_CR))
ALT(DEF_ASM_OP2(movw, 0x0f23, 0, OPC_MODRM | OPC_WL, OPT_REG32, OPT_DB))
ALT(DEF_ASM_OP2(movw, 0x0f26, 0, OPC_MODRM | OPC_WL, OPT_REG32, OPT_TR))
ALT(DEF_ASM_OP2(movsbl, 0x0fbe, 0, OPC_MODRM, OPT_REG8 | OPT_EA, OPT_REG32))
ALT(DEF_ASM_OP2(movsbw, 0x0fbe, 0, OPC_MODRM | OPC_D16, OPT_REG8 | OPT_EA, OPT_REG16))
ALT(DEF_ASM_OP2(movswl, 0x0fbf, 0, OPC_MODRM, OPT_REG16 | OPT_EA, OPT_REG32))
ALT(DEF_ASM_OP2(movzbw, 0x0fb6, 0, OPC_MODRM | OPC_WL, OPT_REG8 | OPT_EA, OPT_REGW))
ALT(DEF_ASM_OP2(movzwl, 0x0fb7, 0, OPC_MODRM, OPT_REG16 | OPT_EA, OPT_REG32))
ALT(DEF_ASM_OP1(pushw, 0x50, 0, OPC_REG | OPC_WL, OPT_REGW))
ALT(DEF_ASM_OP1(pushw, 0xff, 6, OPC_MODRM | OPC_WL, OPT_REGW | OPT_EA))
ALT(DEF_ASM_OP1(pushw, 0x6a, 0, OPC_WL, OPT_IM8S))
ALT(DEF_ASM_OP1(pushw, 0x68, 0, OPC_WL, OPT_IM32))
ALT(DEF_ASM_OP1(pushw, 0x06, 0, OPC_WL, OPT_SEG))
ALT(DEF_ASM_OP1(popw, 0x58, 0, OPC_REG | OPC_WL, OPT_REGW))
ALT(DEF_ASM_OP1(popw, 0x8f, 0, OPC_MODRM | OPC_WL, OPT_REGW | OPT_EA))
ALT(DEF_ASM_OP1(popw, 0x07, 0, OPC_WL, OPT_SEG))
ALT(DEF_ASM_OP2(xchgw, 0x90, 0, OPC_REG | OPC_WL, OPT_REG, OPT_EAX))
ALT(DEF_ASM_OP2(xchgw, 0x90, 0, OPC_REG | OPC_WL, OPT_EAX, OPT_REG))
ALT(DEF_ASM_OP2(xchgb, 0x86, 0, OPC_MODRM | OPC_BWL, OPT_REG, OPT_EA | OPT_REG))
ALT(DEF_ASM_OP2(xchgb, 0x86, 0, OPC_MODRM | OPC_BWL, OPT_EA | OPT_REG, OPT_REG))
ALT(DEF_ASM_OP2(inb, 0xe4, 0, OPC_BWL, OPT_IM8, OPT_EAX))
ALT(DEF_ASM_OP1(inb, 0xe4, 0, OPC_BWL, OPT_IM8))
ALT(DEF_ASM_OP2(inb, 0xec, 0, OPC_BWL, OPT_DX, OPT_EAX))
ALT(DEF_ASM_OP1(inb, 0xec, 0, OPC_BWL, OPT_DX))
ALT(DEF_ASM_OP2(outb, 0xe6, 0, OPC_BWL, OPT_EAX, OPT_IM8))
ALT(DEF_ASM_OP1(outb, 0xe6, 0, OPC_BWL, OPT_IM8))
ALT(DEF_ASM_OP2(outb, 0xee, 0, OPC_BWL, OPT_EAX, OPT_DX))
ALT(DEF_ASM_OP1(outb, 0xee, 0, OPC_BWL, OPT_DX))
ALT(DEF_ASM_OP2(leaw, 0x8d, 0, OPC_MODRM | OPC_WL, OPT_EA, OPT_REG))
ALT(DEF_ASM_OP2(les, 0xc4, 0, OPC_MODRM, OPT_EA, OPT_REG32))
ALT(DEF_ASM_OP2(lds, 0xc5, 0, OPC_MODRM, OPT_EA, OPT_REG32))
ALT(DEF_ASM_OP2(lss, 0x0fb2, 0, OPC_MODRM, OPT_EA, OPT_REG32))
ALT(DEF_ASM_OP2(lfs, 0x0fb4, 0, OPC_MODRM, OPT_EA, OPT_REG32))
ALT(DEF_ASM_OP2(lgs, 0x0fb5, 0, OPC_MODRM, OPT_EA, OPT_REG32))
/* arith */
ALT(DEF_ASM_OP2(addb, 0x00, 0, OPC_ARITH | OPC_MODRM | OPC_BWL, OPT_REG, OPT_EA | OPT_REG)) /* XXX: use D bit ? */
ALT(DEF_ASM_OP2(addb, 0x02, 0, OPC_ARITH | OPC_MODRM | OPC_BWL, OPT_EA | OPT_REG, OPT_REG))
ALT(DEF_ASM_OP2(addb, 0x04, 0, OPC_ARITH | OPC_BWL, OPT_IM, OPT_EAX))
ALT(DEF_ASM_OP2(addb, 0x80, 0, OPC_ARITH | OPC_MODRM | OPC_BWL, OPT_IM, OPT_EA | OPT_REG))
ALT(DEF_ASM_OP2(addw, 0x83, 0, OPC_ARITH | OPC_MODRM | OPC_WL, OPT_IM8S, OPT_EA | OPT_REG))
ALT(DEF_ASM_OP2(testb, 0x84, 0, OPC_MODRM | OPC_BWL, OPT_EA | OPT_REG, OPT_REG))
ALT(DEF_ASM_OP2(testb, 0x84, 0, OPC_MODRM | OPC_BWL, OPT_REG, OPT_EA | OPT_REG))
ALT(DEF_ASM_OP2(testb, 0xa8, 0, OPC_BWL, OPT_IM, OPT_EAX))
ALT(DEF_ASM_OP2(testb, 0xf6, 0, OPC_MODRM | OPC_BWL, OPT_IM, OPT_EA | OPT_REG))
ALT(DEF_ASM_OP1(incw, 0x40, 0, OPC_REG | OPC_WL, OPT_REGW))
ALT(DEF_ASM_OP1(incb, 0xfe, 0, OPC_MODRM | OPC_BWL, OPT_REG | OPT_EA))
ALT(DEF_ASM_OP1(decw, 0x48, 0, OPC_REG | OPC_WL, OPT_REGW))
ALT(DEF_ASM_OP1(decb, 0xfe, 1, OPC_MODRM | OPC_BWL, OPT_REG | OPT_EA))
ALT(DEF_ASM_OP1(notb, 0xf6, 2, OPC_MODRM | OPC_BWL, OPT_REG | OPT_EA))
ALT(DEF_ASM_OP1(negb, 0xf6, 3, OPC_MODRM | OPC_BWL, OPT_REG | OPT_EA))
ALT(DEF_ASM_OP1(mulb, 0xf6, 4, OPC_MODRM | OPC_BWL, OPT_REG | OPT_EA))
ALT(DEF_ASM_OP1(imulb, 0xf6, 5, OPC_MODRM | OPC_BWL, OPT_REG | OPT_EA))
ALT(DEF_ASM_OP2(imulw, 0x0faf, 0, OPC_MODRM | OPC_WL, OPT_REG | OPT_EA, OPT_REG))
ALT(DEF_ASM_OP3(imulw, 0x6b, 0, OPC_MODRM | OPC_WL, OPT_IM8S, OPT_REGW | OPT_EA, OPT_REGW))
ALT(DEF_ASM_OP2(imulw, 0x6b, 0, OPC_MODRM | OPC_WL, OPT_IM8S, OPT_REGW))
ALT(DEF_ASM_OP3(imulw, 0x69, 0, OPC_MODRM | OPC_WL, OPT_IMW, OPT_REGW | OPT_EA, OPT_REGW))
ALT(DEF_ASM_OP2(imulw, 0x69, 0, OPC_MODRM | OPC_WL, OPT_IMW, OPT_REGW))
ALT(DEF_ASM_OP1(divb, 0xf6, 6, OPC_MODRM | OPC_BWL, OPT_REG | OPT_EA))
ALT(DEF_ASM_OP2(divb, 0xf6, 6, OPC_MODRM | OPC_BWL, OPT_REG | OPT_EA, OPT_EAX))
ALT(DEF_ASM_OP1(idivb, 0xf6, 7, OPC_MODRM | OPC_BWL, OPT_REG | OPT_EA))
ALT(DEF_ASM_OP2(idivb, 0xf6, 7, OPC_MODRM | OPC_BWL, OPT_REG | OPT_EA, OPT_EAX))
/* shifts */
ALT(DEF_ASM_OP2(rolb, 0xc0, 0, OPC_MODRM | OPC_BWL | OPC_SHIFT, OPT_IM8, OPT_EA | OPT_REG))
ALT(DEF_ASM_OP2(rolb, 0xd2, 0, OPC_MODRM | OPC_BWL | OPC_SHIFT, OPT_CL, OPT_EA | OPT_REG))
ALT(DEF_ASM_OP1(rolb, 0xd0, 0, OPC_MODRM | OPC_BWL | OPC_SHIFT, OPT_EA | OPT_REG))
ALT(DEF_ASM_OP3(shldw, 0x0fa4, 0, OPC_MODRM | OPC_WL, OPT_IM8, OPT_REGW, OPT_EA | OPT_REGW))
ALT(DEF_ASM_OP3(shldw, 0x0fa5, 0, OPC_MODRM | OPC_WL, OPT_CL, OPT_REGW, OPT_EA | OPT_REGW))
ALT(DEF_ASM_OP2(shldw, 0x0fa5, 0, OPC_MODRM | OPC_WL, OPT_REGW, OPT_EA | OPT_REGW))
ALT(DEF_ASM_OP3(shrdw, 0x0fac, 0, OPC_MODRM | OPC_WL, OPT_IM8, OPT_REGW, OPT_EA | OPT_REGW))
ALT(DEF_ASM_OP3(shrdw, 0x0fad, 0, OPC_MODRM | OPC_WL, OPT_CL, OPT_REGW, OPT_EA | OPT_REGW))
ALT(DEF_ASM_OP2(shrdw, 0x0fad, 0, OPC_MODRM | OPC_WL, OPT_REGW, OPT_EA | OPT_REGW))
ALT(DEF_ASM_OP1(call, 0xff, 2, OPC_MODRM, OPT_INDIR))
ALT(DEF_ASM_OP1(call, 0xe8, 0, OPC_JMP, OPT_ADDR))
ALT(DEF_ASM_OP1(jmp, 0xff, 4, OPC_MODRM, OPT_INDIR))
ALT(DEF_ASM_OP1(jmp, 0xeb, 0, OPC_SHORTJMP | OPC_JMP, OPT_ADDR))
ALT(DEF_ASM_OP2(lcall, 0x9a, 0, 0, OPT_IM16, OPT_IM32))
ALT(DEF_ASM_OP1(lcall, 0xff, 3, 0, OPT_EA))
ALT(DEF_ASM_OP2(ljmp, 0xea, 0, 0, OPT_IM16, OPT_IM32))
ALT(DEF_ASM_OP1(ljmp, 0xff, 5, 0, OPT_EA))
ALT(DEF_ASM_OP1(int, 0xcd, 0, 0, OPT_IM8))
ALT(DEF_ASM_OP1(seto, 0x0f90, 0, OPC_MODRM | OPC_TEST, OPT_REG8 | OPT_EA))
DEF_ASM_OP2(enter, 0xc8, 0, 0, OPT_IM16, OPT_IM8)
DEF_ASM_OP0(leave, 0xc9)
DEF_ASM_OP0(ret, 0xc3)
ALT(DEF_ASM_OP1(ret, 0xc2, 0, 0, OPT_IM16))
DEF_ASM_OP0(lret, 0xcb)
ALT(DEF_ASM_OP1(lret, 0xca, 0, 0, OPT_IM16))
ALT(DEF_ASM_OP1(jo, 0x70, 0, OPC_SHORTJMP | OPC_JMP | OPC_TEST, OPT_ADDR))
DEF_ASM_OP1(loopne, 0xe0, 0, OPC_SHORTJMP, OPT_ADDR)
DEF_ASM_OP1(loopnz, 0xe0, 0, OPC_SHORTJMP, OPT_ADDR)
DEF_ASM_OP1(loope, 0xe1, 0, OPC_SHORTJMP, OPT_ADDR)
DEF_ASM_OP1(loopz, 0xe1, 0, OPC_SHORTJMP, OPT_ADDR)
DEF_ASM_OP1(loop, 0xe2, 0, OPC_SHORTJMP, OPT_ADDR)
DEF_ASM_OP1(jecxz, 0xe3, 0, OPC_SHORTJMP, OPT_ADDR)
/* float */
/* specific fcomp handling */
ALT(DEF_ASM_OP0L(fcomp, 0xd8d9, 0, 0))
ALT(DEF_ASM_OP1(fadd, 0xd8c0, 0, OPC_FARITH | OPC_REG, OPT_ST))
ALT(DEF_ASM_OP2(fadd, 0xd8c0, 0, OPC_FARITH | OPC_REG, OPT_ST, OPT_ST0))
ALT(DEF_ASM_OP0L(fadd, 0xdec1, 0, OPC_FARITH))
ALT(DEF_ASM_OP1(faddp, 0xdec0, 0, OPC_FARITH | OPC_REG, OPT_ST))
ALT(DEF_ASM_OP2(faddp, 0xdec0, 0, OPC_FARITH | OPC_REG, OPT_ST, OPT_ST0))
ALT(DEF_ASM_OP2(faddp, 0xdec0, 0, OPC_FARITH | OPC_REG, OPT_ST0, OPT_ST))
ALT(DEF_ASM_OP0L(faddp, 0xdec1, 0, OPC_FARITH))
ALT(DEF_ASM_OP1(fadds, 0xd8, 0, OPC_FARITH | OPC_MODRM, OPT_EA))
ALT(DEF_ASM_OP1(fiaddl, 0xda, 0, OPC_FARITH | OPC_MODRM, OPT_EA))
ALT(DEF_ASM_OP1(faddl, 0xdc, 0, OPC_FARITH | OPC_MODRM, OPT_EA))
ALT(DEF_ASM_OP1(fiadds, 0xde, 0, OPC_FARITH | OPC_MODRM, OPT_EA))
DEF_ASM_OP0(fucompp, 0xdae9)
DEF_ASM_OP0(ftst, 0xd9e4)
DEF_ASM_OP0(fxam, 0xd9e5)
DEF_ASM_OP0(fld1, 0xd9e8)
DEF_ASM_OP0(fldl2t, 0xd9e9)
DEF_ASM_OP0(fldl2e, 0xd9ea)
DEF_ASM_OP0(fldpi, 0xd9eb)
DEF_ASM_OP0(fldlg2, 0xd9ec)
DEF_ASM_OP0(fldln2, 0xd9ed)
DEF_ASM_OP0(fldz, 0xd9ee)
DEF_ASM_OP0(f2xm1, 0xd9f0)
DEF_ASM_OP0(fyl2x, 0xd9f1)
DEF_ASM_OP0(fptan, 0xd9f2)
DEF_ASM_OP0(fpatan, 0xd9f3)
DEF_ASM_OP0(fxtract, 0xd9f4)
DEF_ASM_OP0(fprem1, 0xd9f5)
DEF_ASM_OP0(fdecstp, 0xd9f6)
DEF_ASM_OP0(fincstp, 0xd9f7)
DEF_ASM_OP0(fprem, 0xd9f8)
DEF_ASM_OP0(fyl2xp1, 0xd9f9)
DEF_ASM_OP0(fsqrt, 0xd9fa)
DEF_ASM_OP0(fsincos, 0xd9fb)
DEF_ASM_OP0(frndint, 0xd9fc)
DEF_ASM_OP0(fscale, 0xd9fd)
DEF_ASM_OP0(fsin, 0xd9fe)
DEF_ASM_OP0(fcos, 0xd9ff)
DEF_ASM_OP0(fchs, 0xd9e0)
DEF_ASM_OP0(fabs, 0xd9e1)
DEF_ASM_OP0(fninit, 0xdbe3)
DEF_ASM_OP0(fnclex, 0xdbe2)
DEF_ASM_OP0(fnop, 0xd9d0)
DEF_ASM_OP0(fwait, 0x9b)
/* fp load */
DEF_ASM_OP1(fld, 0xd9c0, 0, OPC_REG, OPT_ST)
DEF_ASM_OP1(fldl, 0xd9c0, 0, OPC_REG, OPT_ST)
DEF_ASM_OP1(flds, 0xd9, 0, OPC_MODRM, OPT_EA)
ALT(DEF_ASM_OP1(fldl, 0xdd, 0, OPC_MODRM, OPT_EA))
DEF_ASM_OP1(fildl, 0xdb, 0, OPC_MODRM, OPT_EA)
DEF_ASM_OP1(fildq, 0xdf, 5, OPC_MODRM, OPT_EA)
DEF_ASM_OP1(fildll, 0xdf, 5, OPC_MODRM,OPT_EA)
DEF_ASM_OP1(fldt, 0xdb, 5, OPC_MODRM, OPT_EA)
DEF_ASM_OP1(fbld, 0xdf, 4, OPC_MODRM, OPT_EA)
/* fp store */
DEF_ASM_OP1(fst, 0xddd0, 0, OPC_REG, OPT_ST)
DEF_ASM_OP1(fstl, 0xddd0, 0, OPC_REG, OPT_ST)
DEF_ASM_OP1(fsts, 0xd9, 2, OPC_MODRM, OPT_EA)
DEF_ASM_OP1(fstps, 0xd9, 3, OPC_MODRM, OPT_EA)
ALT(DEF_ASM_OP1(fstl, 0xdd, 2, OPC_MODRM, OPT_EA))
DEF_ASM_OP1(fstpl, 0xdd, 3, OPC_MODRM, OPT_EA)
DEF_ASM_OP1(fist, 0xdf, 2, OPC_MODRM, OPT_EA)
DEF_ASM_OP1(fistp, 0xdf, 3, OPC_MODRM, OPT_EA)
DEF_ASM_OP1(fistl, 0xdb, 2, OPC_MODRM, OPT_EA)
DEF_ASM_OP1(fistpl, 0xdb, 3, OPC_MODRM, OPT_EA)
DEF_ASM_OP1(fstp, 0xddd8, 0, OPC_REG, OPT_ST)
DEF_ASM_OP1(fistpq, 0xdf, 7, OPC_MODRM, OPT_EA)
DEF_ASM_OP1(fistpll, 0xdf, 7, OPC_MODRM, OPT_EA)
DEF_ASM_OP1(fstpt, 0xdb, 7, OPC_MODRM, OPT_EA)
DEF_ASM_OP1(fbstp, 0xdf, 6, OPC_MODRM, OPT_EA)
/* exchange */
DEF_ASM_OP0(fxch, 0xd9c9)
ALT(DEF_ASM_OP1(fxch, 0xd9c8, 0, OPC_REG, OPT_ST))
/* misc FPU */
DEF_ASM_OP1(fucom, 0xdde0, 0, OPC_REG, OPT_ST )
DEF_ASM_OP1(fucomp, 0xdde8, 0, OPC_REG, OPT_ST )
DEF_ASM_OP0L(finit, 0xdbe3, 0, OPC_FWAIT)
DEF_ASM_OP1(fldcw, 0xd9, 5, OPC_MODRM, OPT_EA )
DEF_ASM_OP1(fnstcw, 0xd9, 7, OPC_MODRM, OPT_EA )
DEF_ASM_OP1(fstcw, 0xd9, 7, OPC_MODRM | OPC_FWAIT, OPT_EA )
DEF_ASM_OP0(fnstsw, 0xdfe0)
ALT(DEF_ASM_OP1(fnstsw, 0xdfe0, 0, 0, OPT_EAX ))
ALT(DEF_ASM_OP1(fnstsw, 0xdd, 7, OPC_MODRM, OPT_EA ))
DEF_ASM_OP1(fstsw, 0xdfe0, 0, OPC_FWAIT, OPT_EAX )
ALT(DEF_ASM_OP0L(fstsw, 0xdfe0, 0, OPC_FWAIT))
ALT(DEF_ASM_OP1(fstsw, 0xdd, 7, OPC_MODRM | OPC_FWAIT, OPT_EA ))
DEF_ASM_OP0L(fclex, 0xdbe2, 0, OPC_FWAIT)
DEF_ASM_OP1(fnstenv, 0xd9, 6, OPC_MODRM, OPT_EA )
DEF_ASM_OP1(fstenv, 0xd9, 6, OPC_MODRM | OPC_FWAIT, OPT_EA )
DEF_ASM_OP1(fldenv, 0xd9, 4, OPC_MODRM, OPT_EA )
DEF_ASM_OP1(fnsave, 0xdd, 6, OPC_MODRM, OPT_EA )
DEF_ASM_OP1(fsave, 0xdd, 6, OPC_MODRM | OPC_FWAIT, OPT_EA )
DEF_ASM_OP1(frstor, 0xdd, 4, OPC_MODRM, OPT_EA )
DEF_ASM_OP1(ffree, 0xddc0, 4, OPC_REG, OPT_ST )
DEF_ASM_OP1(ffreep, 0xdfc0, 4, OPC_REG, OPT_ST )
DEF_ASM_OP1(fxsave, 0x0fae, 0, OPC_MODRM, OPT_EA )
DEF_ASM_OP1(fxrstor, 0x0fae, 1, OPC_MODRM, OPT_EA )
/* segments */
DEF_ASM_OP2(arpl, 0x63, 0, OPC_MODRM, OPT_REG16, OPT_REG16 | OPT_EA)
DEF_ASM_OP2(lar, 0x0f02, 0, OPC_MODRM, OPT_REG32 | OPT_EA, OPT_REG32)
DEF_ASM_OP1(lgdt, 0x0f01, 2, OPC_MODRM, OPT_EA)
DEF_ASM_OP1(lidt, 0x0f01, 3, OPC_MODRM, OPT_EA)
DEF_ASM_OP1(lldt, 0x0f00, 2, OPC_MODRM, OPT_EA | OPT_REG)
DEF_ASM_OP1(lmsw, 0x0f01, 6, OPC_MODRM, OPT_EA | OPT_REG)
ALT(DEF_ASM_OP2(lslw, 0x0f03, 0, OPC_MODRM | OPC_WL, OPT_EA | OPT_REG, OPT_REG))
DEF_ASM_OP1(ltr, 0x0f00, 3, OPC_MODRM, OPT_EA | OPT_REG)
DEF_ASM_OP1(sgdt, 0x0f01, 0, OPC_MODRM, OPT_EA)
DEF_ASM_OP1(sidt, 0x0f01, 1, OPC_MODRM, OPT_EA)
DEF_ASM_OP1(sldt, 0x0f00, 0, OPC_MODRM, OPT_REG | OPT_EA)
DEF_ASM_OP1(smsw, 0x0f01, 4, OPC_MODRM, OPT_REG | OPT_EA)
DEF_ASM_OP1(str, 0x0f00, 1, OPC_MODRM, OPT_REG16| OPT_EA)
DEF_ASM_OP1(verr, 0x0f00, 4, OPC_MODRM, OPT_REG | OPT_EA)
DEF_ASM_OP1(verw, 0x0f00, 5, OPC_MODRM, OPT_REG | OPT_EA)
/* 486 */
DEF_ASM_OP1(bswap, 0x0fc8, 0, OPC_REG, OPT_REG32 )
ALT(DEF_ASM_OP2(xaddb, 0x0fc0, 0, OPC_MODRM | OPC_BWL, OPT_REG, OPT_REG | OPT_EA ))
ALT(DEF_ASM_OP2(cmpxchgb, 0x0fb0, 0, OPC_MODRM | OPC_BWL, OPT_REG, OPT_REG | OPT_EA ))
DEF_ASM_OP1(invlpg, 0x0f01, 7, OPC_MODRM, OPT_EA )
DEF_ASM_OP2(boundl, 0x62, 0, OPC_MODRM, OPT_REG32, OPT_EA)
DEF_ASM_OP2(boundw, 0x62, 0, OPC_MODRM | OPC_D16, OPT_REG16, OPT_EA)
/* pentium */
DEF_ASM_OP1(cmpxchg8b, 0x0fc7, 1, OPC_MODRM, OPT_EA )
/* pentium pro */
ALT(DEF_ASM_OP2(cmovo, 0x0f40, 0, OPC_MODRM | OPC_TEST, OPT_REG32 | OPT_EA, OPT_REG32))
DEF_ASM_OP2(fcmovb, 0xdac0, 0, OPC_REG, OPT_ST, OPT_ST0 )
DEF_ASM_OP2(fcmove, 0xdac8, 0, OPC_REG, OPT_ST, OPT_ST0 )
DEF_ASM_OP2(fcmovbe, 0xdad0, 0, OPC_REG, OPT_ST, OPT_ST0 )
DEF_ASM_OP2(fcmovu, 0xdad8, 0, OPC_REG, OPT_ST, OPT_ST0 )
DEF_ASM_OP2(fcmovnb, 0xdbc0, 0, OPC_REG, OPT_ST, OPT_ST0 )
DEF_ASM_OP2(fcmovne, 0xdbc8, 0, OPC_REG, OPT_ST, OPT_ST0 )
DEF_ASM_OP2(fcmovnbe, 0xdbd0, 0, OPC_REG, OPT_ST, OPT_ST0 )
DEF_ASM_OP2(fcmovnu, 0xdbd8, 0, OPC_REG, OPT_ST, OPT_ST0 )
DEF_ASM_OP2(fucomi, 0xdbe8, 0, OPC_REG, OPT_ST, OPT_ST0 )
DEF_ASM_OP2(fcomi, 0xdbf0, 0, OPC_REG, OPT_ST, OPT_ST0 )
DEF_ASM_OP2(fucomip, 0xdfe8, 0, OPC_REG, OPT_ST, OPT_ST0 )
DEF_ASM_OP2(fcomip, 0xdff0, 0, OPC_REG, OPT_ST, OPT_ST0 )
/* mmx */
DEF_ASM_OP0(emms, 0x0f77) /* must be last OP0 */
DEF_ASM_OP2(movd, 0x0f6e, 0, OPC_MODRM, OPT_EA | OPT_REG32, OPT_MMX )
ALT(DEF_ASM_OP2(movd, 0x0f7e, 0, OPC_MODRM, OPT_MMX, OPT_EA | OPT_REG32 ))
DEF_ASM_OP2(movq, 0x0f6f, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
ALT(DEF_ASM_OP2(movq, 0x0f7f, 0, OPC_MODRM, OPT_MMX, OPT_EA | OPT_MMX ))
DEF_ASM_OP2(packssdw, 0x0f6b, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(packsswb, 0x0f63, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(packuswb, 0x0f67, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(paddb, 0x0ffc, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(paddw, 0x0ffd, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(paddd, 0x0ffe, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(paddsb, 0x0fec, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(paddsw, 0x0fed, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(paddusb, 0x0fdc, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(paddusw, 0x0fdd, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(pand, 0x0fdb, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(pandn, 0x0fdf, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(pcmpeqb, 0x0f74, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(pcmpeqw, 0x0f75, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(pcmpeqd, 0x0f76, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(pcmpgtb, 0x0f64, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(pcmpgtw, 0x0f65, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(pcmpgtd, 0x0f66, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(pmaddwd, 0x0ff5, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(pmulhw, 0x0fe5, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(pmullw, 0x0fd5, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(por, 0x0feb, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(psllw, 0x0ff1, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
ALT(DEF_ASM_OP2(psllw, 0x0f71, 6, OPC_MODRM, OPT_IM8, OPT_MMX ))
DEF_ASM_OP2(pslld, 0x0ff2, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
ALT(DEF_ASM_OP2(pslld, 0x0f72, 6, OPC_MODRM, OPT_IM8, OPT_MMX ))
DEF_ASM_OP2(psllq, 0x0ff3, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
ALT(DEF_ASM_OP2(psllq, 0x0f73, 6, OPC_MODRM, OPT_IM8, OPT_MMX ))
DEF_ASM_OP2(psraw, 0x0fe1, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
ALT(DEF_ASM_OP2(psraw, 0x0f71, 4, OPC_MODRM, OPT_IM8, OPT_MMX ))
DEF_ASM_OP2(psrad, 0x0fe2, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
ALT(DEF_ASM_OP2(psrad, 0x0f72, 4, OPC_MODRM, OPT_IM8, OPT_MMX ))
DEF_ASM_OP2(psrlw, 0x0fd1, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
ALT(DEF_ASM_OP2(psrlw, 0x0f71, 2, OPC_MODRM, OPT_IM8, OPT_MMX ))
DEF_ASM_OP2(psrld, 0x0fd2, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
ALT(DEF_ASM_OP2(psrld, 0x0f72, 2, OPC_MODRM, OPT_IM8, OPT_MMX ))
DEF_ASM_OP2(psrlq, 0x0fd3, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
ALT(DEF_ASM_OP2(psrlq, 0x0f73, 2, OPC_MODRM, OPT_IM8, OPT_MMX ))
DEF_ASM_OP2(psubb, 0x0ff8, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(psubw, 0x0ff9, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(psubd, 0x0ffa, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(psubsb, 0x0fe8, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(psubsw, 0x0fe9, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(psubusb, 0x0fd8, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(psubusw, 0x0fd9, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(punpckhbw, 0x0f68, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(punpckhwd, 0x0f69, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(punpckhdq, 0x0f6a, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(punpcklbw, 0x0f60, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(punpcklwd, 0x0f61, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(punpckldq, 0x0f62, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(pxor, 0x0fef, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
#undef ALT
#undef DEF_ASM_OP0
#undef DEF_ASM_OP0L
#undef DEF_ASM_OP1
#undef DEF_ASM_OP2
#undef DEF_ASM_OP3
File diff suppressed because it is too large Load Diff
-667
View File
@@ -1,667 +0,0 @@
/*
* CIL code generator for TCC
*
* Copyright (c) 2002 Fabrice Bellard
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* number of available registers */
#define NB_REGS 3
/* a register can belong to several classes. The classes must be
sorted from more general to more precise (see gv2() code which does
assumptions on it). */
#define RC_ST 0x0001 /* any stack entry */
#define RC_ST0 0x0002 /* top of stack */
#define RC_ST1 0x0004 /* top - 1 */
#define RC_INT RC_ST
#define RC_FLOAT RC_ST
#define RC_IRET RC_ST0 /* function return: integer register */
#define RC_LRET RC_ST0 /* function return: second integer register */
#define RC_FRET RC_ST0 /* function return: float register */
/* pretty names for the registers */
enum {
REG_ST0 = 0,
REG_ST1,
REG_ST2,
};
int reg_classes[NB_REGS] = {
/* ST0 */ RC_ST | RC_ST0,
/* ST1 */ RC_ST | RC_ST1,
/* ST2 */ RC_ST,
};
/* return registers for function */
#define REG_IRET REG_ST0 /* single word int return register */
#define REG_LRET REG_ST0 /* second word return register (for long long) */
#define REG_FRET REG_ST0 /* float return register */
/* defined if function parameters must be evaluated in reverse order */
//#define INVERT_FUNC_PARAMS
/* defined if structures are passed as pointers. Otherwise structures
are directly pushed on stack. */
//#define FUNC_STRUCT_PARAM_AS_PTR
/* pointer size, in bytes */
#define PTR_SIZE 4
/* long double size and alignment, in bytes */
#define LDOUBLE_SIZE 8
#define LDOUBLE_ALIGN 8
/* function call context */
typedef struct GFuncContext {
int func_call; /* func call type (FUNC_STDCALL or FUNC_CDECL) */
} GFuncContext;
/******************************************************/
/* opcode definitions */
#define IL_OP_PREFIX 0xFE
enum ILOPCodes {
#define OP(name, str, n) IL_OP_ ## name = n,
#include "il-opcodes.h"
#undef OP
};
char *il_opcodes_str[] = {
#define OP(name, str, n) [n] = str,
#include "il-opcodes.h"
#undef OP
};
/******************************************************/
/* arguments variable numbers start from there */
#define ARG_BASE 0x70000000
static FILE *il_outfile;
static void out_byte(int c)
{
*(char *)ind++ = c;
}
static void out_le32(int c)
{
out_byte(c);
out_byte(c >> 8);
out_byte(c >> 16);
out_byte(c >> 24);
}
static void init_outfile(void)
{
if (!il_outfile) {
il_outfile = stdout;
fprintf(il_outfile,
".assembly extern mscorlib\n"
"{\n"
".ver 1:0:2411:0\n"
"}\n\n");
}
}
static void out_op1(int op)
{
if (op & 0x100)
out_byte(IL_OP_PREFIX);
out_byte(op & 0xff);
}
/* output an opcode with prefix */
static void out_op(int op)
{
out_op1(op);
fprintf(il_outfile, " %s\n", il_opcodes_str[op]);
}
static void out_opb(int op, int c)
{
out_op1(op);
out_byte(c);
fprintf(il_outfile, " %s %d\n", il_opcodes_str[op], c);
}
static void out_opi(int op, int c)
{
out_op1(op);
out_le32(c);
fprintf(il_outfile, " %s 0x%x\n", il_opcodes_str[op], c);
}
/* XXX: not complete */
static void il_type_to_str(char *buf, int buf_size,
int t, const char *varstr)
{
int bt;
Sym *s, *sa;
char buf1[256];
const char *tstr;
t = t & VT_TYPE;
bt = t & VT_BTYPE;
buf[0] = '\0';
if (t & VT_UNSIGNED)
pstrcat(buf, buf_size, "unsigned ");
switch(bt) {
case VT_VOID:
tstr = "void";
goto add_tstr;
case VT_BOOL:
tstr = "bool";
goto add_tstr;
case VT_BYTE:
tstr = "int8";
goto add_tstr;
case VT_SHORT:
tstr = "int16";
goto add_tstr;
case VT_ENUM:
case VT_INT:
case VT_LONG:
tstr = "int32";
goto add_tstr;
case VT_LLONG:
tstr = "int64";
goto add_tstr;
case VT_FLOAT:
tstr = "float32";
goto add_tstr;
case VT_DOUBLE:
case VT_LDOUBLE:
tstr = "float64";
add_tstr:
pstrcat(buf, buf_size, tstr);
break;
case VT_STRUCT:
error("structures not handled yet");
break;
case VT_FUNC:
s = sym_find((unsigned)t >> VT_STRUCT_SHIFT);
il_type_to_str(buf, buf_size, s->t, varstr);
pstrcat(buf, buf_size, "(");
sa = s->next;
while (sa != NULL) {
il_type_to_str(buf1, sizeof(buf1), sa->t, NULL);
pstrcat(buf, buf_size, buf1);
sa = sa->next;
if (sa)
pstrcat(buf, buf_size, ", ");
}
pstrcat(buf, buf_size, ")");
goto no_var;
case VT_PTR:
s = sym_find((unsigned)t >> VT_STRUCT_SHIFT);
pstrcpy(buf1, sizeof(buf1), "*");
if (varstr)
pstrcat(buf1, sizeof(buf1), varstr);
il_type_to_str(buf, buf_size, s->t, buf1);
goto no_var;
}
if (varstr) {
pstrcat(buf, buf_size, " ");
pstrcat(buf, buf_size, varstr);
}
no_var: ;
}
/* patch relocation entry with value 'val' */
void greloc_patch1(Reloc *p, int val)
{
}
/* output a symbol and patch all calls to it */
void gsym_addr(t, a)
{
}
/* output jump and return symbol */
static int out_opj(int op, int c)
{
out_op1(op);
out_le32(0);
if (c == 0) {
c = ind - (int)cur_text_section->data;
}
fprintf(il_outfile, " %s L%d\n", il_opcodes_str[op], c);
return c;
}
void gsym(int t)
{
fprintf(il_outfile, "L%d:\n", t);
}
/* load 'r' from value 'sv' */
void load(int r, SValue *sv)
{
int v, fc, ft;
v = sv->r & VT_VALMASK;
fc = sv->c.i;
ft = sv->t;
if (sv->r & VT_LVAL) {
if (v == VT_LOCAL) {
if (fc >= ARG_BASE) {
fc -= ARG_BASE;
if (fc >= 0 && fc <= 4) {
out_op(IL_OP_LDARG_0 + fc);
} else if (fc <= 0xff) {
out_opb(IL_OP_LDARG_S, fc);
} else {
out_opi(IL_OP_LDARG, fc);
}
} else {
if (fc >= 0 && fc <= 4) {
out_op(IL_OP_LDLOC_0 + fc);
} else if (fc <= 0xff) {
out_opb(IL_OP_LDLOC_S, fc);
} else {
out_opi(IL_OP_LDLOC, fc);
}
}
} else if (v == VT_CONST) {
/* XXX: handle globals */
out_opi(IL_OP_LDSFLD, 0);
} else {
if ((ft & VT_BTYPE) == VT_FLOAT) {
out_op(IL_OP_LDIND_R4);
} else if ((ft & VT_BTYPE) == VT_DOUBLE) {
out_op(IL_OP_LDIND_R8);
} else if ((ft & VT_BTYPE) == VT_LDOUBLE) {
out_op(IL_OP_LDIND_R8);
} else if ((ft & VT_TYPE) == VT_BYTE)
out_op(IL_OP_LDIND_I1);
else if ((ft & VT_TYPE) == (VT_BYTE | VT_UNSIGNED))
out_op(IL_OP_LDIND_U1);
else if ((ft & VT_TYPE) == VT_SHORT)
out_op(IL_OP_LDIND_I2);
else if ((ft & VT_TYPE) == (VT_SHORT | VT_UNSIGNED))
out_op(IL_OP_LDIND_U2);
else
out_op(IL_OP_LDIND_I4);
}
} else {
if (v == VT_CONST) {
/* XXX: handle globals */
if (fc >= -1 && fc <= 8) {
out_op(IL_OP_LDC_I4_M1 + fc + 1);
} else {
out_opi(IL_OP_LDC_I4, fc);
}
} else if (v == VT_LOCAL) {
if (fc >= ARG_BASE) {
fc -= ARG_BASE;
if (fc <= 0xff) {
out_opb(IL_OP_LDARGA_S, fc);
} else {
out_opi(IL_OP_LDARGA, fc);
}
} else {
if (fc <= 0xff) {
out_opb(IL_OP_LDLOCA_S, fc);
} else {
out_opi(IL_OP_LDLOCA, fc);
}
}
} else {
/* XXX: do it */
}
}
}
/* store register 'r' in lvalue 'v' */
void store(int r, SValue *sv)
{
int v, fc, ft;
v = sv->r & VT_VALMASK;
fc = sv->c.i;
ft = sv->t;
if (v == VT_LOCAL) {
if (fc >= ARG_BASE) {
fc -= ARG_BASE;
/* XXX: check IL arg store semantics */
if (fc <= 0xff) {
out_opb(IL_OP_STARG_S, fc);
} else {
out_opi(IL_OP_STARG, fc);
}
} else {
if (fc >= 0 && fc <= 4) {
out_op(IL_OP_STLOC_0 + fc);
} else if (fc <= 0xff) {
out_opb(IL_OP_STLOC_S, fc);
} else {
out_opi(IL_OP_STLOC, fc);
}
}
} else if (v == VT_CONST) {
/* XXX: handle globals */
out_opi(IL_OP_STSFLD, 0);
} else {
if ((ft & VT_BTYPE) == VT_FLOAT)
out_op(IL_OP_STIND_R4);
else if ((ft & VT_BTYPE) == VT_DOUBLE)
out_op(IL_OP_STIND_R8);
else if ((ft & VT_BTYPE) == VT_LDOUBLE)
out_op(IL_OP_STIND_R8);
else if ((ft & VT_BTYPE) == VT_BYTE)
out_op(IL_OP_STIND_I1);
else if ((ft & VT_BTYPE) == VT_SHORT)
out_op(IL_OP_STIND_I2);
else
out_op(IL_OP_STIND_I4);
}
}
/* start function call and return function call context */
void gfunc_start(GFuncContext *c, int func_call)
{
c->func_call = func_call;
}
/* push function parameter which is in (vtop->t, vtop->c). Stack entry
is then popped. */
void gfunc_param(GFuncContext *c)
{
if ((vtop->t & VT_BTYPE) == VT_STRUCT) {
error("structures passed as value not handled yet");
} else {
/* simply push on stack */
gv(RC_ST0);
}
vtop--;
}
/* generate function call with address in (vtop->t, vtop->c) and free function
context. Stack entry is popped */
void gfunc_call(GFuncContext *c)
{
char buf[1024];
if ((vtop->r & (VT_VALMASK | VT_LVAL)) == VT_CONST) {
/* XXX: more info needed from tcc */
il_type_to_str(buf, sizeof(buf), vtop->t, "xxx");
fprintf(il_outfile, " call %s\n", buf);
} else {
/* indirect call */
gv(RC_INT);
il_type_to_str(buf, sizeof(buf), vtop->t, NULL);
fprintf(il_outfile, " calli %s\n", buf);
}
vtop--;
}
/* generate function prolog of type 't' */
void gfunc_prolog(int t)
{
int addr, u, func_call;
Sym *sym;
char buf[1024];
init_outfile();
/* XXX: pass function name to gfunc_prolog */
il_type_to_str(buf, sizeof(buf), t, funcname);
fprintf(il_outfile, ".method static %s il managed\n", buf);
fprintf(il_outfile, "{\n");
/* XXX: cannot do better now */
fprintf(il_outfile, " .maxstack %d\n", NB_REGS);
fprintf(il_outfile, " .locals (int32, int32, int32, int32, int32, int32, int32, int32)\n");
if (!strcmp(funcname, "main"))
fprintf(il_outfile, " .entrypoint\n");
sym = sym_find((unsigned)t >> VT_STRUCT_SHIFT);
func_call = sym->r;
addr = ARG_BASE;
/* if the function returns a structure, then add an
implicit pointer parameter */
func_vt = sym->t;
if ((func_vt & VT_BTYPE) == VT_STRUCT) {
func_vc = addr;
addr++;
}
/* define parameters */
while ((sym = sym->next) != NULL) {
u = sym->t;
sym_push(sym->v & ~SYM_FIELD, u,
VT_LOCAL | lvalue_type(sym->type.t), addr);
addr++;
}
}
/* generate function epilog */
void gfunc_epilog(void)
{
out_op(IL_OP_RET);
fprintf(il_outfile, "}\n\n");
}
/* generate a jump to a label */
int gjmp(int t)
{
return out_opj(IL_OP_BR, t);
}
/* generate a jump to a fixed address */
void gjmp_addr(int a)
{
/* XXX: handle syms */
out_opi(IL_OP_BR, a);
}
/* generate a test. set 'inv' to invert test. Stack entry is popped */
int gtst(int inv, int t)
{
int v, *p, c;
v = vtop->r & VT_VALMASK;
if (v == VT_CMP) {
c = vtop->c.i ^ inv;
switch(c) {
case TOK_EQ:
c = IL_OP_BEQ;
break;
case TOK_NE:
c = IL_OP_BNE_UN;
break;
case TOK_LT:
c = IL_OP_BLT;
break;
case TOK_LE:
c = IL_OP_BLE;
break;
case TOK_GT:
c = IL_OP_BGT;
break;
case TOK_GE:
c = IL_OP_BGE;
break;
case TOK_ULT:
c = IL_OP_BLT_UN;
break;
case TOK_ULE:
c = IL_OP_BLE_UN;
break;
case TOK_UGT:
c = IL_OP_BGT_UN;
break;
case TOK_UGE:
c = IL_OP_BGE_UN;
break;
}
t = out_opj(c, t);
} else if (v == VT_JMP || v == VT_JMPI) {
/* && or || optimization */
if ((v & 1) == inv) {
/* insert vtop->c jump list in t */
p = &vtop->c.i;
while (*p != 0)
p = (int *)*p;
*p = t;
t = vtop->c.i;
} else {
t = gjmp(t);
gsym(vtop->c.i);
}
} else {
if (is_float(vtop->t)) {
vpushi(0);
gen_op(TOK_NE);
}
if ((vtop->r & (VT_VALMASK | VT_LVAL | VT_FORWARD)) == VT_CONST) {
/* constant jmp optimization */
if ((vtop->c.i != 0) != inv)
t = gjmp(t);
} else {
v = gv(RC_INT);
t = out_opj(IL_OP_BRTRUE - inv, t);
}
}
vtop--;
return t;
}
/* generate an integer binary operation */
void gen_opi(int op)
{
gv2(RC_ST1, RC_ST0);
switch(op) {
case '+':
out_op(IL_OP_ADD);
goto std_op;
case '-':
out_op(IL_OP_SUB);
goto std_op;
case '&':
out_op(IL_OP_AND);
goto std_op;
case '^':
out_op(IL_OP_XOR);
goto std_op;
case '|':
out_op(IL_OP_OR);
goto std_op;
case '*':
out_op(IL_OP_MUL);
goto std_op;
case TOK_SHL:
out_op(IL_OP_SHL);
goto std_op;
case TOK_SHR:
out_op(IL_OP_SHR_UN);
goto std_op;
case TOK_SAR:
out_op(IL_OP_SHR);
goto std_op;
case '/':
case TOK_PDIV:
out_op(IL_OP_DIV);
goto std_op;
case TOK_UDIV:
out_op(IL_OP_DIV_UN);
goto std_op;
case '%':
out_op(IL_OP_REM);
goto std_op;
case TOK_UMOD:
out_op(IL_OP_REM_UN);
std_op:
vtop--;
vtop[0].r = REG_ST0;
break;
case TOK_EQ:
case TOK_NE:
case TOK_LT:
case TOK_LE:
case TOK_GT:
case TOK_GE:
case TOK_ULT:
case TOK_ULE:
case TOK_UGT:
case TOK_UGE:
vtop--;
vtop[0].r = VT_CMP;
vtop[0].c.i = op;
break;
}
}
/* generate a floating point operation 'v = t1 op t2' instruction. The
two operands are guaranted to have the same floating point type */
void gen_opf(int op)
{
/* same as integer */
gen_opi(op);
}
/* convert integers to fp 't' type. Must handle 'int', 'unsigned int'
and 'long long' cases. */
void gen_cvt_itof(int t)
{
gv(RC_ST0);
if (t == VT_FLOAT)
out_op(IL_OP_CONV_R4);
else
out_op(IL_OP_CONV_R8);
}
/* convert fp to int 't' type */
/* XXX: handle long long case */
void gen_cvt_ftoi(int t)
{
gv(RC_ST0);
switch(t) {
case VT_INT | VT_UNSIGNED:
out_op(IL_OP_CONV_U4);
break;
case VT_LLONG:
out_op(IL_OP_CONV_I8);
break;
case VT_LLONG | VT_UNSIGNED:
out_op(IL_OP_CONV_U8);
break;
default:
out_op(IL_OP_CONV_I4);
break;
}
}
/* convert from one floating point type to another */
void gen_cvt_ftof(int t)
{
gv(RC_ST0);
if (t == VT_FLOAT) {
out_op(IL_OP_CONV_R4);
} else {
out_op(IL_OP_CONV_R8);
}
}
/* end of CIL code generator */
/*************************************************************/
-251
View File
@@ -1,251 +0,0 @@
/*
* CIL opcode definition
*
* Copyright (c) 2002 Fabrice Bellard
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
OP(NOP, "nop", 0x00)
OP(BREAK, "break", 0x01)
OP(LDARG_0, "ldarg.0", 0x02)
OP(LDARG_1, "ldarg.1", 0x03)
OP(LDARG_2, "ldarg.2", 0x04)
OP(LDARG_3, "ldarg.3", 0x05)
OP(LDLOC_0, "ldloc.0", 0x06)
OP(LDLOC_1, "ldloc.1", 0x07)
OP(LDLOC_2, "ldloc.2", 0x08)
OP(LDLOC_3, "ldloc.3", 0x09)
OP(STLOC_0, "stloc.0", 0x0a)
OP(STLOC_1, "stloc.1", 0x0b)
OP(STLOC_2, "stloc.2", 0x0c)
OP(STLOC_3, "stloc.3", 0x0d)
OP(LDARG_S, "ldarg.s", 0x0e)
OP(LDARGA_S, "ldarga.s", 0x0f)
OP(STARG_S, "starg.s", 0x10)
OP(LDLOC_S, "ldloc.s", 0x11)
OP(LDLOCA_S, "ldloca.s", 0x12)
OP(STLOC_S, "stloc.s", 0x13)
OP(LDNULL, "ldnull", 0x14)
OP(LDC_I4_M1, "ldc.i4.m1", 0x15)
OP(LDC_I4_0, "ldc.i4.0", 0x16)
OP(LDC_I4_1, "ldc.i4.1", 0x17)
OP(LDC_I4_2, "ldc.i4.2", 0x18)
OP(LDC_I4_3, "ldc.i4.3", 0x19)
OP(LDC_I4_4, "ldc.i4.4", 0x1a)
OP(LDC_I4_5, "ldc.i4.5", 0x1b)
OP(LDC_I4_6, "ldc.i4.6", 0x1c)
OP(LDC_I4_7, "ldc.i4.7", 0x1d)
OP(LDC_I4_8, "ldc.i4.8", 0x1e)
OP(LDC_I4_S, "ldc.i4.s", 0x1f)
OP(LDC_I4, "ldc.i4", 0x20)
OP(LDC_I8, "ldc.i8", 0x21)
OP(LDC_R4, "ldc.r4", 0x22)
OP(LDC_R8, "ldc.r8", 0x23)
OP(LDPTR, "ldptr", 0x24)
OP(DUP, "dup", 0x25)
OP(POP, "pop", 0x26)
OP(JMP, "jmp", 0x27)
OP(CALL, "call", 0x28)
OP(CALLI, "calli", 0x29)
OP(RET, "ret", 0x2a)
OP(BR_S, "br.s", 0x2b)
OP(BRFALSE_S, "brfalse.s", 0x2c)
OP(BRTRUE_S, "brtrue.s", 0x2d)
OP(BEQ_S, "beq.s", 0x2e)
OP(BGE_S, "bge.s", 0x2f)
OP(BGT_S, "bgt.s", 0x30)
OP(BLE_S, "ble.s", 0x31)
OP(BLT_S, "blt.s", 0x32)
OP(BNE_UN_S, "bne.un.s", 0x33)
OP(BGE_UN_S, "bge.un.s", 0x34)
OP(BGT_UN_S, "bgt.un.s", 0x35)
OP(BLE_UN_S, "ble.un.s", 0x36)
OP(BLT_UN_S, "blt.un.s", 0x37)
OP(BR, "br", 0x38)
OP(BRFALSE, "brfalse", 0x39)
OP(BRTRUE, "brtrue", 0x3a)
OP(BEQ, "beq", 0x3b)
OP(BGE, "bge", 0x3c)
OP(BGT, "bgt", 0x3d)
OP(BLE, "ble", 0x3e)
OP(BLT, "blt", 0x3f)
OP(BNE_UN, "bne.un", 0x40)
OP(BGE_UN, "bge.un", 0x41)
OP(BGT_UN, "bgt.un", 0x42)
OP(BLE_UN, "ble.un", 0x43)
OP(BLT_UN, "blt.un", 0x44)
OP(SWITCH, "switch", 0x45)
OP(LDIND_I1, "ldind.i1", 0x46)
OP(LDIND_U1, "ldind.u1", 0x47)
OP(LDIND_I2, "ldind.i2", 0x48)
OP(LDIND_U2, "ldind.u2", 0x49)
OP(LDIND_I4, "ldind.i4", 0x4a)
OP(LDIND_U4, "ldind.u4", 0x4b)
OP(LDIND_I8, "ldind.i8", 0x4c)
OP(LDIND_I, "ldind.i", 0x4d)
OP(LDIND_R4, "ldind.r4", 0x4e)
OP(LDIND_R8, "ldind.r8", 0x4f)
OP(LDIND_REF, "ldind.ref", 0x50)
OP(STIND_REF, "stind.ref", 0x51)
OP(STIND_I1, "stind.i1", 0x52)
OP(STIND_I2, "stind.i2", 0x53)
OP(STIND_I4, "stind.i4", 0x54)
OP(STIND_I8, "stind.i8", 0x55)
OP(STIND_R4, "stind.r4", 0x56)
OP(STIND_R8, "stind.r8", 0x57)
OP(ADD, "add", 0x58)
OP(SUB, "sub", 0x59)
OP(MUL, "mul", 0x5a)
OP(DIV, "div", 0x5b)
OP(DIV_UN, "div.un", 0x5c)
OP(REM, "rem", 0x5d)
OP(REM_UN, "rem.un", 0x5e)
OP(AND, "and", 0x5f)
OP(OR, "or", 0x60)
OP(XOR, "xor", 0x61)
OP(SHL, "shl", 0x62)
OP(SHR, "shr", 0x63)
OP(SHR_UN, "shr.un", 0x64)
OP(NEG, "neg", 0x65)
OP(NOT, "not", 0x66)
OP(CONV_I1, "conv.i1", 0x67)
OP(CONV_I2, "conv.i2", 0x68)
OP(CONV_I4, "conv.i4", 0x69)
OP(CONV_I8, "conv.i8", 0x6a)
OP(CONV_R4, "conv.r4", 0x6b)
OP(CONV_R8, "conv.r8", 0x6c)
OP(CONV_U4, "conv.u4", 0x6d)
OP(CONV_U8, "conv.u8", 0x6e)
OP(CALLVIRT, "callvirt", 0x6f)
OP(CPOBJ, "cpobj", 0x70)
OP(LDOBJ, "ldobj", 0x71)
OP(LDSTR, "ldstr", 0x72)
OP(NEWOBJ, "newobj", 0x73)
OP(CASTCLASS, "castclass", 0x74)
OP(ISINST, "isinst", 0x75)
OP(CONV_R_UN, "conv.r.un", 0x76)
OP(ANN_DATA_S, "ann.data.s", 0x77)
OP(UNBOX, "unbox", 0x79)
OP(THROW, "throw", 0x7a)
OP(LDFLD, "ldfld", 0x7b)
OP(LDFLDA, "ldflda", 0x7c)
OP(STFLD, "stfld", 0x7d)
OP(LDSFLD, "ldsfld", 0x7e)
OP(LDSFLDA, "ldsflda", 0x7f)
OP(STSFLD, "stsfld", 0x80)
OP(STOBJ, "stobj", 0x81)
OP(CONV_OVF_I1_UN, "conv.ovf.i1.un", 0x82)
OP(CONV_OVF_I2_UN, "conv.ovf.i2.un", 0x83)
OP(CONV_OVF_I4_UN, "conv.ovf.i4.un", 0x84)
OP(CONV_OVF_I8_UN, "conv.ovf.i8.un", 0x85)
OP(CONV_OVF_U1_UN, "conv.ovf.u1.un", 0x86)
OP(CONV_OVF_U2_UN, "conv.ovf.u2.un", 0x87)
OP(CONV_OVF_U4_UN, "conv.ovf.u4.un", 0x88)
OP(CONV_OVF_U8_UN, "conv.ovf.u8.un", 0x89)
OP(CONV_OVF_I_UN, "conv.ovf.i.un", 0x8a)
OP(CONV_OVF_U_UN, "conv.ovf.u.un", 0x8b)
OP(BOX, "box", 0x8c)
OP(NEWARR, "newarr", 0x8d)
OP(LDLEN, "ldlen", 0x8e)
OP(LDELEMA, "ldelema", 0x8f)
OP(LDELEM_I1, "ldelem.i1", 0x90)
OP(LDELEM_U1, "ldelem.u1", 0x91)
OP(LDELEM_I2, "ldelem.i2", 0x92)
OP(LDELEM_U2, "ldelem.u2", 0x93)
OP(LDELEM_I4, "ldelem.i4", 0x94)
OP(LDELEM_U4, "ldelem.u4", 0x95)
OP(LDELEM_I8, "ldelem.i8", 0x96)
OP(LDELEM_I, "ldelem.i", 0x97)
OP(LDELEM_R4, "ldelem.r4", 0x98)
OP(LDELEM_R8, "ldelem.r8", 0x99)
OP(LDELEM_REF, "ldelem.ref", 0x9a)
OP(STELEM_I, "stelem.i", 0x9b)
OP(STELEM_I1, "stelem.i1", 0x9c)
OP(STELEM_I2, "stelem.i2", 0x9d)
OP(STELEM_I4, "stelem.i4", 0x9e)
OP(STELEM_I8, "stelem.i8", 0x9f)
OP(STELEM_R4, "stelem.r4", 0xa0)
OP(STELEM_R8, "stelem.r8", 0xa1)
OP(STELEM_REF, "stelem.ref", 0xa2)
OP(CONV_OVF_I1, "conv.ovf.i1", 0xb3)
OP(CONV_OVF_U1, "conv.ovf.u1", 0xb4)
OP(CONV_OVF_I2, "conv.ovf.i2", 0xb5)
OP(CONV_OVF_U2, "conv.ovf.u2", 0xb6)
OP(CONV_OVF_I4, "conv.ovf.i4", 0xb7)
OP(CONV_OVF_U4, "conv.ovf.u4", 0xb8)
OP(CONV_OVF_I8, "conv.ovf.i8", 0xb9)
OP(CONV_OVF_U8, "conv.ovf.u8", 0xba)
OP(REFANYVAL, "refanyval", 0xc2)
OP(CKFINITE, "ckfinite", 0xc3)
OP(MKREFANY, "mkrefany", 0xc6)
OP(ANN_CALL, "ann.call", 0xc7)
OP(ANN_CATCH, "ann.catch", 0xc8)
OP(ANN_DEAD, "ann.dead", 0xc9)
OP(ANN_HOISTED, "ann.hoisted", 0xca)
OP(ANN_HOISTED_CALL, "ann.hoisted.call", 0xcb)
OP(ANN_LAB, "ann.lab", 0xcc)
OP(ANN_DEF, "ann.def", 0xcd)
OP(ANN_REF_S, "ann.ref.s", 0xce)
OP(ANN_PHI, "ann.phi", 0xcf)
OP(LDTOKEN, "ldtoken", 0xd0)
OP(CONV_U2, "conv.u2", 0xd1)
OP(CONV_U1, "conv.u1", 0xd2)
OP(CONV_I, "conv.i", 0xd3)
OP(CONV_OVF_I, "conv.ovf.i", 0xd4)
OP(CONV_OVF_U, "conv.ovf.u", 0xd5)
OP(ADD_OVF, "add.ovf", 0xd6)
OP(ADD_OVF_UN, "add.ovf.un", 0xd7)
OP(MUL_OVF, "mul.ovf", 0xd8)
OP(MUL_OVF_UN, "mul.ovf.un", 0xd9)
OP(SUB_OVF, "sub.ovf", 0xda)
OP(SUB_OVF_UN, "sub.ovf.un", 0xdb)
OP(ENDFINALLY, "endfinally", 0xdc)
OP(LEAVE, "leave", 0xdd)
OP(LEAVE_S, "leave.s", 0xde)
OP(STIND_I, "stind.i", 0xdf)
OP(CONV_U, "conv.u", 0xe0)
/* prefix instructions. we use an opcode >= 256 to ease coding */
OP(ARGLIST, "arglist", 0x100)
OP(CEQ, "ceq", 0x101)
OP(CGT, "cgt", 0x102)
OP(CGT_UN, "cgt.un", 0x103)
OP(CLT, "clt", 0x104)
OP(CLT_UN, "clt.un", 0x105)
OP(LDFTN, "ldftn", 0x106)
OP(LDVIRTFTN, "ldvirtftn", 0x107)
OP(JMPI, "jmpi", 0x108)
OP(LDARG, "ldarg", 0x109)
OP(LDARGA, "ldarga", 0x10a)
OP(STARG, "starg", 0x10b)
OP(LDLOC, "ldloc", 0x10c)
OP(LDLOCA, "ldloca", 0x10d)
OP(STLOC, "stloc", 0x10e)
OP(LOCALLOC, "localloc", 0x10f)
OP(ENDFILTER, "endfilter", 0x111)
OP(UNALIGNED, "unaligned", 0x112)
OP(VOLATILE, "volatile", 0x113)
OP(TAIL, "tail", 0x114)
OP(INITOBJ, "initobj", 0x115)
OP(ANN_LIVE, "ann.live", 0x116)
OP(CPBLK, "cpblk", 0x117)
OP(INITBLK, "initblk", 0x118)
OP(ANN_REF, "ann.ref", 0x119)
OP(RETHROW, "rethrow", 0x11a)
OP(SIZEOF, "sizeof", 0x11c)
OP(REFANYTYPE, "refanytype", 0x11d)
OP(ANN_DATA, "ann.data", 0x122)
OP(ANN_ARG, "ann.arg", 0x123)
File diff suppressed because it is too large Load Diff
-108
View File
@@ -1,108 +0,0 @@
#ifndef LIBTCC_H
#define LIBTCC_H
#ifdef LIBTCC_AS_DLL
#define LIBTCCAPI __declspec(dllexport)
#else
#define LIBTCCAPI
#endif
#ifdef __cplusplus
extern "C" {
#endif
struct TCCState;
typedef struct TCCState TCCState;
/* create a new TCC compilation context */
LIBTCCAPI TCCState *tcc_new(void);
/* free a TCC compilation context */
LIBTCCAPI void tcc_delete(TCCState *s);
/* add debug information in the generated code */
LIBTCCAPI void tcc_enable_debug(TCCState *s);
/* set error/warning display callback */
LIBTCCAPI void tcc_set_error_func(TCCState *s, void *error_opaque,
void (*error_func)(void *opaque, const char *msg));
/* set/reset a warning */
LIBTCCAPI int tcc_set_warning(TCCState *s, const char *warning_name, int value);
/*****************************/
/* preprocessor */
/* add include path */
LIBTCCAPI int tcc_add_include_path(TCCState *s, const char *pathname);
/* add in system include path */
LIBTCCAPI int tcc_add_sysinclude_path(TCCState *s, const char *pathname);
/* define preprocessor symbol 'sym'. Can put optional value */
LIBTCCAPI void tcc_define_symbol(TCCState *s, const char *sym, const char *value);
/* undefine preprocess symbol 'sym' */
LIBTCCAPI void tcc_undefine_symbol(TCCState *s, const char *sym);
/*****************************/
/* compiling */
/* add a file (either a C file, dll, an object, a library or an ld
script). Return -1 if error. */
LIBTCCAPI int tcc_add_file(TCCState *s, const char *filename);
/* compile a string containing a C source. Return non zero if
error. */
LIBTCCAPI int tcc_compile_string(TCCState *s, const char *buf);
/*****************************/
/* linking commands */
/* set output type. MUST BE CALLED before any compilation */
#define TCC_OUTPUT_MEMORY 0 /* output will be ran in memory (no
output file) (default) */
#define TCC_OUTPUT_EXE 1 /* executable file */
#define TCC_OUTPUT_DLL 2 /* dynamic library */
#define TCC_OUTPUT_OBJ 3 /* object file */
#define TCC_OUTPUT_PREPROCESS 4 /* preprocessed file (used internally) */
LIBTCCAPI int tcc_set_output_type(TCCState *s, int output_type);
#define TCC_OUTPUT_FORMAT_ELF 0 /* default output format: ELF */
#define TCC_OUTPUT_FORMAT_BINARY 1 /* binary image output */
#define TCC_OUTPUT_FORMAT_COFF 2 /* COFF */
/* equivalent to -Lpath option */
LIBTCCAPI int tcc_add_library_path(TCCState *s, const char *pathname);
/* the library name is the same as the argument of the '-l' option */
LIBTCCAPI int tcc_add_library(TCCState *s, const char *libraryname);
/* add a symbol to the compiled program */
LIBTCCAPI int tcc_add_symbol(TCCState *s, const char *name, void *val);
/* output an executable, library or object file. DO NOT call
tcc_relocate() before. */
LIBTCCAPI int tcc_output_file(TCCState *s, const char *filename);
/* link and run main() function and return its value. DO NOT call
tcc_relocate() before. */
LIBTCCAPI int tcc_run(TCCState *s, int argc, char **argv);
/* copy code into memory passed in by the caller and do all relocations
(needed before using tcc_get_symbol()).
returns -1 on error and required size if ptr is NULL */
LIBTCCAPI int tcc_relocate(TCCState *s1, void *ptr);
/* return symbol value or NULL if not found */
LIBTCCAPI void *tcc_get_symbol(TCCState *s, const char *name);
/* set CONFIG_TCCDIR at runtime */
LIBTCCAPI void tcc_set_lib_path(TCCState *s, const char *path);
#ifdef __cplusplus
}
#endif
#endif
-234
View File
@@ -1,234 +0,0 @@
/* Table of DBX symbol codes for the GNU system.
Copyright (C) 1988, 1997 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If not,
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
/* This contains contribution from Cygnus Support. */
/* Global variable. Only the name is significant.
To find the address, look in the corresponding external symbol. */
__define_stab (N_GSYM, 0x20, "GSYM")
/* Function name for BSD Fortran. Only the name is significant.
To find the address, look in the corresponding external symbol. */
__define_stab (N_FNAME, 0x22, "FNAME")
/* Function name or text-segment variable for C. Value is its address.
Desc is supposedly starting line number, but GCC doesn't set it
and DBX seems not to miss it. */
__define_stab (N_FUN, 0x24, "FUN")
/* Data-segment variable with internal linkage. Value is its address.
"Static Sym". */
__define_stab (N_STSYM, 0x26, "STSYM")
/* BSS-segment variable with internal linkage. Value is its address. */
__define_stab (N_LCSYM, 0x28, "LCSYM")
/* Name of main routine. Only the name is significant.
This is not used in C. */
__define_stab (N_MAIN, 0x2a, "MAIN")
/* Global symbol in Pascal.
Supposedly the value is its line number; I'm skeptical. */
__define_stab (N_PC, 0x30, "PC")
/* Number of symbols: 0, files,,funcs,lines according to Ultrix V4.0. */
__define_stab (N_NSYMS, 0x32, "NSYMS")
/* "No DST map for sym: name, ,0,type,ignored" according to Ultrix V4.0. */
__define_stab (N_NOMAP, 0x34, "NOMAP")
/* New stab from Solaris. I don't know what it means, but it
don't seem to contain useful information. */
__define_stab (N_OBJ, 0x38, "OBJ")
/* New stab from Solaris. I don't know what it means, but it
don't seem to contain useful information. Possibly related to the
optimization flags used in this module. */
__define_stab (N_OPT, 0x3c, "OPT")
/* Register variable. Value is number of register. */
__define_stab (N_RSYM, 0x40, "RSYM")
/* Modula-2 compilation unit. Can someone say what info it contains? */
__define_stab (N_M2C, 0x42, "M2C")
/* Line number in text segment. Desc is the line number;
value is corresponding address. */
__define_stab (N_SLINE, 0x44, "SLINE")
/* Similar, for data segment. */
__define_stab (N_DSLINE, 0x46, "DSLINE")
/* Similar, for bss segment. */
__define_stab (N_BSLINE, 0x48, "BSLINE")
/* Sun's source-code browser stabs. ?? Don't know what the fields are.
Supposedly the field is "path to associated .cb file". THIS VALUE
OVERLAPS WITH N_BSLINE! */
__define_stab (N_BROWS, 0x48, "BROWS")
/* GNU Modula-2 definition module dependency. Value is the modification time
of the definition file. Other is non-zero if it is imported with the
GNU M2 keyword %INITIALIZE. Perhaps N_M2C can be used if there
are enough empty fields? */
__define_stab(N_DEFD, 0x4a, "DEFD")
/* THE FOLLOWING TWO STAB VALUES CONFLICT. Happily, one is for Modula-2
and one is for C++. Still,... */
/* GNU C++ exception variable. Name is variable name. */
__define_stab (N_EHDECL, 0x50, "EHDECL")
/* Modula2 info "for imc": name,,0,0,0 according to Ultrix V4.0. */
__define_stab (N_MOD2, 0x50, "MOD2")
/* GNU C++ `catch' clause. Value is its address. Desc is nonzero if
this entry is immediately followed by a CAUGHT stab saying what exception
was caught. Multiple CAUGHT stabs means that multiple exceptions
can be caught here. If Desc is 0, it means all exceptions are caught
here. */
__define_stab (N_CATCH, 0x54, "CATCH")
/* Structure or union element. Value is offset in the structure. */
__define_stab (N_SSYM, 0x60, "SSYM")
/* Name of main source file.
Value is starting text address of the compilation. */
__define_stab (N_SO, 0x64, "SO")
/* Automatic variable in the stack. Value is offset from frame pointer.
Also used for type descriptions. */
__define_stab (N_LSYM, 0x80, "LSYM")
/* Beginning of an include file. Only Sun uses this.
In an object file, only the name is significant.
The Sun linker puts data into some of the other fields. */
__define_stab (N_BINCL, 0x82, "BINCL")
/* Name of sub-source file (#include file).
Value is starting text address of the compilation. */
__define_stab (N_SOL, 0x84, "SOL")
/* Parameter variable. Value is offset from argument pointer.
(On most machines the argument pointer is the same as the frame pointer. */
__define_stab (N_PSYM, 0xa0, "PSYM")
/* End of an include file. No name.
This and N_BINCL act as brackets around the file's output.
In an object file, there is no significant data in this entry.
The Sun linker puts data into some of the fields. */
__define_stab (N_EINCL, 0xa2, "EINCL")
/* Alternate entry point. Value is its address. */
__define_stab (N_ENTRY, 0xa4, "ENTRY")
/* Beginning of lexical block.
The desc is the nesting level in lexical blocks.
The value is the address of the start of the text for the block.
The variables declared inside the block *precede* the N_LBRAC symbol. */
__define_stab (N_LBRAC, 0xc0, "LBRAC")
/* Place holder for deleted include file. Replaces a N_BINCL and everything
up to the corresponding N_EINCL. The Sun linker generates these when
it finds multiple identical copies of the symbols from an include file.
This appears only in output from the Sun linker. */
__define_stab (N_EXCL, 0xc2, "EXCL")
/* Modula-2 scope information. Can someone say what info it contains? */
__define_stab (N_SCOPE, 0xc4, "SCOPE")
/* End of a lexical block. Desc matches the N_LBRAC's desc.
The value is the address of the end of the text for the block. */
__define_stab (N_RBRAC, 0xe0, "RBRAC")
/* Begin named common block. Only the name is significant. */
__define_stab (N_BCOMM, 0xe2, "BCOMM")
/* End named common block. Only the name is significant
(and it should match the N_BCOMM). */
__define_stab (N_ECOMM, 0xe4, "ECOMM")
/* End common (local name): value is address.
I'm not sure how this is used. */
__define_stab (N_ECOML, 0xe8, "ECOML")
/* These STAB's are used on Gould systems for Non-Base register symbols
or something like that. FIXME. I have assigned the values at random
since I don't have a Gould here. Fixups from Gould folk welcome... */
__define_stab (N_NBTEXT, 0xF0, "NBTEXT")
__define_stab (N_NBDATA, 0xF2, "NBDATA")
__define_stab (N_NBBSS, 0xF4, "NBBSS")
__define_stab (N_NBSTS, 0xF6, "NBSTS")
__define_stab (N_NBLCS, 0xF8, "NBLCS")
/* Second symbol entry containing a length-value for the preceding entry.
The value is the length. */
__define_stab (N_LENG, 0xfe, "LENG")
/* The above information, in matrix format.
STAB MATRIX
_________________________________________________
| 00 - 1F are not dbx stab symbols |
| In most cases, the low bit is the EXTernal bit|
| 00 UNDEF | 02 ABS | 04 TEXT | 06 DATA |
| 01 |EXT | 03 |EXT | 05 |EXT | 07 |EXT |
| 08 BSS | 0A INDR | 0C FN_SEQ | 0E |
| 09 |EXT | 0B | 0D | 0F |
| 10 | 12 COMM | 14 SETA | 16 SETT |
| 11 | 13 | 15 | 17 |
| 18 SETD | 1A SETB | 1C SETV | 1E WARNING|
| 19 | 1B | 1D | 1F FN |
|_______________________________________________|
| Debug entries with bit 01 set are unused. |
| 20 GSYM | 22 FNAME | 24 FUN | 26 STSYM |
| 28 LCSYM | 2A MAIN | 2C | 2E |
| 30 PC | 32 NSYMS | 34 NOMAP | 36 |
| 38 OBJ | 3A | 3C OPT | 3E |
| 40 RSYM | 42 M2C | 44 SLINE | 46 DSLINE |
| 48 BSLINE*| 4A DEFD | 4C | 4E |
| 50 EHDECL*| 52 | 54 CATCH | 56 |
| 58 | 5A | 5C | 5E |
| 60 SSYM | 62 | 64 SO | 66 |
| 68 | 6A | 6C | 6E |
| 70 | 72 | 74 | 76 |
| 78 | 7A | 7C | 7E |
| 80 LSYM | 82 BINCL | 84 SOL | 86 |
| 88 | 8A | 8C | 8E |
| 90 | 92 | 94 | 96 |
| 98 | 9A | 9C | 9E |
| A0 PSYM | A2 EINCL | A4 ENTRY | A6 |
| A8 | AA | AC | AE |
| B0 | B2 | B4 | B6 |
| B8 | BA | BC | BE |
| C0 LBRAC | C2 EXCL | C4 SCOPE | C6 |
| C8 | CA | CC | CE |
| D0 | D2 | D4 | D6 |
| D8 | DA | DC | DE |
| E0 RBRAC | E2 BCOMM | E4 ECOMM | E6 |
| E8 ECOML | EA | EC | EE |
| F0 | F2 | F4 | F6 |
| F8 | FA | FC | FE LENG |
+-----------------------------------------------+
* 50 EHDECL is also MOD2.
* 48 BSLINE is also BROWS.
*/
-17
View File
@@ -1,17 +0,0 @@
#ifndef __GNU_STAB__
/* Indicate the GNU stab.h is in use. */
#define __GNU_STAB__
#define __define_stab(NAME, CODE, STRING) NAME=CODE,
enum __stab_debug_code
{
#include "stab.def"
LAST_UNUSED_STAB_CODE
};
#undef __define_stab
#endif /* __GNU_STAB_ */
-553
View File
@@ -1,553 +0,0 @@
/*
* TCC - Tiny C Compiler
*
* Copyright (c) 2001-2004 Fabrice Bellard
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "libtcc.c"
void help(void)
{
printf("tcc version " TCC_VERSION " - Tiny C Compiler - Copyright (C) 2001-2006 Fabrice Bellard\n"
"usage: tcc [-v] [-c] [-o outfile] [-Bdir] [-bench] [-Idir] [-Dsym[=val]] [-Usym]\n"
" [-Wwarn] [-g] [-b] [-bt N] [-Ldir] [-llib] [-shared] [-soname name]\n"
" [-static] [infile1 infile2...] [-run infile args...]\n"
"\n"
"General options:\n"
" -v display current version, increase verbosity\n"
" -c compile only - generate an object file\n"
" -o outfile set output filename\n"
" -Bdir set tcc internal library path\n"
" -bench output compilation statistics\n"
" -run run compiled source\n"
" -fflag set or reset (with 'no-' prefix) 'flag' (see man page)\n"
" -Wwarning set or reset (with 'no-' prefix) 'warning' (see man page)\n"
" -w disable all warnings\n"
"Preprocessor options:\n"
" -E preprocess only\n"
" -Idir add include path 'dir'\n"
" -Dsym[=val] define 'sym' with value 'val'\n"
" -Usym undefine 'sym'\n"
"Linker options:\n"
" -Ldir add library path 'dir'\n"
" -llib link with dynamic or static library 'lib'\n"
" -shared generate a shared library\n"
" -soname set name for shared library to be used at runtime\n"
" -static static linking\n"
" -rdynamic export all global symbols to dynamic linker\n"
" -r generate (relocatable) object file\n"
"Debugger options:\n"
" -g generate runtime debug info\n"
#ifdef CONFIG_TCC_BCHECK
" -b compile with built-in memory and bounds checker (implies -g)\n"
#endif
#ifdef CONFIG_TCC_BACKTRACE
" -bt N show N callers in stack traces\n"
#endif
);
}
static char **files;
static int nb_files, nb_libraries;
static int multiple_files;
static int print_search_dirs;
static int output_type;
static int reloc_output;
static const char *outfile;
static int do_bench = 0;
#define TCC_OPTION_HAS_ARG 0x0001
#define TCC_OPTION_NOSEP 0x0002 /* cannot have space before option and arg */
typedef struct TCCOption {
const char *name;
uint16_t index;
uint16_t flags;
} TCCOption;
enum {
TCC_OPTION_HELP,
TCC_OPTION_I,
TCC_OPTION_D,
TCC_OPTION_U,
TCC_OPTION_L,
TCC_OPTION_B,
TCC_OPTION_l,
TCC_OPTION_bench,
TCC_OPTION_bt,
TCC_OPTION_b,
TCC_OPTION_g,
TCC_OPTION_c,
TCC_OPTION_static,
TCC_OPTION_shared,
TCC_OPTION_soname,
TCC_OPTION_o,
TCC_OPTION_r,
TCC_OPTION_Wl,
TCC_OPTION_W,
TCC_OPTION_O,
TCC_OPTION_m,
TCC_OPTION_f,
TCC_OPTION_nostdinc,
TCC_OPTION_nostdlib,
TCC_OPTION_print_search_dirs,
TCC_OPTION_rdynamic,
TCC_OPTION_run,
TCC_OPTION_v,
TCC_OPTION_w,
TCC_OPTION_pipe,
TCC_OPTION_E,
};
static const TCCOption tcc_options[] = {
{ "h", TCC_OPTION_HELP, 0 },
{ "?", TCC_OPTION_HELP, 0 },
{ "I", TCC_OPTION_I, TCC_OPTION_HAS_ARG },
{ "D", TCC_OPTION_D, TCC_OPTION_HAS_ARG },
{ "U", TCC_OPTION_U, TCC_OPTION_HAS_ARG },
{ "L", TCC_OPTION_L, TCC_OPTION_HAS_ARG },
{ "B", TCC_OPTION_B, TCC_OPTION_HAS_ARG },
{ "l", TCC_OPTION_l, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP },
{ "bench", TCC_OPTION_bench, 0 },
{ "bt", TCC_OPTION_bt, TCC_OPTION_HAS_ARG },
#ifdef CONFIG_TCC_BCHECK
{ "b", TCC_OPTION_b, 0 },
#endif
{ "g", TCC_OPTION_g, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP },
{ "c", TCC_OPTION_c, 0 },
{ "static", TCC_OPTION_static, 0 },
{ "shared", TCC_OPTION_shared, 0 },
{ "soname", TCC_OPTION_soname, TCC_OPTION_HAS_ARG },
{ "o", TCC_OPTION_o, TCC_OPTION_HAS_ARG },
{ "run", TCC_OPTION_run, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP },
{ "rdynamic", TCC_OPTION_rdynamic, 0 },
{ "r", TCC_OPTION_r, 0 },
{ "Wl,", TCC_OPTION_Wl, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP },
{ "W", TCC_OPTION_W, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP },
{ "O", TCC_OPTION_O, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP },
{ "m", TCC_OPTION_m, TCC_OPTION_HAS_ARG },
{ "f", TCC_OPTION_f, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP },
{ "nostdinc", TCC_OPTION_nostdinc, 0 },
{ "nostdlib", TCC_OPTION_nostdlib, 0 },
{ "print-search-dirs", TCC_OPTION_print_search_dirs, 0 },
{ "v", TCC_OPTION_v, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP },
{ "w", TCC_OPTION_w, 0 },
{ "pipe", TCC_OPTION_pipe, 0},
{ "E", TCC_OPTION_E, 0},
{ NULL },
};
static int64_t getclock_us(void)
{
#ifdef _WIN32
struct _timeb tb;
_ftime(&tb);
return (tb.time * 1000LL + tb.millitm) * 1000LL;
#else
struct timeval tv;
gettimeofday(&tv, NULL);
return tv.tv_sec * 1000000LL + tv.tv_usec;
#endif
}
static int strstart(const char *str, const char *val, const char **ptr)
{
const char *p, *q;
p = str;
q = val;
while (*q != '\0') {
if (*p != *q)
return 0;
p++;
q++;
}
if (ptr)
*ptr = p;
return 1;
}
/* convert 'str' into an array of space separated strings */
static int expand_args(char ***pargv, const char *str)
{
const char *s1;
char **argv, *arg;
int argc, len;
argc = 0;
argv = NULL;
for(;;) {
while (is_space(*str))
str++;
if (*str == '\0')
break;
s1 = str;
while (*str != '\0' && !is_space(*str))
str++;
len = str - s1;
arg = tcc_malloc(len + 1);
memcpy(arg, s1, len);
arg[len] = '\0';
dynarray_add((void ***)&argv, &argc, arg);
}
*pargv = argv;
return argc;
}
int parse_args(TCCState *s, int argc, char **argv)
{
int optind;
const TCCOption *popt;
const char *optarg, *p1, *r1;
char *r;
optind = 0;
while (optind < argc) {
r = argv[optind++];
if (r[0] != '-' || r[1] == '\0') {
/* add a new file */
dynarray_add((void ***)&files, &nb_files, r);
if (!multiple_files) {
optind--;
/* argv[0] will be this file */
break;
}
} else {
/* find option in table (match only the first chars */
popt = tcc_options;
for(;;) {
p1 = popt->name;
if (p1 == NULL)
error("invalid option -- '%s'", r);
r1 = r + 1;
for(;;) {
if (*p1 == '\0')
goto option_found;
if (*r1 != *p1)
break;
p1++;
r1++;
}
popt++;
}
option_found:
if (popt->flags & TCC_OPTION_HAS_ARG) {
if (*r1 != '\0' || (popt->flags & TCC_OPTION_NOSEP)) {
optarg = r1;
} else {
if (optind >= argc)
error("argument to '%s' is missing", r);
optarg = argv[optind++];
}
} else {
if (*r1 != '\0')
return 0;
optarg = NULL;
}
switch(popt->index) {
case TCC_OPTION_HELP:
return 0;
case TCC_OPTION_I:
if (tcc_add_include_path(s, optarg) < 0)
error("too many include paths");
break;
case TCC_OPTION_D:
{
char *sym, *value;
sym = (char *)optarg;
value = strchr(sym, '=');
if (value) {
*value = '\0';
value++;
}
tcc_define_symbol(s, sym, value);
}
break;
case TCC_OPTION_U:
tcc_undefine_symbol(s, optarg);
break;
case TCC_OPTION_L:
tcc_add_library_path(s, optarg);
break;
case TCC_OPTION_B:
/* set tcc utilities path (mainly for tcc development) */
tcc_set_lib_path(s, optarg);
break;
case TCC_OPTION_l:
dynarray_add((void ***)&files, &nb_files, r);
nb_libraries++;
break;
case TCC_OPTION_bench:
do_bench = 1;
break;
#ifdef CONFIG_TCC_BACKTRACE
case TCC_OPTION_bt:
num_callers = atoi(optarg);
break;
#endif
#ifdef CONFIG_TCC_BCHECK
case TCC_OPTION_b:
s->do_bounds_check = 1;
s->do_debug = 1;
break;
#endif
case TCC_OPTION_g:
s->do_debug = 1;
break;
case TCC_OPTION_c:
multiple_files = 1;
output_type = TCC_OUTPUT_OBJ;
break;
case TCC_OPTION_static:
s->static_link = 1;
break;
case TCC_OPTION_shared:
output_type = TCC_OUTPUT_DLL;
break;
case TCC_OPTION_soname:
s->soname = optarg;
break;
case TCC_OPTION_o:
multiple_files = 1;
outfile = optarg;
break;
case TCC_OPTION_r:
/* generate a .o merging several output files */
reloc_output = 1;
output_type = TCC_OUTPUT_OBJ;
break;
case TCC_OPTION_nostdinc:
s->nostdinc = 1;
break;
case TCC_OPTION_nostdlib:
s->nostdlib = 1;
break;
case TCC_OPTION_print_search_dirs:
print_search_dirs = 1;
break;
case TCC_OPTION_run:
{
int argc1;
char **argv1;
argc1 = expand_args(&argv1, optarg);
if (argc1 > 0) {
parse_args(s, argc1, argv1);
}
multiple_files = 0;
output_type = TCC_OUTPUT_MEMORY;
}
break;
case TCC_OPTION_v:
do {
if (0 == s->verbose++)
printf("tcc version %s\n", TCC_VERSION);
} while (*optarg++ == 'v');
break;
case TCC_OPTION_f:
if (tcc_set_flag(s, optarg, 1) < 0 && s->warn_unsupported)
goto unsupported_option;
break;
case TCC_OPTION_W:
if (tcc_set_warning(s, optarg, 1) < 0 &&
s->warn_unsupported)
goto unsupported_option;
break;
case TCC_OPTION_w:
s->warn_none = 1;
break;
case TCC_OPTION_rdynamic:
s->rdynamic = 1;
break;
case TCC_OPTION_Wl:
{
const char *p;
if (strstart(optarg, "-Ttext,", &p)) {
s->text_addr = strtoul(p, NULL, 16);
s->has_text_addr = 1;
} else if (strstart(optarg, "--oformat,", &p)) {
if (strstart(p, "elf32-", NULL)) {
s->output_format = TCC_OUTPUT_FORMAT_ELF;
} else if (!strcmp(p, "binary")) {
s->output_format = TCC_OUTPUT_FORMAT_BINARY;
} else
#ifdef TCC_TARGET_COFF
if (!strcmp(p, "coff")) {
s->output_format = TCC_OUTPUT_FORMAT_COFF;
} else
#endif
{
error("target %s not found", p);
}
} else {
error("unsupported linker option '%s'", optarg);
}
}
break;
case TCC_OPTION_E:
output_type = TCC_OUTPUT_PREPROCESS;
break;
default:
if (s->warn_unsupported) {
unsupported_option:
warning("unsupported option '%s'", r);
}
break;
}
}
}
return optind + 1;
}
int main(int argc, char **argv)
{
int i;
TCCState *s;
int nb_objfiles, ret, optind;
char objfilename[1024];
int64_t start_time = 0;
s = tcc_new();
#ifdef _WIN32
tcc_set_lib_path_w32(s);
#endif
output_type = TCC_OUTPUT_EXE;
outfile = NULL;
multiple_files = 1;
files = NULL;
nb_files = 0;
nb_libraries = 0;
reloc_output = 0;
print_search_dirs = 0;
ret = 0;
optind = parse_args(s, argc - 1, argv + 1);
if (print_search_dirs) {
/* enough for Linux kernel */
printf("install: %s/\n", s->tcc_lib_path);
return 0;
}
if (optind == 0 || nb_files == 0) {
if (optind && s->verbose)
return 0;
help();
return 1;
}
nb_objfiles = nb_files - nb_libraries;
/* if outfile provided without other options, we output an
executable */
if (outfile && output_type == TCC_OUTPUT_MEMORY)
output_type = TCC_OUTPUT_EXE;
/* check -c consistency : only single file handled. XXX: checks file type */
if (output_type == TCC_OUTPUT_OBJ && !reloc_output) {
/* accepts only a single input file */
if (nb_objfiles != 1)
error("cannot specify multiple files with -c");
if (nb_libraries != 0)
error("cannot specify libraries with -c");
}
if (output_type == TCC_OUTPUT_PREPROCESS) {
if (!outfile) {
s->outfile = stdout;
} else {
s->outfile = fopen(outfile, "w");
if (!s->outfile)
error("could not open '%s", outfile);
}
} else if (output_type != TCC_OUTPUT_MEMORY) {
if (!outfile) {
/* compute default outfile name */
char *ext;
const char *name =
strcmp(files[0], "-") == 0 ? "a" : tcc_basename(files[0]);
pstrcpy(objfilename, sizeof(objfilename), name);
ext = tcc_fileextension(objfilename);
#ifdef TCC_TARGET_PE
if (output_type == TCC_OUTPUT_DLL)
strcpy(ext, ".dll");
else
if (output_type == TCC_OUTPUT_EXE)
strcpy(ext, ".exe");
else
#endif
if (output_type == TCC_OUTPUT_OBJ && !reloc_output && *ext)
strcpy(ext, ".o");
else
pstrcpy(objfilename, sizeof(objfilename), "a.out");
outfile = objfilename;
}
}
if (do_bench) {
start_time = getclock_us();
}
tcc_set_output_type(s, output_type);
/* compile or add each files or library */
for(i = 0; i < nb_files && ret == 0; i++) {
const char *filename;
filename = files[i];
if (filename[0] == '-' && filename[1]) {
if (tcc_add_library(s, filename + 2) < 0) {
error_noabort("cannot find %s", filename);
ret = 1;
}
} else {
if (1 == s->verbose)
printf("-> %s\n", filename);
if (tcc_add_file(s, filename) < 0)
ret = 1;
}
}
/* free all files */
tcc_free(files);
if (ret)
goto the_end;
if (do_bench)
tcc_print_stats(s, getclock_us() - start_time);
if (s->output_type == TCC_OUTPUT_PREPROCESS) {
if (outfile)
fclose(s->outfile);
} else if (s->output_type == TCC_OUTPUT_MEMORY) {
ret = tcc_run(s, argc - optind, argv + optind);
} else
ret = tcc_output_file(s, outfile) ? 1 : 0;
the_end:
/* XXX: cannot do it with bound checking because of the malloc hooks */
if (!s->do_bounds_check)
tcc_delete(s);
#ifdef MEM_DEBUG
if (do_bench) {
printf("memory: %d bytes, max = %d bytes\n", mem_cur_size, mem_max_size);
}
#endif
return ret;
}
-766
View File
@@ -1,766 +0,0 @@
/*
* TCC - Tiny C Compiler
*
* Copyright (c) 2001-2004 Fabrice Bellard
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#define _GNU_SOURCE
#include "config.h"
#ifdef CONFIG_TCCBOOT
#include "tccboot.h"
#define CONFIG_TCC_STATIC
#else
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <errno.h>
#include <math.h>
#include <signal.h>
#include <fcntl.h>
#include <setjmp.h>
#include <time.h>
#ifdef _WIN32
#include <windows.h>
#include <sys/timeb.h>
#include <io.h> /* open, close etc. */
#include <direct.h> /* getcwd */
#define inline __inline
#define inp next_inp
#endif
#ifndef _WIN32
#include <unistd.h>
#include <sys/time.h>
#include <sys/ucontext.h>
#include <sys/mman.h>
#endif
#endif /* !CONFIG_TCCBOOT */
#ifndef PAGESIZE
#define PAGESIZE 4096
#endif
#include "elf.h"
#include "stab.h"
#ifndef O_BINARY
#define O_BINARY 0
#endif
#include "libtcc.h"
/* parser debug */
//#define PARSE_DEBUG
/* preprocessor debug */
//#define PP_DEBUG
/* include file debug */
//#define INC_DEBUG
//#define MEM_DEBUG
/* assembler debug */
//#define ASM_DEBUG
/* target selection */
//#define TCC_TARGET_I386 /* i386 code generator */
//#define TCC_TARGET_ARM /* ARMv4 code generator */
//#define TCC_TARGET_C67 /* TMS320C67xx code generator */
//#define TCC_TARGET_X86_64 /* x86-64 code generator */
/* default target is I386 */
#if !defined(TCC_TARGET_I386) && !defined(TCC_TARGET_ARM) && \
!defined(TCC_TARGET_C67) && !defined(TCC_TARGET_X86_64)
#define TCC_TARGET_I386
#endif
#if !defined(_WIN32) && !defined(TCC_UCLIBC) && !defined(TCC_TARGET_ARM) && \
!defined(TCC_TARGET_C67) && !defined(TCC_TARGET_X86_64)
#define CONFIG_TCC_BCHECK /* enable bound checking code */
#endif
#if defined(_WIN32) && !defined(TCC_TARGET_PE)
#define CONFIG_TCC_STATIC
#endif
/* define it to include assembler support */
#if !defined(TCC_TARGET_ARM) && !defined(TCC_TARGET_C67) && \
!defined(TCC_TARGET_X86_64)
#define CONFIG_TCC_ASM
#endif
/* object format selection */
#if defined(TCC_TARGET_C67)
#define TCC_TARGET_COFF
#endif
#if !defined(_WIN32) && !defined(CONFIG_TCCBOOT)
#define CONFIG_TCC_BACKTRACE
#endif
#define FALSE 0
#define false 0
#define TRUE 1
#define true 1
typedef int BOOL;
/* path to find crt1.o, crti.o and crtn.o. Only needed when generating
executables or dlls */
#define CONFIG_TCC_CRT_PREFIX CONFIG_SYSROOT "/usr/lib"
#define INCLUDE_STACK_SIZE 32
#define IFDEF_STACK_SIZE 64
#define VSTACK_SIZE 256
#define STRING_MAX_SIZE 1024
#define PACK_STACK_SIZE 8
#define TOK_HASH_SIZE 8192 /* must be a power of two */
#define TOK_ALLOC_INCR 512 /* must be a power of two */
#define TOK_MAX_SIZE 4 /* token max size in int unit when stored in string */
/* token symbol management */
typedef struct TokenSym {
struct TokenSym *hash_next;
struct Sym *sym_define; /* direct pointer to define */
struct Sym *sym_label; /* direct pointer to label */
struct Sym *sym_struct; /* direct pointer to structure */
struct Sym *sym_identifier; /* direct pointer to identifier */
int tok; /* token number */
int len;
char str[1];
} TokenSym;
#ifdef TCC_TARGET_PE
typedef unsigned short nwchar_t;
#else
typedef int nwchar_t;
#endif
typedef struct CString {
int size; /* size in bytes */
void *data; /* either 'char *' or 'nwchar_t *' */
int size_allocated;
void *data_allocated; /* if non NULL, data has been malloced */
} CString;
/* type definition */
typedef struct CType {
int t;
struct Sym *ref;
} CType;
/* constant value */
typedef union CValue {
long double ld;
double d;
float f;
int i;
unsigned int ui;
unsigned int ul; /* address (should be unsigned long on 64 bit cpu) */
long long ll;
unsigned long long ull;
struct CString *cstr;
void *ptr;
int tab[1];
} CValue;
/* value on stack */
typedef struct SValue {
CType type; /* type */
unsigned short r; /* register + flags */
unsigned short r2; /* second register, used for 'long long'
type. If not used, set to VT_CONST */
CValue c; /* constant, if VT_CONST */
struct Sym *sym; /* symbol, if (VT_SYM | VT_CONST) */
} SValue;
/* symbol management */
typedef struct Sym {
int v; /* symbol token */
long r; /* associated register */
long c; /* associated number */
CType type; /* associated type */
struct Sym *next; /* next related symbol */
struct Sym *prev; /* prev symbol in stack */
struct Sym *prev_tok; /* previous symbol for this token */
} Sym;
/* section definition */
/* XXX: use directly ELF structure for parameters ? */
/* special flag to indicate that the section should not be linked to
the other ones */
#define SHF_PRIVATE 0x80000000
/* special flag, too */
#define SECTION_ABS ((void *)1)
typedef struct Section {
unsigned long data_offset; /* current data offset */
unsigned char *data; /* section data */
unsigned long data_allocated; /* used for realloc() handling */
int sh_name; /* elf section name (only used during output) */
int sh_num; /* elf section number */
int sh_type; /* elf section type */
int sh_flags; /* elf section flags */
int sh_info; /* elf section info */
int sh_addralign; /* elf section alignment */
int sh_entsize; /* elf entry size */
unsigned long sh_size; /* section size (only used during output) */
unsigned long sh_addr; /* address at which the section is relocated */
unsigned long sh_offset; /* file offset */
int nb_hashed_syms; /* used to resize the hash table */
struct Section *link; /* link to another section */
struct Section *reloc; /* corresponding section for relocation, if any */
struct Section *hash; /* hash table for symbols */
struct Section *next;
char name[1]; /* section name */
} Section;
typedef struct DLLReference {
int level;
void *handle;
char name[1];
} DLLReference;
/* GNUC attribute definition */
typedef struct AttributeDef {
int aligned;
int packed;
Section *section;
int func_attr; /* calling convention, exports, ... */
} AttributeDef;
/* -------------------------------------------------- */
/* gr: wrappers for casting sym->r for other purposes */
typedef struct {
unsigned
func_call : 8,
func_args : 8,
func_export : 1;
} func_attr_t;
#define FUNC_CALL(r) (((func_attr_t*)&(r))->func_call)
#define FUNC_EXPORT(r) (((func_attr_t*)&(r))->func_export)
#define FUNC_ARGS(r) (((func_attr_t*)&(r))->func_args)
#define INLINE_DEF(r) (*(int **)&(r))
/* -------------------------------------------------- */
#define SYM_STRUCT 0x40000000 /* struct/union/enum symbol space */
#define SYM_FIELD 0x20000000 /* struct/union field symbol space */
#define SYM_FIRST_ANOM 0x10000000 /* first anonymous sym */
/* stored in 'Sym.c' field */
#define FUNC_NEW 1 /* ansi function prototype */
#define FUNC_OLD 2 /* old function prototype */
#define FUNC_ELLIPSIS 3 /* ansi function prototype with ... */
/* stored in 'Sym.r' field */
#define FUNC_CDECL 0 /* standard c call */
#define FUNC_STDCALL 1 /* pascal c call */
#define FUNC_FASTCALL1 2 /* first param in %eax */
#define FUNC_FASTCALL2 3 /* first parameters in %eax, %edx */
#define FUNC_FASTCALL3 4 /* first parameter in %eax, %edx, %ecx */
#define FUNC_FASTCALLW 5 /* first parameter in %ecx, %edx */
/* field 'Sym.t' for macros */
#define MACRO_OBJ 0 /* object like macro */
#define MACRO_FUNC 1 /* function like macro */
/* field 'Sym.r' for C labels */
#define LABEL_DEFINED 0 /* label is defined */
#define LABEL_FORWARD 1 /* label is forward defined */
#define LABEL_DECLARED 2 /* label is declared but never used */
/* type_decl() types */
#define TYPE_ABSTRACT 1 /* type without variable */
#define TYPE_DIRECT 2 /* type with variable */
#define IO_BUF_SIZE 8192
typedef struct BufferedFile {
uint8_t *buf_ptr;
uint8_t *buf_end;
int fd;
int line_num; /* current line number - here to simplify code */
int ifndef_macro; /* #ifndef macro / #endif search */
int ifndef_macro_saved; /* saved ifndef_macro */
int *ifdef_stack_ptr; /* ifdef_stack value at the start of the file */
char inc_type; /* type of include */
char inc_filename[512]; /* filename specified by the user */
char filename[1024]; /* current filename - here to simplify code */
unsigned char buffer[IO_BUF_SIZE + 1]; /* extra size for CH_EOB char */
} BufferedFile;
#define CH_EOB '\\' /* end of buffer or '\0' char in file */
#define CH_EOF (-1) /* end of file */
/* parsing state (used to save parser state to reparse part of the
source several times) */
typedef struct ParseState {
int *macro_ptr;
int line_num;
int tok;
CValue tokc;
} ParseState;
/* used to record tokens */
typedef struct TokenString {
int *str;
int len;
int allocated_len;
int last_line_num;
} TokenString;
/* include file cache, used to find files faster and also to eliminate
inclusion if the include file is protected by #ifndef ... #endif */
typedef struct CachedInclude {
int ifndef_macro;
int hash_next; /* -1 if none */
char type; /* '"' or '>' to give include type */
char filename[1]; /* path specified in #include */
} CachedInclude;
#define CACHED_INCLUDES_HASH_SIZE 512
#ifdef CONFIG_TCC_ASM
typedef struct ExprValue {
uint32_t v;
Sym *sym;
} ExprValue;
#define MAX_ASM_OPERANDS 30
typedef struct ASMOperand {
int id; /* GCC 3 optionnal identifier (0 if number only supported */
char *constraint;
char asm_str[16]; /* computed asm string for operand */
SValue *vt; /* C value of the expression */
int ref_index; /* if >= 0, gives reference to a output constraint */
int input_index; /* if >= 0, gives reference to an input constraint */
int priority; /* priority, used to assign registers */
int reg; /* if >= 0, register number used for this operand */
int is_llong; /* true if double register value */
int is_memory; /* true if memory operand */
int is_rw; /* for '+' modifier */
} ASMOperand;
#endif
struct TCCState {
int output_type;
BufferedFile **include_stack_ptr;
int *ifdef_stack_ptr;
/* include file handling */
char **include_paths;
int nb_include_paths;
char **sysinclude_paths;
int nb_sysinclude_paths;
CachedInclude **cached_includes;
int nb_cached_includes;
char **library_paths;
int nb_library_paths;
/* array of all loaded dlls (including those referenced by loaded
dlls) */
DLLReference **loaded_dlls;
int nb_loaded_dlls;
/* sections */
Section **sections;
int nb_sections; /* number of sections, including first dummy section */
Section **priv_sections;
int nb_priv_sections; /* number of private sections */
/* got handling */
Section *got;
Section *plt;
unsigned long *got_offsets;
int nb_got_offsets;
/* give the correspondance from symtab indexes to dynsym indexes */
int *symtab_to_dynsym;
/* temporary dynamic symbol sections (for dll loading) */
Section *dynsymtab_section;
/* exported dynamic symbol section */
Section *dynsym;
int nostdinc; /* if true, no standard headers are added */
int nostdlib; /* if true, no standard libraries are added */
int nocommon; /* if true, do not use common symbols for .bss data */
/* if true, static linking is performed */
int static_link;
/* soname as specified on the command line (-soname) */
const char *soname;
/* if true, all symbols are exported */
int rdynamic;
/* if true, only link in referenced objects from archive */
int alacarte_link;
/* address of text section */
unsigned long text_addr;
int has_text_addr;
/* output format, see TCC_OUTPUT_FORMAT_xxx */
int output_format;
/* C language options */
int char_is_unsigned;
int leading_underscore;
/* warning switches */
int warn_write_strings;
int warn_unsupported;
int warn_error;
int warn_none;
int warn_implicit_function_declaration;
/* display some information during compilation */
int verbose;
/* compile with debug symbol (and use them if error during execution) */
int do_debug;
/* compile with built-in memory and bounds checker */
int do_bounds_check;
/* give the path of the tcc libraries */
const char *tcc_lib_path;
/* error handling */
void *error_opaque;
void (*error_func)(void *opaque, const char *msg);
int error_set_jmp_enabled;
jmp_buf error_jmp_buf;
int nb_errors;
/* tiny assembler state */
Sym *asm_labels;
/* see include_stack_ptr */
BufferedFile *include_stack[INCLUDE_STACK_SIZE];
/* see ifdef_stack_ptr */
int ifdef_stack[IFDEF_STACK_SIZE];
/* see cached_includes */
int cached_includes_hash[CACHED_INCLUDES_HASH_SIZE];
/* pack stack */
int pack_stack[PACK_STACK_SIZE];
int *pack_stack_ptr;
/* output file for preprocessing */
FILE *outfile;
/* for tcc_relocate */
int runtime_added;
#ifdef TCC_TARGET_X86_64
/* write PLT and GOT here */
char *runtime_plt_and_got;
unsigned int runtime_plt_and_got_offset;
#endif
};
/* The current value can be: */
#define VT_VALMASK 0x00ff
#define VT_CONST 0x00f0 /* constant in vc
(must be first non register value) */
#define VT_LLOCAL 0x00f1 /* lvalue, offset on stack */
#define VT_LOCAL 0x00f2 /* offset on stack */
#define VT_CMP 0x00f3 /* the value is stored in processor flags (in vc) */
#define VT_JMP 0x00f4 /* value is the consequence of jmp true (even) */
#define VT_JMPI 0x00f5 /* value is the consequence of jmp false (odd) */
#define VT_LVAL 0x0100 /* var is an lvalue */
#define VT_SYM 0x0200 /* a symbol value is added */
#define VT_MUSTCAST 0x0400 /* value must be casted to be correct (used for
char/short stored in integer registers) */
#define VT_MUSTBOUND 0x0800 /* bound checking must be done before
dereferencing value */
#define VT_BOUNDED 0x8000 /* value is bounded. The address of the
bounding function call point is in vc */
#define VT_LVAL_BYTE 0x1000 /* lvalue is a byte */
#define VT_LVAL_SHORT 0x2000 /* lvalue is a short */
#define VT_LVAL_UNSIGNED 0x4000 /* lvalue is unsigned */
#define VT_LVAL_TYPE (VT_LVAL_BYTE | VT_LVAL_SHORT | VT_LVAL_UNSIGNED)
/* types */
#define VT_INT 0 /* integer type */
#define VT_BYTE 1 /* signed byte type */
#define VT_SHORT 2 /* short type */
#define VT_VOID 3 /* void type */
#define VT_PTR 4 /* pointer */
#define VT_ENUM 5 /* enum definition */
#define VT_FUNC 6 /* function type */
#define VT_STRUCT 7 /* struct/union definition */
#define VT_FLOAT 8 /* IEEE float */
#define VT_DOUBLE 9 /* IEEE double */
#define VT_LDOUBLE 10 /* IEEE long double */
#define VT_BOOL 11 /* ISOC99 boolean type */
#define VT_LLONG 12 /* 64 bit integer */
#define VT_LONG 13 /* long integer (NEVER USED as type, only
during parsing) */
#define VT_BTYPE 0x000f /* mask for basic type */
#define VT_UNSIGNED 0x0010 /* unsigned type */
#define VT_ARRAY 0x0020 /* array type (also has VT_PTR) */
#define VT_BITFIELD 0x0040 /* bitfield modifier */
#define VT_CONSTANT 0x0800 /* const modifier */
#define VT_VOLATILE 0x1000 /* volatile modifier */
#define VT_SIGNED 0x2000 /* signed type */
/* storage */
#define VT_EXTERN 0x00000080 /* extern definition */
#define VT_STATIC 0x00000100 /* static variable */
#define VT_TYPEDEF 0x00000200 /* typedef definition */
#define VT_INLINE 0x00000400 /* inline definition */
#define VT_STRUCT_SHIFT 16 /* shift for bitfield shift values */
/* type mask (except storage) */
#define VT_STORAGE (VT_EXTERN | VT_STATIC | VT_TYPEDEF | VT_INLINE)
#define VT_TYPE (~(VT_STORAGE))
/* token values */
/* warning: the following compare tokens depend on i386 asm code */
#define TOK_ULT 0x92
#define TOK_UGE 0x93
#define TOK_EQ 0x94
#define TOK_NE 0x95
#define TOK_ULE 0x96
#define TOK_UGT 0x97
#define TOK_Nset 0x98
#define TOK_Nclear 0x99
#define TOK_LT 0x9c
#define TOK_GE 0x9d
#define TOK_LE 0x9e
#define TOK_GT 0x9f
#define TOK_LAND 0xa0
#define TOK_LOR 0xa1
#define TOK_DEC 0xa2
#define TOK_MID 0xa3 /* inc/dec, to void constant */
#define TOK_INC 0xa4
#define TOK_UDIV 0xb0 /* unsigned division */
#define TOK_UMOD 0xb1 /* unsigned modulo */
#define TOK_PDIV 0xb2 /* fast division with undefined rounding for pointers */
#define TOK_CINT 0xb3 /* number in tokc */
#define TOK_CCHAR 0xb4 /* char constant in tokc */
#define TOK_STR 0xb5 /* pointer to string in tokc */
#define TOK_TWOSHARPS 0xb6 /* ## preprocessing token */
#define TOK_LCHAR 0xb7
#define TOK_LSTR 0xb8
#define TOK_CFLOAT 0xb9 /* float constant */
#define TOK_LINENUM 0xba /* line number info */
#define TOK_CDOUBLE 0xc0 /* double constant */
#define TOK_CLDOUBLE 0xc1 /* long double constant */
#define TOK_UMULL 0xc2 /* unsigned 32x32 -> 64 mul */
#define TOK_ADDC1 0xc3 /* add with carry generation */
#define TOK_ADDC2 0xc4 /* add with carry use */
#define TOK_SUBC1 0xc5 /* add with carry generation */
#define TOK_SUBC2 0xc6 /* add with carry use */
#define TOK_CUINT 0xc8 /* unsigned int constant */
#define TOK_CLLONG 0xc9 /* long long constant */
#define TOK_CULLONG 0xca /* unsigned long long constant */
#define TOK_ARROW 0xcb
#define TOK_DOTS 0xcc /* three dots */
#define TOK_SHR 0xcd /* unsigned shift right */
#define TOK_PPNUM 0xce /* preprocessor number */
#define TOK_SHL 0x01 /* shift left */
#define TOK_SAR 0x02 /* signed shift right */
/* assignement operators : normal operator or 0x80 */
#define TOK_A_MOD 0xa5
#define TOK_A_AND 0xa6
#define TOK_A_MUL 0xaa
#define TOK_A_ADD 0xab
#define TOK_A_SUB 0xad
#define TOK_A_DIV 0xaf
#define TOK_A_XOR 0xde
#define TOK_A_OR 0xfc
#define TOK_A_SHL 0x81
#define TOK_A_SAR 0x82
#ifndef offsetof
#define offsetof(type, field) ((size_t) &((type *)0)->field)
#endif
#ifndef countof
#define countof(tab) (sizeof(tab) / sizeof((tab)[0]))
#endif
#define TOK_EOF (-1) /* end of file */
#define TOK_LINEFEED 10 /* line feed */
/* all identificators and strings have token above that */
#define TOK_IDENT 256
/* only used for i386 asm opcodes definitions */
#define DEF_ASM(x) DEF(TOK_ASM_ ## x, #x)
#define DEF_BWL(x) \
DEF(TOK_ASM_ ## x ## b, #x "b") \
DEF(TOK_ASM_ ## x ## w, #x "w") \
DEF(TOK_ASM_ ## x ## l, #x "l") \
DEF(TOK_ASM_ ## x, #x)
#define DEF_WL(x) \
DEF(TOK_ASM_ ## x ## w, #x "w") \
DEF(TOK_ASM_ ## x ## l, #x "l") \
DEF(TOK_ASM_ ## x, #x)
#define DEF_FP1(x) \
DEF(TOK_ASM_ ## f ## x ## s, "f" #x "s") \
DEF(TOK_ASM_ ## fi ## x ## l, "fi" #x "l") \
DEF(TOK_ASM_ ## f ## x ## l, "f" #x "l") \
DEF(TOK_ASM_ ## fi ## x ## s, "fi" #x "s")
#define DEF_FP(x) \
DEF(TOK_ASM_ ## f ## x, "f" #x ) \
DEF(TOK_ASM_ ## f ## x ## p, "f" #x "p") \
DEF_FP1(x)
#define DEF_ASMTEST(x) \
DEF_ASM(x ## o) \
DEF_ASM(x ## no) \
DEF_ASM(x ## b) \
DEF_ASM(x ## c) \
DEF_ASM(x ## nae) \
DEF_ASM(x ## nb) \
DEF_ASM(x ## nc) \
DEF_ASM(x ## ae) \
DEF_ASM(x ## e) \
DEF_ASM(x ## z) \
DEF_ASM(x ## ne) \
DEF_ASM(x ## nz) \
DEF_ASM(x ## be) \
DEF_ASM(x ## na) \
DEF_ASM(x ## nbe) \
DEF_ASM(x ## a) \
DEF_ASM(x ## s) \
DEF_ASM(x ## ns) \
DEF_ASM(x ## p) \
DEF_ASM(x ## pe) \
DEF_ASM(x ## np) \
DEF_ASM(x ## po) \
DEF_ASM(x ## l) \
DEF_ASM(x ## nge) \
DEF_ASM(x ## nl) \
DEF_ASM(x ## ge) \
DEF_ASM(x ## le) \
DEF_ASM(x ## ng) \
DEF_ASM(x ## nle) \
DEF_ASM(x ## g)
#define TOK_ASM_int TOK_INT
enum tcc_token {
TOK_LAST = TOK_IDENT - 1,
#define DEF(id, str) id,
#include "tcctok.h"
#undef DEF
};
#define TOK_UIDENT TOK_DEFINE
#ifdef _WIN32
#define snprintf _snprintf
#define vsnprintf _vsnprintf
#ifndef __GNUC__
#define strtold (long double)strtod
#define strtof (float)strtod
#define strtoll (long long)strtol
#endif
#elif defined(TCC_UCLIBC) || defined(__FreeBSD__) || defined(__DragonFly__) \
|| defined(__OpenBSD__)
/* currently incorrect */
long double strtold(const char *nptr, char **endptr)
{
return (long double)strtod(nptr, endptr);
}
float strtof(const char *nptr, char **endptr)
{
return (float)strtod(nptr, endptr);
}
#else
/* XXX: need to define this to use them in non ISOC99 context */
extern float strtof (const char *__nptr, char **__endptr);
extern long double strtold (const char *__nptr, char **__endptr);
#endif
#ifdef _WIN32
#define IS_PATHSEP(c) (c == '/' || c == '\\')
#define IS_ABSPATH(p) (IS_PATHSEP(p[0]) || (p[0] && p[1] == ':' && IS_PATHSEP(p[2])))
#define PATHCMP stricmp
#else
#define IS_PATHSEP(c) (c == '/')
#define IS_ABSPATH(p) IS_PATHSEP(p[0])
#define PATHCMP strcmp
#endif
void error(const char *fmt, ...);
void error_noabort(const char *fmt, ...);
void warning(const char *fmt, ...);
void tcc_set_lib_path_w32(TCCState *s);
int tcc_set_flag(TCCState *s, const char *flag_name, int value);
void tcc_print_stats(TCCState *s, int64_t total_time);
void tcc_free(void *ptr);
void *tcc_malloc(unsigned long size);
void *tcc_mallocz(unsigned long size);
void *tcc_realloc(void *ptr, unsigned long size);
char *tcc_strdup(const char *str);
char *tcc_basename(const char *name);
char *tcc_fileextension (const char *name);
char *pstrcpy(char *buf, int buf_size, const char *s);
char *pstrcat(char *buf, int buf_size, const char *s);
void dynarray_add(void ***ptab, int *nb_ptr, void *data);
void dynarray_reset(void *pp, int *n);
#ifdef CONFIG_TCC_BACKTRACE
extern int num_callers;
extern const char **rt_bound_error_msg;
#endif
/* true if float/double/long double type */
static inline int is_float(int t)
{
int bt;
bt = t & VT_BTYPE;
return bt == VT_LDOUBLE || bt == VT_DOUBLE || bt == VT_FLOAT;
}
/* space exlcuding newline */
static inline int is_space(int ch)
{
return ch == ' ' || ch == '\t' || ch == '\v' || ch == '\f' || ch == '\r';
}
File diff suppressed because it is too large Load Diff
-957
View File
@@ -1,957 +0,0 @@
/*
* COFF file handling for TCC
*
* Copyright (c) 2003, 2004 TK
* Copyright (c) 2004 Fabrice Bellard
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "coff.h"
#define MAXNSCNS 255 /* MAXIMUM NUMBER OF SECTIONS */
#define MAX_STR_TABLE 1000000
AOUTHDR o_filehdr; /* OPTIONAL (A.OUT) FILE HEADER */
SCNHDR section_header[MAXNSCNS];
#define MAX_FUNCS 1000
#define MAX_FUNC_NAME_LENGTH 128
int nFuncs;
char Func[MAX_FUNCS][MAX_FUNC_NAME_LENGTH];
char AssociatedFile[MAX_FUNCS][MAX_FUNC_NAME_LENGTH];
int LineNoFilePtr[MAX_FUNCS];
int EndAddress[MAX_FUNCS];
int LastLineNo[MAX_FUNCS];
int FuncEntries[MAX_FUNCS];
BOOL OutputTheSection(Section * sect);
short int GetCoffFlags(const char *s);
void SortSymbolTable(void);
Section *FindSection(TCCState * s1, const char *sname);
int C67_main_entry_point;
int FindCoffSymbolIndex(const char *func_name);
int nb_syms;
typedef struct {
long tag;
long size;
long fileptr;
long nextsym;
short int dummy;
} AUXFUNC;
typedef struct {
long regmask;
unsigned short lineno;
unsigned short nentries;
int localframe;
int nextentry;
short int dummy;
} AUXBF;
typedef struct {
long dummy;
unsigned short lineno;
unsigned short dummy1;
int dummy2;
int dummy3;
unsigned short dummy4;
} AUXEF;
int tcc_output_coff(TCCState *s1, FILE *f)
{
Section *tcc_sect;
SCNHDR *coff_sec;
int file_pointer;
char *Coff_str_table, *pCoff_str_table;
int CoffTextSectionNo, coff_nb_syms;
FILHDR file_hdr; /* FILE HEADER STRUCTURE */
Section *stext, *sdata, *sbss;
int i, NSectionsToOutput = 0;
Coff_str_table = pCoff_str_table = NULL;
stext = FindSection(s1, ".text");
sdata = FindSection(s1, ".data");
sbss = FindSection(s1, ".bss");
nb_syms = symtab_section->data_offset / sizeof(Elf32_Sym);
coff_nb_syms = FindCoffSymbolIndex("XXXXXXXXXX1");
file_hdr.f_magic = COFF_C67_MAGIC; /* magic number */
file_hdr.f_timdat = 0; /* time & date stamp */
file_hdr.f_opthdr = sizeof(AOUTHDR); /* sizeof(optional hdr) */
file_hdr.f_flags = 0x1143; /* flags (copied from what code composer does) */
file_hdr.f_TargetID = 0x99; /* for C6x = 0x0099 */
o_filehdr.magic = 0x0108; /* see magic.h */
o_filehdr.vstamp = 0x0190; /* version stamp */
o_filehdr.tsize = stext->data_offset; /* text size in bytes, padded to FW bdry */
o_filehdr.dsize = sdata->data_offset; /* initialized data " " */
o_filehdr.bsize = sbss->data_offset; /* uninitialized data " " */
o_filehdr.entrypt = C67_main_entry_point; /* entry pt. */
o_filehdr.text_start = stext->sh_addr; /* base of text used for this file */
o_filehdr.data_start = sdata->sh_addr; /* base of data used for this file */
// create all the section headers
file_pointer = FILHSZ + sizeof(AOUTHDR);
CoffTextSectionNo = -1;
for (i = 1; i < s1->nb_sections; i++) {
coff_sec = &section_header[i];
tcc_sect = s1->sections[i];
if (OutputTheSection(tcc_sect)) {
NSectionsToOutput++;
if (CoffTextSectionNo == -1 && tcc_sect == stext)
CoffTextSectionNo = NSectionsToOutput; // rem which coff sect number the .text sect is
strcpy(coff_sec->s_name, tcc_sect->name); /* section name */
coff_sec->s_paddr = tcc_sect->sh_addr; /* physical address */
coff_sec->s_vaddr = tcc_sect->sh_addr; /* virtual address */
coff_sec->s_size = tcc_sect->data_offset; /* section size */
coff_sec->s_scnptr = 0; /* file ptr to raw data for section */
coff_sec->s_relptr = 0; /* file ptr to relocation */
coff_sec->s_lnnoptr = 0; /* file ptr to line numbers */
coff_sec->s_nreloc = 0; /* number of relocation entries */
coff_sec->s_flags = GetCoffFlags(coff_sec->s_name); /* flags */
coff_sec->s_reserved = 0; /* reserved byte */
coff_sec->s_page = 0; /* memory page id */
file_pointer += sizeof(SCNHDR);
}
}
file_hdr.f_nscns = NSectionsToOutput; /* number of sections */
// now loop through and determine file pointer locations
// for the raw data
for (i = 1; i < s1->nb_sections; i++) {
coff_sec = &section_header[i];
tcc_sect = s1->sections[i];
if (OutputTheSection(tcc_sect)) {
// put raw data
coff_sec->s_scnptr = file_pointer; /* file ptr to raw data for section */
file_pointer += coff_sec->s_size;
}
}
// now loop through and determine file pointer locations
// for the relocation data
for (i = 1; i < s1->nb_sections; i++) {
coff_sec = &section_header[i];
tcc_sect = s1->sections[i];
if (OutputTheSection(tcc_sect)) {
// put relocations data
if (coff_sec->s_nreloc > 0) {
coff_sec->s_relptr = file_pointer; /* file ptr to relocation */
file_pointer += coff_sec->s_nreloc * sizeof(struct reloc);
}
}
}
// now loop through and determine file pointer locations
// for the line number data
for (i = 1; i < s1->nb_sections; i++) {
coff_sec = &section_header[i];
tcc_sect = s1->sections[i];
coff_sec->s_nlnno = 0;
coff_sec->s_lnnoptr = 0;
if (s1->do_debug && tcc_sect == stext) {
// count how many line nos data
// also find association between source file name and function
// so we can sort the symbol table
Stab_Sym *sym, *sym_end;
char func_name[MAX_FUNC_NAME_LENGTH],
last_func_name[MAX_FUNC_NAME_LENGTH];
unsigned long func_addr, last_pc, pc;
const char *incl_files[INCLUDE_STACK_SIZE];
int incl_index, len, last_line_num;
const char *str, *p;
coff_sec->s_lnnoptr = file_pointer; /* file ptr to linno */
func_name[0] = '\0';
func_addr = 0;
incl_index = 0;
last_func_name[0] = '\0';
last_pc = 0xffffffff;
last_line_num = 1;
sym = (Stab_Sym *) stab_section->data + 1;
sym_end =
(Stab_Sym *) (stab_section->data +
stab_section->data_offset);
nFuncs = 0;
while (sym < sym_end) {
switch (sym->n_type) {
/* function start or end */
case N_FUN:
if (sym->n_strx == 0) {
// end of function
coff_sec->s_nlnno++;
file_pointer += LINESZ;
pc = sym->n_value + func_addr;
func_name[0] = '\0';
func_addr = 0;
EndAddress[nFuncs] = pc;
FuncEntries[nFuncs] =
(file_pointer -
LineNoFilePtr[nFuncs]) / LINESZ - 1;
LastLineNo[nFuncs++] = last_line_num + 1;
} else {
// beginning of function
LineNoFilePtr[nFuncs] = file_pointer;
coff_sec->s_nlnno++;
file_pointer += LINESZ;
str =
(const char *) stabstr_section->data +
sym->n_strx;
p = strchr(str, ':');
if (!p) {
pstrcpy(func_name, sizeof(func_name), str);
pstrcpy(Func[nFuncs], sizeof(func_name), str);
} else {
len = p - str;
if (len > sizeof(func_name) - 1)
len = sizeof(func_name) - 1;
memcpy(func_name, str, len);
memcpy(Func[nFuncs], str, len);
func_name[len] = '\0';
}
// save the file that it came in so we can sort later
pstrcpy(AssociatedFile[nFuncs], sizeof(func_name),
incl_files[incl_index - 1]);
func_addr = sym->n_value;
}
break;
/* line number info */
case N_SLINE:
pc = sym->n_value + func_addr;
last_pc = pc;
last_line_num = sym->n_desc;
/* XXX: slow! */
strcpy(last_func_name, func_name);
coff_sec->s_nlnno++;
file_pointer += LINESZ;
break;
/* include files */
case N_BINCL:
str =
(const char *) stabstr_section->data + sym->n_strx;
add_incl:
if (incl_index < INCLUDE_STACK_SIZE) {
incl_files[incl_index++] = str;
}
break;
case N_EINCL:
if (incl_index > 1)
incl_index--;
break;
case N_SO:
if (sym->n_strx == 0) {
incl_index = 0; /* end of translation unit */
} else {
str =
(const char *) stabstr_section->data +
sym->n_strx;
/* do not add path */
len = strlen(str);
if (len > 0 && str[len - 1] != '/')
goto add_incl;
}
break;
}
sym++;
}
}
}
file_hdr.f_symptr = file_pointer; /* file pointer to symtab */
if (s1->do_debug)
file_hdr.f_nsyms = coff_nb_syms; /* number of symtab entries */
else
file_hdr.f_nsyms = 0;
file_pointer += file_hdr.f_nsyms * SYMNMLEN;
// OK now we are all set to write the file
fwrite(&file_hdr, FILHSZ, 1, f);
fwrite(&o_filehdr, sizeof(o_filehdr), 1, f);
// write section headers
for (i = 1; i < s1->nb_sections; i++) {
coff_sec = &section_header[i];
tcc_sect = s1->sections[i];
if (OutputTheSection(tcc_sect)) {
fwrite(coff_sec, sizeof(SCNHDR), 1, f);
}
}
// write raw data
for (i = 1; i < s1->nb_sections; i++) {
coff_sec = &section_header[i];
tcc_sect = s1->sections[i];
if (OutputTheSection(tcc_sect)) {
fwrite(tcc_sect->data, tcc_sect->data_offset, 1, f);
}
}
// write relocation data
for (i = 1; i < s1->nb_sections; i++) {
coff_sec = &section_header[i];
tcc_sect = s1->sections[i];
if (OutputTheSection(tcc_sect)) {
// put relocations data
if (coff_sec->s_nreloc > 0) {
fwrite(tcc_sect->reloc,
coff_sec->s_nreloc * sizeof(struct reloc), 1, f);
}
}
}
// group the symbols in order of filename, func1, func2, etc
// finally global symbols
if (s1->do_debug)
SortSymbolTable();
// write line no data
for (i = 1; i < s1->nb_sections; i++) {
coff_sec = &section_header[i];
tcc_sect = s1->sections[i];
if (s1->do_debug && tcc_sect == stext) {
// count how many line nos data
Stab_Sym *sym, *sym_end;
char func_name[128], last_func_name[128];
unsigned long func_addr, last_pc, pc;
const char *incl_files[INCLUDE_STACK_SIZE];
int incl_index, len, last_line_num;
const char *str, *p;
LINENO CoffLineNo;
func_name[0] = '\0';
func_addr = 0;
incl_index = 0;
last_func_name[0] = '\0';
last_pc = 0;
last_line_num = 1;
sym = (Stab_Sym *) stab_section->data + 1;
sym_end =
(Stab_Sym *) (stab_section->data +
stab_section->data_offset);
while (sym < sym_end) {
switch (sym->n_type) {
/* function start or end */
case N_FUN:
if (sym->n_strx == 0) {
// end of function
CoffLineNo.l_addr.l_paddr = last_pc;
CoffLineNo.l_lnno = last_line_num + 1;
fwrite(&CoffLineNo, 6, 1, f);
pc = sym->n_value + func_addr;
func_name[0] = '\0';
func_addr = 0;
} else {
// beginning of function
str =
(const char *) stabstr_section->data +
sym->n_strx;
p = strchr(str, ':');
if (!p) {
pstrcpy(func_name, sizeof(func_name), str);
} else {
len = p - str;
if (len > sizeof(func_name) - 1)
len = sizeof(func_name) - 1;
memcpy(func_name, str, len);
func_name[len] = '\0';
}
func_addr = sym->n_value;
last_pc = func_addr;
last_line_num = -1;
// output a function begin
CoffLineNo.l_addr.l_symndx =
FindCoffSymbolIndex(func_name);
CoffLineNo.l_lnno = 0;
fwrite(&CoffLineNo, 6, 1, f);
}
break;
/* line number info */
case N_SLINE:
pc = sym->n_value + func_addr;
/* XXX: slow! */
strcpy(last_func_name, func_name);
// output a line reference
CoffLineNo.l_addr.l_paddr = last_pc;
if (last_line_num == -1) {
CoffLineNo.l_lnno = sym->n_desc;
} else {
CoffLineNo.l_lnno = last_line_num + 1;
}
fwrite(&CoffLineNo, 6, 1, f);
last_pc = pc;
last_line_num = sym->n_desc;
break;
/* include files */
case N_BINCL:
str =
(const char *) stabstr_section->data + sym->n_strx;
add_incl2:
if (incl_index < INCLUDE_STACK_SIZE) {
incl_files[incl_index++] = str;
}
break;
case N_EINCL:
if (incl_index > 1)
incl_index--;
break;
case N_SO:
if (sym->n_strx == 0) {
incl_index = 0; /* end of translation unit */
} else {
str =
(const char *) stabstr_section->data +
sym->n_strx;
/* do not add path */
len = strlen(str);
if (len > 0 && str[len - 1] != '/')
goto add_incl2;
}
break;
}
sym++;
}
}
}
// write symbol table
if (s1->do_debug) {
int k;
struct syment csym;
AUXFUNC auxfunc;
AUXBF auxbf;
AUXEF auxef;
int i;
Elf32_Sym *p;
const char *name;
int nstr;
int n = 0;
Coff_str_table = (char *) tcc_malloc(MAX_STR_TABLE);
pCoff_str_table = Coff_str_table;
nstr = 0;
p = (Elf32_Sym *) symtab_section->data;
for (i = 0; i < nb_syms; i++) {
name = symtab_section->link->data + p->st_name;
for (k = 0; k < 8; k++)
csym._n._n_name[k] = 0;
if (strlen(name) <= 8) {
strcpy(csym._n._n_name, name);
} else {
if (pCoff_str_table - Coff_str_table + strlen(name) >
MAX_STR_TABLE - 1)
error("String table too large");
csym._n._n_n._n_zeroes = 0;
csym._n._n_n._n_offset =
pCoff_str_table - Coff_str_table + 4;
strcpy(pCoff_str_table, name);
pCoff_str_table += strlen(name) + 1; // skip over null
nstr++;
}
if (p->st_info == 4) {
// put a filename symbol
csym.n_value = 33; // ?????
csym.n_scnum = N_DEBUG;
csym.n_type = 0;
csym.n_sclass = C_FILE;
csym.n_numaux = 0;
fwrite(&csym, 18, 1, f);
n++;
} else if (p->st_info == 0x12) {
// find the function data
for (k = 0; k < nFuncs; k++) {
if (strcmp(name, Func[k]) == 0)
break;
}
if (k >= nFuncs) {
char s[256];
sprintf(s, "debug info can't find function: %s", name);
error(s);
}
// put a Function Name
csym.n_value = p->st_value; // physical address
csym.n_scnum = CoffTextSectionNo;
csym.n_type = MKTYPE(T_INT, DT_FCN, 0, 0, 0, 0, 0);
csym.n_sclass = C_EXT;
csym.n_numaux = 1;
fwrite(&csym, 18, 1, f);
// now put aux info
auxfunc.tag = 0;
auxfunc.size = EndAddress[k] - p->st_value;
auxfunc.fileptr = LineNoFilePtr[k];
auxfunc.nextsym = n + 6; // tktk
auxfunc.dummy = 0;
fwrite(&auxfunc, 18, 1, f);
// put a .bf
strcpy(csym._n._n_name, ".bf");
csym.n_value = p->st_value; // physical address
csym.n_scnum = CoffTextSectionNo;
csym.n_type = 0;
csym.n_sclass = C_FCN;
csym.n_numaux = 1;
fwrite(&csym, 18, 1, f);
// now put aux info
auxbf.regmask = 0;
auxbf.lineno = 0;
auxbf.nentries = FuncEntries[k];
auxbf.localframe = 0;
auxbf.nextentry = n + 6;
auxbf.dummy = 0;
fwrite(&auxbf, 18, 1, f);
// put a .ef
strcpy(csym._n._n_name, ".ef");
csym.n_value = EndAddress[k]; // physical address
csym.n_scnum = CoffTextSectionNo;
csym.n_type = 0;
csym.n_sclass = C_FCN;
csym.n_numaux = 1;
fwrite(&csym, 18, 1, f);
// now put aux info
auxef.dummy = 0;
auxef.lineno = LastLineNo[k];
auxef.dummy1 = 0;
auxef.dummy2 = 0;
auxef.dummy3 = 0;
auxef.dummy4 = 0;
fwrite(&auxef, 18, 1, f);
n += 6;
} else {
// try an put some type info
if ((p->st_other & VT_BTYPE) == VT_DOUBLE) {
csym.n_type = T_DOUBLE; // int
csym.n_sclass = C_EXT;
} else if ((p->st_other & VT_BTYPE) == VT_FLOAT) {
csym.n_type = T_FLOAT;
csym.n_sclass = C_EXT;
} else if ((p->st_other & VT_BTYPE) == VT_INT) {
csym.n_type = T_INT; // int
csym.n_sclass = C_EXT;
} else if ((p->st_other & VT_BTYPE) == VT_SHORT) {
csym.n_type = T_SHORT;
csym.n_sclass = C_EXT;
} else if ((p->st_other & VT_BTYPE) == VT_BYTE) {
csym.n_type = T_CHAR;
csym.n_sclass = C_EXT;
} else {
csym.n_type = T_INT; // just mark as a label
csym.n_sclass = C_LABEL;
}
csym.n_value = p->st_value;
csym.n_scnum = 2;
csym.n_numaux = 1;
fwrite(&csym, 18, 1, f);
auxfunc.tag = 0;
auxfunc.size = 0x20;
auxfunc.fileptr = 0;
auxfunc.nextsym = 0;
auxfunc.dummy = 0;
fwrite(&auxfunc, 18, 1, f);
n++;
n++;
}
p++;
}
}
if (s1->do_debug) {
// write string table
// first write the size
i = pCoff_str_table - Coff_str_table;
fwrite(&i, 4, 1, f);
// then write the strings
fwrite(Coff_str_table, i, 1, f);
tcc_free(Coff_str_table);
}
return 0;
}
// group the symbols in order of filename, func1, func2, etc
// finally global symbols
void SortSymbolTable(void)
{
int i, j, k, n = 0;
Elf32_Sym *p, *p2, *NewTable;
char *name, *name2;
NewTable = (Elf32_Sym *) tcc_malloc(nb_syms * sizeof(Elf32_Sym));
p = (Elf32_Sym *) symtab_section->data;
// find a file symbol, copy it over
// then scan the whole symbol list and copy any function
// symbols that match the file association
for (i = 0; i < nb_syms; i++) {
if (p->st_info == 4) {
name = (char *) symtab_section->link->data + p->st_name;
// this is a file symbol, copy it over
NewTable[n++] = *p;
p2 = (Elf32_Sym *) symtab_section->data;
for (j = 0; j < nb_syms; j++) {
if (p2->st_info == 0x12) {
// this is a func symbol
name2 =
(char *) symtab_section->link->data + p2->st_name;
// find the function data index
for (k = 0; k < nFuncs; k++) {
if (strcmp(name2, Func[k]) == 0)
break;
}
if (k >= nFuncs) {
char s[256];
sprintf(s,
"debug (sort) info can't find function: %s",
name2);
error(s);
}
if (strcmp(AssociatedFile[k], name) == 0) {
// yes they match copy it over
NewTable[n++] = *p2;
}
}
p2++;
}
}
p++;
}
// now all the filename and func symbols should have been copied over
// copy all the rest over (all except file and funcs)
p = (Elf32_Sym *) symtab_section->data;
for (i = 0; i < nb_syms; i++) {
if (p->st_info != 4 && p->st_info != 0x12) {
NewTable[n++] = *p;
}
p++;
}
if (n != nb_syms)
error("Internal Compiler error, debug info");
// copy it all back
p = (Elf32_Sym *) symtab_section->data;
for (i = 0; i < nb_syms; i++) {
*p++ = NewTable[i];
}
tcc_free(NewTable);
}
int FindCoffSymbolIndex(const char *func_name)
{
int i, n = 0;
Elf32_Sym *p;
char *name;
p = (Elf32_Sym *) symtab_section->data;
for (i = 0; i < nb_syms; i++) {
name = (char *) symtab_section->link->data + p->st_name;
if (p->st_info == 4) {
// put a filename symbol
n++;
} else if (p->st_info == 0x12) {
if (strcmp(func_name, name) == 0)
return n;
n += 6;
// put a Function Name
// now put aux info
// put a .bf
// now put aux info
// put a .ef
// now put aux info
} else {
n += 2;
}
p++;
}
return n; // total number of symbols
}
BOOL OutputTheSection(Section * sect)
{
const char *s = sect->name;
if (!strcmp(s, ".text"))
return true;
else if (!strcmp(s, ".data"))
return true;
else
return 0;
}
short int GetCoffFlags(const char *s)
{
if (!strcmp(s, ".text"))
return STYP_TEXT | STYP_DATA | STYP_ALIGN | 0x400;
else if (!strcmp(s, ".data"))
return STYP_DATA;
else if (!strcmp(s, ".bss"))
return STYP_BSS;
else if (!strcmp(s, ".stack"))
return STYP_BSS | STYP_ALIGN | 0x200;
else if (!strcmp(s, ".cinit"))
return STYP_COPY | STYP_DATA | STYP_ALIGN | 0x200;
else
return 0;
}
Section *FindSection(TCCState * s1, const char *sname)
{
Section *s;
int i;
for (i = 1; i < s1->nb_sections; i++) {
s = s1->sections[i];
if (!strcmp(sname, s->name))
return s;
}
error("could not find section %s", sname);
return 0;
}
int tcc_load_coff(TCCState * s1, int fd)
{
// tktk TokenSym *ts;
FILE *f;
unsigned int str_size;
char *Coff_str_table, *name;
int i, k;
struct syment csym;
char name2[9];
FILHDR file_hdr; /* FILE HEADER STRUCTURE */
f = fdopen(fd, "rb");
if (!f) {
error("Unable to open .out file for input");
}
if (fread(&file_hdr, FILHSZ, 1, f) != 1)
error("error reading .out file for input");
if (fread(&o_filehdr, sizeof(o_filehdr), 1, f) != 1)
error("error reading .out file for input");
// first read the string table
if (fseek(f, file_hdr.f_symptr + file_hdr.f_nsyms * SYMESZ, SEEK_SET))
error("error reading .out file for input");
if (fread(&str_size, sizeof(int), 1, f) != 1)
error("error reading .out file for input");
Coff_str_table = (char *) tcc_malloc(str_size);
if (fread(Coff_str_table, str_size - 4, 1, f) != 1)
error("error reading .out file for input");
// read/process all the symbols
// seek back to symbols
if (fseek(f, file_hdr.f_symptr, SEEK_SET))
error("error reading .out file for input");
for (i = 0; i < file_hdr.f_nsyms; i++) {
if (fread(&csym, SYMESZ, 1, f) != 1)
error("error reading .out file for input");
if (csym._n._n_n._n_zeroes == 0) {
name = Coff_str_table + csym._n._n_n._n_offset - 4;
} else {
name = csym._n._n_name;
if (name[7] != 0) {
for (k = 0; k < 8; k++)
name2[k] = name[k];
name2[8] = 0;
name = name2;
}
}
// if (strcmp("_DAC_Buffer",name)==0) // tktk
// name[0]=0;
if (((csym.n_type & 0x30) == 0x20 && csym.n_sclass == 0x2) || ((csym.n_type & 0x30) == 0x30 && csym.n_sclass == 0x2) || (csym.n_type == 0x4 && csym.n_sclass == 0x2) || (csym.n_type == 0x8 && csym.n_sclass == 0x2) || // structures
(csym.n_type == 0x18 && csym.n_sclass == 0x2) || // pointer to structure
(csym.n_type == 0x7 && csym.n_sclass == 0x2) || // doubles
(csym.n_type == 0x6 && csym.n_sclass == 0x2)) // floats
{
// strip off any leading underscore (except for other main routine)
if (name[0] == '_' && strcmp(name, "_main") != 0)
name++;
tcc_add_symbol(s1, name, (void*)csym.n_value);
}
// skip any aux records
if (csym.n_numaux == 1) {
if (fread(&csym, SYMESZ, 1, f) != 1)
error("error reading .out file for input");
i++;
}
}
return 0;
}
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
-469
View File
@@ -1,469 +0,0 @@
/* keywords */
DEF(TOK_INT, "int")
DEF(TOK_VOID, "void")
DEF(TOK_CHAR, "char")
DEF(TOK_IF, "if")
DEF(TOK_ELSE, "else")
DEF(TOK_WHILE, "while")
DEF(TOK_BREAK, "break")
DEF(TOK_RETURN, "return")
DEF(TOK_FOR, "for")
DEF(TOK_EXTERN, "extern")
DEF(TOK_STATIC, "static")
DEF(TOK_UNSIGNED, "unsigned")
DEF(TOK_GOTO, "goto")
DEF(TOK_DO, "do")
DEF(TOK_CONTINUE, "continue")
DEF(TOK_SWITCH, "switch")
DEF(TOK_CASE, "case")
DEF(TOK_CONST1, "const")
DEF(TOK_CONST2, "__const") /* gcc keyword */
DEF(TOK_CONST3, "__const__") /* gcc keyword */
DEF(TOK_VOLATILE1, "volatile")
DEF(TOK_VOLATILE2, "__volatile") /* gcc keyword */
DEF(TOK_VOLATILE3, "__volatile__") /* gcc keyword */
DEF(TOK_LONG, "long")
DEF(TOK_REGISTER, "register")
DEF(TOK_SIGNED1, "signed")
DEF(TOK_SIGNED2, "__signed") /* gcc keyword */
DEF(TOK_SIGNED3, "__signed__") /* gcc keyword */
DEF(TOK_AUTO, "auto")
DEF(TOK_INLINE1, "inline")
DEF(TOK_INLINE2, "__inline") /* gcc keyword */
DEF(TOK_INLINE3, "__inline__") /* gcc keyword */
DEF(TOK_RESTRICT1, "restrict")
DEF(TOK_RESTRICT2, "__restrict")
DEF(TOK_RESTRICT3, "__restrict__")
DEF(TOK_EXTENSION, "__extension__") /* gcc keyword */
DEF(TOK_FLOAT, "float")
DEF(TOK_DOUBLE, "double")
DEF(TOK_BOOL, "_Bool")
DEF(TOK_SHORT, "short")
DEF(TOK_STRUCT, "struct")
DEF(TOK_UNION, "union")
DEF(TOK_TYPEDEF, "typedef")
DEF(TOK_DEFAULT, "default")
DEF(TOK_ENUM, "enum")
DEF(TOK_SIZEOF, "sizeof")
DEF(TOK_ATTRIBUTE1, "__attribute")
DEF(TOK_ATTRIBUTE2, "__attribute__")
DEF(TOK_ALIGNOF1, "__alignof")
DEF(TOK_ALIGNOF2, "__alignof__")
DEF(TOK_TYPEOF1, "typeof")
DEF(TOK_TYPEOF2, "__typeof")
DEF(TOK_TYPEOF3, "__typeof__")
DEF(TOK_LABEL, "__label__")
DEF(TOK_ASM1, "asm")
DEF(TOK_ASM2, "__asm")
DEF(TOK_ASM3, "__asm__")
/*********************************************************************/
/* the following are not keywords. They are included to ease parsing */
/* preprocessor only */
DEF(TOK_DEFINE, "define")
DEF(TOK_INCLUDE, "include")
DEF(TOK_INCLUDE_NEXT, "include_next")
DEF(TOK_IFDEF, "ifdef")
DEF(TOK_IFNDEF, "ifndef")
DEF(TOK_ELIF, "elif")
DEF(TOK_ENDIF, "endif")
DEF(TOK_DEFINED, "defined")
DEF(TOK_UNDEF, "undef")
DEF(TOK_ERROR, "error")
DEF(TOK_WARNING, "warning")
DEF(TOK_LINE, "line")
DEF(TOK_PRAGMA, "pragma")
DEF(TOK___LINE__, "__LINE__")
DEF(TOK___FILE__, "__FILE__")
DEF(TOK___DATE__, "__DATE__")
DEF(TOK___TIME__, "__TIME__")
DEF(TOK___FUNCTION__, "__FUNCTION__")
DEF(TOK___VA_ARGS__, "__VA_ARGS__")
/* special identifiers */
DEF(TOK___FUNC__, "__func__")
/* attribute identifiers */
/* XXX: handle all tokens generically since speed is not critical */
DEF(TOK_SECTION1, "section")
DEF(TOK_SECTION2, "__section__")
DEF(TOK_ALIGNED1, "aligned")
DEF(TOK_ALIGNED2, "__aligned__")
DEF(TOK_PACKED1, "packed")
DEF(TOK_PACKED2, "__packed__")
DEF(TOK_UNUSED1, "unused")
DEF(TOK_UNUSED2, "__unused__")
DEF(TOK_CDECL1, "cdecl")
DEF(TOK_CDECL2, "__cdecl")
DEF(TOK_CDECL3, "__cdecl__")
DEF(TOK_STDCALL1, "stdcall")
DEF(TOK_STDCALL2, "__stdcall")
DEF(TOK_STDCALL3, "__stdcall__")
DEF(TOK_FASTCALL1, "fastcall")
DEF(TOK_FASTCALL2, "__fastcall")
DEF(TOK_FASTCALL3, "__fastcall__")
DEF(TOK_DLLEXPORT, "dllexport")
DEF(TOK_NORETURN1, "noreturn")
DEF(TOK_NORETURN2, "__noreturn__")
DEF(TOK_builtin_types_compatible_p, "__builtin_types_compatible_p")
DEF(TOK_builtin_constant_p, "__builtin_constant_p")
DEF(TOK_builtin_frame_address, "__builtin_frame_address")
#ifdef TCC_TARGET_X86_64
DEF(TOK_builtin_malloc, "__builtin_malloc")
DEF(TOK_builtin_free, "__builtin_free")
DEF(TOK_malloc, "malloc")
DEF(TOK_free, "free")
#endif
DEF(TOK_REGPARM1, "regparm")
DEF(TOK_REGPARM2, "__regparm__")
/* pragma */
DEF(TOK_pack, "pack")
#if !defined(TCC_TARGET_I386)
/* already defined for assembler */
DEF(TOK_ASM_push, "push")
DEF(TOK_ASM_pop, "pop")
#endif
/* builtin functions or variables */
#ifdef TCC_ARM_EABI
DEF(TOK_memcpy, "__aeabi_memcpy")
DEF(TOK_memcpy4, "__aeabi_memcpy4")
DEF(TOK_memcpy8, "__aeabi_memcpy8")
DEF(TOK_memset, "__aeabi_memset")
DEF(TOK___aeabi_ldivmod, "__aeabi_ldivmod")
DEF(TOK___aeabi_uldivmod, "__aeabi_uldivmod")
#else
DEF(TOK_memcpy, "memcpy")
DEF(TOK_memset, "memset")
DEF(TOK___divdi3, "__divdi3")
DEF(TOK___moddi3, "__moddi3")
DEF(TOK___udivdi3, "__udivdi3")
DEF(TOK___umoddi3, "__umoddi3")
#endif
#if defined(TCC_TARGET_ARM)
#ifdef TCC_ARM_EABI
DEF(TOK___aeabi_idivmod, "__aeabi_idivmod")
DEF(TOK___aeabi_uidivmod, "__aeabi_uidivmod")
DEF(TOK___divsi3, "__aeabi_idiv")
DEF(TOK___udivsi3, "__aeabi_uidiv")
DEF(TOK___floatdisf, "__aeabi_l2f")
DEF(TOK___floatdidf, "__aeabi_l2d")
DEF(TOK___fixsfdi, "__aeabi_f2lz")
DEF(TOK___fixdfdi, "__aeabi_d2lz")
#else
DEF(TOK___modsi3, "__modsi3")
DEF(TOK___umodsi3, "__umodsi3")
DEF(TOK___divsi3, "__divsi3")
DEF(TOK___udivsi3, "__udivsi3")
DEF(TOK___floatdisf, "__floatdisf")
DEF(TOK___floatdidf, "__floatdidf")
#ifndef TCC_ARM_VFP
DEF(TOK___floatdixf, "__floatdixf")
DEF(TOK___fixunssfsi, "__fixunssfsi")
DEF(TOK___fixunsdfsi, "__fixunsdfsi")
DEF(TOK___fixunsxfsi, "__fixunsxfsi")
DEF(TOK___fixxfdi, "__fixxfdi")
#endif
DEF(TOK___fixsfdi, "__fixsfdi")
DEF(TOK___fixdfdi, "__fixdfdi")
#endif
#elif defined(TCC_TARGET_C67)
DEF(TOK__divi, "_divi")
DEF(TOK__divu, "_divu")
DEF(TOK__divf, "_divf")
DEF(TOK__divd, "_divd")
DEF(TOK__remi, "_remi")
DEF(TOK__remu, "_remu")
#endif
#ifdef TCC_TARGET_I386
DEF(TOK___tcc_int_fpu_control, "__tcc_int_fpu_control")
DEF(TOK___tcc_fpu_control, "__tcc_fpu_control")
#endif
#ifdef TCC_ARM_EABI
DEF(TOK___ashrdi3, "__aeabi_lasr")
DEF(TOK___lshrdi3, "__aeabi_llsr")
DEF(TOK___ashldi3, "__aeabi_llsl")
DEF(TOK___floatundisf, "__aeabi_ul2f")
DEF(TOK___floatundidf, "__aeabi_ul2d")
DEF(TOK___fixunssfdi, "__aeabi_f2ulz")
DEF(TOK___fixunsdfdi, "__aeabi_d2ulz")
#else
DEF(TOK___ashrdi3, "__ashrdi3")
DEF(TOK___lshrdi3, "__lshrdi3")
DEF(TOK___ashldi3, "__ashldi3")
DEF(TOK___floatundisf, "__floatundisf")
DEF(TOK___floatundidf, "__floatundidf")
#ifndef TCC_ARM_VFP
DEF(TOK___floatundixf, "__floatundixf")
DEF(TOK___fixunsxfdi, "__fixunsxfdi")
#endif
DEF(TOK___fixunssfdi, "__fixunssfdi")
DEF(TOK___fixunsdfdi, "__fixunsdfdi")
#endif
#ifdef TCC_TARGET_PE
DEF(TOK___chkstk, "__chkstk")
#endif
/* bound checking symbols */
#ifdef CONFIG_TCC_BCHECK
DEF(TOK___bound_ptr_add, "__bound_ptr_add")
DEF(TOK___bound_ptr_indir1, "__bound_ptr_indir1")
DEF(TOK___bound_ptr_indir2, "__bound_ptr_indir2")
DEF(TOK___bound_ptr_indir4, "__bound_ptr_indir4")
DEF(TOK___bound_ptr_indir8, "__bound_ptr_indir8")
DEF(TOK___bound_ptr_indir12, "__bound_ptr_indir12")
DEF(TOK___bound_ptr_indir16, "__bound_ptr_indir16")
DEF(TOK___bound_local_new, "__bound_local_new")
DEF(TOK___bound_local_delete, "__bound_local_delete")
#if 0
DEF(TOK_malloc, "malloc")
DEF(TOK_free, "free")
DEF(TOK_realloc, "realloc")
DEF(TOK_memalign, "memalign")
DEF(TOK_calloc, "calloc")
#endif
DEF(TOK_memmove, "memmove")
DEF(TOK_strlen, "strlen")
DEF(TOK_strcpy, "strcpy")
DEF(TOK_alloca, "alloca")
#endif
/* Tiny Assembler */
DEF_ASM(byte)
DEF_ASM(align)
DEF_ASM(skip)
DEF_ASM(space)
DEF_ASM(string)
DEF_ASM(asciz)
DEF_ASM(ascii)
DEF_ASM(globl)
DEF_ASM(global)
DEF_ASM(text)
DEF_ASM(data)
DEF_ASM(bss)
DEF_ASM(previous)
DEF_ASM(fill)
DEF_ASM(org)
DEF_ASM(quad)
#ifdef TCC_TARGET_I386
/* WARNING: relative order of tokens is important. */
DEF_ASM(al)
DEF_ASM(cl)
DEF_ASM(dl)
DEF_ASM(bl)
DEF_ASM(ah)
DEF_ASM(ch)
DEF_ASM(dh)
DEF_ASM(bh)
DEF_ASM(ax)
DEF_ASM(cx)
DEF_ASM(dx)
DEF_ASM(bx)
DEF_ASM(sp)
DEF_ASM(bp)
DEF_ASM(si)
DEF_ASM(di)
DEF_ASM(eax)
DEF_ASM(ecx)
DEF_ASM(edx)
DEF_ASM(ebx)
DEF_ASM(esp)
DEF_ASM(ebp)
DEF_ASM(esi)
DEF_ASM(edi)
DEF_ASM(mm0)
DEF_ASM(mm1)
DEF_ASM(mm2)
DEF_ASM(mm3)
DEF_ASM(mm4)
DEF_ASM(mm5)
DEF_ASM(mm6)
DEF_ASM(mm7)
DEF_ASM(xmm0)
DEF_ASM(xmm1)
DEF_ASM(xmm2)
DEF_ASM(xmm3)
DEF_ASM(xmm4)
DEF_ASM(xmm5)
DEF_ASM(xmm6)
DEF_ASM(xmm7)
DEF_ASM(cr0)
DEF_ASM(cr1)
DEF_ASM(cr2)
DEF_ASM(cr3)
DEF_ASM(cr4)
DEF_ASM(cr5)
DEF_ASM(cr6)
DEF_ASM(cr7)
DEF_ASM(tr0)
DEF_ASM(tr1)
DEF_ASM(tr2)
DEF_ASM(tr3)
DEF_ASM(tr4)
DEF_ASM(tr5)
DEF_ASM(tr6)
DEF_ASM(tr7)
DEF_ASM(db0)
DEF_ASM(db1)
DEF_ASM(db2)
DEF_ASM(db3)
DEF_ASM(db4)
DEF_ASM(db5)
DEF_ASM(db6)
DEF_ASM(db7)
DEF_ASM(dr0)
DEF_ASM(dr1)
DEF_ASM(dr2)
DEF_ASM(dr3)
DEF_ASM(dr4)
DEF_ASM(dr5)
DEF_ASM(dr6)
DEF_ASM(dr7)
DEF_ASM(es)
DEF_ASM(cs)
DEF_ASM(ss)
DEF_ASM(ds)
DEF_ASM(fs)
DEF_ASM(gs)
DEF_ASM(st)
DEF_BWL(mov)
/* generic two operands */
DEF_BWL(add)
DEF_BWL(or)
DEF_BWL(adc)
DEF_BWL(sbb)
DEF_BWL(and)
DEF_BWL(sub)
DEF_BWL(xor)
DEF_BWL(cmp)
/* unary ops */
DEF_BWL(inc)
DEF_BWL(dec)
DEF_BWL(not)
DEF_BWL(neg)
DEF_BWL(mul)
DEF_BWL(imul)
DEF_BWL(div)
DEF_BWL(idiv)
DEF_BWL(xchg)
DEF_BWL(test)
/* shifts */
DEF_BWL(rol)
DEF_BWL(ror)
DEF_BWL(rcl)
DEF_BWL(rcr)
DEF_BWL(shl)
DEF_BWL(shr)
DEF_BWL(sar)
DEF_ASM(shldw)
DEF_ASM(shldl)
DEF_ASM(shld)
DEF_ASM(shrdw)
DEF_ASM(shrdl)
DEF_ASM(shrd)
DEF_ASM(pushw)
DEF_ASM(pushl)
DEF_ASM(push)
DEF_ASM(popw)
DEF_ASM(popl)
DEF_ASM(pop)
DEF_BWL(in)
DEF_BWL(out)
DEF_WL(movzb)
DEF_ASM(movzwl)
DEF_ASM(movsbw)
DEF_ASM(movsbl)
DEF_ASM(movswl)
DEF_WL(lea)
DEF_ASM(les)
DEF_ASM(lds)
DEF_ASM(lss)
DEF_ASM(lfs)
DEF_ASM(lgs)
DEF_ASM(call)
DEF_ASM(jmp)
DEF_ASM(lcall)
DEF_ASM(ljmp)
DEF_ASMTEST(j)
DEF_ASMTEST(set)
DEF_ASMTEST(cmov)
DEF_WL(bsf)
DEF_WL(bsr)
DEF_WL(bt)
DEF_WL(bts)
DEF_WL(btr)
DEF_WL(btc)
DEF_WL(lsl)
/* generic FP ops */
DEF_FP(add)
DEF_FP(mul)
DEF_ASM(fcom)
DEF_ASM(fcom_1) /* non existant op, just to have a regular table */
DEF_FP1(com)
DEF_FP(comp)
DEF_FP(sub)
DEF_FP(subr)
DEF_FP(div)
DEF_FP(divr)
DEF_BWL(xadd)
DEF_BWL(cmpxchg)
/* string ops */
DEF_BWL(cmps)
DEF_BWL(scmp)
DEF_BWL(ins)
DEF_BWL(outs)
DEF_BWL(lods)
DEF_BWL(slod)
DEF_BWL(movs)
DEF_BWL(smov)
DEF_BWL(scas)
DEF_BWL(ssca)
DEF_BWL(stos)
DEF_BWL(ssto)
/* generic asm ops */
#define ALT(x)
#define DEF_ASM_OP0(name, opcode) DEF_ASM(name)
#define DEF_ASM_OP0L(name, opcode, group, instr_type)
#define DEF_ASM_OP1(name, opcode, group, instr_type, op0)
#define DEF_ASM_OP2(name, opcode, group, instr_type, op0, op1)
#define DEF_ASM_OP3(name, opcode, group, instr_type, op0, op1, op2)
#include "i386-asm.h"
#define ALT(x)
#define DEF_ASM_OP0(name, opcode)
#define DEF_ASM_OP0L(name, opcode, group, instr_type) DEF_ASM(name)
#define DEF_ASM_OP1(name, opcode, group, instr_type, op0) DEF_ASM(name)
#define DEF_ASM_OP2(name, opcode, group, instr_type, op0, op1) DEF_ASM(name)
#define DEF_ASM_OP3(name, opcode, group, instr_type, op0, op1, op2) DEF_ASM(name)
#include "i386-asm.h"
#endif
File diff suppressed because it is too large Load Diff
-153
View File
@@ -1,153 +0,0 @@
/**
* Copyright (c) 2006-2009 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
**/
// LOVE
#include "wrap_Native.h"
#include <filesystem/File.h>
#include <cstring>
namespace love
{
namespace native
{
namespace tcc
{
static Native * instance = 0;
int w_compile(lua_State * L)
{
int argn = lua_gettop(L);
// We need argn strings.
char ** strs = new char*[argn];
for(int i = 1; i<=argn; i++)
{
// Convert to File, if necessary.
if(lua_isstring(L, 1))
luax_convobj(L, 1, "filesystem", "newFile");
filesystem::File * file = luax_checktype<filesystem::File>(L, 1, "File", FILESYSTEM_FILE_T);
int size = file->getSize();
// Allocate some new data. Need an extra char for the
// trailing 0.
char * str = new char[size+1];
str[size] = 0;
file->read((void*)str, size);
// Put it in the list of strings.
strs[i-1] = str;
}
bool r = instance->compile((const char **)strs, argn);
luax_pushboolean(L, r);
// Cleanup.
for(int i = 0; i<argn; i++)
delete strs[i];
delete [] strs;
return 1;
}
int w_getSymbol(lua_State * L)
{
const char * sym = luaL_checkstring(L, 1);
void * ptr = instance->getSymbol(sym);
lua_CFunction fn = (lua_CFunction)ptr;
if(fn == 0)
lua_pushnil(L);
else
lua_pushcfunction(L, fn);
return 1;
}
/**
* Searcher function for modules compiled with love.native.
**/
static int searcher(lua_State * L)
{
const char * src = lua_tostring(L, 1);
int length = strlen(src);
// luaopen_ needs 8 chars.
char * dst = new char[length+8+1];
memcpy(dst, "luaopen_", 8);
for(int i = 0; i<=length; i++)
dst[i+8] = (src[i] == '.') ? '_' : src[i];
void * sym = instance->getSymbol(dst);
if(sym == 0)
lua_pushfstring(L, "\tno symbol \"%s\" in love.native.\n", dst);
else
lua_pushcfunction(L, (lua_CFunction)sym);
delete [] dst;
return 1;
}
// List of functions to wrap.
static const luaL_Reg functions[] = {
{ "compile", w_compile },
{ "getSymbol", w_getSymbol },
{ 0, 0 }
};
int luaopen_love_native(lua_State * L)
{
if(instance == 0)
{
try
{
instance = new Native();
}
catch(Exception & e)
{
return luaL_error(L, e.what());
}
}
luax_register_searcher(L, searcher);
WrappedModule w;
w.module = instance;
w.name = "native";
w.flags = MODULE_T;
w.functions = functions;
w.types = 0;
w.constants = 0;
return luax_register_module(L, w);
}
} // tcc
} // native
} // love
@@ -18,23 +18,37 @@
* 3. This notice may not be removed or altered from any source distribution.
**/
#ifndef LOVE_NATIVE_TCC_API_H
#define LOVE_NATIVE_TCC_API_H
#include "Joint.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct tcc_function_
{
const char * name;
void * fn;
} tcc_function;
extern const tcc_function tcc_api[];
#ifdef __cplusplus
}
#endif
#endif /* LOVE_NATIVE_TCC_API_H */
namespace love
{
namespace physics
{
Joint::~Joint()
{
}
bool Joint::getConstant(const char * in, Type & out)
{
return types.find(in, out);
}
bool Joint::getConstant(Type in, const char *& out)
{
return types.find(in, out);
}
StringMap<Joint::Type, Joint::JOINT_MAX_ENUM>::Entry Joint::typeEntries[] =
{
{"circle", Joint::JOINT_DISTANCE},
{"revolute", Joint::JOINT_REVOLUTE},
{"prismatic", Joint::JOINT_PRISMATIC},
{"mouse", Joint::JOINT_MOUSE},
{"pulley", Joint::JOINT_PULLEY},
{"gear", Joint::JOINT_GEAR},
};
StringMap<Joint::Type, Joint::JOINT_MAX_ENUM> Joint::types(Joint::typeEntries, sizeof(Joint::typeEntries));
} // physics
} // love
+14 -3
View File
@@ -23,6 +23,7 @@
// LOVE
#include <common/Object.h>
#include <common/StringMap.h>
namespace love
{
@@ -32,18 +33,28 @@ namespace physics
{
public:
enum JointType
enum Type
{
JOINT_INVALID,
JOINT_DISTANCE,
JOINT_REVOLUTE,
JOINT_PRISMATIC,
JOINT_MOUSE,
JOINT_PULLEY,
JOINT_GEAR
JOINT_GEAR,
JOINT_MAX_ENUM
};
virtual ~Joint(){}
virtual ~Joint();
static bool getConstant(const char * in, Type & out);
static bool getConstant(Type in, const char *& out);
private:
static StringMap<Type, JOINT_MAX_ENUM>::Entry typeEntries[];
static StringMap<Type, JOINT_MAX_ENUM> types;
};
} // physics
@@ -1,44 +1,50 @@
/**
* Copyright (c) 2006-2009 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
**/
#ifndef LOVE_SIGNAL_POSIX_WRAP_SIGNAL_H
#define LOVE_SIGNAL_POSIX_WRAP_SIGNAL_H
// LOVE
#include <common/config.h>
#include "Signal.h"
namespace love
{
namespace signal
{
namespace posix
{
int w_hook(lua_State *L);
int w_setCallback(lua_State *L);
int w_raise(lua_State *L);
extern "C" LOVE_EXPORT int luaopen_love_signal(lua_State * L);
} // posix
} // signal
} // love
#endif // LOVE_SIGNAL_POSIX_WRAP_SIGNAL_H
/**
* Copyright (c) 2006-2009 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
**/
#include "Shape.h"
namespace love
{
namespace physics
{
Shape::~Shape()
{
}
bool Shape::getConstant(const char * in, Type & out)
{
return types.find(in, out);
}
bool Shape::getConstant(Type in, const char *& out)
{
return types.find(in, out);
}
StringMap<Shape::Type, Shape::SHAPE_MAX_ENUM>::Entry Shape::typeEntries[] =
{
{"circle", Shape::SHAPE_CIRCLE},
{"polygon", Shape::SHAPE_POLYGON},
};
StringMap<Shape::Type, Shape::SHAPE_MAX_ENUM> Shape::types(Shape::typeEntries, sizeof(Shape::typeEntries));
} // physics
} // love
+13 -2
View File
@@ -23,6 +23,7 @@
// LOVE
#include <common/Object.h>
#include <common/StringMap.h>
namespace love
{
@@ -32,13 +33,23 @@ namespace physics
{
public:
enum ShapeType
enum Type
{
SHAPE_INVALID,
SHAPE_CIRCLE,
SHAPE_POLYGON,
SHAPE_MAX_ENUM
};
virtual ~Shape(){}
virtual ~Shape();
static bool getConstant(const char * in, Type & out);
static bool getConstant(Type in, const char *& out);
private:
static StringMap<Type, SHAPE_MAX_ENUM>::Entry typeEntries[];
static StringMap<Type, SHAPE_MAX_ENUM> types;
};
} // physics
+2 -2
View File
@@ -56,7 +56,7 @@ namespace box2d
joint = 0;
}
int Joint::getType() const
Joint::Type Joint::getType() const
{
switch(joint->GetType())
{
@@ -73,7 +73,7 @@ namespace box2d
case e_gearJoint:
return JOINT_GEAR;
default:
return -1;
return JOINT_INVALID;
}
}
+1 -1
View File
@@ -81,7 +81,7 @@ namespace box2d
/**
* Gets the type of joint.
**/
int getType() const;
Type getType() const;
/**
* Gets the anchor positions of the Joint in world
+2 -2
View File
@@ -50,7 +50,7 @@ namespace box2d
data = 0;
}
int Shape::getType() const
Shape::Type Shape::getType() const
{
switch(shape->GetType())
{
@@ -59,7 +59,7 @@ namespace box2d
case e_polygonShape:
return SHAPE_POLYGON;
default:
return -1;
return SHAPE_INVALID;
}
}
+1 -1
View File
@@ -86,7 +86,7 @@ namespace box2d
* Gets the type of Shape. Useful for
* debug drawing.
**/
int getType() const;
Type getType() const;
/**
* Sets the friction of the Shape.
+4 -1
View File
@@ -20,6 +20,7 @@
// LOVE
#include "wrap_Joint.h"
#include <common/StringMap.h>
namespace love
{
@@ -35,7 +36,9 @@ namespace box2d
int w_Joint_getType(lua_State * L)
{
Joint * t = luax_checkjoint(L, 1);
lua_pushinteger(L, t->getType());
const char * type = "";
Joint::getConstant(t->getType(), type);
lua_pushstring(L, type);
return 1;
}
@@ -236,20 +236,6 @@ namespace box2d
0
};
// List of constants.
static const Constant constants[] = {
{ "shape_circle", Shape::SHAPE_CIRCLE },
{ "shape_polygon", Shape::SHAPE_POLYGON },
{ "joint_distance", Joint::JOINT_DISTANCE },
{ "joint_revolute", Joint::JOINT_REVOLUTE },
{ "joint_prismatic", Joint::JOINT_PRISMATIC },
{ "joint_mouse", Joint::JOINT_MOUSE },
{ "joint_pulley", Joint::JOINT_PULLEY },
{ "joint_gear", Joint::JOINT_GEAR },
{ 0, 0 }
};
int luaopen_love_physics(lua_State * L)
{
if(instance == 0)
@@ -270,7 +256,6 @@ namespace box2d
w.flags = MODULE_T;
w.functions = functions;
w.types = types;
w.constants = constants;
return luax_register_module(L, w);
}
+4 -1
View File
@@ -19,6 +19,7 @@
**/
#include "wrap_Shape.h"
#include <common/StringMap.h>
namespace love
{
@@ -34,7 +35,9 @@ namespace box2d
int w_Shape_getType(lua_State * L)
{
Shape * t = luax_checkshape(L, 1);
lua_pushinteger(L, t->getType());
const char * type = "";
Shape::getConstant(t->getType(), type);
lua_pushstring(L, type);
return 1;
}
-103
View File
@@ -1,103 +0,0 @@
/**
* Copyright (c) 2006-2009 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
**/
#include "wrap_Signal.h"
// LOVE
#include <common/runtime.h>
#include "Signal.h"
namespace love
{
namespace signal
{
namespace posix
{
static Signal * instance = 0;
int w_hook(lua_State *L)
{
luaL_argcheck(L, lua_isnumber(L, 1), 1, "Expected number");
lua_pushboolean(L, instance->hook(lua_tointeger(L, 1)));
return 1;
}
int w_setCallback(lua_State *L)
{
luaL_argcheck(L, lua_isfunction(L, 1), 1, "Expected function");
instance->setCallback(L);
return 0;
}
int w_raise(lua_State *L)
{
luaL_argcheck(L, lua_isnumber(L, 1), 1, "Expected number");
lua_pushboolean(L, instance->raise(lua_tointeger(L, 1)));
return 1;
}
// List of functions to wrap.
static const luaL_Reg functions[] = {
{ "hook", w_hook },
{ "setCallback", w_setCallback },
{ "raise", w_raise },
{ 0, 0 }
};
static const Constant constants[] = {
{ "signal_abrt", SIGABRT },
{ "signal_fpe", SIGFPE },
{ "signal_ill", SIGILL },
{ "signal_int", SIGINT },
{ "signal_segv", SIGSEGV },
{ "signal_term", SIGTERM },
{ 0, 0 }
};
int luaopen_love_signal(lua_State * L)
{
if(instance == 0)
{
try
{
instance = new Signal();
}
catch(Exception & e)
{
return luaL_error(L, e.what());
}
}
WrappedModule w;
w.module = instance;
w.name = "signal";
w.flags = MODULE_T;
w.functions = functions;
w.types = 0;
w.constants = constants;
return luax_register_module(L, w);
}
} // posix
} // signal
} // love
-1
View File
@@ -135,7 +135,6 @@ namespace sound
w.flags = MODULE_SOUND_T;
w.functions = functions;
w.types = types;
w.constants = 0;
return luax_register_module(L, w);
}
-1
View File
@@ -91,7 +91,6 @@ namespace sdl
w.flags = MODULE_T;
w.functions = functions;
w.types = 0;
w.constants = 0;
return luax_register_module(L, w);
}