2 * Direct3D shader assembler
4 * Copyright 2008 Stefan Dösinger
5 * Copyright 2009 Matteo Bruni
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include "wine/port.h"
25 #include "wine/debug.h"
27 #include "d3dcompiler_private.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(asmshader);
33 struct asm_parser asm_ctx;
35 /* Needed lexer functions declarations */
36 void asmshader_error(const char *s);
37 int asmshader_lex(void);
39 void set_rel_reg(struct shader_reg *reg, struct rel_reg *rel) {
40 /* We can have an additional offset without true relative addressing
42 reg->regnum += rel->additional_offset;
43 if(!rel->has_rel_reg) {
46 reg->rel_reg = asm_alloc(sizeof(*reg->rel_reg));
50 reg->rel_reg->type = rel->type;
51 reg->rel_reg->swizzle = rel->swizzle;
52 reg->rel_reg->regnum = rel->rel_regnum;
65 struct shader_reg reg;
83 BWRITER_COMPARISON_TYPE comptype;
88 BWRITERSAMPLER_TEXTURE_TYPE samplertype;
89 struct rel_reg rel_reg;
90 struct src_regs sregs;
93 /* Common instructions between vertex and pixel shaders */
146 /* Vertex shader only instructions */
150 /* Pixel shader only instructions */
154 %token INSTR_TEXCOORD
161 %token INSTR_TEXREG2AR
162 %token INSTR_TEXREG2GB
163 %token INSTR_TEXREG2RGB
164 %token INSTR_TEXM3x2PAD
165 %token INSTR_TEXM3x2TEX
166 %token INSTR_TEXM3x3PAD
167 %token INSTR_TEXM3x3SPEC
168 %token INSTR_TEXM3x3VSPEC
169 %token INSTR_TEXM3x3TEX
170 %token INSTR_TEXDP3TEX
171 %token INSTR_TEXM3x2DEPTH
174 %token INSTR_TEXDEPTH
184 %token <regnum> REG_TEMP
185 %token <regnum> REG_OUTPUT
186 %token <regnum> REG_INPUT
187 %token <regnum> REG_CONSTFLOAT
188 %token <regnum> REG_CONSTINT
189 %token <regnum> REG_CONSTBOOL
190 %token <regnum> REG_TEXTURE
191 %token <regnum> REG_SAMPLER
192 %token <regnum> REG_TEXCRDOUT
196 %token <regnum> REG_VERTEXCOLOR
197 %token <regnum> REG_FRAGCOLOR
204 %token <regnum> REG_LABEL
222 /* Output modifiers */
241 /* Source register modifiers */
243 %token SMOD_SCALEBIAS
253 %token SAMPTYPE_VOLUME
255 /* Usage declaration tokens */
256 %token <regnum> USAGE_POSITION
257 %token <regnum> USAGE_BLENDWEIGHT
258 %token <regnum> USAGE_BLENDINDICES
259 %token <regnum> USAGE_NORMAL
260 %token <regnum> USAGE_PSIZE
261 %token <regnum> USAGE_TEXCOORD
262 %token <regnum> USAGE_TANGENT
263 %token <regnum> USAGE_BINORMAL
264 %token <regnum> USAGE_TESSFACTOR
265 %token <regnum> USAGE_POSITIONT
266 %token <regnum> USAGE_COLOR
267 %token <regnum> USAGE_FOG
268 %token <regnum> USAGE_DEPTH
269 %token <regnum> USAGE_SAMPLE
272 %token <component> COMPONENT
273 %token <immval> IMMVAL
274 %token <immbool> IMMBOOL
276 %type <reg> dreg_name
278 %type <reg> sreg_name
279 %type <reg> relreg_name
282 %type <writemask> writemask
283 %type <wm_components> wm_components
284 %type <swizzle> swizzle
285 %type <sw_components> sw_components
286 %type <modshift> omods
287 %type <modshift> omodifier
288 %type <comptype> comp
289 %type <declaration> dclusage
290 %type <reg> dcl_inputreg
291 %type <samplertype> sampdcl
292 %type <rel_reg> rel_reg
293 %type <reg> predicate
294 %type <immval> immsum
299 shader: version_marker instructions
301 asm_ctx.funcs->end(&asm_ctx);
304 version_marker: VER_VS10
306 TRACE("Vertex shader 1.0\n");
307 create_vs10_parser(&asm_ctx);
311 TRACE("Vertex shader 1.1\n");
312 create_vs11_parser(&asm_ctx);
316 TRACE("Vertex shader 2.0\n");
317 create_vs20_parser(&asm_ctx);
321 TRACE("Vertex shader 2.x\n");
322 create_vs2x_parser(&asm_ctx);
326 TRACE("Vertex shader 3.0\n");
327 create_vs30_parser(&asm_ctx);
331 TRACE("Pixel shader 1.0\n");
332 create_ps10_parser(&asm_ctx);
336 TRACE("Pixel shader 1.1\n");
337 create_ps11_parser(&asm_ctx);
341 TRACE("Pixel shader 1.2\n");
342 create_ps12_parser(&asm_ctx);
346 TRACE("Pixel shader 1.3\n");
347 create_ps13_parser(&asm_ctx);
351 TRACE("Pixel shader 1.4\n");
352 create_ps14_parser(&asm_ctx);
356 TRACE("Pixel shader 2.0\n");
357 create_ps20_parser(&asm_ctx);
361 TRACE("Pixel shader 2.x\n");
362 create_ps2x_parser(&asm_ctx);
366 TRACE("Pixel shader 3.0\n");
367 create_ps30_parser(&asm_ctx);
370 instructions: /* empty */
371 | instructions complexinstr
376 complexinstr: instruction
380 | predicate instruction
382 TRACE("predicate\n");
383 asm_ctx.funcs->predicate(&asm_ctx, &$1);
388 asm_ctx.funcs->coissue(&asm_ctx);
391 instruction: INSTR_ADD omods dreg ',' sregs
394 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_ADD, $2.mod, $2.shift, 0, &$3, &$5, 2);
399 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_NOP, 0, 0, 0, 0, 0, 0);
401 | INSTR_MOV omods dreg ',' sregs
404 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_MOV, $2.mod, $2.shift, 0, &$3, &$5, 1);
406 | INSTR_SUB omods dreg ',' sregs
409 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_SUB, $2.mod, $2.shift, 0, &$3, &$5, 2);
411 | INSTR_MAD omods dreg ',' sregs
414 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_MAD, $2.mod, $2.shift, 0, &$3, &$5, 3);
416 | INSTR_MUL omods dreg ',' sregs
419 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_MUL, $2.mod, $2.shift, 0, &$3, &$5, 2);
421 | INSTR_RCP omods dreg ',' sregs
424 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_RCP, $2.mod, $2.shift, 0, &$3, &$5, 1);
426 | INSTR_RSQ omods dreg ',' sregs
429 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_RSQ, $2.mod, $2.shift, 0, &$3, &$5, 1);
431 | INSTR_DP3 omods dreg ',' sregs
434 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_DP3, $2.mod, $2.shift, 0, &$3, &$5, 2);
436 | INSTR_DP4 omods dreg ',' sregs
439 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_DP4, $2.mod, $2.shift, 0, &$3, &$5, 2);
441 | INSTR_MIN omods dreg ',' sregs
444 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_MIN, $2.mod, $2.shift, 0, &$3, &$5, 2);
446 | INSTR_MAX omods dreg ',' sregs
449 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_MAX, $2.mod, $2.shift, 0, &$3, &$5, 2);
451 | INSTR_SLT omods dreg ',' sregs
454 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_SLT, $2.mod, $2.shift, 0, &$3, &$5, 2);
456 | INSTR_SGE omods dreg ',' sregs
459 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_SGE, $2.mod, $2.shift, 0, &$3, &$5, 2);
461 | INSTR_ABS omods dreg ',' sregs
464 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_ABS, $2.mod, $2.shift, 0, &$3, &$5, 1);
466 | INSTR_EXP omods dreg ',' sregs
469 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_EXP, $2.mod, $2.shift, 0, &$3, &$5, 1);
471 | INSTR_LOG omods dreg ',' sregs
474 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_LOG, $2.mod, $2.shift, 0, &$3, &$5, 1);
476 | INSTR_LOGP omods dreg ',' sregs
479 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_LOGP, $2.mod, $2.shift, 0, &$3, &$5, 1);
481 | INSTR_EXPP omods dreg ',' sregs
484 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_EXPP, $2.mod, $2.shift, 0, &$3, &$5, 1);
486 | INSTR_DST omods dreg ',' sregs
489 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_DST, $2.mod, $2.shift, 0, &$3, &$5, 2);
491 | INSTR_LRP omods dreg ',' sregs
494 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_LRP, $2.mod, $2.shift, 0, &$3, &$5, 3);
496 | INSTR_FRC omods dreg ',' sregs
499 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_FRC, $2.mod, $2.shift, 0, &$3, &$5, 1);
501 | INSTR_POW omods dreg ',' sregs
504 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_POW, $2.mod, $2.shift, 0, &$3, &$5, 2);
506 | INSTR_CRS omods dreg ',' sregs
509 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_CRS, $2.mod, $2.shift, 0, &$3, &$5, 2);
511 | INSTR_SGN omods dreg ',' sregs
514 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_SGN, $2.mod, $2.shift, 0, &$3, &$5, 3);
516 | INSTR_NRM omods dreg ',' sregs
519 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_NRM, $2.mod, $2.shift, 0, &$3, &$5, 1);
521 | INSTR_SINCOS omods dreg ',' sregs
524 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_SINCOS, $2.mod, $2.shift, 0, &$3, &$5, 1);
526 | INSTR_M4x4 omods dreg ',' sregs
529 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_M4x4, $2.mod, $2.shift, 0, &$3, &$5, 2);
531 | INSTR_M4x3 omods dreg ',' sregs
534 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_M4x3, $2.mod, $2.shift, 0, &$3, &$5, 2);
536 | INSTR_M3x4 omods dreg ',' sregs
539 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_M3x4, $2.mod, $2.shift, 0, &$3, &$5, 2);
541 | INSTR_M3x3 omods dreg ',' sregs
544 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_M3x3, $2.mod, $2.shift, 0, &$3, &$5, 2);
546 | INSTR_M3x2 omods dreg ',' sregs
549 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_M3x2, $2.mod, $2.shift, 0, &$3, &$5, 2);
551 | INSTR_DCL dclusage REG_OUTPUT
553 struct shader_reg reg;
554 TRACE("Output reg declaration\n");
555 ZeroMemory(®, sizeof(reg));
556 reg.type = BWRITERSPR_OUTPUT;
560 reg.writemask = BWRITERSP_WRITEMASK_ALL;
561 asm_ctx.funcs->dcl_output(&asm_ctx, $2.dclusage, $2.regnum, ®);
563 | INSTR_DCL dclusage REG_OUTPUT writemask
565 struct shader_reg reg;
566 TRACE("Output reg declaration\n");
567 ZeroMemory(®, sizeof(reg));
568 reg.type = BWRITERSPR_OUTPUT;
573 asm_ctx.funcs->dcl_output(&asm_ctx, $2.dclusage, $2.regnum, ®);
575 | INSTR_DCL dclusage omods dcl_inputreg
577 struct shader_reg reg;
578 TRACE("Input reg declaration\n");
580 asmparser_message(&asm_ctx, "Line %u: Shift modifier not allowed here\n",
582 set_parse_status(&asm_ctx, PARSE_ERR);
584 if(asm_ctx.shader->version == BWRITERPS_VERSION(2, 0) ||
585 asm_ctx.shader->version == BWRITERPS_VERSION(2, 1)) {
586 asmparser_message(&asm_ctx, "Line %u: Declaration not supported in PS 2\n",
588 set_parse_status(&asm_ctx, PARSE_ERR);
590 ZeroMemory(®, sizeof(reg));
592 reg.regnum = $4.regnum;
595 reg.writemask = BWRITERSP_WRITEMASK_ALL;
596 asm_ctx.funcs->dcl_input(&asm_ctx, $2.dclusage, $2.regnum, $3.mod, ®);
598 | INSTR_DCL dclusage omods dcl_inputreg writemask
600 struct shader_reg reg;
601 TRACE("Input reg declaration\n");
603 asmparser_message(&asm_ctx, "Line %u: Shift modifier not allowed here\n",
605 set_parse_status(&asm_ctx, PARSE_ERR);
607 if(asm_ctx.shader->version == BWRITERPS_VERSION(2, 0) ||
608 asm_ctx.shader->version == BWRITERPS_VERSION(2, 1)) {
609 asmparser_message(&asm_ctx, "Line %u: Declaration not supported in PS 2\n",
611 set_parse_status(&asm_ctx, PARSE_ERR);
613 ZeroMemory(®, sizeof(reg));
615 reg.regnum = $4.regnum;
619 asm_ctx.funcs->dcl_input(&asm_ctx, $2.dclusage, $2.regnum, $3.mod, ®);
621 | INSTR_DCL omods dcl_inputreg
623 struct shader_reg reg;
624 TRACE("Input reg declaration\n");
626 asmparser_message(&asm_ctx, "Line %u: Shift modifier not allowed here\n",
628 set_parse_status(&asm_ctx, PARSE_ERR);
630 if(asm_ctx.shader->type != ST_PIXEL) {
631 asmparser_message(&asm_ctx, "Line %u: Declaration needs a semantic\n",
633 set_parse_status(&asm_ctx, PARSE_ERR);
635 ZeroMemory(®, sizeof(reg));
637 reg.regnum = $3.regnum;
640 reg.writemask = BWRITERSP_WRITEMASK_ALL;
641 asm_ctx.funcs->dcl_input(&asm_ctx, 0, 0, $2.mod, ®);
643 | INSTR_DCL omods dcl_inputreg writemask
645 struct shader_reg reg;
646 TRACE("Input reg declaration\n");
648 asmparser_message(&asm_ctx, "Line %u: Shift modifier not allowed here\n",
650 set_parse_status(&asm_ctx, PARSE_ERR);
652 if(asm_ctx.shader->type != ST_PIXEL) {
653 asmparser_message(&asm_ctx, "Line %u: Declaration needs a semantic\n",
655 set_parse_status(&asm_ctx, PARSE_ERR);
657 ZeroMemory(®, sizeof(reg));
659 reg.regnum = $3.regnum;
663 asm_ctx.funcs->dcl_input(&asm_ctx, 0, 0, $2.mod, ®);
665 | INSTR_DCL sampdcl omods REG_SAMPLER
667 TRACE("Sampler declared\n");
669 asmparser_message(&asm_ctx, "Line %u: Shift modifier not allowed here\n",
671 set_parse_status(&asm_ctx, PARSE_ERR);
673 asm_ctx.funcs->dcl_sampler(&asm_ctx, $2, $3.mod, $4, asm_ctx.line_no);
675 | INSTR_DCL omods REG_SAMPLER
677 TRACE("Sampler declared\n");
679 asmparser_message(&asm_ctx, "Line %u: Shift modifier not allowed here\n",
681 set_parse_status(&asm_ctx, PARSE_ERR);
683 if(asm_ctx.shader->type != ST_PIXEL) {
684 asmparser_message(&asm_ctx, "Line %u: Declaration needs a sampler type\n",
686 set_parse_status(&asm_ctx, PARSE_ERR);
688 asm_ctx.funcs->dcl_sampler(&asm_ctx, BWRITERSTT_UNKNOWN, $2.mod, $3, asm_ctx.line_no);
690 | INSTR_DCL sampdcl omods dcl_inputreg
692 TRACE("Error rule: sampler decl of input reg\n");
693 asmparser_message(&asm_ctx, "Line %u: Sampler declarations of input regs is not valid\n",
695 set_parse_status(&asm_ctx, PARSE_WARN);
697 | INSTR_DCL sampdcl omods REG_OUTPUT
699 TRACE("Error rule: sampler decl of output reg\n");
700 asmparser_message(&asm_ctx, "Line %u: Sampler declarations of output regs is not valid\n",
702 set_parse_status(&asm_ctx, PARSE_WARN);
704 | INSTR_DEF REG_CONSTFLOAT ',' IMMVAL ',' IMMVAL ',' IMMVAL ',' IMMVAL
706 asm_ctx.funcs->constF(&asm_ctx, $2, $4.val, $6.val, $8.val, $10.val);
708 | INSTR_DEFI REG_CONSTINT ',' IMMVAL ',' IMMVAL ',' IMMVAL ',' IMMVAL
710 asm_ctx.funcs->constI(&asm_ctx, $2, $4.val, $6.val, $8.val, $10.val);
712 | INSTR_DEFB REG_CONSTBOOL ',' IMMBOOL
714 asm_ctx.funcs->constB(&asm_ctx, $2, $4);
719 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_REP, 0, 0, 0, 0, &$2, 1);
724 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_ENDREP, 0, 0, 0, 0, 0, 0);
729 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_IF, 0, 0, 0, 0, &$2, 1);
731 | INSTR_IF comp sregs
734 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_IFC, 0, 0, $2, 0, &$3, 2);
739 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_ELSE, 0, 0, 0, 0, 0, 0);
744 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_ENDIF, 0, 0, 0, 0, 0, 0);
749 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_BREAK, 0, 0, 0, 0, 0, 0);
751 | INSTR_BREAK comp sregs
754 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_BREAKC, 0, 0, $2, 0, &$3, 2);
759 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_BREAKP, 0, 0, 0, 0, &$2, 1);
764 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_CALL, 0, 0, 0, 0, &$2, 1);
769 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_CALLNZ, 0, 0, 0, 0, &$2, 2);
774 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_LOOP, 0, 0, 0, 0, &$2, 2);
779 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_RET, 0, 0, 0, 0, 0, 0);
784 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_ENDLOOP, 0, 0, 0, 0, 0, 0);
789 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_LABEL, 0, 0, 0, 0, &$2, 1);
791 | INSTR_SETP comp dreg ',' sregs
794 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_SETP, 0, 0, $2, &$3, &$5, 2);
796 | INSTR_TEXLDL omods dreg ',' sregs
799 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_TEXLDL, $2.mod, $2.shift, 0, &$3, &$5, 2);
801 | INSTR_LIT omods dreg ',' sregs
804 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_LIT, $2.mod, $2.shift, 0, &$3, &$5, 1);
806 | INSTR_MOVA omods dreg ',' sregs
809 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_MOVA, $2.mod, $2.shift, 0, &$3, &$5, 1);
811 | INSTR_CND omods dreg ',' sregs
814 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_CND, $2.mod, $2.shift, 0, &$3, &$5, 3);
816 | INSTR_CMP omods dreg ',' sregs
819 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_CMP, $2.mod, $2.shift, 0, &$3, &$5, 3);
821 | INSTR_DP2ADD omods dreg ',' sregs
824 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_DP2ADD, $2.mod, $2.shift, 0, &$3, &$5, 3);
826 | INSTR_TEXCOORD omods dreg
829 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_TEXCOORD, $2.mod, $2.shift, 0, &$3, 0, 0);
831 | INSTR_TEXCRD omods dreg ',' sregs
834 /* texcoord and texcrd share the same opcode */
835 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_TEXCOORD, $2.mod, $2.shift, 0, &$3, &$5, 1);
840 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_TEXKILL, 0, 0, 0, &$2, 0, 0);
842 | INSTR_TEX omods dreg
845 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_TEX, $2.mod, $2.shift, 0, &$3, 0, 0);
847 | INSTR_TEXDEPTH omods dreg
850 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_TEXDEPTH, $2.mod, $2.shift, 0, &$3, 0, 0);
852 | INSTR_TEXLD omods dreg ',' sregs
855 /* There is more than one acceptable syntax for texld:
856 with 1 sreg (PS 1.4) or
857 with 2 sregs (PS 2.0+)
858 Moreover, texld shares the same opcode as the tex instruction,
859 so there are a total of 3 valid syntaxes
860 These variations are handled in asmparser.c */
861 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_TEX, $2.mod, $2.shift, 0, &$3, &$5, 2);
863 | INSTR_TEXLDP omods dreg ',' sregs
866 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_TEXLDP, $2.mod, $2.shift, 0, &$3, &$5, 2);
868 | INSTR_TEXLDB omods dreg ',' sregs
871 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_TEXLDB, $2.mod, $2.shift, 0, &$3, &$5, 2);
873 | INSTR_TEXBEM omods dreg ',' sregs
876 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_TEXBEM, $2.mod, $2.shift, 0, &$3, &$5, 1);
878 | INSTR_TEXBEML omods dreg ',' sregs
881 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_TEXBEML, $2.mod, $2.shift, 0, &$3, &$5, 1);
883 | INSTR_TEXREG2AR omods dreg ',' sregs
885 TRACE("TEXREG2AR\n");
886 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_TEXREG2AR, $2.mod, $2.shift, 0, &$3, &$5, 1);
888 | INSTR_TEXREG2GB omods dreg ',' sregs
890 TRACE("TEXREG2GB\n");
891 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_TEXREG2GB, $2.mod, $2.shift, 0, &$3, &$5, 1);
893 | INSTR_TEXREG2RGB omods dreg ',' sregs
895 TRACE("TEXREG2RGB\n");
896 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_TEXREG2RGB, $2.mod, $2.shift, 0, &$3, &$5, 1);
898 | INSTR_TEXM3x2PAD omods dreg ',' sregs
900 TRACE("TEXM3x2PAD\n");
901 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_TEXM3x2PAD, $2.mod, $2.shift, 0, &$3, &$5, 1);
903 | INSTR_TEXM3x3PAD omods dreg ',' sregs
905 TRACE("INSTR_TEXM3x3PAD\n");
906 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_TEXM3x3PAD, $2.mod, $2.shift, 0, &$3, &$5, 1);
908 | INSTR_TEXM3x3SPEC omods dreg ',' sregs
910 TRACE("TEXM3x3SPEC\n");
911 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_TEXM3x3SPEC, $2.mod, $2.shift, 0, &$3, &$5, 2);
913 | INSTR_TEXM3x3VSPEC omods dreg ',' sregs
915 TRACE("TEXM3x3VSPEC\n");
916 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_TEXM3x3VSPEC, $2.mod, $2.shift, 0, &$3, &$5, 1);
918 | INSTR_TEXM3x3TEX omods dreg ',' sregs
920 TRACE("TEXM3x3TEX\n");
921 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_TEXM3x3TEX, $2.mod, $2.shift, 0, &$3, &$5, 1);
923 | INSTR_TEXDP3TEX omods dreg ',' sregs
925 TRACE("TEXDP3TEX\n");
926 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_TEXDP3TEX, $2.mod, $2.shift, 0, &$3, &$5, 1);
928 | INSTR_TEXM3x2DEPTH omods dreg ',' sregs
930 TRACE("TEXM3x2DEPTH\n");
931 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_TEXM3x2DEPTH, $2.mod, $2.shift, 0, &$3, &$5, 1);
933 | INSTR_TEXM3x2TEX omods dreg ',' sregs
935 TRACE("TEXM3x2TEX\n");
936 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_TEXM3x2TEX, $2.mod, $2.shift, 0, &$3, &$5, 1);
938 | INSTR_TEXDP3 omods dreg ',' sregs
941 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_TEXDP3, $2.mod, $2.shift, 0, &$3, &$5, 1);
943 | INSTR_TEXM3x3 omods dreg ',' sregs
946 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_TEXM3x3, $2.mod, $2.shift, 0, &$3, &$5, 1);
948 | INSTR_BEM omods dreg ',' sregs
951 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_BEM, $2.mod, $2.shift, 0, &$3, &$5, 2);
953 | INSTR_DSX omods dreg ',' sregs
956 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_DSX, $2.mod, $2.shift, 0, &$3, &$5, 1);
958 | INSTR_DSY omods dreg ',' sregs
961 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_DSY, $2.mod, $2.shift, 0, &$3, &$5, 1);
963 | INSTR_TEXLDD omods dreg ',' sregs
966 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_TEXLDD, $2.mod, $2.shift, 0, &$3, &$5, 4);
971 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_PHASE, 0, 0, 0, 0, 0, 0);
975 dreg: dreg_name rel_reg
977 $$.regnum = $1.regnum;
979 $$.writemask = BWRITERSP_WRITEMASK_ALL;
980 $$.srcmod = BWRITERSPSM_NONE;
981 set_rel_reg(&$$, &$2);
983 | dreg_name writemask
985 $$.regnum = $1.regnum;
988 $$.srcmod = BWRITERSPSM_NONE;
994 $$.regnum = $1; $$.type = BWRITERSPR_TEMP;
998 $$.regnum = $1; $$.type = BWRITERSPR_OUTPUT;
1002 $$.regnum = $1; $$.type = BWRITERSPR_INPUT;
1006 asmparser_message(&asm_ctx, "Line %u: Register c%u is not a valid destination register\n",
1007 asm_ctx.line_no, $1);
1008 set_parse_status(&asm_ctx, PARSE_WARN);
1012 asmparser_message(&asm_ctx, "Line %u: Register i%u is not a valid destination register\n",
1013 asm_ctx.line_no, $1);
1014 set_parse_status(&asm_ctx, PARSE_WARN);
1018 asmparser_message(&asm_ctx, "Line %u: Register b%u is not a valid destination register\n",
1019 asm_ctx.line_no, $1);
1020 set_parse_status(&asm_ctx, PARSE_WARN);
1024 $$.regnum = $1; $$.type = BWRITERSPR_TEXTURE;
1028 $$.regnum = $1; $$.type = BWRITERSPR_TEXCRDOUT;
1032 asmparser_message(&asm_ctx, "Line %u: Register s%u is not a valid destination register\n",
1033 asm_ctx.line_no, $1);
1034 set_parse_status(&asm_ctx, PARSE_WARN);
1038 $$.regnum = BWRITERSRO_POSITION; $$.type = BWRITERSPR_RASTOUT;
1042 $$.regnum = BWRITERSRO_POINT_SIZE; $$.type = BWRITERSPR_RASTOUT;
1046 $$.regnum = BWRITERSRO_FOG; $$.type = BWRITERSPR_RASTOUT;
1050 $$.regnum = $1; $$.type = BWRITERSPR_ATTROUT;
1054 $$.regnum = $1; $$.type = BWRITERSPR_COLOROUT;
1058 $$.regnum = 0; $$.type = BWRITERSPR_DEPTHOUT;
1062 $$.regnum = 0; $$.type = BWRITERSPR_PREDICATE;
1066 asmparser_message(&asm_ctx, "Line %u: Register vPos is not a valid destination register\n",
1068 set_parse_status(&asm_ctx, PARSE_WARN);
1072 asmparser_message(&asm_ctx, "Line %u: Register vFace is not a valid destination register\n",
1074 set_parse_status(&asm_ctx, PARSE_WARN);
1078 /* index 0 is hardcoded for the addr register */
1079 $$.regnum = 0; $$.type = BWRITERSPR_ADDR;
1083 asmparser_message(&asm_ctx, "Line %u: Register aL is not a valid destination register\n",
1085 set_parse_status(&asm_ctx, PARSE_WARN);
1088 writemask: '.' wm_components
1090 if($2.writemask == SWIZZLE_ERR) {
1091 asmparser_message(&asm_ctx, "Line %u: Invalid writemask specified\n",
1093 set_parse_status(&asm_ctx, PARSE_ERR);
1094 /* Provide a correct writemask to prevent following complaints */
1095 $$ = BWRITERSP_WRITEMASK_ALL;
1099 TRACE("Writemask: %x\n", $$);
1103 wm_components: COMPONENT
1105 $$.writemask = 1 << $1;
1109 | wm_components COMPONENT
1111 if($1.writemask == SWIZZLE_ERR || $1.idx == 4)
1112 /* Wrong writemask */
1113 $$.writemask = SWIZZLE_ERR;
1116 $$.writemask = SWIZZLE_ERR;
1118 $$.writemask = $1.writemask | (1 << $2);
1119 $$.idx = $1.idx + 1;
1124 swizzle: /* empty */
1126 $$ = BWRITERVS_NOSWIZZLE;
1127 TRACE("Default swizzle: %08x\n", $$);
1131 if($2.swizzle == SWIZZLE_ERR) {
1132 asmparser_message(&asm_ctx, "Line %u: Invalid swizzle\n",
1134 set_parse_status(&asm_ctx, PARSE_ERR);
1135 /* Provide a correct swizzle to prevent following complaints */
1136 $$ = BWRITERVS_NOSWIZZLE;
1141 $$ = $2.swizzle << BWRITERVS_SWIZZLE_SHIFT;
1142 /* Fill the swizzle by extending the last component */
1143 last = ($2.swizzle >> 2 * ($2.idx - 1)) & 0x03;
1144 for(i = $2.idx; i < 4; i++){
1145 $$ |= last << (BWRITERVS_SWIZZLE_SHIFT + 2 * i);
1147 TRACE("Got a swizzle: %08x\n", $$);
1151 sw_components: COMPONENT
1156 | sw_components COMPONENT
1159 /* Too many sw_components */
1160 $$.swizzle = SWIZZLE_ERR;
1164 $$.swizzle = $1.swizzle | ($2 << 2 * $1.idx);
1165 $$.idx = $1.idx + 1;
1176 $$.mod = $1.mod | $2.mod;
1177 if($1.shift && $2.shift) {
1178 asmparser_message(&asm_ctx, "Line %u: More than one shift flag\n",
1180 set_parse_status(&asm_ctx, PARSE_ERR);
1181 $$.shift = $1.shift;
1183 $$.shift = $1.shift | $2.shift;
1219 $$.mod = BWRITERSPDM_SATURATE;
1224 $$.mod = BWRITERSPDM_PARTIALPRECISION;
1229 $$.mod = BWRITERSPDM_MSAMPCENTROID;
1240 if($$.count == MAX_SRC_REGS){
1241 asmparser_message(&asm_ctx, "Line %u: Too many source registers in this instruction\n",
1243 set_parse_status(&asm_ctx, PARSE_ERR);
1246 $$.reg[$$.count++] = $3;
1249 sreg: sreg_name rel_reg swizzle
1252 $$.regnum = $1.regnum;
1254 $$.srcmod = BWRITERSPSM_NONE;
1255 set_rel_reg(&$$, &$2);
1257 | sreg_name rel_reg smod swizzle
1260 $$.regnum = $1.regnum;
1261 set_rel_reg(&$$, &$2);
1265 | '-' sreg_name rel_reg swizzle
1268 $$.regnum = $2.regnum;
1269 $$.srcmod = BWRITERSPSM_NEG;
1270 set_rel_reg(&$$, &$3);
1273 | '-' sreg_name rel_reg smod swizzle
1276 $$.regnum = $2.regnum;
1277 set_rel_reg(&$$, &$3);
1279 case BWRITERSPSM_BIAS: $$.srcmod = BWRITERSPSM_BIASNEG; break;
1280 case BWRITERSPSM_X2: $$.srcmod = BWRITERSPSM_X2NEG; break;
1281 case BWRITERSPSM_SIGN: $$.srcmod = BWRITERSPSM_SIGNNEG; break;
1282 case BWRITERSPSM_ABS: $$.srcmod = BWRITERSPSM_ABSNEG; break;
1283 case BWRITERSPSM_DZ:
1284 asmparser_message(&asm_ctx, "Line %u: Incompatible source modifiers: NEG and DZ\n",
1286 set_parse_status(&asm_ctx, PARSE_ERR);
1288 case BWRITERSPSM_DW:
1289 asmparser_message(&asm_ctx, "Line %u: Incompatible source modifiers: NEG and DW\n",
1291 set_parse_status(&asm_ctx, PARSE_ERR);
1294 FIXME("Unhandled combination of NEGATE and %u\n", $4);
1298 | IMMVAL '-' sreg_name rel_reg swizzle
1300 if($1.val != 1.0 || (!$1.integer)) {
1301 asmparser_message(&asm_ctx, "Line %u: Only \"1 - reg\" is valid for D3DSPSM_COMP, "
1302 "%g - reg found\n", asm_ctx.line_no, $1.val);
1303 set_parse_status(&asm_ctx, PARSE_ERR);
1305 /* Complement - not compatible with other source modifiers */
1307 $$.regnum = $3.regnum;
1308 $$.srcmod = BWRITERSPSM_COMP;
1309 set_rel_reg(&$$, &$4);
1312 | IMMVAL '-' sreg_name rel_reg smod swizzle
1314 /* For nicer error reporting */
1315 if($1.val != 1.0 || (!$1.integer)) {
1316 asmparser_message(&asm_ctx, "Line %u: Only \"1 - reg\" is valid for D3DSPSM_COMP\n",
1318 set_parse_status(&asm_ctx, PARSE_ERR);
1320 asmparser_message(&asm_ctx, "Line %u: Incompatible source modifiers: D3DSPSM_COMP and %s\n",
1322 debug_print_srcmod($5));
1323 set_parse_status(&asm_ctx, PARSE_ERR);
1326 | SMOD_NOT sreg_name swizzle
1329 $$.regnum = $2.regnum;
1331 $$.srcmod = BWRITERSPSM_NOT;
1335 rel_reg: /* empty */
1337 $$.has_rel_reg = FALSE;
1338 $$.additional_offset = 0;
1342 $$.has_rel_reg = FALSE;
1343 $$.additional_offset = $2.val;
1345 | '[' relreg_name swizzle ']'
1347 $$.has_rel_reg = TRUE;
1349 $$.additional_offset = 0;
1350 $$.rel_regnum = $2.regnum;
1353 | '[' immsum '+' relreg_name swizzle ']'
1355 $$.has_rel_reg = TRUE;
1357 $$.additional_offset = $2.val;
1358 $$.rel_regnum = $4.regnum;
1361 | '[' relreg_name swizzle '+' immsum ']'
1363 $$.has_rel_reg = TRUE;
1365 $$.additional_offset = $5.val;
1366 $$.rel_regnum = $2.regnum;
1369 | '[' immsum '+' relreg_name swizzle '+' immsum ']'
1371 $$.has_rel_reg = TRUE;
1373 $$.additional_offset = $2.val + $7.val;
1374 $$.rel_regnum = $4.regnum;
1381 asmparser_message(&asm_ctx, "Line %u: Unexpected float %f\n",
1382 asm_ctx.line_no, $1.val);
1383 set_parse_status(&asm_ctx, PARSE_ERR);
1390 asmparser_message(&asm_ctx, "Line %u: Unexpected float %f\n",
1391 asm_ctx.line_no, $3.val);
1392 set_parse_status(&asm_ctx, PARSE_ERR);
1394 $$.val = $1.val + $3.val;
1399 $$ = BWRITERSPSM_BIAS;
1403 $$ = BWRITERSPSM_X2;
1407 $$ = BWRITERSPSM_SIGN;
1411 $$ = BWRITERSPSM_DZ;
1415 $$ = BWRITERSPSM_DW;
1419 $$ = BWRITERSPSM_ABS;
1422 relreg_name: REG_ADDRESS
1424 $$.regnum = 0; $$.type = BWRITERSPR_ADDR;
1428 $$.regnum = 0; $$.type = BWRITERSPR_LOOP;
1433 $$.regnum = $1; $$.type = BWRITERSPR_TEMP;
1437 asmparser_message(&asm_ctx, "Line %u: Register o%u is not a valid source register\n",
1438 asm_ctx.line_no, $1);
1439 set_parse_status(&asm_ctx, PARSE_WARN);
1443 $$.regnum = $1; $$.type = BWRITERSPR_INPUT;
1447 $$.regnum = $1; $$.type = BWRITERSPR_CONST;
1451 $$.regnum = $1; $$.type = BWRITERSPR_CONSTINT;
1455 $$.regnum = $1; $$.type = BWRITERSPR_CONSTBOOL;
1459 $$.regnum = $1; $$.type = BWRITERSPR_TEXTURE;
1463 asmparser_message(&asm_ctx, "Line %u: Register oT%u is not a valid source register\n",
1464 asm_ctx.line_no, $1);
1465 set_parse_status(&asm_ctx, PARSE_WARN);
1469 $$.regnum = $1; $$.type = BWRITERSPR_SAMPLER;
1473 asmparser_message(&asm_ctx, "Line %u: Register oPos is not a valid source register\n",
1475 set_parse_status(&asm_ctx, PARSE_WARN);
1479 asmparser_message(&asm_ctx, "Line %u: Register oFog is not a valid source register\n",
1481 set_parse_status(&asm_ctx, PARSE_WARN);
1485 asmparser_message(&asm_ctx, "Line %u: Register oD%u is not a valid source register\n",
1486 asm_ctx.line_no, $1);
1487 set_parse_status(&asm_ctx, PARSE_WARN);
1491 asmparser_message(&asm_ctx, "Line %u: Register oC%u is not a valid source register\n",
1492 asm_ctx.line_no, $1);
1493 set_parse_status(&asm_ctx, PARSE_WARN);
1497 asmparser_message(&asm_ctx, "Line %u: Register oDepth is not a valid source register\n",
1499 set_parse_status(&asm_ctx, PARSE_WARN);
1503 $$.regnum = 0; $$.type = BWRITERSPR_PREDICATE;
1507 $$.regnum = 0; $$.type = BWRITERSPR_MISCTYPE;
1511 $$.regnum = 1; $$.type = BWRITERSPR_MISCTYPE;
1515 $$.regnum = 0; $$.type = BWRITERSPR_ADDR;
1519 $$.regnum = 0; $$.type = BWRITERSPR_LOOP;
1523 $$.regnum = $1; $$.type = BWRITERSPR_LABEL;
1526 comp: COMP_GT { $$ = BWRITER_COMPARISON_GT; }
1527 | COMP_LT { $$ = BWRITER_COMPARISON_LT; }
1528 | COMP_GE { $$ = BWRITER_COMPARISON_GE; }
1529 | COMP_LE { $$ = BWRITER_COMPARISON_LE; }
1530 | COMP_EQ { $$ = BWRITER_COMPARISON_EQ; }
1531 | COMP_NE { $$ = BWRITER_COMPARISON_NE; }
1533 dclusage: USAGE_POSITION
1535 TRACE("dcl_position%u\n", $1);
1537 $$.dclusage = BWRITERDECLUSAGE_POSITION;
1541 TRACE("dcl_blendweight%u\n", $1);
1543 $$.dclusage = BWRITERDECLUSAGE_BLENDWEIGHT;
1545 | USAGE_BLENDINDICES
1547 TRACE("dcl_blendindices%u\n", $1);
1549 $$.dclusage = BWRITERDECLUSAGE_BLENDINDICES;
1553 TRACE("dcl_normal%u\n", $1);
1555 $$.dclusage = BWRITERDECLUSAGE_NORMAL;
1559 TRACE("dcl_psize%u\n", $1);
1561 $$.dclusage = BWRITERDECLUSAGE_PSIZE;
1565 TRACE("dcl_texcoord%u\n", $1);
1567 $$.dclusage = BWRITERDECLUSAGE_TEXCOORD;
1571 TRACE("dcl_tangent%u\n", $1);
1573 $$.dclusage = BWRITERDECLUSAGE_TANGENT;
1577 TRACE("dcl_binormal%u\n", $1);
1579 $$.dclusage = BWRITERDECLUSAGE_BINORMAL;
1583 TRACE("dcl_tessfactor%u\n", $1);
1585 $$.dclusage = BWRITERDECLUSAGE_TESSFACTOR;
1589 TRACE("dcl_positiont%u\n", $1);
1591 $$.dclusage = BWRITERDECLUSAGE_POSITIONT;
1595 TRACE("dcl_color%u\n", $1);
1597 $$.dclusage = BWRITERDECLUSAGE_COLOR;
1601 TRACE("dcl_fog%u\n", $1);
1603 $$.dclusage = BWRITERDECLUSAGE_FOG;
1607 TRACE("dcl_depth%u\n", $1);
1609 $$.dclusage = BWRITERDECLUSAGE_DEPTH;
1613 TRACE("dcl_sample%u\n", $1);
1615 $$.dclusage = BWRITERDECLUSAGE_SAMPLE;
1618 dcl_inputreg: REG_INPUT
1620 $$.regnum = $1; $$.type = BWRITERSPR_INPUT;
1624 $$.regnum = $1; $$.type = BWRITERSPR_TEXTURE;
1627 sampdcl: SAMPTYPE_1D
1637 $$ = BWRITERSTT_CUBE;
1641 $$ = BWRITERSTT_VOLUME;
1644 predicate: '(' REG_PREDICATE swizzle ')'
1646 $$.type = BWRITERSPR_PREDICATE;
1649 $$.srcmod = BWRITERSPSM_NONE;
1652 | '(' SMOD_NOT REG_PREDICATE swizzle ')'
1654 $$.type = BWRITERSPR_PREDICATE;
1657 $$.srcmod = BWRITERSPSM_NOT;
1663 void asmshader_error (char const *s) {
1664 asmparser_message(&asm_ctx, "Line %u: Error \"%s\" from bison\n", asm_ctx.line_no, s);
1665 set_parse_status(&asm_ctx, PARSE_ERR);
1668 /* Error reporting function */
1669 void asmparser_message(struct asm_parser *ctx, const char *fmt, ...) {
1674 if(ctx->messagecapacity == 0) {
1675 ctx->messages = asm_alloc(MESSAGEBUFFER_INITIAL_SIZE);
1676 if(ctx->messages == NULL) {
1677 ERR("Error allocating memory for parser messages\n");
1680 ctx->messagecapacity = MESSAGEBUFFER_INITIAL_SIZE;
1684 va_start(args, fmt);
1685 rc = vsnprintf(ctx->messages + ctx->messagesize,
1686 ctx->messagecapacity - ctx->messagesize, fmt, args);
1689 if (rc < 0 || /* C89 */
1690 rc >= ctx->messagecapacity - ctx->messagesize) { /* C99 */
1691 /* Resize the buffer */
1692 newsize = ctx->messagecapacity * 2;
1693 newbuffer = asm_realloc(ctx->messages, newsize);
1694 if(newbuffer == NULL){
1695 ERR("Error reallocating memory for parser messages\n");
1698 ctx->messages = newbuffer;
1699 ctx->messagecapacity = newsize;
1701 ctx->messagesize += rc;
1707 /* New status is the worst between current status and parameter value */
1708 void set_parse_status(struct asm_parser *ctx, enum parse_status status) {
1709 if(status == PARSE_ERR) ctx->status = PARSE_ERR;
1710 else if(status == PARSE_WARN && ctx->status == PARSE_SUCCESS) ctx->status = PARSE_WARN;
1713 struct bwriter_shader *parse_asm_shader(char **messages) {
1714 struct bwriter_shader *ret = NULL;
1716 asm_ctx.shader = NULL;
1717 asm_ctx.status = PARSE_SUCCESS;
1718 asm_ctx.messagesize = asm_ctx.messagecapacity = 0;
1719 asm_ctx.line_no = 1;
1723 if(asm_ctx.status != PARSE_ERR) ret = asm_ctx.shader;
1724 else if(asm_ctx.shader) SlDeleteShader(asm_ctx.shader);
1727 if(asm_ctx.messagesize) {
1728 /* Shrink the buffer to the used size */
1729 *messages = asm_realloc(asm_ctx.messages, asm_ctx.messagesize + 1);
1731 ERR("Out of memory, no messages reported\n");
1732 asm_free(asm_ctx.messages);
1738 if(asm_ctx.messagecapacity) asm_free(asm_ctx.messages);