diff options
author | Peter Johnson <peter@tortall.net> | 2008-05-23 06:46:51 +0000 |
---|---|---|
committer | Peter Johnson <peter@tortall.net> | 2008-05-23 06:46:51 +0000 |
commit | eb7b1adb30124353ea0add7a07b569ef72f4646f (patch) | |
tree | 553a24fe5e1b96bcdcbd614ff43022aa81ec2ccd /libyasm | |
parent | e4f292ef16ec5888920bc07b57227970e54aec7d (diff) | |
download | yasm-eb7b1adb30124353ea0add7a07b569ef72f4646f.tar.gz |
Enable DLL/plugin builds with cmake on Windows.
Add proper declspec dllimport/dllexport to all libyasm functions.
Use macros to make these do nothing on non-cmake and Unix builds.
svn path=/trunk/yasm/; revision=2101
Diffstat (limited to 'libyasm')
-rw-r--r-- | libyasm/CMakeLists.txt | 5 | ||||
-rw-r--r-- | libyasm/assocdat.h | 9 | ||||
-rw-r--r-- | libyasm/bitvect.h | 108 | ||||
-rw-r--r-- | libyasm/bytecode.h | 36 | ||||
-rw-r--r-- | libyasm/coretype.h | 14 | ||||
-rw-r--r-- | libyasm/errwarn.h | 32 | ||||
-rw-r--r-- | libyasm/expr.h | 28 | ||||
-rw-r--r-- | libyasm/file.h | 23 | ||||
-rw-r--r-- | libyasm/floatnum.h | 14 | ||||
-rw-r--r-- | libyasm/hamt.h | 12 | ||||
-rw-r--r-- | libyasm/insn.h | 16 | ||||
-rw-r--r-- | libyasm/intnum.h | 40 | ||||
-rw-r--r-- | libyasm/inttree.h | 12 | ||||
-rw-r--r-- | libyasm/linemap.h | 14 | ||||
-rw-r--r-- | libyasm/md5.h | 8 | ||||
-rw-r--r-- | libyasm/module.h | 7 | ||||
-rw-r--r-- | libyasm/phash.h | 6 | ||||
-rw-r--r-- | libyasm/section.h | 33 | ||||
-rw-r--r-- | libyasm/symrec.h | 39 | ||||
-rw-r--r-- | libyasm/valparam.h | 23 | ||||
-rw-r--r-- | libyasm/value.h | 14 | ||||
-rw-r--r-- | libyasm/xmalloc.c | 4 |
22 files changed, 496 insertions, 1 deletions
diff --git a/libyasm/CMakeLists.txt b/libyasm/CMakeLists.txt index 8be337e5..125afa0d 100644 --- a/libyasm/CMakeLists.txt +++ b/libyasm/CMakeLists.txt @@ -31,7 +31,10 @@ ADD_LIBRARY(libyasm SHARED xmalloc.c xstrdup.c ) -SET_TARGET_PROPERTIES(libyasm PROPERTIES OUTPUT_NAME "yasm") +SET_TARGET_PROPERTIES(libyasm PROPERTIES + OUTPUT_NAME "yasm" + COMPILE_FLAGS -DYASM_LIB_SOURCE + ) INSTALL(TARGETS libyasm LIBRARY DESTINATION lib diff --git a/libyasm/assocdat.h b/libyasm/assocdat.h index 4b162d66..d18e1ebf 100644 --- a/libyasm/assocdat.h +++ b/libyasm/assocdat.h @@ -34,10 +34,15 @@ #ifndef YASM_ASSOCDAT_H #define YASM_ASSOCDAT_H +#ifndef YASM_LIB_DECL +#define YASM_LIB_DECL +#endif + /** Associated data container. */ typedef struct yasm__assoc_data yasm__assoc_data; /** Create an associated data container. */ +YASM_LIB_DECL /*@only@*/ yasm__assoc_data *yasm__assoc_data_create(void); /** Get associated data for a data callback. @@ -45,6 +50,7 @@ typedef struct yasm__assoc_data yasm__assoc_data; * \param callback callback used when adding data * \return Associated data (NULL if none). */ +YASM_LIB_DECL /*@dependent@*/ /*@null@*/ void *yasm__assoc_data_get (/*@null@*/ yasm__assoc_data *assoc_data, const yasm_assoc_data_callback *callback); @@ -55,16 +61,19 @@ typedef struct yasm__assoc_data yasm__assoc_data; * \param callback callback * \param data data to associate */ +YASM_LIB_DECL /*@only@*/ yasm__assoc_data *yasm__assoc_data_add (/*@null@*/ /*@only@*/ yasm__assoc_data *assoc_data, const yasm_assoc_data_callback *callback, /*@only@*/ /*@null@*/ void *data); /** Destroy all associated data in a container. */ +YASM_LIB_DECL void yasm__assoc_data_destroy (/*@null@*/ /*@only@*/ yasm__assoc_data *assoc_data); /** Print all associated data in a container. */ +YASM_LIB_DECL void yasm__assoc_data_print(const yasm__assoc_data *assoc_data, FILE *f, int indent_level); diff --git a/libyasm/bitvect.h b/libyasm/bitvect.h index e2a10238..dc77d4fa 100644 --- a/libyasm/bitvect.h +++ b/libyasm/bitvect.h @@ -15,6 +15,9 @@ /* and your own application(s) which might - directly or indirectly - */ /* include this definitions file. */ /*****************************************************************************/ +#ifndef YASM_LIB_DECL +#define YASM_LIB_DECL +#endif typedef unsigned char N_char; typedef unsigned char N_byte; @@ -117,213 +120,318 @@ typedef wordptr *listptr; /* ===> MISCELLANEOUS BASIC FUNCTIONS: <=== */ +YASM_LIB_DECL const char * BitVector_Error (ErrCode error); /* return string for err code */ +YASM_LIB_DECL ErrCode BitVector_Boot (void); /* 0 = ok, 1..7 = error */ +YASM_LIB_DECL void BitVector_Shutdown (void); /* undo Boot */ +YASM_LIB_DECL N_word BitVector_Size (N_int bits); /* bit vector size (# of words) */ +YASM_LIB_DECL N_word BitVector_Mask (N_int bits); /* bit vector mask (unused bits) */ /* ===> CLASS METHODS: <=== */ +YASM_LIB_DECL const char * BitVector_Version (void); /* returns version string */ +YASM_LIB_DECL N_int BitVector_Word_Bits (void); /* return # of bits in machine word */ +YASM_LIB_DECL N_int BitVector_Long_Bits (void); /* return # of bits in unsigned long */ /* ===> CONSTRUCTOR METHODS: <=== */ +YASM_LIB_DECL /*@only@*/ wordptr BitVector_Create (N_int bits, boolean clear); /* malloc */ +YASM_LIB_DECL listptr BitVector_Create_List(N_int bits, boolean clear, N_int count); +YASM_LIB_DECL wordptr BitVector_Resize (wordptr oldaddr, N_int bits); /* realloc */ +YASM_LIB_DECL wordptr BitVector_Shadow (wordptr addr); /* make new same size but empty */ +YASM_LIB_DECL wordptr BitVector_Clone (wordptr addr); /* make exact duplicate */ +YASM_LIB_DECL wordptr BitVector_Concat (wordptr X, wordptr Y); /* return concatenation */ /* ===> DESTRUCTOR METHODS: <=== */ +YASM_LIB_DECL void BitVector_Dispose (/*@only@*/ /*@out@*/ charptr string); /* string */ +YASM_LIB_DECL void BitVector_Destroy (/*@only@*/ wordptr addr); /* bitvec */ +YASM_LIB_DECL void BitVector_Destroy_List (listptr list, N_int count); /* list */ /* ===> OBJECT METHODS: <=== */ /* ===> bit vector copy function: */ +YASM_LIB_DECL void BitVector_Copy (wordptr X, wordptr Y); /* X = Y */ /* ===> bit vector initialization: */ +YASM_LIB_DECL void BitVector_Empty (wordptr addr); /* X = {} */ +YASM_LIB_DECL void BitVector_Fill (wordptr addr); /* X = ~{} */ +YASM_LIB_DECL void BitVector_Flip (wordptr addr); /* X = ~X */ +YASM_LIB_DECL void BitVector_Primes (wordptr addr); /* ===> miscellaneous functions: */ +YASM_LIB_DECL void BitVector_Reverse (wordptr X, wordptr Y); /* ===> bit vector interval operations and functions: */ +YASM_LIB_DECL void BitVector_Interval_Empty (/*@out@*/ wordptr addr, N_int lower, N_int upper); +YASM_LIB_DECL void BitVector_Interval_Fill (/*@out@*/ wordptr addr, N_int lower, N_int upper); +YASM_LIB_DECL void BitVector_Interval_Flip (/*@out@*/ wordptr addr, N_int lower, N_int upper); +YASM_LIB_DECL void BitVector_Interval_Reverse (/*@out@*/ wordptr addr, N_int lower, N_int upper); +YASM_LIB_DECL boolean BitVector_interval_scan_inc (wordptr addr, N_int start, N_intptr min, N_intptr max); +YASM_LIB_DECL boolean BitVector_interval_scan_dec (wordptr addr, N_int start, N_intptr min, N_intptr max); +YASM_LIB_DECL void BitVector_Interval_Copy (/*@out@*/ wordptr X, wordptr Y, N_int Xoffset, N_int Yoffset, N_int length); +YASM_LIB_DECL wordptr BitVector_Interval_Substitute(/*@out@*/ wordptr X, wordptr Y, N_int Xoffset, N_int Xlength, N_int Yoffset, N_int Ylength); /* ===> bit vector test functions: */ +YASM_LIB_DECL boolean BitVector_is_empty (wordptr addr); /* X == {} ? */ +YASM_LIB_DECL boolean BitVector_is_full (wordptr addr); /* X == ~{} ? */ +YASM_LIB_DECL boolean BitVector_equal (wordptr X, wordptr Y); /* X == Y ? */ +YASM_LIB_DECL Z_int BitVector_Lexicompare(wordptr X, wordptr Y); /* X <,=,> Y ? */ +YASM_LIB_DECL Z_int BitVector_Compare (wordptr X, wordptr Y); /* X <,=,> Y ? */ /* ===> bit vector string conversion functions: */ +YASM_LIB_DECL /*@only@*/ charptr BitVector_to_Hex (wordptr addr); +YASM_LIB_DECL ErrCode BitVector_from_Hex (/*@out@*/wordptr addr, charptr string); +YASM_LIB_DECL ErrCode BitVector_from_Oct(/*@out@*/ wordptr addr, charptr string); +YASM_LIB_DECL /*@only@*/ charptr BitVector_to_Bin (wordptr addr); +YASM_LIB_DECL ErrCode BitVector_from_Bin (/*@out@*/ wordptr addr, charptr string); +YASM_LIB_DECL /*@only@*/ charptr BitVector_to_Dec (wordptr addr); +YASM_LIB_DECL ErrCode BitVector_from_Dec (/*@out@*/ wordptr addr, charptr string); typedef struct BitVector_from_Dec_static_data BitVector_from_Dec_static_data; +YASM_LIB_DECL BitVector_from_Dec_static_data *BitVector_from_Dec_static_Boot(N_word bits); +YASM_LIB_DECL void BitVector_from_Dec_static_Shutdown(/*@null@*/ BitVector_from_Dec_static_data *data); +YASM_LIB_DECL ErrCode BitVector_from_Dec_static(BitVector_from_Dec_static_data *data, /*@out@*/ wordptr addr, charptr string); +YASM_LIB_DECL /*@only@*/ charptr BitVector_to_Enum (wordptr addr); +YASM_LIB_DECL ErrCode BitVector_from_Enum (/*@out@*/ wordptr addr, charptr string); /* ===> bit vector bit operations, functions & tests: */ +YASM_LIB_DECL void BitVector_Bit_Off (/*@out@*/ wordptr addr, N_int indx); /* X = X \ {x} */ +YASM_LIB_DECL void BitVector_Bit_On (/*@out@*/ wordptr addr, N_int indx); /* X = X + {x} */ +YASM_LIB_DECL boolean BitVector_bit_flip (/*@out@*/ wordptr addr, N_int indx); /* (X+{x})\(X*{x}) */ +YASM_LIB_DECL boolean BitVector_bit_test (wordptr addr, N_int indx); /* {x} in X ? */ +YASM_LIB_DECL void BitVector_Bit_Copy (/*@out@*/ wordptr addr, N_int indx, boolean bit); /* ===> bit vector bit shift & rotate functions: */ +YASM_LIB_DECL void BitVector_LSB (/*@out@*/ wordptr addr, boolean bit); +YASM_LIB_DECL void BitVector_MSB (/*@out@*/ wordptr addr, boolean bit); +YASM_LIB_DECL boolean BitVector_lsb_ (wordptr addr); +YASM_LIB_DECL boolean BitVector_msb_ (wordptr addr); +YASM_LIB_DECL boolean /*@alt void@*/ BitVector_rotate_left (wordptr addr); +YASM_LIB_DECL boolean /*@alt void@*/ BitVector_rotate_right (wordptr addr); +YASM_LIB_DECL boolean /*@alt void@*/ BitVector_shift_left (wordptr addr, boolean carry_in); +YASM_LIB_DECL boolean /*@alt void@*/ BitVector_shift_right (wordptr addr, boolean carry_in); +YASM_LIB_DECL void BitVector_Move_Left (wordptr addr, N_int bits); +YASM_LIB_DECL void BitVector_Move_Right (wordptr addr, N_int bits); /* ===> bit vector insert/delete bits: */ +YASM_LIB_DECL void BitVector_Insert (wordptr addr, N_int offset, N_int count, boolean clear); +YASM_LIB_DECL void BitVector_Delete (wordptr addr, N_int offset, N_int count, boolean clear); /* ===> bit vector arithmetic: */ +YASM_LIB_DECL boolean /*@alt void@*/ BitVector_increment (wordptr addr); /* X++ */ +YASM_LIB_DECL boolean /*@alt void@*/ BitVector_decrement (wordptr addr); /* X-- */ +YASM_LIB_DECL boolean /*@alt void@*/ BitVector_compute (wordptr X, wordptr Y, wordptr Z, boolean minus, boolean *carry); +YASM_LIB_DECL boolean /*@alt void@*/ BitVector_add (wordptr X, wordptr Y, wordptr Z, boolean *carry); +YASM_LIB_DECL boolean /*@alt void@*/ BitVector_sub (wordptr X, wordptr Y, wordptr Z, boolean *carry); +YASM_LIB_DECL boolean /*@alt void@*/ BitVector_inc (wordptr X, wordptr Y); +YASM_LIB_DECL boolean /*@alt void@*/ BitVector_dec (wordptr X, wordptr Y); +YASM_LIB_DECL void BitVector_Negate (wordptr X, wordptr Y); +YASM_LIB_DECL void BitVector_Absolute (wordptr X, wordptr Y); +YASM_LIB_DECL Z_int BitVector_Sign (wordptr addr); +YASM_LIB_DECL ErrCode BitVector_Mul_Pos (wordptr X, wordptr Y, wordptr Z, boolean strict); +YASM_LIB_DECL ErrCode BitVector_Multiply (wordptr X, wordptr Y, wordptr Z); +YASM_LIB_DECL ErrCode BitVector_Div_Pos (wordptr Q, wordptr X, wordptr Y, wordptr R); +YASM_LIB_DECL ErrCode BitVector_Divide (wordptr Q, wordptr X, wordptr Y, wordptr R); +YASM_LIB_DECL ErrCode BitVector_GCD (wordptr X, wordptr Y, wordptr Z); +YASM_LIB_DECL ErrCode BitVector_GCD2 (wordptr U, wordptr V, wordptr W, /* O */ wordptr X, wordptr Y); /* I */ +YASM_LIB_DECL ErrCode BitVector_Power (wordptr X, wordptr Y, wordptr Z); /* ===> direct memory access functions: */ +YASM_LIB_DECL void BitVector_Block_Store(wordptr addr, charptr buffer, N_int length); +YASM_LIB_DECL charptr BitVector_Block_Read (wordptr addr, /*@out@*/ N_intptr length); /* ===> word array functions: */ +YASM_LIB_DECL void BitVector_Word_Store (wordptr addr, N_int offset, N_int value); +YASM_LIB_DECL N_int BitVector_Word_Read (wordptr addr, N_int offset); +YASM_LIB_DECL void BitVector_Word_Insert(wordptr addr, N_int offset, N_int count, boolean clear); +YASM_LIB_DECL void BitVector_Word_Delete(wordptr addr, N_int offset, N_int count, boolean clear); /* ===> arbitrary size chunk functions: */ +YASM_LIB_DECL void BitVector_Chunk_Store(wordptr addr, N_int chunksize, N_int offset, N_long value); +YASM_LIB_DECL N_long BitVector_Chunk_Read (wordptr addr, N_int chunksize, N_int offset); /* ===> set operations: */ +YASM_LIB_DECL void Set_Union (wordptr X, wordptr Y, wordptr Z); /* X = Y + Z */ +YASM_LIB_DECL void Set_Intersection (wordptr X, wordptr Y, wordptr Z); /* X = Y * Z */ +YASM_LIB_DECL void Set_Difference (wordptr X, wordptr Y, wordptr Z); /* X = Y \ Z */ +YASM_LIB_DECL void Set_ExclusiveOr (wordptr X, wordptr Y, wordptr Z); /*(Y+Z)\(Y*Z)*/ +YASM_LIB_DECL void Set_Complement (wordptr X, wordptr Y); /* X = ~Y */ /* ===> set functions: */ +YASM_LIB_DECL boolean Set_subset (wordptr X, wordptr Y); /* X in Y ? */ +YASM_LIB_DECL N_int Set_Norm (wordptr addr); /* = | X | */ +YASM_LIB_DECL N_int Set_Norm2 (wordptr addr); /* = | X | */ +YASM_LIB_DECL N_int Set_Norm3 (wordptr addr); /* = | X | */ +YASM_LIB_DECL Z_long Set_Min (wordptr addr); /* = min(X) */ +YASM_LIB_DECL Z_long Set_Max (wordptr addr); /* = max(X) */ /* ===> matrix-of-booleans operations: */ +YASM_LIB_DECL void Matrix_Multiplication(wordptr X, N_int rowsX, N_int colsX, wordptr Y, N_int rowsY, N_int colsY, wordptr Z, N_int rowsZ, N_int colsZ); +YASM_LIB_DECL void Matrix_Product (wordptr X, N_int rowsX, N_int colsX, wordptr Y, N_int rowsY, N_int colsY, wordptr Z, N_int rowsZ, N_int colsZ); +YASM_LIB_DECL void Matrix_Closure (wordptr addr, N_int rows, N_int cols); +YASM_LIB_DECL void Matrix_Transpose (wordptr X, N_int rowsX, N_int colsX, wordptr Y, N_int rowsY, N_int colsY); diff --git a/libyasm/bytecode.h b/libyasm/bytecode.h index 741aabb6..bff958f8 100644 --- a/libyasm/bytecode.h +++ b/libyasm/bytecode.h @@ -34,6 +34,10 @@ #ifndef YASM_BYTECODE_H #define YASM_BYTECODE_H +#ifndef YASM_LIB_DECL +#define YASM_LIB_DECL +#endif + /** A data value (opaque type). */ typedef struct yasm_dataval yasm_dataval; /** A list of data values. */ @@ -223,6 +227,7 @@ struct yasm_bytecode { * \param line virtual line (from yasm_linemap) * \return Newly allocated bytecode of the specified type. */ +YASM_LIB_DECL /*@only@*/ yasm_bytecode *yasm_bc_create_common (/*@null@*/ const yasm_bytecode_callback *callback, /*@only@*/ /*@null@*/ void *contents, unsigned long line); @@ -232,6 +237,7 @@ struct yasm_bytecode { * \param callback new bytecode callback function * \param contents new type-specific data */ +YASM_LIB_DECL void yasm_bc_transform(yasm_bytecode *bc, const yasm_bytecode_callback *callback, void *contents); @@ -239,11 +245,13 @@ void yasm_bc_transform(yasm_bytecode *bc, /** Common bytecode callback finalize function, for where no finalization * is ever required for this type of bytecode. */ +YASM_LIB_DECL void yasm_bc_finalize_common(yasm_bytecode *bc, yasm_bytecode *prev_bc); /** Common bytecode callback calc_len function, for where the bytecode has * no calculatable length. Causes an internal error if called. */ +YASM_LIB_DECL int yasm_bc_calc_len_common(yasm_bytecode *bc, yasm_bc_add_span_func add_span, void *add_span_data); @@ -251,6 +259,7 @@ int yasm_bc_calc_len_common(yasm_bytecode *bc, yasm_bc_add_span_func add_span, * always short (calc_len never calls add_span). Causes an internal * error if called. */ +YASM_LIB_DECL int yasm_bc_expand_common (yasm_bytecode *bc, int span, long old_val, long new_val, /*@out@*/ long *neg_thres, /*@out@*/ long *pos_thres); @@ -258,6 +267,7 @@ int yasm_bc_expand_common /** Common bytecode callback tobytes function, for where the bytecode * cannot be converted to bytes. Causes an internal error if called. */ +YASM_LIB_DECL int yasm_bc_tobytes_common (yasm_bytecode *bc, unsigned char **bufp, void *d, yasm_output_value_func output_value, @@ -275,6 +285,7 @@ int yasm_bc_tobytes_common * \param bc bytecode * \param e multiple (kept, do not free) */ +YASM_LIB_DECL void yasm_bc_set_multiple(yasm_bytecode *bc, /*@keep@*/ yasm_expr *e); /** Create a bytecode containing data value(s). @@ -287,6 +298,7 @@ void yasm_bc_set_multiple(yasm_bytecode *bc, /*@keep@*/ yasm_expr *e); * \param line virtual line (from yasm_linemap) * \return Newly allocated bytecode. */ +YASM_LIB_DECL /*@only@*/ yasm_bytecode *yasm_bc_create_data (yasm_datavalhead *datahead, unsigned int size, int append_zero, /*@null@*/ yasm_arch *arch, unsigned long line); @@ -297,6 +309,7 @@ void yasm_bc_set_multiple(yasm_bytecode *bc, /*@keep@*/ yasm_expr *e); * \param line virtual line (from yasm_linemap) * \return Newly allocated bytecode. */ +YASM_LIB_DECL /*@only@*/ yasm_bytecode *yasm_bc_create_leb128 (yasm_datavalhead *datahead, int sign, unsigned long line); @@ -306,6 +319,7 @@ void yasm_bc_set_multiple(yasm_bytecode *bc, /*@keep@*/ yasm_expr *e); * \param line virtual line (from yasm_linemap) * \return Newly allocated bytecode. */ +YASM_LIB_DECL /*@only@*/ yasm_bytecode *yasm_bc_create_reserve (/*@only@*/ yasm_expr *numitems, unsigned int itemsize, unsigned long line); @@ -317,6 +331,7 @@ void yasm_bc_set_multiple(yasm_bytecode *bc, /*@keep@*/ yasm_expr *e); * \return NULL if bc is not a reserve bytecode, otherwise an expression * for the number of items to reserve. */ +YASM_LIB_DECL /*@null@*/ const yasm_expr *yasm_bc_reserve_numitems (yasm_bytecode *bc, /*@out@*/ unsigned int *itemsize); @@ -330,6 +345,7 @@ void yasm_bc_set_multiple(yasm_bytecode *bc, /*@keep@*/ yasm_expr *e); * \param line virtual line (from yasm_linemap) for the bytecode * \return Newly allocated bytecode. */ +YASM_LIB_DECL /*@only@*/ yasm_bytecode *yasm_bc_create_incbin (/*@only@*/ char *filename, /*@only@*/ /*@null@*/ yasm_expr *start, /*@only@*/ /*@null@*/ yasm_expr *maxlen, yasm_linemap *linemap, @@ -347,6 +363,7 @@ void yasm_bc_set_multiple(yasm_bytecode *bc, /*@keep@*/ yasm_expr *e); * - from code_fill parameter (if not NULL) * - 0 */ +YASM_LIB_DECL /*@only@*/ yasm_bytecode *yasm_bc_create_align (/*@keep@*/ yasm_expr *boundary, /*@keep@*/ /*@null@*/ yasm_expr *fill, /*@keep@*/ /*@null@*/ yasm_expr *maxskip, @@ -359,6 +376,7 @@ void yasm_bc_set_multiple(yasm_bytecode *bc, /*@keep@*/ yasm_expr *e); * \param line virtual line (from yasm_linemap) * \return Newly allocated bytecode. */ +YASM_LIB_DECL /*@only@*/ yasm_bytecode *yasm_bc_create_org (unsigned long start, unsigned long fill, unsigned long line); @@ -367,6 +385,7 @@ void yasm_bc_set_multiple(yasm_bytecode *bc, /*@keep@*/ yasm_expr *e); * \return Section containing bc (can be NULL if bytecode is not part of a * section). */ +YASM_LIB_DECL /*@dependent@*/ /*@null@*/ yasm_section *yasm_bc_get_section (yasm_bytecode *bc); @@ -375,11 +394,13 @@ void yasm_bc_set_multiple(yasm_bytecode *bc, /*@keep@*/ yasm_expr *e); * \param bc bytecode * \param sym symbol */ +YASM_LIB_DECL void yasm_bc__add_symrec(yasm_bytecode *bc, /*@dependent@*/ yasm_symrec *sym); /** Delete (free allocated memory for) a bytecode. * \param bc bytecode (only pointer to it); may be NULL */ +YASM_LIB_DECL void yasm_bc_destroy(/*@only@*/ /*@null@*/ yasm_bytecode *bc); /** Print a bytecode. For debugging purposes. @@ -387,12 +408,14 @@ void yasm_bc_destroy(/*@only@*/ /*@null@*/ yasm_bytecode *bc); * \param indent_level indentation level * \param bc bytecode */ +YASM_LIB_DECL void yasm_bc_print(const yasm_bytecode *bc, FILE *f, int indent_level); /** Finalize a bytecode after parsing. * \param bc bytecode * \param prev_bc bytecode directly preceding bc in a list of bytecodes */ +YASM_LIB_DECL void yasm_bc_finalize(yasm_bytecode *bc, yasm_bytecode *prev_bc); /** Determine the distance between the starting offsets of two bytecodes. @@ -402,6 +425,7 @@ void yasm_bc_finalize(yasm_bytecode *bc, yasm_bytecode *prev_bc); * the distance was indeterminate. * \warning Only valid /after/ optimization. */ +YASM_LIB_DECL /*@null@*/ /*@only@*/ yasm_intnum *yasm_calc_bc_dist (yasm_bytecode *precbc1, yasm_bytecode *precbc2); @@ -411,6 +435,7 @@ void yasm_bc_finalize(yasm_bytecode *bc, yasm_bytecode *prev_bc); * \return Offset of the next bytecode in bytes. * \warning Only valid /after/ optimization. */ +YASM_LIB_DECL unsigned long yasm_bc_next_offset(yasm_bytecode *precbc); /** Resolve EQUs in a bytecode and calculate its minimum size. @@ -425,6 +450,7 @@ unsigned long yasm_bc_next_offset(yasm_bytecode *precbc); * (and output) during execution. * \note May store to bytecode updated expressions and the short length. */ +YASM_LIB_DECL int yasm_bc_calc_len(yasm_bytecode *bc, yasm_bc_add_span_func add_span, void *add_span_data); @@ -442,6 +468,7 @@ int yasm_bc_calc_len(yasm_bytecode *bc, yasm_bc_add_span_func add_span, * new negative and positive thresholds returned. * \note May store to bytecode updated expressions and the updated length. */ +YASM_LIB_DECL int yasm_bc_expand(yasm_bytecode *bc, int span, long old_val, long new_val, /*@out@*/ long *neg_thres, /*@out@*/ long *pos_thres); @@ -465,6 +492,7 @@ int yasm_bc_expand(yasm_bytecode *bc, int span, long old_val, long new_val, * results on the second call, as calling this function may result in * non-reversible changes to the bytecode. */ +YASM_LIB_DECL /*@null@*/ /*@only@*/ unsigned char *yasm_bc_tobytes (yasm_bytecode *bc, unsigned char *buf, unsigned long *bufsize, /*@out@*/ int *gap, void *d, yasm_output_value_func output_value, @@ -478,6 +506,7 @@ int yasm_bc_expand(yasm_bytecode *bc, int span, long old_val, long new_val, * calculated, 0 if error should be returned in this case * \return 1 on error (set with yasm_error_set), 0 on success. */ +YASM_LIB_DECL int yasm_bc_get_multiple(yasm_bytecode *bc, /*@out@*/ long *multiple, int calc_bc_dist); @@ -485,6 +514,7 @@ int yasm_bc_get_multiple(yasm_bytecode *bc, /*@out@*/ long *multiple, * \param bc bytecode * \return Bytecode multiple, NULL if =1. */ +YASM_LIB_DECL const yasm_expr *yasm_bc_get_multiple_expr(const yasm_bytecode *bc); /** Get a #yasm_insn structure from an instruction bytecode (if possible). @@ -492,12 +522,14 @@ const yasm_expr *yasm_bc_get_multiple_expr(const yasm_bytecode *bc); * \return Instruction details if bytecode is an instruction bytecode, * otherwise NULL. */ +YASM_LIB_DECL /*@dependent@*/ /*@null@*/ yasm_insn *yasm_bc_get_insn(yasm_bytecode *bc); /** Create a new data value from an expression. * \param expn expression * \return Newly allocated data value. */ +YASM_LIB_DECL yasm_dataval *yasm_dv_create_expr(/*@keep@*/ yasm_expr *expn); /** Create a new data value from a string. @@ -512,6 +544,7 @@ yasm_dataval *yasm_dv_create_string(/*@keep@*/ char *contents, size_t len); * \param len length * \return Newly allocated data value. */ +YASM_LIB_DECL yasm_dataval *yasm_dv_create_raw(/*@keep@*/ unsigned char *contents, unsigned long len); @@ -531,6 +564,7 @@ void yasm_dvs_initialize(yasm_datavalhead *headp); /** Delete (free allocated memory for) a list of data values. * \param headp list of data values */ +YASM_LIB_DECL void yasm_dvs_delete(yasm_datavalhead *headp); /** Add data value to the end of a list of data values. @@ -542,6 +576,7 @@ void yasm_dvs_delete(yasm_datavalhead *headp); * \return If data value was actually appended (it wasn't NULL), the data * value; otherwise NULL. */ +YASM_LIB_DECL /*@null@*/ yasm_dataval *yasm_dvs_append (yasm_datavalhead *headp, /*@returned@*/ /*@null@*/ yasm_dataval *dv); @@ -550,6 +585,7 @@ void yasm_dvs_delete(yasm_datavalhead *headp); * \param indent_level indentation level * \param headp data value list */ +YASM_LIB_DECL void yasm_dvs_print(const yasm_datavalhead *headp, FILE *f, int indent_level); #endif diff --git a/libyasm/coretype.h b/libyasm/coretype.h index b23e3eae..a78c28f2 100644 --- a/libyasm/coretype.h +++ b/libyasm/coretype.h @@ -34,6 +34,10 @@ #ifndef YASM_CORETYPE_H #define YASM_CORETYPE_H +#ifndef YASM_LIB_DECL +#define YASM_LIB_DECL +#endif + /** Architecture instance (mostly opaque type). \see arch.h for details. */ typedef struct yasm_arch yasm_arch; /** Preprocessor interface. \see preproc.h for details. */ @@ -302,6 +306,7 @@ typedef int (*yasm_output_reloc_func) * \param size size of each array element * \param compar element comparison function */ +YASM_LIB_DECL int yasm__mergesort(void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *)); @@ -311,6 +316,7 @@ int yasm__mergesort(void *base, size_t nmemb, size_t size, * \param delim set of 1 or more delimiters * \return First/next substring. */ +YASM_LIB_DECL /*@null@*/ char *yasm__strsep(char **stringp, const char *delim); /** Compare two strings, ignoring case differences. @@ -319,6 +325,7 @@ int yasm__mergesort(void *base, size_t nmemb, size_t size, * \param s2 string 2 * \return 0 if strings are equal, -1 if s1<s2, 1 if s1>s2. */ +YASM_LIB_DECL int yasm__strcasecmp(const char *s1, const char *s2); /** Compare portion of two strings, ignoring case differences. @@ -328,6 +335,7 @@ int yasm__strcasecmp(const char *s1, const char *s2); * \param n maximum number of characters to compare * \return 0 if strings are equal, -1 if s1<s2, 1 if s1>s2. */ +YASM_LIB_DECL int yasm__strncasecmp(const char *s1, const char *s2, size_t n); /** strdup() implementation using yasm_xmalloc(). @@ -335,6 +343,7 @@ int yasm__strncasecmp(const char *s1, const char *s2, size_t n); * \param str string * \return Newly allocated duplicate string. */ +YASM_LIB_DECL /*@only@*/ char *yasm__xstrdup(const char *str); /** strndup() implementation using yasm_xmalloc(). @@ -343,6 +352,7 @@ int yasm__strncasecmp(const char *s1, const char *s2, size_t n); * \param max maximum number of characters to copy * \return Newly allocated duplicate string. */ +YASM_LIB_DECL /*@only@*/ char *yasm__xstrndup(const char *str, size_t max); /** Error-checking memory allocation. A default implementation is provided @@ -351,6 +361,7 @@ int yasm__strncasecmp(const char *s1, const char *s2, size_t n); * \param size number of bytes to allocate * \return Allocated memory block. */ +YASM_LIB_DECL extern /*@only@*/ /*@out@*/ void * (*yasm_xmalloc) (size_t size); /** Error-checking memory allocation (with clear-to-0). A default @@ -360,6 +371,7 @@ extern /*@only@*/ /*@out@*/ void * (*yasm_xmalloc) (size_t size); * \param elsize size (in bytes) of each element * \return Allocated and cleared memory block. */ +YASM_LIB_DECL extern /*@only@*/ void * (*yasm_xcalloc) (size_t nelem, size_t elsize); /** Error-checking memory reallocation. A default implementation is provided @@ -369,6 +381,7 @@ extern /*@only@*/ void * (*yasm_xcalloc) (size_t nelem, size_t elsize); * \param elsize new size, in bytes * \return Re-allocated memory block. */ +YASM_LIB_DECL extern /*@only@*/ void * (*yasm_xrealloc) (/*@only@*/ /*@out@*/ /*@returned@*/ /*@null@*/ void *oldmem, size_t size) /*@modifies oldmem@*/; @@ -377,6 +390,7 @@ extern /*@only@*/ void * (*yasm_xrealloc) * that calls yasm_fatal() on allocation errors. * \param p memory block to free */ +YASM_LIB_DECL extern void (*yasm_xfree) (/*@only@*/ /*@out@*/ /*@null@*/ void *p) /*@modifies p@*/; diff --git a/libyasm/errwarn.h b/libyasm/errwarn.h index 214f3125..d1e9928b 100644 --- a/libyasm/errwarn.h +++ b/libyasm/errwarn.h @@ -34,6 +34,10 @@ #ifndef YASM_ERRWARN_H #define YASM_ERRWARN_H +#ifndef YASM_LIB_DECL +#define YASM_LIB_DECL +#endif + /** Warning classes (that may be enabled/disabled). */ typedef enum yasm_warn_class { YASM_WARN_NONE = 0, /**< No warning */ @@ -67,11 +71,13 @@ typedef enum yasm_error_class { } yasm_error_class; /** Initialize any internal data structures. */ +YASM_LIB_DECL void yasm_errwarn_initialize(void); /** Clean up any memory allocated by yasm_errwarn_initialize() or other * functions. */ +YASM_LIB_DECL void yasm_errwarn_cleanup(void); /** Reporting point of internal errors. These are usually due to sanity @@ -82,6 +88,7 @@ void yasm_errwarn_cleanup(void); * \param line source line (ala __LINE__) * \param message internal error message */ +YASM_LIB_DECL extern /*@exits@*/ void (*yasm_internal_error_) (const char *file, unsigned int line, const char *message); @@ -98,6 +105,7 @@ extern /*@exits@*/ void (*yasm_internal_error_) * \param message fatal error message * \param va va_list argument list for message */ +YASM_LIB_DECL extern /*@exits@*/ void (*yasm_fatal) (const char *message, va_list va); /** Reporting point of fatal errors, with variable arguments (internal only). @@ -106,11 +114,13 @@ extern /*@exits@*/ void (*yasm_fatal) (const char *message, va_list va); * \param message fatal error message * \param ... argument list for message */ +YASM_LIB_DECL /*@exits@*/ void yasm__fatal(const char *message, ...); /** Unconditionally clear the error indicator, freeing any associated data. * Has no effect if the error indicator is not set. */ +YASM_LIB_DECL void yasm_error_clear(void); /** Get the error indicator. YASM_ERROR_NONE is returned if no error has @@ -127,9 +137,11 @@ yasm_error_class yasm_error_occurred(void); * \return Nonzero if error indicator is set and a subclass of eclass, 0 * otherwise. */ +YASM_LIB_DECL int yasm_error_matches(yasm_error_class eclass); #ifndef YASM_DOXYGEN +YASM_LIB_DECL extern yasm_error_class yasm_eclass; #define yasm_error_occurred() yasm_eclass #endif @@ -140,6 +152,7 @@ extern yasm_error_class yasm_eclass; * \param format printf format string * \param va argument list for format */ +YASM_LIB_DECL void yasm_error_set_va(yasm_error_class eclass, const char *format, va_list va); /** Set the error indicator. Has no effect if the error indicator is already @@ -148,6 +161,7 @@ void yasm_error_set_va(yasm_error_class eclass, const char *format, va_list va); * \param format printf format string * \param ... argument list for format */ +YASM_LIB_DECL void yasm_error_set(yasm_error_class eclass, const char *format, ...) /*@printflike@*/; @@ -158,6 +172,7 @@ void yasm_error_set(yasm_error_class eclass, const char *format, ...) * \param format printf format string * \param va argument list for format */ +YASM_LIB_DECL void yasm_error_set_xref_va(unsigned long xrefline, const char *format, va_list va); @@ -168,6 +183,7 @@ void yasm_error_set_xref_va(unsigned long xrefline, const char *format, * \param format printf format string * \param ... argument list for format */ +YASM_LIB_DECL void yasm_error_set_xref(unsigned long xrefline, const char *format, ...) /*@printflike@*/; @@ -183,6 +199,7 @@ void yasm_error_set_xref(unsigned long xrefline, const char *format, ...) * \param xrefline virtual line used for cross-referencing (0 if no xref) * \param xrefstr cross-reference error message (NULL if no xref) */ +YASM_LIB_DECL void yasm_error_fetch(/*@out@*/ yasm_error_class *eclass, /*@out@*/ /*@only@*/ /*@null@*/ char **str, /*@out@*/ unsigned long *xrefline, @@ -191,6 +208,7 @@ void yasm_error_fetch(/*@out@*/ yasm_error_class *eclass, /** Unconditionally clear all warning indicators, freeing any associated data. * Has no effect if no warning indicators have been set. */ +YASM_LIB_DECL void yasm_warn_clear(void); /** Get the first warning indicator. YASM_WARN_NONE is returned if no warning @@ -198,6 +216,7 @@ void yasm_warn_clear(void); * be treated as a boolean value. * \return First warning indicator. */ +YASM_LIB_DECL yasm_warn_class yasm_warn_occurred(void); /** Add a warning indicator (va_list version). @@ -205,6 +224,7 @@ yasm_warn_class yasm_warn_occurred(void); * \param format printf format string * \param va argument list for format */ +YASM_LIB_DECL void yasm_warn_set_va(yasm_warn_class wclass, const char *format, va_list va); /** Add a warning indicator. @@ -212,6 +232,7 @@ void yasm_warn_set_va(yasm_warn_class wclass, const char *format, va_list va); * \param format printf format string * \param ... argument list for format */ +YASM_LIB_DECL void yasm_warn_set(yasm_warn_class wclass, const char *format, ...) /*@printflike@*/; @@ -225,30 +246,36 @@ void yasm_warn_set(yasm_warn_class wclass, const char *format, ...) * \param wclass warning class (output) * \param str warning message */ +YASM_LIB_DECL void yasm_warn_fetch(/*@out@*/ yasm_warn_class *wclass, /*@out@*/ /*@only@*/ char **str); /** Enable a class of warnings. * \param wclass warning class */ +YASM_LIB_DECL void yasm_warn_enable(yasm_warn_class wclass); /** Disable a class of warnings. * \param wclass warning class */ +YASM_LIB_DECL void yasm_warn_disable(yasm_warn_class wclass); /** Disable all classes of warnings. */ +YASM_LIB_DECL void yasm_warn_disable_all(void); /** Create an error/warning set for collection of multiple error/warnings. * \return Newly allocated set. */ +YASM_LIB_DECL /*@only@*/ yasm_errwarns *yasm_errwarns_create(void); /** Destroy an error/warning set. * \param errwarns error/warning set */ +YASM_LIB_DECL void yasm_errwarns_destroy(/*@only@*/ yasm_errwarns *errwarns); /** Propagate error indicator and warning indicator(s) to an error/warning set. @@ -261,6 +288,7 @@ void yasm_errwarns_destroy(/*@only@*/ yasm_errwarns *errwarns); * \param errwarns error/warning set * \param line virtual line */ +YASM_LIB_DECL void yasm_errwarn_propagate(yasm_errwarns *errwarns, unsigned long line); /** Get total number of errors logged. @@ -268,6 +296,7 @@ void yasm_errwarn_propagate(yasm_errwarns *errwarns, unsigned long line); * \param warning_as_error if nonzero, warnings are treated as errors. * \return Number of errors. */ +YASM_LIB_DECL unsigned int yasm_errwarns_num_errors(yasm_errwarns *errwarns, int warning_as_error); @@ -299,6 +328,7 @@ typedef void (*yasm_print_warning_func) * \param print_error function called to print out errors * \param print_warning function called to print out warnings */ +YASM_LIB_DECL void yasm_errwarns_output_all (yasm_errwarns *errwarns, yasm_linemap *lm, int warning_as_error, yasm_print_error_func print_error, yasm_print_warning_func print_warning); @@ -308,12 +338,14 @@ void yasm_errwarns_output_all * \param ch possibly unprintable character * \return Printable string representation (static buffer). */ +YASM_LIB_DECL char *yasm__conv_unprint(int ch); /** Hook for library users to map to gettext() if GNU gettext is being used. * \param msgid message catalog identifier * \return Translated message. */ +YASM_LIB_DECL extern const char * (*yasm_gettext_hook) (const char *msgid); #endif diff --git a/libyasm/expr.h b/libyasm/expr.h index 990452f2..96d1796c 100644 --- a/libyasm/expr.h +++ b/libyasm/expr.h @@ -34,6 +34,10 @@ #ifndef YASM_EXPR_H #define YASM_EXPR_H +#ifndef YASM_LIB_DECL +#define YASM_LIB_DECL +#endif + /** Type of an expression item. Types are listed in canonical sorting order. * See expr_order_terms(). * Note #YASM_EXPR_PRECBC must be used carefully (in a-b pairs), as only @@ -86,6 +90,7 @@ struct yasm_expr { * \param line virtual line (where expression defined) * \return Newly allocated expression. */ +YASM_LIB_DECL /*@only@*/ yasm_expr *yasm_expr_create (yasm_expr_op op, /*@only@*/ yasm_expr__item *a, /*@only@*/ /*@null@*/ yasm_expr__item *b, unsigned long line); @@ -94,36 +99,42 @@ struct yasm_expr { * \param precbc preceding bytecode * \return Newly allocated expression item. */ +YASM_LIB_DECL /*@only@*/ yasm_expr__item *yasm_expr_precbc(/*@keep@*/ yasm_bytecode *precbc); /** Create a new symbol expression item. * \param sym symbol * \return Newly allocated expression item. */ +YASM_LIB_DECL /*@only@*/ yasm_expr__item *yasm_expr_sym(/*@keep@*/ yasm_symrec *sym); /** Create a new expression expression item. * \param e expression * \return Newly allocated expression item. */ +YASM_LIB_DECL /*@only@*/ yasm_expr__item *yasm_expr_expr(/*@keep@*/ yasm_expr *e); /** Create a new intnum expression item. * \param intn intnum * \return Newly allocated expression item. */ +YASM_LIB_DECL /*@only@*/ yasm_expr__item *yasm_expr_int(/*@keep@*/ yasm_intnum *intn); /** Create a new floatnum expression item. * \param flt floatnum * \return Newly allocated expression item. */ +YASM_LIB_DECL /*@only@*/ yasm_expr__item *yasm_expr_float(/*@keep@*/ yasm_floatnum *flt); /** Create a new register expression item. * \param reg register * \return Newly allocated expression item. */ +YASM_LIB_DECL /*@only@*/ yasm_expr__item *yasm_expr_reg(uintptr_t reg); /** Create a new expression tree e=l op r. @@ -165,6 +176,7 @@ yasm_expr *yasm_expr_copy(const yasm_expr *e); /** Destroy (free allocated memory for) an expression. * \param e expression */ +YASM_LIB_DECL void yasm_expr_destroy(/*@only@*/ /*@null@*/ yasm_expr *e); /** Determine if an expression is a specified operation (at the top level). @@ -173,6 +185,7 @@ void yasm_expr_destroy(/*@only@*/ /*@null@*/ yasm_expr *e); * \return Nonzero if the expression was the specified operation at the top * level, zero otherwise. */ +YASM_LIB_DECL int yasm_expr_is_op(const yasm_expr *e, yasm_expr_op op); /** Extra transformation function for yasm_expr__level_tree(). @@ -196,6 +209,7 @@ typedef /*@only@*/ yasm_expr * (*yasm_expr_xform_func) * \param expr_xform_extra_data data to pass to expr_xform_extra * \return Leveled expression. */ +YASM_LIB_DECL /*@only@*/ /*@null@*/ yasm_expr *yasm_expr__level_tree (/*@returned@*/ /*@only@*/ /*@null@*/ yasm_expr *e, int fold_const, int simplify_ident, int simplify_reg_mul, int calc_bc_dist, @@ -220,6 +234,7 @@ typedef /*@only@*/ yasm_expr * (*yasm_expr_xform_func) * The input expression is modified such that on return, it's the * offset expression. */ +YASM_LIB_DECL /*@only@*/ /*@null@*/ yasm_expr *yasm_expr_extract_deep_segoff(yasm_expr **ep); /** Extract the segment portion of a SEG:OFF expression, leaving the offset. @@ -229,6 +244,7 @@ typedef /*@only@*/ yasm_expr * (*yasm_expr_xform_func) * expression is modified such that on return, it's the offset * expression. */ +YASM_LIB_DECL /*@only@*/ /*@null@*/ yasm_expr *yasm_expr_extract_segoff(yasm_expr **ep); /** Extract the right portion (y) of a x WRT y expression, leaving the left @@ -239,6 +255,7 @@ typedef /*@only@*/ yasm_expr * (*yasm_expr_xform_func) * input expression is modified such that on return, it's the left side * of the WRT expression. */ +YASM_LIB_DECL /*@only@*/ /*@null@*/ yasm_expr *yasm_expr_extract_wrt(yasm_expr **ep); /** Get the integer value of an expression if it's just an integer. @@ -249,6 +266,7 @@ typedef /*@only@*/ yasm_expr * (*yasm_expr_xform_func) * integers, ie floats, non-valued labels, registers); otherwise the * intnum value of the expression. */ +YASM_LIB_DECL /*@dependent@*/ /*@null@*/ yasm_intnum *yasm_expr_get_intnum (yasm_expr **ep, int calc_bc_dist); @@ -258,6 +276,7 @@ typedef /*@only@*/ yasm_expr * (*yasm_expr_xform_func) * \return NULL if the expression is too complex; otherwise the symbol value of * the expression. */ +YASM_LIB_DECL /*@dependent@*/ /*@null@*/ const yasm_symrec *yasm_expr_get_symrec (yasm_expr **ep, int simplify); @@ -267,6 +286,7 @@ typedef /*@only@*/ yasm_expr * (*yasm_expr_xform_func) * \return NULL if the expression is too complex; otherwise the register value * of the expression. */ +YASM_LIB_DECL /*@dependent@*/ /*@null@*/ const uintptr_t *yasm_expr_get_reg (yasm_expr **ep, int simplify); @@ -274,6 +294,7 @@ typedef /*@only@*/ yasm_expr * (*yasm_expr_xform_func) * \param e expression * \param f file */ +YASM_LIB_DECL void yasm_expr_print(/*@null@*/ const yasm_expr *e, FILE *f); /** Traverse over expression tree in order (const version). @@ -284,6 +305,7 @@ void yasm_expr_print(/*@null@*/ const yasm_expr *e, FILE *f); * \return Stops early (and returns 1) if func returns 1. * Otherwise returns 0. */ +YASM_LIB_DECL int yasm_expr__traverse_leaves_in_const (const yasm_expr *e, /*@null@*/ void *d, int (*func) (/*@null@*/ const yasm_expr__item *ei, /*@null@*/ void *d)); @@ -296,6 +318,7 @@ int yasm_expr__traverse_leaves_in_const * \return Stops early (and returns 1) if func returns 1. * Otherwise returns 0. */ +YASM_LIB_DECL int yasm_expr__traverse_leaves_in (yasm_expr *e, /*@null@*/ void *d, int (*func) (/*@null@*/ yasm_expr__item *ei, /*@null@*/ void *d)); @@ -308,6 +331,7 @@ int yasm_expr__traverse_leaves_in * \param e expression * \note Only performs reordering on *one* level (no recursion). */ +YASM_LIB_DECL void yasm_expr__order_terms(yasm_expr *e); /** Copy entire expression EXCEPT for index "except" at *top level only*. @@ -315,6 +339,7 @@ void yasm_expr__order_terms(yasm_expr *e); * \param except term index not to copy; -1 to copy all terms * \return Newly allocated copy of expression. */ +YASM_LIB_DECL yasm_expr *yasm_expr__copy_except(const yasm_expr *e, int except); /** Test if expression contains an item. Searches recursively into @@ -323,6 +348,7 @@ yasm_expr *yasm_expr__copy_except(const yasm_expr *e, int except); * \param t type of item to look for * \return Nonzero if expression contains an item of type t, zero if not. */ +YASM_LIB_DECL int yasm_expr__contains(const yasm_expr *e, yasm_expr__type t); /** Transform symrec-symrec terms in expression into #YASM_EXPR_SUBST items. @@ -333,6 +359,7 @@ int yasm_expr__contains(const yasm_expr *e, yasm_expr__type t); * pair, bytecode pair (bc2-bc1), and cbd (callback data) * \return Number of transformations made. */ +YASM_LIB_DECL int yasm_expr__bc_dist_subst(yasm_expr **ep, void *cbd, void (*callback) (unsigned int subst, yasm_bytecode *precbc, @@ -346,6 +373,7 @@ int yasm_expr__bc_dist_subst(yasm_expr **ep, void *cbd, * \param items items array * \return 1 on error (index out of range). */ +YASM_LIB_DECL int yasm_expr__subst(yasm_expr *e, unsigned int num_items, const yasm_expr__item *items); diff --git a/libyasm/file.h b/libyasm/file.h index 4a1cd005..f257faed 100644 --- a/libyasm/file.h +++ b/libyasm/file.h @@ -34,6 +34,10 @@ #ifndef YASM_FILE_H #define YASM_FILE_H +#ifndef YASM_LIB_DECL +#define YASM_LIB_DECL +#endif + /** Re2c scanner state. */ typedef struct yasm_scanner { unsigned char *bot; /**< Bottom of scan buffer */ @@ -48,11 +52,13 @@ typedef struct yasm_scanner { /** Initialize scanner state. * \param scanner Re2c scanner state */ +YASM_LIB_DECL void yasm_scanner_initialize(yasm_scanner *scanner); /** Frees any memory used by scanner state; does not free state itself. * \param scanner Re2c scanner state */ +YASM_LIB_DECL void yasm_scanner_delete(yasm_scanner *scanner); /** Fill a scanner state structure with data coming from an input function. @@ -64,6 +70,7 @@ void yasm_scanner_delete(yasm_scanner *scanner); * \return 1 if this was the first time this function was called on this * scanner state, 0 otherwise. */ +YASM_LIB_DECL int yasm_fill_helper (yasm_scanner *scanner, unsigned char **cursor, size_t (*input_func) (void *d, unsigned char *buf, size_t max), @@ -78,6 +85,7 @@ int yasm_fill_helper * \param str C-style string (updated in place) * \param len length of string (updated with new length) */ +YASM_LIB_DECL void yasm_unescape_cstring(unsigned char *str, size_t *len); /** Split a UNIX pathname into head (directory) and tail (base filename) @@ -87,6 +95,7 @@ void yasm_unescape_cstring(unsigned char *str, size_t *len); * \param tail (returned) base filename * \return Length of head (directory). */ +YASM_LIB_DECL size_t yasm__splitpath_unix(const char *path, /*@out@*/ const char **tail); /** Split a Windows pathname into head (directory) and tail (base filename) @@ -96,6 +105,7 @@ size_t yasm__splitpath_unix(const char *path, /*@out@*/ const char **tail); * \param tail (returned) base filename * \return Length of head (directory). */ +YASM_LIB_DECL size_t yasm__splitpath_win(const char *path, /*@out@*/ const char **tail); /** Split a pathname into head (directory) and tail (base filename) portions. @@ -119,6 +129,7 @@ size_t yasm__splitpath_win(const char *path, /*@out@*/ const char **tail); * \internal * \return Current working directory pathname (newly allocated). */ +YASM_LIB_DECL /*@only@*/ char *yasm__getcwd(void); /** Convert a UNIX relative or absolute pathname into an absolute pathname. @@ -126,6 +137,7 @@ size_t yasm__splitpath_win(const char *path, /*@out@*/ const char **tail); * \param path pathname * \return Absolute version of path (newly allocated). */ +YASM_LIB_DECL /*@only@*/ char *yasm__abspath_unix(const char *path); /** Convert a Windows relative or absolute pathname into an absolute pathname. @@ -133,6 +145,7 @@ size_t yasm__splitpath_win(const char *path, /*@out@*/ const char **tail); * \param path pathname * \return Absolute version of path (newly allocated). */ +YASM_LIB_DECL /*@only@*/ char *yasm__abspath_win(const char *path); /** Convert a relative or absolute pathname into an absolute pathname. @@ -159,6 +172,7 @@ size_t yasm__splitpath_win(const char *path, /*@out@*/ const char **tail); * \param to to pathname * \return Combined path (newly allocated). */ +YASM_LIB_DECL char *yasm__combpath_unix(const char *from, const char *to); /** Build a Windows pathname that is equivalent to accessing the "to" pathname @@ -169,6 +183,7 @@ char *yasm__combpath_unix(const char *from, const char *to); * \param to to pathname * \return Combined path (newly allocated). */ +YASM_LIB_DECL char *yasm__combpath_win(const char *from, const char *to); /** Build a pathname that is equivalent to accessing the "to" pathname @@ -208,16 +223,19 @@ char *yasm__combpath_win(const char *from, const char *to); * may be passed if this is unwanted. * \return fopen'ed include file, or NULL if not found. */ +YASM_LIB_DECL /*@null@*/ FILE *yasm_fopen_include (const char *iname, const char *from, const char *mode, /*@null@*/ /*@out@*/ /*@only@*/ char **oname); /** Delete any stored include paths added by yasm_add_include_path(). */ +YASM_LIB_DECL void yasm_delete_include_paths(void); /** Iterate through include paths. */ +YASM_LIB_DECL const char * yasm_get_include_dir(void **iter); /** Add an include path for use by yasm_fopen_include(). @@ -226,6 +244,7 @@ const char * yasm_get_include_dir(void **iter); * * \param path path to add */ +YASM_LIB_DECL void yasm_add_include_path(const char *path); /** Write an 8-bit value to a buffer, incrementing buffer pointer. @@ -356,6 +375,7 @@ void yasm_add_include_path(const char *path); * \param f file * \return 1 if the write was successful, 0 if not (just like fwrite()). */ +YASM_LIB_DECL size_t yasm_fwrite_16_l(unsigned short val, FILE *f); /** Direct-to-file version of YASM_SAVE_32_L(). @@ -365,6 +385,7 @@ size_t yasm_fwrite_16_l(unsigned short val, FILE *f); * \param f file * \return 1 if the write was successful, 0 if not (just like fwrite()). */ +YASM_LIB_DECL size_t yasm_fwrite_32_l(unsigned long val, FILE *f); /** Direct-to-file version of YASM_SAVE_16_B(). @@ -374,6 +395,7 @@ size_t yasm_fwrite_32_l(unsigned long val, FILE *f); * \param f file * \return 1 if the write was successful, 0 if not (just like fwrite()). */ +YASM_LIB_DECL size_t yasm_fwrite_16_b(unsigned short val, FILE *f); /** Direct-to-file version of YASM_SAVE_32_B(). @@ -383,6 +405,7 @@ size_t yasm_fwrite_16_b(unsigned short val, FILE *f); * \param f file * \return 1 if the write was successful, 0 if not (just like fwrite()). */ +YASM_LIB_DECL size_t yasm_fwrite_32_b(unsigned long val, FILE *f); /** Read an 8-bit value from a buffer, incrementing buffer pointer. diff --git a/libyasm/floatnum.h b/libyasm/floatnum.h index 15696a56..8fa3d1d5 100644 --- a/libyasm/floatnum.h +++ b/libyasm/floatnum.h @@ -36,10 +36,16 @@ #ifndef YASM_FLOATNUM_H #define YASM_FLOATNUM_H +#ifndef YASM_LIB_DECL +#define YASM_LIB_DECL +#endif + /** Initialize floatnum internal data structures. */ +YASM_LIB_DECL void yasm_floatnum_initialize(void); /** Clean up internal floatnum allocations. */ +YASM_LIB_DECL void yasm_floatnum_cleanup(void); /** Create a new floatnum from a decimal string. The input string must be in @@ -47,17 +53,20 @@ void yasm_floatnum_cleanup(void); * \param str floating point decimal string * \return Newly allocated floatnum. */ +YASM_LIB_DECL /*@only@*/ yasm_floatnum *yasm_floatnum_create(const char *str); /** Duplicate a floatnum. * \param flt floatnum * \return Newly allocated floatnum with the same value as flt. */ +YASM_LIB_DECL /*@only@*/ yasm_floatnum *yasm_floatnum_copy(const yasm_floatnum *flt); /** Destroy (free allocated memory for) a floatnum. * \param flt floatnum */ +YASM_LIB_DECL void yasm_floatnum_destroy(/*@only@*/ yasm_floatnum *flt); /** Floating point calculation function: acc = acc op operand. @@ -68,6 +77,7 @@ void yasm_floatnum_destroy(/*@only@*/ yasm_floatnum *flt); * \param operand floatnum operand * \return Nonzero on error. */ +YASM_LIB_DECL int yasm_floatnum_calc(yasm_floatnum *acc, yasm_expr_op op, yasm_floatnum *operand); @@ -78,6 +88,7 @@ int yasm_floatnum_calc(yasm_floatnum *acc, yasm_expr_op op, * \return Nonzero if flt can't fit into single precision: -1 if underflow * occurred, 1 if overflow occurred. */ +YASM_LIB_DECL int yasm_floatnum_get_int(const yasm_floatnum *flt, /*@out@*/ unsigned long *ret_val); @@ -98,6 +109,7 @@ int yasm_floatnum_get_int(const yasm_floatnum *flt, * \return Nonzero if flt can't fit into the specified precision: -1 if * underflow occurred, 1 if overflow occurred. */ +YASM_LIB_DECL int yasm_floatnum_get_sized(const yasm_floatnum *flt, unsigned char *ptr, size_t destsize, size_t valsize, size_t shift, int bigendian, int warn); @@ -110,12 +122,14 @@ int yasm_floatnum_get_sized(const yasm_floatnum *flt, unsigned char *ptr, * \param size number of bits of output space * \return 1 if valid size, 0 if invalid size. */ +YASM_LIB_DECL int yasm_floatnum_check_size(const yasm_floatnum *flt, size_t size); /** Print various representations of a floatnum. For debugging purposes only. * \param f file * \param flt floatnum */ +YASM_LIB_DECL void yasm_floatnum_print(const yasm_floatnum *flt, FILE *f); #endif diff --git a/libyasm/hamt.h b/libyasm/hamt.h index d33bbe3b..c54172b7 100644 --- a/libyasm/hamt.h +++ b/libyasm/hamt.h @@ -34,6 +34,10 @@ #ifndef YASM_HAMT_H #define YASM_HAMT_H +#ifndef YASM_LIB_DECL +#define YASM_LIB_DECL +#endif + /** Hash array mapped trie data structure (opaque type). */ typedef struct HAMT HAMT; /** Hash array mapped trie entry (opaque type). */ @@ -45,6 +49,7 @@ typedef struct HAMTEntry HAMTEntry; * \param error_func function called on internal error * \return New, empty, hash array mapped trie. */ +YASM_LIB_DECL HAMT *HAMT_create(int nocase, /*@exits@*/ void (*error_func) (const char *file, unsigned int line, const char *message)); @@ -53,6 +58,7 @@ HAMT *HAMT_create(int nocase, /*@exits@*/ void (*error_func) * \param hamt Hash array mapped trie * \param deletefunc Data deletion function */ +YASM_LIB_DECL void HAMT_destroy(/*@only@*/ HAMT *hamt, void (*deletefunc) (/*@only@*/ void *data)); @@ -72,6 +78,7 @@ void HAMT_destroy(/*@only@*/ HAMT *hamt, * \param deletefunc Data deletion function if data is replaced * \return Data now associated with key. */ +YASM_LIB_DECL /*@dependent@*/ void *HAMT_insert(HAMT *hamt, /*@dependent@*/ const char *str, /*@only@*/ void *data, int *replace, void (*deletefunc) (/*@only@*/ void *data)); @@ -81,6 +88,7 @@ void HAMT_destroy(/*@only@*/ HAMT *hamt, * \param str Key * \return NULL if key/data not present in HAMT, otherwise associated data. */ +YASM_LIB_DECL /*@dependent@*/ /*@null@*/ void *HAMT_search(HAMT *hamt, const char *str); /** Traverse over all keys in HAMT, calling function on each data item. @@ -90,6 +98,7 @@ void HAMT_destroy(/*@only@*/ HAMT *hamt, * \return Stops early (and returns func's return value) if func returns a * nonzero value; otherwise 0. */ +YASM_LIB_DECL int HAMT_traverse(HAMT *hamt, /*@null@*/ void *d, int (*func) (/*@dependent@*/ /*@null@*/ void *node, /*@null@*/ void *d)); @@ -98,18 +107,21 @@ int HAMT_traverse(HAMT *hamt, /*@null@*/ void *d, * \param hamt Hash array mapped trie * \return First entry in HAMT, or NULL if HAMT is empty. */ +YASM_LIB_DECL const HAMTEntry *HAMT_first(const HAMT *hamt); /** Get the next entry in a HAMT. * \param prev Previous entry in HAMT * \return Next entry in HAMT, or NULL if no more entries. */ +YASM_LIB_DECL /*@null@*/ const HAMTEntry *HAMT_next(const HAMTEntry *prev); /** Get the corresponding data for a HAMT entry. * \param entry HAMT entry (as returned by HAMT_first() and HAMT_next()) * \return Corresponding data item. */ +YASM_LIB_DECL void *HAMTEntry_get_data(const HAMTEntry *entry); #endif diff --git a/libyasm/insn.h b/libyasm/insn.h index 905b2f96..9fdf0ebb 100644 --- a/libyasm/insn.h +++ b/libyasm/insn.h @@ -34,6 +34,10 @@ #ifndef YASM_INSN_H #define YASM_INSN_H +#ifndef YASM_LIB_DECL +#define YASM_LIB_DECL +#endif + /** Base structure for an effective address. As with all base * structures, must be present as the first element in any * #yasm_arch implementation of an effective address. @@ -154,24 +158,28 @@ struct yasm_insn { * \param ea effective address * \param segreg segment register (0 if none) */ +YASM_LIB_DECL void yasm_ea_set_segreg(yasm_effaddr *ea, uintptr_t segreg); /** Create an instruction operand from a register. * \param reg register * \return Newly allocated operand. */ +YASM_LIB_DECL yasm_insn_operand *yasm_operand_create_reg(uintptr_t reg); /** Create an instruction operand from a segment register. * \param segreg segment register * \return Newly allocated operand. */ +YASM_LIB_DECL yasm_insn_operand *yasm_operand_create_segreg(uintptr_t segreg); /** Create an instruction operand from an effective address. * \param ea effective address * \return Newly allocated operand. */ +YASM_LIB_DECL yasm_insn_operand *yasm_operand_create_mem(/*@only@*/ yasm_effaddr *ea); /** Create an instruction operand from an immediate expression. @@ -180,6 +188,7 @@ yasm_insn_operand *yasm_operand_create_mem(/*@only@*/ yasm_effaddr *ea); * \param val immediate expression * \return Newly allocated operand. */ +YASM_LIB_DECL yasm_insn_operand *yasm_operand_create_imm(/*@only@*/ yasm_expr *val); /** Get the first operand in an instruction. @@ -205,6 +214,7 @@ yasm_insn_operand *yasm_insn_op_next(yasm_insn_operand *op); * \return If operand was actually appended (it wasn't NULL), the operand; * otherwise NULL. */ +YASM_LIB_DECL /*@null@*/ yasm_insn_operand *yasm_insn_ops_append (yasm_insn *insn, /*@returned@*/ /*@null@*/ yasm_insn_operand *op); @@ -213,18 +223,21 @@ yasm_insn_operand *yasm_insn_op_next(yasm_insn_operand *op); * \param insn instruction * \param prefix data that identifies the prefix */ +YASM_LIB_DECL void yasm_insn_add_prefix(yasm_insn *insn, uintptr_t prefix); /** Associate a segment prefix with an instruction. * \param insn instruction * \param segreg data that identifies the segment register */ +YASM_LIB_DECL void yasm_insn_add_seg_prefix(yasm_insn *insn, uintptr_t segreg); /** Initialize the common parts of an instruction. * \internal For use by yasm_arch implementations only. * \param insn instruction */ +YASM_LIB_DECL void yasm_insn_initialize(/*@out@*/ yasm_insn *insn); /** Delete the common parts of an instruction. @@ -233,6 +246,7 @@ void yasm_insn_initialize(/*@out@*/ yasm_insn *insn); * \param content if nonzero, deletes content of each operand * \param arch architecture */ +YASM_LIB_DECL void yasm_insn_delete(yasm_insn *insn, void (*ea_destroy) (/*@only@*/ yasm_effaddr *)); @@ -243,12 +257,14 @@ void yasm_insn_delete(yasm_insn *insn, * \param indent_level indentation level * \param arch architecture */ +YASM_LIB_DECL void yasm_insn_print(const yasm_insn *insn, FILE *f, int indent_level); /** Finalize the common parts of an instruction. * \internal For use by yasm_arch implementations only. * \param insn instruction */ +YASM_LIB_DECL void yasm_insn_finalize(yasm_insn *insn); #endif diff --git a/libyasm/intnum.h b/libyasm/intnum.h index 382f5fb1..8e1529fc 100644 --- a/libyasm/intnum.h +++ b/libyasm/intnum.h @@ -34,34 +34,44 @@ #ifndef YASM_INTNUM_H #define YASM_INTNUM_H +#ifndef YASM_LIB_DECL +#define YASM_LIB_DECL +#endif + /** Initialize intnum internal data structures. */ +YASM_LIB_DECL void yasm_intnum_initialize(void); /** Clean up internal intnum allocations. */ +YASM_LIB_DECL void yasm_intnum_cleanup(void); /** Create a new intnum from a decimal string. * \param str decimal string * \return Newly allocated intnum. */ +YASM_LIB_DECL /*@only@*/ yasm_intnum *yasm_intnum_create_dec(char *str); /** Create a new intnum from a binary string. * \param str binary string * \return Newly allocated intnum. */ +YASM_LIB_DECL /*@only@*/ yasm_intnum *yasm_intnum_create_bin(char *str); /** Create a new intnum from an octal string. * \param str octal string * \return Newly allocated intnum. */ +YASM_LIB_DECL /*@only@*/ yasm_intnum *yasm_intnum_create_oct(char *str); /** Create a new intnum from a hexidecimal string. * \param str hexidecimal string * \return Newly allocated intnum. */ +YASM_LIB_DECL /*@only@*/ yasm_intnum *yasm_intnum_create_hex(char *str); /** Convert character constant to integer value, using NASM rules. NASM syntax @@ -70,18 +80,21 @@ void yasm_intnum_cleanup(void); * \param str character constant string * \return Newly allocated intnum. */ +YASM_LIB_DECL /*@only@*/ yasm_intnum *yasm_intnum_create_charconst_nasm(const char *str); /** Create a new intnum from an unsigned integer value. * \param i unsigned integer value * \return Newly allocated intnum. */ +YASM_LIB_DECL /*@only@*/ yasm_intnum *yasm_intnum_create_uint(unsigned long i); /** Create a new intnum from an signed integer value. * \param i signed integer value * \return Newly allocated intnum. */ +YASM_LIB_DECL /*@only@*/ yasm_intnum *yasm_intnum_create_int(long i); /** Create a new intnum from LEB128-encoded form. @@ -91,6 +104,7 @@ void yasm_intnum_cleanup(void); * \return Newly allocated intnum. Number of bytes read returned into * bytes_read parameter. */ +YASM_LIB_DECL /*@only@*/ yasm_intnum *yasm_intnum_create_leb128 (const unsigned char *ptr, int sign, /*@out@*/ unsigned long *size); @@ -101,6 +115,7 @@ void yasm_intnum_cleanup(void); * \param srcsize source buffer size (in bytes) * \param bigendian endianness (nonzero=big, zero=little) */ +YASM_LIB_DECL /*@only@*/ yasm_intnum *yasm_intnum_create_sized (unsigned char *ptr, int sign, size_t srcsize, int bigendian); @@ -108,11 +123,13 @@ void yasm_intnum_cleanup(void); * \param intn intnum * \return Newly allocated intnum with the same value as intn. */ +YASM_LIB_DECL /*@only@*/ yasm_intnum *yasm_intnum_copy(const yasm_intnum *intn); /** Destroy (free allocated memory for) an intnum. * \param intn intnum */ +YASM_LIB_DECL void yasm_intnum_destroy(/*@only@*/ yasm_intnum *intn); /** Floating point calculation function: acc = acc op operand. @@ -123,6 +140,7 @@ void yasm_intnum_destroy(/*@only@*/ yasm_intnum *intn); * \param operand intnum operand * \return Nonzero if error occurred. */ +YASM_LIB_DECL int yasm_intnum_calc(yasm_intnum *acc, yasm_expr_op op, yasm_intnum *operand); /** Compare two intnums. @@ -130,53 +148,62 @@ int yasm_intnum_calc(yasm_intnum *acc, yasm_expr_op op, yasm_intnum *operand); * \param intn2 second intnum * \return -1 if intn1 < intn2, 0 if intn1 == intn2, 1 if intn1 > intn2. */ +YASM_LIB_DECL int yasm_intnum_compare(const yasm_intnum *intn1, const yasm_intnum *intn2); /** Zero an intnum. * \param intn intnum */ +YASM_LIB_DECL void yasm_intnum_zero(yasm_intnum *intn); /** Set an intnum to the value of another intnum. * \param intn intnum * \param val intnum to get value from */ +YASM_LIB_DECL void yasm_intnum_set(yasm_intnum *intn, const yasm_intnum *val); /** Set an intnum to an unsigned integer. * \param intn intnum * \param val integer value */ +YASM_LIB_DECL void yasm_intnum_set_uint(yasm_intnum *intn, unsigned long val); /** Set an intnum to an signed integer. * \param intn intnum * \param val integer value */ +YASM_LIB_DECL void yasm_intnum_set_int(yasm_intnum *intn, long val); /** Simple value check for 0. * \param acc intnum * \return Nonzero if acc==0. */ +YASM_LIB_DECL int yasm_intnum_is_zero(const yasm_intnum *acc); /** Simple value check for 1. * \param acc intnum * \return Nonzero if acc==1. */ +YASM_LIB_DECL int yasm_intnum_is_pos1(const yasm_intnum *acc); /** Simple value check for -1. * \param acc intnum * \return Nonzero if acc==-1. */ +YASM_LIB_DECL int yasm_intnum_is_neg1(const yasm_intnum *acc); /** Simple sign check. * \param acc intnum * \return -1 if negative, 0 if zero, +1 if positive */ +YASM_LIB_DECL int yasm_intnum_sign(const yasm_intnum *acc); /** Convert an intnum to an unsigned 32-bit value. The value is in "standard" @@ -186,6 +213,7 @@ int yasm_intnum_sign(const yasm_intnum *acc); * \param intn intnum * \return Unsigned 32-bit value of intn. */ +YASM_LIB_DECL unsigned long yasm_intnum_get_uint(const yasm_intnum *intn); /** Convert an intnum to a signed 32-bit value. The value is in "standard" C @@ -195,6 +223,7 @@ unsigned long yasm_intnum_get_uint(const yasm_intnum *intn); * \param intn intnum * \return Signed 32-bit value of intn. */ +YASM_LIB_DECL long yasm_intnum_get_int(const yasm_intnum *intn); /** Output #yasm_intnum to buffer in little-endian or big-endian. Puts the @@ -211,6 +240,7 @@ long yasm_intnum_get_int(const yasm_intnum *intn); * \param warn enables standard warnings (value doesn't fit into valsize * bits): <0=signed warnings, >0=unsigned warnings, 0=no warn */ +YASM_LIB_DECL void yasm_intnum_get_sized(const yasm_intnum *intn, unsigned char *ptr, size_t destsize, size_t valsize, int shift, int bigendian, int warn); @@ -225,6 +255,7 @@ void yasm_intnum_get_sized(const yasm_intnum *intn, unsigned char *ptr, * 2 => (signed min, unsigned max) * \return Nonzero if intnum will fit. */ +YASM_LIB_DECL int yasm_intnum_check_size(const yasm_intnum *intn, size_t size, size_t rshift, int rangetype); @@ -234,6 +265,7 @@ int yasm_intnum_check_size(const yasm_intnum *intn, size_t size, * \param high high end of range (inclusive) * \return Nonzero if intnum is within range. */ +YASM_LIB_DECL int yasm_intnum_in_range(const yasm_intnum *intn, long low, long high); /** Output #yasm_intnum to buffer in LEB128-encoded form. @@ -242,6 +274,7 @@ int yasm_intnum_in_range(const yasm_intnum *intn, long low, long high); * \param sign signedness of LEB128 encoding (0=unsigned, 1=signed) * \return Number of bytes generated. */ +YASM_LIB_DECL unsigned long yasm_intnum_get_leb128(const yasm_intnum *intn, unsigned char *ptr, int sign); @@ -250,6 +283,7 @@ unsigned long yasm_intnum_get_leb128(const yasm_intnum *intn, * \param sign signedness of LEB128 encoding (0=unsigned, 1=signed) * \return Number of bytes. */ +YASM_LIB_DECL unsigned long yasm_intnum_size_leb128(const yasm_intnum *intn, int sign); /** Output integer to buffer in signed LEB128-encoded form. @@ -257,12 +291,14 @@ unsigned long yasm_intnum_size_leb128(const yasm_intnum *intn, int sign); * \param ptr pointer to storage for output bytes * \return Number of bytes generated. */ +YASM_LIB_DECL unsigned long yasm_get_sleb128(long v, unsigned char *ptr); /** Calculate number of bytes signed LEB128-encoded form of integer will take. * \param v integer * \return Number of bytes. */ +YASM_LIB_DECL unsigned long yasm_size_sleb128(long v); /** Output integer to buffer in unsigned LEB128-encoded form. @@ -270,12 +306,14 @@ unsigned long yasm_size_sleb128(long v); * \param ptr pointer to storage for output bytes * \return Number of bytes generated. */ +YASM_LIB_DECL unsigned long yasm_get_uleb128(unsigned long v, unsigned char *ptr); /** Calculate number of bytes unsigned LEB128-encoded form of integer will take. * \param v integer * \return Number of bytes. */ +YASM_LIB_DECL unsigned long yasm_size_uleb128(unsigned long v); /** Get an intnum as a signed decimal string. The returned string will @@ -284,12 +322,14 @@ unsigned long yasm_size_uleb128(unsigned long v); * \return Newly allocated string containing the decimal representation of * the intnum. */ +YASM_LIB_DECL /*@only@*/ char *yasm_intnum_get_str(const yasm_intnum *intn); /** Print an intnum. For debugging purposes. * \param f file * \param intn intnum */ +YASM_LIB_DECL void yasm_intnum_print(const yasm_intnum *intn, FILE *f); #endif diff --git a/libyasm/inttree.h b/libyasm/inttree.h index 972f5713..de037e44 100644 --- a/libyasm/inttree.h +++ b/libyasm/inttree.h @@ -2,6 +2,10 @@ #ifndef YASM_INTTREE_H #define YASM_INTTREE_H +#ifndef YASM_LIB_DECL +#define YASM_LIB_DECL +#endif + /* The interval_tree.h and interval_tree.cc files contain code for * interval trees implemented using red-black-trees as described in * the book _Introduction_To_Algorithms_ by Cormen, Leisserson, @@ -45,14 +49,22 @@ typedef struct IntervalTree { unsigned int recursionNodeStackTop; } IntervalTree; +YASM_LIB_DECL IntervalTree *IT_create(void); +YASM_LIB_DECL void IT_destroy(IntervalTree *); +YASM_LIB_DECL void IT_print(const IntervalTree *); +YASM_LIB_DECL void *IT_delete_node(IntervalTree *, IntervalTreeNode *, long *low, long *high); +YASM_LIB_DECL IntervalTreeNode *IT_insert(IntervalTree *, long low, long high, void *data); +YASM_LIB_DECL IntervalTreeNode *IT_get_predecessor(const IntervalTree *, IntervalTreeNode *); +YASM_LIB_DECL IntervalTreeNode *IT_get_successor(const IntervalTree *, IntervalTreeNode *); +YASM_LIB_DECL void IT_enumerate(IntervalTree *, long low, long high, void *cbd, void (*callback) (IntervalTreeNode *node, void *cbd)); diff --git a/libyasm/linemap.h b/libyasm/linemap.h index 18062989..03912551 100644 --- a/libyasm/linemap.h +++ b/libyasm/linemap.h @@ -34,20 +34,27 @@ #ifndef YASM_LINEMAP_H #define YASM_LINEMAP_H +#ifndef YASM_LIB_DECL +#define YASM_LIB_DECL +#endif + /** Create a new line mapping repository. * \return New repository. */ +YASM_LIB_DECL yasm_linemap *yasm_linemap_create(void); /** Clean up any memory allocated for a repository. * \param linemap line mapping repository */ +YASM_LIB_DECL void yasm_linemap_destroy(yasm_linemap *linemap); /** Get the current line position in a repository. * \param linemap line mapping repository * \return Current virtual line. */ +YASM_LIB_DECL unsigned long yasm_linemap_get_current(yasm_linemap *linemap); /** Get bytecode and source line information, if any, for a virtual line. @@ -59,6 +66,7 @@ unsigned long yasm_linemap_get_current(yasm_linemap *linemap); * \note If source line information is not available, bcp and sourcep targets * are set to NULL. */ +YASM_LIB_DECL int yasm_linemap_get_source(yasm_linemap *linemap, unsigned long line, /*@null@*/ yasm_bytecode **bcp, const char **sourcep); @@ -71,6 +79,7 @@ int yasm_linemap_get_source(yasm_linemap *linemap, unsigned long line, * \param source source code line * \note The source code line pointer is NOT kept, it is strdup'ed. */ +YASM_LIB_DECL void yasm_linemap_add_source(yasm_linemap *linemap, /*@null@*/ yasm_bytecode *bc, const char *source); @@ -79,6 +88,7 @@ void yasm_linemap_add_source(yasm_linemap *linemap, * \param linemap line mapping repository * \return The current (new) virtual line. */ +YASM_LIB_DECL unsigned long yasm_linemap_goto_next(yasm_linemap *linemap); /** Set a new file/line physical association starting point at the current @@ -89,6 +99,7 @@ unsigned long yasm_linemap_goto_next(yasm_linemap *linemap); * \param file_line physical line number * \param line_inc line increment */ +YASM_LIB_DECL void yasm_linemap_set(yasm_linemap *linemap, /*@null@*/ const char *filename, unsigned long file_line, unsigned long line_inc); @@ -100,6 +111,7 @@ void yasm_linemap_set(yasm_linemap *linemap, /*@null@*/ const char *filename, * \param file_line physical line number * \return The virtual line number of the poked association. */ +YASM_LIB_DECL unsigned long yasm_linemap_poke(yasm_linemap *linemap, /*@null@*/ const char *filename, unsigned long file_line); @@ -110,6 +122,7 @@ unsigned long yasm_linemap_poke(yasm_linemap *linemap, * \param filename physical file name (output) * \param file_line physical line number (output) */ +YASM_LIB_DECL void yasm_linemap_lookup(yasm_linemap *linemap, unsigned long line, /*@out@*/ const char **filename, /*@out@*/ unsigned long *file_line); @@ -122,6 +135,7 @@ void yasm_linemap_lookup(yasm_linemap *linemap, unsigned long line, * \return Stops early (and returns func's return value) if func returns a * nonzero value; otherwise 0. */ +YASM_LIB_DECL int yasm_linemap_traverse_filenames (yasm_linemap *linemap, /*@null@*/ void *d, int (*func) (const char *filename, void *d)); diff --git a/libyasm/md5.h b/libyasm/md5.h index a7dbc9ab..7226f1dc 100644 --- a/libyasm/md5.h +++ b/libyasm/md5.h @@ -7,6 +7,10 @@ #ifndef YASM_MD5_H #define YASM_MD5_H +#ifndef YASM_LIB_DECL +#define YASM_LIB_DECL +#endif + /* Unlike previous versions of this code, uint32 need not be exactly 32 bits, merely 32 bits or more. Choosing a data type which is 32 bits instead of 64 is not important; speed is considerably more @@ -19,10 +23,14 @@ typedef struct yasm_md5_context { unsigned char in[64]; } yasm_md5_context; +YASM_LIB_DECL void yasm_md5_init(yasm_md5_context *context); +YASM_LIB_DECL void yasm_md5_update(yasm_md5_context *context, unsigned char const *buf, unsigned long len); +YASM_LIB_DECL void yasm_md5_final(unsigned char digest[16], yasm_md5_context *context); +YASM_LIB_DECL void yasm_md5_transform(unsigned long buf[4], const unsigned char in[64]); #endif /* !YASM_MD5_H */ diff --git a/libyasm/module.h b/libyasm/module.h index b6b4f60b..ce2e14b7 100644 --- a/libyasm/module.h +++ b/libyasm/module.h @@ -27,6 +27,10 @@ #ifndef YASM_MODULE_H #define YASM_MODULE_H +#ifndef YASM_LIB_DECL +#define YASM_LIB_DECL +#endif + typedef enum yasm_module_type { YASM_MODULE_ARCH = 0, YASM_MODULE_DBGFMT, @@ -36,6 +40,7 @@ typedef enum yasm_module_type { YASM_MODULE_PREPROC } yasm_module_type; +YASM_LIB_DECL /*@dependent@*/ /*@null@*/ void *yasm_load_module (yasm_module_type type, const char *keyword); @@ -52,6 +57,7 @@ typedef enum yasm_module_type { #define yasm_load_preproc(keyword) \ yasm_load_module(YASM_MODULE_PREPROC, keyword) +YASM_LIB_DECL void yasm_list_modules (yasm_module_type type, void (*printfunc) (const char *name, const char *keyword)); @@ -69,6 +75,7 @@ void yasm_list_modules #define yasm_list_preproc(func) \ yasm_list_modules(YASM_MODULE_PREPROC, func) +YASM_LIB_DECL void yasm_register_module(yasm_module_type type, const char *keyword, void *data); diff --git a/libyasm/phash.h b/libyasm/phash.h index c4cc88a0..f446eeab 100644 --- a/libyasm/phash.h +++ b/libyasm/phash.h @@ -10,6 +10,12 @@ Source is http://burtleburtle.net/bob/c/lookupa.h ------------------------------------------------------------------------------ */ +#ifndef YASM_LIB_DECL +#define YASM_LIB_DECL +#endif + +YASM_LIB_DECL unsigned long phash_lookup(const char *k, size_t length, unsigned long level); +YASM_LIB_DECL void phash_checksum(const char *k, size_t length, unsigned long *state); diff --git a/libyasm/section.h b/libyasm/section.h index d42040a6..b17f887d 100644 --- a/libyasm/section.h +++ b/libyasm/section.h @@ -34,6 +34,10 @@ #ifndef YASM_SECTION_H #define YASM_SECTION_H +#ifndef YASM_LIB_DECL +#define YASM_LIB_DECL +#endif + /** Basic YASM relocation. Object formats will need to extend this * structure with additional fields for relocation type, etc. */ @@ -79,6 +83,7 @@ struct yasm_object { * \param dbgfmt_module debug format module * \return Newly allocated object, or NULL on error. */ +YASM_LIB_DECL /*@null@*/ /*@only@*/ yasm_object *yasm_object_create (const char *src_filename, const char *obj_filename, /*@kept@*/ yasm_arch *arch, @@ -99,6 +104,7 @@ struct yasm_object { * already exists) * \return New section. */ +YASM_LIB_DECL /*@dependent@*/ yasm_section *yasm_object_get_general (yasm_object *object, const char *name, unsigned long align, int code, int res_only, /*@out@*/ int *isnew, unsigned long line); @@ -113,6 +119,7 @@ struct yasm_object { * \param line virtual line (from yasm_linemap) * \return 0 if directive recognized, nonzero if unrecognized. */ +YASM_LIB_DECL int yasm_object_directive(yasm_object *object, const char *name, const char *parser, yasm_valparamhead *valparams, yasm_valparamhead *objext_valparams, @@ -122,6 +129,7 @@ int yasm_object_directive(yasm_object *object, const char *name, * object and all bytecodes within those sections are also deleted. * \param object object */ +YASM_LIB_DECL void yasm_object_destroy(/*@only@*/ yasm_object *object); /** Print an object. For debugging purposes. @@ -129,6 +137,7 @@ void yasm_object_destroy(/*@only@*/ yasm_object *object); * \param f file * \param indent_level indentation level */ +YASM_LIB_DECL void yasm_object_print(const yasm_object *object, FILE *f, int indent_level); /** Finalize an object after parsing. @@ -136,6 +145,7 @@ void yasm_object_print(const yasm_object *object, FILE *f, int indent_level); * \param errwarns error/warning set * \note Errors/warnings are stored into errwarns. */ +YASM_LIB_DECL void yasm_object_finalize(yasm_object *object, yasm_errwarns *errwarns); /** Traverses all sections in an object, calling a function on each section. @@ -145,6 +155,7 @@ void yasm_object_finalize(yasm_object *object, yasm_errwarns *errwarns); * \return Stops early (and returns func's return value) if func returns a * nonzero value; otherwise 0. */ +YASM_LIB_DECL int yasm_object_sections_traverse (yasm_object *object, /*@null@*/ void *d, int (*func) (yasm_section *sect, /*@null@*/ void *d)); @@ -154,6 +165,7 @@ int yasm_object_sections_traverse * \param name section name * \return Section matching name, or NULL if no match found. */ +YASM_LIB_DECL /*@dependent@*/ /*@null@*/ yasm_section *yasm_object_find_general (yasm_object *object, const char *name); @@ -161,6 +173,7 @@ int yasm_object_sections_traverse * \param object object * \param src_filename new source filename (e.g. "file.asm") */ +YASM_LIB_DECL void yasm_object_set_source_fn(yasm_object *object, const char *src_filename); /** Optimize an object. Takes the unoptimized object and optimizes it. @@ -169,24 +182,28 @@ void yasm_object_set_source_fn(yasm_object *object, const char *src_filename); * \param errwarns error/warning set * \note Optimization failures are stored into errwarns. */ +YASM_LIB_DECL void yasm_object_optimize(yasm_object *object, yasm_errwarns *errwarns); /** Determine if a section is flagged to contain code. * \param sect section * \return Nonzero if section is flagged to contain code. */ +YASM_LIB_DECL int yasm_section_is_code(yasm_section *sect); /** Get yasm_optimizer-specific flags. For yasm_optimizer use only. * \param sect section * \return Optimizer-specific flags. */ +YASM_LIB_DECL unsigned long yasm_section_get_opt_flags(const yasm_section *sect); /** Set yasm_optimizer-specific flags. For yasm_optimizer use only. * \param sect section * \param opt_flags optimizer-specific flags. */ +YASM_LIB_DECL void yasm_section_set_opt_flags(yasm_section *sect, unsigned long opt_flags); /** Determine if a section was declared as the "default" section (e.g. not @@ -194,18 +211,21 @@ void yasm_section_set_opt_flags(yasm_section *sect, unsigned long opt_flags); * \param sect section * \return Nonzero if section was declared as default. */ +YASM_LIB_DECL int yasm_section_is_default(const yasm_section *sect); /** Set section "default" flag to a new value. * \param sect section * \param def new value of default flag */ +YASM_LIB_DECL void yasm_section_set_default(yasm_section *sect, int def); /** Get object owner of a section. * \param sect section * \return Object this section is a part of. */ +YASM_LIB_DECL yasm_object *yasm_section_get_object(const yasm_section *sect); /** Get assocated data for a section and data callback. @@ -213,6 +233,7 @@ yasm_object *yasm_section_get_object(const yasm_section *sect); * \param callback callback used when adding data * \return Associated data (NULL if none). */ +YASM_LIB_DECL /*@dependent@*/ /*@null@*/ void *yasm_section_get_data (yasm_section *sect, const yasm_assoc_data_callback *callback); @@ -222,6 +243,7 @@ yasm_object *yasm_section_get_object(const yasm_section *sect); * \param callback callback * \param data data to associate */ +YASM_LIB_DECL void yasm_section_add_data(yasm_section *sect, const yasm_assoc_data_callback *callback, /*@null@*/ /*@only@*/ void *data); @@ -235,6 +257,7 @@ void yasm_section_add_data(yasm_section *sect, * The section will destroy the relocation address; it is the caller's * responsibility to destroy any other allocated data. */ +YASM_LIB_DECL void yasm_section_add_reloc(yasm_section *sect, yasm_reloc *reloc, void (*destroy_func) (/*@only@*/ void *reloc)); @@ -242,6 +265,7 @@ void yasm_section_add_reloc(yasm_section *sect, yasm_reloc *reloc, * \param sect section * \return First relocation for section. NULL if no relocations. */ +YASM_LIB_DECL /*@null@*/ yasm_reloc *yasm_section_relocs_first(yasm_section *sect); /** Get the next relocation for a section. @@ -258,6 +282,7 @@ void yasm_section_add_reloc(yasm_section *sect, yasm_reloc *reloc, * \param addrp address of relocation within section (returned) * \param symp relocated symbol (returned) */ +YASM_LIB_DECL void yasm_reloc_get(yasm_reloc *reloc, yasm_intnum **addrp, /*@dependent@*/ yasm_symrec **symp); @@ -266,6 +291,7 @@ void yasm_reloc_get(yasm_reloc *reloc, yasm_intnum **addrp, * \return First bytecode in section (at least one empty bytecode is always * present). */ +YASM_LIB_DECL yasm_bytecode *yasm_section_bcs_first(yasm_section *sect); /** Get the last bytecode in a section. @@ -273,6 +299,7 @@ yasm_bytecode *yasm_section_bcs_first(yasm_section *sect); * \return Last bytecode in section (at least one empty bytecode is always * present). */ +YASM_LIB_DECL yasm_bytecode *yasm_section_bcs_last(yasm_section *sect); /** Add bytecode to the end of a section. @@ -284,6 +311,7 @@ yasm_bytecode *yasm_section_bcs_last(yasm_section *sect); * \return If bytecode was actually appended (it wasn't NULL or empty), the * bytecode; otherwise NULL. */ +YASM_LIB_DECL /*@only@*/ /*@null@*/ yasm_bytecode *yasm_section_bcs_append (yasm_section *sect, /*@returned@*/ /*@only@*/ /*@null@*/ yasm_bytecode *bc); @@ -298,6 +326,7 @@ yasm_bytecode *yasm_section_bcs_last(yasm_section *sect); * \note If errwarns is non-NULL, yasm_errwarn_propagate() is called after * each call to func (with the bytecode's line number). */ +YASM_LIB_DECL int yasm_section_bcs_traverse (yasm_section *sect, /*@null@*/ yasm_errwarns *errwarns, /*@null@*/ void *d, int (*func) (yasm_bytecode *bc, /*@null@*/ void *d)); @@ -306,6 +335,7 @@ int yasm_section_bcs_traverse * \param sect section * \return Section name. */ +YASM_LIB_DECL /*@observer@*/ const char *yasm_section_get_name(const yasm_section *sect); /** Change alignment of a section. @@ -313,6 +343,7 @@ int yasm_section_bcs_traverse * \param align alignment in bytes * \param line virtual line */ +YASM_LIB_DECL void yasm_section_set_align(yasm_section *sect, unsigned long align, unsigned long line); @@ -320,6 +351,7 @@ void yasm_section_set_align(yasm_section *sect, unsigned long align, * \param sect section * \return Alignment in bytes (0 if none). */ +YASM_LIB_DECL unsigned long yasm_section_get_align(const yasm_section *sect); /** Print a section. For debugging purposes. @@ -328,6 +360,7 @@ unsigned long yasm_section_get_align(const yasm_section *sect); * \param sect section * \param print_bcs if nonzero, print bytecodes within section */ +YASM_LIB_DECL void yasm_section_print(/*@null@*/ const yasm_section *sect, FILE *f, int indent_level, int print_bcs); diff --git a/libyasm/symrec.h b/libyasm/symrec.h index 349dcce5..10706d9d 100644 --- a/libyasm/symrec.h +++ b/libyasm/symrec.h @@ -34,6 +34,10 @@ #ifndef YASM_SYMREC_H #define YASM_SYMREC_H +#ifndef YASM_LIB_DECL +#define YASM_LIB_DECL +#endif + /** Symbol status. YASM_SYM_DEFINED is set by yasm_symtab_define_label(), * yasm_symtab_define_equ(), or yasm_symtab_declare()/yasm_symrec_declare() * with a visibility of #YASM_SYM_EXTERN or #YASM_SYM_COMMON. @@ -58,6 +62,7 @@ typedef enum yasm_sym_vis { } yasm_sym_vis; /** Create a new symbol table. */ +YASM_LIB_DECL yasm_symtab *yasm_symtab_create(void); /** Destroy a symbol table and all internal symbols. @@ -65,6 +70,7 @@ yasm_symtab *yasm_symtab_create(void); * \warning All yasm_symrec *'s into this symbol table become invalid after * this is called! */ +YASM_LIB_DECL void yasm_symtab_destroy(/*@only@*/ yasm_symtab *symtab); /** Get a reference to the symbol table's "absolute" symbol. This is @@ -74,6 +80,7 @@ void yasm_symtab_destroy(/*@only@*/ yasm_symtab *symtab); * \param symtab symbol table * \return Absolute symbol (dependent pointer, do not free). */ +YASM_LIB_DECL /*@dependent@*/ yasm_symrec *yasm_symtab_abs_sym(yasm_symtab *symtab); /** Get a reference to (use) a symbol. The symbol does not necessarily need to @@ -83,6 +90,7 @@ void yasm_symtab_destroy(/*@only@*/ yasm_symtab *symtab); * \param line virtual line where referenced * \return Symbol (dependent pointer, do not free). */ +YASM_LIB_DECL /*@dependent@*/ yasm_symrec *yasm_symtab_use (yasm_symtab *symtab, const char *name, unsigned long line); @@ -94,6 +102,7 @@ void yasm_symtab_destroy(/*@only@*/ yasm_symtab *symtab); * \return Symbol (dependent pointer, do not free). May be NULL if symbol * doesn't exist. */ +YASM_LIB_DECL /*@null@*/ /*@dependent@*/ yasm_symrec *yasm_symtab_get (yasm_symtab *symtab, const char *name); @@ -104,6 +113,7 @@ void yasm_symtab_destroy(/*@only@*/ yasm_symtab *symtab); * \param line virtual line of EQU * \return Symbol (dependent pointer, do not free). */ +YASM_LIB_DECL /*@dependent@*/ yasm_symrec *yasm_symtab_define_equ (yasm_symtab *symtab, const char *name, /*@keep@*/ yasm_expr *e, unsigned long line); @@ -117,6 +127,7 @@ void yasm_symtab_destroy(/*@only@*/ yasm_symtab *symtab); * \param line virtual line of label * \return Symbol (dependent pointer, do not free). */ +YASM_LIB_DECL /*@dependent@*/ yasm_symrec *yasm_symtab_define_label (yasm_symtab *symtab, const char *name, /*@dependent@*/ yasm_bytecode *precbc, int in_table, unsigned long line); @@ -131,6 +142,7 @@ void yasm_symtab_destroy(/*@only@*/ yasm_symtab *symtab); * \param line virtual line of label * \return Symbol (dependent pointer, do not free). */ +YASM_LIB_DECL /*@dependent@*/ yasm_symrec *yasm_symtab_define_curpos (yasm_symtab *symtab, const char *name, /*@dependent@*/ yasm_bytecode *precbc, unsigned long line); @@ -143,6 +155,7 @@ void yasm_symtab_destroy(/*@only@*/ yasm_symtab *symtab); * \param vis symbol visibility * \return Symbol (dependent pointer, do not free). */ +YASM_LIB_DECL /*@dependent@*/ yasm_symrec *yasm_symtab_define_special (yasm_symtab *symtab, const char *name, yasm_sym_vis vis); @@ -154,6 +167,7 @@ void yasm_symtab_destroy(/*@only@*/ yasm_symtab *symtab); * \param line virtual line of visibility-setting * \return Symbol (dependent pointer, do not free). */ +YASM_LIB_DECL /*@dependent@*/ yasm_symrec *yasm_symtab_declare (yasm_symtab *symtab, const char *name, yasm_sym_vis vis, unsigned long line); @@ -164,6 +178,7 @@ void yasm_symtab_destroy(/*@only@*/ yasm_symtab *symtab); * \param vis visibility * \param line virtual line of visibility-setting */ +YASM_LIB_DECL void yasm_symrec_declare(yasm_symrec *symrec, yasm_sym_vis vis, unsigned long line); @@ -182,6 +197,7 @@ typedef int (*yasm_symtab_traverse_callback) * \return Nonzero value returned by callback function if it ever returned * nonzero. */ +YASM_LIB_DECL int /*@alt void@*/ yasm_symtab_traverse (yasm_symtab *symtab, /*@null@*/ void *d, yasm_symtab_traverse_callback func); @@ -193,12 +209,14 @@ typedef struct yasm_symtab_iter yasm_symtab_iter; * \param symtab symbol table * \return Iterator for the symbol table. */ +YASM_LIB_DECL const yasm_symtab_iter *yasm_symtab_first(const yasm_symtab *symtab); /** Move a symbol table iterator to the next symbol in the symbol table. * \param prev Previous iterator value * \return Next iterator value, or NULL if no more symbols in the table. */ +YASM_LIB_DECL /*@null@*/ const yasm_symtab_iter *yasm_symtab_next (const yasm_symtab_iter *prev); @@ -206,6 +224,7 @@ const yasm_symtab_iter *yasm_symtab_first(const yasm_symtab *symtab); * \param cur iterator value * \return Corresponding symbol. */ +YASM_LIB_DECL yasm_symrec *yasm_symtab_iter_value(const yasm_symtab_iter *cur); /** Finalize symbol table after parsing stage. Checks for symbols that are @@ -215,6 +234,7 @@ yasm_symrec *yasm_symtab_iter_value(const yasm_symtab_iter *cur); * \param errwarns error/warning set * \note Errors/warnings are stored into errwarns. */ +YASM_LIB_DECL void yasm_symtab_parser_finalize(yasm_symtab *symtab, int undef_extern, yasm_errwarns *errwarns); @@ -223,48 +243,56 @@ void yasm_symtab_parser_finalize(yasm_symtab *symtab, int undef_extern, * \param f file * \param indent_level indentation level */ +YASM_LIB_DECL void yasm_symtab_print(yasm_symtab *symtab, FILE *f, int indent_level); /** Get the name of a symbol. * \param sym symbol * \return Symbol name. */ +YASM_LIB_DECL /*@observer@*/ const char *yasm_symrec_get_name(const yasm_symrec *sym); /** Get the visibility of a symbol. * \param sym symbol * \return Symbol visibility. */ +YASM_LIB_DECL yasm_sym_vis yasm_symrec_get_visibility(const yasm_symrec *sym); /** Get the status of a symbol. * \param sym symbol * \return Symbol status. */ +YASM_LIB_DECL yasm_sym_status yasm_symrec_get_status(const yasm_symrec *sym); /** Get the virtual line of where a symbol was first defined. * \param sym symbol * \return line virtual line */ +YASM_LIB_DECL unsigned long yasm_symrec_get_def_line(const yasm_symrec *sym); /** Get the virtual line of where a symbol was first declared. * \param sym symbol * \return line virtual line */ +YASM_LIB_DECL unsigned long yasm_symrec_get_decl_line(const yasm_symrec *sym); /** Get the virtual line of where a symbol was first used. * \param sym symbol * \return line virtual line */ +YASM_LIB_DECL unsigned long yasm_symrec_get_use_line(const yasm_symrec *sym); /** Get EQU value of a symbol. * \param sym symbol * \return EQU value, or NULL if symbol is not an EQU or is not defined. */ +YASM_LIB_DECL /*@observer@*/ /*@null@*/ const yasm_expr *yasm_symrec_get_equ (const yasm_symrec *sym); @@ -277,6 +305,7 @@ typedef /*@dependent@*/ yasm_bytecode *yasm_symrec_get_label_bytecodep; * \return 0 if not symbol is not a label or if the symbol's visibility is * #YASM_SYM_EXTERN or #YASM_SYM_COMMON (not defined in the file). */ +YASM_LIB_DECL int yasm_symrec_get_label(const yasm_symrec *sym, /*@out@*/ yasm_symrec_get_label_bytecodep *precbc); @@ -285,24 +314,28 @@ int yasm_symrec_get_label(const yasm_symrec *sym, * \param sym symbol * \return 0 if symbol is not the "absolute" symbol, nonzero otherwise. */ +YASM_LIB_DECL int yasm_symrec_is_abs(const yasm_symrec *sym); /** Determine if symbol is a special symbol. * \param sym symbol * \return 0 if symbol is not a special symbol, nonzero otherwise. */ +YASM_LIB_DECL int yasm_symrec_is_special(const yasm_symrec *sym); /** Determine if symbol is a label representing the current assembly position. * \param sym symbol * \return 0 if symbol is not a current position label, nonzero otherwise. */ +YASM_LIB_DECL int yasm_symrec_is_curpos(const yasm_symrec *sym); /** Set object-extended valparams. * \param sym symbol * \param objext_valparams object-extended valparams */ +YASM_LIB_DECL void yasm_symrec_set_objext_valparams (yasm_symrec *sym, /*@only@*/ yasm_valparamhead *objext_valparams); @@ -311,6 +344,7 @@ void yasm_symrec_set_objext_valparams * \param sym symbol * \return Object-extended valparams (NULL if none). */ +YASM_LIB_DECL /*@null@*/ /*@dependent@*/ yasm_valparamhead *yasm_symrec_get_objext_valparams (yasm_symrec *sym); @@ -318,6 +352,7 @@ void yasm_symrec_set_objext_valparams * \param sym symbol * \param common_size common size expression */ +YASM_LIB_DECL void yasm_symrec_set_common_size (yasm_symrec *sym, /*@only@*/ yasm_expr *common_size); @@ -326,6 +361,7 @@ void yasm_symrec_set_common_size * \param sym symbol * \return Common size (NULL if none). */ +YASM_LIB_DECL /*@dependent@*/ /*@null@*/ yasm_expr **yasm_symrec_get_common_size (yasm_symrec *sym); @@ -334,6 +370,7 @@ void yasm_symrec_set_common_size * \param callback callback used when adding data * \return Associated data (NULL if none). */ +YASM_LIB_DECL /*@dependent@*/ /*@null@*/ void *yasm_symrec_get_data (yasm_symrec *sym, const yasm_assoc_data_callback *callback); @@ -343,6 +380,7 @@ void yasm_symrec_set_common_size * \param callback callback * \param data data to associate */ +YASM_LIB_DECL void yasm_symrec_add_data(yasm_symrec *sym, const yasm_assoc_data_callback *callback, /*@only@*/ /*@null@*/ void *data); @@ -352,6 +390,7 @@ void yasm_symrec_add_data(yasm_symrec *sym, * \param indent_level indentation level * \param sym symbol */ +YASM_LIB_DECL void yasm_symrec_print(const yasm_symrec *sym, FILE *f, int indent_level); #endif diff --git a/libyasm/valparam.h b/libyasm/valparam.h index 6914435b..3a7e8df6 100644 --- a/libyasm/valparam.h +++ b/libyasm/valparam.h @@ -34,6 +34,10 @@ #ifndef YASM_VALPARAM_H #define YASM_VALPARAM_H +#ifndef YASM_LIB_DECL +#define YASM_LIB_DECL +#endif + /** Value/parameter pair. \internal */ struct yasm_valparam { /*@reldef@*/ STAILQ_ENTRY(yasm_valparam) link; /**< Next pair in list */ @@ -101,6 +105,7 @@ struct yasm_directive { * \param objext_valparams object format-specific value/parameters * \param line virtual line (from yasm_linemap) */ +YASM_LIB_DECL void yasm_call_directive(const yasm_directive *directive, yasm_object *object, yasm_valparamhead *valparams, yasm_valparamhead *objext_valparams, @@ -112,6 +117,7 @@ void yasm_call_directive(const yasm_directive *directive, yasm_object *object, * \param id_prefix identifier prefix for raw identifiers * \return Newly allocated valparam. */ +YASM_LIB_DECL yasm_valparam *yasm_vp_create_id(/*@keep@*/ char *v, /*@keep@*/ char *p, int id_prefix); @@ -120,6 +126,7 @@ yasm_valparam *yasm_vp_create_id(/*@keep@*/ char *v, /*@keep@*/ char *p, * \param p parameter * \return Newly allocated valparam. */ +YASM_LIB_DECL yasm_valparam *yasm_vp_create_string(/*@keep@*/ char *v, /*@keep@*/ char *p); /** Create a new valparam with expression parameter. @@ -127,6 +134,7 @@ yasm_valparam *yasm_vp_create_string(/*@keep@*/ char *v, /*@keep@*/ char *p); * \param p parameter * \return Newly allocated valparam. */ +YASM_LIB_DECL yasm_valparam *yasm_vp_create_expr(/*@keep@*/ char *v, /*@keep@*/ yasm_expr *p); @@ -138,6 +146,7 @@ yasm_valparam *yasm_vp_create_expr(/*@keep@*/ char *v, * \return Expression, or NULL if vp is NULL or the parameter cannot be * converted to an expression. */ +YASM_LIB_DECL /*@null@*/ /*@only@*/ yasm_expr *yasm_vp_expr (const yasm_valparam *vp, yasm_symtab *symtab, unsigned long line); @@ -147,6 +156,7 @@ yasm_valparam *yasm_vp_create_expr(/*@keep@*/ char *v, * \return String, or NULL if vp is NULL or the parameter cannot be realized * as a string. */ +YASM_LIB_DECL /*@null@*/ /*@dependent@*/ const char *yasm_vp_string(const yasm_valparam *vp); /** Get a valparam parameter as an identifier. @@ -154,16 +164,19 @@ yasm_valparam *yasm_vp_create_expr(/*@keep@*/ char *v, * \return Identifier (string), or NULL if vp is NULL or the parameter is not * an identifier. */ +YASM_LIB_DECL /*@null@*/ /*@dependent@*/ const char *yasm_vp_id(const yasm_valparam *vp); /** Create a new linked list of valparams. * \return Newly allocated valparam list. */ +YASM_LIB_DECL yasm_valparamhead *yasm_vps_create(void); /** Destroy a list of valparams (created with yasm_vps_create). * \param headp list of valparams */ +YASM_LIB_DECL void yasm_vps_destroy(yasm_valparamhead *headp); /** Initialize linked list of valparams. @@ -179,6 +192,7 @@ void yasm_vps_initialize(/*@out@*/ yasm_valparamhead *headp); * \warning Deletes val/params. * \param headp linked list */ +YASM_LIB_DECL void yasm_vps_delete(yasm_valparamhead *headp); /** Append valparam to tail of linked list. @@ -225,6 +239,7 @@ void yasm_vps_append(yasm_valparamhead *headp, /*@keep@*/ yasm_valparam *vp); * \param f file * \param headp linked list */ +YASM_LIB_DECL void yasm_vps_print(/*@null@*/ const yasm_valparamhead *headp, FILE *f); /** Directive valparam parse helper structure. */ @@ -280,6 +295,7 @@ typedef struct yasm_dir_help { * \return -1 on error, 1 if any arguments matched (including via * catch-all callback), 0 if no match. */ +YASM_LIB_DECL int yasm_dir_helper(void *obj, yasm_valparam *vp_first, unsigned long line, const yasm_dir_help *help, size_t nhelp, void *data, int (*helper_valparam) (void *object, @@ -297,6 +313,7 @@ int yasm_dir_helper(void *obj, yasm_valparam *vp_first, unsigned long line, * \param arg flag to set * \return 0 */ +YASM_LIB_DECL int yasm_dir_helper_flag_set(void *obj, yasm_valparam *vp, unsigned long line, void *data, uintptr_t arg); @@ -310,6 +327,7 @@ int yasm_dir_helper_flag_set(void *obj, yasm_valparam *vp, unsigned long line, * \param arg flag to OR * \return 0 */ +YASM_LIB_DECL int yasm_dir_helper_flag_or(void *obj, yasm_valparam *vp, unsigned long line, void *data, uintptr_t arg); @@ -323,6 +341,7 @@ int yasm_dir_helper_flag_or(void *obj, yasm_valparam *vp, unsigned long line, * \param arg flag to AND * \return 0 */ +YASM_LIB_DECL int yasm_dir_helper_flag_and(void *obj, yasm_valparam *vp, unsigned long line, void *data, uintptr_t arg); @@ -340,6 +359,7 @@ int yasm_dir_helper_flag_and(void *obj, yasm_valparam *vp, unsigned long line, * \param arg unused argument * \return -1 on error, 0 otherwise. */ +YASM_LIB_DECL int yasm_dir_helper_expr(void *obj, yasm_valparam *vp, unsigned long line, void *data, uintptr_t arg); @@ -357,6 +377,7 @@ int yasm_dir_helper_expr(void *obj, yasm_valparam *vp, unsigned long line, * \param arg unused argument * \return -1 on error, 0 otherwise. */ +YASM_LIB_DECL int yasm_dir_helper_intn(void *obj, yasm_valparam *vp, unsigned long line, void *data, uintptr_t arg); @@ -373,6 +394,7 @@ int yasm_dir_helper_intn(void *obj, yasm_valparam *vp, unsigned long line, * \param arg unused * \return -1 on error, 0 otherwise. */ +YASM_LIB_DECL int yasm_dir_helper_string(void *obj, yasm_valparam *vp, unsigned long line, void *data, uintptr_t arg); @@ -384,6 +406,7 @@ int yasm_dir_helper_string(void *obj, yasm_valparam *vp, unsigned long line, * \param data unused * \return 0 */ +YASM_LIB_DECL int yasm_dir_helper_valparam_warn(void *obj, yasm_valparam *vp, unsigned long line, void *data); #endif diff --git a/libyasm/value.h b/libyasm/value.h index cc6d3469..3d51ebaf 100644 --- a/libyasm/value.h +++ b/libyasm/value.h @@ -34,6 +34,10 @@ #ifndef YASM_VALUE_H #define YASM_VALUE_H +#ifndef YASM_LIB_DECL +#define YASM_LIB_DECL +#endif + /** Initialize a #yasm_value with just an expression. No processing is * performed, the expression is simply stuck into value.abs and the other * fields are initialized. Use yasm_expr_extract_value() to perform "smart" @@ -45,6 +49,7 @@ * \param e expression (kept) * \param size value size (in bits) */ +YASM_LIB_DECL void yasm_value_initialize(/*@out@*/ yasm_value *value, /*@null@*/ /*@kept@*/ yasm_expr *e, unsigned int size); @@ -56,6 +61,7 @@ void yasm_value_initialize(/*@out@*/ yasm_value *value, * \param sym symrec * \param size value size (in bits) */ +YASM_LIB_DECL void yasm_value_init_sym(/*@out@*/ yasm_value *value, /*@null@*/ yasm_symrec *sym, unsigned int size); @@ -64,11 +70,13 @@ void yasm_value_init_sym(/*@out@*/ yasm_value *value, * \param value value (copy to create) * \param orig original value */ +YASM_LIB_DECL void yasm_value_init_copy(yasm_value *value, const yasm_value *orig); /** Frees any memory inside value; does not free value itself. * \param value value */ +YASM_LIB_DECL void yasm_value_delete(yasm_value *value); /** Set a value to be relative to the current assembly position rather than @@ -80,6 +88,7 @@ void yasm_value_delete(yasm_value *value); * \note If value is just an absolute value, will get an absolute symrec to * reference to (via bc's symbol table). */ +YASM_LIB_DECL void yasm_value_set_curpos_rel(yasm_value *value, yasm_bytecode *bc, unsigned int ip_rel); @@ -89,6 +98,7 @@ void yasm_value_set_curpos_rel(yasm_value *value, yasm_bytecode *bc, * \param precbc previous bytecode to bytecode containing value * \return Nonzero if value could not be split. */ +YASM_LIB_DECL int yasm_value_finalize(yasm_value *value, /*@null@*/ yasm_bytecode *precbc); /** Break a #yasm_expr into a #yasm_value constituent parts. Extracts @@ -110,6 +120,7 @@ int yasm_value_finalize(yasm_value *value, /*@null@*/ yasm_bytecode *precbc); * \note This should only be called after the parse is complete. Calling * before the parse is complete will usually result in an error return. */ +YASM_LIB_DECL int yasm_value_finalize_expr(/*@out@*/ yasm_value *value, /*@null@*/ /*@kept@*/ yasm_expr *e, /*@null@*/ yasm_bytecode *precbc, @@ -126,6 +137,7 @@ int yasm_value_finalize_expr(/*@out@*/ yasm_value *value, * as bc (and there is no WRT or SEG). * \return Intnum if can be resolved to integer value, otherwise NULL. */ +YASM_LIB_DECL /*@null@*/ /*@only@*/ yasm_intnum *yasm_value_get_intnum (yasm_value *value, /*@null@*/ yasm_bytecode *bc, int calc_bc_dist); @@ -148,6 +160,7 @@ int yasm_value_finalize_expr(/*@out@*/ yasm_value *value, * \return 0 if no value output due to value needing relocation; * 1 if value output; -1 if error. */ +YASM_LIB_DECL int yasm_value_output_basic (yasm_value *value, /*@out@*/ unsigned char *buf, size_t destsize, yasm_bytecode *bc, int warn, yasm_arch *arch); @@ -157,6 +170,7 @@ int yasm_value_output_basic * \param indent_level indentation level * \param f file */ +YASM_LIB_DECL void yasm_value_print(const yasm_value *value, FILE *f, int indent_level); #endif diff --git a/libyasm/xmalloc.c b/libyasm/xmalloc.c index d2cd2380..30b30f43 100644 --- a/libyasm/xmalloc.c +++ b/libyasm/xmalloc.c @@ -47,11 +47,15 @@ static void def_xfree(/*@only@*/ /*@out@*/ /*@null@*/ void *p) /*@modifies p@*/; /* storage for global function pointers */ +YASM_LIB_DECL /*@only@*/ /*@out@*/ void * (*yasm_xmalloc) (size_t size) = def_xmalloc; +YASM_LIB_DECL /*@only@*/ void * (*yasm_xcalloc) (size_t nelem, size_t elsize) = def_xcalloc; +YASM_LIB_DECL /*@only@*/ void * (*yasm_xrealloc) (/*@only@*/ /*@out@*/ /*@returned@*/ /*@null@*/ void *oldmem, size_t size) /*@modifies oldmem@*/ = def_xrealloc; +YASM_LIB_DECL void (*yasm_xfree) (/*@only@*/ /*@out@*/ /*@null@*/ void *p) /*@modifies p@*/ = def_xfree; |