slas/asmpp.h

77 lines
2.0 KiB
C

#ifndef ASMPP_H
#define ASMPP_H
#include "asmln.h"
#include "asmdata.h"
#include <stdint.h>
#include <stdbool.h>
typedef struct asmpp_def asmpp_def_t;
typedef struct asmpp_lines asmpp_lines_t;
typedef struct asmpp_macro asmpp_macro_t;
typedef struct asmpp_context asmpp_context_t;
typedef struct asmpp asmpp_t;
// Either outputs a line or handles some builtin macro
typedef int (*asmpp_systemf_t)(asmpp_t* pp, asmln_t* ln);
struct asmpp_def {
int t;
char* value;
asmlnx_t* x;
};
struct asmpp_lines {
asmln_t* line;
asmpp_lines_t* next;
};
struct asmpp_macro {
asmln_t* proto;
asmpp_systemf_t systemf;
asmpp_lines_t* lines;
asmpp_macro_t* next;
};
#define ASMPP_CONTEXT_OUTER 0
#define ASMPP_CONTEXT_MACRO_EXPAND 1
#define ASMPP_CONTEXT_MACRO_COLLECT 2
#define ASMPP_CONTEXT_IF_EXPAND 3
#define ASMPP_CONTEXT_IF_PARSEONLY 4
struct asmpp_context {
//bool collecting;
int type;
uint64_t ifvalue;
asmpp_macro_t* macro;
asmdata_map_t* locals;
asmpp_context_t* next;
};
struct asmpp {
void* udata;
asmpp_systemf_t outputf;
asmdata_map_t* defs;
asmdata_map_t* macros;
asmpp_context_t* context;
};
asmpp_t* asmpp_new(asmpp_systemf_t outputf, void* udata);
void asmpp_delete(asmpp_t* pp);
asmpp_context_t* asmpp_enter(asmpp_t* pp, int type, asmpp_macro_t* macro);
void asmpp_exit(asmpp_t* pp, asmpp_context_t* context);
asmpp_macro_t* asmpp_quickmacro(asmpp_t* pp, asmln_t* proto, asmpp_systemf_t systemf);
asmpp_def_t* asmpp_finddef(asmpp_t* pp, char* name);
asmpp_macro_t* asmpp_findmacro(asmpp_t* pp, char* name, int nparams);
int asmpp_expand(asmpp_t* pp, asmln_t* ln);
bool asmpp_binop(asmpp_t* pp, uint64_t lhsresult, int lhssig, char* op, uint64_t rhsresult, int rhssig, uint64_t* resultp, char** errp, int* signp);
bool asmpp_calc(asmpp_t* pp, int t, char* str, asmlnx_t* x, uint64_t* resultp, char** errp, int* signp);
// From idndef at top of file:
#endif