How to write portable code given lex/ flex code incompatibilities - portability

Flex is somewhat a free implementation of Lex program, although there are some incompatibilities between them.
For instance Lex store the current line into a global variable yylineno whereas in flex to access it you should add in the code %option yylineno .
Is possible to write portable code knowing that %option tag is not recognized by Lex?
Update :
lex: Software Generation Utilities (SGU) Solaris-ELF (4.0)
flex version 2.5.2

I almost found the solution in this case, According To this link, to activate the global variable yylineno you should add -l option when executing flex so you don't have to add the %option in the code,so you will have a compatible code between flex and lex .

Related

How can I inspect x86/x64 code generated by V8 from WebAssembly?

https://webassembly.studio/ allows inspection of WebAssembly (WASM) files and the corresponding SpiderMonkey-generated x86 code. I'd like to similarly inspect instructions generated by V8's WASM compilers (Liftoff and TurboFan).
I'm entirely unfamiliar with V8's codebase/API (I compiled & linked it and followed some tutorials, though). There seems to be a v8::CompiledWasmModule class available, but it does not seem to expose access to generated x86/x64 instructions by either Liftoff or TurboFan.
WebAssembly - adding a new opcode describes the process of adding a WASM opcode to V8. Seemingly appropriate functions for WASM compilation/execution are available in the mentioned classes. Though, these seem rather deeply layered within the V8 codebase and would be difficult to access were I to link V8 as a library. Also, I'm unsure if this corresponds to Liftoff or TurboFan.
Could anybody familiar with the V8 codebase give me some pointers as to how I can access Liftoff and/or TurboFan's WebAssembly compilation module, as to obtain x86/x64 code?
To inspect generated code, you can run the d8 shell with the --print-wasm-code flag. You'll need either a debug build, or a release build with the v8_enable_disassembler = true GN arg.
There's no existing way to retrieve generated code via V8's API; so if that's what you want, then you'd have to add it. Keep in mind that V8 is not designed to be a standalone compiler, which means generated code assumes that it's going to run "inside V8", so if you wanted to use it for anything else, you'd have to make significant modifications.

ctags and ruby modules in vim

I'm using ripper tags (https://github.com/tmm1/ripper-tags) to generate ctags files for a ruby project.
My goals is, in vim, to be able to jump from a line such as:
::Api::Contracts::Creator.new(
To the relevant file which defines that module.
This configuration works fine if there is only one module called Creator. But in practice there will be many Creators in different namespaces, e.g there will also be an ::Api::Users::Creator.
The above configuration will just jump to the first definition of Creator rather than the specific Creator in question.
Is there anyway to configure ctags so that it will jump to the specific definition?
ripper-tags needs to be run with the option
--extra=1
So that tags will be generated which include the full module paths. This still leaves the problem that ctrl+] uses the current word so using it on Module::Class will only search for Class.
But this isn't really a ctags issue so I'll open a separate question on how best to write a custom command in vim to do this.
Using visual select to select the full definition and then ctrl+] will go to the correct definition.

Clion sort include statements

Is there a way to sort my #include statements in Clion? Additionally, can I do this automatically every time I save? I didn't manage to find any such functionality or plugin.
Yes, it is possible with help of clang-format.
File->Settings...->Languages & Framework->C/C++->Clangd->Enable clangs server
clang-format should be installed in your system. Normally it is available in your favourite repository. You can specify the path to it if required
File->Settings...->Tools->clang-format
You have to put .clang-format file into your project root with coding rules. More information you can find on clang-format web site. For example, I am using Google coding rules. My content looks like this:
Language: Cpp
BasedOnStyle: Google
This includes already the include statements sorting. However, there is a choice of other ready-to-use coding styles like LLVM, Mozilla, WebKit, Chromium which you can use and if necessary modify or you can create your own format by providing set of rules you want. The rule you might be interesting in is
SortIncludes (bool)
If true, clang-format will sort #includes.
Please refer to the clang format documentation here

Compiling Firefox from source with custom defines?

I've been doing some tinkering with the Firefox source code, and I'd like to be able to compile it with some custom defines.
For example, the Firefox source code has some ifdef blocks like this, where EXAMPLE is one of many constants.
#ifdef EXAMPLE
// code here
#endif
What I'd like to do is enable some of these constants, presumable by configuring my .mozconfig file to set them somehow.
I haven't found any documentation on how to do this, but based on some examples, I thought maybe adding this might do the trick.
mk_add_options EXAMPLE=1
But it didn't work, and neither does this (DEFINES: command not found):
DEFINES += -DEXAMPLE
It must be possible somehow though, as presumably Firefox developers are using this feature.
How can I set some custom defines for the Firefox build scripts?

Versioning Binaries on OSX

I have a C program that I build using Makefiles on OS X and I'd like to add the version/build number so that it is included in any crash reports. How can this be done without putting the binary as part of an app bundle?
As you may have realised, the standard OSX method is to create a bundle and add the version in the Info.plist and there isn't the usual attributes available within the binary executable, as you'd find in Windows.
Many terminal apps will allow you to discover their version with a -v option, but this is usuallly just a function returning the version number.
If you want to add meta data without hard coding it, you could use the extended file attributes to store the version number, which you can read, write and view with the xattr command.

Resources